@@ -33,9 +33,9 @@ use ton_block::GlobalCapabilities;
3333use sha2:: Digest ;
3434use ed25519:: signature:: { Signature , Verifier } ;
3535use std:: sync:: Arc ;
36- use ton_types:: { BuilderData , error, GasConsumer , ExceptionCode , UInt256 } ;
36+ use ton_types:: { BuilderData , Cell , error, GasConsumer , ExceptionCode , UInt256 } ;
3737
38- use crusty3_zk:: { groth16:: { verify_proof, prepare_verifying_key, Parameters } ,
38+ use crusty3_zk:: { groth16:: { verify_proof, prepare_verifying_key, Parameters , verify_groth16_proof_from_byteblob } ,
3939 bls:: { Bls12 , Fr }
4040 } ;
4141
@@ -89,25 +89,38 @@ pub(super) fn execute_sha256u(engine: &mut Engine) -> Status {
8989 }
9090}
9191
92+ pub fn obtain_cells_data ( cl : Cell ) -> Result < Vec < u8 > , Failure > {
93+ let mut byte_blob = Vec :: new ( ) ;
94+ let mut queue = vec ! ( cl. clone( ) ) ;
95+ while let Some ( cell) = queue. pop ( ) {
96+ let this_reference_data = cell. data ( ) ;
97+
98+ byte_blob. extend ( this_reference_data[ 0 ..this_reference_data. len ( ) -1 ] . iter ( ) . copied ( ) ) ;
99+
100+ let count = cell. references_count ( ) ;
101+ for i in 0 ..count {
102+ queue. push ( cell. reference ( i) ?) ;
103+ }
104+ }
105+
106+ Ok ( byte_blob)
107+ }
108+
92109pub ( super ) fn execute_vergrth16 ( engine : & mut Engine ) -> Failure {
93110 engine. load_instruction ( Instruction :: new ( "VERGRTH16" ) )
94111 . and_then ( |ctx| fetch_stack ( ctx, 1 ) )
95112 . and_then ( |ctx| {
96113 let builder = BuilderData :: from ( ctx. engine . cmd . var ( 0 ) . as_cell ( ) ?) ;
97114 let cell_proof_data_length = builder. length_in_bits ( ) ;
98- //let data = builder.data();
115+
99116 let cell_proof = ctx. engine . finalize_cell ( builder) ?;
100- let cell_proof_data = cell_proof. data ( ) ;
101- if cell_proof_data_length % 8 == 0 {
102117
103- let de_params = Parameters :: read ( & cell_proof_data [ .. ] , true ) . unwrap ( ) ;
118+ let mut cell_proof_data = obtain_cells_data ( cell_proof ) . unwrap ( ) ;
104119
105- let pvk = prepare_verifying_key :: < Bls12 > ( & de_params . vk ) ;
120+ if cell_proof_data_length % 8 == 0 {
106121
107- // let de_proof = Proof::read(&v [..]).unwrap();
122+ let result = verify_groth16_proof_from_byteblob :: < Bls12 > ( & cell_proof_data [ ..] ) . unwrap ( ) ;
108123
109- //let result = verify_proof();
110- let result = true ;
111124 ctx. engine . cc . stack . push ( boolean ! ( result) ) ;
112125 Ok ( ctx)
113126 } else {
0 commit comments