feat: LEP-5 availability commitment support#6
Conversation
Re-reviewed after 9f77216. The previous critical issue (commitment being silently dropped) is now fixed -- the adapter spreads
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| if (availabilityCommitment) { | ||
| msg.availability_commitment = { | ||
| commitment_type: availabilityCommitment.commitmentType, | ||
| hash_algo: availabilityCommitment.hashAlgo, | ||
| chunk_size: availabilityCommitment.chunkSize, | ||
| total_size: availabilityCommitment.totalSize.toString(), | ||
| num_chunks: availabilityCommitment.numChunks, | ||
| root: Array.from(availabilityCommitment.root), | ||
| challenge_indices: availabilityCommitment.challengeIndices, | ||
| }; | ||
| } |
There was a problem hiding this comment.
This availability_commitment is attached to msg here, but BlockchainActionAdapter.requestActionTx (cascade-port.ts lines 215-221) hardcodes exactly five fields when serializing the metadata into JSON.stringify: data_hash, file_name, rq_ids_ic, signatures, public. The availability_commitment key is silently dropped and never reaches the chain. The adapter's JSON.stringify call needs to be updated to forward this field as well, otherwise the entire commitment computation is wasted.
Fix it with Roo Code or mention @roomote and request a fix.
Add client-side Merkle tree construction and challenge index derivation for the Storage Verification Challenge. During cascade registration, the SDK now builds a BLAKE3 Merkle tree over file chunks, derives deterministic challenge indices from the root, and includes the AvailabilityCommitment in the on-chain metadata. - New commitment module (cascade/commitment.ts): selectChunkSize, buildTree, deriveIndices, buildCommitment - Updated codegen types: Params (svcChallengeCount, svcMinChunksForChallenge), CascadeMetadata (availabilityCommitment, chunkProofs), AvailabilityCommitment, ChunkProof, HashAlgo - Uploader reads SVC params from chain, builds commitment during registration - 21 new tests covering tree construction, index derivation, edge cases - Zero regressions on existing test suite
63a3acc to
9f77216
Compare
What
Adds client-side LEP-5 availability commitment support to the JS SDK. During cascade registration, the SDK now builds a BLAKE3 Merkle tree over the file's chunks, derives deterministic challenge indices from the root, and includes the
AvailabilityCommitmentin the on-chain cascade metadata.Why
LEP-5 introduces Storage Verification Challenges. The client computes the commitment at registration time so the chain can later verify that supernodes actually stored the data. The supernode independently verifies the root and generates chunk proofs during finalization.
How it works
svc_challenge_countandsvc_min_chunks_for_challengefrom chain params (zero → defaults 8/4)BLAKE3(root || uint32be(counter)) mod numChunksAvailabilityCommitmentto cascade metadata in the registration transactionCompatibility
Changes
src/cascade/commitment.ts(new):selectChunkSize,buildTree,deriveIndices,buildCommitmentsrc/codegen/lumera/action/v1/params.ts: AddedsvcChallengeCount(field 12),svcMinChunksForChallenge(field 13)src/codegen/lumera/action/v1/metadata.ts: AddedAvailabilityCommitment,ChunkProof,HashAlgotypes + fields 8/9 onCascadeMetadatasrc/cascade/uploader.ts: Reads SVC params, builds commitment, includes in registration metadatasrc/cascade/ports.ts: ExtendedCascadeActionParamswith SVC fieldssrc/blockchain/interfaces.ts: ExtendedActionParamswith SVC fieldssrc/blockchain/client.ts+adapters/cascade-port.ts: Maps new params from chain querysrc/index.ts: Exports new types and commitment functionsTesting
tests/cascade/commitment.test.tscovering tree construction, index derivation, determinism, and edge cases