Giter Club home page Giter Club logo

battleblocks-smart-contracts's Introduction

BattleBlocks Smart Contracts

This repository contains the smart contracts for BattleBlocks, a decentralized application (dapp) built on the Flow blockchain. The dapp includes various functionalities, each implemented as a separate smart contract in this repository.

Development

The contracts in this repository are written in Cadence, the programming language for the Flow blockchain. To deploy and test the contracts, you will need to have the Flow CLI and emulator installed on your local machine.

BattleBlocksNFT

BattleBlocksNFT is a simple implementation of a non-fungible token (NFT) contract. It is based on the ExampleNFT contract provided by the Flow team and is used for demonstrative purposes in the BattleBlocks hackathon.

BattleBlocksChildAccount

BattleBlocksChildAccount is used for walletless account management. This contract allows users to create and manage child accounts within their main account, providing a more streamlined and user-friendly experience. The contract is based on the recently emerging ChildContract smart contract from this repo: https://github.com/onflow/linked-accounts

BattleBlocksGame

BattleBlocksGame is the game smart contract for BattleBlocks. It provides the logic and functionality for players to compete against each other in the game of "Battleships". At the begging of a game, each player sets up a board and person to first find out where the oponnent placed 10 of his blocks, wins. To ensure players are not lying about their block placement and keep their blocks unrevealed until it is time to reveal them, the smart contract uses a merklee tree proof system.

Merkle Tree Proofs

At the begging of the game, a player must submit a merkle tree root which is created by using the merkle tree algorithm

  • Leaves: The merkle tree leaves that are defined by our smart contract are a string of numbers that can be split up into three sections.

    • The first digit indicates whether the coordinate on the grid contains a block: 1 = yes, 0 = no
    • The second and third digit represent the coordinates of the block: 03 = x:0, y: 3
    • The final 5 digits are a random 5 digit number nonce created with a random number generator (min = 10000, max 99999): 23923
    • If we use the example values from above, we would finally end up with the resulting leaf that looks like this: 10323923. This leaf indicates that there is a block at the (0, 3) coordinates. We have also created a random nonce (23923) for it that we will use hash and create the merkle tree
  • Tree Generation: After creating all the nonces and leaves, each leaf is hashed with Keccak256 and a merkle tree is generated by using the merkle tree algorithm, an important thing to note is that in our implementation, odd nodes of the tree are duplicated. After the tree is generated, a tree root should be given as a parameter to the game creation or game joining transaction.

  • Proof: When each player makes a move, unless it is the first move. He needs to prove if the last spot the opposing player has fired at actually contains a block. This is actually why we use merkle trees in the first place. To do this, we define in the smart contract that the player needs to offer proof and raw leaf creation data for the opponents previous guess. After doing so, we prove the truthfullness of the intially supplied merkle tree root (or proof) by using the proof and raw leaf data. If the proof is valid, the game continues and the player score is calculated accordingly.

Deployments

Contract Address Environment
FungibleToken 0x9a0766d93b6608b7 Testnet
MetadataViews 0x631e88ae7f1d7c20 Testnet
NonFungibleToken 0x631e88ae7f1d7c20 Testnet
FiatToken 0xa983fecbed621163 Testnet
FlowToken 0x7e60df042a9c0868 Testnet
BattleBlocksNFT 0xf95724cf2202cd00 Testnet
BattleBlocksAccounts 0xf95724cf2202cd00 Testnet
BattleBlocksGame 0xf95724cf2202cd00 Testnet

License

This project is licensed under the MIT License.

battleblocks-smart-contracts's People

Contributors

fabijan-zulj avatar highskore avatar

Stargazers

 avatar

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.