Skip to content

Commit

Permalink
Issue#422- rename RwTableTag to Target (privacy-scaling-explorations#431
Browse files Browse the repository at this point in the history
)
th3093 authored Jun 6, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 1b2185c commit 8c21467
Showing 6 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion specs/tables.md
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ DELETEME: Review note: Removed aux1 and aux2 and instead added InitialValue whic

| 0 *Rwc* | 1 *IsWrite* | 2 *Tag* k0 | 3 *Id* k1 | 4 *Address* k2 | 5 *FieldTag* k3 | 6,7 *StoKey{Lo,Hi}* k4,k5 | 7,8 *Val{Lo,Hi}* | 9,10 *ValPrev{Lo,Hi}* | 11,12 *InitVal{Lo,Hi}* |
| -------- | ----------- | -------------------------- | -------- | -------- | -------------------------- | ------------------------- | ---------------- | --------------------- | ---------------------- |
| | | *RwTableTag* | | | | | | | |
| | | *Target* | | | | | | | |
| $counter | true | TxAccessListAccount | $txID | $address | | | $val,0 | $valPrev,0 | |
| $counter | true | TxAccessListAccountStorage | $txID | $address | | $storageKey{Lo,Hi} | $val,0 | $valPrev,0 | |
| $counter | $isWrite | TxRefund | $txID | | | | $val,0 | $valPrev,0 | |
6 changes: 3 additions & 3 deletions src/zkevm_specs/copy_circuit.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
CopyDataTypeTag,
CopyCircuitRow,
RW,
RWTableTag,
Target,
CopyCircuit,
TxContextFieldTag,
BytecodeFieldTag,
@@ -106,7 +106,7 @@ def verify_copy_table(copy_circuit: CopyCircuit, tables: Tables, r: FQ):
# lookup into tables
if row.is_memory == 1 and row.is_pad == 0:
val = tables.rw_lookup(
row.rw_counter, 1 - row.q_step, FQ(RWTableTag.Memory), row.id.value(), row.addr
row.rw_counter, 1 - row.q_step, FQ(Target.Memory), row.id.value(), row.addr
).value.value()
cs.constrain_equal(val, row.value)
if row.is_bytecode == 1 and row.is_pad == 0:
@@ -123,7 +123,7 @@ def verify_copy_table(copy_circuit: CopyCircuit, tables: Tables, r: FQ):
val = tables.rw_lookup(
row.rw_counter,
FQ(RW.Write),
FQ(RWTableTag.TxLog),
FQ(Target.TxLog),
row.id.value(), # tx_id
row.addr,
).value.value()
40 changes: 20 additions & 20 deletions src/zkevm_specs/evm_circuit/instruction.py
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@
FixedTableTag,
TxContextFieldTag,
RW,
RWTableTag,
Target,
TxLogFieldTag,
TxReceiptFieldTag,
CopyDataTypeTag,
@@ -694,7 +694,7 @@ def tx_log_lookup_word(
# evm only write tx log
value = self.rw_lookup(
RW.Write,
RWTableTag.TxLog,
Target.TxLog,
id=tx_id,
address=FQ(index + (int(field_tag) << 32) + (log_id.expr().n << 48)),
field_tag=FQ(0),
@@ -711,7 +711,7 @@ def tx_receipt_read(
) -> Expression:
value = self.rw_lookup(
RW.Read,
RWTableTag.TxReceipt,
Target.TxReceipt,
id=tx_id,
address=FQ(0),
field_tag=FQ(field_tag),
@@ -728,7 +728,7 @@ def tx_receipt_write(
) -> Expression:
value = self.rw_lookup(
RW.Write,
RWTableTag.TxReceipt,
Target.TxReceipt,
id=tx_id,
address=FQ(0),
field_tag=FQ(field_tag),
@@ -775,7 +775,7 @@ def opcode_lookup_at(self, index: FQ, is_code: bool) -> FQ:
def rw_lookup(
self,
rw: RW,
tag: RWTableTag,
tag: Target,
id: Optional[Expression] = None,
address: Optional[Expression] = None,
field_tag: Optional[Expression] = None,
@@ -808,7 +808,7 @@ def rw_lookup(

def state_write(
self,
tag: RWTableTag,
tag: Target,
id: Optional[Expression] = None,
address: Optional[Expression] = None,
field_tag: Optional[Expression] = None,
@@ -847,7 +847,7 @@ def state_write(

def state_read(
self,
tag: RWTableTag,
tag: Target,
id: Optional[Expression] = None,
address: Optional[Expression] = None,
field_tag: Optional[Expression] = None,
@@ -875,11 +875,11 @@ def call_context_lookup_word(
) -> WordOrValue:
if call_id is None:
call_id = self.curr.call_id
return self.rw_lookup(rw, RWTableTag.CallContext, call_id, FQ(field_tag)).value
return self.rw_lookup(rw, Target.CallContext, call_id, FQ(field_tag)).value

def rw_table_start_lookup(self, counter: Expression):
# Raises exception if no lookup matches
self.rw_lookup(rw=RW.Read, tag=RWTableTag.Start, rw_counter=counter)
self.rw_lookup(rw=RW.Read, tag=Target.Start, rw_counter=counter)

def reversion_info(self, call_id: Optional[Expression] = None) -> ReversionInfo:
[rw_counter_end_of_reversion, is_persistent] = [
@@ -906,27 +906,27 @@ def stack_push(self) -> Word:

def stack_lookup(self, rw: RW, stack_pointer_offset: Expression) -> Word:
stack_pointer = self.curr.stack_pointer + stack_pointer_offset
return self.rw_lookup(rw, RWTableTag.Stack, self.curr.call_id, stack_pointer).value
return self.rw_lookup(rw, Target.Stack, self.curr.call_id, stack_pointer).value

def memory_lookup(
self, rw: RW, memory_address: Expression, call_id: Optional[Expression] = None
) -> FQ:
if call_id is None:
call_id = self.curr.call_id
return cast_expr(
self.rw_lookup(rw, RWTableTag.Memory, call_id, memory_address).value.value(), FQ
self.rw_lookup(rw, Target.Memory, call_id, memory_address).value.value(), FQ
)

def tx_refund_read(self, tx_id: Expression) -> FQ:
return cast_expr(self.rw_lookup(RW.Read, RWTableTag.TxRefund, tx_id).value.value(), FQ)
return cast_expr(self.rw_lookup(RW.Read, Target.TxRefund, tx_id).value.value(), FQ)

def tx_refund_write(
self,
tx_id: Expression,
reversion_info: Optional[ReversionInfo] = None,
) -> Tuple[FQ, FQ]:
row = self.state_write(
RWTableTag.TxRefund,
Target.TxRefund,
tx_id,
reversion_info=reversion_info,
)
@@ -941,7 +941,7 @@ def account_read_word(
self, account_address: Expression, account_field_tag: AccountFieldTag
) -> WordOrValue:
return self.rw_lookup(
RW.Read, RWTableTag.Account, address=account_address, field_tag=FQ(account_field_tag)
RW.Read, Target.Account, address=account_address, field_tag=FQ(account_field_tag)
).value

def account_write(
@@ -960,7 +960,7 @@ def account_write_word(
reversion_info: Optional[ReversionInfo] = None,
) -> Tuple[WordOrValue, WordOrValue]:
row = self.state_write(
RWTableTag.Account,
Target.Account,
address=account_address,
field_tag=FQ(account_field_tag),
reversion_info=reversion_info,
@@ -1000,7 +1000,7 @@ def account_storage_read(
) -> Word:
row = self.rw_lookup(
RW.Read,
RWTableTag.AccountStorage,
Target.AccountStorage,
tx_id,
account_address,
field_tag=None,
@@ -1016,7 +1016,7 @@ def account_storage_write(
reversion_info: Optional[ReversionInfo] = None,
) -> Tuple[Word, Word, Word]:
row = self.state_write(
RWTableTag.AccountStorage,
Target.AccountStorage,
tx_id,
account_address,
storage_key=storage_key,
@@ -1031,7 +1031,7 @@ def add_account_to_access_list(
reversion_info: Optional[ReversionInfo] = None,
) -> FQ:
row = self.state_write(
RWTableTag.TxAccessListAccount,
Target.TxAccessListAccount,
tx_id,
account_address,
value=FQ(1),
@@ -1045,7 +1045,7 @@ def read_account_to_access_list(
account_address: Expression,
) -> FQ:
row = self.state_read(
RWTableTag.TxAccessListAccount,
Target.TxAccessListAccount,
tx_id,
account_address,
)
@@ -1059,7 +1059,7 @@ def add_account_storage_to_access_list(
reversion_info: Optional[ReversionInfo] = None,
) -> FQ:
row = self.state_write(
RWTableTag.TxAccessListAccountStorage,
Target.TxAccessListAccountStorage,
tx_id,
account_address,
storage_key=storage_key,
16 changes: 8 additions & 8 deletions src/zkevm_specs/evm_circuit/table.py
Original file line number Diff line number Diff line change
@@ -180,7 +180,7 @@ class RW(IntEnum):
Write = 1


class RWTableTag(IntEnum):
class Target(IntEnum):
"""
Tag for RWTable lookup, where the RWTable an advice-column table built by
prover, which will be part of State circuit and each unit read-write data
@@ -206,11 +206,11 @@ class RWTableTag(IntEnum):
# to write them with reversion when the write might fail.
def write_with_reversion(self) -> bool:
return self in [
RWTableTag.TxAccessListAccount,
RWTableTag.TxAccessListAccountStorage,
RWTableTag.Account,
RWTableTag.AccountStorage,
RWTableTag.TxRefund,
Target.TxAccessListAccount,
Target.TxAccessListAccountStorage,
Target.Account,
Target.AccountStorage,
Target.TxRefund,
]


@@ -263,7 +263,7 @@ class CallContextFieldTag(IntEnum):
# CallState in the end by callee.
# Note that stack and memory could also be included here, but since they
# need extra constraints on their data format, so we separate them to be
# different kinds of RWTableTag.
# different kinds of Target.
ProgramCounter = auto()
StackPointer = auto()
GasLeft = auto()
@@ -427,7 +427,7 @@ class BytecodeTableRow(TableRow):
class RWTableRow(TableRow):
rw_counter: Expression
rw: Expression
key0: Expression # RWTableTag
key0: Expression # Target
id: Expression = field(default=FQ(0))
address: Expression = field(default=FQ(0))
field_tag: Expression = field(default=FQ(0))
Loading

0 comments on commit 8c21467

Please sign in to comment.