diff --git a/src/address.c b/src/address.c index f3617a4..756bb0a 100644 --- a/src/address.c +++ b/src/address.c @@ -77,7 +77,10 @@ const uint8_t root_header[] = { 0xd5, 0xc0}; -const uint8_t v3r2_root_header[] = { 0x2, 0x1, 0x34, 0x0, 0x0, 0x0, 0x0, 0x84, 0xda, 0xfa, 0x44, 0x9f, 0x98, 0xa6, 0x98, 0x77, 0x89, 0xba, 0x23, 0x23, 0x58, 0x7, 0x2b, 0xc0, 0xf7, 0x6d, 0xc4, 0x52, 0x40, 0x2, 0xa5, 0xd0, 0x91, 0x8b, 0x9a, 0x75, 0xd2, 0xd5, 0x99 }; +const uint8_t v3r2_root_header[] = {0x2, 0x1, 0x34, 0x0, 0x0, 0x0, 0x0, 0x84, 0xda, 0xfa, + 0x44, 0x9f, 0x98, 0xa6, 0x98, 0x77, 0x89, 0xba, 0x23, 0x23, + 0x58, 0x7, 0x2b, 0xc0, 0xf7, 0x6d, 0xc4, 0x52, 0x40, 0x2, + 0xa5, 0xd0, 0x91, 0x8b, 0x9a, 0x75, 0xd2, 0xd5, 0x99}; const uint8_t data_header[] = { 0x00, @@ -101,7 +104,11 @@ const uint8_t data_tail[] = { 0x40 // zero bit + padding }; -bool pubkey_to_hash(const uint8_t public_key[static PUBKEY_LEN], const uint32_t subwallet_id, const bool is_v3r2, uint8_t *out, size_t out_len) { +bool pubkey_to_hash(const uint8_t public_key[static PUBKEY_LEN], + const uint32_t subwallet_id, + const bool is_v3r2, + uint8_t *out, + size_t out_len) { if (out_len != HASH_LEN) { return false; } @@ -118,27 +125,42 @@ bool pubkey_to_hash(const uint8_t public_key[static PUBKEY_LEN], const uint32_t // Hash init data cell bits SAFE(cx_sha256_init_no_throw(&state)); if (is_v3r2) { - SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, v3r2_data_header, sizeof(v3r2_data_header), NULL, 0)); + SAFE(cx_hash_no_throw((cx_hash_t *) &state, + 0, + v3r2_data_header, + sizeof(v3r2_data_header), + NULL, + 0)); } else { SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, data_header, sizeof(data_header), NULL, 0)); } SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, subwallet_buf, sizeof(subwallet_buf), NULL, 0)); if (is_v3r2) { - SAFE(cx_hash_no_throw((cx_hash_t *) &state, CX_LAST, public_key, PUBKEY_LEN, inner, sizeof(inner))); + SAFE(cx_hash_no_throw((cx_hash_t *) &state, + CX_LAST, + public_key, + PUBKEY_LEN, + inner, + sizeof(inner))); } else { SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, public_key, PUBKEY_LEN, NULL, 0)); SAFE(cx_hash_no_throw((cx_hash_t *) &state, - CX_LAST, - data_tail, - sizeof(data_tail), - inner, - sizeof(inner))); + CX_LAST, + data_tail, + sizeof(data_tail), + inner, + sizeof(inner))); } // Hash root SAFE(cx_sha256_init_no_throw(&state)); if (is_v3r2) { - SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, v3r2_root_header, sizeof(v3r2_root_header), NULL, 0)); + SAFE(cx_hash_no_throw((cx_hash_t *) &state, + 0, + v3r2_root_header, + sizeof(v3r2_root_header), + NULL, + 0)); } else { SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, root_header, sizeof(root_header), NULL, 0)); } diff --git a/src/address.h b/src/address.h index f2adac5..9b72fd8 100644 --- a/src/address.h +++ b/src/address.h @@ -24,7 +24,11 @@ * @return true if success, false otherwise. * */ -bool pubkey_to_hash(const uint8_t public_key[static PUBKEY_LEN], const uint32_t subwallet_id, const bool is_v3r2, uint8_t *out, size_t out_len); +bool pubkey_to_hash(const uint8_t public_key[static PUBKEY_LEN], + const uint32_t subwallet_id, + const bool is_v3r2, + uint8_t *out, + size_t out_len); /** * Convert public key to address. Uses Wallet V4 contract. diff --git a/src/apdu/params.h b/src/apdu/params.h index ee8c34c..a0f02e1 100644 --- a/src/apdu/params.h +++ b/src/apdu/params.h @@ -48,4 +48,5 @@ /** * P2 containing all address display bits. */ -#define P2_ADDR_FLAGS_MAX (P2_ADDR_FLAG_TESTNET | P2_ADDR_FLAG_MASTERCHAIN | P2_ADDR_FLAG_WALLET_SPECIFIERS) +#define P2_ADDR_FLAGS_MAX \ + (P2_ADDR_FLAG_TESTNET | P2_ADDR_FLAG_MASTERCHAIN | P2_ADDR_FLAG_WALLET_SPECIFIERS) diff --git a/src/transaction/transaction_hints.c b/src/transaction/transaction_hints.c index 761f14d..81b5ee0 100644 --- a/src/transaction/transaction_hints.c +++ b/src/transaction/transaction_hints.c @@ -33,7 +33,10 @@ static const uint8_t dns_key_wallet[32] = { #ifdef HAVE_HARDCODED_JETTONS -static void assemble_usdt_state(CellRef_t* out, const CellRef_t *code, address_t* owner, address_t* master) { +static void assemble_usdt_state(CellRef_t* out, + const CellRef_t* code, + address_t* owner, + address_t* master) { BitString_t bits; CellRef_t refs[2]; refs[0] = *code; @@ -50,7 +53,10 @@ static void assemble_usdt_state(CellRef_t* out, const CellRef_t *code, address_t hash_Cell(&bits, refs, 2, out); } -static void assemble_tston_state(CellRef_t* out, const CellRef_t *code, address_t* owner, address_t* master) { +static void assemble_tston_state(CellRef_t* out, + const CellRef_t* code, + address_t* owner, + address_t* master) { BitString_t bits; CellRef_t refs[2]; refs[0] = *code; @@ -68,7 +74,10 @@ static void assemble_tston_state(CellRef_t* out, const CellRef_t *code, address_ hash_Cell(&bits, refs, 2, out); } -static void assemble_wston_state(CellRef_t* out, const CellRef_t *code, address_t* owner, address_t* master) { +static void assemble_wston_state(CellRef_t* out, + const CellRef_t* code, + address_t* owner, + address_t* master) { BitString_t bits; CellRef_t refs[2]; refs[0] = *code; @@ -85,7 +94,10 @@ static void assemble_wston_state(CellRef_t* out, const CellRef_t *code, address_ hash_Cell(&bits, refs, 2, out); } -static void assemble_hton_state(CellRef_t* out, const CellRef_t *code, address_t* owner, address_t* master) { +static void assemble_hton_state(CellRef_t* out, + const CellRef_t* code, + address_t* owner, + address_t* master) { BitString_t bits; CellRef_t refs[2]; refs[0] = *code; @@ -103,7 +115,10 @@ static void assemble_hton_state(CellRef_t* out, const CellRef_t *code, address_t hash_Cell(&bits, refs, 2, out); } -static void assemble_stton_state(CellRef_t* out, const CellRef_t *code, address_t* owner, address_t* master) { +static void assemble_stton_state(CellRef_t* out, + const CellRef_t* code, + address_t* owner, + address_t* master) { BitString_t bits; CellRef_t refs[2]; refs[0] = *code; @@ -119,7 +134,11 @@ static void assemble_stton_state(CellRef_t* out, const CellRef_t *code, address_ hash_Cell(&bits, refs, 2, out); } -static bool jetton_state_assembler_dispatcher(CellRef_t* out, const CellRef_t *code, address_t* owner, address_t* master, uint8_t state_assembler_idx) { +static bool jetton_state_assembler_dispatcher(CellRef_t* out, + const CellRef_t* code, + address_t* owner, + address_t* master, + uint8_t state_assembler_idx) { switch (state_assembler_idx) { case 0: assemble_usdt_state(out, code, owner, master); @@ -151,67 +170,97 @@ typedef struct { static const jetton_t jettons[] = { { - .master_hash = {0xb1, 0x13, 0xa9, 0x94, 0xb5, 0x2, 0x4a, 0x16, 0x71, 0x9f, 0x69, 0x13, 0x93, 0x28, 0xeb, 0x75, 0x95, 0x96, 0xc3, 0x8a, 0x25, 0xf5, 0x90, 0x28, 0xb1, 0x46, 0xfe, 0xcd, 0xc3, 0x62, 0x1d, 0xfe}, + .master_hash = {0xb1, 0x13, 0xa9, 0x94, 0xb5, 0x2, 0x4a, 0x16, 0x71, 0x9f, 0x69, + 0x13, 0x93, 0x28, 0xeb, 0x75, 0x95, 0x96, 0xc3, 0x8a, 0x25, 0xf5, + 0x90, 0x28, 0xb1, 0x46, 0xfe, 0xcd, 0xc3, 0x62, 0x1d, 0xfe}, .name = "USDT", - .code = { - .hash = {0x89, 0x46, 0x8f, 0x2, 0xc7, 0x8e, 0x57, 0x8, 0x2, 0xe3, 0x99, 0x79, 0xc8, 0x51, 0x6f, 0xc3, 0x8d, 0xf0, 0x7e, 0xa7, 0x6a, 0x48, 0x35, 0x7e, 0x5, 0x36, 0xf2, 0xba, 0x7b, 0x3e, 0xe3, 0x7b}, - .max_depth = 0, - }, + .code = + { + .hash = {0x89, 0x46, 0x8f, 0x2, 0xc7, 0x8e, 0x57, 0x8, 0x2, 0xe3, 0x99, + 0x79, 0xc8, 0x51, 0x6f, 0xc3, 0x8d, 0xf0, 0x7e, 0xa7, 0x6a, 0x48, + 0x35, 0x7e, 0x5, 0x36, 0xf2, 0xba, 0x7b, 0x3e, 0xe3, 0x7b}, + .max_depth = 0, + }, .master_workchain = 0, .decimals = 6, .state_assembler_idx = 0, }, { - .master_hash = {0x2f, 0x95, 0x61, 0x43, 0xc4, 0x61, 0x76, 0x95, 0x79, 0xba, 0xef, 0x2e, 0x32, 0xcc, 0x2d, 0x7b, 0xc1, 0x82, 0x83, 0xf4, 0xd, 0x20, 0xbb, 0x3, 0xe4, 0x32, 0xcd, 0x60, 0x3a, 0xc3, 0x3f, 0xfc}, + .master_hash = {0x2f, 0x95, 0x61, 0x43, 0xc4, 0x61, 0x76, 0x95, 0x79, 0xba, 0xef, + 0x2e, 0x32, 0xcc, 0x2d, 0x7b, 0xc1, 0x82, 0x83, 0xf4, 0xd, 0x20, + 0xbb, 0x3, 0xe4, 0x32, 0xcd, 0x60, 0x3a, 0xc3, 0x3f, 0xfc}, .name = "NOT", - .code = { - .hash = {0x8d, 0x28, 0xea, 0x42, 0x1b, 0x77, 0xe8, 0x5, 0xfe, 0xa5, 0x2a, 0xcf, 0x33, 0x52, 0x96, 0x49, 0x9f, 0x3, 0xae, 0xc8, 0xe9, 0xfd, 0x21, 0xdd, 0xb5, 0xf2, 0x56, 0x4a, 0xa6, 0x5c, 0x48, 0xde}, - .max_depth = 0, - }, + .code = + { + .hash = {0x8d, 0x28, 0xea, 0x42, 0x1b, 0x77, 0xe8, 0x5, 0xfe, 0xa5, 0x2a, + 0xcf, 0x33, 0x52, 0x96, 0x49, 0x9f, 0x3, 0xae, 0xc8, 0xe9, 0xfd, + 0x21, 0xdd, 0xb5, 0xf2, 0x56, 0x4a, 0xa6, 0x5c, 0x48, 0xde}, + .max_depth = 0, + }, .master_workchain = 0, .decimals = 9, .state_assembler_idx = 0, }, { - .master_hash = {0xbd, 0xf3, 0xfa, 0x80, 0x98, 0xd1, 0x29, 0xb5, 0x4b, 0x4f, 0x73, 0xb5, 0xba, 0xc5, 0xd1, 0xe1, 0xfd, 0x91, 0xeb, 0x5, 0x41, 0x69, 0xc3, 0x91, 0x6d, 0xfc, 0x8c, 0xcd, 0x53, 0x6d, 0x10, 0x0}, + .master_hash = {0xbd, 0xf3, 0xfa, 0x80, 0x98, 0xd1, 0x29, 0xb5, 0x4b, 0x4f, 0x73, + 0xb5, 0xba, 0xc5, 0xd1, 0xe1, 0xfd, 0x91, 0xeb, 0x5, 0x41, 0x69, + 0xc3, 0x91, 0x6d, 0xfc, 0x8c, 0xcd, 0x53, 0x6d, 0x10, 0x0}, .name = "tsTON", - .code = { - .hash = {0x8, 0x96, 0x21, 0xdd, 0x77, 0xe0, 0xa9, 0xa4, 0xae, 0x44, 0x27, 0x9e, 0x59, 0x2f, 0x13, 0xd6, 0xab, 0x5c, 0x55, 0xde, 0xcd, 0x60, 0xcc, 0x9e, 0xc3, 0x6b, 0x7c, 0x2a, 0xe4, 0xd, 0x15, 0x95}, - .max_depth = 0, - }, + .code = + { + .hash = {0x8, 0x96, 0x21, 0xdd, 0x77, 0xe0, 0xa9, 0xa4, 0xae, 0x44, 0x27, + 0x9e, 0x59, 0x2f, 0x13, 0xd6, 0xab, 0x5c, 0x55, 0xde, 0xcd, 0x60, + 0xcc, 0x9e, 0xc3, 0x6b, 0x7c, 0x2a, 0xe4, 0xd, 0x15, 0x95}, + .max_depth = 0, + }, .master_workchain = 0, .decimals = 9, .state_assembler_idx = 1, }, { - .master_hash = {0x74, 0x4a, 0x8c, 0x6e, 0x18, 0x3c, 0x79, 0xaa, 0x35, 0x6d, 0xd0, 0xff, 0xdb, 0x3c, 0x80, 0x85, 0x79, 0x67, 0x45, 0x2c, 0x19, 0x95, 0xa2, 0x91, 0xe1, 0x8e, 0x7, 0xec, 0xd2, 0xaf, 0xb0, 0xb1}, + .master_hash = {0x74, 0x4a, 0x8c, 0x6e, 0x18, 0x3c, 0x79, 0xaa, 0x35, 0x6d, 0xd0, + 0xff, 0xdb, 0x3c, 0x80, 0x85, 0x79, 0x67, 0x45, 0x2c, 0x19, 0x95, + 0xa2, 0x91, 0xe1, 0x8e, 0x7, 0xec, 0xd2, 0xaf, 0xb0, 0xb1}, .name = "wsTON", - .code = { - .hash = {0xda, 0x4d, 0x2, 0xf6, 0xb4, 0xea, 0x63, 0x4, 0x16, 0xc3, 0x34, 0x9a, 0xfc, 0x75, 0xc8, 0x2, 0x15, 0x1b, 0xb1, 0x6f, 0xd6, 0x47, 0xae, 0x9f, 0x73, 0xbd, 0xe0, 0x17, 0x73, 0x55, 0x72, 0x31}, - .max_depth = 7, - }, + .code = + { + .hash = {0xda, 0x4d, 0x2, 0xf6, 0xb4, 0xea, 0x63, 0x4, 0x16, 0xc3, 0x34, + 0x9a, 0xfc, 0x75, 0xc8, 0x2, 0x15, 0x1b, 0xb1, 0x6f, 0xd6, 0x47, + 0xae, 0x9f, 0x73, 0xbd, 0xe0, 0x17, 0x73, 0x55, 0x72, 0x31}, + .max_depth = 7, + }, .master_workchain = 0, .decimals = 9, .state_assembler_idx = 2, }, { - .master_hash = {0xcf, 0x76, 0xaf, 0x31, 0x8c, 0x8, 0x72, 0xb5, 0x8a, 0x9f, 0x19, 0x25, 0xfc, 0x29, 0xc1, 0x56, 0x21, 0x17, 0x82, 0xb9, 0xfb, 0x1, 0xf5, 0x67, 0x60, 0xd2, 0x92, 0xe5, 0x61, 0x23, 0xbf, 0x87}, + .master_hash = {0xcf, 0x76, 0xaf, 0x31, 0x8c, 0x8, 0x72, 0xb5, 0x8a, 0x9f, 0x19, + 0x25, 0xfc, 0x29, 0xc1, 0x56, 0x21, 0x17, 0x82, 0xb9, 0xfb, 0x1, + 0xf5, 0x67, 0x60, 0xd2, 0x92, 0xe5, 0x61, 0x23, 0xbf, 0x87}, .name = "hTON", - .code = { - .hash = {0x50, 0xb9, 0x17, 0xd9, 0xfd, 0x5b, 0x95, 0x76, 0x9, 0x93, 0x28, 0x76, 0x77, 0xd0, 0x48, 0x12, 0xa1, 0x5a, 0xa5, 0x5e, 0x6b, 0x71, 0xd0, 0xf9, 0x22, 0x6e, 0xcd, 0x7c, 0x20, 0xc3, 0xd8, 0x2a}, - .max_depth = 0, - }, + .code = + { + .hash = {0x50, 0xb9, 0x17, 0xd9, 0xfd, 0x5b, 0x95, 0x76, 0x9, 0x93, 0x28, + 0x76, 0x77, 0xd0, 0x48, 0x12, 0xa1, 0x5a, 0xa5, 0x5e, 0x6b, 0x71, + 0xd0, 0xf9, 0x22, 0x6e, 0xcd, 0x7c, 0x20, 0xc3, 0xd8, 0x2a}, + .max_depth = 0, + }, .master_workchain = 0, .decimals = 9, .state_assembler_idx = 3, }, { - .master_hash = {0xcd, 0x87, 0x2f, 0xa7, 0xc5, 0x81, 0x60, 0x52, 0xac, 0xdf, 0x53, 0x32, 0x26, 0x4, 0x43, 0xfa, 0xec, 0x9a, 0xac, 0xc8, 0xc2, 0x1c, 0xca, 0x4d, 0x92, 0xe7, 0xf4, 0x70, 0x34, 0xd1, 0x18, 0x92}, + .master_hash = {0xcd, 0x87, 0x2f, 0xa7, 0xc5, 0x81, 0x60, 0x52, 0xac, 0xdf, 0x53, + 0x32, 0x26, 0x4, 0x43, 0xfa, 0xec, 0x9a, 0xac, 0xc8, 0xc2, 0x1c, + 0xca, 0x4d, 0x92, 0xe7, 0xf4, 0x70, 0x34, 0xd1, 0x18, 0x92}, .name = "stTON", - .code = { - .hash = {0x2d, 0x79, 0x72, 0xf7, 0x12, 0xfc, 0x39, 0x8b, 0xc3, 0x2f, 0x67, 0x96, 0x98, 0xa, 0xd7, 0x11, 0x90, 0x74, 0x34, 0xa3, 0x11, 0xb5, 0x7f, 0xe7, 0x2d, 0x20, 0xf7, 0x51, 0xb, 0x21, 0x23, 0xe6}, - .max_depth = 6, - }, + .code = + { + .hash = {0x2d, 0x79, 0x72, 0xf7, 0x12, 0xfc, 0x39, 0x8b, 0xc3, 0x2f, 0x67, + 0x96, 0x98, 0xa, 0xd7, 0x11, 0x90, 0x74, 0x34, 0xa3, 0x11, 0xb5, + 0x7f, 0xe7, 0x2d, 0x20, 0xf7, 0x51, 0xb, 0x21, 0x23, 0xe6}, + .max_depth = 6, + }, .master_workchain = 0, .decimals = 9, .state_assembler_idx = 4, @@ -321,13 +370,21 @@ bool process_hints(transaction_t* tx) { return false; } - SAFE(pubkey_to_hash(pubkey, G_context.tx_info.transaction.subwallet_id, !G_context.tx_info.transaction.include_wallet_op, owner.hash, sizeof(owner.hash))); + SAFE(pubkey_to_hash(pubkey, + G_context.tx_info.transaction.subwallet_id, + !G_context.tx_info.transaction.include_wallet_op, + owner.hash, + sizeof(owner.hash))); address_t master; memcpy(master.hash, jettons[jetton_id].master_hash, 32); master.chain = jettons[jetton_id].master_workchain; - SAFE(jetton_state_assembler_dispatcher(&state_init, &jettons[jetton_id].code, &owner, &master, jettons[jetton_id].state_assembler_idx)); + SAFE(jetton_state_assembler_dispatcher(&state_init, + &jettons[jetton_id].code, + &owner, + &master, + jettons[jetton_id].state_assembler_idx)); if (memcmp(state_init.hash, G_context.tx_info.transaction.to.hash, 32) != 0) { return false; @@ -338,7 +395,12 @@ bool process_hints(transaction_t* tx) { SAFE(buffer_read_varuint(&buf, &amount_size, amount_buf, MAX_VALUE_BYTES_LEN)); BitString_storeCoinsBuf(&bits, amount_buf, amount_size); - add_hint_amount(&tx->hints, "Jetton amount", jettons[jetton_id].name, amount_buf, amount_size, jettons[jetton_id].decimals); + add_hint_amount(&tx->hints, + "Jetton amount", + jettons[jetton_id].name, + amount_buf, + amount_size, + jettons[jetton_id].decimals); #else return false; #endif