|
| 1 | +This document provides guidelines on how to run Polygon Zero's Type-1 prover, specifically for proving transactions, but with the option to test full blocks of less than 4M gas. |
| 2 | +So, it is similar to [`eth-proof`](https://github.com/wborgeaud/eth-proof) but for transaction proofs. |
| 3 | + |
| 4 | +## Quick Start |
| 5 | + |
| 6 | +There two ways to run this prover. The simplest way to get started is |
| 7 | +to use the `in-memory` runtime of |
| 8 | +[Paladin](https://github.com/0xPolygonZero/paladin). This requires |
| 9 | +very little setup, but it's not really suitable for a large scale |
| 10 | +test. The other method for testing the prover is to leverage an |
| 11 | +[AMQP](https://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol) |
| 12 | +like [RabbitMQ](https://en.wikipedia.org/wiki/RabbitMQ) to distribute |
| 13 | +workload over many workers. |
| 14 | + |
| 15 | +!!!info |
| 16 | + |
| 17 | + It's worth noting that you'll need at least 40GB of physical memory to run the prover. |
| 18 | + |
| 19 | + |
| 20 | +### Setup |
| 21 | + |
| 22 | +Before running the prover, you'll need to compile the |
| 23 | +application. This command should do the trick: |
| 24 | + |
| 25 | +```bash |
| 26 | +env RUSTFLAGS='-C target-cpu=native' cargo build --release |
| 27 | +``` |
| 28 | + |
| 29 | +You should end up with two binaries in your `target/release` |
| 30 | +folder. One is called `worker` and the other is `leader`. Typically, |
| 31 | +we'll install these somewhere in our `$PATH` for convenience. |
| 32 | + |
| 33 | +Once you have application available, you'll need to create a block |
| 34 | +[witness](https://nmohnblatt.github.io/zk-jargon-decoder/definitions/witness.html) |
| 35 | +which essentially serves as the input for the prover. |
| 36 | + |
| 37 | +Assuming you've deployed the `leader` binary, you should be able to generate a witness |
| 38 | +like this: |
| 39 | + |
| 40 | +```bash |
| 41 | +paladin-leader rpc -u $RPC_URL -t 0x2f0faea6778845b02f9faf84e7e911ef12c287ce7deb924c5925f3626c77906e > 0x2f0faea6778845b02f9faf84e7e911ef12c287ce7deb924c5925f3626c77906e.json |
| 42 | +``` |
| 43 | + |
| 44 | +You'll need access to an Ethereum RPC in order to run this |
| 45 | +command. The input argument is a transaction hash and in particular it |
| 46 | +is the _last_ transaction hash in the block. |
| 47 | + |
| 48 | +Once you've successfully generated a witness, you're ready to start |
| 49 | +proving either with the `in-memory` run time or the `amqp` runtime. |
| 50 | + |
| 51 | +### In Memory Proving |
| 52 | + |
| 53 | +Running the prover with the `in-memory` setup requires no setup. You |
| 54 | +can attempt to generate a proof with a command like this. |
| 55 | + |
| 56 | +```bash |
| 57 | +env RUST_MIN_STACK=33554432 \ |
| 58 | +ARITHMETIC_CIRCUIT_SIZE="15..28" \ |
| 59 | +BYTE_PACKING_CIRCUIT_SIZE="9..28" \ |
| 60 | +CPU_CIRCUIT_SIZE="12..28" \ |
| 61 | +KECCAK_CIRCUIT_SIZE="14..28" \ |
| 62 | +KECCAK_SPONGE_CIRCUIT_SIZE="9..28" \ |
| 63 | +LOGIC_CIRCUIT_SIZE="12..28" \ |
| 64 | +MEMORY_CIRCUIT_SIZE="17..30" \ |
| 65 | +paladin-leader prove \ |
| 66 | +--runtime in-memory \ |
| 67 | +--num-workers 1 \ |
| 68 | +--input-witness 0x2f0faea6778845b02f9faf84e7e911ef12c287ce7deb924c5925f3626c77906e.json |
| 69 | +``` |
| 70 | + |
| 71 | +The circuit parameters here are meant to be compatible with virtually |
| 72 | +all Ethereum blocks. This will create a block proof from an input |
| 73 | +state root of the preceding block. You can adjust the `--num-workers` |
| 74 | +flag based on the number of available compute resources. As a rule of |
| 75 | +thumb, you'd probably want at least 8 cores per worker. |
| 76 | + |
| 77 | +### AMQP Proving |
| 78 | + |
| 79 | +Proving in a distributed compute environment depends on an AMQP |
| 80 | +server. We're not going to cover the setup of RabbitMQ, but assuming |
| 81 | +you have something like that available you can run a "leader" which |
| 82 | +distribute proving tasks to a collection of "workers" which actually |
| 83 | +do the proving work. |
| 84 | + |
| 85 | +In order to run the workers, you'll use a command like: |
| 86 | + |
| 87 | +```bash |
| 88 | +env RUST_MIN_STACK=33554432 \ |
| 89 | +ARITHMETIC_CIRCUIT_SIZE="15..28" \ |
| 90 | +BYTE_PACKING_CIRCUIT_SIZE="9..28" \ |
| 91 | +CPU_CIRCUIT_SIZE="12..28" \ |
| 92 | +KECCAK_CIRCUIT_SIZE="14..28" \ |
| 93 | +KECCAK_SPONGE_CIRCUIT_SIZE="9..28" \ |
| 94 | +LOGIC_CIRCUIT_SIZE="12..28" \ |
| 95 | +MEMORY_CIRCUIT_SIZE="17..30" \ |
| 96 | +paladin-worker --runtime amqp --amqp-uri=amqp://localhost:5672 |
| 97 | +``` |
| 98 | + |
| 99 | +This will start the worker and have it await tasks. Depending on the |
| 100 | +size of your machine, you may be able to run several workers on the |
| 101 | +same operating system. An example [systemd |
| 102 | +service](./deploy/paladin-worker@.service) is included. Once that |
| 103 | +service is installed, you could enable and start 16 workers on the |
| 104 | +same VM like this: |
| 105 | + |
| 106 | +```bash |
| 107 | +seq 0 15 | xargs -I xxx systemctl enable paladin-worker@xxx |
| 108 | +seq 0 15 | xargs -I xxx systemctl start paladin-worker@xxx |
| 109 | +``` |
| 110 | + |
| 111 | +Now that you have your pool of paladin workers, you can start proving |
| 112 | +with a command like this: |
| 113 | + |
| 114 | +```bash |
| 115 | +paladin-leader prove \ |
| 116 | +--runtime amqp \ |
| 117 | +--amqp-uri=amqp://localhost:5672 \ |
| 118 | +--input-witness 0x2f0faea6778845b02f9faf84e7e911ef12c287ce7deb924c5925f3626c77906e.json |
| 119 | +``` |
| 120 | + |
| 121 | +This command will run the same way as the `in-memory` mode except that |
| 122 | +the leader itself isn't doing the work. The separate worker processes |
| 123 | +are doing the heavy lifting. |
| 124 | + |
| 125 | + |
| 126 | +## Proving costs |
| 127 | + |
| 128 | +It makes sense to look at the proving costs, as opposed to TPS. |
| 129 | + |
| 130 | + |
| 131 | +Based on a GCP's 3-year commitment price on a t2d-standard-60 machine, where each vCPU has 4GB memory: |
| 132 | + |
| 133 | +- $0.012376$ USD / vCPU hour |
| 134 | +- $0.001659$ USD / GB hour |
| 135 | + |
| 136 | + We obtain, $(60 \times 0.012376) + (240 \times 0.001659) = 1.14072$ USD. |
| 137 | + |
| 138 | +| Block Number | Transactions | Gas | Proof Time (minutes) | Total Cost | Cost Per Tx | |
| 139 | +| ----------------------------------------------- | ------------ | ---------- | -------------------- | ---------- | ----------- | |
| 140 | +| [17106222](https://etherscan.io/block/17106222) | 105 | 10,781,405 | 44.17 | $0.235 | $0.0022 | |
| 141 | +| [17095624](https://etherscan.io/block/17095624) | 163 | 12,684,901 | 78.12 | $0.415 | $0.0025 | |
| 142 | +| [17735424](https://etherscan.io/block/17735424) | 182 | 16,580,448 | 100.52 | $0.534 | $0.0029 | |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | + |
0 commit comments