@@ -5,7 +5,7 @@ use std::sync::Arc;
55use apollo_sizeof:: SizeOf ;
66use privacy_circuit_verify:: { verify_recursive_circuit, PrivacyProofOutput } ;
77use serde:: { Deserialize , Serialize } ;
8- use starknet_api:: transaction:: fields:: { Proof , ProofFacts , PROOF_VERSION_V0 } ;
8+ use starknet_api:: transaction:: fields:: { Proof , ProofFacts , ProofVersion } ;
99use starknet_types_core:: felt:: Felt ;
1010use thiserror:: Error ;
1111
@@ -15,8 +15,15 @@ pub enum VerifyProofError {
1515 EmptyProof ,
1616 #[ error( transparent) ]
1717 ProgramOutputError ( #[ from] ProgramOutputError ) ,
18- #[ error( "Invalid proof version: expected {expected}, got {actual}." ) ]
19- InvalidProofVersion { expected : Felt , actual : Felt } ,
18+ #[ error(
19+ "Unsupported proof version: got {actual}, expected {v0_felt} ({v0_str}) or {v1_felt} \
20+ ({v1_str}).",
21+ v0_felt = ProofVersion :: V0 . as_felt( ) ,
22+ v0_str = ProofVersion :: V0 . as_str( ) ,
23+ v1_felt = ProofVersion :: V1 . as_felt( ) ,
24+ v1_str = ProofVersion :: V1 . as_str( ) ,
25+ ) ]
26+ InvalidProofVersion { actual : Felt } ,
2027 #[ error( "Proof facts too short: expected at least 3 elements, got {length}." ) ]
2128 ProofFactsTooShort { length : usize } ,
2229 #[ error( "Proof verification failed: {0}" ) ]
@@ -29,9 +36,9 @@ impl PartialEq for VerifyProofError {
2936 ( Self :: EmptyProof , Self :: EmptyProof ) => true ,
3037 ( Self :: ProgramOutputError ( lhs) , Self :: ProgramOutputError ( rhs) ) => lhs == rhs,
3138 (
32- Self :: InvalidProofVersion { expected : exp_l , actual : act_l } ,
33- Self :: InvalidProofVersion { expected : exp_r , actual : act_r } ,
34- ) => exp_l == exp_r && act_l == act_r,
39+ Self :: InvalidProofVersion { actual : act_l } ,
40+ Self :: InvalidProofVersion { actual : act_r } ,
41+ ) => act_l == act_r,
3542 ( Self :: Verification ( lhs) , Self :: Verification ( rhs) ) => lhs == rhs,
3643 ( Self :: ProofFactsTooShort { length : l } , Self :: ProofFactsTooShort { length : r } ) => {
3744 l == r
@@ -83,7 +90,7 @@ impl ProgramOutput {
8390 return Err ( ProgramOutputError :: TooShort ( self . 0 . len ( ) ) ) ;
8491 }
8592 // Add the proof version and variant markers in place of num_tasks.
86- let mut facts = vec ! [ PROOF_VERSION_V0 ] ;
93+ let mut facts = vec ! [ ProofVersion :: V0 . as_felt ( ) ] ;
8794 facts. push ( program_variant) ;
8895 // Skip num_tasks (index 0) and output_size (index 1); add the task output
8996 // (program_hash followed by the virtual OS output).
@@ -119,21 +126,19 @@ pub fn reconstruct_output_preimage(
119126}
120127
121128/// Verifies a submitted proof against the proof facts using the circuit verifier.
129+ ///
130+ /// Accepts either V0 (legacy) or V1 (current) proof versions. Both currently resolve to the same
131+ /// upstream circuit revision. When the V1 circuit revision is bumped, V0 verification should be
132+ /// routed to a `privacy-circuit-verify-legacy` alias pinned to the old revision.
122133pub fn verify_proof ( proof_facts : ProofFacts , proof : Proof ) -> Result < ( ) , VerifyProofError > {
123134 // Reject empty proof payloads before running the verifier.
124135 if proof. is_empty ( ) {
125136 return Err ( VerifyProofError :: EmptyProof ) ;
126137 }
127138
128- // Validate that the first element of proof facts is PROOF_VERSION_V0.
129- let expected_proof_version = PROOF_VERSION_V0 ;
130- let actual_first = proof_facts. 0 . first ( ) . copied ( ) . unwrap_or_default ( ) ;
131- if actual_first != expected_proof_version {
132- return Err ( VerifyProofError :: InvalidProofVersion {
133- expected : expected_proof_version,
134- actual : actual_first,
135- } ) ;
136- }
139+ let proof_version_felt = proof_facts. 0 . first ( ) . copied ( ) . unwrap_or_default ( ) ;
140+ let _proof_version = ProofVersion :: try_from ( proof_version_felt)
141+ . map_err ( |( ) | VerifyProofError :: InvalidProofVersion { actual : proof_version_felt } ) ?;
137142
138143 // Reconstruct the output preimage from proof facts and verify the proof.
139144 let output_preimage = reconstruct_output_preimage ( & proof_facts) ?;
0 commit comments