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:
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:
function changeBeneficiary(address _newBeneficiary) external onlyOwner {
beneficiary = _newBeneficiary;
}
And then call getRewards() so pool will return fake rewards value and adminFees will be inflated:
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:
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
- User deposits
100e18 wNXMinto thestNXMcontract. - Owner creates a contract that matches the
StakingPoolinterface. - Owner calls
stakeNxm()with his pool address andamount = 100e18. - The contract unwraps
wNXM,pool.depositTo()returns sometokenId, which is stored together with the pool address. - Owner calls
changeBeneficiary()and sets the beneficiary to himself (assume a 10% fee). - Owner calls
getRewards(). The contract iterates over all pools, and the fake pool returnswithdrawnRewards = 100e18. - The contract wraps
100e18 NXMintowNXM. adminFeesincreases by10e18 wNXM(the 10% fee).- The owner repeats steps 3 and 6 with slightly adjusted amounts, adding almost the entire
100e18toadminFees. - 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
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
- A user deposits wNXM into the stNXM contract.
- The owner deploys a contract that implements the StakingPool interface.
- The owner calls stakeNxm() with the fake pool address and an amount.
- The contract unwraps wNXM, calls depositTo() on the fake pool, and stores the returned tokenId with the pool address.
- The owner calls changeBeneficiary() to set themselves as the fee beneficiary.
- 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.