Skip to content

Commit 87cc4f2

Browse files
fbeutin-ledgerapaillier-ledger
authored andcommitted
Fix Thorswap for ERC20 tokens by increasing CROSSCHAIN internal plugin priority
(cherry picked from commit 942a7ba)
1 parent fb2f67f commit 87cc4f2

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

src/eth_plugin_handler.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,34 +140,38 @@ eth_plugin_result_t eth_plugin_perform_init(uint8_t *contractAddress,
140140
case ERC721:
141141
#endif // HAVE_NFT_SUPPORT
142142
case EXTERNAL:
143+
PRINTF("eth_plugin_perform_init_default\n");
143144
eth_plugin_perform_init_default(contractAddress, init);
144145
contractAddress = NULL;
145146
break;
146147
case OLD_INTERNAL:
148+
PRINTF("eth_plugin_perform_init_old_internal\n");
147149
if (eth_plugin_perform_init_old_internal(contractAddress, init)) {
148150
contractAddress = NULL;
149151
}
150152
break;
153+
case SWAP_WITH_CALLDATA:
154+
PRINTF("contractAddress == %.*H\n", 20, contractAddress);
155+
PRINTF("Fallback on swap_with_calldata plugin\n");
156+
contractAddress = NULL;
157+
dataContext.tokenContext.pluginStatus = ETH_PLUGIN_RESULT_OK;
158+
break;
151159
default:
152160
PRINTF("Unsupported pluginType %d\n", pluginType);
153161
os_sched_exit(0);
154162
break;
155163
}
156164

157-
if (G_called_from_swap && (contractAddress != NULL)) {
158-
PRINTF("contractAddress == %.*H\n", 20, contractAddress);
159-
PRINTF("selector == %.*H\n", 20, contractAddress);
160-
PRINTF("Fallback on swap_with_calldata plugin\n");
161-
set_swap_with_calldata_plugin_type();
162-
dataContext.tokenContext.pluginStatus = ETH_PLUGIN_RESULT_OK;
163-
contractAddress = NULL;
164-
}
165-
166165
eth_plugin_result_t status = ETH_PLUGIN_RESULT_UNAVAILABLE;
167166

168167
if (contractAddress != NULL) {
169168
PRINTF("No plugin available for %.*H\n", 20, contractAddress);
170-
return status;
169+
if (G_called_from_swap) {
170+
PRINTF("Not supported in swap mode\n");
171+
return ETH_PLUGIN_RESULT_ERROR;
172+
} else {
173+
return status;
174+
}
171175
}
172176

173177
PRINTF("eth_plugin_init\n");

src/handle_swap_sign_transaction.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "shared_context.h"
77
#include "common_utils.h"
88
#include "network.h"
9+
#include "cmd_setPlugin.h"
910
#ifdef HAVE_NBGL
1011
#include "nbgl_use_case.h"
1112
#endif // HAVE_NBGL
@@ -138,6 +139,10 @@ void __attribute__((noreturn)) handle_swap_sign_transaction(const chain_config_t
138139
reset_app_context();
139140
G_called_from_swap = true;
140141
G_swap_response_ready = false;
142+
// If we are in crosschain context, automatically register the CROSSCHAIN plugin
143+
if (G_swap_mode == SWAP_MODE_CROSSCHAIN_PENDING_CHECK) {
144+
set_swap_with_calldata_plugin_type();
145+
}
141146

142147
common_app_init();
143148

src_features/signTx/cmd_signTx.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ uint16_t handleSign(uint8_t p1,
8383
case USTREAM_PROCESSING:
8484
return APDU_RESPONSE_OK;
8585
case USTREAM_FAULT:
86-
return APDU_RESPONSE_INVALID_DATA;
86+
if (G_called_from_swap) {
87+
// We have encountered an error while trying to sign a SWAP type transaction
88+
// Return dedicated error code and flag an early exit back to Exchange
89+
G_swap_response_ready = true;
90+
return APDU_RESPONSE_MODE_CHECK_FAILED;
91+
} else {
92+
return APDU_RESPONSE_INVALID_DATA;
93+
}
8794
default:
8895
PRINTF("Unexpected parser status\n");
8996
return APDU_RESPONSE_INVALID_DATA;

src_features/signTx/logic_signTx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ customStatus_e customProcessor(txContext_t *context) {
5757
dataContext.tokenContext.pluginStatus = ETH_PLUGIN_RESULT_UNAVAILABLE;
5858
// If contract debugging mode is activated, do not go through the plugin activation
5959
// as they wouldn't be displayed if the plugin consumes all data but fallbacks
60-
if (!N_storage.contractDetails) {
60+
// Still go through plugin activation in Swap context
61+
if (!N_storage.contractDetails || G_called_from_swap) {
6162
eth_plugin_prepare_init(&pluginInit,
6263
context->workBuffer,
6364
context->currentFieldLength);

0 commit comments

Comments
 (0)