Refund mechanism doesn’t take into account that key price can change
The refund mechanism calculates the refund based on the current key price rather than the price the user originally paid. A user who refunds after a price change can receive less (or more) funds than they deserve.
Submitted by kenzo, also found by WatchPug and 0x0x0x
Lock manager can change key pricing. The refund mechanism calculates refund according to current key price, not price actually paid.
Impact
A user refunding can get less (or more) funds than deserved.
Proof of Concept
Refund only takes the current price into account: https://github.com/code-423n4/2021-11-unlock/blob/main/smart-contracts/contracts/mixins/MixinRefunds.sol#L144:#L152
Lock manager can update key price at any point, and the old price is not saved anywhere: https://github.com/code-423n4/2021-11-unlock/blob/main/smart-contracts/contracts/mixins/MixinLockCore.sol#L183
So if for example a key price has gone down, a user who tried to refund will get less funds than deserved.
Recommended Mitigation Steps
Consider saving the amount the user paid, and refund according to that. Or having a kind of a price snapshot/version mechanism.
julien51 (Unlock Protocol) acknowledged, but disagreed with severity and commented:
This is a known issue… but indeed we should show things in the UI to indicate things to users.
0xleastwood (judge) decreased severity to Medium and commented:
Agree this sounds like an issue! However, I don’t think this can be justified as a
highrisk issue. But it does seem that the protocol could leak value and impact users, so marking this asmedium.
julien51 (Unlock Protocol) commented:
We actually are adding a new mechanism to keep track of the last price paid by any user which means we could use it in the next version to solve this issue!
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 contract does not store the price each user paid and instead uses the current key price when calculating refunds.
Impact
A user refunding could receive less or more funds than they are owed, potentially leaking value from the protocol.
What the attacker needed
Key price changes after purchase; user requests a refund
The fix
The protocol should save the amount each user paid and calculate refunds based on that, or use a price snapshot/version mechanism.
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 buy a key, you pay a certain price. If you later ask for a refund, the system should give back what you paid. Here, the system looks at the current price instead, so if the price has changed, you might get the wrong amount back.
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.