Parcourir la source

feat: automatically reuse the canonical group generator

Michele Orrù il y a 5 jours
Parent
commit
c70bf20df3
1 fichiers modifiés avec 13 ajouts et 5 suppressions
  1. 13 5
      sigma-compiler-core/src/sigma/codegen.rs

+ 13 - 5
sigma-compiler-core/src/sigma/codegen.rs

@@ -457,13 +457,21 @@ impl<'a> CodeGen<'a> {
                     }
                     AExprType::Point { is_vec: false, .. } => {
                         if allocated_vars.insert(id.clone()) {
+                            // sigma-proofs reserves element index 0 for the
+                            // canonical group generator. Reuse it whenever a
+                            // declared point has that value; otherwise keep
+                            // the point as an ordinary instance element.
                             element_allocs = quote! {
                                 #element_allocs
-                                let #id = #lr_var.allocate_element();
-                            };
-                            element_assigns = quote! {
-                                #element_assigns
-                                #lr_var.set_element(#id, #instance_var.#id);
+                                let #id = if #instance_var.#id
+                                    == <Point as group::Group>::generator()
+                                {
+                                    #lr_var.generator()
+                                } else {
+                                    let #id = #lr_var.allocate_element();
+                                    #lr_var.set_element(#id, #instance_var.#id);
+                                    #id
+                                };
                             };
                         }
                         Ok(quote! {#id})