Skip to content

Commit

Permalink
Groth16 encrypted input mode introduced. #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilias Khairullin authored and ilyar committed Jun 29, 2022
1 parent 24513ac commit 2921702
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ rand = '0.7'
sha2 = '0.9'
ton_types = { git = 'https://github.com/tonlabs/ton-labs-types.git', tag = '1.11.2' }
ton_block = { git = 'https://github.com/tonlabs/ton-labs-block.git', tag = '1.7.51' }
crusty3_zk = { git = 'https://github.com/nilfoundation/crusty3-zk.git'}

crusty3_zk = { git = 'https://github.com/nilfoundation/crusty3-zk.git', branch = '6-extended-vk-encrypted-input-verification' }
ton_labs_assembler = { git = 'https://github.com/nilfoundation/tvm-asm.git', tag = '1.2.30' }

[features]
Expand Down
21 changes: 13 additions & 8 deletions src/executor/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ use ed25519::signature::{Signature, Verifier};
use std::sync::Arc;
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}
};
use crusty3_zk::{groth16::{verify_proof, prepare_verifying_key, Parameters, verify_groth16_proof_from_byteblob, verify_encrypted_input_groth16_proof_from_byteblob},
bls::{Bls12, Fr},
};

const PUBLIC_KEY_BITS: usize = PUBLIC_KEY_BYTES * 8;
const SIGNATURE_BITS: usize = SIGNATURE_BYTES * 8;
Expand Down Expand Up @@ -109,11 +109,16 @@ pub(super) fn execute_vergrth16(engine: &mut Engine) -> Failure {

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

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();
let mut cell_proof_data = obtain_cells_data(cell_proof).unwrap();if cell_proof_data_length % 8 == 0 {
let mut result = false;
if cell_proof_data[0] == 0 {
result = verify_groth16_proof_from_byteblob::<Bls12>(&cell_proof_data[1..]).unwrap();
} else if cell_proof_data[0] == 1 {
result = verify_encrypted_input_groth16_proof_from_byteblob::<Bls12>(&cell_proof_data[1..]).unwrap();
}
else {
return err!(ExceptionCode::InvalidOpcode);
}

ctx.engine.cc.stack.push(boolean!(result));
Ok(ctx)
Expand Down

0 comments on commit 2921702

Please sign in to comment.