forked from ubiquity/ubiquity-dollar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move formal verifications out of the test dir
- Loading branch information
1 parent
f7ce1e7
commit 791889c
Showing
5 changed files
with
828 additions
and
12 deletions.
There are no files selected for viewing
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,48 @@ | ||
[profile.default] | ||
src = 'src' | ||
test = 'test' | ||
out = 'out' | ||
libs = ['lib'] | ||
script = 'scripts' | ||
solc_version = '0.8.19' | ||
evm_version = 'shanghai' | ||
extra_output = [ | ||
"abi", | ||
"evm.bytecode", | ||
"evm.deployedBytecode", | ||
"evm.methodIdentifiers", | ||
] | ||
optimizer = true | ||
optimizer_runs = 20_000 | ||
force = false | ||
# See more config options https://github.com/foundry-rs/foundry/tree/master/config | ||
|
||
[rpc_endpoints] | ||
mainnet = "https://rpc.ankr.com/eth" | ||
|
||
[profile.SMT.model_checker] | ||
contracts = { } | ||
engine = 'chc' | ||
solvers = ['z3'] | ||
show_unproved = true | ||
timeout = 5000 | ||
targets = [ | ||
'assert', | ||
'constantCondition', | ||
'divByZero', | ||
'outOfBounds', | ||
'overflow', | ||
'popEmptyArray', | ||
'underflow', | ||
'balance', | ||
] | ||
|
||
[profile.docs] | ||
src = 'src/dollar' | ||
|
||
[profile.intense.fuzz] | ||
runs = 16500000 # 5h 30m | ||
max_test_rejects = 144000000 | ||
|
||
[profile.intense.invariant] | ||
runs = 350000 # 5h 40m |
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
83 changes: 83 additions & 0 deletions
83
packages/contracts/src/dollar/UbiquityPoolWithInvariants.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity 0.8.19; | ||
|
||
import {LibUbiquityPool} from "./libraries/LibUbiquityPool.sol"; | ||
import {AppStorage, LibAppStorage} from "./libraries/LibAppStorage.sol"; | ||
import {IERC20Ubiquity} from "./interfaces/IERC20Ubiquity.sol"; | ||
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol"; | ||
|
||
contract UbiquityPoolWithInvariants { | ||
using SafeMath for uint256; | ||
|
||
function mintDollar( | ||
uint256 _collateralIndex, | ||
uint256 _dollarAmount, | ||
uint256 _dollarOutMin, | ||
uint256 _maxCollateralIn, | ||
uint256 _maxGovernanceIn, | ||
bool _isOneToOne | ||
) | ||
public | ||
returns ( | ||
uint256 totalDollarMint, | ||
uint256 collateralNeeded, | ||
uint256 governanceNeeded | ||
) | ||
{ | ||
(totalDollarMint, collateralNeeded, governanceNeeded) = LibUbiquityPool | ||
.mintDollar( | ||
_collateralIndex, | ||
_dollarAmount, | ||
_dollarOutMin, | ||
_maxCollateralIn, | ||
_maxGovernanceIn, | ||
_isOneToOne | ||
); | ||
|
||
( | ||
uint256 totalDollarSupplyInUsd, | ||
uint256 collateralUsdBalance | ||
) = getDollarSupplyAndCollateralBalance(); | ||
|
||
assert(totalDollarSupplyInUsd <= collateralUsdBalance); | ||
} | ||
|
||
function redeemDollar( | ||
uint256 _collateralIndex, | ||
uint256 _dollarAmount, | ||
uint256 _governanceOutMin, | ||
uint256 _collateralOutMin | ||
) public returns (uint256 collateralOut, uint256 governanceOut) { | ||
(collateralOut, governanceOut) = LibUbiquityPool.redeemDollar( | ||
_collateralIndex, | ||
_dollarAmount, | ||
_governanceOutMin, | ||
_collateralOutMin | ||
); | ||
|
||
( | ||
uint256 totalDollarSupplyInUsd, | ||
uint256 collateralUsdBalance | ||
) = getDollarSupplyAndCollateralBalance(); | ||
|
||
assert(collateralUsdBalance >= totalDollarSupplyInUsd); | ||
} | ||
|
||
function getDollarSupplyAndCollateralBalance() | ||
public | ||
view | ||
returns (uint256 totalDollarSupplyInUsd, uint256 collateralUsdBalance) | ||
{ | ||
uint256 totalDollarSupply = IERC20Ubiquity( | ||
LibAppStorage.appStorage().dollarTokenAddress | ||
).totalSupply(); | ||
|
||
collateralUsdBalance = LibUbiquityPool.collateralUsdBalance(); | ||
|
||
require(collateralUsdBalance > 0, "Collateral balance is zero"); | ||
require(totalDollarSupply > 0, "Dollar supply is zero"); | ||
|
||
uint256 dollarPrice = LibUbiquityPool.getDollarPriceUsd(); | ||
totalDollarSupplyInUsd = totalDollarSupply.mul(dollarPrice).div(1e6); | ||
} | ||
} |
Oops, something went wrong.