Spark Program | MatchLock: A Reusable Script Primitive for Private-Until-Match Bilateral Settlement on CKB

1. Overview

Project name: MatchLock

One-sentence summary: A permissively licensed CKB lock/type script library, with an SDK and documentation, that lets any CKB project add private-until-match/reveal bilateral commitments and atomic conditional settlement to its own application.

License: MIT OR Apache-2.0 for all scripts, SDK, docs, and demo code

Repository: GitHub - Fizan324926/MatchLock: Project repository for MatchLock · GitHub

Team and maintainer: Fizan

2. Problem

In bilateral transactions such as OTC trades and private asset sales, parties typically have to reveal order parameters (asset, size, price) before the counterparty’s commitment is assured. On CKB, this creates information leakage and front-running risk when a deal fails to settle.

Developers building OTC or private execution applications today must write their own commitment and hold lock/type scripts from scratch, with no shared implementation to rely on. This duplicates effort, multiplies the places funds can be lost to bugs, and leaves applications unable to share tooling. CKB lacks an open, documented, tested building block for this.

3. Solution

We propose a standardized, modular CKB script primitive for hash-committed bilateral commitments and conditional hold/settlement. The project delivers an open-source CKB-VM script library and a developer SDK, published under a permissive license with a versioned interface spec. Any dApp or protocol that needs private-until-reveal order matching or atomic bilateral settlement can integrate it rather than rebuilding it, reducing duplicated development and giving the ecosystem a common, documented starting point. The scripts are unaudited and intended for testnet; ZK-based matching is listed as future work.

The deliverables come in three layers:

  1. Core scripts (Rust, CKB-VM). Lock/type scripts covering hash-committed locks, reveal-and-match logic (each party reveals terms, and the script verifies them against the commitments and a declared matching predicate), and timelocked hold and settlement with deterministic settle or refund paths.
  2. SDK (TypeScript). Helpers to build commitments, construct and sign the transactions, and parse cell state, so integrators do not need to touch script internals. Includes the interface spec and an integration guide so other CKB projects can reuse it freely under the license.
  3. Reference demo. A minimal web page showing two wallets completing and aborting a deal. It exists to prove the library works, not as the main product.

How it works

  1. Each party publishes a hash commitment to its terms, H(terms || salt), in a cell, and locks its funds under the script.
  2. During the reveal window, each party reveals its terms and salt. The script checks that each reveal matches its commitment.
  3. The script then evaluates a declared matching predicate (for example, prices cross and amounts are complementary). If it holds, both sides settle in one atomic transaction.
  4. If a party fails to reveal before the timeout, or the predicate fails, funds are refundable under the timeout path.

What is and is not private (stated precisely)
Phase
Hidden
Visible on-chain
After commit
Terms (price, size, asset details)
Commitment hashes, deposit amounts, addresses, timing
After reveal
Nothing
Terms of both parties
Aborted before reveal
Terms stay hidden
Commitments, deposits, refund
Revealed, no match
Nothing
Terms of both parties, refund

This is a commit-reveal scheme, not zero-knowledge. It protects terms from observers and from the counterparty until both have committed, which prevents last-look and front-running on terms. It does not hide terms once a reveal occurs, and it does not hide that a deal exists or the deposit size.

Out of scope for this grant (documented as future work): zero-knowledge proofs of matching, where terms stay hidden even on a successful match or a failed predicate. This needs proof verification inside CKB-VM and is a separate research effort. The script interface is designed so a ZK verifier can be swapped in later without changing integrators’ code.

4. Open source benefits

  • Open by default. Permissive license, public repo from day one, no paid tier, no admin keys, no protocol fees, no permissioned access.
  • Reusable without asking. Other projects can call the scripts by code hash, import the SDK, or fork the code. The on-chain interface (cell data layout, script args, error codes) is specified in a versioned document.
  • Reduces duplicated work. One tested implementation replaces many ad hoc ones.
  • Teaches the ecosystem. Architecture write-up on Nervos Talk, a developer guide, and an integration walkthrough.
  • Maintained. The maintainer commits to bug-fix and compatibility updates for 12 months after delivery, with security issues handled through a published disclosure contact.

5. Alignment with Nervos / Spark

The design uses CKB’s Cell model and custom lock scripts directly: commitment and deposit live in cells, state transitions are validated by script, and settlement is a single atomic transaction. It demonstrates a pattern other builders can copy for conditional, multi-party flows.

Related work

MatchLock complements Invisibook, a privacy-preserving order-book L2 appchain proposed to the CKB Community Fund DAO. The two differ in layer, scope, and privacy goal:

  • Layer: Invisibook is an L2 appchain with its own consensus. MatchLock is a set of L1 scripts that any CKB application can call.
  • Trade shape: Invisibook targets many-to-many order-book trading. MatchLock targets bilateral deals between two known parties.
  • Privacy goal: Invisibook aims to hide order sizes in an ongoing market. MatchLock hides terms only until both parties have committed, then reveals them at settlement.

Because MatchLock is a reusable library, projects like Invisibook could adopt it for L1 settlement steps rather than rebuilding them.

6. Budget

