Penetration Test Report (Consensys): 0x v3 audit 2019 09

0x v3 Exchange Audit
1 Summary Date September 2019
2 Audit Scope
Lead Auditor Steve Marx
3 System Overview
Co-auditors Sergii Kravchenko, Alex Wade
4 Key
Observations/Recommendations
5 Security Specication
5.1 Actors
5.2 Trust Model
6 Issues
6.1 An account that conrms a transaction via AssetProxyOwner can indenitely
block that transaction Major ✓ Fixed
6.2 Orders with signatures that require regular validation can have their validation
bypassed if the order is partially lled Major ✓ Fixed
6.3 Changing the owners or required conrmations in the AssetProxyOwner can
unconrm a previously conrmed transaction Medium ✓ Fixed
6.4 Reentrancy in executeTransaction() Medium Won't Fix
6.5 “Poison” order that consumes gas can block market trades Medium Won't Fix
6.6 Front running in matchOrders() Medium Won't Fix
6.7 The Exchange owner should not be able to call executeTransaction or
batchExecuteTransaction Medium Won't Fix
6.8 Anyone can front run MixinExchangeCore.cancelOrder() Medium
Won't Fix
6.9 By manipulating the gas limit, relayers can affect the outcome of
ZeroExTransaction s Minor Won't Fix
6.10 Front running market orders Minor Won't Fix
6.11 Modier ordering plays a signicant role in modier ecacy Minor ✓ Fixed
6.12 Several overows in LibBytes Minor ✓ Addressed
6.13 NSignatureTypes enum value bypasses Solidity safety checks Minor
Won't Fix
7 Tool-Based Analysis
7.1 MythX
7.2 Surya
Appendix 1 - Disclosure
1 Summary
ConsenSys Diligence conducted a security audit on version 3 of the 0x Exchange contract
system.
ConsenSys has previously audited 0x v2. The 0x v2 audit report is good background
reading.
2 Audit Scope
The scope of this audit was the following projects within the 0x monorepo:
exchange
exchange-libs
multisig
utils
A separate report will cover the staking contracts.
The following les were reviewed:
File Name SHA-1 Hash
exchange/contracts/src/Exchange.sol cb6733c32d[PII_REDACTED]b83a9ae
exchange/contracts/src/MixinAssetProxyDispatcher.sol ee5492092ebea3397d53163cad5
exchange/contracts/src/MixinExchangeCore.sol 87f9d192c0d75569ee95705baa9
exchange/contracts/src/MixinMatchOrders.sol 42868be4aea9327a636766682a8
exchange/contracts/src/MixinProtocolFees.sol 4982d287aaa[PII_REDACTED]39fb34
exchange/contracts/src/MixinSignatureValidator.sol a69bf0916642b2abaf7e2705d70
File Name SHA-1 Hash
exchange/contracts/src/MixinTransactions.sol c3108f751ef627e171ad35c445c8
exchange/contracts/src/MixinTransferSimulator.sol b3ceb9d2e4a8cc1c55648548b95
exchange/contracts/src/MixinWrapperFunctions.sol 69ea7edd94fc6fd1ede6c6bad139
exchange/contracts/src/interfaces/IAssetProxy.sol 21860ce6d0fe6286966dab04b39
exchange/contracts/src/interfaces/IAssetProxyDispatcher.sol f3022084eee2e1a87d4bc023d2a
exchange/contracts/src/interfaces/IEIP1271Data.sol 3e98264aa000a238a3f954b17ac
exchange/contracts/src/interfaces/IEIP1271Wallet.sol d99b3b52044cba515a1eebbee67
exchange/contracts/src/interfaces/IExchange.sol 82d342133ab823431dc07255853
exchange/contracts/src/interfaces/IExchangeCore.sol 48b0562a[PII_REDACTED]2a40cc2ce
exchange/contracts/src/interfaces/IMatchOrders.sol db34eec2bf4bc41c3b51ec35803
exchange/contracts/src/interfaces/IProtocolFees.sol bcc0151ed53fa72a87102f18015
exchange/contracts/src/interfaces/ISignatureValidator.sol e2304c3b8612ec7b7899d163b82
exchange/contracts/src/interfaces/ITransactions.sol a2f67b8a9e047c0dc7c33efda422
exchange/contracts/src/interfaces/ITransferSimulator.sol 02ea8f864e3277e1f7c30e0ea38a
exchange/contracts/src/interfaces/IWallet.sol 81fbaee73e754cfbc57882e1cd81
exchange/contracts/src/interfaces/IWrapperFunctions.sol d1b20adfa9b2639aff21e8a0d8f8
exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol 02c13f0e1c57b12da14b0384beb
exchange-libs/contracts/src/IWallet.sol d3c769706e00d8a68175a261d79
exchange-libs/contracts/src/LibEIP712ExchangeDomain.sol 823955e1f1b21a34ad3fda91c7e6
exchange-libs/contracts/src/LibExchangeRichErrors.sol e58712de5e18edfe951ea694124
exchange-libs/contracts/src/LibFillResults.sol 49422e7a81067b52f6acc8fe5de1
exchange-libs/contracts/src/LibMath.sol ca6e24ec1de03bdea83351ce5f9
exchange-libs/contracts/src/LibMathRichErrors.sol 7f3b0be62d7a8d6f3026018aad0
exchange-libs/contracts/src/LibOrder.sol 114be366ad7a0a711a0c2e55250
exchange-libs/contracts/src/LibZeroExTransaction.sol 95ea4427d1df12aef259e07ac621
multisig/contracts/src/AssetProxyOwner.sol df9ed7cba84c1362fee9de80d777
multisig/contracts/src/MultiSigWallet.sol 33b84d070486847dcc86a140fd6
File Name SHA-1 Hash
multisig/contracts/src/MultiSigWalletWithTimeLock.sol c54d8b6631eacb20fe6bfad6ee26
utils/contracts/src/Authorizable.sol 2ae731a21730cfdd30feb5d20da4
utils/contracts/src/LibAddress.sol 33eef1855488fbbbfd1eed92101f
utils/contracts/src/LibAddressArray.sol b13d0359922c04fadb4b24abd3d
utils/contracts/src/LibAddressArrayRichErrors.sol 883bc123ba699ba1efc11a75f806
utils/contracts/src/LibAuthorizableRichErrors.sol abfba41b1c63ba91803721d4d0e
utils/contracts/src/LibBytes.sol 7a0c37b1577f5a12378fbf529177
utils/contracts/src/LibBytesRichErrors.sol 611b4e660351ee4e24140074ee1
utils/contracts/src/LibEIP1271.sol 2fe0c70163677ea228d9bcfecdbb
utils/contracts/src/LibEIP712.sol 3b486180d6ee3e6d5e1f2fa57c1c
utils/contracts/src/LibFractions.sol 552a637f32edb135942cd1ea25e
utils/contracts/src/LibOwnableRichErrors.sol dfda0c5639f5fc994712421dc92b
utils/contracts/src/LibReentrancyGuardRichErrors.sol 8af2504839d0b9a4a7a46948867
utils/contracts/src/LibRichErrors.sol 3be89d9503f6fb6aee08aa515119
utils/contracts/src/LibSafeMath.sol f095f7330b0d2b0d85370b47bd5
utils/contracts/src/LibSafeMathRichErrors.sol 7785c4a4076e3f0be3319ec4bc1
utils/contracts/src/Ownable.sol 8ede7b82d2ee0ed63b2162709d8
utils/contracts/src/ReentrancyGuard.sol 5364694b8a2bba36861bfdd8d58
utils/contracts/src/Refundable.sol 0fe9acae963bb683b6c3539de83
utils/contracts/src/SafeMath.sol 5b675f9c12bf862a72c7dc71d008
utils/contracts/src/interfaces/IAuthorizable.sol 3a438f74bdb79cf6bff4dbe52a31
utils/contracts/src/interfaces/IOwnable.sol 5fe3a74b7d5948bba5644db6844
The audit activities can be grouped into the following three broad categories:
1. Security: Identifying security related issues within the contract.
2. Architecture: Evaluating the system architecture through the lens of established
smart contract best practices.
3. Code quality: A full review of the contract source code. The primary areas of focus
include:
Correctness
Readability
Scalability
Code complexity
Quality of test coverage
3 System Overview
The 0x Exchange is a decentralized exchange where various on-chain assets can be
traded. It uses an approach the 0x team refers to as “off-chain order relay with on-chain
settlement”. This means that, in the typical case, traders use signatures to indicate their
willingness to perform a certain trade, and anyone can deliver those trades to the on-chain
exchange contract, where the trade will be executed.
The 0x protocol 3.0 specication is an excellent explanation of the exchange and its inner
workings.
4 Key Observations/Recommendations
The exchange documentation is excellent. Not only does it explain how the contract is
used, but it gives a detailed explanation of what each function does.
The code is clear and includes helpful comments.
Code for the exchange is spread across quite a few les. This sometimes makes it
dicult to follow various paths through the code.
There is quite a bit of low-level assembly. This carries a risk, particularly where direct
memory access is involved. It would be good to stick to Solidity as where possible.
Signature checking, as in 0x v2 remains an area of high complexity. If possible, it
would be good to reduce the number of signature methods.
5 Security Specication
This section describes, from a security perspective, the expected behavior of the system
under audit. It is not a substitute for documentation. The purpose of this section is to
identify specic security properties that were validated by the audit team.
5.1 Actors
The relevant actors are as follows:
0x team – deploys and ini