Skip to content

Commit

Permalink
Split blob key verification into separate function
Browse files Browse the repository at this point in the history
Signed-off-by: litt3 <[email protected]>
  • Loading branch information
litt3 committed Jan 15, 2025
1 parent 8fb46b8 commit 617cbd5
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions api/clients/v2/disperser_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,44 @@ func (c *disperserClient) DisperseBlob(
return nil, [32]byte{}, err
}

if verifyReceivedBlobKey(blobHeader, reply) != nil {
return nil, [32]byte{}, fmt.Errorf("verify received blob key: %w", err)
}

return &blobStatus, corev2.BlobKey(reply.GetBlobKey()), nil
}

// verifyReceivedBlobKey computes the BlobKey from the BlobHeader which was sent to the disperser, and compares it with
// the BlobKey which was returned by the disperser in the DisperseBlobReply
//
// A successful verification guarantees that the disperser didn't make any modifications to the BlobHeader that it
// received from this client.
//
// This function returns nil if the verification succeeds, and otherwise returns an error describing the failure
func verifyReceivedBlobKey(
// the blob header which was constructed locally and sent to the disperser
blobHeader *corev2.BlobHeader,
// the reply received back from the disperser
disperserReply *disperser_rpc.DisperseBlobReply) error {

actualBlobKey, err := blobHeader.BlobKey()
if err != nil {
// this shouldn't be possible, since the blob key has already been used when signing dispersal
return nil, [32]byte{}, fmt.Errorf("computing blob key: %w", err)
return fmt.Errorf("computing blob key: %w", err)
}

blobKeyFromDisperser, err := corev2.BytesToBlobKey(reply.GetBlobKey())
blobKeyFromDisperser, err := corev2.BytesToBlobKey(disperserReply.GetBlobKey())
if err != nil {
return nil, [32]byte{}, fmt.Errorf("converting returned bytes to blob key: %w", err)
return fmt.Errorf("converting returned bytes to blob key: %w", err)
}

if actualBlobKey != blobKeyFromDisperser {
return nil, [32]byte{}, fmt.Errorf(
return fmt.Errorf(
"blob key returned by disperser (%v) doesn't match blob which was dispersed (%v)",
blobKeyFromDisperser, actualBlobKey)
}

return &blobStatus, corev2.BlobKey(reply.GetBlobKey()), nil
return nil
}

// GetBlobStatus returns the status of a blob with the given blob key.
Expand Down

0 comments on commit 617cbd5

Please sign in to comment.