Use INT256_LENGTH and ADDRESS_LENGTH define
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
|
||||
#define WEI_TO_ETHER 18
|
||||
|
||||
#define SELECTOR_LENGTH 4
|
||||
|
||||
#define N_storage (*(volatile internalStorage_t *) PIC(&N_storage_real))
|
||||
|
||||
typedef struct internalStorage_t {
|
||||
@@ -50,7 +52,7 @@ typedef struct tokenContext_t {
|
||||
char pluginName[PLUGIN_ID_LENGTH];
|
||||
uint8_t pluginStatus;
|
||||
|
||||
uint8_t data[32];
|
||||
uint8_t data[INT256_LENGTH];
|
||||
uint8_t fieldIndex;
|
||||
uint8_t fieldOffset;
|
||||
|
||||
@@ -60,10 +62,10 @@ typedef struct tokenContext_t {
|
||||
|
||||
union {
|
||||
struct {
|
||||
uint8_t contract_address[20];
|
||||
uint8_t method_selector[4];
|
||||
uint8_t contract_address[ADDRESS_LENGTH];
|
||||
uint8_t method_selector[SELECTOR_LENGTH];
|
||||
};
|
||||
uint8_t pluginContext[3 * 32];
|
||||
uint8_t pluginContext[3 * INT256_LENGTH];
|
||||
};
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
@@ -78,14 +80,14 @@ typedef struct tokenContext_t {
|
||||
typedef struct publicKeyContext_t {
|
||||
cx_ecfp_public_key_t publicKey;
|
||||
uint8_t address[41];
|
||||
uint8_t chainCode[32];
|
||||
uint8_t chainCode[INT256_LENGTH];
|
||||
bool getChaincode;
|
||||
} publicKeyContext_t;
|
||||
|
||||
typedef struct transactionContext_t {
|
||||
uint8_t pathLength;
|
||||
uint32_t bip32Path[MAX_BIP32_PATH];
|
||||
uint8_t hash[32];
|
||||
uint8_t hash[INT256_LENGTH];
|
||||
tokenDefinition_t tokens[MAX_TOKEN];
|
||||
uint8_t tokenSet[MAX_TOKEN];
|
||||
uint8_t currentTokenIndex;
|
||||
@@ -95,7 +97,7 @@ typedef struct transactionContext_t {
|
||||
typedef struct messageSigningContext_t {
|
||||
uint8_t pathLength;
|
||||
uint32_t bip32Path[MAX_BIP32_PATH];
|
||||
uint8_t hash[32];
|
||||
uint8_t hash[INT256_LENGTH];
|
||||
uint32_t remainingLength;
|
||||
} messageSigningContext_t;
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
|
||||
typedef struct tokenDefinition_t {
|
||||
#ifdef HAVE_CONTRACT_NAME_IN_DESCRIPTOR
|
||||
uint8_t contractName[20];
|
||||
uint8_t contractName[ADDRESS_LENGTH];
|
||||
#endif
|
||||
uint8_t address[20];
|
||||
uint8_t address[ADDRESS_LENGTH];
|
||||
uint8_t ticker[MAX_TICKER_LEN];
|
||||
uint8_t decimals;
|
||||
} tokenDefinition_t;
|
||||
|
||||
@@ -36,7 +36,7 @@ void array_hexstr(char *strbuf, const void *bin, unsigned int len) {
|
||||
}
|
||||
|
||||
void convertUint256BE(uint8_t *data, uint32_t length, uint256_t *target) {
|
||||
uint8_t tmp[32];
|
||||
uint8_t tmp[INT256_LENGTH];
|
||||
memset(tmp, 0, 32);
|
||||
memmove(tmp + 32 - length, data, length);
|
||||
readu256BE(tmp, target);
|
||||
|
||||
@@ -36,6 +36,8 @@ typedef enum customStatus_e {
|
||||
typedef customStatus_e (*ustreamProcess_t)(struct txContext_t *context);
|
||||
|
||||
#define TX_FLAG_TYPE 0x01
|
||||
#define ADDRESS_LENGTH 20
|
||||
#define INT256_LENGTH 32
|
||||
|
||||
// First variant of every Tx enum.
|
||||
#define RLP_NONE 0
|
||||
@@ -97,7 +99,7 @@ typedef enum parserStatus_e {
|
||||
} parserStatus_e;
|
||||
|
||||
typedef struct txInt256_t {
|
||||
uint8_t value[32];
|
||||
uint8_t value[INT256_LENGTH];
|
||||
uint8_t length;
|
||||
} txInt256_t;
|
||||
|
||||
@@ -107,7 +109,7 @@ typedef struct txContent_t {
|
||||
txInt256_t value;
|
||||
txInt256_t nonce;
|
||||
txInt256_t chainID;
|
||||
uint8_t destination[20];
|
||||
uint8_t destination[ADDRESS_LENGTH];
|
||||
uint8_t destinationLength;
|
||||
uint8_t v[4];
|
||||
uint8_t vLength;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "cx.h"
|
||||
#include "ethUtils.h"
|
||||
#include "chainConfig.h"
|
||||
#include "ethUstream.h"
|
||||
|
||||
bool rlpCanDecode(uint8_t *buffer, uint32_t bufferLength, bool *valid) {
|
||||
if (*buffer <= 0x7f) {
|
||||
@@ -120,7 +121,7 @@ bool rlpDecodeLength(uint8_t *buffer,
|
||||
}
|
||||
|
||||
void getEthAddressFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out, cx_sha3_t *sha3Context) {
|
||||
uint8_t hashAddress[32];
|
||||
uint8_t hashAddress[INT256_LENGTH];
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *) sha3Context, CX_LAST, publicKey->W + 1, 64, hashAddress, 32);
|
||||
memmove(out, hashAddress + 12, 20);
|
||||
@@ -155,7 +156,7 @@ void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey,
|
||||
uint8_t *out,
|
||||
cx_sha3_t *sha3Context,
|
||||
chain_config_t *chain_config) {
|
||||
uint8_t hashAddress[32];
|
||||
uint8_t hashAddress[INT256_LENGTH];
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *) sha3Context, CX_LAST, publicKey->W + 1, 64, hashAddress, 32);
|
||||
getEthAddressStringFromBinary(hashAddress + 12, out, sha3Context, chain_config);
|
||||
@@ -166,7 +167,7 @@ void getEthAddressStringFromBinary(uint8_t *address,
|
||||
cx_sha3_t *sha3Context,
|
||||
chain_config_t *chain_config) {
|
||||
UNUSED(chain_config);
|
||||
uint8_t hashChecksum[32];
|
||||
uint8_t hashChecksum[INT256_LENGTH];
|
||||
uint8_t i;
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *) sha3Context, CX_LAST, address, 20, hashChecksum, 32);
|
||||
@@ -184,7 +185,7 @@ void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey,
|
||||
uint8_t *out,
|
||||
cx_sha3_t *sha3Context,
|
||||
chain_config_t *chain_config) {
|
||||
uint8_t hashAddress[32];
|
||||
uint8_t hashAddress[INT256_LENGTH];
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *) sha3Context, CX_LAST, publicKey->W + 1, 64, hashAddress, 32);
|
||||
getEthAddressStringFromBinary(hashAddress + 12, out, sha3Context, chain_config);
|
||||
@@ -196,7 +197,7 @@ void getEthAddressStringFromBinary(uint8_t *address,
|
||||
chain_config_t *chain_config) {
|
||||
// save some precious stack space
|
||||
union locals_union {
|
||||
uint8_t hashChecksum[32];
|
||||
uint8_t hashChecksum[INT256_LENGTH];
|
||||
uint8_t tmp[51];
|
||||
} locals_union;
|
||||
|
||||
|
||||
@@ -347,7 +347,7 @@ void read_u64_be(uint8_t *in, uint64_t *out) {
|
||||
}
|
||||
|
||||
void mul256(uint256_t *number1, uint256_t *number2, uint256_t *target) {
|
||||
uint8_t num1[32], num2[32], result[64];
|
||||
uint8_t num1[INT256_LENGTH], num2[INT256_LENGTH], result[INT256_LENGTH * 2];
|
||||
memset(&result, 0, sizeof(result));
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
write_u64_be(num1 + i * sizeof(uint64_t), number1->elements[i / 2].elements[i % 2]);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "os.h"
|
||||
#include "cx.h"
|
||||
#include "ethUstream.h"
|
||||
|
||||
typedef struct uint128_t {
|
||||
uint64_t elements[2];
|
||||
|
||||
@@ -12,7 +12,7 @@ static const uint8_t BLS12_381_FIELD_MODULUS[] = {
|
||||
0x1e, 0xab, 0xff, 0xfe, 0xb1, 0x53, 0xff, 0xff, 0xb9, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xaa, 0xab};
|
||||
|
||||
void getEth2PublicKey(uint32_t *bip32Path, uint8_t bip32PathLength, uint8_t *out) {
|
||||
uint8_t privateKeyData[32];
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
cx_ecfp_256_extended_private_key_t privateKey;
|
||||
cx_ecfp_384_public_key_t publicKey;
|
||||
uint8_t yFlag = 0;
|
||||
|
||||
@@ -11,7 +11,7 @@ void handleGetPublicKey(uint8_t p1,
|
||||
unsigned int *flags,
|
||||
unsigned int *tx) {
|
||||
UNUSED(dataLength);
|
||||
uint8_t privateKeyData[32];
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
uint32_t bip32Path[MAX_BIP32_PATH];
|
||||
uint32_t i;
|
||||
uint8_t bip32PathLength = *(dataBuffer++);
|
||||
|
||||
@@ -17,7 +17,7 @@ void handleProvideErc20TokenInformation(uint8_t p1,
|
||||
uint32_t offset = 0;
|
||||
uint8_t tickerLength, contractNameLength;
|
||||
uint32_t chainId;
|
||||
uint8_t hash[32];
|
||||
uint8_t hash[INT256_LENGTH];
|
||||
cx_sha256_t sha256;
|
||||
cx_ecfp_public_key_t tokenKey;
|
||||
|
||||
@@ -109,7 +109,7 @@ void handleProvideErc20TokenInformation(uint8_t p1,
|
||||
uint32_t offset = 0;
|
||||
uint8_t tickerLength;
|
||||
uint32_t chainId;
|
||||
uint8_t hash[32];
|
||||
uint8_t hash[INT256_LENGTH];
|
||||
cx_ecfp_public_key_t tokenKey;
|
||||
|
||||
tmpCtx.transactionContext.currentTokenIndex =
|
||||
|
||||
@@ -14,7 +14,7 @@ void handleSignPersonalMessage(uint8_t p1,
|
||||
unsigned int *flags,
|
||||
unsigned int *tx) {
|
||||
UNUSED(tx);
|
||||
uint8_t hashMessage[32];
|
||||
uint8_t hashMessage[INT256_LENGTH];
|
||||
if (p1 == P1_FIRST) {
|
||||
char tmp[11];
|
||||
uint32_t index;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "ui_callbacks.h"
|
||||
|
||||
unsigned int io_seproxyhal_touch_signMessage_ok(const bagl_element_t *e) {
|
||||
uint8_t privateKeyData[32];
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
uint8_t signature[100];
|
||||
uint8_t signatureLength;
|
||||
cx_ecfp_private_key_t privateKey;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
static const uint8_t const EIP_712_MAGIC[] = {0x19, 0x01};
|
||||
|
||||
unsigned int io_seproxyhal_touch_signMessage712_v0_ok(const bagl_element_t *e) {
|
||||
uint8_t privateKeyData[32];
|
||||
uint8_t hash[32];
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
uint8_t hash[INT256_LENGTH];
|
||||
uint8_t signature[100];
|
||||
uint8_t signatureLength;
|
||||
cx_ecfp_private_key_t privateKey;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "ui_callbacks.h"
|
||||
|
||||
unsigned int io_seproxyhal_touch_tx_ok(const bagl_element_t *e) {
|
||||
uint8_t privateKeyData[32];
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
uint8_t signature[100];
|
||||
uint8_t signatureLength;
|
||||
cx_ecfp_private_key_t privateKey;
|
||||
|
||||
@@ -17,7 +17,7 @@ void handleStarkwareSignMessage(uint8_t p1,
|
||||
uint16_t dataLength,
|
||||
unsigned int *flags,
|
||||
unsigned int *tx) {
|
||||
uint8_t privateKeyData[32];
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
uint32_t i;
|
||||
uint8_t bip32PathLength = *(dataBuffer);
|
||||
uint8_t offset = 1;
|
||||
|
||||
@@ -13,7 +13,7 @@ void handleStarkwareUnsafeSign(uint8_t p1,
|
||||
unsigned int *flags,
|
||||
unsigned int *tx) {
|
||||
uint32_t i;
|
||||
uint8_t privateKeyData[32];
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
cx_ecfp_public_key_t publicKey;
|
||||
cx_ecfp_private_key_t privateKey;
|
||||
uint8_t bip32PathLength = *(dataBuffer);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
unsigned int io_seproxyhal_touch_stark_unsafe_sign_ok(const bagl_element_t *e) {
|
||||
cx_ecfp_private_key_t privateKey;
|
||||
uint8_t privateKeyData[32];
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
uint8_t signature[72];
|
||||
unsigned int info = 0;
|
||||
uint32_t tx = 0;
|
||||
|
||||
@@ -12,7 +12,7 @@ typedef enum { TARGET_ADDRESS = 0, TARGET_CONTRACT, TARGET_COMPOUND } targetType
|
||||
typedef struct erc20_parameters_t {
|
||||
uint8_t selectorIndex;
|
||||
uint8_t destinationAddress[21];
|
||||
uint8_t amount[32];
|
||||
uint8_t amount[INT256_LENGTH];
|
||||
uint8_t ticker_1[MAX_TICKER_LEN];
|
||||
uint8_t ticker_2[MAX_TICKER_LEN];
|
||||
uint8_t decimals;
|
||||
|
||||
@@ -10,8 +10,8 @@ void starkware_print_eth_address(uint8_t *address, char *destination);
|
||||
|
||||
typedef struct erc721_parameters_t {
|
||||
uint8_t selectorIndex;
|
||||
uint8_t address[20];
|
||||
uint8_t tokenId[32];
|
||||
uint8_t address[ADDRESS_LENGTH];
|
||||
uint8_t tokenId[INT256_LENGTH];
|
||||
// tokenDefinition_t *tokenSelf;
|
||||
// tokenDefinition_t *tokenAddress;
|
||||
} erc721_parameters_t;
|
||||
|
||||
@@ -352,7 +352,7 @@ void starkware_print_asset_contract(char *destination) {
|
||||
|
||||
// TODO : rewrite as independant code
|
||||
void starkware_get_source_address(char *destination) {
|
||||
uint8_t privateKeyData[32];
|
||||
uint8_t privateKeyData[INT256_LENGTH];
|
||||
cx_ecfp_private_key_t privateKey;
|
||||
cx_ecfp_public_key_t publicKey;
|
||||
os_perso_derive_node_bip32(CX_CURVE_256K1,
|
||||
|
||||
Reference in New Issue
Block a user