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

Kontrol property tests for RepoTokenList and TermAuctionList invariants #47

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d50b955
Small fixes to RepoTokenList
lucasmt Sep 27, 2024
28ba2b1
Add KontrolCheats submodule
lucasmt Sep 25, 2024
dd1bf5d
Add Kontrol property tests for the RepoTokenList invariants
lucasmt Sep 25, 2024
cbd073c
Implement the assumption that redeemTermRepoTokens will not revert
lucasmt Sep 26, 2024
ba9b7fa
Fix typos
lucasmt Sep 26, 2024
ebd4e7f
Comment out invariant from remove test for the time being
lucasmt Sep 26, 2024
34963f2
Add testRemoveAndRedeemMaturedTokens to kontrol.toml
lucasmt Sep 26, 2024
4af2542
Implement assumption that only matured tokens can have a balance of 0
lucasmt Sep 28, 2024
8b9ea05
Changes to asserts
lucasmt Sep 29, 2024
e108606
Update RepoToken model to include a collateral manager
lucasmt Sep 28, 2024
0ae6d87
Add models for additional contracts
lucasmt Sep 28, 2024
4e44158
Add tests for TermAuctionList insert and remove functions
lucasmt Sep 28, 2024
1ea4170
Fix typo in _establishSortedByAuctionId
lucasmt Sep 30, 2024
8b7252d
Fixed comment
lisandrasilva Sep 30, 2024
563520a
Add code to create a new PendingOffer in testInsertPendingNewOffer
lucasmt Sep 30, 2024
61f504c
Update TermRepoCollateralManager to use a concrete number of collater…
lucasmt Oct 1, 2024
f145254
Add unit test for counterexample found and fixed during formal verifi…
lucasmt Sep 28, 2024
90beef5
symbolic address protection
PetarMax Oct 1, 2024
ec91859
address disjunction hypotheses
PetarMax Oct 1, 2024
366d7e2
keccak lemma
PetarMax Oct 1, 2024
06e78c2
some tricks, corrections, and suggestions
PetarMax Oct 1, 2024
f2cf819
further test streamlining
PetarMax Oct 1, 2024
6385563
bounding
PetarMax Oct 1, 2024
27dfa01
minor corrections
PetarMax Oct 1, 2024
3d20f9e
adding address cast
PetarMax Oct 1, 2024
f8a4619
slot update lemmas
PetarMax Oct 2, 2024
30cf94f
KontrolTest
PetarMax Oct 2, 2024
c38fd25
direct storage manipulation
PetarMax Oct 2, 2024
d77553d
Added KontrolTest and assumption for testInsertPendingDuplicateOffer
lisandrasilva Oct 2, 2024
b0d7c6d
adding KontrolTest
PetarMax Oct 2, 2024
85f416e
Added more assumptions for testInsertPendingDuplicateOffer
lisandrasilva Oct 2, 2024
6cdd122
Fixed test
lisandrasilva Oct 2, 2024
b154087
Assumptions needed for testInsertPendingDuplicateOffer
lisandrasilva Oct 2, 2024
c3422d0
changes to structure
PetarMax Oct 2, 2024
967acf2
slot adjustments
PetarMax Oct 2, 2024
c2f2d07
Added check for auction completed
lisandrasilva Oct 3, 2024
3b7c446
Updated _assumeRepoTokensValidate invariant
lisandrasilva Oct 3, 2024
fe72824
Commented invariant wrongly specified
lisandrasilva Oct 3, 2024
0269ac1
Assumptions about offer.amount
lisandrasilva Oct 3, 2024
4a3f348
further lemmas
PetarMax Oct 3, 2024
5cc6184
tweaks to .toml
PetarMax Oct 3, 2024
61cf518
leaving space between offers
PetarMax Oct 3, 2024
d014d44
Added back invariant for offer.amount
lisandrasilva Oct 4, 2024
ec6b4a9
Updated invariant for offer.amount
lisandrasilva Oct 4, 2024
dad0bf9
Added needed assumption for testInsertPendingDuplicateOffer
lisandrasilva Oct 4, 2024
24432b1
testRemoveCompleted passing
lisandrasilva Oct 4, 2024
766bda5
Updated kontrol.toml file to include all proofs
lisandrasilva Oct 4, 2024
2f60c18
Merge branch 'runtime-fv' into rv-develop
lisandrasilva Oct 4, 2024
0fb7c9c
Merge branch 'runtime-fv' into rv-develop
lisandrasilva Oct 4, 2024
26677b8
testRemoveCompleted passing for bmc-depth > 1
lisandrasilva Oct 5, 2024
b0ff641
Refactoring
lisandrasilva Oct 7, 2024
e533cd2
Fixed bug in testRemoveCompleted
lisandrasilva Oct 7, 2024
43df359
setUp function for RepotokenListInvariants and refator of removeCompl…
lisandrasilva Oct 7, 2024
ee22b8e
separate profile for setup and tests
PetarMax Oct 7, 2024
d82cdbe
Optimization for removeCompleted function
lisandrasilva Oct 8, 2024
417b577
Merge branch 'runtime-fv' into rv-develop
lisandrasilva Oct 8, 2024
9cb8e1c
optimizations
lisandrasilva Oct 8, 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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "lib/kontrol-cheatcodes"]
path = lib/kontrol-cheatcodes
url = https://github.com/runtimeverification/kontrol-cheatcodes
[submodule "lib/yearn-vaults-v3"]
path = lib/yearn-vaults-v3
url = https://github.com/yearn/yearn-vaults-v3.git
Expand Down
88 changes: 88 additions & 0 deletions kontrol.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
[build.default]
foundry-project-root = '.'
regen = true
rekompile = true
verbose = false
debug = false
require = 'src/test/kontrol/term-lemmas.k'
module-import = 'RepoTokenListInvariantsTest:TERM-LEMMAS'
ast = true
auxiliary-lemmas = true

