lib.rs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. use proc_macro2::TokenStream;
  2. /// The submodules that would be useful to have in the lower-level
  3. /// `sigma` crate are for now included as submodules of a local `sigma`
  4. /// module
  5. pub mod sigma {
  6. pub mod codegen;
  7. pub mod combiners;
  8. pub mod types;
  9. }
  10. mod codegen;
  11. mod pedersen;
  12. mod rangeproof;
  13. mod substitution;
  14. mod syntax;
  15. mod transform;
  16. pub use syntax::{SigmaCompSpec, TaggedIdent, TaggedPoint, TaggedScalar, TaggedVarDict};
  17. /// The main function of this macro.
  18. ///
  19. /// Parse the macro input with [`parse`](SigmaCompSpec#method.parse) to
  20. /// produce a [`SigmaCompSpec`], and then pass that to this function to
  21. /// output the data structures and code for the ZKP protocol
  22. /// implementation.
  23. ///
  24. /// If `emit_prover` is `true`, output the data structures and code for
  25. /// the prover side. If `emit_verifier` is `true`, output the data
  26. /// structures and code for the verifier side. (Typically both will be
  27. /// `true`, but you can set one to `false` if you don't need that side
  28. /// of the protocol.)
  29. pub fn sigma_compiler_core(
  30. spec: &mut SigmaCompSpec,
  31. emit_prover: bool,
  32. emit_verifier: bool,
  33. ) -> TokenStream {
  34. let mut codegen = codegen::CodeGen::new(spec);
  35. // Apply any substitution transformations
  36. substitution::transform(&mut codegen, &mut spec.statements, &mut spec.vars).unwrap();
  37. /* Just some test code for now:
  38. let C_var = codegen.gen_point(&mut spec.vars, &quote::format_ident!("C"), false, true);
  39. let V_var = codegen.gen_point(&mut spec.vars, &quote::format_ident!("V"), true, true);
  40. codegen.prove_append(quote::quote! {
  41. let #C_var = <Point as group::Group>::generator();
  42. let #V_var = vec![<Point as group::Group>::generator(), <Point as
  43. group::Group>::generator()];
  44. });
  45. codegen.verify_pre_params_append(quote::quote! {
  46. let mut #V_var = Vec::<Point>::new();
  47. #V_var.resize(2, Point::default());
  48. });
  49. */
  50. codegen.generate(spec, emit_prover, emit_verifier)
  51. }