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

Commit 3f87f0e

Browse files
vubvub
authored andcommitted
HF round 2
1 parent 9fd142b commit 3f87f0e

File tree

6 files changed

+40
-19
lines changed

6 files changed

+40
-19
lines changed

ethereum/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
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 = 2457000,
65+
ANTI_DOS_FORK_BLKNUM = 2463000,
66+
CLEARING_FORK_BLKNUM = 2**98,
6667
# Default consensus strategy: ethash, poa, casper, pbft
6768
CONSENSUS_STRATEGY = 'ethash',
6869
# Serenity fork

ethereum/opcodes.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
0x07: ['SMOD', 2, 1, 5],
1212
0x08: ['ADDMOD', 3, 1, 8],
1313
0x09: ['MULMOD', 3, 1, 8],
14-
0x0a: ['EXP', 2, 1, 10],
14+
0x0a: ['EXP', 2, 1, 10], # soon 80
1515
0x0b: ['SIGNEXTEND', 2, 1, 5],
1616
0x10: ['LT', 2, 1, 3],
1717
0x11: ['GT', 2, 1, 3],
@@ -26,7 +26,7 @@
2626
0x1a: ['BYTE', 2, 1, 3],
2727
0x20: ['SHA3', 2, 1, 30],
2828
0x30: ['ADDRESS', 0, 1, 2],
29-
0x31: ['BALANCE', 1, 1, 20],
29+
0x31: ['BALANCE', 1, 1, 20], # now 400
3030
0x32: ['ORIGIN', 0, 1, 2],
3131
0x33: ['CALLER', 0, 1, 2],
3232
0x34: ['CALLVALUE', 0, 1, 2],
@@ -36,8 +36,8 @@
3636
0x38: ['CODESIZE', 0, 1, 2],
3737
0x39: ['CODECOPY', 3, 0, 3],
3838
0x3a: ['GASPRICE', 0, 1, 2],
39-
0x3b: ['EXTCODESIZE', 1, 1, 20],
40-
0x3c: ['EXTCODECOPY', 4, 0, 20],
39+
0x3b: ['EXTCODESIZE', 1, 1, 20], # now 700
40+
0x3c: ['EXTCODECOPY', 4, 0, 20], # now 700
4141
0x40: ['BLOCKHASH', 1, 1, 20],
4242
0x41: ['COINBASE', 0, 1, 2],
4343
0x42: ['TIMESTAMP', 0, 1, 2],
@@ -48,8 +48,8 @@
4848
0x51: ['MLOAD', 1, 1, 3],
4949
0x52: ['MSTORE', 2, 0, 3],
5050
0x53: ['MSTORE8', 2, 0, 3],
51-
0x54: ['SLOAD', 1, 1, 50],
52-
0x55: ['SSTORE', 2, 0, 0],
51+
0x54: ['SLOAD', 1, 1, 50], # 200 now
52+
0x55: ['SSTORE', 2, 0, 0], # actual cost 5000-20000 depending on circumstance
5353
0x56: ['JUMP', 1, 0, 8],
5454
0x57: ['JUMPI', 2, 0, 10],
5555
0x58: ['PC', 0, 1, 2],
@@ -61,16 +61,16 @@
6161
0xa2: ['LOG2', 4, 0, 1125],
6262
0xa3: ['LOG3', 5, 0, 1500],
6363
0xa4: ['LOG4', 6, 0, 1875],
64-
0xe1: ['SLOADBYTES', 3, 0, 50],
65-
0xe2: ['SSTOREBYTES', 3, 0, 0],
66-
0xe3: ['SSIZE', 1, 1, 50],
64+
0xe1: ['SLOADBYTES', 3, 0, 50], # to be discontinued
65+
0xe2: ['SSTOREBYTES', 3, 0, 0], # to be discontinued
66+
0xe3: ['SSIZE', 1, 1, 50], # to be discontinued
6767
0xf0: ['CREATE', 3, 1, 32000],
68-
0xf1: ['CALL', 7, 1, 40],
69-
0xf2: ['CALLCODE', 7, 1, 40],
68+
0xf1: ['CALL', 7, 1, 40], # 700 now
69+
0xf2: ['CALLCODE', 7, 1, 40], # 700 now
7070
0xf3: ['RETURN', 2, 0, 0],
71-
0xf4: ['DELEGATECALL', 6, 1, 40],
71+
0xf4: ['DELEGATECALL', 6, 1, 40], # 700 now
7272
0xf5: ['CALLBLACKBOX', 7, 1, 40],
73-
0xff: ['SUICIDE', 1, 0, 0],
73+
0xff: ['SUICIDE', 1, 0, 0], # 5000 now
7474
}
7575

7676
for i in range(1, 33):
@@ -132,3 +132,4 @@
132132
CALL_CHILD_LIMIT_NUM = 63
133133
CALL_CHILD_LIMIT_DENOM = 64
134134
SUICIDE_SUPPLEMENTAL_GAS = 5000
135+
EXP_SUPPLEMENTAL_GAS = 70

ethereum/state.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
ACCOUNT_SPECIAL_PARAMS = ('nonce', 'balance', 'code', 'storage', 'deleted')
2323
ACCOUNT_OUTPUTTABLE_PARAMS = ('nonce', 'balance', 'code')
24+
BLANK_HASH = utils.sha3(b'')
2425

2526
@lru_cache(1024)
2627
def get_block(db, blockhash):
@@ -197,6 +198,8 @@ def set_storage_data (self, addr, k, v):
197198
self.set_storage(addr, k, encode_int(v) if isinstance(v, (int, long)) and k not in ACCOUNT_SPECIAL_PARAMS else v)
198199

