Skip to content

Commit

Permalink
fix for chain id extraction from EIP155 signed transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
pipermerriam committed Oct 19, 2017
1 parent 9d124f8 commit 700097f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion evm/utils/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def is_eip_155_signed_transaction(transaction):

def extract_chain_id(v):
if is_even(v):
return (v - EIP155_CHAIN_ID_OFFSET) // 2
return (v - EIP155_CHAIN_ID_OFFSET - 1) // 2
else:
return (v - EIP155_CHAIN_ID_OFFSET) // 2

Expand Down
5 changes: 4 additions & 1 deletion evm/vm/forks/spurious_dragon/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def create_unsigned_transaction(cls, nonce, gas_price, gas, to, value, data):

@property
def chain_id(self):
return extract_chain_id(self)
if is_eip_155_signed_transaction(self):
return extract_chain_id(self.v)
else:
return None


class SpuriousDragonUnsignedTransaction(HomesteadUnsignedTransaction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ def test_unsigned_to_eip155_signed_transaction(txn_fixture, transaction_class):
signed_txn = unsigned_txn.as_signed_transaction(key, chain_id=txn_fixture['chainId'])

assert is_same_address(signed_txn.sender, key.public_key.to_canonical_address())
assert signed_txn.chain_id == txn_fixture['chainId']

0 comments on commit 700097f

Please sign in to comment.