Skip to content

Commit

Permalink
Merge pull request #136 from morpho-org/certora/dev
Browse files Browse the repository at this point in the history
[Certora] Dev
  • Loading branch information
MathisGD authored Dec 1, 2023
2 parents 9f4fc70 + c265b46 commit 4f50a27
Show file tree
Hide file tree
Showing 34 changed files with 2,752 additions and 1 deletion.
51 changes: 51 additions & 0 deletions .github/workflows/certora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Certora

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
verify:
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
conf:
- AccrueInterest
- ConsistentState
- ExactMath
- ExitLiquidity
- Health
- LibSummary
- Liveness
- RatioMath
- Reentrancy
- Reverts
- Transfer

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install python
uses: actions/setup-python@v4

- name: Install certora
run: pip install certora-cli

- name: Install solc
run: |
wget https://github.com/ethereum/solidity/releases/download/v0.8.19/solc-static-linux
chmod +x solc-static-linux
sudo mv solc-static-linux /usr/local/bin/solc
- name: Verify ${{ matrix.conf }}
run: certoraRun certora/confs/${{ matrix.conf }}.conf
env:
CERTORAKEY: ${{ secrets.CERTORAKEY }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ docs/
# Node modules
/node_modules

# Certora
.certora**
emv-*-certora*

# Hardhat
/types
/cache_hardhat
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ All audits are stored in the [audits](./audits/)' folder.
## Licences

The primary license for Morpho Blue is the Business Source License 1.1 (`BUSL-1.1`), see [`LICENSE`](./LICENSE).
However, all files in the following folders can also be licensed under `GPL-2.0-or-later` (as indicated in their SPDX headers): [`src/interfaces`](./src/interfaces), [`src/libraries`](./src/libraries), [`src/mocks`](./src/mocks), [`test`](./test).
However, all files in the following folders can also be licensed under `GPL-2.0-or-later` (as indicated in their SPDX headers): [`src/interfaces`](./src/interfaces), [`src/libraries`](./src/libraries), [`src/mocks`](./src/mocks), [`test`](./test), [`certora`](./certora).
389 changes: 389 additions & 0 deletions certora/LICENSE

Large diffs are not rendered by default.

286 changes: 286 additions & 0 deletions certora/README.md

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions certora/confs/AccrueInterest.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
],
"verify": "MorphoHarness:certora/specs/AccrueInterest.spec",
"prover_args": [
"-smt_hashingScheme plaininjectivity",
"-mediumTimeout 30"
],
"rule_sanity": "basic",
"msg": "Morpho Blue Accrue Interest"
}
8 changes: 8 additions & 0 deletions certora/confs/ConsistentState.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
],
"verify": "MorphoHarness:certora/specs/ConsistentState.spec",
"rule_sanity": "basic",
"msg": "Morpho Blue Consistent State"
}
12 changes: 12 additions & 0 deletions certora/confs/ExactMath.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
],
"verify": "MorphoHarness:certora/specs/ExactMath.spec",
"rule_sanity": "basic",
"prover_args": [
"-smt_hashingScheme plaininjectivity",
"-mediumTimeout 30"
],
"msg": "Morpho Blue Exact Math"
}
8 changes: 8 additions & 0 deletions certora/confs/ExitLiquidity.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
],
"verify": "MorphoHarness:certora/specs/ExitLiquidity.spec",
"rule_sanity": "basic",
"msg": "Morpho Blue Exit Liquidity"
}
12 changes: 12 additions & 0 deletions certora/confs/Health.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files": [
"certora/harness/MorphoHarness.sol",
"src/mocks/OracleMock.sol"
],
"verify": "MorphoHarness:certora/specs/Health.spec",
"rule_sanity": "basic",
"prover_args": [
"-smt_hashingScheme plaininjectivity"
],
"msg": "Morpho Blue Health"
}
8 changes: 8 additions & 0 deletions certora/confs/LibSummary.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
],
"verify": "MorphoHarness:certora/specs/LibSummary.spec",
"rule_sanity": "basic",
"msg": "Morpho Blue Lib Summary"
}
8 changes: 8 additions & 0 deletions certora/confs/Liveness.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files": [
"certora/harness/MorphoInternalAccess.sol"
],
"verify": "MorphoInternalAccess:certora/specs/Liveness.spec",
"rule_sanity": "basic",
"msg": "Morpho Blue Liveness"
}
13 changes: 13 additions & 0 deletions certora/confs/RatioMath.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
],
"verify": "MorphoHarness:certora/specs/RatioMath.spec",
"rule_sanity": "basic",
"prover_args": [
"-smt_hashingScheme plaininjectivity",
"-mediumTimeout 30",
"-timeout 3600"
],
"msg": "Morpho Blue Ratio Math"
}
11 changes: 11 additions & 0 deletions certora/confs/Reentrancy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
],
"verify": "MorphoHarness:certora/specs/Reentrancy.spec",
"rule_sanity": "basic",
"prover_args": [
"-enableStorageSplitting false"
],
"msg": "Morpho Blue Reentrancy"
}
8 changes: 8 additions & 0 deletions certora/confs/Reverts.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
],
"verify": "MorphoHarness:certora/specs/Reverts.spec",
"rule_sanity": "basic",
"msg": "Morpho Blue Reverts"
}
11 changes: 11 additions & 0 deletions certora/confs/Transfer.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files": [
"certora/harness/TransferHarness.sol",
"certora/dispatch/ERC20Standard.sol",
"certora/dispatch/ERC20USDT.sol",
"certora/dispatch/ERC20NoRevert.sol"
],
"verify": "TransferHarness:certora/specs/Transfer.spec",
"rule_sanity": "basic",
"msg": "Morpho Blue Transfer"
}
48 changes: 48 additions & 0 deletions certora/dispatch/ERC20NoRevert.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

