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

Commit ce7548d

Browse files
authored
Merge pull request #377 from ethereum/EIP86
EIP86
2 parents cd24f18 + 1ecc8b6 commit ce7548d

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

ethereum/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
HOMESTEAD_FORK_BLKNUM=1150000,
4949
HOMESTEAD_DIFF_ADJUSTMENT_CUTOFF=10,
5050
# Metropolis fork
51-
METROPOLIS_FORK_BLKNUM=9999999,
51+
METROPOLIS_FORK_BLKNUM=99999999,
5252
METROPOLIS_ENTRY_POINT=2 ** 160 - 1,
5353
METROPOLIS_STATEROOT_STORE=0x10,
5454
METROPOLIS_BLOCKHASH_STORE=0x20,

ethereum/processblock.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
from ethereum import bloom
99
from ethereum import vm as vm
1010
from ethereum.exceptions import InvalidNonce, InsufficientStartGas, UnsignedTransaction, \
11-
BlockGasLimitReached, InsufficientBalance
12-
from ethereum.utils import safe_ord, mk_contract_address
11+
BlockGasLimitReached, InsufficientBalance, VerificationFailed
12+
from ethereum.utils import safe_ord, normalize_address, mk_contract_address, \
13+
mk_metropolis_contract_address, big_endian_to_int
1314
from ethereum import transactions
1415
import ethereum.config as config
1516

@@ -37,7 +38,7 @@ def verify(block, parent):
3738
env=parent.env, parent=parent)
3839
assert block == block2
3940
return True
40-
except blocks.VerificationFailed:
41+
except VerificationFailed:
4142
return False
4243

4344

@@ -81,7 +82,10 @@ def rp(what, actual, target):
8182

8283
# (1) The transaction signature is valid;
8384
if not tx.sender: # sender is set and validated on Transaction initialization
84-
raise UnsignedTransaction(tx)
85+
if block.number >= config.default_config["METROPOLIS_FORK_BLKNUM"]:
86+
tx._sender = normalize_address(config.default_config["METROPOLIS_ENTRY_POINT"])
87+
else:
88+
raise UnsignedTransaction(tx)
8589
if block.number >= config.default_config["HOMESTEAD_FORK_BLKNUM"]:
8690
tx.check_low_s()
8791

@@ -222,6 +226,8 @@ def __init__(self, block, tx):
222226
self.get_code = block.get_code
223227
self.get_balance = block.get_balance
224228
self.set_balance = block.set_balance
229+
self.get_nonce = block.get_nonce
230+
self.set_nonce = block.set_nonce
225231
self.set_storage_data = block.set_storage_data
226232
self.get_storage_data = block.get_storage_data
227233
self.log_storage = lambda x: block.account_to_dict(x)['storage']
@@ -299,10 +305,21 @@ def create_contract(ext, msg):
299305
log_msg.debug('CONTRACT CREATION')
300306
#print('CREATING WITH GAS', msg.gas)
301307
sender = decode_hex(msg.sender) if len(msg.sender) == 40 else msg.sender
302-
if ext.tx_origin != msg.sender:
303-
ext._block.increment_nonce(msg.sender)
304-
nonce = utils.encode_int(ext._block.get_nonce(msg.sender) - 1)
305-
msg.to = mk_contract_address(sender, nonce)
308+
code = msg.data.extract_all()
309+
if ext._block.number >= ext._block.config['METROPOLIS_FORK_BLKNUM']:
310+
msg.to = mk_metropolis_contract_address(msg.sender, code)
311+
if ext.get_code(msg.to):
312+
if ext.get_nonce(msg.to) >= 2 ** 40:
313+
ext.set_nonce(msg.to, (ext.get_nonce(msg.to) + 1) % 2 ** 160)
314+
msg.to = normalize_address((ext.get_nonce(msg.to) - 1) % 2 ** 160)
315+
else:
316+
ext.set_nonce(msg.to, (big_endian_to_int(msg.to) + 2) % 2 ** 160)
317+
msg.to = normalize_address((ext.get_nonce(msg.to) - 1) % 2 ** 160)
318+
else:
319+
if ext.tx_origin != msg.sender:
320+
ext._block.increment_nonce(msg.sender)
321+
nonce = utils.encode_int(ext._block.get_nonce(msg.sender) - 1)
322+
msg.to = mk_contract_address(sender, nonce)
306323
b = ext.get_balance(msg.to)
307324
if b > 0:
308325
ext.set_balance(msg.to, b)
@@ -311,7 +328,6 @@ def create_contract(ext, msg):
311328
ext._block.reset_storage(msg.to)
312329
msg.is_create = True
313330
# assert not ext.get_code(msg.to)
314-
code = msg.data.extract_all()
315331
msg.data = vm.CallData([], 0, 0)
316332
snapshot = ext._block.snapshot()
317333
res, gas, dat = _apply_msg(ext, msg, code)

ethereum/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def bytearray_to_bytestr(value):
6868
def mk_contract_address(sender, nonce):
6969
return sha3(rlp.encode([normalize_address(sender), nonce]))[12:]
7070

71+
def mk_metropolis_contract_address(sender, initcode):
72+
return sha3(normalize_address(sender) + initcode)[12:]
7173

7274
def safe_ord(value):
7375
if isinstance(value, int):

0 commit comments

Comments
 (0)