Skip to content

Commit e2c4a65

Browse files
committed
use emptypod vd_mt_proofs (using vd_set as circuit input), merge the two existing set_targets methods of MainPodVerifyTarget
1 parent 3bbb4b8 commit e2c4a65

File tree

5 files changed

+64
-66
lines changed

5 files changed

+64
-66
lines changed

src/backends/plonky2/circuits/mainpod.rs

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use plonky2::{
1717

1818
use crate::{
1919
backends::plonky2::{
20-
basetypes::CircuitBuilder,
20+
basetypes::{CircuitBuilder, VDSet},
2121
circuits::{
2222
common::{
2323
CircuitBuilderPod, CustomPredicateBatchTarget, CustomPredicateEntryTarget,
@@ -28,7 +28,7 @@ use crate::{
2828
},
2929
signedpod::{SignedPodVerifyGadget, SignedPodVerifyTarget},
3030
},
31-
emptypod::EmptyPod,
31+
emptypod::{EmptyPod, STANDARD_EMPTY_POD_DATA},
3232
error::Result,
3333
mainpod::{self, pad_statement},
3434
primitives::merkletree::{
@@ -39,10 +39,9 @@ use crate::{
3939
},
4040
measure_gates_begin, measure_gates_end,
4141
middleware::{
42-
AnchoredKey, CustomPredicate, CustomPredicateBatch, CustomPredicateRef, Hash,
43-
NativeOperation, NativePredicate, Params, PodType, PredicatePrefix, Statement,
44-
StatementArg, ToFields, Value, WildcardValue, EMPTY_VALUE, F, HASH_SIZE, KEY_TYPE, SELF,
45-
VALUE_SIZE,
42+
AnchoredKey, CustomPredicate, CustomPredicateBatch, CustomPredicateRef, NativeOperation,
43+
NativePredicate, Params, PodType, PredicatePrefix, Statement, StatementArg, ToFields,
44+
Value, WildcardValue, EMPTY_VALUE, F, HASH_SIZE, KEY_TYPE, SELF, VALUE_SIZE,
4645
},
4746
};
4847

@@ -1368,7 +1367,10 @@ pub struct CustomPredicateVerification {
13681367
}
13691368

13701369
pub struct MainPodVerifyInput {
1371-
pub vds_root: Hash,
1370+
pub vds_set: VDSet,
1371+
// field containing the `vd_mt_proofs` aside from the `vds_set`, because
1372+
// inide the MainPodVerifyTarget circuit, since it is the InnerCircuit for
1373+
// the RecursiveCircuit, we don't have access to the used verifier_datas.
13721374
pub vd_mt_proofs: Vec<MerkleClaimAndProof>,
13731375
pub signed_pods: Vec<SignedPod>,
13741376
pub recursive_pods_pub_self_statements: Vec<Vec<Statement>>,
@@ -1403,19 +1405,57 @@ fn set_targets_input_pods_self_statements(
14031405
Ok(())
14041406
}
14051407

1406-
impl MainPodVerifyTarget {
1407-
pub fn set_targets(
1408+
pub struct MainPodVerifyCircuit {
1409+
pub params: Params,
1410+
}
1411+
1412+
// TODO: Remove this type and implement it's logic directly in `impl InnerCircuit for MainPodVerifyTarget`
1413+
impl MainPodVerifyCircuit {
1414+
pub fn eval(
14081415
&self,
1409-
pw: &mut PartialWitness<F>,
1410-
input: &MainPodVerifyInput,
1411-
) -> Result<()> {
1412-
pw.set_target_arr(&self.vds_root.elements, &input.vds_root.0)?;
1416+
builder: &mut CircuitBuilder,
1417+
verified_proofs: &[VerifiedProofTarget],
1418+
) -> Result<MainPodVerifyTarget> {
1419+
let main_pod = MainPodVerifyGadget {
1420+
params: self.params.clone(),
1421+
}
1422+
.eval(builder, verified_proofs)?;
1423+
builder.register_public_inputs(&main_pod.id.elements);
1424+
builder.register_public_inputs(&main_pod.vds_root.elements);
1425+
Ok(main_pod)
1426+
}
1427+
}
1428+
1429+
impl InnerCircuit for MainPodVerifyTarget {
1430+
type Input = MainPodVerifyInput;
1431+
type Params = Params;
1432+
1433+
fn build(
1434+
builder: &mut CircuitBuilder,
1435+
params: &Self::Params,
1436+
verified_proofs: &[VerifiedProofTarget],
1437+
) -> Result<Self> {
1438+
MainPodVerifyCircuit {
1439+
params: params.clone(),
1440+
}
1441+
.eval(builder, verified_proofs)
1442+
}
1443+
1444+
/// assigns the values to the targets
1445+
fn set_targets(&self, pw: &mut PartialWitness<F>, input: &Self::Input) -> Result<()> {
1446+
let vds_root = input.vds_set.root();
1447+
pw.set_target_arr(&self.vds_root.elements, &vds_root.0)?;
14131448

14141449
for (i, vd_mt_proof) in input.vd_mt_proofs.iter().enumerate() {
14151450
self.vd_mt_proofs[i].set_targets(pw, true, vd_mt_proof)?;
14161451
}
1452+
// the rest of vd_mt_proofs set them to the empty_pod vd_mt_proof
1453+
let vd_emptypod_mt_proof = input
1454+
.vds_set
1455+
.get_vds_proofs(&[STANDARD_EMPTY_POD_DATA.1.verifier_only.clone()])?;
1456+
let vd_emptypod_mt_proof = vd_emptypod_mt_proof[0].clone();
14171457
for i in input.vd_mt_proofs.len()..self.vd_mt_proofs.len() {
1418-
self.vd_mt_proofs[i].set_targets(pw, false, &input.vd_mt_proofs[i])?;
1458+
self.vd_mt_proofs[i].set_targets(pw, true, &vd_emptypod_mt_proof)?;
14191459
}
14201460

14211461
assert!(input.signed_pods.len() <= self.params.max_input_signed_pods);
@@ -1446,7 +1486,7 @@ impl MainPodVerifyTarget {
14461486
}
14471487
// Padding
14481488
if input.recursive_pods_pub_self_statements.len() != self.params.max_input_recursive_pods {
1449-
let empty_pod = EmptyPod::new_boxed(&self.params, input.vds_root);
1489+
let empty_pod = EmptyPod::new_boxed(&self.params, input.vds_set.root());
14501490
let empty_pod_statements = empty_pod.pub_statements();
14511491
for i in
14521492
input.recursive_pods_pub_self_statements.len()..self.params.max_input_recursive_pods
@@ -1519,48 +1559,6 @@ impl MainPodVerifyTarget {
15191559
}
15201560
}
15211561

1522-
pub struct MainPodVerifyCircuit {
1523-
pub params: Params,
1524-
}
1525-
1526-
// TODO: Remove this type and implement it's logic directly in `impl InnerCircuit for MainPodVerifyTarget`
1527-
impl MainPodVerifyCircuit {
1528-
pub fn eval(
1529-
&self,
1530-
builder: &mut CircuitBuilder,
1531-
verified_proofs: &[VerifiedProofTarget],
1532-
) -> Result<MainPodVerifyTarget> {
1533-
let main_pod = MainPodVerifyGadget {
1534-
params: self.params.clone(),
1535-
}
1536-
.eval(builder, verified_proofs)?;
1537-
builder.register_public_inputs(&main_pod.id.elements);
1538-
builder.register_public_inputs(&main_pod.vds_root.elements);
1539-
Ok(main_pod)
1540-
}
1541-
}
1542-
1543-
impl InnerCircuit for MainPodVerifyTarget {
1544-
type Input = MainPodVerifyInput;
1545-
type Params = Params;
1546-
1547-
fn build(
1548-
builder: &mut CircuitBuilder,
1549-
params: &Self::Params,
1550-
verified_proofs: &[VerifiedProofTarget],
1551-
) -> Result<Self> {
1552-
MainPodVerifyCircuit {
1553-
params: params.clone(),
1554-
}
1555-
.eval(builder, verified_proofs)
1556-
}
1557-
1558-
/// assigns the values to the targets
1559-
fn set_targets(&self, pw: &mut PartialWitness<F>, input: &Self::Input) -> Result<()> {
1560-
self.set_targets(pw, input)
1561-
}
1562-
}
1563-
15641562
#[cfg(test)]
15651563
mod tests {
15661564
use std::{iter, ops::Not};

src/backends/plonky2/mainpod/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ pub(crate) fn layout_statements(
283283
// We mocking or we don't need padding so we skip creating an EmptyPod
284284
MockEmptyPod::new_boxed(params)
285285
} else {
286-
EmptyPod::new_boxed(params, inputs.vds_root)
286+
EmptyPod::new_boxed(params, inputs.vds_set.root())
287287
};
288288
let empty_pod = empty_pod_box.as_ref();
289289
assert!(inputs.recursive_pods.len() <= params.max_input_recursive_pods);
@@ -445,7 +445,7 @@ impl Prover {
445445
// We don't need padding so we skip creating an EmptyPod
446446
MockEmptyPod::new_boxed(params)
447447
} else {
448-
EmptyPod::new_boxed(params, inputs.vds_root)
448+
EmptyPod::new_boxed(params, inputs.vds_set.root())
449449
};
450450
let inputs = MainPodInputs {
451451
recursive_pods: &inputs
@@ -492,10 +492,10 @@ impl Prover {
492492
.recursive_pods
493493
.iter()
494494
.map(|pod| {
495-
assert_eq!(inputs.vds_root, pod.vds_root());
495+
assert_eq!(inputs.vds_set.root(), pod.vds_root());
496496
ProofWithPublicInputs {
497497
proof: pod.proof(),
498-
public_inputs: [pod.id().0 .0, inputs.vds_root.0].concat(),
498+
public_inputs: [pod.id().0 .0, inputs.vds_set.root().0].concat(),
499499
}
500500
})
501501
.collect_vec();
@@ -508,7 +508,7 @@ impl Prover {
508508
let vd_mt_proofs = vd_set.get_vds_proofs(&verifier_datas)?;
509509

510510
let input = MainPodVerifyInput {
511-
vds_root: inputs.vds_root,
511+
vds_set: inputs.vds_set.clone(),
512512
vd_mt_proofs,
513513
signed_pods: signed_pods_input,
514514
recursive_pods_pub_self_statements,
@@ -523,7 +523,7 @@ impl Prover {
523523
Ok(MainPod {
524524
params: params.clone(),
525525
id,
526-
vds_root: inputs.vds_root,
526+
vds_root: inputs.vds_set.root(),
527527
public_statements,
528528
proof: proof_with_pis.proof,
529529
})

src/backends/plonky2/mock/mainpod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl MockMainPod {
177177
Ok(Self {
178178
params: params.clone(),
179179
id,
180-
vds_root: inputs.vds_root,
180+
vds_root: inputs.vds_set.root(),
181181
// input_signed_pods,
182182
// input_main_pods,
183183
// input_statements,

src/frontend/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ impl MainPodBuilder {
564564
statements: &statements,
565565
operations: &operations,
566566
public_statements: &public_statements,
567-
vds_root: self.vd_set.root(),
567+
vds_set: self.vd_set.clone(),
568568
};
569569
let pod = prover.prove(&self.params, &self.vd_set, inputs)?;
570570

src/middleware/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ pub struct MainPodInputs<'a> {
846846
/// Statements that need to be made public (they can come from input pods or input
847847
/// statements)
848848
pub public_statements: &'a [Statement],
849-
pub vds_root: Hash, // TODO: Figure out if we use Hash or a Map here https://github.com/0xPARC/pod2/issues/249
849+
pub vds_set: VDSet,
850850
}
851851

852852
pub trait PodProver {

0 commit comments

Comments
 (0)