Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 0f82ed1

Browse files
committed
save
1 parent 0015c28 commit 0f82ed1

File tree

2 files changed

+103
-62
lines changed

2 files changed

+103
-62
lines changed

gadgets/src/less_than.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ impl<F: Field, const N_BYTES: usize> LtConfig<F, N_BYTES> {
5353
let rotation = rotation.unwrap_or_else(Rotation::cur);
5454
sum::expr(self.diff.iter().map(|c| meta.query_advice(*c, rotation)))
5555
}
56+
57+
/// Annotates the Lt chip's columns.
58+
pub fn annotate<N, AR>(&self, region: &mut Region<'_, F>, name: N)
59+
where
60+
N: Fn() -> AR,
61+
AR: Into<String>,
62+
{
63+
region.name_column(|| format!("{}.lt", name().into()), self.lt);
64+
for (idx, diff_column) in self.diff.iter().enumerate() {
65+
region.name_column(|| format!("{}.diff[{}]", name().into(), idx), *diff_column);
66+
}
67+
}
5668
}
5769

5870
/// Chip that compares lhs < rhs.

zkevm-circuits/src/copy_circuit.rs

Lines changed: 91 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use halo2_proofs::{
2626
poly::Rotation,
2727
};
2828
use itertools::Itertools;
29-
use std::{array, collections::BTreeMap, marker::PhantomData};
29+
use std::{array, collections::BTreeMap, iter, marker::PhantomData};
3030

3131
use gadgets::less_than::{LtChip, LtConfig};
3232
#[cfg(feature = "onephase")]
@@ -242,26 +242,28 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
242242
let is_not_back_mask_exprs = is_inbound_read.clone().map(|chip| chip.is_lt(meta, None));
243243
let is_inbound_read_exprs = is_inbound_read.clone().map(|chip| chip.is_lt(meta, None));
244244

245-
constrain_id(
246-
cb,
247-
meta,
248-
//is_bytecode,
249-
is_tx_log,
250-
is_tx_calldata,
251-
is_memory,
252-
id,
253-
is_pad,
254-
);
245+
// TODO: feat/copy-hi-lo
246+
// constrain_id(
247+
// cb,
248+
// meta,
249+
// //is_bytecode,
250+
// is_tx_log,
251+
// is_tx_calldata,
252+
// is_memory,
253+
// id,
254+
// is_pad,
255+
// );
255256

256257
let is_tx_log = meta.query_advice(is_tx_log, CURRENT);
257258
let is_access_list = meta.query_advice(is_access_list_address, CURRENT)
258259
+ meta.query_advice(is_access_list_storage_key, CURRENT);
259-
260-
constrain_first_last(cb, is_reader.expr(), is_first.expr(), is_last.expr());
261-
262-
constrain_must_terminate(cb, meta, q_enable, &tag);
263-
264-
constrain_forward_parameters(cb, meta, is_continue.expr(), id, tag, src_addr_end);
260+
// TODO: feat/copy-hi-lo
261+
//
262+
// constrain_first_last(cb, is_reader.expr(), is_first.expr(), is_last.expr());
263+
//
264+
// constrain_must_terminate(cb, meta, q_enable, &tag);
265+
//
266+
// constrain_forward_parameters(cb, meta, is_continue.expr(), id, tag, src_addr_end);
265267

266268
// let (is_pad, is_pad_next) = constrain_is_pad(
267269
// cb,
@@ -292,6 +294,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
292294
// )
293295
// };
294296

