Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions contracts/account/script/storage-layout-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
# collides with `owner` at slot 0 is catastrophic and silent, per
# `docs/plans/2026-08-02-option-e-phase3-audit-risk.md` §2). All new
# session-key state lives in ERC-7201 namespaced storage, accessed via a
# fixed-slot inline-assembly getter, which does NOT show up in solc's
# `storageLayout.storage` array — so the strongest possible assertion of
# "no new plain state variables" is: this array is BYTE-IDENTICAL between
# `TotalReclawAccount` and the `SimpleAccount` it subclasses.
# fixed-slot inline-assembly getter. Such storage sits at keccak-derived
# slots (~2**255) that cannot collide with the sequential slots 0..k that
# `owner` occupies, so it is NOT part of the collision class this gate
# guards. Older forge omitted it from `storageLayout.storage` entirely;
# newer forge lists it — so we filter namespaced entries out explicitly and
# assert the remaining PLAIN sequential layout is BYTE-IDENTICAL between
# `TotalReclawAccount` and the `SimpleAccount` it subclasses. (Relying on
# namespaced storage being absent was a toolchain-version assumption that
# broke; filtering is version-independent.)
#
# `contracts/account/foundry.toml` already sets `extra_output =
# ["storageLayout"]`; this script is what consumes it (the phase3-impl
Expand All @@ -30,9 +35,11 @@ forge inspect TotalReclawAccount storageLayout --json > /tmp/tra-storage-layout.
echo "Inspecting SimpleAccount (the deployed baseline's implementation contract) storage layout..."
forge inspect SimpleAccount storageLayout --json > /tmp/simple-account-storage-layout.json

# Compare only the `.storage` array (slot, offset, type, label) — the
# `.types` dictionary can differ trivially in ordering/naming without any
# real layout difference, so it is not part of the gate.
# Compare only the PLAIN sequential `.storage` entries (slot, offset, type,
# label). The `.types` dictionary can differ trivially in ordering/naming
# without any real layout difference, so it is not part of the gate; and
# ERC-7201 namespaced entries are excluded (see header) because they live at
# keccak-derived slots that cannot collide with slot 0.
python3 - <<'PY'
import json
import sys
Expand All @@ -42,10 +49,26 @@ with open("/tmp/tra-storage-layout.json") as f:
with open("/tmp/simple-account-storage-layout.json") as f:
simple = json.load(f)["storage"]

# An ERC-7201 namespaced slot is a keccak-derived value (~2**255); a plain
# sequential state variable is at a small slot (0, 1, 2, ...). Exclude the
# namespaced ones — by the "erc7201" type marker newer forge emits, and,
# defensively, by slot magnitude — so the gate compares only the plain
# layout that could collide with `owner`.
_NAMESPACE_SLOT_FLOOR = 1 << 64

def is_plain(e):
if "erc7201" in e.get("type", ""):
return False
try:
return int(e["slot"]) < _NAMESPACE_SLOT_FLOOR
except (KeyError, ValueError):
return True

def normalize(entries):
return [
{"slot": e["slot"], "offset": e["offset"], "label": e["label"], "type": e["type"]}
for e in entries
if is_plain(e)
]

tra_n = normalize(tra)
Expand Down
Loading