Fix gas loop optimization in MerkleProof.sol
(#5028)
#5036
+18
−4
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.
Fixes #5028
Changes are made in 2 commits:
c9b7c9b8aa60c3cd45d76f31d89d73f4a1823b60
wherei
is left uninitialized in for loops,i
is prepend incremented and incrementing is done in an unchecked block. This is NOT mentioned in the Loop gas optimisation #5028 issue however, I figured it would be relevant in for loop optimization as the only constraint this introduces is that proof length and totalHashes do not exceed 2^256-1 which is entirely unfeasible.9e2ba99dfcf5f145fd68c5eea42d899836d9571b
includes the fix mentioned in the issue where the length of proof is cached to prevent an unnecessary DUP (3 gas per iteration)PR Checklist
npx changeset add
)