🛠️
Stacks Documentation
  • Start Here
  • 🧠Concepts
    • Stacks 101
      • What Is Stacks?
      • Bitcoin Connection
      • Proof of Transfer
      • Stacks Among Other Layers
      • Financial Incentive and Security Budget
    • Network Fundamentals
      • Network Basics
      • Mainnet and Testnets
      • Accounts
      • Authentication
      • Bitcoin Name System
      • SIPs
      • Technical Specifications
    • Block Production
      • Mining
      • Signing
      • Bitcoin Finality
      • Bitcoin Reorgs
      • Stacking
    • Transactions
      • How Transactions Work
      • Post Conditions
    • Clarity
      • Overview
      • Decidability
    • sBTC
      • Core Features
      • sBTC Operations
        • Deposit
        • Withdrawal
        • Deposit vs Withdrawal Times
      • Emily API
      • Peg Wallet UTXO
      • Clarity Contracts
        • sBTC Registry
        • sBTC Token
        • sBTC Deposit
        • sBTC Withdrawal
      • Auxiliary Features
        • Transaction Fee Sponsorship
        • Signer Wallet Rotation
      • Walkthroughs
        • Signer Process Walkthrough
        • sBTC Transaction Walkthrough
      • sBTC FAQ
    • Gaia
      • Configuration
      • Deploy Gaia Hub
      • Amazon EC2
      • Linux
      • Mac OS
  • 🛠️Guides & Tutorials
    • Developer Quickstart
    • Clarity Crash Course
    • Build a Borrowing & Lending Protocol
    • Bitcoin Integration
      • Sending Bitcoin with Leather Wallet
      • Verifying a Bitcoin Transaction
      • Parsing a Bitcoin Transaction
    • Create Tokens
      • Creating a NFT
      • Creating a Fungible Token
    • Build a Frontend
      • Post Conditions with Stacks.js
      • Authentication with Stacks.js
      • Sending Transactions with Stacks.js
    • Testing Smart Contracts
      • Fuzz Testing
    • Run a Node
      • Run a Node with Docker
      • Run a Node with Digital Ocean
      • Run a Node with a Hosted Provider
      • Run a Node with Quicknode
      • Run a Bitcoin Node
      • Run a Pruned Bitcoin Node
    • Run a Miner
      • Miner Prerequisites
      • Miner Costs and Fees
      • Mine Testnet Stacks Tokens
      • Mine Mainnet Stacks Tokens
      • Verify Miner
    • Run a Signer
      • Signer Quickstart
      • How to Read Signer Logs
      • How to Monitor a Signer
      • Best practices for running a Signer
      • OpSec Best Practices
    • sBTC
      • How to Run an sBTC Signer
      • Best practices for running an sBTC Signer
      • How to Use the sBTC Bridge
      • Earn sBTC Rewards
    • Stack STX
      • Solo Stack
      • Operate a Pool
      • Stack with a Pool
      • Increase Stacked Position
      • Stop Stacking
    • Oracles
    • Community Tutorials
  • 📚Reference
    • API
    • Clarity Types
    • Clarity Functions
    • Clarity Keywords
    • Stacks Node Configuration
    • Signer Configuration
    • Stacks Tooling
  • 🏗️Example Contracts
    • Audited Starter Contracts
    • Stacking
    • BNS
    • Multi Send
  • 🧡Press & Top Links
    • 🔶2024
      • 🔸January 2024
      • 🔸February 2024
      • 🔸March 2024
      • 🔸April 2024
      • 🔸May 2024
      • 🔸June 2024
      • 🔸July 2024
      • 🔸August 2024
      • 🔸September 2024
      • 🔸October 2024
      • 🔸November 2024
      • 🔸December 2024
    • 🔶2025
      • 🔸January 2025
      • 🔸February 2025
      • 🔸March 2025
      • 🔸April 2025
      • 🔸May 2025
  • 🧡Bitcoin Theses and Reports
    • 🟠Bitcoin Theses
    • 📙Bitcoin Reports
  • Contribute
