From f7b78df0244f8383ee5a0a1b43399b026d750f4f Mon Sep 17 00:00:00 2001 From: Novo Date: Sun, 25 Oct 2026 18:01:56 +0100 Subject: [PATCH] BIP352: validate control block size in reference impl --- bip-0352/reference.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bip-0352/reference.py b/bip-0352/reference.py index c334d328..b38a29e5 100755 --- a/bip-0352/reference.py +++ b/bip-0352/reference.py @@ -32,6 +32,10 @@ from bitcoin_utils import ( K_max = 2323 # per-group recipient limit NUMS_H = 0x50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0 +TAPROOT_CONTROL_BASE_SIZE = 33 +TAPROOT_CONTROL_NODE_SIZE = 32 +TAPROOT_CONTROL_MAX_NODE_COUNT = 128 +TAPROOT_CONTROL_MAX_SIZE = TAPROOT_CONTROL_BASE_SIZE + TAPROOT_CONTROL_NODE_SIZE * TAPROOT_CONTROL_MAX_NODE_COUNT def get_pubkey_from_input(vin: VinInfo) -> GE: @@ -79,6 +83,9 @@ def get_pubkey_from_input(vin: VinInfo) -> GE: # Script-path spend control_block = witnessStack[-1] # control block is <32 byte internal key> and 0 or more <32 byte hash> + assert len(control_block) >= TAPROOT_CONTROL_BASE_SIZE + assert len(control_block) <= TAPROOT_CONTROL_MAX_SIZE + assert (len(control_block) - TAPROOT_CONTROL_BASE_SIZE) % TAPROOT_CONTROL_NODE_SIZE == 0 internal_key = control_block[1:33] if (internal_key == NUMS_H.to_bytes(32, 'big')): # Skip if NUMS_H