WEMIX DEX V2 - Retainer #19

CertiKFiles named in the report

Audit

Part of CertiK’s retainer series

CertiK reviewed WEMIX (WEMIX DEX V2 - Retainer #19) on 28 Mar 2023: 13 findings, 0 critical; 4 marked fixed, 9 open.

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

Report hosted on skynet.certik.com.

Trustblock does not review code.

Findings13

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

SeverityOpenAcknowledgedFixed
Critical000
High000
Medium001
Low903
LowDivide Before MultiplyOpen

Performing integer division before multiplication truncates the low bits, losing the precision of calculation. ```solidity=325 _payment = _amount.div(1 ether).mul(_price); ```

LowIncompatibility with Deflationary TokensOpen

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=76 require(IERC20(_token).transferFrom(_from, address(this), _valueOrTid), "B:E20 transfer"); //deposit to this contract ``` - Transferring tokens by `_valueOrTid`. ```solidity=78 require(IBridgeERC20(_token).burnFrom(_from, _valueOrTid), "B:E20 burn"); //burn ``` - The `_valueOrTid` appears to be used for bookkeeping purposes without compensating the potential transfer fees. - Note: `burnFrom` is an external function and its behavior wasn't evaluated. --- ```solidity=66 require(IERC20(_token).transferFrom(_from, address(this), _cost), "TransferCost: transferFrom is failed"); ``` - Transferring tokens by `_cost`. ```solidity=67 addIncome(_token, _column, _cost); ``` - This function call executes the following operation. - In `RecipientRole.addIncome`, - `sumIncomes[_token] = sumIncomes[_token].add(_amount);` - In `SafeMath.add`, - `uint256 c = a + b;` - The `_cost` appears to be used for bookkeeping purposes without compensating the potential transfer fees. --- ```solidity=22 _payCost(CA(WEMIX), _from, _cost, _column); ``` - Transferring tokens by `_cost`. - This function call executes the following operation. - In `TransferCost._payCost`, - `require(IERC20(_token).transferFrom(_from, address(this), _cost), "TransferCost: transferFrom is failed");` ```solidity=22 _payCost(CA(WEMIX), _from, _cost, _column); ``` - This function call executes the following operation. - In `TransferCost._payCost`, - `addIncome(_token, _column, _cost);` - In `RecipientRole.addIncome`, - `sumIncomes[_token] = sumIncomes[_token].add(_amount);` - In `SafeMath.add`, - `uint256 c = a + b;` - The `_cost` appears to be used for bookkeeping purposes without compensating the potential transfer fees. --- ```solidity=55 _exit(_token, msg.sender, msg.sender, _valueOrTid, _extraData); ``` - Transferring tokens by `_valueOrTid`. - This function call executes the following operation. - In `BridgeBase._exit`, - `require(IERC20(_token).transferFrom(_from, address(this), _valueOrTid), "B:E20 transfer"); //deposit to this contract` ```solidity=55 _exit(_token, msg.sender, msg.sender, _valueOrTid, _extraData); ``` - This function call executes the following operation. - In `BridgeBase._exit`, - `require(IBridgeERC20(_token).burnFrom(_from, _valueOrTid), "B:E20 burn"); //burn` - Note: `burnFrom` is an external function and its behavior wasn't evaluated. - The `_valueOrTid` appears to be used for bookkeeping purposes without compensating the potential transfer fees. --- ```solidity=95 _exit(_token, _msgSender(), _msgSender(), _valueOrTid, _extraData); ``` - Transferring tokens by `_valueOrTid`. - This function call executes the following operation. - In `BridgeBase._exit`, - `require(IERC20(_token).transferFrom(_from, address(this), _valueOrTid), "B:E20 transfer"); //deposit to this contract` ```solidity=95 _exit(_token, _msgSender(), _msgSender(), _valueOrTid, _extraData); ``` - This function call executes the following operation. - In `BridgeBase._exit`, - `require(IBridgeERC20(_token).burnFrom(_from, _valueOrTid), "B:E20 burn"); //burn` - Note: `burnFrom` is an external function and its behavior wasn't evaluated. - The `_valueOrTid` appears to be used for bookkeeping purposes without compensating the potential transfer fees.

LowInconsistent Comment and CodeOpen

The linked comment states that 'when index is out of the range of chartList, data is retrieved from currentChar.'. However, the `if` statement doesn't handle the case when the `_index` is larger than `chartList[_token][_interval].length`.

LowInefficient Memory ParameterOpen

One or more parameters with `memory` data location are never modified in their functions and those functions are never called internally within the contract. Thus, their data location can be changed to `calldata` to avoid the gas consumption copying from calldata to memory. ```solidity=59 function enter(address _token, address _to, uint256 _valueOrTid, bytes32 _txHash, uint256 _extraData, bytes memory _signature, string memory) public onlyValidatorSig(abi.encodePacked(address(this), _token, _to, _valueOrTid, _txHash, _extraData), _signature){ ``` `enter` has memory location parameters: `_signature`. --- ```solidity=152 function tradeSeed(uint256 _serialSeed, uint256 _serialCurrency, uint256 _amount, bytes memory _signature) public onlyValidatorSig(abi.encodePacked(address(this), _serialSeed, _serialCurrency, _amount), _signature){ ``` `tradeSeed` has memory location parameters: `_signature`. --- ```solidity=157 function closeOrder(uint256 _serial, bytes memory _signature) public onlyValidatorSig(abi.encodePacked(address(this), _serial), _signature){ ``` `closeOrder` has memory location parameters: `_signature`. --- ```solidity=54 function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual; ``` `safeTransferFrom` has memory location parameters: `data`.

LowLocked Tokens Can Still Be TradedOpen

The `buySeed()`, `buyItem()` and `tradeSeed()` functions do not check if tokens are locked, which means that locked tokens can still be traded.

LowOut of Scope Dependency - ValidatorOpen

The system has privileged roles called 'validator' who have the power to manage orders in smart contracts. The scope of the audit treats the 'validator' as black boxes and assumes their functional correctness. However, if a 'validator' is compromised, the attacker can take advantage of that and damage the project.

LowPotential Lack Of Access ControlOpen

The functions `withdrawExchangeIncome` and `withdrawOrder` can be called by anyone as they have no access restrictions. This enables anyone to call them and withdraw assets for other parties.

LowPotential misuse of the `isValidator()` check.Open

The function `isValidator(address account)` is used to check if parameter `account` is validator while function `isOwner()` checks if msg.sender is the deployer/owner of the contract. They are totally different functionalities. It may have serious consequence if the deployer/owner of the contract is not validator and calls `isValidator(address account)` with an arbitrary account successfully.

LowVariables That Could Be Declared as ImmutableOpen

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.

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

  • contracts/Role/ValidatorRole.sol
  • contracts/Bridge/TokenBridgeServiceV2.sol
  • contracts/Bridge/Base/TransferCostTradeV2.sol
  • contracts/Bridge/Base/TokenExchangeChartV2.sol
  • contracts/Bridge/TokenBridgeTradeV2.sol
  • contracts/Bridge/Base/BridgeBase.sol
  • contracts/Bridge/Base/TokenExchangeV2.sol
  • contracts/Common/TokenManager.sol

Part of WEMIX’s security record

WEMIX
Audits75 audits by 1 firmLast audit Feb 2025, by CertiK.
Critical findingsNo open critical findingsAcross the 75 reports, 17 critical findings were reported. Each is marked fixed by the firm that reported it.
Open WEMIX’s security record

Security firm

CertiK

1,045 projects reviewed · 1,376 reports · latest May 2025

See CertiK’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