Quantstamp reviewed Primex Finance on 18 Aug 2023: 38 findings, 0 critical; 28 marked fixed, 10 acknowledged; 8 more marked mitigated.
Report hosted on certificate.quantstamp.com.
Trustblock does not review code.
Statuses are the security firm’s own, from its report.
| Severity | Open | Acknowledged | Fixed | Mitigated |
|---|---|---|---|---|
| Critical | 0 | 0 | 0 | 0 |
| High | 0 | 0 | 3 | 0 |
| Medium | 0 | 4 | 10 | 2 |
| Low | 0 | 6 | 15 | 6 |
Marked Informational or Undetermined by the firm. Not counted as findings.
The proxy contracts used in the Transparent Upgradeable Proxy pattern are compiled using solidity 0.8.10, but the implementation contracts are compiled using solidity 0.8.18.
In general, the protocol has some limits on what the token can be supported to interact: 1. The protocol only supports tokens with at most 18 decimals: the protocol aligns the "multiplier" on the decimals to 18 in several places: `BatchManager`, `LimitPriceCOM`, `TakeProfitStopLossCCM`, `BestDexLens`, and `PositionLibrary` contracts. The 18 decimals are also how the `WadRayMath` library handles the WAD precision. 2. The protocol does not support token charging fees on transfers: despite that the `TokenTransfersLibrary.doTransferFromTo()` function returns the balance difference as the output, all places calling the function do not use the output. In other words, all places calling the function assume to get the full amount on transfer. 3. The protocol does not support rebaseable tokens: the contract `TraderBalanceVault` maintains the accounting of token balances in `balances`. Tokens with elastic supply (also known as rebasing tokens) and tokens with dishonest implementation would not be compatible with the logic intended by this contract.
The `SpotTradingRewardDistributorStorage` contract declares the `dns` variable, but the `SpotTradingRewardDistributor.initialized()` function does not set its value. The `dns` variable is not used in `SpotTradingRewardDistributor`, but if there is a function that requires the use of `dns`, the variable should be initialized during a contract upgrade.
Any user can register a referrer by calling the `ReferralProgram.register()` function. This could potentially be dangerous as there is no way to verify that a single account belongs to a single human. Thus, if a reward was associated with referrals, a user would be incentivized to create and refer fake accounts to amass rewards. Since the reward mechanism for the referral program is unclear to us, we consider the severity to be undetermined.
While upgradability is not a vulnerability in itself, token holders should be aware that the token contract can be upgraded at any given time. This audit does not guarantee the behavior of future contracts that the token may be upgraded to. Here is the list of upgradable contracts: ```sh ▶ grep -rl --exclude="I*" --exclude-dir="mocks" "function initialize" contracts contracts/SpotTradingRewardDistributor/SpotTradingRewardDistributor.sol contracts/TraderBalanceVault/TraderBalanceVault.sol contracts/PMXBonusNFT/PMXBonusNFT.sol contracts/ActivityRewardDistributor/ActivityRewardDistributor.sol contracts/PToken/PToken.sol contracts/PriceOracle/PriceOracle.sol contracts/WhiteBlackList/WhiteBlackListReferral/WhiteBlackListReferral.sol contracts/WhiteBlackList/WhiteBlackList/WhiteBlackList.sol contracts/LimitOrderManager/LimitOrderManager.sol contracts/KeeperRewardDistributor/KeeperRewardDistributor.sol contracts/Bucket/Bucket.sol contracts/LiquidityMiningRewardDistributor/LiquidityMiningRewardDistributor.sol contracts/DebtToken/DebtToken.sol contracts/Reserve/Reserve.sol contracts/ReferralProgram/ReferralProgram.sol contracts/PrimexDNS/PrimexDNS.sol contracts/BonusExecutor/FeeExecutor.sol contracts/BonusExecutor/FeeDecreaser.sol contracts/Treasury/Treasury.sol contracts/PositionManager/PositionManager.sol ```
The `TraderBalanceVault.depositAndLock()` function allows the `VAULT_ACCESS_ROLE` to add any amount of any asset to any trader's locked balance. However, this function does not actually require that a deposit takes place, contrary to what the function name suggests.
When increasing the deposit of a position through `PositionLibrary.increaseDeposit()`, the following check is performed: ``` _require(depositedAmountInBorrowed >= params.amountOutMin, ...) ``` However, this check will also be performed in case `params.asset == borrowedAsset`, meaning that no swap is executed. Therefore, this swap may revert if the user has provided `_amountOutMin` in `increaseDeposit(..)` of `PositionManager.sol` anyway.
In order to validate the proper deployment and initialization of the contracts, it is a good practice to emit events. Also, any important state transitions can be logged, which is beneficial for monitoring the contract, and also tracking eventual bugs or hacks. Below we present a non-exhaustive list of events that could be emitted to improve application management: 1. `Bucket.setReserveRate()` 1. `Bucket.setWithdrawalFee()` 1. `Bucket.setInterestRateStrategy()` 1. `PositionManager.setKeeperRewardDistributor()` 1. `PositionManager.setMinPositionSize()` 1. `PositionManager.setOracleTolerableLimitMultiplier()` 1. `Reserve.setTransferRestrictions()` 1. `PrimexDNS.setConditionalManager()` 1. `PrimexDNS.setPMX()` 1. `PrimexDNS.setProtocolRate` 1. `PrimexDNS.setProtocolRateInPMX` 1. `PrimexDNS.setAavePool()` 1. `PrimexDNS.activateBucket()` 1. `PrimexDNS.freezeBucket()` 1. `PrimexDNS.setDexAdapter()` 1. `PrimexDNS.activateDEX()` 1. `PrimexDNS.freezeDEX()` 1. `PriceOracle.updatePriceFeed()` 1. `PriceOracle.updateVolatilityFeed()` 1. `PriceOracle.setGasPriceFeed()` 1. `KeeperRewardDistributor.setDefaultMaxGasPrice()` 1. `KeeperRewardDistributor.setOracleGasPriceTolerance()` 1. `KeeperRewardDistributor.setMaxGasAmount` 1. `KeeperRewardDistributor.setPmxPartInReward()` 1. `KeeperRewardDistributor.setNativePartInReward()` 1. `KeeperRewardDistributor.setPositionSizeCoefficients()` 1. `KeeperRewardDistributor.setAdditionalGas()` 1. `SpotTradingRewardDistributor.decreaseRewardPerPeriod()` 1. `SpotTradingRewardDistributor.setRewardPerPeriod()` 1. `SpotTradingRewardDistributor.topUpAvailablePmxBalance()` 1. `SpotTradingRewardDistributor.withdrawPmx()` 1. `Treasury.setMaxSpendingLimit()` 1. `Treasury.decreaseLimits()` 1. `ReferralProgram.setReferrals()` 1. `DexAdapter.setQuoter()` 1. `DexAdapter.setDexType()` 1. `Redeemer.changeRate()` 1. `Redeemer.adminClaimEarlyTokens()` 1. `Redeemer.adminClaimRegularTokens()` 1. `SwapManager.setSwapRate()` 1. `SwapManager.setSwapRateInPmx()` 1. `PMXBonusNFT.setExecutor()` 1. `PMXBonusNFT.blockNFT()` 1. `PMXBonusNFT.unblockNFT()`
Several contracts approves token infinitely for another contract. While we do not find any exploit from this, and the risk is mitigated as it is only approved to another contract within the protocol, it increase the risk surface as a vulnerability can cause the token on the approved contracts to be all taken away. We found the pattern in the following places: 1. `ActivityRewardDistributor.initialize()` 2. `Bucket.initialize()` 3. `LiquidityMiningRewardDistributor.initialize()` 4. `SpotTradingRewardDistributor.initialize()`
When swapping from the wallet through the `swap()` function, the input token `params.tokenA` can be `NATIVE_CURRENCY`. The current implementation does not accept `NATIVE_CURRENCY` when swapping directly from the wallet through the `TokenTransfersLibrary.doTransferFromTo()` function. However, the implementation accepts `NATIVE_CURRENCY` when using funds from the `traderBalanceVault.lockAsset()`. Nonetheless, the call to `PrimexPricingLibrary.multiSwap()` will eventually fail. However, it might be great to clarify whether native token should be supported or not and add the corresponding validation.
Leaving an implementation contract uninitialized poses a security risk. An uninitialized implementation contract can be exploited by attackers, potentially compromising the associated proxy. To mitigate this risk, it is recommended to invoke the `_disableInitializers()` function in the constructor during deployment (see: [OpenZeppelin doc](https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#initializing_the_implementation_contract)). This action will automatically lock the implementation contract, preventing any unauthorized usage. The following is the list of impacted contracts found with the `grep` command: ```sh ▶ grep -rl --include="*.sol" --exclude="I*.sol" --exclude-dir="mocks" "initializer" . ./SpotTradingRewardDistributor/SpotTradingRewardDistributor.sol ./TraderBalanceVault/TraderBalanceVault.sol ./PMXBonusNFT/PMXBonusNFT.sol ./ActivityRewardDistributor/ActivityRewardDistributor.sol ./PToken/PToken.sol ./PriceOracle/PriceOracle.sol ./WhiteBlackList/WhiteBlackListReferral/WhiteBlackListReferral.sol ./WhiteBlackList/WhiteBlackList/WhiteBlackList.sol ./LimitOrderManager/LimitOrderManager.sol ./KeeperRewardDistributor/KeeperRewardDistributor.sol ./Bucket/Bucket.sol ./LiquidityMiningRewardDistributor/LiquidityMiningRewardDistributor.sol ./DebtToken/DebtToken.sol ./Reserve/Reserve.sol ./ReferralProgram/ReferralProgram.sol ./PrimexDNS/PrimexDNS.sol ./BonusExecutor/FeeDecreaser.sol ./Treasury/Treasury.sol ./PositionManager/PositionManager.sol ```
The `PrimexPricingLibrary.getLiquidiationPriceByOrder()` function has an unresolved `TODO` stating: "This function is only used in tests. Maybe it can be removed."
The function `AccessControl._setupRole()` has been [deprecated](https://docs.openzeppelin.com/contracts/4.x/api/access#AccessControl-_setupRole-bytes32-address-) in favor of `AccessControl._grantRole()`, which performs the same operations.
The report names a repository or files. Open the report to see its scope.
Repository and files the report names (13)
240 projects reviewed · 338 reports · latest Nov 2026
See Quantstamp’s auditsSomething 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