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

0 stars 0 forks source link

Harvester: Simpler implementation for canHarvest() #66

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

hickuphh3

Vulnerability details

Recommended Mitigation Steps

The negation of the disjunction form of the canHarvest() function will help save gas. In other words, instead of !(A || B), return (!A && !B).

function canHarvest(
    address _vault
)
  public
  view
  returns (bool)
{
  Strategy storage strategy = strategies[_vault];
  // only can harvest if there are strategies, and when sufficient time has elapsed
  // solhint-disable-next-line not-rely-on-time
    return (strategy.addresses.length > 0 && strategy.lastCalled <= block.timestamp.sub(strategy.timeout));
}
GalloDaSballo commented 2 years ago

Nice gas optimization by using boolean short circuit

GalloDaSballo commented 2 years ago

Sponsor has mitigated