# Paima engine template

**URL:** <https://forums.minaprotocol.com/t/paima-engine-template/6353>\
**Category:** Mina Navigator Proposals\
**Created:** [July 8, 2024, 3:29pm UTC](https://forums.minaprotocol.com/t/paima-engine-template/6353 "2024-07-08T15:29:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hgedia](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.minaprotocol.com/hgedia/32/1734_2.png) [@hgedia](https://forums.minaprotocol.com/u/hgedia)\
**Post date:** [July 8, 2024, 3:29pm UTC](https://forums.minaprotocol.com/t/paima-engine-template/6353/1 "2024-07-08T15:29:45Z")

</div>

This topic is to discuss the proposal submitted by @SebastienGllmt  
Please see below for the details of the proposal and discussion.

**1st Aug, 2024**  
_Funding Note: This proposal is approved for funding. This proposal has a medium impact on the ecosystem. Paima has successfully launched products and thus risk associated with this delivery is low. The budget is inline with the work proposed. We hope the deliverables of game templates will introduce new teams to the ecosystem over mid-term._

**13 July, 2024**  
_Current status: Under Consideration._  
_Opened for community discussion on : 13th July 2024_

---

<div class="post-metadata">

**Author:** ![SebastienGllmt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.minaprotocol.com/sebastiengllmt/32/1974_2.png) [@SebastienGllmt](https://forums.minaprotocol.com/u/SebastienGllmt)\
**Post date:** [July 13, 2024, 9:18am UTC](https://forums.minaprotocol.com/t/paima-engine-template/6353/2 "2024-07-13T09:18:33Z")

</div>

# Title

Onchain game leveraging Mina Protocol

# Project Background

Paima Studios is a game studio building onchain games, and we are building our next commercial game leveraging Mina Protocol. However, multiple public-good infrastructure pieces are missing to enable this.

Notably,

- It’s it’s hard to build a commercial product using Mina if you can’t tap into the EVM userbase
- Core infrastructure and cryptographic primitives to build games that leverage Mina are missing

To solve this,

- We will release MIT open-source primitives for Mina to solve the challenges missing above
- We will release MIT open-source templates using these primitives so other companies have a starting point for building their own experience
- We will release a commercial game leveraging the primitives (and [idle game](https://mobilefreetoplay.com/idle-games-everything-you-need-to-know/) game where VDFs prove you have idled). Early preview of the Twitter (announced at the time of writing this proposal) here: [https://x.com/ClickAndMoo](https://x.com/ClickAndMoo)

# Proposal Overview

- Problem: there are missing pieces to build a successful commercial product in Mina
- Solution: Create public-good infrastructure for Mina, templatize them for ease-of-use, and release a commercial game to prove their viability in business and bring adoption to Mina
- Impact: this work will

1. lower the development cost of using Mina by having more primitives and templates to leverage
2. increase adoption of Mina by improving access to EVM users and creating a commercial game

# Architecture & Design

**Architecture**

- General Paima Engine architecture: [https://docs.paimastudios.com/](https://docs.paimastudios.com/)
- Mina integration architecture: [Paima ZK Layer Architecture | Paima Blog](https://blog.paimastudios.com/paima-zk-layer)
- Paima batcher architecture: [https://docs.paimastudios.com/home/read-write-L2-state/batched-mode](https://docs.paimastudios.com/home/read-write-L2-state/batched-mode)

For the VDF specifically, there are 2 common algorithms for implementing VDF:

- Wesolowski: complex, but faster
- Piertzak: slower, but simpler (and recursive)

We will write a VDF _verifier_ and not a _prover_ in o1js, given writing a prover is significantly more complex (in implementation and performance), and isn’t required as the user can generate a proof on their local machine, and all we need in o1js is a verification of this local computation.

Given Piertzak’s implementation uses recursion, we believe this will be the easiest to implement into Mina’s recursion system. Both implementations have a Rust implementation which will serve as the basis of our o1js implementation. Notably, the Piertzak implementation can be found [here](https://github.com/poanetwork/vdf/blob/719925d8a33c1d482a95d608a09dcdc199e97cdc/vdf/src/proof_pietrzak.rs#L187)

**Vision**

Our plan is to leverage this template to build commercial games leveraging Mina protocol

**Existing work**

- Mina funnel support in Paima Engine: [https://docs.paimastudios.com/home/react-to-events/funnel-types/mina-funnel](https://docs.paimastudios.com/home/react-to-events/funnel-types/mina-funnel)
- Mina wallet support in Paima Engine: [Basics | Paima Engine](https://docs.paimastudios.com/home/multichain-support/wallet-layer/introduction)
- Example of commercial games we’ve built in the past: [https://tarochi.paimastudios.com/](https://tarochi.paimastudios.com/)

**Production timeline**

- May: Mina template for basic Paima Engine integration, including

1. The ability to synchronize Mina events and actions from a rollup node
2. The ability to connect to and verify signatures of Mina wallets from our SDK

- June: Mina template that uses ZkProgram for local proof generation (needed for the game to scale by having the user run a lot of the proof generation on their machine). This will support

1. EVM wallet usage, including a writeup about how the EVM verification ZkProgram works and benchmark vs other approaches
2. Connecting it to a batcher system so that games can subsidize tx fees to allow it to be usable from MetaMask

- July: Mina template leveraging a Verifiable Delay Function (VDF) verifier to enable use-cases that depend on timers (very common in games)

Additionally,

- The template will be live and updated with new features every month
- We plan to leverage this in a future commercial game (release date TBD)

# Budget & milestones

**Deliverables**

- A Paima Engine template that is updated into 3 parts. One for basic Mina support, another for ZkProgram support, and another for VDF support.

**Mid-poiont milestone**

- A template with Mina support anybody can run, with an implementation for the EVM ZkProgram milestone

**Project timeline** : 3 months

**Budget** : 30k MINA

**Budget breakdown** : 10000 MINA/month on

- 1 senior developer for the core implementation of the template
- 2 senior developer part-time for as-needed support (Paima Engine feature requests, o1js support)
- 1 project manager to review code and ensure milestones are properly met

**Wallet Address** : B62qmsMCXDA9bbubwrZDnwUabeXV9MoaWLXyVaAP78Cr7mQxBCNimvs

# Team Info

**Proposer Github** : [SebastienGllmt (Sebastien Guillemot) · GitHub](https://github.com/SebastienGllmt)

**Proposer experience**

- Co-founded Zeko (zk rollup for Mina)
- Co-founded Paima Studios which has built multiple games live to mainnet including our game Tarochi with 100+ ETH in volume

**Team members**

- Core developer for the project: [SpaceManiac (Tad Hardesty) · GitHub](https://github.com/SpaceManiac)
- Paima Engine feautre support: [ecioppettini (Enzo Cioppettini) · GitHub](https://github.com/ecioppettini)
- o1js support: [L-as · GitHub](https://github.com/L-as)
- Project Manager: [SebastienGllmt (Sebastien Guillemot) · GitHub](https://github.com/SebastienGllmt)

**Achievements**

- Build Tarochi, a decentralized RPG game deployed to Arbitrum+Cardano which has 100+ ETH in lifetime volume
- Built Paima Engine, one of the largest sovereign rollups in crypto
- Build a lot of core infrastructure for Cardano including its most popular [Rust SDK](https://github.com/dcSpark/cardano-multiplatform-lib)

# Risks & Mitigations

- The main risk we forsee is that even with ZkProgram usage, performance may still be too slow to build a game. We have many options to speed it up including leveraging Zeko which has faster block times and can be used to create L3 with less restrictions than the Mina L1 (ex: more account updates), so we think we can surpass these risks
- VDF is a complex primitive and it is sometimes hard to predict subtleties in the implemenetation. We have made this the last milestone to take into account that future work may be required on it

---

<div class="post-metadata">

**Author:** ![Pfedprog](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.minaprotocol.com/pfedprog/32/1980_2.png) [@Pfedprog](https://forums.minaprotocol.com/u/Pfedprog)\
**Post date:** [July 15, 2024, 6:30pm UTC](https://forums.minaprotocol.com/t/paima-engine-template/6353/3 "2024-07-15T18:30:21Z")

</div>

Interesting proposal and really great article [Paima ZK Layer Architecture | Paima Blog](https://blog.paimastudios.com/paima-zk-layer/).

Curious to learn what are your thoughts regarding Smart Contract vs ZkProgram.

---

<div class="post-metadata">

**Author:** ![0x471](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.minaprotocol.com/0x471/32/2097_2.png) [@0x471](https://forums.minaprotocol.com/u/0x471)\
**Post date:** [July 26, 2024, 1:20am UTC](https://forums.minaprotocol.com/t/paima-engine-template/6353/4 "2024-07-26T01:20:32Z")

</div>

Thanks for the proposal!

The blogpost about Mina integration architecture was before Aligned Layer announced. Do you still consider using Mina Bridge or Aligned layer for verifying Mina state on Ethereum?

---

<div class="post-metadata">

**Author:** ![SebastienGllmt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.minaprotocol.com/sebastiengllmt/32/1974_2.png) [@SebastienGllmt](https://forums.minaprotocol.com/u/SebastienGllmt)\
**Post date:** [August 1, 2024, 3:44pm UTC](https://forums.minaprotocol.com/t/paima-engine-template/6353/5 "2024-08-01T15:44:12Z")

</div>

We just released our blog post that talks about the _Smart Contract vs ZkProgram_ topic precisely! It also talks about how we leverage this concept to build our account abstraction system so that players can access our game directly from EVM wallets

> **[EVM rollapps powered by Mina Protocol | Paima Blog](https://blog.paimastudios.com/mina-evm/)**
>
> Cover image

---

<div class="post-metadata">

**Author:** ![SebastienGllmt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.minaprotocol.com/sebastiengllmt/32/1974_2.png) [@SebastienGllmt](https://forums.minaprotocol.com/u/SebastienGllmt)\
**Post date:** [August 1, 2024, 3:46pm UTC](https://forums.minaprotocol.com/t/paima-engine-template/6353/6 "2024-08-01T15:46:04Z")

</div>

I believe Aligned Layer will get us to production faster, and will also lower long-term costs to combining our stack with other systems like DA layers (ex: Avail’s EVM connection is built using SP1 which will also be built with Aligned Layer, which makes it possible to use EVM+Avail+Mina together for an app)

I talk a bit about the trade-off of Aligned Layer vs using the Mina bridge directly near the end of our most recent blog post

> **[EVM rollapps powered by Mina Protocol | Paima Blog](https://blog.paimastudios.com/mina-evm/)**
>
> Cover image

---

<div class="post-metadata">

**Author:** ![hgedia](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.minaprotocol.com/hgedia/32/1734_2.png) [@hgedia](https://forums.minaprotocol.com/u/hgedia)\
**Post date:** [August 3, 2024, 10:57am UTC](https://forums.minaprotocol.com/t/paima-engine-template/6353/7 "2024-08-03T10:57:57Z")

</div>

Funding Note: This proposal is approved for funding. This proposal has a medium impact on the ecosystem. Paima has successfully launched products and thus risk associated with this delivery is low. The budget is inline with the work proposed. We hope the deliverables of game templates will introduce new teams to the ecosystem over mid-term.

---

<div class="post-metadata">

**Author:** ![SebastienGllmt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.minaprotocol.com/sebastiengllmt/32/1974_2.png) [@SebastienGllmt](https://forums.minaprotocol.com/u/SebastienGllmt)\
**Post date:** [September 1, 2024, 2:32am UTC](https://forums.minaprotocol.com/t/paima-engine-template/6353/8 "2024-09-01T02:32:12Z")

</div>

We tried porting the Rust implementation of the Pietrzak VDF to o1js, but even after some modifications to the verifier algorithm, it’s still to to run in o1js. There is one possible idea we have for Pietrzak VDFs that has a chance of working, but the verification time would at least be in the minutes

Given getting VDFs to work in Mina seems it will transition to being more of an open research problem than an engineering problem like we would have hoped, we’ve decided to instead wrap up the initial roadmap of the work with a blog post sharing the different literature we’ve read through along with summarizing the open problems we think could lead to a working VDF in the future

We’ve also open-sourced the code for the benchmark of the GCD step that is required for _class groups of an imaginary quadratic field_ that led us to rule out the Pietrzak VDF approach [GitHub - PaimaStudios/o1js-gcd](https://github.com/PaimaStudios/o1js-gcd)

> **[SoK: VDFs for proving passage of time in ZK games | Paima Blog](https://blog.paimastudios.com/vdf-sok/)**
>
> Cover image

---

<div class="post-metadata">

**Author:** ![YashBit](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.minaprotocol.com/yashbit/32/2199_2.png) [@YashBit](https://forums.minaprotocol.com/u/YashBit)\
**Post date:** [October 10, 2024, 8:00am UTC](https://forums.minaprotocol.com/t/paima-engine-template/6353/10 "2024-10-10T08:00:15Z")

</div>

@SebastienGllmt @hgedia

I am currently in the process of preparing a proposal for implementing VDFs (MinRoot) on o1js. Would love to get in touch.
