-
Notifications
You must be signed in to change notification settings - Fork 100
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
1 parent
0c56098
commit 8bf9baa
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
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,16 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
contract gasExhaust { | ||
uint256 counter; | ||
uint256 gasConsumeLimit; | ||
|
||
function setGasConsumeLimit(uint256 _gasConsume) public { | ||
gasConsumeLimit = _gasConsume; | ||
} | ||
|
||
fallback() external { | ||
while (gasleft() > gasConsumeLimit) { | ||
counter++; | ||
} | ||
} | ||
} |
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,25 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/Test.sol"; | ||
|
||
import {gasExhaust} from "../../../src/mocks/malicious/gasExhaust.sol"; | ||
|
||
contract gasExhaustTest is Test { | ||
gasExhaust public attacker; | ||
|
||
function setUp() public { | ||
attacker = new gasExhaust(); | ||
} | ||
|
||
function testGasExhaustSuccess() public { | ||
attacker.setGasConsumeLimit(6000); | ||
(bool success, bytes memory returnData) = address(attacker).call{gas: 25000}(""); | ||
assertEq(success, true); | ||
} | ||
|
||
function testGasExhaustFail() public { | ||
attacker.setGasConsumeLimit(100); | ||
(bool success, bytes memory returnData) = address(attacker).call{gas: 25000}(""); | ||
assertEq(success, false); | ||
} | ||
} |