From b369ed7fafa2365623dac1b0cb38ca0dcb118537 Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Mon, 24 Feb 2020 11:13:56 -0500 Subject: [PATCH 01/18] clean up secret keys after use --- src/algo_keys.c | 46 +++++++++++++++++++++++++++++++++++++--------- src/algo_keys.h | 1 - src/main.c | 36 ++++++++++++++++++++++-------------- 3 files changed, 59 insertions(+), 24 deletions(-) diff --git a/src/algo_keys.c b/src/algo_keys.c index ff50cb01..538b3ec8 100644 --- a/src/algo_keys.c +++ b/src/algo_keys.c @@ -2,16 +2,12 @@ #include "cx.h" #include "algo_keys.h" - -// Allocate 64 bytes for privateKeyData because os_perso_derive_node_bip32 -// appears to write more than 32 bytes to this buffer. However, we only -// need 32 bytes for cx_ecfp_init_private_key.. -static uint8_t privateKeyData[64]; +#include uint8_t publicKey[32]; -void -algorand_key_derive(void) +static void +algorand_key_derive(uint8_t *privateKeyData) { uint32_t bip32Path[5]; @@ -26,7 +22,23 @@ algorand_key_derive(void) void algorand_private_key(cx_ecfp_private_key_t *privateKey) { - cx_ecfp_init_private_key(CX_CURVE_Ed25519, privateKeyData, 32, privateKey); + uint8_t privateKeyData[64]; + + // Zero out returned privateKey + explicit_bzero(privateKey, sizeof(*privateKey)); + + // Derive private key from internal master key, zero out intermediate private + // key data when done + BEGIN_TRY { + TRY { + algorand_key_derive(privateKeyData); + cx_ecfp_init_private_key(CX_CURVE_Ed25519, privateKeyData, 32, privateKey); + } + FINALLY { + explicit_bzero(privateKeyData, sizeof(privateKeyData)); + } + } + END_TRY; } void @@ -35,8 +47,24 @@ algorand_public_key(uint8_t *buf) cx_ecfp_private_key_t privateKey; cx_ecfp_public_key_t publicKey; + // Zero out return buf and publicKey to be computed (in case there is an + // exception before publicKey is filled in) + explicit_bzero(buf, 32); + explicit_bzero(&publicKey, sizeof(publicKey)); + + // Generate private key algorand_private_key(&privateKey); - cx_ecfp_generate_pair(CX_CURVE_Ed25519, &publicKey, &privateKey, 1); + + // Attempt to convert private key to public key, zero out privateKey + BEGIN_TRY { + TRY { + cx_ecfp_generate_pair(CX_CURVE_Ed25519, &publicKey, &privateKey, 1); + } + FINALLY { + explicit_bzero(&privateKey, sizeof(privateKey)); + } + } + END_TRY; // publicKey.W is 65 bytes: a header byte, followed by a 32-byte // x coordinate, followed by a 32-byte y coordinate. The bytes diff --git a/src/algo_keys.h b/src/algo_keys.h index ae3c6c35..3f0acc5d 100644 --- a/src/algo_keys.h +++ b/src/algo_keys.h @@ -2,6 +2,5 @@ extern uint8_t publicKey[32]; -void algorand_key_derive(void); void algorand_private_key(cx_ecfp_private_key_t *privateKey); void algorand_public_key(uint8_t *buf); diff --git a/src/main.c b/src/main.c index bb29d27c..d8088a7d 100644 --- a/src/main.c +++ b/src/main.c @@ -58,22 +58,31 @@ txn_approve() PRINTF("Signing message: %.*h\n", msg_len, msgpack_buf); cx_ecfp_private_key_t privateKey; - algorand_private_key(&privateKey); - int sig_len = cx_eddsa_sign(&privateKey, - 0, CX_SHA512, - &msgpack_buf[0], msg_len, - NULL, 0, - G_io_apdu_buffer, - 6+2*(32+1), // Formerly from cx_compliance_141.c - NULL); + BEGIN_TRY { + TRY { + algorand_private_key(&privateKey); - tx = sig_len; - G_io_apdu_buffer[tx++] = 0x90; - G_io_apdu_buffer[tx++] = 0x00; + int sig_len = cx_eddsa_sign(&privateKey, + 0, CX_SHA512, + &msgpack_buf[0], msg_len, + NULL, 0, + G_io_apdu_buffer, + 6+2*(32+1), // Formerly from cx_compliance_141.c + NULL); - // Send back the response, do not restart the event loop - io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx); + tx = sig_len; + G_io_apdu_buffer[tx++] = 0x90; + G_io_apdu_buffer[tx++] = 0x00; + + // Send back the response, do not restart the event loop + io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx); + } + FINALLY { + explicit_bzero(&privateKey, sizeof(privateKey)); + } + } + END_TRY; // Display back the original UX ui_idle(); @@ -106,7 +115,6 @@ algorand_main(void) volatile unsigned int tx = 0; volatile unsigned int flags = 0; - algorand_key_derive(); algorand_public_key(publicKey); msgpack_next_off = 0; From b1b4a7aefabc67f3dd2ac8f8cc28d2f015d63ebc Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Mon, 24 Feb 2020 14:21:21 -0500 Subject: [PATCH 02/18] throw from put_byte if attempted overrun --- src/algo_tx.c | 4 ++++ src/main.c | 28 +++++++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/algo_tx.c b/src/algo_tx.c index aa45aa89..c36989ab 100644 --- a/src/algo_tx.c +++ b/src/algo_tx.c @@ -9,7 +9,11 @@ put_byte(uint8_t **p, uint8_t *e, uint8_t b) { if (*p < e) { *((*p)++) = b; + return; } + + // Output buffer too short, caller should handle + THROW(0x6760); } static void diff --git a/src/main.c b/src/main.c index d8088a7d..85a53e3c 100644 --- a/src/main.c +++ b/src/main.c @@ -48,19 +48,16 @@ void txn_approve() { unsigned int tx = 0; - unsigned int msg_len; - - msgpack_buf[0] = 'T'; - msgpack_buf[1] = 'X'; - msg_len = 2 + tx_encode(¤t_txn, msgpack_buf+2, sizeof(msgpack_buf)-2); - - PRINTF("Signing message: %.*h\n", msg_len, msgpack_buf); - cx_ecfp_private_key_t privateKey; BEGIN_TRY { TRY { + msgpack_buf[0] = 'T'; + msgpack_buf[1] = 'X'; + msg_len = 2 + tx_encode(¤t_txn, msgpack_buf+2, sizeof(msgpack_buf)-2); + PRINTF("Signing message: %.*h\n", msg_len, msgpack_buf); + algorand_private_key(&privateKey); int sig_len = cx_eddsa_sign(&privateKey, @@ -74,12 +71,17 @@ txn_approve() tx = sig_len; G_io_apdu_buffer[tx++] = 0x90; G_io_apdu_buffer[tx++] = 0x00; - - // Send back the response, do not restart the event loop - io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx); + } + CATCH_OTHER(e) { + // Report error code and return + tx = 0; + G_io_apdu_buffer[tx++] = (e >> 8) & 0xFF; + G_io_apdu_buffer[tx++] = e & 0xFF; } FINALLY { explicit_bzero(&privateKey, sizeof(privateKey)); + // Send back the response, do not restart the event loop + io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx); } } END_TRY; @@ -282,8 +284,8 @@ algorand_main(void) break; } // Unexpected exception => report - G_io_apdu_buffer[tx] = sw >> 8; - G_io_apdu_buffer[tx + 1] = sw; + G_io_apdu_buffer[tx] = (sw >> 8) & 0xFF; + G_io_apdu_buffer[tx + 1] = sw & 0xFF; tx += 2; } FINALLY { From 5afe4587b3eed9b211decf48b11fa3131648622c Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Mon, 24 Feb 2020 14:54:13 -0500 Subject: [PATCH 03/18] move algorand_private_key into TRY, use volatile sw to match existing code --- src/algo_keys.c | 5 ++--- src/main.c | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/algo_keys.c b/src/algo_keys.c index 538b3ec8..fd082647 100644 --- a/src/algo_keys.c +++ b/src/algo_keys.c @@ -52,12 +52,11 @@ algorand_public_key(uint8_t *buf) explicit_bzero(buf, 32); explicit_bzero(&publicKey, sizeof(publicKey)); - // Generate private key - algorand_private_key(&privateKey); - // Attempt to convert private key to public key, zero out privateKey BEGIN_TRY { TRY { + // Generate private key + algorand_private_key(&privateKey); cx_ecfp_generate_pair(CX_CURVE_Ed25519, &publicKey, &privateKey, 1); } FINALLY { diff --git a/src/main.c b/src/main.c index 85a53e3c..55abd4f1 100644 --- a/src/main.c +++ b/src/main.c @@ -50,6 +50,7 @@ txn_approve() unsigned int tx = 0; unsigned int msg_len; cx_ecfp_private_key_t privateKey; + volatile unsigned short sw = 0; BEGIN_TRY { TRY { @@ -61,22 +62,31 @@ txn_approve() algorand_private_key(&privateKey); int sig_len = cx_eddsa_sign(&privateKey, - 0, CX_SHA512, - &msgpack_buf[0], msg_len, - NULL, 0, - G_io_apdu_buffer, - 6+2*(32+1), // Formerly from cx_compliance_141.c - NULL); + 0, CX_SHA512, + &msgpack_buf[0], msg_len, + NULL, 0, + G_io_apdu_buffer, + 6+2*(32+1), // Formerly from cx_compliance_141.c + NULL); tx = sig_len; G_io_apdu_buffer[tx++] = 0x90; G_io_apdu_buffer[tx++] = 0x00; } CATCH_OTHER(e) { - // Report error code and return + // Report error code + switch (e & 0xF000) { + case 0x6000: + case 0x9000: + sw = e; + break; + default: + sw = 0x6800 | (e & 0x7FF); + break; + } tx = 0; - G_io_apdu_buffer[tx++] = (e >> 8) & 0xFF; - G_io_apdu_buffer[tx++] = e & 0xFF; + G_io_apdu_buffer[tx++] = (sw >> 8) & 0xFF; + G_io_apdu_buffer[tx++] = sw & 0xFF; } FINALLY { explicit_bzero(&privateKey, sizeof(privateKey)); From 3940cd425c55cba3284d238e2765d5e30f732988 Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Mon, 24 Feb 2020 14:57:44 -0500 Subject: [PATCH 04/18] fix comment --- src/algo_keys.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/algo_keys.c b/src/algo_keys.c index fd082647..5a65af0d 100644 --- a/src/algo_keys.c +++ b/src/algo_keys.c @@ -52,10 +52,9 @@ algorand_public_key(uint8_t *buf) explicit_bzero(buf, 32); explicit_bzero(&publicKey, sizeof(publicKey)); - // Attempt to convert private key to public key, zero out privateKey + // Attempt to convert private key to public key, zero out privateKey after BEGIN_TRY { TRY { - // Generate private key algorand_private_key(&privateKey); cx_ecfp_generate_pair(CX_CURVE_Ed25519, &publicKey, &privateKey, 1); } From 0ec345c254c7e52b3ddeb077ae1c59a75ab3738e Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Mon, 24 Feb 2020 14:59:26 -0500 Subject: [PATCH 05/18] fix indentation --- src/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 55abd4f1..de9cb72b 100644 --- a/src/main.c +++ b/src/main.c @@ -62,12 +62,12 @@ txn_approve() algorand_private_key(&privateKey); int sig_len = cx_eddsa_sign(&privateKey, - 0, CX_SHA512, - &msgpack_buf[0], msg_len, - NULL, 0, - G_io_apdu_buffer, - 6+2*(32+1), // Formerly from cx_compliance_141.c - NULL); + 0, CX_SHA512, + &msgpack_buf[0], msg_len, + NULL, 0, + G_io_apdu_buffer, + 6+2*(32+1), // Formerly from cx_compliance_141.c + NULL); tx = sig_len; G_io_apdu_buffer[tx++] = 0x90; From 950e66df23275bc20d802fe65a4b5d1ee2fb85ae Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Mon, 24 Feb 2020 15:28:37 -0500 Subject: [PATCH 06/18] move strings include to top --- src/algo_keys.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/algo_keys.c b/src/algo_keys.c index 5a65af0d..8fe0799d 100644 --- a/src/algo_keys.c +++ b/src/algo_keys.c @@ -1,8 +1,9 @@ +#include + #include "os.h" #include "cx.h" #include "algo_keys.h" -#include uint8_t publicKey[32]; From 1c020f0a8b3ed9ba53a0b09c1ea308583dae808c Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Mon, 24 Feb 2020 17:20:04 -0500 Subject: [PATCH 07/18] add back comment about privateKeyData length --- src/algo_keys.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/algo_keys.c b/src/algo_keys.c index 8fe0799d..1d4f7730 100644 --- a/src/algo_keys.c +++ b/src/algo_keys.c @@ -23,6 +23,9 @@ algorand_key_derive(uint8_t *privateKeyData) void algorand_private_key(cx_ecfp_private_key_t *privateKey) { + // Allocate 64 bytes for privateKeyData because os_perso_derive_node_bip32 + // appears to write more than 32 bytes to this buffer. However, we only + // need 32 bytes for cx_ecfp_init_private_key... uint8_t privateKeyData[64]; // Zero out returned privateKey From 5843daf257eb229accf73df0e70abc1b718465ff Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Thu, 12 Mar 2020 14:44:52 -0400 Subject: [PATCH 08/18] add proper exit function --- src/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main.c b/src/main.c index 0cb583b7..3e1b329a 100644 --- a/src/main.c +++ b/src/main.c @@ -388,6 +388,17 @@ io_exchange_al(unsigned char channel, unsigned short tx_len) return 0; } +void app_exit(void) { + BEGIN_TRY_L(exit) { + TRY_L(exit) { + os_sched_exit(-1); + } + FINALLY_L(exit) { + } + } + END_TRY_L(exit); +} + __attribute__((section(".boot"))) int main(void) @@ -431,4 +442,6 @@ main(void) } END_TRY; } + app_exit(); + return 0; } From 275491385b4e54556a5426637e538bafed15f728 Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Thu, 19 Mar 2020 15:51:07 -0400 Subject: [PATCH 09/18] revert key clearning changes, make us match ledgerhq branch --- Makefile | 10 +++---- src/algo_keys.c | 50 +++++++-------------------------- src/algo_keys.h | 1 + src/algo_tx.c | 4 --- src/main.c | 74 ++++++++++++++++++------------------------------- 5 files changed, 43 insertions(+), 96 deletions(-) diff --git a/Makefile b/Makefile index 6942f032..3cda06cf 100755 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ include $(BOLOS_SDK)/Makefile.glyphs # Main app configuration APPNAME = "Algorand" -APPVERSION = 1.0.3 +APPVERSION = 1.0.6 APP_LOAD_PARAMS = --appFlags 0x250 $(COMMON_LOAD_PARAMS) APP_LOAD_PARAMS += --path "44'/283'" @@ -64,11 +64,11 @@ else DEFINES += PRINTF\(...\)= endif -DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=7 IO_HID_EP_LENGTH=64 HAVE_USB_APDU +DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=4 IO_HID_EP_LENGTH=64 HAVE_USB_APDU -# Support for WebUSB transport -WEBUSB_URL = ledger-app.algorand.com -DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=$(shell echo -n $(WEBUSB_URL) | wc -c) WEBUSB_URL=$(shell echo -n $(WEBUSB_URL) | sed -e "s/./\\\'\0\\\',/g") +#WEBUSB_URL = ledger-app.algorand.com +#DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=$(shell echo -n $(WEBUSB_URL) | wc -c) WEBUSB_URL=$(shell echo -n $(WEBUSB_URL) | sed -e "s/./\\\'\0\\\',/g") +DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL="" # Support for U2F transport DEFINES += HAVE_U2F HAVE_IO_U2F U2F_PROXY_MAGIC=\"algo\" USB_SEGMENT_SIZE=64 BLE_SEGMENT_SIZE=32 diff --git a/src/algo_keys.c b/src/algo_keys.c index 1d4f7730..ff50cb01 100644 --- a/src/algo_keys.c +++ b/src/algo_keys.c @@ -1,14 +1,17 @@ -#include - #include "os.h" #include "cx.h" #include "algo_keys.h" +// Allocate 64 bytes for privateKeyData because os_perso_derive_node_bip32 +// appears to write more than 32 bytes to this buffer. However, we only +// need 32 bytes for cx_ecfp_init_private_key.. +static uint8_t privateKeyData[64]; + uint8_t publicKey[32]; -static void -algorand_key_derive(uint8_t *privateKeyData) +void +algorand_key_derive(void) { uint32_t bip32Path[5]; @@ -23,26 +26,7 @@ algorand_key_derive(uint8_t *privateKeyData) void algorand_private_key(cx_ecfp_private_key_t *privateKey) { - // Allocate 64 bytes for privateKeyData because os_perso_derive_node_bip32 - // appears to write more than 32 bytes to this buffer. However, we only - // need 32 bytes for cx_ecfp_init_private_key... - uint8_t privateKeyData[64]; - - // Zero out returned privateKey - explicit_bzero(privateKey, sizeof(*privateKey)); - - // Derive private key from internal master key, zero out intermediate private - // key data when done - BEGIN_TRY { - TRY { - algorand_key_derive(privateKeyData); - cx_ecfp_init_private_key(CX_CURVE_Ed25519, privateKeyData, 32, privateKey); - } - FINALLY { - explicit_bzero(privateKeyData, sizeof(privateKeyData)); - } - } - END_TRY; + cx_ecfp_init_private_key(CX_CURVE_Ed25519, privateKeyData, 32, privateKey); } void @@ -51,22 +35,8 @@ algorand_public_key(uint8_t *buf) cx_ecfp_private_key_t privateKey; cx_ecfp_public_key_t publicKey; - // Zero out return buf and publicKey to be computed (in case there is an - // exception before publicKey is filled in) - explicit_bzero(buf, 32); - explicit_bzero(&publicKey, sizeof(publicKey)); - - // Attempt to convert private key to public key, zero out privateKey after - BEGIN_TRY { - TRY { - algorand_private_key(&privateKey); - cx_ecfp_generate_pair(CX_CURVE_Ed25519, &publicKey, &privateKey, 1); - } - FINALLY { - explicit_bzero(&privateKey, sizeof(privateKey)); - } - } - END_TRY; + algorand_private_key(&privateKey); + cx_ecfp_generate_pair(CX_CURVE_Ed25519, &publicKey, &privateKey, 1); // publicKey.W is 65 bytes: a header byte, followed by a 32-byte // x coordinate, followed by a 32-byte y coordinate. The bytes diff --git a/src/algo_keys.h b/src/algo_keys.h index 3f0acc5d..ae3c6c35 100644 --- a/src/algo_keys.h +++ b/src/algo_keys.h @@ -2,5 +2,6 @@ extern uint8_t publicKey[32]; +void algorand_key_derive(void); void algorand_private_key(cx_ecfp_private_key_t *privateKey); void algorand_public_key(uint8_t *buf); diff --git a/src/algo_tx.c b/src/algo_tx.c index c36989ab..aa45aa89 100644 --- a/src/algo_tx.c +++ b/src/algo_tx.c @@ -9,11 +9,7 @@ put_byte(uint8_t **p, uint8_t *e, uint8_t b) { if (*p < e) { *((*p)++) = b; - return; } - - // Output buffer too short, caller should handle - THROW(0x6760); } static void diff --git a/src/main.c b/src/main.c index 3e1b329a..7941f7ef 100644 --- a/src/main.c +++ b/src/main.c @@ -48,53 +48,32 @@ void txn_approve() { unsigned int tx = 0; + unsigned int msg_len; + + msgpack_buf[0] = 'T'; + msgpack_buf[1] = 'X'; + msg_len = 2 + tx_encode(¤t_txn, msgpack_buf+2, sizeof(msgpack_buf)-2); + + PRINTF("Signing message: %.*h\n", msg_len, msgpack_buf); + cx_ecfp_private_key_t privateKey; - volatile unsigned short sw = 0; - - BEGIN_TRY { - TRY { - msgpack_buf[0] = 'T'; - msgpack_buf[1] = 'X'; - msg_len = 2 + tx_encode(¤t_txn, msgpack_buf+2, sizeof(msgpack_buf)-2); - PRINTF("Signing message: %.*h\n", msg_len, msgpack_buf); - - algorand_private_key(&privateKey); - - int sig_len = cx_eddsa_sign(&privateKey, - 0, CX_SHA512, - &msgpack_buf[0], msg_len, - NULL, 0, - G_io_apdu_buffer, - 6+2*(32+1), // Formerly from cx_compliance_141.c - NULL); - - tx = sig_len; - G_io_apdu_buffer[tx++] = 0x90; - G_io_apdu_buffer[tx++] = 0x00; - } - CATCH_OTHER(e) { - // Report error code - switch (e & 0xF000) { - case 0x6000: - case 0x9000: - sw = e; - break; - default: - sw = 0x6800 | (e & 0x7FF); - break; - } - tx = 0; - G_io_apdu_buffer[tx++] = (sw >> 8) & 0xFF; - G_io_apdu_buffer[tx++] = sw & 0xFF; - } - FINALLY { - explicit_bzero(&privateKey, sizeof(privateKey)); - // Send back the response, do not restart the event loop - io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx); - } - } - END_TRY; + algorand_private_key(&privateKey); + + int sig_len = cx_eddsa_sign(&privateKey, + 0, CX_SHA512, + &msgpack_buf[0], msg_len, + NULL, 0, + G_io_apdu_buffer, + 6+2*(32+1), // Formerly from cx_compliance_141.c + NULL); + + tx = sig_len; + G_io_apdu_buffer[tx++] = 0x90; + G_io_apdu_buffer[tx++] = 0x00; + + // Send back the response, do not restart the event loop + io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx); // Display back the original UX ui_idle(); @@ -127,6 +106,7 @@ algorand_main(void) volatile unsigned int tx = 0; volatile unsigned int flags = 0; + algorand_key_derive(); algorand_public_key(publicKey); msgpack_next_off = 0; @@ -296,8 +276,8 @@ algorand_main(void) break; } // Unexpected exception => report - G_io_apdu_buffer[tx] = (sw >> 8) & 0xFF; - G_io_apdu_buffer[tx + 1] = sw & 0xFF; + G_io_apdu_buffer[tx] = sw >> 8; + G_io_apdu_buffer[tx + 1] = sw; tx += 2; } FINALLY { From 602e366656a6b8b403b38d7b0100018325d5e7cb Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Thu, 19 Mar 2020 15:41:18 -0400 Subject: [PATCH 10/18] fix ble disconnect screensaver freeze --- Makefile | 6 +++-- src/algo_ui.h | 1 + src/main.c | 65 +++++++++++++++++++++++++++++------------------- src/ui_address.c | 18 ++++++++------ src/ui_idle.c | 36 +++++++++++++++++++++++---- 5 files changed, 86 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 3cda06cf..2443dd28 100755 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ include $(BOLOS_SDK)/Makefile.glyphs # Main app configuration APPNAME = "Algorand" -APPVERSION = 1.0.6 +APPVERSION = 1.0.7 APP_LOAD_PARAMS = --appFlags 0x250 $(COMMON_LOAD_PARAMS) APP_LOAD_PARAMS += --path "44'/283'" @@ -26,13 +26,15 @@ SDK_SOURCE_PATH += lib_stusb lib_stusb_impl lib_u2f DEFINES += APPVERSION=\"$(APPVERSION)\" -DEFINES += OS_IO_SEPROXYHAL IO_SEPROXYHAL_BUFFER_SIZE_B=128 +DEFINES += OS_IO_SEPROXYHAL DEFINES += HAVE_BAGL HAVE_SPRINTF DEFINES += HAVE_BOLOS_APP_STACK_CANARY ifeq ($(TARGET_NAME),TARGET_NANOS) DEFINES += HAVE_UX_LEGACY +DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128 else ifeq ($(TARGET_NAME),TARGET_NANOX) +DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300 DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000 DEFINES += HAVE_BLE_APDU diff --git a/src/algo_ui.h b/src/algo_ui.h index 193ecb81..83898431 100644 --- a/src/algo_ui.h +++ b/src/algo_ui.h @@ -5,6 +5,7 @@ extern char lineBuffer[]; extern char text[128]; +void ui_loading(); void ui_idle(); void ui_address(); void ui_txn(); diff --git a/src/main.c b/src/main.c index 7941f7ef..e0939dbe 100644 --- a/src/main.c +++ b/src/main.c @@ -106,9 +106,6 @@ algorand_main(void) volatile unsigned int tx = 0; volatile unsigned int flags = 0; - algorand_key_derive(); - algorand_public_key(publicKey); - msgpack_next_off = 0; #if defined(TARGET_NANOS) @@ -116,13 +113,6 @@ algorand_main(void) UX_CALLBACK_SET_INTERVAL(500); #endif -#if defined(TARGET_NANOX) - // enable bluetooth on nano x - G_io_app.plane_mode = os_setting_get(OS_SETTING_PLANEMODE, NULL, 0); - BLE_power(0, NULL); - BLE_power(1, "Nano X"); -#endif - // DESIGN NOTE: the bootloader ignores the way APDU are fetched. The only // goal is to retrieve APDU. // When APDU are to be fetched from multiple IOs, like NFC+USB+BLE, make @@ -255,6 +245,7 @@ algorand_main(void) } break; case 0xFF: // return to dashboard + CLOSE_TRY; goto return_to_dashboard; default: @@ -296,9 +287,7 @@ io_seproxyhal_display(const bagl_element_t *element) io_seproxyhal_display_default((bagl_element_t *)element); } -unsigned char -io_event(unsigned char channel) -{ +unsigned char io_event(unsigned char channel) { // nothing done with the event, throw an error on the transport layer if // needed @@ -308,29 +297,34 @@ io_event(unsigned char channel) UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer); break; - case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: // for Nano S + case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer); break; + case SEPROXYHAL_TAG_STATUS_EVENT: + if (G_io_apdu_media == IO_APDU_MEDIA_USB_HID && !(U4BE(G_io_seproxyhal_spi_buffer, 3) & SEPROXYHAL_TAG_STATUS_EVENT_FLAG_USB_POWERED)) { + THROW(EXCEPTION_IO_RESET); + } + // no break is intentional + default: + UX_DEFAULT_EVENT(); + break; + case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT: - UX_DISPLAYED_EVENT(); + UX_DISPLAYED_EVENT({}); break; case SEPROXYHAL_TAG_TICKER_EVENT: - UX_TICKER_EVENT(G_io_seproxyhal_spi_buffer, { + UX_TICKER_EVENT(G_io_seproxyhal_spi_buffer, + { #if defined(TARGET_NANOS) - // defaulty retrig very soon (will be overriden during - // stepper_prepro) - UX_CALLBACK_SET_INTERVAL(500); - UX_REDISPLAY(); + // defaulty retrig very soon (will be overriden during + // stepper_prepro) + UX_CALLBACK_SET_INTERVAL(500); + UX_REDISPLAY(); #endif }); break; - - // unknown events are acknowledged - default: - UX_DEFAULT_EVENT(); - break; } // close the event if not done previously (by a display or whatever) @@ -403,18 +397,39 @@ main(void) TRY { io_seproxyhal_init(); +#if defined(TARGET_NANOX) + G_io_app.plane_mode = os_setting_get(OS_SETTING_PLANEMODE, NULL, 0); +#endif + USB_power(0); USB_power(1); + // Display a loading screen before (slowly) deriving keys. BLE_power + // also seems to be a bit slow, so show the loading screen here. + ui_loading(); + +#if defined(TARGET_NANOX) + BLE_power(0, NULL); + BLE_power(1, "Nano X"); +#endif + + // Key derivation is quite slow, and must come *after* the calls to + // BLE_power, otherwise the device will freeze on BLE disconnect on + // the lock screen. + algorand_key_derive(); + algorand_public_key(publicKey); + ui_idle(); algorand_main(); } CATCH(EXCEPTION_IO_RESET) { // Reset IO and UX + CLOSE_TRY; continue; } CATCH_ALL { + CLOSE_TRY; break; } FINALLY { diff --git a/src/ui_address.c b/src/ui_address.c index b906f1e1..31f7d741 100644 --- a/src/ui_address.c +++ b/src/ui_address.c @@ -5,6 +5,7 @@ #include "algo_keys.h" #include "algo_addr.h" +#if defined(TARGET_NANOS) static const bagl_element_t bagl_ui_address_nanos[] = { { {BAGL_RECTANGLE, 0x00, 0, 0, 128, 32, 0, 0, BAGL_FILL, 0x000000, 0xFFFFFF, @@ -48,14 +49,6 @@ bagl_ui_address_nanos_button(unsigned int button_mask, unsigned int button_mask_ return 0; } -void -step_address() -{ - char checksummed[65]; - checksummed_addr(publicKey, checksummed); - ui_text_put(checksummed); -} - void ui_address() { @@ -66,3 +59,12 @@ ui_address() ui_idle(); } } +#endif + +void +step_address() +{ + char checksummed[65]; + checksummed_addr(publicKey, checksummed); + ui_text_put(checksummed); +} diff --git a/src/ui_idle.c b/src/ui_idle.c index 664030fd..c8e5f4ad 100644 --- a/src/ui_idle.c +++ b/src/ui_idle.c @@ -7,15 +7,20 @@ static const ux_menu_entry_t menu_top[]; static const ux_menu_entry_t menu_about[]; static const ux_menu_entry_t menu_about[] = { - {NULL, NULL, 0, NULL, "Version", APPVERSION, 0, 0}, - {menu_top, NULL, 1, NULL, "Back", NULL, 0, 0}, + {NULL, NULL, 0, NULL, "Version", APPVERSION, 0, 0}, + {menu_top, NULL, 1, NULL, "Back", NULL, 0, 0}, UX_MENU_END }; static const ux_menu_entry_t menu_top[] = { - {NULL, ui_address, 0, NULL, "Address", NULL, 0, 0}, - {menu_about, NULL, 0, NULL, "About", NULL, 0, 0}, - {NULL, os_sched_exit, 0, NULL, "Quit app", NULL, 0, 0}, + {NULL, ui_address, 0, NULL, "Address", NULL, 0, 0}, + {menu_about, NULL, 0, NULL, "About", NULL, 0, 0}, + {NULL, os_sched_exit, 0, NULL, "Quit app", NULL, 0, 0}, + UX_MENU_END +}; + +static const ux_menu_entry_t menu_loading[] = { + {NULL, NULL, 0, NULL, "Loading...", "Please wait", 0, 0}, UX_MENU_END }; #endif @@ -31,7 +36,28 @@ const ux_flow_step_t * const ux_idle_flow [] = { &ux_idle_flow_3_step, FLOW_END_STEP, }; + +UX_STEP_NOCB(ux_loading_1_step, bn, {"Loading...", "Please wait"}); +const ux_flow_step_t * const ux_loading_flow [] = { + &ux_loading_1_step, + FLOW_END_STEP, +}; +#endif + +void +ui_loading() +{ +#if defined(TARGET_NANOX) + // reserve a display stack slot if none yet + if(G_ux.stack_count == 0) { + ux_stack_push(); + } + ux_flow_init(0, ux_loading_flow, NULL); +#endif +#if defined(TARGET_NANOS) + UX_MENU_DISPLAY(0, menu_loading, NULL); #endif +} void ui_idle() From 3e51c5f159597b3d76f2cd0eaca17b50c01bca47 Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Thu, 19 Mar 2020 15:59:01 -0400 Subject: [PATCH 11/18] add newline --- src/ui_idle.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui_idle.c b/src/ui_idle.c index c8e5f4ad..dd56f522 100644 --- a/src/ui_idle.c +++ b/src/ui_idle.c @@ -38,6 +38,7 @@ const ux_flow_step_t * const ux_idle_flow [] = { }; UX_STEP_NOCB(ux_loading_1_step, bn, {"Loading...", "Please wait"}); + const ux_flow_step_t * const ux_loading_flow [] = { &ux_loading_1_step, FLOW_END_STEP, From 46bf8a3fa6c4766ec5902c4ecdadcaff424d5e14 Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Thu, 23 Apr 2020 14:32:12 -0400 Subject: [PATCH 12/18] add missing keyreg fields --- src/algo_tx.c | 4 ++ src/algo_tx.h | 4 ++ src/algo_tx_dec.c | 8 +++ src/ui_txn.c | 150 +++++++++++++++++++++++++++------------------- 4 files changed, 105 insertions(+), 61 deletions(-) diff --git a/src/algo_tx.c b/src/algo_tx.c index aa45aa89..0b788f4b 100644 --- a/src/algo_tx.c +++ b/src/algo_tx.c @@ -263,12 +263,16 @@ tx_encode(struct txn *t, uint8_t *buf, int buflen) buf[0] += map_kv_str (&p, e, "gen", t->genesisID, sizeof(t->genesisID)); buf[0] += map_kv_bin (&p, e, "gh", t->genesisHash, sizeof(t->genesisHash)); buf[0] += map_kv_uint64(&p, e, "lv", t->lastValid); + buf[0] += T(KEYREG, map_kv_bool (&p, e, "nonpart", t->keyreg.nonpartFlag)); buf[0] += map_kv_bin (&p, e, "note", t->note, t->note_len); buf[0] += T(PAYMENT, map_kv_bin (&p, e, "rcv", t->payment.receiver, sizeof(t->payment.receiver))); buf[0] += T(KEYREG, map_kv_bin (&p, e, "selkey", t->keyreg.vrfpk, sizeof(t->keyreg.vrfpk))); buf[0] += map_kv_bin (&p, e, "snd", t->sender, sizeof(t->sender)); buf[0] += map_kv_str (&p, e, "type", typestr, SIZE_MAX); + buf[0] += T(KEYREG, map_kv_uint64(&p, e, "votefst", t->keyreg.voteFirst)); + buf[0] += T(KEYREG, map_kv_uint64(&p, e, "votekd", t->keyreg.keyDilution)); buf[0] += T(KEYREG, map_kv_bin (&p, e, "votekey", t->keyreg.votepk, sizeof(t->keyreg.votepk))); + buf[0] += T(KEYREG, map_kv_uint64(&p, e, "votelst", t->keyreg.voteLast)); buf[0] += T(ASSET_XFER, map_kv_uint64(&p, e, "xaid", t->asset_xfer.id)); #undef T diff --git a/src/algo_tx.h b/src/algo_tx.h index ccba93f5..9006493b 100644 --- a/src/algo_tx.h +++ b/src/algo_tx.h @@ -33,6 +33,10 @@ struct txn_payment { struct txn_keyreg { uint8_t votepk[32]; uint8_t vrfpk[32]; + uint64_t voteFirst; + uint64_t voteLast; + uint64_t keyDilution; + uint8_t nonpartFlag; }; struct txn_asset_xfer { diff --git a/src/algo_tx_dec.c b/src/algo_tx_dec.c index f8f5e053..8c8a67c5 100644 --- a/src/algo_tx_dec.c +++ b/src/algo_tx_dec.c @@ -274,6 +274,14 @@ tx_decode(uint8_t *buf, int buflen, struct txn *t) decode_bin_fixed(&buf, buf_end, t->keyreg.vrfpk, sizeof(t->keyreg.vrfpk)); } else if (!strcmp(key, "votekey")) { decode_bin_fixed(&buf, buf_end, t->keyreg.votepk, sizeof(t->keyreg.votepk)); + } else if (!strcmp(key, "votefst")) { + decode_uint64(&buf, buf_end, &t->keyreg.voteFirst); + } else if (!strcmp(key, "votelst")) { + decode_uint64(&buf, buf_end, &t->keyreg.voteLast); + } else if (!strcmp(key, "votekd")) { + decode_uint64(&buf, buf_end, &t->keyreg.keyDilution); + } else if (!strcmp(key, "nonpart")) { + decode_bool(&buf, buf_end, &t->keyreg.nonpartFlag); } else if (!strcmp(key, "aamt")) { decode_uint64(&buf, buf_end, &t->asset_xfer.amount); } else if (!strcmp(key, "aclose")) { diff --git a/src/ui_txn.c b/src/ui_txn.c index 055f7c3a..71900a39 100644 --- a/src/ui_txn.c +++ b/src/ui_txn.c @@ -180,6 +180,25 @@ static int step_vrfpk() { return 1; } +static int step_votefirst() { + ui_text_put(u64str(current_txn.keyreg.voteFirst)); + return 1; +} + +static int step_votelast() { + ui_text_put(u64str(current_txn.keyreg.voteLast)); + return 1; +} + +static int step_nonpart() { + if (current_txn.keyreg.nonpartFlag) { + ui_text_put("True"); + } else { + ui_text_put("False"); + } + return 1; +} + static int step_asset_xfer_id() { ui_text_put(u64str(current_txn.asset_xfer.id)); return 1; @@ -369,34 +388,37 @@ ALGO_UX_STEP_NOCB_INIT(PAYMENT, 8, bnnn_paging, step_receiver(), {"Receiver", ALGO_UX_STEP_NOCB_INIT(PAYMENT, 9, bn, step_amount(), {"Amount (uAlg)", text}); ALGO_UX_STEP_NOCB_INIT(PAYMENT, 10, bnnn_paging, step_close(), {"Close to", text}); -ALGO_UX_STEP_NOCB_INIT(KEYREG, 11, bnnn_paging, step_votepk(), {"Vote PK", text}); -ALGO_UX_STEP_NOCB_INIT(KEYREG, 12, bnnn_paging, step_vrfpk(), {"VRF PK", text}); - -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 13, bn, step_asset_xfer_id(), {"Asset ID", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 14, bn, step_asset_xfer_amount(), {"Asset amt", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 15, bnnn_paging, step_asset_xfer_sender(), {"Asset src", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 16, bnnn_paging, step_asset_xfer_receiver(), {"Asset dst", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 17, bnnn_paging, step_asset_xfer_close(), {"Asset close", text}); - -ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 18, bn, step_asset_freeze_id(), {"Asset ID", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 19, bnnn_paging, step_asset_freeze_account(), {"Asset account", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 20, bn, step_asset_freeze_flag(), {"Freeze flag", text}); - -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 21, bn, step_asset_config_id(), {"Asset ID", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 22, bn, step_asset_config_total(), {"Total units", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 23, bn, step_asset_config_default_frozen(), {"Default frozen", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 24, bnnn_paging, step_asset_config_unitname(), {"Unit name", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 25, bn, step_asset_config_decimals(), {"Decimals", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 26, bnnn_paging, step_asset_config_assetname(), {"Asset name", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 27, bnnn_paging, step_asset_config_url(), {"URL", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 28, bnnn_paging, step_asset_config_metadata_hash(), {"Metadata hash", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 29, bnnn_paging, step_asset_config_manager(), {"Manager", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 30, bnnn_paging, step_asset_config_reserve(), {"Reserve", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 31, bnnn_paging, step_asset_config_freeze(), {"Freezer", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 32, bnnn_paging, step_asset_config_clawback(), {"Clawback", text}); - -ALGO_UX_STEP(33, pbb, NULL, 0, txn_approve(), NULL, {&C_icon_validate_14, "Sign", "transaction"}); -ALGO_UX_STEP(34, pbb, NULL, 0, txn_deny(), NULL, {&C_icon_crossmark, "Cancel", "signature"}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 11, bnnn_paging, step_votepk(), {"Vote PK", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 12, bnnn_paging, step_vrfpk(), {"VRF PK", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 13, bn, step_votefirst(), {"Vote first", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 14, bn, step_votelast(), {"Vote last", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 15, bn, step_nonpart(), {"Nonparticipating", text}); + +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 16, bn, step_asset_xfer_id(), {"Asset ID", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 17, bn, step_asset_xfer_amount(), {"Asset amt", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 18, bnnn_paging, step_asset_xfer_sender(), {"Asset src", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 19, bnnn_paging, step_asset_xfer_receiver(), {"Asset dst", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 20, bnnn_paging, step_asset_xfer_close(), {"Asset close", text}); + +ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 21, bn, step_asset_freeze_id(), {"Asset ID", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 22, bnnn_paging, step_asset_freeze_account(), {"Asset account", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 23, bn, step_asset_freeze_flag(), {"Freeze flag", text}); + +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 24, bn, step_asset_config_id(), {"Asset ID", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 25, bn, step_asset_config_total(), {"Total units", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 26, bn, step_asset_config_default_frozen(), {"Default frozen", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 27, bnnn_paging, step_asset_config_unitname(), {"Unit name", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 28, bn, step_asset_config_decimals(), {"Decimals", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 29, bnnn_paging, step_asset_config_assetname(), {"Asset name", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 30, bnnn_paging, step_asset_config_url(), {"URL", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 31, bnnn_paging, step_asset_config_metadata_hash(), {"Metadata hash", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 32, bnnn_paging, step_asset_config_manager(), {"Manager", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 33, bnnn_paging, step_asset_config_reserve(), {"Reserve", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 34, bnnn_paging, step_asset_config_freeze(), {"Freezer", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 35, bnnn_paging, step_asset_config_clawback(), {"Clawback", text}); + +ALGO_UX_STEP(36, pbb, NULL, 0, txn_approve(), NULL, {&C_icon_validate_14, "Sign", "transaction"}); +ALGO_UX_STEP(37, pbb, NULL, 0, txn_deny(), NULL, {&C_icon_crossmark, "Cancel", "signature"}); const ux_flow_step_t * const ux_txn_flow [] = { &txn_flow_0, @@ -434,6 +456,9 @@ const ux_flow_step_t * const ux_txn_flow [] = { &txn_flow_32, &txn_flow_33, &txn_flow_34, + &txn_flow_35, + &txn_flow_36, + &txn_flow_37, FLOW_END_STEP, }; #endif // TARGET_NANOX @@ -451,39 +476,42 @@ struct ux_step { static unsigned int ux_current_step; static const struct ux_step ux_steps[] = { - { ALL_TYPES, "Txn type", &step_txn_type }, - { ALL_TYPES, "Sender", &step_sender }, - { ALL_TYPES, "Fee (uAlg)", &step_fee }, - { ALL_TYPES, "First valid", &step_firstvalid }, - { ALL_TYPES, "Last valid", &step_lastvalid }, - { ALL_TYPES, "Genesis ID", &step_genesisID }, - { ALL_TYPES, "Genesis hash", &step_genesisHash }, - { ALL_TYPES, "Note", &step_note }, - { PAYMENT, "Receiver", &step_receiver }, - { PAYMENT, "Amount (uAlg)", &step_amount }, - { PAYMENT, "Close to", &step_close }, - { KEYREG, "Vote PK", &step_votepk }, - { KEYREG, "VRF PK", &step_vrfpk }, - { ASSET_XFER, "Asset ID", &step_asset_xfer_id }, - { ASSET_XFER, "Asset amt", &step_asset_xfer_amount }, - { ASSET_XFER, "Asset src", &step_asset_xfer_sender }, - { ASSET_XFER, "Asset dst", &step_asset_xfer_receiver }, - { ASSET_XFER, "Asset close", &step_asset_xfer_close }, - { ASSET_FREEZE, "Asset ID", &step_asset_freeze_id }, - { ASSET_FREEZE, "Asset account", &step_asset_freeze_account }, - { ASSET_FREEZE, "Freeze flag", &step_asset_freeze_flag }, - { ASSET_CONFIG, "Asset ID", &step_asset_config_id }, - { ASSET_CONFIG, "Total units", &step_asset_config_total }, - { ASSET_CONFIG, "Default frozen", &step_asset_config_default_frozen }, - { ASSET_CONFIG, "Unit name", &step_asset_config_unitname }, - { ASSET_CONFIG, "Decimals", &step_asset_config_decimals }, - { ASSET_CONFIG, "Asset name", &step_asset_config_assetname }, - { ASSET_CONFIG, "URL", &step_asset_config_url }, - { ASSET_CONFIG, "Metadata hash", &step_asset_config_metadata_hash }, - { ASSET_CONFIG, "Manager", &step_asset_config_manager }, - { ASSET_CONFIG, "Reserve", &step_asset_config_reserve }, - { ASSET_CONFIG, "Freezer", &step_asset_config_freeze }, - { ASSET_CONFIG, "Clawback", &step_asset_config_clawback }, + { ALL_TYPES, "Txn type", &step_txn_type }, + { ALL_TYPES, "Sender", &step_sender }, + { ALL_TYPES, "Fee (uAlg)", &step_fee }, + { ALL_TYPES, "First valid", &step_firstvalid }, + { ALL_TYPES, "Last valid", &step_lastvalid }, + { ALL_TYPES, "Genesis ID", &step_genesisID }, + { ALL_TYPES, "Genesis hash", &step_genesisHash }, + { ALL_TYPES, "Note", &step_note }, + { PAYMENT, "Receiver", &step_receiver }, + { PAYMENT, "Amount (uAlg)", &step_amount }, + { PAYMENT, "Close to", &step_close }, + { KEYREG, "Vote PK", &step_votepk }, + { KEYREG, "VRF PK", &step_vrfpk }, + { KEYREG, "Vote first", &step_votefirst }, + { KEYREG, "Vote last", &step_votelast }, + { KEYREG, "Nonparticipating", &step_nonpart }, + { ASSET_XFER, "Asset ID", &step_asset_xfer_id }, + { ASSET_XFER, "Asset amt", &step_asset_xfer_amount }, + { ASSET_XFER, "Asset src", &step_asset_xfer_sender }, + { ASSET_XFER, "Asset dst", &step_asset_xfer_receiver }, + { ASSET_XFER, "Asset close", &step_asset_xfer_close }, + { ASSET_FREEZE, "Asset ID", &step_asset_freeze_id }, + { ASSET_FREEZE, "Asset account", &step_asset_freeze_account }, + { ASSET_FREEZE, "Freeze flag", &step_asset_freeze_flag }, + { ASSET_CONFIG, "Asset ID", &step_asset_config_id }, + { ASSET_CONFIG, "Total units", &step_asset_config_total }, + { ASSET_CONFIG, "Default frozen", &step_asset_config_default_frozen }, + { ASSET_CONFIG, "Unit name", &step_asset_config_unitname }, + { ASSET_CONFIG, "Decimals", &step_asset_config_decimals }, + { ASSET_CONFIG, "Asset name", &step_asset_config_assetname }, + { ASSET_CONFIG, "URL", &step_asset_config_url }, + { ASSET_CONFIG, "Metadata hash", &step_asset_config_metadata_hash }, + { ASSET_CONFIG, "Manager", &step_asset_config_manager }, + { ASSET_CONFIG, "Reserve", &step_asset_config_reserve }, + { ASSET_CONFIG, "Freezer", &step_asset_config_freeze }, + { ASSET_CONFIG, "Clawback", &step_asset_config_clawback }, }; static const bagl_element_t bagl_ui_approval_nanos[] = { From cc7b8599d24ff3566d1e01de795b3aa076e08c5f Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Fri, 24 Apr 2020 14:47:29 -0400 Subject: [PATCH 13/18] add rekey support --- src/algo_tx.c | 1 + src/algo_tx.h | 1 + src/algo_tx_dec.c | 2 + src/ui_txn.c | 98 +++++++++++++++++++++++++++-------------------- 4 files changed, 60 insertions(+), 42 deletions(-) diff --git a/src/algo_tx.c b/src/algo_tx.c index 0b788f4b..90062f0d 100644 --- a/src/algo_tx.c +++ b/src/algo_tx.c @@ -266,6 +266,7 @@ tx_encode(struct txn *t, uint8_t *buf, int buflen) buf[0] += T(KEYREG, map_kv_bool (&p, e, "nonpart", t->keyreg.nonpartFlag)); buf[0] += map_kv_bin (&p, e, "note", t->note, t->note_len); buf[0] += T(PAYMENT, map_kv_bin (&p, e, "rcv", t->payment.receiver, sizeof(t->payment.receiver))); + buf[0] += map_kv_bin (&p, e, "rekey", t->rekey, sizeof(t->rekey)); buf[0] += T(KEYREG, map_kv_bin (&p, e, "selkey", t->keyreg.vrfpk, sizeof(t->keyreg.vrfpk))); buf[0] += map_kv_bin (&p, e, "snd", t->sender, sizeof(t->sender)); buf[0] += map_kv_str (&p, e, "type", typestr, SIZE_MAX); diff --git a/src/algo_tx.h b/src/algo_tx.h index 9006493b..6c6f0f64 100644 --- a/src/algo_tx.h +++ b/src/algo_tx.h @@ -63,6 +63,7 @@ struct txn { // Common header fields uint8_t sender[32]; + uint8_t rekey[32]; uint64_t fee; uint64_t firstValid; uint64_t lastValid; diff --git a/src/algo_tx_dec.c b/src/algo_tx_dec.c index 8c8a67c5..862a3385 100644 --- a/src/algo_tx_dec.c +++ b/src/algo_tx_dec.c @@ -252,6 +252,8 @@ tx_decode(uint8_t *buf, int buflen, struct txn *t) } } else if (!strcmp(key, "snd")) { decode_bin_fixed(&buf, buf_end, t->sender, sizeof(t->sender)); + } else if (!strcmp(key, "rekey")) { + decode_bin_fixed(&buf, buf_end, t->rekey, sizeof(t->rekey)); } else if (!strcmp(key, "fee")) { decode_uint64(&buf, buf_end, &t->fee); } else if (!strcmp(key, "fv")) { diff --git a/src/ui_txn.c b/src/ui_txn.c index 71900a39..366ea9e1 100644 --- a/src/ui_txn.c +++ b/src/ui_txn.c @@ -81,6 +81,17 @@ static int step_sender() { return 1; } +static int step_rekey() { + if (all_zero_key(current_txn.rekey)) { + return 0; + } + + char checksummed[65]; + checksummed_addr(current_txn.rekey, checksummed); + ui_text_put(checksummed); + return 1; +} + static int step_fee() { ui_text_put(u64str(current_txn.fee)); return 1; @@ -377,48 +388,49 @@ static unsigned int ux_last_step; ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 0, bn, step_txn_type(), {"Txn type", text}); ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 1, bnnn_paging, step_sender(), {"Sender", text}); -ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 2, bn, step_fee(), {"Fee (uAlg)", text}); -ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 3, bn, step_firstvalid(), {"First valid", text}); -ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 4, bn, step_lastvalid(), {"Last valid", text}); -ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 5, bn, step_genesisID(), {"Genesis ID", text}); -ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 6, bnnn_paging, step_genesisHash(), {"Genesis hash", text}); -ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 7, bn, step_note(), {"Note", text}); - -ALGO_UX_STEP_NOCB_INIT(PAYMENT, 8, bnnn_paging, step_receiver(), {"Receiver", text}); -ALGO_UX_STEP_NOCB_INIT(PAYMENT, 9, bn, step_amount(), {"Amount (uAlg)", text}); -ALGO_UX_STEP_NOCB_INIT(PAYMENT, 10, bnnn_paging, step_close(), {"Close to", text}); - -ALGO_UX_STEP_NOCB_INIT(KEYREG, 11, bnnn_paging, step_votepk(), {"Vote PK", text}); -ALGO_UX_STEP_NOCB_INIT(KEYREG, 12, bnnn_paging, step_vrfpk(), {"VRF PK", text}); -ALGO_UX_STEP_NOCB_INIT(KEYREG, 13, bn, step_votefirst(), {"Vote first", text}); -ALGO_UX_STEP_NOCB_INIT(KEYREG, 14, bn, step_votelast(), {"Vote last", text}); -ALGO_UX_STEP_NOCB_INIT(KEYREG, 15, bn, step_nonpart(), {"Nonparticipating", text}); - -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 16, bn, step_asset_xfer_id(), {"Asset ID", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 17, bn, step_asset_xfer_amount(), {"Asset amt", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 18, bnnn_paging, step_asset_xfer_sender(), {"Asset src", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 19, bnnn_paging, step_asset_xfer_receiver(), {"Asset dst", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 20, bnnn_paging, step_asset_xfer_close(), {"Asset close", text}); - -ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 21, bn, step_asset_freeze_id(), {"Asset ID", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 22, bnnn_paging, step_asset_freeze_account(), {"Asset account", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 23, bn, step_asset_freeze_flag(), {"Freeze flag", text}); - -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 24, bn, step_asset_config_id(), {"Asset ID", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 25, bn, step_asset_config_total(), {"Total units", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 26, bn, step_asset_config_default_frozen(), {"Default frozen", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 27, bnnn_paging, step_asset_config_unitname(), {"Unit name", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 28, bn, step_asset_config_decimals(), {"Decimals", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 29, bnnn_paging, step_asset_config_assetname(), {"Asset name", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 30, bnnn_paging, step_asset_config_url(), {"URL", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 31, bnnn_paging, step_asset_config_metadata_hash(), {"Metadata hash", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 32, bnnn_paging, step_asset_config_manager(), {"Manager", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 33, bnnn_paging, step_asset_config_reserve(), {"Reserve", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 34, bnnn_paging, step_asset_config_freeze(), {"Freezer", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 35, bnnn_paging, step_asset_config_clawback(), {"Clawback", text}); - -ALGO_UX_STEP(36, pbb, NULL, 0, txn_approve(), NULL, {&C_icon_validate_14, "Sign", "transaction"}); -ALGO_UX_STEP(37, pbb, NULL, 0, txn_deny(), NULL, {&C_icon_crossmark, "Cancel", "signature"}); +ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 2, bnnn_paging, step_rekey(), {"RekeyTo", text}); +ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 3, bn, step_fee(), {"Fee (uAlg)", text}); +ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 4, bn, step_firstvalid(), {"First valid", text}); +ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 5, bn, step_lastvalid(), {"Last valid", text}); +ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 6, bn, step_genesisID(), {"Genesis ID", text}); +ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 7, bnnn_paging, step_genesisHash(), {"Genesis hash", text}); +ALGO_UX_STEP_NOCB_INIT(ALL_TYPES, 8, bn, step_note(), {"Note", text}); + +ALGO_UX_STEP_NOCB_INIT(PAYMENT, 9, bnnn_paging, step_receiver(), {"Receiver", text}); +ALGO_UX_STEP_NOCB_INIT(PAYMENT, 10, bn, step_amount(), {"Amount (uAlg)", text}); +ALGO_UX_STEP_NOCB_INIT(PAYMENT, 11, bnnn_paging, step_close(), {"Close to", text}); + +ALGO_UX_STEP_NOCB_INIT(KEYREG, 12, bnnn_paging, step_votepk(), {"Vote PK", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 13, bnnn_paging, step_vrfpk(), {"VRF PK", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 14, bn, step_votefirst(), {"Vote first", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 15, bn, step_votelast(), {"Vote last", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 16, bn, step_nonpart(), {"Nonparticipating", text}); + +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 17, bn, step_asset_xfer_id(), {"Asset ID", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 18, bn, step_asset_xfer_amount(), {"Asset amt", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 19, bnnn_paging, step_asset_xfer_sender(), {"Asset src", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 20, bnnn_paging, step_asset_xfer_receiver(), {"Asset dst", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 21, bnnn_paging, step_asset_xfer_close(), {"Asset close", text}); + +ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 22, bn, step_asset_freeze_id(), {"Asset ID", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 23, bnnn_paging, step_asset_freeze_account(), {"Asset account", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 24, bn, step_asset_freeze_flag(), {"Freeze flag", text}); + +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 25, bn, step_asset_config_id(), {"Asset ID", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 26, bn, step_asset_config_total(), {"Total units", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 27, bn, step_asset_config_default_frozen(), {"Default frozen", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 28, bnnn_paging, step_asset_config_unitname(), {"Unit name", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 29, bn, step_asset_config_decimals(), {"Decimals", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 30, bnnn_paging, step_asset_config_assetname(), {"Asset name", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 31, bnnn_paging, step_asset_config_url(), {"URL", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 32, bnnn_paging, step_asset_config_metadata_hash(), {"Metadata hash", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 33, bnnn_paging, step_asset_config_manager(), {"Manager", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 34, bnnn_paging, step_asset_config_reserve(), {"Reserve", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 35, bnnn_paging, step_asset_config_freeze(), {"Freezer", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 36, bnnn_paging, step_asset_config_clawback(), {"Clawback", text}); + +ALGO_UX_STEP(37, pbb, NULL, 0, txn_approve(), NULL, {&C_icon_validate_14, "Sign", "transaction"}); +ALGO_UX_STEP(38, pbb, NULL, 0, txn_deny(), NULL, {&C_icon_crossmark, "Cancel", "signature"}); const ux_flow_step_t * const ux_txn_flow [] = { &txn_flow_0, @@ -459,6 +471,7 @@ const ux_flow_step_t * const ux_txn_flow [] = { &txn_flow_35, &txn_flow_36, &txn_flow_37, + &txn_flow_38, FLOW_END_STEP, }; #endif // TARGET_NANOX @@ -478,6 +491,7 @@ static unsigned int ux_current_step; static const struct ux_step ux_steps[] = { { ALL_TYPES, "Txn type", &step_txn_type }, { ALL_TYPES, "Sender", &step_sender }, + { ALL_TYPES, "RekeyTo", &step_rekey }, { ALL_TYPES, "Fee (uAlg)", &step_fee }, { ALL_TYPES, "First valid", &step_firstvalid }, { ALL_TYPES, "Last valid", &step_lastvalid }, From d436624408e33a189ad17f7eb33f971b2fe78136 Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Mon, 27 Apr 2020 15:40:42 -0400 Subject: [PATCH 14/18] use -Oz instead of -Os --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2443dd28..cf077b79 100755 --- a/Makefile +++ b/Makefile @@ -94,13 +94,13 @@ $(info GCCPATH is not set: arm-none-eabi-* will be used from PATH) endif CC := $(CLANGPATH)clang -CFLAGS += -O3 -Os +CFLAGS += -O3 -Oz AS := $(GCCPATH)arm-none-eabi-gcc AFLAGS += LD := $(GCCPATH)arm-none-eabi-gcc -LDFLAGS += -O3 -Os +LDFLAGS += -O3 -Oz LDLIBS += -lm -lgcc -lc # Main rules From 8ad3dd88ee82ff9396bf9834853ce0db5d34ae0d Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Mon, 27 Apr 2020 16:14:19 -0400 Subject: [PATCH 15/18] reduce max note size on nano x --- src/algo_tx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algo_tx.h b/src/algo_tx.h index 6c6f0f64..a7980e4b 100644 --- a/src/algo_tx.h +++ b/src/algo_tx.h @@ -71,7 +71,7 @@ struct txn { uint8_t genesisHash[32]; #if defined(TARGET_NANOX) - uint8_t note[1024]; + uint8_t note[512]; #else uint8_t note[32]; #endif From be6df62f1d12a0dd6f2be7b5cedaa60b562ee46e Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Wed, 3 Jun 2020 15:24:03 -0400 Subject: [PATCH 16/18] change nonparticipating -> participating --- src/ui_txn.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ui_txn.c b/src/ui_txn.c index 366ea9e1..64a0ae2f 100644 --- a/src/ui_txn.c +++ b/src/ui_txn.c @@ -201,11 +201,11 @@ static int step_votelast() { return 1; } -static int step_nonpart() { +static int step_participating() { if (current_txn.keyreg.nonpartFlag) { - ui_text_put("True"); + ui_text_put("No"); } else { - ui_text_put("False"); + ui_text_put("Yes"); } return 1; } @@ -400,11 +400,11 @@ ALGO_UX_STEP_NOCB_INIT(PAYMENT, 9, bnnn_paging, step_receiver(), {"Receiver", ALGO_UX_STEP_NOCB_INIT(PAYMENT, 10, bn, step_amount(), {"Amount (uAlg)", text}); ALGO_UX_STEP_NOCB_INIT(PAYMENT, 11, bnnn_paging, step_close(), {"Close to", text}); -ALGO_UX_STEP_NOCB_INIT(KEYREG, 12, bnnn_paging, step_votepk(), {"Vote PK", text}); -ALGO_UX_STEP_NOCB_INIT(KEYREG, 13, bnnn_paging, step_vrfpk(), {"VRF PK", text}); -ALGO_UX_STEP_NOCB_INIT(KEYREG, 14, bn, step_votefirst(), {"Vote first", text}); -ALGO_UX_STEP_NOCB_INIT(KEYREG, 15, bn, step_votelast(), {"Vote last", text}); -ALGO_UX_STEP_NOCB_INIT(KEYREG, 16, bn, step_nonpart(), {"Nonparticipating", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 12, bnnn_paging, step_votepk(), {"Vote PK", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 13, bnnn_paging, step_vrfpk(), {"VRF PK", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 14, bn, step_votefirst(), {"Vote first", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 15, bn, step_votelast(), {"Vote last", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 16, bn, step_participating(), {"Participating", text}); ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 17, bn, step_asset_xfer_id(), {"Asset ID", text}); ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 18, bn, step_asset_xfer_amount(), {"Asset amt", text}); @@ -505,7 +505,7 @@ static const struct ux_step ux_steps[] = { { KEYREG, "VRF PK", &step_vrfpk }, { KEYREG, "Vote first", &step_votefirst }, { KEYREG, "Vote last", &step_votelast }, - { KEYREG, "Nonparticipating", &step_nonpart }, + { KEYREG, "Participating", &step_participating }, { ASSET_XFER, "Asset ID", &step_asset_xfer_id }, { ASSET_XFER, "Asset amt", &step_asset_xfer_amount }, { ASSET_XFER, "Asset src", &step_asset_xfer_sender }, From 724fa098c5705849c4eef221df099aad607dfdba Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Wed, 3 Jun 2020 15:24:24 -0400 Subject: [PATCH 17/18] bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cf077b79..875e298e 100755 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ include $(BOLOS_SDK)/Makefile.glyphs # Main app configuration APPNAME = "Algorand" -APPVERSION = 1.0.7 +APPVERSION = 1.0.8 APP_LOAD_PARAMS = --appFlags 0x250 $(COMMON_LOAD_PARAMS) APP_LOAD_PARAMS += --path "44'/283'" From 4fe8727210c0ca3f4988dc9a8c23ec88d32e5255 Mon Sep 17 00:00:00 2001 From: Max Justicz Date: Wed, 3 Jun 2020 16:16:45 -0400 Subject: [PATCH 18/18] add key dilution step --- src/ui_txn.c | 62 +++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/ui_txn.c b/src/ui_txn.c index 64a0ae2f..34ec43ec 100644 --- a/src/ui_txn.c +++ b/src/ui_txn.c @@ -201,6 +201,11 @@ static int step_votelast() { return 1; } +static int step_keydilution() { + ui_text_put(u64str(current_txn.keyreg.keyDilution)); + return 1; +} + static int step_participating() { if (current_txn.keyreg.nonpartFlag) { ui_text_put("No"); @@ -404,33 +409,34 @@ ALGO_UX_STEP_NOCB_INIT(KEYREG, 12, bnnn_paging, step_votepk(), {"Vote PK" ALGO_UX_STEP_NOCB_INIT(KEYREG, 13, bnnn_paging, step_vrfpk(), {"VRF PK", text}); ALGO_UX_STEP_NOCB_INIT(KEYREG, 14, bn, step_votefirst(), {"Vote first", text}); ALGO_UX_STEP_NOCB_INIT(KEYREG, 15, bn, step_votelast(), {"Vote last", text}); -ALGO_UX_STEP_NOCB_INIT(KEYREG, 16, bn, step_participating(), {"Participating", text}); - -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 17, bn, step_asset_xfer_id(), {"Asset ID", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 18, bn, step_asset_xfer_amount(), {"Asset amt", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 19, bnnn_paging, step_asset_xfer_sender(), {"Asset src", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 20, bnnn_paging, step_asset_xfer_receiver(), {"Asset dst", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 21, bnnn_paging, step_asset_xfer_close(), {"Asset close", text}); - -ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 22, bn, step_asset_freeze_id(), {"Asset ID", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 23, bnnn_paging, step_asset_freeze_account(), {"Asset account", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 24, bn, step_asset_freeze_flag(), {"Freeze flag", text}); - -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 25, bn, step_asset_config_id(), {"Asset ID", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 26, bn, step_asset_config_total(), {"Total units", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 27, bn, step_asset_config_default_frozen(), {"Default frozen", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 28, bnnn_paging, step_asset_config_unitname(), {"Unit name", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 29, bn, step_asset_config_decimals(), {"Decimals", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 30, bnnn_paging, step_asset_config_assetname(), {"Asset name", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 31, bnnn_paging, step_asset_config_url(), {"URL", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 32, bnnn_paging, step_asset_config_metadata_hash(), {"Metadata hash", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 33, bnnn_paging, step_asset_config_manager(), {"Manager", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 34, bnnn_paging, step_asset_config_reserve(), {"Reserve", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 35, bnnn_paging, step_asset_config_freeze(), {"Freezer", text}); -ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 36, bnnn_paging, step_asset_config_clawback(), {"Clawback", text}); - -ALGO_UX_STEP(37, pbb, NULL, 0, txn_approve(), NULL, {&C_icon_validate_14, "Sign", "transaction"}); -ALGO_UX_STEP(38, pbb, NULL, 0, txn_deny(), NULL, {&C_icon_crossmark, "Cancel", "signature"}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 16, bn, step_keydilution(), {"Key dilution", text}); +ALGO_UX_STEP_NOCB_INIT(KEYREG, 17, bn, step_participating(), {"Participating", text}); + +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 18, bn, step_asset_xfer_id(), {"Asset ID", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 19, bn, step_asset_xfer_amount(), {"Asset amt", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 20, bnnn_paging, step_asset_xfer_sender(), {"Asset src", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 21, bnnn_paging, step_asset_xfer_receiver(), {"Asset dst", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_XFER, 22, bnnn_paging, step_asset_xfer_close(), {"Asset close", text}); + +ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 23, bn, step_asset_freeze_id(), {"Asset ID", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 24, bnnn_paging, step_asset_freeze_account(), {"Asset account", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_FREEZE, 25, bn, step_asset_freeze_flag(), {"Freeze flag", text}); + +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 26, bn, step_asset_config_id(), {"Asset ID", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 27, bn, step_asset_config_total(), {"Total units", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 28, bn, step_asset_config_default_frozen(), {"Default frozen", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 29, bnnn_paging, step_asset_config_unitname(), {"Unit name", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 30, bn, step_asset_config_decimals(), {"Decimals", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 31, bnnn_paging, step_asset_config_assetname(), {"Asset name", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 32, bnnn_paging, step_asset_config_url(), {"URL", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 33, bnnn_paging, step_asset_config_metadata_hash(), {"Metadata hash", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 34, bnnn_paging, step_asset_config_manager(), {"Manager", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 35, bnnn_paging, step_asset_config_reserve(), {"Reserve", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 36, bnnn_paging, step_asset_config_freeze(), {"Freezer", text}); +ALGO_UX_STEP_NOCB_INIT(ASSET_CONFIG, 37, bnnn_paging, step_asset_config_clawback(), {"Clawback", text}); + +ALGO_UX_STEP(38, pbb, NULL, 0, txn_approve(), NULL, {&C_icon_validate_14, "Sign", "transaction"}); +ALGO_UX_STEP(39, pbb, NULL, 0, txn_deny(), NULL, {&C_icon_crossmark, "Cancel", "signature"}); const ux_flow_step_t * const ux_txn_flow [] = { &txn_flow_0, @@ -472,6 +478,7 @@ const ux_flow_step_t * const ux_txn_flow [] = { &txn_flow_36, &txn_flow_37, &txn_flow_38, + &txn_flow_39, FLOW_END_STEP, }; #endif // TARGET_NANOX @@ -505,6 +512,7 @@ static const struct ux_step ux_steps[] = { { KEYREG, "VRF PK", &step_vrfpk }, { KEYREG, "Vote first", &step_votefirst }, { KEYREG, "Vote last", &step_votelast }, + { KEYREG, "Key dilution", &step_keydilution }, { KEYREG, "Participating", &step_participating }, { ASSET_XFER, "Asset ID", &step_asset_xfer_id }, { ASSET_XFER, "Asset amt", &step_asset_xfer_amount },