Skip to content

Commit d11488e

Browse files
nkaskovilyar
authored andcommitted
Incoming cell processing changed for verification instruction
1 parent eb4468f commit d11488e

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/executor/crypto.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use ton_block::GlobalCapabilities;
3333
use sha2::Digest;
3434
use ed25519::signature::{Signature, Verifier};
3535
use std::sync::Arc;
36-
use ton_types::{BuilderData, error, GasConsumer, ExceptionCode, UInt256};
36+
use ton_types::{BuilderData, Cell, error, GasConsumer, ExceptionCode, UInt256};
3737

3838
use crusty3_zk::{groth16::{verify_proof, prepare_verifying_key, Parameters, verify_groth16_proof_from_byteblob},
3939
bls::{Bls12, Fr}
@@ -89,15 +89,34 @@ 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+
92109
pub(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();
117+
118+
let mut cell_proof_data = obtain_cells_data(cell_proof).unwrap();
119+
101120
if cell_proof_data_length % 8 == 0 {
102121

103122
let result = verify_groth16_proof_from_byteblob::<Bls12>(&cell_proof_data[..]).unwrap();

0 commit comments

Comments
 (0)