Platform: Code4rena
Start Date: 16/12/2022
Pot Size: $60,500 USDC
Total HM: 12
Participants: 58
Period: 5 days
Judge: Trust
Total Solo HM: 4
Id: 196
League: ETH
Rank: 54/58
Findings: 1
Award: $33.40
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Jeiwan
Also found by: 0x52, Franfran, HollaDieWaldfee, KingNFT, Saintcode_, bin2chen, evan, fs0c, noot, poirots, rvierdiiev, stealthyz, teawaterwire, unforgiven
33.3998 USDC - $33.40
When passing fee params to buyAndReduceDebt
with swapFeeTo
and swapFeeBips
, the PaprController will try to send the underlying token on the following line:
underlying.transfer(params.swapFeeTo, amountIn * params.swapFeeBips / BIPS_ONE);
But in a normal state, the controller won't have any underlying token as they are sent directly to the Uniswap pool. Therefore the function will fail if a fee is passed.
And if the controller were to hold these tokens (usdc for instance) this could be even worse as an attacker could drain them by buying small amounts of Papr token passing a big fee (bigger than the amountIn - there is no check on that).
It only takes modifying the test testBuyAndReduceDebtReducesDebt
:
uint256 fee = 100; underlying.approve(address(controller), underlyingOut + underlyingOut * fee / 1e4); swapParams = IPaprController.SwapParams({ amount: underlyingOut, minOut: 1, sqrtPriceLimitX96: _maxSqrtPriceLimit({sellingPAPR: false}), swapFeeTo: address(5), swapFeeBips: fee });
resulting in the following error:
Encountered 1 failing test in test/paprController/BuyAndReduceDebt.t.sol:BuyAndReduceDebt [FAIL. Reason: Arithmetic over/underflow] testBuyAndReduceDebtReducesDebt() (gas: 454860)
happening on the the line of the underlying token transfer.
forge
The same way it's done in increaseDebtAndSell
to get the underlying token first on the controller and then send them to the fee recipient and the user
#0 - c4-judge
2022-12-25T16:53:31Z
trust1995 marked the issue as duplicate of #20
#1 - c4-judge
2022-12-25T16:53:36Z
trust1995 marked the issue as satisfactory
#2 - C4-Staff
2023-01-10T22:32:22Z
JeeberC4 marked the issue as duplicate of #196