Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/zkevm_specs/evm/execution/copy_to_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def copy_to_log(instruction: Instruction):
instruction.constrain_equal(
byte,
instruction.tx_log_lookup(
aux.tx_id, TxLogFieldTag.Data, i + aux.data_start_index.n
aux.tx_id,
instruction.curr.log_id,
TxLogFieldTag.Data,
i + aux.data_start_index.n,
),
)

Expand Down
13 changes: 10 additions & 3 deletions src/zkevm_specs/evm/execution/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def log(instruction: Instruction):
if instruction.is_zero(is_persistent) == 0:
instruction.constrain_equal(
contract_address,
instruction.tx_log_lookup(tx_id=tx_id, field_tag=TxLogFieldTag.Address),
instruction.tx_log_lookup(
tx_id=tx_id, log_id=instruction.curr.log_id + 1, field_tag=TxLogFieldTag.Address
),
)

# constrain topics in stack & logs
Expand All @@ -44,7 +46,10 @@ def log(instruction: Instruction):
instruction.constrain_equal(
topic.expr(),
instruction.tx_log_lookup(
tx_id=tx_id, field_tag=TxLogFieldTag.Topic, index=i
tx_id=tx_id,
log_id=instruction.curr.log_id + 1,
field_tag=TxLogFieldTag.Topic,
index=i,
).expr(),
)

Expand Down Expand Up @@ -76,7 +81,9 @@ def log(instruction: Instruction):
next_memory_size, memory_expansion_gas = instruction.memory_expansion_dynamic_length(
mstart, msize
)
dynamic_gas = GAS_COST_LOG * (opcode - Opcode.LOG0) + 8 * msize + memory_expansion_gas
dynamic_gas = (
GAS_COST_LOG + GAS_COST_LOG * (opcode - Opcode.LOG0) + 8 * msize + memory_expansion_gas
)

assert isinstance(is_persistent, FQ)
instruction.step_state_transition_in_same_context(
Expand Down
4 changes: 2 additions & 2 deletions src/zkevm_specs/evm/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,14 @@ def tx_calldata_lookup(self, tx_id: Expression, call_data_index: Expression) ->

# look up tx log fields (Data, Address, Topic),
def tx_log_lookup(
self, tx_id: Expression, field_tag: TxLogFieldTag, index: int = 0
self, tx_id: Expression, log_id: Expression, field_tag: TxLogFieldTag, index: int = 0
) -> Expression:
# evm only write tx log
value = self.rw_lookup(
RW.Write,
RWTableTag.TxLog,
key1=tx_id,
key2=self.curr.log_id,
key2=log_id,
key3=FQ(field_tag),
key4=FQ(index),
).value
Expand Down
6 changes: 3 additions & 3 deletions tests/evm/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_logs(topics: list, mstart: U64, msize: U64, is_persistent: bool):
data = rand_bytes(msize)
topic_count = len(topics)
next_memory_size, memory_expansion_cost = memory_expansion(mstart, msize)
dynamic_gas = GAS_COST_LOG * topic_count + 8 * msize + memory_expansion_cost
dynamic_gas = GAS_COST_LOG + GAS_COST_LOG * topic_count + 8 * msize + memory_expansion_cost
bytecode = bytecodes[topic_count]
bytecode_hash = RLC(bytecode.hash(), randomness)
tx = Transaction(id=TX_ID, gas=dynamic_gas)
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_logs(topics: list, mstart: U64, msize: U64, is_persistent: bool):
)

if is_persistent:
rw_dictionary.tx_log_write(TX_ID, 0, TxLogFieldTag.Address, 0, FQ(CALLEE_ADDRESS))
rw_dictionary.tx_log_write(TX_ID, 1, TxLogFieldTag.Address, 0, FQ(CALLEE_ADDRESS))

# append topic rows
construct_topic_rws(rw_dictionary, 1017, topics, is_persistent, randomness)
Expand Down Expand Up @@ -252,7 +252,7 @@ def construct_topic_rws(
rw_dictionary.stack_read(CALL_ID, sp, RLC(topics[i], randomness, 32))
if is_persistent:
rw_dictionary.tx_log_write(
TX_ID, 0, TxLogFieldTag.Topic, i, RLC(topics[i], randomness, 32)
TX_ID, 1, TxLogFieldTag.Topic, i, RLC(topics[i], randomness, 32)
)

sp += 1