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
MediumUnsafe Signer RegistrationOpen

The function `Registration:register` (L134-180) is of some concern: 1. Front-run attack: the `register` function binds the "signer" address retrieved from an SGX report data to the function caller (`msg.sender`). However, anyone can monitor the transaction mempool and front-run the call with the same data to bind a specific signer to the attacker's custodian. Neither the `_report` nor the `_signature` specifies which custodian to tie to the signer. Also, note the current implementation does not require the caller of the `register` function to be an approved custodian. Thus, anyone can perform this attack. 2. Replay attack: the `releaseHash` from the `extractMetadataFromReport` function relies on `mrEnclave` and `isvSvn`. However, we assume that the team will run multiple environments (e.g., staging and prod) as a common software engineering practice, and the enclave (program) data can be the same. There can be the risk of a replay attack on the same report and signer cross environments. Note that during this audit, we assume the following statements to be correct for the off-chain components: 1. The hard-coded `exponent` and `modulus` in `Registration.sol:L417-420` (function `verifyReportCryptography`) are the public-key data for the Intel Provisioning Certification Key Certificate (PCK Cert). 2. The Intel Provisioning Certification Service will only sign the attestation after verifying the report is from SGX and does not sign on anything else. 3. The first 20 bytes of the field `QE.REPORT.ReportData` of the quote data are of the address format of the attestation key (see: [SGX doc](https://download.01.org/intel-sgx/latest/dcap-latest/linux/docs/Intel_SGX_ECDSA_QuoteLibReference_DCAP_API.pdf), section 3.8 and A.4) and only the enclave can specify the value of the field. Otherwise, there is no integrity proof that the signer's address is indeed from the enclave.

LowConcerns on `SolRsaVerify`Open

We found a few concerning points regarding the library `SolRsaVerify`: 1. Clone and Own: this team seems to port this library seems from another repository ([link](https://github.com/adria0/SolRsaVerify)). However, the team did not port the test from the original repository. Also, the original code seems not fuzz-tested as well. 2. Missing validation: According to the RSA spec doc ([RFC 8017 Section 8.2.2](https://datatracker.ietf.org/doc/html/rfc8017#section-8.2.2)), "If the length of the signature S is not k octets, output "invalid signature" and stop.". The function `pkcs1Sha256Verify` does not have such validation. Note that we also have other recommendations in the section on code documentation and best practices to improve the quality of this file.

LowGas Concern on WithdrawalOpen

The `LibCollateral.sol:getUnprocessedWithdrawals` function calculates the `(withdrawalReductionAmount, start, end)` by looping through the linked list of the unprocessed withdrawals. The looping brings the out-of-gas risk to the `LibCollateral.sol:commitWithdrawal` function. Although it cannot commit the halfway-processed withdraw due to the atomic nature of the smart contract, the out-of-gas reversion of the `LibCollateral.sol:commitWithdrawal` function will cause `Collateral.sol:withdraw` (L355-397) and `Stake.sol:withdrawDDX` (L165-210) to fail. Those failures will block users from transferring their funds out of the DEX. Note that the current implementation mitigates the concern by resetting the linked-list head on each withdrawal. It sets the head to the subsequent linked-list node after the check-pointed `latestConfirmedBlockNumber`. In other words, as long as the DEX continuously checkpoints the state back to the smart contract, the users will be able to withdraw without the out-of-gas concern. However, this assumes the availability of the DEX operation. If the users accidentally create too many fragment withdrawals, the DEX can lock users' funds by stopping operating. The ability to block users' exit disobeys the non-custodial assumption that the users have ownership of their funds at all times.

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