Total requested: $850 USD (equivalent in CKB at the official approval price snapshot).
Milestone
Deliverables
Allocation
1. Core scripts
Rust scripts for commit, reveal, settle, and timeout refund; unit and integration tests; Testnet deployment; interface spec v0.1
$400
2. SDK and integration docs
Minimal TypeScript SDK; developer guide with an integration example; Nervos Talk write-up
$250
3. Demo, testing, report
Minimal two-wallet demo page; Testnet simulations of success, abort, and timeout; security notes and known limitations; completion report
$200
Total
$850

The frontend is deliberately the smallest part of the work. Most of the budget goes to the reusable scripts, SDK, and docs.

7. Timeline

Milestone 1 (Weeks 1-3): Core scripts and Testnet deployment Deliverables: scripts and tests in the public repo, deployed to Testnet, interface spec published.

Milestone 2 (Weeks 4-5): SDK and documentation Deliverables: SDK package, developer guide with integration example, architecture write-up on Nervos Talk.

Milestone 3 (Weeks 6-7): Demo, testing, and final report Deliverables: demo page, recorded walkthrough, test results, limitations and threat-model notes, Spark completion report.

8. Risks and Limitations

  • Not audited. Scripts handle funds. Delivery includes a self-review and a clear “unaudited, Testnet only” notice. A third-party audit is recommended before any Mainnet use and is not funded here.
  • Reveal exposes terms. Commit-reveal cannot keep terms private after a successful reveal. This is documented, and ZK matching is listed as future work.
  • Griefing by non-reveal. A party can commit and never reveal. The timeout and refund path limits fund loss, and the guide documents mitigations such as small bonds.
  • Scope. The budget covers the scoped design above, not a ZK system.
  • Public metadata. Wallet addresses, deposit amounts, and timing are visible on-chain and can reveal information about a deal even while terms are hidden. The docs will describe mitigations.

9. How to Verify

  • Public repositories: scripts, SDK, integration example, and demo, all under the stated license.
  • Testnet deployment: published script code hashes and sample transactions for success, abort, and timeout paths.
  • Tests: test suite runnable by reviewers with a single documented command.
  • Documentation: interface spec, developer guide, and Nervos Talk write-up.
  • Recorded demo: full lifecycle of a matched deal and an aborted deal, including what is visible on-chain at each step.
3 Likes

Hi @Chaichamp,

Thank you for taking the time to revise the proposal based on our previous feedback, and for your continued efforts to refine the MatchLock concept.

The committee has completed its review. After careful discussion, we regret to inform you that we have decided not to approve the MatchLock project at this time.

We’d like to be candid about the reasons behind this decision:

Existing ecosystem infrastructure already adequately supports this primitive: Commit-reveal is a fundamental cryptographic primitive already used by nearly every project on CKB—and across the broader blockchain ecosystem. The core code for a hash commitment scheme is only a few lines, and existing libraries already handle it well. In the committee’s view, packaging it as a third-party library that other projects would have to adopt would add an extra dependency without delivering clear additional value over existing foundational components.

We greatly appreciate all the effort your team has put in. The committee hopes that you and your team will give greater consideration to the specific needs that exist in the community and propose solutions that genuinely address them. Keep building, and feel free to reach out anytime!

Best regards,
Xingtian
On behalf of the Spark Program Committee
CC: @Hanssen @yixiu.ckbfans.bit @zz_tovarishch

1 Like

Hi @xingtianchunyan,

Thank you for reviewing MatchLock and for explaining the decision.

Before I respond to the substance, I want to check one thing. The message says the proposal was revised based on previous feedback, but I don’t have a record of an earlier feedback round on this proposal, and I haven’t submitted a revision. Could you point me to the earlier feedback you’re referring to? It’s possible the comment was meant for a different proposal, and I’d like to make sure the review is attached to the right one.

On the reasoning itself: I understand the concern that a hash commitment is only a few lines of code. MatchLock isn’t intended to be a commit-reveal library. The scope is the part built around the commitment: reveal-and-match against a declared predicate, atomic two-sided settlement, and timeout/refund paths, with a versioned interface spec and SDK. Could you tell me whether the concern applies to that settlement logic as well, or only to the commitment layer?

Thanks again for your time.

Best,
Fizan

Hi, @Fizan

Regarding the first matter, I’m very sorry! This was a mistake on my part at work: I edited the reply using a template but didn’t save it correctly.
Regarding the second matter, I’ve relayed your question to the committee. I’ll get back to you no later than after our next weekly meeting.

Thank you for your patience.

Best,
xingtian

Hi @xingtianchunyan,

Thanks for confirming, no problem at all, and thank you for passing my question to the committee.

In case it helps while they discuss it, here is MatchLock in plain terms. Imagine two people who want to make a private deal, one selling something and one buying it. Neither wants to name a price first, because the other side could use it against them. So each seals their terms in an envelope and puts their money into escrow. Once both envelopes are in, they are opened together. If the terms fit, the swap happens in a single step. If they don’t fit, or someone never opens their envelope, the escrow returns the money automatically after a deadline.

The sealed envelope is the simple part. The proposal is about the rest: checking the terms against the seal, deciding whether the deal matches, completing the swap atomically, and handling the refund. MatchLock is a reusable on-chain script that does this, so builders don’t have to write that escrow logic themselves.

Looking forward to the committee’s response.

Best,
Fizan