Skip to content

[v2] fix(ast): spell storage layout types as solc labels them - #2203

Merged
nebasuke merged 2 commits into
mainfrom
bas/storage-layout-solc-type-labels
Sep 28, 2026
Merged

nebasuke merged 2 commits into
mainfrom
bas/storage-layout-solc-type-labels

Conversation

@nebasuke

@nebasuke nebasuke commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #2196 by using solc's spelling for storage layout types.

Claude summary

Fixes #2196. Storage layout type names now read as solc's storageLayout labels: struct S,
enum C.E, contract I, address payable, and function types with their signature,
function (uint256,struct Store.TokenData) view returns (string), also inside mappings and arrays.
Before, they used the prefix-free internal spelling, which drops all four and reduces every function
type to the bare word function.

solc spells both its storage labels and the JSON ABI internalType with Type::toString(true),
which Slang already renders for the ABI. The storage layout now uses that spelling, which gains a
mapping case so that keys and values keep their prefixes too.

StorageItem::type_name() changes for every user-defined, address payable and function type.

Tests

A new fixture asserts solc 0.8.35's labels for one source covering function types (bare, in a
mapping, external, pure, payable), structs in mappings and arrays, enums, interfaces,
address payable next to address, a user-defined value type and a nested mapping. It fails on
main with every one of those differences; five existing expectations gain their struct prefix.

Corpus

With #2199's storage_types check comparing exactly (no prefix normalisation), over the whole
Sourcify 0.8.x corpus (2,326,676 contracts):

storage_types failures storage_layout failures
main 1,132,133 contracts 0
this PR 0 0

Every other bucket is unchanged: with this PR the census passes 2,286,059 contracts, as main did
before the storage checks existed.

Performance

The solc spelling builds more text per storage item, and building it with nested format! calls
cost +2.3% instructions on compute_contracts_abi for cooldogs, the Bencher alert on the first
commit. The second commit writes each type name into one buffer instead, which puts the ABI
benchmarks below main. Bencher on the tip, no alerts; the other benchmarks don't move:

compute_contracts_abi instructions allocations bytes
cooldogs −5.5% −2.5% −0.2%
uniswap −3.2% −2.7% −0.6%
ens_registrar_controller −2.1% 0 0
one_step_leverage_f −1.5% +1.0% +0.4%

Not here

Internal signatures keep the prefix-free spelling, so two overloads differing only in a
function-typed parameter still share one, f(function).

Storage layout type names used the prefix-free internal spelling, which
reduces every function type to `function` and drops the `struct `/`enum `/
`contract ` prefixes and `address payable` that solc's storageLayout labels
carry. They now use solc's `Type::toString(true)` spelling, the same one the
ABI `internalType` already renders, extended to mappings so nested keys and
values keep their prefixes.

Fixes #2196.
@changeset-bot

changeset-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fae4921

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchbas/storage-layout-solc-type-labels
Testbedci

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

🐰 View full continuous benchmarking report in Bencher

@nebasuke
nebasuke marked this pull request as ready for review September 25, 2026 22:05
@nebasuke
nebasuke requested review from a team as code owners September 25, 2026 22:05

@teofr teofr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

@nebasuke
nebasuke added this pull request to the merge queue Sep 28, 2026
Merged via the queue into main with commit cb1dcd3 Sep 28, 2026
19 checks passed
@nebasuke
nebasuke deleted the bas/storage-layout-solc-type-labels branch September 28, 2026 16:16
nebasuke added a commit that referenced this pull request Oct 9, 2026
#2215 gives the storage layout a types table shaped like solc's, so
`storage_types` now follows each item's type through both tables at
once (array bases, mapping keys and values, struct members) and
compares label, numberOfBytes and encoding, instead of the item's type
label alone. The two tables key types differently, so they are paired
by walking, not by name.

The same checks run on `transientStorageLayout`. The #2196 entry goes:
#2203 fixed the labels it tolerated.
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.

[v2] Storage layout type names don't match solc's labels

2 participants