lib.rs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 pubscalareq;
  13. mod rangeproof;
  14. mod substitution;
  15. mod syntax;
  16. mod transform;
  17. pub use syntax::{SigmaCompSpec, TaggedIdent, TaggedPoint, TaggedScalar, TaggedVarDict};
  18. /// The main function of this macro.
  19. ///
  20. /// Parse the macro input with [`parse`](SigmaCompSpec#method.parse) to
  21. /// produce a [`SigmaCompSpec`], and then pass that to this function to
  22. /// output the data structures and code for the ZKP protocol
  23. /// implementation.
  24. ///
  25. /// If `emit_prover` is `true`, output the data structures and code for
  26. /// the prover side. If `emit_verifier` is `true`, output the data
  27. /// structures and code for the verifier side. (Typically both will be
  28. /// `true`, but you can set one to `false` if you don't need that side
  29. /// of the protocol.)
  30. pub fn sigma_compiler_core(
  31. spec: &mut SigmaCompSpec,
  32. emit_prover: bool,
  33. emit_verifier: bool,
  34. ) -> TokenStream {
  35. let mut codegen = codegen::CodeGen::new(spec);
  36. // Apply any substitution transformations
  37. substitution::transform(&mut codegen, &mut spec.statements, &mut spec.vars).unwrap();
  38. // Apply any range statement transformations
  39. rangeproof::transform(&mut codegen, &mut spec.statements, &mut spec.vars).unwrap();
  40. // Apply any public scalar equality transformations
  41. pubscalareq::transform(&mut codegen, &mut spec.statements, &mut spec.vars).unwrap();
  42. codegen.generate(spec, emit_prover, emit_verifier)
  43. }