code-423n4 / 2021-12-mellow-findings

0 stars 0 forks source link

`++i` is more efficient than `i++` #94

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

Using ++i is more gas efficient than i++, especially in for loops.

We suggest to use unchecked {++i} to even better gas performance.

For example:

https://github.com/code-423n4/2021-12-mellow/blob/6679e2dd118b33481ee81ad013ece4ea723327b5/mellow-vaults/contracts/AaveVault.sol#L52-L52

for (uint256 i = 0; i < _tvls.length; i++) {

https://github.com/code-423n4/2021-12-mellow/blob/6679e2dd118b33481ee81ad013ece4ea723327b5/mellow-vaults/contracts/AaveVault.sol#L68-L68

for (uint256 i = 0; i < _aTokens.length; i++) {

https://github.com/code-423n4/2021-12-mellow/blob/6679e2dd118b33481ee81ad013ece4ea723327b5/mellow-vaults/contracts/AaveVault.sol#L86-L86

for (uint256 i = 0; i < _aTokens.length; i++) {

https://github.com/code-423n4/2021-12-mellow/blob/6679e2dd118b33481ee81ad013ece4ea723327b5/mellow-vaults/contracts/AaveVault.sol#L37-L37

for (uint256 i = 0; i < _vaultTokens.length; i++) {

https://github.com/code-423n4/2021-12-mellow/blob/6679e2dd118b33481ee81ad013ece4ea723327b5/mellow-vaults/contracts/ERC20Vault.sol#L93-L93

for (uint256 i = 0; i < tokens.length; i++) {
0xleastwood commented 2 years ago

duplicate of #54