-
Notifications
You must be signed in to change notification settings - Fork 119
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
Ergonomic MerkleTreeGadget
#158
Conversation
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 with @tessico's choice of accepting Var
instead of the original struct.
- I wonder if we should name
rescue_merkle_tree.rs
asappend_only.rs
for consistency with their non-circuit implementations?
pub struct LeafVar { | ||
/// Position of the leaf element in the MT. Serves as UID. | ||
pub uid: Variable, | ||
/// The value of the leaf element. | ||
pub elem: Variable, | ||
} | ||
|
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.
Do you think we should make this an associated type of trait MerkleTreeGadget
instead, just like MerklePathVar
?
The main rationale being that some MT's leaf (e.g. SMT) doesn't have to care about or even have uid
. So it may suggest leaving the concrete instantiation to specific gadgets.
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.
on this note, I noticed our current RescueSMT
's digest_leaf
is actually hashing [0, pos, elem]
, which I guess doesn't hurt, but when we treat it as a set (as we do when using SMT), we don't need that pos
, no? @mrain
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.
No. In case of set, elem
is of type ()
. Information is stored in pos
actually.
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.
oh, right!
my original comment on making it an associated type might still be worth considering.
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.
Yes, good suggestion. Done in 7288912.
Yes, but after #142 lands. Currently the Rescue hash is "hardcoded" in the gadget implementation, so I think for now we should keep the name as is. |
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.
LGTM!
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.
LGTM
Description
closes: ##88
as well as some indirect progress towards #142.
Note that non membership proofs are out of scope of this PR, but we can still close the referenced issue #88, if approved, since we already have a separate issue for non-membership proof constraints: #99.
Regarding the design, the initial refactor I had started doing was based on the API proposed by @alxiong in #88 - thanks a lot for this! You will see that it has changed in that methods don't accept native field elements/structs, but rather variables representing these items in the circuit. This was done for two reasons:
create_<>_variable -> Result<SomeVariable, ()>
and then usingSomeVariable
in enforcing constraints. I feel that this is a clean abstraction, and we should probably stick to not enforcing constraints "directly" from native items.Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Pending
section inCHANGELOG.md
Files changed
in the GitHub PR explorer