From 425ee6e038d4104cbbb0804c76714ab067b1d8f5 Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Thu, 15 Jul 2021 12:27:12 +0800 Subject: [PATCH] Docfixes and minor refactors. Co-authored-by: Daira Hopwood --- src/circuit/gadget/ecc/chip/mul_fixed.rs | 8 ++++---- src/circuit/gadget/utilities.rs | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/circuit/gadget/ecc/chip/mul_fixed.rs b/src/circuit/gadget/ecc/chip/mul_fixed.rs index bc537ef5..03aa26a8 100644 --- a/src/circuit/gadget/ecc/chip/mul_fixed.rs +++ b/src/circuit/gadget/ecc/chip/mul_fixed.rs @@ -424,7 +424,7 @@ impl Config { )?; } - // offset_acc = \sum_{j = 0}^{NUM_WINDOWS - 2} 2^{FIXED_BASE_WINDOW_SIZE * j+1} + // offset_acc = \sum_{j = 0}^{NUM_WINDOWS - 2} 2^{FIXED_BASE_WINDOW_SIZE*j + 1} let offset_acc = (0..(NUM_WINDOWS - 1)).fold(pallas::Scalar::zero(), |acc, w| { acc + (*TWO_SCALAR).pow(&[ constants::FIXED_BASE_WINDOW_SIZE as u64 * w as u64 + 1, @@ -434,7 +434,7 @@ impl Config { ]) }); - // `scalar = [k * 8^84 - offset_acc]`, where `offset_acc = \sum_{j = 0}^{83} 2^{FIXED_BASE_WINDOW_SIZE * j + 1}`. + // `scalar = [k * 8^84 - offset_acc]`, where `offset_acc = \sum_{j = 0}^{83} 2^{FIXED_BASE_WINDOW_SIZE*j + 1}`. let scalar = scalar.windows_field()[scalar.windows_field().len() - 1] .map(|k| k * (*H_SCALAR).pow(&[(NUM_WINDOWS - 1) as u64, 0, 0, 0]) - offset_acc); @@ -531,14 +531,14 @@ impl ScalarFixed { } // The scalar decomposition is guaranteed to be in three-bit windows, - // so we also cast the least significant byte in their serialisation + // so we also cast the least significant 4 bytes in their serialisation // into usize for convenient indexing into `u`-values fn windows_usize(&self) -> Vec> { self.windows_field() .iter() .map(|window| { if let Some(window) = window { - let window = window.to_bytes()[0] as usize; + let window = window.get_lower_32() as usize; assert!(window < constants::H); Some(window) } else { diff --git a/src/circuit/gadget/utilities.rs b/src/circuit/gadget/utilities.rs index 338bd11a..70998561 100644 --- a/src/circuit/gadget/utilities.rs +++ b/src/circuit/gadget/utilities.rs @@ -99,7 +99,8 @@ pub fn transpose_option_array( ret } -/// Subsets a field element to a specified bitrange (little-endian) +/// Takes a specified subsequence of the little-endian bit representation of a field element. +/// The bits are numbered from 0 for the LSB. pub fn bitrange_subset(field_elem: F, bitrange: Range) -> F { assert!(bitrange.end <= F::NUM_BITS as usize);