TYPE 0x0905 · LEGACY FAMILY

P2WSH_LEGACY

Legacy P2WSH (pay-to-witness-script-hash) wrapped as a typed Ladder Script block. SHA256 of inner conditions must match. Same pattern as P2SH but with SHA256.

Legacy Invertible
P2WSH_LEGACY SHA256 + INNER EVAL Inner script must be valid Ladder Script conditions
FieldData TypeSizeSideDescription
hash256 HASH256 32 B Conditions SHA256 commitment to the inner script. Node-computed — the user provides PREIMAGE (serialised Ladder Script conditions) and the node computes this field automatically. Raw hash input is rejected.
preimage PREIMAGE var Witness Serialised Ladder Script conditions (the inner script) — provided by the user. The node derives HASH256 from this data at creation time.
[inner witness] var var Witness Witness fields required to satisfy the inner conditions

Conditions side (committed in the rung leaf):

0x0905 0 1 HASH256 · 32B = 38 bytes

Witness side (in input witness):

0x0905 0 n PREIMAGE · varB [inner witness fields] = variable
Total (conditions + witness) variable

Witness size depends on the inner Ladder Script conditions and their witness fields.

1. Locate HASH256 and PREIMAGE (or SCRIPT_BODY as a fallback). Either missing → ERROR. HASH256 not exactly 32 B → ERROR
2. Compute SHA256(PREIMAGE) and memcmp against the committed HASH256. Mismatch → UNSATISFIED
3. Recurse into EvalInnerConditions(PREIMAGE, depth+1). Same recursion semantics as P2SH_LEGACY: deserialize as Ladder conditions (failure → ERROR), enforce MAX_LEGACY_INNER_DEPTH = 2, apply the audit-E-020 witness-stack exact-count guard, then evaluate inner rungs with OR logic (first satisfied wins).
ConditionResult
Missing HASH256 or PREIMAGEERROR
HASH256 wrong size (not 32B)ERROR
SHA256(PREIMAGE) != committed hashUNSATISFIED
PREIMAGE fails to deserialize as Ladder conditionsERROR
Inner conditions evaluation failsUNSATISFIED
Recursion depth > 2ERROR
Inner conditions satisfiedSATISFIED
Conditions (committed in the rung leaf)
{
  "type": "P2WSH_LEGACY",
  "inverted": false,
  "fields": [
    { "type": "HASH256", "hex": "e3b0c4...32 bytes" }
  ]
}
Witness (input)
{
  "type": "P2WSH_LEGACY",
  "inverted": false,
  "fields": [
    { "type": "PREIMAGE", "hex": "01020304...serialised Ladder conditions" },
    { "type": "PUBKEY", "hex": "02abc1...33 bytes" },
    { "type": "SIGNATURE", "hex": "e5f6a7...64 bytes" }
  ]
}
  • Same anti-spam properties as P2SH_LEGACY — inner script must be valid Ladder Script.
  • The HASH256 field is node-computed: the user supplies PREIMAGE (the inner script) and the node derives the hash commitment automatically. Submitting a raw HASH256 value directly is rejected.
  • Uses SHA256 instead of HASH160 for the script hash, matching Bitcoin's P2WSH design.
  • Recursion depth limited to 2.
Segwit Script Migration
Same anti-spam pattern as P2SH_LEGACY but using SHA256 hash (matching P2WSH).
Complex Inner Conditions
Inner Ladder conditions with full composability, behind a SHA256 commitment.