Skip to content

Commit

Permalink
add harness and marketplace totals rules
Browse files Browse the repository at this point in the history
  • Loading branch information
0xb337r007 committed Jun 6, 2024
1 parent 0211ea2 commit 9a342eb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
22 changes: 22 additions & 0 deletions certora/harness/MarketplaceHarness.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Marketplace} from "../../contracts/Marketplace.sol";
import {MarketplaceConfig} from "../../contracts/Configuration.sol";

contract MarketplaceHarness is Marketplace {
constructor(IERC20 token_, MarketplaceConfig memory configuration) Marketplace(token_, configuration) {}

function totalReceived() public view returns (uint256) {
return _marketplaceTotals.received;
}

function totalSent() public view returns (uint256) {
return _marketplaceTotals.sent;
}

function tokenBalance() public view returns (uint256) {
return token.balanceOf(address(this));
}
}
3 changes: 2 additions & 1 deletion certora/scripts/verify-marketplace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ fi

certoraRun \
contracts/Marketplace.sol \
--verify Marketplace:certora/specs/Marketplace.spec \
certora/harness/MarketplaceHarness.sol \
--verify MarketplaceHarness:certora/specs/Marketplace.spec \
--optimistic_loop \
--loop_iter 3 \
--rule_sanity "basic" \
Expand Down
34 changes: 32 additions & 2 deletions certora/specs/Marketplace.spec
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
rule test {
assert(true);
methods {
function totalReceived() external returns (uint) envfree;
function totalSent() external returns (uint) envfree;
function tokenBalance() external returns (uint) envfree;
}

rule sanity(env e, method f) {
calldataarg args;
f(e, args);
satisfy true;
}

rule totalReceivedCannotDecrease(env e, method f) {
mathint total_before = totalReceived();

calldataarg args;
f(e, args);

mathint total_after = totalReceived();

assert total_after >= total_before;
}

rule totalSentCannotDecrease(env e, method f) {
mathint total_before = totalSent();

calldataarg args;
f(e, args);

mathint total_after = totalSent();

assert total_after >= total_before;
}

0 comments on commit 9a342eb

Please sign in to comment.