Skip to content
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
2 changes: 0 additions & 2 deletions src/ethereum/forks/amsterdam/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/arrow_glacier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/berlin/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/bpo1/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/bpo2/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/bpo3/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/bpo4/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/bpo5/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/byzantium/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/cancun/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/constantinople/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/dao_fork/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/frontier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/gray_glacier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/homestead/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/istanbul/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/london/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/muir_glacier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/osaka/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/paris/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/prague/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/shanghai/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/spurious_dragon/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
2 changes: 0 additions & 2 deletions src/ethereum/forks/tangerine_whistle/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def encode_internal_node(node: Optional[InternalNode]) -> Extended:
def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
"""
Encode a Node for storage in the Merkle Trie.

Currently mostly an unimplemented stub.
"""
if isinstance(node, Account):
assert storage_root is not None
Expand Down
139 changes: 139 additions & 0 deletions tests/berlin/eip2929_gas_cost_increases/test_warm_status_revert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
"""
Tests that warm/cold access status is reverted when a sub-call reverts.
"""

import pytest
from execution_testing import (
Account,
Alloc,
CodeGasMeasure,
Conditional,
Environment,
Fork,
Op,
StateTestFiller,
Transaction,
)

REFERENCE_SPEC_GIT_PATH = "EIPS/eip-2929.md"
REFERENCE_SPEC_VERSION = "0e11417265a623adb680c527b15d0cb6701b870b"


@pytest.mark.valid_from("Berlin")
def test_storage_warm_status_reverted_by_subcall(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
) -> None:
"""
Test that storage slot warm status is reverted when a sub-call reverts.

Inner self-call does SLOAD(0) and SSTORE(0, 2) then REVERTs. After
revert, SLOAD(0) must be a cold access and storage[0] must still
hold its original value.
"""
env = Environment()

# Inner behavior (no calldata): warm slot 0 via SLOAD+SSTORE, revert.
inner_code = (
Op.POP(Op.SLOAD(0)) + Op.SSTORE(0, 2) + Op.REVERT(offset=0, size=0)
)

# Overhead: PUSH instructions for the SLOAD key argument.
sload_push_cost = (Op.PUSH1(0) * len(Op.SLOAD.kwargs)).gas_cost(fork)
cold_sload_cost = Op.SLOAD(key_warm=False).gas_cost(fork)

# After revert, measure gas of SLOAD(0) — should be cold.
sload_measure = CodeGasMeasure(
code=Op.SLOAD(0),
overhead_cost=sload_push_cost,
extra_stack_items=1,
sstore_key=1,
stop=False,
)

# Also verify storage[0] value (should still be 1).
verify_value = Op.SSTORE(2, Op.SLOAD(0))

# Outer behavior (has calldata): call self (inner), measure, verify.
outer_code = (
Op.POP(Op.CALL(gas=100_000, address=Op.ADDRESS))
+ sload_measure
+ verify_value
+ Op.STOP
)

code = Conditional(
condition=Op.CALLDATASIZE,
if_true=outer_code,
if_false=inner_code,
)

contract = pre.deploy_contract(code, storage={0: 1})
sender = pre.fund_eoa()

state_test(
env=env,
pre=pre,
post={
contract: Account(
storage={0: 1, 1: cold_sload_cost, 2: 1},
),
},
tx=Transaction(
sender=sender,
to=contract,
gas_limit=1_000_000,
data=b"\x01",
),
)


@pytest.mark.valid_from("Berlin")
def test_account_warm_status_reverted_by_subcall(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
) -> None:
"""
Test that account warm status is reverted when a sub-call reverts.

Inner call does BALANCE(target) then REVERTs. After revert,
BALANCE(target) in the outer call must be a cold access.
"""
env = Environment()

target = pre.fund_eoa(amount=1)

# Inner: BALANCE(target) warms target, then reverts.
inner = pre.deploy_contract(
Op.POP(Op.BALANCE(target)) + Op.REVERT(offset=0, size=0)
)

# Overhead: PUSH for the BALANCE address argument.
balance_push_cost = (Op.PUSH1(0) * len(Op.BALANCE.kwargs)).gas_cost(fork)
cold_balance_cost = Op.BALANCE(address_warm=False).gas_cost(fork)

# Outer: call inner (reverts), then measure BALANCE(target) gas.
outer = pre.deploy_contract(
Op.POP(Op.CALL(gas=100_000, address=inner))
+ CodeGasMeasure(
code=Op.BALANCE(target),
overhead_cost=balance_push_cost,
extra_stack_items=1,
sstore_key=0,
)
)

sender = pre.fund_eoa()

state_test(
env=env,
pre=pre,
post={outer: Account(storage={0: cold_balance_cost})},
tx=Transaction(
sender=sender,
to=outer,
gas_limit=1_000_000,
),
)
Loading
Loading