From 7f80101beef2646760e53379ea120ba6ddf9ac4a Mon Sep 17 00:00:00 2001 From: Jan Mazak Date: Tue, 20 Jun 2023 11:19:12 +0200 Subject: [PATCH] remove features from Nano S --- Makefile | 42 ++++++++++- doc/build.md | 2 +- doc/features.md | 11 +++ fuzzing/CMakeLists.txt | 9 +++ src/addressUtilsByron.c | 109 ++++++++++++++++------------- src/addressUtilsByron.h | 10 ++- src/addressUtilsByron_test.c | 2 +- src/addressUtilsShelley.c | 18 ++++- src/cardano.h | 4 ++ src/deriveNativeScriptHash.c | 4 ++ src/deriveNativeScriptHash.h | 4 ++ src/deriveNativeScriptHash_ui.c | 4 ++ src/deriveNativeScriptHash_ui.h | 6 ++ src/getVersion.c | 10 ++- src/handlers.c | 4 ++ src/ipUtils.c | 4 ++ src/ipUtils.h | 6 +- src/ipUtils_test.c | 5 +- src/messageSigning.c | 2 + src/messageSigning.h | 2 + src/nativeScriptHashBuilder.c | 4 ++ src/nativeScriptHashBuilder.h | 4 ++ src/nativeScriptHashBuilder_test.c | 5 +- src/runTests.c | 10 +++ src/securityPolicy.c | 24 ++++++- src/securityPolicy.h | 7 +- src/signOpCert.c | 4 ++ src/signOpCert.h | 4 ++ src/signTx.c | 69 +++++++++++++++++- src/signTx.h | 8 +++ src/signTxMint.c | 4 ++ src/signTxMint.h | 4 ++ src/signTxMint_ui.c | 4 ++ src/signTxMint_ui.h | 4 ++ src/signTxPoolRegistration.c | 4 ++ src/signTxPoolRegistration.h | 4 ++ src/signTxPoolRegistration_ui.c | 4 ++ src/signTxPoolRegistration_ui.h | 5 ++ src/signTx_ui.c | 12 +++- src/state.h | 4 ++ src/txHashBuilder.c | 12 ++++ src/txHashBuilder.h | 14 +++- src/txHashBuilder_test.c | 2 +- src/uiScreens_bagl.c | 16 +++++ src/uiScreens_bagl.h | 4 ++ src/uiScreens_nbgl.c | 4 ++ src/uiScreens_nbgl.h | 4 ++ 47 files changed, 429 insertions(+), 73 deletions(-) create mode 100644 doc/features.md diff --git a/Makefile b/Makefile index 5e18b380..465ceb60 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ #******************************************************************************* APPNAME = "Cardano ADA" + APPVERSION_M = 6 APPVERSION_N = 1 APPVERSION_P = 2 @@ -63,8 +64,6 @@ DEFINES += HAVE_SPRINTF HAVE_SNPRINTF_FORMAT_U DEFINES += APPVERSION=\"$(APPVERSION)\" DEFINES += MAJOR_VERSION=$(APPVERSION_M) MINOR_VERSION=$(APPVERSION_N) PATCH_VERSION=$(APPVERSION_P) -DEFINES += UNUSED\(x\)=\(void\)x - ## USB HID? DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=4 IO_HID_EP_LENGTH=64 HAVE_USB_APDU @@ -122,6 +121,29 @@ else DEFINES += PRINTF\(...\)= endif +# restricted features for Nano S +# but not in DEVEL mode where we usually want to test all features with HEADLESS +ifeq ($(TARGET_NAME), TARGET_NANOS) + ifneq ($(DEVEL), 1) + APP_XS = 1 + endif +else + APP_XS = 0 +endif + +ifeq ($(APP_XS), 1) + DEFINES += APP_XS +else + # features not included in the Nano S app + DEFINES += APP_FEATURE_OPCERT + DEFINES += APP_FEATURE_NATIVE_SCRIPT_HASH + DEFINES += APP_FEATURE_POOL_REGISTRATION + DEFINES += APP_FEATURE_POOL_RETIREMENT + DEFINES += APP_FEATURE_BYRON_ADDRESS_DERIVATION + DEFINES += APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK +endif +# always include this, it's important for Plutus users +DEFINES += APP_FEATURE_TOKEN_MINTING ################## # Dependencies # @@ -203,3 +225,19 @@ format: size: all $(GCCPATH)arm-none-eabi-size --format=gnu bin/app.elf + +############## +# Device-specific builds +############## + +nanos: clean + BOLOS_SDK=$(NANOS_SDK) make + +nanosp: clean + BOLOS_SDK=$(NANOSP_SDK) make + +nanox: clean + BOLOS_SDK=$(NANOX_SDK) make + +stax: clean + BOLOS_SDK=$(STAX_SDK) make diff --git a/doc/build.md b/doc/build.md index 14a11485..b94de09c 100644 --- a/doc/build.md +++ b/doc/build.md @@ -5,7 +5,7 @@ - Install Docker - Pull the required containers as discussed in https://github.com/LedgerHQ/ledger-app-builder/ (lite container is sufficient for a C build): - `sudo docker pull ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest` + `docker pull ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest` ## Compiling the app diff --git a/doc/features.md b/doc/features.md new file mode 100644 index 00000000..ec9745f3 --- /dev/null +++ b/doc/features.md @@ -0,0 +1,11 @@ +# Features (not) available on specific Ledger devices + +Nano S has a very limited space for storing applications. It is not enough to fit all Cardano features there, so some of them are only available on Nano S+ and other more spacious Ledger devices (e.g. Nano X and Stax). + +The features not supported on Nano S, Cardano app version 7 and above: +* pool registration and retirement +* signing of operational certificates +* computation of native script hashes +* details in Byron change outputs (only the address is shown) + +Details can be found in [Makefile](../Makefile) and in the code (search for compilation flags beginning with `APP_FEATURE_`). diff --git a/fuzzing/CMakeLists.txt b/fuzzing/CMakeLists.txt index fe7e9fe6..0d324582 100644 --- a/fuzzing/CMakeLists.txt +++ b/fuzzing/CMakeLists.txt @@ -142,6 +142,15 @@ add_compile_definitions( HAVE_HASH HAVE_SHA256 HAVE_SHA3 + + # include all app features, incl. those removed from Nano S + APP_FEATURE_OPCERT + APP_FEATURE_NATIVE_SCRIPT_HASH + APP_FEATURE_POOL_REGISTRATION + APP_FEATURE_POOL_RETIREMENT + APP_FEATURE_BYRON_ADDRESS_DERIVATION + APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK + APP_FEATURE_TOKEN_MINTING ) set(SOURCE diff --git a/src/addressUtilsByron.c b/src/addressUtilsByron.c index cf68f2b8..bb3c01a1 100644 --- a/src/addressUtilsByron.c +++ b/src/addressUtilsByron.c @@ -7,6 +7,15 @@ #include "crc32.h" #include "bufView.h" +#if defined(APP_FEATURE_BYRON_ADDRESS_DERIVATION) || defined(APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK) + +static const size_t ADDRESS_ROOT_SIZE = 28; +static const size_t PROTOCOL_MAGIC_ADDRESS_ATTRIBUTE_KEY = 2; + +#endif + +#ifdef APP_FEATURE_BYRON_ADDRESS_DERIVATION + enum { CARDANO_ADDRESS_TYPE_PUBKEY = 0, /* @@ -15,9 +24,6 @@ enum { */ }; -static const size_t ADDRESS_ROOT_SIZE = 28; -static const size_t PROTOCOL_MAGIC_ADDRESS_ATTRIBUTE_KEY = 2; - void addressRootFromExtPubKey( const extendedPublicKey_t* extPubKey, uint8_t* outBuffer, size_t outSize @@ -136,6 +142,56 @@ size_t cborPackRawAddressWithChecksum( return view_processedSize(&output); } +size_t deriveRawAddress( + const bip44_path_t* pathSpec, uint32_t protocolMagic, + uint8_t* outBuffer, size_t outSize +) +{ + ASSERT(outSize < BUFFER_SIZE_PARANOIA); + + uint8_t addressRoot[28] = {0}; + { + extendedPublicKey_t extPubKey; + + deriveExtendedPublicKey(pathSpec, &extPubKey); + + addressRootFromExtPubKey( + &extPubKey, + addressRoot, SIZEOF(addressRoot) + ); + } + + return cborEncodePubkeyAddressInner( + addressRoot, SIZEOF(addressRoot), + protocolMagic, + outBuffer, outSize + ); +} + +size_t deriveAddress_byron( + const bip44_path_t* pathSpec, uint32_t protocolMagic, + uint8_t* outBuffer, size_t outSize +) +{ + ASSERT(outSize < BUFFER_SIZE_PARANOIA); + + uint8_t rawAddressBuffer[40] = {0}; + size_t rawAddressSize = deriveRawAddress( + pathSpec, protocolMagic, + rawAddressBuffer, SIZEOF(rawAddressBuffer) + ); + + return cborPackRawAddressWithChecksum( + rawAddressBuffer, rawAddressSize, + outBuffer, outSize + ); + +} + +#endif // APP_FEATURE_BYRON_ADDRESS_DERIVATION + +#ifdef APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK + static uint64_t parseToken(read_view_t* view, uint8_t type) { const cbor_token_t token = view_parseToken(view); @@ -166,7 +222,6 @@ static size_t parseBytesSizeToken(read_view_t* view) return parsedSizeDowncasted; } - uint32_t extractProtocolMagic( const uint8_t* addressBuffer, size_t addressSize ) @@ -252,48 +307,4 @@ uint32_t extractProtocolMagic( return protocolMagic; } -size_t deriveRawAddress( - const bip44_path_t* pathSpec, uint32_t protocolMagic, - uint8_t* outBuffer, size_t outSize -) -{ - ASSERT(outSize < BUFFER_SIZE_PARANOIA); - - uint8_t addressRoot[28] = {0}; - { - extendedPublicKey_t extPubKey; - - deriveExtendedPublicKey(pathSpec, &extPubKey); - - addressRootFromExtPubKey( - &extPubKey, - addressRoot, SIZEOF(addressRoot) - ); - } - - return cborEncodePubkeyAddressInner( - addressRoot, SIZEOF(addressRoot), - protocolMagic, - outBuffer, outSize - ); -} - -size_t deriveAddress_byron( - const bip44_path_t* pathSpec, uint32_t protocolMagic, - uint8_t* outBuffer, size_t outSize -) -{ - ASSERT(outSize < BUFFER_SIZE_PARANOIA); - - uint8_t rawAddressBuffer[40] = {0}; - size_t rawAddressSize = deriveRawAddress( - pathSpec, protocolMagic, - rawAddressBuffer, SIZEOF(rawAddressBuffer) - ); - - return cborPackRawAddressWithChecksum( - rawAddressBuffer, rawAddressSize, - outBuffer, outSize - ); - -} +#endif // APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK diff --git a/src/addressUtilsByron.h b/src/addressUtilsByron.h index e5d275a0..d107993c 100644 --- a/src/addressUtilsByron.h +++ b/src/addressUtilsByron.h @@ -4,19 +4,27 @@ #include "common.h" #include "bip44.h" +#ifdef APP_FEATURE_BYRON_ADDRESS_DERIVATION + size_t deriveAddress_byron( const bip44_path_t* pathSpec, uint32_t protocolMagic, uint8_t* outBuffer, size_t outSize ); +#endif // APP_FEATURE_BYRON_ADDRESS_DERIVATION + +#ifdef APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK + // Note: validates the overall address structure at the same time uint32_t extractProtocolMagic( const uint8_t* addressBuffer, size_t addressSize ); +#endif // APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK + -#ifdef DEVEL +#if defined(DEVEL) && !defined(APP_XS) void run_addressUtilsByron_test(); #endif // DEVEL diff --git a/src/addressUtilsByron_test.c b/src/addressUtilsByron_test.c index 945418e5..444e3bb6 100644 --- a/src/addressUtilsByron_test.c +++ b/src/addressUtilsByron_test.c @@ -1,4 +1,4 @@ -#ifdef DEVEL +#if defined(DEVEL) && !defined(APP_XS) #include "addressUtilsByron.h" #include "cardano.h" diff --git a/src/addressUtilsShelley.c b/src/addressUtilsShelley.c index 7740708e..f6db8d23 100644 --- a/src/addressUtilsShelley.c +++ b/src/addressUtilsShelley.c @@ -439,8 +439,6 @@ size_t deriveAddress(const addressParams_t* addressParams, uint8_t* outBuffer, s ASSERT(outSize < BUFFER_SIZE_PARANOIA); ASSERT(isValidAddressParams(addressParams)); - const bip44_path_t* spendingPath = &addressParams->spendingKeyPath; - // shelley switch (addressParams->type) { case BASE_PAYMENT_KEY_STAKE_KEY: @@ -458,8 +456,16 @@ size_t deriveAddress(const addressParams_t* addressParams, uint8_t* outBuffer, s case REWARD_KEY: case REWARD_SCRIPT: return deriveAddress_reward(addressParams, outBuffer, outSize); + + #ifdef APP_FEATURE_BYRON_ADDRESS_DERIVATION case BYRON: - return deriveAddress_byron(spendingPath, addressParams->protocolMagic, outBuffer, outSize); + return deriveAddress_byron( + &addressParams->spendingKeyPath, + addressParams->protocolMagic, + outBuffer, outSize + ); + #endif // APP_FEATURE_BYRON_ADDRESS_DERIVATION + default: ASSERT(false); } @@ -698,6 +704,12 @@ bool isValidAddressParams(const addressParams_t* params) #define CHECK(cond) if (!(cond)) return false if (params->type != BYRON) { CHECK(isValidNetworkId(params->networkId)); + } else { + // code for Byron address derivation not available in XS app + // thus we cannot process address params + #ifndef APP_FEATURE_BYRON_ADDRESS_DERIVATION + return false; + #endif } CHECK(isValidStakingInfo(params)); diff --git a/src/cardano.h b/src/cardano.h index f0cfe29b..03f13e01 100644 --- a/src/cardano.h +++ b/src/cardano.h @@ -160,6 +160,8 @@ typedef struct { // ============================== NATIVE SCRIPTS ============================== +#ifdef APP_FEATURE_NATIVE_SCRIPT_HASH + // depth of n means it can handle up to n-1 levels of nesting #define MAX_SCRIPT_DEPTH 11 @@ -172,4 +174,6 @@ typedef enum { NATIVE_SCRIPT_INVALID_HEREAFTER = 5, } native_script_type; +#endif // APP_FEATURE_NATIVE_SCRIPT_HASH + #endif // H_CARDANO_APP_CARDANO diff --git a/src/deriveNativeScriptHash.c b/src/deriveNativeScriptHash.c index cac061f9..de8df37c 100644 --- a/src/deriveNativeScriptHash.c +++ b/src/deriveNativeScriptHash.c @@ -1,3 +1,5 @@ +#ifdef APP_FEATURE_NATIVE_SCRIPT_HASH + #include "deriveNativeScriptHash.h" #include "deriveNativeScriptHash_ui.h" #include "state.h" @@ -304,3 +306,5 @@ void deriveNativeScriptHash_handleAPDU( } #undef TRACE_WITH_CTX + +#endif // APP_FEATURE_NATIVE_SCRIPT_HASH diff --git a/src/deriveNativeScriptHash.h b/src/deriveNativeScriptHash.h index 2044a1d8..b26e59c4 100644 --- a/src/deriveNativeScriptHash.h +++ b/src/deriveNativeScriptHash.h @@ -1,6 +1,8 @@ #ifndef H_CARDANO_APP_DERIVE_NATIVE_SCRIPT_HASH #define H_CARDANO_APP_DERIVE_NATIVE_SCRIPT_HASH +#ifdef APP_FEATURE_NATIVE_SCRIPT_HASH + #include "bip44.h" #include "cardano.h" #include "common.h" @@ -48,4 +50,6 @@ typedef struct { ui_native_script_type ui_scriptType; } ins_derive_native_script_hash_context_t; +#endif // APP_FEATURE_NATIVE_SCRIPT_HASH + #endif // H_CARDANO_APP_DERIVE_NATIVE_SCRIPT_HASH diff --git a/src/deriveNativeScriptHash_ui.c b/src/deriveNativeScriptHash_ui.c index 716d3023..99bb376d 100644 --- a/src/deriveNativeScriptHash_ui.c +++ b/src/deriveNativeScriptHash_ui.c @@ -1,3 +1,5 @@ +#ifdef APP_FEATURE_NATIVE_SCRIPT_HASH + #include "deriveNativeScriptHash.h" #include "deriveNativeScriptHash_ui.h" #include "state.h" @@ -338,3 +340,5 @@ void deriveNativeScriptHash_displayNativeScriptHash_policyId() fill_and_display_if_required("Policy ID", bufferHex, deriveNativeScriptHash_displayNativeScriptHash_finish, respond_with_user_reject); #endif // HAVE_BAGL } + +#endif // APP_FEATURE_NATIVE_SCRIPT_HASH diff --git a/src/deriveNativeScriptHash_ui.h b/src/deriveNativeScriptHash_ui.h index 95460806..b4193c34 100644 --- a/src/deriveNativeScriptHash_ui.h +++ b/src/deriveNativeScriptHash_ui.h @@ -1,5 +1,8 @@ #ifndef H_CARDANO_APP_DERIVE_NATIVE_SCRIPT_HASH_UI #define H_CARDANO_APP_DERIVE_NATIVE_SCRIPT_HASH_UI + +#ifdef APP_FEATURE_NATIVE_SCRIPT_HASH + enum { DISPLAY_UI_STEP_POSITION = 200, #ifdef HAVE_NBGL @@ -17,4 +20,7 @@ void deriveNativeScriptHash_displayNativeScriptHash_callback(); void deriveNativeScriptHash_displayNativeScriptHash_bech32(); void deriveNativeScriptHash_displayNativeScriptHash_policyId(); + +#endif // APP_FEATURE_NATIVE_SCRIPT_HASH + #endif // H_CARDANO_APP_DERIVE_NATIVE_SCRIPT_HASH_UI diff --git a/src/getVersion.c b/src/getVersion.c index 3edf206b..2c831dfc 100644 --- a/src/getVersion.c +++ b/src/getVersion.c @@ -6,8 +6,9 @@ enum { - FLAG_DEVEL = 1, - + FLAG_DEVEL = 1 << 0, +// FLAG_HEADLESS = 1 << 1, + FLAG_APP_XS = 1 << 2, }; void getVersion_handleAPDU( @@ -40,12 +41,15 @@ void getVersion_handleAPDU( .major = MAJOR_VERSION, .minor = MINOR_VERSION, .patch = PATCH_VERSION, - .flags = 0, + .flags = 0, // see below }; #ifdef DEVEL response.flags |= FLAG_DEVEL; #endif // DEVEL + #ifdef APP_XS + response.flags |= FLAG_APP_XS; + #endif // APP_XS io_send_buf(SUCCESS, (uint8_t*) &response, sizeof(response)); ui_idle(); diff --git a/src/handlers.c b/src/handlers.c index 4c6cc5a1..db9792f4 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -29,11 +29,15 @@ handler_fn_t* lookupHandler(uint8_t ins) // 0x1* - public-key/address related CASE(0x10, getPublicKeys_handleAPDU); CASE(0x11, deriveAddress_handleAPDU); + #ifdef APP_FEATURE_NATIVE_SCRIPT_HASH CASE(0x12, deriveNativeScriptHash_handleAPDU); + #endif // APP_FEATURE_NATIVE_SCRIPT_HASH // 0x2* - signing related CASE(0x21, signTx_handleAPDU); + #ifdef APP_FEATURE_OPCERT CASE(0x22, signOpCert_handleAPDU); + #endif // APP_FEATURE_OPCERT CASE(0x23, signCVote_handleAPDU); #ifdef DEVEL diff --git a/src/ipUtils.c b/src/ipUtils.c index 7b6fc89f..2cbcfc31 100644 --- a/src/ipUtils.c +++ b/src/ipUtils.c @@ -1,3 +1,5 @@ +#ifdef APP_FEATURE_POOL_REGISTRATION + /* * Taken from glibc: * https://www.gnu.org/software/libc/sources.html @@ -159,3 +161,5 @@ void inet_ntop6 (const uint8_t* src, char* dst, size_t dstSize) strncpy(dst, tmp, dstSize); } + +#endif // APP_FEATURE_POOL_REGISTRATION diff --git a/src/ipUtils.h b/src/ipUtils.h index 111fa076..333945e8 100644 --- a/src/ipUtils.h +++ b/src/ipUtils.h @@ -1,6 +1,8 @@ #ifndef H_CARDANO_APP_IP_UTILS #define H_CARDANO_APP_IP_UTILS +#ifdef APP_FEATURE_POOL_REGISTRATION + #include "os.h" #define IPV4_STR_SIZE_MAX (sizeof "255.255.255.255") @@ -13,4 +15,6 @@ void inet_ntop6 (const uint8_t* src, char* dst, size_t dstSize); void run_ipUtils_test(); #endif // DEVEL -#endif // H_CARDANO_APP_SIGN_TX_UTILS +#endif // APP_FEATURE_POOL_REGISTRATION + +#endif // H_CARDANO_APP_IP_UTILS diff --git a/src/ipUtils_test.c b/src/ipUtils_test.c index 413bef7c..b54e019f 100644 --- a/src/ipUtils_test.c +++ b/src/ipUtils_test.c @@ -1,4 +1,4 @@ -#ifdef DEVEL +#if defined(DEVEL) && defined(APP_FEATURE_POOL_REGISTRATION) #include "ipUtils.h" #include "utils.h" @@ -55,4 +55,5 @@ void run_ipUtils_test() test3(); } -#endif // DEVEL +#endif // DEVEL && APP_FEATURE_POOL_REGISTRATION + diff --git a/src/messageSigning.c b/src/messageSigning.c index 41e5c00d..4d495ff1 100644 --- a/src/messageSigning.c +++ b/src/messageSigning.c @@ -64,6 +64,7 @@ void getCVoteRegistrationSignature(bip44_path_t* pathSpec, #endif } +#ifdef APP_FEATURE_OPCERT void getOpCertSignature(bip44_path_t* pathSpec, const uint8_t* opCertBodyBuffer, size_t opCertBodySize, uint8_t* outBuffer, size_t outSize) @@ -74,3 +75,4 @@ void getOpCertSignature(bip44_path_t* pathSpec, signRawMessageWithPath(pathSpec, opCertBodyBuffer, opCertBodySize, outBuffer, outSize); } +#endif // APP_FEATURE_OPCERT diff --git a/src/messageSigning.h b/src/messageSigning.h index fbf18f89..e2db31f8 100644 --- a/src/messageSigning.h +++ b/src/messageSigning.h @@ -11,8 +11,10 @@ void getCVoteRegistrationSignature(bip44_path_t* pathSpec, const uint8_t* payloadHashBuffer, size_t payloadHashSize, uint8_t* outBuffer, size_t outSize); +#ifdef APP_FEATURE_OPCERT void getOpCertSignature(bip44_path_t* pathSpec, const uint8_t* opCertBodyBuffer, size_t opCertBodySize, uint8_t* outBuffer, size_t outSize); +#endif // APP_FEATURE_OPCERT #endif // H_CARDANO_APP_MESSAGE_SIGNING diff --git a/src/nativeScriptHashBuilder.c b/src/nativeScriptHashBuilder.c index 6bea3f82..7e4a80b0 100644 --- a/src/nativeScriptHashBuilder.c +++ b/src/nativeScriptHashBuilder.c @@ -1,3 +1,5 @@ +#ifdef APP_FEATURE_NATIVE_SCRIPT_HASH + #include "cbor.h" #include "nativeScriptHashBuilder.h" @@ -227,3 +229,5 @@ void nativeScriptHashBuilder_finalize( #undef APPEND_CBOR #undef _TRACE_BUFFER #undef _TRACE + +#endif // APP_FEATURE_NATIVE_SCRIPT_HASH diff --git a/src/nativeScriptHashBuilder.h b/src/nativeScriptHashBuilder.h index de2653e4..a5508fb1 100644 --- a/src/nativeScriptHashBuilder.h +++ b/src/nativeScriptHashBuilder.h @@ -1,6 +1,8 @@ #ifndef H_CARDANO_APP_NATIVE_SCRIPT_HASH_BUILDER #define H_CARDANO_APP_NATIVE_SCRIPT_HASH_BUILDER +#ifdef APP_FEATURE_NATIVE_SCRIPT_HASH + #include "cardano.h" #include "hash.h" @@ -59,4 +61,6 @@ void nativeScriptHashBuilder_finalize( void run_nativeScriptHashBuilder_test(); /* #endif // DEVEL */ +#endif // APP_FEATURE_NATIVE_SCRIPT_HASH + #endif // H_CARDANO_APP_NATIVE_SCRIPT_HASH_BUILDER diff --git a/src/nativeScriptHashBuilder_test.c b/src/nativeScriptHashBuilder_test.c index c3f2e88c..5bcc340c 100644 --- a/src/nativeScriptHashBuilder_test.c +++ b/src/nativeScriptHashBuilder_test.c @@ -1,4 +1,4 @@ -#ifdef DEVEL +#if defined(DEVEL) && defined(APP_FEATURE_NATIVE_SCRIPT_HASH) #include "hexUtils.h" #include "nativeScriptHashBuilder.h" @@ -105,4 +105,5 @@ void run_nativeScriptHashBuilder_test() #undef FINALIZE #undef BEFORE_EACH #undef BUF_FROM_STR -#endif // DEVEL + +#endif // DEVEL && APP_FEATURE_NATIVE_SCRIPT_HASH diff --git a/src/runTests.c b/src/runTests.c index 8134edaa..959b63ca 100644 --- a/src/runTests.c +++ b/src/runTests.c @@ -32,6 +32,7 @@ void handleRunTests( // Note: Make sure to have RESET_ON_CRASH flag disabled // as it interferes with tests verifying assertions BEGIN_ASSERT_NOEXCEPT { + PRINTF("Running tests\n"); run_hex_test(); run_base58_test(); @@ -40,17 +41,26 @@ void handleRunTests( run_endian_test(); run_textUtils_test(); run_tokens_test(); + #if defined(APP_FEATURE_POOL_REGISTRATION) run_ipUtils_test(); + #endif run_hash_test(); run_cbor_test(); run_bip44_test(); run_key_derivation_test(); + #if !defined(APP_XS) run_addressUtilsByron_test(); + #endif run_addressUtilsShelley_test(); + #if !defined(APP_XS) run_txHashBuilder_test(); + #endif run_auxDataHashBuilder_test(); + #if defined(APP_FEATURE_NATIVE_SCRIPT_HASH) run_nativeScriptHashBuilder_test(); + #endif PRINTF("All tests done\n"); + } END_ASSERT_NOEXCEPT; io_send_buf(SUCCESS, NULL, 0); diff --git a/src/securityPolicy.c b/src/securityPolicy.c index 18d31fe8..a5ffd4b2 100644 --- a/src/securityPolicy.c +++ b/src/securityPolicy.c @@ -463,7 +463,7 @@ security_policy_t policyForSignTxInput(sign_tx_signingmode_t txSigningMode) static bool is_addressBytes_suitable_for_tx_output( const uint8_t* addressBuffer, size_t addressSize, - const uint8_t networkId, const uint32_t protocolMagic + const uint8_t networkId, const uint32_t protocolMagic __attribute__((unused)) ) { ASSERT(addressSize < BUFFER_SIZE_PARANOIA); @@ -482,7 +482,9 @@ static bool is_addressBytes_suitable_for_tx_output( return false; case BYRON: + #ifdef APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK CHECK(extractProtocolMagic(addressBuffer, addressSize) == protocolMagic); + #endif // APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK break; default: { @@ -1091,6 +1093,8 @@ security_policy_t policyForSignTxCertificateStaking( DENY(); // should not be reached } +#ifdef APP_FEATURE_POOL_RETIREMENT + security_policy_t policyForSignTxCertificateStakePoolRetirement( sign_tx_signingmode_t txSigningMode, const bip44_path_t* poolIdPath, @@ -1115,6 +1119,10 @@ security_policy_t policyForSignTxCertificateStakePoolRetirement( DENY(); // should not be reached } +#endif // APP_FEATURE_POOL_RETIREMENT + +#ifdef APP_FEATURE_POOL_REGISTRATION + security_policy_t policyForSignTxStakePoolRegistrationInit( sign_tx_signingmode_t txSigningMode, uint32_t numOwners @@ -1285,6 +1293,8 @@ security_policy_t policyForSignTxStakePoolRegistrationConfirm( ALLOW(); } +#endif // APP_FEATURE_POOL_REGISTRATION + // For each withdrawal security_policy_t policyForSignTxWithdrawal( sign_tx_signingmode_t txSigningMode, @@ -1461,6 +1471,8 @@ static inline security_policy_t _plutusWitnessPolicy(const bip44_path_t* path, b } } +#ifdef APP_FEATURE_POOL_REGISTRATION + static inline security_policy_t _poolRegistrationOwnerWitnessPolicy(const bip44_path_t* witnessPath, const bip44_path_t* poolOwnerPath) { switch (bip44_classifyPath(witnessPath)) { @@ -1504,6 +1516,8 @@ static inline security_policy_t _poolRegistrationOperatorWitnessPolicy(const bip } } +#endif // APP_FEATURE_POOL_REGISTRATION + // For each transaction witness // Note: witnesses reveal public key of an address and Ledger *does not* check // whether they correspond to previously declared inputs and certificates @@ -1511,7 +1525,7 @@ security_policy_t policyForSignTxWitness( sign_tx_signingmode_t txSigningMode, const bip44_path_t* witnessPath, bool mintPresent, - const bip44_path_t* poolOwnerPath + const bip44_path_t* poolOwnerPath __attribute__((unused)) ) { switch (txSigningMode) { @@ -1524,12 +1538,16 @@ security_policy_t policyForSignTxWitness( case SIGN_TX_SIGNINGMODE_PLUTUS_TX: return _plutusWitnessPolicy(witnessPath, mintPresent); + #ifdef APP_FEATURE_POOL_REGISTRATION + case SIGN_TX_SIGNINGMODE_POOL_REGISTRATION_OWNER: return _poolRegistrationOwnerWitnessPolicy(witnessPath, poolOwnerPath); case SIGN_TX_SIGNINGMODE_POOL_REGISTRATION_OPERATOR: return _poolRegistrationOperatorWitnessPolicy(witnessPath); + #endif // APP_FEATURE_POOL_REGISTRATION + default: ASSERT(false); } @@ -1853,6 +1871,7 @@ security_policy_t policyForCVoteRegistrationConfirm() PROMPT(); } +#ifdef APP_FEATURE_OPCERT security_policy_t policyForSignOpCert(const bip44_path_t* poolColdKeyPathSpec) { switch (bip44_classifyPath(poolColdKeyPathSpec)) { @@ -1872,6 +1891,7 @@ security_policy_t policyForSignOpCert(const bip44_path_t* poolColdKeyPathSpec) DENY(); // should not be reached } +#endif // APP_FEATURE_OPCERT security_policy_t policyForSignCVoteInit() { diff --git a/src/securityPolicy.h b/src/securityPolicy.h index 37613d7c..299c4298 100644 --- a/src/securityPolicy.h +++ b/src/securityPolicy.h @@ -113,11 +113,14 @@ security_policy_t policyForSignTxCertificateStaking( const certificate_type_t certificateType, const stake_credential_t* stakeCredential ); +#ifdef APP_FEATURE_POOL_RETIREMENT security_policy_t policyForSignTxCertificateStakePoolRetirement( sign_tx_signingmode_t txSigningMode, const bip44_path_t* stakeCredential, uint64_t epoch ); +#endif // APP_FEATURE_POOL_RETIREMENT +#ifdef APP_FEATURE_POOL_REGISTRATION security_policy_t policyForSignTxStakePoolRegistrationInit( sign_tx_signingmode_t txSigningMode, uint32_t numOwners @@ -147,7 +150,7 @@ security_policy_t policyForSignTxStakePoolRegistrationNoMetadata(); security_policy_t policyForSignTxStakePoolRegistrationConfirm( uint32_t numOwners, uint32_t numRelays ); - +#endif // APP_FEATURE_POOL_REGISTRATION security_policy_t policyForSignTxWithdrawal( sign_tx_signingmode_t txSigningMode, const stake_credential_t* stakeCredential @@ -185,7 +188,9 @@ security_policy_t policyForSignTxReferenceInput(const sign_tx_signingmode_t txSi security_policy_t policyForSignTxConfirm(); +#ifdef APP_FEATURE_OPCERT security_policy_t policyForSignOpCert(const bip44_path_t* poolColdKeyPathSpec); +#endif // APP_FEATURE_OPCERT security_policy_t policyForCVoteRegistrationVoteKey(); security_policy_t policyForCVoteRegistrationVoteKeyPath( diff --git a/src/signOpCert.c b/src/signOpCert.c index 9a3302b4..b28e820c 100644 --- a/src/signOpCert.c +++ b/src/signOpCert.c @@ -1,3 +1,5 @@ +#ifdef APP_FEATURE_OPCERT + #include "common.h" #include "signOpCert.h" @@ -243,3 +245,5 @@ static void signOpCert_ui_runStep() } UI_STEP_END(UI_STEP_INVALID); } + +#endif // APP_FEATURE_OPCERT diff --git a/src/signOpCert.h b/src/signOpCert.h index af844792..e88eec68 100644 --- a/src/signOpCert.h +++ b/src/signOpCert.h @@ -1,6 +1,8 @@ #ifndef H_CARDANO_APP_SIGN_OP_CERT #define H_CARDANO_APP_SIGN_OP_CERT +#ifdef APP_FEATURE_OPCERT + #include "common.h" #include "handlers.h" #include "bip44.h" @@ -20,4 +22,6 @@ typedef struct { int ui_step; } ins_sign_op_cert_context_t; +#endif // APP_FEATURE_OPCERT + #endif // H_CARDANO_APP_SIGN_OP_CERT \ No newline at end of file diff --git a/src/signTx.c b/src/signTx.c index 65746842..f8efc472 100644 --- a/src/signTx.c +++ b/src/signTx.c @@ -188,10 +188,14 @@ void tx_advanceStage() } ctx->stage = SIGN_STAGE_BODY_MINT; if (ctx->includeMint) { + #ifdef APP_FEATURE_TOKEN_MINTING txHashBuilder_enterMint(&BODY_CTX->txHashBuilder); signTxMint_init(); // wait for mint APDU break; + #else + ASSERT(false); + #endif // APP_FEATURE_TOKEN_MINTING } __attribute__((fallthrough)); @@ -312,7 +316,11 @@ void tx_advanceCertificatesStateIfAppropriate() break; default: + #ifdef APP_FEATURE_POOL_REGISTRATION ASSERT(ctx->stage == SIGN_STAGE_BODY_CERTIFICATES_POOL_SUBMACHINE); + #else + ASSERT(false); + #endif // APP_FEATURE_POOL_REGISTRATION } } @@ -343,6 +351,8 @@ static inline void checkForFinishedSubmachines() } break; + #ifdef APP_FEATURE_POOL_REGISTRATION + case SIGN_STAGE_BODY_CERTIFICATES_POOL_SUBMACHINE: if (signTxPoolRegistration_isFinished()) { TRACE(); @@ -353,6 +363,8 @@ static inline void checkForFinishedSubmachines() } break; + #endif // APP_FEATURE_POOL_REGISTRATION + case SIGN_STAGE_AUX_DATA_CVOTE_REGISTRATION_SUBMACHINE: if (signTxCVoteRegistration_isFinished()) { TRACE(); @@ -367,6 +379,8 @@ static inline void checkForFinishedSubmachines() } break; + #ifdef APP_FEATURE_TOKEN_MINTING + case SIGN_STAGE_BODY_MINT_SUBMACHINE: if (signTxMint_isFinished()) { TRACE(); @@ -376,6 +390,8 @@ static inline void checkForFinishedSubmachines() } break; + #endif // APP_FEATURE_TOKEN_MINTING + case SIGN_STAGE_BODY_COLLATERAL_OUTPUT_SUBMACHINE: if (isCurrentOutputFinished()) { TRACE(); @@ -480,13 +496,19 @@ static void signTx_handleInitAPDU(uint8_t p2, const uint8_t* wireDataBuffer, siz TRACE("Signing mode %d", (int) ctx->commonTxData.txSigningMode); switch (ctx->commonTxData.txSigningMode) { case SIGN_TX_SIGNINGMODE_ORDINARY_TX: - case SIGN_TX_SIGNINGMODE_POOL_REGISTRATION_OWNER: - case SIGN_TX_SIGNINGMODE_POOL_REGISTRATION_OPERATOR: case SIGN_TX_SIGNINGMODE_MULTISIG_TX: case SIGN_TX_SIGNINGMODE_PLUTUS_TX: // these signing modes are allowed break; + case SIGN_TX_SIGNINGMODE_POOL_REGISTRATION_OWNER: + case SIGN_TX_SIGNINGMODE_POOL_REGISTRATION_OPERATOR: + // these are allowed unless we have the XS app which does not have code for handling them + #ifndef APP_FEATURE_POOL_REGISTRATION + THROW(ERR_INVALID_DATA); + #endif // APP_FEATURE_POOL_REGISTRATION + break; + default: THROW(ERR_INVALID_DATA); } @@ -535,6 +557,13 @@ static void signTx_handleInitAPDU(uint8_t p2, const uint8_t* wireDataBuffer, siz ctx->shouldDisplayTxid = false; } + // minting not included in the XS app + #ifndef APP_FEATURE_TOKEN_MINTING + if (ctx->includeMint) { + THROW(ERR_INVALID_DATA); + } + #endif // APP_FEATURE_TOKEN_MINTING + security_policy_t policy = policyForSignTxInit( ctx->commonTxData.txSigningMode, ctx->commonTxData.networkId, @@ -925,16 +954,24 @@ static void _parseCertificateData(const uint8_t* wireDataBuffer, size_t wireData view_parseBuffer(certificateData->poolKeyHash, &view, POOL_KEY_HASH_LENGTH); break; + #ifdef APP_FEATURE_POOL_REGISTRATION + case CERTIFICATE_TYPE_STAKE_POOL_REGISTRATION: // nothing more to parse, certificate data will be provided // in additional APDUs processed by a submachine return; + #endif // APP_FEATURE_POOL_REGISTRATION + + #ifdef APP_FEATURE_POOL_RETIREMENT + case CERTIFICATE_TYPE_STAKE_POOL_RETIREMENT: _parsePathSpec(&view, &certificateData->poolIdPath); certificateData->epoch = parse_u8be(&view); break; + #endif // APP_FEATURE_POOL_RETIREMENT + default: THROW(ERR_INVALID_DATA); } @@ -1016,6 +1053,8 @@ static void _addCertificateDataToTx( break; } + #ifdef APP_FEATURE_POOL_RETIREMENT + case CERTIFICATE_TYPE_STAKE_POOL_RETIREMENT: { _fillHashFromPath(&BODY_CTX->stageData.certificate.poolIdPath, certificateData->poolKeyHash, SIZEOF(certificateData->poolKeyHash)); txHashBuilder_addCertificate_poolRetirement( @@ -1026,6 +1065,8 @@ static void _addCertificateDataToTx( break; } + #endif // APP_FEATURE_POOL_RETIREMENT + default: ASSERT(false); } @@ -1038,6 +1079,7 @@ static void signTx_handleCertificateAPDU(uint8_t p2, const uint8_t* wireDataBuff ASSERT(wireDataSize < BUFFER_SIZE_PARANOIA); ASSERT(BODY_CTX->currentCertificate < ctx->numCertificates); + #ifdef APP_FEATURE_POOL_REGISTRATION // delegate to state sub-machine for stake pool registration certificate data if (signTxPoolRegistration_isValidInstruction(p2)) { TRACE(); @@ -1048,6 +1090,7 @@ static void signTx_handleCertificateAPDU(uint8_t p2, const uint8_t* wireDataBuff signTxPoolRegistration_handleAPDU(p2, wireDataBuffer, wireDataSize); return; } + #endif // APP_FEATURE_POOL_REGISTRATION VALIDATE(p2 == P2_UNUSED, ERR_INVALID_REQUEST_PARAMETERS); CHECK_STAGE(SIGN_STAGE_BODY_CERTIFICATES); @@ -1097,6 +1140,8 @@ static void signTx_handleCertificateAPDU(uint8_t p2, const uint8_t* wireDataBuff return; } + #ifdef APP_FEATURE_POOL_REGISTRATION + case CERTIFICATE_TYPE_STAKE_POOL_REGISTRATION: { // pool registration certificates have a separate sub-machine for handling APDU and UI // nothing more to be done with them here, we just init the sub-machine @@ -1107,6 +1152,10 @@ static void signTx_handleCertificateAPDU(uint8_t p2, const uint8_t* wireDataBuff return; } + #endif // APP_FEATURE_POOL_REGISTRATION + + #ifdef APP_FEATURE_POOL_RETIREMENT + case CERTIFICATE_TYPE_STAKE_POOL_RETIREMENT: { security_policy_t policy = policyForSignTxCertificateStakePoolRetirement( ctx->commonTxData.txSigningMode, @@ -1130,6 +1179,8 @@ static void signTx_handleCertificateAPDU(uint8_t p2, const uint8_t* wireDataBuff return; } + #endif // APP_FEATURE_POOL_RETIREMENT + default: ASSERT(false); } @@ -1305,6 +1356,8 @@ static void signTx_handleValidityIntervalStartAPDU(uint8_t p2, const uint8_t* wi // ============================== MINT ============================== +#ifdef APP_FEATURE_TOKEN_MINTING + static void signTx_handleMintAPDU(uint8_t p2, const uint8_t* wireDataBuffer, size_t wireDataSize) { { @@ -1324,6 +1377,8 @@ static void signTx_handleMintAPDU(uint8_t p2, const uint8_t* wireDataBuffer, siz signTxMint_handleAPDU(p2, wireDataBuffer, wireDataSize); } +#endif // APP_FEATURE_TOKEN_MINTING + // ========================= SCRIPT DATA HASH ========================== static void signTx_handleScriptDataHashAPDU(uint8_t p2, const uint8_t* wireDataBuffer, size_t wireDataSize) @@ -1778,7 +1833,9 @@ static subhandler_fn_t* lookup_subhandler(uint8_t p1) CASE(0x06, signTx_handleCertificateAPDU); CASE(0x07, signTx_handleWithdrawalAPDU); CASE(0x09, signTx_handleValidityIntervalStartAPDU); + #ifdef APP_FEATURE_TOKEN_MINTING CASE(0x0b, signTx_handleMintAPDU); + #endif // APP_FEATURE_TOKEN_MINTING CASE(0x0c, signTx_handleScriptDataHashAPDU); CASE(0x0d, signTx_handleCollateralInputAPDU); CASE(0x0e, signTx_handleRequiredSignerAPDU); @@ -1819,11 +1876,15 @@ void signTx_handleAPDU( case SIGN_STAGE_BODY_FEE: case SIGN_STAGE_BODY_TTL: case SIGN_STAGE_BODY_CERTIFICATES: + #ifdef APP_FEATURE_POOL_REGISTRATION case SIGN_STAGE_BODY_CERTIFICATES_POOL_SUBMACHINE: + #endif // APP_FEATURE_POOL_REGISTRATION case SIGN_STAGE_BODY_WITHDRAWALS: case SIGN_STAGE_BODY_VALIDITY_INTERVAL: case SIGN_STAGE_BODY_MINT: + #ifdef APP_FEATURE_TOKEN_MINTING case SIGN_STAGE_BODY_MINT_SUBMACHINE: + #endif // APP_FEATURE_TOKEN_MINTING case SIGN_STAGE_BODY_SCRIPT_DATA_HASH: case SIGN_STAGE_BODY_COLLATERAL_INPUTS: case SIGN_STAGE_BODY_REQUIRED_SIGNERS: @@ -1869,11 +1930,15 @@ ins_sign_tx_body_context_t* accessBodyContext() case SIGN_STAGE_BODY_FEE: case SIGN_STAGE_BODY_TTL: case SIGN_STAGE_BODY_CERTIFICATES: + #ifdef APP_FEATURE_POOL_REGISTRATION case SIGN_STAGE_BODY_CERTIFICATES_POOL_SUBMACHINE: + #endif // APP_FEATURE_POOL_REGISTRATION case SIGN_STAGE_BODY_WITHDRAWALS: case SIGN_STAGE_BODY_VALIDITY_INTERVAL: case SIGN_STAGE_BODY_MINT: + #ifdef APP_FEATURE_TOKEN_MINTING case SIGN_STAGE_BODY_MINT_SUBMACHINE: + #endif // APP_FEATURE_TOKEN_MINTING case SIGN_STAGE_BODY_SCRIPT_DATA_HASH: case SIGN_STAGE_BODY_COLLATERAL_INPUTS: case SIGN_STAGE_BODY_REQUIRED_SIGNERS: diff --git a/src/signTx.h b/src/signTx.h index e9573733..aa3d8555 100644 --- a/src/signTx.h +++ b/src/signTx.h @@ -33,11 +33,15 @@ typedef enum { SIGN_STAGE_BODY_FEE = 29, SIGN_STAGE_BODY_TTL = 30, SIGN_STAGE_BODY_CERTIFICATES = 31, + #ifdef APP_FEATURE_POOL_REGISTRATION SIGN_STAGE_BODY_CERTIFICATES_POOL_SUBMACHINE = 32, // pool registration certificate sub-machine + #endif // APP_FEATURE_POOL_REGISTRATION SIGN_STAGE_BODY_WITHDRAWALS = 33, SIGN_STAGE_BODY_VALIDITY_INTERVAL = 34, SIGN_STAGE_BODY_MINT = 35, + #ifdef APP_FEATURE_TOKEN_MINTING SIGN_STAGE_BODY_MINT_SUBMACHINE = 36, + #endif // APP_FEATURE_TOKEN_MINTING SIGN_STAGE_BODY_SCRIPT_DATA_HASH = 37, SIGN_STAGE_BODY_COLLATERAL_INPUTS = 38, SIGN_STAGE_BODY_REQUIRED_SIGNERS = 39, @@ -172,9 +176,13 @@ typedef struct { } stageData; union { + #ifdef APP_FEATURE_POOL_REGISTRATION pool_registration_context_t pool_registration_subctx; + #endif // APP_FEATURE_POOL_REGISTRATION output_context_t output_subctx; + #ifdef APP_FEATURE_TOKEN_MINTING mint_context_t mint_subctx; + #endif // APP_FEATURE_TOKEN_MINTING } stageContext; } ins_sign_tx_body_context_t; diff --git a/src/signTxMint.c b/src/signTxMint.c index 589b499b..88ca8bc5 100644 --- a/src/signTxMint.c +++ b/src/signTxMint.c @@ -1,3 +1,5 @@ +#ifdef APP_FEATURE_TOKEN_MINTING + #include "signTxMint.h" #include "signTxMint_ui.h" #include "signTxUtils.h" @@ -290,3 +292,5 @@ bool signTxMint_isFinished() ASSERT(false); } } + +#endif // APP_FEATURE_TOKEN_MINTING diff --git a/src/signTxMint.h b/src/signTxMint.h index 97958082..51389107 100644 --- a/src/signTxMint.h +++ b/src/signTxMint.h @@ -1,6 +1,8 @@ #ifndef H_CARDANO_APP_SIGN_TX_MINT #define H_CARDANO_APP_SIGN_TX_MINT +#ifdef APP_FEATURE_TOKEN_MINTING + #include "common.h" #include "cardano.h" #include "addressUtilsShelley.h" @@ -55,4 +57,6 @@ void signTxMint_handleAPDU(uint8_t p2, const uint8_t* wireDataBuffer, size_t wir bool signTxMint_isFinished(); +#endif // APP_FEATURE_TOKEN_MINTING + #endif // H_CARDANO_APP_SIGN_TX_MINT diff --git a/src/signTxMint_ui.c b/src/signTxMint_ui.c index 5638b5e8..456871ec 100644 --- a/src/signTxMint_ui.c +++ b/src/signTxMint_ui.c @@ -1,3 +1,5 @@ +#ifdef APP_FEATURE_TOKEN_MINTING + #include "signTxMint.h" #include "signTxMint_ui.h" #include "signTxUtils.h" @@ -203,3 +205,5 @@ void signTxMint_handleConfirm_ui_runStep() } UI_STEP_END(HANDLE_CONFIRM_STEP_INVALID); } + +#endif // APP_FEATURE_TOKEN_MINTING \ No newline at end of file diff --git a/src/signTxMint_ui.h b/src/signTxMint_ui.h index be87f434..58f5aeaf 100644 --- a/src/signTxMint_ui.h +++ b/src/signTxMint_ui.h @@ -1,6 +1,8 @@ #ifndef H_CARDANO_APP_SIGN_TX_MINT_UI #define H_CARDANO_APP_SIGN_TX_MINT_UI +#ifdef APP_FEATURE_TOKEN_MINTING + enum { HANDLE_MINT_TOP_LEVEL_DATA_DISPLAY = 9200, HANDLE_MINT_TOP_LEVEL_DATA_RESPOND, @@ -34,4 +36,6 @@ enum { void signTxMint_handleConfirm_ui_runStep(); +#endif // APP_FEATURE_TOKEN_MINTING + #endif // H_CARDANO_APP_SIGN_TX_MINT_UI diff --git a/src/signTxPoolRegistration.c b/src/signTxPoolRegistration.c index 80fc4935..d66f6f81 100644 --- a/src/signTxPoolRegistration.c +++ b/src/signTxPoolRegistration.c @@ -1,3 +1,5 @@ +#ifdef APP_FEATURE_POOL_REGISTRATION + #include "signTx.h" #include "signTxPoolRegistration_ui.h" #include "state.h" @@ -969,3 +971,5 @@ void signTxPoolRegistration_handleAPDU(uint8_t p2, const uint8_t* wireDataBuffer ASSERT(false); } } + +#endif // APP_FEATURE_POOL_REGISTRATION diff --git a/src/signTxPoolRegistration.h b/src/signTxPoolRegistration.h index 7363147b..85504acb 100644 --- a/src/signTxPoolRegistration.h +++ b/src/signTxPoolRegistration.h @@ -1,6 +1,8 @@ #ifndef H_CARDANO_APP_SIGN_TX_POOL_REGISTRATION #define H_CARDANO_APP_SIGN_TX_POOL_REGISTRATION +#ifdef APP_FEATURE_POOL_REGISTRATION + #include "common.h" #include "cardano.h" #include "txHashBuilder.h" @@ -83,4 +85,6 @@ void signTxPoolRegistration_handleAPDU(uint8_t p2, const uint8_t* wireDataBuffer bool signTxPoolRegistration_isFinished(); +#endif // APP_FEATURE_POOL_REGISTRATION + #endif // H_CARDANO_APP_SIGN_TX_POOL_REGISTRATION diff --git a/src/signTxPoolRegistration_ui.c b/src/signTxPoolRegistration_ui.c index 04ece815..855d840b 100644 --- a/src/signTxPoolRegistration_ui.c +++ b/src/signTxPoolRegistration_ui.c @@ -1,3 +1,5 @@ +#ifdef APP_FEATURE_POOL_REGISTRATION + #include "signTx.h" #include "signTxPoolRegistration_ui.h" #include "state.h" @@ -792,3 +794,5 @@ void signTxPoolRegistration_handleConfirm_ui_runStep() } UI_STEP_END(HANDLE_CONFIRM_STEP_INVALID); } + +#endif // APP_FEATURE_POOL_REGISTRATION diff --git a/src/signTxPoolRegistration_ui.h b/src/signTxPoolRegistration_ui.h index b155805f..b9b60ea2 100644 --- a/src/signTxPoolRegistration_ui.h +++ b/src/signTxPoolRegistration_ui.h @@ -1,6 +1,8 @@ #ifndef H_CARDANO_APP_SIGN_TX_POOL_REGISATRATION_UI #define H_CARDANO_APP_SIGN_TX_POOL_REGISATRATION_UI +#ifdef APP_FEATURE_POOL_REGISTRATION + // ============================== INIT ============================== enum { @@ -122,4 +124,7 @@ enum { }; void signTxPoolRegistration_handleConfirm_ui_runStep(); + +#endif // APP_FEATURE_POOL_REGISTRATION + #endif // H_CARDANO_APP_SIGN_TX_POOL_REGISATRATION_UI diff --git a/src/signTx_ui.c b/src/signTx_ui.c index 97b71c73..91c00b91 100644 --- a/src/signTx_ui.c +++ b/src/signTx_ui.c @@ -74,12 +74,17 @@ static const char* _newTxLine1(sign_tx_signingmode_t txSigningMode) #ifdef HAVE_NBGL static void signTx_handleInit_ui_runStep_cb(void) { + // if the protocol magic check is not enabled, + // displaying the protocol magic might be misleading, + // so we must not show it + #ifdef APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK char networkParams[100] = {0}; ui_getNetworkParamsScreen_2( networkParams, SIZEOF(networkParams), ctx->commonTxData.protocolMagic); fill_and_display_if_required("Protocol magic", networkParams, signTx_handleInit_ui_runStep, respond_with_user_reject); + #endif } #endif // HAVE_NBGL @@ -118,7 +123,8 @@ void signTx_handleInit_ui_runStep() #ifdef HAVE_BAGL ui_displayNetworkParamsScreen( "Network details", - ctx->commonTxData.networkId, ctx->commonTxData.protocolMagic, + ctx->commonTxData.networkId, + ctx->commonTxData.protocolMagic, this_fn ); #elif defined(HAVE_NBGL) @@ -518,6 +524,8 @@ void signTx_handleCertificate_ui_runStep() UI_STEP_END(HANDLE_CERTIFICATE_STEP_INVALID); } +#ifdef APP_FEATURE_POOL_RETIREMENT + void signTx_handleCertificatePoolRetirement_ui_runStep() { TRACE("UI step %d", ctx->ui_step); @@ -579,6 +587,8 @@ void signTx_handleCertificatePoolRetirement_ui_runStep() UI_STEP_END(HANDLE_CERTIFICATE_POOL_RETIREMENT_STEP_INVALID); } +#endif // APP_FEATURE_POOL_RETIREMENT + // ============================== WITHDRAWALS ============================== void signTx_handleWithdrawal_ui_runStep() diff --git a/src/state.h b/src/state.h index 8ca7f18a..f95bcb53 100644 --- a/src/state.h +++ b/src/state.h @@ -14,9 +14,13 @@ typedef union { // Here should go states of all instructions ins_get_keys_context_t getKeysContext; ins_derive_address_context_t deriveAddressContext; + #ifdef APP_FEATURE_NATIVE_SCRIPT_HASH ins_derive_native_script_hash_context_t deriveNativeScriptHashContext; + #endif // APP_FEATURE_NATIVE_SCRIPT_HASH ins_sign_tx_context_t signTxContext; + #ifdef APP_FEATURE_OPCERT ins_sign_op_cert_context_t signOpCertContext; + #endif // APP_FEATURE_OPCERT ins_sign_cvote_context_t signCVoteContext; } instructionState_t; diff --git a/src/txHashBuilder.c b/src/txHashBuilder.c index 3c0ff551..43efdff3 100644 --- a/src/txHashBuilder.c +++ b/src/txHashBuilder.c @@ -850,6 +850,8 @@ void txHashBuilder_addCertificate_delegation( } } +#ifdef APP_FEATURE_POOL_RETIREMENT + void txHashBuilder_addCertificate_poolRetirement( tx_hash_builder_t* builder, const uint8_t* poolKeyHash, size_t poolKeyHashSize, @@ -882,6 +884,10 @@ void txHashBuilder_addCertificate_poolRetirement( } } +#endif // APP_FEATURE_POOL_RETIREMENT + +#ifdef APP_FEATURE_POOL_REGISTRATION + void txHashBuilder_poolRegistrationCertificate_enter( tx_hash_builder_t* builder, uint16_t numOwners, uint16_t numRelays @@ -1276,6 +1282,8 @@ void txHashBuilder_addPoolRegistrationCertificate_addPoolMetadata_null( builder->state = TX_HASH_BUILDER_IN_CERTIFICATES; } +#endif // APP_FEATURE_POOL_REGISTRATION + static void txHashBuilder_assertCanLeaveCertificates(tx_hash_builder_t* builder) { _TRACE("state = %d, remainingCertificates = %u", builder->state, builder->remainingCertificates); @@ -1430,6 +1438,8 @@ static void txHashBuilder_assertCanLeaveValidityIntervalStart(tx_hash_builder_t* // ============================== MINT ============================== +#ifdef APP_FEATURE_TOKEN_MINTING + void txHashBuilder_enterMint(tx_hash_builder_t* builder) { _TRACE("state = %d", builder->state); @@ -1486,6 +1496,8 @@ void txHashBuilder_addMint_token( amount < 0 ? CBOR_TYPE_NEGATIVE : CBOR_TYPE_UNSIGNED); } +#endif // APP_FEATURE_TOKEN_MINTING + static void txHashBuilder_assertCanLeaveMint(tx_hash_builder_t* builder) { _TRACE("state = %u, remainingMintAssetGroups = %u, remainingMintTokens = %u", diff --git a/src/txHashBuilder.h b/src/txHashBuilder.h index e633bca6..34e0b675 100644 --- a/src/txHashBuilder.h +++ b/src/txHashBuilder.h @@ -264,12 +264,18 @@ void txHashBuilder_addCertificate_delegation( const uint8_t* poolKeyHash, size_t poolKeyHashSize ); +#ifdef APP_FEATURE_POOL_RETIREMENT + void txHashBuilder_addCertificate_poolRetirement( tx_hash_builder_t* builder, const uint8_t* poolKeyHash, size_t poolKeyHashSize, uint64_t epoch ); +#endif // APP_FEATURE_POOL_RETIREMENT + +#ifdef APP_FEATURE_POOL_REGISTRATION + void txHashBuilder_poolRegistrationCertificate_enter( tx_hash_builder_t* builder, uint16_t numOwners, uint16_t numRelays @@ -320,6 +326,8 @@ void txHashBuilder_addPoolRegistrationCertificate_addPoolMetadata_null( tx_hash_builder_t* builder ); +#endif // APP_FEATURE_POOL_REGISTRATION + void txHashBuilder_enterWithdrawals(tx_hash_builder_t* builder); void txHashBuilder_addWithdrawal( @@ -338,6 +346,8 @@ void txHashBuilder_addValidityIntervalStart( uint64_t validityIntervalStart ); +#ifdef APP_FEATURE_TOKEN_MINTING + void txHashBuilder_enterMint(tx_hash_builder_t* builder); void txHashBuilder_addMint_topLevelData( @@ -356,6 +366,8 @@ void txHashBuilder_addMint_token( int64_t amount ); +#endif // APP_FEATURE_TOKEN_MINTING + void txHashBuilder_addScriptDataHash( tx_hash_builder_t* builder, const uint8_t* scriptHashData, size_t scriptHashDataSize @@ -406,7 +418,7 @@ void txHashBuilder_finalize( ); -#ifdef DEVEL +#if defined(DEVEL) && !defined(APP_XS) void run_txHashBuilder_test(); #endif // DEVEL diff --git a/src/txHashBuilder_test.c b/src/txHashBuilder_test.c index 3dad47a3..52b6d4a4 100644 --- a/src/txHashBuilder_test.c +++ b/src/txHashBuilder_test.c @@ -1,4 +1,4 @@ -#ifdef DEVEL +#if defined(DEVEL) && !defined(APP_XS) #include "txHashBuilder.h" #include "cardano.h" diff --git a/src/uiScreens_bagl.c b/src/uiScreens_bagl.c index 1e158a0c..cea937ae 100644 --- a/src/uiScreens_bagl.c +++ b/src/uiScreens_bagl.c @@ -653,11 +653,23 @@ void ui_displayNetworkParamsScreen( STATIC_ASSERT(!IS_SIGNED(networkId), "signed type for %u"); STATIC_ASSERT(sizeof(protocolMagic) <= sizeof(unsigned), "oversized type for %u"); STATIC_ASSERT(!IS_SIGNED(protocolMagic), "signed type for %u"); + + #ifdef APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK snprintf( networkParams, SIZEOF(networkParams), "network id %u / protocol magic %u", networkId, protocolMagic ); + #else + // if the protocol magic check is not enabled, + // displaying the protocol magic might be misleading, + // so we must not show it + snprintf( + networkParams, SIZEOF(networkParams), + "network id %u", + networkId + ); + #endif // APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK ASSERT(strlen(networkParams) + 1 < SIZEOF(networkParams)); ui_displayPaginatedText( @@ -702,6 +714,8 @@ void ui_displayPoolMarginScreen( ); } +#ifdef APP_FEATURE_POOL_REGISTRATION + void ui_displayPoolOwnerScreen( const pool_owner_t* owner, uint32_t ownerIndex, @@ -859,6 +873,8 @@ void ui_displayIpPortScreen( ); } +#endif // APP_FEATURE_POOL_REGISTRATION + void ui_displayInputScreen( const sign_tx_transaction_input_t* input, ui_callback_fn_t callback) diff --git a/src/uiScreens_bagl.h b/src/uiScreens_bagl.h index f4073130..abb162bb 100644 --- a/src/uiScreens_bagl.h +++ b/src/uiScreens_bagl.h @@ -134,6 +134,8 @@ void ui_displayPoolMarginScreen( ui_callback_fn_t callback ); +#ifdef APP_FEATURE_POOL_REGISTRATION + __noinline_due_to_stack__ void ui_displayPoolOwnerScreen( const pool_owner_t* owner, @@ -167,6 +169,8 @@ void ui_displayIpPortScreen( ui_callback_fn_t callback ); +#endif // APP_FEATURE_POOL_REGISTRATION + __noinline_due_to_stack__ void ui_displayInputScreen( const sign_tx_transaction_input_t* input, diff --git a/src/uiScreens_nbgl.c b/src/uiScreens_nbgl.c index db1b7bf9..1dfca96a 100644 --- a/src/uiScreens_nbgl.c +++ b/src/uiScreens_nbgl.c @@ -620,6 +620,8 @@ void ui_getPoolMarginScreen( TRACE("%s", line1); } +#ifdef APP_FEATURE_POOL_REGISTRATION + void ui_getPoolOwnerScreen( char* firstLine, const size_t firstLineSize, @@ -748,6 +750,8 @@ void ui_getIpPortScreen( ASSERT(strlen(portStr) + 1 < portStrSize); } +#endif // APP_FEATURE_POOL_REGISTRATION + void ui_getInputScreen( char* line, const size_t lineSize, diff --git a/src/uiScreens_nbgl.h b/src/uiScreens_nbgl.h index b7424145..e5120cfa 100644 --- a/src/uiScreens_nbgl.h +++ b/src/uiScreens_nbgl.h @@ -165,6 +165,8 @@ void ui_getPoolMarginScreen( uint64_t marginNumerator, uint64_t marginDenominator ); +#ifdef APP_FEATURE_POOL_REGISTRATION + __noinline_due_to_stack__ void ui_getPoolOwnerScreen( char* firstLine, @@ -200,6 +202,8 @@ void ui_getIpPortScreen( const ipport_t* port ); +#endif // APP_FEATURE_POOL_REGISTRATION + __noinline_due_to_stack__ void ui_getInputScreen( char* line,