-
Notifications
You must be signed in to change notification settings - Fork 8
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
refactor: double hash #206
Conversation
test: add sort function in Merkle Builder test: sort tree leaves in MerkleStreamer tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have stopped my review when I saw the binarySearch
and sort
functions implemented in our code base.
Both OpenZeppelin and Solady offer implementations for this:
There's no point in maintaining mirror implementations of the same code, so we should just import and use one of these two libraries
Firstly, there is no function for |
There are mupltiple Then, it is true that the You can just define a storage array in the bytes32[] public leaves = new bytes32[](RECIPIENTS_COUNT);
constructor() {
leaves[0] = MerkleBuilder.computeLeaf(INDEX1, users.recipient1.addr, CLAIM_AMOUNT);
leaves[1] = MerkleBuilder.computeLeaf(INDEX2, users.recipient2.addr, CLAIM_AMOUNT);
leaves[2] = MerkleBuilder.computeLeaf(INDEX3, users.recipient3.addr, CLAIM_AMOUNT);
leaves[3] = MerkleBuilder.computeLeaf(INDEX4, users.recipient4.addr, CLAIM_AMOUNT);
} In general, I would like us to prefer to import code rather than copy-paste it, so that we don't have to (i) understand it and (ii) maintain it. |
Did not know about
makes sense, going to remove them |
Perfect, thanks! |
Use solady to sort merkle tree
chore: improve writing in comments test: improve variable names test: remove "_initMerkleTree"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM, let's just add the explanatory comment mentioned below
I see that you want to remove the |
I insist on keeping those declarations in the I've also noticed that the constructor was defined in the middle of the contract, and so I've moved it to the top. I think it's looking good now! |
well, in case of |
Yes, but they are treated as immutables. Let's keep the code like this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
* refactor: double hash the leaf in claim function * test: add binarySearch function in MerkleBuilder test: add sort function in Merkle Builder test: sort tree leaves in MerkleStreamer tests * test: update Precompiles bytecode * test: use solady to sort merkle tree * test: uppercase constants chore: improve writing in comments test: improve variable names test: remove "_initMerkleTree" * test: add comment explaining why the Merkle tree leaves are sorted * test: reorder functions in Defaults --------- Co-authored-by: Paul Razvan Berg <[email protected]>
Closes #204 and #205