@@ -2,7 +2,6 @@ pub mod operation;
22pub mod statement;
33use std:: any:: Any ;
44
5- use anyhow:: { anyhow, Result } ;
65use itertools:: Itertools ;
76pub use operation:: * ;
87use plonky2:: {
@@ -23,9 +22,11 @@ use crate::{
2322 signedpod:: SignedPod ,
2423 } ,
2524 middleware:: {
26- self , AnchoredKey , Hash , MainPodInputs , NativeOperation , NonePod , OperationType , Params ,
27- Pod , PodId , PodProver , PodType , StatementArg , ToFields , F , KEY_TYPE , SELF ,
25+ self , error:: MiddlewareError , AnchoredKey , Hash , MainPodInputs , NativeOperation , NonePod ,
26+ OperationType , Params , Pod , PodId , PodProver , PodType , StatementArg , ToFields , F , KEY_TYPE ,
27+ SELF ,
2828 } ,
29+ Error , Result ,
2930} ;
3031
3132/// Hash a list of public statements to derive the PodId
@@ -72,11 +73,11 @@ pub(crate) fn extract_merkle_proofs(
7273 } )
7374 . collect :: < Result < Vec < _ > > > ( ) ?;
7475 if merkle_proofs. len ( ) > params. max_merkle_proofs {
75- Err ( anyhow ! (
76+ Err ( Error :: Custom ( format ! (
7677 "The number of required Merkle proofs ({}) exceeds the maximum number ({})." ,
7778 merkle_proofs. len( ) ,
7879 params. max_merkle_proofs
79- ) )
80+ ) ) )
8081 } else {
8182 fill_pad (
8283 & mut merkle_proofs,
@@ -98,10 +99,10 @@ fn find_op_arg(statements: &[Statement], op_arg: &middleware::Statement) -> Resu
9899 ( & middleware:: Statement :: try_from ( s. clone ( ) ) . ok ( ) ? == op_arg) . then_some ( i)
99100 } )
100101 . map ( OperationArg :: Index )
101- . ok_or ( anyhow ! (
102+ . ok_or ( Error :: Custom ( format ! (
102103 "Statement corresponding to op arg {} not found" ,
103104 op_arg
104- ) ) ,
105+ ) ) ) ,
105106 }
106107}
107108
@@ -122,10 +123,10 @@ fn find_op_aux(
122123 . and_then ( |mid_pf : merkletree:: MerkleProof | ( & mid_pf == pf_arg) . then_some ( i) )
123124 } )
124125 . map ( OperationAux :: MerkleProofIndex )
125- . ok_or ( anyhow ! (
126+ . ok_or ( Error :: Custom ( format ! (
126127 "Merkle proof corresponding to op arg {} not found" ,
127128 op_aux
128- ) ) ,
129+ ) ) ) ,
129130 }
130131}
131132
@@ -384,11 +385,7 @@ impl Pod for MainPod {
384385 // 2. get the id out of the public statements
385386 let id: PodId = PodId ( hash_statements ( & self . public_statements , & self . params ) ) ;
386387 if id != self . id {
387- return Err ( anyhow ! (
388- "id does not match, expected {}, computed {}" ,
389- self . id,
390- id
391- ) ) ;
388+ return Err ( Error :: Middleware ( MiddlewareError :: IdNotEqual ( self . id , id) ) ) ;
392389 }
393390
394391 // 1, 3, 4, 5 verification via the zkSNARK proof
@@ -402,7 +399,7 @@ impl Pod for MainPod {
402399
403400 let data = builder. build :: < C > ( ) ;
404401 data. verify ( self . proof . clone ( ) )
405- . map_err ( |e| anyhow ! ( "MainPod proof verification failure: {:?}" , e) )
402+ . map_err ( |e| Error :: Custom ( format ! ( "MainPod proof verification failure: {:?}" , e) ) )
406403 }
407404
408405 fn id ( & self ) -> PodId {
0 commit comments