Skip to content

⚡️ Storage slot optimization idea (using address directly) #1506

Description

@seinmyung25

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions