Skip to content

Commit

Permalink
Merge pull request #461 from morpho-org/feat/certora
Browse files Browse the repository at this point in the history
Check non-view non-multicall functions are protected
  • Loading branch information
MathisGD authored Oct 31, 2024
2 parents 726c7c1 + 4040b02 commit 17025b3
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/certora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Certora

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

jobs:
verify:
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
conf:
- AaveV2MigrationBundlerV2
- AaveV3MigrationBundlerV2
- AaveV3OptimizerMigrationBundlerV2
- ChainAgnosticBundlerV2
- CompoundV2MigrationBundlerV2
- CompoundV3MigrationBundlerV2
- EthereumBundlerV2

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

- name: Install python
uses: actions/setup-python@v5
with:
python-version: ">=3.11"

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

- name: Install solc (0.8.24)
run: |
wget https://github.com/ethereum/solidity/releases/download/v0.8.24/solc-static-linux
chmod +x solc-static-linux
sudo mv solc-static-linux /usr/local/bin/solc-0.8.24
- name: Verify ${{ matrix.conf }} specification
run: certoraRun certora/confs/${{ matrix.conf }}.conf
env:
CERTORAKEY: ${{ secrets.CERTORAKEY }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ node_modules/
/artifacts

*.log

# Certora
.certora_internal
35 changes: 35 additions & 0 deletions certora/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Bundlers formal verification

This folder contains the [CVL](https://docs.certora.com/en/latest/docs/cvl/index.html) specification and verification setup for the following bundler contracts:

- [AaveV2MigrationBundlerV2](../src/migration/AaveV2MigrationBundlerV2.sol)
- [AaveV3MigrationBundlerV2](../src/migration/AaveV3MigrationBundlerV2.sol)
- [AaveV3OptimizerMigrationBundlerV2](../src/migration/AaveV3OptimizerMigrationBundlerV2.sol)
- [ChainAgnosticBundlerV2](../src/chain-agnostic/ChainAgnosticBundlerV2.sol)
- [CompoundV2MigrationBundlerV2](../src/migration/CompoundV2MigrationBundlerV2.sol)
- [CompoundV3MigrationBundlerV2](../src/migration/CompoundV3MigrationBundlerV2.sol)
- [EthereumBundlerV2](../src/ethereum/EthereumBundlerV2.sol)

## Getting started

To verify a specification, run the command `certoraRun Spec.conf` where `Spec.conf` is one of the configuration files in [`certora/confs`](confs).

You must have set the `CERTORAKEY` environment variable to a valid Certora key.

## Overview

Bundler methods used during a bundle execution have the `protected` modifier. This modifier ensures that:
- an initiator has been set;
- the caller is the bundle initiator or the Morpho contract.

The `Protected.spec` file checks that all bundler functions, except noted exceptions, respect the requirements of the `protected` modifier when an initiator has been set.

## Verification architecture

### Folders and file structure

The [`certora/specs`](specs) folder contains the following files:

- [`Protected.spec`](specs/Protected.spec) checks that all methods except noted exceptions respect the `protected` modifier when an initiator has been set.

The [`certora/confs`](confs) folder contains a configuration file for each deployed bundler.
10 changes: 10 additions & 0 deletions certora/confs/AaveV2MigrationBundlerV2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files": [
"src/migration/AaveV2MigrationBundlerV2.sol"
],
"solc": "solc-0.8.24",
"verify": "AaveV2MigrationBundlerV2:certora/specs/Protected.spec",
"rule_sanity": "basic",
"server": "production",
"msg": "Aave V2 Migration Bundler V2 protected functions"
}
10 changes: 10 additions & 0 deletions certora/confs/AaveV3MigrationBundlerV2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files": [
"src/migration/AaveV3MigrationBundlerV2.sol"
],
"solc": "solc-0.8.24",
"verify": "AaveV3MigrationBundlerV2:certora/specs/Protected.spec",
"rule_sanity": "basic",
"server": "production",
"msg": "Aave V3 Migration Bundler V2 protected functions"
}
10 changes: 10 additions & 0 deletions certora/confs/AaveV3OptimizerMigrationBundlerV2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files": [
"src/migration/AaveV3OptimizerMigrationBundlerV2.sol"
],
"solc": "solc-0.8.24",
"verify": "AaveV3OptimizerMigrationBundlerV2:certora/specs/Protected.spec",
"rule_sanity": "basic",
"server": "production",
"msg": "Aave V3 Optimizer Migration Bundler V2 protected functions"
}
10 changes: 10 additions & 0 deletions certora/confs/ChainAgnosticBundlerV2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files": [
"src/chain-agnostic/ChainAgnosticBundlerV2.sol"
],
"solc": "solc-0.8.24",
"verify": "ChainAgnosticBundlerV2:certora/specs/Protected.spec",
"rule_sanity": "basic",
"server": "production",
"msg": "Chain Agnostic Bundler V2 protected functions"
}
10 changes: 10 additions & 0 deletions certora/confs/CompoundV2MigrationBundlerV2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files": [
"src/migration/CompoundV2MigrationBundlerV2.sol"
],
"solc": "solc-0.8.24",
"verify": "CompoundV2MigrationBundlerV2:certora/specs/Protected.spec",
"rule_sanity": "basic",
"server": "production",
"msg": "Compound V2 Migration Bundler V2 protected functions"
}
10 changes: 10 additions & 0 deletions certora/confs/CompoundV3MigrationBundlerV2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files": [
"src/migration/CompoundV3MigrationBundlerV2.sol"
],
"solc": "solc-0.8.24",
"verify": "CompoundV3MigrationBundlerV2:certora/specs/Protected.spec",
"rule_sanity": "basic",
"server": "production",
"msg": "Compound V3 Migration Bundler V2 protected functions"
}
10 changes: 10 additions & 0 deletions certora/confs/EthereumBundlerV2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files": [
"src/ethereum/EthereumBundlerV2.sol"
],
"solc": "solc-0.8.24",
"verify": "EthereumBundlerV2:certora/specs/Protected.spec",
"rule_sanity": "basic",
"server": "production",
"msg": "Ethereum Bundler V2 protected functions"
}
19 changes: 19 additions & 0 deletions certora/specs/Protected.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-2.0-or-later

// Check that all methods except those noted below comply with the `protected` modifier when an initiator has been set.
rule protectedWithSetInitiator(method f, env e, calldataarg data) filtered {
// Do not check view functions.
f -> !f.isView &&
// Do not check the fallback function.
!f.isFallback &&
// Do not check multicall, which is used to start a new bundle.
f.selector != sig:multicall(bytes[]).selector
}
{
// Safe require because `protected` functions should be callable by the initiator.
require e.msg.sender != currentContract._initiator;
// Safe require because `protected` functions should be callable by Morpho.
require e.msg.sender != currentContract.MORPHO;
f@withrevert(e,data);
assert lastReverted;
}

0 comments on commit 17025b3

Please sign in to comment.