From 4ff50611c9fcd0f306b529c647247af129d42d3f Mon Sep 17 00:00:00 2001 From: Rappie Date: Sat, 8 Jun 2024 18:19:17 +0200 Subject: [PATCH 1/3] Make VMs available as global constant singleton --- src/IHevm.sol | 5 ++++- src/IStdCheats.sol | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/IHevm.sol b/src/IHevm.sol index e0eba10..a3043ab 100644 --- a/src/IHevm.sol +++ b/src/IHevm.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -/// @author https://github.com/crytic/properties/blob/2526765eedd9bda30c168cd271fa403ac72cb1a9/contracts/util/Hevm.sol +import {Constants} from "./Constants.sol"; + interface IHevm { // Set block.timestamp to newTimestamp function warp(uint256 newTimestamp) external; @@ -51,3 +52,5 @@ interface IHevm { // Labels the address in traces function label(address addr, string calldata label) external; } + +IHevm constant hevm = IHevm(Constants.ADDRESS_CHEATS); diff --git a/src/IStdCheats.sol b/src/IStdCheats.sol index d1c1329..9c40dca 100644 --- a/src/IStdCheats.sol +++ b/src/IStdCheats.sol @@ -1,6 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; +import {Constants} from "./Constants.sol"; + // Available cheat codes for Medusa // Documentation: https://github.com/crytic/medusa/tree/dev/mdbook/docs/src/cheatcodes // Usage: https://github.com/crytic/medusa/blob/dev/mdbook/docs/src/cheatcodes_overview.md @@ -76,3 +78,5 @@ interface IStdCheats { function parseInt(string memory) external returns(int256); function parseBool(string memory) external returns(bool); } + +IStdCheats constant mvm = IStdCheats(Constants.ADDRESS_CHEATS); From b8a90ebe3e9b1135d6f766606ff03e1afc379f00 Mon Sep 17 00:00:00 2001 From: Rappie Date: Sat, 8 Jun 2024 18:20:08 +0200 Subject: [PATCH 2/3] Remove `HelperCheats` --- src/Fuzzlib.sol | 2 -- src/helpers/HelperCheats.sol | 27 --------------------------- 2 files changed, 29 deletions(-) delete mode 100644 src/helpers/HelperCheats.sol diff --git a/src/Fuzzlib.sol b/src/Fuzzlib.sol index 3362e79..1f91499 100644 --- a/src/Fuzzlib.sol +++ b/src/Fuzzlib.sol @@ -3,7 +3,6 @@ pragma solidity ^0.8.0; import {HelperBase} from "./helpers/HelperBase.sol"; import {HelperAssert} from "./helpers/HelperAssert.sol"; -import {HelperCheats} from "./helpers/HelperCheats.sol"; import {HelperClamp} from "./helpers/HelperClamp.sol"; import {HelperLog} from "./helpers/HelperLog.sol"; import {HelperMath} from "./helpers/HelperMath.sol"; @@ -12,7 +11,6 @@ import {HelperRandom} from "./helpers/HelperRandom.sol"; contract Fuzzlib is HelperBase, HelperAssert, - HelperCheats, HelperClamp, HelperLog, HelperMath, diff --git a/src/helpers/HelperCheats.sol b/src/helpers/HelperCheats.sol deleted file mode 100644 index 409395a..0000000 --- a/src/helpers/HelperCheats.sol +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import {IHevm} from "../IHevm.sol"; -import {IStdCheats} from "../IStdCheats.sol"; -import {Constants} from "../Constants.sol"; - -abstract contract HelperCheats { - IHevm internal vm = IHevm(Constants.ADDRESS_CHEATS); // echidna - IStdCheats internal mvm = IStdCheats(Constants.ADDRESS_CHEATS); // medusa - - function warp(uint256 timestamp) public { - vm.warp(timestamp); - } - - function roll(uint256 blockNumber) public { - vm.roll(blockNumber); - } - - function prank(address sender) public { - vm.prank(sender); - } - - function deal(address sender, uint amount) public { - vm.deal(sender, amount); - } -} From 3bd2c2471d7f41d4719959c44de3b3696acafca1 Mon Sep 17 00:00:00 2001 From: Rappie Date: Mon, 10 Jun 2024 17:26:58 +0200 Subject: [PATCH 3/3] Rename singleton VM's back to `vm` --- src/IHevm.sol | 2 +- src/IStdCheats.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IHevm.sol b/src/IHevm.sol index a3043ab..676723d 100644 --- a/src/IHevm.sol +++ b/src/IHevm.sol @@ -53,4 +53,4 @@ interface IHevm { function label(address addr, string calldata label) external; } -IHevm constant hevm = IHevm(Constants.ADDRESS_CHEATS); +IHevm constant vm = IHevm(Constants.ADDRESS_CHEATS); diff --git a/src/IStdCheats.sol b/src/IStdCheats.sol index 9c40dca..7187424 100644 --- a/src/IStdCheats.sol +++ b/src/IStdCheats.sol @@ -79,4 +79,4 @@ interface IStdCheats { function parseBool(string memory) external returns(bool); } -IStdCheats constant mvm = IStdCheats(Constants.ADDRESS_CHEATS); +IStdCheats constant vm = IStdCheats(Constants.ADDRESS_CHEATS);