Skip to content

Add StorageKey impls for all primitive integer types and bool#1431

Open
cburgdorf wants to merge 1 commit into
argotorg:masterfrom
cburgdorf:storage_keys
Open

Add StorageKey impls for all primitive integer types and bool#1431
cburgdorf wants to merge 1 commit into
argotorg:masterfrom
cburgdorf:storage_keys

Conversation

@cburgdorf
Copy link
Copy Markdown
Collaborator

Previously only u256 and Address could be used as StorageMap keys. With these impls, StorageMap<K, V> accepts any of u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, i256, isize, and bool — matching Solidity's mapping(intN/uintN/bool => V) slot derivation, since each write_key left-pads to 32 bytes via WordRepr::to_word() (zero-extending unsigned, sign-extending signed, encoding bool as 0/1).

Notable consumer: containers like DoubleEndedQueue that want to pack their indices into a single storage slot via u128 keys — previously forced to u256 keys for lack of this impl.

The new test fixture storage_map_key_types.fe exercises each key type by storing and reading values back through a contract method.

Note: test_signed_keys constructs negative i8/i32/i256 keys inside the contract instead of decoding them from calldata, sidestepping an unrelated Sonatina calldata-decoder bug for negative intN values where N < 256.

cburgdorf added a commit to cburgdorf/fe that referenced this pull request May 7, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31c506e823

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/fe/tests/fixtures/fe_test/storage_map_key_types.fe Outdated
Previously only `u256` and `Address` could be used as `StorageMap`
keys. With these impls, `StorageMap<K, V>` accepts any of u8, u16,
u32, u64, u128, usize, i8, i16, i32, i64, i128, i256, isize, and
bool — matching Solidity's `mapping(intN/uintN/bool => V)` slot
derivation, since each `write_key` left-pads to 32 bytes via
`WordRepr::to_word()` (zero-extending unsigned, sign-extending signed,
encoding `bool` as 0/1).

Notable consumer: containers like `DoubleEndedQueue` that want to pack
their indices into a single storage slot via `u128` keys — previously
forced to `u256` keys for lack of this impl.

The new test fixture `storage_map_key_types.fe` exercises each key
type by storing and reading values back through a contract method.

Note: `test_signed_keys` constructs negative i8/i32/i256 keys *inside*
the contract instead of decoding them from calldata, sidestepping an
unrelated Sonatina calldata-decoder bug for negative `intN` values
where N < 256.
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.

1 participant