Skip to content

Commit

Permalink
modify copy circuit try to fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamWuGit committed Aug 5, 2024
1 parent caad244 commit da3ace2
Showing 1 changed file with 64 additions and 29 deletions.
93 changes: 64 additions & 29 deletions zkevm-circuits/src/copy_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,23 +468,28 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
#[cfg(feature = "dual_bytecode")]
let is_first_bytecode = meta.query_advice(is_first_bytecode_table, CURRENT);

let cond = meta.query_fixed(q_enable, CURRENT)
let mut cond = meta.query_fixed(q_enable, CURRENT)
* meta.query_advice(is_bytecode, CURRENT)
* meta.query_advice(non_pad_non_mask, CURRENT);

// construct table for lookup
#[cfg(feature = "dual_bytecode")]
let table_expr: Vec<Expression<F>> = bytecode_table
.table_exprs_mini(meta)
.into_iter()
.zip_eq(bytecode_table1.table_exprs_mini(meta))
.map(|(first_table_item, second_table_item)| {
first_table_item * is_first_bytecode.clone()
+ not::expr(is_first_bytecode.clone()) * second_table_item
})
.collect();

#[cfg(not(feature = "dual_bytecode"))]
{
cond = cond * is_first_bytecode.expr();
}

// construct table for lookup
// #[cfg(feature = "dual_bytecode")]
// let table_expr: Vec<Expression<F>> = bytecode_table
// .table_exprs_mini(meta)
// .into_iter()
// .zip_eq(bytecode_table1.table_exprs_mini(meta))
// .map(|(first_table_item, second_table_item)| {
// first_table_item * is_first_bytecode.clone()
// + not::expr(is_first_bytecode.clone()) * second_table_item
// })
// .collect();

//#[cfg(not(feature = "dual_bytecode"))]
let table_expr = bytecode_table.table_exprs_mini(meta);

vec![
Expand All @@ -500,6 +505,44 @@ impl<F: Field> SubCircuitConfig<F> for CopyCircuitConfig<F> {
.collect()
});

// lookup second bytecode table
#[cfg(feature = "dual_bytecode")]
meta.lookup_any("Bytecode lookup", |meta| {
let is_first_bytecode = meta.query_advice(is_first_bytecode_table, CURRENT);

let mut cond = meta.query_fixed(q_enable, CURRENT)
* meta.query_advice(is_bytecode, CURRENT)
* meta.query_advice(non_pad_non_mask, CURRENT)
* (1.expr() - is_first_bytecode);

// construct table for lookup
// #[cfg(feature = "dual_bytecode")]
// let table_expr: Vec<Expression<F>> = bytecode_table
// .table_exprs_mini(meta)
// .into_iter()
// .zip_eq(bytecode_table1.table_exprs_mini(meta))
// .map(|(first_table_item, second_table_item)| {
// first_table_item * is_first_bytecode.clone()
// + not::expr(is_first_bytecode.clone()) * second_table_item
// })
// .collect();

//#[cfg(not(feature = "dual_bytecode"))]
let table_expr = bytecode_table1.table_exprs_mini(meta);

vec![
1.expr(),
meta.query_advice(id, CURRENT),
BytecodeFieldTag::Byte.expr(),
meta.query_advice(addr, CURRENT),
meta.query_advice(value, CURRENT),
]
.into_iter()
.zip_eq(table_expr)
.map(|(arg, table)| (cond.clone() * arg, table))
.collect()
});

meta.lookup_any("tx lookup for CallData", |meta| {
let cond = meta.query_fixed(q_enable, CURRENT)
* meta.query_advice(is_tx_calldata, CURRENT)
Expand Down Expand Up @@ -668,10 +711,12 @@ impl<F: Field> CopyCircuitConfig<F> {
copy_event: &CopyEvent,
#[cfg(feature = "dual_bytecode")] bytecode_map: &BTreeMap<Word, bool>,
) -> Result<(), Error> {
#[cfg(feature = "dual_bytecode")]
let copy_rows = CopyTable::assignments(copy_event, challenges, bytecode_map);
#[cfg(not(feature = "dual_bytecode"))]
let copy_rows = CopyTable::assignments(copy_event, challenges);
let copy_rows = CopyTable::assignments(
copy_event,
challenges,
#[cfg(feature = "dual_bytecode")]
bytecode_map,
);

for (step_idx, (tag, table_row, circuit_row)) in copy_rows.iter().enumerate() {
let is_read = step_idx % 2 == 0;
Expand Down Expand Up @@ -885,7 +930,7 @@ impl<F: Field> CopyCircuitConfig<F> {
}
}
);
#[cfg(feature = "dual_bytecode")]

self.assign_copy_event(
&mut region,
&mut offset,
Expand All @@ -895,19 +940,9 @@ impl<F: Field> CopyCircuitConfig<F> {
&lt_word_end_chip,
challenges,
copy_event,
#[cfg(feature = "dual_bytecode")]
bytecode_map,
)?;
#[cfg(not(feature = "dual_bytecode"))]
self.assign_copy_event(
&mut region,
&mut offset,
&tag_chip,
&is_id_unchange,
&is_src_end_chip,
&lt_word_end_chip,
challenges,
copy_event,
)?;
log::trace!("offset after {}th copy event: {}", ev_idx, offset);
}
for _ in 0..filler_rows {
Expand Down

0 comments on commit da3ace2

Please sign in to comment.