Skip to content
Business logic Audit finding Beginner

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.

hcrlen Follow

Originally disclosed on Immunefi

Informational View original
  • 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

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

Solidity
function withdraw(uint8 stakeIndex) external nonReentrant {
    _withdraw(stakeIndex);
}

_withdraw computes:

Solidity
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:

Solidity
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:

Solidity
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 _getAccrued off-chain
  • Subtract claimedAmount and claimedReward

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

Solidity
// 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

Solidity
function withdraw(uint8 stakeIndex) external nonReentrant {
    _withdraw(stakeIndex); // computed values never returned
}

{% endstep %}

{% step %}

_withdraw computes amountToClaim and rewardToClaim internally but discards them

Solidity
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

Solidity
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

Solidity
 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

Solidity
// 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 %}

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

  1. Observe that other user-facing state-changing functions return useful data.
  2. Note that withdraw returns nothing despite computing meaningful values.
  3. Note that the internal withdraw helper discards the computed amounts.
  4. Note that an integrating contract cannot learn how much was claimed.
  5. Note that the user must rely on the Withdrawn event.
  6. 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.

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.