Skip to content

using unchecked to improve gas efficiency #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

songlh
Copy link

@songlh songlh commented Jul 5, 2022

For ERC20, _totalSupply is the sum of all values in _balances. Thus, in function _mint(), "_totalSupply += amount" does not overflow, which can guarantee all additions on _balances[account] or _balances[recipent] do not overflow.

Similarly, subtractions on _totalSupply do not overflow, because subtraction on _balances[sender] conducted earlier does not overflow.

There are several explicit checks (e.g., "senderBalance >= amount"), which can enable the use of unchecked.

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