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/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..2d263204 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 @@ -223,7 +223,6 @@ def test_descriptor_from_string_validation(self): for d in keys: Descriptor.from_string(d) - # invalid keys = [ # # LIANA_MINISCRIPT_DESCRIPTOR @@ -325,6 +324,36 @@ 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))", + "dv:older(1)", + "older(10)", + ): + source = template % left + 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 + 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""" for op in OPERATORS: