The load()
function incorrectly computes storage slots for vaults using keccak256(abi.encode(VAULT_LOCATION, vaultId))
, reversing the standard Solidity mapping slot order. This violates Solidity’s storage layout rules, creating risks of key collision and data corruption where multiple vaults/mappings could overwrite each other’s storage slots.
Solidity Storage Rules:
For mappings and dynamic storage, slots are calculated as:
key
: Unique identifier (e.g., vaultId
)
base_slot
: Precomputed namespace (e.g., VAULT_LOCATION
)
Incorrect Implementation:
The code reverses the order:
This causes:
All vaults to share a linear sequence of slots starting from keccak256(VAULT_LOCATION)
High probability of slot collisions between vaults with sequential IDs
Collision Example:
For VAULT_LOCATION = 0x123...
and vaultId = 1
:
Correct Slot: keccak256(abi.encode(1, 0x123...))
Actual Slot: keccak256(abi.encode(0x123..., 1))
These produce entirely different (and non-isolated) storage locations.
Severity | Consequences |
---|---|
Critical | • Cross-Vault Data Corruption: Vaults with different IDs may collide with unrelated storage areas |
• Mapping Overlap: Other mappings using keccak256(key, base_slot)
could overwrite vault data
• Protocol-Wide Instability: Financial accounting errors in debt/collateral tracking
• Exploit Potential: Attackers could deliberately collide slots to manipulate balances
Example Scenario:
Vault #1 uses slot keccak256(VAULT_LOCATION || 1)
Another mapping uses slot keccak256(1 || OTHER_BASE_SLOT)
If VAULT_LOCATION = OTHER_BASE_SLOT
, these slots collide, causing silent data overwrites.
Correct the slot calculation order:
Storage Layout Tests:
Add Foundry tests to verify slot isolation:
Static Analysis Rule:
Implement a Slither custom detector to flag reversed abi.encode
orders in keccak256
calls:
Documentation Update:
Explicitly document storage slot conventions in the codebase:
"For namespaced storage, always use
keccak256(abi.encode(key, base_slot))
."
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.