Skip to content
Business logic Audit finding Intermediate

MixinRefunds: frontrun updateKeyPricing() for free profit

A lock owner can increase the key price, but a user can frontrun that update by buying keys at the old lower price and then requesting a refund at the new higher price, receiving more money than they paid. This allows the attacker to drain the lock's funds.

itsmeSTYJ Follow

Originally disclosed on Code4rena

Submitted by itsmeSTYJ

A malicious user is able to withdraw all payments that were paid to a lock owner if the owner increases the keyPrice.

Proof of Concept

When updateKeyPricing() is called to increase the price of a key, it is possible to frontrun this call and buy many keys at the cheaper price then request for a refund at the higher price.

Recommendation

Keep track of the price at which keys are purchased so that when you issue a refund, you use the original keyPrice to refund instead of the updated keyPrice

julien51 (Unlock Protocol) acknowledged, but disagreed with High severity and commented:

This is only true for locks where there is no penalty. We should make it clear on the front-end that when changing the price it is recommended to set up a penalty (at least temporarily) for the price difference so that no key can be refunded for the full price.

0xleastwood (judge) commented:

Circling back on this, I’m not sure how a penalty would be correctly applied to all locks. Wouldn’t users who wanted to get a refund for their key get penalised if they purchase after the change in key price? I think it would also be safer to update the key price and apply the penalty in the one transaction.

julien51 (Unlock Protocol) commented:

I think that is a good finding, but there again (like often) I think this is pretty edgy. The cancellation penalty is pretty easy to apply just to a single lock from the lock manager’s perspective. Before changing the lock price, a lock manager can easily apply a penalty for the difference in price. IE if I change the price from 10 to 12, I apply a penalty for 2 and anyone who tries to abuse this will only get a refund of 12-2 = 10.

On top of that we’re actually storing the amount paid for the latest key as part of our next upgrade to support automatically recurring memberships, which should make things even more robust as anyone will only get re-imbursed based on what they paid…

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

Considering the sponsor’s comments and after some further discussion on Discord. I think it is more correct to downgrade this to medium severity. While it isn’t clear, the lock manager is expected to apply a penalty before updating the cost of a membership such that users cannot game the price difference. However, this isn’t enforced on-chain or documented anywhere so based on the judge’s and warden’s context at the time, this seemed like a valid high severity issue. It is important to note that users who refund their membership after purchasing a membership post price change will be refunded less than users who purchased their memberships before the price change. The sponsor is looking to integrate these fixes in their next upgrade.

The original report as published on Code4rena, by itsmeSTYJ. 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 refund logic uses the current key price rather than the price at which the key was purchased, so a price increase creates an arbitrage opportunity.

Impact

An attacker could withdraw all payments made to the lock owner if the owner increases the key price, but the sponsor notes this only applies to locks without a cancellation penalty and suggests a penalty can mitigate it.

What the attacker needed

Lock owner increases key price; no cancellation penalty set; attacker can frontrun transaction

The fix

The refund should be based on the price at which the key was originally purchased, not the updated price; the sponsor also suggests applying a cancellation penalty for the price difference before changing the price.

How it was found

  1. The lock owner calls updateKeyPricing() to increase the key price.
  2. Before that transaction is mined, an attacker buys many keys at the old lower price.
  3. After the price update, the attacker requests refunds for the keys at the new higher price, receiving more than they paid.

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 lock lets people buy keys at a set price and later get a refund. If the owner raises the price, someone can quickly buy keys at the old cheap price before the change takes effect, then ask for a refund at the new higher price, making a profit. This works because the refund amount is based on the current price, not the price the buyer actually paid.

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 itsmeSTYJ

View all

9 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.