Added missing return value checks following recent changes

This commit is contained in:
Alexandre Paillier
2023-10-05 15:01:58 +02:00
parent 9a9e946b50
commit 49da32af8e
14 changed files with 254 additions and 166 deletions

View File

@@ -53,10 +53,12 @@ int handle_check_address(check_address_parameters_t* params, chain_config_t* cha
ZERO(locals_union2); ZERO(locals_union2);
cx_ecfp_generate_pair(CX_CURVE_256K1, &locals_union2.publicKey, &locals_union1.privateKey, 1); cx_ecfp_generate_pair(CX_CURVE_256K1, &locals_union2.publicKey, &locals_union1.privateKey, 1);
ZERO(locals_union1); ZERO(locals_union1);
getEthAddressStringFromKey(&locals_union2.publicKey, if (!getEthAddressStringFromKey(&locals_union2.publicKey,
locals_union1.address, locals_union1.address,
&local_sha3, &local_sha3,
chain_config->chainId); chain_config->chainId)) {
THROW(CX_INVALID_PARAMETER);
}
ZERO(locals_union2); ZERO(locals_union2);
uint8_t offset_0x = 0; uint8_t offset_0x = 0;

View File

@@ -33,11 +33,13 @@ int handle_get_printable_amount(get_printable_amount_parameters_t* params, chain
} }
} }
amountToString(params->amount, if (!amountToString(params->amount,
params->amount_length, params->amount_length,
decimals, decimals,
ticker, ticker,
params->printable_amount, params->printable_amount,
sizeof(params->printable_amount)); sizeof(params->printable_amount))) {
THROW(EXCEPTION_OVERFLOW);
}
return 1; return 1;
} }

View File

@@ -35,22 +35,26 @@ bool copy_transaction_parameters(create_transaction_parameters_t* sign_transacti
PRINTF("Error while parsing config\n"); PRINTF("Error while parsing config\n");
return false; return false;
} }
amountToString(sign_transaction_params->amount, if (!amountToString(sign_transaction_params->amount,
sign_transaction_params->amount_length, sign_transaction_params->amount_length,
decimals, decimals,
ticker, ticker,
stack_data.fullAmount, stack_data.fullAmount,
sizeof(stack_data.fullAmount)); sizeof(stack_data.fullAmount))) {
THROW(EXCEPTION_OVERFLOW);
}
// If the amount is a fee, its value is nominated in ETH even if we're doing an ERC20 swap // If the amount is a fee, its value is nominated in ETH even if we're doing an ERC20 swap
strlcpy(ticker, config->coinName, MAX_TICKER_LEN); strlcpy(ticker, config->coinName, MAX_TICKER_LEN);
decimals = WEI_TO_ETHER; decimals = WEI_TO_ETHER;
amountToString(sign_transaction_params->fee_amount, if (!amountToString(sign_transaction_params->fee_amount,
sign_transaction_params->fee_amount_length, sign_transaction_params->fee_amount_length,
decimals, decimals,
ticker, ticker,
stack_data.maxFee, stack_data.maxFee,
sizeof(stack_data.maxFee)); sizeof(stack_data.maxFee))) {
THROW(EXCEPTION_OVERFLOW);
}
// Full reset the global variables // Full reset the global variables
os_explicit_zero_BSS_segment(); os_explicit_zero_BSS_segment();

View File

