PositionManager will revert when trying to return back to user excess of the premium transferred from the user when minting position
The PositionManager contract uses safeTransferFrom to return excess premium to the user, but it never approves itself to spend its own tokens. If the actual premium is lower than the preliminary premium, the transfer will revert, preventing the user from opening a position.
PositionManager.mint calculates preliminary premium to be paid for buying the option and transfers it from the user. The actual premium paid may differ, and if it's smaller, excess is returned back to user. However, it is returned using the safeTransferFrom:
The problem is that PositionManager doesn't approve itself to transfer baseToken to msg.sender, and USDC transferFrom implementation requires approval even if address is transferring from its own address. Thus the transfer will revert and user will be unable to open position.
function transferFrom(
address from,
address to,
uint256 value
)
external
override
whenNotPaused
notBlacklisted(msg.sender)
notBlacklisted(from)
notBlacklisted(to)
returns (bool)
{
require(
value <= allowed[from][msg.sender],
"ERC20: transfer amount exceeds allowance"
);
_transfer(from, to, value);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(value);
return true;
}
PositionManager doesn't approve itself to do transfers anywhere, so baseToken.safeTransferFrom(address(this), msg.sender, obtainedPremium - premium); will always revert, preventing the user from opening position via PositionManager, breaking important protocol function.
Impact
User is unable to open positions via PositionManager in certain situations as all such transactions will revert, breaking important protocol functionality and potentially losing user funds / profit due to failure to open position.
The actual premium to pay will be the result of the higher value between the swap-priced premium and the oracle-priced premium. So, in the scenario where the swap price is lower than the oracle price, the oracle price will be used to compute the final premium.
Therefore, it's not possible that the final premium is a lower value than obtainedPremium, so the bug will never be triggered because the condition obtainedPremium > premium will never be true.
sherlock-admin2
Escalate
This issue is LOW because the bug will never be triggered.
PositionManager calculates the variable obtainedPremium calling DVP.premium, that uses the oracle price to calculate the premium:
The actual premium to pay will be the result of the higher value between the swap-priced premium and the oracle-priced premium. So, in the scenario where the swap price is lower than the oracle price, the oracle price will be used to compute the final premium.
Therefore, it's not possible that the final premium is a lower value than obtainedPremium, so the bug will never be triggered because the condition obtainedPremium > premium will never be true.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
panprog
Yes, the way it is now, it can never actually happen but that's only due to another issue which makes it revert if any DEX slippage occurs. When it works as intended, the remainder has to be transferred back to the sender.
So yeah, up to judge to decide. I consider it borderline, because if we isolate "how it is supposed to work", returning back the remainder should be possible, it's impossible only due to a different issue.
cvetanovv
It seems that the report is invalid. I think we should judge according to the code that is at the moment, not if it works properly.
nevillehuang
Based on head of judging comments in a previous contest for such issues, I believe this should remain valid.
Czar102
I agree with @panprog and @nevillehuang – the fix to the other issue will not fix this one. Hence, these are separate issues and both of them may be valid since they present discrepancies from the expected behavior of the contracts.
I'm planning to reject the escalation and leave the issue as is.
The original report as published on Sherlock, by juan. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the contract used safeTransferFrom instead of safeTransfer for returning tokens from its own balance, and USDC requires approval even for self-transfers.
Impact
Users may be unable to open positions via PositionManager in certain situations, potentially losing funds or profit due to the failed transaction.
What the attacker needed
USDC as base token; actual premium < preliminary premium
The fix
The protocol team fixed this issue by using safeTransfer instead of safeTransferFrom.
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.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
When you buy something, you might pay a deposit first and get change later. Here, the contract tries to give back the extra money using a method that requires permission, but it never gave itself that permission. So the refund fails and the whole purchase fails.
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.