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

EIP86 #377

Merged
merged 5 commits into from
Jul 6, 2016
Merged

EIP86 #377

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethereum/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
HOMESTEAD_FORK_BLKNUM=1150000,
HOMESTEAD_DIFF_ADJUSTMENT_CUTOFF=10,
# Metropolis fork
METROPOLIS_FORK_BLKNUM=9999999,
METROPOLIS_FORK_BLKNUM=99999999,
METROPOLIS_ENTRY_POINT=2 ** 160 - 1,
METROPOLIS_STATEROOT_STORE=0x10,
METROPOLIS_BLOCKHASH_STORE=0x20,
Expand Down
34 changes: 25 additions & 9 deletions ethereum/processblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from ethereum import bloom
from ethereum import vm as vm
from ethereum.exceptions import InvalidNonce, InsufficientStartGas, UnsignedTransaction, \
BlockGasLimitReached, InsufficientBalance
from ethereum.utils import safe_ord, mk_contract_address
BlockGasLimitReached, InsufficientBalance, VerificationFailed
from ethereum.utils import safe_ord, normalize_address, mk_contract_address, \
mk_metropolis_contract_address, big_endian_to_int
from ethereum import transactions
import ethereum.config as config

Expand Down Expand Up @@ -37,7 +38,7 @@ def verify(block, parent):
env=parent.env, parent=parent)
assert block == block2
return True
except blocks.VerificationFailed:
except VerificationFailed:
return False


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

# (1) The transaction signature is valid;
if not tx.sender: # sender is set and validated on Transaction initialization
raise UnsignedTransaction(tx)
if block.number >= config.default_config["METROPOLIS_FORK_BLKNUM"]:
tx._sender = normalize_address(config.default_config["METROPOLIS_ENTRY_POINT"])
else:
raise UnsignedTransaction(tx)
if block.number >= config.default_config["HOMESTEAD_FORK_BLKNUM"]:
tx.check_low_s()

Expand Down Expand Up @@ -222,6 +226,8 @@ def __init__(self, block, tx):
self.get_code = block.get_code
self.get_balance = block.get_balance
self.set_balance = block.set_balance
self.get_nonce = block.get_nonce
self.set_nonce = block.set_nonce
self.set_storage_data = block.set_storage_data
self.get_storage_data = block.get_storage_data
self.log_storage = lambda x: block.account_to_dict(x)['storage']
Expand Down Expand Up @@ -299,10 +305,21 @@ def create_contract(ext, msg):
log_msg.debug('CONTRACT CREATION')
#print('CREATING WITH GAS', msg.gas)
sender = decode_hex(msg.sender) if len(msg.sender) == 40 else msg.sender
if ext.tx_origin != msg.sender:
ext._block.increment_nonce(msg.sender)
nonce = utils.encode_int(ext._block.get_nonce(msg.sender) - 1)
msg.to = mk_contract_address(sender, nonce)
code = msg.data.extract_all()
if ext._block.number >= ext._block.config['METROPOLIS_FORK_BLKNUM']:
msg.to = mk_metropolis_contract_address(msg.sender, code)
if ext.get_code(msg.to):
if ext.get_nonce(msg.to) >= 2 ** 40:
ext.set_nonce(msg.to, (ext.get_nonce(msg.to) + 1) % 2 ** 160)
msg.to = normalize_address((ext.get_nonce(msg.to) - 1) % 2 ** 160)
else:
ext.set_nonce(msg.to, (big_endian_to_int(msg.to) + 2) % 2 ** 160)
msg.to = normalize_address((ext.get_nonce(msg.to) - 1) % 2 ** 160)
else:
if ext.tx_origin != msg.sender:
ext._block.increment_nonce(msg.sender)
nonce = utils.encode_int(ext._block.get_nonce(msg.sender) - 1)
msg.to = mk_contract_address(sender, nonce)
b = ext.get_balance(msg.to)
if b > 0:
ext.set_balance(msg.to, b)
Expand All @@ -311,7 +328,6 @@ def create_contract(ext, msg):
ext._block.reset_storage(msg.to)
msg.is_create = True
# assert not ext.get_code(msg.to)
code = msg.data.extract_all()
msg.data = vm.CallData([], 0, 0)
snapshot = ext._block.snapshot()
res, gas, dat = _apply_msg(ext, msg, code)
Expand Down
2 changes: 2 additions & 0 deletions ethereum/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def bytearray_to_bytestr(value):
def mk_contract_address(sender, nonce):
return sha3(rlp.encode([normalize_address(sender), nonce]))[12:]

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

def safe_ord(value):
if isinstance(value, int):
Expand Down