Skip to content

feat: Add DLC Input support for spliced contracts#228

Merged
matthewjablack merged 11 commits into
masterfrom
feat/splicing-support
Jul 25, 2025
Merged

feat: Add DLC Input support for spliced contracts#228
matthewjablack merged 11 commits into
masterfrom
feat/splicing-support

Conversation

@matthewjablack
Copy link
Copy Markdown
Contributor

Overview

Implements DLC Input support within FundingInput messages to enable advanced DLC functionality like spliced contracts. This is a breaking change to the FundingInput serialization format.

BREAKING CHANGE Warning

This PR introduces breaking changes to FundingInput serialization:

  • All FundingInput messages now include an optional DlcInput suffix (0x00 or 0x01 + data)
  • Existing serialized FundingInput messages will fail to deserialize correctly
  • New FundingInput messages are incompatible with older versions of the library
  • Migration required for any stored or transmitted FundingInput data

New Features

DlcInput Message Type

  • New message type: DlcInput (42773)
  • Fields: localFundPubkey, remoteFundPubkey, fundValue

Enhanced FundingInput Format

  • Required suffix: All FundingInputs now end with optional DlcInput data
  • Format: [existing fields][0x00] or [existing fields][0x01][DlcInput data]
  • Rust-DLC alignment: Matches rust-dlc optional format specification

Technical Implementation

New Serialization Format

FundingInput (UPDATED):
[inputSerialId: 8 bytes]
[prevTx: variable]
[prevTxVout: 4 bytes]
[sequence: 4 bytes]
[maxWitnessLen: 2 bytes]
[redeemScript: variable]
[0x00] // No DLC input (NEW REQUIRED BYTE)
OR
[0x01][DlcInput data] // With DLC input (NEW FORMAT)

JSON Schema Extension

{
  "inputSerialId": 1,
  "prevTx": "02000000...",
  "prevTxVout": 0,
  "sequence": 4294967295,
  "maxWitnessLen": 108,
  "redeemScript": "",
  "dlcInput": {  // NEW: Optional field
    "localFundPubkey": "023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb",
    "remoteFundPubkey": "025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357", 
    "fundValue": 100000000
  }
}

Migration Required

For Applications Using FundingInput

  1. Re-serialize all stored FundingInput data using the new format
  2. Update protocol versions to handle format differences

Dependencies & Tooling

  • Rust-DLC alignment: Uses bennyhodl/rust-dlc@spliced-contract branch
  • Test vectors: Updated dlcspecs test vectors for new format
  • Migration script: Added update-dlcspecs-vectors.sh for regenerating test data

Testing

# Test new DlcInput functionality
npm test -- --grep "DlcInput"

# Test enhanced FundingInput format
npm test -- --grep "FundingInput.*DlcInput"

# Test format compatibility
npm test -- --grep "rust-dlc optional format"

# Run compatibility tests
npm test compatibility

# Regenerate test vectors
./scripts/update-dlcspecs-vectors.sh

- add new DlcInput message with localFundPubkey, remoteFundPubkey, fundValue
- implement full TLV serialization and JSON support
- export DlcInput from messaging package index
- add optional dlcInput field to FundingInput class
- implement rust-dlc compatible optional format (0x00/0x01 prefix)
- support DlcInput in JSON serialization/deserialization
- maintain backward compatibility with existing FundingInput usage
- add DlcInput serialization/deserialization tests
- test FundingInput with and without DlcInput scenarios
- verify rust-dlc optional format byte prefix (0x00/0x01)
- test JSON round-trip compatibility
- ensure backward compatibility validation
- switch to bennyhodl/rust-dlc@spliced-contract branch
- update dlc-messages and dlc dependencies to support DLC input features
- update dependency versions in Cargo.lock
- update dlcspecs test vectors with DlcInput test cases
- ensure compatibility with rust-dlc spliced-contract branch
- maintain existing test vector structure while adding new capabilities
- update any package-level dependencies for DlcInput support
- add update-dlcspecs-vectors.sh script for regenerating test vectors
- update .gitignore to exclude test vector backup directories
- script helps maintain test vectors when updating rust-dlc dependencies
- reduce CLI timeout to 1min in CI environments (vs 5min locally)
- increase test timeouts to 90s in CI (vs 15s locally)
- improve CI cargo caching for git dependencies
- pre-fetch dependencies to avoid network timeouts
- add environment-aware timeout configuration
BREAKING CHANGE: DlcInput message format changed from fundValue to contractId

- replace fundValue (8-byte BigInt) with contractId (32-byte Buffer)
- update DlcInput validation to check 32-byte contractId length
- update all tests to use contractId instead of fundValue
- remove unused imports (bigIntToNumber, toBigInt, validPublicKey)
- update JSON interface to use contractId string field

This enables contract identification in DLC inputs for spliced contracts
(allows finding the relevant contractId of the DLC Input)
- add dust filtering (1000 sat threshold) to match C++ behavior
- add calculateMaxCollateral() utility for precise DLC amounts
- fix single-funded DLC fee handling for zero-input parties
- resolves 'No Change' DLC splicing issue
- add DlcInput.ts with 32-byte contractId field and full serialization
- support optional DlcInput nesting in FundingInput messages
- enable DlcInput in DlcOffer and DlcAccept messages
- generate enum_3_of_5_with_dlc_input_test.json test vector
- include generation script for future test vector updates
- skip Rust compatibility tests (Rust implementation pending)
@bennyhodl
Copy link
Copy Markdown
Collaborator

No comments, LGTM!

@matthewjablack matthewjablack merged commit 35a39b0 into master Jul 25, 2025
2 checks passed
@matthewjablack matthewjablack deleted the feat/splicing-support branch July 25, 2025 17:05
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.

2 participants