Dopex - gumgumzum'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: 163/189

Findings: 1

Award: $0.07

🌟 Selected for report: 0

🚀 Solo Findings: 0

Lines of code

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

Vulnerability details

Impact

totalWethDelegated is not updated after withdrawing unused WETH leading incorrect WETH reserve balance after a sync or its failure due to an arithmetic underflow.

Proof of Concept

Test

  function testSync() public {
    weth.transfer(address(rdpxV2Core), 10 ether);
    
    uint256 rdpxV2CoreWethBalance = weth.balanceOf(address(rdpxV2Core));
    
    weth.transfer(address(vm.addr(8)), rdpxV2CoreWethBalance * 2);

    vm.startPrank(vm.addr(8));

    weth.approve(address(rdpxV2Core), rdpxV2CoreWethBalance * 2);

    rdpxV2Core.sync();
    uint256 delegateId = rdpxV2Core.addToDelegate(rdpxV2CoreWethBalance * 2, 2e8);
    rdpxV2Core.withdraw(delegateId);

    vm.stopPrank();

    rdpxV2Core.sync();
  }

Results

Running 1 test for tests/rdpxV2-core/Unit.t.sol:Unit [FAIL. Reason: Arithmetic over/underflow] testSync() (gas: 311989) Test result: FAILED. 0 passed; 1 failed; finished in 1.48s

Tools Used

Manual Review

Decrement totalWethDelegated when withdrawing unused WETH

  function withdraw(
    uint256 delegateId
  ) external returns (uint256 amountWithdrawn) {
    _whenNotPaused();
    _validate(delegateId < delegates.length, 14);
    Delegate storage delegate = delegates[delegateId];
    _validate(delegate.owner == msg.sender, 9);

    amountWithdrawn = delegate.amount - delegate.activeCollateral;
    _validate(amountWithdrawn > 0, 15);
    delegate.amount = delegate.activeCollateral;

    totalWethDelegated -= amountWithdrawn;
    
    IERC20WithBurn(weth).safeTransfer(msg.sender, amountWithdrawn);

    emit LogDelegateWithdraw(delegateId, amountWithdrawn);
  }

Assessed type

Math

#0 - c4-pre-sort

2023-09-07T07:58:51Z

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:56:53Z

GalloDaSballo marked the issue as satisfactory

#3 - c4-judge

2023-10-21T07:38:54Z

GalloDaSballo changed the severity to 3 (High Risk)

#4 - c4-judge

2023-10-21T07:47:10Z

GalloDaSballo marked the issue as partial-50

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