Skip to content

Commit 63da10e

Browse files
Fix recover_transaction function in Ragger client for non-legacy transactions
1 parent 4277465 commit 63da10e

File tree

1 file changed

+10
-12
lines changed
  • client/src/ledger_app_clients/ethereum

1 file changed

+10
-12
lines changed

client/src/ledger_app_clients/ethereum/utils.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,22 @@ def recover_message(msg, vrs: tuple) -> bytes:
1717
return bytes.fromhex(addr[2:])
1818

1919

20-
# TODO: Figure out why it doesn't work for non-legacy transactions
2120
def recover_transaction(tx_params, vrs: tuple) -> bytes:
2221
raw_tx = Account.create().sign_transaction(tx_params).rawTransaction
2322
prefix = bytes()
2423
if raw_tx[0] in [0x01, 0x02]:
2524
prefix = raw_tx[:1]
2625
raw_tx = raw_tx[len(prefix):]
27-
if prefix == bytes():
28-
# v is returned on one byte only so it might have overflowed
29-
# in that case, we will reconstruct it to its full value
30-
if "chainId" in tx_params:
31-
trunc_chain_id = tx_params["chainId"]
32-
while trunc_chain_id.bit_length() > 32:
33-
trunc_chain_id >>= 8
34-
target = tx_params["chainId"] * 2 + 35
35-
trunc_target = trunc_chain_id * 2 + 35
36-
diff = vrs[0][0] - (trunc_target & 0xff)
37-
vrs = (target + diff, vrs[1], vrs[2])
26+
# v is returned on one byte only so it might have overflowed
27+
# in that case, we will reconstruct it to its full value
28+
if "chainId" in tx_params:
29+
trunc_chain_id = tx_params["chainId"]
30+
while trunc_chain_id.bit_length() > 32:
31+
trunc_chain_id >>= 8
32+
target = tx_params["chainId"] * 2 + 35
33+
trunc_target = trunc_chain_id * 2 + 35
34+
diff = vrs[0][0] - (trunc_target & 0xff)
35+
vrs = (target + diff, vrs[1], vrs[2])
3836
decoded = rlp.decode(raw_tx)
3937
reencoded = rlp.encode(decoded[:-3] + list(vrs))
4038
addr = Account.recover_transaction(prefix + reencoded)

0 commit comments

Comments
 (0)