- Notifications
You must be signed in to change notification settings - Fork1
🎲 Let's roll dices on Algorand!
License
cusma/algo-dices
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Let's roll your dices on Algorand!
AlgoDices let playersroll dices on-chain (bothTestNetandMainNet), thanks theRandomness Beacon Application.
Starting from AVM 7, Algorand enablesturstless randomness on chain,thanks to the use ofVRF:with thevrf_verify
opcode an oracle Smart Contract can prove that apseudo-random value has been honestly computed off-chain through a VRF processfor a given blockchain round in the future.
AlgoDices makes use of the Randomness Beacon App deployed onTestNetandMainNet,which verifies, stores and provides the randomness toother applications for a given (future) round according toARC-21.
NOTE: There is a non-negligible risk the MainNet Randomness Beaconmiss certain round or becomes unavailable. In the latter case a newversion of AlgoDices will be released.
AlgoDices ABI exposes two methods:
book_dices_roll
roll_dices
AlgoDices App requires players to opt-in.
Players can book dices rolls for future round, committing to futurerandomness:
{"name":"book_dices_roll","args": [ {"type":"uint64","name":"future_round","desc":"Future round booked for dices roll" } ],"returns": {"type":"void" },"desc":"Book dices roll for a future round."}
Althogh the more the round is distant in the future the better is for security,AlgoDices App does not impose any minimumfuture_round
, leaving this check tothe client. An external App interacting with AlgoDices, for example, couldmandatefuture_round
to be greater than current round plusN
.
book_dices_roll
twice will overwrite the last booked round, even ifthe previous booked randomness is unused.
Once the booked randomness is available, players can roll dices with"real"number of faces (d2
,d4
,d6
,d8
,d10
,d12
,d20
, are common dices inboard games).
Players can roll multiple dices together (e.g.2d6
,1d8
and1d20
),up to 14.
future_round + 8
round to be sure thattheir booked randomness is available in the Randomness Beacon App.
{"name":"roll_dices","args": [ {"type":"application","name":"randomness_beacon","desc":"Randomness Beacon App ID (TestNet: 110096026, MainNet: 947957720)" }, {"type":"uint8[]","name":"dices","desc":"Array of dices to roll (faces: 2, 4, 6, 8, 10, 12, 20)" } ],"returns": {"type":"uint8[]","desc":"Dices roll result." },"desc":"Roll dices with a given number of faces. Fee: 3 * min_fee."}
AlgoDiceroll_dices
returns an array containing the dices results.
On-chain games cancall AlgoDices imposing their own rules, for example:aGameApp
callsroll_die
two times (on behalf of players Alice and Bobparticipating in the game through proxy Contract Accounts controlled byGameApp) as Inner Transactions executed in the same GameApp Call, requiringdice = 6
. The highest result wins the match.
AlgoDices is also atrustless dices roller to play board games andRPGs (like D&D) "over-the-phone": players can safely roll dices remotely,with no mean of cheating. A Dungeon Master could ask the 🧝🏻♀️ Wizard Elfto roll8d6
to count 🔥 Fireball damages and be sure the result is correct!
You can easily roll dices with the Python 🎲 AlgoDices CLI.
Clonealgo-dices
repo an open it:
$ git clone git@github.com:cusma/algo-dices.git$cd algo-dices
Install the virtual environment described inPipfile
usingpipenv
:
$ pipenv install
Lounch 🎲 AlgoDices CLI:
$ pipenv run python3 algodices.py🎲 AlgoDices, let's roll verifiable random dices on Algornd!Usage: algodices.py optin [--test] algodices.py book <future_rounds> [--test] algodices.py roll <dice> ... [--test]Commands: optin Subscribe to AlgoDices. book Book a die roll in future round. roll Roll dices (e.g. 2d6, 1d8 and 1d20: roll 6 6 8 20).Options: -h, --help -t, --test
-t
option to play on TestNet.
"word_1 ... word_25"
.
Example: roll 2d6, 1d8 and 1d20 on TestNet:
$ pipenv run python3 algodices.py roll 6 6 8 20 -t --- 🎰 RESULTS 🎰 --- 🎲 d6: 1 --- 🎲 d6: 5 --- 🎲 d8: 1 --- 🎲 d20: 17
AlgoDices can be played also withDappFlow ABI Studio,either on TestNet or MainNet, by logging with your wallet and importingthe AlgoDicescontract.json
.
stateDiagram[*] --> AlgoDices : createAlgoDices --> AlgoDices_User : opt_inAlgoDices_User --> Booked_Randomness : book_dices_rollBooked_Randomness --> Booked_Randomness : book_dices_rollstate randomness <<choice>>Booked_Randomness --> randomness : roll_dices(faces)randomness --> Dices_Result : randomess_availablerandomness --> Booked_Randomness : randomness_unavailableDices_Result --> AlgoDices_User
Multiple dices rolls on single round (e.g.[2d6, 1d8, 1d20]
);- Contract Account proxy for players;
- Switch to 512 bits math allowing more than 14 dices;
- Unlimited dices rolls (pay-per-roll).
Thanks to@ori-shem-tov,@fabrice102 for the Randomness OracleApplication and@barnjamin for theCoinFlipper example thatinspired AlgoDices.
Another special thanks again to@fabrice102for the precious and clever considerations on "safe" optimization ofrandomness source usage.
About
🎲 Let's roll dices on Algorand!