2020-10-28 23:20:38 +00:00
|
|
|
using LendingPoolHarnessForVariableDebtToken as POOL
|
2020-10-14 21:59:12 +00:00
|
|
|
|
2020-11-22 20:20:43 +00:00
|
|
|
/**
|
|
|
|
Checks that each possible opertaion changes the balance of at most one user.
|
2020-10-14 21:59:12 +00:00
|
|
|
*/
|
|
|
|
rule balanceOfChange(address a, address b, method f)
|
|
|
|
{
|
|
|
|
env e;
|
2020-11-22 20:20:43 +00:00
|
|
|
require a != b;
|
2020-10-14 21:59:12 +00:00
|
|
|
uint256 balanceABefore = sinvoke balanceOf(e, a);
|
|
|
|
uint256 balanceBBefore = sinvoke balanceOf(e, b);
|
|
|
|
|
|
|
|
calldataarg arg;
|
|
|
|
sinvoke f(e, arg);
|
|
|
|
|
|
|
|
uint256 balanceAAfter = sinvoke balanceOf(e, a);
|
|
|
|
uint256 balanceBAfter = sinvoke balanceOf(e, b);
|
|
|
|
|
2020-11-22 20:20:43 +00:00
|
|
|
assert (balanceABefore == balanceAAfter || balanceBBefore == balanceBAfter);
|
2020-10-14 21:59:12 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 20:20:43 +00:00
|
|
|
/**
|
|
|
|
Checks that the change to total supply is coherent with the change to the balance due to an operation
|
|
|
|
(which is neither a burn nor a mint).
|
2020-10-14 21:59:12 +00:00
|
|
|
*/
|
2020-11-22 20:20:43 +00:00
|
|
|
rule integirtyBalanceOfTotalSupply(address a, method f)
|
2020-10-14 21:59:12 +00:00
|
|
|
{
|
|
|
|
env e;
|
|
|
|
|
|
|
|
uint256 balanceABefore = balanceOf(e, a);
|
|
|
|
uint256 totalSupplyBefore = totalSupply(e);
|
|
|
|
|
|
|
|
calldataarg arg;
|
|
|
|
sinvoke f(e, arg);
|
|
|
|
require (f.selector != burn(address, uint256, uint256).selector &&
|
2020-11-22 20:20:43 +00:00
|
|
|
f.selector != mint(address, address, uint256, uint256).selector);
|
2020-10-14 21:59:12 +00:00
|
|
|
uint256 balanceAAfter = balanceOf(e, a);
|
|
|
|
uint256 totalSupplyAfter = totalSupply(e);
|
|
|
|
|
|
|
|
assert (balanceAAfter != balanceABefore => ( balanceAAfter - balanceABefore == totalSupplyAfter - totalSupplyBefore));
|
|
|
|
}
|
|
|
|
|
2020-11-22 20:20:43 +00:00
|
|
|
/**
|
|
|
|
Checks that the change to total supply is coherent with the change to the balance due to a burn operation.
|
2020-10-14 21:59:12 +00:00
|
|
|
*/
|
2020-11-22 20:20:43 +00:00
|
|
|
rule integirtyBalanceOfTotalSupplyOnBurn(address a)
|
2020-10-14 21:59:12 +00:00
|
|
|
{
|
|
|
|
env e;
|
|
|
|
|
|
|
|
uint256 balanceABefore = balanceOf(e, a);
|
|
|
|
uint256 totalSupplyBefore = totalSupply(e);
|
|
|
|
|
|
|
|
uint256 x;
|
|
|
|
address asset;
|
|
|
|
uint256 index = POOL.getReserveNormalizedVariableDebt(e, asset);
|
|
|
|
sinvoke burn(e, a, x, index);
|
|
|
|
uint256 balanceAAfter = balanceOf(e, a);
|
|
|
|
uint256 totalSupplyAfter = totalSupply(e);
|
2020-11-22 20:20:43 +00:00
|
|
|
assert (balanceAAfter != balanceABefore => (balanceAAfter - balanceABefore == totalSupplyAfter - totalSupplyBefore));
|
2020-10-14 21:59:12 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 20:20:43 +00:00
|
|
|
/**
|
|
|
|
Checks that the change to total supply is coherent with the change to the balance due to a mint operation.
|
|
|
|
*/
|
|
|
|
rule integirtyBalanceOfTotalSupplyOnMint(address u, address delegatedUser)
|
2020-10-14 21:59:12 +00:00
|
|
|
{
|
|
|
|
env e;
|
|
|
|
|
2020-11-22 20:20:43 +00:00
|
|
|
uint256 balanceUBefore = balanceOf(e, u);
|
2020-10-14 21:59:12 +00:00
|
|
|
uint256 totalSupplyBefore = totalSupply(e);
|
|
|
|
|
|
|
|
uint256 x;
|
|
|
|
address asset;
|
|
|
|
uint256 index = POOL.getReserveNormalizedVariableDebt(e, asset);
|
2020-11-22 20:20:43 +00:00
|
|
|
sinvoke mint(e, delegatedUser, u, x, index);
|
|
|
|
uint256 balanceUAfter = balanceOf(e, u);
|
2020-10-14 21:59:12 +00:00
|
|
|
uint256 totalSupplyAfter = totalSupply(e);
|
2020-11-22 20:20:43 +00:00
|
|
|
assert (balanceUAfter != balanceUBefore => (balanceUAfter - balanceUBefore == totalSupplyAfter - totalSupplyBefore));
|
2020-10-14 21:59:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-22 20:20:43 +00:00
|
|
|
Minting an amount of x tokens for user u increases her balance by x, up to rounding errors.
|
|
|
|
{ b = balanceOf(u,t) }
|
|
|
|
mint(delegatedUser, u, x, index)
|
|
|
|
{ balanceOf(u,t) = b + x }.
|
2020-10-14 21:59:12 +00:00
|
|
|
|
2020-11-22 20:20:43 +00:00
|
|
|
Also, if the minting is done by a user delegatedUser different than u, the balance of delegatedUser
|
|
|
|
remains unchanged.
|
2020-10-14 21:59:12 +00:00
|
|
|
*/
|
2020-11-22 20:20:43 +00:00
|
|
|
rule integrityMint(address u, address delegatedUser, uint256 x) {
|
2020-10-14 21:59:12 +00:00
|
|
|
env e;
|
|
|
|
address asset;
|
|
|
|
uint256 index = POOL.getReserveNormalizedVariableDebt(e,asset);
|
2020-11-22 20:20:43 +00:00
|
|
|
uint256 balanceUBefore = balanceOf(e, u);
|
|
|
|
uint256 balanceDelegatedUBefore = balanceOf(e, delegatedUser);
|
|
|
|
sinvoke mint(e, delegatedUser, u, x, index);
|
2020-10-14 21:59:12 +00:00
|
|
|
|
2020-11-22 20:20:43 +00:00
|
|
|
uint256 balanceUAfter = balanceOf(e, u);
|
|
|
|
uint256 balanceDelegatedUAfter = balanceOf(e, delegatedUser);
|
|
|
|
|
|
|
|
assert balanceUAfter == balanceUBefore + x && (u != delegatedUser => (balanceDelegatedUAfter == balanceDelegatedUBefore));
|
2020-10-14 21:59:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-22 20:20:43 +00:00
|
|
|
Mint is additive, namely it can performed either all at once or gradually:
|
|
|
|
mint(delegatedUser, u, x, index); mint(delegatedUser, u, y, index) ~ mint(delegatedUser, u, x+y, index) at the same timestamp.
|
2020-10-14 21:59:12 +00:00
|
|
|
*/
|
2020-11-22 20:20:43 +00:00
|
|
|
rule additiveMint(address a, address delegatedUser, uint256 x, uint256 y) {
|
2020-10-14 21:59:12 +00:00
|
|
|
env e;
|
|
|
|
address asset;
|
|
|
|
uint256 index = POOL.getReserveNormalizedVariableDebt(e, asset);
|
|
|
|
storage initialStorage = lastStorage;
|
2020-11-22 20:20:43 +00:00
|
|
|
sinvoke mint(e, delegatedUser, a, x, index);
|
|
|
|
sinvoke mint(e, delegatedUser, a, y, index);
|
2020-10-14 21:59:12 +00:00
|
|
|
uint256 balanceScenario1 = balanceOf(e, a);
|
2020-11-22 20:20:43 +00:00
|
|
|
uint256 t = x + y;
|
|
|
|
sinvoke mint(e, delegatedUser, a, t ,index) at initialStorage;
|
2020-10-14 21:59:12 +00:00
|
|
|
|
|
|
|
uint256 balanceScenario2 = balanceOf(e, a);
|
|
|
|
assert balanceScenario1 == balanceScenario2, "mint is not additive";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-22 20:20:43 +00:00
|
|
|
Burning an amount of x tokens for user u decreases her balance by x, up to rounding errors.
|
|
|
|
{ bu = balanceOf(u) }
|
|
|
|
burn(u, x)
|
|
|
|
{ balanceOf(u) = bu - x }.
|
2020-10-14 21:59:12 +00:00
|
|
|
*/
|
|
|
|
rule integrityBurn(address a, uint256 x) {
|
|
|
|
env e;
|
|
|
|
address asset;
|
|
|
|
uint256 index = POOL.getReserveNormalizedVariableDebt(e, asset);
|
|
|
|
uint256 balancebefore = balanceOf(e, a);
|
|
|
|
sinvoke burn(e, a, x, index);
|
|
|
|
|
|
|
|
uint256 balanceAfter = balanceOf(e, a);
|
|
|
|
assert balanceAfter == balancebefore - x;
|
|
|
|
}
|
|
|
|
/**
|
2020-11-22 20:20:43 +00:00
|
|
|
Minting is additive, i.e., it can be performed either all at once or in steps:
|
|
|
|
burn(u, x); burn(u, y) ~ burn(u, x+y) at the same timestamp.
|
2020-10-14 21:59:12 +00:00
|
|
|
*/
|
|
|
|
rule additiveBurn(address a, uint256 x, uint256 y) {
|
|
|
|
env e;
|
|
|
|
address asset;
|
|
|
|
uint256 index = POOL.getReserveNormalizedVariableDebt(e, asset);
|
|
|
|
storage initialStorage = lastStorage;
|
|
|
|
sinvoke burn(e, a, x, index);
|
|
|
|
sinvoke burn(e, a, y, index);
|
|
|
|
uint256 balanceScenario1 = balanceOf(e, a);
|
2020-11-22 20:20:43 +00:00
|
|
|
uint256 t = x + y;
|
2020-10-14 21:59:12 +00:00
|
|
|
sinvoke burn(e, a, t ,index) at initialStorage;
|
|
|
|
|
|
|
|
uint256 balanceScenario2 = balanceOf(e, a);
|
|
|
|
assert balanceScenario1 == balanceScenario2, "burn is not additive";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-22 20:20:43 +00:00
|
|
|
Minting and burning are inverse operations:
|
|
|
|
{ bu = balanceOf(u) }
|
2020-10-14 21:59:12 +00:00
|
|
|
mint(u,x); burn(u, u, x)
|
2020-11-22 20:20:43 +00:00
|
|
|
{ balanceOf(u) = bu }.
|
2020-10-14 21:59:12 +00:00
|
|
|
*/
|
|
|
|
rule inverseMintBurn(address a, uint256 x) {
|
|
|
|
env e;
|
|
|
|
address asset;
|
2020-11-22 20:20:43 +00:00
|
|
|
address delegatedUser;
|
2020-10-14 21:59:12 +00:00
|
|
|
uint256 index = POOL.getReserveNormalizedVariableDebt(e, asset);
|
|
|
|
uint256 balancebefore = balanceOf(e, a);
|
2020-11-22 20:20:43 +00:00
|
|
|
sinvoke mint(e, delegatedUser, a, x, index);
|
2020-10-14 21:59:12 +00:00
|
|
|
sinvoke burn(e, a, x, index);
|
2020-11-22 20:20:43 +00:00
|
|
|
uint256 balanceAfter = balanceOf(e, a);
|
|
|
|
assert balancebefore == balanceAfter, "burn is not the inverse of mint";
|
|
|
|
}
|