Skip to content
Draft
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
51 changes: 26 additions & 25 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ endif

MY_DIR := $(dir $(lastword $(MAKEFILE_LIST)))

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.installer_script

include $(BOLOS_SDK)/Makefile.defines

# Set the default value for PRODUCTION_BUILD to 1 if not already defined
PRODUCTION_BUILD ?= 1

$(info ************ TARGET_NAME = [$(TARGET_NAME)])
# Display whether this is a production build or for internal use
ifeq ($(PRODUCTION_BUILD), 1)
$(info ************ PRODUCTION_BUILD = [PRODUCTION BUILD])
Expand All @@ -39,19 +34,22 @@ endif

# Add the PRODUCTION_BUILD definition to the compiler flags
DEFINES += PRODUCTION_BUILD=$(PRODUCTION_BUILD)

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.app_testing

ifndef COIN
COIN=NAM
endif

VARIANT_PARAM=COIN
VARIANT_VALUES=$(COIN)

include $(CURDIR)/Makefile.version

$(info COIN = [$(COIN)])

ifeq ($(COIN),NAM)
# Main app configuration
DEFINES += APP_STANDARD
APPNAME = "Namada"
APPPATH = "44'/877'" --path "44'/1'"

Expand All @@ -66,33 +64,44 @@ endif

APP_LOAD_PARAMS = --curve ed25519 $(COMMON_LOAD_PARAMS) --path $(APPPATH)

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices
# Enable QR code display for all devices
ENABLE_NBGL_QRCODE ?= 1

$(info TARGET_NAME = [$(TARGET_NAME)])
$(info ICONNAME = [$(ICONNAME)])
RUST_TARGET:=thumbv6m-none-eabi

ifndef ICONNAME
$(error ICONNAME is not set)
endif
$(info ************ RUST_TARGET = [$(RUST_TARGET)])

include $(BOLOS_SDK)/Makefile.target

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.platform

# Compile MASP mode for all devices excetpt Nano S,
ifneq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += COMPILE_MASP
endif

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.platform
# Add SDK BLAKE2b
DEFINES += HAVE_HASH HAVE_BLAKE2
INCLUDES_PATH += $(BOLOS_SDK)/lib_cxng/src


# Building Rust
LDFLAGS += -z muldefs
LDLIBS += -L$(MY_DIR)rust/target/$(RUST_TARGET)/release -lrslib

APP_SOURCE_PATH += $(CURDIR)/rust/include
APP_CUSTOM_LINK_DEPENDENCIES = rust
RUST_TARGET:=thumbv6m-none-eabi

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.installer_script

$(info TARGET_NAME = [$(TARGET_NAME)])
$(info ICONNAME = [$(ICONNAME)])

ifndef ICONNAME
$(error ICONNAME is not set)
endif

# make rust a prerequisite for all object files
$(OBJECT_FILES): | rust

.PHONY: rust
rust:
Expand All @@ -104,17 +113,9 @@ rust_clean:

clean: rust_clean

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.side_loading

# Import generic rules from the SDK
include $(BOLOS_SDK)/Makefile.rules

#add dependency on custom makefile filename
dep/%.d: %.c Makefile

listvariants:
@echo VARIANTS COIN NAM

