Conversation
Since MerkleNode is a private type, users cannot pattern match to extract a MerkleNode::Leaf, so this is the only way to get the leaf elemenet of a Merkle proof. This is also, therefore, the only way to verify that a Merkle proof proves inclusion of the desired element, since `verify` doesn't check this. (Technically you can also use `remember`, but that includes side-effects that may be undesirable.)
The Merkle trees are ususally instantiated with cryptographic types, e.g. field elements, which do not implement serde traits. This commit changes the bound on the derived serde impls for Merkle tree types to require ark_serialize impls on the element types and uses #[serde(with)] to serialize these elements using ark_serialize. We also add an instantiation of the Rescue hash scheme for field elements as the _index_ type, since the BigUint instantiation just coverts to field elements anyways, but BigUint does not implement serde _or_ ark_serialize, while field elements do.
alxiong
left a comment
There was a problem hiding this comment.
I like the idea of requiring serde(bound=) to enforce the usage of CanonicalSerde during serialization.
but meanwhile, I'm not sure about #[serde(with = "field_elem")], what if the type is not a primitive types, and not a field elements from arkwork?
the benefit of using BigUint compared to F is its generality.
@jbearer what do you think of renaming mod field_elem to something like canoncial_serdeable (idk maybe there's better names? 🤷♂️ ) and the serializer takes in
elem: impl Into<T> where T: CanonicalSerize instead?
|
Yeah that's a good idea. Also totally agree with the benefit of |
Description
Was playing around with Jellyfish for a hobby project and ran into a couple of ergonomics issues in the Merkle tree API.
commit 699dea9
Author: Jeb Bearer jeb@espressosys.com
Date: Wed Dec 14 11:43:07 2022 -0800
commit bdbd5b1
Author: Jeb Bearer jeb@espressosys.com
Date: Wed Dec 14 10:18:37 2022 -0800
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.
Pendingsection inCHANGELOG.mdFiles changedin the GitHub PR explorer