The main purpose of creating this token is to be more gas-efficient that its counterpart from Openzeppelin. For the most part, it is as gas-efficient as possible. But in the case of the _transfer function, it can save more gas by making some simple adjustments.
To be more precise, the section fetching the recipient's balance should be done after the sender's balance is checked for availability of funds.
If they do not have enough funds to send, then it reverts without ever fetching the recipient's balance (which is irrelevant now).
In addition, there are cases where we know the result of a calculation at the time of writing the code. For example, mstore(add(0x00, 4), from) can be simplified to mstore(0x04, from) which saves a few more gas.
Likelihood: Low
It can happen when the sender's balance is not enough to proceed with the transaction.
It does not occur when the sender has enough funds and the transaction goes through.
Impact:
It can save upto 2,190 gas which is about 3.31% improvement comparing with the original version of this function (of course when it reverts with the IERC20Errors::ERC20InsufficientBalance custom error).
To see it in action, you need to run the test test_transferRevert2() function, then apply the changes and run it again. Next, compare their used gas amounts.
Original:
Improved:
Please make the following changes to improve the gas usage of the function by 3.31%.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.
The contest is complete and the rewards are being distributed.