@@ -57,21 +57,19 @@ pub const RECURSION_VK_SET: &[[u32; 8]] = &[
5757/// Then, calls [`verify_sp1_reduce_proof`] and returns the result.
5858pub fn verify_sp1_proof (
5959 sp1_proof : & SP1Proof ,
60- sp1_public_inputs : & [ u8 ] ,
6160 vkey_hash : & [ BabyBear ; 8 ] ,
6261) -> Result < ( ) , CompressedError > {
6362 let SP1Proof :: Compressed ( reduce_proof) = sp1_proof else {
6463 return Err ( CompressedError :: Mode ( sp1_proof. into ( ) ) ) ;
6564 } ;
66- verify_sp1_reduce_proof ( reduce_proof. as_ref ( ) , sp1_public_inputs , vkey_hash)
65+ verify_sp1_reduce_proof ( reduce_proof. as_ref ( ) , vkey_hash)
6766}
6867
6968// The rest of the functions in this file have been copied from elsewhere with slight modifications.
7069
7170/// Verify a compressed proof.
7271pub fn verify_sp1_reduce_proof (
7372 reduce_proof : & SP1ReduceProof < SC > ,
74- sp1_public_inputs : & [ u8 ] ,
7573 vkey_hash : & [ BabyBear ; 8 ] ,
7674) -> Result < ( ) , CompressedError > {
7775 let SP1ReduceProof { vk : compress_vk, proof } = reduce_proof;
@@ -89,20 +87,6 @@ pub fn verify_sp1_reduce_proof(
8987 let machine_proof = MachineProof { shard_proofs : vec ! [ proof. clone( ) ] } ;
9088 compress_machine. verify ( compress_vk, & machine_proof, & mut challenger) ?;
9189
92- // Validate the SP1 public values against the committed digest.
93- let committed_value_digest_bytes = public_values
94- . committed_value_digest
95- . iter ( )
96- . flat_map ( |w| w. 0 . iter ( ) . map ( |x| x. as_canonical_u32 ( ) as u8 ) )
97- . collect :: < Vec < _ > > ( ) ;
98-
99- if committed_value_digest_bytes. as_slice ( ) != hash_public_inputs ( sp1_public_inputs) . as_slice ( ) &&
100- committed_value_digest_bytes. as_slice ( ) !=
101- hash_public_inputs_with_fn ( sp1_public_inputs, blake3_hash)
102- {
103- return Err ( CompressedError :: PublicValuesMismatch ) ;
104- }
105-
10690 // Validate recursion's public values.
10791 if !is_recursion_public_values_valid ( compress_machine. config ( ) , public_values) {
10892 return Err ( MachineVerificationError :: InvalidPublicValues (
@@ -134,6 +118,55 @@ pub fn verify_sp1_reduce_proof(
134118 Ok ( ( ) )
135119}
136120
121+ /// Verify a compressed proof.
122+ pub fn verify_sp1_public_values (
123+ reduce_proof : & SP1ReduceProof < SC > ,
124+ sp1_public_inputs : & [ u8 ] ,
125+ ) -> Result < ( ) , CompressedError > {
126+ let SP1ReduceProof { proof, .. } = reduce_proof;
127+
128+ let public_values: & RecursionPublicValues < _ > = proof. public_values . as_slice ( ) . borrow ( ) ;
129+ // Validate the SP1 public values against the committed digest.
130+ let committed_value_digest_bytes = public_values
131+ . committed_value_digest
132+ . iter ( )
133+ . flat_map ( |w| w. 0 . iter ( ) . map ( |x| x. as_canonical_u32 ( ) as u8 ) )
134+ . collect :: < Vec < _ > > ( ) ;
135+
136+ if committed_value_digest_bytes. as_slice ( ) != hash_public_inputs ( sp1_public_inputs) . as_slice ( )
137+ && committed_value_digest_bytes. as_slice ( )
138+ != hash_public_inputs_with_fn ( sp1_public_inputs, blake3_hash)
139+ {
140+ return Err ( CompressedError :: PublicValuesMismatch ) ;
141+ }
142+
143+ Ok ( ( ) )
144+ }
145+
146+ /// Verify a compressed proof with public values.
147+ pub fn verify_sp1_proof_with_public_values (
148+ sp1_proof : & SP1Proof ,
149+ sp1_public_inputs : & [ u8 ] ,
150+ vkey_hash : & [ BabyBear ; 8 ] ,
151+ ) -> Result < ( ) , CompressedError > {
152+ let SP1Proof :: Compressed ( reduce_proof) = sp1_proof else {
153+ return Err ( CompressedError :: Mode ( sp1_proof. into ( ) ) ) ;
154+ } ;
155+ verify_sp1_reduce_proof_with_public_values ( reduce_proof, sp1_public_inputs, vkey_hash)
156+ }
157+
158+ /// Verify a compressed proof.
159+ pub fn verify_sp1_reduce_proof_with_public_values (
160+ reduce_proof : & SP1ReduceProof < SC > ,
161+ sp1_public_inputs : & [ u8 ] ,
162+ vkey_hash : & [ BabyBear ; 8 ] ,
163+ ) -> Result < ( ) , CompressedError > {
164+ // Verify the proof
165+ verify_sp1_reduce_proof ( reduce_proof, vkey_hash) ?;
166+ // Verify the public values against the committed digest
167+ verify_sp1_public_values ( reduce_proof, sp1_public_inputs)
168+ }
169+
137170/// Compute the digest of the public values.
138171fn recursion_public_values_digest (
139172 config : & SC ,
0 commit comments