From 7ae7622fb1dbbd291a963500a1e88744ea1d5181 Mon Sep 17 00:00:00 2001 From: vub Date: Sun, 30 Apr 2017 05:24:48 -0400 Subject: [PATCH] Added more EIP86 compatibility --- ethereum/new_statetest_utils.py | 10 ++++++---- ethereum/processblock.py | 11 +++++++---- ethereum/state_transition.py | 8 +++++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/ethereum/new_statetest_utils.py b/ethereum/new_statetest_utils.py index 4170eda95..84a050d30 100644 --- a/ethereum/new_statetest_utils.py +++ b/ethereum/new_statetest_utils.py @@ -101,17 +101,19 @@ def compute_state_test_unit(state, txdata, indices, konfig): to=decode_hex(remove_0x_head(txdata['to'])), value=parse_int_or_hex(txdata['value'][indices["value"]] or b"0"), data=decode_hex(remove_0x_head(txdata['data'][indices["data"]]))) - tx.sign(decode_hex(remove_0x_head(txdata['secretKey']))) + if 'secretKey' in txdata: + tx.sign(decode_hex(remove_0x_head(txdata['secretKey']))) + else: + tx.v = parse_int_or_hex(txdata['v']) # Run it prev = state.to_dict() success, output = state_transition.apply_transaction(state, tx) - post = state.to_dict() print("Applied tx") except InvalidTransaction as e: print("Exception: %r" % e) - post = state.to_dict() success, output = False, b'' state.commit() + post = state.to_dict() output_decl = { "hash": '0x' + encode_hex(state.trie.root_hash), "indexes": indices, @@ -167,7 +169,7 @@ def verify_state_test(test): parse_int_or_hex(test["transaction"]['value'][result["indexes"]["value"]]), data)) computed = compute_state_test_unit(_state, test["transaction"], result["indexes"], configs[config_name]) - if computed["hash"] != result["hash"]: + if computed["hash"][-64:] != result["hash"][-64:]: for k in computed["diff"]: print(k, computed["diff"][k]) raise Exception("Hash mismatch, computed: %s, supplied: %s" % (computed["hash"], result["hash"])) diff --git a/ethereum/processblock.py b/ethereum/processblock.py index 988c29306..76c12c1c0 100644 --- a/ethereum/processblock.py +++ b/ethereum/processblock.py @@ -30,6 +30,8 @@ # contract creating transactions send to an empty address CREATE_CONTRACT_ADDRESS = b'' +null_address = b'\xff' * 20 + class Log(rlp.Serializable): @@ -120,10 +122,11 @@ def create_contract(ext, msg): code = msg.data.extract_all() if ext.tx_origin != msg.sender: ext.increment_nonce(msg.sender) - nonce = utils.encode_int(ext.get_nonce(msg.sender) - 1) - if ext.post_metropolis_hardfork() and msg.sender == ext.tx_origin and False: - msg.to = sha3(msg.sender + code)[12:] + if ext.post_metropolis_hardfork() and msg.sender == null_address: + msg.to = mk_contract_address(sender, 0) + # msg.to = sha3(msg.sender + code)[12:] else: + nonce = utils.encode_int(ext.get_nonce(msg.sender) - 1) msg.to = mk_contract_address(sender, nonce) b = ext.get_balance(msg.to) if b > 0: @@ -159,4 +162,4 @@ def create_contract(ext, msg): return 1, gas, msg.to else: ext.revert(snapshot) - return 0, gas, b'' + return 0, gas, dat diff --git a/ethereum/state_transition.py b/ethereum/state_transition.py index 3024a3392..1a57b1e48 100644 --- a/ethereum/state_transition.py +++ b/ethereum/state_transition.py @@ -242,7 +242,13 @@ def rp(what, actual, target): txdict["data"] = "data<%d>" % (len(txdict["data"]) // 2 - 1) log_tx.debug('TX NEW', tx_dict=txdict) # start transacting ################# - state.increment_nonce(tx.sender) + if tx.sender != null_address: + state.increment_nonce(tx.sender) + else: + if tx.gasprice != 0 or tx.value != 0 or tx.nonce != 0: + raise InvalidTransaction("EIP86 transactions must have 0 gasprice and value") + if tx.v != state.config['NETWORK_ID']: + raise InvalidTransaction("Wrong network ID for EIP86 transaction") # buy startgas assert state.get_balance(tx.sender) >= tx.startgas * tx.gasprice