Skip to content

Commit 5794313

Browse files
committed
Uptodate instruction definition implemented
1 parent 6f3acd7 commit 5794313

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

src/executor/crypto.rs

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,24 @@ use crate::{
2626
types::{Exception, Status}
2727
};
2828

29-
use crusty3_zk::create_random_proof;
3029
use ed25519::signature::Verifier;
3130
use std::borrow::Cow;
3231
use ton_block::GlobalCapabilities;
33-
use sha2::Digest;
34-
use ed25519::signature::{Signature, Verifier};
35-
use std::sync::Arc;
36-
use ton_types::{BuilderData, Cell, error, GasConsumer, ExceptionCode, UInt256};
37-
38-
use crusty3_zk::{groth16::{verify_proof, prepare_verifying_key, Parameters, verify_groth16_proof_from_byteblob, verify_encrypted_input_groth16_proof_from_byteblob},
39-
bls::{Bls12, Fr},
32+
use ton_types::{
33+
BuilderData,
34+
Cell,
35+
error,
36+
GasConsumer,
37+
ExceptionCode,
38+
UInt256,
39+
Result,
40+
};
41+
use crusty3_zk::{
42+
groth16::{
43+
verify_groth16_proof_from_byteblob,
44+
verify_encrypted_input_groth16_proof_from_byteblob,
45+
},
46+
bls::{Bls12},
4047
};
4148

4249
const PUBLIC_KEY_BITS: usize = PUBLIC_KEY_BYTES * 8;
@@ -89,7 +96,7 @@ pub(super) fn execute_sha256u(engine: &mut Engine) -> Status {
8996
}
9097
}
9198

92-
pub fn obtain_cells_data(cl: Cell) -> Result<Vec<u8>, Failure> {
99+
pub fn obtain_cells_data(cl: Cell) -> Result<Vec<u8>> {
93100
let mut byte_blob = Vec::new();
94101
let mut queue = vec!(cl.clone());
95102
while let Some(cell) = queue.pop() {
@@ -106,33 +113,24 @@ pub fn obtain_cells_data(cl: Cell) -> Result<Vec<u8>, Failure> {
106113
Ok(byte_blob)
107114
}
108115

109-
pub(super) fn execute_vergrth16(engine: &mut Engine) -> Failure {
110-
engine.load_instruction(Instruction::new("VERGRTH16"))
111-
.and_then(|ctx| fetch_stack(ctx, 1))
112-
.and_then(|ctx| {
113-
let builder = BuilderData::from(ctx.engine.cmd.var(0).as_cell()?);
114-
let cell_proof_data_length = builder.length_in_bits();
115-
116-
let cell_proof = ctx.engine.finalize_cell(builder)?;
117-
118-
let mut cell_proof_data = obtain_cells_data(cell_proof).unwrap();if cell_proof_data_length % 8 == 0 {
119-
let mut result = false;
120-
if cell_proof_data[0] == 0 {
121-
result = verify_groth16_proof_from_byteblob::<Bls12>(&cell_proof_data[1..]).unwrap();
122-
} else if cell_proof_data[0] == 1 {
123-
result = verify_encrypted_input_groth16_proof_from_byteblob::<Bls12>(&cell_proof_data[1..]).unwrap();
124-
}
125-
else {
126-
return err!(ExceptionCode::InvalidOpcode);
127-
}
128-
129-
ctx.engine.cc.stack.push(boolean!(result));
130-
Ok(ctx)
131-
} else {
132-
err!(ExceptionCode::CellUnderflow)
133-
}
134-
})
135-
.err()
116+
pub(super) fn execute_vergrth16(engine: &mut Engine) -> Status {
117+
engine.load_instruction(Instruction::new("VERGRTH16"))?;
118+
fetch_stack(engine, 1)?;
119+
let builder = engine.cmd.var(0).clone().as_builder_mut()?;
120+
let cell_proof_data_length = builder.length_in_bits();
121+
let cell_proof = engine.finalize_cell(builder.into())?;
122+
let cell_proof_data = obtain_cells_data(cell_proof).unwrap();
123+
if cell_proof_data_length % 8 == 0 {
124+
let result = if cell_proof_data[0] == 0 {
125+
verify_groth16_proof_from_byteblob::<Bls12>(&cell_proof_data[1..]).unwrap()
126+
} else {
127+
verify_encrypted_input_groth16_proof_from_byteblob::<Bls12>(&cell_proof_data[1..]).unwrap()
128+
};
129+
engine.cc.stack.push(boolean!(result));
130+
return Ok(())
131+
} else {
132+
err!(ExceptionCode::CellUnderflow)
133+
}
136134
}
137135

138136
enum DataForSignature {

0 commit comments

Comments
 (0)