Skip to content

Commit

Permalink
Upgrade to NU6 + version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
apaillier-ledger committed Nov 27, 2024
1 parent 1781c13 commit 55bcd93
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ APPNAME = "Zcash"

# Application version
APPVERSION_M=2
APPVERSION_N=2
APPVERSION_N=3
APPVERSION_P=0
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"

Expand Down Expand Up @@ -84,8 +84,6 @@ APP_SOURCE_FILES += ${BOLOS_SDK}/lib_standard_app/format.c
APP_SOURCE_FILES += ${BOLOS_SDK}/lib_standard_app/crypto_helpers.c

DEFINES += BIP44_COIN_TYPE=133 BIP44_COIN_TYPE_2=133 COIN_P2PKH_VERSION=7352 COIN_P2SH_VERSION=7357 COIN_FAMILY=1 COIN_COINID=\"Zcash\" COIN_COINID_HEADER=\"ZCASH\" COIN_COLOR_HDR=0x3790CA COIN_COLOR_DB=0x9BC8E5 COIN_COINID_NAME=\"Zcash\" COIN_COINID_SHORT=\"ZEC\" COIN_KIND=COIN_KIND_ZCASH
# Switch to NU5 over Canopy
DEFINES += COIN_CONSENSUS_BRANCH_ID=0XC2D6D0B4
DEFINES += TCS_LOADER_PATCH_VERSION=0

ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
Expand Down
3 changes: 2 additions & 1 deletion src/btchip_rom_variables.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ unsigned char const OVERWINTER_PARAM_OUTPUTS[16] = { 'Z', 'c', 'a', 's', 'h', 'O
unsigned char const OVERWINTER_PARAM_SIGHASH[16] = { 'Z', 'c', 'a', 's', 'h', 'S', 'i', 'g', 'H', 'a', 's', 'h', 0, 0, 0, 0 };
unsigned char const OVERWINTER_NO_JOINSPLITS[32] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

unsigned char const NU5_GROUP_ID[4] = {0xB4, 0xD0, 0xD6, 0xC2};
unsigned char const NU5_GROUP_ID[4] = {0xB4, 0xD0, 0xD6, 0xC2};
unsigned char const NU6_GROUP_ID[4] = {0x55, 0x10, 0xE7, 0xC8};

unsigned char const NU5_PARAM_TXID[16] = { 'Z', 'c', 'a', 's', 'h', 'T', 'x', 'H', 'a', 's', 'h', '_', 0, 0, 0, 0};
unsigned char const NU5_PARAM_HEADERS[16] = { 'Z', 'T', 'x', 'I', 'd', 'H', 'e', 'a', 'd', 'e', 'r', 's', 'H', 'a', 's', 'h' };
Expand Down
3 changes: 2 additions & 1 deletion src/btchip_rom_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern unsigned char const OVERWINTER_PARAM_SIGHASH[16];
extern unsigned char const OVERWINTER_NO_JOINSPLITS[32];

extern unsigned char const NU5_GROUP_ID[4];
extern unsigned char const NU6_GROUP_ID[4];
extern unsigned char const NU5_PARAM_TXID[16];
extern unsigned char const NU5_PARAM_HEADERS[16];
extern unsigned char const NU5_PARAM_TRANSPA[16];
Expand Down Expand Up @@ -80,4 +81,4 @@ extern unsigned char const DISPATCHER_INS[DISPATCHER_APDUS];
extern unsigned char const DISPATCHER_DATA_IN[DISPATCHER_APDUS];
extern apduProcessingFunction const DISPATCHER_FUNCTIONS[DISPATCHER_APDUS];

#endif /* _BTCHIP_ROM_VARIABLES_ */
#endif /* _BTCHIP_ROM_VARIABLES_ */
48 changes: 24 additions & 24 deletions src/btchip_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,21 @@ void transaction_parse(unsigned char parseMode) {
PRINTF("SEGWIT Version\n%.*H\n",sizeof(btchip_context_D.transactionVersion),btchip_context_D.transactionVersion);
PRINTF("SEGWIT HashedPrevouts\n%.*H\n",sizeof(btchip_context_D.segwit.cache.hashedPrevouts),btchip_context_D.segwit.cache.hashedPrevouts);
PRINTF("SEGWIT HashedSequence\n%.*H\n",sizeof(btchip_context_D.segwit.cache.hashedSequence),btchip_context_D.segwit.cache.hashedSequence);
if (btchip_context_D.usingOverwinter)
if (btchip_context_D.usingOverwinter)
if (btchip_context_D.NU5Transaction) {
uint8_t header_digest[32];
// Compute header_digest
blake2b_256_init(&btchip_context_D.transactionHashFull.blake2b, NU5_PARAM_HEADERS);
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, btchip_context_D.transactionVersion, sizeof(btchip_context_D.transactionVersion));
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, btchip_context_D.nVersionGroupId, sizeof(btchip_context_D.nVersionGroupId));
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, NU5_GROUP_ID, 4);
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, NU6_GROUP_ID, 4);
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, btchip_context_D.nLockTime, sizeof(btchip_context_D.nLockTime));
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, btchip_context_D.nExpiryHeight, sizeof(btchip_context_D.nExpiryHeight));

