Skip to content
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

style!: cleanup blob struct #18

Merged
merged 2 commits into from
Jan 6, 2025
Merged

Conversation

samlaf
Copy link
Contributor

@samlaf samlaf commented Jan 3, 2025

Fixes #14

Contains some breaking api changes.
Also fixed the tests syntactically only, did not think very deeply about their semantics, so hopefully nothing breaks (doubt it though because this new API is much much simpler: blobs are no longer mutable and stateful).

@epociask tagging you since I think you are using this in nitro. Should be a pretty simple change to update to this new API.

Copy link
Collaborator

@bxue-l2 bxue-l2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good to me. Wait for others to comment

);
assert!(blob.is_padded(), "has to be padded");

blob.remove_padding().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the test to revert it back?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean to create a blob and then destruct it getting the raw data back? This test does this, is this what you meant?

/// if the data has 32 byte segments exceeding the modulo of the field
/// then the bytes will be modded by the order of the field and the data
/// will be transformed incorrectly
pub fn from_padded_bytes_unchecked(input: &[u8]) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to go through the rest of the changes but this function is used in nitro proofs. So will be a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. Why are you padding your data outside of this blob in nitro?
But basically you can just use the new() constructor directly now, its doing this same unchecked loading (use from_raw_data if the data isnt already padded)

Comment on lines -89 to -99
/// Removes padding from the blob data if it is padded.
pub fn remove_padding(&mut self) -> Result<(), BlobError> {
if !self.is_padded {
Err(BlobError::NotPaddedError)
} else {
self.blob_data =
helpers::remove_empty_byte_from_padded_bytes_unchecked(&self.blob_data);
self.is_padded = false;
self.length_after_padding = 0;
Ok(())
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we removing this function cause it isnt used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No removing because blobs are no longer stateful so we can't change them in place.
Still kept a function to_raw_data to get back the underlying data (unpad and give back the raw_data)

@samlaf samlaf force-pushed the style--issue14-cleanup-blob-struct branch from 17050bf to dd40e9f Compare January 4, 2025 17:43
@samlaf
Copy link
Contributor Author

samlaf commented Jan 4, 2025

Rebased on top of master after having merged #22

@samlaf samlaf requested review from anupsv and bxue-l2 January 4, 2025 17:43
@samlaf samlaf merged commit 85be357 into master Jan 6, 2025
1 check passed
@samlaf samlaf deleted the style--issue14-cleanup-blob-struct branch January 6, 2025 16:09
@bxue-l2
Copy link
Collaborator

bxue-l2 commented Jan 6, 2025

did you merge without approval? I am ok with the change, but should we set the branch protection?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

blob: make the Blob struct more rust-like
3 participants