-
Notifications
You must be signed in to change notification settings - Fork 59
feat: ability to verify e2e STARK proof + CLI command #1689
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
base: feat/prove-default-name
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use std::{fs::read, marker::PhantomData, path::Path, sync::Arc}; | ||
use std::{borrow::Borrow, fs::read, marker::PhantomData, path::Path, sync::Arc}; | ||
|
||
#[cfg(feature = "evm-verify")] | ||
use alloy_sol_types::sol; | ||
|
@@ -11,16 +11,19 @@ use openvm_build::{ | |
}; | ||
use openvm_circuit::{ | ||
arch::{ | ||
hasher::poseidon2::vm_poseidon2_hasher, instructions::exe::VmExe, verify_segments, | ||
ContinuationVmProof, ExecutionError, InitFileGenerator, VerifiedExecutionPayload, VmConfig, | ||
VmExecutor, VmVerificationError, | ||
hasher::{poseidon2::vm_poseidon2_hasher, Hasher}, | ||
instructions::exe::VmExe, | ||
verify_segments, ContinuationVmProof, ExecutionError, InitFileGenerator, | ||
VerifiedExecutionPayload, VmConfig, VmExecutor, PROGRAM_CACHED_TRACE_INDEX, | ||
PUBLIC_VALUES_AIR_ID, | ||
}, | ||
system::{ | ||
memory::{tree::public_values::extract_public_values, CHUNK}, | ||
program::trace::VmCommittedExe, | ||
program::trace::{compute_exe_commit, VmCommittedExe}, | ||
}, | ||
}; | ||
use openvm_continuations::verifier::{ | ||
common::types::VmVerifierPvs, | ||
internal::types::VmStarkProof, | ||
root::{types::RootVmVerifierInput, RootVmVerifierConfig}, | ||
}; | ||
|
@@ -33,7 +36,7 @@ use openvm_stark_backend::proof::Proof; | |
use openvm_stark_sdk::{ | ||
config::{baby_bear_poseidon2::BabyBearPoseidon2Engine, FriParameters}, | ||
engine::StarkFriEngine, | ||
openvm_stark_backend::{verifier::VerificationError, Chip}, | ||
openvm_stark_backend::Chip, | ||
}; | ||
use openvm_transpiler::{ | ||
elf::Elf, | ||
|
@@ -228,7 +231,7 @@ impl<E: StarkFriEngine<SC>> GenericSdk<E> { | |
&self, | ||
app_vk: &AppVerifyingKey, | ||
proof: &ContinuationVmProof<SC>, | ||
) -> Result<VerifiedContinuationVmPayload, VmVerificationError> { | ||
) -> Result<VerifiedContinuationVmPayload> { | ||
let engine = E::new(app_vk.fri_params); | ||
let VerifiedExecutionPayload { | ||
exe_commit, | ||
|
@@ -250,9 +253,10 @@ impl<E: StarkFriEngine<SC>> GenericSdk<E> { | |
&self, | ||
app_vk: &AppVerifyingKey, | ||
proof: &Proof<SC>, | ||
) -> Result<(), VerificationError> { | ||
) -> Result<()> { | ||
let e = E::new(app_vk.fri_params); | ||
e.verify(&app_vk.app_vm_vk, proof) | ||
e.verify(&app_vk.app_vm_vk, proof)?; | ||
Ok(()) | ||
} | ||
|
||
pub fn agg_keygen( | ||
|
@@ -322,6 +326,51 @@ impl<E: StarkFriEngine<SC>> GenericSdk<E> { | |
Ok(proof) | ||
} | ||
|
||
pub fn verify_e2e_stark_proof( | ||
&self, | ||
agg_stark_pk: AggStarkProvingKey, | ||
proof: &VmStarkProof<SC>, | ||
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. Pass a reference instead of a value. |
||
) -> Result<[F; CHUNK]> { | ||
let program_commit = | ||
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. Return |
||
proof.proof.commitments.main_trace[PROGRAM_CACHED_TRACE_INDEX].as_ref(); | ||
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. Check if all required AIRs are present. Otherwise |
||
let internal_commit: &[_; CHUNK] = &agg_stark_pk | ||
.internal_committed_exe | ||
.get_program_commit() | ||
.into(); | ||
|
||
let vm_pk = if program_commit == internal_commit { | ||
&agg_stark_pk.internal_vm_pk | ||
} else { | ||
&agg_stark_pk.leaf_vm_pk | ||
}; | ||
let e = E::new(vm_pk.fri_params); | ||
e.verify(&vm_pk.vm_pk.get_vk(), &proof.proof)?; | ||
|
||
let public_values_air_proof_data = proof | ||
.proof | ||
.per_air | ||
.iter() | ||
.find(|p| p.air_id == PUBLIC_VALUES_AIR_ID) | ||
.unwrap(); | ||
let pvs: &VmVerifierPvs<_> = | ||
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. Since this function returns a |
||
public_values_air_proof_data.public_values[..VmVerifierPvs::<u8>::width()].borrow(); | ||
|
||
let hasher = vm_poseidon2_hasher(); | ||
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. Check if program terminates with exit code = 0. |
||
let public_values_root = hasher.merkle_root(&proof.user_public_values); | ||
if public_values_root != pvs.public_values_commit { | ||
return Err(eyre::eyre!( | ||
"Invalid public values root: expected {:?}, got {:?}", | ||
pvs.public_values_commit, | ||
public_values_root | ||
)); | ||
} | ||
|
||
let start_pc = pvs.connector.initial_pc; | ||
let initial_memory_root = &pvs.memory.initial_root; | ||
let exe_commit = compute_exe_commit(&hasher, program_commit, initial_memory_root, start_pc); | ||
Ok(exe_commit) | ||
} | ||
|
||
#[cfg(feature = "evm-prove")] | ||
pub fn generate_evm_proof<VC: VmConfig<F>>( | ||
&self, | ||
|
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.
Taking
openvm/crates/vm/src/arch/vm.rs
Line 735 in 4da0af9