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

Gad/setup #18

Draft
wants to merge 29 commits into
base: staging-2.5-fork
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9b40087
Auction manager initial setup
GadElbazCertora Jul 25, 2024
711e083
Merge pull request #12 from Certora/staging-2.5-fork
GadElbazCertora Jul 25, 2024
f93dcfe
auctionManager new rules
GadElbazCertora Jul 25, 2024
6ca9193
add eeth and weeth
GadElbazCertora Jul 28, 2024
576f37d
update weeth spec
GadElbazCertora Jul 28, 2024
07577f9
update weeth
GadElbazCertora Jul 28, 2024
dddb740
.
GadElbazCertora Jul 28, 2024
d9cb4ed
Merge pull request #13 from etherfi-protocol/staging-2.5
GadElbazCertora Jul 31, 2024
fcbef39
update setups - stakingManager
GadElbazCertora Aug 4, 2024
45a5491
update rules
GadElbazCertora Aug 11, 2024
92a2ad7
Merge pull request #17 from Certora/staging-2.5-fork
GadElbazCertora Aug 11, 2024
9cb729b
align spec with new code
GadElbazCertora Aug 11, 2024
c0fece6
update nfts rules
GadElbazCertora Aug 12, 2024
2fab56e
update auction manager spec
GadElbazCertora Aug 26, 2024
20749f2
update staking manager spec
GadElbazCertora Aug 26, 2024
b7255fe
etherfi node specs
GadElbazCertora Aug 26, 2024
3f55802
auction manager update
GadElbazCertora Sep 16, 2024
13e0a1f
AuctionManager
GadElbazCertora Sep 16, 2024
0aacea5
Auction Manager Setup remove redundant
GadElbazCertora Sep 16, 2024
718c8b0
EETH update
GadElbazCertora Sep 16, 2024
f011de7
nft dispatch update
GadElbazCertora Sep 16, 2024
46135db
update staking manager
GadElbazCertora Sep 16, 2024
4eb3a2f
add oracle and remove redundant
GadElbazCertora Sep 16, 2024
c54a0be
add EtherFi interface
GadElbazCertora Sep 16, 2024
d361f5a
update etherfi node spec
GadElbazCertora Sep 18, 2024
b0f8ccd
add etherfi nodes manager specs
GadElbazCertora Sep 18, 2024
df1b9bb
remove redundant
GadElbazCertora Sep 19, 2024
5ab7b00
update comments and documentation
GadElbazCertora Sep 19, 2024
705ae29
small update
GadElbazCertora Sep 19, 2024
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
19 changes: 19 additions & 0 deletions certora/config/AuctionManager.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"files": [
"src/AuctionManager.sol",
"src/NodeOperatorManager.sol"
],
"link": [
"AuctionManager:nodeOperatorManager=NodeOperatorManager"
],
"packages": [
"@openzeppelin=lib/openzeppelin-contracts",
"forge-std=lib/forge-std/src"
],
"verify": "AuctionManager:certora/specs/AuctionManager.spec",
"optimistic_loop": true,
"optimistic_fallback": true,
"loop_iter": "3",
"solc": "solc8.24",
"msg": "AuctionManager",
}
18 changes: 18 additions & 0 deletions certora/config/EETH.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"files": [
"src/EETH.sol"
],
"link": [
],
"packages": [
"@openzeppelin=lib/openzeppelin-contracts",
"forge-std=lib/forge-std/src"
],
"verify": "EETH:certora/specs/EETH.spec",
"parametric_contracts": ["EETH"],
"optimistic_loop": true,
"optimistic_fallback": true,
"loop_iter": "3",
"solc": "solc8.24",
"msg": "EETH setup"
}
19 changes: 19 additions & 0 deletions certora/config/EtherFiNode.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"files": [
"src/EtherFiNode.sol",
],
"link": [
],
"packages": [
"@openzeppelin=lib/openzeppelin-contracts",
"forge-std=lib/forge-std/src"
],
"verify": "EtherFiNode:certora/specs/EtherFiNode.spec",
"optimistic_loop": true,
"optimistic_fallback": true,
"optimistic_hashing": true,
"build_cache": true,
"loop_iter": "3",
"solc": "solc8.24",
"msg": "EtherFiNode",
}
27 changes: 27 additions & 0 deletions certora/config/EtherFiNodesManager.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"files": [
"src/EtherFiNodesManager.sol",
"src/EtherFiNode.sol",
"src/TNFT.sol",
"src/BNFT.sol",
"src/RoleRegistry.sol",
],
"link": [
"EtherFiNodesManager:tnft=TNFT",
"EtherFiNodesManager:bnft=BNFT",
"EtherFiNodesManager:roleRegistry=RoleRegistry",
],
"packages": [
"@openzeppelin=lib/openzeppelin-contracts",
"forge-std=lib/forge-std/src"
],
"verify": "EtherFiNodesManager:certora/specs/EtherFiNodesManagerSetup.spec",
"optimistic_loop": true,
"optimistic_fallback": true,
"optimistic_hashing": true,
"parametric_contracts":["EtherFiNodesManager"],
"build_cache": true,
"loop_iter": "3",
"solc": "solc8.24",
"msg": "EtherFiNodesManager all rules",
}
30 changes: 30 additions & 0 deletions certora/config/StakingManager.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"files": [
"src/StakingManager.sol",
"src/AuctionManager.sol",
"src/NodeOperatorManager.sol",
"src/TNFT.sol",
"src/BNFT.sol",
"src/RoleRegistry.sol",
"test/DepositContract.sol"
],
"link": [
"StakingManager:auctionManager=AuctionManager",
"AuctionManager:nodeOperatorManager=NodeOperatorManager",
"StakingManager:roleRegistry=RoleRegistry",
"StakingManager:depositContractEth2=DepositContract",
],
"packages": [
"@openzeppelin=lib/openzeppelin-contracts",
"forge-std=lib/forge-std/src"
],
"verify": "StakingManager:certora/specs/StakingManager.spec",
"optimistic_loop": true,
"optimistic_fallback": true,
"optimistic_hashing": true,
"parametric_contracts":["StakingManager", "AuctionManager"],
"build_cache": true,
"loop_iter": "3",
"solc": "solc8.24",
"msg": "StakingManager",
}
20 changes: 20 additions & 0 deletions certora/config/WeETH.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"files": [
"src/WeETH.sol",
"src/EETH.sol"
],
"link": [
"WeETH:eETH=EETH"
],
"packages": [
"@openzeppelin=lib/openzeppelin-contracts",
"forge-std=lib/forge-std/src"
],
"verify": "WeETH:certora/specs/WeETH.spec",
"parametric_contracts": ["WeETH"],
"optimistic_loop": true,
"optimistic_fallback": true,
"loop_iter": "3",
"solc": "solc8.24",
"msg": "EETH setup"
}
47 changes: 47 additions & 0 deletions certora/specs/AuctionManageSetup.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
methods {
function _.upgradeToAndCall(address,bytes) external => NONDET;
}

