Created
September 14, 2019 11:39
-
-
Save CrackerHax/ec6964ea030d4b31d47b7d412036c623 to your computer and use it in GitHub Desktop.
Python script for getting ethereum public key from transaction id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import web3 | |
w3 = web3.Web3(web3.HTTPProvider('https://geth.golem.network:55555')) | |
tx = w3.eth.getTransaction('0x00ee93fd1e6fdbdf841b4458a078210449dce89525502c965fd3534ba397e2e3') | |
tx.hash | |
from eth_account._utils.signing import extract_chain_id, to_standard_v | |
s = w3.eth.account._keys.Signature(vrs=( | |
to_standard_v(extract_chain_id(tx.v)[1]), | |
w3.toInt(tx.r), | |
w3.toInt(tx.s) | |
)) | |
from eth_account._utils.transactions import ALLOWED_TRANSACTION_KEYS | |
tt = {k:tx[k] for k in ALLOWED_TRANSACTION_KEYS - {'chainId', 'data'}} | |
tt['data']=tx.input | |
tt['chainId']=extract_chain_id(tx.v)[0] | |
from eth_account._utils.transactions import serializable_unsigned_transaction_from_dict | |
ut = serializable_unsigned_transaction_from_dict(tt) | |
s.recover_public_key_from_msg_hash(ut.hash()) |
Thx for the gist and the improvements. I was able to dig into some edge cases:
- Type
0x03
transactions are not supported - Type
0x00
legacy transactions are not handled correctly according to EIP 155 (for values where v=27 or v=28) and there is notchainId
- Transactions with a non-empty
accessList
are not handled correctly.
I tried to fix all of those and posted a gist for the slightly longer version here: https://gist.github.com/kernoelpanic/423c61f90e81e4c9d473ff6fda783559
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out that has edge cases, here's the full code for all types:
Though there are still edge cases to this code which I haven't been able to figure out. MEV bots are able to break the code above to give inaccurate from_addresses. A sample of tx hashes that break the system:
Predicted, Actual, tx_hash: