Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-camuto committed Mar 21, 2024
1 parent cc5f574 commit 54f5445
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion halo2_gadgets/benches/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where
let message_word = |i: usize| {
let value = self.message.map(|message_vals| message_vals[i]);
region.assign_advice(
|| format!("load message_{}", i),
|| format!("load message_{i}"),
config.input[i],
0,
|| value,
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl<
.enumerate()
{
self.sponge
.absorb(layouter.namespace(|| format!("absorb_{}", i)), value)?;
.absorb(layouter.namespace(|| format!("absorb_{i}")), value)?;
}
self.sponge
.finish_absorbing(layouter.namespace(|| "finish absorbing"))?
Expand Down
24 changes: 12 additions & 12 deletions halo2_gadgets/src/poseidon/pow5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl<
let mut state = Vec::with_capacity(WIDTH);
let mut load_state_word = |i: usize, value: F| -> Result<_, Error> {
let var = region.assign_advice_from_constant(
|| format!("state_{}", i),
|| format!("state_{i}"),
config.state[i],
0,
value,
Expand Down Expand Up @@ -325,7 +325,7 @@ impl<
initial_state[i]
.0
.copy_advice(
|| format!("load state_{}", i),
|| format!("load state_{i}"),
&mut region,
config.state[i],
0,
Expand All @@ -341,7 +341,7 @@ impl<
let constraint_var = match input.0[i].clone() {
Some(PaddedWord::Message(word)) => word,
Some(PaddedWord::Padding(padding_value)) => region.assign_fixed(
|| format!("load pad_{}", i),
|| format!("load pad_{i}"),
config.rc_b[i],
1,
|| Value::known(padding_value),
Expand All @@ -350,7 +350,7 @@ impl<
};
constraint_var
.copy_advice(
|| format!("load input_{}", i),
|| format!("load input_{i}"),
&mut region,
config.state[i],
1,
Expand All @@ -370,7 +370,7 @@ impl<
.unwrap_or_else(|| Value::known(F::ZERO));
region
.assign_advice(
|| format!("load output_{}", i),
|| format!("load output_{i}"),
config.state[i],
2,
|| value,
Expand Down Expand Up @@ -474,7 +474,7 @@ impl<F: Field, const WIDTH: usize> Pow5State<F, WIDTH> {
});

region.assign_advice(
|| format!("round_{} partial_sbox", round),
|| format!("round_{round} partial_sbox"),
config.partial_sbox,
offset,
|| r.as_ref().map(|r| r[0]),
Expand Down Expand Up @@ -536,7 +536,7 @@ impl<F: Field, const WIDTH: usize> Pow5State<F, WIDTH> {
let load_state_word = |i: usize| {
initial_state[i]
.0
.copy_advice(|| format!("load state_{}", i), region, config.state[i], 0)
.copy_advice(|| format!("load state_{i}"), region, config.state[i], 0)
.map(StateWord)
};

Expand All @@ -558,7 +558,7 @@ impl<F: Field, const WIDTH: usize> Pow5State<F, WIDTH> {
// Load the round constants.
let mut load_round_constant = |i: usize| {
region.assign_fixed(
|| format!("round_{} rc_{}", round, i),
|| format!("round_{round} rc_{i}"),
config.rc_a[i],
offset,
|| Value::known(config.round_constants[round][i]),
Expand All @@ -574,7 +574,7 @@ impl<F: Field, const WIDTH: usize> Pow5State<F, WIDTH> {
let next_state_word = |i: usize| {
let value = next_state[i];
let var = region.assign_advice(
|| format!("round_{} state_{}", next_round, i),
|| format!("round_{next_round} state_{i}"),
config.state[i],
offset + 1,
|| value,
Expand Down Expand Up @@ -649,7 +649,7 @@ mod tests {
let state_word = |i: usize| {
let value = Value::known(Fp::from(i as u64));
let var = region.assign_advice(
|| format!("load state_{}", i),
|| format!("load state_{i}"),
config.state[i],
0,
|| value,
Expand Down Expand Up @@ -688,7 +688,7 @@ mod tests {
|mut region| {
let mut final_state_word = |i: usize| {
let var = region.assign_advice(
|| format!("load final_state_{}", i),
|| format!("load final_state_{i}"),
config.state[i],
0,
|| Value::known(expected_final_state[i]),
Expand Down Expand Up @@ -774,7 +774,7 @@ mod tests {
let message_word = |i: usize| {
let value = self.message.map(|message_vals| message_vals[i]);
region.assign_advice(
|| format!("load message_{}", i),
|| format!("load message_{i}"),
config.state[i],
0,
|| value,
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/poseidon/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl<F: PrimeField, const RATE: usize, const L: usize> Domain<F, RATE> for Const
type Padding = iter::Take<iter::Repeat<F>>;

fn name() -> String {
format!("ConstantLength<{}>", L)
format!("ConstantLength<{L}>")
}

fn initial_capacity_element() -> F {
Expand Down
6 changes: 3 additions & 3 deletions halo2_proofs/benches/lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|mut table| {
for row in 0u64..(1 << 8) {
table.assign_cell(
|| format!("row {}", row),
|| format!("row {row}"),
config.table,
row as usize,
|| Value::known(F::from(row)),
Expand All @@ -131,7 +131,7 @@ fn criterion_benchmark(c: &mut Criterion) {
for offset in 0u64..(1 << 10) {
config.selector.enable(&mut region, offset as usize)?;
region.assign_advice(
|| format!("offset {}", offset),
|| format!("offset {offset}"),
config.advice,
offset as usize,
|| Value::known(F::from(offset % 256)),
Expand All @@ -140,7 +140,7 @@ fn criterion_benchmark(c: &mut Criterion) {
for offset in 1u64..(1 << 10) {
config.selector.enable(&mut region, offset as usize)?;
region.assign_advice(
|| format!("offset {}", offset),
|| format!("offset {offset}"),
config.other_advice,
offset as usize - 1,
|| Value::known(F::from(offset % 256)),
Expand Down
12 changes: 6 additions & 6 deletions halo2_proofs/examples/simple-lookup-unblinded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn main() {

let diff = lhs - rhs;

let constraint = diff.clone() * (Expression::Constant(F::ZERO) - diff.clone());
let constraint = diff.clone() * (Expression::Constant(F::ZERO) - diff);

Constraints::with_selector(s_mul, vec![constraint])
});
Expand All @@ -118,14 +118,14 @@ fn main() {
|mut table| {
for row in 0u64..2_u64.pow(K - 1) {
table.assign_cell(
|| format!("input row {}", row),
|| format!("input row {row}"),
config.table_input,
row as usize,
|| Value::known(F::from(row)),
)?;
// table output (2x the input) -- yeehaw
table.assign_cell(
|| format!("output row {}", row),
|| format!("output row {row}"),
config.table_output,
row as usize,
|| Value::known(F::from(2 * row)),
Expand All @@ -144,14 +144,14 @@ fn main() {
config.qlookup.enable(&mut region, offset as usize)?;
// input
region.assign_advice(
|| format!("offset {}", offset),
|| format!("offset {offset}"),
config.advice,
offset as usize,
|| Value::known(F::from(offset)),
)?;
// 2x
let cell = region.assign_advice(
|| format!("offset {}", offset),
|| format!("offset {offset}"),
config.other_advice,
offset as usize,
|| Value::known(F::from(2 * offset)),
Expand Down Expand Up @@ -247,7 +247,7 @@ fn main() {

env_logger::init();

println!("k = {}", K);
println!("k = {K}");
// time it
println!("keygen");
let start = std::time::Instant::now();
Expand Down
12 changes: 6 additions & 6 deletions halo2_proofs/examples/simple-lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn main() {

let diff = lhs - rhs;

let constraint = diff.clone() * (Expression::Constant(F::ZERO) - diff.clone());
let constraint = diff.clone() * (Expression::Constant(F::ZERO) - diff);

Constraints::with_selector(s_mul, vec![constraint])
});
Expand All @@ -118,14 +118,14 @@ fn main() {
|mut table| {
for row in 0u64..2_u64.pow(K - 1) {
table.assign_cell(
|| format!("input row {}", row),
|| format!("input row {row}"),
config.table_input,
row as usize,
|| Value::known(F::from(row)),
)?;
// table output (2x the input) -- yeehaw
table.assign_cell(
|| format!("output row {}", row),
|| format!("output row {row}"),
config.table_output,
row as usize,
|| Value::known(F::from(2 * row)),
Expand All @@ -144,14 +144,14 @@ fn main() {
config.qlookup.enable(&mut region, offset as usize)?;
// input
region.assign_advice(
|| format!("offset {}", offset),
|| format!("offset {offset}"),
config.advice,
offset as usize,
|| Value::known(F::from(offset)),
)?;
// 2x
let cell = region.assign_advice(
|| format!("offset {}", offset),
|| format!("offset {offset}"),
config.other_advice,
offset as usize,
|| Value::known(F::from(2 * offset)),
Expand Down Expand Up @@ -247,7 +247,7 @@ fn main() {

env_logger::init();

println!("k = {}", K);
println!("k = {K}");
// time it
println!("keygen");
let start = std::time::Instant::now();
Expand Down
14 changes: 8 additions & 6 deletions halo2_proofs/src/plonk/circuit/compress_selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ where
}

// Now, compute the selector and combination assignments.
let mut combination_assignment = vec![F::ZERO; n];
let mut combination_assignment = if return_polys {
vec![F::ZERO; n]
} else {
vec![]
};
let combination_len = combination.len();
let combination_index = combination_assignments.len();
let query = allocate_fixed_column();
Expand All @@ -207,6 +211,7 @@ where
}

// Update the combination assignment
// if return polys is false the iteration will not run as it is empty
for (combination, selector) in combination_assignment
.iter_mut()
.zip(selector.activations.iter())
Expand All @@ -226,11 +231,8 @@ where
expression,
}
}));
if return_polys {
combination_assignments.push(combination_assignment);
} else {
combination_assignments.push(vec![]);
}
// if return polys is false this is empty
combination_assignments.push(combination_assignment);
}

(combination_assignments, selector_assignments)
Expand Down

0 comments on commit 54f5445

Please sign in to comment.