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

Commit e4fbff0

Browse files
vubvub
authored andcommitted
More fork changes/hotfixes
1 parent 6d7e28a commit e4fbff0

File tree

5 files changed

+44
-33
lines changed

5 files changed

+44
-33
lines changed

ethereum/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
CHILD_DAO_LIST = map(utils.normalize_address, child_dao_list),
6363
DAO_WITHDRAWER = utils.normalize_address('0xbf4ed7b27f1d666546e30d74d50d173d20bca754'),
6464
# Anti-DoS fork
65-
ANTI_DOS_FORK_BLKNUM = 2**99,
65+
ANTI_DOS_FORK_BLKNUM = 9999999,
6666
# Default consensus strategy: ethash, poa, casper, pbft
6767
CONSENSUS_STRATEGY = 'ethash',
6868
# Serenity fork

ethereum/tests/test_blocks.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
from ethereum.slogging import get_logger
1616
logger = get_logger()
1717

18+
# from ethereum.slogging import LogRecorder, configure_logging, set_level
19+
# config_string = ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,eth.vm.exit:trace,eth.pb.msg:trace,eth.pb.tx:debug'
20+
# configure_logging(config_string=config_string)
21+
1822

1923
def translate_keys(olddict, keymap, valueconv, deletes):
2024
o = {}
@@ -86,12 +90,23 @@ def run_block_test(params, config_overrides = {}):
8690
assert c.add_block(rlp.decode(rlpdata, Block))
8791
env.config = old_config
8892

93+
def get_config_overrides(filename):
94+
o = {}
95+
if 'Homestead' in filename:
96+
o['HOMESTEAD_FORK_BLKNUM'] = 0
97+
if 'TestNetwork' in filename:
98+
o['HOMESTEAD_FORK_BLKNUM'] = 5
99+
if 'bcTheDaoTest' in filename:
100+
o['DAO_FORK_BLKNUM'] = 8
101+
if 'EIP150' in filename:
102+
o['HOMESTEAD_FORK_BLKNUM'] = 5
103+
o['DAO_FORK_BLKNUM'] = 8
104+
o['ANTI_DOS_FORK_BLKNUM'] = 10
105+
return o
106+
89107

90108
def test_block(filename, testname, testdata):
91-
run_block_test(testdata, {
92-
'HOMESTEAD_FORK_BLKNUM': 0 if 'Homestead' in filename else 5 if 'TestNetwork' in filename else 1000000,
93-
'DAO_FORK_BLKNUM': 8 if 'bcTheDaoTest' in filename else 1920000
94-
})
109+
run_block_test(testdata, get_config_overrides(filename))
95110

96111

97112
excludes = {
@@ -117,19 +132,13 @@ def main():
117132
for testname, testdata in list(tests.items()):
118133
if testname == sys.argv[2]:
119134
print("Testing: %s %s" % (filename, testname))
120-
run_block_test(testdata, {
121-
'HOMESTEAD_FORK_BLKNUM': 0 if 'Homestead' in filename else 5 if 'TestNetwork' in filename else 1000000,
122-
'DAO_FORK_BLKNUM': 8 if 'bcTheDaoTest' in filename else 1920000
123-
})
135+
run_block_test(testdata, get_config_overrides(filename))
124136
else:
125137
for filename, tests in list(fixtures.items()):
126138
for testname, testdata in list(tests.items()):
127139
if (filename.split('/')[-1], testname) not in excludes:
128140
print("Testing: %s %s" % (filename, testname))
129-
run_block_test(testdata, {
130-
'HOMESTEAD_FORK_BLKNUM': 0 if 'Homestead' in filename else 5 if 'TestNetwork' in filename else 1000000,
131-
'DAO_FORK_BLKNUM': 8 if 'bcTheDaoTest' in filename else 1920000
132-
})
141+
run_block_test(testdata, get_config_overrides(filename))
133142

134143

135144
if __name__ == '__main__':

ethereum/testutils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
"previousHash": b"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
3535
}
3636

37-
# from ethereum.slogging import LogRecorder, configure_logging, set_level
38-
# config_string = ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,eth.vm.exit:trace,eth.pb.msg:trace,eth.pb.tx:debug'
39-
# configure_logging(config_string=config_string)
37+
from ethereum.slogging import LogRecorder, configure_logging, set_level
38+
config_string = ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,eth.vm.exit:trace,eth.pb.msg:trace,eth.pb.tx:debug'
39+
configure_logging(config_string=config_string)
4040

4141
FILL = 1
4242
VERIFY = 2
@@ -359,7 +359,7 @@ def run_state_test(params, mode):
359359
logs = state.receipts[-1].logs
360360
assert success
361361
state.commit()
362-
print('success')
362+
print('tx applied')
363363
except InvalidTransaction:
364364
success, output = False, b''
365365
state.commit()

ethereum/vm.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ def eat_gas(compustate, amount):
140140
return vm_exception("OUT OF GAS")
141141
else:
142142
compustate.gas -= amount
143+
return True
144+
145+
146+
def all_but_1n(x, n):
147+
return x - x / n
143148

144149

