CertiK reviewed Playnance (UpVsDown) on 14 Sep 2023: 20 findings, 1 critical; none marked fixed.
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 | 1 | 0 | 0 |
| High | 2 | 0 | 0 |
| Medium | 7 | 0 | 0 |
| Low | 10 | 0 | 0 |
The `distribute` function serves the purpose of distributing bets from participants who have incurred losses to the winners of the ongoing pool, simultaneously collecting fees from the losing participants. However, a potential issue arises when multiple pools are concurrently active, and trades are being executed on these pools. Under such circumstances, executing the distribution process for one specific pool has the potential to drain all the tokens from the other active pools since it sends all the balance of the bet tokens to the fee address. ```solidity=359 sendEther(feeAddress,getContractBalance()); ``` ```solidity=355 if (winners.distributedCount == winners.bets.length) { sendEther(feeAddress, (dist.fee + dist.totalMinusFee)*feePercentage / 100); sendEther(feeJackpotAddress, (dist.feeJackpot + dist.totalMinusJackpotFee)*feeJackpotPercentage / 100); //Send leftovers to fee address sendEther(feeAddress,getContractBalance()); clearPool(poolId); } ``` As a result, users of games participating in other pools, whether they are winners or losers, will not be able to claim their bets and rewards. **Important Note**: Certain identification and KYC procedures were attempted to be applied to the project team in order to better understand the centralization situation and potential risks of the project. Based on the collected information and further conducted investigation, the project passed the criteria with a certain amount of requirements satisfied for the investigation. Still we strongly advise end users to conduct further research and exercise due diligence before engaging with the project. It is crucial for end users to independently verify and assess all available information to make informed decisions.
In the contract `Ownable` the role `_owner` has authority over the functions shown in the diagram below.  Any compromise to the `_owner` account may allow the hacker to take advantage of this authority and affect the following functions: - renounceOwnership: Leave the contract without the owner. - transferOwnership: Transfer ownership of the contract to a new account (`newOwner`). In the contract `UpVsDownGameV2` the role `_owner` has authority over the functions shown in the diagram below.  Any compromise to the `_owner` account may allow the hacker to take advantage of this authority and affect the following functions: - changeGameControllerAddress: Set gameController address, who can control the whole process of this game. - changeGameFeePercentage: Set a game fee percentage that represents the rate of taxation from the loser. - changeGameFeeAddress: Set the fee address that can receive the game fee, the default fee address is the deployer. - stopGame: stop the game process, bettors can't call the `makeTrade` - startGame: start the game process to make the bettors trade. In the contract `UpVsDownGameV2` the role `gameController` has authority over the functions shown in the diagram below.  Any compromise to the `gameController` account may allow the hacker to take advantage of this authority and affect the following functions. - trigger: to start the game, end the game, distribute bets and rewards to winners, or return bets to players. - distribute: to distribute the bets and rewards to winners, or return bets to players. - createPool: Create a trading pool to allow bettors to place bets. In the contract `UpVsDownGameV4` the role `gameController` has authority over the functions. Any compromise to the `gameController` account may allow the hacker to take advantage of this authority and affect the following functions: - changeGameFeeJackpotPercentage(), to change the game fee percentage. - changeGameFeeJackpotAddress(), to change the game fee charged address. **Important Note**: Certain identification and KYC procedures were attempted to be applied to the project team in order to better understand the centralization situation and potential risks of the project. Based on the collected information and further conducted investigation, the project passed the criteria with a certain amount of requirements satisfied for the investigation. Still we strongly advise end users to conduct further research and exercise due diligence before engaging with the project. It is crucial for end users to independently verify and assess all available information to make informed decisions.
A game round consists of two steps, where the `trigger` function can be called to set `startPrice` and initiate the game. After the game starts, players engage in trading and place bets on the game outcome. After a certain period of time, the `trigger` function is called again to determine the game result based on `endPrice` and distribute the bets and rewards to the winners. However, there is no guarantee that `endPrice` will not be zero, so the second step can be executed multiple times, generating different game results and redistributing bets and rewards from other rounds, this can lead to unfairness in the user's gameplay and potentially result in losses for other players. ```solidity=283 function trigger( bytes calldata poolId, int64 timeMS, uint256 tradesStartTimeMS, uint256 tradesEndTimeMS, int32 price, uint32 batchSize ) public onlyGameController onlyPoolExists(poolId) { Round storage currentRound = pools[poolId]; if(isPoolOpen(poolId)) { require(isRunning, 'The game is not running, rounds can only be ended at this point'); currentRound.startPrice = price; currentRound.roundStartTime = timeMS; currentRound.tradesStartTimeMS = tradesStartTimeMS; currentRound.tradesEndTimeMS = tradesEndTimeMS; emit RoundStarted(poolId, timeMS, currentRound.startPrice, currentRound.minBetAmount, currentRound.maxBetAmount, currentRound.poolBetsLimit, poolId); } else if (currentRound.endPrice == 0) { currentRound.endPrice = price; emit RoundEnded(poolId, timeMS, currentRound.startPrice, currentRound.endPrice, poolId); distribute(poolId, batchSize, timeMS); } else { revert PendingDistributions(); } } ``` **Important Note**: Certain identification and KYC procedures were attempted to be applied to the project team in order to better understand the centralization situation and potential risks of the project. Based on the collected information and further conducted investigation, the project passed the criteria with a certain amount of requirements satisfied for the investigation. Still we strongly advise end users to conduct further research and exercise due diligence before engaging with the project. It is crucial for end users to independently verify and assess all available information to make informed decisions.
The `createPool` function has the potential to overwrite an existing pool if the poolId already exists. This can result in the bettor's funds becoming locked in the overwritten pool, potentially causing a loss of funds. Additionally, this can cause a logic error in the system, leading to unexpected behavior. ````solidity=276 function createPool(bytes calldata poolId, uint256 minBetAmount , uint256 maxBetAmount, uint256 poolBetsLimit) public onlyGameController { pools[poolId].created = true; pools[poolId].minBetAmount = minBetAmount; pools[poolId].maxBetAmount = maxBetAmount; pools[poolId].poolBetsLimit = poolBetsLimit; } ````
The function `distribute` can be called to distribute the bets and rewards to the winners. However, there is no guarantee that the round ends. Based on the correct process, bets and rewards will be distributed to the winners after `endPrice` is set by the function `trigger`.
The method `changeGameFeePercentage` is used to set the fee rate for taxing the losers' funds. The current implementation allows for setting the fee rate to any value without an upper bound. If the fee rate is 100 percent, the winner will not receive any profit. ````solidity=256 function changeGameFeePercentage(uint8 newFeePercentage) public onlyOwner { feePercentage = newFeePercentage; } ````
During the execution of the `distribute` function, users' bets are distributed by invoking the `sendEther` function. However, if the winner is a malicious smart contract with a fallback function that reverts any payment, all the bets will become locked within the contract.
The function `distribute` is centralized and can only be invoked by the `GameController` role. Consequently, the timing of distributing bets and rewards is solely determined by the `GameController` role, even if the game has already ended. This can result in a poor user experience. In the worst-case scenario, if the `GameController` role is exploited, bets and rewards could potentially remain in the contract indefinitely. We would like to confirm with the client if the current implementation aligns with the original project design.
A reentrancy attack can occur when the contract creates a function that makes an external call to another untrusted contract before resolving any effects. If the attacker can control the untrusted contract, they can make a recursive call back to the original function, repeating interactions that would have otherwise not run after the external call resolved the effects. ### External call(s) ```solidity=322 sendEther(group.addresses[i], group.bets[i]); ``` * This function call executes the following external call(s). * In `UpVsDownGameV2.sendEther`, * `(sent,data) = address(to).call{gas: 0,value: amount}("")` ### State variables written after the call(s) ```solidity=326 group.distributedCount = to; ``` --- ### External call(s) ```solidity=340 returnBets(poolId, returnGroup, batchSize); ``` * This function call executes the following external call(s). * In `UpVsDownGameV2.sendEther`, * `(sent,data) = address(to).call{gas: 0,value: amount}("")` ### State variables written after the call(s) ```solidity=344 clearPool(poolId); ``` * This function call executes the following assignment(s). * In `UpVsDownGameV2.clearPool`, * `delete pools[poolId].upBetGroup` * In `UpVsDownGameV2.clearPool`, * `delete pools[poolId].downBetGroup` * In `UpVsDownGameV2.clearPool`, * `delete pools[poolId].startPrice` * In `UpVsDownGameV2.clearPool`, * `delete pools[poolId].endPrice` --- ### External call(s) ```solidity=364 sendEther(winners.addresses[i], winnings + winners.bets[i]); ``` * This function call executes the following external call(s). * In `UpVsDownGameV2.sendEther`, * `(sent,data) = address(to).call{gas: 0,value: amount}("")` ### State variables written after the call(s) ```solidity=366 winners.totalDistributed = winners.totalDistributed + winnings; ``` ```solidity=371 winners.distributedCount = to; ``` ```solidity=362 for (uint i = winners.distributedCount; i < to; i++) { ``` --- ### External call(s) ```solidity=364 sendEther(winners.addresses[i], winnings + winners.bets[i]); ``` * This function call executes the following external call(s). * In `UpVsDownGameV2.sendEther`, * `(sent,data) = address(to).call{gas: 0,value: amount}("")` ```solidity=373 sendEther(feeAddress, dist.fee + dist.totalMinusFee - winners.totalDistributed); ``` ### State variables written after the call(s) ```solidity=374 clearPool(poolId); ``` * This function call executes the following assignment(s). * In `UpVsDownGameV2.clearPool`, * `delete pools[poolId].upBetGroup` * In `UpVsDownGameV2.clearPool`, * `delete pools[poolId].downBetGroup` * In `UpVsDownGameV2.clearPool`, * `delete pools[poolId].startPrice` * In `UpVsDownGameV2.clearPool`, * `delete pools[poolId].endPrice`
The functions `changeGameFeePercentage` and `changeGameFeeJackpotPercentage` allows the owner to set the fee percent to 100, hence, all return bet amount will possibly be charged as fees. ```solidity=197 function changeGameFeePercentage(uint8 newFeePercentage) public onlyOwner { require (newFeePercentage <=100 , "Wrong fee percentage value"); feePercentage = newFeePercentage; } function changeGameFeeJackpotPercentage(uint8 newFeeJackpotPercentage) public onlyOwner { require (newFeeJackpotPercentage <=100 , "Wrong jackpot fee percentage value"); feeJackpotPercentage = newFeeJackpotPercentage; } ```
The fee calculation can be simplified. ```solidity=356 sendEther(feeAddress, (dist.fee + dist.totalMinusFee)*feePercentage / 100); sendEther(feeJackpotAddress, (dist.feeJackpot + dist.totalMinusJackpotFee)*feeJackpotPercentage / 100); ``` Since the `dist.fee + dist.totalMinusFee` is equal to `losers.total`, and `dist.feeJackpot + dist.totalMinusJackpotFee` is equal to `losers.total` too.
The sequence of external call and storage manipulation must follow a check effect interaction pattern. - `returnBets` ```solidity=282 for (uint i = group.distributedCount; i < to; i ++) { sendEther(group.addresses[i], group.bets[i]); emit TradeReturned(poolId, group.addresses[i], group.bets[i], group.whiteLabelIds[i]); } group.distributedCount = to; ``` - `distribute()` ```solidity=344 for (uint i = winners.distributedCount; i < to; i++) { uint256 winnings = (winners.bets[i] * dist.totalFees * 100 / winners.total / 100); sendEther(winners.addresses[i], winnings + winners.bets[i]); emit TradeWinningsSent(poolId, winners.addresses[i], winners.bets[i], winnings, winners.addresses[i], winners.whiteLabelIds[i],feePercentage,feeJackpotPercentage); winners.totalDistributed = winners.totalDistributed + winnings; } emit RoundDistributed(poolId, winners.bets.length, winners.distributedCount, to, timeMS); winners.distributedCount = to; if (winners.distributedCount == winners.bets.length) { sendEther(feeAddress, (dist.fee + dist.totalMinusFee)*feePercentage / 100); sendEther(feeJackpotAddress, (dist.feeJackpot + dist.totalMinusJackpotFee)*feeJackpotPercentage / 100); //Send leftovers to fee address sendEther(feeAddress,getContractBalance()); clearPool(poolId); } ```
Boolean constants can be used directly and do not need to be compared to true or false. ```solidity=242 require(pools[poolId].created == true, 'Pool does not exist'); ```
Within the `trigger` function, there appears to be a lack of validations in place to guarantee the integrity of certain parameters. It is important to implement validations that ascertain the following conditions: - The value of the `price` parameter must be greater than zero to ensure valid trade calculations - The start time of the trade, denoted as `tradesStartTimeMS`, should be earlier than the trade end time, denoted as `tradesEndTimeMS`. This validation is essential to maintain chronological coherence in the trade timeline ```solidity=250 if(isPoolOpen(poolId)) { require(isRunning, 'The game is not running, rounds can only be ended at this point'); currentRound.startPrice = price; currentRound.roundStartTime = timeMS; currentRound.tradesStartTimeMS = tradesStartTimeMS; currentRound.tradesEndTimeMS = tradesEndTimeMS; emit RoundStarted(poolId, timeMS, currentRound.startPrice, currentRound.minBetAmount, currentRound.maxBetAmount, currentRound.poolBetsLimit, poolId); } ```
Functions that update state variables should emit relevant events as notifications.
Addresses are not validated before assignment or external calls, potentially allowing the use of zero addresses and leading to unexpected behavior or vulnerabilities. For example, transferring tokens to a zero address can result in a permanent loss of those tokens. ```solidity=247 gameController = newGameController; ``` - `newGameController` is not zero-checked before being used. --- ```solidity=253 gameController = newGameController; ``` - `newGameController` is not zero-checked before being used. --- ```solidity=261 feeAddress = newFeeAddress; ``` - `newFeeAddress` is not zero-checked before being used.
Performing division by zero would raise an error and revert the transaction. ```solidity=345 uint256 winnings = (winners.bets[i] * dist.totalFees * 100 / winners.total / 100); ``` The expression `winners.bets[i] * dist.totalFees * 100 / winners.total` may divide by zero. Its divisor has has estimated interval [0, 231584178474632390847141970017375815706539969331281128078915168015826259279870].
The parameter `price` passed to the function `trigger` eventually determines which group will win the game. And this function `trigger` is only accessible to the `GameController` role. We would like the team to explain the source of the price and provide a more detailed explanation of the calculation logic behind it.
According to the distribution logic, if both the `startPrice` and `endPrice` are equal, regardless of whether they are zero or not, the `downBetGroup` will ultimately emerge as the winner of the game. ```solidity=329 function distribute ( bytes calldata poolId, uint32 batchSize, int64 timeMS ) public onlyGameController onlyPoolExists(poolId) { ... BetGroup storage winners = round.downBetGroup; BetGroup storage losers = round.upBetGroup; if (round.startPrice < round.endPrice) { winners = round.upBetGroup; losers = round.downBetGroup; } ... ```` We would like to confirm with the client if the current implementation aligns with the original project design.
The project contains one or more contract or library definitions that are not used, which can lead to unnecessary complexity and reduced maintainability. ```solidity=104 library Strings { ``` - The library `Strings` is declared but never used.
| Address | Chain | Source code |
|---|---|---|
| 0xdb41…0a840xdb414fe5a6ae09f4b58df1e5615c38c4bee10a84 | Chain: Polygon (POS) | Source code: Verified source |
| 0x7a77…9d270x7a7726273407287c7926bd177f482d1442a79d27 | Chain: Polygon (POS) | Source code: Verified source |
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