Data Storage
Off-Chain Storage
Overview
Off-chain storage in Haircomb refers to the process of storing transaction-related data outside the main blockchain ledger. This method is critical for enhancing scalability and reducing the burden on the blockchain network. By keeping the blockchain lean, Haircomb can support a higher volume of transaction outputs without sacrificing efficiency or performance.
Off-chain storage is particularly effective in situations where storing every transaction detail by every participant on-chain would lead to significant bloat, making the system slow and costly. In the Haircomb architecture, off-chain storage allows for lightweight, scalable transaction management while maintaining security and privacy.
Benefits and Use Cases
- Scalability: By storing data off-chain, Haircomb can process and support a much larger number of transaction outputs compared to traditional blockchain systems like BTC, where every transaction is recorded on-chain. This results in better throughput and lower overall transaction fees per output.
- Performance: Off-chain storage reduces the amount of data that needs to be validated and maintained on-chain, leading to an improved overall network performance. This is especially beneficial for systems handling large volumes of micropayments or high-fanout transactions.
- Examples:
- Micropayment Systems: Off-chain storage enables Haircomb to handle millions of small transaction outputs, making it ideal for industries like digital content or gaming.
- Multi-Recipient Payments: By offloading the transaction data of complex multi-payment transactions, Haircomb can efficiently handle scenarios where one transaction is intended for many recipients.
- Fundraising: Off-chain storage facilitates large-scale fundraising efforts, where numerous small transaction outputs need to be processed without overwhelming the blockchain.
Implementation
- Technologies: Haircomb’s off-chain storage uses Merkle trees and distributed hash tables (DHTs) to store transaction data securely. Only essential data, such as cryptographic commitments, is stored on-chain, while the rest of the data is kept in external storage wallets on Haircomb nodes.
- Data Access: Off-chain data can be accessed and verified through cryptographic hashes that are anchored on-chain. When a transaction needs to be validated, the system retrieves the necessary off-chain data and verifies it against the on-chain hash, ensuring the integrity of the stored data. This method allows for efficient integration between off-chain and on-chain data.
On-Chain Commits
Overview
On-chain commits in Haircomb are cryptographic commitments that link off-chain data to the blockchain. These commits are small pieces of data stored on the blockchain that represent the state or existence of off-chain data without storing the entire dataset on-chain. They serve as a bridge between the immutable blockchain ledger and the more flexible off-chain storage systems.
On-chain commits are essential for ensuring data integrity, transparency, and verifiability while leveraging the scalability advantages of off-chain storage.
Commitment scheme
Commits should be understood in the context of a commitment scheme. A commitment scheme is a mechanism by which prover commits to a specific secret value, unable to change it after the fact, and being able to reveal it to verifier later.
A haircomb commitment scheme uses the formula:
commitment = SHA256(whitepaper hash || committed value)
The bech32(commitment)
is then interpreted as a P2WSH bitcoin address and funded with minimal amount of bitcoin on the bitcoin chain.The bitcoin address is not spendable on Bitcoin, and is funded here purely to store the 32 bytes it encodes (the commitment) on the bitcoin chain.
A haircomb commitment scheme is:
- Computationally hiding: A third party cannot discover what the committed value is without breaking the preimage resistance of SHA256, only by being revealed the secret value by the prover.
- Computationally binding: A malicious party cannot change the commitment made by the original prover into another commitment, delete it, or alter it in any way, without redoing the cumulative proof of work on the bitcoin blockchain.
- Totally ordered: For every two commitments (X, Y) it is true that either: X happens before Y, or X happens after Y. We consider the position of the commitment X the triplet (block height, transaction number, transaction output number) in which the commitment X occured on chain for the first time.
Commit Structure and Format
- Structure: Each on-chain commit in Haircomb is represented as a cryptographic hash (typically using SHA-256) that references the off-chain data. This hash guarantees that any changes to the off-chain data will be detectable, as the commit will no longer match the altered data.
- Format: On-chain commits are encoded in certain unique P2WSH addresses on-chain. These commits are ordered by block height, transaction number and the output number in which an unique commit appeared for the first time.
Benefits and Use Cases
- Data Integrity: On-chain commits ensure that the off-chain data remains unchanged and tamper-proof. Any modification to the off-chain data can be easily detected by comparing it with the on-chain commit. This makes it ideal for storing sensitive financial or transactional information off-chain while preserving its integrity.
- Transparency: Even though most transaction data is stored off-chain, on-chain commits provide transparency by allowing users and validators to audit the system. Since the on-chain commit points to a specific state of the data, anyone can verify that the off-chain data remains consistent with the blockchain.
- Examples:
- Auditable Supply Chains: On-chain commits can be used to track the state of goods or services in a supply chain. The off-chain data contains detailed information about each transaction, while the on-chain commits ensure the integrity and verifiability of that data.
- Financial Agreements: In scenarios where sensitive contractual or financial data is stored off-chain, on-chain commits provide a way to verify the integrity of the agreement without exposing the underlying data.
Implementation
- Technologies: Haircomb leverages Merkle trees and cryptographic hashing algorithms, particularly SHA-256, for on-chain commits. These technologies allow Haircomb to efficiently store data off-chain while maintaining a secure reference on the blockchain itself.
- Data Management: On-chain commits are managed by ensuring that the hashes of off-chain data are correctly recorded in each block. When a transaction occurs, the related data is stored off-chain, and a hash is created and added to the blockchain. Data is then accessed through these on-chain references, ensuring both scalability and data integrity. Validators can audit the system by comparing the on-chain commits with the corresponding off-chain data.