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()) |
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: