Skip to content

Commit

Permalink
zypher slides close to done
Browse files Browse the repository at this point in the history
  • Loading branch information
nuke-web3 committed Jun 7, 2024
1 parent e1a1548 commit baae1ef
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 89 deletions.
4 changes: 1 addition & 3 deletions content/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
- [🪧 Verifiable Games Using RISC Zero](./risc-zero/zypher-buildathon/presentation.md)
- [👷 ZK Chess Checkmate](./risc-zero/zypher-buildathon/workshop.md)

---

- [🙋 Guide](./contribute/index.md)
- [🙋 Contribute](./contribute/index.md)
- [🌀 Topic Template](./contribute/template/page.md)
- [📋 Copy & Paste Slides](./contribute/copy-paste-slides/page.md)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions content/risc-zero/zypher-buildathon/materials.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ Here are a few key game specific ones:

<iframe loading=lazy width="560" height="315" src="https://www.youtube-nocookie.com/embed/z7V830zndoA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

☝️ A fantastic verteran review of their work and showcases fundementally new type of game that web3 makes possible: build base infrastructure for others **to build on top of _permissionlessly_**.
Shared infra -> purality of ways to interact with a wider community on the same base layer opens up novel MMO games _**built by and for players**_!
☝️ A fantastic veteran review of their work and showcases fundamentally new type of game that web3 makes possible: build base infrastructure for others **to build on top of _permissionless_**.
Shared infra -> plurality of ways to interact with a wider community on the same base layer opens up novel MMO games _**built by and for players**_!

Although today zkVMs help devs avoid needing to write most of the game in some contract language or (zk)DSL, like is enabled in RISC Zero with <a target="_blank" href="https://github.com/risc0/risc0/tree/release-0.21/examples/bevy">the bevy game engine</a>.
And it's very likely to be far more cost effective to run too!
Expand Down
143 changes: 71 additions & 72 deletions content/risc-zero/zypher-buildathon/slides.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Verifiale Games Using RISC Zero
title: Verifiable Games Using RISC Zero
tags: RISC Zero, Talk, Presentation, Workshop, zkVM, zkGames, Zypher, Hackathon, Buildathon, Zero Knowledge Proof, Applied Cryptography, Rust, Zypher
duration: 60 minuets
description: RISC Zero Workshop for the Zypher Provable Games Buildathon - June 2024
Expand Down Expand Up @@ -37,9 +37,9 @@ revealOptions:

<img rounded style="width: 50%; height: 230px; object-fit: cover;" src="./img/fusion-dragon-ball.gif" />

**_On-chain_ $~~~$ 👉 $ZK$ 👈 $~~~$ _Off-chain_**
**_On-chain_ $~~~$ 👉 $ZK$ 👈 $~~~$ _Off-chain_**

<a style="font-size: 0.8em" target="_blank" href="https://nuke-web3.github.io/book/risc-zero/zypher-buildathon/materials.html">Workshop Materials ↗️</a>
<a target="_blank" href="https://nuke-web3.github.io/book/risc-zero/zypher-buildathon/materials.html">Event Materials ↗️</a>

---

Expand All @@ -60,20 +60,31 @@ Notes:

## What problems can ZK address for games?

On-chain (coprocessor):
<nuke-cols>
<nuke-col center>

### On-chain & Web3

- calldata limits restrict complexity
- gas costs are prohibitive
- public blockchains don’t support incomplete information games
- Zypher’s bullet points for challenges of on-chain gaming
- prohibitive gas costs
- most blockchains lack privacy

</nuke-col>
<nuke-col center>

Off-chain (TODO):
### Off-chain & Web2

- Cheating through manipulation of official game logic
- Private game aspects without any 3rd party / admin to adjudicate.
- Private game aspects without any 3rd party / admin to adjudicate

</nuke-col>
</nuke-cols>

> See <a target="_blank" href="https://zyphergames.notion.site/gZKm-supporting-content-528587063a314eabb9eb1ecc1d87b8b0">Zypher's supporting content</a> for more.
Notes:

- **ZK coprocessor** - run verifiable program logic in zkVM by 3rd party or yourself to untrusting parties
- Added **security** and **fairness** and **privacy** that zero-knowledge proofs can provide, as they involve complex decision-making and competitive interactions.
- Commonly turn based, but can simply be tick based (STF analogy -> blocks)
- Privacy is optional, fully transparent games with ZKPs _can_ provided added guarantees around many things other than that (if carefully designed)
Expand All @@ -85,7 +96,6 @@ Notes:
- Enabling incomplete information games (e.g. “fog of war” mechanics)
- Can prove final score without revealing _anything_ about the game that resulted in it! Proof of Exploit CTF.

- todo Mention alternatives? Why we are a good or the best choice? (privacy possible, not solidity or DSL specific)
- Off-chain: CFT game where you prove you got a flag without revealing it (because that needs to remain secret) no 3rd party to check, use a proof!

---
Expand All @@ -100,22 +110,34 @@ Developers are encouraged to implement game designs that can verify player actio

---

## Definitions & Lingo
## RISC Zero 101

- TODO diagram of host that encapsulates guest w/ input & output
- see https://www.youtube.com/watch?v=DzOWh3Ht0_Q & get diagrams
<img rounded style="width: 60%;" src="./img/zkVM-diagram-black.png" />

> Read <a target="_blank" href="https://dev.risczero.com/api/getting-started">Getting Started</a> and/or watch the <a target="_blank" href="https://www.youtube.com/playlist?list=PLcPzhUaCxlCj7wKkzekYYq7QDvtGTOPm7">playlist</a>.
Notes:

- deeper understanding as exercise for views of this presentation.
See the official docs & youtube for great deep
- very happy to answer questions on our discord!

---

## RISC Zero On-chain

<img rounded style="width: 60%;" src="./img/risc0-ethereum-bonsai.png" />

> Read about <a target="_blank" href="https://dev.risczero.com/api/blockchain-integration/bonsai-on-eth">Blockchain Integration</a> and watch the <a target="_blank" href="https://www.youtube.com/playlist?list=PLcPzhUaCxlCgsTtFen4oxFIDkUMSVSFFo">Foundry Template playlist</a>.
Notes:

- TODO diagram how the proof works in game context (seq. diagrams with actors IDed (player, execution, prover))

---

# ✨ Inspiration

> :warning: _Do not copy&paste submissions_ :pray:
##### ⚠️ -- Do not copy 🍝 -- 🙏

Notes:

Expand All @@ -126,33 +148,35 @@ Building on them to something significantly enhancements _**may**_ be considered

## ZK Checkmate Demo

<!-- FIXME link that works in book and slids and gh-pages -->
<!-- FIXME link that works in book and slides and gh-pages -->

Join in following the [Hands-on instructions ↗️](./checkmate-chess-example.md)
Join in following the [Hands-on instructions ↗️](./workshop.md)

Notes:

