You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for (uint i = 0; i < arr.length; i++) {
//Operations not effecting the length of the array.
}
Loading length of array costs gas. Therefore, the length should be cached, if the length of the array doesn't change inside the loop. Furthermore, there is no need to assign the initial value 0. This csts extra gas.
Recommended implementation:
uint length = arr.length;
for (uint i; i < length; ++i) {
//Operations not effecting the length of the array.
}
By doing so the length is only loaded once rather than loading it as many times as iterations (Therefore, less gas is spent).
Occurences
./basket/contracts/callManagers/RebalanceManager.sol:218: for (uint256 i; i < _swapsV2.length; i++) {
./basket/contracts/callManagers/RebalanceManager.sol:234: for (uint256 i; i < _swapsV3.length; i++) {
./basket/contracts/callManagers/RebalanceManagerV2.sol:155: for (uint256 i; i < _swapsV2.length; i++) {
./basket/contracts/callManagers/RebalanceManagerV3.sol:166: for (uint256 i; i < _swapsV2.length; i++) {
./basket/contracts/callManagers/RebalanceManagerV3.sol:171: for (uint256 j; j < trade.swaps.length; j++) {
./basket/contracts/facets/Basket/BasketFacet.sol:50: for (uint256 i; i < bs.tokens.length; i++) {
./basket/contracts/facets/Basket/BasketFacet.sol:160: for (uint256 i; i < bs.tokens.length; i++) {
./basket/contracts/facets/Basket/BasketFacet.sol:202: for (uint256 i; i < bs.tokens.length; i++) {
./basket/contracts/facets/Basket/BasketFacet.sol:321: for (uint256 i = 0; i < tokens.length; i++) {
./basket/contracts/facets/Basket/BasketFacet.sol:348: for (uint256 i; i < bs.tokens.length; i++) {
./basket/contracts/facets/Basket/BasketFacet.sol:381: for (uint256 i; i < bs.tokens.length; i++) {
./basket/contracts/facets/Call/CallFacet.sol:55: for (uint256 i = 0; i < callStorage.callers.length; i++) {
./basket/contracts/facets/Call/CallFacet.sol:82: for (uint256 i = 0; i < _targets.length; i++) {
./basket/contracts/facets/Call/CallFacet.sol:95: for (uint256 i = 0; i < _targets.length; i++) {
./basket/contracts/factories/PieFactoryContract.sol:88: for (uint256 i = 0; i < _tokens.length; i++) {
./basket/contracts/singleJoinExit/SingleNativeTokenExit.sol:69: for (uint256 i; i < tokens.length; i++) {
./basket/contracts/singleJoinExit/SingleNativeTokenExitV2.sol:74: for (uint256 i; i < _exitTokenStruct.trades.length; i++) {
./basket/contracts/singleJoinExit/SingleNativeTokenExitV2.sol:76: for (uint256 j; j < trade.swaps.length; j++) {
./basket/contracts/singleJoinExit/SingleTokenJoin.sol:108: for (uint256 i; i < tokens.length; i++) {
./basket/contracts/singleJoinExit/SingleTokenJoinV2.sol:86: for (uint256 i; i < _joinTokenStruct.trades.length; i++) {
./basket/contracts/singleJoinExit/SingleTokenJoinV2.sol:91: for (uint256 j; j < trade.swaps.length; j++) {
./basket/contracts/singleJoinExit/SingleTokenJoinV2.sol:100: for (uint256 j; j < trade.swaps.length; j++) {
./basket/contracts/singleJoinExit/SingleTokenJoinV2.sol:117: for (uint256 i; i < tokens.length; i++) {
The text was updated successfully, but these errors were encountered:
Handle
0x0x0x
Vulnerability details
Proof of Concept
Example:
Loading length of array costs gas. Therefore, the length should be cached, if the length of the array doesn't change inside the loop. Furthermore, there is no need to assign the initial value 0. This csts extra gas.
Recommended implementation:
By doing so the length is only loaded once rather than loading it as many times as iterations (Therefore, less gas is spent).
Occurences
The text was updated successfully, but these errors were encountered: