Incorrect balance check in PT redemption commands
The Dispatcher contract checks the YT balance instead of the PT balance when redeeming PT, which can prevent users from redeeming their PTs after maturity if the contract holds fewer YTs than PTs. This could lead to permanent freezing of user funds in the protocol.
- Disclosed after under an hour
#44167 [SC-Medium] Incorrect balance check in PT redemption commands
Submitted on Apr 17th 2025 at 13:07:11 UTC by @Rhaydden for Audit Comp | Spectra Finance
- Report ID: #44167
- Report Type: Smart Contract
- Report severity: Medium
- Target: https://github.com/immunefi-team/Spectra-Audit-Competition/blob/main/src/router/Dispatcher.sol
- Impacts:
- Permanent freezing of unclaimed yield
Description
Brief/Intro
Dispatcher contract incorrectly checks YT balances when users attempt to redeem PT, instead of checking the actual PT balances. This leads to a situation where users with legitimate redemption rights may be unable to redeem their PTs if the Dispatcher contract has fewer YTs than PTs, especially critical after maturity when YTs should no longer be required for redemption. This could result in permanent freezing of user funds in the protocol.
Vulnerability Details
When handling REDEEM_PT_FOR_ASSET and REDEEM_PT_FOR_IBT commands, the code incorrectly limits the redemption amount based on the YT balance of the contract instead of the PT balance:
// In REDEEM_PT_FOR_ASSET
shares = Math.min(shares, IERC20(IPrincipalToken(pt).getYT()).balanceOf(address(this)));
// In REDEEM_PT_FOR_IBT
shares = Math.min(shares, IERC20(IPrincipalToken(pt).getYT()).balanceOf(address(this)));
The Dispatcher should be checking the balance of the token being redeemed (PT) rather than a related token (YT). While PT and YT tokens are minted in equal amounts upon deposit and both are typically required for redemption before maturity, this balance check is fundamentally incorrect for several reasons:
- The Dispatcher is acting as an intermediary that performs operations on behalf of users. When redeeming PTs, it should check that it has enough PTs to redeem, not YTs.
- According to the protocol's design (as seen in PrincipalToken.sol's
_maxBurnablefunction), after a PT reaches maturity, users can redeem PTs regardless of YT balances:
/**
* @dev Computes the maximum amount of burnable shares for a user
* @param _user The address of the user
* @return maxBurnable The maximum amount of burnable shares
*/
function _maxBurnable(address _user) internal view returns (uint256 maxBurnable) {
if (block.timestamp >= expiry) {
maxBurnable = balanceOf(_user);
} else {
uint256 ptBalance = balanceOf(_user);
uint256 ytBalance = IYieldToken(yt).balanceOf(_user);
maxBurnable = (ptBalance > ytBalance) ? ytBalance : ptBalance;
}
}
- The router could end up with different amounts of PT and YT tokens, especially after maturity or through direct transfers. The current implementation would incorrectly limit redemptions in these scenarios.
Impact Details
After a PT reaches maturity, users should be able to redeem their PTs regardless of YT balances. However, the Dispatcher would still limit redemptions based on YT balance, leaving PTs permanently frozen in the contract if YT balance is insufficient.
References
Proof of Concept
Proof of concept
Consider a scenario:
- A user deposits assets into Spectra and receives equal amounts of PT and YT tokens.
- The user transfers some of their PTs to another wallet, but keeps their YTs in the original wallet.
- The PT contract reaches maturity. According to the protocol design, PTs can now be redeemed without requiring YTs.
- The user who received the PTs wants to redeem them through the Router using the REDEEM_PT_FOR_ASSET command.
- The user executes a transaction that calls the Router with the REDEEM_PT_FOR_ASSET command.
- Inside the Dispatcher's _dispatch function, it checks:
shares = Math.min(shares, IERC20(IPrincipalToken(pt).getYT()).balanceOf(address(this)));
- Since the Dispatcher has no YTs (or fewer YTs than PTs), this check evaluates to zero or a lower value than the PT amount being redeemed.
- As a result, no redemption occurs (or less than the expected amount is redeemed).
- The user's PTs are now effectively frozen in the Router contract, despite the PT contract allowing redemption after maturity without YTs.
Fix
Consider replacing the YT balance check with a PT balance check in both REDEEM_PT_FOR_ASSET and REDEEM_PT_FOR_IBT commands:
// In REDEEM_PT_FOR_ASSET handler
- shares = Math.min(shares, IERC20(IPrincipalToken(pt).getYT()).balanceOf(address(this)));
+ shares = Math.min(shares, IERC20(pt).balanceOf(address(this)));
// In REDEEM_PT_FOR_IBT handler
- shares = Math.min(shares, IERC20(IPrincipalToken(pt).getYT()).balanceOf(address(this)));
+ shares = Math.min(shares, IERC20(pt).balanceOf(address(this)));
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 Dispatcher contract uses the YT balance of the contract instead of the PT balance when limiting the redemption amount for PT redemption commands.
Impact
After maturity, users may be unable to redeem their PTs if the Dispatcher holds fewer YTs than PTs, potentially causing permanent freezing of user funds.
What the attacker needed
PT has reached maturity; Dispatcher holds fewer YTs than PTs; User uses Router to redeem PT
The fix
The YT balance check should be replaced with a PT balance check in both REDEEM_PT_FOR_ASSET and REDEEM_PT_FOR_IBT commands.
How it was found
- A user deposits assets into Spectra and receives equal amounts of PT and YT tokens.
- The user transfers some PTs to another wallet but keeps the YTs in the original wallet.
- The PT contract reaches maturity, so PTs can be redeemed without YTs.
- The user who received the PTs tries to redeem them through the Router using the REDEEM_PT_FOR_ASSET command.
- The Dispatcher checks the YT balance of the contract instead of the PT balance, which may be zero or lower than the PT amount.
- As a result, no redemption occurs or less than the expected amount is redeemed, freezing the user's PTs.
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.
When you deposit into Spectra, you get two tokens: a principal token (PT) and a yield token (YT). After the PT matures, you should be able to redeem it without needing any YT. But the router contract mistakenly checks how many YT it holds instead of how many PT it holds, so it may refuse to let you redeem your PT even though you should be allowed to.
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.