Remove check for v length

This commit is contained in:
pscott
2021-08-06 15:20:58 +02:00
parent e2e567ed60
commit c5fb10dd47
6 changed files with 19 additions and 25 deletions

View File

@@ -54,9 +54,7 @@ int local_strchr(char *string, char ch) {
return -1;
}
// Almost like U4BE except that it takes `size` as a parameter.
// The `strict` parameter defines whether we should throw in case of a length > 4.
uint32_t u32_from_BE(uint8_t *in, uint8_t size, bool strict) {
uint32_t u32_from_BE(uint8_t *in, uint8_t size) {
switch (size) {
case 0:
return 0;
@@ -66,13 +64,7 @@ uint32_t u32_from_BE(uint8_t *in, uint8_t size, bool strict) {
return (in[0] << 8) | in[1];
case 3:
return (in[0] << 16) | (in[1] << 8) | in[2];
case 4:
return (in[0] << 24) | (in[1] << 16) | (in[2] << 8) | in[3];
default:
if (strict) {
PRINTF("Unexpected format\n");
THROW(EXCEPTION);
}
return (in[0] << 24) | (in[1] << 16) | (in[2] << 8) | in[3];
}
}

View File

@@ -28,9 +28,7 @@ void convertUint256BE(uint8_t* data, uint32_t length, uint256_t* target);
int local_strchr(char* string, char ch);
// Converts a list of bytes (in BE) of length `size` to a uint32_t. `strict` will make the function
// throw if the size is > 4.
uint32_t u32_from_BE(uint8_t* in, uint8_t size, bool strict);
uint32_t u32_from_BE(uint8_t* in, uint8_t size);
bool uint256_to_decimal(const uint8_t* value, size_t value_len, char* out, size_t out_len);

View File

@@ -24,7 +24,6 @@
#define MAX_INT256 32
#define MAX_ADDRESS 20
#define MAX_V 4
void initTx(txContext_t *context,
cx_sha3_t *sha3,
@@ -255,6 +254,10 @@ static void processTo(txContext_t *context) {
}
static void processData(txContext_t *context) {
PRINTF("DATA len: %d, DATA: %.*H\n",
context->currentFieldLength,
context->currentFieldLength,
context->workBuffer);
if (context->currentFieldIsList) {
PRINTF("Invalid type for RLP_DATA\n");
THROW(EXCEPTION);
@@ -275,6 +278,7 @@ static void processData(txContext_t *context) {
}
static void processAndDiscard(txContext_t *context) {
PRINTF("DISCARDING: %.*H\n", context->currentFieldLength, context->workBuffer);
if (context->currentFieldIsList) {
PRINTF("Invalid type for Discarded field\n");
THROW(EXCEPTION);
@@ -291,14 +295,14 @@ static void processAndDiscard(txContext_t *context) {
}
static void processV(txContext_t *context) {
PRINTF("current Length: %d\tBuff: %.*H\n",
context->currentFieldLength,
context->currentFieldLength,
context->workBuffer);
if (context->currentFieldIsList) {
PRINTF("Invalid type for RLP_V\n");
THROW(EXCEPTION);
}
if (context->currentFieldLength > MAX_V) {
PRINTF("Invalid length for RLP_V\n");
THROW(EXCEPTION);
}
if (context->currentFieldPos < context->currentFieldLength) {
uint32_t copySize =
MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos);

View File

@@ -26,13 +26,12 @@ uint32_t get_chain_id(void) {
switch (txContext.txType) {
case LEGACY:
chain_id = u32_from_BE(txContext.content->v, txContext.content->vLength, true);
chain_id = u32_from_BE(txContext.content->v, txContext.content->vLength);
break;
case EIP2930:
case EIP1559:
chain_id = u32_from_BE(tmpContent.txContent.chainID.value,
tmpContent.txContent.chainID.length,
true);
tmpContent.txContent.chainID.length);
break;
default:
PRINTF("Txtype `%d` not supported while generating chainID\n", txContext.txType);

View File

@@ -261,11 +261,10 @@ uint32_t get_chainID() {
uint32_t chain_id = 0;
if (txContext.txType == LEGACY) {
chain_id = u32_from_BE(txContext.content->v, txContext.content->vLength, true);
chain_id = u32_from_BE(txContext.content->v, txContext.content->vLength);
} else if (txContext.txType == EIP2930 || txContext.txType == EIP1559) {
chain_id = u32_from_BE(tmpContent.txContent.chainID.value,
tmpContent.txContent.chainID.length,
true);
chain_id =
u32_from_BE(tmpContent.txContent.chainID.value, tmpContent.txContent.chainID.length);
} else {
PRINTF("Txtype `%u` not supported while generating chainID\n", txContext.txType);
}

View File

@@ -7,7 +7,7 @@ unsigned int io_seproxyhal_touch_tx_ok(__attribute__((unused)) const bagl_elemen
uint8_t signature[100];
cx_ecfp_private_key_t privateKey;
uint32_t tx = 0;
uint32_t v = u32_from_BE(tmpContent.txContent.v, tmpContent.txContent.vLength, true);
uint32_t v = u32_from_BE(tmpContent.txContent.v, tmpContent.txContent.vLength);
io_seproxyhal_io_heartbeat();
os_perso_derive_node_bip32(CX_CURVE_256K1,
tmpCtx.transactionContext.bip32Path,
@@ -27,6 +27,8 @@ unsigned int io_seproxyhal_touch_tx_ok(__attribute__((unused)) const bagl_elemen
sizeof(signature),
&info);
explicit_bzero(&privateKey, sizeof(privateKey));
PRINTF("v: %.*H\n", tmpContent.txContent.vLength, tmpContent.txContent.v);
PRINTF("u32 v: %.*H\n", sizeof(v), &v);
if (txContext.txType == EIP1559 || txContext.txType == EIP2930) {
if (info & CX_ECCINFO_PARITY_ODD) {
G_io_apdu_buffer[0] = 1;