Segwit

From claude-dev-suite/claude-dev-suite · View interactive version

Segwit is an AI agent skill from the GitHub repository claude-dev-suite/claude-dev-suite. Segregated Witness: BIP141 (consensus), BIP143 (sighash), BIP144 (P2P serialization), BIP173 (Bech32 address). Witness segregation, weight units, txid vs wtxid, witness commitment. USE WHEN: working with native segwit (P2WPKH/P2WSH), embedded segwit (P2SH-P2WPKH/P2SH-P2WSH), or understanding the wit

How to use this skill

Skill file

SegWit (BIP141 family)

Activated August 2017. Moved signatures and other auxiliary data into

a new witness section that is not included in txid hashing.

Goals achieved

  1. Fixed transaction malleability for SegWit-only inputs.
  2. Weight discount — witness bytes count 1 WU (vs 4 WU for base).

Effective block size cap rose from 1 MB to ~4 MWU.

  1. Linear sighash (BIP143) — O(n) signing instead of O(n²) for

multi-input txs.

  1. Soft-fork upgrade path — version field on witness program enables

future versions (1 = Taproot).

Witness program structure

scriptPubKey for SegWit outputs:

<version_byte> <data_push>

Version byte = OP_0 (v0), OP_1 (v1 = Taproot, BIP341). Future

versions reserved.

Length of data push determines type:

future soft fork).

Address encoding (BIP173 / BIP350)

to fix BIP173 length-extension bug.

Encoding helpers usually check the witness version byte and

auto-select Bech32 vs Bech32m.

Embedded SegWit (legacy compat)

For wallets that can only produce P2SH addresses:

Sighash (BIP143)

For SegWit v0 inputs, sighash is computed over a precomputed digest:

`hashPrevouts || hashSequence || outpoint || scriptCode || amount ||

nSequence || hashOutputs || nLockTime || nHashType`.

Two key facts:

  1. The input amount is committed → fee-bumping attack with old

signatures is detected (each input value is signed).

  1. hashPrevouts, hashSequence, hashOutputs are reused across all

inputs → O(n) total cost.

Taproot (BIP341) supersedes this with an even cleaner digest.

P2P relay (BIP144)

stripped).

witness support.

witness data.

Common gotchas

network → wire-format invalid.

wrong, must strip witness for txid.

P2WPKH (bc1q...) → wastes ~10 vB per input.

Bech32m, otherwise checksum is rejected by spec-compliant wallets.

See also

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.