Papr contest - teawaterwire's results

NFT Lending Powered by Uniswap v3.

General Information

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

Backed Protocol

Findings Distribution

Researcher Performance

Rank: 54/58

Findings: 1

Award: $33.40

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

Labels

bug
2 (Med Risk)
satisfactory
duplicate-196

Awards

33.3998 USDC - $33.40

External Links

Lines of code

https://github.com/with-backed/papr/blob/9528f2711ff0c1522076b9f93fba13f88d5bd5e6/src/PaprController.sol#L226

Vulnerability details

Impact

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).

Proof of Concept

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.

Tools Used

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

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter