From 63da10e20ee59036a0d2cd2e5625bb18e86ac586 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Mon, 26 Feb 2024 15:09:42 +0100 Subject: [PATCH 1/2] Fix recover_transaction function in Ragger client for non-legacy transactions --- .../src/ledger_app_clients/ethereum/utils.py | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/client/src/ledger_app_clients/ethereum/utils.py b/client/src/ledger_app_clients/ethereum/utils.py index f538403c7..2b50fe551 100644 --- a/client/src/ledger_app_clients/ethereum/utils.py +++ b/client/src/ledger_app_clients/ethereum/utils.py @@ -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) From 682354ce654838febb429a6611c4c1b102c5d915 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Tue, 27 Feb 2024 16:20:26 +0100 Subject: [PATCH 2/2] Updated Ragger client changelog --- client/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/client/CHANGELOG.md b/client/CHANGELOG.md index 3d66d0b07..094bcd627 100644 --- a/client/CHANGELOG.md +++ b/client/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Increased the delay between `autonext` callback calls for EIP-712 on Stax +- `recover_transaction` util function for non-legacy transactions ## [0.2.1] - 2023-12-01