@@ -12,6 +12,9 @@ use solana_bn254::compression::prelude::{
1212 convert_endianness,
1313} ;
1414
15+ pub type CompressedProofBytes = ( [ u8 ; 32 ] , [ u8 ; 64 ] , [ u8 ; 32 ] ) ;
16+ pub type UncompressedProofBytes = ( [ u8 ; 64 ] , [ u8 ; 128 ] , [ u8 ; 64 ] ) ;
17+
1518#[ derive( Debug , Clone , Copy ) ]
1619pub struct ProofCompressed {
1720 pub a : [ u8 ; 32 ] ,
@@ -71,9 +74,8 @@ pub fn deserialize_hex_string_to_be_bytes(hex_str: &str) -> Result<[u8; 32], Pro
7174 . strip_prefix ( "0x" )
7275 . or_else ( || hex_str. strip_prefix ( "0X" ) )
7376 . unwrap_or ( hex_str) ;
74- let big_uint = num_bigint:: BigUint :: from_str_radix ( trimmed_str, 16 ) . map_err ( |error| {
75- ProverClientError :: InvalidHexString ( format ! ( "{hex_str}: {error}" ) )
76- } ) ?;
77+ let big_uint = num_bigint:: BigUint :: from_str_radix ( trimmed_str, 16 )
78+ . map_err ( |error| ProverClientError :: InvalidHexString ( format ! ( "{hex_str}: {error}" ) ) ) ?;
7779 let big_uint_bytes = big_uint. to_bytes_be ( ) ;
7880 if big_uint_bytes. len ( ) > 32 {
7981 return Err ( ProverClientError :: InvalidHexString ( format ! (
@@ -95,7 +97,7 @@ pub fn compress_proof(
9597 proof_a : & [ u8 ; 64 ] ,
9698 proof_b : & [ u8 ; 128 ] ,
9799 proof_c : & [ u8 ; 64 ] ,
98- ) -> Result < ( [ u8 ; 32 ] , [ u8 ; 64 ] , [ u8 ; 32 ] ) , ProverClientError > {
100+ ) -> Result < CompressedProofBytes , ProverClientError > {
99101 let proof_a = alt_bn128_g1_compress ( proof_a) ?;
100102 let proof_b = alt_bn128_g2_compress ( proof_b) ?;
101103 let proof_c = alt_bn128_g1_compress ( proof_c) ?;
@@ -104,7 +106,7 @@ pub fn compress_proof(
104106
105107pub fn proof_from_json_struct (
106108 json : GnarkProofJson ,
107- ) -> Result < ( [ u8 ; 64 ] , [ u8 ; 128 ] , [ u8 ; 64 ] ) , ProverClientError > {
109+ ) -> Result < UncompressedProofBytes , ProverClientError > {
108110 let proof_a_x = deserialize_hex_string_to_be_bytes ( json. ar . first ( ) . ok_or_else ( || {
109111 ProverClientError :: InvalidProofData ( "missing proof A x coordinate" . to_string ( ) )
110112 } ) ?) ?;
@@ -117,37 +119,24 @@ pub fn proof_from_json_struct(
117119 . map_err ( |_| ProverClientError :: InvalidProofData ( "invalid proof A length" . to_string ( ) ) ) ?;
118120 let proof_a = negate_g1 ( & proof_a) ?;
119121 let proof_b_x_0 = deserialize_hex_string_to_be_bytes (
120- json. bs
121- . first ( )
122- . and_then ( |row| row. first ( ) )
123- . ok_or_else ( || {
124- ProverClientError :: InvalidProofData ( "missing proof B x0 coordinate" . to_string ( ) )
125- } ) ?,
122+ json. bs . first ( ) . and_then ( |row| row. first ( ) ) . ok_or_else ( || {
123+ ProverClientError :: InvalidProofData ( "missing proof B x0 coordinate" . to_string ( ) )
124+ } ) ?,
126125 ) ?;
127126 let proof_b_x_1 = deserialize_hex_string_to_be_bytes (
128- json. bs
129- . first ( )
130- . and_then ( |row| row. get ( 1 ) )
131- . ok_or_else ( || {
132- ProverClientError :: InvalidProofData ( "missing proof B x1 coordinate" . to_string ( ) )
133- } ) ?,
127+ json. bs . first ( ) . and_then ( |row| row. get ( 1 ) ) . ok_or_else ( || {
128+ ProverClientError :: InvalidProofData ( "missing proof B x1 coordinate" . to_string ( ) )
129+ } ) ?,
134130 ) ?;
135131 let proof_b_y_0 = deserialize_hex_string_to_be_bytes (
136- json. bs
137- . get ( 1 )
138- . and_then ( |row| row. first ( ) )
139- . ok_or_else ( || {
140- ProverClientError :: InvalidProofData ( "missing proof B y0 coordinate" . to_string ( ) )
141- } ) ?,
142- ) ?;
143- let proof_b_y_1 = deserialize_hex_string_to_be_bytes (
144- json. bs
145- . get ( 1 )
146- . and_then ( |row| row. get ( 1 ) )
147- . ok_or_else ( || {
148- ProverClientError :: InvalidProofData ( "missing proof B y1 coordinate" . to_string ( ) )
149- } ) ?,
132+ json. bs . get ( 1 ) . and_then ( |row| row. first ( ) ) . ok_or_else ( || {
133+ ProverClientError :: InvalidProofData ( "missing proof B y0 coordinate" . to_string ( ) )
134+ } ) ?,
150135 ) ?;
136+ let proof_b_y_1 =
137+ deserialize_hex_string_to_be_bytes ( json. bs . get ( 1 ) . and_then ( |row| row. get ( 1 ) ) . ok_or_else (
138+ || ProverClientError :: InvalidProofData ( "missing proof B y1 coordinate" . to_string ( ) ) ,
139+ ) ?) ?;
151140 let proof_b: [ u8 ; 128 ] = [ proof_b_x_0, proof_b_x_1, proof_b_y_0, proof_b_y_1]
152141 . concat ( )
153142 . try_into ( )
0 commit comments