-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
55 additions
and
7 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity 0.8.19; | ||
|
||
contract HighLevelCallsInLoop { | ||
address payable[] destinations; | ||
|
||
function bad() external { | ||
// BAD for loop (the fallback may revert causing DoS) | ||
for (uint i = 0; i < destinations.length; i++) { | ||
destinations[i].transfer(i); | ||
} | ||
} | ||
|
||
function bad2() external { | ||
// BAD for loop (the fallback may revert causing DoS) | ||
for (uint i = 0; i < destinations.length; i++) { | ||
facilitateTransfer(i, i * 2); | ||
} | ||
} | ||
|
||
function facilitateTransfer(uint256 index, uint256 money) internal { | ||
destinations[index].transfer(money); | ||
} | ||
|
||
function bad3() external view { | ||
// BAD for loop | ||
for (uint i = 0; i < destinations.length; i++) { | ||
SimplyRevert(destinations[i]).sayHello(); | ||
} | ||
} | ||
|
||
function goodButTreatedAsBad() external view { | ||
// BAD for loop | ||
for (uint i = 0; i < destinations.length; i++) { | ||
SimplyRevert(destinations[i]).innocent(); | ||
} | ||
} | ||
} | ||
|
||
contract SimplyRevert { | ||
error HellNo(string); | ||
|
||
function sayHello() external pure { | ||
revert(); | ||
} | ||
|
||
function innocent() external pure {} | ||
} |