The current implementation of airdropERC20 in the TSender contract assumes the msg.sender (caller) has granted sufficient allowance for the contract to transfer the total amount of tokens required for the airdrop. However, it doesn't explicitly handle the scenario where the allowance is insufficient.
Problem:
The airdropERC20 function performs a transferFrom call on the ERC20 token contract to transfer the total amount (totalAmount) from the msg.sender to the TSender contract itself. This is done to ensure the contract has enough tokens before proceeding with individual transfers to recipients.
However, if the msg.sender hasn't granted enough allowance for the TSender contract to transfer the totalAmount, the transferFrom call will revert. The current code doesn't explicitly check for this specific revert reason.
Potential Consequences:
Transaction Revert: The entire airdropERC20 transaction will revert due to the failed transferFrom call, potentially wasting gas and causing the airdrop to fail entirely.
Lack of Informative Error Message: Without checking the specific revert reason, the user might only see a generic error message, making it difficult to diagnose the root cause (insufficient allowance).
Solution:
There are two ways to improve the handling of insufficient allowance:
Check Revert Reason: Modify the code after the transferFrom call to check the specific revert reason using assembly language. If the reason indicates insufficient allowance, revert the transaction with a more informative error message. Here's an example (pseudocode):
if (call(...) != success) {
if (revertReason == "Insufficient Allowance") {
revert("Insufficient allowance granted to TSender contract");
} else {
// Revert with original revert reason
}
}
Use ERC20 Library: Leverage a dedicated ERC20 library that simplifies token interactions and often includes functions to handle specific revert reasons, including insufficient allowance. This can provide a more robust and user-friendly approach.
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.