Patch Overview
What changes are needed to add Ladder Script to Bitcoin Core
154Lines Added
16Files Modified
11,318New Code (Rung Lib)
21New Files
Ladder Script adds a self-contained library (src/rung/) to Bitcoin Core. The patch to existing code is minimal: 154 lines across 16 files. The bulk of the implementation (11,318 lines) lives in new files that do not touch existing code.
Patch to Existing Bitcoin Core
These are the only modifications to existing Bitcoin Core files. Each change is surgical and additive.
| File | Change | Lines |
|---|---|---|
| validation.cpp | Route v4 RUNG_TX inputs spending MLSC outputs to VerifyRungTx. Pass block_height through CheckInputScripts. ValidateRungOutputs call. MLSC-only flag on mainnet. | +43 |
| script/interpreter.cpp | Precompute ladder sighash caches for v4 transactions. Reuses BIP341 hash infrastructure. | +13 |
| script/interpreter.h | Add SigVersion::LADDER = 4 and m_ladder_ready flag to PrecomputedTransactionData. | +5 |
| primitives/transaction.h | Define RUNG_TX_VERSION = 4. | +4 |
| script/script_error.cpp | Add SCRIPT_ERR_LADDER_INVALID_WITNESS and SCRIPT_ERR_LADDER_EVAL_FALSE error strings. | +4 |
| script/solver.cpp | Detect 0xC2 prefix as TxoutType::RUNG_CONDITIONS in the script solver. | +7 |
| script/solver.h | Add RUNG_CONDITIONS to TxoutType enum. | +1 |
| policy/policy.cpp | Route v4 transactions to rung::IsStandardRungTx. Bypass standard input/witness checks for MLSC outputs. | +17 |
| rpc/mempool.cpp | Skip burn-amount check for MLSC outputs in sendrawtransaction and submitpackage. | +5 |
| rpc/util.cpp | Add LadderDestination visitor for address description RPC. | +8 |
| addresstype.cpp | Extract LadderDestination from RUNG_CONDITIONS outputs. Encode as scriptPubKey. | +14 |
| addresstype.h | Define LadderDestination struct. Add to CTxDestination variant. | +24 |
| key_io.cpp | Encode/decode rung1... Bech32m addresses. | +35 |
| bech32.h | Add RUNG_ADDRESS character limit (500) for rung addresses. | +1 |
| CMakeLists.txt | Add add_subdirectory(rung) and link bitcoin_rung. | +5 |
| test/CMakeLists.txt | Add rung_tests.cpp to test binary. | +1 |
New Rung Library (src/rung/)
Self-contained library. No modifications to existing Bitcoin Core code. Builds as libbitcoin_rung.a.
| File | Lines | Purpose |
|---|---|---|
| evaluator.cpp | 3,503 | All 61 block evaluators, EvalBlock dispatch, EvalRung (AND), EvalLadder (OR), VerifyRungTx entry point, BatchVerifier |
| rpc.cpp | 2,605 | RPC commands: createrung, createrungtx, signrungtx, decoderung, parseladder, formatladder, computectvhash, generatepqkeypair |
| types.h | 1,423 | Block type enum (61 types), data types, RungCoil, implicit field layouts, micro-header table, BlockDescriptor table |
| serialize.cpp | 944 | Wire format: micro-headers, implicit fields, DeserializeLadderWitness, SerializeLadderWitness, anti-spam enforcement |
| conditions.cpp | 657 | MLSC Merkle tree: leaf computation, proof verification, merkle_pub_key, CreateMLSCScript |
| descriptor.cpp | 566 | Conditions descriptor language: ParseDescriptor, FormatDescriptor |
| evaluator.h | 266 | Evaluator declarations, LadderSignatureChecker, BatchVerifier, RungEvalContext, TxAggregateContext |
| conditions.h | 202 | RungConditions, MLSCProof, MLSC output helpers, Merkle leaf computation declarations |
| adaptor.cpp | 187 | Adaptor signature verification and secret extraction |
| policy.cpp | 149 | Mempool policy: IsBaseBlockType, IsCovenantBlockType, IsStatefulBlockType, IsStandardRungTx |
| sighash.cpp | 146 | SignatureHashLadder: tagged hash, ANYPREVOUT/ANYPREVOUTANYSCRIPT skip rules |
| pq_verify.cpp | 145 | Post-quantum signature verification: FALCON-512, FALCON-1024, Dilithium3, SPHINCS+ |
| serialize.h | 123 | Constants (MAX_RUNGS=16, MAX_BLOCKS=8, etc.), SerializationContext |
| sighash.h | 64 | SignatureHashLadder declaration, ANYPREVOUT constants |
| descriptor.h | 58 | ParseDescriptor, FormatDescriptor declarations |
| adaptor.h | 57 | Adaptor signature types and declarations |
| pq_verify.h | 51 | PQ verification declarations, scheme detection |
| aggregate.h | 51 | AggregateProof, TxAggregateContext structs |
| types.cpp | 45 | RungField::IsValid implementation |
| aggregate.cpp | 41 | VerifyAggregateSpend, VerifyDeferredAttestation |
| policy.h | 35 | Policy function declarations |
Test Coverage
| Layer | Count | What |
|---|---|---|
| Unit tests | 480 | Block evaluation, serialisation, sighash, conditions, policy, MLSC proofs, field validation |
| Regtest functional | 60 | Every block type: create, sign, broadcast, mine, spend on live regtest node |
| TLA+ formal specs | 80 | 9 specifications, 3.3M states checked: evaluation semantics, anti-spam, wire format, Merkle proofs, sighash, covenants, cross-input |
Patch Files
Two patch files apply to Bitcoin Core v30.1:
patches/bitcoin-core-v30-ladder-script.patch
+154 lines across 16 files
Core integration: routing, sighash, script solver, policy, address encoding, RPC, build system
patches/validation-block-height.patch
+43 lines across 2 files
Block height plumbing for EPOCH_GATE and height-dependent governance blocks
Total change to existing Bitcoin Core: 197 lines across 18 files. The remaining 11,318 lines are new, self-contained code in src/rung/ that does not modify any existing function.