Skip to content

Commit

Permalink
chore(certora): add sumOfBalancesIsTotalStaked invariant
Browse files Browse the repository at this point in the history
Closes #24
  • Loading branch information
0x-r4bbit committed Oct 14, 2024
1 parent 7452242 commit 4edba7e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
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());

0 comments on commit 4edba7e

Please sign in to comment.