-
Notifications
You must be signed in to change notification settings - Fork 12k
Use uint256
iterators in MerkleTree
loops
#5414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Let me know if I should add the change in |
Hi @heueristik, thanks for sharing. There are some gas savings during construction (I wasn't expecting it) but not much during runtime. ![]() ![]() Although the savings seem considerable, applying this change is considered a breaking change given the arguments will be encoded differently after merging. I'm not 100% convinced the change is worth changing the interface |
Thank you @ernestognw for taking a look. Can you help me to understand which arguments will be encoded differently?
for |
Hey @heueristik, sorry my bad, I thought these were arguments to a function. That is not the case. Have you done some benchmarking? I suspect there may be no gas difference when using |
I'm under the impression that there are no breaking changes here. I think we should merge it since using |
🧐 Motivation
The current
MerkleTree.sol
contract contains twofor
loops, both of which useuint32
as an iterator when iterating from0
touint8 treeDepth
. This is not optimal anduint256
should be used to minimize conversions.📝 Details
Use
uint256
for the iterators inMerkleTree.sol
openzeppelin-contracts/contracts/utils/structs/MerkleTree.sol
Line 91 in bf69b60
openzeppelin-contracts/contracts/utils/structs/MerkleTree.sol
Line 146 in bf69b60
to save gas.
While on it, you can also change the for loops in the
Heap.t.sol
test.openzeppelin-contracts/test/utils/structs/Heap.t.sol
Line 16 in bf69b60
The text was updated successfully, but these errors were encountered: