Skip to content

Commit

Permalink
add grth16
Browse files Browse the repository at this point in the history
  • Loading branch information
Трепачева Алина committed May 6, 2024
1 parent 9fa6494 commit 77c2c16
Show file tree
Hide file tree
Showing 23 changed files with 15,747 additions and 11 deletions.
42 changes: 42 additions & 0 deletions tvm_vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,60 @@ num.workspace = true
num-traits.workspace = true
rand.workspace = true
similar = { features = ["bytes"], optional = true, version = "2.4.0" }
serde_json.workspace = true
#serde.workspace = true
thiserror.workspace = true
zstd = { default-features = false, optional = true, version = "0.13.0" }
#bellman = { git = "https://github.com/zkcrypto/bellman" }
bls12_381 = "0.8"


ark-bls12-381 = "0.4.0"
ark-bn254 = "0.4.0"
ark-ec = { version = "0.4.1" }
ark-ff = { version = "0.4.1", features = ["asm"] }
ark-groth16 = { version = "0.4.0", default-features = false }
ark-relations = "0.4.0"
ark-serialize = "0.4.1"
ark-snark = "0.4.0"
blst = "0.3.11"
byte-slice-cast = "1.2.2"
ark-crypto-primitives = { version = "0.4.0", features = ["r1cs", "prf"] }
ark-r1cs-std = "0.4.0"
ark-std = "0.4.0"
#
tvm_block.workspace = true
tvm_types.workspace = true
#fastcrypto-zkp = "0.1.3"
fastcrypto = "0.1.8"
num-bigint = { version = "0.4", default-features = false, features = ["rand"] }

im = "15"

once_cell = "1.16"
schemars = "0.8.10"
serde = { version = "1.0.156", features = ["derive"] }
#serde_derive = "1.0.200"
#serde_json = "1.0.93"
derive_more = "0.99.16"
base64ct ={ version = "1.5.3", features = ["alloc"]}
reqwest = { version = "0.11.20", features = [
"blocking",
"json",
"rustls-tls",
]}
itertools = "0.12.0"
neptune = "13.0.0"
typenum = "1.13.0"
ff = {version = "0.13.0", features = ["derive"]}

[dev-dependencies]
criterion = "0.5.1"
libloading = "0.8.1"
log4rs = "1.2.0"
pprof = { features = ["criterion", "flamegraph"], version = "0.13.0" }
pretty_assertions = "1.4.0"
serde = { version = "1.0.156", features = ["derive"] }

[features]
fift_check = []
Expand Down
Empty file modified tvm_vm/benches/coverage.sh
100755 → 100644
Empty file.
Empty file modified tvm_vm/benches/mergesort/run-fift.sh
100755 → 100644
Empty file.
Empty file modified tvm_vm/benches/prepare-linux.sh
100755 → 100644
Empty file.
Empty file modified tvm_vm/benches/run-fift.sh
100755 → 100644
Empty file.
Empty file modified tvm_vm/doc/make-pdf.sh
100755 → 100644
Empty file.
28 changes: 17 additions & 11 deletions tvm_vm/src/executor/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use std::borrow::Cow;

use bls12_381::Bls12;
use ed25519::Signature;
use ed25519_dalek::Verifier;
use ed25519_dalek::VerifyingKey;
Expand All @@ -31,6 +32,11 @@ use crate::stack::StackItem;
use crate::types::Exception;
use crate::types::Status;






const PUBLIC_KEY_BITS: usize = PUBLIC_KEY_BYTES * 8;
const SIGNATURE_BITS: usize = SIGNATURE_BYTES * 8;
const PUBLIC_KEY_BYTES: usize = ed25519_dalek::PUBLIC_KEY_LENGTH;
Expand Down Expand Up @@ -148,27 +154,27 @@ fn check_signature(engine: &mut Engine, name: &'static str, hash: bool) -> Statu
let signature = match Signature::try_from(&signature[..SIGNATURE_BYTES]) {
Ok(signature) => signature,
Err(err) =>
{
#[allow(clippy::collapsible_else_if)]
if engine.check_capabilities(GlobalCapabilities::CapsTvmBugfixes2022 as u64) {
engine.cc.stack.push(boolean!(false));
return Ok(());
} else {
if hash {
{
#[allow(clippy::collapsible_else_if)]
if engine.check_capabilities(GlobalCapabilities::CapsTvmBugfixes2022 as u64) {
engine.cc.stack.push(boolean!(false));
return Ok(());
} else {
return err!(ExceptionCode::FatalError, "cannot load signature {}", err);
if hash {
engine.cc.stack.push(boolean!(false));
return Ok(());
} else {
return err!(ExceptionCode::FatalError, "cannot load signature {}", err);
}
}
}
}
};
let data = preprocess_signed_data(engine, data.as_ref());
#[cfg(feature = "signature_no_check")]
let result =
let result =
engine.modifiers.chksig_always_succeed || pub_key.verify(&data, &signature).is_ok();
#[cfg(not(feature = "signature_no_check"))]
let result = pub_key.verify(&data, &signature).is_ok();
let result = pub_key.verify(&data, &signature).is_ok();
engine.cc.stack.push(boolean!(result));
Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions tvm_vm/src/executor/engine/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::executor::blockchain::*;
use crate::executor::config::*;
use crate::executor::continuation::*;
use crate::executor::crypto::*;
use crate::executor::zk::*;
use crate::executor::currency::*;
use crate::executor::deserialization::*;
use crate::executor::dictionary::*;
Expand Down Expand Up @@ -932,6 +933,7 @@ impl Handlers {
.set(0x02, execute_sha256u)
.set(0x10, execute_chksignu)
.set(0x11, execute_chksigns)
.set(0x12, execute_vrgrth16)
.set(0x40, execute_cdatasizeq)
.set(0x41, execute_cdatasize)
.set(0x42, execute_sdatasizeq)
Expand Down
4 changes: 4 additions & 0 deletions tvm_vm/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ mod stack;
mod tuple;
mod types;

pub mod zk_stuff;

pub use engine::*;
use tvm_types::BuilderData;
use tvm_types::Cell;
Expand All @@ -45,6 +47,8 @@ use tvm_types::Result;
#[cfg(test)]
#[path = "../tests/test_executor.rs"]
mod tests;
mod zk;


pub trait Mask {
fn bit(&self, bits: Self) -> bool;
Expand Down
Binary file added tvm_vm/src/executor/sprout-groth16.vk
Binary file not shown.
Loading

0 comments on commit 77c2c16

Please sign in to comment.