Without measuring the balance before and after the transfer, there's no way to ensure that enough tokens were transferred, in the cases where the token has a fee-on-transfer mechanic. If there are latent funds in the contract, subsequent transfers will succeed.
Accounting Errors
Exploitation by Malicious Users
Financial Loss
Trust Platform Disrupted
inspection manual
solidity
Measuring Balance Before and After Transfer:
Before making a transfer, measure the token balance at the recipient's address.
After making the transfer, measure the token balance again at the recipient's address.
Calculate the number of tokens actually received based on the difference between the balance after and before the transfer.
Validation of Number of Tokens Received:
Make sure the number of tokens received matches the expected amount. If they do not match, cancel the transaction to prevent accounting errors.
update Contract Code:
Implement balance measurement logic and validate the number of tokens received in the 'bid' function.
Code snippet L183-L203:
Fixed code:
explanation:
Balance measurement before and after transfer:
‘uint256 _bidTokenAmountBefore = IERC20(bidToken).balanceOf(_recipient);’
‘uint256 _bidTokenAmountAfter = IERC20(bidToken).balanceOf(_recipient);’
This allows us to know the number of tokens received taking into account transfer fees.
Calculation of the number of tokens received:
‘uint256 receivedAmount = _bidTokenAmountAfter - _bidTokenAmountBefore;’
Ensure that we get the number of tokens actually received.
Validate the number of tokens received:
‘if (receivedAmount != amount) { revert CommonEventsAndErrors.InvalidParam(); }’
Avoids the possibility of receiving an inappropriate number of tokens.
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.