Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Jun 30, 2023
1 parent bde3eb2 commit 808e74a
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 97 deletions.
34 changes: 16 additions & 18 deletions bus-mapping/src/circuit_input_builder/tracer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ fn tracer_err_insufficient_balance() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -405,7 +405,7 @@ fn tracer_err_address_collision() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -525,7 +525,7 @@ fn tracer_create_collision_free() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -655,7 +655,7 @@ fn tracer_err_code_store_out_of_gas() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -705,7 +705,6 @@ fn tracer_err_code_store_out_of_gas_tx_deploy() {
txs[0]
.from(accs[1].address)
.gas(55000u64.into())
.nonce(0)
.input(code_creator.into());
},
|block, _tx| block.number(0x0264),
Expand Down Expand Up @@ -804,7 +803,7 @@ fn tracer_err_invalid_code() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -901,7 +900,7 @@ fn tracer_err_max_code_size_exceeded() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -951,7 +950,6 @@ fn tracer_err_max_code_size_exceeded_tx_deploy() {
txs[0]
.from(accs[1].address)
.gas(60000u64.into())
.nonce(0)
.input(code_creator.into());
},
|block, _tx| block.number(0x0264),
Expand Down Expand Up @@ -1042,7 +1040,7 @@ fn tracer_create_stop() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1160,7 +1158,7 @@ fn tracer_err_invalid_jump() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1260,7 +1258,7 @@ fn tracer_err_execution_reverted() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1319,7 +1317,7 @@ fn tracer_stop() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1387,7 +1385,7 @@ fn tracer_err_return_data_out_of_bounds() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1540,7 +1538,7 @@ fn tracer_err_write_protection(is_call: bool) {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1742,7 +1740,7 @@ fn create2_address() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1840,7 +1838,7 @@ fn create_address() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1924,7 +1922,7 @@ fn test_gen_access_trace() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -2146,7 +2144,7 @@ fn test_gen_access_trace_create_push_call_stack() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
txs[1].to(accs[1].address).from(accs[2].address);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down
1 change: 0 additions & 1 deletion bus-mapping/src/evm/opcodes/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ impl<const IS_CREATE2: bool> Opcode for Create<IS_CREATE2> {
(CallContextField::IsStatic, false.to_word()),
(CallContextField::IsCreate, true.to_word()),
(CallContextField::CodeHash, code_hash.to_word()),
(CallContextField::Value, callee.value),
] {
state.call_context_write(&mut exec_step, callee.call_id, field, value);
}
Expand Down
15 changes: 1 addition & 14 deletions mock/src/test_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ pub use external_tracer::LoggerConfig;
/// txs[0].to(accs[0].address).from(accs[2].address);
/// txs[1]
/// .to(accs[1].address)
/// .from(accs[2].address)
/// .nonce(1);
/// .from(accs[2].address);
/// },
/// |block, _tx| block.number(0xcafeu64),
/// )
Expand Down Expand Up @@ -132,18 +131,6 @@ impl<const NACC: usize, const NTX: usize> TestContext<NACC, NTX> {
.expect("Mismatched acc len");

let mut transactions = vec![MockTransaction::default(); NTX];
// By default, set the TxIndex and the Nonce values of the multiple transactions
// of the context correlative so that any Ok test passes by default.
// If the user decides to override these values, they'll then be set to whatever
// inputs were provided by the user.
transactions
.iter_mut()
.enumerate()
.skip(1)
.for_each(|(idx, tx)| {
let idx = u64::try_from(idx).expect("Unexpected idx conversion error");
tx.transaction_idx(idx).nonce(idx);
});
let tx_refs = transactions.iter_mut().collect();

// Build Tx modifiers.
Expand Down
4 changes: 2 additions & 2 deletions mock/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ impl MockTransaction {
self
}

/// Set nonce field for the MockTransaction.
pub fn nonce(&mut self, nonce: u64) -> &mut Self {
/// Set nonce field for the MockTransaction. Overridden in TestContext.
pub(crate) fn nonce(&mut self, nonce: u64) -> &mut Self {
self.nonce = nonce;
self
}
Expand Down
45 changes: 40 additions & 5 deletions zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::{
Challenges, Expr,
},
};
use bus_mapping::operation::Target;
use eth_types::{evm_unimplemented, Field};
use gadgets::util::not;
use halo2_proofs::{
Expand Down Expand Up @@ -1394,6 +1395,15 @@ impl<F: Field> ExecutionConfig<F> {
}
}

// TODO: We should find a better way to avoid this kind of special case.
// #1489 is the issue for this refactor.
if copy_lookup_count > 1 {
log::warn!("The number of copy events is more than 1, it's not supported by current design. Stop checking this step: {:?}",
step
);
return;
}

let rlc_assignments: BTreeSet<_> = (0..step.rw_indices_len())
.map(|index| block.get_rws(step, index))
.map(|rw| rw.table_assignment().unwrap().rlc(lookup_randomness))
Expand All @@ -1420,20 +1430,24 @@ impl<F: Field> ExecutionConfig<F> {

// Check that the number of rw operations generated from the bus-mapping
// correspond to the number of assigned rw lookups by the EVM Circuit
// plus the number of rw lookups done by the copy circuit.
if step.rw_indices_len() != assigned_rw_values.len() + step.copy_rw_counter_delta as usize {
// plus the number of rw lookups done by the copy circuit
// minus the number of copy lookup event.
if step.rw_indices_len()
!= assigned_rw_values.len() + step.copy_rw_counter_delta as usize - copy_lookup_count
{
log::error!(
"step.rw_indices.len: {} != assigned_rw_values.len: {} + step.copy_rw_counter_delta: {} in step: {:?}",
"step.rw_indices.len: {} != assigned_rw_values.len: {} + step.copy_rw_counter_delta: {} - copy_lookup_count: {} in step: {:?}",
step.rw_indices_len(),
assigned_rw_values.len(),
step.copy_rw_counter_delta,
copy_lookup_count,
step
);
}

let mut rev_count = 0;
let offset = 0;
let copy_lookup_processed = false;
let mut offset = 0;
let mut copy_lookup_processed = false;
for (idx, assigned_rw_value) in assigned_rw_values.iter().enumerate() {
let is_rev = if assigned_rw_value.0.contains(" with reversion") {
rev_count += 1;
Expand All @@ -1457,6 +1471,27 @@ impl<F: Field> ExecutionConfig<F> {
idx - rev_count + offset - copy_lookup_processed as usize
};

// If assigned_rw_value is a `copy lookup` event, the following
// `step.copy_rw_counter_delta` rw lookups must be memory operations.
if assigned_rw_value.0.starts_with("copy lookup") {
for i in 0..step.copy_rw_counter_delta as usize {
let index = idx + i;
let rw = block.get_rws(step, index);
if rw.tag() != Target::Memory {
log::error!(
"incorrect rw memory witness from copy lookup.\n lookup name: \"{}\"\n {}th rw of step {:?}, rw: {:?}",
assigned_rw_value.0,
index,
step.execution_state(),
rw);
}
}

offset = step.copy_rw_counter_delta as usize;
copy_lookup_processed = true;
continue;
}

let rw = block.get_rws(step, idx);
let table_assignments = rw.table_assignment();
let rlc = table_assignments.unwrap().rlc(lookup_randomness);
Expand Down
1 change: 0 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/begin_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,6 @@ mod test {
|mut txs, _accs| {
txs[0]
.from(MOCK_ACCOUNTS[0])
.nonce(nonce)
.gas_price(gwei(2))
.gas(Word::from(0x10000))
.value(eth(2))
Expand Down
6 changes: 2 additions & 4 deletions zkevm-circuits/src/evm_circuit/execution/end_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ mod test {
.to(accs[0].address)
.from(accs[1].address)
.gas(Word::from(30_000))
.gas_price(gwei(2))
.nonce(0);
.gas_price(gwei(2));
// txs[1]
// .to(accs[2].address)
// .from(accs[3].address)
Expand Down Expand Up @@ -445,8 +444,7 @@ mod test {
.to(accs[0].address)
.from(accs[1].address)
.gas(Word::from(50_000))
.gas_price(gwei(2))
.nonce(0);
.gas_price(gwei(2));
},
|block, _tx| block,
)
Expand Down
Loading

0 comments on commit 808e74a

Please sign in to comment.