Skip to content

Commit 0a02399

Browse files
committed
Uptodate instruction definition implemented
1 parent 448184a commit 0a02399

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,15 +26,22 @@ use crate::{
2626
types::{Exception, Status}
2727
};
2828

29-
use crusty3_zk::create_random_proof;
3029
use ed25519::signature::Verifier;
31-
use sha2::Digest;
32-
use ed25519::signature::{Signature, Verifier};
33-
use std::sync::Arc;
34-
use ton_types::{BuilderData, Cell, error, GasConsumer, ExceptionCode, UInt256};
35-
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},
30+
use ton_types::{
31+
BuilderData,
32+
Cell,
33+
error,
34+
GasConsumer,
35+
ExceptionCode,
36+
UInt256,
37+
Result,
38+
};
39+
use crusty3_zk::{
40+
groth16::{
41+
verify_groth16_proof_from_byteblob,
42+
verify_encrypted_input_groth16_proof_from_byteblob,
43+
},
44+
bls::{Bls12},
3845
};
3946

4047
const PUBLIC_KEY_BITS: usize = PUBLIC_KEY_BYTES * 8;
@@ -83,7 +90,7 @@ pub(super) fn execute_sha256u(engine: &mut Engine) -> Status {
8390
}
8491
}
8592

86-
pub fn obtain_cells_data(cl: Cell) -> Result<Vec<u8>, Failure> {
93+
pub fn obtain_cells_data(cl: Cell) -> Result<Vec<u8>> {
8794
let mut byte_blob = Vec::new();
8895
let mut queue = vec!(cl.clone());
8996
while let Some(cell) = queue.pop() {
@@ -100,33 +107,24 @@ pub fn obtain_cells_data(cl: Cell) -> Result<Vec<u8>, Failure> {
100107
Ok(byte_blob)
101108
}
102109

103-
pub(super) fn execute_vergrth16(engine: &mut Engine) -> Failure {
104-
engine.load_instruction(Instruction::new("VERGRTH16"))
105-
.and_then(|ctx| fetch_stack(ctx, 1))
106-
.and_then(|ctx| {
107-
let builder = BuilderData::from(ctx.engine.cmd.var(0).as_cell()?);
108-
let cell_proof_data_length = builder.length_in_bits();
109-
110-
let cell_proof = ctx.engine.finalize_cell(builder)?;
111-
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-
}
122-
123-
ctx.engine.cc.stack.push(boolean!(result));
124-
Ok(ctx)
125-
} else {
126-
err!(ExceptionCode::CellUnderflow)
127-
}
128-
})
129-
.err()
110+
pub(super) fn execute_vergrth16(engine: &mut Engine) -> Status {
111+
engine.load_instruction(Instruction::new("VERGRTH16"))?;
112+
fetch_stack(engine, 1)?;
113+
let builder = BuilderData::from(engine.cmd.var(0).as_cell()?);
114+
let cell_proof_data_length = builder.length_in_bits();
115+
let cell_proof = engine.finalize_cell(builder)?;
116+
let cell_proof_data = obtain_cells_data(cell_proof).unwrap();
117+
if cell_proof_data_length % 8 == 0 {
118+
let result = if cell_proof_data[0] == 0 {
119+
verify_groth16_proof_from_byteblob::<Bls12>(&cell_proof_data[1..]).unwrap()
120+
} else {
121+
verify_encrypted_input_groth16_proof_from_byteblob::<Bls12>(&cell_proof_data[1..]).unwrap()
122+
};
123+
engine.cc.stack.push(boolean!(result));
124+
return Ok(())
125+
} else {
126+
err!(ExceptionCode::CellUnderflow)
127+
}
130128
}
131129

132130
// CHKSIGNS (d s k – ?)

0 commit comments

Comments
 (0)