Skip to content

feat(u): add u slot subcommand for Solidity storage slot computation#5475

Open
bit2swaz wants to merge 2 commits into
unionlabs:mainfrom
bit2swaz:feat/slot-calculator-cli
Open

feat(u): add u slot subcommand for Solidity storage slot computation#5475
bit2swaz wants to merge 2 commits into
unionlabs:mainfrom
bit2swaz:feat/slot-calculator-cli

Conversation

@bit2swaz

Copy link
Copy Markdown

Closes #3417.

What this does

Adds a u slot subcommand (alias u s) to the u CLI. Given a Solidity storage layout type and an ordered list of keys, it prints the storage slot as a 0x-prefixed 32-byte hex value to stdout.

u slot "mapping(uint256 => mapping(uint256 => uint256)[])" 100 1 123
# 0x00a9b48fe93e5d10ebc2d9021d1477088c6292bf047876944343f57fdf3f0467

Keys go outermost to innermost. The output is bare (no label), so it pipes into other tools without any stripping.

Implementation

  • New module tools/u/src/slot.rs with three private functions: parse_layout (wraps the bare type in a dummy state variable so syn-solidity can parse it), parse_mapping_key (maps a Solidity key type and string value to MappingKey), and build_slot (walks the type tree consuming keys front-to-back, allocating each Slot node in a typed_arena::Arena to satisfy the borrow-based lifetime constraints).
  • Reuses the existing solidity-slot library unchanged.
  • Wired into main.rs as Cmd::Slot with visible alias s.
  • Added syn-solidity and typed-arena to workspace dependencies.

Test coverage

14 unit tests covering: nested mapping + array layout parsing, all supported key types (uint256, uint64, bytes32, string), rejection of unsupported types and malformed inputs, the known-answer vector from the issue, too-few and too-many keys, a single mapping, a single dynamic array, and a bytes32 key.

Checklist

  • cargo clippy -p u --all-targets passes
  • cargo fmt -p u produces no diff
  • cargo test -p u passes (14/14)
  • Known-answer vector confirmed end-to-end via CLI
  • Positional args (not flags), per maintainer feedback
  • Lives in existing tools/u crate, no new crate

@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

@bit2swaz is attempting to deploy a commit to the unionbuild Team on Vercel.

A member of the Team first needs to authorize it.

@bit2swaz

Copy link
Copy Markdown
Author

@benluelo lmk if any changes are needed :)

Comment thread tools/u/src/slot.rs Outdated
@bit2swaz bit2swaz requested a review from benluelo June 24, 2026 01:28
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.

Move Slot type into it's own library

2 participants