From 96c452262c6596ee12177dfce579612f93b29ae0 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 1 Apr 2022 10:26:47 -0400 Subject: [PATCH 1/4] global failure --- src/test.sol | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/test.sol b/src/test.sol index 96d3c15..a0a0cf9 100644 --- a/src/test.sol +++ b/src/test.sol @@ -15,6 +15,11 @@ pragma solidity >=0.4.23; +interface LimitedHEVM { + function load(address, bytes32) external returns (bytes32); + function store(address, bytes32, bytes32) external; +} + contract DSTest { event log (string); event logs (bytes); @@ -36,7 +41,7 @@ contract DSTest { event log_named_string (string key, string val); bool public IS_TEST = true; - bool public failed; + bool private _failed; address constant HEVM_ADDRESS = address(bytes20(uint160(uint256(keccak256('hevm cheat code'))))); @@ -44,8 +49,32 @@ contract DSTest { modifier mayRevert() { _; } modifier testopts(string memory) { _; } + function failed() public returns (bool) { + if (_failed) { + return _failed; + } else { + bool globalFailed = false; + if (hasHEVMContext()) { + bytes32 slot = LimitedHEVM(HEVM_ADDRESS).load(HEVM_ADDRESS, 0); + globalFailed = slot == bytes32(uint256(0x01)); + } + return globalFailed; + } + } + function fail() internal { - failed = true; + if (hasHEVMContext()) { + LimitedHEVM(HEVM_ADDRESS).store(HEVM_ADDRESS, 0, bytes32(uint256(0x01))); + } + _failed = true; + } + + function hasHEVMContext() internal view returns (bool) { + uint256 hevmCodeSize = 0; + assembly { + hevmCodeSize := extcodesize(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D) + } + return hevmCodeSize > 0; } modifier logs_gas() { From 54d40a89cc5745afedba7428a082ca69ec82a6c3 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 6 Apr 2022 10:27:59 -0400 Subject: [PATCH 2/4] low-level call, failed slot --- src/test.sol | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/test.sol b/src/test.sol index a0a0cf9..de2d3e6 100644 --- a/src/test.sol +++ b/src/test.sol @@ -55,8 +55,13 @@ contract DSTest { } else { bool globalFailed = false; if (hasHEVMContext()) { - bytes32 slot = LimitedHEVM(HEVM_ADDRESS).load(HEVM_ADDRESS, 0); - globalFailed = slot == bytes32(uint256(0x01)); + (, bytes memory retdata) = HEVM_ADDRESS.call( + abi.encodePacked( + bytes4(keccak256("load(address,bytes32)")), + abi.encode(HEVM_ADDRESS, bytes32("failed")) + ) + ); + globalFailed = abi.decode(retdata, (bool)); } return globalFailed; } @@ -64,7 +69,13 @@ contract DSTest { function fail() internal { if (hasHEVMContext()) { - LimitedHEVM(HEVM_ADDRESS).store(HEVM_ADDRESS, 0, bytes32(uint256(0x01))); + HEVM_ADDRESS.call( + abi.encodePacked( + bytes4(keccak256("store(address,bytes32,bytes32)")), + abi.encode(HEVM_ADDRESS, bytes32("failed"), bytes32(uint256(0x01))) + ) + ); + } _failed = true; } From 35cf0b56569d825cfa1800ce3fd422df0eb1fce1 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 6 Apr 2022 10:28:40 -0400 Subject: [PATCH 3/4] no interface --- src/test.sol | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/test.sol b/src/test.sol index de2d3e6..4b4e7e8 100644 --- a/src/test.sol +++ b/src/test.sol @@ -15,11 +15,6 @@ pragma solidity >=0.4.23; -interface LimitedHEVM { - function load(address, bytes32) external returns (bytes32); - function store(address, bytes32, bytes32) external; -} - contract DSTest { event log (string); event logs (bytes); From 02ada4154ac007d0856afc8fe03c03afade6d267 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 6 Apr 2022 10:49:30 -0400 Subject: [PATCH 4/4] version bump :) --- src/test.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test.sol b/src/test.sol index 4b4e7e8..5f9dbe9 100644 --- a/src/test.sol +++ b/src/test.sol @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -pragma solidity >=0.4.23; +pragma solidity >=0.5.0; contract DSTest { event log (string);