-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix coprocessors returning lists in SuperNova (#1186)
* Fix coprocessors returning lists in SuperNova In NIVC, the Lurk circuit calls out to the coprocessor circuit, and then on the next fold step calls back into the main Lurk circuit with the result of the coprocessor. If the coprocessor returns a single value, there is no issue, but if the coprocessor returns a list, then the lurk circuit attempts to evaluate that expression instead of simply returning it. To fix it, we wrap the coprocessor return expr with a thunk. * test correctness of a simple coprocessor that returns a list in the NIVC context --------- Co-authored-by: Arthur Paulino <[email protected]>
- Loading branch information
1 parent
5de1e79
commit eaf996c
Showing
8 changed files
with
160 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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,62 @@ | ||
use halo2curves::bn256::Fr; | ||
use std::sync::Arc; | ||
|
||
use crate::{ | ||
eval::lang::Lang, | ||
lem::{ | ||
eval::{evaluate, make_cprocs_funcs_from_lang, make_eval_step_from_config, EvalConfig}, | ||
store::Store, | ||
}, | ||
proof::{supernova::SuperNovaProver, RecursiveSNARKTrait}, | ||
public_parameters::{instance::Instance, supernova_public_params}, | ||
state::user_sym, | ||
}; | ||
|
||
#[test] | ||
fn test_nil_nil_lang() { | ||
use crate::coprocessor::test::NilNil; | ||
let mut lang = Lang::<Fr, NilNil<Fr>>::new(); | ||
lang.add_coprocessor(user_sym("nil-nil"), NilNil::new()); | ||
|
||
let eval_config = EvalConfig::new_nivc(&lang); | ||
let lurk_step = make_eval_step_from_config(&eval_config); | ||
let cprocs = make_cprocs_funcs_from_lang(&lang); | ||
|
||
let store = Store::default(); | ||
let expr = store.read_with_default_state("(nil-nil)").unwrap(); | ||
let frames = evaluate(Some((&lurk_step, &cprocs, &lang)), expr, &store, 50).unwrap(); | ||
|
||
// iteration 1: main circuit sets up a call to the coprocessor | ||
// iteration 2: coprocessor does its job | ||
// iteration 3: main circuit sets termination to terminal | ||
assert_eq!(frames.len(), 3); | ||
|
||
let first_frame = frames.first().unwrap(); | ||
let last_frame = frames.last().unwrap(); | ||
let output = &last_frame.output; | ||
|
||
// the result is the (nil . nil) pair | ||
let nil = store.intern_nil(); | ||
assert!(store.ptr_eq(&output[0], &store.cons(nil, nil))); | ||
|
||
// computation must end with the terminal continuation | ||
assert!(store.ptr_eq(&output[2], &store.cont_terminal())); | ||
|
||
let supernova_prover = SuperNovaProver::new(5, Arc::new(lang)); | ||
let instance = Instance::new_supernova(&supernova_prover, true); | ||
let pp = supernova_public_params(&instance).unwrap(); | ||
|
||
let (proof, ..) = supernova_prover | ||
.prove_from_frames(&pp, &frames, &store) | ||
.unwrap(); | ||
|
||
let input_scalar = store.to_scalar_vector(&first_frame.input); | ||
let output_scalar = store.to_scalar_vector(output); | ||
|
||
// uncompressed proof verifies | ||
assert!(proof.verify(&pp, &input_scalar, &output_scalar).unwrap()); | ||
|
||
// compressed proof verifies | ||
let proof = proof.compress(&pp).unwrap(); | ||
assert!(proof.verify(&pp, &input_scalar, &output_scalar).unwrap()); | ||
} |
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
eaf996c
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.
Benchmarks
Table of Contents
Overview
This benchmark report shows the Fibonacci GPU benchmark.
NVIDIA L4
Intel(R) Xeon(R) CPU @ 2.20GHz
32 vCPUs
125 GB RAM
Workflow run: https://github.com/lurk-lab/lurk-rs/actions/runs/8114883874
Benchmark Results
LEM Fibonacci Prove - rc = 100
ref=5de1e798ca3e8d21642556e135649cc0365bdba4
ref=eaf996c69d0c47c6f316b9359ff144ddcaf17f47
num-100
1.45 s
(✅ 1.00x)1.46 s
(✅ 1.00x slower)num-200
2.77 s
(✅ 1.00x)2.77 s
(✅ 1.00x slower)LEM Fibonacci Prove - rc = 600
ref=5de1e798ca3e8d21642556e135649cc0365bdba4
ref=eaf996c69d0c47c6f316b9359ff144ddcaf17f47
num-100
1.85 s
(✅ 1.00x)1.83 s
(✅ 1.01x faster)num-200
3.04 s
(✅ 1.00x)3.02 s
(✅ 1.01x faster)Made with criterion-table