Skip to content
Business logic Audit finding Beginner

StakeTime field in UserStake struct is stored but never used on-chain, wasting storage on every stake

The UserStake struct stores a stakeTime value on every deposit, but no on-chain function ever reads it. This wastes storage and gas on each stake transaction without providing any functional benefit.

hcrlen Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

68983 sc insight staketime field in userstake struct is stored but never used on chain wasting storage on every stake

Submitted on Mar 12th 2026 at 08:12:42 UTC by @hcrlen for Audit Comp | Folks Finance: Staking Contracts

Description

Brief/Intro

UserStake struct stores stakeTime on every deposit but this field is never referenced in any on-chain logic, resulting in unnecessary storage consumption on every stake operation.

Vulnerability Details

In _stake(), stakeTime is written to storage:

Solidity
UserStake({
    ...
    stakeTime: uint64(block.timestamp), // never read again
    ...
})

A review of the entire contract shows that stakeTime is never read by any function, including:

  • withdrawal logic
  • reward calculations
  • migration logic
  • validation checks

As a result, the value is written to storage but never used.

Impact Details

Writing to a new storage slot requires an SSTORE operation (≈20,000 gas for a cold write). Since stakeTime is not used anywhere in the contract, each stake transaction incurs this extra gas cost without providing any functional benefit.

Over time, this increases gas costs for all users interacting with the staking contract.

Recommendations

Remove stakeTime from UserStake. The Staked event's block timestamp provides equivalent off-chain tracking.

Proof of Concept

{% stepper %} {% step %}

1. Call stake() or stakeWithPermit().

{% endstep %}

{% step %}

2. _stake() stores stakeTime in the UserStake struct.

Solidity
userStakes[msg.sender].push(
    UserStake({
        amount: amount,
        reward: reward,
        claimedAmount: 0,
        claimedReward: 0,
        aprBps: stakingPeriod.aprBps,
        stakeTime: uint64(block.timestamp), // <--
        unlockTime: uint64(block.timestamp) +  stakingPeriod.stakingDurationSeconds,
        unlockDuration: stakingPeriod.unlockDurationSeconds
    })
);

{% endstep %}

{% step %}

3. The variable is never referenced or used again by any on-chain function.

{% endstep %} {% endstepper %}

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

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 stakeTime field was added to the struct for tracking or future use but was never wired into any logic, leaving a dead storage write.

Impact

Each stake transaction incurs an extra storage write cost of roughly 20,000 gas with no functional benefit, increasing gas costs for all users over time.

What the attacker needed

None

The fix

Remove stakeTime from UserStake; the Staked event's block timestamp provides equivalent off-chain tracking.

How it was found

  1. Call stake() or stakeWithPermit().
  2. _stake() stores stakeTime in the UserStake struct.
  3. The variable is never referenced or used again by any on-chain function.

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 can save data permanently on the blockchain, and each save costs gas, which is a fee paid by the user. This contract saves a timestamp every time someone stakes, but nothing ever reads that timestamp back. So users pay extra gas for information that is never used.

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 hcrlen

View all

3 more disclosed reports, best first.

More from Folks Finance: Staking Contracts

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.