Skip to content
Business logic Audit finding Intermediate

user.creation is updated incorrectly when the user tries to extend membership

When a user extends their membership, the contract incorrectly updates the user's creation timestamp by adding the duration increase, which pushes the membership start date far into the future. This makes the user unable to use any membership features for an extended period.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

FSDNetwork.sol L274-L291

https://github.com/code-423n4/2021-11-fairside/blob/20c68793f48ee2678508b9d3a1bae917c007b712/contracts/network/FSDNetwork.sol#L274-L291

if (user.creation == 0) {
    user.creation = block.timestamp;
    user.gracePeriod =
        membership[msg.sender].creation +
        MEMBERSHIP_DURATION +
        60 days;
} else {
    uint256 elapsedDurationPercentage = ((block.timestamp -
        user.creation) * 1 ether) / MEMBERSHIP_DURATION;
    if (elapsedDurationPercentage < 1 ether) {
        uint256 durationIncrease = (costShareBenefit.mul(1 ether) /
            (totalCostShareBenefit - costShareBenefit)).mul(
                MEMBERSHIP_DURATION
            ) / 1 ether;
        user.creation += durationIncrease;
        user.gracePeriod += durationIncrease;
    }
}

PoC

  1. Alice calls function purchaseMembership() and adds 20 ether of costShareBenefit on day 1:
alice.creation = day 1 timestamp;
alice.gracePeriod = day 791 timestamp;
  1. Alice calls function purchaseMembership() again and adds 20 ether of costShareBenefit on day 2:
elapsedDurationPercentage = 1/720
durationIncrease = 730 day

alice.creation = day 731 timestamp;
alice.gracePeriod = day 1521 timestamp;

Making Alice unable to use any membership features until two years later.

YunChe404 (FairSide) confirmed and disagreed with severity

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 code adds the duration increase to user.creation instead of only to user.gracePeriod, causing the start time to move forward.

What the attacker needed

User has an existing membership; User calls purchaseMembership() again to extend

How it was found

  1. Alice calls purchaseMembership() and adds 20 ether of costShareBenefit on day 1.
  2. Alice calls purchaseMembership() again and adds 20 ether of costShareBenefit on day 2.
  3. The contract calculates elapsedDurationPercentage and durationIncrease, then adds durationIncrease to user.creation and user.gracePeriod.
  4. Alice's creation timestamp becomes day 731, making her unable to use membership features until two years later.

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 stores a user's membership start time. When the user buys more membership, the code mistakenly adds extra time to that start time instead of extending the end time. This locks the user out of using their membership for a long time.

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