-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stark verification example scout script
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "phase2-stark-verifier" | ||
version = "0.0.0" | ||
authors = ["Jared Wasinger"] | ||
license = "Apache-2.0" | ||
repository = "https://github.com/ewasm/scout" | ||
description = "Eth 2.0 Phase 2 execution script: MIMC STARK verifier" | ||
publish = false | ||
edition = "2018" | ||
|
||
[dependencies] | ||
ssz = "0.1.2" | ||
ssz-derive = "0.1.2" | ||
sha3 = "^0.6" | ||
stark_verifier = { git = "https://github.com/jwasinger/stark-verifier", branch = "feat/lib" } | ||
num-bigint = { git = "https://github.com/jwasinger/num-bigint", branch = "feature/pow"} | ||
num-traits = "0.2.8" | ||
|
||
[dependencies.ewasm_api] | ||
git = "https://github.com/ewasm/ewasm-rust-api" | ||
rev = "1c01982" | ||
default-features = false | ||
features = ["std", "eth2", "qimalloc"] | ||
|
||
# [profile.release] | ||
# lto = true | ||
# debug = false | ||
|
||
[lib] | ||
crate-type = ["cdylib"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
helloworld: | ||
file: "target/wasm32-unknown-unknown/release/phase2_stark_verifier.wasm" | ||
trimexports: | ||
preset: "ewasm" | ||
verifyexports: | ||
preset: "ewasm" | ||
snip: | ||
preset: "ewasm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
extern crate stark_verifier; | ||
extern crate ewasm_api; | ||
extern crate num_bigint; | ||
|
||
use std::str::FromStr; | ||
use num_traits::pow::Pow; | ||
|
||
use ewasm_api::*; | ||
use stark_verifier::deserializer; | ||
use stark_verifier::{verify_mimc_proof, MODULUS}; | ||
use num_bigint::{BigInt, BigUint}; | ||
|
||
fn process_block(pre_state_root: types::Bytes32, block_data: &[u8]) -> types::Bytes32 { | ||
let (stark_proof, _) = deserializer::from_bytes(&block_data).expect("couldn't deserialize"); | ||
|
||
// TODO: package subsequent parameters in the proof itself | ||
const LOG_STEPS: usize = 13; | ||
let mut constants: Vec<BigInt> = Vec::new(); | ||
let modulus: BigInt = num_bigint::BigInt::from_str(MODULUS).expect("modulus couldn't be deserialized into bigint"); | ||
|
||
for i in 0..64 { | ||
let constant = BigInt::from(i as u8).pow(BigUint::from(7u8)) ^ BigInt::from(42u8); | ||
constants.push(constant); | ||
} | ||
|
||
let output = BigInt::from_str("95224774355499767951968048714566316597785297695903697235130434363122555476056").unwrap(); | ||
|
||
match verify_mimc_proof(BigInt::from(3u8), 2usize.pow(LOG_STEPS as u32), &constants, output, stark_proof, &modulus) { | ||
true => types::Bytes32 { bytes: [0u8; 32] }, | ||
false => types::Bytes32 { bytes: [1u8; 32] } | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn main() { | ||
let pre_state_root = eth2::load_pre_state_root(); | ||
let block_data = eth2::acquire_block_data(); | ||
let post_state_root = process_block(pre_state_root, &block_data); | ||
eth2::save_post_state_root(post_state_root) | ||
} |