-
Notifications
You must be signed in to change notification settings - Fork 10
fix: blob size validation #562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
46cfc09 to
9f1e487
Compare
| let blob = blobs | ||
| .get(&hash)? | ||
| .ok_or_else(|| ActorError::not_found(format!("blob {} not found", hash)))?; | ||
| Ok((hash, blob.size, sources)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gets the size of the newly added blobs and return it to Fendermint
| let blob = blobs | ||
| .get(&hash)? | ||
| .ok_or_else(|| ActorError::not_found(format!("blob {} not found", hash)))?; | ||
| Ok((hash, blob.size, sources)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns the size of pending blobs to Fendermint.
| env.blob_pool.add(BlobPoolItem { | ||
| subscriber: blob.subscriber, | ||
| hash: blob.hash, | ||
| size: blob.size, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added size in the pool item so it can be checked against the download blob.
| /// The return type used when fetching "added" or "pending" blobs. | ||
| /// See `get_added_blobs` and `get_pending_blobs` for more information. | ||
| type BlobRequest = (Hash, HashSet<(Address, SubscriptionId, PublicKey)>); | ||
| type BlobRequest = (Hash, u64, HashSet<(Address, SubscriptionId, PublicKey)>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns the size of the blob as u64 so that it could be added to the resolution pool
| /// The blake3 hash of the blob. | ||
| pub hash: Hash, | ||
| /// The size of the blob. | ||
| pub size: u64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FinalizedBlob needs to have size to construct BlobPoolItem again so it can be removed from the pool.
1f5a5f0 to
48a1a1a
Compare
Signed-off-by: avichalp <hi@avichalp.me>
Signed-off-by: avichalp <hi@avichalp.me>
00cac73 to
f238fa4
Compare
sanderpick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice! big improvement. i left one question about changing the toolchain version
| use recall_ipld::hamt::{BytesKey, MapKey}; | ||
|
|
||
| type BlobSourcesResult = | ||
| anyhow::Result<Vec<(Hash, u64, HashSet<(Address, SubscriptionId, PublicKey)>)>, ActorError>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at some point we should make these giant types into structs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rust-toolchain.toml
Outdated
| @@ -1,4 +1,4 @@ | |||
| [toolchain] | |||
| channel = "1.81.0" | |||
| channel = "1.82.0" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to do this on this PR? I think CI will need to be changed as well... esp. the docker build and publish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will revert this for now
This reverts commit f238fa4. Signed-off-by: avichalp <hi@avichalp.me>
Summary
This PR addresses issue #458 where malicious users could upload large blobs while declaring smaller sizes in the SDK, resulting in validators storing more data than users are charged for.
Problem
In the current implementation, users first stage data in a validator (either using Iroh's reverse upload or directly). Without proper validation, a user could:
sizeparameter in the SDK to a smaller value (e.g., 1MB)Solution
The PR implements size validation at multiple checkpoints throughout the blob lifecycle:
Size Verification During Set Pending: Added a validation check in
set_blob_pendingthat verifies the blob's actual size matches the claimed size before changing status to pendingSize Validation During Download: Added validation in the Iroh resolver to ensure downloaded blob size matches the expected size
Size Information Propagation: Modified relevant data structures to carry size information throughout the resolution process:
BlobRequest,PendingBlob, andFinalizedBlobstructuresBlobPoolItemto include size parameterKey Changes
Data Structure Updates:
BlobRequestto include blob size:(Hash, u64, HashSet<(Address, SubscriptionId, PublicKey)>)FinalizedBlobandPendingBlobstructuresBlobPoolItemto include size informationFunction Modifications:
get_added_blobsandget_pending_blobsto return blob sizeset_blob_pendingto accept and validate size parameterValidation Points:
This fix ensures users cannot exploit the system by misrepresenting blob sizes, protecting validators from storing more data than they're compensated for.
Resolves #458