AutoExit could receive a reward calculated from the entire position’s fund even if onlyFee is true in AutoExit.execute()
kennedy1030 Follow with deepplus and KupiaSec
Originally disclosed on Code4rena
Submitted by kennedy1030, also found by deepplus and KupiaSec
https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/automators/AutoExit.sol#L100-L214
https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/automators/Automator.sol#L193-L215
Impact
The owner of the NFT could end up paying more rewards to AutoExit than anticipated when onlyFee is set to true.
Proof of Concept
https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/automators/AutoExit.sol#L155
function execute(ExecuteParams calldata params) external {
[...]
// reward is taken before swap - if from fees only
if (config.onlyFees) {
155 state.amount0 -= state.feeAmount0 * params.rewardX64 / Q64;
state.amount1 -= state.feeAmount1 * params.rewardX64 / Q64;
}
[...]
}
https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/automators/Automator.sol#L208
function _decreaseFullLiquidityAndCollect(
uint256 tokenId,
uint128 liquidity,
uint256 amountRemoveMin0,
uint256 amountRemoveMin1,
uint256 deadline
) internal returns (uint256 amount0, uint256 amount1, uint256 feeAmount0, uint256 feeAmount1) {
if (liquidity > 0) {
// store in temporarily "misnamed" variables - see comment below
202 (feeAmount0, feeAmount1) = nonfungiblePositionManager.decreaseLiquidity(
INonfungiblePositionManager.DecreaseLiquidityParams(
tokenId, liquidity, amountRemoveMin0, amountRemoveMin1, deadline
)
);
}
208 (amount0, amount1) = nonfungiblePositionManager.collect(
INonfungiblePositionManager.CollectParams(tokenId, address(this), type(uint128).max, type(uint128).max)
);
// fee amount is what was collected additionally to liquidity amount
feeAmount0 = amount0 - feeAmount0;
feeAmount1 = amount1 - feeAmount1;
}
As seen at L208, feeAmount represents the uncollected fees excluding assets from the current liquidity. However, it includes the owed amount, which comprises uncollected assets not just from fees but also from nonfungiblePositionManager.decreaseLiquidity() called earlier at L202. If the owner has already executed nonfungiblePositionManager.decreaseLiquidity(), the uncollected assets would consist of some assets withdrawn from their liquidity, possibly a significant portion. This implies that onlyFee configuration is not functioning effectively.
Here is a simple scenario to highlight this issue:
- The owner invokes
nonfungiblePositionManager.approve(address(autoExit), NFT)and setsonlyFeeto true. - The owner then calls
nonfungiblePositionManager.decreaseLiquidity()to withdraw the majority of their liquidity.. - Subsequently, an operator calls
autoExit.execute()and receives more rewards than anticipated.
Recommended Mitigation Steps
In Automator._decreaseFullLiquidityAndCollect(), feeAmount0, feeAmount1 must only include the amount calculated from the feeGrowthInside of UniswapV3 position.
mariorz (Revert) acknowledged, but disagreed with severity and commented:
Don’t believe this should be a “high risk”.
- Users calling
decreaseLiquiditywithout calling collect is possible but non-standard and there is no real reason to do this.- If this ever happened by some edge case, the
Operatoris an approved role that would be incentivized to return the extra fees to the affected user.- There is no risk for other lenders or borrowers.
- Risk for the affected LP is limited to <2% of the position value.
ronnyx2017 (judge) decreased severity to Medium and commented:
More like user error or a malicious operator.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in Revert Lend. Code4rena made it public on 22 May 2024. Found in the 2024-03-revert-lend audit contest (finding M-17), also found by 2 other wardens.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.