Skip to content

Commit

Permalink
[Q-5] Use safeTransferETH instead of low-level call
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaryash90 committed Apr 1, 2024
1 parent fb8595a commit fbde069
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions contracts/prebuilts/unaudited/airdrop/Airdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ contract Airdrop is EIP712, Initializable, Ownable {

for (uint256 i = 0; i < len; i++) {
nativeTokenAmount += _contents[i].amount;
(bool success, ) = _contents[i].recipient.call{ value: _contents[i].amount }("");
if (!success) {
revert AirdropFailed();
}
SafeTransferLib.safeTransferETH(_contents[i].recipient, _contents[i].amount);
}

if (nativeTokenAmount != msg.value) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/airdrop/Airdrop.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import { Airdrop } from "contracts/prebuilts/unaudited/airdrop/Airdrop.sol";
import { Airdrop, SafeTransferLib } from "contracts/prebuilts/unaudited/airdrop/Airdrop.sol";

// Test imports
import { TWProxy } from "contracts/infra/TWProxy.sol";
Expand Down Expand Up @@ -228,7 +228,7 @@ contract AirdropTest is BaseTest {
Airdrop.AirdropContentERC20[] memory contents = _getContentsERC20(10);

vm.prank(signer);
vm.expectRevert(abi.encodeWithSelector(Airdrop.AirdropFailed.selector));
vm.expectRevert(abi.encodeWithSelector(SafeTransferLib.ETHTransferFailed.selector));
airdrop.airdropNativeToken{ value: 0 }(contents);

// add some balance to airdrop contract, which it will try sending to recipeints when msg.value zero
Expand Down

0 comments on commit fbde069

Please sign in to comment.