Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ece50eb
add setup and rules about modules
teryanarmen Feb 10, 2023
2a99238
fix run script
teryanarmen Feb 10, 2023
6142597
use solc7.6 for fv
mmv08 Mar 31, 2023
2ce4faa
Merge branch 'main' of github.com:safe-global/safe-contracts into for…
mmv08 Mar 31, 2023
78fdf78
Mark assembly blocks as memory-safe
mmv08 Apr 6, 2023
c55691a
use solidity 0.8.19 for github action benchmark
mmv08 Apr 6, 2023
4d2284c
Update makefile
mmv08 Apr 11, 2023
2253f7e
fix the harness patch
mmv08 Apr 11, 2023
dc0cbf9
properties doc skeleton
mmv08 Apr 12, 2023
2524f74
properties notes
mmv08 Apr 20, 2023
6b03373
Merge branch 'main' of github.com:safe-global/safe-contracts into fea…
mmv08 Apr 27, 2023
ac6c56b
use 10m optimizer runs
mmv08 Apr 27, 2023
3ae2bde
Write calldata/return data to the memory allocated via the free memor…
mmv08 May 2, 2023
0c98fc0
memory-safe simulateAndRevert
mmv08 May 2, 2023
67d05a6
Merge branch 'main' of github.com:safe-global/safe-contracts into for…
mmv08 May 3, 2023
7a77545
Update CLA github action to v2.3.0
Uxio0 May 8, 2023
e8e9241
add certora workflow
mmv08 May 9, 2023
ed32c96
Fix changelog mention of createChainSpecificProxyWithNonce
frangio May 11, 2023
4b9c46f
Merge pull request #561 from frangio/changelog-fix
mmv08 May 11, 2023
1c29d23
fix script path
mmv08 May 10, 2023
c8932d4
use cvl2
mmv08 May 15, 2023
ad9b319
Merge pull request #560 from safe-global/formal-verification
mmv08 May 16, 2023
11e3459
Merge branch 'main' of github.com:safe-global/safe-contracts into fea…
mmv08 May 16, 2023
f8bd215
Remove gasleft in setupModules, add erc4337 compatibility test
mmv08 May 19, 2023
f77dfce
Fix typechecking in test files (#573)
mmv08 May 30, 2023
9cbdaa6
verify that guard can only be updated through setGuard
mmv08 May 17, 2023
1b25deb
Verify functions that may change the fallback handler address (#566)
mmv08 May 31, 2023
f37e0ed
Add an invariant for singleton address (#565)
mmv08 May 31, 2023
80ced58
Add an optimistic assumption about DELEGATECALL, update nonce monoton…
mmv08 May 31, 2023
13a5d89
Pump version to 1.4.1 (#579)
mmv08 May 31, 2023
36a07fe
Formal verification: native token balance updates (#582)
mmv08 Jun 15, 2023
1ed486b
Fix addresses for 1.4.1 in changelog (#590)
rmeissner Jun 15, 2023
7e46388
Fix certora CI action
mmv08 Jun 15, 2023
eec5ebc
Merge pull request #591 from safe-global/fix/certora-ci
mmv08 Jun 16, 2023
bf943f8
Formal verification: No message can be signed through the core contra…
mmv08 Jun 16, 2023
930478f
Merge branch 'main' of github.com:safe-global/safe-contracts into fea…
Jun 22, 2023
1a0d70c
fix munged patch
Jun 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add setup and rules about modules
  • Loading branch information
teryanarmen committed Feb 10, 2023
commit ece50eb9ac05854e807f5164dd2b42a3af1e5735
1 change: 1 addition & 0 deletions certora/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
munged
25 changes: 25 additions & 0 deletions certora/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
default: help

PATCH = applyHarness.patch
CONTRACTS_DIR = ../contracts
MUNGED_DIR = munged

help:
@echo "usage:"
@echo " make clean: remove all generated files (those ignored by git)"
@echo " make $(MUNGED_DIR): create $(MUNGED_DIR) directory by applying the patch file to $(CONTRACTS_DIR)"
@echo " make record: record a new patch file capturing the differences between $(CONTRACTS_DIR) and $(MUNGED_DIR)"

munged: $(wildcard $(CONTRACTS_DIR)/*.sol) $(PATCH)
rm -rf $@
cp -r $(CONTRACTS_DIR) $@
patch -p0 -d $@ < $(PATCH)

record:
diff -druN $(CONTRACTS_DIR) $(MUNGED_DIR) | sed 's+../contracts/++g' | sed 's+munged/++g' > $(PATCH)

refresh: munged record

clean:
git clean -fdX
touch $(PATCH)
24 changes: 24 additions & 0 deletions certora/applyHarness.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff -druN Safe.sol Safe.sol
--- Safe.sol 2023-02-08 21:35:44
+++ Safe.sol 2023-02-09 12:55:35
@@ -60,7 +60,7 @@
// By setting the threshold it is not possible to call setup anymore,
// so we create a Safe with 0 owners and threshold 1.
// This is an unusable Safe, perfect for the singleton
- threshold = 1;
+ // threshold = 1; // MUNGED: remove and add to constructor of the harness
}

/// @dev Setup function sets initial storage of contract.
diff -druN base/Executor.sol base/Executor.sol
--- base/Executor.sol 2023-01-31 17:25:15
+++ base/Executor.sol 2023-02-09 13:44:38
@@ -18,6 +18,8 @@
Enum.Operation operation,
uint256 txGas
) internal returns (bool success) {
+ // MUNGED lets just be a bit more optimistic, `execute` does nothing and always returns true
+ return true;
if (operation == Enum.Operation.DelegateCall) {
// solhint-disable-next-line no-inline-assembly
assembly {
22 changes: 22 additions & 0 deletions certora/harnesses/SafeHarness.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: LGPL-3.0-only
import "../munged/Safe.sol";

contract SafeHarness is Safe {

constructor(address[] memory _owners,
uint256 _threshold,
address to,
bytes memory data,
address fallbackHandler,
address paymentToken,
uint256 payment,
address payable paymentReceiver
) {
this.setup(_owners, _threshold, to, data, fallbackHandler, paymentToken, payment, paymentReceiver);
}

// harnessed getters
function getModule(address module) public view returns (address) {
return modules[module];
}
}
12 changes: 12 additions & 0 deletions certora/scripts/base/verifySafe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
solc-select use 0.8.9

certoraRun certora/harnesses/SafeHarness.sol ComplexityCheck/DummyERC20A.sol ComplexityCheck/DummyERC20B.sol \
--verify SafeHarness:certora/specs/Safe.spec \
--staging master \
--optimistic_loop \
--settings -optimisticFallback=true \
--loop_iter 3 \
--optimistic_hashing \
--rule_sanity \
--send_only \
--msg "Safe $1 "
79 changes: 79 additions & 0 deletions certora/specs/Safe.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
methods {
//
getThreshold() returns (uint256) envfree
disableModule(address,address)
nonce() returns (uint256) envfree

// harnessed
getModule(address) returns (address) envfree
}

definition noHavoc(method f) returns bool =
f.selector != execTransactionFromModuleReturnData(address,uint256,bytes,uint8).selector
&& f.selector != execTransactionFromModule(address,uint256,bytes,uint8).selector
&& f.selector != execTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes).selector;

definition reachableOnly(method f) returns bool =
f.selector != setup(address[],uint256,address,bytes,address,address,uint256,address).selector
&& f.selector != simulateAndRevert(address,bytes).selector;

/// Nonce must never decrease
rule nonceMonotonicity(method f) filtered {
f -> noHavoc(f)
} {
uint256 nonceBefore = nonce();

calldataarg args; env e;
f(e, args);

uint256 nonceAfter = nonce();

assert nonceAfter == nonceBefore || nonceAfter == nonceBefore + 1;
}


/// The sentinel must never point to the zero address.
/// @notice It should either point to itself or some nonzero value
invariant liveSentinel()
getModule(1) != 0
filtered { f -> noHavoc(f) && reachableOnly(f) }
{ preserved {
requireInvariant noDeadEnds(getModule(1), 1);
}}

/// Threshold must always be nonzero.
invariant nonzeroThreshold()
getThreshold() > 0
filtered { f -> noHavoc(f) && reachableOnly(f) }

/// Two different modules must not point to the same module/
invariant uniquePrevs(address prev1, address prev2)
prev1 != prev2 && getModule(prev1) != 0 => getModule(prev1) != getModule(prev2)
filtered { f -> noHavoc(f) && reachableOnly(f) }
{
preserved {
requireInvariant noDeadEnds(getModule(prev1), prev1);
requireInvariant noDeadEnds(getModule(prev2), prev2);
requireInvariant uniquePrevs(prev1, 1);
requireInvariant uniquePrevs(prev2, 1);
requireInvariant uniquePrevs(prev1, getModule(prev2));
requireInvariant uniquePrevs(prev2, getModule(prev1));
}
}

/// A module that points to the zero address must not have another module pointing to it.
invariant noDeadEnds(address dead, address lost)
dead != 0 && getModule(dead) == 0 => getModule(lost) != dead
filtered { f -> noHavoc(f) && reachableOnly(f) }
{
preserved {
requireInvariant liveSentinel();
requireInvariant noDeadEnds(getModule(1), 1);
}
preserved disableModule(address prevModule, address module) with (env e) {
requireInvariant uniquePrevs(prevModule, lost);
requireInvariant uniquePrevs(prevModule, dead);
requireInvariant noDeadEnds(dead, module);
requireInvariant noDeadEnds(module, dead);
}
}
29 changes: 29 additions & 0 deletions certora/specs/properties.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

only permissioned address can do permissioned activities.
who can swap owner?
who should be able to?


who should be allowed to make contract do delegate calls?
contract creator
address specified by contract creator

setup only be done once

check signature validation?
can't sign a signature that isn't yours...
not really something we can prove

module states
enabled
cancelled
always circular
checkNSignatures same as checkSignature N times

properties about approved hashes
who can approve hashes?
Can hashes do more than one thing?

getStorageAt gets storage at

execTransactionFromModuleReturnData