Skip to content
Access control Write-up Intermediate

Mcdex Insufficient Validation Bug Fix Review

The Broker contract's batchTrade function trusted a caller-supplied liquidity pool contract to validate data, and also allowed the caller to choose source and destination addresses for gas reimbursement. An attacker could supply a malicious pool that performed no validation and set the victim as source and themselves as destination, draining the victim's deposited ETH.

immunefi.com

Published on immunefi.com

Whitehat Lucash-dev, who is a member of Immunefi’s Whitehat Scholarship, submitted a critical vulnerability in MCDEX’s broker contract on June 14 that would have allowed a malicious user to drain that contract of ETH. It does not appear as though the vulnerability was ever exploited, and at the time of the report…

The author, on immunefi.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The batchTrade function delegated validation to a caller-supplied liquidity pool contract and allowed the caller to freely choose the source and destination addresses for gas reimbursement, so no trusted check tied the transfer to a legitimate trade.

Impact

An attacker could drain all user funds deposited in the Broker contract, though at the time of the report the funds at risk were not substantial and the bug was fixed before exploitation.

What the attacker needed

Victim has deposited funds in Broker; attacker can deploy a contract; attacker can call batchTrade

The fix

The batchTrade function was fixed by adding validation of the signature provided by the caller.

How it was found

  1. Deploy a malicious liquidity pool contract whose brokerTrade function does nothing.
  2. Have a victim deposit funds into the Broker contract.
  3. Build an order with the victim as trader, the attacker as relayer, and the malicious pool as liquidity pool.
  4. Call batchTrade with the compressed order and a gas reimbursement amount of one ether.
  5. Observe the victim's balance drop to zero and the attacker's balance rise by the same amount.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A smart contract is a program on a blockchain that holds and moves funds. Here, a function that was supposed to check trades trusted another contract chosen by the caller to do the checking, so an attacker could point it at a fake contract that checked nothing. The function also let the caller pick whose money to take and where to send it, so the attacker could move another user's deposit to themselves.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.