fix(StdStorage): distinguish derived return values from missing slots - #898
Open
developer3516 wants to merge 1 commit into
Open
fix(StdStorage): distinguish derived return values from missing slots#898developer3516 wants to merge 1 commit into
developer3516 wants to merge 1 commit into
Conversation
`find()` reverts with "Slot(s) not found." whenever no storage slot holds the value returned by the target call. That message is misleading for tokens whose balance is computed rather than stored: an Aave aToken scales a stored balance by a liquidity index, so `deal()` fails even though the balance slot is correctly identified as affecting the call. Report that case separately. When at least one read slot demonstrably changes the return value but none hold it, say so and name the two realistic causes: a derived value, or a packed variable that needs `enable_packed_slots()`. The extra probe only runs on the failing path, so the common case is unaffected. Short bytes/string returns are excluded, since a word-wise mismatch there says nothing about how the value is produced; those keep the original message, as does the reflection-token case from foundry-rs#740 where no slot affects the call at all. Closes foundry-rs#140
developer3516
requested review from
0xrusowsky,
DaniPopes,
grandizzy,
mattsse and
onbjerg
as code owners
August 17, 2026 08:12
2 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Closes #140.
deal()fails on tokens whose balance is computed rather than stored. The original report uses an Aave aToken, whosebalanceOfreturns the stored scaled balance multiplied by a liquidity index:stdStorage.find()locates a slot by requiring that the value held in the slot equals the value returned by the call. For a scaled-balance token that is never true, so the search fails with:That message is misleading. The balance slot is found —
checkSlotMutatesCallcorrectly reports that mutating it changesbalanceOf. It is rejected one step later by the value-equality check, and the user is told nothing about why.Solution
Report the two failures separately. When the search fails, probe whether any recorded read slot actually influences the return value:
"Slot(s) not found."This is the reflection-token case from bug(StdCheats): deal() hangs on reflection tokens #740, whose regression test is untouched.Implementation notes:
find()is already at the EVM stack limit — adding a single local there fails to compile with Stack too deep.bytes/stringreturns are excluded. There a word-wise mismatch says nothing about how the value is produced, sotest_RevertStorageFindRestoresFailedShortBytesProbekeeps the original message.Testing
test_RevertFindOnScaledBalanceTokenadds a minimal aToken-style mock (stored balance × index) and asserts the new message. It mirrors the structure of the existingtest_RevertFindOnReflectionToken.forge test: 207 passing, 0 failing.forge fmt --checkclean.This does not make
deal()work on such tokens — that would require inverting the token's own accounting, which is out of scope. It tells the user what happened so they can reach forvm.storeor the underlying scaled-balance accessor.