[prove.setup]
foundry-project-root = '.'
verbose = false
debug = false
max-depth = 100000
max-iterations = 10000
reinit = false
cse = false
workers = 1
max-frontier-parallel = 6
maintenance-rate = 24
assume-defined = true
no-log-rewrites = true
kore-rpc-command = 'kore-rpc-booster --no-post-exec-simplify'
failure-information = true
counterexample-information = true
minimize-proofs = false
fail-fast = true
smt-timeout = 16000
smt-retry-limit = 0
break-every-step = false
break-on-jumpi = false
break-on-calls = false
break-on-storage = false
break-on-basic-blocks = false
break-on-cheatcodes = false
auto_abstract = true
run-constructor = false
bmc-depth = 3
match-test = [
"RepoTokenListInvariantsTest.setUp",
"TermAuctionListInvariantsTest.setUp",
]
ast = true

[prove.tests]
foundry-project-root = '.'
verbose = false
debug = false
max-depth = 100000
max-iterations = 10000
reinit = false
cse = false
workers = 1
max-frontier-parallel = 6
maintenance-rate = 24
assume-defined = true
no-log-rewrites = true
kore-rpc-command = 'kore-rpc-booster --no-post-exec-simplify'
failure-information = true
counterexample-information = true
minimize-proofs = false
fail-fast = true
smt-timeout = 16000
smt-retry-limit = 0
break-every-step = false
break-on-jumpi = false
break-on-calls = false
break-on-storage = false
break-on-basic-blocks = false
break-on-cheatcodes = false
auto_abstract = true
run-constructor = false
match-test = [
"RepoTokenListInvariantsTest.testInsertSortedNewToken",
"RepoTokenListInvariantsTest.testInsertSortedDuplicateToken",
"RepoTokenListInvariantsTest.testRemoveAndRedeemMaturedTokens",
"TermAuctionListInvariantsTest.testInsertPendingNewOffer",
"TermAuctionListInvariantsTest.testInsertPendingDuplicateOffer",
"TermAuctionListInvariantsTest.testRemoveCompleted",
]
ast = true

