Periphery#_swapPTsForTarget won't work correctly if PT is mature but redeem is restricted
The _swapPTsForTarget function always attempts to redeem mature PTs even when redemption is restricted for the adapter, causing the function to fail. An attacker could not exploit this directly, but users would be unable to swap PTs for the target asset when redemption is restricted.
Source: https://github.com/sherlock-audit/2023-03-sense-judging/issues/32
Found by
0x52
Summary
Periphery#_swapPTsForTarget doesn't properly account for mature PTs that have their redemption restricted
Vulnerability Detail
function _swapPTsForTarget(
address adapter,
uint256 maturity,
uint256 ptBal,
PermitData calldata permit
) internal returns (uint256 tBal) {
_transferFrom(permit, divider.pt(adapter, maturity), ptBal);
if (divider.mscale(adapter, maturity) > 0) {
tBal = divider.redeem(adapter, maturity, ptBal); <- @audit-issue always tries to redeem even if restricted
} else {
tBal = _balancerSwap(
divider.pt(adapter, maturity),
Adapter(adapter).target(),
ptBal,
BalancerPool(spaceFactory.pools(adapter, maturity)).getPoolId(),
0,
payable(address(this))
);
}
}
Adapters can have their redeem restricted meaning the even when they are mature they can't be redeemed. In the scenario that it is restricted Periphery#_swapPTsForTarget simply won't work.
Impact
Redemption will fail when redeem is restricted because it tries to redeem instead of swapping
Code Snippet
Tool used
Manual Review
Recommendation
Use the same structure as _removeLiquidity:
if (divider.mscale(adapter, maturity) > 0) {
if (uint256(Adapter(adapter).level()).redeemRestricted()) {
ptBal = _ptBal;
} else {
// 2. Redeem PTs for Target
tBal += divider.redeem(adapter, maturity, _ptBal);
}
Discussion
jparklev
Accepted: This is valid and is indeed something we should fix
jparklev
Fixed here: https://github.com/sense-finance/sense-v1/pull/352
We removed the redeem code path if redeem is disabled
IAm0x52
Fix looks good. Periphery will swap instead of redeeming if redeem is restricted
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
The function does not check whether redemption is restricted for the adapter before attempting to redeem mature PTs.
Impact
When redemption is restricted, the function will fail, preventing users from swapping PTs for the target asset.
What the attacker needed
Adapter has redeem restricted; PT is mature
The fix
The function was fixed by removing the redeem code path when redemption is disabled, so it swaps instead.
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.
This is a smart contract bug where a function tries to redeem a token (PT) even when the system has disabled redemption for that token. As a result, the function fails instead of using an alternative method to swap the token. Users would be unable to perform that swap when redemption is restricted.
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.