Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bench_vs/lambda/recursion/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 29 additions & 7 deletions bench_vs/lambda/recursion/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//! Naive recursion guest: verifies an inner lambda-vm proof inside the VM.
//!
//! Private input layout (postcard-encoded):
//! `(VmProof, Vec<u8>, ProofOptions)`
//! `(VmProof, Vec<u8>, ProofOptions, VmVerifyingKey)`
//! where the `Vec<u8>` holds the inner program's ELF bytes and `ProofOptions`
//! specifies the parameters the inner prover used. Commits `[1]` on success.
//! specifies the parameters the inner prover used. On success commits a
//! postcard-encoded [`RecursionCommitment`]: every input here is
//! prover-supplied, so soundness comes from an outer verifier passing it to
//! `verify_recursion_commitment` with the trusted inner ELF.
//!
//! Not `no_std` (std/alloc are available — `build-std` provides them, and the
//! prover links as a normal std crate; its prove-side code is dead-code
Expand All @@ -14,7 +17,7 @@

#![no_main]

use lambda_vm_prover::{ProofOptions, VmProof};
use lambda_vm_prover::{ProofOptions, RecursionCommitment, VmProof, VmVerifyingKey};

#[unsafe(export_name = "main")]
pub fn main() -> ! {
Expand All @@ -29,16 +32,35 @@ pub fn main() -> ! {
}));

let blob = lambda_vm_syscalls::syscalls::get_private_input();
let (vm_proof, inner_elf, options): (VmProof, Vec<u8>, ProofOptions) =
let (vm_proof, inner_elf, options, vkey): (VmProof, Vec<u8>, ProofOptions, VmVerifyingKey) =
postcard::from_bytes(&blob).expect("failed to deserialize recursion input");
lambda_vm_prover::profile_markers::step_marker::<
{ lambda_vm_prover::profile_markers::STEP_DECODE_DONE },
>();

let ok = lambda_vm_prover::verify_with_options(&vm_proof, &inner_elf, &options, None, None)
.expect("verify errored");
let ok = lambda_vm_prover::verify_with_options_with_vkey(
&vm_proof,
&inner_elf,
&options,
None,
None,
Some(&vkey),
)
.expect("verify errored");
assert!(ok, "inner proof failed verification");

lambda_vm_syscalls::syscalls::commit(&[1u8]);
// `vm_proof.vk_digest` was just checked equal to `vkey.compute_digest()`
// inside verify, so reuse it instead of re-serializing and re-hashing.
let commitment = RecursionCommitment {
elf_digest: lambda_vm_prover::elf_digest(&inner_elf),
vk_digest: vm_proof.vk_digest,
options,
table_counts: vm_proof.table_counts,
num_private_input_pages: vm_proof.num_private_input_pages,
runtime_page_ranges: vm_proof.runtime_page_ranges,
public_output: vm_proof.public_output,
};
let output = postcard::to_allocvec(&commitment).expect("failed to serialize commitment");
lambda_vm_syscalls::syscalls::commit(&output);
lambda_vm_syscalls::syscalls::sys_halt();
}
2 changes: 1 addition & 1 deletion crypto/stark/src/proof/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl fmt::Display for ProofOptionsError {
/// - `coset_offset`: the offset for the coset
/// - `grinding_factor`: the number of leading zeros that we want for the Hash(hash || nonce)
#[cfg_attr(feature = "wasm", wasm_bindgen)]
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct ProofOptions {
pub blowup_factor: u8,
pub fri_number_of_queries: usize,
Expand Down
1 change: 1 addition & 0 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ rayon = { version = "1.8.0", optional = true }
sysinfo = { version = "0.31", default-features = false, features = ["system"] }
log = "0.4"
sha3 = { version = "0.10.8", default-features = false }
postcard = { version = "1.0", default-features = false, features = ["alloc"] }

[dev-dependencies]
env_logger = "*"
Expand Down
Loading
Loading