code-423n4 / 2022-01-sherlock-findings

0 stars 0 forks source link

safeApprove will fail if the current approval is not 0 #269

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

pauliax

Vulnerability details

Impact

safeApprove will fail if the current approval is > 0 but < amount:

  if (want.allowance(address(this), address(lp)) < amount) {
    want.safeApprove(address(lp), type(uint256).max);
  }

This condition is unlikely to happen in practice as you approve the max value which should in theory last forever, but nevertheless a better option would be to reset the approval before setting it once again:

  if (want.allowance(address(this), address(lp)) < amount) {
    want.safeApprove(address(lp), 0);
    want.safeApprove(address(lp), type(uint256).max);
  }