199200
def account_exists(self, addr):
201+
if self.is_CLEARING():
202+
return self.get_nonce(addr) or self.get_balance(addr) or self.get_code(addr)
200203
if addr not in self.modified:
201204
o = self.trie.get(addr) != trie.BLANK_NODE
202205
elif self.cache[addr].get('deleted', False):
@@ -248,7 +251,10 @@ def commit(self):
248251
if addr in self.modified or True:
249252
if not acct.deleted:
250253
acct._cached_rlp = None
251-
self.trie.update(addr, rlp.encode(acct))
254+
if self.is_CLEARING() and acct.is_blank():
255+
self.trie.delete(addr)
256+
else:
257+
self.trie.update(addr, rlp.encode(acct))
252258
else:
253259
self.trie.delete(addr)
254260
self.cache = {}
@@ -272,6 +278,9 @@ def del_account(self, address):
272278
for param in ACCOUNT_OUTPUTTABLE_PARAMS:
273279
self.set_storage(address, param, getattr(blank_acct, param))
274280
self.reset_storage(address)
281+
self.set_balance(address, 0)
282+
self.set_nonce(address, 0)
283+
self.set_code(address, '')
275284
self.set_storage(address, 'deleted', True)
276285

277286
def add_log(self, log):
@@ -445,6 +454,9 @@ def is_SERENITY(self, at_fork_height=False):
445454
def is_ANTI_DOS(self, at_fork_height=False):
446455
return self._is_X_fork('ANTI_DOS', at_fork_height)
447456

457+
def is_CLEARING(self, at_fork_height=False):
458+
return self._is_X_fork('CLEARING', at_fork_height)
459+
448460
def is_DAO(self, at_fork_height=False):
449461
return self._is_X_fork('DAO', at_fork_height)
450462

@@ -529,3 +541,6 @@ def blank_account(cls, db, initial_nonce=0):
529541
o = cls(initial_nonce, 0, trie.BLANK_ROOT, code_hash, db)
530542
o._mutable = True
531543
return o
544+
545+
def is_blank(self):
546+
return self.nonce == 0 and self.balance == 0 and self.storage == trie.BLANK_ROOT and self.code_hash == BLANK_HASH

ethereum/state_transition.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ def __init__(self, state, tx):
430430
self.post_metropolis_hardfork = lambda: state.is_METROPOLIS()
431431
self.post_serenity_hardfork = lambda: state.is_SERENITY()
432432
self.post_anti_dos_hardfork = lambda: state.is_ANTI_DOS()
433+
self.post_clearing_hardfork = lambda: state.is_CLEARING()
433434
self.blockhash_store = state.config['METROPOLIS_BLOCKHASH_STORE']
434435
self.snapshot = state.snapshot
435436
self.revert = state.revert
@@ -476,6 +477,7 @@ def __init__(self, state):
476477
self.post_metropolis_hardfork = lambda: state.is_METROPOLIS()
477478
self.post_serenity_hardfork = lambda: state.is_SERENITY()
478479
self.post_anti_dos_hardfork = lambda: state.is_ANTI_DOS()
480+
self.post_clearing_hardfork = lambda: state.is_CLEARING()
479481
self.blockhash_store = state.config['METROPOLIS_BLOCKHASH_STORE']
480482
self.snapshot = state.snapshot
481483
self.revert = state.revert

ethereum/vm.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ def vm_execute(ext, msg, code):
289289
# calc n bytes to represent exponent
290290
nbytes = len(utils.encode_int(exponent))
291291
expfee = nbytes * opcodes.GEXPONENTBYTE
292+
if ext.post_clearing_hardfork():
293+
expfee += opcodes.EXP_SUPPLEMENTAL_GAS * (1 + nbytes)
292294
if compustate.gas < expfee:
293295
compustate.gas = 0
294296
return vm_exception('OOG EXPONENT')
@@ -577,7 +579,7 @@ def vm_execute(ext, msg, code):
577579
return vm_exception('OOG EXTENDING MEMORY')
578580
to = utils.encode_int(to)
579581
to = ((b'\x00' * (32 - len(to))) + to)[12:]
580-
extra_gas = (not ext.account_exists(to)) * opcodes.GCALLNEWACCOUNT + \
582+
extra_gas = (not ext.account_exists(to)) * (value > 0 or not ext.post_clearing_hardfork()) * opcodes.GCALLNEWACCOUNT + \
581583
(value > 0) * opcodes.GCALLVALUETRANSFER + \
582584
ext.post_anti_dos_hardfork() * opcodes.CALL_SUPPLEMENTAL_GAS
583585
submsg_gas = gas + opcodes.GSTIPEND * (value > 0)
@@ -687,12 +689,12 @@ def vm_execute(ext, msg, code):
687689
elif op == 'SUICIDE':
688690
to = utils.encode_int(stk.pop())
689691
to = ((b'\x00' * (32 - len(to))) + to)[12:]
692+
xfer = ext.get_balance(msg.to)
690693
if ext.post_anti_dos_hardfork():
691694
extra_gas = opcodes.SUICIDE_SUPPLEMENTAL_GAS + \
692-
(not ext.account_exists(to)) * opcodes.GCALLNEWACCOUNT
695+
(not ext.account_exists(to)) * (xfer > 0 or not ext.post_clearing_hardfork()) * opcodes.GCALLNEWACCOUNT
693696
if not eat_gas(compustate, extra_gas):
694697
return vm_exception("OUT OF GAS")
695-
xfer = ext.get_balance(msg.to)
696698
ext.set_balance(to, ext.get_balance(to) + xfer)
697699
ext.set_balance(msg.to, 0)
698700
ext.add_suicide(msg.to)

fixtures

Submodule fixtures updated 30 files

0 commit comments

Comments
 (0)