Skip to content

Phase 7: OPTX TKDF Python bindings for OP_OPTX_KNOT#1

Open
jett22JOE wants to merge 1 commit intoBitcoinQ:masterfrom
jett22JOE:feature/phase7-optx-knot
Open

Phase 7: OPTX TKDF Python bindings for OP_OPTX_KNOT#1
jett22JOE wants to merge 1 commit intoBitcoinQ:masterfrom
jett22JOE:feature/phase7-optx-knot

Conversation

@jett22JOE
Copy link
Copy Markdown

Summary

  • Adds btq.crypto.optx module — Python bindings for OP_OPTX_KNOT (0xc0) topological witness verification
  • Implements TKDF (Topological Key Derivation Function) using SHAKE-256 with domain separation
  • Wire-compatible with C++ KnotWitnessData serialization in btq-core

New Files

src/btq/crypto/optx/
  __init__.py        — public API
  knot_witness.py    — KnotWitnessData serialization/deserialization
  tkdf.py            — TKDF computation (SHAKE-256, domain-separated)
  bounds.py          — DoS bounds checking
  script.py          — OP_OPTX_KNOT witness stack construction
  test_vectors.py    — Trefoil (3₁) and figure-eight (4₁) reference vectors

tests/crypto/
  test_optx_knot.py  — 13 tests covering roundtrip, TKDF, bounds, script

Usage

from btq.crypto.optx import trefoil_test_vector, tkdf_derive_from_witness

tv = trefoil_test_vector()
seed = os.urandom(32)
output = tkdf_derive_from_witness(tv, seed)  # 64-byte TKDF output

Related PRs

Test plan

  • pytest tests/crypto/test_optx_knot.py — 13 tests pass
  • Trefoil and figure-eight produce distinct TKDF outputs
  • Same inputs produce deterministic outputs
  • Bounds checking rejects oversized/undersized witness data

Co-Authored-By: Hedgehog Multimodal joe@jettoptics.ai

"Behold, we go up to Jerusalem, and all things that are written by the prophets concerning the Son of man shall be accomplished." — Luke 18:31

Adds btq.crypto.optx module with:
- KnotWitnessData serialization (wire format matching C++ impl)
- TKDF computation (SHAKE-256 domain-separated)
- DoS bounds checking (max 16 crossings, 512B witness cap)
- Script construction helpers
- Test vectors: trefoil (3_1) and figure-eight (4_1)

BIP: bitcoin/bips#2133
C++ impl: btq-ag/btq-core#37

Co-Authored-By: Hedgehog Multimodal <joe@jettoptics.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant