Skip to content

WritemarkerChain

Hitenjain14 edited this page Mar 18, 2025 · 2 revisions

Chain Hashing in Write Markers

Overview

Chain Hashing in write markers is a mechanism designed to enhance the efficiency and security of data verification and payment settlement on the blockchain. Instead of submitting individual write markers sequentially, which increases transaction costs and slows down processing, blobbers create a chain of write markers. This chain is verified by the blockchain using cryptographic hashing, ensuring correctness and integrity while reducing the number of transactions.

Problem Statement

Blobbers must submit Write Markers to the blockchain to prove they have stored a specific amount of data. This submission allows them to be challenged and paid accordingly. However, submitting each Write Marker individually introduces inefficiencies:

  • High blockchain transaction costs
  • Increased load on the blockchain
  • Slower processing and payment verification

To address these issues, we implement a chained write marker structure that allows blobbers to submit multiple uncommitted markers in a single transaction.

Chain Hashing Mechanism

1. Chaining Write Markers

Each Write Marker contains a Chain Hash, which is computed as:

Chain Hash = SHA-256(Previous Chain Hash || Allocation Root)

Where:

  • Previous Chain Hash: The chain hash of the last committed Write Marker
  • Allocation Root: The unique root hash representing the current allocation state

If the Previous Chain Hash is empty (first write marker), the allocation root alone is used.

2. Submission Process

  • The blobber accumulates up to 128 uncommitted Write Markers.
  • The blobber submits the latest Write Marker along with the allocation roots of all uncommitted markers.
  • The blockchain computes the chain hash using the stored previous marker and verifies the integrity of the entire chain.

3. Cryptographic Verification

The Write Marker Signature payload includes:

  • Chain Hash
  • Previous Chain Hash
  • Chain Size
  • Allocation Root
  • Previous Allocation Root
  • Client ID
  • Blobber ID
  • Timestamp
  • Allocation ID
  • Write marker Size
  • File Meta Root

The blockchain and validators verify:

  1. The correctness of the chain hash using the SHA-256 function.
  2. The integrity of chain size to prevent tampering.
  3. The validity of the user signature to ensure authenticity.

If any inconsistency is detected (e.g., mismatched chain hash or incorrect chain size), the blobber’s submission is rejected.

Chain Hash Calculation Code

The following function calculates the chain hash:

func CalculateChainHash(prevChainHash, newRoot string) string {
    hasher := sha256.New()
    if prevChainHash != "" {
        prevBytes, _ := hex.DecodeString(prevChainHash)
        hasher.Write(prevBytes) //nolint:errcheck
    }
    newBytes, _ := hex.DecodeString(newRoot)
    hasher.Write(newBytes) //nolint:errcheck
    return hex.EncodeToString(hasher.Sum(nil))
}

Diagram: Chained Write Markers

1. Chaining Process

sequenceDiagram
    participant WM1 as Write Marker 1
    participant WM2 as Write Marker 2
    participant WM3 as Write Marker 3
    participant Blockchain

    WM1->>WM2: Prev Chain Hash + Allocation Root
    WM1->>WM2: Chain Size = Size(WM1)
    WM2->>WM3: Prev Chain Hash + Allocation Root
    WM2->>WM3: Chain Size = Size(WM1) + Size(WM2)
    WM3->>Blockchain: Submit latest marker with chain
Loading

2. Verification Process

sequenceDiagram
    participant Blobber
    participant Blockchain
    Blobber->>Blockchain: Submit Write Marker Chain
    Blockchain->>Blockchain: Compute Chain Hash & Verify Chain Size
    Blockchain-->>Blobber: Accept if valid, reject if invalid
Loading