{"id":23532609,"url":"https://github.com/conduition/dlctix","last_synced_at":"2025-04-22T22:41:18.705Z","repository":{"id":223344686,"uuid":"760061856","full_name":"conduition/dlctix","owner":"conduition","description":"Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin.","archived":false,"fork":false,"pushed_at":"2025-02-20T03:03:27.000Z","size":965,"stargazers_count":18,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T19:34:32.257Z","etag":null,"topics":["bitcoin","discreet-log-contract","scriptless","smart-contracts"],"latest_commit_sha":null,"homepage":"https://conduition.io/scriptless/ticketed-dlc/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/conduition.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-19T17:58:42.000Z","updated_at":"2025-03-13T09:45:00.000Z","dependencies_parsed_at":"2024-03-08T08:28:31.880Z","dependency_job_id":"d80a80e6-f155-437a-9ba6-bd97f404dfdb","html_url":"https://github.com/conduition/dlctix","commit_stats":null,"previous_names":["conduition/dlctix"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conduition%2Fdlctix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conduition%2Fdlctix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conduition%2Fdlctix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conduition%2Fdlctix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/conduition","download_url":"https://codeload.github.com/conduition/dlctix/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250337277,"owners_count":21414092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","discreet-log-contract","scriptless","smart-contracts"],"created_at":"2024-12-25T23:11:53.892Z","updated_at":"2025-04-22T22:41:18.683Z","avatar_url":"https://github.com/conduition.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dlctix\n\nTicketed [Discreet Log Contracts (DLCs)](https://bitcoinops.org/en/topics/discreet-log-contracts/) to enable instant buy-in for conditional payment contracts on [Bitcoin](https://bitcoin.org).\n\nThis project is part of the [Backdrop Build V3 cohort](https://backdropbuild.com) \u003cimg style=\"width: 12px;\" src=\"img/backdrop-logo.png\"\u003e\n\n\u003cimg width=\"40%\" src=\"img/backdrop-build-v3.png\"\u003e\n\n### Summary\n\nTo read more about this concept in detail, [see my full blog post](https://conduition.io/scriptless/ticketed-dlc/).\n\nA group of people don't trust each other, but DO trust some 3rd-party mediator called an _Oracle._ They want to wager money on some future event and redistribute the money depending on which outcome occurs (if any), according to the Oracle. Real-world examples include:\n\n- Futures contracts (e.g. Contracts for Derivatives)\n- Insurance contracts\n- Security deposits (e.g. for car rentals)\n- Gambling\n- Competition prizes\n\n[Discreet Log Contracts (DLCs)](https://bitcoinops.org/en/topics/discreet-log-contracts/) enable this kind of conditional payment to be executed natively on Bitcoin, with great efficiency. They have been known about for many years, but traditional DLCs are not scaleable to large contracts with many people buying in with very small amounts, such as lotteries or crowdfunding, because a traditional DLC requires on-chain Bitcoin contributions _from every participant_ in the DLC who is buying in - otherwise the contract would not be secure. The fees on such a jointly-funded contract quickly become impractical. There are also privacy issues: Every participant would be permanently associating their on-chain bitcoins with the DLC in question.\n\nWith my Ticketed DLCs approach, a single untrusted party called the Market Maker can lease their on-chain capital to use for the on-chain DLC, while buy-ins from the DLC contestants are instead paid to the Market Maker using off-chain payment protocols such as [Fedimint eCash](https://fedimint.org/) or [Lightning](https://lightning.network). The Market Maker can profit from this arrangement by charging the contestants an up-front fee which covers the opportunity cost of locking their on-chain capital for the duration of the DLC.\n\nDLC contestants buy specific SHA256 preimages called _ticket secrets_ from the Market Maker off-chain. In so doing, a DLC contestant is buying the ability to redeem potential payouts from the DLC. Without the correct ticket secret, any winnings instead return to the Market Maker.\n\nOnce the Oracle publishes an attestation confirming the true outcome of the DLC, the Market Maker can issue off-chain payouts to the DLC winners. In exchange, the Market Maker receives a _payout preimage_ from each contestant which allows the Market Maker to reclaim his on-chain capital.\n\nIn the optimal case if everyone cooperates and payouts are conducted off-chain, there are only two on-chain transactions: The funding of the DLC by the Market Maker, and the withdrawal back to the Market Maker. **The result is zero on-chain visibility into who participated or won the DLC, and the absolute best on-chain efficiency possible** while still retaining the guarantee of on-chain contract enforcement. Assuming the Oracle is trustworthy, then the correct winners will always be paid out eventually, regardless of whether the Market Maker or the contestants cooperate, collude, or go offline.\n\n## Code\n\nThis repository is a reusable Rust implementation of the Ticketed DLC contract using hash-locks.\n\nIt implements the transaction-building, multisignature-signing, and validation steps needed for all parties (both contestants and the Market Maker) to successfully execute a Ticketed DLC on and off-chain. It _does not_ include any networking code, nor does it package a Bitcoin or Lightning Network wallet. Rather, this crate is a generic building block for higher-level applications which can implement Ticketed DLCs in more specific contexts.\n\nTo demonstrate the practicality of this approach, I have written [a series of integration tests](./src/regtest.rs) which leverage a remote [Bitcoin Regtest Node](https://bisq.network/blog/how-to-set-up-bitcoin-regtest/) to simulate and test the various stages and paths of the Ticketed DLC's on-chain execution. The best way to visualize these stages is with a transaction diagram.\n\n\u003cimg width=\"70%\" src=\"img/ticketed-dlc-diagram.png\"\u003e\n\n## Walkthrough\n\nTo see an example, see [the basic integration test](./tests/basic.rs) which includes very detailed comments and descriptions of everything happening during the DLC construction, signing, and execution phases.\n\n## Running the Tests\n\nTo run the integration tests, you'll need a [Bitcoin Regtest Node](https://bisq.network/blog/how-to-set-up-bitcoin-regtest/), either running locally on your machine or accessible by remote HTTP.\n\n### 1. Clone this repo.\n\n```console\ngit clone https://github.com/conduition/dlctix.git\n```\n\n### 2. [Install Rust](https://rustup.rs/)\n\n### 3. Install `bitcoind`.\n\nYou can download a pre-compiled `bitcoind` binary from [the official bitcoin core releases page](https://bitcoincore.org/en/download/), or build it [from source yourself](https://github.com/bitcoin/bitcoin).\n\nFor tests to pass, the `bitcoind` binary should be in your executable `PATH`.\n\n\u003e [!TIP]\n\u003e As an alternative to installing `bitcoind` locally, you can designate a remotely-accessible regtest node and run tests against that. Fill in a `.env` file in the root of the `dlctix` repo folder:\n\u003e\n\u003e ```env\n\u003e BITCOIND_RPC_ADDRESS=http://some-remote.url:18443\n\u003e BITCOIND_RPC_AUTH_USERNAME=\u003cyour_nodes_rpc_username\u003e\n\u003e BITCOIND_RPC_AUTH_PASSWORD=\u003cyour_nodes_rpc_password\u003e\n\u003e ```\n\u003e\n\u003e Because the remote node's blockchain state is a singleton, tests will run in series, so that their executions do not interfere with each other's blockchain state.\n\n\n### 4. Run the `dlctix` tests.\n\n```\ncargo test\n```\n\nThis will compile and execute the unit and integration tests, which validate the numerous contract execution paths and validation conditions which must be enforceable by different parties.\n\n```\n$ cargo test\n   Compiling proc-macro2 v1.0.78\n   Compiling unicode-ident v1.0.12\n   Compiling libc v0.2.153\n   ...\n   Compiling serde_cbor v0.11.2\n   Compiling dotenv v0.15.0\n   Compiling dlctix v0.0.6 (/home/user/src/dlctix)\n    Finished test [unoptimized + debuginfo] target(s) in 56.70s\n     Running unittests src/lib.rs (target/debug/deps/dlctix-1f9c250df9b6ac38)\n\nrunning 11 tests\ntest consts::tests::test_p2tr_dust ... ok\ntest regtest::all_players_cooperate ... ok\ntest regtest::all_winners_cooperate ... ok\ntest regtest::contract_expiry_all_winners_cooperate ... ok\ntest regtest::contract_expiry_on_chain_resolution ... ok\ntest regtest::individual_sellback ... ok\ntest regtest::market_maker_reclaims_outcome_tx ... ok\ntest regtest::with_on_chain_resolutions ... ok\ntest serialization::tests::contract_parameters_serialization ... ok\ntest serialization::tests::player_serialization ... ok\ntest regtest::stress_test ... ok\n\ntest result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 46.14s\n\n     Running tests/basic.rs (target/debug/deps/basic-0f34ed113194694a)\n\nrunning 1 test\ntest two_player_example ... ok\n\ntest result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.45s\n\n   Doc-tests dlctix\n\nrunning 0 tests\n\ntest result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\n\n```\n\nTo run more test threads in parallel, do:\n\n```\ncargo test -- --test-threads 8\n```\n\nIf you have `bitcoind` installed locally, each `regtest` case will spawn its own regtest `bitcoind` instance in a subprocess and run against that.\n\nIf you _do not_ have `bitcoind` in your `$PATH`, then regtest test-cases will run sequentially regardless of how many threads you ask for.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconduition%2Fdlctix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconduition%2Fdlctix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconduition%2Fdlctix/lists"}