// Save header_digest
blake2b_256_final(&btchip_context_D.transactionHashFull.blake2b, header_digest);
memcpy(btchip_context_D.nu5_ctx.header_digest, header_digest, DIGEST_SIZE);
}
}
else {
if (cx_hash_no_throw(&btchip_context_D.transactionHashFull.blake2b.header, 0, btchip_context_D.transactionVersion, sizeof(btchip_context_D.transactionVersion), NULL, 0)) {
goto fail;
Expand All @@ -248,7 +248,7 @@ void transaction_parse(unsigned char parseMode) {
goto fail;
}
if (btchip_context_D.usingOverwinter == ZCASH_USING_OVERWINTER_SAPLING) {
if (cx_hash_no_throw(&btchip_context_D.transactionHashFull.blake2b.header, 0, OVERWINTER_NO_JOINSPLITS, 32, NULL, 0)) { // sapling hashShieldedSpend)
if (cx_hash_no_throw(&btchip_context_D.transactionHashFull.blake2b.header, 0, OVERWINTER_NO_JOINSPLITS, 32, NULL, 0)) { // sapling hashShieldedSpend)
goto fail;
}
if (cx_hash_no_throw(&btchip_context_D.transactionHashFull.blake2b.header, 0, OVERWINTER_NO_JOINSPLITS, 32, NULL, 0)) { // sapling hashShieldedOutputs
Expand Down Expand Up @@ -327,17 +327,17 @@ void transaction_parse(unsigned char parseMode) {

// We will use this hash to compute prevouts digest
blake2b_256_init(&btchip_context_D.segwit.hash.hashPrevouts.blake2b, NU5_PARAM_PREVOUT);

// We will use this hash to compute sequence digest
blake2b_256_init(&btchip_context_D.transactionHashFull.blake2b, NU5_PARAM_SEQUENC);

// We will use this hash to compute amounts_sig_digest
blake2b_256_init(&btchip_context_D.hashAmount.blake2b, NU5_PARAM_AMOUNTS);

// We will use this hash to compute scriptpubkeys_sig_digest
blake2b_256_init(&btchip_context_D.transactionHashAuthorization.blake2b, NU5_PARAM_SCRIPTS);
}

// nVersionGroupId
check_transaction_available(4);
memcpy(btchip_context_D.nVersionGroupId,
Expand Down Expand Up @@ -388,7 +388,7 @@ void transaction_parse(unsigned char parseMode) {
check_transaction_available(
36); // prevout : 32 hash + 4 index

if (btchip_context_D.NU5Transaction) {
if (btchip_context_D.NU5Transaction) {
blake2b_256_update(&btchip_context_D.segwit.hash.hashPrevouts.blake2b, btchip_context_D.transactionBufferPointer, 36);
}

Expand Down Expand Up @@ -520,7 +520,7 @@ void transaction_parse(unsigned char parseMode) {

if (btchip_context_D.NU5Transaction) {
// Compute amounts_sig_digest
CX_ASSERT(cx_hash_no_throw(&btchip_context_D.hashAmount.blake2b.header, 0, btchip_context_D.transactionBufferPointer, 8, NULL, 0));
CX_ASSERT(cx_hash_no_throw(&btchip_context_D.hashAmount.blake2b.header, 0, btchip_context_D.transactionBufferPointer, 8, NULL, 0));
}

transaction_offset_increase(8);
Expand Down Expand Up @@ -785,7 +785,7 @@ void transaction_parse(unsigned char parseMode) {
// Start to compute signature_digest
uint8_t parameters[16];
memcpy(parameters, NU5_PARAM_TXID, 12);
memcpy(parameters + 12, NU5_GROUP_ID, 4);
memcpy(parameters + 12, NU6_GROUP_ID, 4);
blake2b_256_init(tx_ctx, parameters);
blake2b_256_update(tx_ctx, btchip_context_D.nu5_ctx.header_digest, DIGEST_SIZE);
blake2b_256_update(tx_ctx, transparent_sig_digest, DIGEST_SIZE);
Expand Down Expand Up @@ -954,9 +954,9 @@ void transaction_parse(unsigned char parseMode) {
goto ok;
}

if (btchip_context_D.NU5Transaction) {
if (btchip_context_D.NU5Transaction) {
uint8_t tmp[32];

// Store prevout_digest
blake2b_256_final(&btchip_context_D.segwit.hash.hashPrevouts.blake2b, tmp);
memcpy(btchip_context_D.segwit.cache.hashedPrevouts, tmp, 32);
Expand Down Expand Up @@ -998,7 +998,7 @@ void transaction_parse(unsigned char parseMode) {
// Amount
check_transaction_available(8);

if (btchip_context_D.NU5Transaction) {
if (btchip_context_D.NU5Transaction) {
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, btchip_context_D.transactionBufferPointer, 8);
}

Expand Down Expand Up @@ -1072,7 +1072,7 @@ void transaction_parse(unsigned char parseMode) {
goto ok;
}

if (btchip_context_D.NU5Transaction) {
if (btchip_context_D.NU5Transaction) {
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, btchip_context_D.transactionBufferPointer, dataAvailable);
}

Expand All @@ -1083,10 +1083,10 @@ void transaction_parse(unsigned char parseMode) {
}
case BTCHIP_TRANSACTION_OUTPUT_HASHING_DONE: {
PRINTF("Output hashing done\n");
if (btchip_context_D.NU5Transaction) {

if (btchip_context_D.NU5Transaction) {
uint8_t tmp[32];

// Store outputs_digest
blake2b_256_final(&btchip_context_D.transactionHashFull.blake2b, tmp);
memcpy(btchip_context_D.segwit.cache.hashedOutputs, tmp, 32);
Expand All @@ -1102,10 +1102,10 @@ void transaction_parse(unsigned char parseMode) {
// Locktime
check_transaction_available(4);

if (btchip_context_D.NU5Transaction) {
if (btchip_context_D.NU5Transaction) {
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, btchip_context_D.transactionVersion, sizeof(btchip_context_D.transactionVersion));
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, btchip_context_D.nVersionGroupId, sizeof(btchip_context_D.nVersionGroupId));
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, NU5_GROUP_ID, 4);
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, NU6_GROUP_ID, 4);
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, btchip_context_D.transactionBufferPointer, 4);
}
transaction_offset_increase(4);
Expand Down Expand Up @@ -1152,8 +1152,8 @@ void transaction_parse(unsigned char parseMode) {
goto ok;
}

if (btchip_context_D.NU5Transaction) {
// We don't support sapling or orchard actions
if (btchip_context_D.NU5Transaction) {
// We don't support sapling or orchard actions
// Only expiryHeight should remain at this point
if (btchip_context_D.transactionDataRemaining != 4) {
PRINTF("expiryHeight expected");
Expand All @@ -1166,7 +1166,7 @@ void transaction_parse(unsigned char parseMode) {
transaction_offset_increase(dataAvailable);
btchip_context_D.transactionContext.scriptRemaining -=
dataAvailable;
if (btchip_context_D.NU5Transaction) {
if (btchip_context_D.NU5Transaction) {
uint8_t hashHeader[32];
uint8_t hashTransparent[32];
uint8_t hashSapling[32];
Expand All @@ -1180,7 +1180,7 @@ void transaction_parse(unsigned char parseMode) {
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, btchip_context_D.segwit.cache.hashedPrevouts, 32);
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, btchip_context_D.segwit.cache.hashedSequence, 32);
blake2b_256_update(&btchip_context_D.transactionHashFull.blake2b, btchip_context_D.segwit.cache.hashedOutputs, 32);

// store transparent_digest
blake2b_256_final(&btchip_context_D.transactionHashFull.blake2b, hashTransparent);

Expand All @@ -1197,7 +1197,7 @@ void transaction_parse(unsigned char parseMode) {
// initialize personalization hash for tx_id
uint8_t parameters[16];
memcpy(parameters, NU5_PARAM_TXID, 12);
memcpy(parameters + 12, NU5_GROUP_ID, 4);
memcpy(parameters + 12, NU6_GROUP_ID, 4);

// This context will be used for txid_digest
blake2b_256_init(&btchip_context_D.transactionHashFull.blake2b, parameters);
Expand Down

0 comments on commit 55bcd93

Please sign in to comment.