TSender

Cyfrin
DeFiFoundry
15,000 USDC
View results
Submission Details
Severity: low
Invalid

The `TSender::airdropERC20` function doesn't check if the both arrays are not empty

Summary

The TSender::airdropERC20 function does not check if the lengths of the recipients and amounts arrays are non-zero.

Vulnerability Details

The airdropERC20 function is designed to distribute ERC20 tokens to multiple recipients. The function currently checks if the lengths of the recipients and amounts arrays match. But the function does not verify if the lengths of the recipients and amounts arrays are non-zero. This is done in the areListsValid function, but it is not used in the airdropERC20.

function airdropERC20(
address tokenAddress,
address[] calldata recipients,
uint256[] calldata amounts,
uint256 totalAmount
) external {
assembly {
// check for equal lengths
@> if iszero(eq(recipients.length, amounts.length)) {
mstore(0x00, 0x50a302d6) // cast sig TSender__LengthsDontMatch()
revert(0x1c, 0x04)
}
...
}
}

Impact

If the airdropERC20 function is called with empty arrays, the function will revert with out of bounds error. The following test demonstrates that:

function test_EmptyArrays() public virtual {
// Arrange
vm.startPrank(address(this));
mockERC20.mint(1e9);
mockERC20.approve(address(tSender), 1e9);
vm.stopPrank();
address[] memory recipients = new address[](0);
recipients[0] = recipientOne;
uint256[] memory amounts = new uint256[](0);
amounts[0] = 0;
// Act
vm.prank(address(this));
tSender.airdropERC20(address(mockERC20), recipients, amounts, 0);
}

And the result:

[FAIL. Reason: panic: array out-of-bounds access (0x32)] test_EmptyArrays() (gas: 84911)

That leads to unnecessary consume of gas for the initial checks and setup.

Tools Used

Manual Review

Recommendations

Use the areListsValids to check the valididty of the arrays before proceeding with the execution logic of the airdropERC20 function.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.