.PHONY: version
version:
@echo "v$(APPVERSION)" > app.version
4 changes: 2 additions & 2 deletions app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is the `transaction_version` field of `Runtime`
APPVERSION_M=2
APPVERSION_M=3
# This is the `spec_version` field of `Runtime`
APPVERSION_N=0
# This is the patch version of this release
APPVERSION_P=5
APPVERSION_P=1
12 changes: 6 additions & 6 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ __Z_INLINE void handle_getversion(__Z_UNUSED volatile uint32_t *flags, volatile
G_io_apdu_buffer[0] = 0x01;
#endif

G_io_apdu_buffer[1] = (LEDGER_MAJOR_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[2] = (LEDGER_MAJOR_VERSION >> 0) & 0xFF;
G_io_apdu_buffer[1] = (MAJOR_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[2] = (MAJOR_VERSION >> 0) & 0xFF;

G_io_apdu_buffer[3] = (LEDGER_MINOR_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[4] = (LEDGER_MINOR_VERSION >> 0) & 0xFF;
G_io_apdu_buffer[3] = (MINOR_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[4] = (MINOR_VERSION >> 0) & 0xFF;

G_io_apdu_buffer[5] = (LEDGER_PATCH_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[6] = (LEDGER_PATCH_VERSION >> 0) & 0xFF;
G_io_apdu_buffer[5] = (PATCH_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[6] = (PATCH_VERSION >> 0) & 0xFF;

// SDK won't reply if device is blocked ---> Always false
G_io_apdu_buffer[7] = 0;
Expand Down
1 change: 1 addition & 0 deletions app/src/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern "C" {
#define HDPATH_4_DEFAULT (0u)

#define MASK_HARDENED 0x80000000
#define MASK_HARDENED_ZIP32 (0x80000000u | 0x7FFFFFFF) // 2147483647

#define SECP256K1_PK_LEN 65u
#define COMPRESSED_SECP256K1_PK_LEN 33u
Expand Down
4 changes: 2 additions & 2 deletions app/src/common/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
#include "tx.h"
#include "apdu_codes.h"
#include "buffering.h"
#include "parser.h"
#include "common/parser.h"
#include <string.h>
#include "zxmacros.h"

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || defined(TARGET_FLEX)
#define RAM_BUFFER_SIZE 8192
#define FLASH_BUFFER_SIZE 16384
#elif defined(TARGET_NANOS)
#define RAM_BUFFER_SIZE 256
#define RAM_BUFFER_SIZE 0
#define FLASH_BUFFER_SIZE 8192
#endif

Expand Down
8 changes: 7 additions & 1 deletion app/src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ zxerr_t crypto_fillDeviceSeed(uint8_t *device_seed) {

// Generate randomness using a fixed path related to the device mnemonic
const uint32_t path[HDPATH_LEN_DEFAULT] = {
HDPATH_0_DEFAULT, HDPATH_1_DEFAULT, MASK_HARDENED, MASK_HARDENED, MASK_HARDENED,
HDPATH_0_DEFAULT, HDPATH_1_DEFAULT, MASK_HARDENED, MASK_HARDENED, MASK_HARDENED_ZIP32,
};

MEMZERO(device_seed, KEY_LENGTH);
Expand All @@ -576,6 +576,7 @@ zxerr_t crypto_fillDeviceSeed(uint8_t *device_seed) {
io_seproxyhal_io_heartbeat();
CATCH_CXERROR(os_derive_bip32_with_seed_no_throw(HDW_ED25519_SLIP10, CX_CURVE_Ed25519, path, HDPATH_LEN_DEFAULT, raw_privkey, NULL,
NULL, 0));
io_seproxyhal_io_heartbeat();
error = zxerr_ok;
MEMCPY(device_seed, raw_privkey, KEY_LENGTH);

Expand Down Expand Up @@ -696,7 +697,9 @@ zxerr_t crypto_sign_spends_sapling(const parser_tx_t *txObj, keys_t *keys) {
spend += spendLen;
spend_item_t *item = spendlist_retrieve_rand_item(i);

io_seproxyhal_io_heartbeat();
CHECK_ZXERR(sign_sapling_spend(keys, item->alpha, sign_hash, signature));
io_seproxyhal_io_heartbeat();

// Save signature in flash
CHECK_ZXERR(spend_signatures_append(signature));
Expand Down Expand Up @@ -885,6 +888,7 @@ zxerr_t crypto_check_masp(const parser_tx_t *txObj, keys_t *keys) {
.bufferLen = txObj->transaction.sections.maspBuilder.metadata.spends_indices.len,
.offset = 0,
.tx_obj = NULL};
io_seproxyhal_io_heartbeat();
CHECK_PARSER_OK(checkSpends(txObj, keys, &builder_spends_ctx, &tx_spends_ctx, &spends_indices_ctx));

// Check outputs
Expand All @@ -900,6 +904,7 @@ zxerr_t crypto_check_masp(const parser_tx_t *txObj, keys_t *keys) {
.bufferLen = txObj->transaction.sections.maspBuilder.metadata.outputs_indices.len,
.offset = 0,
.tx_obj = NULL};
io_seproxyhal_io_heartbeat();
CHECK_PARSER_OK(checkOutputs(txObj, &builder_outputs_ctx, &tx_outputs_ctx, &output_indices_ctx));

// Check converts
Expand All @@ -915,6 +920,7 @@ zxerr_t crypto_check_masp(const parser_tx_t *txObj, keys_t *keys) {
.bufferLen = txObj->transaction.sections.maspBuilder.metadata.converts_indices.len,
.offset = 0,
.tx_obj = NULL};
io_seproxyhal_io_heartbeat();
CHECK_PARSER_OK(checkConverts(txObj, &builder_converts_ctx, &tx_converts_ctx, &converts_indices_ctx));
return zxerr_ok;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "parser_common.h"
#include "parser_impl.h"
#include "parser.h"
#include "common/parser.h"

#include "crypto.h"
#include "crypto_helper.h"
Expand Down
2 changes: 1 addition & 1 deletion app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ parser_error_t getNumItems(const parser_context_t *ctx, uint8_t *numItems) {
items += 3 * ctx->tx_obj->transaction.sections.maspBuilder.builder.sapling_builder.n_outputs; // print from outputs
items += 3 * ctx->tx_obj->transaction.sections.maspBuilder.builder.sapling_builder.n_spends; // print from spends

*numItems = (app_mode_expert() ? items + 4 : items + 2);
*numItems = (app_mode_expert() ? items + 5 : items + 2);
} else {
*numItems = (app_mode_expert() ? TRANSFER_EXPERT_PARAMS : TRANSFER_NORMAL_PARAMS);
}
Expand Down
40 changes: 20 additions & 20 deletions app/src/parser_impl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,64 +25,64 @@ extern "C" {
#endif

#define BOND_NORMAL_PARAMS 5
#define BOND_EXPERT_PARAMS 7
#define BOND_EXPERT_PARAMS 8

#define CUSTOM_NORMAL_PARAMS 3
#define CUSTOM_EXPERT_PARAMS 7
#define CUSTOM_EXPERT_PARAMS 8

#define INIT_ACCOUNT_NORMAL_PARAMS 5
#define INIT_ACCOUNT_EXPERT_PARAMS 7
#define INIT_ACCOUNT_EXPERT_PARAMS 8

#define INIT_PROPOSAL_NORMAL_PARAMS 9
#define INIT_PROPOSAL_EXPERT_PARAMS 11
#define INIT_PROPOSAL_EXPERT_PARAMS 12

#define VOTE_PROPOSAL_NORMAL_PARAMS 6
#define VOTE_PROPOSAL_EXPERT_PARAMS 8
#define VOTE_PROPOSAL_EXPERT_PARAMS 9

#define BECOME_VALIDATOR_NORMAL_PARAMS 11
#define BECOME_VALIDATOR_EXPERT_PARAMS 13
#define BECOME_VALIDATOR_EXPERT_PARAMS 14

#define REVEAL_PUBKEY_NORMAL_PARAMS 4
#define REVEAL_PUBKEY_EXPERT_PARAMS 6
#define REVEAL_PUBKEY_EXPERT_PARAMS 7

#define TRANSFER_NORMAL_PARAMS 3
#define TRANSFER_EXPERT_PARAMS 5
#define TRANSFER_EXPERT_PARAMS 6

#define UPDATE_VP_NORMAL_PARAMS 4
#define UPDATE_VP_EXPERT_PARAMS 6
#define UPDATE_VP_EXPERT_PARAMS 7

#define WITHDRAW_NORMAL_PARAMS 4
#define WITHDRAW_EXPERT_PARAMS 6
#define WITHDRAW_EXPERT_PARAMS 7

#define COMMISSION_CHANGE_NORMAL_PARAMS 5
#define COMMISSION_CHANGE_EXPERT_PARAMS 7
#define COMMISSION_CHANGE_EXPERT_PARAMS 8

#define UNJAIL_VALIDATOR_NORMAL_PARAMS 4
#define UNJAIL_VALIDATOR_EXPERT_PARAMS 6
#define UNJAIL_VALIDATOR_EXPERT_PARAMS 7

#define IBC_NORMAL_PARAMS 10
#define IBC_EXPERT_PARAMS 12
#define IBC_EXPERT_PARAMS 13

#define REDELEGATE_NORMAL_PARAMS 7
#define REDELEGATE_EXPERT_PARAMS 9
#define REDELEGATE_EXPERT_PARAMS 10

#define CLAIM_REWARDS_NORMAL_PARAMS 4
#define CLAIM_REWARDS_EXPERT_PARAMS 6
#define CLAIM_REWARDS_EXPERT_PARAMS 7

#define RESIGN_STEWARD_NORMAL_PARAMS 4
#define RESIGN_STEWARD_EXPERT_PARAMS 6
#define RESIGN_STEWARD_EXPERT_PARAMS 7

#define CHANGE_CONSENSUS_KEY_NORMAL_PARAMS 5
#define CHANGE_CONSENSUS_KEY_EXPERT_PARAMS 7
#define CHANGE_CONSENSUS_KEY_EXPERT_PARAMS 8

#define UPDATE_STEWARD_COMMISSION_NORMAL_PARAMS 4
#define UPDATE_STEWARD_COMMISSION_EXPERT_PARAMS 6
#define UPDATE_STEWARD_COMMISSION_EXPERT_PARAMS 7

#define CHANGE_VALIDATOR_METADATA_NORMAL_PARAMS 4
#define CHANGE_VALIDATOR_METADATA_EXPERT_PARAMS 6
#define CHANGE_VALIDATOR_METADATA_EXPERT_PARAMS 7

#define BRIDGE_POOL_TRANSFER_NORMAL_PARAMS 11
#define BRIDGE_POOL_TRANSFER_EXPERT_PARAMS 13
#define BRIDGE_POOL_TRANSFER_EXPERT_PARAMS 14

#define CTX_CHECK_AVAIL(CTX, SIZE) \
if ( (CTX) == NULL || ((CTX)->offset + (SIZE)) > (CTX)->bufferLen) { return parser_unexpected_buffer_end; }
Expand Down
3 changes: 2 additions & 1 deletion app/src/parser_impl_txn.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,9 @@ parser_error_t readHeader(parser_context_t *ctx, parser_tx_t *v) {
// Read length of chain_id
uint32_t chain_id_len = 0;
CHECK_ERROR(readUint32(ctx, &chain_id_len))
v->transaction.header.chain_id.len = (uint16_t)chain_id_len;

ctx->offset += chain_id_len;
CHECK_ERROR(readBytes(ctx, &v->transaction.header.chain_id.ptr, v->transaction.header.chain_id.len))

// Check if an expiration is set
uint8_t has_expiration = 0;
Expand Down
14 changes: 9 additions & 5 deletions app/src/parser_print_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,29 +414,33 @@ parser_error_t printExpert( const parser_context_t *ctx,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {

if(displayIdx >= 4 && ctx->tx_obj->transaction.header.fees.symbol != NULL) {
if(displayIdx >= 5 && ctx->tx_obj->transaction.header.fees.symbol != NULL) {
displayIdx++;
}

switch (displayIdx) {
case 0:
snprintf(outKey, outKeyLen, "Chain ID");
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->transaction.header.chain_id.ptr, ctx->tx_obj->transaction.header.chain_id.len, pageIdx, pageCount);
break;
case 1:
snprintf(outKey, outKeyLen, "Timestamp");
CHECK_ERROR(printTimestamp(ctx->tx_obj->transaction.timestamp,
outVal, outValLen, pageIdx, pageCount))
break;
case 1: {
case 2: {
const bytes_t *pubkey = &ctx->tx_obj->transaction.header.pubkey;
snprintf(outKey, outKeyLen, "Pubkey");
CHECK_ERROR(printPublicKey(pubkey, outVal, outValLen, pageIdx, pageCount));
break;
}
case 2:
case 3:
snprintf(outKey, outKeyLen, "Gas limit");
if (uint64_to_str(outVal, outValLen, ctx->tx_obj->transaction.header.gasLimit) != NULL) {
return parser_unexpected_error;
}
break;
case 3: {
case 4: {
if(ctx->tx_obj->transaction.header.fees.symbol != NULL) {
snprintf(outKey, outKeyLen, "Fees/gas unit");
CHECK_ERROR(printAmount(&ctx->tx_obj->transaction.header.fees.amount, true, ctx->tx_obj->transaction.header.fees.denom, "", outVal, outValLen, pageIdx, pageCount))
Expand All @@ -446,7 +450,7 @@ parser_error_t printExpert( const parser_context_t *ctx,
}
break;
}
case 4: {
case 5: {
snprintf(outKey, outKeyLen, "Fees/gas unit");
CHECK_ERROR(printAmount(&ctx->tx_obj->transaction.header.fees.amount, true, ctx->tx_obj->transaction.header.fees.denom, "", outVal, outValLen, pageIdx, pageCount))
break;
Expand Down
1 change: 1 addition & 0 deletions app/src/parser_txdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ typedef struct {
bytes_t memoHash;
const section_t *memoSection;
uint8_t atomic;
bytes_t chain_id;
} header_t;
typedef struct {
uint32_t sectionLen;
Expand Down
Loading
Loading