Skip to content

Commit

Permalink
Increase the memory limit for descriptor templates; add test for a la…
Browse files Browse the repository at this point in the history
…rger miniscript policy exercising the limit on Nano S
  • Loading branch information
bigspider committed Dec 14, 2023
1 parent 82c084a commit e62ae69
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/common/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
32 changes: 32 additions & 0 deletions tests/test_e2e_miniscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e62ae69

Please sign in to comment.