Skip to content

Commit f5b44ce

Browse files
authored
Merge pull request #2018 from fselmo/eip-3554-and-eip-3541
EIP-3554 and EIP-3541
2 parents efa07f7 + 8005e7f commit f5b44ce

File tree

13 files changed

+420
-137
lines changed

13 files changed

+420
-137
lines changed

eth/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,11 @@ class OutOfBoundsRead(VMError):
195195
boundaries of the buffer (such as with RETURNDATACOPY)
196196
"""
197197
pass
198+
199+
200+
class ReservedBytesInCode(VMError):
201+
"""
202+
Raised when bytes for the code to be deployed are reserved
203+
for a particular reason.
204+
"""
205+
pass

eth/vm/forks/frontier/constants.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,2 @@
1-
from eth_typing import (
2-
Address
3-
)
4-
5-
CREATE_CONTRACT_ADDRESS = Address(b'')
6-
7-
8-
#
9-
# Difficulty
10-
#
111
FRONTIER_DIFFICULTY_ADJUSTMENT_CUTOFF = 13
12-
13-
14-
#
15-
# Stack Limit
16-
#
17-
STACK_DEPTH_LIMIT = 1024
18-
19-
20-
#
21-
# Gas Costs and Refunds
22-
#
232
REFUND_SELFDESTRUCT = 24000
24-
GAS_CODEDEPOSIT = 200

eth/vm/forks/homestead/constants.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,3 @@
22
# Difficulty
33
#
44
HOMESTEAD_DIFFICULTY_ADJUSTMENT_CUTOFF = 10
5-
6-
7-
#
8-
# Gas Costs and Refunds
9-
#
10-
GAS_CODEDEPOSIT = 200

eth/vm/forks/london/computation.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from eth.exceptions import ReservedBytesInCode
12
from eth.vm.forks.berlin.computation import (
23
BerlinComputation,
34
)
45

56
from .opcodes import LONDON_OPCODES
7+
from ..london.constants import EIP3541_RESERVED_STARTING_BYTE
68

79

810
class LondonComputation(BerlinComputation):
@@ -11,3 +13,10 @@ class LondonComputation(BerlinComputation):
1113
Inherits from :class:`~eth.vm.forks.berlin.BerlinComputation`
1214
"""
1315
opcodes = LONDON_OPCODES
16+
17+
@classmethod
18+
def validate_new_contract_code(cls, contract_code: bytes) -> None:
19+
if contract_code[:1] == EIP3541_RESERVED_STARTING_BYTE:
20+
raise ReservedBytesInCode(
21+
"Contract code begins with EIP3541 reserved byte '0xEF'."
22+
)

eth/vm/forks/london/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
BASE_FEE_MAX_CHANGE_DENOMINATOR = 8
1212
INITIAL_BASE_FEE = 1000000000
1313
ELASTICITY_MULTIPLIER = 2
14+
15+
EIP3541_RESERVED_STARTING_BYTE = b'\xef'

eth/vm/forks/london/headers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
from eth.constants import GENESIS_GAS_LIMIT
2323
from eth.rlp.headers import BlockHeader
2424
from eth.vm.forks.berlin.headers import (
25-
compute_berlin_difficulty,
2625
configure_header,
2726
)
27+
from eth.vm.forks.muir_glacier.headers import (
28+
compute_difficulty,
29+
)
30+
2831

2932
from .blocks import LondonBlockHeader
3033
from .constants import (
@@ -121,7 +124,7 @@ def create_header_from_parent(difficulty_fn: Callable[[BlockHeaderAPI, int], int
121124
return new_header
122125

123126

124-
compute_london_difficulty = compute_berlin_difficulty
127+
compute_london_difficulty = compute_difficulty(9700000)
125128

126129
create_london_header_from_parent = create_header_from_parent(
127130
compute_london_difficulty

eth/vm/forks/spurious_dragon/computation.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from eth_hash.auto import keccak
2+
23
from eth_utils import (
34
encode_hex,
45
)
@@ -12,12 +13,13 @@
1213
)
1314
from eth.exceptions import (
1415
OutOfGas,
16+
VMError,
1517
)
1618
from eth.vm.forks.homestead.computation import (
1719
HomesteadComputation,
1820
)
1921

20-
from .constants import EIP170_CODE_SIZE_LIMIT
22+
from ..spurious_dragon.constants import EIP170_CODE_SIZE_LIMIT
2123
from .opcodes import SPURIOUS_DRAGON_OPCODES
2224

2325

@@ -68,6 +70,12 @@ def apply_create_message(
6870
computation.error = err
6971
state.revert(snapshot)
7072
else:
73+
try:
74+
cls.validate_new_contract_code(contract_code)
75+
except VMError as err:
76+
state.revert(snapshot)
77+
raise err
78+
7179
if cls.logger:
7280
cls.logger.debug2(
7381
"SETTING CODE: %s -> length: %s | hash: %s",
@@ -81,3 +89,8 @@ def apply_create_message(
8189
else:
8290
state.commit(snapshot)
8391
return computation
92+
93+
@classmethod
94+
def validate_new_contract_code(cls, contract_code: bytes) -> None:
95+
# helps facilitate EIP-3541 validation in LondonComputation
96+
pass

eth/vm/forks/spurious_dragon/constants.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#
2-
# Gas Costs and Refunds
3-
#
4-
GAS_CODEDEPOSIT = 200
5-
6-
71
# https://github.com/ethereum/EIPs/issues/160
82
GAS_EXP_EIP160 = 10
93
GAS_EXPBYTE_EIP160 = 50

newsfragments/2018.feature.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Implement `EIP-3554 <https://eips.ethereum.org/EIPS/eip-3554>`_ for London support.
2+
3+
Implement `EIP-3541 <https://eips.ethereum.org/EIPS/eip-3541>`_ for London support.

tests/core/vm/conftest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
from eth_utils import to_canonical_address
3+
4+
from eth.vm.transaction_context import BaseTransactionContext
5+
6+
7+
@pytest.fixture
8+
def normalized_address_a():
9+
return "0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6"
10+
11+
12+
@pytest.fixture
13+
def normalized_address_b():
14+
return "0xcd1722f3947def4cf144679da39c4c32bdc35681"
15+
16+
17+
@pytest.fixture
18+
def canonical_address_a(normalized_address_a):
19+
return to_canonical_address(normalized_address_a)
20+
21+
22+
@pytest.fixture
23+
def canonical_address_b(normalized_address_b):
24+
return to_canonical_address(normalized_address_b)
25+
26+
27+
@pytest.fixture
28+
def transaction_context(canonical_address_b):
29+
tx_context = BaseTransactionContext(
30+
gas_price=1,
31+
origin=canonical_address_b,
32+
)
33+
return tx_context

0 commit comments

Comments
 (0)