GithubHelp home page GithubHelp logo

nashhash's Introduction

NASHHASH hi

Game theory games on the blockchain

Install

  1. clone the app

  2. npm install -g truffle

  3. npm install -g yarn

  4. yarn install

  5. IMPORTANT: you're going to want to set your metamask mneumonic in an .env file . used for deployments too.

    1. Create a file in root dir called .env

    2. first line set WORDS=<secret phrase>

    3. nice all done

Build

Run locally

  1. truffle develop

  2. compile; deploy

  3. yarn start

Deploy

  1. Purge assets rm -r build; rm -r src/contracts

  2. Compile truffle compile

  3. Deploy: truffle migrate --reset --network rinkeby

  4. Copy assets to local cp -r build/contracts src/contracts

Test

  1. Purge assets rm -r build;
  2. truffle develop
  3. compile
  4. migrate --reset
  5. test

Common errors

INVALID ADDRESS

make sure you include account in function call. ie. instance.function(params, { from: user_address })

P2.5:

  1. bot to always complete game

Gamemaster

Build and test the package

  1. Install golang

     brew install go
    
  2. Setup the GOPATH

     export GOPATH=$(pwd)
    

You want to set it up to some/path/nashhash/src

  1. Genereate the go binding for the Game.sol

     cd gm
     go generate
    
  2. In a separate terminal window, starth geth on rinkeby. It might take sometime to sync.

     geth --rinkeby
    
  3. Run tests

     go test -v -timeout 5m
    

The timeout is important. Some tests will not run under the default constrsaint. This will result in test failure.

Description

Gamemaster is a piece of server side code that manages the state of all instances of the games. Each newly created game (aka newly deployed contract) is assigned a GameOperator.

GameOperator runs as a separate go routine who's main purpose is to control game state transitions. A contract can be in three different states:

  1. COMMIT_STATE – the contract is accepting commits
  2. REVEAL_STATE – the contract is accepting reveals
  3. PAYOUT_STATE – the contract is ready for the payout() to be called by the owner.

The states transitions as follows: COMMIT_STATE -> REVEAL_STATE -> PAYOUT_STATE -> COMMIT_STATE -> REVEAL_STATE -> ...

The GameOperator has three different transitions it can influence.

  1. When the contract is in PAYOUT_STATE, the GameOperator is responsibile for noticing this and calling payout() method of the contract (and thus pay the gas fee for findWinners() internal function)
  2. When the contract has been in COMMIT_STATE for too long, we might want the game to start without waiting for the rest of the players. In that case the owner has to call forceToRevealState() to trigger a COMMIT_STATE -> REVEAL_STATE transition.
  3. Similar but with forceToPayoutState()

Game Master Daemon

Build

cd src/gmd
go build

This will produce an executable gmd

Run

gmd -ip=<ip_addr> -port=<port_number> -key=<owner_private_key>

We can omit -ip and -port flags to run gmd on 127.0.0.1:50000 Additionally, port provided must be a private port.

gmd is not daemonized yet. To run it in the background you will have to explicitly do so.

Example

Lets run the gmd in the background

nohup ./gmd -key=76a23cff887b294bb60ccde7ad1eb800f0f6ede70d33b154a53eadb20681a4e3 &>log.txt &

This above command will report the PID of the process. Use this PID to kill the process if needed.

If we need to kill it

kill -9 <PID>

GameMaster Client (gmc)

  1. Build

     go build
    
  2. Run

     ./gmc -ip=<gm_ip> -port=<port>
    

If flags are not provided, will default to 127.0.0.1:50000

  1. Example

First, make sure gmd is running. Without it, client will have nowhere to connect to.

Lets start the client:

./gmc

If we have a game at contract 0x7B9d950cC1ecD94eD0cF3916989B0ac56C70AB24, we connect it like so:

gmclerk> connect  0x7B9d950cC1ecD94eD0cF3916989B0ac56C70AB24

The relevant logging should be triggered on the gmd end. If everything went well, gmc will return the prompt to you. If something went bad, it will print the error and return the promt. Restart gmc if you are getting this error:

2018/06/13 04:28:47 connection is shut down

If we now want to disconnect the game, here is how we do it:

gmclerk> disconnect  0x7B9d950cC1ecD94eD0cF3916989B0ac56C70AB24

We can also connect all games in a file:

gmclerk> connect -f <filename>

nashhash's People

Contributors

ain2108 avatar freeslugs avatar talaltoukan avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

sbnair

nashhash's Issues

Repeated Reveal Bug

Consider what happens if player A:

  1. Commits a number
  2. Reveals a number
  3. Reveals the same number again within the same round.
function reveal(string guess, string random) public whenNotPaused {
        

        require(state.gameState == GameState.REVEAL_STATE);
        
        checkGuess(guess);

        // Check that the hashes match
        // Hashes will keep matching for repeated reveals
        require(commits[msg.sender] == keccak256(guess, random));

        // When they do, we add the revealed guess to game data
        gameData[msg.sender] = guess;

        // Game data keys will be full of Player A keys. Thus if findWinners() finds a winner, it must be A
        gameDataKeys[state.currNumberReveals] = msg.sender;
        
        // Repeated reveals by the same player will increment the total reveal counter
        state.currNumberReveals++;

        // This allows one player quickly reveal his number maxPlayers times, and thus winning the game
       // by triggering a transition to payout state.
        if(state.currNumberReveals == config.MAX_PLAYERS){
            emit RevealsSubmitted();
            state.gameState = GameState.PAYOUT_STATE;
            state.gameStateDebug = 2;
        }
    }

Remove state from LowestUniqNum.sol

// Guesses and guesser addresses
mapping (uint => address) private guessAddrs;
uint[] private guesses;

I was wondering if we can get rid of this in storage mapping and use some kind of in memory local data structure?

Non essential, but potentially cheaper from gas fees perspective and better for state consistency

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.