Explorar el Código

halo2: Implement utility function to load constant values

parazyd hace 5 años
padre
commit
15b13ff27d
Se han modificado 1 ficheros con 18 adiciones y 2 borrados
  1. 18 2
      examples/halo2/src/circuit/gadget/utilities.rs

+ 18 - 2
examples/halo2/src/circuit/gadget/utilities.rs

@@ -7,8 +7,8 @@ use pasta_curves::arithmetic::FieldExt;
 use std::{array, convert::TryInto, ops::Range};
 use std::{array, convert::TryInto, ops::Range};
 
 
 // pub(crate) mod cond_swap;
 // pub(crate) mod cond_swap;
-// pub(crate) mod decompose_running_sum;
-// pub(crate) mod lookup_range_check;
+pub mod decompose_running_sum;
+pub mod lookup_range_check;
 
 
 /// A variable representing a field element.
 /// A variable representing a field element.
 #[derive(Copy, Clone, Debug)]
 #[derive(Copy, Clone, Debug)]
@@ -59,6 +59,22 @@ pub trait UtilitiesInstructions<F: FieldExt> {
             },
             },
         )
         )
     }
     }
+
+    fn load_constant(
+        &self,
+        mut layouter: impl Layouter<F>,
+        column: Column<Advice>,
+        constant: F,
+    ) -> Result<Self::Var, Error> {
+        layouter.assign_region(
+            || "load constant",
+            |mut region| {
+                let cell =
+                    region.assign_advice_from_constant(|| "constant value", column, 0, constant)?;
+                Ok(Var::new(cell, Some(constant)))
+            },
+        )
+    }
 }
 }
 
 
 /// Assigns a cell at a specific offset within the given region, constraining it
 /// Assigns a cell at a specific offset within the given region, constraining it