hats-finance / Tokemak-0x4a2d708ea6b0c04186ecb774cfad1e50fb5efc0b

0 stars 0 forks source link

Incorrect condition for `lookback3InDays` in `validate()` #22

Open hats-bug-reporter[bot] opened 7 months ago

hats-bug-reporter[bot] commented 7 months ago

Github username: @0xRizwan Twitter username: 0xRizwann Submission hash (on-chain): 0x1179dc69a49592d03a7c836e94c93ccd6cef156d9cd3565600d248bc63ef62bc Severity: low

Description: Description\

Per docs, 30-60-90 NAV Test or LookBack Test is a test conducted on the NAV (per unit or token) of the LMP. Swapping costs should be carefully monitored to provide positive value to the LMP. The 30 followed by 60, 90 day test is meant to allow enough time for the LMP to earn back the swap costs.

The max number of days are 90 days,

    uint8 internal constant MAX_NAV_TRACKING = 91;

and in LMPStrategyConfig.validate() where the below conditions are checked so that it should not be more than MAX_NAV_TRACKING

    function validate(StrategyConfig memory config) internal pure {

   . . . some code 

        if (
            config.navLookback.lookback1InDays >= NavTracking.MAX_NAV_TRACKING
                || config.navLookback.lookback2InDays >= NavTracking.MAX_NAV_TRACKING
                || config.navLookback.lookback3InDays >       
NavTracking.MAX_NAV_TRACKING                              @audit, should be >=
        ) {
            revert InvalidConfig("navLookbackInDays");
        }

   . . . some code 

    }
}

It can be seen, config.navLookback.lookback1InDays and config.navLookback.lookback2InDays is correctly checked, however, config.navLookback.lookback3InDays considers only greater than MAX_NAV_TRACKING which means it considers 91 days inclusive which is not as per design as the max is 90 days.

Recommendations\ Replace > with >= while checking for config.navLookback.lookback3InDays in LMPStrategyConfig.validate(),

For example:


    function validate(StrategyConfig memory config) internal pure {

   . . . some code 

        if (
            config.navLookback.lookback1InDays >= NavTracking.MAX_NAV_TRACKING
                || config.navLookback.lookback2InDays >= NavTracking.MAX_NAV_TRACKING
-                || config.navLookback.lookback3InDays >  
+               || config.navLookback.lookback3InDays >=       
NavTracking.MAX_NAV_TRACKING                              
        ) {
            revert InvalidConfig("navLookbackInDays");
        }

   . . . some code 

    }
}
codenutt commented 7 months ago

Confirmed.