Skip to content

szerintedmi/numbergame

Repository files navigation

THIS repo is defunct, project moved to a new repo: ethereum-lupi

numbergame

Decentralised Smallest Number Game on Ethereum

Play a game where each player sends one positive integer in a game round, with a fixed 'bet' amount. The player who sends a unique and smallest number wins the pot. This means if two people happen to send the same number, then the third one gets all the bets regardless the other two number were smaller. If there is no winner (ie. there is no unique number in the round ) then all players get back their bet.
What number would you put if you were to play this game?

NOTE: It's a work in progress project: there are plenty of TODO and some open questions. Check it below and the comments in code.

Contribution, code review and suggestions are welcome!

Game Mechanics

  1. A round is initiated by the first player. And be closed in a future time (closing date).
  2. Players submit their guess: a positive integer number for the round. A pre-defined guess amount is included to have a stake in the game.
  3. At the closing date, the round stops accepting further bets and a winner is selected. The winner is defined as the one who picked the lowest number that nobody else has picked.
  4. At game close the organizer takes a pre-defined fee.
    • If there’s a winner, the contract disburses all remaining funds to the winner.
    • If there’s no winner, the remaining funds are disbursed to the participants.

Technical implementation - First pass approach

Participants send their bet to a 3rd party (oraclize.it) which encrypts it with it’s own secret key. The encrypted version of the bet is sent in to the contract. At a given time - which is specified at the beginning of the round - the 3rd party starts revealing the clear-text bets, one by one. After all bets are revealed, the round is closed.

OverView diagram See also: Detailed Sequence Diagram

There are a number of known issues with this approach. See ongoing discussion in wiki about potential alternative solutions to keep bids secret until end of the round.

Dev environment

Prerequisites

git clone --recursive https://github.com/szerintedmi/numbergame.git
cd numbergame
npm install
cd ethereum-bridge
npm install
  • testrpc (global): npm run testrpc:install
    • if you want to run testrpc in a docker container:
      npm run testrpc:docker:build
  • truffle (global): npm run truffle:install

Compile & deploy & run

on testprc

npm run testrpc:start
npm run bridge:start
npm run truffle:migrate
npm run dev

Detailed deploy instructions

  • An improved and customized Ethereum explorer fork if you want to browse the local chain:
    npm run explorer:start

TODO:

  • When contract .sol changed then both testrcp and ethereum-bridge need to be restarted. Truffle migrate won't deploy the new version.
  • dockerize (Dockerfiles + docker-compose config)

Testing

truffle test (work in progress)

Licence

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.