0x Invalid Signature Flaw

From Quadriga Initiative Cryptocurrency Hacks, Scams, and Frauds Repository
Revision as of 21:13, 24 January 2023 by Azoundria (talk | contribs) (Created page with "{{Imported Case Study|source=https://www.quadrigainitiative.com/casestudy/0xinvalidsignatureflaw.php}} thumb|0x ProjectThe 0x project offered a "liquidity aggregator" which is used as part of an online exchange. In order to use the exchange, a trader needs to sign the transaction. However, there was a way to bypass this mechanism, which could have allowed an attacker to conduct fraudulent trades. The exploit was fixed before any funds were taken....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Notice: This page is a freshly imported case study from the original repository. The original content was in a different format, and may not have relevant information for all sections. Please help restructure the content by moving information from the 'About' section to other sections, and add any missing information or sources you can find. If you are new here, please read General Tutorial on Wikis or Anatomy of a Case Study for help getting started.

0x Project

The 0x project offered a "liquidity aggregator" which is used as part of an online exchange. In order to use the exchange, a trader needs to sign the transaction. However, there was a way to bypass this mechanism, which could have allowed an attacker to conduct fraudulent trades.

The exploit was fixed before any funds were taken.

This is a global/international case not involving a specific country.

About 0x Project

The "0x API is a professional grade liquidity aggregator, enabling the future of DeFi applications." Their "smart order routing splits up your transaction across decentralized exchange networks to be filled with the lowest slippage possible."

"From July 23, 2018 to September 7, 2018 ConsenSys Diligence conducted a security audit of the 0x project's protocol version v2 of their contract system."

"On Friday July 12th, 0x shut down their v2 Exchange because a flaw in the signature verification routine meant that a signature of 0x04 was treated as a valid signature for all non-smart-contract accounts."

"Under normal circumstances (a conformant IFetcher implementation), this code works fine, but something surprising happens if you pass in an externally owned account (EOA). An EOA address has no associated code, and this means all calls to it succeed and return nothing. The low-level STATICCALL opcode used here will return success but will only copy as much data into memory as was returned. So even though we asked for 32 bytes of return data, nothing gets copied to memory because there is no data to copy."

"Because nothing gets copied, memory is just as it was before the call. That means ptr is still pointing to the selector data, so this function returns 0xa95c372d000000… (the function selector for fetch())."

"The same thing happens if you call a contract that implements fetch() without a return value or just implements a fallback function. The bug occurs any time the call succeeds but doesn’t return as much data as the caller expects."

"This bug manifested itself in the 0x v2.0 Exchange in a particularly nasty way due to where the bug was. The exchange allows trades to be constructed off chain and then validated and filled on chain. To know that a trade is authorized, the exchange must validate a trader’s signature."

"One option the exchange offers for validating a trader’s signature is to delegate that checking to a contract. Essentially, the trader can be a smart wallet that implements a function with the signature isValidSignature(bytes32,bytes) and returns a boolean true if the signature is valid."

"[T]he problem is that isValidSignature is called via code that’s very similar to the above vulnerable contract. If the target is not a smart contract (or otherwise returns no data), the data already in memory stays unchanged. Any non-zero value there is interpreted as true and authorizes the trade."

"Even this would be okay if traders had to specifically opt in to this type of signature scheme, but remember that these trades are constructed off chain to avoid the expense and delay of making an on chain transaction. So the person taking the proposed trade is able to dictate which type of signature checking should happen via a flag."

"All an attacker needs to do is trade with an externally owned account and specify that the signature should be checked by calling isValidSignature. This validation will succeed because no data is returned and the data already present in memory is non-zero."

The project "patched and re-deployed the[ir] entire 0x smart contract pipeline from scratch, updated [their] developer tools and packages, 0x Instant, and 0x Launch Kit." "[T]he vulnerability found in the 0x v2.0 Exchange contract was not exploited and no user funds [were] lost."

"Teams will need to point to the patched and newly deployed Exchange and AssetProxy contracts as well as clear their orderbooks of outstanding orders. Users will need to reset their allowances for the new 0x AssetProxy contracts."

This is a global/international case not involving a specific country.

The background of the exchange platform, service, or individuals involved, as it would have been seen or understood at the time of the events.

Include:

  • Known history of when and how the service was started.
  • What problems does the company or service claim to solve?
  • What marketing materials were used by the firm or business?
  • Audits performed, and excerpts that may have been included.
  • Business registration documents shown (fake or legitimate).
  • How were people recruited to participate?
  • Public warnings and announcements prior to the event.

Don't Include:

  • Any wording which directly states or implies that the business is/was illegitimate, or that a vulnerability existed.
  • Anything that wasn't reasonably knowable at the time of the event.

There could be more than one section here. If the same platform is involved with multiple incidents, then it can be linked to a main article page.

The Reality

This sections is included if a case involved deception or information that was unknown at the time. Examples include:

  • When the service was actually started (if different than the "official story").
  • Who actually ran a service and their own personal history.
  • How the service was structured behind the scenes. (For example, there was no "trading bot".)
  • Details of what audits reported and how vulnerabilities were missed during auditing.

What Happened

The specific events of the loss and how it came about. What actually happened to cause the loss and some of the events leading up to it.

Key Event Timeline - 0x Invalid Signature Flaw
Date Event Description
July 13th, 2019 12:00:00 AM First Event This is an expanded description of what happened and the impact. If multiple lines are necessary, add them here.

Total Amount Lost

The total amount lost is unknown.

How much was lost and how was it calculated? If there are conflicting reports, which are accurate and where does the discrepancy lie?

Immediate Reactions

How did the various parties involved (firm, platform, management, and/or affected individual(s)) deal with the events? Were services shut down? Were announcements made? Were groups formed?

Ultimate Outcome

What was the end result? Was any investigation done? Were any individuals prosecuted? Was there a lawsuit? Was any tracing done?

Total Amount Recovered

It is unknown how much was recovered.

What funds were recovered? What funds were reimbursed for those affected users?

Ongoing Developments

What parts of this case are still remaining to be concluded?

Prevention Policies

There was no loss to users of the exchange in this case.

References

List of Ethereum Smart Contracts Post-Mortems - Security - OpenZeppelin Community (Jun 22)

Shut down of 0x Exchange v2.0 contract and migration to patched version | by Will Warren | 0x Blog (Jun 22)

Post Mortem 0x V2 0 Exchange Vulnerability (Jun 22)

The 0x vulnerability, explained (Jun 22)

Return Data Length Validation A Bug We Missed (Jun 22)

0x: Powering the decentralized exchange of tokens on Ethereum (Jun 23)

GitHub - ConsenSys/0x_audit_report_2018-07-23: 0x Protocol v2 Audit (Jun 23)