code-423n4 / 2021-09-yaxis-findings

0 stars 0 forks source link

Caching storage pointer in `removeToken` #96

Closed code423n4 closed 3 years ago

code423n4 commented 3 years ago

Handle

hrkrshnn

Vulnerability details

Caching storage pointer in removeToken

Caching the storage pointer tokens[_vault] will save gas.

modified   contracts/v3/Manager.sol
@@ -465,12 +465,13 @@ contract Manager is IManager {
         notHalted
         onlyStrategist
     {
-        uint256 k = tokens[_vault].length;
+        address[] storage tokensArray = tokens[_vault];
+        uint256 k = tokensArray.length;
         uint256 index;
         bool found;

         for (uint i = 0; i < k; i++) {
-            if (tokens[_vault][i] == _token) {
+            if (tokensArray[i] == _token) {
                 index = i;
                 found = true;
                 break;
Haz077 commented 3 years ago

Caching tokens[_vault] will not save gas.

GalloDaSballo commented 3 years ago

Personally not sure as the finding is very bare bones, will agree with sponsor due to lack of evidence