Home

Awesome

ERC4626 Property Tests

Foundry (dapptools-style) property-based tests for ERC4626 standard conformance.

You can read our post on "Generalized property tests for ERC4626 vaults."

Overview

What is it?

What isn’t it?

Testing properties:

Usage

Step 0: Install foundry and add forge-std in your vault repo:

$ curl -L https://foundry.paradigm.xyz | bash

$ cd /path/to/your-erc4626-vault
$ forge install foundry-rs/forge-std

Step 1: Add this erc4626-tests as a dependency to your vault:

$ cd /path/to/your-erc4626-vault
$ forge install a16z/erc4626-tests

Step 2: Extend the abstract test contract ERC4626Test with your own custom vault setup method, for example:

// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.0 <0.9.0;

import "erc4626-tests/ERC4626.test.sol";

import { ERC20Mock   } from "/path/to/mocks/ERC20Mock.sol";
import { ERC4626Mock } from "/path/to/mocks/ERC4626Mock.sol";

contract ERC4626StdTest is ERC4626Test {
    function setUp() public override {
        _underlying_ = address(new ERC20Mock("Mock ERC20", "MERC20", 18));
        _vault_ = address(new ERC4626Mock(ERC20Mock(__underlying__), "Mock ERC4626", "MERC4626"));
        _delta_ = 0;
        _vaultMayBeEmpty = false;
        _unlimitedAmount = false;
    }
}

Specifically, set the state variables as follows:

Step 3: Run forge test

$ forge test

Examples

Below are examples of adding these property tests to existing ERC4626 vaults:

Disclaimer

These smart contracts are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the user interface or the smart contracts. They have not been audited and as such there can be no assurance they will work as intended, and users may experience delays, failures, errors, omissions or loss of transmitted information. THE SMART CONTRACTS CONTAINED HEREIN ARE FURNISHED AS IS, WHERE IS, WITH ALL FAULTS AND WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, NON-INFRINGEMENT OR FITNESS FOR ANY PARTICULAR PURPOSE. Further, use of any of these smart contracts may be restricted or prohibited under applicable law, including securities laws, and it is therefore strongly advised for you to contact a reputable attorney in any jurisdiction where these smart contracts may be accessible for any questions or concerns with respect thereto. Further, no information provided in this repo should be construed as investment advice or legal advice for any particular facts or circumstances, and is not meant to replace competent counsel. a16z is not liable for any use of the foregoing, and users should proceed with caution and use at their own risk. See a16z.com/disclosures for more info.

Footnotes

  1. That is, the deposit() and redeem() functions “MUST return the same or more amounts as their preview function if called in the same transaction.”

  2. That is, the mint() and withdraw() functions “MUST return the same or fewer amounts as their preview function if called in the same transaction.”

  3. Our property tests indeed revealed an issue in their eToken testing mock contract. The tests passed after it is fixed.