From 6ec710695f7e06548e40ec5348c9621c112445cf Mon Sep 17 00:00:00 2001 From: Harshil <181649964+Harshil-1603@users.noreply.github.com> Date: Wed, 21 Oct 2026 19:33:38 +0530 Subject: [PATCH 1/5] Require both d and u properties for andor conditions --- src/embit/descriptor/miniscript.py | 4 ++-- tests/tests/test_descriptor.py | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/embit/descriptor/miniscript.py b/src/embit/descriptor/miniscript.py index 9783afc1..7043ff99 100644 --- a/src/embit/descriptor/miniscript.py +++ b/src/embit/descriptor/miniscript.py @@ -276,7 +276,7 @@ def verify(self): if self.args[0].type != "B": raise MiniscriptError("andor: X should be 'B'") px = self.args[0].properties - if "d" not in px and "u" not in px: + if "d" not in px or "u" not in px: raise MiniscriptError("andor: X should be 'du'") if self.args[1].type != self.args[2].type: raise MiniscriptError("andor: Y and Z should have the same types") @@ -424,7 +424,7 @@ def verify(self): if self.args[0].type != "B": raise MiniscriptError("and_n: X should be 'B'") px = self.args[0].properties - if "d" not in px and "u" not in px: + if "d" not in px or "u" not in px: raise MiniscriptError("and_n: X should be 'du'") if self.args[1].type != "B": raise MiniscriptError("and_n: Y should be B") diff --git a/tests/tests/test_descriptor.py b/tests/tests/test_descriptor.py index 2101227b..5be2eef5 100644 --- a/tests/tests/test_descriptor.py +++ b/tests/tests/test_descriptor.py @@ -2,7 +2,7 @@ from binascii import hexlify from embit.descriptor import Descriptor, Key from embit.descriptor.arguments import KeyHash, Number -from embit.descriptor.miniscript import OPERATORS, WRAPPERS +from embit.descriptor.miniscript import Miniscript, OPERATORS, WRAPPERS from embit.descriptor.errors import MiniscriptError from embit.descriptor.checksum import add_checksum, DescriptorError from embit.networks import NETWORKS @@ -325,6 +325,27 @@ def test_invalid_miniscript(self): for desc in invalid_descs: self.assertRaises(MiniscriptError, Descriptor.from_string, desc) + def test_andor_requires_dissatisfiable_unit_left_child(self): + key = "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798" + for template in ("andor(%s,1,0)", "and_n(%s,1)"): + for left in ("1", "or_i(1,1)", "or_i(0,older(10))", "older(10)"): + source = template % left + with self.subTest(source=source): + fragment = Miniscript.from_string(source) + with self.assertRaises(MiniscriptError): + fragment.verify() + with self.assertRaises(MiniscriptError): + Descriptor.from_string("wsh(%s)" % source) + for left in ("0", "pk(%s)" % key): + source = template % left + with self.subTest(source=source): + fragment = Miniscript.from_string(source) + fragment.verify() + self.assertEqual( + Descriptor.from_string("wsh(%s)" % source).miniscript.compile(), + fragment.compile(), + ) + def test_len(self): """Checks that len(miniscript) returns correct length""" for op in OPERATORS: From e223867b62280c4e4a4511697506cfe757ffb86d Mon Sep 17 00:00:00 2001 From: Harshil <181649964+Harshil-1603@users.noreply.github.com> Date: Fri, 23 Oct 2026 03:13:28 +0530 Subject: [PATCH 2/5] Keep unsatisfiable andor controls in bare type verification Zero-left controls satisfy the d/u type requirements but have no satisfaction. Preserve their bare verify() checks and all invalid-type rejections, while limiting descriptor positives to public-key controls. Assisted-by: OpenAI Codex (GPT-6) --- tests/tests/test_descriptor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/tests/test_descriptor.py b/tests/tests/test_descriptor.py index 5be2eef5..e3e19101 100644 --- a/tests/tests/test_descriptor.py +++ b/tests/tests/test_descriptor.py @@ -223,7 +223,6 @@ def test_descriptor_from_string_validation(self): for d in keys: Descriptor.from_string(d) - # invalid keys = [ # # LIANA_MINISCRIPT_DESCRIPTOR @@ -341,6 +340,10 @@ def test_andor_requires_dissatisfiable_unit_left_child(self): with self.subTest(source=source): fragment = Miniscript.from_string(source) fragment.verify() + if left == "0": + # These fragments have valid types but no satisfaction; + # they are controls for bare verify(), not descriptors. + continue self.assertEqual( Descriptor.from_string("wsh(%s)" % source).miniscript.compile(), fragment.compile(), From ccff026014c16ab937b942855c8616ae5f581708 Mon Sep 17 00:00:00 2001 From: Harshil <181649964+Harshil-1603@users.noreply.github.com> Date: Wed, 11 Nov 2026 08:28:46 +0530 Subject: [PATCH 3/5] Cover wrapped miniscript conditions and document stricter validation Assisted-by: OpenAI Codex --- CHANGELOG.md | 7 +++++++ tests/tests/test_descriptor.py | 12 +++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b11788d..b37f9912 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Require both dissatisfiable and unit properties for the left child of + miniscript `andor` and `and_n` fragments. + ## [0.8.2] - 2026-08-08 ### Changed diff --git a/tests/tests/test_descriptor.py b/tests/tests/test_descriptor.py index e3e19101..fedeec94 100644 --- a/tests/tests/test_descriptor.py +++ b/tests/tests/test_descriptor.py @@ -327,7 +327,13 @@ def test_invalid_miniscript(self): def test_andor_requires_dissatisfiable_unit_left_child(self): key = "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798" for template in ("andor(%s,1,0)", "and_n(%s,1)"): - for left in ("1", "or_i(1,1)", "or_i(0,older(10))", "older(10)"): + for left in ( + "1", + "or_i(1,1)", + "or_i(0,older(10))", + "dv:older(1)", + "older(10)", + ): source = template % left with self.subTest(source=source): fragment = Miniscript.from_string(source) @@ -340,10 +346,6 @@ def test_andor_requires_dissatisfiable_unit_left_child(self): with self.subTest(source=source): fragment = Miniscript.from_string(source) fragment.verify() - if left == "0": - # These fragments have valid types but no satisfaction; - # they are controls for bare verify(), not descriptors. - continue self.assertEqual( Descriptor.from_string("wsh(%s)" % source).miniscript.compile(), fragment.compile(), From 91c534020de3ce06f6bc26623072993660373f3d Mon Sep 17 00:00:00 2001 From: Harshil <181649964+Harshil-1603@users.noreply.github.com> Date: Fri, 13 Nov 2026 03:05:53 +0530 Subject: [PATCH 4/5] Keep unsatisfiable miniscript controls in type-only verification Apply the concrete reviewer request without changing runtime behavior. Assisted-by: OpenAI Codex --- tests/tests/test_descriptor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/tests/test_descriptor.py b/tests/tests/test_descriptor.py index fedeec94..5bee1f81 100644 --- a/tests/tests/test_descriptor.py +++ b/tests/tests/test_descriptor.py @@ -346,6 +346,11 @@ def test_andor_requires_dissatisfiable_unit_left_child(self): with self.subTest(source=source): fragment = Miniscript.from_string(source) fragment.verify() + if left == "0": + # Type-valid but unsatisfiable: Core rejects these as + # descriptors. Until sanity checks (#144), only assert + # verify(); pk() still covers descriptor parsing. + continue self.assertEqual( Descriptor.from_string("wsh(%s)" % source).miniscript.compile(), fragment.compile(), From e4d3a99c836e1c4f235bc73edbddcc1a649579b9 Mon Sep 17 00:00:00 2001 From: Harshil <181649964+Harshil-1603@users.noreply.github.com> Date: Sat, 14 Nov 2026 09:46:51 +0530 Subject: [PATCH 5/5] Keep descriptor regressions compatible with the MicroPython shim Use plain loops instead of unsupported subTest contexts, preserving all assertions. Use hexlify for older MicroPython builds where applicable. Assisted-by: OpenAI Codex --- tests/tests/test_descriptor.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/tests/tests/test_descriptor.py b/tests/tests/test_descriptor.py index 5bee1f81..2d263204 100644 --- a/tests/tests/test_descriptor.py +++ b/tests/tests/test_descriptor.py @@ -335,26 +335,24 @@ def test_andor_requires_dissatisfiable_unit_left_child(self): "older(10)", ): source = template % left - with self.subTest(source=source): - fragment = Miniscript.from_string(source) - with self.assertRaises(MiniscriptError): - fragment.verify() - with self.assertRaises(MiniscriptError): - Descriptor.from_string("wsh(%s)" % source) + fragment = Miniscript.from_string(source) + with self.assertRaises(MiniscriptError): + fragment.verify() + with self.assertRaises(MiniscriptError): + Descriptor.from_string("wsh(%s)" % source) for left in ("0", "pk(%s)" % key): source = template % left - with self.subTest(source=source): - fragment = Miniscript.from_string(source) - fragment.verify() - if left == "0": - # Type-valid but unsatisfiable: Core rejects these as - # descriptors. Until sanity checks (#144), only assert - # verify(); pk() still covers descriptor parsing. - continue - self.assertEqual( - Descriptor.from_string("wsh(%s)" % source).miniscript.compile(), - fragment.compile(), - ) + fragment = Miniscript.from_string(source) + fragment.verify() + if left == "0": + # Type-valid but unsatisfiable: Core rejects these as + # descriptors. Until sanity checks (#144), only assert + # verify(); pk() still covers descriptor parsing. + continue + self.assertEqual( + Descriptor.from_string("wsh(%s)" % source).miniscript.compile(), + fragment.compile(), + ) def test_len(self): """Checks that len(miniscript) returns correct length"""