From a027303de8eec15a79d899d813bc6fb7794ec5e5 Mon Sep 17 00:00:00 2001 From: Salvatore Ingala <6681844+bigspider@users.noreply.github.com> Date: Thu, 14 Dec 2023 10:00:18 +0100 Subject: [PATCH] Increase the memory limit for descriptor templates; add test for a larger miniscript policy exercising the limit on Nano S --- src/common/wallet.h | 4 ++-- tests/test_e2e_miniscript.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/common/wallet.h b/src/common/wallet.h index 6ff81920e..112ee68b4 100644 --- a/src/common/wallet.h +++ b/src/common/wallet.h @@ -38,11 +38,11 @@ #ifdef TARGET_NANOS // this amount should be enough for many useful policies #define MAX_DESCRIPTOR_TEMPLATE_LENGTH_V2 192 -#define MAX_WALLET_POLICY_BYTES 264 +#define MAX_WALLET_POLICY_BYTES 308 #else // on larger devices, we can afford to reserve a lot more memory #define MAX_DESCRIPTOR_TEMPLATE_LENGTH_V2 512 -#define MAX_WALLET_POLICY_BYTES 768 +#define MAX_WALLET_POLICY_BYTES 896 #endif #define MAX_DESCRIPTOR_TEMPLATE_LENGTH \ diff --git a/tests/test_e2e_miniscript.py b/tests/test_e2e_miniscript.py index a7bb09d87..1d4c3236e 100644 --- a/tests/test_e2e_miniscript.py +++ b/tests/test_e2e_miniscript.py @@ -332,6 +332,38 @@ def test_e2e_miniscript_me_and_bob_or_me_and_carl_1(rpc, rpc_test_wallet, client run_test_e2e(wallet_policy, [core_wallet_name1], rpc, rpc_test_wallet, client, speculos_globals, comm) +def test_e2e_miniscript_nanos_large_policy(rpc, rpc_test_wallet, client: Client, speculos_globals: SpeculosGlobals, comm: Union[TransportClient, SpeculosClient], model: str): + # Nano S has much tighter memory limits. + # The policy in this test requires 304 bytes after is parsed, which is larger than the previous 276. + # However, it is a kind of policy in the style of the Liana wallet, that it would be nice to support. + + # reported by pythcoiner + + if model != "nanos": + pytest.skip("Test only for Nano S") + + core_wallet_name1, core_xpub_orig1 = create_new_wallet() + core_wallet_name2, core_xpub_orig2 = create_new_wallet() + core_wallet_name3, core_xpub_orig3 = create_new_wallet() + + path = "44'/1'/0'" + internal_xpub = get_internal_xpub(speculos_globals.seed, path) + internal_xpub_orig = f"[{speculos_globals.master_key_fingerprint.hex()}/{path}]{internal_xpub}" + + wallet_policy = WalletPolicy( + name="Memory-intensive", + descriptor_template="wsh(or_d(multi(4,@0/<0;1>/*,@1/<0;1>/*,@2/<0;1>/*,@3/<0;1>/*),and_v(v:thresh(3,pkh(@0/<2;3>/*),a:pkh(@1/<2;3>/*),a:pkh(@2/<2;3>/*),a:pkh(@3/<2;3>/*)),older(65535))))", + keys_info=[ + internal_xpub_orig, + f"{core_xpub_orig1}", + f"{core_xpub_orig2}", + f"{core_xpub_orig3}", + ]) + + run_test_e2e(wallet_policy, [core_wallet_name1, core_wallet_name2, core_wallet_name3], rpc, + rpc_test_wallet, client, speculos_globals, comm) + + def test_e2e_miniscript_policy_with_a(rpc, rpc_test_wallet, client: Client, speculos_globals: SpeculosGlobals, comm: Union[TransportClient, SpeculosClient]): # versions 2.1.0 and 2.1.1 of the app incorrectly compiled the 'a:' wrapper, producing incorrect addresses