Standard library for writing ripfuzz harnesses.
Please refer to the list of currently available cheatcodes. More cheatcodes will be added as ripfuzz grows support.
To install using Foundry:
forge install pyk/ripfuzz-stdAlternatively, you can directly add it as a submodule:
git submodule add https://github.com/pyk/ripfuzz-std// 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 CounterHarnessMIT