[show.default]
foundry-project-root = '.'
verbose = true
debug = false
1 change: 1 addition & 0 deletions lib/kontrol-cheatcodes
Submodule kontrol-cheatcodes added at c8a62a
14 changes: 9 additions & 5 deletions src/RepoTokenList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ library RepoTokenList {
address prev = current;
while (current != NULL_NODE) {
address next;
if (getRepoTokenMaturity(current) < block.timestamp) {
if (getRepoTokenMaturity(current) <= block.timestamp) {
bool removeMaturedToken;
uint256 repoTokenBalance = ITermRepoToken(current).balanceOf(address(this));

Expand Down Expand Up @@ -337,6 +337,7 @@ library RepoTokenList {
* @param repoToken The repoToken to validate and insert
* @param discountRateAdapter The discount rate adapter
* @param asset The address of the base asset
* @return validRepoToken Whether the repoToken is valid
* @return discountRate The discount rate to be applied to the validated repoToken
* @return redemptionTimestamp The redemption timestamp of the validated repoToken
*/
Expand All @@ -345,14 +346,14 @@ library RepoTokenList {
ITermRepoToken repoToken,
ITermDiscountRateAdapter discountRateAdapter,
address asset
) internal returns (uint256 discountRate, uint256 redemptionTimestamp) {
) internal returns (bool validRepoToken, uint256 discountRate, uint256 redemptionTimestamp) {
discountRate = listData.discountRates[address(repoToken)];
if (discountRate != INVALID_AUCTION_RATE) {
(redemptionTimestamp, , ,) = repoToken.config();

// skip matured repoTokens
if (redemptionTimestamp < block.timestamp) {
revert InvalidRepoToken(address(repoToken));
return (false, discountRate, redemptionTimestamp); //revert InvalidRepoToken(address(repoToken));
}

uint256 oracleRate = discountRateAdapter.getDiscountRate(address(repoToken));
Expand All @@ -368,11 +369,13 @@ library RepoTokenList {

(isRepoTokenValid, redemptionTimestamp) = validateRepoToken(listData, repoToken, asset);
if (!isRepoTokenValid) {
revert InvalidRepoToken(address(repoToken));
return (false, discountRate, redemptionTimestamp);
}
insertSorted(listData, address(repoToken));
listData.discountRates[address(repoToken)] = discountRate;
}

return (true, discountRate, redemptionTimestamp);
}

/**
Expand All @@ -394,6 +397,8 @@ library RepoTokenList {
return;
}

uint256 maturityToInsert = getRepoTokenMaturity(repoToken);

address prev;
while (current != NULL_NODE) {

Expand All @@ -403,7 +408,6 @@ library RepoTokenList {
}

uint256 currentMaturity = getRepoTokenMaturity(current);
uint256 maturityToInsert = getRepoTokenMaturity(repoToken);

// Insert repoToken before current if its maturity is less than or equal
if (maturityToInsert < currentMaturity) {
Expand Down
6 changes: 5 additions & 1 deletion src/Strategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -999,13 +999,17 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard {
}

// Validate and insert the repoToken into the list, retrieve auction rate and redemption timestamp
(, uint256 redemptionTimestamp) = repoTokenListData
(bool isRepoTokenValid , , uint256 redemptionTimestamp) = repoTokenListData
.validateAndInsertRepoToken(
ITermRepoToken(repoToken),
discountRateAdapter,
address(asset)
);

if (!isRepoTokenValid) {
revert RepoTokenList.InvalidRepoToken(repoToken);
}

// Sweep assets and redeem repoTokens, if needed
_redeemRepoTokens(0);

Expand Down
Loading