-
Notifications
You must be signed in to change notification settings - Fork 2
Expose fromFixedDecimalLosslessPacked #68
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
94184af
update the contract
0xgleb 25b8d15
add from_fixed_decimal
0xgleb 04a7ede
From<Float> for B256
0xgleb 23e7fe0
add serde
0xgleb 2cb3589
make inner B256 pub
0xgleb 0b056f8
expose pack_lossless
0xgleb fac873b
Merge branch 'main' into feat/from-fixed-decimal
0xgleb edb8d22
Default
0xgleb 6d179f2
Merge branch 'main' into feat/from-fixed-decimal
0xgleb 27ddf9e
Merge branch 'main' into feat/from-fixed-decimal
hardyjosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
🧹 Nitpick (assertive)
Note: Changing the Float struct's inner type is a breaking change.
The change from
FixedBytes<32>toB256modifies the public API. Any external code that pattern matches onFloat(FixedBytes<32>)or otherwise depends on the exact type will break. Consider documenting this in the changelog or release notes.The addition of
SerializeandDeserializetraits is excellent for the goal of enabling Rust usage.🤖 Prompt for AI Agents
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.
B256is an alias forFixedBytes<32>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.
🧩 Analysis chain
🏁 Script executed:
Length of output: 485
🌐 Web query:
💡 Result:
Definition of
B256in Alloy PrimitivesB256 is a type alias provided by the Alloy primitives Rust library, widely used in Ethereum-related Rust projects such as Foundry, reth, and revm.
Type Alias Definition
B256 is defined as a type alias for a 32-byte fixed-size byte array:
This means
B256andFixedBytes<32>are interchangeable in type usage[4].The underlying type for
B256is a struct holding an array of 32 bytes:This struct encapsulates the bytes and provides implementations and traits relevant to Ethereum-style fixed-length data[4].
Related Type Aliases
Alloy provides similar type aliases for various sizes of fixed-length byte arrays, such as:
B8: 1 byteB16: 2 bytesB32: 4 bytesB64: 8 bytesB128: 16 bytesB192: 24 bytesB224: 28 bytesB256: 32 bytesB512: 64 bytesB1024: 128 bytes[2]These aliases make it easy to work with byte arrays matching the sizes commonly used in Ethereum and Solidity smart contracts.
Usage Context
B256is commonly used to represent 32-byte data such as hashes (e.g., block hash, transaction hash) in Ethereum-like blockchains[2][4].FixedBytesgeneric struct and its type aliases (likeB256) are part of thealloy_primitivescrate, which standardizes these primitives across many EVM-based Rust projects[1][2][4].Example Usage
This example illustrates that
B256is simply a more readable alias forFixedBytes<32>[1][4].Summary Table
References to Source
B256is defined aspub type B256 = FixedBytes<32>;, a 32-byte fixed byte-array type[2][4].FixedBytesgeneric allows for arbitrary fixed-size byte arrays, with aliases likeB256for convenience[1][2].This approach standardizes handling of fixed-size byte arrays in Rust for Ethereum and related applications.
Citations:
cast storagedisplays wrong values for packed slots foundry-rs/foundry#6319@0xgleb You're absolutely correct! Thank you for the clarification.
The web search confirms that
B256is indeed a type alias forFixedBytes<32>in the Alloy primitives library:Since they are completely interchangeable types, the change from
FixedBytes<32>toB256is not a breaking change. I apologize for the incorrect analysis in my previous comment. The change is purely cosmetic and uses the more conventional alias that's commonly used in Ethereum-related Rust projects.The addition of
SerializeandDeserializetraits remains a great improvement for enabling Rust usage of the Float code.✏️ Learnings added