Skip to content

fix(StdStorage): find string/bytes slots (dynamic ABI returns)#887

Open
Yonkoo11 wants to merge 1 commit into
foundry-rs:masterfrom
Yonkoo11:fix/stdstorage-find-dynamic-string-345
Open

fix(StdStorage): find string/bytes slots (dynamic ABI returns)#887
Yonkoo11 wants to merge 1 commit into
foundry-rs:masterfrom
Yonkoo11:fix/stdstorage-find-dynamic-string-345

Conversation

@Yonkoo11

Copy link
Copy Markdown

Summary

stdstore.find() failed on public string / bytes state vars (short strings in particular): Slot(s) not found.

Cause: mutation checks only compared one returndata word at depth. For dynamic ABI returns that word is the offset (0x20), not the content, so writing storage never registered as a hit. The follow-up slot value == return word check has the same mismatch (short-string packing is not the ABI word).

Change

  • Detect single dynamic returns (returndata length ≥ 64 and word0 == 0x20)
  • For those, probe slots with a full returndata hash compare
  • Skip the raw slot/return equality check in that path
  • Static multi-word returns (structs) still compare only the word at depth so sibling fields are not false hits

Tests

  • test_StorageFindShortString — 31-char public string, expects slot 0 (bug(StdStorage): find() does not work for short strings #345)
  • test_StorageFindLongString — find must not revert
  • test_StorageFindBytes — public bytes, expects slot 0
  • Existing test/StdStorage.t.sol suite (incl. fuzz) green locally

Notes

Closes #345

Prepared with AI assistance; I reviewed and ran the tests above.

find() compared only a single returndata word at depth. For string/bytes
getters that word is the ABI offset (0x20), so mutating storage never
looked like a hit and short strings failed with "Slot(s) not found".

For single dynamic returns, compare the full returndata hash when probing
slots, and skip the raw slot==return equality check (storage encoding is
not the ABI word). Static multi-word returns still use the depth word so
struct field isolation is unchanged.

Fixes foundry-rs#345
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.

bug(StdStorage): find() does not work for short strings

1 participant