Skip to content

Commit

Permalink
mocks: add gasExhaust contract
Browse files Browse the repository at this point in the history
  • Loading branch information
arbazkiraak committed Dec 4, 2023
1 parent 0c56098 commit 8bf9baa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/mocks/malicious/gasExhaust.sol
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++;
}
}
}
25 changes: 25 additions & 0 deletions test/mocks/malicious/gasExhaust.t.sol
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);
}
}

0 comments on commit 8bf9baa

Please sign in to comment.