Skip to content

Commit 39fdd9f

Browse files
committed
Update the contract limit size to follow EIP170. Add tests against the size limit.
1 parent 1f60fd8 commit 39fdd9f

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

eth/vm/forks/spurious_dragon/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010

1111

1212
# https://github.com/ethereum/EIPs/issues/170
13-
EIP170_CODE_SIZE_LIMIT = 24577
13+
EIP170_CODE_SIZE_LIMIT = 24576
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import pytest
2+
3+
from eth_utils import (
4+
to_canonical_address,
5+
)
6+
7+
from eth.vm.message import (
8+
Message,
9+
)
10+
11+
from eth.vm.forks.spurious_dragon.computation import (
12+
SpuriousDragonComputation,
13+
)
14+
15+
from eth.vm.transaction_context import (
16+
BaseTransactionContext,
17+
)
18+
19+
20+
NORMALIZED_ADDRESS_A = "0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6"
21+
NORMALIZED_ADDRESS_B = "0xcd1722f3947def4cf144679da39c4c32bdc35681"
22+
CANONICAL_ADDRESS_A = to_canonical_address("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6")
23+
CANONICAL_ADDRESS_B = to_canonical_address("0xcd1722f3947def4cf144679da39c4c32bdc35681")
24+
CONTRACT_CODE_A = b""
25+
CONTRACT_CODE_B = b""
26+
CONTRACT_CODE_C = b""
27+
28+
29+
@pytest.fixture
30+
def state(chain_without_block_validation):
31+
state = chain_without_block_validation.get_vm().state
32+
state.account_db.set_balance(CANONICAL_ADDRESS_A, 1000)
33+
return state
34+
35+
36+
@pytest.fixture
37+
def transaction_context():
38+
tx_context = BaseTransactionContext(
39+
gas_price=1,
40+
origin=CANONICAL_ADDRESS_B,
41+
)
42+
return tx_context
43+
44+
45+
def test_code_size_limit(transaction_context, state):
46+
"""
47+
CONTRACT_CODE_A size is greater than EIP170_CODE_SIZE_LIMIT
48+
"""
49+
message_contract_code_a = Message(
50+
to=CANONICAL_ADDRESS_A,
51+
sender=CANONICAL_ADDRESS_B,
52+
value=100,
53+
data=b'',
54+
code=CONTRACT_CODE_A,
55+
gas=100,
56+
)
57+
computation = SpuriousDragonComputation(
58+
state=state,
59+
message=message_contract_code_a,
60+
transaction_context=transaction_context,
61+
)
62+
63+
"""
64+
TODO: CONTRACT_CODE_B size is equal to EIP170_CODE_SIZE_LIMIT
65+
"""
66+
message_contract_code_b = Message(
67+
to=CANONICAL_ADDRESS_A,
68+
sender=CANONICAL_ADDRESS_B,
69+
value=100,
70+
data=b'',
71+
code=CONTRACT_CODE_B,
72+
gas=100,
73+
)
74+
75+
"""
76+
TODO: CONTRACT_CODE_C size is lower than EIP170_CODE_SIZE_LIMIT
77+
"""
78+
message_contract_code_c = Message(
79+
to=CANONICAL_ADDRESS_A,
80+
sender=CANONICAL_ADDRESS_B,
81+
value=100,
82+
data=b'',
83+
code=CONTRACT_CODE_C,
84+
gas=100,
85+
)

0 commit comments

Comments
 (0)