Skip to content

Commit

Permalink
speedup bytecode circuit assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
lispc committed Jan 2, 2023
1 parent 7587594 commit 4addc1c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
27 changes: 27 additions & 0 deletions zkevm-circuits/src/bytecode_circuit/bytecode_unroller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,36 @@ impl<F: Field> BytecodeCircuitConfig<F> {
assert!(size > self.minimum_rows);
let last_row_offset = size - self.minimum_rows + 1;

let mut is_first_time = true;

layouter.assign_region(
|| "assign bytecode",
|mut region| {
if is_first_time {
is_first_time = false;
self.set_row(
&mut region,
&push_rindex_is_zero_chip,
&length_is_zero_chip,
last_row_offset,
false,
true,
Value::known(F::zero()),
F::from(BytecodeFieldTag::Padding as u64),
F::zero(),
F::one(),
F::zero(),
0,
Value::known(F::zero()),
F::zero(),
F::zero(),
true,
true,
F::zero(),
)?;
return Ok(());
}

let mut offset = 0;
let mut push_rindex_prev = 0;
for bytecode in witness.iter() {
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ impl<F: Field> ExecutionConfig<F> {
.try_into()
.unwrap();

let mut is_first_time = false;
let mut is_first_time = true;

layouter.assign_region(
|| "Execution step",
Expand Down
38 changes: 19 additions & 19 deletions zkevm-circuits/src/keccak_circuit/keccak_packed_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use halo2_proofs::{
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Expression, Fixed, TableColumn},
poly::Rotation,
};
use log::{debug, info, trace};
use log::{debug, trace};
use std::{env::var, marker::PhantomData, vec};

const MAX_DEGREE: usize = 9;
Expand Down Expand Up @@ -947,9 +947,9 @@ impl<F: Field> SubCircuitConfig<F> for KeccakCircuitConfig<F> {
decode::expr(absorb_res),
absorb_result.expr(),
);
info!("- Post absorb:");
info!("Lookups: {}", lookup_counter);
info!("Columns: {}", cell_manager.get_width());
debug!("- Post absorb:");
debug!("Lookups: {}", lookup_counter);
debug!("Columns: {}", cell_manager.get_width());
total_lookup_counter += lookup_counter;

// Squeeze
Expand Down Expand Up @@ -993,9 +993,9 @@ impl<F: Field> SubCircuitConfig<F> for KeccakCircuitConfig<F> {
is_paddings.push(cell_manager.query_cell(meta));
data_rlcs.push(cell_manager.query_cell(meta));
}
info!("- Post padding:");
info!("Lookups: {}", lookup_counter);
info!("Columns: {}", cell_manager.get_width());
debug!("- Post padding:");
debug!("Lookups: {}", lookup_counter);
debug!("Columns: {}", cell_manager.get_width());
total_lookup_counter += lookup_counter;

// Theta
Expand Down Expand Up @@ -1053,9 +1053,9 @@ impl<F: Field> SubCircuitConfig<F> for KeccakCircuitConfig<F> {
}
}
s = os.clone();
info!("- Post theta:");
info!("Lookups: {}", lookup_counter);
info!("Columns: {}", cell_manager.get_width());
debug!("- Post theta:");
debug!("Lookups: {}", lookup_counter);
debug!("Columns: {}", cell_manager.get_width());
total_lookup_counter += lookup_counter;

// Rho/Pi
Expand Down Expand Up @@ -1142,9 +1142,9 @@ impl<F: Field> SubCircuitConfig<F> for KeccakCircuitConfig<F> {
});
lookup_counter += 1;
}
info!("- Post rho/pi:");
info!("Lookups: {}", lookup_counter);
info!("Columns: {}", cell_manager.get_width());
debug!("- Post rho/pi:");
debug!("Lookups: {}", lookup_counter);
debug!("Columns: {}", cell_manager.get_width());
total_lookup_counter += lookup_counter;

// Chi
Expand Down Expand Up @@ -1231,9 +1231,9 @@ impl<F: Field> SubCircuitConfig<F> for KeccakCircuitConfig<F> {
cb.require_equal("next row check", s[i][j].clone(), s_next[i][j].clone());
}
}
info!("- Post chi:");
info!("Lookups: {}", lookup_counter);
info!("Columns: {}", cell_manager.get_width());
debug!("- Post chi:");
debug!("Lookups: {}", lookup_counter);
debug!("Columns: {}", cell_manager.get_width());
total_lookup_counter += lookup_counter;

let mut lookup_counter = 0;
Expand Down Expand Up @@ -1279,9 +1279,9 @@ impl<F: Field> SubCircuitConfig<F> for KeccakCircuitConfig<F> {
.unwrap(),
true,
);
info!("- Post squeeze:");
info!("Lookups: {}", lookup_counter);
info!("Columns: {}", cell_manager.get_width());
debug!("- Post squeeze:");
debug!("Lookups: {}", lookup_counter);
debug!("Columns: {}", cell_manager.get_width());
total_lookup_counter += lookup_counter;

// The round constraints that we've been building up till now
Expand Down

0 comments on commit 4addc1c

Please sign in to comment.