Obscuro Testnet includes an example dApp to help you better understand how dApps capitalise on Obscuro’s unique privacy features.
Number Guessing Game
A number guessing game is a simple way of showcasing the principles of privacy in Obscuro. The goal of the game is to guess a secret number. Each time an attempt is made an entrance fee of 1 unit of the token is paid (with 1x10^18 units making a single token). If a player correctly guesses the number the contract will pay out all of the accumulated entrance fees to them and reset itself with a new random number.
Consider for a moment how a secret number could be created without divulging it. This is impossible in a transparent, decentralised ecosystem like Ethereum because when the secret number is generated by the smart contract it would be trivial to look up the internal state of the contract and see the secret number. OK, so let’s imagine the internal state of the contract and therefore the secret number is hidden, what happens when players start making their guesses? Using a block explorer to see the attempted guesses in plain view within the details of the transaction immediately provides new players with an unfair advantage and the game is ruined.
Building the guessing game in Obscuro addresses both scenarios described above. The guessing game smart contract generates a random secret number when it is deployed. This number is never revealed to a player or node operator, or indeed anybody because it is generated within a Trusted Execution Environment. And when players make their guesses the transactions carrying the guesses are encrypted and therefore obscured in a block explorer.
How to Play
- Start up the wallet extension. Follow instructions here.
- For the moment, the Guessing Game includes an ERC20 token (called OGG, short for Obscuro Guessing Game). This is partly because OGG is modified to have a built-in faucet: It allocates tokens to addresses as they make a request to allow other addresses to take tokens from their account.
- If you want to see this balance in your wallet, you have to import a new Token with the address:
- Browse to the number guessing game. Check you see
Network ID: 777at the top of the game window to confirm you are connected to Obscuro Testnet.
- MetaMask will open and ask to connect your account. Click
- Approve the payment of 1 or more token units to play the game (this will be added to the prize pool) by clicking the
Approve game feebutton.
- MetaMask will ask for your account to sign a transaction specifying the Guess contract address as the approval delegate. This means that you’re giving permission for the game to take the participation fee. Click
Confirm. Once approved you will see a confirmation popup. Click
- Now you can play the game by typing your guess into the secret number field. Click the
- MetaMask will ask for your account to sign a contract interaction (your guess). Click
Confirm. Note how the data presented by MetaMask to you is not yet encypted. That happens when MetaMask signs the transaction and sends it to the wallet extension “network”, allowing the wallet extension to encrypt it before it leaves your computer.
- Open MetaMask to check the progress of your guess transaction in the
Activitytab of MetaMask. Wait a few moments for it to change from pending to complete.
- The game should show you two messages, one confirming the success of the Approval transaction, and the second confirming the result of the guess attempt (whether correct, wrong, warmer or colder than the last guess).
Once the guess transaction is completed you can check the guess transaction on ObscuroScan:
- In MetaMask click on the transaction to open it then click
Copy Transaction ID. Open ObscuroScan.
- Paste your copied transaction ID into the search box to find your individual guess transaction. Note how the transaction data visible to everyone is encrypted in the field
EncryptedTxBloband how (for now) the transaction is decrypted to allow developers to confirm correct behaviour of the network.
- You can see your guess as the number at the right hand end of the
inputvalue in a hexadecimal format, e.g. a guess of 99 is shown as 63.
Known Issues and Limitations
- When making a guess nothing appears to happen. MetaMask shows a failed transaction in the
Activitytab for the guess submission.
- Cause: the guessing game has been reset between this and your previous guess. As a result your nonce is out of sequence.
- Workaround: reset your MetaMask account data in MetaMask using the option
Settings > Advanced > Reset Account
Now you have enjoyed playing the guessing game you are invited to make it even better! Go ahead and fork the guessing game code in this GitHub repository and bring your own contributions to Obscuro Testnet. Of course, you are free to deploy any smart contract to the testnet.