solady icon indicating copy to clipboard operation
solady copied to clipboard

⚡️ Storage slot optimization idea (using address directly)

Open seinmyung25 opened this issue 2 months ago • 5 comments

I have a quick question about a storage-slot optimization idea.

Instead of deriving a mapping slot via keccak256(owner, slot), I’m considering using the address directly under a dedicated namespace, e.g.:

bytes32 private constant _BALANCE_SPACE_SEED = 0x87a211a2000000000000000000000000000000000000000000000000000000;

function balanceOf(address owner) public view returns (uint256 result) {
    /// @solidity memory-safe-assembly
    assembly {
        result := sload(or(_BALANCE_SPACE_SEED, owner))
    }
}

Would this be safe and correct. Are there any risks of storage collisions or other security issues with or(_BALANCE_SPACE_SEED, owner).

seinmyung25 avatar Dec 14 '25 06:12 seinmyung25