Skip to content

Semantic integrity hash affected by field order #548

@joneshf

Description

@joneshf

It looks like something changed to the way hashes work for records and unions. In an older version, the order of fields in records/unions would not change the hash. That seems to be in line with the standard. In more recent versions, the order of fields affects the hash produced.

dhall-hash 1.8.2
[nix-shell:~]$ dhall --version
1.8.2

[nix-shell:~]$ echo '{foo = 1, bar = 2}' | dhall-hash
sha256:6364e21a806e13b82afaa6ea927ae23e15bb53da2573292f085911396877cf3f

[nix-shell:~]$ echo '{bar = 2, foo = 1}' | dhall-hash
sha256:6364e21a806e13b82afaa6ea927ae23e15bb53da2573292f085911396877cf3f

[nix-shell:~]$ echo '<foo : Natural | bar : Natural>' | dhall-hash
sha256:657b73e8d23f4386ba6895247a6dda9c762c4beb35e6e8a3b0108d6d3888b91c

[nix-shell:~]$ echo '<bar : Natural | foo : Natural>' | dhall-hash
sha256:657b73e8d23f4386ba6895247a6dda9c762c4beb35e6e8a3b0108d6d3888b91c
dhall hash 1.16.1
$ echo '{foo = 1, bar = 2}' | stack exec dhall -- hash
sha256:83f262b95390c2c55b381d753802019bb3188a25ac5fbe3c8b3c00c47afd9534
$ echo '{bar = 2, foo = 1}' | stack exec dhall -- hash
sha256:6364e21a806e13b82afaa6ea927ae23e15bb53da2573292f085911396877cf3f
$ echo '<foo : Natural | bar : Natural>' | stack exec dhall -- hash
sha256:d188708d41b0db2981e50442bdd19ace258830e9e13fd1a3b6ec94b2224d8578
$ echo '<bar : Natural | foo : Natural>' | stack exec dhall -- hash
sha256:657b73e8d23f4386ba6895247a6dda9c762c4beb35e6e8a3b0108d6d3888b91c

Is this change intended? If so, we should update the spec to make that clearer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions