From b2408ab69e9274537560b37902c96a79e3c2bc4e Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Tue, 4 May 2021 03:19:25 +0800 Subject: [PATCH] Load circuit using sinsemilla_s_generators() from constants --- .../gadget/sinsemilla/chip/generator_table.rs | 37 +++---------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/src/circuit/gadget/sinsemilla/chip/generator_table.rs b/src/circuit/gadget/sinsemilla/chip/generator_table.rs index f4e0eb13b..1b340cac3 100644 --- a/src/circuit/gadget/sinsemilla/chip/generator_table.rs +++ b/src/circuit/gadget/sinsemilla/chip/generator_table.rs @@ -1,4 +1,4 @@ -use crate::primitives::sinsemilla::{K, S_PERSONALIZATION}; +use crate::primitives::sinsemilla::{sinsemilla_s_generators, K, S_PERSONALIZATION}; use halo2::{ arithmetic::{CurveAffine, CurveExt, FieldExt}, circuit::{Chip, Layouter}, @@ -103,7 +103,7 @@ impl GeneratorTableChip { || "generator_table", |mut gate| { // We generate the row values lazily (we only need them during keygen). - let mut rows = config.generate::(); + let mut rows = sinsemilla_s_generators::(); for index in 0..(1 << K) { let mut row = None; @@ -113,20 +113,20 @@ impl GeneratorTableChip { index, || { row = rows.next(); - row.map(|(idx, _, _)| idx).ok_or(Error::SynthesisError) + Ok(C::Base::from_u64(index as u64)) }, )?; gate.assign_fixed( || "table_x", config.table_x, index, - || row.map(|(_, x, _)| x).ok_or(Error::SynthesisError), + || row.map(|(x, _)| x).ok_or(Error::SynthesisError), )?; gate.assign_fixed( || "table_y", config.table_y, index, - || row.map(|(_, _, y)| y).ok_or(Error::SynthesisError), + || row.map(|(_, y)| y).ok_or(Error::SynthesisError), )?; } Ok(()) @@ -135,33 +135,6 @@ impl GeneratorTableChip { } } -impl GeneratorTableConfig { - // Generates S[0..2^k] as 2^k independent, verifiably random generators of the group. - // Loads these generators into a lookup table along with their indices. - // Uses SWU hash-to-curve. - fn generate(&self) -> impl Iterator { - let init = get_s_by_idx::(0).to_affine().coordinates().unwrap(); - - (1..=(1 << K)).scan( - (C::Base::default(), *init.x(), *init.y()), - move |(idx, x, y), i| { - // We computed this table row in the previous iteration. - let res = (*idx, *x, *y); - - // i holds the zero-indexed row number for the next table row. - *idx = C::Base::from_u64(i as u64); - - let new = get_s_by_idx::(i).to_affine().coordinates().unwrap(); - - *x = *new.x(); - *y = *new.y(); - - Some(res) - }, - ) - } -} - /// Get generator S by index pub fn get_s_by_idx(idx: u32) -> C::Curve { let hash = C::CurveExt::hash_to_curve(S_PERSONALIZATION);