-
Notifications
You must be signed in to change notification settings - Fork 23
WritemarkerChain
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.
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.
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.
- 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.
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:
- The correctness of the chain hash using the SHA-256 function.
- The integrity of chain size to prevent tampering.
- 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.
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))
}
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
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