test(certora): add rule to check Karma externalSupply is always <= totalDistributorAllocation

This commit is contained in:
Andrea Franz
2025-03-14 18:49:36 +01:00
committed by r4bbit
parent dabcf5c990
commit 14eaf35091
2 changed files with 22 additions and 7 deletions

View File

@@ -3,6 +3,8 @@ using Karma as karma;
methods {
function owner() external returns (address) envfree;
function totalDistributorAllocation() external returns (uint256) envfree;
function totalSupply() external returns (uint256) envfree;
function externalSupply() external returns (uint256) envfree;
function _.setReward(uint256, uint256) external => HAVOC_ECF;
}
@@ -20,11 +22,14 @@ invariant totalDistributorAllocationIsSumOfDistributorAllocations()
f -> !isUpgradeFunction(f)
}
// TODO:
// sum of external supply <= total supply
rule externalSupplyIsLessOrEqThanTotalDistributorAllocation() {
assert externalSupply() <= totalDistributorAllocation();
}
definition isUpgradeFunction(method f) returns bool = (
f.selector == sig:karma.upgradeToAndCall(address, bytes).selector
f.selector == sig:karma.upgradeToAndCall(address, bytes).selector ||
f.selector == sig:karma.upgradeTo(address).selector
);
definition isERC20TransferFunction(method f) returns bool = (

View File

@@ -163,12 +163,13 @@ contract Karma is Initializable, ERC20Upgradeable, Ownable2StepUpgradeable, UUPS
for (uint256 i = 0; i < rewardDistributors.length(); i++) {
IRewardDistributor distributor = IRewardDistributor(rewardDistributors.at(i));
uint256 supply = distributor.totalRewardsSupply();
if (supply > rewardDistributorAllocations[address(distributor)]) {
supply = rewardDistributorAllocations[address(distributor)];
}
externalSupply += supply;
}
if (externalSupply > totalDistributorAllocation) {
return totalDistributorAllocation;
}
return externalSupply;
}
@@ -230,4 +231,13 @@ contract Karma is Initializable, ERC20Upgradeable, Ownable2StepUpgradeable, UUPS
function allowance(address, address) public pure override returns (uint256) {
return 0;
}
/**
* @notice Returns the external supply of the token.
* @dev The external supply is the sum of the rewards from all reward distributors.
* @return The external supply of the token.
*/
function externalSupply() public view returns (uint256) {
return _externalSupply();
}
}