LibHelpers.piecewiseLinear will revert when the value is less than the first element of the array
The piecewise linear interpolation helper reverts when the input value is below the first element of the x-array, and since the redemption curve's first x-value is not enforced to be zero, a collateral ratio below that first value causes redemptions to revert. An attacker could not directly exploit this, but the protocol could become unable to process redemptions under certain under-collateralised conditions.
Originally disclosed on Code4rena
Submitted by auditor0517
https://github.com/AngleProtocol/angle-transmuter/blob/9707ee4ed3d221e02dcfcd2ebaa4b4d38d280936/contracts/transmuter/facets/Redeemer.sol#L156-L157 https://github.com/AngleProtocol/angle-transmuter/blob/9707ee4ed3d221e02dcfcd2ebaa4b4d38d280936/contracts/transmuter/libraries/LibSetters.sol#L230-L240 https://github.com/AngleProtocol/angle-transmuter/blob/9707ee4ed3d221e02dcfcd2ebaa4b4d38d280936/contracts/transmuter/libraries/LibHelpers.sol#L77-L80
LibHelpers.piecewiseLinear reverts when the value is less than the first element of the array. This method is used in Redeemer contract and if the collateral ratio is below the first element of xRedemptionCurve, the redepmtion will revert.
Proof of Concept
In Redeemer._quoteRedemptionCurve, a penalty factor is applied when the protocol is under-collateralized using LibHelpers.piecewiseLinear.
Redeemer.sol#L156-L157
uint64[] memory xRedemptionCurveMem = ts.xRedemptionCurve;
penaltyFactor = uint64(LibHelpers.piecewiseLinear(collatRatio, xRedemptionCurveMem, yRedemptionCurveMem));
xRedemptionCurveMem is strictly increasing and upper bounded by BASE_9, and there’s no more limitations.
LibSetters.sol
230 (action == ActionType.Redeem && (xFee[n - 1] > BASE_9 || yFee[n - 1] < 0 || yFee[n - 1] > int256(BASE_9)))
233 for (uint256 i = 0; i < n - 1; ++i) {
234 if (
240 (action == ActionType.Redeem && (xFee[i] >= xFee[i + 1] || yFee[i] < 0 || yFee[i] > int256(BASE_9)))
So collatRatio can be less than the first element of xRedemptionCurveMem. In that case, LibHelpers.findLowerBound will return 0 and LibHelpers.piecewiseLinear will revert on the following line.
LibHelpers.sol#L77-L80
return
yArray[indexLowerBound] +
((yArray[indexLowerBound + 1] - yArray[indexLowerBound]) * int64(x - xArray[indexLowerBound])) /
int64(xArray[indexLowerBound + 1] - xArray[indexLowerBound]);
Redeemer._redeem calls _quoteRedemptionCurve, so the redemption will be blocked in this case.
Recommended Mitigation Steps
We can add the following line to mitigate this issue.
if (indexLowerBound == 0 && x < xArray[0]) return yArray[0];
Picodes (Angle) confirmed and commented:
Indeed we are assuming throughout the test base that the first value is 0 but the check is missing in the code so there this could happen. It’s kind of conditional to a misconfiguration though. Leaving it up to the judge.
@Picodes - Medium is appropriate because it’s likely to happen with the current configuration.
PR: https://github.com/AngleProtocol/angle-transmuter/commit/5f7635cdab52b75416309d45f8cd253609c705ff Add a handler for this edge case.
Status: Mitigation confirmed. Full details in reports from Lambda, auditor0517, and Jeiwan.
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 piecewise linear helper does not handle the case where the input is below the first x-value, and the configuration setter does not require the first x-value to be zero.
Impact
Redemptions could be blocked when the collateral ratio falls below the first configured x-value, but this is conditional on a misconfiguration or an unusual market state.
What the attacker needed
Collateral ratio below first x-value; redemption curve misconfigured or market drop
The fix
The helper should return the first y-value when the input is below the first x-value, and the code was mitigated with a handler for this edge case.
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 smart contract uses a mathematical function to calculate a penalty when the system is low on collateral. That function assumes the input is never smaller than the first number in a configured list, but nothing enforces that assumption. If the collateral ratio drops below that first number, the function crashes and redemptions stop working.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.