# What affects the hash code of a DAML's package

**URL:** <https://forum.canton.network/t/what-affects-the-hash-code-of-a-damls-package/7558>\
**Category:** App Development\
**Tags:** daml\
**Created:** [December 23, 2024, 5:29pm UTC](https://forum.canton.network/t/what-affects-the-hash-code-of-a-damls-package/7558 "2024-12-23T17:29:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [December 23, 2024, 5:29pm UTC](https://forum.canton.network/t/what-affects-the-hash-code-of-a-damls-package/7558/1 "2024-12-23T17:29:12Z")

</div>

G-d willing

Hello,  
During my coding with DAML, I noticed 2 scenarios where the content of a DAML package was changed, but its hash code didn’t. These 2 scenarios are. The first scenario was when I added a dependency to the `daml.yaml` file, but without actually using any of the resources of that package.  
The second scenario was when in the dependent package there were code changes that weren’t being used in the actual package. So, in other words, the only resource my package was dependent on, that was not “really” changed. The reason I wrote really with the double quotes is that it was changed, but whatever was changed, was not being used in the package.  
I mean, let’s say I have package A that is dependent on package B.  
Package B defines 2 types, type Address, and type Phone.  
Package A uses only the Address type. So, even when making changes to the Phone type, and even adding new types to package B, the actual hash code of package A did not change.

Since this issue is coupled with contract upgrades, I need to know what else affects it.

Thanks,

---

<div class="post-metadata">

**Author:** ![WallaceKelly](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/wallacekelly/32/5046_2.png) [@WallaceKelly](https://forum.canton.network/u/WallaceKelly)\
**Post date:** [January 2, 2025, 2:59pm UTC](https://forum.canton.network/t/what-affects-the-hash-code-of-a-damls-package/7558/2 "2025-01-02T14:59:29Z")

</div>

@cohen.avraham, can you try re-running your second scenario? I’m getting different results. Here is what I did:

I created a pair of projects – `app` and `lib`. I created a `multi-package.yaml` file to build them both. I compared the package ids of four versions of `app`:

1. _Without_ any data-dependency.
2. After adding an _unused_ data-dependency.
3. After _referring to_ a template from the data-dependency.
4. After _editing an unused record_ in the data-dependency.

The package ids for 1 and 2 are identical, as you have observed.

For me, the package ids changed from 2 to 3 and from 3 to 4.

This all seems consistent with the docs [here](https://docs.daml.com/concepts/identity-and-package-management.html#package-formats-and-identifiers) and [here](https://docs.daml.com/daml/intro/9_Dependencies.html#dar-dalf-daml-lf-and-the-engine).

> **Raw results**
>
> ```sh
> 
> # all edits are commented out
> 
> > cat app/daml.yaml | grep data
> # data-dependencies:
> 
> > cat app/daml.yaml | grep lib
> # - ../lib/.daml/dist/lib-0.0.1.dar
> 
> > cat app/daml/Main.daml| grep LAsset
> -- type LAssetId = ContractId L.Asset
> 
> > cat lib/daml/Lib.daml| grep Wallace
> -- data WallaceWasHere = YES
> 
> > daml build --all
> Running multi-package build of all packages
> 
> > mv app/.daml/dist/app-0.0.1.dar app-0.0.1.1.dar
> 
> # the unused data dependency has been added
> 
> > cat app/daml.yaml | grep lib
> - ../lib/.daml/dist/lib-0.0.1.dar
> 
> > daml build --all
> Running multi-package build of all packages
> 
> > mv app/.daml/dist/app-0.0.1.dar app-0.0.1.2.dar
> 
> # the data-dependency has been referenced
> 
> > cat app/daml/Main.daml| grep LAsset
> type LAssetId = ContractId L.Asset
> 
> > daml build --all
> Running multi-package build of all packages
> 
> > mv app/.daml/dist/app-0.0.1.dar app-0.0.1.3.dar
> 
> # the data-dependency has been edited
> 
> > cat lib/daml/Lib.daml| grep Wallace
> data WallaceWasHere = YES
> 
> > daml build --all
> Running multi-package build of all packages
> 
> > mv app/.daml/dist/app-0.0.1.dar app-0.0.1.4.dar
> 
> # display the four package ids
> 
> > daml damlc inspect-dar --json app-0.0.1.1.dar | jq -r .main_package_id
> 308ef3763a1d1ec6bca606735aa027c81c61aa9423aa3ad657078925f53d65fb
> 
> > daml damlc inspect-dar --json app-0.0.1.2.dar | jq -r .main_package_id
> 308ef3763a1d1ec6bca606735aa027c81c61aa9423aa3ad657078925f53d65fb
> 
> > daml damlc inspect-dar --json app-0.0.1.3.dar | jq -r .main_package_id
> 1686c7a11bf6b18c34dae188c2c4a54bf3938400416c690a9f3f4ce6966f9462
> 
> > daml damlc inspect-dar --json app-0.0.1.4.dar | jq -r .main_package_id
> 3f7a739f9ce407b7150bcaf21112d810bbfd08f4d0d861c8e96f9e8e85995a69
> 
> ```

---

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [January 6, 2025, 10:15am UTC](https://forum.canton.network/t/what-affects-the-hash-code-of-a-damls-package/7558/3 "2025-01-06T10:15:08Z")

</div>

Thanks @WallaceKelly for your response.  
Well, I want to know if there are more scenarios where the hash code of the package won’t change.

---

<div class="post-metadata">

**Author:** ![WallaceKelly](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/wallacekelly/32/5046_2.png) [@WallaceKelly](https://forum.canton.network/u/WallaceKelly)\
**Post date:** [January 6, 2025, 2:00pm UTC](https://forum.canton.network/t/what-affects-the-hash-code-of-a-damls-package/7558/4 "2025-01-06T14:00:52Z")

</div>

It’s an interesting question, but probably hard to answer exhaustively. What are all the things we could try?

The following, for example,…

> [@What goes into a package hash?](https://discuss.daml.com/t/what-goes-into-a-package-hash/5383/2):
>
> It’s a hash of the package (after compilation to Daml-LF) and all of its dependencies (also compiled to Daml-LF first, if they’re not “data-dependencies”). The SDK version the code is compiled with is also the version of the Standard Library that it gets compiled against, which is why that changes the hash, just like upgrading any other dependency. Depending on the specifics of the code and the versions of the compiler, it’s also possible that the compiler might be generating different LF, whic…

… mentions that a change in line endings (for the source code) will not change the package id. I just confirmed that.

That brings our list to two:

- Adding an unused data-dependency.
- Changing the line endings (from LR to CRLF for example).
