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

Add transient storage constraints #524

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions specs/state-proof.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ to not be in the table.

### Transient Storage
- 5.0. `field_tag` is 0
- 5.1. `initial_value` is 0
- 5.2. `value` is 0 if first access and `READ`
- 5.3. `value` column at previous rotation equals `value_prev` at current rotation
- 5.4. `state root` is the same

### Call Context
- 6.0. `address` and `storage_key` are 0
Expand Down
17 changes: 17 additions & 0 deletions src/zkevm_specs/state_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Tag(IntEnum):
TxAccessListAccountStorage = 9
TxLog = 10
TxReceipt = 11
TransientStorage = 12


class Row(NamedTuple):
Expand Down Expand Up @@ -609,6 +610,8 @@ def keys_rwc_to_limbs_in_order(row: Row) -> List[FQ]:
check_tx_receipt(row, row_prev)
elif row.tag() == Tag.TxLog:
check_tx_log(row, row_prev)
elif row.tag() == Tag.AccountTransientStorage:
check_transient_storage(row, row_prev)
else:
raise ValueError("Unreachable")

Expand Down Expand Up @@ -824,6 +827,20 @@ def __new__(self, rw_counter: int, rw: RW, tx_id: int, field_tag: TxReceiptField
# fmt: on


class TransientStorageOp(Operation):
"""
TransientStorageOp Operation
"""

def __new__(self, rw_counter: int, rw: RW, tx_id: int, addr: U160, key: U256, value: FQ):
# fmt: off
return super().__new__(self, rw_counter, rw,
U256(Tag.TxReceipt), U256(tx_id), U256(0), U256(field_tag), U256(0), # keys
WordOrValue(value), WordOrValue(FQ(0)), # values
FQ(1)) # lexicographic_ordering_selector
# fmt: on


def op2row(op: Operation, root: Word) -> Row:
rw_counter = FQ(op.rw_counter)
is_write = FQ(0) if op.rw == RW.Read else FQ(1)
Expand Down
Loading