sha256: Fix / silence lints

This commit is contained in:
Jack Grigg 2021-02-25 20:34:07 +00:00
parent 2f21135e68
commit a688c8b03d
16 changed files with 91 additions and 42 deletions

View File

@ -21,6 +21,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
use crate::{BlockWord, Sha256, Table16Chip, Table16Config, BLOCK_SIZE}; use crate::{BlockWord, Sha256, Table16Chip, Table16Config, BLOCK_SIZE};
#[allow(dead_code)]
fn bench(name: &str, k: u32, c: &mut Criterion) { fn bench(name: &str, k: u32, c: &mut Criterion) {
struct MyCircuit {} struct MyCircuit {}
@ -72,7 +73,7 @@ fn bench(name: &str, k: u32, c: &mut Criterion) {
// Initialize the polynomial commitment parameters // Initialize the polynomial commitment parameters
let params_path = Path::new("./benches/sha256_assets/sha256_params"); let params_path = Path::new("./benches/sha256_assets/sha256_params");
if let Err(_) = File::open(&params_path) { if File::open(&params_path).is_err() {
let params: Params<EqAffine> = Params::new(k); let params: Params<EqAffine> = Params::new(k);
let mut buf = Vec::new(); let mut buf = Vec::new();
@ -91,7 +92,7 @@ fn bench(name: &str, k: u32, c: &mut Criterion) {
// Initialize the proving key // Initialize the proving key
let vk_path = Path::new("./benches/sha256_assets/sha256_vk"); let vk_path = Path::new("./benches/sha256_assets/sha256_vk");
if let Err(_) = File::open(&vk_path) { if File::open(&vk_path).is_err() {
let vk = keygen_vk(&params, &empty_circuit).expect("keygen_vk should not fail"); let vk = keygen_vk(&params, &empty_circuit).expect("keygen_vk should not fail");
let mut buf = Vec::new(); let mut buf = Vec::new();
@ -126,7 +127,7 @@ fn bench(name: &str, k: u32, c: &mut Criterion) {
// Create a proof // Create a proof
let proof_path = Path::new("./benches/sha256_assets/sha256_proof"); let proof_path = Path::new("./benches/sha256_assets/sha256_proof");
if let Err(_) = File::open(&proof_path) { if File::open(&proof_path).is_err() {
let mut transcript = Blake2bWrite::init(vec![]); let mut transcript = Blake2bWrite::init(vec![]);
create_proof(&params, &pk, &[circuit], &[], &mut transcript) create_proof(&params, &pk, &[circuit], &[], &mut transcript)
.expect("proof generation should not fail"); .expect("proof generation should not fail");
@ -152,6 +153,7 @@ fn bench(name: &str, k: u32, c: &mut Criterion) {
}); });
} }
#[allow(dead_code)]
fn criterion_benchmark(c: &mut Criterion) { fn criterion_benchmark(c: &mut Criterion) {
bench("sha256", 16, c); bench("sha256", 16, c);
// bench("sha256", 20, c); // bench("sha256", 20, c);

View File

@ -167,7 +167,7 @@ impl<F: FieldExt> Table16Chip<F> {
); );
let message_schedule = let message_schedule =
MessageSchedule::configure(meta, lookup_inputs, message_schedule, extras, perm.clone()); MessageSchedule::configure(meta, lookup_inputs, message_schedule, extras, perm);
Table16Config { Table16Config {
lookup_table, lookup_table,
@ -240,6 +240,8 @@ impl<F: FieldExt> Sha256Instructions for Table16Chip<F> {
/// Common assignment patterns used by Table16 regions. /// Common assignment patterns used by Table16 regions.
trait Table16Assignment<F: FieldExt> { trait Table16Assignment<F: FieldExt> {
// Assign cells for general spread computation used in sigma, ch, ch_neg, maj gates // Assign cells for general spread computation used in sigma, ch, ch_neg, maj gates
#[allow(clippy::too_many_arguments)]
#[allow(clippy::type_complexity)]
fn assign_spread_outputs( fn assign_spread_outputs(
&self, &self,
region: &mut Region<'_, Table16Chip<F>>, region: &mut Region<'_, Table16Chip<F>>,
@ -280,6 +282,7 @@ trait Table16Assignment<F: FieldExt> {
} }
// Assign outputs of sigma gates // Assign outputs of sigma gates
#[allow(clippy::too_many_arguments)]
fn assign_sigma_outputs( fn assign_sigma_outputs(
&self, &self,
region: &mut Region<'_, Table16Chip<F>>, region: &mut Region<'_, Table16Chip<F>>,

View File

@ -180,6 +180,8 @@ pub struct State {
} }
impl State { impl State {
#[allow(clippy::many_single_char_names)]
#[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
a: StateWord, a: StateWord,
b: StateWord, b: StateWord,
@ -749,6 +751,7 @@ impl Compression {
Ok(digest) Ok(digest)
} }
#[cfg(test)]
pub(super) fn empty_configure<F: FieldExt>( pub(super) fn empty_configure<F: FieldExt>(
meta: &mut ConstraintSystem<F>, meta: &mut ConstraintSystem<F>,
lookup: SpreadInputs, lookup: SpreadInputs,

View File

@ -10,6 +10,7 @@ impl<F: FieldExt> CompressionGate<F> {
// Decompose `A,B,C,D` words // Decompose `A,B,C,D` words
// (2, 11, 9, 10)-bit chunks // (2, 11, 9, 10)-bit chunks
#[allow(clippy::too_many_arguments)]
pub fn s_decompose_abcd( pub fn s_decompose_abcd(
s_decompose_abcd: Expression<F>, s_decompose_abcd: Expression<F>,
a: Expression<F>, a: Expression<F>,
@ -67,6 +68,7 @@ impl<F: FieldExt> CompressionGate<F> {
// Decompose `E,F,G,H` words // Decompose `E,F,G,H` words
// (6, 5, 14, 7)-bit chunks // (6, 5, 14, 7)-bit chunks
#[allow(clippy::too_many_arguments)]
pub fn s_decompose_efgh( pub fn s_decompose_efgh(
s_decompose_efgh: Expression<F>, s_decompose_efgh: Expression<F>,
a_lo: Expression<F>, a_lo: Expression<F>,
@ -124,6 +126,7 @@ impl<F: FieldExt> CompressionGate<F> {
// s_upper_sigma_0 on abcd words // s_upper_sigma_0 on abcd words
// (2, 11, 9, 10)-bit chunks // (2, 11, 9, 10)-bit chunks
#[allow(clippy::too_many_arguments)]
pub fn s_upper_sigma_0( pub fn s_upper_sigma_0(
s_upper_sigma_0: Expression<F>, s_upper_sigma_0: Expression<F>,
spread_r0_even: Expression<F>, spread_r0_even: Expression<F>,
@ -165,6 +168,7 @@ impl<F: FieldExt> CompressionGate<F> {
// s_upper_sigma_1 on efgh words // s_upper_sigma_1 on efgh words
// (6, 5, 14, 7)-bit chunks // (6, 5, 14, 7)-bit chunks
#[allow(clippy::too_many_arguments)]
pub fn s_upper_sigma_1( pub fn s_upper_sigma_1(
s_upper_sigma_1: Expression<F>, s_upper_sigma_1: Expression<F>,
spread_r0_even: Expression<F>, spread_r0_even: Expression<F>,
@ -206,6 +210,7 @@ impl<F: FieldExt> CompressionGate<F> {
} }
// First part of choice gate on (E, F, G), E ∧ F // First part of choice gate on (E, F, G), E ∧ F
#[allow(clippy::too_many_arguments)]
pub fn s_ch( pub fn s_ch(
s_ch: Expression<F>, s_ch: Expression<F>,
spread_p0_even: Expression<F>, spread_p0_even: Expression<F>,
@ -229,6 +234,7 @@ impl<F: FieldExt> CompressionGate<F> {
} }
// Second part of Choice gate on (E, F, G), ¬E ∧ G // Second part of Choice gate on (E, F, G), ¬E ∧ G
#[allow(clippy::too_many_arguments)]
pub fn s_ch_neg( pub fn s_ch_neg(
s_ch_neg: Expression<F>, s_ch_neg: Expression<F>,
spread_q0_even: Expression<F>, spread_q0_even: Expression<F>,
@ -260,6 +266,7 @@ impl<F: FieldExt> CompressionGate<F> {
} }
// Majority gate on (A, B, C) // Majority gate on (A, B, C)
#[allow(clippy::too_many_arguments)]
pub fn s_maj( pub fn s_maj(
s_maj: Expression<F>, s_maj: Expression<F>,
spread_m_0_even: Expression<F>, spread_m_0_even: Expression<F>,
@ -302,6 +309,7 @@ impl<F: FieldExt> CompressionGate<F> {
} }
// s_h_prime to get H' = H + Ch(E, F, G) + s_upper_sigma_1(E) + K + W // s_h_prime to get H' = H + Ch(E, F, G) + s_upper_sigma_1(E) + K + W
#[allow(clippy::too_many_arguments)]
pub fn s_h_prime( pub fn s_h_prime(
s_h_prime: Expression<F>, s_h_prime: Expression<F>,
h_prime_lo: Expression<F>, h_prime_lo: Expression<F>,
@ -335,6 +343,7 @@ impl<F: FieldExt> CompressionGate<F> {
} }
// s_a_new to get A_new = H' + Maj(A, B, C) + s_upper_sigma_0(A) // s_a_new to get A_new = H' + Maj(A, B, C) + s_upper_sigma_0(A)
#[allow(clippy::too_many_arguments)]
pub fn s_a_new( pub fn s_a_new(
s_a_new: Expression<F>, s_a_new: Expression<F>,
a_new_lo: Expression<F>, a_new_lo: Expression<F>,
@ -359,6 +368,7 @@ impl<F: FieldExt> CompressionGate<F> {
} }
// s_e_new to get E_new = H' + D // s_e_new to get E_new = H' + D
#[allow(clippy::too_many_arguments)]
pub fn s_e_new( pub fn s_e_new(
s_e_new: Expression<F>, s_e_new: Expression<F>,
e_new_lo: Expression<F>, e_new_lo: Expression<F>,
@ -385,6 +395,7 @@ impl<F: FieldExt> CompressionGate<F> {
} }
// s_digest on final round // s_digest on final round
#[allow(clippy::too_many_arguments)]
pub fn s_digest( pub fn s_digest(
s_digest: Expression<F>, s_digest: Expression<F>,
lo_0: Expression<F>, lo_0: Expression<F>,

View File

@ -12,6 +12,7 @@ use halo2::{
}; };
// Test vector 'abc' // Test vector 'abc'
#[cfg(test)]
pub const COMPRESSION_OUTPUT: [u32; 8] = [ pub const COMPRESSION_OUTPUT: [u32; 8] = [
0b10111010011110000001011010111111, 0b10111010011110000001011010111111,
0b10001111000000011100111111101010, 0b10001111000000011100111111101010,
@ -767,6 +768,7 @@ impl Compression {
} }
// s_h_prime to get H' = H + Ch(E, F, G) + s_upper_sigma_1(E) + K + W // s_h_prime to get H' = H + Ch(E, F, G) + s_upper_sigma_1(E) + K + W
#[allow(clippy::too_many_arguments)]
pub(super) fn assign_h_prime<F: FieldExt>( pub(super) fn assign_h_prime<F: FieldExt>(
&self, &self,
region: &mut Region<'_, Table16Chip<F>>, region: &mut Region<'_, Table16Chip<F>>,
@ -1051,6 +1053,7 @@ impl Compression {
} }
// Assign hi and lo halves for both dense and spread versions of a word // Assign hi and lo halves for both dense and spread versions of a word
#[allow(clippy::type_complexity)]
pub fn assign_word_halves<F: FieldExt>( pub fn assign_word_halves<F: FieldExt>(
&self, &self,
region: &mut Region<'_, Table16Chip<F>>, region: &mut Region<'_, Table16Chip<F>>,
@ -1081,6 +1084,7 @@ pub fn val_from_dense_halves(dense_halves: (CellValue16, CellValue16)) -> u32 {
dense_halves.0.value.unwrap() as u32 + (1 << 16) * dense_halves.1.value.unwrap() as u32 dense_halves.0.value.unwrap() as u32 + (1 << 16) * dense_halves.1.value.unwrap() as u32
} }
#[allow(clippy::many_single_char_names)]
pub fn match_state( pub fn match_state(
state: State, state: State,
) -> ( ) -> (

View File

@ -7,6 +7,7 @@ use halo2::{
}; };
impl Compression { impl Compression {
#[allow(clippy::many_single_char_names)]
pub fn assign_digest<F: FieldExt>( pub fn assign_digest<F: FieldExt>(
&self, &self,
region: &mut Region<'_, Table16Chip<F>>, region: &mut Region<'_, Table16Chip<F>>,

View File

@ -3,6 +3,7 @@ use super::{compression_util::*, Compression, State};
use halo2::{arithmetic::FieldExt, circuit::Region, plonk::Error}; use halo2::{arithmetic::FieldExt, circuit::Region, plonk::Error};
impl Compression { impl Compression {
#[allow(clippy::many_single_char_names)]
pub fn initialize_iv<F: FieldExt>( pub fn initialize_iv<F: FieldExt>(
&self, &self,
region: &mut Region<'_, Table16Chip<F>>, region: &mut Region<'_, Table16Chip<F>>,
@ -48,6 +49,7 @@ impl Compression {
)) ))
} }
#[allow(clippy::many_single_char_names)]
pub fn initialize_state<F: FieldExt>( pub fn initialize_state<F: FieldExt>(
&self, &self,
region: &mut Region<'_, Table16Chip<F>>, region: &mut Region<'_, Table16Chip<F>>,

View File

@ -5,6 +5,7 @@ use super::{compression_util::*, Compression, State};
use halo2::{arithmetic::FieldExt, circuit::Region, plonk::Error}; use halo2::{arithmetic::FieldExt, circuit::Region, plonk::Error};
impl Compression { impl Compression {
#[allow(clippy::many_single_char_names)]
pub fn assign_round<F: FieldExt>( pub fn assign_round<F: FieldExt>(
&self, &self,
region: &mut Region<'_, Table16Chip<F>>, region: &mut Region<'_, Table16Chip<F>>,

View File

@ -17,9 +17,11 @@ mod subregion2;
mod subregion3; mod subregion3;
use schedule_gates::ScheduleGate; use schedule_gates::ScheduleGate;
pub use schedule_util::get_msg_schedule_test_input;
use schedule_util::*; use schedule_util::*;
#[cfg(test)]
pub use schedule_util::get_msg_schedule_test_input;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(super) struct MessageWord { pub(super) struct MessageWord {
var: Cell, var: Cell,
@ -65,6 +67,7 @@ impl MessageSchedule {
/// `extras` contains columns that the message schedule will only use for internal /// `extras` contains columns that the message schedule will only use for internal
/// gates, and will not place any constraints on (such as lookup constraints) outside /// gates, and will not place any constraints on (such as lookup constraints) outside
/// itself. /// itself.
#[allow(clippy::many_single_char_names)]
pub(super) fn configure<F: FieldExt>( pub(super) fn configure<F: FieldExt>(
meta: &mut ConstraintSystem<F>, meta: &mut ConstraintSystem<F>,
lookup: SpreadInputs, lookup: SpreadInputs,
@ -303,6 +306,7 @@ impl MessageSchedule {
} }
} }
#[allow(clippy::type_complexity)]
pub(super) fn process<F: FieldExt>( pub(super) fn process<F: FieldExt>(
&self, &self,
layouter: &mut impl Layouter<Table16Chip<F>>, layouter: &mut impl Layouter<Table16Chip<F>>,
@ -399,12 +403,12 @@ impl MessageSchedule {
} }
// Assign W[0..16] // Assign W[0..16]
for i in 0..16 { for (i, word) in input.iter().enumerate() {
let (var, halves) = let (var, halves) =
self.assign_word_and_halves(&mut region, input[i].value.unwrap(), i)?; self.assign_word_and_halves(&mut region, word.value.unwrap(), i)?;
w.push(MessageWord { w.push(MessageWord {
var, var,
value: input[i].value, value: word.value,
}); });
w_halves.push(halves); w_halves.push(halves);
} }
@ -437,6 +441,7 @@ impl MessageSchedule {
} }
/// Empty configuration without gates. Useful for fast testing /// Empty configuration without gates. Useful for fast testing
#[cfg(test)]
pub(super) fn empty_configure<F: FieldExt>( pub(super) fn empty_configure<F: FieldExt>(
meta: &mut ConstraintSystem<F>, meta: &mut ConstraintSystem<F>,
lookup: SpreadInputs, lookup: SpreadInputs,

View File

@ -5,6 +5,7 @@ pub struct ScheduleGate<F: FieldExt>(pub Expression<F>);
impl<F: FieldExt> ScheduleGate<F> { impl<F: FieldExt> ScheduleGate<F> {
/// s_word for W_16 to W_63 /// s_word for W_16 to W_63
#[allow(clippy::too_many_arguments)]
pub fn s_word( pub fn s_word(
s_word: Expression<F>, s_word: Expression<F>,
sigma_0_lo: Expression<F>, sigma_0_lo: Expression<F>,
@ -42,6 +43,7 @@ impl<F: FieldExt> ScheduleGate<F> {
/// s_decompose_1 for W_1 to W_13 /// s_decompose_1 for W_1 to W_13
/// (3, 4, 11, 14)-bit chunks /// (3, 4, 11, 14)-bit chunks
#[allow(clippy::too_many_arguments)]
pub fn s_decompose_1( pub fn s_decompose_1(
s_decompose_1: Expression<F>, s_decompose_1: Expression<F>,
a: Expression<F>, a: Expression<F>,
@ -64,6 +66,8 @@ impl<F: FieldExt> ScheduleGate<F> {
/// s_decompose_2 for W_14 to W_48 /// s_decompose_2 for W_14 to W_48
/// (3, 4, 3, 7, 1, 1, 13)-bit chunks /// (3, 4, 3, 7, 1, 1, 13)-bit chunks
#[allow(clippy::many_single_char_names)]
#[allow(clippy::too_many_arguments)]
pub fn s_decompose_2( pub fn s_decompose_2(
s_decompose_2: Expression<F>, s_decompose_2: Expression<F>,
a: Expression<F>, a: Expression<F>,
@ -92,6 +96,7 @@ impl<F: FieldExt> ScheduleGate<F> {
/// s_decompose_3 for W_49 to W_61 /// s_decompose_3 for W_49 to W_61
/// (10, 7, 2, 13)-bit chunks /// (10, 7, 2, 13)-bit chunks
#[allow(clippy::too_many_arguments)]
pub fn s_decompose_3( pub fn s_decompose_3(
s_decompose_3: Expression<F>, s_decompose_3: Expression<F>,
a: Expression<F>, a: Expression<F>,
@ -132,6 +137,7 @@ impl<F: FieldExt> ScheduleGate<F> {
/// sigma_0 v1 on W_1 to W_13 /// sigma_0 v1 on W_1 to W_13
/// (3, 4, 11, 14)-bit chunks /// (3, 4, 11, 14)-bit chunks
#[allow(clippy::too_many_arguments)]
pub fn s_lower_sigma_0( pub fn s_lower_sigma_0(
s_lower_sigma_0: Expression<F>, s_lower_sigma_0: Expression<F>,
spread_r0_even: Expression<F>, spread_r0_even: Expression<F>,
@ -180,6 +186,7 @@ impl<F: FieldExt> ScheduleGate<F> {
/// sigma_1 v1 on W_49 to W_61 /// sigma_1 v1 on W_49 to W_61
/// (10, 7, 2, 13)-bit chunks /// (10, 7, 2, 13)-bit chunks
#[allow(clippy::too_many_arguments)]
pub fn s_lower_sigma_1( pub fn s_lower_sigma_1(
s_lower_sigma_1: Expression<F>, s_lower_sigma_1: Expression<F>,
spread_r0_even: Expression<F>, spread_r0_even: Expression<F>,
@ -218,12 +225,12 @@ impl<F: FieldExt> ScheduleGate<F> {
+ spread_b_lo.clone() * F::from_u64(1 << 50) + spread_b_lo.clone() * F::from_u64(1 << 50)
+ spread_b_mid.clone() * F::from_u64(1 << 54) + spread_b_mid.clone() * F::from_u64(1 << 54)
+ spread_b_hi.clone() * F::from_u64(1 << 58); + spread_b_hi.clone() * F::from_u64(1 << 58);
let xor_2 = spread_d.clone() let xor_2 = spread_d
+ spread_a.clone() * F::from_u64(1 << 26) + spread_a * F::from_u64(1 << 26)
+ spread_b_lo.clone() * F::from_u64(1 << 46) + spread_b_lo * F::from_u64(1 << 46)
+ spread_b_mid.clone() * F::from_u64(1 << 50) + spread_b_mid * F::from_u64(1 << 50)
+ spread_b_hi.clone() * F::from_u64(1 << 54) + spread_b_hi * F::from_u64(1 << 54)
+ spread_c.clone() * F::from_u64(1 << 60); + spread_c * F::from_u64(1 << 60);
let xor = xor_0 + xor_1 + xor_2; let xor = xor_0 + xor_1 + xor_2;
ScheduleGate( ScheduleGate(
@ -234,6 +241,7 @@ impl<F: FieldExt> ScheduleGate<F> {
/// sigma_0 v2 on W_14 to W_48 /// sigma_0 v2 on W_14 to W_48
/// (3, 4, 3, 7, 1, 1, 13)-bit chunks /// (3, 4, 3, 7, 1, 1, 13)-bit chunks
#[allow(clippy::too_many_arguments)]
pub fn s_lower_sigma_0_v2( pub fn s_lower_sigma_0_v2(
s_lower_sigma_0_v2: Expression<F>, s_lower_sigma_0_v2: Expression<F>,
spread_r0_even: Expression<F>, spread_r0_even: Expression<F>,
@ -296,6 +304,7 @@ impl<F: FieldExt> ScheduleGate<F> {
/// sigma_1 v2 on W_14 to W_48 /// sigma_1 v2 on W_14 to W_48
/// (3, 4, 3, 7, 1, 1, 13)-bit chunks /// (3, 4, 3, 7, 1, 1, 13)-bit chunks
#[allow(clippy::too_many_arguments)]
pub fn s_lower_sigma_1_v2( pub fn s_lower_sigma_1_v2(
s_lower_sigma_1_v2: Expression<F>, s_lower_sigma_1_v2: Expression<F>,
spread_r0_even: Expression<F>, spread_r0_even: Expression<F>,

View File

@ -1,4 +1,4 @@
use super::super::{super::BLOCK_SIZE, BlockWord, CellValue16, Table16Chip, ROUNDS}; use super::super::{CellValue16, Table16Chip};
use super::MessageSchedule; use super::MessageSchedule;
use halo2::{ use halo2::{
arithmetic::FieldExt, arithmetic::FieldExt,
@ -6,6 +6,9 @@ use halo2::{
plonk::Error, plonk::Error,
}; };
#[cfg(test)]
use super::super::{super::BLOCK_SIZE, BlockWord, ROUNDS};
// Rows needed for each gate // Rows needed for each gate
pub const DECOMPOSE_0_ROWS: usize = 2; pub const DECOMPOSE_0_ROWS: usize = 2;
pub const DECOMPOSE_1_ROWS: usize = 2; pub const DECOMPOSE_1_ROWS: usize = 2;
@ -36,11 +39,11 @@ pub fn get_word_row(word_idx: usize) -> usize {
assert!(word_idx <= 63); assert!(word_idx <= 63);
if word_idx == 0 { if word_idx == 0 {
0 0
} else if word_idx >= 1 && word_idx <= 13 { } else if (1..=13).contains(&word_idx) {
SUBREGION_0_ROWS + SUBREGION_1_WORD * (word_idx - 1) as usize SUBREGION_0_ROWS + SUBREGION_1_WORD * (word_idx - 1) as usize
} else if word_idx >= 14 && word_idx <= 48 { } else if (14..=48).contains(&word_idx) {
SUBREGION_0_ROWS + SUBREGION_1_ROWS + SUBREGION_2_WORD * (word_idx - 14) + 1 as usize SUBREGION_0_ROWS + SUBREGION_1_ROWS + SUBREGION_2_WORD * (word_idx - 14) + 1
} else if word_idx >= 49 && word_idx <= 61 { } else if (49..=61).contains(&word_idx) {
SUBREGION_0_ROWS SUBREGION_0_ROWS
+ SUBREGION_1_ROWS + SUBREGION_1_ROWS
+ SUBREGION_2_ROWS + SUBREGION_2_ROWS
@ -55,6 +58,7 @@ pub fn get_word_row(word_idx: usize) -> usize {
} }
/// Test vector: "abc" /// Test vector: "abc"
#[cfg(test)]
pub fn get_msg_schedule_test_input() -> [BlockWord; BLOCK_SIZE] { pub fn get_msg_schedule_test_input() -> [BlockWord; BLOCK_SIZE] {
[ [
BlockWord::new(0b01100001011000100110001110000000), BlockWord::new(0b01100001011000100110001110000000),
@ -76,6 +80,7 @@ pub fn get_msg_schedule_test_input() -> [BlockWord; BLOCK_SIZE] {
] ]
} }
#[cfg(test)]
pub const MSG_SCHEDULE_TEST_OUTPUT: [u32; ROUNDS] = [ pub const MSG_SCHEDULE_TEST_OUTPUT: [u32; ROUNDS] = [
0b01100001011000100110001110000000, 0b01100001011000100110001110000000,
0b00000000000000000000000000000000, 0b00000000000000000000000000000000,

View File

@ -79,12 +79,12 @@ impl MessageSchedule {
Ok(Subregion1Word { Ok(Subregion1Word {
index, index,
a: CellValue32::new(a, pieces[0].into()), a: CellValue32::new(a, pieces[0]),
b: CellValue32::new(b, pieces[1].into()), b: CellValue32::new(b, pieces[1]),
c: CellValue32::new(spread_c.dense.var, spread_c.dense.value.unwrap().into()), c: CellValue32::new(spread_c.dense.var, spread_c.dense.value.unwrap().into()),
d: CellValue32::new(spread_d.dense.var, spread_d.dense.value.unwrap().into()), d: CellValue32::new(spread_d.dense.var, spread_d.dense.value.unwrap().into()),
spread_c: CellValue32::new(spread_c.spread.var, spread_c.spread.value.unwrap().into()), spread_c: CellValue32::new(spread_c.spread.var, spread_c.spread.value.unwrap()),
spread_d: CellValue32::new(spread_d.spread.var, spread_d.spread.value.unwrap().into()), spread_d: CellValue32::new(spread_d.spread.var, spread_d.spread.value.unwrap()),
}) })
} }

View File

@ -162,7 +162,7 @@ impl MessageSchedule {
for i in 27..49 { for i in 27..49 {
tmp_lower_sigma_0_v2_results = tmp_lower_sigma_0_v2_results =
new_word(i, tmp_lower_sigma_0_v2_results[i + 2 - 15 - 14].clone())?; new_word(i, tmp_lower_sigma_0_v2_results[i + 2 - 15 - 14])?;
} }
// Return lower_sigma_0_v2 output for W_[36..49] // Return lower_sigma_0_v2 output for W_[36..49]
@ -209,18 +209,19 @@ impl MessageSchedule {
Ok(Subregion2Word { Ok(Subregion2Word {
index, index,
a: CellValue32::new(a, pieces[0].into()), a: CellValue32::new(a, pieces[0]),
b: CellValue32::new(spread_b.dense.var, spread_b.dense.value.unwrap().into()), b: CellValue32::new(spread_b.dense.var, spread_b.dense.value.unwrap().into()),
c: CellValue32::new(c, pieces[2].into()), c: CellValue32::new(c, pieces[2]),
d: CellValue32::new(spread_d.dense.var, spread_d.dense.value.unwrap().into()), d: CellValue32::new(spread_d.dense.var, spread_d.dense.value.unwrap().into()),
e: CellValue32::new(e, pieces[4].into()), e: CellValue32::new(e, pieces[4]),
f: CellValue32::new(f, pieces[5].into()), f: CellValue32::new(f, pieces[5]),
g: CellValue32::new(spread_g.dense.var, spread_g.dense.value.unwrap().into()), g: CellValue32::new(spread_g.dense.var, spread_g.dense.value.unwrap().into()),
spread_d: CellValue32::new(spread_d.spread.var, spread_d.spread.value.unwrap().into()), spread_d: CellValue32::new(spread_d.spread.var, spread_d.spread.value.unwrap()),
spread_g: CellValue32::new(spread_g.spread.var, spread_g.spread.value.unwrap().into()), spread_g: CellValue32::new(spread_g.spread.var, spread_g.spread.value.unwrap()),
}) })
} }
#[allow(clippy::type_complexity)]
fn assign_lower_sigma_v2_pieces<F: FieldExt>( fn assign_lower_sigma_v2_pieces<F: FieldExt>(
&self, &self,
region: &mut Region<'_, Table16Chip<F>>, region: &mut Region<'_, Table16Chip<F>>,
@ -384,7 +385,7 @@ impl MessageSchedule {
let row = get_word_row(subregion2_word.index) + SIGMA_0_V2_ROWS + 3; let row = get_word_row(subregion2_word.index) + SIGMA_0_V2_ROWS + 3;
let (spread_a, spread_b_lo, spread_b_hi, spread_c, spread_d, e, f, spread_g) = let (spread_a, spread_b_lo, spread_b_hi, spread_c, spread_d, e, f, spread_g) =
self.assign_lower_sigma_v2_pieces(region, row, subregion2_word.clone())?; self.assign_lower_sigma_v2_pieces(region, row, subregion2_word)?;
// (3, 4, 3, 7, 1, 1, 13) // (3, 4, 3, 7, 1, 1, 13)

View File

@ -8,9 +8,11 @@ use halo2::{arithmetic::FieldExt, circuit::Region, plonk::Error};
// (10, 7, 2, 13)-bit chunks // (10, 7, 2, 13)-bit chunks
pub struct Subregion3Word { pub struct Subregion3Word {
index: usize, index: usize,
#[allow(dead_code)]
a: CellValue32, a: CellValue32,
b: CellValue32, b: CellValue32,
c: CellValue32, c: CellValue32,
#[allow(dead_code)]
d: CellValue32, d: CellValue32,
spread_a: CellValue32, spread_a: CellValue32,
spread_d: CellValue32, spread_d: CellValue32,
@ -177,11 +179,11 @@ impl MessageSchedule {
Ok(Subregion3Word { Ok(Subregion3Word {
index, index,
a: CellValue32::new(spread_a.dense.var, spread_a.dense.value.unwrap().into()), a: CellValue32::new(spread_a.dense.var, spread_a.dense.value.unwrap().into()),
b: CellValue32::new(b, pieces[1].into()), b: CellValue32::new(b, pieces[1]),
c: CellValue32::new(c, pieces[2].into()), c: CellValue32::new(c, pieces[2]),
d: CellValue32::new(spread_d.dense.var, spread_d.dense.value.unwrap().into()), d: CellValue32::new(spread_d.dense.var, spread_d.dense.value.unwrap().into()),
spread_a: CellValue32::new(spread_a.spread.var, spread_a.spread.value.unwrap().into()), spread_a: CellValue32::new(spread_a.spread.var, spread_a.spread.value.unwrap()),
spread_d: CellValue32::new(spread_d.spread.var, spread_d.spread.value.unwrap().into()), spread_d: CellValue32::new(spread_d.spread.var, spread_d.spread.value.unwrap()),
}) })
} }

View File

@ -76,8 +76,8 @@ impl SpreadVar {
}) })
} }
pub(super) fn without_lookup<'r, C: Chip>( pub(super) fn without_lookup<C: Chip>(
region: &mut Region<'r, C>, region: &mut Region<'_, C>,
dense_col: Column<Advice>, dense_col: Column<Advice>,
dense_row: usize, dense_row: usize,
spread_col: Column<Advice>, spread_col: Column<Advice>,

View File

@ -48,14 +48,14 @@ pub fn compress_u32(word: u32) -> u16 {
// Chops a 32-bit word into pieces of given length. The lengths are specified // Chops a 32-bit word into pieces of given length. The lengths are specified
// starting from the little end. // starting from the little end.
pub fn chop_u32(word: u32, lengths: &[u8]) -> Vec<u32> { pub fn chop_u32(word: u32, lengths: &[u8]) -> Vec<u32> {
assert_eq!(lengths.iter().sum::<u8>(), 32 as u8); assert_eq!(lengths.iter().sum::<u8>(), 32u8);
let mut pieces: Vec<u32> = Vec::with_capacity(lengths.len()); let mut pieces: Vec<u32> = Vec::with_capacity(lengths.len());
for i in 0..lengths.len() { for i in 0..lengths.len() {
assert!(lengths[i] > 0); assert!(lengths[i] > 0);
// lengths[i] bitstring of all 1's // lengths[i] bitstring of all 1's
let mask: u32 = (1 << lengths[i]) as u32 - 1; let mask: u32 = (1 << lengths[i]) as u32 - 1;
// Shift mask by bits already shifted // Shift mask by bits already shifted
let offset: u8 = lengths[0..i].into_iter().sum(); let offset: u8 = lengths[0..i].iter().sum();
let mask: u32 = mask << offset; let mask: u32 = mask << offset;
pieces.push((word & mask) >> offset as u32); pieces.push((word & mask) >> offset as u32);
} }
@ -65,14 +65,14 @@ pub fn chop_u32(word: u32, lengths: &[u8]) -> Vec<u32> {
// Chops a 64-bit word into pieces of given length. The lengths are specified // Chops a 64-bit word into pieces of given length. The lengths are specified
// starting from the little end. // starting from the little end.
pub fn chop_u64(word: u64, lengths: &[u8]) -> Vec<u64> { pub fn chop_u64(word: u64, lengths: &[u8]) -> Vec<u64> {
assert_eq!(lengths.iter().sum::<u8>(), 64 as u8); assert_eq!(lengths.iter().sum::<u8>(), 64u8);
let mut pieces: Vec<u64> = Vec::with_capacity(lengths.len()); let mut pieces: Vec<u64> = Vec::with_capacity(lengths.len());
for i in 0..lengths.len() { for i in 0..lengths.len() {
assert!(lengths[i] > 0); assert!(lengths[i] > 0);
// lengths[i] bitstring of all 1's // lengths[i] bitstring of all 1's
let mask: u64 = ((1 as u64) << lengths[i]) - 1; let mask: u64 = (1u64 << lengths[i]) - 1;
// Shift mask by bits already shifted // Shift mask by bits already shifted
let offset: u8 = lengths[0..i].into_iter().sum(); let offset: u8 = lengths[0..i].iter().sum();
let mask: u64 = mask << offset; let mask: u64 = mask << offset;
pieces.push((word & mask) >> offset as u64); pieces.push((word & mask) >> offset as u64);
} }