Skip to content

Commit 4f34fbf

Browse files
nemothenooneilyar
authored andcommitted
Initial instruction definition implemented
1 parent 047b70c commit 4f34fbf

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ similar = { features = [ 'bytes' ], optional = true, version = '2.2.0' }
1919
ton_block = { git = 'https://github.com/tonlabs/ever-block.git', tag = '1.9.101' }
2020
ton_types = { git = 'https://github.com/tonlabs/ever-types.git', tag = '2.0.26' }
2121
zstd = { default-features = false, optional = true, version = '0.11' }
22+
crusty3_zk = { git = 'https://github.com/nilfoundation/crusty3-zk.git', branch = '6-extended-vk-encrypted-input-verification' }
2223

2324
[features]
2425
fift_check = [ ]

src/executor/crypto.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,20 @@ use crate::{
2525
},
2626
types::{Exception, Status}
2727
};
28+
29+
use crusty3_zk::create_random_proof;
2830
use ed25519::signature::Verifier;
2931
use std::borrow::Cow;
3032
use ton_block::GlobalCapabilities;
33+
use sha2::Digest;
34+
use ed25519::signature::{Signature, Verifier};
35+
use std::sync::Arc;
3136
use ton_types::{BuilderData, error, GasConsumer, ExceptionCode, UInt256};
3237

38+
use crusty3_zk::{groth16::{verify_proof, prepare_verifying_key, Parameters},
39+
bls::{Bls12, Fr}
40+
};
41+
3342
const PUBLIC_KEY_BITS: usize = PUBLIC_KEY_BYTES * 8;
3443
const SIGNATURE_BITS: usize = SIGNATURE_BYTES * 8;
3544
const PUBLIC_KEY_BYTES: usize = ed25519_dalek::PUBLIC_KEY_LENGTH;
@@ -80,6 +89,34 @@ pub(super) fn execute_sha256u(engine: &mut Engine) -> Status {
8089
}
8190
}
8291

92+
pub(super) fn execute_vergrth16(engine: &mut Engine) -> Failure {
93+
engine.load_instruction(Instruction::new("VERGRTH16"))
94+
.and_then(|ctx| fetch_stack(ctx, 1))
95+
.and_then(|ctx| {
96+
let builder = BuilderData::from(ctx.engine.cmd.var(0).as_cell()?);
97+
let cell_proof_data_length = builder.length_in_bits();
98+
//let data = builder.data();
99+
let cell_proof = ctx.engine.finalize_cell(builder)?;
100+
let cell_proof_data = cell_proof.data();
101+
if cell_proof_data_length % 8 == 0 {
102+
103+
let de_params = Parameters::read(&cell_proof_data[..], true).unwrap();
104+
105+
let pvk = prepare_verifying_key::<Bls12>(&de_params.vk);
106+
107+
//let de_proof = Proof::read(&v[..]).unwrap();
108+
109+
//let result = verify_proof();
110+
let result = true;
111+
ctx.engine.cc.stack.push(boolean!(result));
112+
Ok(ctx)
113+
} else {
114+
err!(ExceptionCode::CellUnderflow)
115+
}
116+
})
117+
.err()
118+
}
119+
83120
enum DataForSignature {
84121
Hash(BuilderData),
85122
Slice(Vec<u8>)

src/executor/engine/handlers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@ impl Handlers {
894894
.set(0x02, execute_sha256u)
895895
.set(0x10, execute_chksignu)
896896
.set(0x11, execute_chksigns)
897+
.set(0x12, execute_vergrth16)
897898
.set(0x40, execute_cdatasizeq)
898899
.set(0x41, execute_cdatasize)
899900
.set(0x42, execute_sdatasizeq)

0 commit comments

Comments
 (0)