-
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 payload includes:
- Chain Hash
- Previous Chain Hash
- Chain Size
- User Signature
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))
}