Coder Social home page Coder Social logo

chainsweep's Introduction

ChainSweep on-chain game

Screenshot

Live demo on Arbitrum Stylus Testnet

This game is an on-chain implementation of a game similar to the well-known "minesweeper" game.

In a field of blocks you have to validate blocks, avoiding the ones that contain bugs. When you click a buggy block, you lose. When you validated all blocks without bugs, you win.

The game is run fully on-chain (Arbitrum Stylus Testnet). Every move you make is a separate transaction.

The important piece of information in the game is where exactly the bugs are (the fields you shouldn't click). If the smart contract chooses these spots and stores them on chain, then it would be trivial to win the game by looking with a block explorer or other tools where the bugs are. To avoid this, the contract only stores which fields have been revealed so far. When the player makes a new move, the smart contract re-generates a potential assignment of bugs on the field that's consistent with the moves made so far. This makes that the game remains unpredictable.

To make the calculation of possible assignments efficient, it uses Arbitrum Stylus so that Rust code can be run as WebAssembly and the simulation process doesn't take too much gas.

This is a submission for Scaling Ethereum 2024.

Setup

Install Rust, and then install the Stylus CLI tool with Cargo

RUSTFLAGS="-C link-args=-rdynamic" cargo install --force cargo-stylus

Add the wasm32-unknown-unknown build target to your Rust compiler:

rustup target add wasm32-unknown-unknown

You should now have it available as a Cargo subcommand:

cargo stylus --help

Install solc (necessary to generate json ABI):

wget https://github.com/ethereum/solidity/releases/download/v0.8.25/solc-static-linux -O ~/.local/bin/solc
chmod a+x ~/.local/bin/solc

Testnet Information

All testnet information, including faucets and RPC endpoints can be found here.

Local development

1. Setup

Local dev node with stylus support setup (note, I had to replace docker-compose with docker compose in the init script for it to work)

Install foundry:

cargo install --git https://github.com/foundry-rs/foundry --profile local --locked forge cast chisel anvil

2. Local dev

You start the local node with test-node.bash --blockscout in the directory where you installed the local stylus dev node. The local explorer is then accessible at http://localhost:4000/.

License

This project is fully open source, under the Apache-2.0 license.

Sources

The repository was bootstrapped from the stylus-hello-world project. I looked at code from the stylus-workshop-rust-solidity project as well.

chainsweep's People

Contributors

mathijs81 avatar

Watchers

 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.