diff --git a/src/mocks/malicious/gasExhaust.sol b/src/mocks/malicious/gasExhaust.sol new file mode 100644 index 0000000..d09d27d --- /dev/null +++ b/src/mocks/malicious/gasExhaust.sol @@ -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++; + } + } +} diff --git a/test/mocks/malicious/gasExhaust.t.sol b/test/mocks/malicious/gasExhaust.t.sol new file mode 100644 index 0000000..8f51d99 --- /dev/null +++ b/test/mocks/malicious/gasExhaust.t.sol @@ -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); + } +}