feat: disallow non-deterministic iteration order#3
Open
kevaundray wants to merge 4 commits intoparadigmxyz:mainfrom
Open
feat: disallow non-deterministic iteration order#3kevaundray wants to merge 4 commits intoparadigmxyz:mainfrom
kevaundray wants to merge 4 commits intoparadigmxyz:mainfrom
Conversation
kevaundray
commented
Feb 14, 2026
Comment on lines
+5
to
+8
| // TODO: `reveal_witness` from reth uses B256Map. We would need to change it from | ||
| // there first. | ||
| #[allow(clippy::disallowed_types)] | ||
| use alloy_primitives::map::B256Map; |
Contributor
Author
There was a problem hiding this comment.
This would need to be fixed in reth
Contributor
Author
|
This can be somewhat tricky because the change would need to also happen in dependencies (mainly reth and alloy) -- HashMap is technically okay to use, but one would just need to ensure that the iteration order is deterministic. This is already done in some places with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Some zkVMs run/execute the program multiple times while proving. For example, this can be done once with the emulator and then another time with an assembly generated version of the emulator. These two runs for correctness reasons should match, however since
HashMap::iteris non-deterministic, this is not the case.Moreover, deterministic runs make it a lot easier to debug programs.
For why HashMap is non-deterministic, one can see here
Suggested solution
Replace all usages of HashMap with IndexMap or BTreeMap. These implementations have stable iteration orders. Also added a clippy lint to ensure that those types cannot be used in this crate.
Notes
This is somewhat a fairly common issue in code that requires/desire deterministic builds like compilers, see here and here
This PR would only partially solve the issue since some crates in reth also use HashMap