Here’s the optimized version of the isCold
and isWarm
functions with reduced gas usage:
Combine isCold
and isWarm
: Since isCold
is the opposite of isWarm
, we can calculate one and get the other. This reduces the number of calculations and gas usage.
Move isWarm
implementation to an internal function: By moving the isWarm
implementation to an internal function_isWarm
, we can reuse it in the isWarm
function and also in other parts of the contract where we need to check if a stream is warm.
Simplify isCold
function: The isCold
function now simply returns the negation of the _isWarm
function, which is more gas-efficient than duplicating the same logic.
Eliminate redundant checks: The 7 lines of code from 287 to 293 in SablierV2Lockup.sol can be replaced by a single check:
This reduces the gas usage and simplifies the code.
The optimized version of the functions should result in lower gas usage, as it avoids redundant calculations and leverages the complementary nature of the Cold and Warm states.
https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.