Skip to content

Commit 2921702

Browse files
Ilias Khairullinilyar
authored andcommitted
Groth16 encrypted input mode introduced. #6
1 parent 24513ac commit 2921702

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ rand = '0.7'
1717
sha2 = '0.9'
1818
ton_types = { git = 'https://github.com/tonlabs/ton-labs-types.git', tag = '1.11.2' }
1919
ton_block = { git = 'https://github.com/tonlabs/ton-labs-block.git', tag = '1.7.51' }
20-
crusty3_zk = { git = 'https://github.com/nilfoundation/crusty3-zk.git'}
21-
20+
crusty3_zk = { git = 'https://github.com/nilfoundation/crusty3-zk.git', branch = '6-extended-vk-encrypted-input-verification' }
2221
ton_labs_assembler = { git = 'https://github.com/nilfoundation/tvm-asm.git', tag = '1.2.30' }
2322

2423
[features]

src/executor/crypto.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ use ed25519::signature::{Signature, Verifier};
3333
use std::sync::Arc;
3434
use ton_types::{BuilderData, Cell, error, GasConsumer, ExceptionCode, UInt256};
3535

36-
use crusty3_zk::{groth16::{verify_proof, prepare_verifying_key, Parameters, verify_groth16_proof_from_byteblob},
37-
bls::{Bls12, Fr}
38-
};
36+
use crusty3_zk::{groth16::{verify_proof, prepare_verifying_key, Parameters, verify_groth16_proof_from_byteblob, verify_encrypted_input_groth16_proof_from_byteblob},
37+
bls::{Bls12, Fr},
38+
};
3939

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

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

112-
let mut cell_proof_data = obtain_cells_data(cell_proof).unwrap();
113-
114-
if cell_proof_data_length % 8 == 0 {
115-
116-
let result = verify_groth16_proof_from_byteblob::<Bls12>(&cell_proof_data[..]).unwrap();
112+
let mut cell_proof_data = obtain_cells_data(cell_proof).unwrap();if cell_proof_data_length % 8 == 0 {
113+
let mut result = false;
114+
if cell_proof_data[0] == 0 {
115+
result = verify_groth16_proof_from_byteblob::<Bls12>(&cell_proof_data[1..]).unwrap();
116+
} else if cell_proof_data[0] == 1 {
117+
result = verify_encrypted_input_groth16_proof_from_byteblob::<Bls12>(&cell_proof_data[1..]).unwrap();
118+
}
119+
else {
120+
return err!(ExceptionCode::InvalidOpcode);
121+
}
117122

118123
ctx.engine.cc.stack.push(boolean!(result));
119124
Ok(ctx)

0 commit comments

Comments
 (0)