Skip to content

Commit

Permalink
mocks: add returnBomb case and test
Browse files Browse the repository at this point in the history
  • Loading branch information
arbazkiraak committed Dec 12, 2023
1 parent 8bf9baa commit ccccbb6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
17 changes: 15 additions & 2 deletions src/mocks/malicious/returnBomb.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
pragma solidity ^0.8.0;

/*
The returnDataSize value needs careful calibration: it should not be so high that it depletes all the gas, causing a revert, nor should it be so low that the function consumes all the gas yet still returns the data successfully.
Our goal is to determine an optimal median value for returnDataSize that will ensure the outer call reverts as intended.
*/

contract returnBomb {
fallback() external {
uint128 public returnDataSize = 10000; // by default

function setReturnDataSize(uint128 _returnDataSize) external {
returnDataSize = _returnDataSize;
}

fallback () external {
assembly {
revert(1, 10000000)
revert(0,returnDataSize.slot)
}
}
}
21 changes: 18 additions & 3 deletions test/mocks/malicious/returnBomb.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,23 @@ contract returnBombTest is Test {
attacker = new returnBomb();
}

function testReturnBomb() public {
(bool success, bytes memory returnData) = address(attacker).call{gas: 3397}("");
assertEq(success, false);
function callSomething() public {
uint256 innerGasVal = gasleft() / 2;
(bool success, bytes memory returnData) = address(attacker).call{gas: innerGasVal}("");
console.log("returnBomb Innercall success: ", success);
}

function testReturnBombRevert() public {
vm.expectRevert();
this.callSomething{gas: 3000}();
}

function testReturnBombNotRevert() public {
this.callSomething{gas: 10000}();
}

function testSetters() public {
attacker.setReturnDataSize(50000);
assertEq(attacker.returnDataSize(),50000);
}
}

0 comments on commit ccccbb6

Please sign in to comment.