contract ERC20NoRevert {
address public owner;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;

constructor() {
owner = msg.sender;
}

modifier onlyOwner() {
require(msg.sender == owner);
_;
}

function _transfer(address _from, address _to, uint256 _amount) internal returns (bool) {
if (balanceOf[_from] < _amount) {
return false;
}
balanceOf[_from] -= _amount;
balanceOf[_to] += _amount;
return true;
}

function transfer(address _to, uint256 _amount) public returns (bool) {
return _transfer(msg.sender, _to, _amount);
}

function transferFrom(address _from, address _to, uint256 _amount) public returns (bool) {
if (allowance[_from][msg.sender] < _amount) {
return false;
}
allowance[_from][msg.sender] -= _amount;
return _transfer(_from, _to, _amount);
}

function approve(address _spender, uint256 _amount) public {
allowance[msg.sender][_spender] = _amount;
}

function mint(address _receiver, uint256 _amount) public onlyOwner {
balanceOf[_receiver] += _amount;
totalSupply += _amount;
}
}
42 changes: 42 additions & 0 deletions certora/dispatch/ERC20Standard.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

contract ERC20Standard {
address public owner;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;

constructor() {
owner = msg.sender;
}

modifier onlyOwner() {
require(msg.sender == owner);
_;
}

function _transfer(address _from, address _to, uint256 _amount) internal returns (bool) {
balanceOf[_from] -= _amount;
balanceOf[_to] += _amount;
return true;
}

function transfer(address _to, uint256 _amount) public returns (bool) {
return _transfer(msg.sender, _to, _amount);
}

function transferFrom(address _from, address _to, uint256 _amount) public returns (bool) {
allowance[_from][msg.sender] -= _amount;
return _transfer(_from, _to, _amount);
}

function approve(address _spender, uint256 _amount) public {
allowance[msg.sender][_spender] = _amount;
}

function mint(address _receiver, uint256 _amount) public onlyOwner {
balanceOf[_receiver] += _amount;
totalSupply += _amount;
}
}
45 changes: 45 additions & 0 deletions certora/dispatch/ERC20USDT.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

contract ERC20USDT {
address public owner;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;

constructor() {
owner = msg.sender;
}

modifier onlyOwner() {
require(msg.sender == owner);
_;
}

function _transfer(address _from, address _to, uint256 _amount) internal {
balanceOf[_from] -= _amount;
balanceOf[_to] += _amount;
}

function transfer(address _to, uint256 _amount) public {
_transfer(msg.sender, _to, _amount);
}

function transferFrom(address _from, address _to, uint256 _amount) public {
if (allowance[_from][msg.sender] < type(uint256).max) {
allowance[_from][msg.sender] -= _amount;
}
_transfer(_from, _to, _amount);
}

function approve(address _spender, uint256 _amount) public {
require(!((_amount != 0) && (allowance[msg.sender][_spender] != 0)));

allowance[msg.sender][_spender] = _amount;
}

function mint(address _receiver, uint256 _amount) public onlyOwner {
balanceOf[_receiver] += _amount;
totalSupply += _amount;
}
}
6 changes: 6 additions & 0 deletions certora/gambit.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"filename" : "../src/Morpho.sol",
"sourceroot": "..",
"num_mutants": 15,
"solc_remappings": []
}
Loading

0 comments on commit 4f50a27

Please sign in to comment.