Skip to content

Commit

Permalink
Merge pull request #718 from safe-global/optimizer-enabled-with-origi…
Browse files Browse the repository at this point in the history
…nal-solc

Reverting back to 0.7.6
  • Loading branch information
remedcu authored Dec 21, 2023
2 parents 24d5abe + 5c23638 commit f715936
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 50 deletions.
5 changes: 4 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ ERC4337_TEST_NODE_URL=
ERC4337_TEST_SINGLETON_ADDRESS=
ERC4337_TEST_SAFE_FACTORY_ADDRESS=
# (Optional) Tells the test runner which Safe Singleton Contract to use for testing: Safe or SafeL2. Defaults to Safe.
SAFE_CONTRACT_UNDER_TEST="Safe"
SAFE_CONTRACT_UNDER_TEST="Safe"
# Used for compiling with different solidity testing
SOLIDITY_VERSION= # Example: "0.8.19"
SOLIDITY_SETTINGS= # Example: '{"viaIR":true,"optimizer":{"enabled":true, "details": {"yul": true}}}'
16 changes: 8 additions & 8 deletions certora/applyHarness.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
diff -druN Safe.sol Safe.sol
--- Safe.sol 2023-12-05 16:23:27
+++ Safe.sol 2023-12-05 21:15:44
--- Safe.sol 2023-12-06 16:00:31
+++ Safe.sol 2023-12-07 00:01:59
@@ -76,7 +76,7 @@
* so we create a Safe with 0 owners and threshold 1.
* This is an unusable Safe, perfect for the singleton
Expand Down Expand Up @@ -42,12 +42,12 @@ diff -druN Safe.sol Safe.sol
}
}
diff -druN base/Executor.sol base/Executor.sol
--- base/Executor.sol 2023-12-05 16:20:21
+++ base/Executor.sol 2023-12-05 21:16:46
--- base/Executor.sol 2023-12-06 16:00:31
+++ base/Executor.sol 2023-12-07 00:01:59
@@ -29,8 +29,10 @@
/* solhint-disable no-inline-assembly */
/// @solidity memory-safe-assembly
assembly ("memory-safe") {
assembly {
- success := delegatecall(txGas, to, add(data, 0x20), mload(data), 0, 0)
+ // success := delegatecall(txGas, to, add(data, 0x20), mload(data), 0, 0)
+ // MUNGED: lets be optimistic and assume execute does nothing for DELEGATECALL
Expand All @@ -58,7 +58,7 @@ diff -druN base/Executor.sol base/Executor.sol
/* solhint-disable no-inline-assembly */
diff -druN base/Executor.sol.orig base/Executor.sol.orig
--- base/Executor.sol.orig 1970-01-01 05:30:00
+++ base/Executor.sol.orig 2023-12-05 21:15:44
+++ base/Executor.sol.orig 2023-12-07 00:01:59
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: LGPL-3.0-only
+pragma solidity >=0.7.0 <0.9.0;
Expand Down Expand Up @@ -90,7 +90,7 @@ diff -druN base/Executor.sol.orig base/Executor.sol.orig
+ if (operation == Enum.Operation.DelegateCall) {
+ /* solhint-disable no-inline-assembly */
+ /// @solidity memory-safe-assembly
+ assembly ("memory-safe") {
+ assembly {
+ success := delegatecall(txGas, to, add(data, 0x20), mload(data), 0, 0)
+ }
+ /* solhint-enable no-inline-assembly */
Expand All @@ -106,7 +106,7 @@ diff -druN base/Executor.sol.orig base/Executor.sol.orig
+}
diff -druN base/Executor.sol.rej base/Executor.sol.rej
--- base/Executor.sol.rej 1970-01-01 05:30:00
+++ base/Executor.sol.rej 2023-12-05 21:15:44
+++ base/Executor.sol.rej 2023-12-07 00:01:59
@@ -0,0 +1,15 @@
+@@ -26,12 +26,8 @@
+ uint256 txGas
Expand Down
2 changes: 1 addition & 1 deletion certora/conf/module.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"prover_args": [
" -smt_groundQuantifiers false"
],
"solc": "solc8.19",
"solc": "solc7.6",
"verify": "SafeHarness:certora/specs/ModuleReach.spec"
}
2 changes: 1 addition & 1 deletion certora/conf/nativeTokenRefund.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
" -optimisticFallback true -mediumTimeout 30"
],
"rule_sanity": "basic",
"solc": "solc8.19",
"solc": "solc7.6",
"verify": "SafeHarness:certora/specs/NativeTokenRefund.spec"
}
2 changes: 1 addition & 1 deletion certora/conf/owner.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"prover_args": [
"-smt_groundQuantifiers false -mediumTimeout 2000"
],
"solc": "solc8.19",
"solc": "solc7.6",
"verify": "SafeHarness:certora/specs/OwnerReach.spec"
}
2 changes: 1 addition & 1 deletion certora/conf/run.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"rule_sanity": "basic",
"run_source": "MUTATION",
"send_only": true,
"solc": "solc8.19",
"solc": "solc7.6",
"verify": "SafeHarness:certora/specs/Safe.spec"
}
2 changes: 1 addition & 1 deletion certora/conf/safe.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
" -optimisticFallback true -s z3 -copyLoopUnroll 5 -mediumTimeout 5 -depth 30"
],
"rule_sanity": "basic",
"solc": "solc8.19",
"solc": "solc7.6",
"verify": "SafeHarness:certora/specs/Safe.spec"
}
2 changes: 1 addition & 1 deletion certora/conf/signatures.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"-optimisticFallback true -mediumTimeout 30"
],
"rule_sanity": "basic",
"solc": "solc8.19",
"solc": "solc7.6",
"verify": "SafeHarness:certora/specs/Signatures.spec"
}
2 changes: 1 addition & 1 deletion certora/scripts/verifyNativeTokenRefund.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fi

