solady
solady copied to clipboard
⚡️ Optimize ERC20 slot computation with bitwise operations
Description
Replaces mstore + keccak256 with bitwise operations for balance slot computation in ERC20.
Pattern change:
// Before
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, owner)
result := sload(keccak256(0x0c, 0x20))
// After
result := sload(or(shl(224, _BALANCE_SLOT_SEED), shr(96, shl(96, owner))))
Functions optimized: balanceOf, transfer, transferFrom, _mint, _burn, _transfer
Impact: Reduced gas cost through fewer memory operations and direct bitwise slot computation.
Checklist
Ensure you completed all of the steps below before submitting your pull request:
- [x] Ran
forge fmt? - [x] Ran
forge test?