Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ripfuzz Standard Library

Standard library for writing ripfuzz harnesses.

Please refer to the list of currently available cheatcodes. More cheatcodes will be added as ripfuzz grows support.

Installation

To install using Foundry:

forge install pyk/ripfuzz-std

Alternatively, you can directly add it as a submodule:

git submodule add https://github.com/pyk/ripfuzz-std

Example usage

// import ripfuzz-std
import {Harness} from "ripfuzz/Harness.sol";

contract Counter {
    uint256 public count;
    address public owner;

    constructor() {
        owner = msg.sender;
    }

    function increment() external {
        require(msg.sender == owner, "not owner");
        count += 1;
    }

    function add(uint256 x) external {
        require(msg.sender == owner, "not owner");
        count += x;
    }
}

contract CounterHarness is Harness {
    Counter counter;
    address user;

    function setup() external {
        user = createAddress("user");
        rvm.deal(user, 100 ether);

        // Deploy as `user` so that user owns the counter.
        rvm.prank(user);
        counter = new Counter();
    }

    function increment() external {
        rvm.prank(user);
        counter.increment();
    }

    function add(uint256 x) external {
        x = bound(x, 1, 100);
        rvm.prank(user);
        counter.add(x);
    }

    function invariant_OwnerIsUser() external {
        eq(counter.owner(), user, "owner is user");
    }

    function invariant_CountStaysBounded() external {
        ensure(counter.count() < 1_000_000, "count stayed below 1_000_000");
    }
}

Run the harness with ripfuzz:

ripfuzz run CounterHarness

License

MIT

About

Ripfuzz Standard Library

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages