A ZK-powered database built with Polygon Miden

HC

Calum Moore

Nov 21, 2022

Polybase-and-Miden-VM
Polybase-and-Miden-VM
Polybase-and-Miden-VM

Polybase DB uses Polygon Miden VM to enable zero-knowledge proof features using Polylang, a new programming language. The language allows developers to define the permissions of their databases. The syntax is similar to TypeScript to make it easy for both web2 and web3 developers to use.

The Polylang programming language

This code defines an “Account” database table with a transfer function to allow moving a balance from one account to another (with only the owner having permission to initiate a transfer).

Polybase balance transfer function.

As Polybase DB is a decentralized database (meaning no individual person controls it), we need to ensure these permissions are respected, without having a centralized gatekeeper.

Decentralizing permissions with ZK proofs

Existing blockchains (e.g. Ethereum) validate that transactions in a block are valid by having every network participant rerun the transactions and check they end up with the same output result or “block hash”. As you can imagine, having lots of machines do the same work, over and over again, is expensive and slow.

An alternative way to validate that the transactions are valid is using a new kind of cryptography called zk-proofs (zero-knowledge proofs).** With zk-proofs a single machine performs the computation and provides a certificate to prove that transactions/computation was performed correctly, and therefore the output is valid. Anyone can trust the output of the code without running the code itself.

At Polybase, we use zk-proofs.

Using Miden VM to create proofs

Miden VM is a tool created by Polygon to create zk-proofs. We choose to use it because:

  • It uses STARKS instead of SNARKS, which means it does not require a trusted setup ceremony and is quantum secure

  • It’s faster than other similar STARK-based zk-proof libraries (benchmarks coming soon)

  • It’s Turing complete

  • It uses a virtual machine (VM) instead of gate based proof system, which means it can handle for-loops and is easier to compile from our Polylang language

  • It’s written in rust and compiles to web assembly, so it can be run in the browser

VM and STARK-based proofs are generally thought to be slower to generate and larger in size than other proof systems (such as Plonky2), but we’ve been really impressed with the performance so far, and there are known ways to improve the performance further. We are excited to be working with the Miden core team to help make these changes a reality.

Generating proofs on the client

There are three key benefits to using zk-proofs and generating them on the user’s device.

Scalability

Running computation on the client and then simply sending a short proof is much more efficient, so using zk-proofs allows us to scale Polybase DB far beyond traditional blockchains. And because validating proofs is fast, clients can proactively share data and updates with other peers on the network, creating a p2p network that prevents the bottlenecks associated with centralized databases.

Cost

Because most of the work needed to make changes to the database is performed by the client device, we can reduce the amount of work the network has to perform, and so dramatically reduce the cost or “gas fees”. We can also move data “off-chain”. Rather than every node on the network storing all the data (like in Ethereum), database creators can choose how many times to replicate it. This tremendously reduces costs.

Proving data

Using zk-proofs, we can verify that a given piece of data is stored in the database, allowing great flexibility on where data is stored and how it is indexed and aggregated. This enables the developer to choose the trade-offs (e.g. security, durability, and performance) that are important to them. Data could be stored on the user’s device (for ultra-sensitive data), a decentralized storage network such as Filecoin/Arweave (for collaborative data), or even a centralized storage provider such as S3. You can also use our Ethereum bridge to prove values that exist in Ethereum or vice versa.

Of course, if you just want a database experience similar to Firebase, we will always offer a simple and cohesive experience that works out of the box.

Hiding the complexity

At Polybase we strive to make exceptional developer experiences. Miden’s virtual machine uses a low-level assembly language, which allows for precise control over the flow of computation. But it is difficult for developers to use directly.

| We made Polylang compile to Miden assembly, hiding all the complexity from the user.

So now, with just a few lines of code, you can create a database table with permissions, write data, and read it back. You don’t need to think about the underlying cryptography at all.

Creating a database in Polybase.

Next step

Start building with Polybase DB → polybase.xyz/docs