# Unisocks-Style NFT Sale Using UTXO ## Metadata **Status**:: #x **Zettel**:: #zettel/permanent **Created**:: [[2025-04-22]] **Tags**:: #brainstorm #utxo #blockchain #utxo-state #evergreen **Reference**:: [[Unisocks-Style NFT Sale in CKB (Fleeting)]] **Reference**:: [[Bartoletti et al. - Scalable UTXO Smart Contracts via Fine-Grained Distributed State]] ## Introduction The "Unisocks-style NFT sale" model, pioneered by Uniswap's Unisocks project, introduces a novel mechanism for selling limited-edition digital or physical goods on the blockchain. Unlike fixed-price sales, this model employs a **bonding curve**—a mathematical function that dynamically increases the price $P$ of each unit as more units $k$ are sold: $ k \to P(k) $ This approach incentivizes early purchases and creates a self-adjusting market price based on demand. This article explores how to implement such a sale model using the **extended UTXO** (eUTXO) blockchain paradigm, where each UTXO can carry immutable associated data, enabling sophisticated state management. ## Problem Statement Implementing a bonding curve-based NFT sale on a UTXO-based blockchain presents unique challenges: - **State Management:** Tracking the number of units sold $k$ reliably on-chain. - **Concurrency:** Handling simultaneous purchase attempts without conflicts or bottlenecks. - **Scalability:** Supporting large supply sizes without excessive on-chain resource consumption. - **Fairness and Atomicity:** Ensuring buyers pay the correct price and receive the corresponding unit atomically. ## Brainstorming ### 1. Single State UTXO Tracking Sold Units In this straightforward approach, the entire sale state is encapsulated in a single UTXO that records the current number of sold units $k$. To purchase the next unit, a buyer must consume this state UTXO and produce a new one with $k + 1$. **Transaction structure:** ``` Inputs: 1: state(sold = k) 2..: payment inputs from buyer Outputs: 1: state(sold = k + 1) 2: payment P(k) to publisher 3: NFT unit(k + 1) to buyer 4: change back to buyer ``` **Limitations:** - **Concurrency bottleneck:** Only one buyer can consume the state UTXO at a time, causing contention and network congestion during high demand. - **Scalability:** Throughput is limited by the single state UTXO. --- ### 2. One UTXO per Unit Index To alleviate the single-UTXO bottleneck, the publisher pre-mints one state UTXO for each unit to be sold, each tagged with a unique unit index `id`. **Example pre-minted UTXOs:** ``` state(id = 1), state(id = 2), ..., state(id = N) ``` A buyer purchases unit $k$ by consuming the corresponding state UTXO: ``` Inputs: 1: state(id = k) 2..: payment inputs from buyer Outputs: 1: payment P(k-1) to publisher 2: NFT unit(k) to buyer 3: change back to buyer ``` **Challenges:** 1. **Fixed supply cap:** The total number of units $N$ is fixed at minting time. 2. **High upfront cost:** The publisher must create potentially thousands of UTXOs in advance. 3. **Over-purchasing risk:** Buyers can buy multiple units simultaneously, potentially exceeding intended limits. ### 3. Hybrid Range-Based State UTXOs This solution combines the previous two by grouping units into ranges represented by state UTXOs with `from` and `to` indices: ``` state(from = 1, to = 1), state(from = 2, to = 2), state(from = 3, to = 3), state(from = 4, to = 7), state(from = 8, to = 15), state(from = 16, to = 31), ``` Each state UTXO represents a contiguous range of units available for sale. All the UTXOs constitute a distributed map as in [[Bartoletti et al. - Scalable UTXO Smart Contracts via Fine-Grained Distributed State]]. **Example transactions:** - Buying unit 1: ``` Inputs: 1: state(from=1, to=1) 2: buyer payment Outputs: 1: payment P(0) to publisher 2: NFT unit(1) to buyer ``` - Buying unit 4 from range (4 to 7): ``` Inputs: 1: state(from=4, to=7) 2: buyer payment Outputs: 1: state(from=5, to=7) 2: payment P(3) to publisher 3: NFT unit(4) to buyer ``` - Buying unit 10 from range (8 to 15): ``` Inputs: 1: state(from=8, to=15) 2: buyer payment Outputs: 1: state(from=8, to=9) 2: state(from=11, to=15) 3: payment P(9) to publisher 4: NFT unit(10) to buyer ``` This range-based approach allows: - **Parallel purchases** by different buyers on disjoint ranges. - **Dynamic supply management** by merging or splitting ranges. - **Reduced upfront minting cost** compared to one UTXO per unit. ### 4. Round-Based Orders and Settlement In this model, buyers place orders by locking funds corresponding to their maximum acceptable price. Orders are stored in a distributed map (see [[Bartoletti et al. - Scalable UTXO Smart Contracts via Fine-Grained Distributed State|bartoletti2025ScalableUTXO]]) keyed by a hash of a secret preimage $p$, known only to the buyer. The value is a list indicating the maximum unit IDs the buyer is willing to accept. For example, the list $[5, 8]$ means the buyer wants to purchase two units, one with ID up to 5 and another up to 8. The buyer locks funds equal to the sum of prices $P(5) + P(8)$. At the end of each round: - The publisher collects all orders by including all the UTXOs in the distributed map. - Using a random variable $r$ (e.g., recent block hashes), orders are shuffled deterministically by sorting on $H(H(p) \Vert r)$. - The publisher sequentially settles orders, issuing units if the requested unit ID is acceptable, or refunding otherwise. This approach: - Prevents censorship by requiring all orders to be included. - Enables batch processing of purchases. - Reduces front-running by randomizing order execution. ## Conclusion Implementing a Unisocks-style NFT sale on a UTXO blockchain involves balancing concurrency, scalability, and price integrity. The solutions discussed provide a spectrum of design choices: - **Single UTXO state**: Simple but limited scalability. - **Per-unit UTXOs**: High concurrency but capped supply and high upfront cost. - **Hybrid range-based UTXOs**: Scalable and flexible, enabling parallelism and dynamic supply. - **Round-based batch settlement**: Fair and censorship-resistant, suitable for high-demand scenarios.