- Chess demo for verifying a winning move (checkmate) without revealing what the move is.
Contrived example a bit, but highlights:
- use crates without modification - no need to rewrite in circuits or zkDSL!
- Use standard patterns like `println!` & `fmt!` normally for basic experiments.
- 10s on lines of code overall -> useful proof, easily extensible!
- Original [deep dive video](https://www.youtube.com/watch?v=vxqxRiTXGBI&list=PLcPzhUaCxlCgig7ofeARMPwQ8vbuD6hC5&index=10) ([slides](https://drive.google.com/file/d/1Bum4x50qatqBUlQyNVkt90nnA2SEOHNO/view))
- See the recording there to follow along for an overview.
- I encourage you to experiment yourself!

---

## <a target="_blank" href="https://github.com/risc0/risc0/tree/release-0.21/examples/bevy">Bevy (R0 v0.21)</a>
## <a target="_blank" href="https://github.com/risc0/risc0/tree/v1.0.1/examples/bevy">Bevy (R0 v1.0.1)</a>

- **Serious** Rust <a target="_blank" href="https://bevyengine.org/">game engine</a>
- Great base to start hackin' 🤠
- Start with shared `core` logic

Notes:

- Serious Rust game engine for ZK games
- BEST place to start to see if you can compile & run this without modification on your machine.
- Core logic can be used in the host & the guest for Bevy games
- Design guest to be _minimal_ as proofs are costly!

---

## <a target="_blank" href="https://devfolio.co/projects/zksnake-c689">zkSnake (R0 v0.20)</a>

<iframe loading=lazy width="560" height="315" src="https://www.youtube-nocookie.com/embed/zkMqd_AhCFU?si=XH-R6XPzIqf0pHN8" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

> https://github.com/0xAndoroid/zkSnake
#### <a target="_blank" href="https://github.com/0xAndoroid/zkSnake">zkSnake Source ↗️</a>

Notes:

Expand All @@ -163,20 +187,21 @@ Notes:

## 3D ZK Games?!

## ▶️ <a target="_blank" href="https://bevyengine.org/examples/Games/alien-cake-addict">Bevy Wasm webGPL/webGPU example</a>
<img rounded style="width: 50%; height: 230px; object-fit: cover;" src="./img/bevy-alien-cake-addict.gif" />

🤯 <a target="_blank" href="https://zyphergames.notion.site/Invitation-gZKm-Provable-Games-Buildathon-1e52aef746874bf08ff1a12c4eed799b?p=77dac845c4984302b9d43a34cc7c2892&pm=c">Zypher Real-time Multiplayer Games Track</a> featured demo!
#### <a target="_blank" href="https://bevyengine.org/examples/Games/alien-cake-addict">🎮 Play the Demo 🎮</a>

Check warning on line 192 in content/risc-zero/zypher-buildathon/slides.md

View workflow job for this annotation

GitHub Actions / ci-checks

link checker warning

https://bevyengine.org/examples/Games/alien-cake-addict. Request was redirected to https://bevyengine.org/examples/Games/alien-cake-addict/

- <a target="_blank" href="https://zyphergames.notion.site/Invitation-gZKm-Provable-Games-Buildathon-1e52aef746874bf08ff1a12c4eed799b?p=77dac845c4984302b9d43a34cc7c2892&pm=c">Real-time Multiplayer Games Track</a> featured demo!
- <a target="_blank" href="https://github.com/zypher-game/Alien-Cake-Addict">Rendered web game + wallet connect</a>
- <a target="_blank" href="https://github.com/bevyengine/bevy-website/blob/main/generate-wasm-examples/generate_wasm_examples.sh">Original Bevy docs source</a> to generate the playable browser example
- <a target="_blank" href="https://github.com/bevyengine/bevy-website/blob/main/generate-wasm-examples/generate_wasm_examples.sh">Demo tooling</a> to generate browser example

---

## 🤔 What is special about RISC Zero?

- developer productivity (@ hackathons & beyond)
- Top 1000 [crates.io](https://crates.io/) tested ~nightly: [reports.risczero.com](https://reports.risczero.com/)

Check warning on line 203 in content/risc-zero/zypher-buildathon/slides.md

View workflow job for this annotation

GitHub Actions / ci-checks

link checker warning

https://reports.risczero.com/. Request was redirected to https://reports.risczero.com/release-1.0
- todo: key features that are HARD in zkDLS
- todo: key features that are HARD in zkDSL
- proof continuation
- execution separate from proof (realtime exec & prove in parallel / after / remote)
- foundry template & steel & mainnet verifiers
Expand All @@ -193,8 +218,22 @@ Notes:

---

## 🎨 ZK Game Design Patterns

- Prove transcript of game for verifiable high scores
- Prove state update based on complex game logic
- Prove validity of player moves while concealing
- play & prove latter (snake game)
- proof for each hidden move, perhaps in a tx on chain
- can run only core game logic in zkVM - GUI and other non-security/privacy/fairness aspects can live outside the proven core logic (diagram)
- randomness
- cannot do within guest - only fake & deterministic random for replay of moves perhaps (who gets to know seed? Choose? VRF maybe?)

---

## 📝 Key Takeaways

- as a game dev: what does zk do and not do for me?
- IMPORTANT: match version of `cargo risczero` & examples / templates / examples
- keep guest minimal - extra cycles are VERY expensive (but this is a hackathon, don't over optimize)
- USE DEV MODE!
Expand All @@ -206,46 +245,6 @@ Notes:

---

## TODO

- You emphasized that the proofs are “verrrry” expensive to build — I think we can dial that back. As a it’s something like 100k-1M times more expensive than native compute.
- Not sure what we can offer re malware/viruses — that felt a bit confusing to me
- Jumping around windows was disorienting — would suggest figuring out the specific ordering of which windows you want to open and try to use more words to flag what’s about to happen. perhaps even grabbing the relevant screenshots and importing things into the slides rather than doing a live-tour
- Make text bigger pretty much everywhere, but especially in terminal windows
- FEN is a format for notation chess games and chess positions https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation
- Nice job highlighting the idea that you don't have to do everything inside the zkvm
- Would be nice to synthesize the design patterns. i.e., things we can do are:
- Prove transcript of game for verifiable high scores
- Prove state update based on complex game logic.
- Prove validity of player moves while concealing
- Question about pulling something out into core library.
- Typo on last slide re: zkDSL (it says zkDLS)

youtube description workshop instructions?

see discord ref page for moving to book

missing:

- synthesis of design patterns used in games
- play & prove latter (snake game)
- proof for each hidden move, perhaps in a tx on chain
- can run only core game logic in zkVM - GUI and other non-security/privacy/fairness aspects can live outside the proven core logic (diagram)
- recap
- as a game dev: what does zk do and not do for me?
- randomness
- cannot do within guest - only fake & deterministic random for replay of moves perhaps (who gets to know seed? Choose? VRF maybe?)
- video or screen shots instead of live code
- more diagrams especially wrt games
- how the proof works in game context (seq. diagrams with actors IDed (player, execution, prover))
- what do we not know about web3 games... more on chain that we know of as a team?
- bigger text (for term especially)
- More about web3 integrations specifically? Does foundry worth with zypher?
- scale solidity games off-chain with Zeth... but should rewrite in rust!
-

---

# Further Reading & Resources

- <a style="font-size: 0.8em" target="_blank" href="https://nuke-web3.github.io/book/risc-zero/zypher-buildathon/materials.html">Event Materials ↗️</a>
## <a target="_blank" href="https://nuke-web3.github.io/book/risc-zero/zypher-buildathon/materials.html">Event Materials ↗️</a>
36 changes: 25 additions & 11 deletions content/risc-zero/zypher-buildathon/workshop.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
## ZK Checkmate (R0 v1.0)

Let's experiment with a ZK chess game for verifying a winning move (a checkmate) is possible next turn without revealing what the move is to anyone.
We extend the example by proving we know a set of moves that arrives at that final board state.

1. Watch <a target="_blank" href="https://www.youtube.com/playlist?list=PLcPzhUaCxlCj7wKkzekYYq7QDvtGTOPm7">this playlist</a> to learn the basics
1. (Optional) <a target="_blank" href="https://www.youtube.com/watch?v=juxiL-PM6kk">Watch a primer</a> on <a target="_blank" href="https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation">FEN</a> and <a target="_blank" href="https://www.dcode.fr/san-chess-notation">SAN</a> notation for chess.

Check warning on line 6 in content/risc-zero/zypher-buildathon/workshop.md

View workflow job for this annotation

GitHub Actions / ci-checks

link checker warning

https://www.dcode.fr/san-chess-notation. Request was redirected to https://www.dcode.fr/san-chess-notation?__r=1.bf4792491257fd2108b080914644e2fa
1. Watch <a target="_blank" href="https://www.youtube.com/playlist?list=PLcPzhUaCxlCj7wKkzekYYq7QDvtGTOPm7">this playlist</a> to learn the basics of RISC Zero
1. Use `rzup` to setup your development environment based on the **correct version of the <a target="_blank" href="https://dev.risczero.com/api/">RISC Zero Getting Started Docs</a>** for you.
```sh
# Get rzup
curl -L https://risczero.com/install | bash
# Follow command instructions to use rzup
# ... This will take a while first time!
```
1. Clone and run <a target="_blank" href="https://github.com/risc0/risc0/tree/v1.0.1/examples/chess">the chess example</a> with:
1. <a target="_blank" href="https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template#creating-a-repository-from-a-template">Generate a new repo from the template</a> for <a target="_blank" href="https://github.com/risc0/risc0/tree/v1.0.1/examples/chess">this chess example</a>:
```sh
git clone --branch v1.0.1 --depth=1 https://github.com/risc0/risc0
cd risc0
cd examples/chess
# Clone direct, or your new repo fom this template:
git clone https://github.com/<YOUR_GH_USER>/risc0-v1-chess
# **OR** Clone the template direct:
git clone https://github.com/nuke-web3/risc0-v1-chess
cd risc0-v1-chess
cargo r -r
# ... This will take a while first time!
# If you get errors, see step one to get setup!
```
1. Take a look at the structure of the code:
1. Take a look at the structure of the code and key files:
```sh
risc0/examples/chess
risc0/examples/risc0-v1-chess
├── Cargo.toml
├── core
│ ├── Cargo.toml
│ └── src
│ └── lib.rs # SHARED logic (host & guest)
│ └── lib.rs # 🌍 Shared = Host ↔️ Guest
├── methods
│ ├── build.rs
│ ├── Cargo.toml
│ ├── guest
│ │ ├── Cargo.lock
│ │ ├── Cargo.toml
│ │ └── src
│ │ └── main.rs # 🌟 Guest = Game Logic to be proven
│ │ └── main.rs # 🧰 Guest = Game Logic to be proven 🌟
│ └── src
│ └── lib.rs
├── README.md
└── src
└── main.rs # Host = Execution of guest & GUI & more unproven
└── main.rs # 🏃 Host = Execution of guest & GUI & more unproven
```
1. Make some changes to:
1. `src/main.rs` to change the FEN game state and see if a non-mate move is detected.
1. `methods/guest/src/main.rs` to change what is proven about the game.
1. `methods/guest/src/main.rs` to change what is proven about the game:
Perhaps add something to `core/src/lib.rs` around player ID that could be proven?

## 📝 Key Takeaways
Expand All @@ -55,4 +59,14 @@ This example is a bit contrived as it's a single move that should be easy to spo
- 10s on lines of code overall -> useful proof, easily extensible!
- <a target="_blank" href="https://en.wikipedia.org/wiki/Bayesian_game">Incomplete information games</a> are possible on-chain! Hidden data/moves for players are proven, never revealed to _anyone_!

## 🤓 Taking it Further

Here are some ideas to keep extending this example to learn more:

- Make the game multiplayer with turns between untrusting parties
- Perhaps using moves signed by players in a <a target="_blank" href="https://ethereum.org/en/developers/docs/scaling/state-channels/">state channel</a> type construction, latter proven to arrive at a final winner (only?) in the receipt.
- Integrate with the <a target="_blank" href="https://github.com/risc0/risc0-foundry-template">Foundry Template</a>
- Game with stake or pot to play?
- Verify a winner and dispence funds accordingly.

> Original <a target="_blank" href="https://www.youtube.com/watch?v=vxqxRiTXGBI&list=PLcPzhUaCxlCgig7ofeARMPwQ8vbuD6hC5&index=10">deep dive video</a> & <a target="_blank" href="https://drive.google.com/file/d/1Bum4x50qatqBUlQyNVkt90nnA2SEOHNO/view">slides</a> & <a target="_blank" href="https://github.com/risc0/risc0-rust-examples/tree/main/chess">source</a> - a great reference to supliment, but outdated using R0 v0.12 .
2 changes: 1 addition & 1 deletion tools/styles/base-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
--r-heading4-size: 1.5em;
--r-code-font: monospace;
/* custom var */
--r-code-font-size: 0.75em;
--r-code-font-size: 0.85em;
--r-link-color: #cdd06f;
--r-link-color-decoration: #fbff96;
--r-color-controls: #fbff96;
Expand Down

0 comments on commit baae1ef

Please sign in to comment.