Missing return value on withdraw and missing view function for withdrawable amount
The withdraw function computes the amount and reward to claim but returns nothing, and there is no public view function to query how much a stake can currently withdraw. Users and integrators must parse events or replicate the accrual maths off-chain, which risks rounding differences and inaccurate displayed amounts.
- Disclosed after under an hour
69540 sc insight missing return value on withdraw and missing view function for withdrawable amount
Submitted on Mar 15th 2026 at 13:12:58 UTC by @hcrlen for Audit Comp | Folks Finance: Staking Contracts
- Report ID: #69540
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/Folks-Finance/folks-staking-contracts/blob/main/src/Staking.sol
- Impacts:
Description
Brief/Intro
The withdraw function returns nothing despite computing amountToClaim and rewardToClaim internally. Additionally there is no public view function to query the current withdrawable amount for a stake, forcing users and integrators to replicate the accrual math off-chain.
Vulnerability Details
Issue 1: withdraw returns nothing
function withdraw(uint8 stakeIndex) external nonReentrant {
_withdraw(stakeIndex);
}
_withdraw computes:
uint256 amountToClaim = accruedAmount - userStake.claimedAmount;
uint256 rewardToClaim = accruedReward - userStake.claimedReward;
But these values are never returned. The caller has no way to know how much they received without:
- Parsing the Withdrawn event
- Checking token balance before and after
Every other state-changing function returns useful data:
function stake(...) external returns (uint8)
function stakeWithPermit(...) external returns (uint8)
function addStakingPeriod(...) external returns (uint8)
function migratePositionsFrom(...) external returns (UserStake[] memory)
withdraw is the only user state-changing function that returns nothing.
Issue 2: No view function for withdrawable amount
_getAccrued is internal:
function _getAccrued(uint256 amount, uint256 duration, uint256 elapsed) internal pure returns (uint256) {
return Math.mulDiv(amount, Math.min(elapsed, duration), duration);
}
Users and integrators cannot query current withdrawable amount on-chain. They must:
- Call getUserStake(user, stakeIndex) to get raw stake data
- Manually compute
_getAccruedoff-chain - Subtract
claimedAmountandclaimedReward
This makes it harder for frontends to display accurate withdrawable amounts and for other contracts to integrate with the staking contract.
Impact Details
Users and integrators cannot determine withdrawable amounts on-chain, and callers of withdraw receive no feedback on how much was claimed.
References
Add any relevant links to documentation or code
Proof of Concept
{% stepper %} {% step %}
Observe every other user-facing state-changing function returns useful data
// stake - returns stakeIndex so user knows which index was assigned
function stake(...) external returns (uint8)
// stakeWithPermit - returns stakeIndex
function stakeWithPermit(...) external returns (uint8)
// migratePositionsFrom - returns migrated stakes array
function migratePositionsFrom(...) external returns (UserStake[] memory)
{% endstep %}
{% step %}
withdraw returns nothing despite computing meaningful values
function withdraw(uint8 stakeIndex) external nonReentrant {
_withdraw(stakeIndex); // computed values never returned
}
{% endstep %}
{% step %}
_withdraw computes amountToClaim and rewardToClaim internally but discards them
uint256 amountToClaim = accruedAmount - userStake.claimedAmount;
uint256 rewardToClaim = accruedReward - userStake.claimedReward;
activeTotalStaked -= amountToClaim;
activeTotalRewards -= rewardToClaim;
userStake.claimedAmount += amountToClaim;
userStake.claimedReward += rewardToClaim;
emit Withdrawn(msg.sender, stakeIndex, amountToClaim, rewardToClaim);
TOKEN.safeTransfer(msg.sender, amountToClaim + rewardToClaim);
// nothing returned
{% endstep %}
{% step %}
A contract integrating with withdraw cannot know how much was claimed
{% endstep %}
{% step %}
User must rely on Withdrawn event
{% endstep %}
{% step %}
_getAccrued is internal not callable externally
function _getAccrued(uint256 amount, uint256 duration, uint256 elapsed) internal pure returns (uint256) {
return Math.mulDiv(amount, Math.min(elapsed, duration), duration);
}
{% endstep %}
{% step %}
getUserStake(user, stakeIndex) returns only raw stake data with no computed withdrawable amount
struct UserStake {
uint256 amount;
uint256 reward;
uint256 claimedAmount;
uint256 claimedReward;
uint32 aprBps;
uint64 stakeTime;
uint64 unlockTime;
uint64 unlockDuration;
}
{% endstep %}
{% step %}
To compute withdrawable amount, user must manually replicate off-chain
// user must replicate this entire calculation manually
uint256 elapsed = block.timestamp - userStake.unlockTime;
uint256 accruedAmount = Math.mulDiv(
userStake.amount,
Math.min(elapsed, userStake.unlockDuration),
userStake.unlockDuration
);
uint256 withdrawable = accruedAmount - userStake.claimedAmount;
{% endstep %}
{% step %}
No public on-chain function exists to compute this users, frontends, and integrating contracts must replicate _getAccrued logic off-chain
- Off-chain rounding differences vs on-chain result
- Incorrect withdrawable amount displayed to users
- Integrating contracts unable to query withdrawable amount before calling
withdraw{% 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 withdraw function and its internal helper were written without return values, and the accrual helper was kept internal, so no on-chain query exists for the withdrawable amount.
Impact
Users and integrators cannot determine withdrawable amounts on-chain, and callers of withdraw receive no feedback on how much was claimed; off-chain replication could also show incorrect amounts.
What the attacker needed
None
The fix
The withdraw function should return the claimed amount and reward, and a public view function should expose the current withdrawable amount.
How it was found
- Observe that other user-facing state-changing functions return useful data.
- Note that withdraw returns nothing despite computing meaningful values.
- Note that the internal withdraw helper discards the computed amounts.
- Note that an integrating contract cannot learn how much was claimed.
- Note that the user must rely on the Withdrawn event.
- Note that the accrual helper is internal and not callable externally.
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 is a program on a blockchain. This one lets people stake tokens and later withdraw them, but the withdraw action gives back no information about how much was paid out, and there is no public way to ask the contract what is currently withdrawable. That is a usability and integration gap rather than a way to steal funds.
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.