Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions include/keepkey/firmware/eip712.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
Parser wants to see C strings, not javascript strings:
requires all complete json message strings to be enclosed by braces,
i.e., { ... } Cannot have entire json string quoted, i.e., "{ ... }" will not
work. Remove all quote escape chars, e.g., {"types": not {\"types\": int
values must be hex. Negative sign indicates negative value, e.g., -5, -8a67
Note: Do not prefix ints or uints with 0x
work. Remove all quote escape chars, e.g., {"types": not {\"types\":
Integer values must use canonical base-10 digits. Negative values use a
leading minus sign. Do not prefix ints or uints with 0x.
All hex and byte strings must be big-endian
Byte strings and address should be prefixed by 0x
*/
Expand Down Expand Up @@ -95,10 +95,16 @@ typedef enum { DOMAIN = 1, MESSAGE } dm;
#define JSON_TYPE_T_NOVAL 31
#define ADDR_STRING_NULL 32
#define JSON_TYPE_WNOVAL 33
#define USER_CANCELLED 34

#define LAST_ERROR JSON_TYPE_WNOVAL
#define LAST_ERROR USER_CANCELLED

int encode(const json_t* jsonTypes, const json_t* jsonVals, const char* typeS,
uint8_t* hashRet);

/* Exposed for strict-value regression tests. */
int encAddress(const char* string, uint8_t* encoded);
int encodeBytes(const char* string, uint8_t* encoded);
int encodeBytesN(const char* typeT, const char* string, uint8_t* encoded);

#endif
3 changes: 3 additions & 0 deletions include/keepkey/firmware/ethereum.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef struct _CoinType CoinType;
void ethereum_signing_init(EthereumSignTx* msg, const HDNode* node,
bool needs_confirm);
void ethereum_signing_abort(void);
bool ethereum_signing_isInProgress(void);
void ethereum_signing_txack(EthereumTxAck* tx);
void format_ethereum_address(const uint8_t* to, char* destination_str,
uint32_t destination_str_len);
Expand Down Expand Up @@ -70,6 +71,8 @@ void bn_from_bytes(const uint8_t* value, size_t value_len, bignum256* val);
void ethereum_typed_hash_sign(const EthereumSignTypedHash* msg,
const HDNode* node,
EthereumTypedDataSignature* resp);
bool ethereum_typed_hash_policy_allows(bool advanced_mode);
bool ethereum_eip712_is_domain_primary_type(const char* primary_type);
bool ethereum_path_check(uint32_t address_n_count, const uint32_t* address_n,
bool pubkey_export, uint64_t chain);
void e712_types_values(Ethereum712TypesValues* msg,
Expand Down
28 changes: 27 additions & 1 deletion include/keepkey/firmware/ethereum_contracts/thortx.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,31 @@
"\xee\xee\xee\xee\xee\xee\xee\xee\xee\xee\xee\xee\xee\xee\xee\xee\xee\xee" \
"\xee\xee"

#define THOR_ROUTER "42a5ed456650a09dc10ebc6361a7480fdd61f27b"
/* THORChain ETH router (mainnet), current v4.1.1.
* NOTE: THORChain migrates this router periodically (v1 42a5ed.. -> v3
* 3624525.. -> v4 d37bbe..). A hardcoded pin must be updated on each migration;
* the durable path is the signed-metadata clear-sign protocol (host-signed,
* key-pinned) which needs no firmware update per router change. */
#define THOR_ROUTER "d37bbe5744d730a1d98d8dc97c42f0ca46ad7146"

/* THORChain deploys its Router at a DIFFERENT address on every EVM chain, so
* the pin must be chain-scoped (see thor_router_for_chain): a deposit on any
* chain but mainnet can never match THOR_ROUTER and would fall to the
* blind-sign gate. Avalanche C-Chain router, verified live against THORChain
* /inbound_addresses via a Pioneer quote (2026-07). Lowercase, no 0x, to match
* thor_format_to_addr's output. Same migration caveat as THOR_ROUTER.
* ponytail: BSC (chainId 56) and Base (8453) routers also exist on-chain but
* are omitted until verified against a live node — the shipped Pioneer catalog
* lists STALE addresses (its AVAX entry 8f66c4ae.. is already wrong vs the live
* 00dc6100..), and Pioneer currently routes BSC/Base swaps via Relay, not a
* THORChain deposit, so no such tx reaches the device today. Add each here once
* verified live. */
#define THOR_ROUTER_AVAX "00dc6100103bc402d490aee3f9a5560cbd91f1d4"

/* Maya Protocol ETH router v4 (mainnet), verified on Etherscan
* (0xe3985e6b61b814f7cdb188766562ba71b446b46d). The prior pin
* d89dce57.. has never held contract code on mainnet. */
#define MAYA_ROUTER "e3985e6b61b814f7cdb188766562ba71b446b46d"

/* deposit(address,address,uint256,string) — legacy selector */
#define THOR_SELECTOR_DEPOSIT "\x1f\xec\xe7\xb4"
Expand All @@ -43,6 +67,8 @@ typedef struct _EthereumSignTx EthereumSignTx;
bool thor_has_deposit_selector(const EthereumSignTx* msg);
bool thor_is_expiry_variant(const EthereumSignTx* msg);
bool thor_isThorchainTx(const EthereumSignTx* msg);
bool thor_isMayachainTx(const EthereumSignTx* msg);
bool thor_confirmThorTx(uint32_t data_total, const EthereumSignTx* msg);
bool thor_confirmMayaTx(uint32_t data_total, const EthereumSignTx* msg);

#endif
3 changes: 3 additions & 0 deletions include/keepkey/firmware/ethereum_contracts/zxliquidtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>

#define UNISWAP_ROUTER_ADDRESS \
"\x7a\x25\x0d\x56\x30\xB4\xcF\x53\x97\x39\xdF\x2C\x5d\xAc\xb4\xc6\x59\xF2" \
Expand All @@ -31,5 +32,7 @@ typedef struct _EthereumSignTx EthereumSignTx;

bool zx_isZxLiquidTx(const EthereumSignTx* msg);
bool zx_confirmZxLiquidTx(uint32_t data_total, const EthereumSignTx* msg);
bool zx_formatZxLiquidityPrimaryAmount(const EthereumSignTx* msg, char* out,
size_t out_len);

#endif
10 changes: 7 additions & 3 deletions include/keepkey/firmware/ethereum_tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <stdbool.h>
#include <stdint.h>

#if BITCOIN_ONLY
#define TOKENS_COUNT 0 // no ERC-20 tokens in the bitcoin-only image
#else
enum {
#define X(CHAIN_ID, CONTRACT_ADDR, TICKER, DECIMALS) \
CONCAT(TokenIndex, __COUNTER__),
Expand All @@ -35,11 +38,12 @@ enum {
};

#define TOKENS_COUNT ((int)TokenIndexLast - (int)TokenIndexFirst)
#endif

typedef struct _TokenType {
const char* const address;
const char* const ticker;
uint8_t chain_id;
uint32_t chain_id;
uint8_t decimals;
} TokenType;

Expand All @@ -51,7 +55,7 @@ extern const TokenType* UnknownToken;

const TokenType* tokenIter(int32_t* ctr);

const TokenType* tokenByChainAddress(uint8_t chain_id, const uint8_t* address);
const TokenType* tokenByChainAddress(uint32_t chain_id, const uint8_t* address);

/// Tokens don't have unique tickers, so this might not return the one you're
/// looking for :/
Expand All @@ -64,7 +68,7 @@ const TokenType* tokenByChainAddress(uint8_t chain_id, const uint8_t* address);
/// \param[out] token The found token, assuming it was uniquely determinable.
/// \returns true iff the token can be uniquely found in the list of known
/// tokens.
bool tokenByTicker(uint8_t chain_id, const char* ticker,
bool tokenByTicker(uint32_t chain_id, const char* ticker,
const TokenType** token);

void coinFromToken(CoinType* coin, const TokenType* token);
Expand Down
2 changes: 2 additions & 0 deletions include/keepkey/firmware/fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ void fsm_msgEthereumSignMessage(EthereumSignMessage* msg);
void fsm_msgEthereumVerifyMessage(const EthereumVerifyMessage* msg);
void fsm_msgEthereumSignTypedHash(const EthereumSignTypedHash* msg);
void fsm_msgEthereum712TypesValues(Ethereum712TypesValues* msg);
void fsm_msgEthereumTxMetadata(const EthereumTxMetadata* msg);
void fsm_msgLoadClearsignSigner(const LoadClearsignSigner* msg);

void fsm_msgNanoGetAddress(NanoGetAddress* msg);
void fsm_msgNanoSignTx(NanoSignTx* msg);
Expand Down
Loading
Loading