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.
Submitted by WatchPug
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
- Alice calls
function purchaseMembership()and adds 20 ether ofcostShareBenefiton day 1:
alice.creation = day 1 timestamp;
alice.gracePeriod = day 791 timestamp;
- Alice calls
function purchaseMembership()again and adds 20 ether ofcostShareBenefiton 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.
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
- Alice calls purchaseMembership() and adds 20 ether of costShareBenefit on day 1.
- Alice calls purchaseMembership() again and adds 20 ether of costShareBenefit on day 2.
- The contract calculates elapsedDurationPercentage and durationIncrease, then adds durationIncrease to user.creation and user.gracePeriod.
- 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.