Duplicate Zero Address Check in transferErcTokens() Increases Gas Cost
In the TokenDivider::transferErcTokens
function, there is a redundant check for the zero address. The same condition if(to == address(0))
appears twice in the function, with both checks reverting with the same error TokenDivider__CantTransferToAddressZero()
. This duplicate validation unnecessarily increases gas costs without providing any additional security benefits.
To verify this gas optimization, paste the following test into your TokenDiverTest.t.sol contract and run it:
Running forge test --mt testTransferErcTokens
shows:
With duplicate check: 1,147,593 gas units
After removing duplicate check: 1,147,559 gas units
The duplicate check results in:
Higher gas costs for users when calling the transferErcTokens
function
While relatively small, this cost multiplies across all transfer transactions in the system
Foundry
Remove the second zero address check in the transferErcTokens
function while keeping the first one. Here's the diff of the changes:
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.