Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 75f1bf5

Browse files
authored
Merge pull request #415 from ethereum/eip150tests
EIP150 for `develop` branch / release
2 parents 96302c1 + ae3f9fe commit 75f1bf5

File tree

9 files changed

+183
-70
lines changed

9 files changed

+183
-70
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ script:
2828
after_success:
2929
- travis_retry pip install coveralls
3030
- cd .tox/$TOX_ENV && coveralls
31-
after_script:
32-
- cat .tox/$TOX_ENV/log/*.log; true
3331
notifications:
3432
slack:
3533
secure: W/UAhQ/GgYwMWrl3aiVAVOWr4WGdWrxUOX/rTB3ZgwDwGqDYLzQO5UqbsQlo1JXPZ6JOWfIPMURhHu7DSfue9dBW6xQ+NL+bFHe9lSXG4nqFK3IjezYyTBzNRJRDbGUvSSqgj6D5cwhJ8BjfUIRPbJz3CxL64KmsNXezEaMY60w=

ethereum/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
DAO_FORK_BLKNUM=1920000,
6464
CHILD_DAO_LIST=map(utils.normalize_address, child_dao_list),
6565
DAO_WITHDRAWER=utils.normalize_address('0xbf4ed7b27f1d666546e30d74d50d173d20bca754'),
66+
# Anti-DoS fork
67+
ANTI_DOS_FORK_BLKNUM=2457000,
68+
CLEARING_FORK_BLKNUM=2 ** 98,
6669
)
6770
assert default_config['NEPHEW_REWARD'] == \
6871
default_config['BLOCK_REWARD'] // 32

ethereum/opcodes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,12 @@
111111

112112
GCALLNEWACCOUNT = 25000
113113
GSUICIDEREFUND = 24000
114+
115+
# Anti-DoS HF changes
116+
SLOAD_SUPPLEMENTAL_GAS = 150
117+
CALL_SUPPLEMENTAL_GAS = 660
118+
EXTCODELOAD_SUPPLEMENTAL_GAS = 680
119+
BALANCE_SUPPLEMENTAL_GAS = 380
120+
CALL_CHILD_LIMIT_NUM = 63
121+
CALL_CHILD_LIMIT_DENOM = 64
122+
SUICIDE_SUPPLEMENTAL_GAS = 5000

ethereum/processblock.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ def __init__(self, block, tx):
248248
self.create = lambda msg: create_contract(self, msg)
249249
self.msg = lambda msg: _apply_msg(self, msg, self.get_code(msg.code_address))
250250
self.account_exists = block.account_exists
251-
self.post_homestead_hardfork = lambda: block.number >= block.config['HOMESTEAD_FORK_BLKNUM']
251+
self.post_homestead_hardfork = block.number >= block.config['HOMESTEAD_FORK_BLKNUM']
252+
self.post_anti_dos_hardfork = block.number >= block.config['ANTI_DOS_FORK_BLKNUM']
252253

253254

254255
def apply_msg(ext, msg):

ethereum/tests/test_blocks.py

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from rlp import DecodingError, DeserializationError
66
import sys
77
import ethereum.testutils as testutils
8+
from ethereum.testutils import get_config_overrides
89
import copy
910

1011
from ethereum.slogging import get_logger
@@ -69,47 +70,47 @@ def run_block_test(params, config_overrides={}):
6970
blockmap = {b.hash: b}
7071
env.db.put(b.hash, rlp.encode(b))
7172
old_config = copy.deepcopy(env.config)
72-
for k, v in config_overrides.items():
73-
env.config[k] = v
74-
b2 = None
75-
for blk in params["blocks"]:
76-
if 'blockHeader' not in blk:
77-
try:
73+
try:
74+
for k, v in config_overrides.items():
75+
env.config[k] = v
76+
b2 = None
77+
for blk in params["blocks"]:
78+
if 'blockHeader' not in blk:
79+
try:
80+
rlpdata = decode_hex(blk["rlp"][2:])
81+
blkparent = rlp.decode(
82+
rlp.encode(rlp.decode(rlpdata)[0]), blocks.BlockHeader).prevhash
83+
b2 = rlp.decode(rlpdata, blocks.Block, parent=blockmap[blkparent], env=env)
84+
success = b2.validate_uncles()
85+
except (ValueError, TypeError, AttributeError, VerificationFailed,
86+
DecodingError, DeserializationError, InvalidTransaction, KeyError):
87+
success = False
88+
assert not success
89+
else:
7890
rlpdata = decode_hex(blk["rlp"][2:])
79-
blkparent = rlp.decode(
80-
rlp.encode(rlp.decode(rlpdata)[0]), blocks.BlockHeader).prevhash
91+
blkparent = rlp.decode(rlp.encode(rlp.decode(rlpdata)[0]), blocks.BlockHeader).prevhash
8192
b2 = rlp.decode(rlpdata, blocks.Block, parent=blockmap[blkparent], env=env)
82-
success = b2.validate_uncles()
83-
except (ValueError, TypeError, AttributeError, VerificationFailed,
84-
DecodingError, DeserializationError, InvalidTransaction, KeyError):
85-
success = False
86-
assert not success
87-
else:
88-
rlpdata = decode_hex(blk["rlp"][2:])
89-
blkparent = rlp.decode(rlp.encode(rlp.decode(rlpdata)[0]), blocks.BlockHeader).prevhash
90-
b2 = rlp.decode(rlpdata, blocks.Block, parent=blockmap[blkparent], env=env)
91-
assert b2.validate_uncles()
92-
blockmap[b2.hash] = b2
93-
env.db.put(b2.hash, rlp.encode(b2))
94-
if b2:
95-
print('Block %d with state root %s' % (b2.number, encode_hex(b2.state.root_hash)))
96-
# blkdict = b.to_dict(False, True, False, True)
97-
# assert blk["blockHeader"] == \
98-
# translate_keys(blkdict["header"], translator_list, lambda y, x: x, [])
99-
# assert blk["transactions"] == \
100-
# [translate_keys(t, translator_list, valueconv, ['hash'])
101-
# for t in blkdict["transactions"]]
102-
# assert blk["uncleHeader"] == \
103-
# [translate_keys(u, translator_list, lambda x: x, [])
104-
# for u in blkdict["uncles"]]
105-
env.config = old_config
93+
assert b2.validate_uncles()
94+
blockmap[b2.hash] = b2
95+
env.db.put(b2.hash, rlp.encode(b2))
96+
if b2:
97+
print('Block %d with state root %s' % (b2.number, encode_hex(b2.state.root_hash)))
98+
# blkdict = b.to_dict(False, True, False, True)
99+
# assert blk["blockHeader"] == \
100+
# translate_keys(blkdict["header"], translator_list, lambda y, x: x, [])
101+
# assert blk["transactions"] == \
102+
# [translate_keys(t, translator_list, valueconv, ['hash'])
103+
# for t in blkdict["transactions"]]
104+
# assert blk["uncleHeader"] == \
105+
# [translate_keys(u, translator_list, lambda x: x, [])
106+
# for u in blkdict["uncles"]]
107+
finally:
108+
env.config = old_config
106109

107110

108111
def test_block(filename, testname, testdata):
109-
run_block_test(testdata, {
110-
'HOMESTEAD_FORK_BLKNUM': 0 if 'Homestead' in filename else 5 if 'TestNetwork' in filename else 1000000,
111-
'DAO_FORK_BLKNUM': 8 if 'bcTheDaoTest' in filename else 1920000
112-
})
112+
config_overrides = get_config_overrides(filename)
113+
run_block_test(testdata, config_overrides=config_overrides)
113114

114115

115116
excludes = {
@@ -135,18 +136,15 @@ def main():
135136
for testname, testdata in list(tests.items()):
136137
if testname == sys.argv[2]:
137138
print("Testing: %s %s" % (filename, testname))
138-
run_block_test(testdata, {
139-
'HOMESTEAD_FORK_BLKNUM': 0 if 'Homestead' in filename else 5 if 'TestNetwork' in filename
140-
else 1000000,
141-
'DAO_FORK_BLKNUM': 8 if 'bcTheDaoTest' in filename else 1920000})
139+
config_overrides = get_config_overrides(filename)
140+
run_block_test(testdata, config_overrides=config_overrides)
142141
else:
143142
for filename, tests in list(fixtures.items()):
144143
for testname, testdata in list(tests.items()):
145144
if (filename.split('/')[-1], testname) not in excludes:
146145
print("Testing: %s %s" % (filename, testname))
147-
run_block_test(testdata, {
148-
'HOMESTEAD_FORK_BLKNUM': 0 if 'Homestead' in filename else 5 if 'TestNetwork' in filename else 1000000,
149-
'DAO_FORK_BLKNUM': 8 if 'bcTheDaoTest' in filename else 1920000})
146+
config_overrides = get_config_overrides(filename)
147+
run_block_test(testdata, config_overrides=config_overrides)
150148

151149

152150
if __name__ == '__main__':

ethereum/tests/test_opcodes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from ethereum import opcodes
2+
3+
opcode_gas = {
4+
opcode: gas for (opcode, ins, outs, gas) in opcodes.opcodes.values()
5+
}
6+
7+
8+
def test_eip150_opcode_gascost():
9+
"""Ensure gas prices specified in
10+
https://github.com/ethereum/eips/issues/150
11+
"""
12+
assert opcode_gas['EXTCODESIZE'] + opcodes.EXTCODELOAD_SUPPLEMENTAL_GAS == 700
13+
assert opcode_gas['EXTCODECOPY'] + opcodes.EXTCODELOAD_SUPPLEMENTAL_GAS == 700
14+
assert opcode_gas['BALANCE'] + opcodes.BALANCE_SUPPLEMENTAL_GAS == 400
15+
assert opcode_gas['SLOAD'] + opcodes.SLOAD_SUPPLEMENTAL_GAS == 200
16+
17+
assert opcode_gas['CALL'] + opcodes.CALL_SUPPLEMENTAL_GAS == 700
18+
assert opcode_gas['DELEGATECALL'] + opcodes.CALL_SUPPLEMENTAL_GAS == 700
19+
assert opcode_gas['CALLCODE'] + opcodes.CALL_SUPPLEMENTAL_GAS == 700
20+
21+
assert opcode_gas['SUICIDE'] + opcodes.SUICIDE_SUPPLEMENTAL_GAS == 5000

ethereum/testutils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ def blkhash(n):
396396
'out', 'gas', 'logs', 'postStateRoot']:
397397
_shouldbe = params1.get(k, None)
398398
_reallyis = params2.get(k, None)
399+
if str_to_bytes(k) == b'out' and _shouldbe[:1] in ('#', b'#'):
400+
_reallyis = str_to_bytes('#%s' % ((len(_reallyis) - 2) // 2))
399401
if _shouldbe != _reallyis:
400402
print(('Mismatch {key}: shouldbe {shouldbe_key} != reallyis {reallyis_key}.\n'
401403
'post: {shouldbe_post} != {reallyis_post}').format(
@@ -575,6 +577,23 @@ def fixture_to_bytes(value):
575577
return value
576578

577579

580+
def get_config_overrides(filename):
581+
override = {}
582+
if os.path.join('BlockchainTests', 'Homestead') in filename:
583+
override['HOMESTEAD_FORK_BLKNUM'] = 0
584+
elif os.path.join('BlockchainTests', 'TestNetwork') in filename:
585+
override['HOMESTEAD_FORK_BLKNUM'] = 5
586+
override['DAO_FORK_BLKNUM'] = 8
587+
override['ANTI_DOS_FORK_BLKNUM'] = 10
588+
elif os.path.join('BlockchainTests', 'EIP150') in filename:
589+
override['HOMESTEAD_FORK_BLKNUM'] = 0
590+
override['ANTI_DOS_FORK_BLKNUM'] = 0
591+
override['DAO_FORK_BLKNUM'] = 2 ** 99 # not applicable
592+
if 'bcTheDaoTest' in filename:
593+
override['DAO_FORK_BLKNUM'] = 8
594+
return override
595+
596+
578597
def generate_test_params(testsource, metafunc, skip_func=None, exclude_func=None):
579598
if ['filename', 'testname', 'testdata'] != metafunc.fixturenames:
580599
return

0 commit comments

Comments
 (0)