SLX Casino
Smart Contract Audit Report
Audit Summary
SLX is building a new dice game where users can place over/under bets to win tokens.
For this audit, we reviewed the following contracts on the SX Network:
- Dice contract at 0x73552811bc2549f416E93659fF56037a1D23fCE4.
- House contract at 0xedE6f8C72efeA7a8065fADcdEbB062D9b5AE8Acf.
- QRNGManager contract at 0x6E787b0ccEEe9d0675D32c93b7f56F6b49f36904.
Audit Findings
Informational findings were identified and the team may want to review them. In addition, centralized aspects are present.
Date: December 21st, 2022.
Updated: December 22nd, 2022 to reflect updates made by the project team that resolves Findings #1 - #3.
Updated: December 27th, 2022 to reflect mainnet deployments.Finding #1 - House - Medium (Resolved)
Description: The refundCustomBet() function deductswinnableAmount
fromlockedInBets
, howeverlockedInBets
is never increased in the contract.
Risk/Impact: All refund transactions will revert due to underflow asfunction refundCustomBet( address player, uint amount, uint winnableAmount, address _customToken ) external isHouseLive isAdmin { require(player != address(0), "Zero Address"); require(amount > 0, "Amount is zero"); lockedInBets -= winnableAmount; IERC20(_customToken).safeTransfer(player, amount); }
lockedInBets
will always equal zero.
Recommendation: The refundCustomBet() function should instead decreaselockedInCustomBets[_customToken]
bywinnableAmount
and thelockedInBets
state variable should be removed to reduce contract size and deployment costs.
Resolution: The team has implemented the above recommendation.
Finding #2 - House - Informational (Resolved)
Description: TheSetBalanceMaxProfitRatioForCustom
event in the setBalanceMaxProfitRatioForCustom() function, improperly takes inbalanceMaxProfitRatio
as a parameter instead ofbalanceMaxProfitRatioForCustom
.
Risk/Impact: The value emitted in the event will be inaccurate as the wrong variable is being passed in.function setBalanceMaxProfitRatioForCustom(uint _balanceMaxProfitRatioForCustom) external onlyOwner { balanceMaxProfitRatioForCustom = _balanceMaxProfitRatioForCustom; emit SetBalanceMaxProfitRatioForCustom(balanceMaxProfitRatio); }
Recommendation:balanceMaxProfitRatioForCustom
should be passed into theSetBalanceMaxProfitRatioForCustom
event in the setBalanceMaxProfitRatioForCustom() function.
Resolution: The team has implemented the above recommendation.
Finding #3 - House - Informational (Resolved)
Description: ThebalanceMaxProfitRatio
state variable is not utilized in the contract.
Recommendation: ThebalanceMaxProfitRatio
state variable and setBalanceMaxProfitRatio() function should either be removed to reduce contract size and deployment costs or utilized in a way that fits the project team's intended functionality.
Resolution: The team has implemented the above recommendation.
Finding #4 - DiceManager - Informational
Description: TheminBetAmount, maxBetAmount, and houseEdgeBP
state variables serve no purpose as they are not utilized in any logic in any contracts.
Recommendation: These state variables and their respective setter functions should either be removed to reduce contract size and deployment costs or utilized in a way that fits the project team's intended functionality. As the contract is already deployed, this is merely informational.
Contracts Overview
Dice Contract:
- As the contracts are implemented with Solidity v0.8.x, they are safe from any possible overflows/underflows.
House Contract:
- Any user can place a custom bet by choosing a number between 3 and 11 and specifying whether the sum of two simulated 6-sided dice rolls will be over or under their chosen number.
- The user will also specify a token address and a bet amount.
- The token address must have been added to the team's custom token list in the House contract and the bet amount must exceed the minimum amount for the custom token.
- A winnable amount is calculated by multiplying the user's bet amount by the team's custom multiplier value for the user's bet choice.
- The winnable amount cannot exceed the maximum value for the custom token set by the team.
- Upon placing a bet, a request ID is assigned to the bet in the QRNGManager via the airnodeRrp contract. The airnodeRrp contract was out of scope for this audit so our team is unable to provide an assessment with regard to security.
- The user's placed bet is transferred to the House contract.
- The QRNGManager contract can use this contract to determine the outcome of the bet.
- If the bet is a winner, the calculated win amount is transferred from the House contract to the user.
- The owner can set the minimum and maximum bet amounts for any address at any time.
- The owner can enable/disable bet placing at any time.
- The owner can update the House contract and QRNGManager contract addresses at any time.
- The owner can withdraw any tokens from the contract to a recipient address at any time.
QRNGManager Contract:
- When placing a custom bet in the Dice contract, the amount of the custom token is transferred from the user to this contract and their bet is finalized.
- When settling a bet, the calculated number of reward tokens are transferred from this contract to the winner's address.
- Any Admin address can withdraw any custom tokens from the contract to a specified recipient at any time.
- Any Admin address can refund any bet by transferring a specified number of tokens from the contract to a specified recipient at any time.
- Any Admin can manually settle a bet by specifying an amount of a custom token to transfer from the contract to a recipient.
- Any user can deposit any amount of ETH into the contract at any time.
- The owner can enable/disable all bet placing and bet settling at any time.
- The owner can add/remove addresses from the custom token list at any time. The team should exercise caution and ensure that only trusted tokens are added to the custom token list.
- The owner can set the contract's balance maximum profit ratios to any values at any time.
- The owner can add/remove any addresses from the Admin list at any time.
- The owner can withdraw any tokens or ETH from the contract to a recipient address at any time.
- Any "Game" address can use this contract to initiate a full request via the airnodeRrp contract which intends to return a Request ID hash for a placed bet.
- The airnodeRrp contract can fulfill a bet using the bet's request ID which intends to generate two random numbers that will be used in the Dice contract to determine the outcome of a bet. The random number generation relies on the use off-chain logic which has not been reviewed by our team.
- The owner can add/remove addresses as a Game address at any time.
- The owner can update the Airnode address, Sponsor wallet, and Endpoint value at any time.
Audit Results
Vulnerability Category | Notes | Result |
---|---|---|
Arbitrary Jump/Storage Write | N/A | PASS |
Centralization of Control |
|
WARNING |
Compiler Issues | N/A | PASS |
Delegate Call to Untrusted Contract | N/A | PASS |
Dependence on Predictable Variables | N/A | PASS |
Ether/Token Theft | N/A | PASS |
Flash Loans | N/A | PASS |
Front Running | N/A | PASS |
Improper Events | N/A | PASS |
Improper Authorization Scheme | N/A | PASS |
Integer Over/Underflow | N/A | PASS |
Logical Issues | N/A | PASS |
Oracle Issues | N/A | PASS |
Outdated Compiler Version | N/A | PASS |
Race Conditions | N/A | PASS |
Reentrancy | N/A | PASS |
Signature Issues | N/A | PASS |
Sybil Attack | N/A | PASS |
Unbounded Loops | N/A | PASS |
Unused Code | N/A | PASS |
Overall Contract Safety | PASS |
Dice Contract
($) = payable function
# = non-constant function
Int = Internal
Ext = External
Pub = Public
+ Context
- [Int] _msgSender
- [Int] _msgData
+ Ownable (Context)
- [Pub] #
- [Pub] owner
- [Int] _checkOwner
- [Pub] renounceOwnership #
- modifiers: onlyOwner
- [Pub] transferOwnership #
- modifiers: onlyOwner
- [Int] _transferOwnership #
+ [Int] IGame
- [Ext] settleBet #
+ [Int] IERC20
- [Ext] totalSupply
- [Ext] balanceOf
- [Ext] transfer #
- [Ext] allowance
- [Ext] approve #
- [Ext] transferFrom #
+ [Int] IERC20Permit
- [Ext] permit #
- [Ext] nonces
- [Ext] DOMAIN_SEPARATOR
+ [Lib] Address
- [Int] isContract
- [Int] sendValue #
- [Int] functionCall #
- [Int] functionCall #
- [Int] functionCallWithValue #
- [Int] functionCallWithValue #
- [Int] functionStaticCall
- [Int] functionStaticCall
- [Int] functionDelegateCall #
- [Int] functionDelegateCall #
- [Int] verifyCallResultFromTarget
- [Int] verifyCallResult
- [Prv] _revert
+ [Lib] SafeERC20
- [Int] safeTransfer #
- [Int] safeTransferFrom #
- [Int] safeApprove #
- [Int] safeIncreaseAllowance #
- [Int] safeDecreaseAllowance #
- [Int] safePermit #
- [Prv] _callOptionalReturn #
+ [Int] IHouse
- [Ext] placeCustomBet #
- [Ext] settleCustomBet #
- [Ext] refundCustomBet #
- [Ext] balanceAvailableForCustomBet
+ DiceManager (Ownable)
- [Pub] #
- [Ext] setHouse #
- modifiers: onlyOwner
- [Ext] betsLength
- [Ext] addCustomToken #
- modifiers: onlyOwner
- [Ext] setCustomMinBet #
- modifiers: onlyOwner
- [Ext] setCustomMaxBet #
- modifiers: onlyOwner
- [Ext] getCustomMinBet
- [Pub] getCustomMaxBet
- [Ext] toggleGameIsLive #
- modifiers: onlyOwner
- [Int] amountToWinnableAmount
- [Ext] withdrawCustomTokenFunds #
- modifiers: onlyOwner
+ [Int] IQRNGManager
- [Ext] makeRequestUint256 #
- [Ext] isQRNG
+ Dice (DiceManager, IGame)
- [Pub] #
- modifiers: DiceManager
- [Ext] setQRNG #
- modifiers: onlyOwner
- [Ext] placeCustomBet #
- [Ext] settleBet #
- [Prv] _settleBet #
- [Int] _getResult
House Contract
($) = payable function
# = non-constant function
Int = Internal
Ext = External
Pub = Public
+ Context
- [Int] _msgSender
- [Int] _msgData
+ Ownable (Context)
- [Pub] #
- [Pub] owner
- [Int] _checkOwner
- [Pub] renounceOwnership #
- modifiers: onlyOwner
- [Pub] transferOwnership #
- modifiers: onlyOwner
- [Int] _transferOwnership #
+ [Int] IGame
- [Ext] settleBet #
+ [Int] IERC20
- [Ext] totalSupply
- [Ext] balanceOf
- [Ext] transfer #
- [Ext] allowance
- [Ext] approve #
- [Ext] transferFrom #
+ [Int] IERC20Permit
- [Ext] permit #
- [Ext] nonces
- [Ext] DOMAIN_SEPARATOR
+ [Lib] Address
- [Int] isContract
- [Int] sendValue #
- [Int] functionCall #
- [Int] functionCall #
- [Int] functionCallWithValue #
- [Int] functionCallWithValue #
- [Int] functionStaticCall
- [Int] functionStaticCall
- [Int] functionDelegateCall #
- [Int] functionDelegateCall #
- [Int] verifyCallResultFromTarget
- [Int] verifyCallResult
- [Prv] _revert
+ [Lib] SafeERC20
- [Int] safeTransfer #
- [Int] safeTransferFrom #
- [Int] safeApprove #
- [Int] safeIncreaseAllowance #
- [Int] safeDecreaseAllowance #
- [Int] safePermit #
- [Prv] _callOptionalReturn #
+ [Int] IHouse
- [Ext] placeCustomBet #
- [Ext] settleCustomBet #
- [Ext] refundCustomBet #
- [Ext] balanceAvailableForCustomBet
+ House (Ownable, IHouse)
- [Ext] ($)
- [Ext] ($)
- [Pub] #
- [Ext] deposit ($)
- [Pub] customBalance
- [Ext] toggleHouseLive #
- modifiers: onlyOwner
- [Ext] addCustomToken #
- modifiers: onlyOwner
- [Ext] removeCustomToken #
- modifiers: onlyOwner
- [Ext] setBalanceMaxProfitRatioForCustom #
- modifiers: onlyOwner
- [Ext] addAdmin #
- modifiers: onlyOwner
- [Ext] removeAdmin #
- modifiers: onlyOwner
- [Pub] balanceAvailableForCustomBet
- [Pub] maxProfitForCustomBet
- [Ext] placeCustomBet #
- modifiers: isHouseLive,isAdmin,isCustomTokenActive
- [Ext] settleCustomBet #
- modifiers: isHouseLive,isAdmin,isCustomTokenActive
- [Ext] sendTokens #
- modifiers: isHouseLive,isAdmin
- [Ext] refundCustomBet #
- modifiers: isHouseLive,isAdmin
- [Ext] withdrawFunds #
- modifiers: onlyOwner
- [Ext] withdrawCustomTokenFunds #
- modifiers: onlyOwner
QRNGManager Contract
($) = payable function
# = non-constant function
Int = Internal
Ext = External
Pub = Public
+ [Int] IAuthorizationUtilsV0
- [Ext] checkAuthorizationStatus
- [Ext] checkAuthorizationStatuses
+ [Int] ITemplateUtilsV0
- [Ext] createTemplate #
- [Ext] getTemplates
- [Ext] templates
+ [Int] IWithdrawalUtilsV0
- [Ext] requestWithdrawal #
- [Ext] fulfillWithdrawal ($)
- [Ext] sponsorToWithdrawalRequestCount
+ [Int] IAirnodeRrpV0 (IAuthorizationUtilsV0, ITemplateUtilsV0, IWithdrawalUtilsV0)
- [Ext] setSponsorshipStatus #
- [Ext] makeTemplateRequest #
- [Ext] makeFullRequest #
- [Ext] fulfill #
- [Ext] fail #
- [Ext] sponsorToRequesterToSponsorshipStatus
- [Ext] requesterToRequestCountPlusOne
- [Ext] requestIsAwaitingFulfillment
+ RrpRequesterV0
- [Pub] #
+ Context
- [Int] _msgSender
- [Int] _msgData
+ Ownable (Context)
- [Pub] #
- [Pub] owner
- [Int] _checkOwner
- [Pub] renounceOwnership #
- modifiers: onlyOwner
- [Pub] transferOwnership #
- modifiers: onlyOwner
- [Int] _transferOwnership #
+ [Int] IGame
- [Ext] settleBet #
+ [Int] IQRNGManager
- [Ext] makeRequestUint256 #
- [Ext] isQRNG
+ QRNGManager (Ownable, RrpRequesterV0, IQRNGManager)
- [Pub] #
- modifiers: RrpRequesterV0
- [Ext] addGame #
- modifiers: onlyOwner
- [Ext] removeGame #
- modifiers: onlyOwner
- [Ext] setRequestParameters #
- modifiers: onlyOwner
- [Ext] setSponsorWallet #
- modifiers: onlyOwner
- [Prv] expand
- [Ext] makeRequestUint256 #
- modifiers: isGame
- [Ext] fulfillUint256 #
- modifiers: onlyAirnodeRrp
- [Ext] isQRNG
About SourceHat
SourceHat has quickly grown to have one of the most experienced and well-equipped smart contract auditing teams in the industry. Our team has conducted 1800+ solidity smart contract audits covering all major project types and protocols, securing a total of over $50 billion U.S. dollars in on-chain value!
Our firm is well-reputed in the community and is trusted as a top smart contract auditing company for the review of solidity code, no matter how complex. Our team of experienced solidity smart contract auditors performs audits for tokens, NFTs, crowdsales, marketplaces, gambling games, financial protocols, and more!
Contact us today to get a free quote for a smart contract audit of your project!
What is a SourceHat Audit?
Typically, a smart contract audit is a comprehensive review process designed to discover logical errors, security vulnerabilities, and optimization opportunities within code. A SourceHat Audit takes this a step further by verifying economic logic to ensure the stability of smart contracts and highlighting privileged functionality to create a report that is easy to understand for developers and community members alike.
How Do I Interpret the Findings?
Each of our Findings will be labeled with a Severity level. We always recommend the team resolve High, Medium, and Low severity findings prior to deploying the code to the mainnet. Here is a breakdown on what each Severity level means for the project:
- High severity indicates that the issue puts a large number of users' funds at risk and has a high probability of exploitation, or the smart contract contains serious logical issues which can prevent the code from operating as intended.
- Medium severity issues are those which place at least some users' funds at risk and has a medium to high probability of exploitation.
- Low severity issues have a relatively minor risk association; these issues have a low probability of occurring or may have a minimal impact.
- Informational issues pose no immediate risk, but inform the project team of opportunities for gas optimizations and following smart contract security best practices.