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

Commit

Permalink
Added more EIP86 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
vub authored and vub committed Apr 30, 2017
1 parent 6d95df5 commit 7ae7622
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
10 changes: 6 additions & 4 deletions ethereum/new_statetest_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"]))
Expand Down
11 changes: 7 additions & 4 deletions ethereum/processblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
8 changes: 7 additions & 1 deletion ethereum/state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ae7622

Please sign in to comment.