-
Notifications
You must be signed in to change notification settings - Fork 45
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
Introduce SmtProof
#270
Introduce SmtProof
#270
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.
Thank you! Looks good! I left some comments inline - most are pretty small.
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! Thank you! I left some more comment inline. Most are nits, but there is one about leaf serialization which I think might have a bug.
|
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.
All looks good! Thank you! I think merging this shouldn't cause any issues downstream as changes to SimpleSmt
are non-breaking, right?
Also, I left one comment for further discussion. Let's create an issue for it.
/// Returns the number of entries stored in the leaf | ||
pub fn num_entries(&self) -> u64 { | ||
match self { | ||
SmtLeaf::Empty(_) => 0, | ||
SmtLeaf::Single(_) => 1, | ||
SmtLeaf::Multiple(entries) => { | ||
entries.len().try_into().expect("shouldn't have more than 2^64 entries") | ||
} | ||
} | ||
} |
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.
Realistically, it is unlikely that the number of entries in a leaf would be more than
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.
* add conversion for `SmtLeaf` * introduce `SmtProof` scaffolding * implement `verify_membership()` * SmtLeaf: knows its index * `SmtLeaf::index` * `SmtLeaf::get_value()` returns an Option * fix `verify_membership()` * impl `SmtProof::get` * impl `into_parts()` * `SmtProof::compute_root` * use `SmtProof` in `Smt::open` * `SmtLeaf` constructors * Vec * impl `Error` for `SmtLeafError` * fix std Error * move Word/Digest conversions to LeafIndex * `SmtProof::new()` returns an error * `SparseMerkleTree::path_and_leaf_to_opening` * `SmtLeaf`: serializable/deserializable * `SmtProof`: serializable/deserializable * add tests for SmtLeaf serialization * move `SmtLeaf` to submodule * use constructors internally * fix docs * Add `Vec` * add `Vec` to tests * no_std use statements * fmt * `Errors`: make heading * use `SMT_DEPTH` * SmtLeaf single case: check leaf index * Multiple case: check consistency with leaf index * use `pub(super)` instead of `pub(crate)` * use `pub(super)` * `SmtLeaf`: add `num_entries()` accessor * Fix `SmtLeaf` serialization * improve leaf serialization tests
Closes #251
This PR required a change in
SmtLeaf
. Specifically, forSmtProof::get(key)
to know if it contains a value forkey
,SmtLeaf
needs to know its index in theSmt
.This means that constructing a leaf from entries (
Vec<RpoDigest, Word>
) is no longer possible, because in the case where no entries are provided (leading to an empty leaf), we have no way to know the leaf index. This lead to adding multiple constructors (which some are able to constructor anSmtLeaf
without error).Also note that
SmtProof::new()
doesn't return an error (contrary toTieredSmtProof
). This is because the only possible error would be ifMerklePath
doesn't have length 64. However,SparseMerkleTree::Opening
requiresFrom<(MerklePath, SmtLeaf)>
- that is, we already have the assumption there that theMerklePath
is of proper length. I kept that assumption inSmtProof
. We could potentially add adebug_assert
, orexpect()
it away inopen()
, as is done withTieredSmtProof
.This change would also impact the
node
'sNullifierProof
: it would need to be changed to also include theleaf_index
. However, I don't see a way around it, unless I'm missing something.