Skip to content

Commit

Permalink
Incoming cell processing changed for verification instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaskov authored and ilyar committed Jun 29, 2022
1 parent 6a30f96 commit 24513ac
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/executor/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use ed25519::signature::Verifier;
use sha2::Digest;
use ed25519::signature::{Signature, Verifier};
use std::sync::Arc;
use ton_types::{BuilderData, error, GasConsumer, ExceptionCode, UInt256};
use ton_types::{BuilderData, Cell, error, GasConsumer, ExceptionCode, UInt256};

use crusty3_zk::{groth16::{verify_proof, prepare_verifying_key, Parameters, verify_groth16_proof_from_byteblob},
bls::{Bls12, Fr}
Expand Down Expand Up @@ -83,15 +83,34 @@ pub(super) fn execute_sha256u(engine: &mut Engine) -> Status {
}
}

pub fn obtain_cells_data(cl: Cell) -> Result<Vec<u8>, Failure> {
let mut byte_blob = Vec::new();
let mut queue = vec!(cl.clone());
while let Some(cell) = queue.pop() {
let this_reference_data = cell.data();

byte_blob.extend(this_reference_data[0..this_reference_data.len()-1].iter().copied());

let count = cell.references_count();
for i in 0..count {
queue.push(cell.reference(i)?);
}
}

Ok(byte_blob)
}

pub(super) fn execute_vergrth16(engine: &mut Engine) -> Failure {
engine.load_instruction(Instruction::new("VERGRTH16"))
.and_then(|ctx| fetch_stack(ctx, 1))
.and_then(|ctx| {
let builder = BuilderData::from(ctx.engine.cmd.var(0).as_cell()?);
let cell_proof_data_length = builder.length_in_bits();
//let data = builder.data();

let cell_proof = ctx.engine.finalize_cell(builder)?;
let cell_proof_data = cell_proof.data();

let mut cell_proof_data = obtain_cells_data(cell_proof).unwrap();

if cell_proof_data_length % 8 == 0 {

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

0 comments on commit 24513ac

Please sign in to comment.