@@ -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,12 @@ 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} or {v1}." ,
20+ v0 = ProofVersion :: V0 ,
21+ v1 = ProofVersion :: V1 ,
22+ ) ]
23+ InvalidProofVersion { actual : Felt } ,
2024 #[ error( "Proof facts too short: expected at least 3 elements, got {length}." ) ]
2125 ProofFactsTooShort { length : usize } ,
2226 #[ error( "Proof verification failed: {0}" ) ]
@@ -29,9 +33,9 @@ impl PartialEq for VerifyProofError {
2933 ( Self :: EmptyProof , Self :: EmptyProof ) => true ,
3034 ( Self :: ProgramOutputError ( lhs) , Self :: ProgramOutputError ( rhs) ) => lhs == rhs,
3135 (
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,
36+ Self :: InvalidProofVersion { actual : act_l } ,
37+ Self :: InvalidProofVersion { actual : act_r } ,
38+ ) => act_l == act_r,
3539 ( Self :: Verification ( lhs) , Self :: Verification ( rhs) ) => lhs == rhs,
3640 ( Self :: ProofFactsTooShort { length : l } , Self :: ProofFactsTooShort { length : r } ) => {
3741 l == r
@@ -83,7 +87,7 @@ impl ProgramOutput {
8387 return Err ( ProgramOutputError :: TooShort ( self . 0 . len ( ) ) ) ;
8488 }
8589 // Add the proof version and variant markers in place of num_tasks.
86- let mut facts = vec ! [ PROOF_VERSION_V0 ] ;
90+ let mut facts = vec ! [ ProofVersion :: V0 . as_felt ( ) ] ;
8791 facts. push ( program_variant) ;
8892 // Skip num_tasks (index 0) and output_size (index 1); add the task output
8993 // (program_hash followed by the virtual OS output).
@@ -119,21 +123,19 @@ pub fn reconstruct_output_preimage(
119123}
120124
121125/// Verifies a submitted proof against the proof facts using the circuit verifier.
126+ ///
127+ /// Accepts either V0 (legacy) or V1 (current) proof versions. Both currently resolve to the same
128+ /// upstream circuit revision. When the V1 circuit revision is bumped, V0 verification should be
129+ /// routed to a `privacy-circuit-verify-legacy` alias pinned to the old revision.
122130pub fn verify_proof ( proof_facts : ProofFacts , proof : Proof ) -> Result < ( ) , VerifyProofError > {
123131 // Reject empty proof payloads before running the verifier.
124132 if proof. is_empty ( ) {
125133 return Err ( VerifyProofError :: EmptyProof ) ;
126134 }
127135
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- }
136+ let proof_version_felt = proof_facts. proof_version_felt ( ) ;
137+ let _proof_version = ProofVersion :: try_from ( proof_version_felt)
138+ . map_err ( |( ) | VerifyProofError :: InvalidProofVersion { actual : proof_version_felt } ) ?;
137139
138140 // Reconstruct the output preimage from proof facts and verify the proof.
139141 let output_preimage = reconstruct_output_preimage ( & proof_facts) ?;
0 commit comments