CertiK reviewed space-dex.io (Space Dex) on 9 Mar 2023: 25 findings, 0 critical; 13 marked fixed, 12 open.
Report hosted on skynet.certik.com.
Trustblock does not review code.
Statuses are the security firm’s own, from its report.
| Severity | Open | Acknowledged | Fixed |
|---|---|---|---|
| Critical | 0 | 0 | 0 |
| High | 2 | 0 | 1 |
| Medium | 0 | 0 | 0 |
| Low | 10 | 0 | 12 |
In the contract `Vault.sol`, the role `gov` has authority over the following functions: - `function setVaultUtils(IVaultUtils _vaultUtils)` - `function setError(uint256 _errorCode, string calldata _error)` - `function setInManagerMode(bool _inManagerMode)` - `function setManager(address _manager, bool _isManager)` - `function setInPrivateLiquidationMode(bool _inPrivateLiquidationMode)` - `function setLiquidator(address _liquidator, bool _isActive)` - `function setIsSwapEnabled(bool _isSwapEnabled)` - `function setMaxGasPrice(uint256 _maxGasPrice)` - `function setPriceFeed(address _priceFeed)` - `function setGov(address _gov)` - `function setMaxLeverage(uint256 _maxLeverage)` - `function setBufferAmount(address _token, uint256 _amount)` - `function setMaxGlobalShortSize(address _token, uint256 _amount)` - `function setFees( uint256 _taxBasisPoints, uint256 _stableTaxBasisPoints, uint256 _mintBurnFeeBasisPoints, uint256 _swapFeeBasisPoints, uint256 _stableSwapFeeBasisPoints, uint256 _marginFeeBasisPoints, uint256 _liquidationFeeUsd, uint256 _minProfitTime, bool _hasDynamicFees )` - `function setFundingRate( uint256 _fundingInterval, uint256 _fundingRateFactor, uint256 _stableFundingRateFactor )` - `function setTokenConfig( address _token, uint256 _tokenDecimals, uint256 _tokenWeight, uint256 _minProfitBps, uint256 _maxUsdjAmount, bool _isStable, bool _isShortable )` - `function clearTokenConfig(address _token)` - `function withdrawFees(address _token, address _receiver)` - `function setUsdjAmount(address _token, uint256 _amount)` The role `manager` has authority over the following functions: - `function buyUSDJ(address _token, address _receiver)` - `function sellUSDJ(address _token, address _receiver)` Any compromise to these accounts may allow a hacker to take advantage of this authority to withdraw fees and update malicious parameters. ----- In the contract `VaultPriceFeed.sol`, the role `gov` has authority over the following functions: - `function setChainlinkFlags(address _chainlinkFlags)` - `function setAdjustment( address _token, bool _isAdditive, uint256 _adjustmentBps )` - `function setIsSecondaryPriceEnabled(bool _isEnabled)` - `function setSecondaryPriceFeed(address _secondaryPriceFeed)` - `function setSpreadBasisPoints(address _token, uint256 _spreadBasisPoints)` - `function setFavorPrimaryPrice(bool _favorPrimaryPrice)` - `function setPriceSampleSpace(uint256 _priceSampleSpace)` - `function setMaxStrictPriceDeviation(uint256 _maxStrictPriceDeviation)` - `function setTokenConfig( address _token, address _priceFeed, uint256 _priceDecimals, bool _isStrictStable )` Any compromise to the `gov` account may allow a hacker to take advantage of this authority to manipulate the price of tokens. ----- In the contract `ShortsTracker.sol`, the role `gov` has authority over the following functions: - `function setHandler(address _handler, bool _isActive)` - `function setIsGlobalShortDataReady(bool value)` - `function setInitData( address[] calldata _tokens, uint256[] calldata _averagePrices )` The role `handler` has authority over the following functions: - `function updateGlobalShortData( address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta, uint256 _markPrice, bool _isIncrease )` Any compromise to these accounts may allow a hacker to take advantage of this authority to set their own handlers and then manipulate global short data. ----- In the contract `Router.sol`, the role `gov` has authority over the following functions: - `function setGov(address _gov)` - `function addPlugin(address _plugin)` - `function removePlugin(address _plugin)` Any compromise to the `gov` account may allow a hacker to take advantage of this authority to add their own plugins. ----- In the contract `BasePositionManager.sol`, the role `gov` has authority over the following functions: - `function setAdmin(address _admin)` - `function approve( address _token, address _spender, uint256 _amount )` - `function sendValue(address payable _receiver, uint256 _amount)` The role `admin` has authority over the following functions: - `function setDepositFee(uint256 _depositFee)` - `function setIncreasePositionBufferBps(uint256 _increasePositionBufferBps)` - `function setReferralStorage(address _referralStorage)` - `function setMaxGlobalSizes( address[] memory _tokens, uint256[] memory _longSizes, uint256[] memory _shortSizes )` - `function withdrawFees(address _token, address _receiver)` Any compromise to these accounts may allow a hacker to take advantage of this authority to set `admin`, which can set any `depositeFee`
In the contract `TimeDistributor.sol`, the role `gov` has authority over the following functions: - `function setGov(address _gov)` - `function setDistribution( address[] calldata _receivers, uint256[] calldata _amounts, address[] calldata _rewardTokens )` The role `admin` has authority over the following functions: - `function setTokensPerInterval(address _receiver, uint256 _amount)` - `function updateLastDistributionTime(address _receiver)` Any compromise to these accounts may allow a hacker to take advantage of this authority to manipulate the receivers of reward distribution. ----- In the contract `BaseToken.sol`, the role `gov` has authority over the following functions: - `function setGov(address _gov)` - `function setInfo(string memory _name, string memory _symbol)` - `function setYieldTrackers(address[] memory _yieldTrackers)` - `function addAdmin(address _account)` - `function removeAdmin(address _account)` - `function withdrawToken( address _token, address _account, uint256 _amount )` - `function setInPrivateTransferMode(bool _inPrivateTransferMode)` - `function setHandler(address _handler, bool _isActive)` The role `admin` has authority over the following functions: - `function addNonStakingAccount(address _account)` - `function removeNonStakingAccount(address _account)` - `function recoverClaim(address _account, address _receiver)` Any compromise to these accounts may allow a hacker to take advantage of this authority to manipulate the global parameters, set the `handler`, and withdraw any token in this contract. ----- In the contract `Bridge.sol`, the role `gov` has authority over the following functions: - `function withdrawToken(address _token, address _account, uint256 _amount)` Any compromise to the `gov` account may allow a hacker to take advantage of this authority to withdraw any token in this contract. ----- In the contract `FaucetToken.sol`, the role `_gov` has authority over the following functions: - `function mint(address account, uint256 amount)` - `function enableFaucet()` - `function disableFaucet()` - `function setDropletAmount(uint256 dropletAmount)` Any compromise to the `_gov` account may allow a hacker to take advantage of this authority to mint any `FaucetToken` and control the process of token distribution. ----- In the contracts `MintableBaseToken.sol`, `JLP.sol`, and `SnapshotToken.sol`, the role `gov` has authority over the following functions: - `function setMinter()` the role `minter` has authority over the following functions: - `function mint(address _account, uint256 _amount)` - `function burn(address _account, uint256 _amount)` In the contract `SnapshotToken.sol`, the role `minter` also has authority over the following functions: - `function batchMint(address[] memory _accounts, uint256[] memory _amounts)` Any compromise to these accounts may allow a hacker to take advantage of this authority to mint any amount of tokens or burn any amount of tokens of any account. ----- In the contracts `YieldToken.sol`, `YieldFarm.sol`, and `USDJ.sol`, the role `gov` has authority over the following functions: - `function setGov(address _gov)` - `function setInfo(string memory _name, string memory _symbol)` - `function setYieldTrackers(address[] memory _yieldTrackers)` - `function addAdmin(address _account)` - `function removeAdmin(address _account)` - `function withdrawToken( address _token, address _account, uint256 _amount )` - `function setInWhitelistMode(bool _inWhitelistMode)` - `function setWhitelistedHandler(address _handler, bool _isWhitelisted)` The role `admin` has authority over the following functions: - `function addNonStakingAccount(address _account)` - `function removeNonStakingAccount(address _account)` - `function recoverClaim(address _account, address _receiver)` In the contract `USDJ.sol`, the role `gov` also has authority over the following functions: - `function addVault(address _vault)` - `function removeVault(address _vault)` The role `Vault` has authority over the following functions: - `function mint(address _account, uint256 _amount)` - `function burn(address _account, uint256 _amount)` Any compromise to these accounts may allow a hacker to take advantage of this authority to set `Vault` and then mint or burn any amount of USDJ. ----- In the contract `YieldTracker.sol`, the role `gov` has authority over the following functions: - `function setGov(address _gov)` - `function setDistributor(address _distributor)` - `function withdrawToken(address _token, address _account, uint256 _amount)` Any compromise to the `gov` account may allow a hacker to take advantage of this authority to set the `distributor` and withdraw any token in this contract.
The Space Dex is a decentralized exchange that provides perpetual futures with a minimal spread so that the traders can trade at an oracle price with zero price impact (slippage), which means the execution price always stays the same regardless of the trade size. The oracle price is fed from some external CEX venues. However, the CEX prices of an asset may not be adequately and perpetually liquid under certain circumstances. In this case, a whale manipulator could create a significant long position on this illiquid asset without slippage, then move the external liquidity on the CEX up with less cost to make a profit upon closing the position. After that, the whale could short the asset and move the external liquidity down on the CEX to further pocket the profit. The `maxGlobalLongSize` and `maxGlobalShortSize` set in the function `_validateMaxGlobalSize()` of the contract `BasePositionManager` could alleviate this situation if these values are properly chosen. In addition, the `maxGlobalShortSizes` in the contract `Vault` could restrict the short position size but it does not have the restriction on the long position size. According to the whitepaper, the multi-asset pool currently consists of WBNB, WETH, WBTC, and BUSD. To ensure this scenario will be alleviated, it is recommended not to add illiquid assets to the pool.
In the contract `JlpManager`, the function `setAumAdjustment()` allows the gov role to set the `aumAddition` and `aumDeduction` without any threshold. ```solidity=111 function setAumAdjustment(uint256 _aumAddition, uint256 _aumDeduction) external onlyGov { aumAddition = _aumAddition; aumDeduction = _aumDeduction; } ``` The `JLP` price is calculated to be the ratio of the `aum` over the total supply of `JLP` in the function `getPrice()`: ```solidity=196 function getPrice(bool _maximise) external view returns (uint256) { uint256 aum = getAum(_maximise); uint256 supply = IERC20(jlp).totalSupply(); return aum.mul(JLP_PRECISION).div(supply); } ``` In this case, the `JLP` is prone to price manipulation via the gov role, because the `aum` returned from the function `getAum()` can be adjusted by adding `aumAddition` and subtracting `aumDeduction` directly.
When transferring deflationary ERC20 tokens, the input amount may not be equal to the received amount due to the charged transaction fee. For example, if a user sends 100 deflationary tokens (with a 10% transaction fee), only 90 tokens actually arrived to the contract. However, a failure to discount such fees may allow the same user to withdraw 100 tokens from the contract, which causes the contract to lose 10 tokens in such a transaction. Reference: https://thoreum-finance.medium.com/what-exploit-happened-today-for-gocerberus-and-garuda-also-for-lokum-ybear-piggy-caramelswap-3943ee23a39f ```solidity=60 require( ERC20(target).transferFrom(msg.sender, address(this), amount), "transferFrom failed" ); ``` - Transferring tokens by `amount`. ```solidity=58 _addLiquidity(amount, source, target); ``` - This function call executes the following operation. - In `PegSwap._addLiquidity`, - `uint256 newAmount = getSwappableAmount(source, target).add(amount);` - In `SafeMath.add`, - `uint256 c = a + b;` - The `amount` appears to be used for bookkeeping purposes without compensating the potential transfer fees. --- ```solidity=99 require( ERC20(source).transferFrom(msg.sender, address(this), amount), "transferFrom failed" ); ``` - Transferring tokens by `amount`. ```solidity=95 _addLiquidity(amount, target, source); ``` - This function call executes the following operation. - In `PegSwap._addLiquidity`, - `uint256 newAmount = getSwappableAmount(source, target).add(amount);` - In `SafeMath.add`, - `uint256 c = a + b;` - The `amount` appears to be used for bookkeeping purposes without compensating the potential transfer fees. --- ```solidity=867 IERC20(_path[0]).safeTransfer(vault, _amountIn); ``` - Transferring tokens by `_amountIn`. ```solidity=846 require( msg.value == _executionFee.add(_amountIn), "OrderBook: incorrect value transferred" ); ``` - This function call executes the following operation. - In `SafeMath.add`, - `uint256 c = a + b;` - The `_amountIn` appears to be used for bookkeeping purposes without compensating the potential transfer fees. --- ```solidity=722 IERC20(usdj).transfer(address(_vault), _amount); ``` - Transferring tokens by `_amount`. ```solidity=721 IUSDJ(usdj).mint(address(this), _amount); ``` - The `_amount` appears to be used for bookkeeping purposes without compensating the potential transfer fees. - Note: `mint` is an external function and its behavior wasn't evaluated. --- ```solidity=153 FLN.safeTransferFrom(wallet_, address(this), amount_); ``` - Transferring tokens by `amount_`. ```solidity=157 totalStaked = totalStaked.add(amount_); ``` - This function call executes the following operation. - In `SafeMath.add`, - `uint256 c = a + b;` - The `amount_` appears to be used for bookkeeping purposes without compensating the potential transfer fees. --- ```solidity=169 FLN.safeTransferFrom(wallet_, address(this), amount_); ``` - Transferring tokens by `amount_`. ```solidity=173 totalStaked = totalStaked.add(amount_); ``` - This function call executes the following operation. - In `SafeMath.add`, - `uint256 c = a + b;` - The `amount_` appears to be used for bookkeeping purposes without compensating the potential transfer fees. --- ```solidity=276 _initStake(_msgSender(), amount_); ``` - Transferring tokens by `amount_`. - This function call executes the following operation. - In `FalconPool._initStake`, - `FLN.safeTransferFrom(wallet_, address(this), amount_);` ```solidity=276 _initStake(_msgSender(), amount_); ``` - This function call executes the following operation. - In `FalconPool._initStake`, - `totalStaked = totalStaked.add(amount_);` - In `SafeMath.add`, - `uint256 c = a + b;` - The `amount_` appears to be used for bookkeeping purposes without compensating the potential transfer fees. --- ```solidity=21 IERC20(stakingToken).safeTransferFrom(msg.sender, address(this), _amount); ``` - Transferring tokens by `_amount`. ```solidity=22 _mint(msg.sender, _amount); ``` - This function call executes the following operation. - In `YieldToken._mint`, - `nonStakingSupply = nonStakingSupply.add(_amount);` - In `SafeMath.add`, - `uint256 c = a + b;` - The `_amount` appears to be used for bookkeeping purposes without compensating the potential transfer fees.
Functions that update state variables should emit relevant events as notifications.
Addresses should be checked before assignment or external call to make sure they are not zero addresses. **contracts/access/Governable.sol** ```solidity=18 gov = _gov; ``` - `_gov` is not zero-checked before being used. **contracts/amm/PancakeRouter.sol** --- ```solidity=13 pair = _pair; ``` - `_pair` is not zero-checked before being used. **contracts/chainlink/AutomationBalancerV3.sol** --- ```solidity=63 link677 = _link677; ``` - `_link677` is not zero-checked before being used. --- ```solidity=64 link = _link; ``` - `_link` is not zero-checked before being used. --- ```solidity=65 weth = _weth; ``` - `_weth` is not zero-checked before being used. **contracts/chainlink/AutomationDistribution.sol** --- ```solidity=82 weth = _weth; ``` - `_weth` is not zero-checked before being used. **contracts/core/BasePositionManager.sol** --- ```solidity=95 vault = _vault; ``` - `_vault` is not zero-checked before being used. --- ```solidity=96 router = _router; ``` - `_router` is not zero-checked before being used. --- ```solidity=97 weth = _weth; ``` - `_weth` is not zero-checked before being used. --- ```solidity=99 shortsTracker = _shortsTracker; ``` - `_shortsTracker` is not zero-checked before being used. --- ```solidity=109 admin = _admin; ``` - `_admin` is not zero-checked before being used. --- ```solidity=127 referralStorage = _referralStorage; ``` - `_referralStorage` is not zero-checked before being used. **contracts/core/JlpManager.sol** --- ```solidity=71 usdj = _usdj; ``` - `_usdj` is not zero-checked before being used. --- ```solidity=72 jlp = _jlp; ``` - `_jlp` is not zero-checked before being used. **contracts/core/OrderBook.sol** --- ```solidity=251 router = _router; ``` - `_router` is not zero-checked before being used. --- ```solidity=252 vault = _vault; ``` - `_vault` is not zero-checked before being used. --- ```solidity=253 weth = _weth; ``` - `_weth` is not zero-checked before being used. --- ```solidity=254 usdj = _usdj; ``` - `_usdj` is not zero-checked before being used. --- ```solidity=288 gov = _gov; ``` - `_gov` is not zero-checked before being used. **contracts/core/PositionManager.sol** --- ```solidity=57 orderBook = _orderBook; ``` - `_orderBook` is not zero-checked before being used. **contracts/core/Router.sol** --- ```solidity=47 vault = _vault; ``` - `_vault` is not zero-checked before being used. --- ```solidity=48 usdj = _usdj; ``` - `_usdj` is not zero-checked before being used. --- ```solidity=49 weth = _weth; ``` - `_weth` is not zero-checked before being used. --- ```solidity=59 gov = _gov; ``` - `_gov` is not zero-checked before being used. **contracts/core/Vault.sol** --- ```solidity=257 router = _router; ``` - `_router` is not zero-checked before being used. --- ```solidity=258 usdj = _usdj; ``` - `_usdj` is not zero-checked before being used. --- ```solidity=259 priceFeed = _priceFeed; ``` - `_priceFeed` is not zero-checked before being used. --- ```solidity=260 vaultController = _controller; ``` - `_priceFeed` is not zero-checked before being used. --- ```solidity=334 gov = _gov; ``` - `_gov` is not zero-checked before being used. --- ```solidity=339 priceFeed = _priceFeed; ``` - `_priceFeed` is not zero-checked before being used. **contracts/core/VaultPriceFeed.sol** --- ```solidity=69 gov = _gov; ``` - `_gov` is not zero-checked before being used. --- ```solidity=73 chainlinkFlags = _chainlinkFlags; ``` - `_chainlinkFlags` is recommended to be removed as the contract will not be deployed on Arbitrum. --- ```solidity=107 secondaryPriceFeed = _secondaryPriceFeed; ``` - `_secondaryPriceFeed` is not zero-checked before being used. **contracts/oracle/FastPriceFeed.sol** --- ```solidity=134 fastPriceEvents = _fastPriceEvents; ``` - `_fastPriceEvents` is not zero-checked before being used. --- ```solidity=135 tokenManager = _tokenManager; ``` - `_tokenManager` is not zero-checked before being used. --- ```solidity=136 positionRouter = _positionRouter; ``` - `_positionRouter` is not zero-checked before being used. --- ```solidity=181 fastPriceEvents = _fastPriceEvents; ``` - `_fastPriceEvents` is not zero-checked before being used. --- ```solidity=189 vaultPriceFeed = _vaultPriceFeed; ``` - `_vaultPriceFeed` is not zero-checked before being used. --- ```solidity=249 tokenManager = _tokenManager; ``` - `_tokenManager` is not zero-checked before being used. **contracts/peripherals/PriceFeedTimelock.sol** --- ```solidity=96 admin = _admin; ``` - `_admin` is not zero-checked before being used. --- ```solidity=98 tokenManager = _tokenManager; ``` - `_tokenManager` is not zero-checked before
In the contract `Vault`, the function `decreasePosition()` is intended to decrease a long/short position by calling the function `_decreasePosition()`. In the function `increasePosition()`, the `position.averagePrice` is updated via the following code: ```solidity=712 if (position.size > 0 && _sizeDelta > 0) { position.averagePrice = getNextAveragePrice( _indexToken, position.size, position.averagePrice, _isLong, price, _sizeDelta, position.lastIncreasedTime ); } ``` However, the `position.averagePrice` is not updated when decreasing the position. That means the position's average price is only updated when the position is increased and it will change if the position is decreased.
The contracts use the `pragma solidity 0.6.12` directive. That indicates that an outdated version of the compiler will be used, which is prone to several disclosed bugs.
In the aforementioned setter functions, the variables that will be set as a value by privileged roles do not have any bounds. For example, in the contract `Vault`, the initial max leverage is 15x, but it can be reset by the gov role in the function `setMaxLeverage()` with any number.
The linked functions are equivalent to the compiler-generated getter functions for the respective variables.
The linked variables assigned in the constructor can be declared as `immutable`. Immutable state variables can be assigned during contract creation but will remain constant throughout the lifetime of a deployed contract. A big advantage of immutable variables is that reading them is significantly cheaper than reading from regular state variables since they will not be stored in storage.
The report names a repository or files. Open the report to see its scope.
Repository and files the report names (25)
1,045 projects reviewed · 1,376 reports · latest May 2025
See CertiK’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