-
Notifications
You must be signed in to change notification settings - Fork 59
feat: Macro define_verify_openvm_stark #1620
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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,4 @@ | ||
*.asm | ||
Cargo.lock | ||
target/ | ||
openvm/ |
This file contains hidden or 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,18 @@ | ||
[workspace] | ||
[package] | ||
name = "openvm-verify-stark-program" | ||
version = "0.0.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
openvm = { path = "../../../toolchain/openvm", features = ["std"] } | ||
hex-literal = { version = "0.4.1", default-features = false } | ||
bytemuck = { version = "1.20.0", features = ["extern_crate_alloc"] } | ||
|
||
[features] | ||
default = [] | ||
|
||
[profile.profiling] | ||
inherits = "release" | ||
debug = 2 | ||
strip = false |
This file contains hidden or 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,24 @@ | ||
extern crate alloc; | ||
use alloc::vec::Vec; | ||
|
||
use openvm::{define_verify_openvm_stark, io::read}; | ||
|
||
define_verify_openvm_stark!( | ||
verify_openvm_stark, | ||
env!("CARGO_MANIFEST_DIR"), | ||
"root_verifier.asm" | ||
); | ||
|
||
// const APP_EXE_COMMIT: [u32; 8] = [ | ||
// 343014587, 230645511, 1447462186, 773379336, 1182270030, 1497892484, 461820702, 353704350, | ||
// ]; | ||
// const APP_VM_COMMIT: [u32; 8] = [ | ||
// 445134834, 1133596793, 530952192, 425228715, 1806903712, 1362083369, 295028151, 482389308, | ||
// ]; | ||
|
||
pub fn main() { | ||
let app_exe_commit: [u32; 8] = read(); | ||
let app_vm_commit: [u32; 8] = read(); | ||
let pvs: Vec<u32> = read(); | ||
verify_openvm_stark(&app_exe_commit, &app_vm_commit, &pvs); | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -6,6 +6,7 @@ use openvm_circuit::{ | |
arch::{ | ||
hasher::poseidon2::vm_poseidon2_hasher, ContinuationVmProof, ExecutionError, | ||
GenerationError, SingleSegmentVmExecutor, SystemConfig, VmConfig, VmExecutor, | ||
DEFAULT_MAX_NUM_PUBLIC_VALUES, | ||
}, | ||
system::{memory::tree::public_values::UserPublicValuesProof, program::trace::VmCommittedExe}, | ||
}; | ||
|
@@ -27,9 +28,11 @@ use openvm_native_recursion::{ | |
wrapper::Halo2WrapperProvingKey, | ||
RawEvmProof, | ||
}, | ||
hints::Hintable, | ||
types::InnerConfig, | ||
vars::StarkProofVariable, | ||
}; | ||
use openvm_rv32im_guest::hint_load_by_key_encode; | ||
use openvm_rv32im_transpiler::{ | ||
Rv32ITranspilerExtension, Rv32IoTranspilerExtension, Rv32MTranspilerExtension, | ||
}; | ||
|
@@ -41,7 +44,9 @@ use openvm_sdk::{ | |
types::{EvmHalo2Verifier, EvmProof}, | ||
DefaultStaticVerifierPvHandler, Sdk, StdIn, | ||
}; | ||
use openvm_stark_backend::{keygen::types::LinearConstraint, p3_matrix::Matrix}; | ||
use openvm_stark_backend::{ | ||
keygen::types::LinearConstraint, p3_field::PrimeField32, p3_matrix::Matrix, | ||
}; | ||
use openvm_stark_sdk::{ | ||
config::{ | ||
baby_bear_poseidon2::{BabyBearPoseidon2Config, BabyBearPoseidon2Engine}, | ||
|
@@ -393,7 +398,7 @@ fn test_static_verifier_custom_pv_handler() { | |
#[test] | ||
fn test_e2e_proof_generation_and_verification_with_pvs() { | ||
let mut pkg_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).to_path_buf(); | ||
pkg_dir.push("guest"); | ||
pkg_dir.push("guest/fib"); | ||
|
||
let vm_config = SdkVmConfig::builder() | ||
.system(SdkSystemConfig { | ||
|
@@ -463,7 +468,7 @@ fn test_sdk_guest_build_and_transpile() { | |
// .with_options(vec!["--release"]); | ||
; | ||
let mut pkg_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).to_path_buf(); | ||
pkg_dir.push("guest"); | ||
pkg_dir.push("guest/fib"); | ||
let one = sdk | ||
.build(guest_opts.clone(), &pkg_dir, &Default::default()) | ||
.unwrap(); | ||
|
@@ -484,7 +489,7 @@ fn test_inner_proof_codec_roundtrip() -> eyre::Result<()> { | |
// generate a proof | ||
let sdk = Sdk::new(); | ||
let mut pkg_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).to_path_buf(); | ||
pkg_dir.push("guest"); | ||
pkg_dir.push("guest/fib"); | ||
let elf = sdk.build(Default::default(), pkg_dir, &Default::default())?; | ||
|
||
let vm_config = SdkVmConfig::builder() | ||
|
@@ -574,11 +579,109 @@ fn test_segmentation_retry() { | |
.sum(); | ||
assert!(new_total_height < total_height); | ||
} | ||
|
||
#[test] | ||
fn test_root_verifier_asm_generate() { | ||
let agg_stark_config = agg_stark_config_for_test(); | ||
let agg_pk = AggStarkProvingKey::keygen(agg_stark_config); | ||
fn test_verify_openvm_stark_e2e() -> Result<()> { | ||
const ASM_FILENAME: &str = "root_verifier.asm"; | ||
let sdk = Sdk::new(); | ||
sdk.generate_root_verifier_asm(&agg_pk); | ||
let guest_opts = GuestOptions::default(); | ||
let mut pkg_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).to_path_buf(); | ||
pkg_dir.push("guest/fib"); | ||
let elf = sdk.build(guest_opts.clone(), &pkg_dir, &Default::default())?; | ||
|
||
let vm_config = SdkVmConfig::builder() | ||
.system(SdkSystemConfig { | ||
config: SystemConfig::default().with_continuations(), | ||
}) | ||
.rv32i(Default::default()) | ||
.rv32m(Default::default()) | ||
.io(Default::default()) | ||
.native(Default::default()) | ||
.build(); | ||
assert!(vm_config.system.config.continuation_enabled); | ||
|
||
let app_exe = sdk.transpile(elf, vm_config.transpiler())?; | ||
let fri_params = FriParameters::new_for_testing(LEAF_LOG_BLOWUP); | ||
let app_config = AppConfig::new_with_leaf_fri_params(fri_params, vm_config.clone(), fri_params); | ||
|
||
let app_pk = sdk.app_keygen(app_config.clone())?; | ||
let committed_app_exe = sdk.commit_app_exe(fri_params, app_exe.clone())?; | ||
|
||
let commits = | ||
AppExecutionCommit::compute(&vm_config, &committed_app_exe, &app_pk.leaf_committed_exe); | ||
|
||
let agg_pk = AggStarkProvingKey::keygen(AggStarkConfig { | ||
max_num_user_public_values: DEFAULT_MAX_NUM_PUBLIC_VALUES, | ||
leaf_fri_params: FriParameters::new_for_testing(LEAF_LOG_BLOWUP), | ||
internal_fri_params: FriParameters::new_for_testing(INTERNAL_LOG_BLOWUP), | ||
root_fri_params: FriParameters::new_for_testing(ROOT_LOG_BLOWUP), | ||
profiling: false, | ||
compiler_options: CompilerOptions { | ||
enable_cycle_tracker: true, | ||
..Default::default() | ||
}, | ||
root_max_constraint_degree: (1 << ROOT_LOG_BLOWUP) + 1, | ||
}); | ||
let asm = sdk.generate_root_verifier_asm(&agg_pk); | ||
let asm_path = format!( | ||
"{}/guest/verify_openvm_stark/{}", | ||
env!("CARGO_MANIFEST_DIR"), | ||
ASM_FILENAME | ||
); | ||
std::fs::write(asm_path, asm)?; | ||
|
||
let e2e_stark_proof = sdk.generate_e2e_stark_proof( | ||
Arc::new(app_pk), | ||
committed_app_exe, | ||
agg_pk, | ||
StdIn::default(), | ||
)?; | ||
|
||
let verify_exe = { | ||
let mut pkg_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).to_path_buf(); | ||
pkg_dir.push("guest/verify_openvm_stark"); | ||
let elf = sdk.build(guest_opts.clone(), &pkg_dir, &Default::default())?; | ||
sdk.transpile(elf, vm_config.transpiler())? | ||
}; | ||
|
||
let pvs = [13u32, 21, 0, 0, 0, 0, 0, 0]; | ||
|
||
let exe_commit_u32: Vec<_> = commits | ||
.exe_commit | ||
.iter() | ||
.map(|x| x.as_canonical_u32()) | ||
.collect(); | ||
let vm_commit_u32: Vec<_> = commits | ||
.leaf_vm_verifier_commit | ||
.iter() | ||
.map(|x| x.as_canonical_u32()) | ||
.collect(); | ||
let pvs_u32: Vec<_> = pvs | ||
.iter() | ||
.flat_map(|x| x.to_le_bytes()) | ||
.map(|x| x as u32) | ||
.collect(); | ||
|
||
let key = ASM_FILENAME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is the filename part of the key? |
||
.as_bytes() | ||
.iter() | ||
.cloned() | ||
.chain(exe_commit_u32.iter().flat_map(|x| x.to_le_bytes())) | ||
.chain(vm_commit_u32.iter().flat_map(|x| x.to_le_bytes())) | ||
.chain(pvs_u32.iter().flat_map(|x| x.to_le_bytes())) | ||
.collect(); | ||
let mut stdin = StdIn::default(); | ||
let to_encode: Vec<Vec<F>> = e2e_stark_proof.proof.write(); | ||
let value = hint_load_by_key_encode(&to_encode); | ||
stdin.add_key_value(key, value); | ||
|
||
let exe_commit_u32_8: [u32; 8] = exe_commit_u32.try_into().unwrap(); | ||
let vm_commit_u32_8: [u32; 8] = vm_commit_u32.try_into().unwrap(); | ||
|
||
stdin.write(&exe_commit_u32_8); | ||
stdin.write(&vm_commit_u32_8); | ||
stdin.write(&pvs_u32); | ||
|
||
sdk.execute(verify_exe, vm_config, stdin)?; | ||
|
||
Ok(()) | ||
} |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.