Abstract away Merkle trees with VectorCommitment scheme
irakliyk opened this issue · comments
We currently make a hard assumption that for vector commitments (i.e., trace LDE commitment, constraint evaluation commitment, FRI layer commitments etc.) Merkle trees are used. It would be nice to abstract this assumption away and provide a way for the user to specify which vector commitment type to use.
This would help with such things as #38 and also would make #9 simpler as we could provide SaltedMerkleTree
as one of the vector commitment types.
To make vector commitments fully generic, we could use something like this:
pub trait VectorCommitment: Sized {
type Options;
type Item: Clone + Serializable + Deserializable;
type Commitment: Copy + Serializable + Deserializable;
type Proof: Clone + Serializable + Deserializable;
type MultiProof: Clone + Serializable + Deserializable;
type Error: Debug;
fn new(items: Vec<Self::Item>, options: Self::Options) -> Result<Self, Self::Error>;
fn commitment(&self) -> Self::Commitment;
fn open(&self, index: usize) -> Result<(Self::Item, Self::Proof), Self::Error>;
fn open_many(&self, indexes: &[usize]) -> Result<(Vec<Self::Item>, Self::MultiProof), Self::Error>;
fn verify(
commitment: Self::Commitment,
index: usize,
item: Self::Item,
proof: &Self::Proof
) -> Result<(), Self::Error>;
fn verify_many(
commitment: Self::Commitment,
indexes: &[usize],
items: &[Self::Item],
proof: &Self::MultiProof
) -> Result<(), Self::Error>;
}
The first step for implementing this is probably to update our current MerkleTree
implementation to comply with this interface.