Browse Source

Use the input TaggedVarDict, not the one modified by apply_substitutions, to generate the Params and Witness structures

Ian Goldberg 3 months ago
parent
commit
fa3d992bcc
2 changed files with 11 additions and 5 deletions
  1. 8 2
      sigma_compiler_core/src/lib.rs
  2. 3 3
      sigma_compiler_core/src/syntax.rs

+ 8 - 2
sigma_compiler_core/src/lib.rs

@@ -169,6 +169,12 @@ pub fn sigma_compiler_core(
     let proto_name = &spec.proto_name;
     let group_name = &spec.group_name;
 
+    // Save a copy of the input TaggedVarDict, because the Params and
+    // Witness structs will be built from that TaggedVarDict, not the
+    // one modified by apply_substitutions below.
+
+    let input_vars = spec.vars.clone();
+
     // Apply any substitution transformations
     transform::apply_substitutions(&mut spec.statements, &mut spec.vars).unwrap();
 
@@ -180,7 +186,7 @@ pub fn sigma_compiler_core(
     // Generate the public params struct definition
     let params_def = {
         let mut pub_params_fields = StructFieldList::default();
-        pub_params_fields.push_vars(&spec.vars, true);
+        pub_params_fields.push_vars(&input_vars, true);
 
         let decls = pub_params_fields.field_decls();
         let dump_impl = if cfg!(feature = "dump") {
@@ -246,7 +252,7 @@ pub fn sigma_compiler_core(
     // Generate the witness struct definition
     let witness_def = if emit_prover {
         let mut witness_fields = StructFieldList::default();
-        witness_fields.push_vars(&spec.vars, false);
+        witness_fields.push_vars(&input_vars, false);
 
         let decls = witness_fields.field_decls();
         quote! {

+ 3 - 3
sigma_compiler_core/src/syntax.rs

@@ -20,7 +20,7 @@ use syn::{parenthesized, Error, Expr, Ident, Token};
 ///  - `pub vec`
 ///  - `rand vec`
 
-#[derive(Debug, PartialEq, Eq)]
+#[derive(Clone, Debug, PartialEq, Eq)]
 pub struct TaggedScalar {
     pub id: Ident,
     pub is_pub: bool,
@@ -76,7 +76,7 @@ impl Parse for TaggedScalar {
 ///  - `const vec`
 ///  - `cind const vec`
 
-#[derive(Debug, PartialEq, Eq)]
+#[derive(Clone, Debug, PartialEq, Eq)]
 pub struct TaggedPoint {
     pub id: Ident,
     pub is_cind: bool,
@@ -119,7 +119,7 @@ impl Parse for TaggedPoint {
 
 /// A [`TaggedIdent`] can be either a [`TaggedScalar`] or a
 /// [`TaggedPoint`]
-#[derive(Debug, PartialEq, Eq)]
+#[derive(Clone, Debug, PartialEq, Eq)]
 pub enum TaggedIdent {
     Scalar(TaggedScalar),
     Point(TaggedPoint),