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.
- 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
- Report ID: #68983
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/Folks-Finance/folks-staking-contracts/blob/main/src/Staking.sol
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:
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.
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 %}
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
- Call stake() or stakeWithPermit().
- _stake() stores stakeTime in the UserStake struct.
- 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.