Skip to content

Commit 8a81dde

Browse files
Nashtarewborgeaudeinar-polygon
authored
Add necessary 2-to-1 aggreg. components for proof_gen (#364)
* Two to one aggregation * Comments * Two-to-one block aggregation proof * Minor * Minor * feat: Implement two-to-one Block Aggregation WIP: compute hashes directly from witness and check against public inputs WIP: add TwoToOneBlockAggCircuitData WIP: add test WIP: rewrite to use hasher circuitry WIP: test: can generate proofs of unrelated blocks WIP: test/refactor: generate multiple blocks WIP: test/refactor: autoformat WIP: refactor: use result iterator WIP: convert PIS WIP: feat: witness: set public input hashes WIP: feat: cache proofs in /tmp WIP: config: default to no cache WIP: bug: cache write-read assertion fails WIP: bug: prepare for more eyeballs WIP: bug: work on to_public_inputs WIP feat: private public inputs WIP feat: set pv targets WIP experiment: public input WIP refactor: clean up WIP feat: 1-level aggregation working WIP forgot: private public inputs WIP: use agg child structure WIP: split into IVC and binop WIP: split part2 into IVC and binop WIP: split part3 into IVC and binop WIP: ivc structure done WIP: wip wip WIP: ivc+binop WIP: after talking to Linda WIP: adjust num_public_inputs WIP: VirtualTarget index: 5 was set twice feat: assert on input values length experiment: minimize failing circuit feat: add selector for public values WIP: bug: add methods from branch `no_dummy_segment_no_pis` WIP: bug: first draft feat: verify 4-block aggregation test: add more tests * cleanup(tests) * cleanup(tests): obey Clippy * cleanup: remove unneeded experiment * cleanup: remove vector to public inputs * cleanup: remove IVC and re-add two_to_one_block * cleanup: fix de/serialization * cleanup: add comments * cleanup: remove checks * cleanup: remove unrelated change * cleanup: remove unused parameter and todo * feat: enable caching as default * cleanup: remove previous block aggregation implementation * refactor: simplify naming * refactor: improve naming * cleanup: remove custom build config * cleanup: undo this change * cleanup: obey Clippy * cleanup: remove two-to-one aggregation * review: resolve small issues * fixup! cleanup: remove two-to-one aggregation * review: make order consistent * fixup! review: make order consistent * review: merge aggregation children * review: rename `evm_proof` to `base_proof` * review: squash tests * review: investigate padding length * review: investigate padding length part 2 * review: remove magic numbers * review: remove HasCircuit trait and pass in CircuitData field directly * review: rework `set_dummy_if_necessary` * review: remove logging in test * review: remove legacy test * review: remove all `debug_assert!` * review: obey Clippy and fmt * review: impl Merklet tree test * WIP review: fix hashing mechanism and make hash public input * review: remove VK from inputs * review: test Merkle tree working * review: refactor: remove scaffolding * review: fix ascii art * review: clippy * review: remove logging * review: fmt * review: remove redundant computations * fmt * review: implement feedback from Hamy * fmt * Add necessary methods for proof_gen * Update comment * Fix comment --------- Co-authored-by: wborgeaud <williamborgeaud@gmail.com> Co-authored-by: Einar Rasmussen <erasmussen@polygon.technology>
1 parent 5da11bd commit 8a81dde

File tree

3 files changed

+98
-4
lines changed

3 files changed

+98
-4
lines changed

proof_gen/src/proof_gen.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use plonky2::{
1212
};
1313

1414
use crate::{
15-
proof_types::{AggregatableProof, GeneratedAggProof, GeneratedBlockProof, GeneratedTxnProof},
15+
proof_types::{
16+
AggregatableBlockProof, AggregatableProof, GeneratedAggBlockProof, GeneratedAggProof,
17+
GeneratedBlockProof, GeneratedTxnProof,
18+
},
1619
prover_state::ProverState,
1720
types::{Config, Field, PlonkyProofIntern, EXTENSION_DEGREE},
1821
};
@@ -114,6 +117,27 @@ pub fn generate_block_proof(
114117
})
115118
}
116119