145150
def vm_exception(error, **kargs):
@@ -550,15 +555,15 @@ def vm_execute(ext, msg, code):
550555
cd = CallData(mem, mstart, msz)
551556
ingas = compustate.gas
552557
if ext.post_anti_dos_hardfork():
553-
ingas = ingas * opcodes.CALL_CHILD_LIMIT_NUM / CALL_CHILD_LIMIT_DENOM
558+
ingas = all_but_1n(ingas, opcodes.CALL_CHILD_LIMIT_DENOM)
554559
create_msg = Message(msg.to, b'', value, ingas, cd, msg.depth + 1)
555560
o, gas, addr = ext.create(create_msg)
556561
if o:
557562
stk.append(utils.coerce_to_int(addr))
558-
compustate.gas = gas
563+
compustate.gas = compustate.gas - ingas + gas
559564
else:
560565
stk.append(0)
561-
compustate.gas = 0
566+
compustate.gas -= ingas
562567
else:
563568
stk.append(0)
564569
elif op == 'CALL':
@@ -576,8 +581,7 @@ def vm_execute(ext, msg, code):
576581
if ext.post_anti_dos_hardfork():
577582
if compustate.gas < extra_gas:
578583
return vm_exception('OUT OF GAS', needed=extra_gas)
579-
elif gas > (compustate.gas - extra_gas) * opcodes.CALL_CHILD_LIMIT_NUM / opcodes.CALL_CHILD_LIMIT_DENOM:
580-
gas = (compustate.gas - extra_gas) * opcodes.CALL_CHILD_LIMIT_NUM / opcodes.CALL_CHILD_LIMIT_DENOM
584+
gas = min(gas, all_but_1n(compustate.gas - extra_gas, opcodes.CALL_CHILD_LIMIT_DENOM))
581585
else:
582586
if compustate.gas < gas + extra_gas:
583587
return vm_exception('OUT OF GAS', needed=gas+extra_gas)
@@ -612,15 +616,14 @@ def vm_execute(ext, msg, code):
612616
return vm_exception('OOG EXTENDING MEMORY')
613617
extra_gas = (value > 0) * opcodes.GCALLVALUETRANSFER + \
614618
ext.post_anti_dos_hardfork() * opcodes.CALL_SUPPLEMENTAL_GAS
615-
submsg_gas = gas + opcodes.GSTIPEND * (value > 0)
616619
if ext.post_anti_dos_hardfork():
617620
if compustate.gas < extra_gas:
618621
return vm_exception('OUT OF GAS', needed=extra_gas)
619-
elif gas > (compustate.gas - extra_gas) * opcodes.CALL_CHILD_LIMIT_NUM / opcodes.CALL_CHILD_LIMIT_DENOM:
620-
gas = (compustate.gas - extra_gas) * opcodes.CALL_CHILD_LIMIT_NUM / opcodes.CALL_CHILD_LIMIT_DENOM
622+
gas = min(gas, all_but_1n(compustate.gas - extra_gas, opcodes.CALL_CHILD_LIMIT_DENOM))
621623
else:
622624
if compustate.gas < gas + extra_gas:
623625
return vm_exception('OUT OF GAS', needed=gas+extra_gas)
626+
submsg_gas = gas + opcodes.GSTIPEND * (value > 0)
624627
if ext.get_balance(msg.to) >= value and msg.depth < 1024:
625628
compustate.gas -= (gas + extra_gas)
626629
assert compustate.gas >= 0
@@ -655,8 +658,7 @@ def vm_execute(ext, msg, code):
655658
not mem_extend(mem, compustate, op, codestart, codesz):
656659
return vm_exception('OOG EXTENDING MEMORY')
657660
if ext.post_anti_dos_hardfork():
658-
if gas > compustate.gas * opcodes.CALL_CHILD_LIMIT_NUM / opcodes.CALL_CHILD_LIMIT_DENOM:
659-
gas = compustate.gas * opcodes.CALL_CHILD_LIMIT_NUM / opcodes.CALL_CHILD_LIMIT_DENOM
661+
gas = min(gas, all_but_1n(compustate.gas, opcodes.CALL_CHILD_LIMIT_DENOM))
660662
else:
661663
if gas > compustate.gas:
662664
return vm_exception("OUT OF GAS", needed=gas)
@@ -680,13 +682,13 @@ def vm_execute(ext, msg, code):
680682
return vm_exception('OOG EXTENDING MEMORY')
681683
return peaceful_exit('RETURN', compustate.gas, mem[s0: s0 + s1])
682684
elif op == 'SUICIDE':
683-
if ext.post_anti_dos_hardfork():
684-
if gas < opcodes.SUICIDE_SUPPLEMENTAL_GAS:
685-
return vm_exception("OUT OF GAS")
686-
else:
687-
gas -= opcodes.SUICIDE_SUPPLEMENTAL_GAS
688685
to = utils.encode_int(stk.pop())
689686
to = ((b'\x00' * (32 - len(to))) + to)[12:]
687+
if ext.post_anti_dos_hardfork():
688+
extra_gas = opcodes.SUICIDE_SUPPLEMENTAL_GAS + \
689+
(not ext.account_exists(to)) * opcodes.GCALLNEWACCOUNT
690+
if not eat_gas(compustate, extra_gas):
691+
return vm_exception("OUT OF GAS")
690692
xfer = ext.get_balance(msg.to)
691693
ext.set_balance(to, ext.get_balance(to) + xfer)
692694
ext.set_balance(msg.to, 0)

0 commit comments

Comments
 (0)