From 19756cdbe8507d888b698d48c2f6d670725fd7db Mon Sep 17 00:00:00 2001 From: emilio Date: Mon, 19 Oct 2020 18:29:32 +0200 Subject: [PATCH] fixed PVE001, PVE009(1) --- .../LendingPoolAddressesProviderRegistry.sol | 2 ++ .../lendingpool/LendingPoolConfigurator.sol | 26 +++++++++++++++++-- contracts/libraries/helpers/Errors.sol | 10 +++++-- .../interfaces/ITokenConfiguration.sol | 13 ++++++++++ helpers/contracts-helpers.ts | 1 - helpers/types.ts | 1 + test/addresses-provider-registry.spec.ts | 9 +++++++ 7 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 contracts/tokenization/interfaces/ITokenConfiguration.sol diff --git a/contracts/configuration/LendingPoolAddressesProviderRegistry.sol b/contracts/configuration/LendingPoolAddressesProviderRegistry.sol index f8dfb629..77c260bf 100644 --- a/contracts/configuration/LendingPoolAddressesProviderRegistry.sol +++ b/contracts/configuration/LendingPoolAddressesProviderRegistry.sol @@ -54,6 +54,8 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP * @param provider the pool address to be registered **/ function registerAddressesProvider(address provider, uint256 id) external override onlyOwner { + require(id != 0, Errors.INVALID_ADDRESSES_PROVIDER_ID); + _addressesProviders[provider] = id; _addToAddressesProvidersList(provider); emit AddressesProviderRegistered(provider); diff --git a/contracts/lendingpool/LendingPoolConfigurator.sol b/contracts/lendingpool/LendingPoolConfigurator.sol index 8f154e23..c3da634c 100644 --- a/contracts/lendingpool/LendingPoolConfigurator.sol +++ b/contracts/lendingpool/LendingPoolConfigurator.sol @@ -10,6 +10,7 @@ import { import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol'; import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol'; import {ILendingPool} from '../interfaces/ILendingPool.sol'; +import {ITokenConfiguration} from '../tokenization/interfaces/ITokenConfiguration.sol'; import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol'; import {Errors} from '../libraries/helpers/Errors.sol'; import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol'; @@ -200,7 +201,6 @@ contract LendingPoolConfigurator is VersionedInitializable { /** * @dev initializes a reserve - * @param asset the address of the reserve to be initialized * @param aTokenImpl the address of the aToken contract implementation * @param stableDebtTokenImpl the address of the stable debt token contract * @param variableDebtTokenImpl the address of the variable debt token contract @@ -208,13 +208,35 @@ contract LendingPoolConfigurator is VersionedInitializable { * @param interestRateStrategyAddress the address of the interest rate strategy contract for this reserve **/ function initReserve( - address asset, address aTokenImpl, address stableDebtTokenImpl, address variableDebtTokenImpl, uint8 underlyingAssetDecimals, address interestRateStrategyAddress ) public onlyAaveAdmin { + address asset = ITokenConfiguration(aTokenImpl).UNDERLYING_ASSET_ADDRESS(); + + require( + address(pool) == ITokenConfiguration(aTokenImpl).POOL(), + Errors.INVALID_ATOKEN_POOL_ADDRESS + ); + require( + address(pool) == ITokenConfiguration(stableDebtTokenImpl).POOL(), + Errors.INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS + ); + require( + address(pool) == ITokenConfiguration(variableDebtTokenImpl).POOL(), + Errors.INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS + ); + require( + asset == ITokenConfiguration(stableDebtTokenImpl).UNDERLYING_ASSET_ADDRESS(), + Errors.INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS + ); + require( + asset == ITokenConfiguration(variableDebtTokenImpl).UNDERLYING_ASSET_ADDRESS(), + Errors.INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS + ); + address aTokenProxyAddress = _initTokenWithProxy(aTokenImpl, underlyingAssetDecimals); address stableDebtTokenProxyAddress = _initTokenWithProxy( diff --git a/contracts/libraries/helpers/Errors.sol b/contracts/libraries/helpers/Errors.sol index ee71efaa..985a2bc3 100644 --- a/contracts/libraries/helpers/Errors.sol +++ b/contracts/libraries/helpers/Errors.sol @@ -50,8 +50,8 @@ library Errors { string public constant CALLER_MUST_BE_LENDING_POOL = '28'; // 'The caller of this function must be a lending pool' string public constant CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself' string public constant TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero' - string public constant INVALID_MINT_AMOUNT = '53'; //invalid amount to mint - string public constant INVALID_BURN_AMOUNT = '54'; //invalid amount to burn + string public constant INVALID_MINT_AMOUNT = '61'; //invalid amount to mint + string public constant INVALID_BURN_AMOUNT = '62'; //invalid amount to burn // require error messages - ReserveLogic string public constant RESERVE_ALREADY_INITIALIZED = '34'; // 'Reserve has already been initialized' @@ -64,9 +64,15 @@ library Errors { //require error messages - LendingPoolConfiguration string public constant CALLER_NOT_AAVE_ADMIN = '35'; // 'The caller must be the aave admin' string public constant RESERVE_LIQUIDITY_NOT_0 = '36'; // 'The liquidity of the reserve needs to be 0' + string public constant INVALID_ATOKEN_POOL_ADDRESS = '63'; // the lending pool in the aToken implementation is not configured correctly + string public constant INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = '64'; // the lending pool in the stable debt token implementation is not configured correctly + string public constant INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS = '65'; // the lending pool in the variable debt token implementation is not configured correctly + string public constant INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '66'; // the underlying asset in the stable debt token implementation is not configured correctly + string public constant INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '67'; // the underlying asset in the variable debt token implementation is not configured correctly //require error messages - LendingPoolAddressesProviderRegistry string public constant PROVIDER_NOT_REGISTERED = '37'; // 'Provider is not registered' + string public constant INVALID_ADDRESSES_PROVIDER_ID = '68'; // the addresses provider id needs to be greater than 0 //return error messages - LendingPoolCollateralManager string public constant HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '38'; // 'Health factor is not below the threshold' diff --git a/contracts/tokenization/interfaces/ITokenConfiguration.sol b/contracts/tokenization/interfaces/ITokenConfiguration.sol new file mode 100644 index 00000000..50eb3b09 --- /dev/null +++ b/contracts/tokenization/interfaces/ITokenConfiguration.sol @@ -0,0 +1,13 @@ +pragma solidity ^0.6; + +/** + * @title ITokenConfiguration + * @author Aave + * @dev common interface between aTokens and debt tokens to fetch the + * token configuration + **/ +interface ITokenConfiguration { + function UNDERLYING_ASSET_ADDRESS() external view returns (address); + + function POOL() external view returns (address); +} diff --git a/helpers/contracts-helpers.ts b/helpers/contracts-helpers.ts index 77730b04..62afaa35 100644 --- a/helpers/contracts-helpers.ts +++ b/helpers/contracts-helpers.ts @@ -857,7 +857,6 @@ export const initReserves = async ( console.log('init reserve currency ', assetSymbol); await lendingPoolConfigurator.initReserve( - tokenAddress, aToken.address, stableDebtToken.address, variableDebtToken.address, diff --git a/helpers/types.ts b/helpers/types.ts index 0b5e4a33..f2682691 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -106,6 +106,7 @@ export enum ProtocolErrors { //require error messages - LendingPoolAddressesProviderRegistry PROVIDER_NOT_REGISTERED = '37', // 'Provider is not registered' + INVALID_ADDRESSES_PROVIDER_ID = '68', //return error messages - LendingPoolCollateralManager HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '38', // 'Health factor is not below the threshold' diff --git a/test/addresses-provider-registry.spec.ts b/test/addresses-provider-registry.spec.ts index 457514e4..5630591d 100644 --- a/test/addresses-provider-registry.spec.ts +++ b/test/addresses-provider-registry.spec.ts @@ -18,6 +18,15 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => { ); }); + it('tries to register an addresses provider with id 0', async () => { + const {users, registry} = testEnv; + const {INVALID_ADDRESSES_PROVIDER_ID} = ProtocolErrors; + + await expect(registry.registerAddressesProvider(users[2].address, '0')).to.be.revertedWith( + INVALID_ADDRESSES_PROVIDER_ID + ); + }); + it('Registers a new mock addresses provider', async () => { const {users, registry} = testEnv;