@@ -4,6 +4,7 @@
#include "ui_callbacks.h" #include "ui_callbacks.h"
#include "ethUtils.h" #include "ethUtils.h"
#include "starkDisplayUtils.h" #include "starkDisplayUtils.h"
#include "apdu_constants.h"
// clang-format off // clang-format off
UX_STEP_NOCB(ux_stark_limit_order_1_step, UX_STEP_NOCB(ux_stark_limit_order_1_step,
@@ -78,6 +79,16 @@ UX_FLOW(ux_stark_limit_order_flow,
&ux_stark_limit_order_7_step, &ux_stark_limit_order_7_step,
&ux_stark_limit_order_8_step); &ux_stark_limit_order_8_step);
static void stark_format_address(void) {
if (!getEthDisplayableAddress(dataContext.starkContext.conditionAddress,
strings.tmp.tmp,
sizeof(strings.tmp.tmp),
&global_sha3,
chainConfig->chainId)) {
THROW(APDU_RESPONSE_ERROR_NO_INFO);
}
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// clang-format off // clang-format off
UX_STEP_NOCB(ux_stark_transfer_1_step, UX_STEP_NOCB(ux_stark_transfer_1_step,
@@ -167,11 +178,7 @@ UX_STEP_NOCB_INIT(
UX_STEP_NOCB_INIT( UX_STEP_NOCB_INIT(
ux_stark_conditional_transfer_8_step, ux_stark_conditional_transfer_8_step,
bnnn_paging, bnnn_paging,
getEthDisplayableAddress(dataContext.starkContext.conditionAddress, stark_format_address(),
strings.tmp.tmp,
sizeof(strings.tmp.tmp),
&global_sha3,
chainConfig->chainId),
{ {
.title = "Cond. Address", .title = "Cond. Address",
.text = strings.tmp.tmp .text = strings.tmp.tmp

View File

@@ -49,10 +49,12 @@ void handleGetPublicKey(uint8_t p1,
explicit_bzero(&privateKey, sizeof(privateKey)); explicit_bzero(&privateKey, sizeof(privateKey));
explicit_bzero(privateKeyData, sizeof(privateKeyData)); explicit_bzero(privateKeyData, sizeof(privateKeyData));
io_seproxyhal_io_heartbeat(); io_seproxyhal_io_heartbeat();
getEthAddressStringFromKey(&tmpCtx.publicKeyContext.publicKey, if (!getEthAddressStringFromKey(&tmpCtx.publicKeyContext.publicKey,
tmpCtx.publicKeyContext.address, tmpCtx.publicKeyContext.address,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
THROW(CX_INVALID_PARAMETER);
}
uint64_t chain_id = chainConfig->chainId; uint64_t chain_id = chainConfig->chainId;
if (dataLength >= sizeof(chain_id)) { if (dataLength >= sizeof(chain_id)) {

View File

@@ -62,10 +62,12 @@ void handlePerformPrivacyOperation(uint8_t p1,
(tmpCtx.publicKeyContext.getChaincode ? tmpCtx.publicKeyContext.chainCode : NULL)); (tmpCtx.publicKeyContext.getChaincode ? tmpCtx.publicKeyContext.chainCode : NULL));
cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey); cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey);
cx_ecfp_generate_pair(CX_CURVE_256K1, &tmpCtx.publicKeyContext.publicKey, &privateKey, 1); cx_ecfp_generate_pair(CX_CURVE_256K1, &tmpCtx.publicKeyContext.publicKey, &privateKey, 1);
getEthAddressStringFromKey(&tmpCtx.publicKeyContext.publicKey, if (!getEthAddressStringFromKey(&tmpCtx.publicKeyContext.publicKey,
tmpCtx.publicKeyContext.address, tmpCtx.publicKeyContext.address,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
THROW(CX_INVALID_PARAMETER);
}
if (p2 == P2_PUBLIC_ENCRYPTION_KEY) { if (p2 == P2_PUBLIC_ENCRYPTION_KEY) {
decodeScalar(privateKeyData, privateKeyDataSwapped); decodeScalar(privateKeyData, privateKeyDataSwapped);
cx_ecfp_init_private_key(CX_CURVE_Curve25519, privateKeyDataSwapped, 32, &privateKey); cx_ecfp_init_private_key(CX_CURVE_Curve25519, privateKeyDataSwapped, 32, &privateKey);

View File

@@ -198,11 +198,13 @@ static bool ui_712_format_addr(const uint8_t *const data, uint8_t length) {
return false; return false;
} }
if (ui_712_field_shown()) { if (ui_712_field_shown()) {
getEthDisplayableAddress((uint8_t *) data, if (!getEthDisplayableAddress((uint8_t *) data,
strings.tmp.tmp, strings.tmp.tmp,
sizeof(strings.tmp.tmp), sizeof(strings.tmp.tmp),
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
THROW(APDU_RESPONSE_ERROR_NO_INFO);
}
} }
return true; return true;
} }

View File

@@ -1,3 +1,4 @@
#include <ctype.h>
#include "shared_context.h" #include "shared_context.h"
#include "utils.h" #include "utils.h"
#include "feature_signTx.h" #include "feature_signTx.h"
@@ -9,7 +10,7 @@
#include "ethUtils.h" #include "ethUtils.h"
#include "common_ui.h" #include "common_ui.h"
#include "ui_callbacks.h" #include "ui_callbacks.h"
#include <ctype.h> #include "apdu_constants.h"
#define ERR_SILENT_MODE_CHECK_FAILED 0x6001 #define ERR_SILENT_MODE_CHECK_FAILED 0x6001
@@ -189,7 +190,9 @@ static void address_to_string(uint8_t *in,
cx_sha3_t *sha3, cx_sha3_t *sha3,
uint64_t chainId) { uint64_t chainId) {
if (in_len != 0) { if (in_len != 0) {
getEthDisplayableAddress(in, out, out_len, sha3, chainId); if (!getEthDisplayableAddress(in, out, out_len, sha3, chainId)) {
THROW(APDU_RESPONSE_ERROR_NO_INFO);
}
} else { } else {
strlcpy(out, "Contract", out_len); strlcpy(out, "Contract", out_len);
} }
@@ -269,7 +272,9 @@ static void get_network_as_string(char *out, size_t out_size) {
if (name == NULL) { if (name == NULL) {
// No network name found so simply copy the chain ID as the network name. // No network name found so simply copy the chain ID as the network name.
u64_to_string(chain_id, out, out_size); if (!u64_to_string(chain_id, out, out_size)) {
THROW(0x6502);
}
} else { } else {
// Network name found, simply copy it. // Network name found, simply copy it.
strlcpy(out, name, out_size); strlcpy(out, name, out_size);
@@ -294,7 +299,9 @@ static void get_public_key(uint8_t *out, uint8_t outLength) {
cx_ecfp_generate_pair(CX_CURVE_256K1, &publicKey, &privateKey, 1); cx_ecfp_generate_pair(CX_CURVE_256K1, &publicKey, &privateKey, 1);
explicit_bzero(&privateKey, sizeof(privateKey)); explicit_bzero(&privateKey, sizeof(privateKey));
explicit_bzero(privateKeyData, sizeof(privateKeyData)); explicit_bzero(privateKeyData, sizeof(privateKeyData));
getEthAddressFromKey(&publicKey, out, &global_sha3); if (!getEthAddressFromKey(&publicKey, out, &global_sha3)) {
THROW(CX_INVALID_PARAMETER);
}
} }
/* Local implmentation of strncasecmp, workaround of the segfaulting base implem /* Local implmentation of strncasecmp, workaround of the segfaulting base implem

View File

@@ -65,11 +65,13 @@ static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) {
} }
if (page == 1) { if (page == 1) {
if (context.conditional) { if (context.conditional) {
getEthDisplayableAddress(dataContext.starkContext.conditionAddress, if (!getEthDisplayableAddress(dataContext.starkContext.conditionAddress,
condAddressBuffer, condAddressBuffer,
sizeof(condAddressBuffer), sizeof(condAddressBuffer),
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
return false;
}
pairs[0].item = "Cond. Address"; pairs[0].item = "Cond. Address";
pairs[0].value = condAddressBuffer; pairs[0].value = condAddressBuffer;

View File

@@ -14,11 +14,13 @@ static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc1155_context_t
} else { } else {
strlcpy(msg->title, "Revoke", msg->titleLength); strlcpy(msg->title, "Revoke", msg->titleLength);
} }
getEthDisplayableAddress(context->address, if (!getEthDisplayableAddress(context->address,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
case 1: case 1:
strlcpy(msg->title, "To Manage ALL", msg->titleLength); strlcpy(msg->title, "To Manage ALL", msg->titleLength);
@@ -26,11 +28,13 @@ static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc1155_context_t
break; break;
case 2: case 2:
strlcpy(msg->title, "NFT Address", msg->titleLength); strlcpy(msg->title, "NFT Address", msg->titleLength);
getEthDisplayableAddress(msg->item1->nft.contractAddress, if (!getEthDisplayableAddress(msg->item1->nft.contractAddress,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
default: default:
PRINTF("Unsupported screen index %d\n", msg->screenIndex); PRINTF("Unsupported screen index %d\n", msg->screenIndex);
@@ -43,11 +47,13 @@ static void set_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *contex
switch (msg->screenIndex) { switch (msg->screenIndex) {
case 0: case 0:
strlcpy(msg->title, "To", msg->titleLength); strlcpy(msg->title, "To", msg->titleLength);
getEthDisplayableAddress(context->address, if (!getEthDisplayableAddress(context->address,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
case 1: case 1:
strlcpy(msg->title, "Collection Name", msg->titleLength); strlcpy(msg->title, "Collection Name", msg->titleLength);
@@ -55,22 +61,28 @@ static void set_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *contex
break; break;
case 2: case 2:
strlcpy(msg->title, "NFT Address", msg->titleLength); strlcpy(msg->title, "NFT Address", msg->titleLength);
getEthDisplayableAddress(msg->item1->nft.contractAddress, if (!getEthDisplayableAddress(msg->item1->nft.contractAddress,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
case 3: case 3:
strlcpy(msg->title, "NFT ID", msg->titleLength); strlcpy(msg->title, "NFT ID", msg->titleLength);
uint256_to_decimal(context->tokenId, if (!uint256_to_decimal(context->tokenId,
sizeof(context->tokenId), sizeof(context->tokenId),
msg->msg, msg->msg,
msg->msgLength); msg->msgLength)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
case 4: case 4:
strlcpy(msg->title, "Quantity", msg->titleLength); strlcpy(msg->title, "Quantity", msg->titleLength);
tostring256(&context->value, 10, msg->msg, msg->msgLength); if (!tostring256(&context->value, 10, msg->msg, msg->msgLength)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
default: default:
PRINTF("Unsupported screen index %d\n", msg->screenIndex); PRINTF("Unsupported screen index %d\n", msg->screenIndex);
@@ -85,11 +97,13 @@ static void set_batch_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *
switch (msg->screenIndex) { switch (msg->screenIndex) {
case 0: case 0:
strlcpy(msg->title, "To", msg->titleLength); strlcpy(msg->title, "To", msg->titleLength);
getEthDisplayableAddress(context->address, if (!getEthDisplayableAddress(context->address,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
case 1: case 1:
strlcpy(msg->title, "Collection Name", msg->titleLength); strlcpy(msg->title, "Collection Name", msg->titleLength);
@@ -97,15 +111,20 @@ static void set_batch_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *
break; break;
case 2: case 2:
strlcpy(msg->title, "NFT Address", msg->titleLength); strlcpy(msg->title, "NFT Address", msg->titleLength);
getEthDisplayableAddress(msg->item1->nft.contractAddress, if (!getEthDisplayableAddress(msg->item1->nft.contractAddress,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
case 3: case 3:
strlcpy(msg->title, "Total Quantity", msg->titleLength); strlcpy(msg->title, "Total Quantity", msg->titleLength);
tostring256(&context->value, 10, &quantity_str[0], sizeof(quantity_str)); if (!tostring256(&context->value, 10, &quantity_str[0], sizeof(quantity_str))) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
snprintf(msg->msg, snprintf(msg->msg,
msg->msgLength, msg->msgLength,
"%s from %d NFT IDs", "%s from %d NFT IDs",

View File

@@ -201,12 +201,14 @@ void erc20_plugin_call(int message, void *parameters) {
strlcpy(msg->msg, "Unlimited ", msg->msgLength); strlcpy(msg->msg, "Unlimited ", msg->msgLength);
strlcat(msg->msg, context->ticker, msg->msgLength); strlcat(msg->msg, context->ticker, msg->msgLength);
} else { } else {
amountToString(context->amount, if (!amountToString(context->amount,
sizeof(context->amount), sizeof(context->amount),
context->decimals, context->decimals,
context->ticker, context->ticker,
msg->msg, msg->msg,
100); 100)) {
THROW(EXCEPTION_OVERFLOW);
}
} }
msg->result = ETH_PLUGIN_RESULT_OK; msg->result = ETH_PLUGIN_RESULT_OK;
break; break;
@@ -216,11 +218,13 @@ void erc20_plugin_call(int message, void *parameters) {
strlcpy(msg->msg, context->contract_name, msg->msgLength); strlcpy(msg->msg, context->contract_name, msg->msgLength);
} else { } else {
strlcpy(msg->title, "Address", msg->titleLength); strlcpy(msg->title, "Address", msg->titleLength);
getEthDisplayableAddress(context->destinationAddress, if (!getEthDisplayableAddress(context->destinationAddress,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
msg->pluginSharedRW->sha3, msg->pluginSharedRW->sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
} }
msg->result = ETH_PLUGIN_RESULT_OK; msg->result = ETH_PLUGIN_RESULT_OK;

View File

@@ -10,11 +10,13 @@ static void set_approval_ui(ethQueryContractUI_t *msg, erc721_context_t *context
switch (msg->screenIndex) { switch (msg->screenIndex) {
case 0: case 0:
strlcpy(msg->title, "Allow", msg->titleLength); strlcpy(msg->title, "Allow", msg->titleLength);
getEthDisplayableAddress(context->address, if (!getEthDisplayableAddress(context->address,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
case 1: case 1:
strlcpy(msg->title, "To Manage Your", msg->titleLength); strlcpy(msg->title, "To Manage Your", msg->titleLength);
@@ -22,18 +24,22 @@ static void set_approval_ui(ethQueryContractUI_t *msg, erc721_context_t *context
break; break;
case 2: case 2:
strlcpy(msg->title, "NFT Address", msg->titleLength); strlcpy(msg->title, "NFT Address", msg->titleLength);
getEthDisplayableAddress(msg->item1->nft.contractAddress, if (!getEthDisplayableAddress(msg->item1->nft.contractAddress,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
case 3: case 3:
strlcpy(msg->title, "NFT ID", msg->titleLength); strlcpy(msg->title, "NFT ID", msg->titleLength);
uint256_to_decimal(context->tokenId, if (!uint256_to_decimal(context->tokenId,
sizeof(context->tokenId), sizeof(context->tokenId),
msg->msg, msg->msg,
msg->msgLength); msg->msgLength)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
default: default:
PRINTF("Unsupported screen index %d\n", msg->screenIndex); PRINTF("Unsupported screen index %d\n", msg->screenIndex);
@@ -50,11 +56,13 @@ static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc721_context_t
} else { } else {
strlcpy(msg->title, "Revoke", msg->titleLength); strlcpy(msg->title, "Revoke", msg->titleLength);
} }
getEthDisplayableAddress(context->address, if (!getEthDisplayableAddress(context->address,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
case 1: case 1:
strlcpy(msg->title, "To Manage ALL", msg->titleLength); strlcpy(msg->title, "To Manage ALL", msg->titleLength);
@@ -62,11 +70,13 @@ static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc721_context_t
break; break;
case 2: case 2:
strlcpy(msg->title, "NFT Address", msg->titleLength); strlcpy(msg->title, "NFT Address", msg->titleLength);
getEthDisplayableAddress(msg->item1->nft.contractAddress, if (!getEthDisplayableAddress(msg->item1->nft.contractAddress,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
default: default:
PRINTF("Unsupported screen index %d\n", msg->screenIndex); PRINTF("Unsupported screen index %d\n", msg->screenIndex);
@@ -79,11 +89,13 @@ static void set_transfer_ui(ethQueryContractUI_t *msg, erc721_context_t *context
switch (msg->screenIndex) { switch (msg->screenIndex) {
case 0: case 0:
strlcpy(msg->title, "To", msg->titleLength); strlcpy(msg->title, "To", msg->titleLength);
getEthDisplayableAddress(context->address, if (!getEthDisplayableAddress(context->address,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
case 1: case 1:
strlcpy(msg->title, "Collection Name", msg->titleLength); strlcpy(msg->title, "Collection Name", msg->titleLength);
@@ -91,18 +103,22 @@ static void set_transfer_ui(ethQueryContractUI_t *msg, erc721_context_t *context
break; break;
case 2: case 2:
strlcpy(msg->title, "NFT Address", msg->titleLength); strlcpy(msg->title, "NFT Address", msg->titleLength);
getEthDisplayableAddress(msg->item1->nft.contractAddress, if (!getEthDisplayableAddress(msg->item1->nft.contractAddress,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
case 3: case 3:
strlcpy(msg->title, "NFT ID", msg->titleLength); strlcpy(msg->title, "NFT ID", msg->titleLength);
uint256_to_decimal(context->tokenId, if (!uint256_to_decimal(context->tokenId,
sizeof(context->tokenId), sizeof(context->tokenId),
msg->msg, msg->msg,
msg->msgLength); msg->msgLength)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
break; break;
default: default:
PRINTF("Unsupported screen index %d\n", msg->screenIndex); PRINTF("Unsupported screen index %d\n", msg->screenIndex);

View File

@@ -117,11 +117,14 @@ void eth2_plugin_call(int message, void *parameters) {
// Use a temporary buffer to store the string representation. // Use a temporary buffer to store the string representation.
char tmp[ETH2_DEPOSIT_PUBKEY_LENGTH]; char tmp[ETH2_DEPOSIT_PUBKEY_LENGTH];
getEthDisplayableAddress((uint8_t *) context->deposit_address, if (!getEthDisplayableAddress((uint8_t *) context->deposit_address,
tmp, tmp,
sizeof(tmp), sizeof(tmp),
msg->pluginSharedRW->sha3, msg->pluginSharedRW->sha3,
chainConfig->chainId); chainConfig->chainId)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}
// Copy back the string to the global variable. // Copy back the string to the global variable.
strlcpy(context->deposit_address, tmp, ETH2_DEPOSIT_PUBKEY_LENGTH); strlcpy(context->deposit_address, tmp, ETH2_DEPOSIT_PUBKEY_LENGTH);
@@ -200,12 +203,14 @@ void eth2_plugin_call(int message, void *parameters) {
uint8_t decimals = WEI_TO_ETHER; uint8_t decimals = WEI_TO_ETHER;
char *ticker = chainConfig->coinName; char *ticker = chainConfig->coinName;
strlcpy(msg->title, "Amount", msg->titleLength); strlcpy(msg->title, "Amount", msg->titleLength);
amountToString(tmpContent.txContent.value.value, if (!amountToString(tmpContent.txContent.value.value,
tmpContent.txContent.value.length, tmpContent.txContent.value.length,
decimals, decimals,
ticker, ticker,
msg->msg, msg->msg,
100); 100)) {
THROW(EXCEPTION_OVERFLOW);
}
msg->result = ETH_PLUGIN_RESULT_OK; msg->result = ETH_PLUGIN_RESULT_OK;
} break; } break;
case 1: { // Deposit pubkey screen case 1: { // Deposit pubkey screen

View File

@@ -6,6 +6,7 @@
#include "stark_utils.h" #include "stark_utils.h"
#include "utils.h" #include "utils.h"
#include "ethUtils.h" #include "ethUtils.h"
#include "apdu_constants.h"
#ifdef HAVE_STARKWARE #ifdef HAVE_STARKWARE
@@ -352,11 +353,13 @@ void starkware_print_asset_contract(char *destination, size_t destinationLength)
if (dataContext.tokenContext.quantumIndex != MAX_ITEMS) { if (dataContext.tokenContext.quantumIndex != MAX_ITEMS) {
tokenDefinition_t *token = tokenDefinition_t *token =
&tmpCtx.transactionContext.extraInfo[dataContext.tokenContext.quantumIndex].token; &tmpCtx.transactionContext.extraInfo[dataContext.tokenContext.quantumIndex].token;
getEthDisplayableAddress(token->address, if (!getEthDisplayableAddress(token->address,
destination, destination,
destinationLength, destinationLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
THROW(APDU_RESPONSE_ERROR_NO_INFO);
}
} else { } else {
strlcpy(destination, "UNKNOWN", destinationLength); strlcpy(destination, "UNKNOWN", destinationLength);
} }
@@ -380,7 +383,12 @@ void starkware_get_source_address(char *destination) {
io_seproxyhal_io_heartbeat(); io_seproxyhal_io_heartbeat();
destination[0] = '0'; destination[0] = '0';
destination[1] = 'x'; destination[1] = 'x';
getEthAddressStringFromKey(&publicKey, destination + 2, &global_sha3, chainConfig->chainId); if (!getEthAddressStringFromKey(&publicKey,
destination + 2,
&global_sha3,
chainConfig->chainId)) {
THROW(CX_INVALID_PARAMETER);
}
destination[42] = '\0'; destination[42] = '\0';
} }
@@ -716,11 +724,13 @@ void starkware_plugin_call(int message, void *parameters) {
if (is_deversify_contract(tmpContent.txContent.destination)) { if (is_deversify_contract(tmpContent.txContent.destination)) {
strlcpy(msg->msg, "DeversiFi", msg->msgLength); strlcpy(msg->msg, "DeversiFi", msg->msgLength);
} else { } else {
getEthDisplayableAddress(tmpContent.txContent.destination, if (!getEthDisplayableAddress(tmpContent.txContent.destination,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
THROW(APDU_RESPONSE_ERROR_NO_INFO);
}
} }
msg->result = ETH_PLUGIN_RESULT_OK; msg->result = ETH_PLUGIN_RESULT_OK;
break; break;
@@ -730,11 +740,13 @@ void starkware_plugin_call(int message, void *parameters) {
case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN:
case STARKWARE_REGISTER_AND_DEPOSIT_ETH: case STARKWARE_REGISTER_AND_DEPOSIT_ETH:
strlcpy(msg->title, "From ETH Address", msg->titleLength); strlcpy(msg->title, "From ETH Address", msg->titleLength);
getEthDisplayableAddress(context->amount, if (!getEthDisplayableAddress(context->amount,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
THROW(APDU_RESPONSE_ERROR_NO_INFO);
}
break; break;
case STARKWARE_ESCAPE: case STARKWARE_ESCAPE:
strlcpy(msg->title, "Amount", msg->titleLength); strlcpy(msg->title, "Amount", msg->titleLength);
@@ -806,11 +818,13 @@ void starkware_plugin_call(int message, void *parameters) {
case STARKWARE_WITHDRAW_TO: case STARKWARE_WITHDRAW_TO:
case STARKWARE_WITHDRAW_NFT_TO: case STARKWARE_WITHDRAW_NFT_TO:
strlcpy(msg->title, "To ETH Address", msg->titleLength); strlcpy(msg->title, "To ETH Address", msg->titleLength);
getEthDisplayableAddress(context->amount, if (!getEthDisplayableAddress(context->amount,
msg->msg, msg->msg,
msg->msgLength, msg->msgLength,
&global_sha3, &global_sha3,
chainConfig->chainId); chainConfig->chainId)) {
THROW(APDU_RESPONSE_ERROR_NO_INFO);
}
break; break;
case STARKWARE_WITHDRAW_AND_MINT: case STARKWARE_WITHDRAW_AND_MINT:
strlcpy(msg->title, "Asset Contract", msg->titleLength); strlcpy(msg->title, "Asset Contract", msg->titleLength);