ferranbt / fastssz

Fast Ethereum2.0 SSZ encoder/decoder
MIT License
74 stars 44 forks source link

Method to produce source code hash is not deterministic #110

Closed gmaiainc closed 1 year ago

gmaiainc commented 1 year ago

When fastssz is ran multiple times against the same package, even without changes to the original files, the generated file keeps changing. This is because the hash that is present on the header of the generated files is not deterministic. This is reproducible when fastssz is ran on any package with more than one source file.

This is most likely due to a bug in https://github.com/ferranbt/fastssz/blob/87558029fb68920c009520583ad7521e1b909119/sszgen/generator/generator.go#L314, which iterates over e.files (a map). In Go, the order of iteration over maps is not stable, therefore the plaintext fed to the sha256 hash is also not stable.

ferranbt commented 1 year ago

Hi, I think you are correct. I am assuming what changes is the hash digest and not the generated code? Would you like to open a PR to fix the issue?