1. Save gas by stored traded market in array in DateTime.sol
Impact
In DateTime.getTradedMarket() function, it used 7 if to get result which mean it’s cost at most 7 check every time this function is called.
In DateTime.getMarketIndex() function, it loop from 1 to maxMarketIndex and call getTradedMarket() each time. Instead if we stored result of getTradedMarket() in a list like below we can save gas (at most 7*7 = 49 checks)
1. Save gas by stored traded market in array in
DateTime.sol
Impact
In
DateTime.getTradedMarket()
function, it used 7if
to get result which mean it’s cost at most 7 check every time this function is called.In
DateTime.getMarketIndex()
function, it loop from 1 tomaxMarketIndex
and callgetTradedMarket()
each time. Instead if we stored result ofgetTradedMarket()
in a list like below we can save gas (at most 7*7 = 49 checks)Proof of concept
https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/notional-wrapped-fcash/contracts/lib/DateTime.sol#L23
https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/notional-wrapped-fcash/contracts/lib/DateTime.sol#L64
Recommended Mitigation Steps
Precompute and store result of
getTradedMarket()
in a list