Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
07293d2
initial second implementation of rebasing to another account
sparrowDom Oct 30, 2024
048b03f
update to core functionality
sparrowDom Oct 30, 2024
36c599e
add gas fucntion
sparrowDom Nov 3, 2024
05d746e
simplify execute
sparrowDom Nov 3, 2024
28d83f9
simplify mint and burn
sparrowDom Nov 3, 2024
45f476b
initial version of Daniel's yield delegation implementation
sparrowDom Nov 7, 2024
9994263
prettier and linter fixes
naddison36 Nov 7, 2024
4c22467
Add slots to OUSD contract to align with existing deployments
naddison36 Nov 7, 2024
f537b63
Generated new OUSD contract diagrams
naddison36 Nov 7, 2024
5743461
Added deploy scripts for OToken upgrades
naddison36 Nov 7, 2024
68ae87e
Generated new OUSD storage diagram
naddison36 Nov 7, 2024
2dbd19e
Merge remote-tracking branch 'origin/master' into sparrowDom/rebaseEl…
naddison36 Nov 7, 2024
58afd12
some minor bug fixes
sparrowDom Nov 7, 2024
17f121c
Prettier and fix spelling in comments
naddison36 Nov 7, 2024
381d13d
Unit test fixes
naddison36 Nov 7, 2024
4ee1b4b
fix initialise function sigature and visibility of functions
sparrowDom Nov 7, 2024
9a29c45
fix some tests
sparrowDom Nov 7, 2024
47e529f
add explanation for the alternativeCreditsPerToken check
sparrowDom Nov 7, 2024
24f099b
prettier
sparrowDom Nov 7, 2024
22c1cf5
reintroduce the original check
sparrowDom Nov 7, 2024
a5269b8
explicitly call rebaseOpt out if the yield delegating account hasn't …
sparrowDom Nov 8, 2024
e64ab17
add one more test
sparrowDom Nov 8, 2024
68d14bd
add Readme of the token contract logic
sparrowDom Nov 8, 2024
ef7c4ab
force account to be rebasing on yield delegation
sparrowDom Nov 8, 2024
90ec917
add explicit whitelist of allowed states when delegating yield
sparrowDom Nov 11, 2024
2c96306
add more defensive checks where isNonRebasingAccount can not mistanki…
sparrowDom Nov 13, 2024
4bf3360
remove increase/decrease allowance
sparrowDom Nov 13, 2024
5cbcf4c
Update docs with invarients
DanielVF Nov 13, 2024
0ab7bc8
Use safecast for any downcasting (#2306)
sparrowDom Nov 13, 2024
2029659
More invarients around outer functions
DanielVF Nov 13, 2024
5951660
Format invarients
DanielVF Nov 13, 2024
8c126c8
further simplify the code when handling different rebase states
sparrowDom Nov 13, 2024
8c2a358
remove nonreentrant modifiers from the toke code as they are not needed
sparrowDom Nov 13, 2024
d7a303f
allow empty conracts to rebaseOptIn without auto migration
sparrowDom Nov 15, 2024
2b3189f
Transfer unit tests for new token implementation (#2310)
sparrowDom Nov 15, 2024
aa53ea3
More invarients
DanielVF Nov 13, 2024
727e4e9
Correct total supply docs
DanielVF Nov 15, 2024
77d69f1
Transfer unit tests for new token implementation (#2310)
sparrowDom Nov 15, 2024
0cfa352
fix test
sparrowDom Nov 15, 2024
31c8078
remove redundant state checks
sparrowDom Nov 15, 2024
511dcaa
remove overwriting the same value to alternativeCreditsPerToken
sparrowDom Nov 15, 2024
5f63650
add non zero checks in delegation functions
sparrowDom Nov 15, 2024
4e327fa
correct error
sparrowDom Nov 15, 2024
9e9c726
correct some contract view modifiers
sparrowDom Nov 15, 2024
6e1b63e
add a readable error message when allowance is exceeded
sparrowDom Nov 15, 2024
659f294
reducing 2 functions to 1
sparrowDom Nov 15, 2024
f261756
deprecate isUpgraded
sparrowDom Nov 18, 2024
54b7ebe
rename totalSupply
sparrowDom Nov 18, 2024
2b31fd6
improve initialisation checks
sparrowDom Nov 18, 2024
108f0eb
remove gas optimisation that would also allow for errorneously large …
sparrowDom Nov 18, 2024
24865d0
remove underflow checks
sparrowDom Nov 18, 2024
b728d2e
simplify code check for rebaseOptIn and add a test for it
sparrowDom Nov 18, 2024
ba625f0
remove comments
sparrowDom Nov 18, 2024
f8280d1
move the balance and credits query above the rebaseState changes
sparrowDom Nov 18, 2024
ab460b8
use _adjustGlobals function to adjust globals in yield delegation
sparrowDom Nov 18, 2024
c94cd5f
futher simplify the undelegateYield function
sparrowDom Nov 18, 2024
c3684a5
unify the variable names
sparrowDom Nov 18, 2024
9cc74cc
add comment
sparrowDom Nov 18, 2024
2987362
a couple of more places to utilise the _adjustGlobals function
sparrowDom Nov 18, 2024
6b02387
no need this being a separate variable
sparrowDom Nov 18, 2024
6556835
undo bug introduction
sparrowDom Nov 18, 2024
56b11e2
wrong use of msg.sender bug fix
sparrowDom Nov 18, 2024
bbb3f45
function doesn't need to return any values
sparrowDom Nov 19, 2024
e949129
simplify
sparrowDom Nov 19, 2024
a1d3cdc
improve syntax
sparrowDom Nov 19, 2024
504a421
add events for yield delegation
sparrowDom Nov 19, 2024
546695f
remove var init
sparrowDom Nov 19, 2024
62c1045
fix deploy file
sparrowDom Nov 19, 2024
fd45920
add tests to catch possible incorrect rebaseOptIn / rebaseOptOut attr…
sparrowDom Nov 20, 2024
3d03c7b
simplify changeSupply code
sparrowDom Nov 20, 2024
fbb11a9
add storage slot gap
sparrowDom Nov 20, 2024
6d5c745
Comments update
DanielVF Nov 20, 2024
9ded07a
Comments spelling update
DanielVF Nov 20, 2024
2c6bdc2
correct comments
sparrowDom Nov 20, 2024
9436e7c
Merge remote-tracking branch 'origin/sparrowDom/rebaseElsewhere_v2' i…
sparrowDom Nov 20, 2024
f1939db
unify variable names
sparrowDom Nov 20, 2024
57c8733
make credits calculation based of off balance for higher accuracy (in…
sparrowDom Nov 20, 2024
dc803f2
minor gas optimisation
sparrowDom Nov 20, 2024
4893186
correct storage slot amount so it totals to 200
sparrowDom Nov 21, 2024
09bde1b
Improve rebasing supply accuracy V2 (#2314)
sparrowDom Nov 21, 2024
ae51bbd
gas optimisation
sparrowDom Nov 21, 2024
f03deb3
better naming
sparrowDom Nov 21, 2024
db2044a
add a test where multiple rebaseOptIn/OptOut calls do not result in i…
sparrowDom Nov 22, 2024
4495130
add a check for zero address with governanceRebaseOptIn tx
sparrowDom Nov 23, 2024
53db807
Update on rebasing
DanielVF Nov 25, 2024
948014c
add a check for zero address with governanceRebaseOptIn tx
sparrowDom Nov 23, 2024
7d7055c
Merge remote-tracking branch 'origin/sparrowDom/rebaseElsewhere_v2' i…
sparrowDom Nov 25, 2024
01b49a3
make an exception for balance exact non rebasing accounts (StdNonReba…
sparrowDom Nov 25, 2024
e355f3d
add test for the 1e27 cpt token exception
sparrowDom Nov 25, 2024
7636c99
add a test to for creditsBalanceOf and creditsBalanceOfHighres
sparrowDom Nov 25, 2024
da68531
add nonRebasingCreditsPerToken to the test
sparrowDom Nov 25, 2024
1b9d1e3
add auto migration test and revert test for rebaseOptOut
sparrowDom Nov 25, 2024
34021fb
prettier
sparrowDom Nov 26, 2024
57cccba
add tests for missing requires in yield delegation
sparrowDom Nov 26, 2024
24bf72a
simplify code
sparrowDom Nov 26, 2024
f1b5290
revert to the previous implementation of the deprecated function
sparrowDom Nov 26, 2024
20f1bd1
add OETH upgrade deployment file
sparrowDom Nov 28, 2024
7b76cb8
change license to Business Source License
sparrowDom Nov 29, 2024
dbb3434
prettier
sparrowDom Nov 29, 2024
93545c3
on changeSupply round up in the favour of the protocol
sparrowDom Nov 29, 2024
dc854bc
round down when calculating credits from balances
sparrowDom Dec 1, 2024
63ee2ba
Revert "round down when calculating credits from balances"
sparrowDom Dec 2, 2024
296f5f4
fix typos (#2323)
sparrowDom Dec 5, 2024
74bd138
gas optimisation (#2322)
sparrowDom Dec 5, 2024
040ad7a
add missing natspec (#2321)
sparrowDom Dec 5, 2024
d9c6def
L-02 Missing Docstrings (#2319)
sparrowDom Dec 5, 2024
5e57112
Correct globals storage
DanielVF Dec 10, 2024
eb957f1
Only empty accounts can rebaseOptIn if already rebasing
DanielVF Dec 17, 2024
d285b32
gas optimisation
sparrowDom Dec 17, 2024
55efcd6
remove extra new line
sparrowDom Dec 17, 2024
412e93d
Merge remote-tracking branch 'origin/master' into sparrowDom/rebaseEl…
sparrowDom Dec 17, 2024
c980607
optimise gas when setting alternativeCreditsPerToken (#2325)
sparrowDom Dec 17, 2024
07b3e70
Certora Formal Verification for OUSD (#2329)
Roy-Certora Dec 19, 2024
18d4a51
Fix certora spec. Starting with an invalid state would result in an i…
DanielVF Jan 7, 2025
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ fork-coverage
unit-coverage

.VSCodeCounter

# Certora #
.certora_internal
16 changes: 16 additions & 0 deletions certora/confs/OUSD_accounting.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"files": [
"contracts/contracts/token/OUSD.sol"
],
"msg": "OUSD Accounting invariants",
"packages": [
"@openzeppelin/contracts=contracts/lib/openzeppelin/contracts",
],
"process": "emv",
"prover_args": [

],
"solc": "solc8.28",
"verify": "OUSD:certora/specs/OUSD/AccountInvariants.spec",
"server": "production",
}
18 changes: 18 additions & 0 deletions certora/confs/OUSD_balances.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"files": [
"contracts/contracts/token/OUSD.sol"
],
"msg": "OUSD Balances invariants",
"packages": [
"@openzeppelin/contracts=contracts/lib/openzeppelin/contracts",
],
"process": "emv",
"prover_args": [
"-mediumTimeout 40",
],
"multi_assert_check":true,
"smt_timeout":"1000",
"solc": "solc8.28",
"verify": "OUSD:certora/specs/OUSD/BalanceInvariants.spec",
"server": "production"
}
17 changes: 17 additions & 0 deletions certora/confs/OUSD_other.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"files": [
"contracts/contracts/token/OUSD.sol"
],
"msg": "OUSD other invariants",
"packages": [
"@openzeppelin/contracts=contracts/lib/openzeppelin/contracts",
],
"process": "emv",
"prover_args": [
"-mediumTimeout 40",
],
"smt_timeout":"1000",
"solc": "solc8.28",
"verify": "OUSD:certora/specs/OUSD/OtherInvariants.spec",
"server": "production"
}
19 changes: 19 additions & 0 deletions certora/confs/OUSD_sumOfBalances.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"files": [
"contracts/contracts/token/OUSD.sol"
],
"msg": "OUSD Sum of balances rules",
"packages": [
"@openzeppelin/contracts=contracts/lib/openzeppelin/contracts",
],
"process": "emv",
"prover_args": [
"-mediumTimeout 40",
"-s [z3:lia2,z3:arith1,yices:def]",
],
"multi_assert_check":true,
"smt_timeout":"1000",
"solc": "solc8.28",
"verify": "OUSD:certora/specs/OUSD/SumOfBalances.spec",
"server": "production"
}
4 changes: 4 additions & 0 deletions certora/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
certoraRun certora/confs/OUSD_accounting.conf
certoraRun certora/confs/OUSD_balances.conf
certoraRun certora/confs/OUSD_other.conf
certoraRun certora/confs/OUSD_sumOfBalances.conf
158 changes: 158 additions & 0 deletions certora/specs/OUSD/AccountInvariants.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import "./common.spec";

function allAccountValidState() {
requireInvariant DelegationAccountsCorrelation();
requireInvariant DelegationValidRebaseState();
requireInvariant stdNonRebasingDoesntYield();
requireInvariant alternativeCreditsPerTokenIsOneOrZeroOnly();
requireInvariant yieldDelegationSourceHasNonZeroYeildTo();
requireInvariant yieldDelegationTargetHasNonZeroYeildFrom();
requireInvariant yieldToOfZeroIsZero();
requireInvariant yieldFromOfZeroIsZero();
requireInvariant cantYieldToSelf();
requireInvariant cantYieldFromSelf();
requireInvariant zeroAlternativeCreditsPerTokenStates();
requireInvariant nonZeroAlternativeCreditsPerTokenStates();
}

/// @title Any non zero valued YieldTo points to an account that has a YieldFrom pointing back to the starting account and vice versa.
/// @property Account Invariants
invariant DelegationAccountsCorrelation()
forall address account.
(OUSD.yieldTo[account] != 0 => (OUSD.yieldFrom[OUSD.yieldTo[account]] == account))
&&
(OUSD.yieldFrom[account] != 0 => (OUSD.yieldTo[OUSD.yieldFrom[account]] == account))
{
preserved with (env e) {
requireInvariant DelegationValidRebaseState();
requireInvariant yieldToOfZeroIsZero();
requireInvariant yieldFromOfZeroIsZero();
}
}

/// @title Any non zero valued YieldTo points to an account Iff that account is in YieldDelegationSource state and
/// Any non zero valued YieldFrom points to an account Iff that account is in YieldDelegationTarget state.
/// @property Account Invariants
invariant DelegationValidRebaseState()
forall address account.
(OUSD.yieldTo[account] != 0 <=> OUSD.rebaseState[account] == YieldDelegationSource())
&&
(OUSD.yieldFrom[account] != 0 <=> OUSD.rebaseState[account] == YieldDelegationTarget())
{
preserved with (env e) {
requireInvariant DelegationAccountsCorrelation();
requireInvariant yieldToOfZeroIsZero();
requireInvariant yieldFromOfZeroIsZero();
}
}

/// @title Any account with a zero value in alternativeCreditsPerToken has a rebaseState that is one of (NotSet, StdRebasing, or YieldDelegationTarget)
/// @property Account Invariants
invariant zeroAlternativeCreditsPerTokenStates()
forall address account . OUSD.alternativeCreditsPerToken[account] == 0 <=> (OUSD.rebaseState[account] == NotSet() ||
OUSD.rebaseState[account] == StdRebasing() ||
OUSD.rebaseState[account] == YieldDelegationTarget())
{
preserved {
requireInvariant yieldToOfZeroIsZero();
requireInvariant yieldFromOfZeroIsZero();
requireInvariant DelegationAccountsCorrelation();
requireInvariant DelegationValidRebaseState();
}
}

/// @title Any account with value of 1e18 in alternativeCreditsPerToken has a rebaseState that is one of (StdNonRebasing, YieldDelegationSource)
/// @property Account Invariants
invariant nonZeroAlternativeCreditsPerTokenStates()
forall address account . OUSD.alternativeCreditsPerToken[account] != 0 <=> (OUSD.rebaseState[account] == StdNonRebasing() ||
OUSD.rebaseState[account] == YieldDelegationSource())
{
preserved undelegateYield(address _account) with (env e) {
requireInvariant yieldToOfZeroIsZero();
requireInvariant yieldFromOfZeroIsZero();
requireInvariant DelegationAccountsCorrelation();
requireInvariant DelegationValidRebaseState();
}
}

/// @title The result of balanceOf of any account in StdNonRebasing state equals the account's credit-balance.
/// @property Balance Invariants
invariant stdNonRebasingBalanceEqCreditBalances(address account)
OUSD.rebaseState[account] == StdNonRebasing() => OUSD.balanceOf(account) == OUSD.creditBalances[account]
{
preserved {
requireInvariant yieldToOfZeroIsZero();
requireInvariant yieldFromOfZeroIsZero();
requireInvariant DelegationAccountsCorrelation();
requireInvariant DelegationValidRebaseState();
requireInvariant nonZeroAlternativeCreditsPerTokenStates();
requireInvariant stdNonRebasingDoesntYield();
requireInvariant alternativeCreditsPerTokenIsOneOrZeroOnly();
}
}

/// @title Any account in StdNonRebasing state doesn't yield to no account.
/// @property Account Invariants
invariant stdNonRebasingDoesntYield()
forall address account . OUSD.rebaseState[account] == StdNonRebasing() => OUSD.yieldTo[account] == 0
{
preserved {
requireInvariant yieldToOfZeroIsZero();
requireInvariant yieldFromOfZeroIsZero();
requireInvariant DelegationAccountsCorrelation();
requireInvariant DelegationValidRebaseState();
}
}

/// @title alternativeCreditsPerToken can only be set to 0 or 1e18, no other values
/// @property Account Invariants
invariant alternativeCreditsPerTokenIsOneOrZeroOnly()
forall address account . OUSD.alternativeCreditsPerToken[account] == 0 || OUSD.alternativeCreditsPerToken[account] == e18();

/// @title Any account with rebaseState = YieldDelegationSource has a nonZero yieldTo
/// @property Account Invariants
invariant yieldDelegationSourceHasNonZeroYeildTo()
forall address account . OUSD.rebaseState[account] == YieldDelegationSource() => OUSD.yieldTo[account] != 0;

/// @title Any account with rebaseState = YieldDelegationTarget has a nonZero yieldFrom
/// @property Account Invariants
invariant yieldDelegationTargetHasNonZeroYeildFrom()
forall address account . OUSD.rebaseState[account] == YieldDelegationTarget() => OUSD.yieldFrom[account] != 0;

// Helper Invariants
/// @title yieldTo of zero is zero
/// @property Account Invariants
invariant yieldToOfZeroIsZero()
yieldTo(0) == 0;

/// @title yieldFrom of zero is zero
/// @property Account Invariants
invariant yieldFromOfZeroIsZero()
yieldFrom(0) == 0;

/// @title yieldTo of an account can't be the same as the account
/// @property Account Invariants
invariant cantYieldToSelf()
forall address account . OUSD.yieldTo[account] != 0 => OUSD.yieldTo[account] != account;

/// @title yieldFrom of an account can't be the same as the account
/// @property Account Invariants
invariant cantYieldFromSelf()
forall address account . OUSD.yieldFrom[account] != 0 => OUSD.yieldFrom[account] != account;

/// @title Only delegation changes the different effective identity.
/// @property Account Invariants
rule onlyDelegationChangesPairingState(address accountA, address accountB, method f)
filtered{f -> !f.isView}
{
bool different_before = differentAccounts(accountA, accountB);
env e;
calldataarg args;
f(e, args);
bool different_after = differentAccounts(accountA, accountB);

if(delegateMethods(f)) {
satisfy different_before != different_after;
}
assert different_before != different_after => delegateMethods(f);
}
Loading
Loading