-
Notifications
You must be signed in to change notification settings - Fork 358
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
Add merkle proof module #1101
Add merkle proof module #1101
Conversation
…eat/merkle-proof-verifier-#936
// Check proof validity. | ||
if (leaves_len + proof.len() != proof_flags_len + 1) { | ||
panic!("MerkleProof: invalid multi proof"); | ||
} |
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.
It looks like a perfect case to use assert_eq
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.
Sadly assert_eq
only works on tests.
We can use this for testing (generating trees and proofs) https://github.com/ericnordelo/strk-merkle-tree |
…eat/merkle-proof-verifier-#936
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.
Very nice PR, Eric! The code and tests look great. I left some questions and feedback mostly on docs and comments
|
||
/// These functions deal with verification of Merkle Tree proofs. | ||
/// | ||
/// WARNING: You should avoid using leaf values that are 62 bytes long prior to |
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.
Should the recommendation be to avoid leaf values that are 63 bytes long (31.5 * 2) or can we confirm this may apply to 62 bytes?
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.
What about two felt252 long?
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.
"two felt252 long" works! TBH I think specifying the bytes length offers more precision, but I'm okay with how it is now
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
…elo/cairo-contracts into feat/merkle-proof-verifier-#936
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 left a few final suggestions, but LGTM!
packages/merkle_tree/src/tests/merkle_proof/test_with_poseidon.cairo
Outdated
Show resolved
Hide resolved
packages/merkle_tree/src/tests/merkle_proof/test_with_poseidon.cairo
Outdated
Show resolved
Hide resolved
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
….cairo Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
….cairo Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
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.
Great job on the module, Eric! Everything's looking good, I left several minor comments
let proof = [ | ||
0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, | ||
0x05fb6a626bb2c1e12fc2d6fa7f218ec06928ba5febf4d5677c2c5060827e383b | ||
].span(); |
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.
The same root and proof values are used in almost all the test cases. Should we consider them constants and place them in the common
module alongside with LEAVES
?
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 agree, but common
module is for things that are common among different modules. This can be defined as local test constants.
let proof = [ | ||
0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, | ||
0x05fb6a626bb2c1e12fc2d6fa7f218ec06928ba5febf4d5677c2c5060827e383b | ||
].span(); |
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.
Same thing here, moving Poseidon root
and proof
values to common
would help avoid code repetition
Co-authored-by: immrsd <103599616+immrsd@users.noreply.github.com>
Co-authored-by: immrsd <103599616+immrsd@users.noreply.github.com>
…elo/cairo-contracts into feat/merkle-proof-verifier-#936
Fixes #936