Skip to content

Commit

Permalink
Changes after review: add F5 invariant
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed Apr 20, 2023
1 parent 74b255f commit 1b21017
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/base/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,11 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
return PoolCommons.utilization(emaState);
}

/// @inheritdoc IPoolDerivedState
function depositScale(uint256 index_) external view override returns (uint256) {
return deposits.scaling[index_];
}

/// @inheritdoc IPoolState
function emasInfo() external view override returns (uint256, uint256, uint256, uint256) {
return (
Expand Down
9 changes: 9 additions & 0 deletions src/interfaces/pool/commons/IPoolDerivedState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ interface IPoolDerivedState {
*/
function depositUtilization() external view returns (uint256);

/**
* @notice Returns the scaling value of deposit at given index.
* @param index_ Deposit index.
* @return Deposit scaling.
*/
function depositScale(
uint256 index_
) external view returns (uint256);

}
1 change: 1 addition & 0 deletions tests/INVARIANTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
- **F2**: For any index `i`, the prefix sum up to and including `i` is the sum of values stored in indices `j<=i`
- **F3**: For any index `i < MAX_FENWICK_INDEX`, `findIndexOfSum(prefixSum(i)) > i`
- **F4**: For any index i, there is zero deposit above i and below findIndexOfSum(prefixSum(i) + 1): `depositAtIndex(j) == 0 for i < j < findIndexOfSum(prefixSum(i)+1)`
- **F5**: Global scalar is never updated (`DepositsState.scaling[8192]` is always 0)

## Exchange rate invariants ##
- **R1**: Exchange rates are unchanged by pledging collateral
Expand Down
6 changes: 6 additions & 0 deletions tests/forge/invariants/base/BasicInvariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ abstract contract BasicInvariants is BaseInvariants {
* F2: For any index i, the prefix sum up to and including i is the sum of values stored in indices j<=i
* F3: For any index i < MAX_FENWICK_INDEX, findIndexOfSum(prefixSum(i)) > i
* F4: For any index i, there is zero deposit above i and below findIndexOfSum(prefixSum(i) + 1): findIndexOfSum(prefixSum(i)) == findIndexOfSum(prefixSum(j) - deposits.valueAt(j)), where j is the next index from i with deposits != 0
* F5: Global scalar is never updated (`DepositsState.values[8192]` is always 0)
****************************************************************************************************************************************/

// checks pool lps are equal to sum of all lender lps in a bucket
Expand Down Expand Up @@ -352,6 +353,11 @@ abstract contract BasicInvariants is BaseInvariants {
}
}

// **F5**: Global scalar is never updated (`DepositsState.scaling[8192]` is always 0)
function invariant_fenwick_globalscalar_F5() public useCurrentTimestamp {
require(_pool.depositScale(8192) == 0, "F5: Global scalar was updated");
}

function invariant_call_summary() public virtual useCurrentTimestamp {
console.log("\nCall Summary\n");
console.log("--Lender----------");
Expand Down

0 comments on commit 1b21017

Please sign in to comment.