Use of safeApprove will always cause approveMax to revert
The mStable yield source used OpenZeppelin's deprecated safeApprove to raise an allowance that was already set to the maximum in the constructor. Because safeApprove reverts when the current allowance is not zero, the approveMax function could never increase a partially used allowance.
Submitted by 0xRajeev, also found by pauliax, shw, and cmichel
Unlike SwappableYieldSource which uses safeIncreaseAllowance to increase the allowance to uint256.max, mStableYieldSource uses OpenZeppelin’s safeApprove() which has been documented as (1) Deprecated because of approve-like race condition and (2) To be used only for initial setting of allowance (current allowance == 0) or resetting to 0 because it reverts otherwise.
The usage here is intended to allow increase of allowance when it falls low similar to the documented usage in SwappableYieldSource. Using it for that scenario will not work as expected because it will always revert if current allowance is != 0. The initial allowance is already set as uint256.max in constructor. And once it gets reduced, it can never be increased using this function unless it is invoked when allowance is reduced completely to 0. See issue page for referenced code.
Recommend Using logic similar to SwappableYieldSource instead of using safeApprove().
PierrickGT (PoolTogether) confirmed:
This issue has been fixed in the following commit: https://github.com/pooltogether/pooltogether-mstable/pull/3/commits/156a990901e6ddff543897905e3ea3d09c78d817
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the developer used safeApprove, which only permits setting an allowance from zero, instead of an increase-style helper, while the allowance was already initialised to the maximum.
Impact
The approveMax function could not restore a reduced allowance, so the yield source could be left unable to approve spending after the allowance dropped; the text does not describe any theft or loss of funds.
What the attacker needed
Allowance already set to maximum; allowance later reduced below maximum
The fix
It was fixed by replacing the logic with an increase-style allowance helper similar to the one used in SwappableYieldSource.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A token allowance is a permission one contract gives another to spend its tokens. The code tried to top up that permission with a helper function that only works when the permission is currently zero, so once any of it had been spent the top-up always failed. The result is a function that cannot do its job.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.