Files
app-ethereum/src_common/ethUstream.c

632 lines
21 KiB
C
Raw Normal View History

2016-06-01 21:41:29 +02:00
/*******************************************************************************
2020-12-01 16:20:13 +01:00
* Ledger Ethereum App
* (c) 2016-2019 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
2016-06-01 21:41:29 +02:00
#include <stdint.h>
2021-03-24 16:32:08 +01:00
#include <string.h>
2016-06-01 21:41:29 +02:00
#include "ethUstream.h"
#include "ethUtils.h"
#include "utils.h"
2016-06-01 21:41:29 +02:00
2020-12-01 16:20:13 +01:00
#define MAX_INT256 32
2016-06-01 21:41:29 +02:00
#define MAX_ADDRESS 20
2020-12-01 16:20:13 +01:00
void initTx(txContext_t *context,
cx_sha3_t *sha3,
txContent_t *content,
ustreamProcess_t customProcessor,
void *extra) {
2020-11-24 10:23:45 +01:00
memset(context, 0, sizeof(txContext_t));
2016-06-01 21:41:29 +02:00
context->sha3 = sha3;
context->content = content;
context->customProcessor = customProcessor;
context->extra = extra;
context->currentField = RLP_NONE + 1;
cx_keccak_init(context->sha3, 256);
2016-06-01 21:41:29 +02:00
}
uint8_t readTxByte(txContext_t *context) {
uint8_t data;
if (context->commandLength < 1) {
2017-01-22 18:25:42 +01:00
PRINTF("readTxByte Underflow\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
data = *context->workBuffer;
context->workBuffer++;
context->commandLength--;
if (context->processingField) {
context->currentFieldPos++;
}
if (!(context->processingField && context->fieldSingleByte)) {
2020-12-01 16:20:13 +01:00
cx_hash((cx_hash_t *) context->sha3, 0, &data, 1, NULL, 0);
2016-06-01 21:41:29 +02:00
}
return data;
}
void copyTxData(txContext_t *context, uint8_t *out, uint32_t length) {
if (context->commandLength < length) {
2017-01-22 18:25:42 +01:00
PRINTF("copyTxData Underflow\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
if (out != NULL) {
2020-11-24 10:23:45 +01:00
memmove(out, context->workBuffer, length);
2016-06-01 21:41:29 +02:00
}
if (!(context->processingField && context->fieldSingleByte)) {
2020-12-01 16:20:13 +01:00
cx_hash((cx_hash_t *) context->sha3, 0, context->workBuffer, length, NULL, 0);
2016-06-01 21:41:29 +02:00
}
context->workBuffer += length;
context->commandLength -= length;
if (context->processingField) {
context->currentFieldPos += length;
}
}
static void processContent(txContext_t *context) {
// Keep the full length for sanity checks, move to the next field
if (!context->currentFieldIsList) {
2017-01-22 18:25:42 +01:00
PRINTF("Invalid type for RLP_CONTENT\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
context->dataLength = context->currentFieldLength;
context->currentField++;
context->processingField = false;
}
static void processAccessList(txContext_t *context) {
if (!context->currentFieldIsList) {
PRINTF("Invalid type for RLP_ACCESS_LIST\n");
THROW(EXCEPTION);
}
if (context->currentFieldPos < context->currentFieldLength) {
uint32_t copySize =
MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos);
copyTxData(context, NULL, copySize);
}
if (context->currentFieldPos == context->currentFieldLength) {
context->currentField++;
context->processingField = false;
}
}
2018-07-27 21:02:24 +02:00
static void processType(txContext_t *context) {
if (context->currentFieldIsList) {
PRINTF("Invalid type for RLP_TYPE\n");
THROW(EXCEPTION);
}
if (context->currentFieldLength > MAX_INT256) {
PRINTF("Invalid length for RLP_TYPE\n");
THROW(EXCEPTION);
}
if (context->currentFieldPos < context->currentFieldLength) {
2020-12-01 16:20:13 +01:00
uint32_t copySize =
MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos);
2018-07-27 21:02:24 +02:00
copyTxData(context, NULL, copySize);
}
if (context->currentFieldPos == context->currentFieldLength) {
context->currentField++;
context->processingField = false;
}
}
static void processChainID(txContext_t *context) {
if (context->currentFieldIsList) {
PRINTF("Invalid type for RLP_CHAINID\n");
THROW(EXCEPTION);
}
if (context->currentFieldLength > MAX_INT256) {
PRINTF("Invalid length for RLP_CHAINID\n");
THROW(EXCEPTION);
}
if (context->currentFieldPos < context->currentFieldLength) {
uint32_t copySize =
MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos);
copyTxData(context, context->content->chainID.value, copySize);
}
if (context->currentFieldPos == context->currentFieldLength) {
context->content->chainID.length = context->currentFieldLength;
context->currentField++;
context->processingField = false;
}
}
2016-06-01 21:41:29 +02:00
static void processNonce(txContext_t *context) {
if (context->currentFieldIsList) {
2017-01-22 18:25:42 +01:00
PRINTF("Invalid type for RLP_NONCE\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
if (context->currentFieldLength > MAX_INT256) {
2017-01-22 18:25:42 +01:00
PRINTF("Invalid length for RLP_NONCE\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
if (context->currentFieldPos < context->currentFieldLength) {
2020-12-01 16:20:13 +01:00
uint32_t copySize =
MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos);
copyTxData(context, context->content->nonce.value, copySize);
2016-06-01 21:41:29 +02:00
}
if (context->currentFieldPos == context->currentFieldLength) {
context->content->nonce.length = context->currentFieldLength;
2016-06-01 21:41:29 +02:00
context->currentField++;
context->processingField = false;
}
}
static void processStartGas(txContext_t *context) {
if (context->currentFieldIsList) {
2017-01-22 18:25:42 +01:00
PRINTF("Invalid type for RLP_STARTGAS\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
if (context->currentFieldLength > MAX_INT256) {
2020-12-01 16:20:13 +01:00
PRINTF("Invalid length for RLP_STARTGAS %d\n", context->currentFieldLength);
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
if (context->currentFieldPos < context->currentFieldLength) {
2020-12-01 16:20:13 +01:00
uint32_t copySize =
MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos);
copyTxData(context, context->content->startgas.value + context->currentFieldPos, copySize);
2016-06-01 21:41:29 +02:00
}
if (context->currentFieldPos == context->currentFieldLength) {
context->content->startgas.length = context->currentFieldLength;
context->currentField++;
context->processingField = false;
}
}
// Alias over `processStartGas()`.
static void processGasLimit(txContext_t *context) {
processStartGas(context);
}
2016-06-01 21:41:29 +02:00
static void processGasprice(txContext_t *context) {
if (context->currentFieldIsList) {
2017-01-22 18:25:42 +01:00
PRINTF("Invalid type for RLP_GASPRICE\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
if (context->currentFieldLength > MAX_INT256) {
2017-01-22 18:25:42 +01:00
PRINTF("Invalid length for RLP_GASPRICE\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
if (context->currentFieldPos < context->currentFieldLength) {
2020-12-01 16:20:13 +01:00
uint32_t copySize =
MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos);
copyTxData(context, context->content->gasprice.value + context->currentFieldPos, copySize);
2016-06-01 21:41:29 +02:00
}
if (context->currentFieldPos == context->currentFieldLength) {
context->content->gasprice.length = context->currentFieldLength;
context->currentField++;
context->processingField = false;
}
}
static void processValue(txContext_t *context) {
if (context->currentFieldIsList) {
2017-01-22 18:25:42 +01:00
PRINTF("Invalid type for RLP_VALUE\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
if (context->currentFieldLength > MAX_INT256) {
2017-01-22 18:25:42 +01:00
PRINTF("Invalid length for RLP_VALUE\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
if (context->currentFieldPos < context->currentFieldLength) {
2020-12-01 16:20:13 +01:00
uint32_t copySize =
MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos);
copyTxData(context, context->content->value.value + context->currentFieldPos, copySize);
2016-06-01 21:41:29 +02:00
}
if (context->currentFieldPos == context->currentFieldLength) {
context->content->value.length = context->currentFieldLength;
context->currentField++;
context->processingField = false;
}
}
static void processTo(txContext_t *context) {
2016-06-01 21:41:29 +02:00
if (context->currentFieldIsList) {
2017-01-22 18:25:42 +01:00
PRINTF("Invalid type for RLP_TO\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
if (context->currentFieldLength > MAX_ADDRESS) {
2017-01-22 18:25:42 +01:00
PRINTF("Invalid length for RLP_TO\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
2016-06-01 21:41:29 +02:00
if (context->currentFieldPos < context->currentFieldLength) {
2020-12-01 16:20:13 +01:00
uint32_t copySize =
MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos);
copyTxData(context, context->content->destination + context->currentFieldPos, copySize);
2016-06-01 21:41:29 +02:00
}
if (context->currentFieldPos == context->currentFieldLength) {
context->content->destinationLength = context->currentFieldLength;
2016-06-01 21:41:29 +02:00
context->currentField++;
context->processingField = false;
}
}
static void processData(txContext_t *context) {
Add support for ERC-721 and ERC-1155 (v3) (#218) * First draft for erc721 token allowance * Split ui and provide parameters into their own files * Print txtype when not supported * fix compilation for erc721 * Use pluginType * Add debug statement in compound plugin * add debug error msg in plugin error * Add parameter parsing for all methods * Remove debug logs * Add SET_APPROVAL_FOR_ALL; Add correct parsing method on contract init * Add dst_size parameter to copy functions * Add query contract id code * format * Add UIs * update ethapp.asc * Change setExternalPlugin to setPlugin; Add support for ERC721 * clang-format * Fix typo Unconsistent -> Inconsistent * Add support for 721; use extraInfo * Add extraInfo to ethpluginQueryConractUI * Rename extraInfo to item * Add txFromEtherscan to tests * Add nft key and temp padding * Remove comments around HAVE_BYPASS_SIGNATURES * Rename TESTING_KEY to NFT_TESTING_KEY * Add comments regarding value of queryContractUI->item * Fix comment regarding method selector * Rename provideToken to provideInfo; Update plugin doc * fix caps of eth_plugin_prepare_provide_info * fix caps of handle_provide_info * Use verificationFn insead of hardcoded cx_ecdsa_verify * Add comments about nftInfo_t and tokenDefinition_t * Add erc721 test * Remove comment from plugin interface version * Fix network_ticker duplicate * Add setPlugin and provideNFTInfo to doc.asc * Add back setExternalPlugin; implement new setPlugin * Update plugin sdk * Call setPlugin instead of setExternalPlugin * setPlugin work without checking sig * Remove printf of displayed fees * Add working 721 test * Finalize ERC721 and add simple test * Display NFT address on set approval and operator * Support set approval for all for erc721 * Finish UI for set approval for all erc721 * Move copy_parameter and copy_address to eth_plugin_internal; Add tests for erc721 * update plugin sdk * Add erc1155 plugin and 1155 tests placeholder * Add restriction for AWS key and setPlugin * Add NOT_OLD_INTERNAL variant; Add erc_1155_plugin_call * Fixed compilation warnings (function pointer casting) Co-authored-by: pscott <scott.piriou@ledger.fr>
2021-11-22 14:39:36 +01:00
PRINTF("PROCESS DATA\n");
2016-06-01 21:41:29 +02:00
if (context->currentFieldIsList) {
2017-01-22 18:25:42 +01:00
PRINTF("Invalid type for RLP_DATA\n");
2016-06-01 21:41:29 +02:00
THROW(EXCEPTION);
}
2021-06-11 11:37:16 +02:00
if (context->currentFieldPos < context->currentFieldLength) {
uint32_t copySize =
MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos);
// If there is no data, set dataPresent to false.
if (copySize == 1 && *context->workBuffer == 0x00) {
context->content->dataPresent = false;
}
copyTxData(context, NULL, copySize);
}
if (context->currentFieldPos == context->currentFieldLength) {
Add support for ERC-721 and ERC-1155 (v3) (#218) * First draft for erc721 token allowance * Split ui and provide parameters into their own files * Print txtype when not supported * fix compilation for erc721 * Use pluginType * Add debug statement in compound plugin * add debug error msg in plugin error * Add parameter parsing for all methods * Remove debug logs * Add SET_APPROVAL_FOR_ALL; Add correct parsing method on contract init * Add dst_size parameter to copy functions * Add query contract id code * format * Add UIs * update ethapp.asc * Change setExternalPlugin to setPlugin; Add support for ERC721 * clang-format * Fix typo Unconsistent -> Inconsistent * Add support for 721; use extraInfo * Add extraInfo to ethpluginQueryConractUI * Rename extraInfo to item * Add txFromEtherscan to tests * Add nft key and temp padding * Remove comments around HAVE_BYPASS_SIGNATURES * Rename TESTING_KEY to NFT_TESTING_KEY * Add comments regarding value of queryContractUI->item * Fix comment regarding method selector * Rename provideToken to provideInfo; Update plugin doc * fix caps of eth_plugin_prepare_provide_info * fix caps of handle_provide_info * Use verificationFn insead of hardcoded cx_ecdsa_verify * Add comments about nftInfo_t and tokenDefinition_t * Add erc721 test * Remove comment from plugin interface version * Fix network_ticker duplicate * Add setPlugin and provideNFTInfo to doc.asc * Add back setExternalPlugin; implement new setPlugin * Update plugin sdk * Call setPlugin instead of setExternalPlugin * setPlugin work without checking sig * Remove printf of displayed fees * Add working 721 test * Finalize ERC721 and add simple test * Display NFT address on set approval and operator * Support set approval for all for erc721 * Finish UI for set approval for all erc721 * Move copy_parameter and copy_address to eth_plugin_internal; Add tests for erc721 * update plugin sdk * Add erc1155 plugin and 1155 tests placeholder * Add restriction for AWS key and setPlugin * Add NOT_OLD_INTERNAL variant; Add erc_1155_plugin_call * Fixed compilation warnings (function pointer casting) Co-authored-by: pscott <scott.piriou@ledger.fr>
2021-11-22 14:39:36 +01:00
PRINTF("incrementing field\n");
2021-06-11 11:37:16 +02:00
context->currentField++;
context->processingField = false;
}
}
static void processAndDiscard(txContext_t *context) {
if (context->currentFieldIsList) {
PRINTF("Invalid type for Discarded field\n");
THROW(EXCEPTION);
}
2016-06-01 21:41:29 +02:00
if (context->currentFieldPos < context->currentFieldLength) {
2020-12-01 16:20:13 +01:00
uint32_t copySize =
MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos);
2016-06-01 21:41:29 +02:00
copyTxData(context, NULL, copySize);
}
if (context->currentFieldPos == context->currentFieldLength) {
context->currentField++;
context->processingField = false;
}
}
static void processV(txContext_t *context) {
if (context->currentFieldIsList) {
2017-01-22 18:25:42 +01:00
PRINTF("Invalid type for RLP_V\n");
THROW(EXCEPTION);
}
2022-07-08 11:12:50 +02:00
if (context->currentFieldLength > sizeof(context->content->v)) {
PRINTF("Invalid length for RLP_V\n");
THROW(EXCEPTION);
}
if (context->currentFieldPos < context->currentFieldLength) {
2020-12-01 16:20:13 +01:00
uint32_t copySize =
MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos);
// Make sure we do not copy more than the size of v.
copySize = MIN(copySize, sizeof(context->content->v));
2020-12-01 16:20:13 +01:00
copyTxData(context, context->content->v + context->currentFieldPos, copySize);
}
if (context->currentFieldPos == context->currentFieldLength) {
context->content->vLength = context->currentFieldLength;
context->currentField++;
context->processingField = false;
}
}
static bool processEIP1559Tx(txContext_t *context) {
switch (context->currentField) {
case EIP1559_RLP_CONTENT: {
processContent(context);
if ((context->processingFlags & TX_FLAG_TYPE) == 0) {
2021-06-10 17:36:01 +02:00
context->currentField++;
}
break;
}
2021-06-10 17:36:01 +02:00
// This gets hit only by Wanchain
case EIP1559_RLP_TYPE: {
processType(context);
break;
}
case EIP1559_RLP_CHAINID: {
processChainID(context);
break;
}
case EIP1559_RLP_NONCE: {
processNonce(context);
break;
}
case EIP1559_RLP_MAX_FEE_PER_GAS: {
processGasprice(context);
break;
}
case EIP1559_RLP_GASLIMIT: {
processGasLimit(context);
break;
}
case EIP1559_RLP_TO: {
processTo(context);
break;
}
case EIP1559_RLP_VALUE: {
processValue(context);
break;
}
case EIP1559_RLP_DATA: {
processData(context);
break;
}
case EIP1559_RLP_ACCESS_LIST: {
processAccessList(context);
break;
}
2021-06-24 18:46:18 +02:00
case EIP1559_RLP_MAX_PRIORITY_FEE_PER_GAS:
2021-06-11 11:37:16 +02:00
processAndDiscard(context);
break;
default:
PRINTF("Invalid RLP decoder context\n");
return true;
}
return false;
}
static bool processEIP2930Tx(txContext_t *context) {
switch (context->currentField) {
case EIP2930_RLP_CONTENT:
processContent(context);
if ((context->processingFlags & TX_FLAG_TYPE) == 0) {
context->currentField++;
}
break;
2021-06-10 17:36:01 +02:00
// This gets hit only by Wanchain
case EIP2930_RLP_TYPE:
processType(context);
break;
case EIP2930_RLP_CHAINID:
processChainID(context);
break;
case EIP2930_RLP_NONCE:
processNonce(context);
break;
case EIP2930_RLP_GASPRICE:
processGasprice(context);
break;
case EIP2930_RLP_GASLIMIT:
processGasLimit(context);
break;
case EIP2930_RLP_TO:
processTo(context);
break;
case EIP2930_RLP_VALUE:
processValue(context);
break;
2021-06-11 11:37:16 +02:00
case EIP2930_RLP_DATA:
processData(context);
break;
case EIP2930_RLP_ACCESS_LIST:
processAccessList(context);
break;
default:
PRINTF("Invalid RLP decoder context\n");
return true;
}
return false;
}
static bool processLegacyTx(txContext_t *context) {
switch (context->currentField) {
case LEGACY_RLP_CONTENT:
processContent(context);
if ((context->processingFlags & TX_FLAG_TYPE) == 0) {
context->currentField++;
}
break;
2021-06-10 17:36:01 +02:00
// This gets hit only by Wanchain
case LEGACY_RLP_TYPE:
processType(context);
break;
case LEGACY_RLP_NONCE:
processNonce(context);
break;
case LEGACY_RLP_GASPRICE:
processGasprice(context);
break;
case LEGACY_RLP_STARTGAS:
processStartGas(context);
break;
case LEGACY_RLP_TO:
processTo(context);
break;
case LEGACY_RLP_VALUE:
processValue(context);
break;
case LEGACY_RLP_DATA:
2021-06-11 11:37:16 +02:00
processData(context);
break;
case LEGACY_RLP_R:
case LEGACY_RLP_S:
2021-06-11 11:37:16 +02:00
processAndDiscard(context);
break;
case LEGACY_RLP_V:
processV(context);
break;
default:
PRINTF("Invalid RLP decoder context\n");
return true;
}
return false;
}
static parserStatus_e parseRLP(txContext_t *context) {
bool canDecode = false;
uint32_t offset;
while (context->commandLength != 0) {
bool valid;
// Feed the RLP buffer until the length can be decoded
context->rlpBuffer[context->rlpBufferPos++] = readTxByte(context);
if (rlpCanDecode(context->rlpBuffer, context->rlpBufferPos, &valid)) {
// Can decode now, if valid
if (!valid) {
PRINTF("RLP pre-decode error\n");
return USTREAM_FAULT;
}
canDecode = true;
break;
}
// Cannot decode yet
// Sanity check
if (context->rlpBufferPos == sizeof(context->rlpBuffer)) {
PRINTF("RLP pre-decode logic error\n");
return USTREAM_FAULT;
}
}
if (!canDecode) {
PRINTF("Can't decode\n");
return USTREAM_PROCESSING;
}
// Ready to process this field
if (!rlpDecodeLength(context->rlpBuffer,
&context->currentFieldLength,
&offset,
&context->currentFieldIsList)) {
PRINTF("RLP decode error\n");
return USTREAM_FAULT;
}
// Ready to process this field
if (offset == 0) {
// Hack for single byte, self encoded
context->workBuffer--;
context->commandLength++;
context->fieldSingleByte = true;
} else {
context->fieldSingleByte = false;
}
context->currentFieldPos = 0;
context->rlpBufferPos = 0;
context->processingField = true;
return USTREAM_CONTINUE;
}
2018-07-31 19:59:59 +02:00
static parserStatus_e processTxInternal(txContext_t *context) {
2016-06-01 21:41:29 +02:00
for (;;) {
2018-07-31 19:59:59 +02:00
customStatus_e customStatus = CUSTOM_NOT_HANDLED;
// EIP 155 style transaction
2021-04-21 17:15:43 +02:00
if (PARSING_IS_DONE(context)) {
Add support for ERC-721 and ERC-1155 (v3) (#218) * First draft for erc721 token allowance * Split ui and provide parameters into their own files * Print txtype when not supported * fix compilation for erc721 * Use pluginType * Add debug statement in compound plugin * add debug error msg in plugin error * Add parameter parsing for all methods * Remove debug logs * Add SET_APPROVAL_FOR_ALL; Add correct parsing method on contract init * Add dst_size parameter to copy functions * Add query contract id code * format * Add UIs * update ethapp.asc * Change setExternalPlugin to setPlugin; Add support for ERC721 * clang-format * Fix typo Unconsistent -> Inconsistent * Add support for 721; use extraInfo * Add extraInfo to ethpluginQueryConractUI * Rename extraInfo to item * Add txFromEtherscan to tests * Add nft key and temp padding * Remove comments around HAVE_BYPASS_SIGNATURES * Rename TESTING_KEY to NFT_TESTING_KEY * Add comments regarding value of queryContractUI->item * Fix comment regarding method selector * Rename provideToken to provideInfo; Update plugin doc * fix caps of eth_plugin_prepare_provide_info * fix caps of handle_provide_info * Use verificationFn insead of hardcoded cx_ecdsa_verify * Add comments about nftInfo_t and tokenDefinition_t * Add erc721 test * Remove comment from plugin interface version * Fix network_ticker duplicate * Add setPlugin and provideNFTInfo to doc.asc * Add back setExternalPlugin; implement new setPlugin * Update plugin sdk * Call setPlugin instead of setExternalPlugin * setPlugin work without checking sig * Remove printf of displayed fees * Add working 721 test * Finalize ERC721 and add simple test * Display NFT address on set approval and operator * Support set approval for all for erc721 * Finish UI for set approval for all erc721 * Move copy_parameter and copy_address to eth_plugin_internal; Add tests for erc721 * update plugin sdk * Add erc1155 plugin and 1155 tests placeholder * Add restriction for AWS key and setPlugin * Add NOT_OLD_INTERNAL variant; Add erc_1155_plugin_call * Fixed compilation warnings (function pointer casting) Co-authored-by: pscott <scott.piriou@ledger.fr>
2021-11-22 14:39:36 +01:00
PRINTF("parsing is done\n");
2016-06-01 21:41:29 +02:00
return USTREAM_FINISHED;
}
2021-06-29 16:07:28 +02:00
// Old style transaction (pre EIP-155). Transations could just skip `v,r,s` so we needed to
// cut parsing here. commandLength == 0 could happen in two cases :
2021-06-10 17:36:01 +02:00
// 1. We are in an old style transaction : just return `USTREAM_FINISHED`.
2021-06-29 16:07:28 +02:00
// 2. We are at the end of an APDU in a multi-apdu process. This would make us return
// `USTREAM_FINISHED` preemptively. Case number 2 should NOT happen as it is up to
// `ledgerjs` to correctly decrease the size of the APDU (`commandLength`) so that this
// situation doesn't happen.
2021-06-10 17:36:01 +02:00
if ((context->txType == LEGACY && context->currentField == LEGACY_RLP_V) &&
(context->commandLength == 0)) {
context->content->vLength = 0;
Add support for ERC-721 and ERC-1155 (v3) (#218) * First draft for erc721 token allowance * Split ui and provide parameters into their own files * Print txtype when not supported * fix compilation for erc721 * Use pluginType * Add debug statement in compound plugin * add debug error msg in plugin error * Add parameter parsing for all methods * Remove debug logs * Add SET_APPROVAL_FOR_ALL; Add correct parsing method on contract init * Add dst_size parameter to copy functions * Add query contract id code * format * Add UIs * update ethapp.asc * Change setExternalPlugin to setPlugin; Add support for ERC721 * clang-format * Fix typo Unconsistent -> Inconsistent * Add support for 721; use extraInfo * Add extraInfo to ethpluginQueryConractUI * Rename extraInfo to item * Add txFromEtherscan to tests * Add nft key and temp padding * Remove comments around HAVE_BYPASS_SIGNATURES * Rename TESTING_KEY to NFT_TESTING_KEY * Add comments regarding value of queryContractUI->item * Fix comment regarding method selector * Rename provideToken to provideInfo; Update plugin doc * fix caps of eth_plugin_prepare_provide_info * fix caps of handle_provide_info * Use verificationFn insead of hardcoded cx_ecdsa_verify * Add comments about nftInfo_t and tokenDefinition_t * Add erc721 test * Remove comment from plugin interface version * Fix network_ticker duplicate * Add setPlugin and provideNFTInfo to doc.asc * Add back setExternalPlugin; implement new setPlugin * Update plugin sdk * Call setPlugin instead of setExternalPlugin * setPlugin work without checking sig * Remove printf of displayed fees * Add working 721 test * Finalize ERC721 and add simple test * Display NFT address on set approval and operator * Support set approval for all for erc721 * Finish UI for set approval for all erc721 * Move copy_parameter and copy_address to eth_plugin_internal; Add tests for erc721 * update plugin sdk * Add erc1155 plugin and 1155 tests placeholder * Add restriction for AWS key and setPlugin * Add NOT_OLD_INTERNAL variant; Add erc_1155_plugin_call * Fixed compilation warnings (function pointer casting) Co-authored-by: pscott <scott.piriou@ledger.fr>
2021-11-22 14:39:36 +01:00
PRINTF("finished\n");
return USTREAM_FINISHED;
}
2016-06-01 21:41:29 +02:00
if (context->commandLength == 0) {
Add support for ERC-721 and ERC-1155 (v3) (#218) * First draft for erc721 token allowance * Split ui and provide parameters into their own files * Print txtype when not supported * fix compilation for erc721 * Use pluginType * Add debug statement in compound plugin * add debug error msg in plugin error * Add parameter parsing for all methods * Remove debug logs * Add SET_APPROVAL_FOR_ALL; Add correct parsing method on contract init * Add dst_size parameter to copy functions * Add query contract id code * format * Add UIs * update ethapp.asc * Change setExternalPlugin to setPlugin; Add support for ERC721 * clang-format * Fix typo Unconsistent -> Inconsistent * Add support for 721; use extraInfo * Add extraInfo to ethpluginQueryConractUI * Rename extraInfo to item * Add txFromEtherscan to tests * Add nft key and temp padding * Remove comments around HAVE_BYPASS_SIGNATURES * Rename TESTING_KEY to NFT_TESTING_KEY * Add comments regarding value of queryContractUI->item * Fix comment regarding method selector * Rename provideToken to provideInfo; Update plugin doc * fix caps of eth_plugin_prepare_provide_info * fix caps of handle_provide_info * Use verificationFn insead of hardcoded cx_ecdsa_verify * Add comments about nftInfo_t and tokenDefinition_t * Add erc721 test * Remove comment from plugin interface version * Fix network_ticker duplicate * Add setPlugin and provideNFTInfo to doc.asc * Add back setExternalPlugin; implement new setPlugin * Update plugin sdk * Call setPlugin instead of setExternalPlugin * setPlugin work without checking sig * Remove printf of displayed fees * Add working 721 test * Finalize ERC721 and add simple test * Display NFT address on set approval and operator * Support set approval for all for erc721 * Finish UI for set approval for all erc721 * Move copy_parameter and copy_address to eth_plugin_internal; Add tests for erc721 * update plugin sdk * Add erc1155 plugin and 1155 tests placeholder * Add restriction for AWS key and setPlugin * Add NOT_OLD_INTERNAL variant; Add erc_1155_plugin_call * Fixed compilation warnings (function pointer casting) Co-authored-by: pscott <scott.piriou@ledger.fr>
2021-11-22 14:39:36 +01:00
PRINTF("Command length done\n");
2016-06-01 21:41:29 +02:00
return USTREAM_PROCESSING;
}
if (!context->processingField) {
parserStatus_e status = parseRLP(context);
if (status != USTREAM_CONTINUE) {
return status;
2016-06-01 21:41:29 +02:00
}
}
if (context->customProcessor != NULL) {
2018-07-31 19:59:59 +02:00
customStatus = context->customProcessor(context);
Add support for ERC-721 and ERC-1155 (v3) (#218) * First draft for erc721 token allowance * Split ui and provide parameters into their own files * Print txtype when not supported * fix compilation for erc721 * Use pluginType * Add debug statement in compound plugin * add debug error msg in plugin error * Add parameter parsing for all methods * Remove debug logs * Add SET_APPROVAL_FOR_ALL; Add correct parsing method on contract init * Add dst_size parameter to copy functions * Add query contract id code * format * Add UIs * update ethapp.asc * Change setExternalPlugin to setPlugin; Add support for ERC721 * clang-format * Fix typo Unconsistent -> Inconsistent * Add support for 721; use extraInfo * Add extraInfo to ethpluginQueryConractUI * Rename extraInfo to item * Add txFromEtherscan to tests * Add nft key and temp padding * Remove comments around HAVE_BYPASS_SIGNATURES * Rename TESTING_KEY to NFT_TESTING_KEY * Add comments regarding value of queryContractUI->item * Fix comment regarding method selector * Rename provideToken to provideInfo; Update plugin doc * fix caps of eth_plugin_prepare_provide_info * fix caps of handle_provide_info * Use verificationFn insead of hardcoded cx_ecdsa_verify * Add comments about nftInfo_t and tokenDefinition_t * Add erc721 test * Remove comment from plugin interface version * Fix network_ticker duplicate * Add setPlugin and provideNFTInfo to doc.asc * Add back setExternalPlugin; implement new setPlugin * Update plugin sdk * Call setPlugin instead of setExternalPlugin * setPlugin work without checking sig * Remove printf of displayed fees * Add working 721 test * Finalize ERC721 and add simple test * Display NFT address on set approval and operator * Support set approval for all for erc721 * Finish UI for set approval for all erc721 * Move copy_parameter and copy_address to eth_plugin_internal; Add tests for erc721 * update plugin sdk * Add erc1155 plugin and 1155 tests placeholder * Add restriction for AWS key and setPlugin * Add NOT_OLD_INTERNAL variant; Add erc_1155_plugin_call * Fixed compilation warnings (function pointer casting) Co-authored-by: pscott <scott.piriou@ledger.fr>
2021-11-22 14:39:36 +01:00
PRINTF("After customprocessor\n");
2020-12-01 16:20:13 +01:00
switch (customStatus) {
2018-07-31 19:59:59 +02:00
case CUSTOM_NOT_HANDLED:
case CUSTOM_HANDLED:
break;
case CUSTOM_SUSPENDED:
return USTREAM_SUSPENDED;
case CUSTOM_FAULT:
PRINTF("Custom processor aborted\n");
return USTREAM_FAULT;
2018-07-31 19:59:59 +02:00
default:
PRINTF("Unhandled custom processor status\n");
return USTREAM_FAULT;
}
2016-06-01 21:41:29 +02:00
}
2018-07-31 19:59:59 +02:00
if (customStatus == CUSTOM_NOT_HANDLED) {
PRINTF("Current field: %d\n", context->currentField);
switch (context->txType) {
bool fault;
case LEGACY:
fault = processLegacyTx(context);
if (fault) {
return USTREAM_FAULT;
} else {
break;
}
case EIP2930:
fault = processEIP2930Tx(context);
if (fault) {
return USTREAM_FAULT;
} else {
break;
2020-12-01 16:20:13 +01:00
}
case EIP1559:
fault = processEIP1559Tx(context);
if (fault) {
return USTREAM_FAULT;
} else {
break;
}
2020-12-01 16:20:13 +01:00
default:
Add support for ERC-721 and ERC-1155 (v3) (#218) * First draft for erc721 token allowance * Split ui and provide parameters into their own files * Print txtype when not supported * fix compilation for erc721 * Use pluginType * Add debug statement in compound plugin * add debug error msg in plugin error * Add parameter parsing for all methods * Remove debug logs * Add SET_APPROVAL_FOR_ALL; Add correct parsing method on contract init * Add dst_size parameter to copy functions * Add query contract id code * format * Add UIs * update ethapp.asc * Change setExternalPlugin to setPlugin; Add support for ERC721 * clang-format * Fix typo Unconsistent -> Inconsistent * Add support for 721; use extraInfo * Add extraInfo to ethpluginQueryConractUI * Rename extraInfo to item * Add txFromEtherscan to tests * Add nft key and temp padding * Remove comments around HAVE_BYPASS_SIGNATURES * Rename TESTING_KEY to NFT_TESTING_KEY * Add comments regarding value of queryContractUI->item * Fix comment regarding method selector * Rename provideToken to provideInfo; Update plugin doc * fix caps of eth_plugin_prepare_provide_info * fix caps of handle_provide_info * Use verificationFn insead of hardcoded cx_ecdsa_verify * Add comments about nftInfo_t and tokenDefinition_t * Add erc721 test * Remove comment from plugin interface version * Fix network_ticker duplicate * Add setPlugin and provideNFTInfo to doc.asc * Add back setExternalPlugin; implement new setPlugin * Update plugin sdk * Call setPlugin instead of setExternalPlugin * setPlugin work without checking sig * Remove printf of displayed fees * Add working 721 test * Finalize ERC721 and add simple test * Display NFT address on set approval and operator * Support set approval for all for erc721 * Finish UI for set approval for all erc721 * Move copy_parameter and copy_address to eth_plugin_internal; Add tests for erc721 * update plugin sdk * Add erc1155 plugin and 1155 tests placeholder * Add restriction for AWS key and setPlugin * Add NOT_OLD_INTERNAL variant; Add erc_1155_plugin_call * Fixed compilation warnings (function pointer casting) Co-authored-by: pscott <scott.piriou@ledger.fr>
2021-11-22 14:39:36 +01:00
PRINTF("Transaction type %d is not supported\n", context->txType);
2020-12-01 16:20:13 +01:00
return USTREAM_FAULT;
2016-06-01 21:41:29 +02:00
}
}
}
Add support for ERC-721 and ERC-1155 (v3) (#218) * First draft for erc721 token allowance * Split ui and provide parameters into their own files * Print txtype when not supported * fix compilation for erc721 * Use pluginType * Add debug statement in compound plugin * add debug error msg in plugin error * Add parameter parsing for all methods * Remove debug logs * Add SET_APPROVAL_FOR_ALL; Add correct parsing method on contract init * Add dst_size parameter to copy functions * Add query contract id code * format * Add UIs * update ethapp.asc * Change setExternalPlugin to setPlugin; Add support for ERC721 * clang-format * Fix typo Unconsistent -> Inconsistent * Add support for 721; use extraInfo * Add extraInfo to ethpluginQueryConractUI * Rename extraInfo to item * Add txFromEtherscan to tests * Add nft key and temp padding * Remove comments around HAVE_BYPASS_SIGNATURES * Rename TESTING_KEY to NFT_TESTING_KEY * Add comments regarding value of queryContractUI->item * Fix comment regarding method selector * Rename provideToken to provideInfo; Update plugin doc * fix caps of eth_plugin_prepare_provide_info * fix caps of handle_provide_info * Use verificationFn insead of hardcoded cx_ecdsa_verify * Add comments about nftInfo_t and tokenDefinition_t * Add erc721 test * Remove comment from plugin interface version * Fix network_ticker duplicate * Add setPlugin and provideNFTInfo to doc.asc * Add back setExternalPlugin; implement new setPlugin * Update plugin sdk * Call setPlugin instead of setExternalPlugin * setPlugin work without checking sig * Remove printf of displayed fees * Add working 721 test * Finalize ERC721 and add simple test * Display NFT address on set approval and operator * Support set approval for all for erc721 * Finish UI for set approval for all erc721 * Move copy_parameter and copy_address to eth_plugin_internal; Add tests for erc721 * update plugin sdk * Add erc1155 plugin and 1155 tests placeholder * Add restriction for AWS key and setPlugin * Add NOT_OLD_INTERNAL variant; Add erc_1155_plugin_call * Fixed compilation warnings (function pointer casting) Co-authored-by: pscott <scott.piriou@ledger.fr>
2021-11-22 14:39:36 +01:00
PRINTF("end of here\n");
2016-06-01 21:41:29 +02:00
}
2020-12-01 16:20:13 +01:00
parserStatus_e processTx(txContext_t *context,
const uint8_t *buffer,
2020-12-01 16:20:13 +01:00
uint32_t length,
uint32_t processingFlags) {
2016-06-01 21:41:29 +02:00
parserStatus_e result;
BEGIN_TRY {
TRY {
context->workBuffer = buffer;
context->commandLength = length;
2018-07-31 19:59:59 +02:00
context->processingFlags = processingFlags;
result = processTxInternal(context);
PRINTF("result: %d\n", result);
2016-06-01 21:41:29 +02:00
}
CATCH_OTHER(e) {
result = USTREAM_FAULT;
}
FINALLY {
}
}
END_TRY;
return result;
}
2018-07-31 19:59:59 +02:00
parserStatus_e continueTx(txContext_t *context) {
parserStatus_e result;
BEGIN_TRY {
TRY {
result = processTxInternal(context);
}
CATCH_OTHER(e) {
result = USTREAM_FAULT;
}
FINALLY {
}
}
END_TRY;
return result;
2018-07-31 19:59:59 +02:00
}