Skip to content

Conversation

@seinmyung25
Copy link

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:

  • Ran forge fmt?
  • Ran forge test?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant