DerivaDEX 2

QuantstampFiles named in the report

Quantstamp reviewed DerivaDEX 2 on 22 Jul 2022: 23 findings, 0 critical; 12 marked fixed, 8 acknowledged, 3 open.

No open critical findings
Open the reportOpen DerivaDEX 2’s security record

Report hosted on certificate.quantstamp.com.

Trustblock does not review code.

Findings23

Statuses are the security firm’s own, from its report.

SeverityOpenAcknowledgedFixed
Critical000
High002
Medium111
Low279
MediumGas Concern: Looping Through `registeredCustodians`Acknowledged

The code loops through the `registeredCustodians` of a specific release hash in a few places: `Custodian.sol:L185-196` (the `setMinimumBond` function), `Registration.sol:L221-231` (the `updateReleaseSchedule` function), and `LibRelease.sol:L54-65` (the `evaluateReleaseSchedule` function). Too many custodians/signers registered for a specific release hash can block the for-loop by running out of gas. Among the potential failures, the failure on the `LibRelease:evaluateReleaseSchedule` function is the most severe one. The failure of the `LibRelease:evaluateReleaseSchedule` function will cause the function `Checkpoint.sol:checkpoint` to fail. Therefore, the checkpoint can fail to proceed if too many registered custodians exist.

LowDiamond Facet UpgradeAcknowledged

If, during an upgrade, `diamondCut(...)` calls are executed in multiple Ethereum transactions, users may be exposed to contracts that are upgraded only partially, i.e., some of the functions are upgraded while others are not. This may result in unexpected inconsistencies.

LowHardcoded Chain DiscriminatorAcknowledged

The function `LibCollateral.sol:generateTraderGroupKey` (L630-638) simply keep the "0" as the chain discriminator. According to the code document, the design preserves 0 for the Ethereum chain. There are some risks with this discriminator. First, one should not deploy this code to another chain. So future code changes and audits should be aware of this. Meanwhile, the "Ethereum" chain can refer to test nets and the main net. The current implementation will fail to discriminate the test net from the main net.

LowHighly Dependent on Off-Chain ComponentsAcknowledged

DerivaDEX, as currently implemented, relies heavily on off-chain components. For example, a minimum number of two registered custodians is required at all times for the proper functioning of the protocol. However, if custodians are hacked or DDoSed, this may cause problems for the protocol.

LowNon-Unique SMT Leaf Hash on Empty ValueAcknowledged

From the reference sparse Merkle tree documentation ([link](https://justjjy.com/An-optimized-compact-sparse-merkle-tree)), it states that: "Since the key is included in the leaf’s hash, and the key is unique in SMT, no matter what the value is, the leaf_hash(key, value) is unique". However, in the function `LibSMT.sol:hashLeaf` (L225-236), it directly returns `0x00` if the leaf's value is empty. This `0x00` value violates the spec that the leaf hash should be unique no matter the value. One can give two different keys with an empty value. The "leaf-hash" returned from the function will both be empty. Luckily, this vulnerability does not impact any of the current contracts. The `LibSMT.sol:computeRoot` function is used inside `Collateral.sol`, `FundedInsuranceFund.sol`, and `Stake.sol`. All of the current occurrences provide a non-empty leaf value.

LowRisk of `initialize(...)` Called More than OnceAcknowledged

The function `initialize(...)` does not have an explicit guard against being called more than once. The current implementation relies on the operation to carefully remove the `initialize` from the `functionSelectors` when calling `diamondCut`. This can be prone to error, and the impact can be huge once the facet is re-initialized.

LowUnnecessary `SafeMath`Acknowledged

Solidity 0.8 embeds the overflow/underflow check as part of the compiler. Thus, it is no longer needed or recommended to use the `SafeMath` library. (Note that this issue occurs after the re-audit fix for QSP-18)

LowUnnecessary Complexity of `LibSMT`Acknowledged

The `LibSMT.sol:computeRoot` (L63-84) accepts an array of leaves and a proof to calculate the root. However, all the code referencing the `LibSMT.sol:computeRoot` only passes the `_leaves` with a single element in the array (see: `Collateral.sol:L370`, `FundedInsuranceFund.sol:L136`, and `Stake.sol:L185`). As a result, it is possible to change the function signature of the `LibSMT.sol:computeRoot` to accept single leaf input. If `LibSMT.sol` only needs to support the computation of a single leaf, it can remove the function of `LibSMT.sol:operationHashSiblings`. Furthermore, the need for the stack diminishes as the computation only needs to stack a single node (or two items: one key and one value) inside the stack at a time. The code can replace the stack with two variables.

Contracts in scope

No deployed address is recorded for this audit.

The report names a repository or files. Open the report to see its scope.

Repository and files the report names (99)

  • protocol/contracts/src/tokens/DummyToken.sol
  • protocol/contracts/src/storage/LibDiamondStoragePause.sol
  • protocol/contracts/src/facets/Checkpoint.sol
  • protocol/contracts/src/facets/Custodian.sol
  • protocol/contracts/test/TestLibCheckpoint.sol
  • protocol/contracts/src/gnosis/ICreateCall.sol
  • protocol/contracts/src/libs/LibBytes.sol
  • protocol/contracts/src/facets/InsuranceFund.sol
  • protocol/contracts/test/TestFundedInsuranceFund.sol
  • protocol/contracts/src/libs/LibTraderInternal.sol
  • protocol/contracts/src/facets/Specs.sol
  • protocol/contracts/src/facets/interfaces/IInsuranceFund.sol
  • protocol/contracts/src/libs/LibClone.sol
  • protocol/contracts/test/TestLibBytes32.sol
  • protocol/contracts/src/facets/Trader.sol
  • protocol/contracts/src/libs/defs/CheckpointDefs.sol
  • protocol/contracts/src/diamond/OwnershipFacet.sol
  • protocol/contracts/src/libs/defs/SpecsDefs.sol
  • protocol/contracts/src/tokens/interfaces/IDIFundTokenFactory.sol
  • protocol/contracts/src/facets/Governance.sol
  • protocol/contracts/test/TestSolRsaVerify.sol
  • protocol/contracts/test/TestRegistrationForSnapshot.sol
  • protocol/contracts/src/libs/SafeMath128.sol
  • protocol/contracts/src/libs/LibDelegation.sol
  • protocol/contracts/test/TestRegistration.sol
  • protocol/contracts/src/libs/LibEIP712.sol
  • protocol/contracts/src/DerivaDEX.sol
  • protocol/contracts/src/libs/defs/DepositDefs.sol
  • protocol/contracts/src/storage/LibDiamondStorageDerivaDEX.sol
  • protocol/contracts/src/diamond/DiamondFacet.sol
  • protocol/contracts/src/tokens/interfaces/IDDX.sol
  • protocol/contracts/src/facets/Banner.sol
  • protocol/contracts/src/tokens/interfaces/IDIFundToken.sol
  • protocol/contracts/src/libs/MathHelpers.sol
  • protocol/contracts/src/gnosis/IGnosisSafeProxyFactory.sol
  • protocol/contracts/test/TestLibCollateral.sol
  • protocol/contracts/src/facets/Stake.sol
  • protocol/contracts/src/libs/defs/FundedInsuranceFundDefs.sol
  • protocol/contracts/src/facets/interfaces/IComptroller.sol
  • protocol/contracts/src/libs/defs/InsuranceFundDefs.sol
  • protocol/contracts/src/storage/LibDiamondStorageTrader.sol
  • protocol/contracts/src/libs/StringUtils.sol
  • protocol/contracts/test/TestCheckpointSingleNodeDeployment.sol
  • protocol/contracts/src/libs/defs/TraderDefs.sol
  • protocol/contracts/src/diamond/IERC165.sol
  • protocol/contracts/test/GasConsumer.sol
  • protocol/contracts/src/libs/LibSMT.sol
  • protocol/contracts/src/storage/LibDiamondStorageRegistration.sol
  • protocol/contracts/src/libs/LibRelease.sol
  • protocol/contracts/src/diamond/LibDiamondStorage.sol
  • protocol/contracts/src/facets/Registration.sol
  • protocol/contracts/test/TestLibSMT.sol
  • protocol/contracts/src/libs/Base64.sol
  • protocol/contracts/src/diamond/IDiamondCut.sol
  • protocol/contracts/src/storage/LibDiamondStorageDeposit.sol
  • protocol/contracts/src/libs/LibSignature.sol
  • protocol/contracts/src/libs/LibBytes32.sol
  • protocol/contracts/src/libs/defs/SharedDefs.sol
  • protocol/contracts/src/libs/LibCheckpoint.sol
  • protocol/contracts/src/libs/defs/GovernanceDefs.sol
  • protocol/contracts/src/tokens/SafeERC20Wrapper.sol
  • protocol/contracts/test/TestLibRelease.sol
  • protocol/contracts/src/diamond/LibDiamondCut.sol
  • protocol/contracts/src/libs/LibVoteCast.sol
  • protocol/contracts/src/libs/SolRsaVerify.sol
  • protocol/contracts/src/tokens/CompetitionDummyToken.sol
  • protocol/contracts/test/TestStake.sol
  • protocol/contracts/src/tokens/DIFundToken.sol
  • protocol/contracts/src/facets/interfaces/ICToken.sol
  • protocol/contracts/test/TestCollateral.sol
  • protocol/contracts/test/TestCheckpointMultiNodeDeployment.sol
  • protocol/contracts/src/gnosis/IGnosisSafe.sol
  • protocol/contracts/src/tokens/DDXWalletCloneable.sol
  • protocol/contracts/src/storage/LibDiamondStorageDepositGuarded.sol
  • protocol/contracts/src/storage/LibDiamondStorageReentrancyGuard.sol
  • protocol/contracts/src/tokens/HDUMToken.sol
  • protocol/contracts/src/libs/SafeMath96.sol
  • protocol/contracts/src/libs/LibCollateral.sol
  • protocol/contracts/src/tokens/DIFundTokenFactory.sol
  • protocol/contracts/src/tokens/interfaces/IDDXWalletCloneable.sol
  • protocol/contracts/src/facets/Pause.sol
  • protocol/contracts/src/tokens/DDX.sol
  • protocol/contracts/test/TestLibStack.sol
  • protocol/contracts/src/libs/LibStack.sol
  • protocol/contracts/src/libs/SafeMath32.sol
  • protocol/contracts/src/tokens/interfaces/IERC20Extended.sol
  • protocol/contracts/test/TestCheckpoint.sol
  • protocol/contracts/src/facets/FundedInsuranceFund.sol
  • protocol/contracts/src/libs/LibPermit.sol
  • protocol/contracts/src/storage/LibDiamondStorageGovernance.sol
  • protocol/contracts/src/diamond/IDiamondLoupe.sol
  • protocol/contracts/src/storage/LibDiamondStorageBanner.sol
  • protocol/contracts/src/libs/defs/RegistrationDefs.sol
  • protocol/contracts/src/facets/Collateral.sol
  • protocol/contracts/src/storage/LibDiamondStorageCheckpoint.sol
  • protocol/contracts/src/facets/interfaces/IAToken.sol
  • protocol/contracts/src/storage/LibDiamondStorageInsuranceFund.sol
  • protocol/contracts/src/facets/Reject.sol
  • protocol/contracts/src/libs/ReentrancyGuard.sol

Part of DerivaDEX 2’s security record

DerivaDEX 2
Audits1 audit by 1 firmLast audit Jul 2022, by Quantstamp.
Critical findingsNo open critical findingsIn 1 report.
Open DerivaDEX 2’s security record

Security firm

Quantstamp

236 projects reviewed · 332 reports · latest Oct 2026

See Quantstamp’s audits

Something wrong on this page? A missing report, a wrong date, a finding that was fixed since. Tell us and we check it against its source.

Tell us