Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(certora): add sumOfBalancesIsTotalStaked invariant #42

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
with: { java-version: "11", java-package: jre }

- name: Install Certora CLI
run: pip3 install certora-cli==5.0.5
run: pip3 install certora-cli==7.17.2

- name: Install Solidity
run: |
Expand Down
10 changes: 8 additions & 2 deletions certora/confs/RewardsStreamerMP.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"files": ["src/RewardsStreamerMP.sol"],
"files": [
"src/RewardsStreamerMP.sol",
"certora/helpers/ERC20A.sol"
],
"link" : [
"RewardsStreamerMP:STAKING_TOKEN=ERC20A",
"RewardsStreamerMP:REWARD_TOKEN=ERC20A"
],
"msg": "Verifying RewardsStreamerMP.sol",
"rule_sanity": "basic",
"verify": "RewardsStreamerMP:certora/specs/RewardsStreamerMP.spec",
"wait_for_results": "all",
"optimistic_loop": true,
"loop_iter": "3",
"packages": [
Expand Down
10 changes: 10 additions & 0 deletions certora/helpers/ERC20A.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.26;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract ERC20A is ERC20 {
constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {}
}

17 changes: 15 additions & 2 deletions certora/specs/RewardsStreamerMP.spec
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
rule test {
assert true;
using ERC20A as staked;

methods {
function totalStaked() external returns (uint256) envfree;
}

ghost mathint sumOfBalances {
init_state axiom sumOfBalances == 0;
}

hook Sstore users[KEY address account].stakedBalance uint256 newValue (uint256 oldValue) {
sumOfBalances = sumOfBalances - oldValue + newValue;
}

invariant sumOfBalancesIsTotalStaked()
sumOfBalances == to_mathint(totalStaked());
Loading