Powered by GitBook
On this page
  • Overview
  • Constants
  • Error Constants
  • Public Functions
  • complete-deposit-wrapper
  • complete-deposits-wrapper
  • Private Functions
  • complete-individual-deposits-helper
  • Interactions with Other Contracts
  • Security Considerations

Was this helpful?

  1. Concepts
  2. sBTC
  3. Clarity Contracts

sBTC Deposit

PrevioussBTC TokenNextsBTC Withdrawal

Last updated 6 months ago

Was this helpful?

Overview

The (sbtc-deposit.clar) manages the deposit process for the sBTC system. It handles the validation and minting of sBTC tokens when users deposit Bitcoin, and interacts with the sBTC Registry contract to update the protocol state.

Constants

  • txid-length: The required length of a transaction ID (32 bytes).

  • dust-limit: The minimum amount for a valid deposit (546 satoshis).

Error Constants

  • ERR_TXID_LEN (u300): Indicates that the provided transaction ID is not the correct length.

  • ERR_DEPOSIT_REPLAY (u301): Signifies an attempt to replay a deposit that has already been completed.

  • ERR_LOWER_THAN_DUST (u302): Indicates that the deposit amount is below the dust limit.

  • ERR_DEPOSIT_INDEX_PREFIX: Used as a prefix for deposit-related errors in batch processing.

  • ERR_DEPOSIT (u303): General deposit error.

  • ERR_INVALID_CALLER (u304): Indicates that the caller is not authorized to perform the operation.

Public Functions

complete-deposit-wrapper

Processes a single deposit request.

  • Parameters:

    • txid: (buff 32) - The Bitcoin transaction ID

    • vout-index: uint - The output index of the deposit transaction

    • amount: uint - The amount of sBTC to mint (in satoshis)

    • recipient: principal - The Stacks address to receive the minted sBTC

  • Returns: (response bool uint)

Function flow:

  1. Verifies that the caller is the current signer principal.

  2. Checks that the deposit amount is above the dust limit.

  3. Validates the transaction ID length.

  4. Ensures the deposit hasn't been processed before (prevents replay).

  5. Mints sBTC tokens to the recipient.

  6. Updates the deposit state in the sBTC Registry contract.

complete-deposits-wrapper

Processes multiple deposit requests in a single transaction.

  • Parameters:

    • deposits: (list 650 {txid: (buff 32), vout-index: uint, amount: uint, recipient: principal}) - List of deposit data

  • Returns: (response uint uint)

Function flow:

  1. Verifies that the caller is the current signer principal.

  2. Iterates through the list of deposits, processing each one using the complete-individual-deposits-helper function.

Private Functions

complete-individual-deposits-helper

Helper function to process individual deposits within the batch operation.

  • Parameters:

    • deposit: {txid: (buff 32), vout-index: uint, amount: uint, recipient: principal} - Single deposit data

    • helper-response: (response uint uint) - Accumulator for tracking processed deposits

  • Returns: (response uint uint)

Function flow:

  1. Calls complete-deposit-wrapper for the individual deposit.

  2. If successful, increments the processed deposit count.

  3. If an error occurs, it's propagated with additional index information.

Interactions with Other Contracts

  • .sbtc-registry: Calls get-current-signer-data, get-completed-deposit, and complete-deposit to manage deposit state.

  • .sbtc-token: Calls protocol-mint to create new sBTC tokens.

Security Considerations

  1. Access Control: Only the current signer principal can call the deposit completion functions.

  2. Replay Prevention: The contract checks for previously processed deposits to prevent replay attacks.

  3. Dust Limit: Enforces a minimum deposit amount to prevent spam and ensure economic viability.

  4. Transaction ID Validation: Ensures the provided transaction ID is the correct length.

🧠
sBTC Deposit contract