certoraRun certora/harnesses/SafeHarness.sol \
--verify SafeHarness:certora/specs/NativeTokenRefund.spec \
--solc solc8.19 \
--solc solc7.6 \
--optimistic_loop \
--prover_args '-optimisticFallback true -s z3' \
--loop_iter 3 \
Expand Down
4 changes: 2 additions & 2 deletions contracts/Safe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ contract Safe is
uint256 contractSignatureLen;
/* solhint-disable no-inline-assembly */
/// @solidity memory-safe-assembly
assembly ("memory-safe") {
assembly {
contractSignatureLen := mload(add(add(signatures, offset), 0x20))
}
/* solhint-enable no-inline-assembly */
Expand All @@ -273,7 +273,7 @@ contract Safe is
bytes memory contractSignature;
/* solhint-disable no-inline-assembly */
/// @solidity memory-safe-assembly
assembly ("memory-safe") {
assembly {
// The signature data for contract signatures is appended to the concatenated signatures and the offset is stored in s
contractSignature := add(add(signatures, offset), 0x20)
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/base/Executor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract contract Executor {
if (operation == Enum.Operation.DelegateCall) {
/* solhint-disable no-inline-assembly */
/// @solidity memory-safe-assembly
assembly ("memory-safe") {
assembly {
success := delegatecall(txGas, to, add(data, 0x20), mload(data), 0, 0)
}
/* solhint-enable no-inline-assembly */
Expand Down
2 changes: 1 addition & 1 deletion contracts/base/FallbackManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract contract FallbackManager is SelfAuthorized {
bytes32 slot = FALLBACK_HANDLER_STORAGE_SLOT;
/* solhint-disable no-inline-assembly */
/// @solidity memory-safe-assembly
assembly ("memory-safe") {
assembly {
sstore(slot, handler)
}
/* solhint-enable no-inline-assembly */
Expand Down
2 changes: 1 addition & 1 deletion contracts/base/ModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ abstract contract ModuleManager is SelfAuthorized, Executor, GuardManager {
// Set correct size of returned array
/* solhint-disable no-inline-assembly */
/// @solidity memory-safe-assembly
assembly ("memory-safe") {
assembly {
mstore(array, moduleCount)
}
/* solhint-enable no-inline-assembly */
Expand Down
2 changes: 1 addition & 1 deletion contracts/common/SecuredTokenTransfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract contract SecuredTokenTransfer {
bytes memory data = abi.encodeWithSelector(0xa9059cbb, receiver, amount);
/* solhint-disable no-inline-assembly */
/// @solidity memory-safe-assembly
assembly ("memory-safe") {
assembly {
// We write the return value to scratch space.
// See https://docs.soliditylang.org/en/v0.7.6/internals/layout_in_memory.html#layout-in-memory
let success := call(sub(gas(), 10000), token, 0, add(data, 0x20), mload(data), 0, 0x20)
Expand Down
2 changes: 1 addition & 1 deletion contracts/common/SignatureDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract contract SignatureDecoder {
function signatureSplit(bytes memory signatures, uint256 pos) internal pure returns (uint8 v, bytes32 r, bytes32 s) {
/* solhint-disable no-inline-assembly */
/// @solidity memory-safe-assembly
assembly ("memory-safe") {
assembly {
let signaturePos := mul(0x41, pos)
r := mload(add(signatures, add(signaturePos, 0x20)))
s := mload(add(signatures, add(signaturePos, 0x40)))
Expand Down
4 changes: 2 additions & 2 deletions contracts/common/StorageAccessible.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract contract StorageAccessible {
for (uint256 index = 0; index < length; index++) {
/* solhint-disable no-inline-assembly */
/// @solidity memory-safe-assembly
assembly ("memory-safe") {
assembly {
let word := sload(add(offset, index))
mstore(add(add(result, 0x20), mul(index, 0x20)), word)
}
Expand All @@ -42,7 +42,7 @@ abstract contract StorageAccessible {
function simulateAndRevert(address targetContract, bytes memory calldataPayload) external {
/* solhint-disable no-inline-assembly */
/// @solidity memory-safe-assembly
assembly ("memory-safe") {
assembly {
let success := delegatecall(gas(), targetContract, add(calldataPayload, 0x20), mload(calldataPayload), 0, 0)
// Load free memory location
let ptr := mload(0x40)
Expand Down
13 changes: 3 additions & 10 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ import "./src/tasks/show_codesize";
import { BigNumber } from "@ethersproject/bignumber";
import { DeterministicDeploymentInfo } from "hardhat-deploy/dist/types";

const primarySolidityVersion = SOLIDITY_VERSION || "0.8.19";
const soliditySettings = SOLIDITY_SETTINGS
? JSON.parse(SOLIDITY_SETTINGS)
: JSON.parse('{"viaIR":true,"optimizer":{"enabled":true, "details": {"yul": true}}}');
const primarySolidityVersion = SOLIDITY_VERSION || "0.7.6";
const soliditySettings = SOLIDITY_SETTINGS ? JSON.parse(SOLIDITY_SETTINGS) : undefined;

const deterministicDeployment = (network: string): DeterministicDeploymentInfo => {
const info = getSingletonFactoryInfo(parseInt(network));
Expand Down Expand Up @@ -72,12 +70,7 @@ const userConfig: HardhatUserConfig = {
target: "ethers-v6",
},
solidity: {
compilers: [
{ version: primarySolidityVersion, settings: soliditySettings },
{ version: "0.7.6" },
{ version: "0.6.12" },
{ version: "0.5.17" },
],
compilers: [{ version: primarySolidityVersion, settings: soliditySettings }, { version: "0.6.12" }, { version: "0.5.17" }],
},
networks: {
hardhat: {
Expand Down
53 changes: 40 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"husky": "^8.0.3",
"prettier": "^3.1.0",
"prettier-plugin-solidity": "^1.2.0",
"solc": "0.8.19",
"solc": "0.7.6",
"solhint": "^4.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.3.2",
Expand Down
2 changes: 1 addition & 1 deletion test/libraries/SignMessageLib.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("SignMessageLib", () => {
it("can be used only via DELEGATECALL opcode", async () => {
const { lib } = await setupTests();

await expect(lib.signMessage("0xbaddad")).to.be.rejectedWith("Transaction reverted without a reason string");
await expect(lib.signMessage("0xbaddad")).to.be.rejected;
});

it("changes the expected storage slot without touching the most important ones", async () => {
Expand Down

0 comments on commit f715936

Please sign in to comment.