Skip to content

Commit

Permalink
Fix recover_transaction function in Ragger client for non-legacy tran…
Browse files Browse the repository at this point in the history
…sactions
  • Loading branch information
apaillier-ledger committed Feb 26, 2024
1 parent 4277465 commit 63da10e
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions client/src/ledger_app_clients/ethereum/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,22 @@ def recover_message(msg, vrs: tuple) -> bytes:
return bytes.fromhex(addr[2:])


# TODO: Figure out why it doesn't work for non-legacy transactions
def recover_transaction(tx_params, vrs: tuple) -> bytes:
raw_tx = Account.create().sign_transaction(tx_params).rawTransaction
prefix = bytes()
if raw_tx[0] in [0x01, 0x02]:
prefix = raw_tx[:1]
raw_tx = raw_tx[len(prefix):]
if prefix == bytes():
# v is returned on one byte only so it might have overflowed
# in that case, we will reconstruct it to its full value
if "chainId" in tx_params:
trunc_chain_id = tx_params["chainId"]
while trunc_chain_id.bit_length() > 32:
trunc_chain_id >>= 8
target = tx_params["chainId"] * 2 + 35
trunc_target = trunc_chain_id * 2 + 35
diff = vrs[0][0] - (trunc_target & 0xff)
vrs = (target + diff, vrs[1], vrs[2])
# v is returned on one byte only so it might have overflowed
# in that case, we will reconstruct it to its full value
if "chainId" in tx_params:
trunc_chain_id = tx_params["chainId"]
while trunc_chain_id.bit_length() > 32:
trunc_chain_id >>= 8
target = tx_params["chainId"] * 2 + 35
trunc_target = trunc_chain_id * 2 + 35
diff = vrs[0][0] - (trunc_target & 0xff)
vrs = (target + diff, vrs[1], vrs[2])
decoded = rlp.decode(raw_tx)
reencoded = rlp.encode(decoded[:-3] + list(vrs))
addr = Account.recover_transaction(prefix + reencoded)
Expand Down

0 comments on commit 63da10e

Please sign in to comment.