Dopex - Vagner's results

A rebate system for option writers in the Dopex Protocol.

General Information

Platform: Code4rena

Start Date: 21/08/2023

Pot Size: $125,000 USDC

Total HM: 26

Participants: 189

Period: 16 days

Judge: GalloDaSballo

Total Solo HM: 3

Id: 278

League: ETH

Dopex

Findings Distribution

Researcher Performance

Rank: 143/189

Findings: 2

Award: $10.34

🌟 Selected for report: 1

🚀 Solo Findings: 0

Lines of code

https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/core/RdpxV2Core.sol#L975-L990

Vulnerability details

Impact

totalWethDelegated is not updated in all of the functionalities involving delegated WETH, which could cause, a malicious user to block all of the internal accounting of the protocol.

Proof of Concept

The variable totalWethDelegated is used to account for all of the WETH which is available to use in the bondWithDelegate mechanism. Every time someone intends to delegate their WETH to be used in the bonding process and gain some initiatives out of it, they can call addToDelegate which creates a new delegate position and adds the amount transferred to totalWethDelegated https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/core/RdpxV2Core.sol#L941-L964 In the case where that specific user doesn't want to delegate their WETH anymore, they can call withdraw to withdraw their WETH out of the contract, updating the delegate position https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/core/RdpxV2Core.sol#L975-L990 but nowhere in the withdraw, totalWethDelegated gets updated which means that an abuser can inflate totalWethDelegated as much as he wants by calling addToDelegate and then withdraw. The only way totalWethDelegated can lower it's value is only in the bonding with delegate mechanism, process which could fail since the value is inflated and there isn't that actual amount of WETH in the contract. Also because of totalWethDelegated being too big, all of the time sync would be called it will fail and revert because of the underflow that will happen here https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/core/RdpxV2Core.sol#L1002 when it tries to subtract totalWethDelegated from the balance that the contract has in WETH, which means that the whole UniV2LiquidityAmo.sol and UniV3LiquidityAmo.sol functionality would fail and revert, blocking important mechanisms used by the protocol, with their funds in UniswapV2 or V3.

Tools Used

Manual review

Every time withdraw is called, subtract also from the totalWethDelegated, the amount that the user provided, so in that way totalWethDelegated would be accurate to the WETH available in the contract for delegations.

Assessed type

Under/Overflow

#0 - c4-pre-sort

2023-09-07T08:01:23Z

bytes032 marked the issue as duplicate of #2186

#1 - c4-judge

2023-10-20T17:55:32Z

GalloDaSballo changed the severity to 2 (Med Risk)

#2 - c4-judge

2023-10-20T17:57:13Z

GalloDaSballo marked the issue as satisfactory

#3 - c4-judge

2023-10-20T18:01:09Z

GalloDaSballo removed the grade

#4 - c4-judge

2023-10-20T18:01:18Z

GalloDaSballo marked the issue as satisfactory

#5 - c4-judge

2023-10-21T07:38:54Z

GalloDaSballo changed the severity to 3 (High Risk)

Awards

10.1883 USDC - $10.19

Labels

bug
2 (Med Risk)
downgraded by judge
primary issue
satisfactory
selected for report
sponsor confirmed
sufficient quality report
M-15

External Links

Lines of code

https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/amo/UniV2LiquidityAmo.sol#L160-L178 https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/amo/UniV3LiquidityAmo.sol#L118-L133

Vulnerability details

Impact

The function sync is used in RdpxV2Core.sol to synchronize the balances of the reserve assets stored in the contract, but it is not called in all of the situations where swaps/providing/removing liquidity is made.

Proof of Concept

As you can see sync is called in UniV3LiquidityAmo.sol after _sendTokensToRdpxV2Core is called to occur for all of the balances change after modifying the liquidity in UniswapV3 https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/amo/UniV3LiquidityAmo.sol#L361 but it is not called functions like collectFees where funds are directly transferred to RdpxV2Core.sol https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/amo/UniV3LiquidityAmo.sol#L118-L133 or in _sendTokensToRdpxV2Core in the UniV2LiquidityAmo.sol which transfers tokens to RdpxV2Core https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/amo/UniV2LiquidityAmo.sol#L157-L178 Because of that wrong assumptions can be taken in cases of lowerDepeg or upperDepeg, or any other functions that uses the balances of assets stored, if sync was not called before.

Tools Used

Manual review

Since you already call sync in _sendTokensToRdpxV2Core from UniV3LiquidityAmo.sol, call it in collectFees and _sendTokensToRdpxV2Core from UniV2LiquidityAmo.sol also to accounts for any balance changes, which will protect the protocol against errors.

Assessed type

Other

#0 - c4-pre-sort

2023-09-09T03:53:50Z

bytes032 marked the issue as duplicate of #798

#1 - c4-pre-sort

2023-09-09T04:06:58Z

bytes032 marked the issue as not a duplicate

#2 - c4-pre-sort

2023-09-09T04:07:02Z

bytes032 marked the issue as primary issue

#3 - bytes032

2023-09-09T04:11:06Z

Potentially impacts the following functions:

Edit: It’s actually not called in collectFee’s as well. I’m duplicating all of these under a single primary issue, because #269 mentions both.

#4 - c4-pre-sort

2023-09-11T11:57:22Z

bytes032 marked the issue as sufficient quality report

#5 - c4-sponsor

2023-09-25T17:26:00Z

witherblock (sponsor) confirmed

#6 - GalloDaSballo

2023-10-12T08:02:10Z

Seems like an opportunity for a higher exploit was missed by stopping at the broken sync

#7 - c4-judge

2023-10-15T18:11:07Z

GalloDaSballo marked issue #250 as primary and marked this issue as a duplicate of 250

#8 - c4-judge

2023-10-15T18:11:19Z

GalloDaSballo marked the issue as satisfactory

#9 - c4-judge

2023-10-15T18:14:22Z

GalloDaSballo changed the severity to 3 (High Risk)

#10 - c4-judge

2023-10-15T18:14:28Z

GalloDaSballo changed the severity to 2 (Med Risk)

#11 - c4-judge

2023-10-25T07:26:26Z

GalloDaSballo marked the issue as selected for report

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