From 5fe62661d33403d44981817b69e0aeea09fa0aac Mon Sep 17 00:00:00 2001 From: Andrei Kozlov Date: Tue, 21 May 2024 14:35:02 +0300 Subject: [PATCH] Allow only uniquie assets at the flashloans --- .../libraries/logic/ValidationLogic.sol | 3 +++ tests/core/Pool.FlashLoans.t.sol | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/core/contracts/protocol/libraries/logic/ValidationLogic.sol b/src/core/contracts/protocol/libraries/logic/ValidationLogic.sol index 2486db31..4d577133 100644 --- a/src/core/contracts/protocol/libraries/logic/ValidationLogic.sol +++ b/src/core/contracts/protocol/libraries/logic/ValidationLogic.sol @@ -471,6 +471,9 @@ library ValidationLogic { ) internal view { require(assets.length == amounts.length, Errors.INCONSISTENT_FLASHLOAN_PARAMS); for (uint256 i = 0; i < assets.length; i++) { + for (uint256 j = i + 1; j < assets.length; j++) { + require(assets[i] != assets[j], Errors.INCONSISTENT_FLASHLOAN_PARAMS); + } validateFlashloanSimple(reservesData[assets[i]], amounts[i]); } } diff --git a/tests/core/Pool.FlashLoans.t.sol b/tests/core/Pool.FlashLoans.t.sol index ea9c2e84..60985f9f 100644 --- a/tests/core/Pool.FlashLoans.t.sol +++ b/tests/core/Pool.FlashLoans.t.sol @@ -144,6 +144,30 @@ contract PoolFlashLoansTests is TestnetProcedures { ); } + function test_reverts_flashLoan_same_asset_more_then_once(uint8 length) public { + vm.assume(length > 1); + bytes memory emptyParams; + address[] memory assets = new address[](length); + uint256[] memory amounts = new uint256[](length); + uint256[] memory modes = new uint256[](length); + for (uint256 i = 0; i < length; i++) { + assets[i] = tokenList.weth; + amounts[i] = 1; + } + + vm.expectRevert(bytes(Errors.INCONSISTENT_FLASHLOAN_PARAMS)); + vm.prank(alice); + contracts.poolProxy.flashLoan( + address(mockFlashReceiver), + assets, + amounts, + modes, + alice, + emptyParams, + 0 + ); + } + function test_reverts_flashLoan_simple_invalid_return() public { bytes memory emptyParams;