persistent ghost mapping(uint256 => uint256) bids_amount {
init_state axiom forall uint256 bid_id . bids_amount[bid_id] == 0;
}

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

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

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

ghost mapping(uint256 => bool) bids_is_active {
init_state axiom forall uint256 bid_id . bids_is_active[bid_id] == false;
}

hook Sstore bids[KEY uint256 bid_id].amount uint256 new_amount (uint256 old_amount) {
bids_amount[bid_id] = new_amount;
sum_of_bids = sum_of_bids + 1;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to reset the bid? In that case when new_amount = 0 the sum_of_bids should reduce by 1.

}

hook Sload uint256 _amount bids[KEY uint256 bid_id].amount {
require _amount == bids_amount[bid_id];
}

hook Sstore bids[KEY uint256 bid_id].isActive bool new_acitive (bool old_active) {
if (new_acitive) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not new_active && !old_active ?

sum_of_active_bids = sum_of_active_bids + 1;
sum_of_all_active_bids_amounts = sum_of_all_active_bids_amounts + bids_amount[bid_id];
} else if (!new_acitive && old_active) {
sum_of_active_bids = sum_of_active_bids - 1;
sum_of_all_active_bids_amounts = sum_of_all_active_bids_amounts - bids_amount[bid_id];
}
bids_is_active[bid_id] = new_acitive;
}

hook Sload bool _isActive bids[KEY uint256 bid_id].isActive {
require _isActive == bids_is_active[bid_id];
}
123 changes: 123 additions & 0 deletions certora/specs/AuctionManager.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import "./AuctionManageSetup.spec";

using NodeOperatorManager as NodeOperatorManager;
/* Verification of `AuctionManager` */
methods {

// Getters:
function whitelistEnabled() external returns (bool) envfree;
function whitelistBidAmount() external returns (uint128) envfree;
function minBidAmount() external returns (uint64) envfree;
function maxBidAmount() external returns (uint64) envfree;
function numberOfActiveBids() external returns (uint256) envfree;
function numberOfBids() external returns (uint256) envfree;
function bids(uint256) external returns (uint256, uint64, address, bool) envfree;
function getBidOwner(uint256) external returns (address) envfree;
function isBidActive(uint256) external returns (bool) envfree;
function accumulatedRevenue() external returns (uint128) envfree;
function accumulatedRevenueThreshold() external returns (uint128) envfree;

function NodeOperatorManager.getUserTotalKeys(address) external returns (uint64) envfree;
function NodeOperatorManager.getNumKeysRemaining(address) external returns (uint64) envfree;
}

