-
Notifications
You must be signed in to change notification settings - Fork 8
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
Setup router invariants #397
Draft
hieronx
wants to merge
11
commits into
main
Choose a base branch
from
router-invariants
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ccbe632
Setup
hieronx 9be8d6a
Fix router setup
hieronx f2cbbc0
Add RE-1 invariant + more handlers for router
hieronx 385c90b
Fix invalid vault claim balance checks
hieronx 0a47cab
Add claim method
hieronx d8e041a
Fix disallow asset
hieronx fb02181
Fix executing locked request in handler
hieronx c229a8b
Fix properties 6
hieronx f39a604
Fix E1
hieronx 65d3630
Merge branch 'main' of https://github.com/centrifuge/liquidity-pools …
hieronx e37fbb3
Add CR-1 and CR-2
hieronx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule forge-std
updated
35 files
+6 −12 | .github/workflows/ci.yml | |
+3 −1 | .github/workflows/sync.yml | |
+0 −3 | .gitmodules | |
+1 −1 | README.md | |
+3 −3 | foundry.toml | |
+0 −1 | lib/ds-test | |
+1 −1 | package.json | |
+17 −48 | scripts/vm.py | |
+518 −225 | src/StdAssertions.sol | |
+20 −9 | src/StdChains.sol | |
+18 −3 | src/StdInvariant.sol | |
+7 −11 | src/StdJson.sol | |
+202 −107 | src/StdStorage.sol | |
+179 −0 | src/StdToml.sol | |
+1 −1 | src/StdUtils.sol | |
+4 −4 | src/Test.sol | |
+833 −48 | src/Vm.sol | |
+401 −382 | src/console.sol | |
+1 −1,555 | src/console2.sol | |
+51 −33 | src/mocks/MockERC20.sol | |
+46 −36 | src/mocks/MockERC721.sol | |
+693 −4 | src/safeconsole.sol | |
+39 −909 | test/StdAssertions.t.sol | |
+36 −26 | test/StdChains.t.sol | |
+19 −11 | test/StdCheats.t.sol | |
+49 −0 | test/StdJson.t.sol | |
+8 −8 | test/StdMath.t.sol | |
+167 −11 | test/StdStorage.t.sol | |
+49 −0 | test/StdToml.t.sol | |
+18 −18 | test/StdUtils.t.sol | |
+3 −3 | test/Vm.t.sol | |
+8 −0 | test/fixtures/test.json | |
+6 −0 | test/fixtures/test.toml | |
+1 −1 | test/mocks/MockERC20.t.sol | |
+1 −1 | test/mocks/MockERC721.t.sol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity 0.8.26; | ||
|
||
// Recon Deps | ||
import {BaseTargetFunctions} from "@chimera/BaseTargetFunctions.sol"; | ||
import {Properties} from "../Properties.sol"; | ||
import {vm} from "@chimera/Hevm.sol"; | ||
|
||
// Dependencies | ||
import {ERC20} from "src/token/ERC20.sol"; | ||
import {ERC7540Vault} from "src/ERC7540Vault.sol"; | ||
|
||
/** | ||
* A collection of handlers that interact with the Centrifuge Router | ||
*/ | ||
abstract contract RouterFunctions is BaseTargetFunctions, Properties { | ||
// === Enable lock deposit request === // | ||
function router_enableLockDepositRequest(uint256 assets) public { | ||
assets = between(assets, 0, _getTokenAndBalanceForVault()); | ||
|
||
token.approve(address(router), assets); | ||
|
||
// B4 Balances | ||
uint256 balanceB4 = token.balanceOf(actor); | ||
uint256 balanceOfRouterEscrowB4 = token.balanceOf(address(routerEscrow)); | ||
|
||
bool hasReverted; | ||
try router.enableLockDepositRequest(address(vault), assets) { | ||
sumOfLockedDepositRequests[address(token)] += assets; | ||
} catch { | ||
hasReverted = true; | ||
} | ||
|
||
// After Balances and Checks | ||
uint256 balanceAfter = token.balanceOf(actor); | ||
uint256 balanceOfRouterEscrowAfter = token.balanceOf(address(routerEscrow)); | ||
|
||
// NOTE: We only enforce the check if the tx didn't revert | ||
if (!hasReverted) { | ||
// Extra check | ||
// NOTE: Unchecked so we get broken property and debug faster | ||
uint256 deltaUser = balanceB4 - balanceAfter; | ||
uint256 deltaRouterEscrow = balanceOfRouterEscrowAfter - balanceOfRouterEscrowB4; | ||
|
||
if (RECON_EXACT_BAL_CHECK) { | ||
eq(deltaUser, assets, "Router-x"); | ||
} | ||
|
||
eq(deltaUser, deltaRouterEscrow, "Router-x"); | ||
} | ||
} | ||
|
||
// === Lock deposit request === // | ||
// TODO | ||
|
||
// === Executed locked deposit request === // | ||
function router_unlockDepositRequest() public { | ||
uint256 balanceB4 = token.balanceOf(actor); | ||
uint256 balanceOfRouterEscrowB4 = token.balanceOf(address(routerEscrow)); | ||
uint256 lockedRequestB4 = router.lockedRequests(actor, address(vault)); | ||
|
||
bool hasReverted; | ||
try router.unlockDepositRequest(address(vault), actor) { | ||
sumOfUnlockedDepositRequests[address(token)] += lockedRequestB4; | ||
} catch { | ||
hasReverted = true; | ||
} | ||
|
||
// After Balances and Checks | ||
uint256 balanceAfter = token.balanceOf(actor); | ||
uint256 balanceOfRouterEscrowAfter = token.balanceOf(address(routerEscrow)); | ||
uint256 lockedRequestAfter = router.lockedRequests(actor, address(vault)); | ||
|
||
// NOTE: We only enforce the check if the tx didn't revert | ||
if (!hasReverted) { | ||
uint256 deltaUser = balanceB4 - balanceAfter; | ||
uint256 deltaRouterEscrow = balanceOfRouterEscrowAfter - balanceOfRouterEscrowB4; | ||
|
||
if (RECON_EXACT_BAL_CHECK) { | ||
eq(deltaUser, lockedRequestB4, "Router-x"); | ||
} | ||
|
||
eq(deltaRouterEscrow, lockedRequestB4, "Router-x"); | ||
eq(lockedRequestAfter, 0, "Router-x"); | ||
} | ||
} | ||
|
||
// === Executed locked deposit request === // | ||
function router_executeLockedDepositRequest() public { | ||
uint256 balanceOfEscrowB4 = token.balanceOf(address(escrow)); | ||
uint256 balanceOfRouterEscrowB4 = token.balanceOf(address(routerEscrow)); | ||
uint256 lockedRequestB4 = router.lockedRequests(actor, address(vault)); | ||
|
||
bool hasReverted; | ||
try router.executeLockedDepositRequest(address(vault), actor, 0) { | ||
sumOfExecutedLockedDepositRequests[address(token)] += lockedRequestB4; | ||
} catch { | ||
hasReverted = true; | ||
} | ||
|
||
if (!poolManager.isAllowedAsset(poolId, address(token))) { | ||
// TODO: Ensure this works via actor switch | ||
t(hasReverted, "Router-x Must Revert"); | ||
} | ||
|
||
// After Balances and Checks | ||
uint256 balanceOfEscrowAfter = token.balanceOf(address(escrow)); | ||
uint256 balanceOfRouterEscrowAfter = token.balanceOf(address(routerEscrow)); | ||
uint256 lockedRequestAfter = router.lockedRequests(actor, address(vault)); | ||
|
||
// NOTE: We only enforce the check if the tx didn't revert | ||
if (!hasReverted) { | ||
uint256 deltaEscrow = balanceOfEscrowAfter - balanceOfEscrowB4; | ||
uint256 deltaRouterEscrow = balanceOfRouterEscrowB4 - balanceOfRouterEscrowAfter; | ||
|
||
eq(deltaEscrow, lockedRequestB4, "Router-x"); | ||
eq(deltaRouterEscrow, lockedRequestB4, "Router-x"); | ||
eq(lockedRequestAfter, 0, "Router-x"); | ||
} | ||
} | ||
|
||
// TODO: once we have multi actor support, include receiver != controller case | ||
function router_claimDeposit(address sender) public { | ||
// Bal b4 | ||
uint256 trancheUserB4 = trancheToken.balanceOf(actor); | ||
uint256 trancheEscrowB4 = trancheToken.balanceOf(address(escrow)); | ||
uint256 shares = vault.maxMint(address(actor)); | ||
|
||
bool hasReverted; | ||
vm.prank(sender); | ||
try router.claimDeposit(address(vault), address(actor), address(actor)) { | ||
// Processed Deposit | E-2 | Global-1 | ||
sumOfClaimedDeposits[address(trancheToken)] += shares; | ||
} catch { | ||
hasReverted = true; | ||
} | ||
|
||
if (!router.isEnabled(address(vault), address(actor)) && address(actor) != sender) { | ||
t(hasReverted, "Router-x Must Revert"); | ||
} | ||
|
||
// Bal after | ||
uint256 trancheUserAfter = trancheToken.balanceOf(actor); | ||
uint256 trancheEscrowAfter = trancheToken.balanceOf(address(escrow)); | ||
|
||
// NOTE: We only enforce the check if the tx didn't revert | ||
if (!hasReverted) { | ||
unchecked { | ||
uint256 deltaUser = trancheUserAfter - trancheUserB4; // B4 - after -> They pay | ||
uint256 deltaEscrow = trancheEscrowB4 - trancheEscrowAfter; // After - B4 -> They gain | ||
emit DebugNumber(deltaUser); | ||
emit DebugNumber(deltaEscrow); | ||
|
||
eq(deltaUser, deltaEscrow, "Router-x"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to assign some variable ( meaningful name ) to these magic numbers :D.
Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are tests that are copy pasted as output of broken properties from medusa/echidna. So there is no meaningful names for these, and we shouldn't adapt these.