Skip to content
Business logic Audit finding Intermediate

Key buyers will not be able to get refund if lock manager withdraws profits

The lock manager can withdraw all funds from a lock, leaving insufficient balance for key buyers to receive refunds when they cancel their keys. An attacker (or even a non-malicious manager) could accidentally or deliberately disable refunds, causing users to lose the ability to get their money back.

kenzo Follow

Originally disclosed on Code4rena

Submitted by kenzo

Unlock contains a feature in which a key buyer can ask for a refund. The refund is sent from the lock - where the purchase funds were sent. The lock manager can withdraw all funds from the lock. Therefore, if the lock manager withdraws enough profits from the lock, the user would not be able to cancel his key and request refund. Even if a lock manager is not malicious, if he would want to enable users to cancel their key, he would have to keep track of how much tokens need to be kept in the contract in order to enable this - not a trivial calculation. A naive lock manager might accidentally disable refunds for his clients.

Impact

Refunds are not guaranteed. A user might buy a key expecting to cancel it within some time, only to discover he can not cancel it. (This loss of user funds is why I consider this a high risk finding.) An unaware lock manager who just wants to withdraw all his profits might accidentally discover that he removed his users’ ability to cancel their key.

Notes

It seems the Unlock team is aware to some extent that withdrawing breaks refunds, as they state in the withdraw function:

   * TODO: consider allowing anybody to trigger this as long as it goes to owner anyway?
   *  -- however be wary of draining funds as it breaks the `cancelAndRefund` and `expireAndRefundFor`
   * use cases.

However, even if just the owner is allowed to call it, he may break the refund functionality - on purpose or accidentally. Looking on Unlock documentation I don’t see a warning to creators about withdrawing their funds.

Proof of Concept

withdraw function has no limit on the amount withdrawn, therefore the owner can withdraw all funds: https://github.com/code-423n4/2021-11-unlock/blob/main/smart-contracts/contracts/mixins/MixinLockCore.sol#L133:#L162

cancelAndRefund transfers the funds from the same lock contract: https://github.com/code-423n4/2021-11-unlock/blob/main/smart-contracts/contracts/mixins/MixinRefunds.sol#L118 Therefore if there are not enough funds, the transfer will fail.

Recommended Mitigation Steps

Perhaps a sort of MasterChef-like shares system can be implemented in order to make sure the owner leaves enough funds in the lock to process refunds.

julien51 (Unlock Protocol) disagreed with severity and commented:

As noted, this is actually documented. You are right though that we should make this more obvious on the UI. I would not classify this as High Risk.

0xleastwood (judge) decreased severity to Medium and commented:

Nice find! I think this can be downgraded to medium as the availability of the protocol is impacted by this issue.

julien51 (Unlock Protocol) commented:

This would not affect the whole protocol but only the “malicious” lock and it is impractice not only documented but also how these things work in the real world. If Netflix went out of business tomorrow, I could not get a refund on this month’s membership fee…

0xleastwood (judge) commented:

While I mostly agree with the sponsor, this may be intended behaviour as user’s should not be entitled to a refund in this case. However, based on what was known at the time, it seemed like this broke the functionality of cancelAndRefund and expireAndRefundFor functions, hence why it was marked as medium severity.

The original report as published on Code4rena, by kenzo. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 withdraw function allows the lock manager to remove all funds without ensuring enough remains to cover potential refunds.

Impact

Users may be unable to get refunds, potentially losing their funds, but this only affects the specific lock and not the whole protocol.

What the attacker needed

A lock with refundable keys; lock manager withdraws funds

The fix

The contract should be modified to ensure that enough funds remain in the lock to cover refunds, for example by implementing a shares system or limiting withdrawals.

How it was found

  1. A user buys a key by sending funds to the lock contract.
  2. The lock manager calls the withdraw function and removes all funds from the lock.
  3. The user later tries to cancel the key and request a refund.
  4. The refund transfer fails because the lock contract has insufficient balance.

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 holds money that users pay to buy keys. Normally, users can cancel a key and get a refund from that same contract. But the person who manages the lock can take all the money out, so when a user tries to cancel, there is nothing left to refund. This means users might lose their money if the manager withdraws too much.

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.

More by kenzo

View all

53 more disclosed reports, best first.

More from Unlock Protocol contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.