-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add STARK Verification Example #22
Open
jwasinger
wants to merge
1
commit into
ewasm:master
Choose a base branch
from
jwasinger:mimc-stark
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These look like constants. You should precompute these and place them as data.