arkworks-rs / crypto-primitives

Interfaces and implementations of cryptographic primitives, along with R1CS constraints for them
https://www.arkworks.rs
Apache License 2.0
165 stars 79 forks source link

Add `.leaves()` to `MerkleTree` #144

Open WizardOfMenlo opened 3 months ago

WizardOfMenlo commented 3 months ago

As per title. When constructing a Merkle tree we pass in &[LeafType] which is then cloned and stored in the struct, never to be accessed again (it is used internally to generate proofs and multiproofs). Often, when you want to generate a proof you also want to send along the Leaf associated to it, and currently there is no easy way to do this (other than carrying the full leaves around, effectively doubling your mem consumption).

See, for example, https://github.com/WizardOfMenlo/stir/blob/2e95b1a6b42a827508d7d8d9e14a48e4af375380/src/stir/prover.rs#L23 and https://github.com/WizardOfMenlo/stir/blob/2e95b1a6b42a827508d7d8d9e14a48e4af375380/src/stir/prover.rs#L150