DerivaDEX

QuantstampFiles named in the report

Quantstamp reviewed DerivaDEX on 4 Sep 2020: 27 findings, 0 critical; 17 marked fixed, 6 acknowledged, 4 open.

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

Report hosted on certificate.quantstamp.com.

Trustblock does not review code.

Findings27

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

SeverityOpenAcknowledgedFixed
Critical000
High102
Medium014
Low3511
MediumAave accrued interest model may be gamed by users staking toward the end of an intervalAcknowledged

Aave balances normally auto-increment through time with the accrued interest in the user's own balances. When Aave tokens are staked in the `InsuranceFund`, the staked value is saved at the moment of staking, the accrued interest will be still generated but for the total balance of the `InsuranceFund`, however the accrued interest for Aave tokens is calculated and divided when claiming later on. As an example, if we take a staking interval equal to 1 week, a user that stakes 1K aUSDT at day 1 will receive the same value of the accrued interest as a staker that stakes at day 7; the total accrued interest is equally divided between the users following their staking collateral at the end of the interval as implemented in `transferTokensAave()` function. Aave instantaneously divides all accrued interest between the stakers, meaning that if both stakers kept their collateral and didn't stake it, the initial user will gain more interest than if he staked in the insurance fund. A malicious user can stake a high amount of Aave tokens before the end of an interval to gain more interest, meaning that he can takes others stakers Aave accrued interest. The implemented logic to distribute Aave accrued interest is dependent on transaction ordering.

LowContract will not pause if multiple diamond facet upgrade transactions occurAcknowledged

If during an upgrade `diamondCut()` is called multiple times, this situation can create issues since the fallback function does not pause, meaning that the users will be exposed to upgraded functions and old functions waiting to be upgraded at the same time.

LowDDX reward computation dependent on USD-pegged stable coinsAcknowledged

DerivaDEX plans to list only USD stable coins, however all kind of tokens can be listed. The issue described below is applicable for both USD stable coins and other tokens (if listed). As implemented [here](https://github.com/apalepu23/derivadex_v1/blob/6bb9ac918e87bc416966b385cc5800cd7c310953/packages/protocol/contracts/facets/insurance-fund/InsuranceFund.sol#L541#L548), the sum of the user staked collaterals and the total staked collaterals sum is used to compute the interval DDX reward for the `msg.sender`. DDX reward is calculated following the underlying token unit in the case of compound or simply the aToken unit at the moment of staking for Aave or any other kind of tokens, The face value in USD of different stablecoins can drift from the target price, as an example if Token A face value is 1.05 USD and token B value is 0.95 USD, both stake will receive the same reward if the staked value is the same. Further, extra care should be used if tokens are added that contain a decimal value different than 18.

LowExternal tokens should be added cautiously to `InsuranceFund`Acknowledged

The function `addInsuranceFundCollateral()` allows the admin (governance) to admit new collateral types, which could be arbitrary tokens or contracts.

LowMapping Storage LayoutAcknowledged

Using mappings with value types that require less than 32 bytes of storage will not save gas, instead, more gas will be required when the data is handled in memory. DDX token uses `uint96` as mapping value type for allowances and balances, this is adding extra complexity when implementing ERC20 standard functions, more gas consumption and non-compliance with the ERC20 standard. As an example using `safe96` inside `approve()` may cause function to revert for a reason not described in the standard; this can break some applications that interact with ERC20 tokens if they set any value between `uint96` and `uint256` (please not that `approve()` is intended to accept any value).

LowUnable to remove collateral types in `InsuranceFund`Acknowledged

While new collateral types can be added, there is now way of removing an insurance fund collateral. If something goes wrong, it would stay in the contract forever, and could make loops over `collateralNames` more expensive.

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 (47)

  • contracts/facets/interfaces/IComptroller.sol
  • contracts/facets/interfaces/IAToken.sol
  • contracts/facets/insurance-fund/InsuranceFund.sol
  • contracts/tokens/DIFundTokenFactory.sol
  • contracts/tokens/DummyToken.sol
  • contracts/facets/governance/Governance.sol
  • contracts/libs/LibBytes.sol
  • contracts/libs/LibVoteCast.sol
  • contracts/storage/LibDiamondStorageTrader.sol
  • contracts/libs/MathHelpers.sol
  • contracts/storage/LibDiamondStoragePause.sol
  • contracts/tokens/SafeERC20Wrapper.sol
  • contracts/libs/SafeMath32.sol
  • contracts/libs/defs/GovernanceDefs.sol
  • contracts/facets/pause/Pause.sol
  • contracts/libs/LibClone.sol
  • contracts/tokens/DDX.sol
  • contracts/tokens/DIFundToken.sol
  • contracts/diamond/LibDiamondStorage.sol
  • contracts/diamond/DiamondFacet.sol
  • contracts/storage/LibDiamondStorageGovernance.sol
  • contracts/storage/LibDiamondStorageInsuranceFund.sol
  • contracts/tokens/HDUMToken.sol
  • contracts/tokens/interfaces/IDIFundTokenFactory.sol
  • contracts/storage/LibDiamondStorageDerivaDEX.sol
  • contracts/tokens/interfaces/IDDX.sol
  • contracts/facets/trader/Trader.sol
  • contracts/libs/LibEIP712.sol
  • contracts/facets/interfaces/IInsuranceFund.sol
  • contracts/diamond/IERC165.sol
  • contracts/diamond/LibDiamondCut.sol
  • contracts/diamond/IDiamondCut.sol
  • contracts/tokens/interfaces/IDIFundToken.sol
  • contracts/tokens/interfaces/IDDXWalletCloneable.sol
  • contracts/libs/defs/TraderDefs.sol
  • contracts/facets/interfaces/ICToken.sol
  • contracts/libs/defs/InsuranceFundDefs.sol
  • contracts/libs/SafeMath96.sol
  • contracts/diamond/IDiamondLoupe.sol
  • contracts/DerivaDEX.sol
  • contracts/libs/LibDelegation.sol
  • contracts/tokens/DDXWalletCloneable.sol
  • contracts/libs/SafeMath128.sol
  • contracts/Migrations.sol
  • contracts/diamond/OwnershipFacet.sol
  • contracts/facets/trader/LibTraderInternal.sol
  • contracts/libs/LibPermit.sol

Part of DerivaDEX’s security record

DerivaDEX
Audits1 audit by 1 firmLast audit Sep 2020, by Quantstamp.
Critical findingsNo open critical findingsIn 1 report.
Open DerivaDEX’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