Skip to content

Commit

Permalink
more API retiring
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino committed Nov 14, 2023
1 parent 89a51db commit d42c1fb
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 699 deletions.
6 changes: 3 additions & 3 deletions benches/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn sha256_ivc_prove<M: measurement::Measurement>(
let cproc_sym = user_sym(&format!("sha256_ivc_{arity}"));

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

let lurk_step = make_eval_step_from_lang(&lang, true);
Expand Down Expand Up @@ -189,7 +189,7 @@ fn sha256_ivc_prove_compressed<M: measurement::Measurement>(
let cproc_sym = user_sym(&format!("sha256_ivc_{arity}"));

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

let lurk_step = make_eval_step_from_lang(&lang, true);
Expand Down Expand Up @@ -274,7 +274,7 @@ fn sha256_nivc_prove<M: measurement::Measurement>(
let cproc_sym = user_sym(&format!("sha256_ivc_{arity}"));

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

let lurk_step = make_eval_step_from_lang(&lang, false);
Expand Down
16 changes: 2 additions & 14 deletions examples/circom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ use lurk::lem::{pointers::Ptr, store::Store};
use lurk::proof::{nova::NovaProver, Prover};
use lurk::public_parameters::instance::{Instance, Kind};
use lurk::public_parameters::public_params;
use lurk::{ptr::Ptr as AlphaPtr, store::Store as AlphaStore};
use lurk::{Num, Symbol};
use lurk::Symbol;
use lurk_macros::Coproc;
use pasta_curves::pallas::Scalar as Fr;

Expand Down Expand Up @@ -79,17 +78,6 @@ impl<F: LurkField> CircomGadget<F> for CircomSha256<F> {
vec![a, b]
}

fn simple_evaluate_alpha(&self, s: &AlphaStore<F>, _args: &[AlphaPtr<F>]) -> AlphaPtr<F> {
// TODO: actually use the lurk inputs
let expected = Num::Scalar(
F::from_str_vartime(
"55165702627807990590530466439275329993482327026534454077267643456",
)
.unwrap(),
);
s.intern_num(expected)
}

fn evaluate_simple(&self, _s: &Store<F>, _args: &[Ptr<F>]) -> Ptr<F> {
// TODO: actually use the lurk inputs
Ptr::num(
Expand All @@ -114,7 +102,7 @@ fn main() {
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();
lang.add_coprocessor(sym_str, CircomCoprocessor::new(circom_sha256), store);
lang.add_coprocessor(sym_str, CircomCoprocessor::new(circom_sha256));

let expr = "(.circom_sha256_2)".to_string();
let ptr = store.read_with_default_state(&expr).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/sha256_ivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn main() {
let call = sha256_ivc(store, n, &(0..n).collect::<Vec<_>>());

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

let nova_prover =
Expand Down
2 changes: 1 addition & 1 deletion examples/sha256_nivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn main() {
let call = sha256_nivc(store, n, &(0..n).collect::<Vec<_>>());

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

let lurk_step = make_eval_step_from_lang(&lang, false);
Expand Down
66 changes: 0 additions & 66 deletions lurk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@ pub fn derive_enum_coproc(input: TokenStream) -> TokenStream {

fn impl_enum_coproc(name: &Ident, variants: &DataEnum) -> TokenStream {
let eval_arity_arms = eval_arity_match_arms(name, variants);
let evaluate_alpha_arms = evaluate_alpha_match_arms(name, variants);
let simple_evaluate_alpha_arms = simple_evaluate_alpha_match_arms(name, variants);
let evaluate_internal_arms = evaluate_internal_match_arms(name, variants);
let evaluate_arms = evaluate_match_arms(name, variants);
let evaluate_simple_arms = evaluate_simple_match_arms(name, variants);
let has_circuit_arms = has_circuit_match_arms(name, variants);

let arity_arms = arity_match_arms(name, variants);
let synthesize_alpha_arms = synthesize_alpha_match_arms(name, variants);
let synthesize_internal_arms = synthesize_internal_match_arms(name, variants);
let synthesize_arms = synthesize_match_arms(name, variants);
let synthesize_simple_arms = synthesize_simple_match_arms(name, variants);
Expand All @@ -56,18 +53,6 @@ fn impl_enum_coproc(name: &Ident, variants: &DataEnum) -> TokenStream {
}
}

fn evaluate_alpha(&self, s: &lurk::store::Store<F>, args: lurk::ptr::Ptr<F>, env: lurk::ptr::Ptr<F>, cont: lurk::ptr::ContPtr<F>) -> lurk::eval::IO<F> {
match self {
#evaluate_alpha_arms
}
}

fn simple_evaluate_alpha(&self, s: &lurk::store::Store<F>, args: &[lurk::ptr::Ptr<F>]) -> lurk::ptr::Ptr<F> {
match self {
#simple_evaluate_alpha_arms
}
}

fn evaluate_internal(&self, s: &lurk::lem::store::Store<F>, ptrs: &[lurk::lem::pointers::Ptr<F>]) -> Vec<lurk::lem::pointers::Ptr<F>> {
match self {
#evaluate_internal_arms
Expand Down Expand Up @@ -100,21 +85,6 @@ fn impl_enum_coproc(name: &Ident, variants: &DataEnum) -> TokenStream {
}
}

fn synthesize_alpha<CS: bellpepper_core::ConstraintSystem<F>>(
&self,
cs: &mut CS,
g: &lurk::circuit::gadgets::data::GlobalAllocations<F>,
store: &lurk::store::Store<F>,
input_exprs: &[lurk::circuit::gadgets::pointer::AllocatedPtr<F>],
input_env: &lurk::circuit::gadgets::pointer::AllocatedPtr<F>,
input_cont: &lurk::circuit::gadgets::pointer::AllocatedContPtr<F>,
not_dummy: &bellpepper::gadgets::boolean::Boolean,
) -> Result<(lurk::circuit::gadgets::pointer::AllocatedPtr<F>, lurk::circuit::gadgets::pointer::AllocatedPtr<F>, lurk::circuit::gadgets::pointer::AllocatedContPtr<F>), bellpepper_core::SynthesisError> {
match self {
#synthesize_alpha_arms
}
}

fn synthesize_internal<CS: bellpepper_core::ConstraintSystem<F>>(
&self,
cs: &mut CS,
Expand Down Expand Up @@ -174,30 +144,6 @@ fn eval_arity_match_arms(name: &Ident, variants: &DataEnum) -> proc_macro2::Toke
match_arms
}

fn evaluate_alpha_match_arms(name: &Ident, variants: &DataEnum) -> proc_macro2::TokenStream {
let mut match_arms = quote! {};
for variant in variants.variants.iter() {
let variant_ident = &variant.ident;

match_arms.extend(quote! {
#name::#variant_ident(coprocessor) => coprocessor.evaluate_alpha(s, args, env, cont),
});
}
match_arms
}

fn simple_evaluate_alpha_match_arms(name: &Ident, variants: &DataEnum) -> proc_macro2::TokenStream {
let mut match_arms = quote! {};
for variant in variants.variants.iter() {
let variant_ident = &variant.ident;

match_arms.extend(quote! {
#name::#variant_ident(coprocessor) => coprocessor.simple_evaluate_alpha(s, args),
});
}
match_arms
}

fn evaluate_internal_match_arms(name: &Ident, variants: &DataEnum) -> proc_macro2::TokenStream {
let mut match_arms = quote! {};
for variant in variants.variants.iter() {
Expand Down Expand Up @@ -258,18 +204,6 @@ fn arity_match_arms(name: &Ident, variants: &DataEnum) -> proc_macro2::TokenStre
match_arms
}

fn synthesize_alpha_match_arms(name: &Ident, variants: &DataEnum) -> proc_macro2::TokenStream {
let mut match_arms = quote! {};
for variant in variants.variants.iter() {
let variant_ident = &variant.ident;

match_arms.extend(quote! {
#name::#variant_ident(cocircuit) => cocircuit.synthesize_alpha(cs, g, store, input_exprs, input_env, input_cont, not_dummy),
});
}
match_arms
}

fn synthesize_internal_match_arms(name: &Ident, variants: &DataEnum) -> proc_macro2::TokenStream {
let mut match_arms = quote! {};
for variant in variants.variants.iter() {
Expand Down
4 changes: 0 additions & 4 deletions src/circuit/gadgets/circom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use crate::{
field::LurkField,
lem::{pointers::Ptr, store::Store},
ptr::Ptr as AlphaPtr,
store::Store as AlphaStore,
};

use super::pointer::AllocatedPtr;
Expand All @@ -27,7 +25,5 @@ pub trait CircomGadget<F: LurkField>: Send + Sync + Clone {

fn into_circom_input(self, input: &[AllocatedPtr<F>]) -> Vec<(String, Vec<F>)>;

fn simple_evaluate_alpha(&self, s: &AlphaStore<F>, args: &[AlphaPtr<F>]) -> AlphaPtr<F>;

fn evaluate_simple(&self, s: &Store<F>, args: &[Ptr<F>]) -> Ptr<F>;
}
37 changes: 1 addition & 36 deletions src/coprocessor/circom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@ pub mod non_wasm {

use ansi_term::Colour::Red;
use anyhow::{bail, Result};
use bellpepper::gadgets::boolean::Boolean;
use bellpepper_core::{ConstraintSystem, SynthesisError};
use circom_scotia::r1cs::CircomConfig;

use crate::{
circuit::gadgets::{
circom::CircomGadget,
data::GlobalAllocations,
pointer::{AllocatedContPtr, AllocatedPtr},
},
circuit::gadgets::{circom::CircomGadget, pointer::AllocatedPtr},
cli::paths::circom_dir,
coprocessor::{CoCircuit, Coprocessor},
field::LurkField,
lem::{pointers::Ptr, store::Store},
ptr::Ptr as AlphaPtr,
store::Store as AlphaStore,
};

fn print_error(name: &str, available: &[String]) -> Result<()> {
Expand Down Expand Up @@ -110,30 +103,6 @@ Then run `lurk coprocessor --name {name} <{}_FOLDER>` to instantiate a new gadge
0
}

fn synthesize_alpha<CS: ConstraintSystem<F>>(
&self,
cs: &mut CS,
g: &GlobalAllocations<F>,
_store: &AlphaStore<F>,
input_exprs: &[AllocatedPtr<F>],
input_env: &AllocatedPtr<F>,
input_cont: &AllocatedContPtr<F>,
_not_dummy: &Boolean,
) -> Result<(AllocatedPtr<F>, AllocatedPtr<F>, AllocatedContPtr<F>), SynthesisError>
{
let input = self.gadget.clone().into_circom_input(input_exprs);
let witness =
circom_scotia::calculate_witness(&self.config, input, true).map_err(|e| {
eprintln!("{:?}", e);
SynthesisError::Unsatisfiable
})?;
let output = circom_scotia::synthesize(cs, self.config.r1cs.clone(), Some(witness))?;

let res = AllocatedPtr::from_parts(g.num_tag.clone(), output);

Ok((res, input_env.clone(), input_cont.clone()))
}

fn synthesize_simple<CS: ConstraintSystem<F>>(
&self,
cs: &mut CS,
Expand Down Expand Up @@ -164,10 +133,6 @@ Then run `lurk coprocessor --name {name} <{}_FOLDER>` to instantiate a new gadge
0
}

fn simple_evaluate_alpha(&self, s: &AlphaStore<F>, args: &[AlphaPtr<F>]) -> AlphaPtr<F> {
self.gadget.simple_evaluate_alpha(s, args)
}

fn evaluate_simple(&self, s: &Store<F>, args: &[Ptr<F>]) -> Ptr<F> {
self.gadget.evaluate_simple(s, args)
}
Expand Down
Loading

0 comments on commit d42c1fb

Please sign in to comment.