120+
/// Generates an aggregation block proof from two child proofs.
121+
///
122+
/// Note that the child proofs may be either block or aggregation proofs.
123+
pub fn generate_agg_block_proof(
124+
p_state: &ProverState,
125+
lhs_child: &AggregatableBlockProof,
126+
rhs_child: &AggregatableBlockProof,
127+
) -> ProofGenResult<GeneratedAggBlockProof> {
128+
let intern = p_state
129+
.state
130+
.prove_two_to_one_block(
131+
lhs_child.intern(),
132+
lhs_child.is_agg(),
133+
rhs_child.intern(),
134+
rhs_child.is_agg(),
135+
)
136+
.map_err(|err| err.to_string())?;
137+
138+
Ok(GeneratedAggBlockProof { intern })
139+
}
140+
117141
/// Generates a dummy proof for a dummy circuit doing nothing.
118142
/// This is useful for testing purposes only.
119143
pub fn dummy_proof() -> ProofGenResult<PlonkyProofIntern> {

proof_gen/src/proof_types.rs

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
//! This module defines the various proof types used throughout the block proof
22
//! generation process.
33
4-
use evm_arithmetization::{proof::PublicValues, BlockHeight};
4+
use evm_arithmetization::{
5+
fixed_recursive_verifier::{extract_block_public_values, extract_two_to_one_block_hash},
6+
proof::PublicValues,
7+
BlockHeight,
8+
};
9+
use plonky2::plonk::config::Hasher as _;
510
use serde::{Deserialize, Serialize};
611

7-
use crate::types::PlonkyProofIntern;
12+
use crate::types::{Hash, Hasher, PlonkyProofIntern};
813

914
/// A transaction proof along with its public values, for proper connection with
1015
/// contiguous proofs.
@@ -39,6 +44,17 @@ pub struct GeneratedBlockProof {
3944
pub intern: PlonkyProofIntern,
4045
}
4146

47+
/// An aggregation block proof along with its hashed public values, for proper
48+
/// connection with other proofs.
49+
///
50+
/// Aggregation block proofs can represent any aggregation of independent
51+
/// blocks.
52+
#[derive(Clone, Debug, Deserialize, Serialize)]
53+
pub struct GeneratedAggBlockProof {
54+
/// Underlying plonky2 proof.
55+
pub intern: PlonkyProofIntern,
56+
}
57+
4258
/// Sometimes we don't care about the underlying proof type and instead only if
4359
/// we can combine it into an agg proof. For these cases, we want to abstract
4460
/// away whether or not the proof was a txn or agg proof.
@@ -84,3 +100,52 @@ impl From<GeneratedAggProof> for AggregatableProof {
84100
Self::Agg(v)
85101
}
86102
}
103+
104+
#[derive(Clone, Debug, Deserialize, Serialize)]
105+
pub enum AggregatableBlockProof {
106+
/// The underlying proof is a single block proof.
107+
Block(GeneratedBlockProof),
108+
/// The underlying proof is an aggregated proof.
109+
Agg(GeneratedAggBlockProof),
110+
}
111+
112+
impl AggregatableBlockProof {
113+
pub fn pv_hash(&self) -> Hash {
114+
match self {
115+
AggregatableBlockProof::Block(info) => {
116+
let pv = extract_block_public_values(&info.intern.public_inputs);
117+
Hasher::hash_no_pad(pv)
118+
}
119+
AggregatableBlockProof::Agg(info) => {
120+
let hash = extract_two_to_one_block_hash(&info.intern.public_inputs);
121+
Hash::from_partial(hash)
122+
}
123+
}
124+
}
125+
126+
pub(crate) const fn is_agg(&self) -> bool {
127+
match self {
128+
AggregatableBlockProof::Block(_) => false,
129+
AggregatableBlockProof::Agg(_) => true,
130+
}
131+
}
132+
133+
pub(crate) const fn intern(&self) -> &PlonkyProofIntern {
134+
match self {
135+
AggregatableBlockProof::Block(info) => &info.intern,
136+
AggregatableBlockProof::Agg(info) => &info.intern,
137+
}
138+
}
139+
}
140+
141+
impl From<GeneratedBlockProof> for AggregatableBlockProof {
142+
fn from(v: GeneratedBlockProof) -> Self {
143+
Self::Block(v)
144+
}
145+
}
146+
147+
impl From<GeneratedAggBlockProof> for AggregatableBlockProof {
148+
fn from(v: GeneratedAggBlockProof) -> Self {
149+
Self::Agg(v)
150+
}
151+
}

proof_gen/src/types.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
44
use plonky2::{
55
field::goldilocks_field::GoldilocksField,
6-
plonk::{config::PoseidonGoldilocksConfig, proof::ProofWithPublicInputs},
6+
hash::poseidon::PoseidonHash,
7+
plonk::{self, config::PoseidonGoldilocksConfig, proof::ProofWithPublicInputs},
78
};
89

910
/// The base field on which statements are being proven.
@@ -17,6 +18,10 @@ pub const EXTENSION_DEGREE: usize = 2;
1718
/// A type alias for proofs generated by the zkEVM.
1819
pub type PlonkyProofIntern = ProofWithPublicInputs<Field, Config, EXTENSION_DEGREE>;
1920

21+
pub type Hasher = PoseidonHash;
22+
23+
pub type Hash = <Hasher as plonk::config::Hasher<Field>>::Hash;
24+
2025
/// A type alias for the set of preprocessed circuits necessary to generate
2126
/// succinct block proofs.
2227
pub type AllRecursiveCircuits = evm_arithmetization::fixed_recursive_verifier::AllRecursiveCircuits<

0 commit comments

Comments
 (0)