-
Notifications
You must be signed in to change notification settings - Fork 1
recursion: supply DECODE/page commitments via private input; bind them to the inner ELF via a program_id fold #782
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
Open
Oppen
wants to merge
5
commits into
main
Choose a base branch
from
fix/recursion-precomputed-pages
base: main
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fe26ffd
feat(recursion): pass DECODE/page commitments via private input, comm…
Oppen acf996e
fix(recursion): bind supplied DECODE/page roots to inner ELF via prog…
Oppen 0039f84
fix build
Oppen db2bfa8
remove poc
Oppen 5fc54e6
ci(recursion): build recursion guest ELFs in the test-prover matrix
Oppen 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,98 @@ | ||
| //! Naive recursion guest: verifies an inner lambda-vm proof inside the VM. | ||
| //! | ||
| //! Private input layout (postcard-encoded): | ||
| //! `(VmProof, Vec<u8>, ProofOptions)` | ||
| //! where the `Vec<u8>` holds the inner program's ELF bytes and `ProofOptions` | ||
| //! specifies the parameters the inner prover used. Commits `[1]` on success. | ||
| //! Private input (postcard): `(VmProof, Vec<u8>, Commitment, Vec<(u64, Commitment)>)` | ||
| //! — the inner program's ELF bytes plus its precomputed DECODE and | ||
| //! ELF-data-page commitments, supplied instead of recomputed in-VM. | ||
| //! `verify_with_options` does NOT bind the supplied roots to `inner_elf`; that | ||
| //! binding is established by folding them into `program_id` (below) and having | ||
| //! the host recompute that id and compare. That recompute is expensive, so it | ||
| //! happens once at the top level in the host, never in the guest — see | ||
| //! `program_id` in the prover's `statement` module. | ||
| //! | ||
| //! 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 | ||
| //! eliminated since we only call `verify`). Like every other allocating guest | ||
| //! it is `#![no_main]` and uses the syscalls crate's global allocator (a large | ||
| //! `TlsfHeap`), initialized first thing in `main` — `verify` allocates far more | ||
| //! than the target's default heap provides. | ||
| //! `ProofOptions` is fixed by the `min`/`blowup8` Cargo feature, not private | ||
| //! input (an attacker could otherwise pick trivially weak options and have the | ||
| //! guest accept as if a real proof had been checked). | ||
| //! | ||
| //! On success commits `program_id(inner_elf, decode_commitment, | ||
| //! page_commitments) || inner_public_output` — the program identity (a fold | ||
| //! pinning the ELF together with the roots it was verified against) plus the | ||
| //! result the inner proof attested. | ||
| //! | ||
| //! std (not `no_std`): `build-std` provides it, prove-side code is DCE'd. | ||
| //! `#![no_main]`; inits the syscalls global allocator first thing in `main`. | ||
|
|
||
| #![no_main] | ||
|
|
||
| use lambda_vm_prover::{ProofOptions, VmProof}; | ||
| #[cfg(feature = "blowup8")] | ||
| use lambda_vm_prover::GoldilocksCubicProofOptions; | ||
| use lambda_vm_prover::{Commitment, ProofOptions, VmProof}; | ||
|
|
||
| #[cfg(not(any(feature = "min", feature = "blowup8")))] | ||
| compile_error!("select exactly one of the `min`/`blowup8` features"); | ||
| #[cfg(all(feature = "min", feature = "blowup8"))] | ||
| compile_error!("select exactly one of the `min`/`blowup8` features"); | ||
|
|
||
| /// Smallest possible proof options (blowup=2, 1 query). Intentionally | ||
| /// insecure — for cheap diagnostics, not soundness. | ||
| #[cfg(feature = "min")] | ||
| fn recursion_proof_options() -> ProofOptions { | ||
| ProofOptions { | ||
| blowup_factor: 2, | ||
| fri_number_of_queries: 1, | ||
| coset_offset: 3, | ||
| grinding_factor: 1, | ||
| fri_final_poly_log_degree: 7, | ||
| } | ||
| } | ||
|
|
||
| /// 128-bit security (multi-query). | ||
| #[cfg(feature = "blowup8")] | ||
| fn recursion_proof_options() -> ProofOptions { | ||
| GoldilocksCubicProofOptions::with_blowup(8).expect("blowup=8 is always valid") | ||
| } | ||
|
|
||
| #[unsafe(export_name = "main")] | ||
| pub fn main() -> ! { | ||
| lambda_vm_syscalls::allocator::init_allocator(); | ||
|
|
||
| // Install panic handler to make sure any OOM is because verifying itself is | ||
| // expensive rather than panics causing stack unwinding, which itself is very | ||
| // expensive in the guest. | ||
| // Panic -> sys_panic; unwinding is very expensive in-guest. | ||
| const PANIC_MSG: &str = "PANICKED"; | ||
| std::panic::set_hook(Box::new(|_| unsafe { | ||
| lambda_vm_syscalls::syscalls::sys_panic(PANIC_MSG.as_ptr(), PANIC_MSG.len()) | ||
| })); | ||
|
|
||
| let blob = lambda_vm_syscalls::syscalls::get_private_input(); | ||
| let (vm_proof, inner_elf, options): (VmProof, Vec<u8>, ProofOptions) = | ||
| postcard::from_bytes(&blob).expect("failed to deserialize recursion input"); | ||
| let (vm_proof, inner_elf, decode_commitment, page_commitments): ( | ||
| VmProof, | ||
| Vec<u8>, | ||
| Commitment, | ||
| Vec<(u64, Commitment)>, | ||
| ) = 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 options = recursion_proof_options(); | ||
| let ok = lambda_vm_prover::verify_with_options( | ||
| &vm_proof, | ||
| &inner_elf, | ||
| &options, | ||
| Some(decode_commitment), | ||
| Some(&page_commitments), | ||
| ) | ||
| .expect("verify errored"); | ||
| assert!(ok, "inner proof failed verification"); | ||
|
|
||
| lambda_vm_syscalls::syscalls::commit(&[1u8]); | ||
| // program_id is not self-enforcing: a consumer must recompute it natively | ||
| // and reject on mismatch. Commit the inner output alongside it. | ||
| let id = lambda_vm_prover::statement::program_id_from_elf( | ||
| &inner_elf, | ||
| &decode_commitment, | ||
| &page_commitments, | ||
| ) | ||
| .expect("program_id"); | ||
| let mut output = id.to_vec(); | ||
| output.extend_from_slice(&vm_proof.public_output); | ||
| lambda_vm_syscalls::syscalls::commit(&output); | ||
| lambda_vm_syscalls::syscalls::sys_halt(); | ||
| } |
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.