mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-05-20 16:59:44 +00:00
Merge pull request #7 from mir-protocol/merkle_proofs
Candidate API for Merkle proof data
This commit is contained in:
commit
1ab12c3dfd
39
src/gadgets/merkle_proofs.rs
Normal file
39
src/gadgets/merkle_proofs.rs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
use crate::circuit_builder::CircuitBuilder;
|
||||||
|
use crate::field::field::Field;
|
||||||
|
use crate::proof::{Hash, HashTarget};
|
||||||
|
use crate::target::Target;
|
||||||
|
|
||||||
|
pub struct MerkleProof<F: Field> {
|
||||||
|
/// The Merkle digest of each sibling subtree, staying from the bottommost layer.
|
||||||
|
pub siblings: Vec<Hash<F>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct MerkleProofTarget {
|
||||||
|
/// The Merkle digest of each sibling subtree, staying from the bottommost layer.
|
||||||
|
pub siblings: Vec<HashTarget>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Verifies that the given leaf data is present at the given index in the Merkle tree with the
|
||||||
|
/// given root.
|
||||||
|
pub(crate) fn verify_merkle_proof<F: Field>(
|
||||||
|
leaf_data: Vec<F>,
|
||||||
|
leaf_index: usize,
|
||||||
|
merkle_root: Hash<F>,
|
||||||
|
proof: MerkleProof<F>,
|
||||||
|
) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<F: Field> CircuitBuilder<F> {
|
||||||
|
/// Verifies that the given leaf data is present at the given index in the Merkle tree with the
|
||||||
|
/// given root.
|
||||||
|
pub(crate) fn verify_merkle_proof(
|
||||||
|
&mut self,
|
||||||
|
leaf_data: Vec<Target>,
|
||||||
|
leaf_index: Target,
|
||||||
|
merkle_root: HashTarget,
|
||||||
|
proof: MerkleProofTarget,
|
||||||
|
) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
pub(crate) mod arithmetic;
|
pub(crate) mod arithmetic;
|
||||||
pub(crate) mod split_join;
|
|
||||||
pub(crate) mod hash;
|
pub(crate) mod hash;
|
||||||
|
pub(crate) mod merkle_proofs;
|
||||||
|
pub(crate) mod split_join;
|
||||||
|
|||||||
25
src/proof.rs
25
src/proof.rs
@ -1,5 +1,6 @@
|
|||||||
use crate::field::field::Field;
|
use crate::field::field::Field;
|
||||||
use crate::target::Target;
|
use crate::target::Target;
|
||||||
|
use crate::gadgets::merkle_proofs::{MerkleProofTarget, MerkleProof};
|
||||||
|
|
||||||
/// Represents a ~256 bit hash output.
|
/// Represents a ~256 bit hash output.
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
@ -32,7 +33,8 @@ pub struct Proof<F: Field> {
|
|||||||
/// Purported values of each polynomial at each challenge point.
|
/// Purported values of each polynomial at each challenge point.
|
||||||
pub openings: Vec<OpeningSet<F>>,
|
pub openings: Vec<OpeningSet<F>>,
|
||||||
|
|
||||||
// TODO: FRI Merkle proofs.
|
/// A FRI argument for each FRI query.
|
||||||
|
pub fri_proofs: Vec<FriProof<F>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ProofTarget {
|
pub struct ProofTarget {
|
||||||
@ -50,22 +52,29 @@ pub struct ProofTarget {
|
|||||||
pub fri_proofs: Vec<FriProofTarget>,
|
pub fri_proofs: Vec<FriProofTarget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct FriProof<F: Field> {
|
||||||
|
/// A Merkle root for each reduced polynomial in the commit phase.
|
||||||
|
pub commit_phase_merkle_roots: Vec<Hash<F>>,
|
||||||
|
/// Merkle proofs for the original purported codewords, i.e. the subject of the LDT.
|
||||||
|
pub initial_merkle_proofs: Vec<MerkleProof<F>>,
|
||||||
|
/// Merkle proofs for the reduced polynomials that were sent in the commit phase.
|
||||||
|
pub intermediate_merkle_proofs: Vec<MerkleProof<F>>,
|
||||||
|
/// The final polynomial in coefficient form.
|
||||||
|
pub final_poly: Vec<F>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents a single FRI query, i.e. a path through the reduction tree.
|
/// Represents a single FRI query, i.e. a path through the reduction tree.
|
||||||
pub struct FriProofTarget {
|
pub struct FriProofTarget {
|
||||||
|
/// A Merkle root for each reduced polynomial in the commit phase.
|
||||||
|
pub commit_phase_merkle_roots: Vec<HashTarget>,
|
||||||
/// Merkle proofs for the original purported codewords, i.e. the subject of the LDT.
|
/// Merkle proofs for the original purported codewords, i.e. the subject of the LDT.
|
||||||
pub initial_merkle_proofs: Vec<MerkleProofTarget>,
|
pub initial_merkle_proofs: Vec<MerkleProofTarget>,
|
||||||
/// Merkle proofs for the reduced polynomials that were sent in the commit phase.
|
/// Merkle proofs for the reduced polynomials that were sent in the commit phase.
|
||||||
pub intermediate_merkle_proofs: Vec<MerkleProofTarget>,
|
pub intermediate_merkle_proofs: Vec<MerkleProofTarget>,
|
||||||
/// The final polynomial in point-value form.
|
/// The final polynomial in coefficient form.
|
||||||
pub final_poly: Vec<Target>,
|
pub final_poly: Vec<Target>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MerkleProofTarget {
|
|
||||||
pub leaf: Vec<Target>,
|
|
||||||
pub siblings: Vec<Target>,
|
|
||||||
// TODO: Also need left/right turn info.
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The purported values of each polynomial at a single point.
|
/// The purported values of each polynomial at a single point.
|
||||||
pub struct OpeningSet<F: Field> {
|
pub struct OpeningSet<F: Field> {
|
||||||
pub constants: Vec<F>,
|
pub constants: Vec<F>,
|
||||||
|
|||||||
@ -111,6 +111,8 @@ pub(crate) fn prove<F: Field>(
|
|||||||
|
|
||||||
let openings = Vec::new(); // TODO
|
let openings = Vec::new(); // TODO
|
||||||
|
|
||||||
|
let fri_proofs = Vec::new(); // TODO
|
||||||
|
|
||||||
info!("{:.3}s for overall witness & proof generation",
|
info!("{:.3}s for overall witness & proof generation",
|
||||||
start_proof_gen.elapsed().as_secs_f32());
|
start_proof_gen.elapsed().as_secs_f32());
|
||||||
|
|
||||||
@ -119,6 +121,7 @@ pub(crate) fn prove<F: Field>(
|
|||||||
plonk_zs_root,
|
plonk_zs_root,
|
||||||
quotient_polys_root,
|
quotient_polys_root,
|
||||||
openings,
|
openings,
|
||||||
|
fri_proofs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user