-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an associated type DigestGadget to MerkleTreeGadget
- Loading branch information
Showing
2 changed files
with
46 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
//! Trait definitions for a Merkle tree gadget. | ||
use crate::merkle_tree::MerkleTreeScheme; | ||
use jf_relation::{errors::CircuitError, BoolVar, Variable}; | ||
use ark_ff::PrimeField; | ||
use jf_relation::{errors::CircuitError, BoolVar, PlonkCircuit, Variable}; | ||
|
||
mod rescue_merkle_tree; | ||
|
||
|
@@ -36,9 +37,10 @@ mod rescue_merkle_tree; | |
/// circuit.enforce_merkle_proof(leaf_var, path_vars, root_var).unwrap(); | ||
/// assert!(circuit.check_circuit_satisfiability(&[]).is_ok()); | ||
/// ``` | ||
pub trait MerkleTreeGadget<M> | ||
pub trait MerkleTreeGadget<M, F> | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tessico
Author
Contributor
|
||
where | ||
M: MerkleTreeScheme, | ||
F: PrimeField, | ||
{ | ||
/// Type to represent the leaf element of the concrete MT instantiation. | ||
type LeafVar; | ||
|
@@ -48,6 +50,9 @@ where | |
/// Merkle path. | ||
type MerklePathVar; | ||
|
||
/// Gadget for the digest algorithm. | ||
type DigestGadget: DigestAlgorithmGadget<F>; | ||
|
||
/// Allocate a variable for the leaf element. | ||
fn create_leaf_variable( | ||
&mut self, | ||
|
@@ -82,3 +87,19 @@ where | |
expected_merkle_root: Variable, | ||
) -> Result<(), CircuitError>; | ||
} | ||
|
||
/// Circuit counterpart to DigestAlgorithm | ||
pub trait DigestAlgorithmGadget<F> | ||
where | ||
F: PrimeField, | ||
{ | ||
/// Digest a list of variables | ||
fn digest(circuit: &mut PlonkCircuit<F>, data: &[Variable]) -> Result<Variable, CircuitError>; | ||
|
||
/// Digest an indexed element | ||
fn digest_leaf( | ||
circuit: &mut PlonkCircuit<F>, | ||
pos: usize, | ||
elem: Variable, | ||
) -> Result<Variable, CircuitError>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
should we further constrain:
M: MerkleTreeScheme<NodeValue = F>
?