From b5162aa3b2fb60931e23d75537a6d915838a447c Mon Sep 17 00:00:00 2001 From: Jun Kim <64379343+junkim012@users.noreply.github.com> Date: Tue, 9 Jul 2024 09:25:19 +0200 Subject: [PATCH] fix: save array length to the stack --- src/vault/Vault.sol | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/vault/Vault.sol b/src/vault/Vault.sol index 4b82c1c0..bf3b09b6 100644 --- a/src/vault/Vault.sol +++ b/src/vault/Vault.sol @@ -184,7 +184,8 @@ contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, Reentrancy { if (marketsToAdd.length != allocationCaps.length) revert MarketsAndAllocationCapLengthMustBeEqual(); - for (uint256 i; i != marketsToAdd.length;) { + uint256 marketsToAddLength = marketsToAdd.length; + for (uint256 i; i != marketsToAddLength;) { IIonPool pool = marketsToAdd[i]; if (pool != IDLE) { @@ -229,7 +230,8 @@ contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, Reentrancy external onlyRole(OWNER_ROLE) { - for (uint256 i; i != marketsToRemove.length;) { + uint256 marketsToRemoveLength = marketsToRemove.length; + for (uint256 i; i != marketsToRemoveLength;) { IIonPool pool = marketsToRemove[i]; if (pool == IDLE) { @@ -333,9 +335,10 @@ contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, Reentrancy external onlyRole(OWNER_ROLE) { - if (ionPools.length != newCaps.length) revert IonPoolsArrayAndNewCapsArrayMustBeOfEqualLength(); + uint256 ionPoolsLength = ionPools.length; + if (ionPoolsLength != newCaps.length) revert IonPoolsArrayAndNewCapsArrayMustBeOfEqualLength(); - for (uint256 i; i != ionPools.length;) { + for (uint256 i; i != ionPoolsLength;) { IIonPool pool = ionPools[i]; if (!supportedMarkets.contains(address(pool))) revert MarketNotSupported(pool); caps[pool] = newCaps[i]; @@ -365,7 +368,9 @@ contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, Reentrancy uint256 totalWithdrawn; uint256 currentIdleDeposits = BASE_ASSET.balanceOf(address(this)); - for (uint256 i; i != allocations.length;) { + + uint256 allocationsLength = allocations.length; + for (uint256 i; i != allocationsLength;) { MarketAllocation calldata allocation = allocations[i]; IIonPool pool = allocation.pool; @@ -797,6 +802,8 @@ contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, Reentrancy } function _maxDeposit() internal view returns (uint256 maxDepositable) { + uint256 supportedMarketsLength = supportedMarkets.length(); + for (uint256 i; i != supportedMarkets.length();) { IIonPool pool = IIonPool(supportedMarkets.at(i));