297+
// TODO: feat/copy-hi-lo
295298
constrain_non_pad_non_mask(
296299
cb,
297300
meta,
@@ -303,20 +306,21 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
303306

304307
//constrain_masked_value(cb, meta, mask.expr(), value, value_prev);
305308

306-
constrain_value_rlc(
307-
cb,
308-
meta,
309-
is_first.expr(),
310-
is_continue.expr(),
311-
is_last_col,
312-
non_pad_non_mask,
313-
is_inbound_read.clone(),
314-
value_acc,
315-
value_limbs,
316-
challenges.keccak_input(),
317-
);
318-
319-
constrain_event_rlc_acc(cb, meta, is_last_col, value_acc, rlc_acc, is_bytecode, tag);
309+
// TODO: feat/copy-hi-lo
310+
// constrain_value_rlc(
311+
// cb,
312+
// meta,
313+
// is_first.expr(),
314+
// is_continue.expr(),
315+
// is_last_col,
316+
// non_pad_non_mask,
317+
// is_inbound_read.clone(),
318+
// value_acc,
319+
// value_limbs,
320+
// challenges.keccak_input(),
321+
// );
322+
//
323+
// constrain_event_rlc_acc(cb, meta, is_last_col, value_acc, rlc_acc, is_bytecode, tag);
320324

321325
// no word_rlc required after word hi lo
322326
// Apply the same constraints for the RLCs of words before and after the write.
@@ -334,21 +338,22 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
334338
// );
335339
// }
336340

337-
constrain_address(cb, meta, is_continue.expr(), addr);
338-
339-
{
340-
let is_rw_word_type = meta.query_advice(is_memory, CURRENT) + is_tx_log.expr();
341-
let is_rw_type = is_rw_word_type.expr() + is_access_list.expr();
342-
343-
constrain_rw_counter(
344-
cb,
345-
meta,
346-
is_last.expr(),
347-
is_rw_type.expr(),
348-
rw_counter,
349-
rwc_inc_left,
350-
);
351-
}
341+
// TODO: feat/copy-hi-lo
342+
// constrain_address(cb, meta, is_continue.expr(), addr);
343+
//
344+
// {
345+
// let is_rw_word_type = meta.query_advice(is_memory, CURRENT) + is_tx_log.expr();
346+
// let is_rw_type = is_rw_word_type.expr() + is_access_list.expr();
347+
//
348+
// constrain_rw_counter(
349+
// cb,
350+
// meta,
351+
// is_last.expr(),
352+
// is_rw_type.expr(),
353+
// rw_counter,
354+
// rwc_inc_left,
355+
// );
356+
// }
352357

353358
cb.gate(meta.query_fixed(q_enable, CURRENT))
354359
});
@@ -749,20 +754,28 @@ impl<F: Field> CopyCircuitConfig<F> {
749754
region.name_column(|| "value_word", self.value_word);
750755
region.name_column(|| "value_word_prev", self.value_word_prev);
751756
region.name_column(|| "value_acc", self.value_acc);
757+
for (idx, (chip, name)) in self
758+
.is_front_mask
759+
.iter()
760+
.zip(iter::repeat("is_front_mask"))
761+
.enumerate()
762+
.chain(
763+
self.is_not_back_mask
764+
.iter()
765+
.zip(iter::repeat("is_not_back_mask"))
766+
.enumerate(),
767+
)
768+
.chain(
769+
self.is_inbound_read
770+
.iter()
771+
.zip(iter::repeat("is_inbound_read"))
772+
.enumerate(),
773+
)
774+
{
775+
chip.annotate(&mut region, || format!("{}[{}]", name, idx))
776+
}
752777
for i in 0..16 {
753778
region.name_column(|| format!("value_limbs[{}]", i), self.value_limbs[i]);
754-
region.name_column(
755-
|| format!("is_front_mask[{}].lt", i),
756-
self.is_front_mask[i].lt,
757-
);
758-
region.name_column(
759-
|| format!("is_not_back_mask[{}].lt", i),
760-
self.is_not_back_mask[i].lt,
761-
);
762-
region.name_column(
763-
|| format!("is_inbound_read[{}].lt", i),
764-
self.is_inbound_read[i].lt,
765-
);
766779
region.name_column(
767780
|| format!("non_pad_non_mask[{}]", i),
768781
self.non_pad_non_mask[i],
@@ -890,6 +903,20 @@ impl<F: Field> CopyCircuitConfig<F> {
890903
*offset,
891904
|| Value::known(F::one()),
892905
)?;
906+
// addr_copy_start
907+
region.assign_advice(
908+
|| format!("assign addr_copy_start {}", *offset),
909+
self.copy_table.addr_copy_start,
910+
*offset,
911+
|| Value::known(F::zero()),
912+
)?;
913+
// addr_copy_end
914+
region.assign_advice(
915+
|| format!("assign addr_copy_end {}", *offset),
916+
self.copy_table.addr_copy_end,
917+
*offset,
918+
|| Value::known(F::zero()),
919+
)?;
893920
// real_bytes_left
894921
region.assign_advice(
895922
|| format!("assign bytes_left {}", *offset),
@@ -953,14 +980,16 @@ impl<F: Field> CopyCircuitConfig<F> {
953980
// tag
954981
tag_chip.assign(region, *offset, &CopyDataType::Padding)?;
955982

956-
for ((is_front_mask, is_not_back_mask), is_inbound_read) in is_front_mask_chip
983+
for (idx, ((is_front_mask, is_not_back_mask), is_inbound_read)) in is_front_mask_chip
957984
.iter()
958985
.zip(is_not_back_mask_chip)
959986
.zip(is_inbound_read_chip)
987+
.enumerate()
960988
{
961-
is_front_mask.assign(region, *offset, F::one(), F::zero())?;
962-
is_not_back_mask.assign(region, *offset, F::one(), F::zero())?;
963-
is_inbound_read.assign(region, *offset, F::one(), F::zero())?;
989+
let address = F::from(idx as u64);
990+
is_front_mask.assign(region, *offset, address, F::zero())?;
991+
is_not_back_mask.assign(region, *offset, address, F::zero())?;
992+
is_inbound_read.assign(region, *offset, address, F::zero())?;
964993
}
965994

966995
for (idx, non_pad_non_mask) in self.non_pad_non_mask.iter().enumerate() {

0 commit comments

Comments
 (0)