Approaching Tezos From an Ethereum Developer’s Mindset — Our Journey

@chainofinsight
Chain of Insight
Published in
6 min readAug 6, 2020

--

Image credit: BitBoy Crypto

Recently our team has come to really enjoy developing on Tezos. Coming from an Ethereum background we first approached problems with an Ethereum developer’s mindset which got in the way a bit, but our journey also led to our first happy accident — the creation of “Proof of Puzzle” and the PoP Machine Glow zero knowledge prover.

Thinking of Ethereum as a “world wide supercomputer” and its tx model (which makes it free to call non-payable functions), it’s easy to fetch the result of pure computations at no cost to the end user. To start with, we had a rough idea of what we wanted to build: an on-chain crypto-puzzle checker that automatically transfers rewards (like funds, tokens and NFTs) to the solver’s wallet without requiring them to sweep an external wallet. It would be free to check the answers to riddles, but cost a small amount of gas to claim a prize from the contract. After creating a rough mock up, we theorized it could be cheaper to process these transactions on Tezos instead of Ethereum. Or, as the pseudo-mysterious “L.M. Goodman” wrote in the Tezos position paper

“A downside of a Turing complete scripting language for [smart] contracts is that the number of steps needed to execute a script is potentially unbounded, a property which is generally uncomputable. To address this problem, Ethereum has devised a system by which the miner validating the transaction requires a fee proportional to the complexity and number of steps needed to execute the contract.”

After some initial testing there wasn’t a huge value difference between transacting on either chain — at least for the puzzle computations we needed to do — but Tezos transactions were slightly cheaper. That said, we discovered other benefits which led us to continue building on Tezos. This is the story of what we’ve learned so far.

Here’s a few key points we learned about Tezos while developing PoPMG:

  • Tezos is uniquely suited for blockchain oracles
  • It pairs well with games and cryptography
  • And has more flexible storage possibilities

Let’s break that down a bit…

The Oracle Thing

Because Tezos entry points have the natural convention of returning a contract’s storage, they’re perfect for developing oracle contracts. The below source code and explorer link is one such a contract. This contract’s storage is updated by a web server running pytezos every ~30 seconds, at each new block height on Carthagenet. At any moment you can call it and read back the value of Apple’s stock (AAPL) to an accuracy of +-30 seconds, provided you can trust the web server updating storage 😏

Games and Cryptography

The functional approach of Michelson makes Tezos a good fit for the contracts we develop for puzzle games. Michelson is more readable than EVM code, and it’s easier to unit test because

  1. you don’t need to deploy (“originate” in Tezos verbiage) your contract just to test it
  2. It’s easier to wrap your head around possible outcomes because the only state mutations allowed will be to the contract’s storage.

This absence of mutations is a boon for cryptography because it keeps the crypto implementation “pure”, ensuring optimal performance and deterministic integrity. It’s a boon for game development because it removes possibilities for side effects in your game logic.

Data Storage

Storage limitations have long been a thing in Ethereum development. Many Dapps (especially games) choose to parse data like game scores from events released by the contract’s logs rather than store it in the EVM state. We first were bumping our heads against this limit after developing an Ethereum based music player and jukebox back in 2018.

While the contract itself runs smoothly, reading from or manipulating the list of songs tended not to scale well over time. So it wasn’t exactly the intergalactic super-ipod we’d intended it to be. Another limitation regarding storage is the way stacks are handled by the EVM. It’s an issue discussed in depth in this article

The TLDR; of the above article is you need to be careful about organizing your data, as there’s a limitation on stack depth in the EVM. This isn’t a deal breaker — developers have long since found creative ways to work around this limitation (e.g. see this example) by bundling data in arrays. However, it’s far from ideal and tends to have an accumulation effect in practice. E.g. increased bundling => leads to increased parsing => leads to increased computation => and by extension increased gas costs. Tezos by contrast, has a novel way of dealing with stack execution. Consider the following excerpt from the Tezos Developer Resources guide

“A Michelson program is a series of instructions that are run in sequence: each instruction receives as input the stack resulting of the previous instruction, and rewrites it for the next one. The stack contains both immediate values and heap allocated structures. All values are immutable and garbage collected. […] The types of the input and output stack are fixed and monomorphic, and the program is typechecked before being introduced into the system. No smart contract execution can fail because an instruction has been executed on a stack of unexpected length or contents.”

Of course no system can ever process a computation of infinity length. Naturally, Tezos has storage limits too, although there is no fixed limit on the storage of a contract. That said, after a certain storage size it can become difficult to get your operation included in a block. Bakers will notice if including a computation in a block is going tie up resources. As the Tezos Developer guide explains it

“A baker is more likely to include an operation with lower gas and storage limits because it takes less resources to execute so it is in the best interest of the user to pick limits that are as close as possible to the actual use.”

What We’ve Been Up To

It’s no secret we’re working on a sequel to Satoshi’s Lost Faucet, but difficult to describe the intense work that’s already gone into its creation (and how much there’s still left to do 😅). The working title of the game is Schrödinger’s Cup. Not much we can say just at the moment, except we’ve really overhauled the concept of how puzzle checker web forms should behave.

Checker from a cool Neon District puzzle

Nothing wrong with these black box puzzle checkers, but they aren’t exactly transparent. To change this we created a novel zero knowledge cryptography system called PoP Machine Glow, and with PoPMG prize claims can be embedded directly in the solving experience without requiring the player to leave the dapp to go sweep a private key.

Something we’re excited about is PoPMG is lightweight enough to generate knowledge commitments from a mobile device. By providing an on ramp for mobile users, we hope to usher in a new era of crypto puzzles. We’re big fans of the original Myst game from Brøderbund and believe its success indicates mainstream adoption for well designed puzzle games is not so far away as some might think.

The Legend of Tezos Nomic 😎

One unique piece of Schrödinger’s Cup (that we can talk about, since it’s not a puzzle) is a game of Peter Suber’s Nomic running on Tezos.

“Tezos can instantiate any blockchain based protocol. Its seed protocol specifies a procedure for stakeholders to approve amendments to the protocol, including amendments to the amendment procedure itself. Upgrades to Tezos are staged through a testing environment to allow stakeholders to recall potentially problematic amendments. […] The philosophy of Tezos is inspired by Peter Suber’s Nomic[1], a game built around a fully introspective set of rules.” [Tezos Whitepaper]

There’s still a lot of usability work to do before we’ll want to show it off, but we built a basic beta that plays through all the incredible psychic turns and twists of a game of Nomic. To get a taste of what’s possible check out a live gameplay demo we made of a recent play test session

Nomic gameplay session 06/26/2020

TQuorum Series

Lastly, we gave a presentation recently for the Tezos TQuorum series. If you’re interested in learning more about the minute details of the PoPMG zero knowledge prover and generator, this presentation is an excellent primer. Presentation also touches on Schrödinger’s Cup and the state of blockchain gaming in general.

--

--