Skip to content

Commit b3c5c92

Browse files
Merge pull request #9 from ton-blockchain/develop
Hardcoded jettons
2 parents e92bd21 + 49da2a8 commit b3c5c92

File tree

758 files changed

+1310
-2302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

758 files changed

+1310
-2302
lines changed

Makefile

Lines changed: 33 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -21,125 +21,53 @@ endif
2121

2222
include $(BOLOS_SDK)/Makefile.defines
2323

24-
APP_LOAD_PARAMS = --curve ed25519
25-
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
26-
APP_LOAD_PARAMS += --appFlags 0x200 # APPLICATION_FLAG_BOLOS_SETTINGS
27-
else
28-
APP_LOAD_PARAMS += --appFlags 0x000
24+
ifneq ($(TARGET_NAME),TARGET_NANOS)
25+
DEFINES += HAVE_HARDCODED_JETTONS
2926
endif
30-
APP_LOAD_PARAMS += --path "44'/607'"
31-
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)
3227

3328
APPNAME = "TON"
3429
APPVERSION_M = 2
35-
APPVERSION_N = 1
30+
APPVERSION_N = 3
3631
APPVERSION_P = 0
3732
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"
3833

39-
ifeq ($(TARGET_NAME),TARGET_NANOS)
40-
ICONNAME=icons/nanos_app_ton.gif
41-
else ifeq ($(TARGET_NAME),TARGET_STAX)
42-
ICONNAME=icons/ledger_stax_ton_32.gif
43-
else
44-
ICONNAME=icons/nanox_app_ton.gif
45-
endif
46-
47-
all: default
48-
49-
DEFINES += $(DEFINES_LIB)
50-
DEFINES += APPNAME=\"$(APPNAME)\"
51-
DEFINES += APPVERSION=\"$(APPVERSION)\"
52-
DEFINES += MAJOR_VERSION=$(APPVERSION_M) MINOR_VERSION=$(APPVERSION_N) PATCH_VERSION=$(APPVERSION_P)
53-
DEFINES += OS_IO_SEPROXYHAL
54-
DEFINES += HAVE_SPRINTF HAVE_SNPRINTF_FORMAT_U
55-
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=6 IO_HID_EP_LENGTH=64 HAVE_USB_APDU
56-
DEFINES += USB_SEGMENT_SIZE=64
57-
DEFINES += BLE_SEGMENT_SIZE=32
58-
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""
59-
60-
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
61-
DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000 HAVE_BLE_APDU
62-
endif
63-
64-
ifeq ($(TARGET_NAME),TARGET_NANOS)
65-
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
66-
else
67-
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
68-
endif
69-
70-
ifeq ($(TARGET_NAME),TARGET_STAX)
71-
DEFINES += NBGL_QRCODE
72-
SDK_SOURCE_PATH += qrcode
73-
else
74-
DEFINES += HAVE_BAGL HAVE_UX_FLOW
75-
ifneq ($(TARGET_NAME),TARGET_NANOS)
76-
DEFINES += HAVE_GLO096
77-
DEFINES += BAGL_WIDTH=128 BAGL_HEIGHT=64
78-
DEFINES += HAVE_BAGL_ELLIPSIS # long label truncation feature
79-
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
80-
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
81-
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX
82-
endif
83-
endif
84-
85-
DEBUG = 0
86-
ifneq ($(DEBUG),0)
87-
DEFINES += HAVE_PRINTF
88-
ifeq ($(TARGET_NAME),TARGET_NANOS)
89-
DEFINES += PRINTF=screen_printf
90-
else
91-
DEFINES += PRINTF=mcu_usb_printf
92-
endif
93-
else
94-
DEFINES += PRINTF\(...\)=
95-
endif
96-
97-
ifneq ($(BOLOS_ENV),)
98-
$(info BOLOS_ENV=$(BOLOS_ENV))
99-
CLANGPATH := $(BOLOS_ENV)/clang-arm-fropi/bin/
100-
GCCPATH := $(BOLOS_ENV)/gcc-arm-none-eabi-5_3-2016q1/bin/
101-
else
102-
$(info BOLOS_ENV is not set: falling back to CLANGPATH and GCCPATH)
103-
endif
104-
ifeq ($(CLANGPATH),)
105-
$(info CLANGPATH is not set: clang will be used from PATH)
106-
endif
107-
ifeq ($(GCCPATH),)
108-
$(info GCCPATH is not set: arm-none-eabi-* will be used from PATH)
109-
endif
34+
APP_SOURCE_PATH += src
11035

