Skip to content
Access control Audit finding Intermediate

Owner can steal funds from contract by calling stakeNxm() with fake pool address

The contract owner can pass a fake staking pool address to stakeNxm(), which is stored without validation. By setting themselves as fee beneficiary and calling getRewards(), the fake pool returns inflated rewards, increasing adminFees so the owner can withdraw the contract's entire wNXM balance.

0xRaz Follow with CasinoCompiler, Cybrid and 12 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-11-stnxm-by-easedefi-judging/issues/251

Found by

0xRaz, CasinoCompiler, Cybrid, DevBear0411, Drynooo, JohnTPark24, Pataroff, asui, blockace, dandan, elolpuer, farismaulana, firmanregar, n33k, tobi0x18

Summary

Owner can pass any address to _stakeNxm(), including a fake staking pool with a matching interface, to add this pool into tokenIdToPool mapping. Then owner can set himself as the fee beneficiary and call getRewards(). The fake pool can return arbitrary values from withdraw(), inflating rewards so that adminFees equals the contract’s entire wNxm balance, allowing the owner to withdraw all funds.

Root Cause

Owner can pass any address to stakeNxm() to add fake pool to storage:

Solidity
function stakeNxm(uint256 _amount, address _poolAddress, uint256 _trancheId, uint256 _requestTokenId)
    external
    onlyOwner
    update
{
    _stakeNxm(_amount, _poolAddress, _trancheId, _requestTokenId);
}

function _stakeNxm(uint256 _amount, address _poolAddress, uint256 _trancheId, uint256 _requestTokenId) internal {
    wNxm.unwrap(_amount);
    // Make sure it's the most recent token controller address.
    nxm.approve(nxmMaster.getLatestAddress("TC"), _amount);

    IStakingPool pool = IStakingPool(_poolAddress);
    uint256 tokenId = pool.depositTo(_amount, _trancheId, _requestTokenId, address(this));
    tokenIdToTranches[tokenId].push(_trancheId);
    // if new nft token is minted we need to keep track of
    // tokenId and poolAddress inorder to calculate assets
    // under management
    if (tokenIdToPool[tokenId] == address(0)) {
        tokenIds.push(tokenId);
        tokenIdToPool[tokenId] = _poolAddress;
    }
}

Next owner can update beneficiary to himself:

Solidity
function changeBeneficiary(address _newBeneficiary) external onlyOwner {
    beneficiary = _newBeneficiary;
}

And then call getRewards() so pool will return fake rewards value and adminFees will be inflated:

Solidity
function getRewards() external update returns (uint256 rewards) {
    for (uint256 i = 0; i < tokenIds.length; i++) {
        uint256 tokenId = tokenIds[i];
        rewards += _withdrawFromPool(tokenIdToPool[tokenId], tokenId, false, true, tokenIdToTranches[tokenId]);
    }
    rewards += collectDexFees();
    adminFees += rewards * adminPercent / DIVISOR;
    ...
}

function _withdrawFromPool(
    ...
) internal returns (uint256 amount) {
    IStakingPool pool = IStakingPool(_poolAddress);
    (uint256 withdrawnStake, uint256 withdrawnRewards) =
        pool.withdraw(_tokenId, _withdrawStake, _withdrawRewards, _trancheIds);
    amount = withdrawnStake + withdrawnRewards;
    wNxm.wrap(amount);
}

Next he will call withdrawAdminFees() to withdraw funds:

Solidity
function withdrawAdminFees() external update {
    if (adminFees > 0) wNxm.transfer(beneficiary, adminFees);
    adminFees = 0;
}

Internal Pre-conditions

No response

External Pre-conditions

No response

Attack Path

  1. User deposits 100e18 wNXM into the stNXM contract.
  2. Owner creates a contract that matches the StakingPool interface.
  3. Owner calls stakeNxm() with his pool address and amount = 100e18.
  4. The contract unwraps wNXM, pool.depositTo() returns some tokenId, which is stored together with the pool address.
  5. Owner calls changeBeneficiary() and sets the beneficiary to himself (assume a 10% fee).
  6. Owner calls getRewards(). The contract iterates over all pools, and the fake pool returns withdrawnRewards = 100e18.
  7. The contract wraps 100e18 NXM into wNXM.
  8. adminFees increases by 10e18 wNXM (the 10% fee).
  9. The owner repeats steps 3 and 6 with slightly adjusted amounts, adding almost the entire 100e18 to adminFees.
  10. Owner calls withdrawAdminFees() and steals the funds from the contract.

Impact

Owner will steal funds from the contract.

PoC

No response

Mitigation

Ensure that poolAddress is valid in stakeNxm().

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/EaseDeFi/stNXM-Contracts/commit/448a741b44d3588c490b62134ca9e330e270a8ed

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

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

Impact

The owner can steal all funds from the contract.

What the attacker needed

Owner privileges; a fake staking pool contract

The fix

The protocol team fixed this issue by ensuring that the pool address is validated in stakeNxm().

How it was found

  1. A user deposits wNXM into the stNXM contract.
  2. The owner deploys a contract that implements the StakingPool interface.
  3. The owner calls stakeNxm() with the fake pool address and an amount.
  4. The contract unwraps wNXM, calls depositTo() on the fake pool, and stores the returned tokenId with the pool address.
  5. The owner calls changeBeneficiary() to set themselves as the fee beneficiary.
  6. The owner calls getRewards(); the fake pool returns inflated withdrawnRewards, increasing adminFees.

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.

The owner of a smart contract is normally trusted, but here the owner can trick the contract into thinking it earned large rewards from a fake pool. Those fake rewards increase the owner's fee balance, letting them take all the funds that other users deposited. The core problem is that the contract never checks whether the pool address is a real, approved staking pool.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More from stNXM by EaseDeFi

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.