This document describes the specification and verification of Aave's V3 protocol using the Certora Prover. The work was undertaken from Nov. 12, 2021 to Jan. 24, 2022. The latest commit that was reviewed and ran through the Certora Prover was a87d546
.
The scope of this verification is Aave's governance system, particularly the following contracts:
StableDebtToken.sol
( Verification Results
)VariableDebtToken.sol
( Verification Results
)Atoken.sol
(Verification Results
)ReserveConfiguration.sol
(Verification Results
)UserConfiguration.sol
(Verification Results
)And partial verificaiton of:
The Certora Prover proved the implementation of the protocol is correct with respect to formal specifications written by the the Certora team. The team also performed a manual audit of these contracts.
The specification program was modularized to optimize coverage. First, the tokenization contracts were found to uphold to the same properties the Aave V2 tokenization did, as well as additional properties. On the main Pool contract, the focus of the verification was the protocol's storage of its reserves data, their classification to EModes - a new feature of the V3 protocol - and its compatibility with the user's action. This was done by modularly checking the userConfiguration and reservesConfiguration libraries first.
The resulting specification files are available on Aave's public git repository.
Severity: Critical
Issue: | Loss of assets |
---|---|
Description: | RepayWithATokens function lacks an HF check, can be exploited to withdraw liquidity from the system for free. |
Mitigation/Fix: | Canceled repayment with ATokens on behalf of another user |
Property violated: | Any Operation Should Preserve User's HF>1 |
Severity: High
Issue: | Risk Exposure |
---|---|
Description: | User can come to hold both an isolated and a non-isolated assets as collaterals upon calling AToken.transfer(), liquidation call and mintUnbacked(). Can be exploited to surpass the debt ceiling |
Mitigation/Fix: | A check for isolation mode was added to the functions |
Property violated: | A User Can't Hold Both an Isolated and non-Isolated Assets as Collaterals |
Severity: High
Issue: | Loss of assets |
---|---|
Description: | Confusion of Asset and EMode price feed for liquidations |
Mitigation/Fix: | Price Sources are called according to EMode |
Property violated: | Emode source price usage |
Severity: Medium
Issue: | Loss of Users' Profitability |
---|---|
Description: | EMode liquidation may use wrong liquidation bonus |
Mitigation/Fix: | Bonus rewarded correctly according to EMode |
Severity: Medium
Issue: | Loss of revenue |
---|---|
Description: | When repaying with aToken, the interest rate is updated as if we provided the equivalent liquidity in underlying instead of in AToken. In fact there’s no liquidity provided to the system. It can be used to manipulate the interest rates. |
Mitigation/Fix: | Call to rates updating function was changed to use 0 as the added liquidity |
Rule Coverage: | No Change in Underlying's Balance Implies No Change in rate |
Severity: Low
Issue: | Integrity of ReserveList |
---|---|
Description: | _addReserveToList function will push a new reserve into all empty spots of the reserves list, instead of just the first one |
Mitigation/Fix: | A return call was inserted to the loop |
Rule Coverage: | The same asset should not appear twice on the reserves list |
Severity: Recommendation
Issue: | Denial of Service |
---|---|
Description: | Users can be forced into isolation mode through supply(),AToken.transfer() functions, thus temporarily preventing them from borrowing other assets |
Property violated: | Informative Rule: Check which functions can revert for one user due to another user's action |
Mitagation/Fix: | User can withdraw asset of isolation mode |
The Certora Prover takes as input a contract and a specification and formally proves that the contract satisfies the specification in all scenarios. Importantly, the guarantees of the Certora Prover are scoped to the provided specification, and the Certora Prover does not check any cases not covered by the specification.
We hope that this information is useful, but provide no warranty of any kind, explicit or implied. The contents of this report should not be construed as a complete guarantee that the contract is secure in all dimensions. In no event shall Certora or any of its employees be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the results reported here.
Aave is a decentralized non-custodial liquidity markets protocol where users can participate as suppliers or borrowers. Suppliers provide liquidity to the market to earn a passive income, while borrowers are able to borrow in an overcollateralized (perpetually) or undercollateralized (one-block liquidity) fashion.
The specification contains six files, three for the tokenization part, one for the pool and one for each of the reserve and user configuration contracts. The tokens' contracts have similar specifications, using (up to slight modifications) properties based on Certora's aggregated experience with ERC20 verificartion.
On the main Pool contract, the focus of the coverage was the protocol's storage of its reserves data, their classification to EModes - a new feature of the V3 protocol - and its compatibility with the user's action. This was done by modularly checking the userConfiguration and reservesConfiguration libraries first.
We made the following assumptions during the verification process:
✔️ indicates the rule is formally verified on the latest reviewed commit. Footnotes describe any simplifications or assumptions used while verifying the rules (beyond the general assumptions listed above).
In this document, verification conditions are either shown as logical formulas or Hoare triples of the form {p} C {q}. A verification condition given by a logical formula denotes an invariant that holds if every reachable state satisfies the condition.
Hoare triples of the form {p} C {q} holds if any non-reverting execution of program C that starts in a state satsifying the precondition p ends in a state satisfying the postcondition q. The notation {p} C@withrevert {q} is similar but applies to both reverting and non-reverting executions. Preconditions and postconditions are similar to the Solidity require and assert statements.
Formulas relate the results of method calls. In most cases, these methods are getters defined in the contracts, but in some cases they are getters we have added to our harness or definitions provided in the rules file. Undefined variables in the formulas are treated as arbitrary: the rule is checked for every possible value of the variables.
getUserLastUpdated(user) <= currentBlock.timestamp
{ A!= B && balanceA == balanceOf(A) && balanceB == balanceOf(B) }
op ;
{ balanceOf(A) == balanceA || balanceOf(B) == balanceB }
where op
is any operation
{ balanceA == balanceOf(A) && total == totalSupply() }
op ;
{ balanceOf(A) != balanceA => balanceOf(A) - balanceA == totalSupply() - total };
burn(user,x);burn(user,y);
~
burn(user,x+y)
{ b == balanceOf(user) }
mint(delegatedUser,user,x,index);
{ balanceOf(user) == b+x }
{ b == balanceOf(user) }
burn(user,x)
{ balanceOf(user) == b-x }
{ b == balanceOf(user) }
mint(delegatedUser,user,x,index); burn(user, x)
{ balanceOf(user) == b }
{ A!= B && balanceA == balanceOf(A) && balanceB == balanceOf(B) }
op ;
{ balanceOf(A) == balanceA || balanceOf(B) == balanceB }
{ balanceA == balanceOf(A) && total == totalSupply() }
op ;
{ balanceOf(A) != balanceA => balanceOf(A) - balanceA == totalSupply() - total };
{ total == totalSupply() }
op ;
{ totalSupply() != total => msg.sender == pool && (op == mint() || op == burn()) };
{ b == balanceOf(user) }
mint(delegatedUser,user,amount,index); burn(user, amount, index)
{ balanceOf(user) == b }
burn(u, u’, x); burn(u, u’, y) ~ burn(u, u’, x+y) at the same timestamp
{ b = balanceOf(u) }
mint(u,x)
{ balanceOf(u) == b + x }
{ other != user && bb = balanceOf(other) }
burn(user, amount, index)
{ balanceOf(other) == bb }
{ other != user && bbo = balanceOf(other) && bbu = balanceOf(user) }
mint(user, onBehalfOf, amount, index)
{ balanceOf(other) == bbo && (user != onBehalfOf => balanceOf(user) == bbu) }
{ b = balanceOf(user) }
burn(user, 0, index)
{ balanceOf(user) == b }
{ A != B != C && balanceA == balanceOf(A) && balanceB == balanceOf(B) && balanceC == balanceOf(C) }
op ;
{ balanceOf(A) == balanceA || balanceOf(B) == balanceB || balanceOf(C) == balanceC }
{ b == balanceOf(u) }
mint(u,x)
{ b + x - ε ≤ balanceOf(u) ≤ b + x + ε }
mint(u,x); mint(u,y) ~ mint(u,x+y)
with resepct to balanceOf(u) up to some ε
{ }
mint(caller, user, amount, index)
{ amount == 0 => REVERT }
I.
{ u ≠ u’ ∧ bu = balanceOf(u) ∧ bu’ = balanceOf(u’) }
transfer(u, u’ x);
{ | balanceOf(u) - (bu - x) | ≤ ε ∧
| balanceOf(u’) - (bu’ + x) | ≤ ε }
II.
{ b = underlyingAssetBalanceOf(u’’) }
transfer(u, u’ x);
{ b = underlyingAssetBalanceOf(u’’) }
{ f1 != f2, t1 != t2, f2 != t1, f1 != t2, f1 == t1 <=> f2 == t2,
balanceOf(f1) == balanceOf(f2), balanceOf(t1) == balanceOf(t2) }
transfer(f1, t1, x), transfer(f1, t1, y), transfer(f2, t2, x+y)
{ |balanceOf(f1) - balanceOf(f2)| ≤ 3ε, |balanceOf(t1) - balanceOf(t2)| ≤ 3ε }
{ bu = balanceOf(u) ∧ ba = underlyingAssetBalanceOf(u’) }
burn(u, u’, x)
{ | balanceOf(u) - (bu - x) | ≤ ε ∧
u’ ≠ AToken ⇒ | underlyingAssetBalanceOf(u’) - (ba + x) | ≤ ε }
burn(u, u’, x); burn(u, u’, y) ~ burn(u, u’, x+y) at the same timestamp
{ other != user, other != recieverOfUnderlying,
db = additionalData(other), bb = balanceOf(other)}
burn(user, recieverOfUnderlying, amount, index)
{ additionalData(other) == db && balanceOf(other) == bb }
{ other != user, db = additionalData(other), bb = balanceOf(other) }
mint(caller, user, amount, index)
{ additionalData(other) == db && balanceOf(other) == bb }
{ r = ReserveConfiguration, x = some member of r }
setX(r, y)
{ getX(r) == y }
{ r = ReserveConfiguration, x = some member of r, x' = another member of r }
setX(r, y)
{ getX'(r) == x' }
{isEmpty => !isBorrowingAny() && !isUsingAsCollateralOrBorrowing(reserveIndex) }
{ (isBorrowingAny() || isUsingAsCollateral(reserveIndex)) => !isEmpty() }
{ isBorrowing(reserveIndex) => isBorrowingAny() }
(isUsingAsCollateral(reserveIndex) || isBorrowing(reserveIndex))
<=> isUsingAsCollateralOrBorrowing(reserveIndex)
!isUsingAsCollateralOne() => !isIsolated()
{ reserveIndex < 128 }
setBorrowing(reserveIndex, borrowing)
{ isBorrowing(reserveIndex) == borrowing }
{ reserveIndex < 128 }
setUsingAsCollateral(reserveIndex, usingAsCollateral)
{ isUsingAsCollateral(reserveIndex) == usingAsCollateral }
{ reserveIndexOther != reserveIndex && reserveIndexOther < 128 &&
reserveIndex < 128 &&
otherReserveBorrowing == isBorrowing(reserveIndexOther) &&
otherReserveCollateral == isUsingAsCollateral(reserveIndexOther) }
setBorrowing(reserveIndex, borrowing)
{ otherReserveBorrowing == isBorrowing(reserveIndexOther) &&
otherReserveCollateral == isUsingAsCollateral(reserveIndexOther) }
{ reserveIndexOther != reserveIndex &&
reserveIndexOther < 128 && reserveIndex < 128 &&
otherReserveBorrowing = isBorrowing(reserveIndexOther) &&
otherReserveCollateral = isUsingAsCollateral(reserveIndexOther) }
setUsingAsCollateral(reserveIndex, isUsingAsCollateral)
{ otherReserveBorrowing == isBorrowing(reserveIndexOther) &&
otherReserveCollateral == isUsingAsCollateral(reserveIndexOther) }
{ reserves[asset].aToken.totalSupply() <= reserves[asset].supplyCap() }
** rule times-out for some functions
{ }
setUserEMode(category)
{ getUserEMode() == category }
{ }
setUserEMode(0);
{ NOTREVERT }
{ r = _reserves[asset].configuration && a = r.getActive() &&
f = r.getFrozen() && p = r.getPaused() && b = r.getBorrowingEnabled() &&
s = r.getStableRateBorrowingEnabled() }
borrow(asset, amount, interestRateMode, referralCode, onBehalfOf)
{ a && !f && !p && b && (interestRateMode == 1 => s) }
reservesCount()
is monotonic ✔️{ rb = reservesCount() }
op
{ reservesCount() >= rb }
{ rb1 = getReserveConfiguration(asset1)
&& rb2 = getReserveConfiguration(asset2)}
op
{ asset1 != asset2 => (rb1 == getReserveConfiguration(asset1)
|| rb2 == getReserveConfiguration(asset2)) }
{getReserveList(i) != 0 => i < reservesCount()}
I.
{(i != 0 and token != 0) => (getReserveList(i) == token
<=> getReserveDataIndex(token) == i)}
II.
{(i == 0 and token != 0) => (getReserveList(i) == token
=> getReserveDataIndex(token) == i)}