7
7
from ethereum import specials
8
8
from ethereum import bloom
9
9
from ethereum import vm as vm
10
- from ethereum .exceptions import InvalidNonce , InsufficientStartGas , UnsignedTransaction , \
11
- BlockGasLimitReached , InsufficientBalance
12
- from ethereum . utils import safe_ord , mk_contract_address
10
+ from ethereum .exceptions import *
11
+ from ethereum . utils import safe_ord , normalize_address , mk_contract_address , \
12
+ mk_metropolis_contract_address , int_to_addr , big_endian_to_int
13
13
from ethereum import transactions
14
14
import ethereum .config as config
15
15
@@ -81,7 +81,10 @@ def rp(what, actual, target):
81
81
82
82
# (1) The transaction signature is valid;
83
83
if not tx .sender : # sender is set and validated on Transaction initialization
84
- raise UnsignedTransaction (tx )
84
+ if block .number >= config .default_config ["METROPOLIS_FORK_BLKNUM" ]:
85
+ tx ._sender = normalize_address (config .default_config ["METROPOLIS_ENTRY_POINT" ])
86
+ else :
87
+ raise UnsignedTransaction (tx )
85
88
if block .number >= config .default_config ["HOMESTEAD_FORK_BLKNUM" ]:
86
89
tx .check_low_s ()
87
90
@@ -222,6 +225,8 @@ def __init__(self, block, tx):
222
225
self .get_code = block .get_code
223
226
self .get_balance = block .get_balance
224
227
self .set_balance = block .set_balance
228
+ self .get_nonce = block .get_nonce
229
+ self .set_nonce = block .set_nonce
225
230
self .set_storage_data = block .set_storage_data
226
231
self .get_storage_data = block .get_storage_data
227
232
self .log_storage = lambda x : block .account_to_dict (x )['storage' ]
@@ -299,10 +304,21 @@ def create_contract(ext, msg):
299
304
log_msg .debug ('CONTRACT CREATION' )
300
305
#print('CREATING WITH GAS', msg.gas)
301
306
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 )
307
+ code = msg .data .extract_all ()
308
+ if ext ._block .number >= ext ._block .METROPOLIS_FORK_BLKNUM :
309
+ msg .to = mk_metropolis_contract_address (msg .sender , code )
310
+ if ext .get_code (msg .to ):
311
+ if ext .get_nonce (msg .to ) >= 2 ** 40 :
312
+ ext .set_nonce (msg .to , (ext .get_nonce (msg .to ) + 1 ) % 2 ** 160 )
313
+ msg .to = normalize_address ((ext .get_nonce (msg .to ) - 1 ) % 2 ** 160 )
314
+ else :
315
+ ext .set_nonce (msg .to , (big_endian_to_int (msg .to ) + 2 ) % 2 ** 160 )
316
+ msg .to = normalize_address ((ext .get_nonce (msg .to ) - 1 ) % 2 ** 160 )
317
+ else :
318
+ if ext .tx_origin != msg .sender :
319
+ ext ._block .increment_nonce (msg .sender )
320
+ nonce = utils .encode_int (ext ._block .get_nonce (msg .sender ) - 1 )
321
+ msg .to = mk_contract_address (sender , nonce )
306
322
b = ext .get_balance (msg .to )
307
323
if b > 0 :
308
324
ext .set_balance (msg .to , b )
@@ -311,7 +327,6 @@ def create_contract(ext, msg):
311
327
ext ._block .reset_storage (msg .to )
312
328
msg .is_create = True
313
329
# assert not ext.get_code(msg.to)
314
- code = msg .data .extract_all ()
315
330
msg .data = vm .CallData ([], 0 , 0 )
316
331
snapshot = ext ._block .snapshot ()
317
332
res , gas , dat = _apply_msg (ext , msg , code )
0 commit comments