Skip to content

Commit

Permalink
fix copytable lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamWuGit committed Jul 31, 2024
1 parent 7f6b2d7 commit e3799b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
14 changes: 8 additions & 6 deletions zkevm-circuits/src/copy_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ pub struct CopyCircuitConfig<F> {
pub is_word_end: IsEqualConfig<F>,
/// non pad and non mask witness to reduce the degree of lookups.
pub non_pad_non_mask: Column<Advice>,
#[cfg(feature = "dual_bytecode")]
/// Whether the bytecode is belong to the first bytecode sub circuit .
pub is_first_bytecode_table: Column<Advice>,
// External tables
/// TxTable
pub tx_table: TxTable,
Expand Down Expand Up @@ -185,7 +188,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
array_init(|_| meta.advice_column());
let is_first = copy_table.is_first;
#[cfg(feature = "dual_bytecode")]
let is_first_bytecode_table = copy_table.is_first_bytecode_table;
let is_first_bytecode_table = meta.advice_column_in(SecondPhase);
let id = copy_table.id;
let addr = copy_table.addr;
let src_addr_end = copy_table.src_addr_end;
Expand Down Expand Up @@ -497,7 +500,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
.collect()
});

meta.lookup_any("tx table calldata lookup", |meta| {
meta.lookup_any("tx lookup for CallData", |meta| {
let cond = meta.query_fixed(q_enable, CURRENT)
* meta.query_advice(is_tx_calldata, CURRENT)
* meta.query_advice(non_pad_non_mask, CURRENT);
Expand Down Expand Up @@ -638,6 +641,7 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
is_id_unchange,
is_src_end,
is_word_end,
is_first_bytecode_table,
non_pad_non_mask,
tx_table,
rw_table,
Expand Down Expand Up @@ -708,6 +712,7 @@ impl<F: Field> CopyCircuitConfig<F> {
self.mask,
self.front_mask,
self.word_index,
self.is_first_bytecode_table,
]
.iter()
.zip_eq(circuit_row)
Expand All @@ -725,9 +730,6 @@ impl<F: Field> CopyCircuitConfig<F> {

// lt chip
if is_read {
#[cfg(feature = "dual_bytecode")]
let addr = table_row[3].0;
#[cfg(not(feature = "dual_bytecode"))]
let addr = table_row[2].0;

is_src_end_chip.assign(
Expand Down Expand Up @@ -969,7 +971,7 @@ impl<F: Field> CopyCircuitConfig<F> {
// is_first_bytecode_table
region.assign_advice(
|| format!("assign is_first_bytecode_table {}", *offset),
self.copy_table.is_first_bytecode_table,
self.is_first_bytecode_table,
*offset,
|| Value::known(F::zero()),
)?;
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/copy_circuit/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ fn copy_circuit_invalid_calldatacopy() {

assert_error_matches(
test_copy_circuit_from_block(block),
vec!["rw lookup", "rw lookup"],
vec!["tx lookup for CallData", "rw lookup"],
);
}

Expand Down
29 changes: 8 additions & 21 deletions zkevm-circuits/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1726,9 +1726,6 @@ pub struct CopyTable {
pub q_enable: Column<Fixed>,
/// Whether the row is the first read-write pair for a copy event.
pub is_first: Column<Advice>,
#[cfg(feature = "dual_bytecode")]
/// Whether the bytecode is belong to the first bytecode sub circuit .
pub is_first_bytecode_table: Column<Advice>,
/// The relevant ID for the read-write row, represented as a random linear
/// combination. The ID may be one of the below:
/// 1. Call ID/Caller ID for CopyDataType::Memory
Expand Down Expand Up @@ -1761,13 +1758,10 @@ pub struct CopyTable {
/// TxLog. This also now includes various precompile calls, hence will take up more cells.
pub tag: BinaryNumberConfig<CopyDataType, { CopyDataType::N_BITS }>,
}
#[cfg(feature = "dual_bytecode")]
type CopyTableRow<F> = [(Value<F>, &'static str); 9];

#[cfg(not(feature = "dual_bytecode"))]
type CopyTableRow<F> = [(Value<F>, &'static str); 8];

type CopyCircuitRow<F> = [(Value<F>, &'static str); 10];
#[cfg(feature = "dual_bytecode")]
type CopyCircuitRow<F> = [(Value<F>, &'static str); 11];

/// CopyThread is the state used while generating rows of the copy table.
struct CopyThread<F: Field> {
Expand All @@ -1789,8 +1783,6 @@ impl CopyTable {
Self {
q_enable,
is_first: meta.advice_column(),
#[cfg(feature = "dual_bytecode")]
is_first_bytecode_table: meta.advice_column_in(SecondPhase),
id: meta.advice_column_in(SecondPhase),
tag: BinaryNumberChip::configure(meta, q_enable, None),
addr: meta.advice_column(),
Expand Down Expand Up @@ -2007,12 +1999,6 @@ impl CopyTable {
thread.tag,
[
(Value::known(F::from(is_first)), "is_first"),
#[cfg(feature = "dual_bytecode")]
(
// set value from block get bytecode circuit.
Value::known(F::from(is_first_bytecode_table)),
"is_first_bytecode_table",
),
(thread.id, "id"),
(Value::known(addr), "addr"),
(Value::known(F::from(thread.addr_end)), "src_addr_end"),
Expand All @@ -2035,6 +2021,12 @@ impl CopyTable {
(Value::known(F::from(copy_step.mask)), "mask"),
(Value::known(F::from(thread.front_mask)), "front_mask"),
(Value::known(F::from(word_index)), "word_index"),
#[cfg(feature = "dual_bytecode")]
(
// set value from block get bytecode circuit.
Value::known(F::from(is_first_bytecode_table)),
"is_first_bytecode_table",
),
],
));

Expand Down Expand Up @@ -2129,8 +2121,6 @@ impl<F: Field> LookupTable<F> for CopyTable {
vec![
self.q_enable.into(),
self.is_first.into(),
#[cfg(feature = "dual_bytecode")]
self.is_first_bytecode_table.into(),
self.id.into(),
self.addr.into(),
self.src_addr_end.into(),
Expand All @@ -2145,7 +2135,6 @@ impl<F: Field> LookupTable<F> for CopyTable {
vec![
String::from("q_enable"),
String::from("is_first"),
String::from("is_first_bytecode_circuit"),
String::from("id"),
String::from("addr"),
String::from("src_addr_end"),
Expand All @@ -2160,8 +2149,6 @@ impl<F: Field> LookupTable<F> for CopyTable {
vec![
meta.query_fixed(self.q_enable, Rotation::cur()),
meta.query_advice(self.is_first, Rotation::cur()),
#[cfg(feature = "dual_bytecode")]
meta.query_advice(self.is_first_bytecode_table, Rotation::cur()),
meta.query_advice(self.id, Rotation::cur()), // src_id
self.tag.value(Rotation::cur())(meta), // src_tag
meta.query_advice(self.id, Rotation::next()), // dst_id
Expand Down

0 comments on commit e3799b4

Please sign in to comment.