111-
CC := $(CLANGPATH)clang
112-
CFLAGS += -O3 -Os
113-
AS := $(GCCPATH)arm-none-eabi-gcc
114-
LD := $(GCCPATH)arm-none-eabi-gcc
115-
LDFLAGS += -O3 -Os
116-
LDLIBS += -lm -lgcc -lc
36+
ICON_NANOX = icons/nanox_app_ton.gif
37+
ICON_NANOSP = icons/nanox_app_ton.gif
38+
ICON_NANOS = icons/nanos_app_ton.gif
39+
ICON_STAX = icons/ledger_stax_ton_32.gif
40+
ICON_FLEX = icons/ledger_flex_ton_40.gif
11741

118-
include $(BOLOS_SDK)/Makefile.glyphs
42+
CURVE_APP_LOAD_PARAMS = ed25519
11943

120-
APP_SOURCE_PATH += src
121-
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl
44+
PATH_APP_LOAD_PARAMS = "44'/607'"
12245

123-
ifneq ($(TARGET_NAME),TARGET_STAX)
124-
SDK_SOURCE_PATH += lib_ux
125-
endif
126-
127-
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
128-
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
129-
endif
46+
VARIANT_PARAM = COIN
47+
VARIANT_VALUES = TON
13048

131-
load: all
132-
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS)
49+
# DEBUG = 1
13350

134-
load-offline: all
135-
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS) --offline
51+
# HAVE_APPLICATION_FLAG_DERIVE_MASTER = 1
52+
# HAVE_APPLICATION_FLAG_GLOBAL_PIN = 1
53+
# HAVE_APPLICATION_FLAG_BOLOS_SETTINGS = 1
54+
# HAVE_APPLICATION_FLAG_LIBRARY = 1
13655

137-
delete:
138-
python3 -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)
56+
ENABLE_BLUETOOTH = 1
57+
# ENABLE_NFC = 1
13958

140-
include $(BOLOS_SDK)/Makefile.rules
59+
ENABLE_NBGL_QRCODE = 1
60+
# ENABLE_NBGL_KEYBOARD = 1
61+
# ENABLE_NBGL_KEYPAD = 1
14162

142-
dep/%.d: %.c Makefile
63+
# DISABLE_STANDARD_APP_FILES = 1
64+
# DISABLE_DEFAULT_IO_SEPROXY_BUFFER_SIZE = 1 # To allow custom size declaration
65+
# DISABLE_STANDARD_APP_DEFINES = 1 # Will set all the following disablers
66+
# DISABLE_STANDARD_SNPRINTF = 1
67+
# DISABLE_STANDARD_USB = 1
68+
# DISABLE_STANDARD_WEBUSB = 1
69+
# DISABLE_STANDARD_BAGL_UX_FLOW = 1
70+
# DISABLE_DEBUG_LEDGER_ASSERT = 1
71+
# DISABLE_DEBUG_THROW = 1
14372

144-
listvariants:
145-
@echo VARIANTS COIN TON
73+
include $(BOLOS_SDK)/Makefile.standard_app

doc/COMMANDS.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@
4747
Use P2 to control what kind of address to present to user:
4848
* set bit 0x01 to make address testnet only
4949
* set bit 0x02 to use masterchain instead of basechain for the address
50+
* set bit 0x04 to include is_v3r2 flag and subwallet_id
5051

5152
The bip32 path must be at least 3 elements long and must start with the prefix `m/44'/607'/`.
5253