// Functions filtered out since they use `delegatecall`.
definition isFilteredFunc(method f) returns bool = (
f.selector == sig:upgradeToAndCall(address, bytes).selector
);

/// @title numberOfActiveBids equals the sum of active bids.
invariant numberOfActiveBidsCorrect()
sum_of_active_bids == to_mathint(numberOfActiveBids())
filtered {f -> !isFilteredFunc(f)}

/// @title numberOfBids equals the sum of all bids.
invariant numberOfBidsEqTheSumOfAllBids()
sum_of_bids == to_mathint(numberOfBids())
filtered {f -> !isFilteredFunc(f) && f.selector != sig:initialize(address).selector}

/// @title solvency invariant - contract should hold atleast sumOfAllActiveBidAmounts amount of eth.
invariant activeBidsSolvency()
to_mathint(nativeBalances[currentContract]) >= sum_of_all_active_bids_amounts
filtered {f -> !isFilteredFunc(f)}
{
preserved with (env e) {
require e.msg.sender != currentContract;
}
preserved processAuctionFeeTransfer(uint256 bidId) with (env e) {
// bidId must be inactive (because there is a stacker that is not address zero).
require isBidActive(bidId) == false;
}
}

/// @title once a bid is set, the only field that can be changed is isActive field.
rule bidImmutability(method f, uint256 bid_id) filtered {f -> !isFilteredFunc(f)} {
env e;
calldataarg args;

require bid_id < numberOfBids();

uint256 AmountBefore;
uint64 bidderPubKeyIndexBefore;
address bidderAddressBefore;
uint256 AmountAfter;
uint64 bidderPubKeyIndexAfter;
address bidderAddressAfter;

AmountBefore, bidderPubKeyIndexBefore, bidderAddressBefore, _ = bids(bid_id);

f(e, args);

AmountAfter, bidderPubKeyIndexAfter, bidderAddressAfter, _ = bids(bid_id);

assert AmountBefore == AmountAfter, "bid amount was changed";
assert bidderPubKeyIndexBefore == bidderPubKeyIndexAfter, "bidder key index was changed";
assert bidderAddressBefore == bidderAddressAfter, "bidder address was changed";
}

/// @title The contact is set as initialized in the constructor.
invariant alwaysInitialized()
currentContract._initialized == max_uint8
filtered {f -> !isFilteredFunc(f)}

/// @title createBid works as intended.
rule integrityOfCreateBid(uint256 _bidSize, uint256 _bidAmountPerBid) {
env e;
uint256 newBidId;
mathint msgValue = e.msg.value;
mathint numberOfBidsBefore = numberOfBids();
mathint numberOfActiveBidsBefore = numberOfActiveBids();
mathint bidIndexInBatch = newBidId - numberOfBidsBefore;
mathint senderFirstKeyIndex = NodeOperatorManager.getUserTotalKeys(e.msg.sender) - NodeOperatorManager.getNumKeysRemaining(e.msg.sender);

require to_mathint(newBidId) < numberOfBidsBefore + _bidSize;
require to_mathint(newBidId) >= numberOfBidsBefore;

// new bid fields:
uint256 amount;
uint64 bidderPubKeyIndex;
address bidderAddress;
bool isActive;

createBid(e, _bidSize, _bidAmountPerBid);

// get one of the new bids:
amount, bidderPubKeyIndex, bidderAddress, isActive = bids(e, newBidId);

mathint numberOfBidsAfter = numberOfBids();
mathint numberOfActiveBidsAfter = numberOfActiveBids();
mathint senderLastKeyIndex = NodeOperatorManager.getUserTotalKeys(e.msg.sender) - NodeOperatorManager.getNumKeysRemaining(e.msg.sender);

// trivial due to requires:
assert msgValue == _bidSize * _bidAmountPerBid, "function should have reverted";
// number of bids update correctly
assert numberOfBidsAfter == numberOfBidsBefore + _bidSize, "amount of bids updated incorrectly";
assert numberOfActiveBidsAfter == numberOfActiveBidsBefore + _bidSize, "amount of active bids updated incorrectly";
assert senderLastKeyIndex == senderFirstKeyIndex + _bidSize, "amount of used keys updated incorrectly";
// the right bids were added:
assert amount == _bidAmountPerBid;
assert bidderPubKeyIndex == assert_uint64(senderFirstKeyIndex + bidIndexInBatch);
assert bidderAddress == e.msg.sender;
assert isActive;
}

Loading