The call to _setBufferCap(_bufferCap); cause a call to _updateBufferStored();, that have the line bufferStored = buffer();, and buffer do unnecessary calculates because it returns 0 (because this is the start of the contract).
So to save gas we can change lines 41-43:
code before:
RateLimited.sol (function constructor() )
There is unnecessary call to
_setBufferCap(_bufferCap);
in line 43 (https://github.com/code-423n4/2022-03-volt/blob/f1210bf3151095e4d371c9e9d7682d9031860bbd/contracts/utils/RateLimited.sol#L43).The call to
_setBufferCap(_bufferCap);
cause a call to_updateBufferStored();
, that have the linebufferStored = buffer();
, and buffer do unnecessary calculates because it returns 0 (because this is the start of the contract).So to save gas we can change lines 41-43: code before:
code after:
And we save gas of the unnecessary calculates of buffer()!
RateLimited.sol (function _depleteBuffer() )
In line 103 there is require that variable
newBuffer
is not 0. It can be checked in line 97 (because there is no change ofnewBuffer
from this line. (link - https://github.com/code-423n4/2022-03-volt/blob/f1210bf3151095e4d371c9e9d7682d9031860bbd/contracts/utils/RateLimited.sol#L103)code before:
code after: