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

Additional tests and specifications #8

Merged
merged 2 commits into from Feb 26, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 46 additions & 0 deletions certora/specs/SharePrice.spec
Expand Up @@ -2,6 +2,7 @@ using MockERC20 as token;
using MockMErc20DelegateFixer as fixer;

methods {
function getCash() external returns (uint256) envfree;
function badDebt() external returns (uint256) envfree;
function fixUser(address liquidator, address user) external;
function borrowIndex() external returns (uint256) envfree;
Expand Down Expand Up @@ -125,6 +126,51 @@ filtered {
"bad debt should only increase when fixing users";
}

rule badDebtRulesCash(env e, uint256 amount) {
require e.msg.sender != fixer;

uint256 startingBadDebt = badDebt();
uint256 startingCash = token.balanceOf(fixer);

/// bound input as to not overflow (safe math is not used)
require startingCash + startingBadDebt <= to_mathint(uintMax());

repayBadDebtWithCash(e, amount);

uint256 endingBadDebt = badDebt();

/// starting cash + starting bad debt == ending bad debt + ending cash == getCash()

assert startingCash + startingBadDebt == endingBadDebt + to_mathint(token.balanceOf(fixer)),
"cash not the same";

assert startingCash + startingBadDebt == to_mathint(getCash()),
"bad debt should not increase when repaying with cash";
}

rule allBadDebtRulesCash(method f, env e, calldataarg args)
filtered {
f ->
f.selector == sig:repayBadDebtWithCash(uint256).selector ||
f.selector == sig:repayBadDebtWithReserves().selector
} {
require e.msg.sender != fixer;

uint256 startingBadDebt = badDebt();
uint256 startingCash = token.balanceOf(fixer);

/// bound input as to not overflow (safe math is not used)
require startingCash + startingBadDebt <= to_mathint(uintMax());

f(e, args);

uint256 endingBadDebt = badDebt();

/// bad debt + cash == getCash()

assert to_mathint(getCash()) == endingBadDebt + to_mathint(token.balanceOf(fixer)),
"cash not correct";
}

rule repayBadDebtWithReservesSuccess(env e) {
uint256 startingReserves = totalReserves();
Expand Down
37 changes: 37 additions & 0 deletions test/integration/proposals/mips/mip-m17/mip-m17.t.sol
Expand Up @@ -274,6 +274,21 @@ contract MIPM17IntegrationTest is PostProposalCheck {
);
}

function testCashEqualsUnderlyingBalancePlusBalance() public {
assertEq(
mxcDotDelegator.badDebt() +
xcDotToken.balanceOf(address(mxcDotDelegator)),
mxcDotDelegator.getCash(),
"xcDot cash incorrect"
);
assertEq(
fraxDelegator.badDebt() +
fraxToken.balanceOf(address(fraxDelegator)),
fraxDelegator.getCash(),
"frax cash incorrect"
);
}

function testEthMadMarketsCeaseFunction() public {
address madEthMTokenHolder = 0xDD15c08320F01F1b6348b35EeBe29fDB5ca0cDa6;

Expand All @@ -285,6 +300,28 @@ contract MIPM17IntegrationTest is PostProposalCheck {
assertTrue(returnCode != 0, "incorrect return code on redeem");
}

function testUsdcMadMarketsCeaseFunction() public {
address madUsdcMTokenHolder = 0xE0B2026E3DB1606ef0Beb764cCdf7b3CEE30Db4A;

uint256 balance = nomadUSDCDelegator.balanceOf(madUsdcMTokenHolder);

vm.prank(madUsdcMTokenHolder);
uint256 returnCode = nomadUSDCDelegator.redeem(balance);

assertTrue(returnCode != 0, "incorrect return code on redeem");
}

function testBtcMadMarketsCeaseFunction() public {
address madBTCMTokenHolder = 0xb587526953Ad321C1aB2eA26F7311d2aA1A98a4a;

uint256 balance = nomadBTCDelegator.balanceOf(madBTCMTokenHolder);

vm.prank(madBTCMTokenHolder);
uint256 returnCode = nomadBTCDelegator.redeem(balance);

assertTrue(returnCode != 0, "incorrect return code on redeem");
}

function testSetUpxcDot() public {
{
/// @dev check that the borrows, reserves and index calculations match
Expand Down