@@ -12,7 +12,7 @@ use crate::middleware::{
1212 containers:: { Array , Dictionary , Set } ,
1313 hash_str, Hash , MainPodInputs , Params , PodId , PodProver , PodSigner , SELF ,
1414} ;
15- use crate :: middleware:: { hash_value, EMPTY_VALUE , KEY_SIGNER , KEY_TYPE } ;
15+ use crate :: middleware:: { hash_value, OperationAux , EMPTY_VALUE , KEY_SIGNER , KEY_TYPE } ;
1616
1717mod custom;
1818mod operation;
@@ -348,8 +348,6 @@ impl MainPodBuilder {
348348 ) ) ) ;
349349 st_args. push ( StatementArg :: Literal ( v. clone ( ) ) )
350350 }
351- // Merkle proofs are never arguments to statements.
352- OperationArg :: MerkleProof ( _) => ( ) ,
353351 } ;
354352 }
355353 Ok ( st_args)
@@ -365,7 +363,7 @@ impl MainPodBuilder {
365363
366364 fn op ( & mut self , public : bool , mut op : Operation ) -> Result < Statement , anyhow:: Error > {
367365 use NativeOperation :: * ;
368- let Operation ( op_type, ref mut args) = & mut op;
366+ let Operation ( op_type, ref mut args, _ ) = & mut op;
369367 // TODO: argument type checking
370368 let pred = op_type
371369 . output_predicate ( )
@@ -673,6 +671,7 @@ impl MainPodBuilder {
673671 Operation (
674672 OperationType :: Native ( NativeOperation :: NewEntry ) ,
675673 vec ! [ OperationArg :: Entry ( k. clone( ) , v) ] ,
674+ OperationAux :: None ,
676675 ) ,
677676 )
678677 }
@@ -820,12 +819,9 @@ impl MainPodCompiler {
820819 self . operations . push ( op) ;
821820 }
822821
823- fn compile_op_arg ( & self , op_arg : & OperationArg ) -> Option < middleware:: OperationArg > {
822+ fn compile_op_arg ( & self , op_arg : & OperationArg ) -> Option < middleware:: Statement > {
824823 match op_arg {
825- OperationArg :: Statement ( s) => self
826- . compile_st ( s)
827- . ok ( )
828- . map ( |s| middleware:: OperationArg :: Statement ( s) ) ,
824+ OperationArg :: Statement ( s) => self . compile_st ( s) . ok ( ) ,
829825 OperationArg :: Literal ( _v) => {
830826 // OperationArg::Literal is a syntax sugar for the frontend. This is translated to
831827 // a new ValueOf statement and it's key used instead.
@@ -837,9 +833,6 @@ impl MainPodCompiler {
837833 // statement doesn't have any requirement on the key and value.
838834 None
839835 }
840- OperationArg :: MerkleProof ( pf) => {
841- Some ( middleware:: OperationArg :: MerkleProof ( pf. clone ( ) ) )
842- }
843836 }
844837 }
845838
@@ -903,11 +896,11 @@ impl MainPodCompiler {
903896 _ => Err ( anyhow ! ( "Statement compile failed in manual compile" ) ) ?,
904897 } ,
905898 empty_st,
906- match & op. 1 [ 2 ] {
907- OperationArg :: MerkleProof ( mp) => mp. clone ( ) ,
899+ match & op. 2 {
900+ OperationAux :: MerkleProof ( mp) => mp. clone ( ) ,
908901 _ => {
909902 return Err ( anyhow ! (
910- "Third argument to DictContainsFromEntries must be Merkle proof"
903+ "Auxiliary argument to DictContainsFromEntries must be Merkle proof"
911904 ) ) ;
912905 }
913906 } ,
@@ -968,7 +961,7 @@ impl MainPodCompiler {
968961 op. 1 . iter ( )
969962 . flat_map ( |arg| self . compile_op_arg ( arg) . map ( |op_arg| Ok ( op_arg) ) )
970963 . collect :: < Result < Vec < _ > > > ( ) ?;
971- middleware:: Operation :: op ( mop_code, & mop_args)
964+ middleware:: Operation :: op ( mop_code, & mop_args, & op . 2 )
972965 }
973966
974967 fn compile_st_op ( & mut self , st : & Statement , op : & Operation , params : & Params ) -> Result < ( ) > {
@@ -1038,56 +1031,55 @@ pub mod build_utils {
10381031 macro_rules! op {
10391032 ( new_entry, ( $key: expr, $value: expr) ) => { $crate:: frontend:: Operation (
10401033 $crate:: frontend:: OperationType :: Native ( $crate:: frontend:: NativeOperation :: NewEntry ) ,
1041- $crate:: op_args!( ( $key, $value) ) ) } ;
1034+ $crate:: op_args!( ( $key, $value) ) , crate :: middleware :: OperationAux :: None ) } ;
10421035 ( eq, $( $arg: expr) ,+) => { $crate:: frontend:: Operation (
10431036 $crate:: frontend:: OperationType :: Native ( $crate:: frontend:: NativeOperation :: EqualFromEntries ) ,
1044- $crate:: op_args!( $( $arg) ,* ) ) } ;
1037+ $crate:: op_args!( $( $arg) ,* ) , crate :: middleware :: OperationAux :: None ) } ;
10451038 ( ne, $( $arg: expr) ,+) => { $crate:: frontend:: Operation (
10461039 $crate:: frontend:: OperationType :: Native ( $crate:: frontend:: NativeOperation :: NotEqualFromEntries ) ,
1047- $crate:: op_args!( $( $arg) ,* ) ) } ;
1040+ $crate:: op_args!( $( $arg) ,* ) , crate :: middleware :: OperationAux :: None ) } ;
10481041 ( gt, $( $arg: expr) ,+) => { crate :: frontend:: Operation (
10491042 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: GtFromEntries ) ,
1050- crate :: op_args!( $( $arg) ,* ) ) } ;
1043+ crate :: op_args!( $( $arg) ,* ) , crate :: middleware :: OperationAux :: None ) } ;
10511044 ( lt, $( $arg: expr) ,+) => { crate :: frontend:: Operation (
10521045 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: LtFromEntries ) ,
1053- crate :: op_args!( $( $arg) ,* ) ) } ;
1046+ crate :: op_args!( $( $arg) ,* ) , crate :: middleware :: OperationAux :: None ) } ;
10541047 ( transitive_eq, $( $arg: expr) ,+) => { crate :: frontend:: Operation (
10551048 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: TransitiveEqualFromStatements ) ,
1056- crate :: op_args!( $( $arg) ,* ) ) } ;
1049+ crate :: op_args!( $( $arg) ,* ) , crate :: middleware :: OperationAux :: None ) } ;
10571050 ( gt_to_ne, $( $arg: expr) ,+) => { crate :: frontend:: Operation (
10581051 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: GtToNotEqual ) ,
1059- crate :: op_args!( $( $arg) ,* ) ) } ;
1052+ crate :: op_args!( $( $arg) ,* ) , crate :: middleware :: OperationAux :: None ) } ;
10601053 ( lt_to_ne, $( $arg: expr) ,+) => { crate :: frontend:: Operation (
10611054 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: LtToNotEqual ) ,
1062- crate :: op_args!( $( $arg) ,* ) ) } ;
1055+ crate :: op_args!( $( $arg) ,* ) , crate :: middleware :: OperationAux :: None ) } ;
10631056 ( sum_of, $( $arg: expr) ,+) => { crate :: frontend:: Operation (
10641057 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: SumOf ) ,
1065- crate :: op_args!( $( $arg) ,* ) ) } ;
1058+ crate :: op_args!( $( $arg) ,* ) , crate :: middleware :: OperationAux :: None ) } ;
10661059 ( product_of, $( $arg: expr) ,+) => { crate :: frontend:: Operation (
10671060 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: ProductOf ) ,
1068- crate :: op_args!( $( $arg) ,* ) ) } ;
1061+ crate :: op_args!( $( $arg) ,* ) , crate :: middleware :: OperationAux :: None ) } ;
10691062 ( max_of, $( $arg: expr) ,+) => { crate :: frontend:: Operation (
10701063 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: MaxOf ) ,
1071- crate :: op_args!( $( $arg) ,* ) ) } ;
1064+ crate :: op_args!( $( $arg) ,* ) , crate :: middleware :: OperationAux :: None ) } ;
10721065 ( custom, $op: expr, $( $arg: expr) ,+) => { $crate:: frontend:: Operation (
10731066 $crate:: frontend:: OperationType :: Custom ( $op) ,
1074- $crate:: op_args!( $( $arg) ,* ) ) } ;
1075- ( dict_contains, $( $arg : expr) ,+ ) => { crate :: frontend:: Operation (
1067+ $crate:: op_args!( $( $arg) ,* ) , crate :: middleware :: OperationAux :: None ) } ;
1068+ ( dict_contains, $dict : expr , $key : expr, $value : expr , $aux : expr ) => { crate :: frontend:: Operation (
10761069 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: DictContainsFromEntries ) ,
1077- crate :: op_args!( $( $arg ) , * ) ) } ;
1078- ( dict_not_contains, $( $arg : expr) ,+ ) => { crate :: frontend:: Operation (
1070+ crate :: op_args!( $dict , $key , $value ) , crate :: middleware :: OperationAux :: MerkleProof ( $aux ) ) } ;
1071+ ( dict_not_contains, $dict : expr , $key : expr, $aux : expr ) => { crate :: frontend:: Operation (
10791072 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: DictNotContainsFromEntries ) ,
1080- crate :: op_args!( $( $arg ) , * ) ) } ;
1081- ( set_contains, $( $arg : expr) ,+ ) => { crate :: frontend:: Operation (
1073+ crate :: op_args!( $dict , $key ) , crate :: middleware :: OperationAux :: MerkleProof ( $aux ) ) } ;
1074+ ( set_contains, $set : expr , $value : expr, $aux : expr ) => { crate :: frontend:: Operation (
10821075 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: SetContainsFromEntries ) ,
1083- crate :: op_args!( $( $arg ) , * ) ) } ;
1084- ( set_not_contains, $( $arg : expr) ,+ ) => { crate :: frontend:: Operation (
1076+ crate :: op_args!( $set , $value ) , crate :: middleware :: OperationAux :: MerkleProof ( $aux ) ) } ;
1077+ ( set_not_contains, $set : expr , $value : expr, $aux : expr ) => { crate :: frontend:: Operation (
10851078 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: SetNotContainsFromEntries ) ,
1086- crate :: op_args!( $( $arg ) , * ) ) } ;
1087- ( array_contains, $( $arg : expr) ,+ ) => { crate :: frontend:: Operation (
1079+ crate :: op_args!( $set , $value ) , crate :: middleware :: OperationAux :: MerkleProof ( $aux ) ) } ;
1080+ ( array_contains, $array : expr , $value : expr, $aux : expr ) => { crate :: frontend:: Operation (
10881081 crate :: frontend:: OperationType :: Native ( crate :: frontend:: NativeOperation :: ArrayContainsFromEntries ) ,
1089- crate :: op_args!( $( $arg) ,* ) ) } ;
1090-
1082+ crate :: op_args!( $array, $value) , crate :: middleware:: OperationAux :: MerkleProof ( $aux) ) } ;
10911083 }
10921084}
10931085
@@ -1268,6 +1260,7 @@ pub mod tests {
12681260 OperationArg :: from( ( & signed_pod, "a" ) ) ,
12691261 OperationArg :: from( ( & signed_pod, "b" ) ) ,
12701262 ] ,
1263+ OperationAux :: None ,
12711264 ) ;
12721265 let st1 = builder. op ( true , op_eq1) . unwrap ( ) ;
12731266 let op_eq2 = Operation (
@@ -1276,12 +1269,14 @@ pub mod tests {
12761269 OperationArg :: from( ( & signed_pod, "b" ) ) ,
12771270 OperationArg :: from( ( & signed_pod, "a" ) ) ,
12781271 ] ,
1272+ OperationAux :: None ,
12791273 ) ;
12801274 let st2 = builder. op ( true , op_eq2) . unwrap ( ) ;
12811275
12821276 let op_eq3 = Operation (
12831277 OperationType :: Native ( NativeOperation :: TransitiveEqualFromStatements ) ,
12841278 vec ! [ OperationArg :: Statement ( st1) , OperationArg :: Statement ( st2) ] ,
1279+ OperationAux :: None ,
12851280 ) ;
12861281 let st3 = builder. op ( true , op_eq3) ;
12871282
@@ -1352,8 +1347,8 @@ pub mod tests {
13521347 OperationArg :: Statement ( st0) ,
13531348 OperationArg :: Statement ( st1) ,
13541349 OperationArg :: Statement ( st2) ,
1355- OperationArg :: MerkleProof ( dict. prove( & Hash :: from( "a" ) . into( ) ) . unwrap( ) . 1 ) ,
13561350 ] ,
1351+ OperationAux :: MerkleProof ( dict. prove ( & Hash :: from ( "a" ) . into ( ) ) . unwrap ( ) . 1 ) ,
13571352 ) )
13581353 . unwrap ( ) ;
13591354 let mut main_prover = MockProver { } ;
0 commit comments