Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/embit/descriptor/miniscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
33 changes: 31 additions & 2 deletions tests/tests/test_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -223,7 +223,6 @@ def test_descriptor_from_string_validation(self):
for d in keys:
Descriptor.from_string(d)


# invalid
keys = [
# # LIANA_MINISCRIPT_DESCRIPTOR
Expand Down Expand Up @@ -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:
Expand Down
Loading