5354
| CLA | INS | P1 | P2 | Lc | CData |
5455
| --- | --- | --- | --- | --- | --- |
55-
| 0xE0 | 0x05 | 0x00 (no display) <br> 0x01 (display) | 0x00-0x03 | 1 + 4n | `len(bip32_path) (1)` \|\|<br> `bip32_path{1} (4)` \|\|<br>`...` \|\|<br>`bip32_path{n} (4)` |
56+
| 0xE0 | 0x05 | 0x00 (no display) <br> 0x01 (display) | 0x00-0x07 | 1 + 4n + (0 or 5) | `len(bip32_path) (1)` \|\|<br> `bip32_path{1} (4)` \|\|<br>`...` \|\|<br>`bip32_path{n} (4)` \|\|<br> (if `P2 & 0x04`) `is_v3r2 (1)` (`0x00` or `0x01`) \|\|<br> (if `P2 & 0x04`) `subwallet_id (4)` |
5657

5758
### Response
5859

@@ -89,6 +90,7 @@ Then an arbitrary number of chunks with transaction data (see [TRANSACTION.md](.
8990
Use P2 to control what kind of address to present to user:
9091
* set bit 0x01 to make address testnet only
9192
* set bit 0x02 to use masterchain instead of basechain for the address
93+
* set bit 0x04 to include is_v3r2 flag and subwallet_id
9294

9395
The bip32 path must be at least 3 elements long and must start with the prefix `m/44'/607'/`.
9496

@@ -98,7 +100,7 @@ Proofs are generated according to this [spec](https://github.com/ton-blockchain/
98100

99101
| CLA | INS | P1 | P2 | Lc | CData |
100102
| --- | --- | --- | --- | --- | --- |
101-
| 0xE0 | 0x08 | 0x01 | 0x00-0x03 | 1 + 4n + 1 + d + 8 + p | `len(bip32_path) (1)` \|\|<br> `bip32_path{1} (4)` \|\|<br>`...` \|\|<br>`bip32_path{n} (4)` \|\|<br> `len(app_domain) == d (1)` \|\|<br> `app_domain (d)` \|\|<br> `timestamp (8)` \|\|<br> `payload (p)` |
103+
| 0xE0 | 0x08 | 0x01 | 0x00-0x03 | 1 + 4n + 1 + d + 8 + p | `len(bip32_path) (1)` \|\|<br> `bip32_path{1} (4)` \|\|<br>`...` \|\|<br>`bip32_path{n} (4)` \|\|<br> (if `P2 & 0x04`) `is_v3r2 (1)` (`0x00` or `0x01`) \|\|<br> (if `P2 & 0x04`) `subwallet_id (4)` \|\|<br> `len(app_domain) == d (1)` \|\|<br> `app_domain (d)` \|\|<br> `timestamp (8)` \|\|<br> `payload (p)` |
102104

103105
### Response
104106

doc/MESSAGES.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ transfer#0f8a7ea5 query_id:uint64 amount:(VarUInteger 16) destination:MsgAddress
4545
### Hints
4646
| Value | Length or type | Description |
4747
| --- | --- | --- |
48-
| `has_query_id` | 1 | Whether `query_id` is present |
49-
| `query_id` | 0 or 8 | `query_id` for the message, 0 will be used if `!has_query_id` |
48+
| `flags` | 1 | Bit +1 - whether `query_id` is present, bit +2 - whether this is a known jetton (bit +2 is not available on nano S) |
49+
| `query_id` | 0 or 8 | `query_id` for the message, 0 will be used if not present. Present only when `flags & 1` |
50+
| `jetton_id` | 0 or 2 | ID of the known jetton. Present only when `flags & 2` |
51+
| `owner_workchain` | 0 or 1 | Workchain of owner. Present only when `flags & 2` |
5052
| `amount` | `varuint` | Jetton amount |
5153
| `destination` | `address` | Whom to transfer jettons to |
5254
| `response_destination` | `address` | Whom to transfer the excess of TON to |

fuzzing/fuzz_tx_parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <sys/types.h>
55

66
extern "C" {
7-
#include "common/buffer.h"
7+
#include "common/mybuffer.h"
88
#include "transaction/deserialize.h"
99
#include "transaction/types.h"
1010
}

icons/ledger_flex_ton_40.gif

194 Bytes
Loading

ledger_app.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[app]
22
build_directory = "./"
33
sdk = "C"
4-
devices = ["nanos", "nanox", "nanos+", "stax"]
4+
devices = ["nanos", "nanox", "nanos+", "stax", "flex"]
55

66
[use_cases]
77
debug = "DEBUG=1"

src/address.c

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,45 +77,93 @@ const uint8_t root_header[] = {
7777
0xd5,
7878
0xc0};
7979

80+
const uint8_t v3r2_root_header[] = {0x2, 0x1, 0x34, 0x0, 0x0, 0x0, 0x0, 0x84, 0xda, 0xfa,
81+
0x44, 0x9f, 0x98, 0xa6, 0x98, 0x77, 0x89, 0xba, 0x23, 0x23,
82+
0x58, 0x7, 0x2b, 0xc0, 0xf7, 0x6d, 0xc4, 0x52, 0x40, 0x2,
83+
0xa5, 0xd0, 0x91, 0x8b, 0x9a, 0x75, 0xd2, 0xd5, 0x99};
84+
8085
const uint8_t data_header[] = {
8186
0x00,
8287
0x51, // Cell header
8388
0x00,
8489
0x00,
8590
0x00,
8691
0x00, // Seqno
87-
0x29,
88-
0xa9,
89-
0xa3,
90-
0x17, // Wallet ID
92+
};
93+
94+
const uint8_t v3r2_data_header[] = {
95+
0x00,
96+
0x50, // Cell header
97+
0x00,
98+
0x00,
99+
0x00,
100+
0x00, // Seqno
91101
};
92102

93103
const uint8_t data_tail[] = {
94104
0x40 // zero bit + padding
95105
};
96106

97-
bool pubkey_to_hash(const uint8_t public_key[static PUBKEY_LEN], uint8_t *out, size_t out_len) {
107+
bool pubkey_to_hash(const uint8_t public_key[static PUBKEY_LEN],
108+
const uint32_t subwallet_id,
109+
const bool is_v3r2,
110+
uint8_t *out,
111+
size_t out_len) {
98112
if (out_len != HASH_LEN) {
99113
return false;
100114
}
101115

102116
uint8_t inner[HASH_LEN] = {0};
103117
cx_sha256_t state;
104118

119+
uint8_t subwallet_buf[4];
120+
subwallet_buf[0] = (subwallet_id >> 24) & 0xff;
121+
subwallet_buf[1] = (subwallet_id >> 16) & 0xff;
122+
subwallet_buf[2] = (subwallet_id >> 8) & 0xff;
123+
subwallet_buf[3] = subwallet_id & 0xff;
124+
105125
// Hash init data cell bits
106126
SAFE(cx_sha256_init_no_throw(&state));
107-
SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, data_header, sizeof(data_header), NULL, 0));
108-
SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, public_key, PUBKEY_LEN, NULL, 0));
109-
SAFE(cx_hash_no_throw((cx_hash_t *) &state,
110-
CX_LAST,
111-
data_tail,
112-
sizeof(data_tail),
113-
inner,
114-
sizeof(inner)));
127+
if (is_v3r2) {
128+
SAFE(cx_hash_no_throw((cx_hash_t *) &state,
129+
0,
130+
v3r2_data_header,
131+
sizeof(v3r2_data_header),
132+
NULL,
133+
0));
134+
} else {
135+
SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, data_header, sizeof(data_header), NULL, 0));
136+
}
137+
SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, subwallet_buf, sizeof(subwallet_buf), NULL, 0));
138+
if (is_v3r2) {
139+
SAFE(cx_hash_no_throw((cx_hash_t *) &state,
140+
CX_LAST,
141+
public_key,
142+
PUBKEY_LEN,
143+
inner,
144+
sizeof(inner)));
145+
} else {
146+
SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, public_key, PUBKEY_LEN, NULL, 0));
147+
SAFE(cx_hash_no_throw((cx_hash_t *) &state,
148+
CX_LAST,
149+
data_tail,
150+
sizeof(data_tail),
151+
inner,
152+
sizeof(inner)));
153+
}
115154

116155
// Hash root
117156
SAFE(cx_sha256_init_no_throw(&state));
118-
SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, root_header, sizeof(root_header), NULL, 0));
157+
if (is_v3r2) {
158+
SAFE(cx_hash_no_throw((cx_hash_t *) &state,
159+
0,
160+
v3r2_root_header,
161+
sizeof(v3r2_root_header),
162+
NULL,
163+
0));
164+
} else {
165+
SAFE(cx_hash_no_throw((cx_hash_t *) &state, 0, root_header, sizeof(root_header), NULL, 0));
166+
}
119167
SAFE(cx_hash_no_throw((cx_hash_t *) &state, CX_LAST, inner, sizeof(inner), out, out_len));
120168

121169
return true;
@@ -125,6 +173,8 @@ bool address_from_pubkey(const uint8_t public_key[static PUBKEY_LEN],
125173
const uint8_t chain,
126174
const bool bounceable,
127175
const bool testOnly,
176+
const uint32_t subwallet_id,
177+
const bool is_v3r2,
128178
uint8_t *out,
129179
size_t out_len) {
130180
if (out_len < ADDRESS_LEN) {
@@ -133,7 +183,7 @@ bool address_from_pubkey(const uint8_t public_key[static PUBKEY_LEN],
133183

134184
uint8_t hash[HASH_LEN] = {0};
135185

136-
if (!pubkey_to_hash(public_key, hash, sizeof(hash))) {
186+
if (!pubkey_to_hash(public_key, subwallet_id, is_v3r2, hash, sizeof(hash))) {
137187
return false;
138188
}
139189

src/address.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
* @param[in] public_key
1313
* Pointer to byte buffer with public key.
1414
* The public key is represented as 32 bytes.
15+
* @param[in] subwallet_id
16+
* Subwallet ID to be used when deriving wallet hash.
17+
* @param[in] is_v3r2
18+
* Whether to use wallet version V3R2 or V4.
1519
* @param[out] out
1620
* Pointer to output byte buffer for address.
1721
* @param[in] out_len
@@ -20,7 +24,11 @@
2024
* @return true if success, false otherwise.
2125
*
2226
*/
23-
bool pubkey_to_hash(const uint8_t public_key[static PUBKEY_LEN], uint8_t *out, size_t out_len);
27+
bool pubkey_to_hash(const uint8_t public_key[static PUBKEY_LEN],
28+
const uint32_t subwallet_id,
29+
const bool is_v3r2,
30+
uint8_t *out,
31+
size_t out_len);
2432

2533
/**
2634
* Convert public key to address. Uses Wallet V4 contract.
@@ -34,6 +42,10 @@ bool pubkey_to_hash(const uint8_t public_key[static PUBKEY_LEN], uint8_t *out, s
3442
* Address have to have bounceable flag set
3543
* @param[in] testOnly
3644
* Address have to have testnet flag set
45+
* @param[in] subwallet_id
46+
* Subwallet ID to be used when deriving wallet address.
47+
* @param[in] is_v3r2
48+
* Whether to use wallet version V3R2 or V4.
3749
* @param[out] out
3850
* Pointer to output byte buffer for address.
3951
* @param[in] out_len
@@ -46,5 +58,7 @@ bool address_from_pubkey(const uint8_t public_key[static PUBKEY_LEN],
4658
const uint8_t chain,
4759
const bool bounceable,
4860
const bool testOnly,
61+
const uint32_t subwallet_id,
62+
const bool is_v3r2,
4963
uint8_t *out,
5064
size_t out_len);

0 commit comments

Comments
 (0)