Skip to content

Commit

Permalink
Chore: generalize the REPL's Lang
Browse files Browse the repository at this point in the history
* Remove hardcoded Coproc occurrences from the REPL implementation
* Use Coproc on the top-level call
* Fix a non-generalized leftover from #1017
  • Loading branch information
arthurpaulino committed Jan 5, 2024
1 parent bc13609 commit dbdeacf
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 125 deletions.
9 changes: 5 additions & 4 deletions benches/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use lurk::{
eval::lang::Lang,
field::LurkField,
lem::{
eval::{evaluate, make_eval_step_from_config, EvalConfig},
eval::{evaluate, make_cprocs_funcs_from_lang, make_eval_step_from_config, EvalConfig},
multiframe::MultiFrame,
pointers::Ptr,
store::Store,
Expand Down Expand Up @@ -134,7 +134,7 @@ fn sha256_ivc_prove<M: measurement::Measurement>(

let prover = NovaProver::new(prove_params.reduction_count, lang_rc.clone());

let frames = &evaluate(Some((&lurk_step, &lang)), ptr, store, limit).unwrap();
let frames = &evaluate(Some((&lurk_step, &[], &lang)), ptr, store, limit).unwrap();

b.iter_batched(
|| frames,
Expand Down Expand Up @@ -215,7 +215,7 @@ fn sha256_ivc_prove_compressed<M: measurement::Measurement>(

let prover = NovaProver::new(prove_params.reduction_count, lang_rc.clone());

let frames = &evaluate(Some((&lurk_step, &lang)), ptr, store, limit).unwrap();
let frames = &evaluate(Some((&lurk_step, &[], &lang)), ptr, store, limit).unwrap();

b.iter_batched(
|| frames,
Expand Down Expand Up @@ -274,6 +274,7 @@ fn sha256_nivc_prove<M: measurement::Measurement>(
let lang_rc = Arc::new(lang.clone());

let lurk_step = make_eval_step_from_config(&EvalConfig::new_ivc(&lang));
let cprocs = make_cprocs_funcs_from_lang(&lang);

// use cached public params
let instance = Instance::new(
Expand All @@ -298,7 +299,7 @@ fn sha256_nivc_prove<M: measurement::Measurement>(

let prover = SuperNovaProver::new(prove_params.reduction_count, lang_rc.clone());

let frames = &evaluate(Some((&lurk_step, &lang)), ptr, store, limit).unwrap();
let frames = &evaluate(Some((&lurk_step, &cprocs, &lang)), ptr, store, limit).unwrap();

b.iter_batched(
|| frames,
Expand Down
5 changes: 3 additions & 2 deletions examples/sha256_nivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use lurk::{
eval::lang::Lang,
field::LurkField,
lem::{
eval::{evaluate, make_eval_step_from_config, EvalConfig},
eval::{evaluate, make_cprocs_funcs_from_lang, make_eval_step_from_config, EvalConfig},
multiframe::MultiFrame,
pointers::Ptr,
store::Store,
Expand Down Expand Up @@ -77,7 +77,8 @@ fn main() {
let lang_rc = Arc::new(lang.clone());

let lurk_step = make_eval_step_from_config(&EvalConfig::new_nivc(&lang));
let frames = evaluate(Some((&lurk_step, &lang)), call, store, 1000).unwrap();
let cprocs = make_cprocs_funcs_from_lang(&lang);
let frames = evaluate(Some((&lurk_step, &cprocs, &lang)), call, store, 1000).unwrap();

let supernova_prover = SuperNovaProver::<Fr, Sha256Coproc<Fr>, MultiFrame<'_, _, _>>::new(
REDUCTION_COUNT,
Expand Down
53 changes: 41 additions & 12 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{
};

use crate::{
eval::lang::Coproc,
eval::lang::{Coproc, Lang},
field::{LanguageField, LurkField},
lem::{multiframe::MultiFrame, store::Store},
public_parameters::disk_cache::public_params_dir,
Expand Down Expand Up @@ -94,7 +94,7 @@ struct LoadArgs {
#[clap(long, value_enum)]
backend: Option<Backend>,

/// Arithmetic field (defaults to the backend's standard field)
/// Arithmetic field (defaults to "Pallas")
#[clap(long, value_enum)]
field: Option<LanguageField>,

Expand Down Expand Up @@ -207,7 +207,7 @@ struct ReplArgs {
#[clap(long, value_enum)]
backend: Option<Backend>,

/// Arithmetic field (defaults to the backend's standard field)
/// Arithmetic field (defaults to "Pallas")
#[clap(long, value_enum)]
field: Option<LanguageField>,

Expand Down Expand Up @@ -305,7 +305,9 @@ fn get_store<F: LurkField + for<'a> serde::de::Deserialize<'a>>(
macro_rules! new_repl {
( $cli: expr, $rc: expr, $limit: expr, $field: path, $backend: expr ) => {{
let store = get_store(&$cli.zstore).with_context(|| "reading store from file")?;
Repl::<$field>::new(store, $rc, $limit, $backend)
// TODO: pick a predefined `Lang` according to a CLI parameter
let lang = Lang::new();
Repl::<$field, Coproc<$field>>::new(store, lang, $rc, $limit, $backend)
}};
}

Expand Down Expand Up @@ -420,6 +422,10 @@ struct VerifyArgs {
#[clap(value_parser)]
proof_key: String,

/// Arithmetic field (defaults to "Pallas")
#[clap(long, value_enum)]
field: Option<LanguageField>,

/// Path to public parameters directory
#[clap(long, value_parser)]
public_params_dir: Option<Utf8PathBuf>,
Expand All @@ -439,6 +445,10 @@ struct InspectArgs {
#[clap(value_parser)]
proof_key: String,

/// Arithmetic field (defaults to "Pallas")
#[clap(long, value_enum)]
field: Option<LanguageField>,

/// Flag to show the entire proof meta-data
#[arg(long)]
full: bool,
Expand Down Expand Up @@ -593,9 +603,20 @@ impl Cli {
}
cli_config(verify_args.config.as_ref(), Some(&cli_settings));

LurkProof::<_, _, MultiFrame<'_, _, Coproc<pallas::Scalar>>>::verify_proof(
&verify_args.proof_key,
)
// TODO: pick a predefined `Lang` according to a CLI parameter
match verify_args.field.unwrap_or_default() {
LanguageField::BN256 => {
LurkProof::<_, _, MultiFrame<'_, _, Coproc<bn256::Fr>>>::verify_proof(
&verify_args.proof_key,
)
}
LanguageField::Pallas => {
LurkProof::<_, _, MultiFrame<'_, _, Coproc<pallas::Scalar>>>::verify_proof(
&verify_args.proof_key,
)
}
_ => unreachable!(),
}
}
#[allow(unused_variables)]
Command::Inspect(inspect_args) => {
Expand All @@ -606,11 +627,19 @@ impl Cli {
}
cli_config(None, Some(&cli_settings));

LurkProofMeta::<pallas::Scalar>::inspect_proof(
&inspect_args.proof_key,
None,
inspect_args.full,
)
match inspect_args.field.unwrap_or_default() {
LanguageField::BN256 => LurkProofMeta::<bn256::Fr>::inspect_proof(
&inspect_args.proof_key,
None,
inspect_args.full,
),
LanguageField::Pallas => LurkProofMeta::<pallas::Scalar>::inspect_proof(
&inspect_args.proof_key,
None,
inspect_args.full,
),
_ => unreachable!(),
}
}
Command::Circom(circom_args) => {
use crate::cli::circom::create_circom_gadget;
Expand Down
Loading

0 comments on commit dbdeacf

Please sign in to comment.