@@ -2,56 +2,57 @@ use base64::prelude::*;
22use log:: { debug, warn} ;
33
44pub fn verify_protocol_state_proof_integrity ( proof : & [ u8 ] , public_input : & [ u8 ] ) -> bool {
5- debug ! ( "Reading Mina protocol state proof base64" ) ;
6- let protocol_state_proof_base64 =
7- if let Ok ( protocol_state_proof_base64) = std:: str:: from_utf8 ( proof) {
8- protocol_state_proof_base64
9- } else {
10- return false ;
11- } ;
12- debug ! ( "Reading Mina protocol state hash base58" ) ;
13- let protocol_state_hash_base58 =
14- if let Ok ( protocol_state_hash_base58) = std:: str:: from_utf8 ( public_input) {
15- protocol_state_hash_base58
16- } else {
17- return false ;
18- } ;
19-
20- debug ! ( "Decoding Mina protocol state proof base64" ) ;
21- if BASE64_URL_SAFE
22- . decode ( protocol_state_proof_base64. trim_end ( ) )
23- . is_err ( )
24- {
25- warn ! ( "Failed to decode Mina protocol state proof base64" ) ;
5+ debug ! ( "Checking Mina protocol state proof" ) ;
6+ if let Err ( err) = check_protocol_state_proof ( proof) {
7+ warn ! ( "Protocol state proof check failed: {}" , err) ;
268 return false ;
279 }
2810
29- debug ! ( "Decoding Mina protocol state hash base58" ) ;
30- if bs58:: decode ( protocol_state_hash_base58. trim_end ( ) )
31- . into_vec ( )
32- . is_err ( )
33- {
34- warn ! ( "Failed to decode Mina protocol state hash base58" ) ;
11+ debug ! ( "Checking Mina protocol state public inputs" ) ;
12+ if let Err ( err) = check_protocol_state_pub ( public_input) {
13+ warn ! ( "Protocol state public inputs check failed: {}" , err) ;
3514 return false ;
3615 }
3716
3817 true
3918}
4019
20+ pub fn check_protocol_state_proof ( protocol_state_proof_bytes : & [ u8 ] ) -> Result < ( ) , String > {
21+ // TODO(xqft): check binprot deserialization
22+ let protocol_state_proof_base64 =
23+ std:: str:: from_utf8 ( protocol_state_proof_bytes) . map_err ( |err| err. to_string ( ) ) ?;
24+ BASE64_URL_SAFE
25+ . decode ( protocol_state_proof_base64)
26+ . map_err ( |err| err. to_string ( ) ) ?;
27+
28+ Ok ( ( ) )
29+ }
30+
31+ pub fn check_protocol_state_pub ( protocol_state_pub : & [ u8 ] ) -> Result < ( ) , String > {
32+ // TODO(xqft): check hash and binprot deserialization
33+ let protocol_state_base64 =
34+ std:: str:: from_utf8 ( & protocol_state_pub[ 32 ..] ) . map_err ( |err| err. to_string ( ) ) ?;
35+ BASE64_STANDARD
36+ . decode ( protocol_state_base64)
37+ . map_err ( |err| err. to_string ( ) ) ?;
38+
39+ Ok ( ( ) )
40+ }
41+
4142#[ cfg( test) ]
4243mod test {
4344 use super :: verify_protocol_state_proof_integrity;
4445
4546 const PROTOCOL_STATE_PROOF_BYTES : & [ u8 ] =
46- include_bytes ! ( "../../../../batcher/aligned/test_files/mina/protocol_state_proof .proof" ) ;
47- const PROTOCOL_STATE_HASH_BYTES : & [ u8 ] =
48- include_bytes ! ( "../../../../batcher/aligned/test_files/mina/protocol_state_hash .pub" ) ;
47+ include_bytes ! ( "../../../../batcher/aligned/test_files/mina/protocol_state .proof" ) ;
48+ const PROTOCOL_STATE_PUB_BYTES : & [ u8 ] =
49+ include_bytes ! ( "../../../../batcher/aligned/test_files/mina/protocol_state .pub" ) ;
4950
5051 #[ test]
5152 fn verify_protocol_state_proof_integrity_does_not_fail ( ) {
5253 assert ! ( verify_protocol_state_proof_integrity(
5354 PROTOCOL_STATE_PROOF_BYTES ,
54- PROTOCOL_STATE_HASH_BYTES ,
55+ PROTOCOL_STATE_PUB_BYTES ,
5556 ) ) ;
5657 }
5758}
0 commit comments