Skip to content

Commit

Permalink
remove Alpha-specific examples, making LEM the norm (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino authored Nov 1, 2023
1 parent 062a427 commit ee75928
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 279 deletions.
22 changes: 9 additions & 13 deletions examples/sha256_ivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter, Registry};
use tracing_texray::TeXRayLayer;

use lurk::{
circuit::circuit_frame::MultiFrame,
coprocessor::sha256::{Sha256Coproc, Sha256Coprocessor},
eval::{empty_sym_env, lang::Lang},
eval::lang::Lang,
field::LurkField,
lem::{multiframe::MultiFrame, pointers::Ptr, store::Store},
proof::{nova::NovaProver, Prover},
ptr::Ptr,
public_parameters::{
instance::{Instance, Kind},
public_params,
},
state::user_sym,
store::Store,
};

const REDUCTION_COUNT: usize = 10;
Expand Down Expand Up @@ -48,7 +46,7 @@ fn sha256_ivc<F: LurkField>(store: &Store<F>, n: usize, input: &[usize]) -> Ptr<
"#
);

store.read(&program).unwrap()
store.read_with_default_state(&program).unwrap()
}

/// Run the example in this file with
Expand All @@ -62,17 +60,15 @@ fn main() {
tracing::subscriber::set_global_default(subscriber).unwrap();

let args = std::env::args().collect::<Vec<_>>();
let n = args[1].parse().unwrap();
let n = args.get(1).unwrap_or(&"1".into()).parse().unwrap();

let store = &mut Store::<Fr>::new();
let store = &Store::<Fr>::default();
let cproc_sym = user_sym(&format!("sha256_ivc_{n}"));

let call = sha256_ivc(store, n, &(0..n).collect::<Vec<_>>());

let lang = Lang::<Fr, Sha256Coproc<Fr>>::new_with_bindings(
store,
vec![(cproc_sym, Sha256Coprocessor::new(n).into())],
);
let mut lang = Lang::<Fr, Sha256Coproc<Fr>>::new();
lang.add_coprocessor_lem(cproc_sym, Sha256Coprocessor::new(n), store);
let lang_rc = Arc::new(lang.clone());

let nova_prover =
Expand All @@ -97,7 +93,7 @@ fn main() {
let (proof, z0, zi, num_steps) = tracing_texray::examine(tracing::info_span!("bang!"))
.in_scope(|| {
nova_prover
.evaluate_and_prove(&pp, call, empty_sym_env(store), store, 10000, &lang_rc)
.evaluate_and_prove(&pp, call, store.intern_nil(), store, 10000, &lang_rc)
.unwrap()
});
let proof_end = proof_start.elapsed();
Expand All @@ -114,7 +110,7 @@ fn main() {

if res {
println!(
"Congratulations! You proved and verified a SHA256 hash calculation in {:?} time!",
"Congratulations! You proved and verified a IVC SHA256 hash calculation in {:?} time!",
pp_end + proof_end + verify_end
);
}
Expand Down
117 changes: 0 additions & 117 deletions examples/sha256_ivc_lem.rs

This file was deleted.

28 changes: 16 additions & 12 deletions examples/sha256_nivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter, Registry};
use tracing_texray::TeXRayLayer;

use lurk::{
circuit::circuit_frame::MultiFrame,
coprocessor::sha256::{Sha256Coproc, Sha256Coprocessor},
eval::{empty_sym_env, lang::Lang},
eval::lang::Lang,
field::LurkField,
lem::{
eval::{evaluate, make_eval_step_from_lang},
multiframe::MultiFrame,
pointers::Ptr,
store::Store,
},
proof::{supernova::SuperNovaProver, Prover},
ptr::Ptr,
public_parameters::{
instance::{Instance, Kind},
supernova_public_params,
},
state::user_sym,
store::Store,
};

const REDUCTION_COUNT: usize = 10;

fn sha256_nivc<F: LurkField>(store: &mut Store<F>, n: usize, input: &[usize]) -> Ptr<F> {
fn sha256_nivc<F: LurkField>(store: &Store<F>, n: usize, input: &[usize]) -> Ptr<F> {
assert_eq!(n, input.len());
let input = input
.iter()
Expand Down Expand Up @@ -48,7 +51,7 @@ fn sha256_nivc<F: LurkField>(store: &mut Store<F>, n: usize, input: &[usize]) ->
"#
);

store.read(&program).unwrap()
store.read_with_default_state(&program).unwrap()
}

/// Run the example in this file with
Expand All @@ -64,17 +67,18 @@ fn main() {
let args = std::env::args().collect::<Vec<_>>();
let n = args.get(1).unwrap_or(&"1".into()).parse().unwrap();

let store = &mut Store::<Fr>::new();
let store = &Store::<Fr>::default();
let cproc_sym = user_sym(&format!("sha256_nivc_{n}"));

let call = sha256_nivc(store, n, &(0..n).collect::<Vec<_>>());

let lang = Lang::<Fr, Sha256Coproc<Fr>>::new_with_bindings(
store,
vec![(cproc_sym, Sha256Coprocessor::new(n).into())],
);
let mut lang = Lang::<Fr, Sha256Coproc<Fr>>::new();
lang.add_coprocessor_lem(cproc_sym, Sha256Coprocessor::new(n), store);
let lang_rc = Arc::new(lang.clone());

let lurk_step = make_eval_step_from_lang(&lang, false);
let (frames, _) = evaluate(Some((&lurk_step, &lang)), call, store, 1000).unwrap();

let supernova_prover =
SuperNovaProver::<Fr, Sha256Coproc<Fr>, MultiFrame<'_, _, _>>::new(REDUCTION_COUNT, lang);

Expand All @@ -97,7 +101,7 @@ fn main() {
let (proof, z0, zi, num_steps, last_circuit_index) =
tracing_texray::examine(tracing::info_span!("bang!")).in_scope(|| {
supernova_prover
.evaluate_and_prove(&pp, call, empty_sym_env(store), store, 10000, lang_rc)
.prove(&pp, &frames, store, lang_rc)
.unwrap()
});
let proof_end = proof_start.elapsed();
Expand Down
127 changes: 0 additions & 127 deletions examples/sha256_nivc_lem.rs

This file was deleted.

Loading

1 comment on commit ee75928

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarks

Table of Contents

Benchmark Results

LEM Prove

Fibonacci-rc=100 Fibonacci-rc=600
num-100 6.82 s (✅ 1.00x) 7.48 s (✅ 1.10x slower)
num-200 14.41 s (✅ 1.00x) 16.68 s (❌ 1.16x slower)

Made with criterion-table

Please sign in to comment.