@@ -17,7 +17,7 @@ use plonky2::{
1717
1818use 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
13701369pub 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) ]
15651563mod tests {
15661564 use std:: { iter, ops:: Not } ;
0 commit comments