Skip to content

Commit

Permalink
memory_opt: Prevent an event from spilling into the disabled rows.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurélien Nicolas committed Jul 13, 2023
1 parent 212e12d commit 06e8139
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions zkevm-circuits/src/copy_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
- meta.query_advice(is_last, Rotation::cur())
- meta.query_advice(is_last, Rotation::next());

// Prevent an event from spilling into the disabled rows. This also ensures that eventually is_last=1.
cb.require_zero("the next row is enabled", is_continue.expr() * not::expr(meta.query_fixed(q_enable, Rotation::next())));

let is_word_end = is_word_end.is_equal_expression.expr();

// Apply the same constraints for the RLCs of words before and after the write.
Expand Down Expand Up @@ -736,13 +739,6 @@ impl<F: Field> CopyCircuitConfig<F> {
{
let is_read = step_idx % 2 == 0;

region.assign_fixed(
|| format!("q_enable at row: {offset}"),
self.q_enable,
*offset,
|| Value::known(F::one()),
)?;

// Copy table assignments
for (&column, &(value, label)) in
<CopyTable as LookupTable<F>>::advice_columns(&self.copy_table)
Expand Down Expand Up @@ -880,9 +876,7 @@ impl<F: Field> CopyCircuitConfig<F> {
.sum::<usize>();

// The `+ 2` is used to take into account the two extra empty copy rows needed
// to satisfy the query at `Rotation(2)` performed inside of the
// `rows[2].value == rows[0].value * r + rows[1].value` requirement in the RLC
// Accumulation gate.
// to satisfy the queries at `Rotation(2)`.
assert!(
copy_rows_needed + 2 <= max_copy_rows,
"copy rows not enough {copy_rows_needed} vs {max_copy_rows}"
Expand Down Expand Up @@ -976,14 +970,14 @@ impl<F: Field> CopyCircuitConfig<F> {
lt_chip: &LtChip<F, 8>,
lt_word_end_chip: &IsEqualChip<F>,
) -> Result<(), Error> {
// q_enable
region.assign_fixed(
|| "q_enable",
self.q_enable,
*offset,
|| Value::known(F::from(!is_last_two)),
)?;
if !is_last_two {
// q_enable
region.assign_fixed(
|| "q_enable",
self.q_enable,
*offset,
|| Value::known(F::one()),
)?;
// q_step
if *offset % 2 == 0 {
self.q_step.enable(region, *offset)?;
Expand Down

0 comments on commit 06e8139

Please sign in to comment.