Skip to content

Commit

Permalink
chore: migrate examples to the Bn256 field
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino committed Feb 7, 2024
1 parent 5fc5679 commit e47a823
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
10 changes: 5 additions & 5 deletions examples/circom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use lurk::circuit::gadgets::pointer::AllocatedPtr;
#[cfg(not(target_arch = "wasm32"))]
use lurk::coprocessor::circom::non_wasm::CircomCoprocessor;

use halo2curves::bn256::Fr as Bn;
use lurk::eval::lang::Lang;
use lurk::field::LurkField;
use lurk::lem::{pointers::Ptr, store::Store};
Expand All @@ -48,7 +49,6 @@ use lurk::public_parameters::{
};
use lurk::Symbol;
use lurk_macros::Coproc;
use pasta_curves::pallas::Scalar as Fr;

const REDUCTION_COUNT: usize = 1;

Expand Down Expand Up @@ -99,17 +99,17 @@ enum Sha256Coproc<F: LurkField> {
/// `cargo run --release -- circom --name sha256_2 examples/sha256/`
/// `cargo run --release --example circom`
fn main() {
let store = &Store::<Fr>::default();
let store = &Store::default();
let sym_str = Symbol::new(&[".circom_sha256_2"], false); // two inputs
let circom_sha256: CircomSha256<Fr> = CircomSha256::new(0);
let mut lang = Lang::<Fr, Sha256Coproc<Fr>>::new();
let circom_sha256: CircomSha256<Bn> = CircomSha256::new(0);
let mut lang = Lang::<Bn, Sha256Coproc<Bn>>::new();
lang.add_coprocessor(sym_str, CircomCoprocessor::new(circom_sha256));
let lang_rc = Arc::new(lang);

let expr = "(.circom_sha256_2)".to_string();
let ptr = store.read_with_default_state(&expr).unwrap();

let nova_prover = NovaProver::<Fr, Sha256Coproc<Fr>>::new(REDUCTION_COUNT, lang_rc.clone());
let nova_prover = NovaProver::<Bn, Sha256Coproc<Bn>>::new(REDUCTION_COUNT, lang_rc.clone());

println!("Setting up public parameters...");

Expand Down
8 changes: 4 additions & 4 deletions examples/sha256_ivc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pasta_curves::pallas::Scalar as Fr;
use halo2curves::bn256::Fr as Bn;
use std::{sync::Arc, time::Instant};
use tracing_subscriber::{fmt, prelude::*, EnvFilter, Registry};
use tracing_texray::TeXRayLayer;
Expand Down Expand Up @@ -62,16 +62,16 @@ fn main() {
let args = std::env::args().collect::<Vec<_>>();
let n = args.get(1).unwrap_or(&"1".into()).parse().unwrap();

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

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

let mut lang = Lang::<Fr, Sha256Coproc<Fr>>::new();
let mut lang = Lang::<Bn, Sha256Coproc<Bn>>::new();
lang.add_coprocessor(cproc_sym, Sha256Coprocessor::new(n));
let lang_rc = Arc::new(lang.clone());

let nova_prover = NovaProver::<Fr, Sha256Coproc<Fr>>::new(REDUCTION_COUNT, lang_rc.clone());
let nova_prover = NovaProver::<Bn, Sha256Coproc<Bn>>::new(REDUCTION_COUNT, lang_rc.clone());

println!("Setting up public parameters (rc = {REDUCTION_COUNT})...");

Expand Down
8 changes: 4 additions & 4 deletions examples/sha256_nivc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pasta_curves::pallas::Scalar as Fr;
use halo2curves::bn256::Fr as Bn;
use std::{sync::Arc, time::Instant};
use tracing_subscriber::{fmt, prelude::*, EnvFilter, Registry};
use tracing_texray::TeXRayLayer;
Expand Down Expand Up @@ -66,12 +66,12 @@ fn main() {
let args = std::env::args().collect::<Vec<_>>();
let n = args.get(1).unwrap_or(&"1".into()).parse().unwrap();

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

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

let mut lang = Lang::<Fr, Sha256Coproc<Fr>>::new();
let mut lang = Lang::<Bn, Sha256Coproc<Bn>>::new();
lang.add_coprocessor(cproc_sym, Sha256Coprocessor::new(n));
let lang_rc = Arc::new(lang.clone());

Expand All @@ -80,7 +80,7 @@ fn main() {
let frames = evaluate(Some((&lurk_step, &cprocs, &lang)), call, store, 1000).unwrap();

let supernova_prover =
SuperNovaProver::<Fr, Sha256Coproc<Fr>>::new(REDUCTION_COUNT, lang_rc.clone());
SuperNovaProver::<Bn, Sha256Coproc<Bn>>::new(REDUCTION_COUNT, lang_rc.clone());

println!("Setting up running claim parameters (rc = {REDUCTION_COUNT})...");
let pp_start = Instant::now();
Expand Down
9 changes: 4 additions & 5 deletions examples/tp_table.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use anyhow::{anyhow, Result};
use ascii_table::{Align, AsciiTable};
use criterion::black_box;
use halo2curves::bn256::Fr as Bn;
use lurk::{
eval::lang::{Coproc, Lang},
lem::{eval::evaluate, store::Store},
proof::nova::{public_params, NovaProver, PublicParams},
};
use num_traits::ToPrimitive;
use pasta_curves::pallas::Scalar as Fr;
use statrs::statistics::Statistics;
use std::{cell::OnceCell, sync::Arc, time::Instant};

Expand Down Expand Up @@ -142,7 +142,6 @@ fn n_folds_env() -> Result<usize> {
/// │ 16 │ 59.38±0.83 │ 56.42±0.63 │
/// └────────────┴────────────┴────────────┘
/// ```
/// The first table
fn main() {
let rc_vec = rc_env().unwrap_or_else(|_| vec![100]);
let max_n_folds = n_folds_env().unwrap_or(3);
Expand All @@ -152,12 +151,12 @@ fn main() {

let limit = n_iters(max_n_folds, *max_rc);

let store = Store::<Fr>::default();
let store = Store::default();
let program = store.read_with_default_state(PROGRAM).unwrap();

let frames = evaluate::<Fr, Coproc<Fr>>(None, program, &store, limit).unwrap();
let frames = evaluate::<Bn, Coproc<Bn>>(None, program, &store, limit).unwrap();

let lang = Lang::<Fr>::new();
let lang = Lang::<Bn>::new();
let lang_arc = Arc::new(lang.clone());

let mut data = Vec::with_capacity(rc_vec.len());
Expand Down

0 comments on commit e47a823

Please sign in to comment.