Skip to content
Business logic Audit finding Intermediate

Wrong design/implementation of freeTrial allows attacker to steal funds from the protocol

The freeTrial feature allows a user to get a full refund before the trial ends, and users can transfer part of their time to another user via shareKey. An attacker could transfer trial time from multiple addresses to one address, accumulate up to expirationDuration, and then call cancelAndRefund to steal funds from the protocol.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

The current design/implementation of freeTrial allows users to get full refund before the freeTrial ends. Plus, a user can transfer partial of their time to another user using shareKey.

This makes it possible for the attacker to steal from the protocol by transferring freeTrial time from multiple addresses to one address and adding up to expirationDuration and call refund to steal from the protocol.

Proof of Concept

Given:

  • keyPrice is 1 ETH;
  • expirationDuration is 360 days;
  • freeTrialLength is 31 days.

The attacker can create two wallet addresses: Alice and Bob.

  1. Alice calls purchase(), transfer 30 days via shareKey() to Bob, then calls cancelAndRefund() to get full refund; Repeat 12 times;
  2. Bob calls cancelAndRefund() and get 1 ETH.

Recommendation

Consider disabling cancelAndRefund() for users who transferred time to another user.

julien51 (Unlock Protocol) confirmed and commented:

I think this is valid! The free trial approach is indeed a risk on that front and we need to “warn” lock managers about this more.

For lock manager who still want to offer free trials, the best approach would probably be to set a high transfer fee to make sure that free trials cannot be transfered.

As a consequence of this, I am not sure this is as critical as indicated by the submitter.

0xleastwood (judge) commented:

Nice find!

From what I can tell at least, this does seem like a viable attack vector. Can I ask why this should not be treated as high risk? @julien51

julien51 (Unlock Protocol) commented:

Sorry for the long delay here. In short: this is valid, but only an issue for locks which are enabling free trials (no one has done it) and we would make sure our UI shows this as a potential issue. In other words: a lock manager would need to explicitly enable free trials, despite our warning to put their own funds at risk. For that reason I don’t think this is “High”.

0xleastwood (judge) commented:

While this is a valid issue pertaining only to lock managers who explicitly enable free trials, this may still lead to a loss of funds if cancelAndRefund is called by a user who has transferred their time to another account. I still believe this deserves a high severity rating.

In my honest opinion, a warning isn’t sufficient to prevent such abuse. I think on-chain enforcement ideal in this situation.

The original report as published on Code4rena, by WatchPug. 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

Likely the refund logic does not account for time that has been transferred to another user, allowing a full refund even after transferring trial time.

Impact

An attacker could steal funds from the protocol, but only if the lock manager explicitly enables free trials; the report notes that no one has done so.

What the attacker needed

Lock manager enables free trials; attacker controls multiple addresses; free trial length shorter than expiration

How it was found

  1. Alice calls purchase() and receives free trial time.
  2. Alice transfers 30 days of her time to Bob using shareKey().
  3. Alice calls cancelAndRefund() and gets a full refund.
  4. Alice repeats the process 12 times.
  5. Bob calls cancelAndRefund() and gets 1 ETH.

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 lets people buy time-limited access. It also gives a free trial and allows transferring some of that time to another person. The bug is that you can still get a full refund after transferring your trial time away, so someone can collect trial time on one account and then refund it for real money.

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 WatchPug

View all

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