Skip to content

ddk: take per-outcome payout script overrides as an input to the stateless API - #223

Closed
matthewjablack wants to merge 1 commit into
bennyhodl:masterfrom
matthewjablack:feat/payout-script-overrides-param
Closed

matthewjablack wants to merge 1 commit into
bennyhodl:masterfrom
matthewjablack:feat/payout-script-overrides-param

Conversation

@matthewjablack

Copy link
Copy Markdown
Contributor

Alternative to #222, after Benny's point that the application owns TLV parsing. DDK doesn't define a record here and never reads one from a message. It takes the overrides as a plain input.

A CET pays the offerer or the accepter and nobody else. A loan settled by a DLC needs an outcome that pays whoever liquidated the position on the EVM side, in the lender's place. Every stateless entry point rebuilds the CETs inside context_from_messages and signs or verifies in the same call, so an application that parses its own TLV still has nowhere to put the result. That's the part DDK has to own.

PayoutScriptOverrides is a HashMap<String, ScriptBuf> keyed by enum outcome. For a named outcome, the output that would have paid the accepter's payout_spk pays that script instead. Amounts come from the descriptor, so a liquidation outcome is written as offer = 0, accept = total. The accepter is the lender in a loan and a liquidator is paid in the lender's place, so the lender liquidating itself is the normal accepter payout with nothing to override.

It's an Option<&PayoutScriptOverrides> on every operation that touches CET bytes: create_dlc_transactions, create_signed_dlc_transactions, sign_accept and the spliced and raw witness variants, finalize_sign and its variants, sign_cet, create_cet_adaptor_signatures and verify_cet_adaptor_signatures, and a field on AcceptOfferParams. sign_refund, create_funding_psbt, compute_contract_id and create_dlc_splice_input only use the funding or refund transaction and are unchanged. Both parties have to pass the same map to every call on a contract, since adaptor signatures commit to the CET bytes. How the map travels is the application's problem, a TLV record on the offer in our case.

The rewrite runs in build_context after every CET is built and before anything is signed. An outcome no enum descriptor has, or an empty script, is rejected. Numerical descriptors are skipped. The accepter's output is found by script, so offer and accept payout scripts have to differ, which every real contract already does.

This is a breaking signature change on the 2.0 rc. I went with one parameter rather than _with_overrides variants because the API already has spliced and raw witness variants and a third axis would get silly. Most of the diff is None at call sites in tests and examples.

Tests cover the rewrite through create_dlc_transactions, an unknown outcome rejected, an empty script rejected, and adaptor signatures made with the overrides verifying with them and failing without. Workspace lib tests green, clippy and fmt clean on ddk. I didn't run the bitcoind backed stateless integration tests. The 1.x manager path is not touched here; dlcd-rs on 1.1.2 would still need #222 or a move to the stateless API.

…eless API

A CET pays the offering and accepting parties and nobody else. A loan
settled by a DLC needs an outcome that pays a third party, the
liquidator, in the lender's place. Every stateless entry point rebuilds
the CETs and signs or verifies in the same call, so an application has
nowhere to patch them itself.

Each operation that touches CETs now takes an optional map of enum
outcome to script. For a named outcome the accepting party's output
pays that script instead. DDK does not define how the map travels
between the parties; the application owns that, for example as a TLV
record on the offer.
@bennyhodl

Copy link
Copy Markdown
Owner

Note

🤖 Claude Opus 5.5 responding on behalf of bennyhodl

Replaced by #224. We went with the TLV record (type 65005) instead of a parameter on the stateless API, so the manager and the stateless module read the overrides from the same offer, and both build the same CETs in one shared builder. Overrides can name an enum outcome or a numeric range, and a manager only accepts an offer carrying the record if the application allows the type (with_allowed_offer_tlv_types).

@matthewjablack

Copy link
Copy Markdown
Contributor Author

Superseded by #224.

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