<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fluid Dex on Medium]]></title>
        <description><![CDATA[Stories by Fluid Dex on Medium]]></description>
        <link>https://medium.com/@fluid-dex?source=rss-8f18c7bd8194------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sJe94Et9VrtLlu8Xjk7NoA.png</url>
            <title>Stories by Fluid Dex on Medium</title>
            <link>https://medium.com/@fluid-dex?source=rss-8f18c7bd8194------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 05:59:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fluid-dex/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[On the optimization of PlonK]]></title>
            <link>https://fluid-dex.medium.com/on-the-optimization-of-plonk-87797f5942cd?source=rss-8f18c7bd8194------2</link>
            <guid isPermaLink="false">https://medium.com/p/87797f5942cd</guid>
            <category><![CDATA[zero-knowledge-proofs]]></category>
            <dc:creator><![CDATA[Fluid Dex]]></dc:creator>
            <pubDate>Sat, 19 Jun 2021 01:34:28 GMT</pubDate>
            <atom:updated>2021-06-20T05:58:18.482Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Acknowledgement: we thank Ariel Gabizon, Daira Hopwood, Kobi Gurkan, Pratyush Mishra (in alphabetical order) for their kindly reviews and insightful comments.</em></p><p>In this article we brief three directions on optimizing PLONK, which is a polynomial interactive oracle proofs (IOP) zkSNARK systems. Proof systems other than using IOP also exist, for comparisons please refer to: <a href="https://telaviv2019.scalingbitcoin.org/files/a-survey-of-progress-in-succinct-zero-knowledge-proofs-towards-trustless-snarks.pptx">A Survey of Progress in Succinct Zero-Knowledge Proofs</a>.</p><h3>The 3 layers of a polynomial IOP zkSNARK system</h3><ul><li>Accumulation layer: <em>for Recursive Proof Composition</em></li><li>IOP layer: <em>PlonK core is here</em></li><li>Polynomial commitment layer: <em>for efficiently verifying polynomials</em></li></ul><p>Readers can gain a basic idea on the relationships between each layer from <a href="https://electriccoin.co/blog/explaining-halo-2/">https://electriccoin.co/blog/explaining-halo-2/</a> (although it’s about Halo 2, it’s still helpful for understanding the relationships), so we would like to skip redundant explanations here.</p><h3>The origin of PlonK</h3><p>Out of the desire for a universal, programmable zkSNARK, <a href="https://aztec.network/">AZTEC</a> invents and promotes the industry use of <a href="https://eprint.iacr.org/2019/953.pdf">PlonK</a>. PlonK is flexible to build application-specific constraints, so that it strikes a balance between theoretical properties and engineering needs. Vitalik also wrote an awesome article explaining PlonK: <a href="https://vitalik.ca/general/2019/09/22/plonk.html">Understanding PLONK</a>. You may also find some useful resources on <a href="https://github.com/Fluidex/awesome-plonk">https://github.com/Fluidex/awesome-plonk</a>.</p><p>PlonK has been popular since it went published. <a href="https://zksync.io/">zkSync</a>, <a href="https://dusk.network/">Dusk Network</a>, <a href="https://minaprotocol.com/">Mina</a>, <a href="https://mirprotocol.org/">Mir</a>, and <a href="https://zcash.github.io/halo2/concepts/arithmetization.html">Zcash’s Halo 2</a>, are projects using PlonK or its variants.</p><h3>The features of PlonK</h3><p>PlonK supports universal and updateable setup, so</p><blockquote>This means two things: first, instead of there being one separate trusted setup for every program you want to prove things about, there is one single trusted setup for the whole scheme after which you can use the scheme with any program (up to some maximum size chosen when making the setup). Second, there is a way for multiple parties to participate in the trusted setup such that it is secure as long as any one of them is honest, and this multi-party procedure is fully sequential: first one person participates, then the second, then the third… The full set of participants does not even need to be known ahead of time; new participants could just add themselves to the end. This makes it easy for the trusted setup to have a large number of participants, making it quite safe in practice. — — taken from <a href="https://vitalik.ca/general/2019/09/22/plonk.html">Vitalik’s website</a></blockquote><p>Groth16 and other non-universal proof systems use rank-1 constraint system (R1CS) as the intermediate representation for their zkp circuits. PlonK is gate-based instead of R1CS-based, and transpiling from R1CS will likely be inefficient if using PlonK. For example, addition gates are cheap in R1CS-based systems, however which is not the case in gate-based systems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JyuxVGW4IQxx62UcU1VAFg.png" /></figure><p>R1CS has the form (see the definitions in <a href="https://eprint.iacr.org/2018/691.pdf">[WZC+ 18]</a> or <a href="https://eprint.iacr.org/2021/651.pdf">[CWC+ 21]</a>):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UTa-K0hc3puhJi9TAn5V3g.png" /></figure><p>However, PlonK using a constraint system in the form of:</p><p>PlonK focuses on constant fan-in circuits, and its linear constraints can be reduced to a permutation check, which can be more simply combined than general linear constraints. <a href="https://hackmd.io/@aztec-network/plonk-arithmetiization-air#How-does-all-this-relate-to-R1CS">From AIRs to RAPs — how PLONK-style arithmetization works</a> discusses the advantages and disadvantages of them. In a word, PlonK is more flexible (e.g., it allows constraints of degree larger than two, comparing to R1CS) and allows writing application-specific programs.</p><p>Therefore, it’d be more efficient if constructing from gates in PlonK, instead of transpiling from R1CS.</p><h3>Optimizing PlonK on IOP layer</h3><p>We could also work from the three layers mentioned above to optimize PlonK.</p><p>For example, on the IOP layer, we could use custom gates (in Plonk you could flexibly DIY constraints) to define bit arithmetic operations, including EC point addition, Poseidon hashes, Pedersen hashes, 8-bit XOR, and so on, to save the proving computations.</p><p><a href="https://eprint.iacr.org/2020/315.pdf">Plookup</a> (PlonK with lookup table) is a further optimization. It enables lookup table in PlonK circuits, so that you can precompute a lookup table of the legitimate (input, output) combinations, and prove a witness existing in the table, instead of proving the witness itself. This means we can use lookup tables to help the computations that were SNARK-unfriendly originally. For example, without lookup tables, SNARKs is not friendly to bit operations: because we will have to compute bit-by-bit; but with lookup tables, we can now store the result of an 8-bit operation in a table to lookup and access, avoiding computing bit-by-bit again. (You can think of it as compute 8 bits at a time.)</p><p>Plookup can also be extended to vector lookups and multiple tables, bringing huge benefits to circuit programming models involving dynamic memory (e.g., vectors &amp; dynamic array). A use case is to build zkEVM on top of it, proving the execution and the correctness of the execution.</p><p>AZTEC’s “Turbo-PlonK” is “PlonK + custom gate”, and its “Ultra-PlonK” is “PlonK (+ custom gate) + Plookup”. According to their benchmarks(<a href="https://medium.com/aztec-protocol/plonk-benchmarks-2-5x-faster-than-groth16-on-mimc-9e1009f96dfe">[1]</a>, <a href="https://medium.com/aztec-protocol/plonk-benchmarks-ii-5x-faster-than-groth16-on-pedersen-hashes-ea5285353db0">[2]</a>, <a href="https://medium.com/aztec-protocol/aztecs-zk-zk-rollup-looking-behind-the-cryptocurtain-2b8af1fca619">[3]</a>, <a href="https://www.youtube.com/watch?v=Vdlc1CmRYRY&amp;t=1560s">[4]</a>), they achieve considerable improvements by integrating custom gates and Plookup.</p><h3>Optimization on accumulation layer</h3><p>Another great technique is recursive proof composition: it has such a nice feature that you can recursively aggregate several proofs into a single proof while still keeping it succinct, and you can verify them all in one go.</p><p><a href="https://eprint.iacr.org/2019/1021.pdf">Halo</a> is probably the first notable efficient recursive zkp scheme without requiring a trusted setup, which inspires many future works. <a href="https://eprint.iacr.org/2020/499.pdf">[BCMS20]</a> formalizes&amp;generalizes this technique and calls it “accumulation scheme”.</p><p>PlonK can use custom gate for prime field arithmetic, which means it will be quite convenient and efficient to implement Halo-style recursion in PlonK. This is an optimization technique on accumulation layer.</p><h3>Optimization on polynomial commitment layer</h3><p><a href="https://eprint.iacr.org/2020/081.pdf">SHPLONK</a> is an optimization on polynomial commitment layer, which can work with PlonK to achieve smaller proof size and shorter proving time. Other protocols aiming at optimizing polynomial commitment also exist. (Or alternatively, inspired by FRI, <a href="https://eprint.iacr.org/2019/1400.pdf">REDSHIFT</a> uses List Polynomial Commitment to turn PlonK into a zkSTARK, which increases the proof size but reduces the proving time and removes the need for a trusted setup.)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87797f5942cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ZK-Rollup development experience sharing, Part I]]></title>
            <link>https://medium.com/coinmonks/zk-rollup-development-experience-sharing-part-i-6c233640b541?source=rss-8f18c7bd8194------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c233640b541</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[zkp]]></category>
            <category><![CDATA[zkrollup]]></category>
            <category><![CDATA[zkproof]]></category>
            <category><![CDATA[dex]]></category>
            <dc:creator><![CDATA[Fluid Dex]]></dc:creator>
            <pubDate>Sun, 18 Apr 2021 13:43:16 GMT</pubDate>
            <atom:updated>2021-05-20T03:29:47.697Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Acknowledgement: we would like to thank barryWhiteHat, Jordi Baylina, Koh Wei Jie (in alphabetical order) for their insightful feedbacks.</em></p><p>Prerequisites: basic programming and blockchain knowledge, no cryptography background needed.</p><p>Currently, major expectations on blockchain technology are further scaling, higher performance and lower costs. In this post, we will dive into ZK-Rollup, which is one of the <a href="https://ethereum.org/nl/developers/docs/layer-2-scaling/">Ethereum layer 2 scaling solutions</a>. It exquisitely applies a zero knowledge proof technique (known as ZK-SNARK) to reduce the on-chain costs, and thus, is able to improve Ethereum TPS considerably (~10x-100x). ZK-Rollup is considered as the most important Ethereum Layer 2 scaling solution in the long term by many people, including Vitalik, the founder of Ethereum.</p><blockquote>In general, my own view is that in the short term, optimistic rollups are likely to win out for general-purpose EVM computation and ZK rollups are likely to win out for simple payments, exchange and other application-specific use cases, but in the medium to long term ZK rollups will win out in all use cases as ZK-SNARK technology improves. — Vitalik</blockquote><p>In this series of posts, we will share our experience on developing a ZK-Rollup system. The motivation of these posts is that, currently there are many high quality resources introducing the cryptography behind ZK-SNARK, with a lot of math details. In the meantime, there are also many non-technical blogs looking into the impact and prospect of ZK-Rollup. Very few will dive into questions like, how does ZK-Rollup boost performance exactly? Or, how does a complete ZK-Rollup system look like? Or, is there any important but usually overlooked details in a ZK-Rollup system?</p><p><a href="https://github.com/Fluidex/">Fluidex</a>, as one of the very few teams that are independently developing a ZK-Rollup system from scratch, is happy to share some experience gained from ZK-Rollup system development. We hope this could benefit other developers in the field. We will talk about some important but rarely mentioned topics, like where the performance bottleneck is in a ZK-Rollup system, where does the economic cost lie, etc.</p><h3>Overview of ZK-SNARK &amp; ZK-Rollup</h3><p>Again, we won’t focus on the cryptographic details of ZK-SNARK proof, because as stated, there are enough high quality resources explaining it. In this chapter, we will briefly answer the following questions: What can ZK-SNARK do? Why does it become the core of ZK-Rollup, and help boost Ethereum performance along with “rollup”? What does “rollup” mean exactly?</p><h3>The Nature of ZK-SNARK</h3><p>Generally speaking, in a blockchain ecosystem, each node will execute the same computation for each transaction in the block, then verify that their results are the same as those of other nodes. In other words, for each transaction to be on chain, it will be executed by every node. That’s one major reason why blockchain have relatively low performance.</p><p>However, is “computing again” the only way to verify a transaction? To put it differently: is it necessary that the cost of verifying is as much as the cost of computing?</p><p>The answer is NO. Verifying could be cheaper than computing. Let’s take Sudoku for example. The complexity of solving a Sudoku is quite different from that of verifying a Sudoku solution. To “compute again” is the least efficient verification method. If you happen to have a computer science background, just consider the P vs NP problems in computational complexity theory.</p><p>Therefore, in blockchain, it’s worthwhile to have a technical solution that can lower the verification cost, even by increasing the computation cost. The reason is that, for each transaction, computation will only happen once, while verification will happen on every node. ZK-SNARK by nature is such a technique that significantly lowers the verification cost. Generally, ZK-SNARK can make the verification cost several orders of magnitude less than the computational cost. To be precise, reducing the verification complexity from linear to constant (or logarithmic), that is what “succinctness”, the “S” in “SNARK”, stands for.</p><p>Let’s look at how ZK-SNARK works.</p><p>For a particular program, it will first be preprocessed. After the one-off preprocessing, for each input, a prover will need to compute the result corresponding to the input, as well as generate a “proof” (usually in form of big integers) with relatively larger costs. Any verifier could use this “proof” and input to quickly verify the correctness of the result without actually running the program.</p><p>A more detailed description in pseudo code:</p><pre>// here is the the application code<br>// it is usually called &#39;circuit code&#39;<br>function some_function(inputs):<br>   // no global vars allowed here<br>   outputs = some_calculation(inputs)<br>   return outputs<br></pre><pre>// preprocessing only runs once for every &#39;some_function&#39;<br>// we deliberately ignore &#39;setup&#39; here to make it easier for understanding<br>// for a more precise and detailed description, you can have a look at the references at the end of this article<br>const preprocess_result = zksnark_preprocess(some_function)<br>const verification_key = preprocess_result.verification_key;<br>const proving_key = preprocess_result.proving_key;</pre><pre>// for every &#39;inputs&#39;, generate &#39;proof&#39;. The following codes run off chain<br>// we deliberately ignore &#39;witness&#39; here to make it easier for understanding<br>// we will make more explanation on what consists of inputs/outputs of a realworld ZK-Rollup system in the following sections<br>const outputs = some_function(inputs);<br>// the &#39;prove&#39; will need a lot of computing resource to finish<br>const proof = zksnark_prove(proving_key, input, output);</pre><pre>// verify the input/output is correct<br>// The following codes usually run on chain<br>const is_correct = zksnark_verify(verification_key, input, output, proof);<br>assert(is_correct == true);</pre><h3>Real-world Design of a Rollup System</h3><p>In a normal Rollup system, we will maintain a global merkle tree. All states in the Rollup system (including the balance of each token of the account, nonce of the account, etc.) will become a leaf node on the tree.</p><p>ZK-SNARK will guarantee mathematically that every update to the merkle tree satisfies some “predetermined rules”. Those rules are determined by the ZK-Rollup developers’ settings. For example, for a ZK-Rollup transfer system, the developers could demand that:</p><ol><li>Transfer amount is less than the balance of the sender account;</li><li>The signature of the sender account is valid, and nonce is correct;</li><li>The amount reduced in the sender account equals the amount increased in the receiver account.</li></ol><p>Additionally, the hash of the merkle root will be computed from the new leaf.</p><p>To guarantee security in the worst case (that is, even if the operators of the Rollup system run off, users can still withdraw their assets in one piece), the system should make sure users are able to rebuild the tree from scratch (known as “data availability”), and are able to make assertions like “Alice actually has 3 ETH in this tree” by merkle proof. To achieve this, the system should make the data of each transaction public, and stored on chain.</p><p>For a batch of hundreds or thousands of transactions, after we executed them in a particular order and updated the merkle tree, we will use ZK-SNARK to prove the correctness of the result (i.e., the new root of the merkle tree). Note that the number of transactions here is determined by a predefined config, which is fixed during runtime. This batch of transactions will be proved and verified together, known as a “L2 Block”.</p><p>Again, let’s use pseudo code to demonstrate the data flow in a real-world ZK-Rollup system:</p><pre>// the following code runs as smart contract<br>// &#39;global_merkle_tree_root&#39; is the only state needed to be stored inside smart contract<br>let global_merkle_tree_root = ...;<br>const verification_key = ...;<br>function init() {<br>  // set global_merkle_tree_root and verification_key<br>}</pre><pre>function verify_txs(proof, txs, old_merkle_root, new_merkle_root) {<br>   assert(old_merkle_root == global_merkle_tree_root);<br>   // in fact we will hash of txs/old_merkle_root/new_merkle_root as a single input to &#39;zksnark_verify&#39; for performance. We will not discuss this detail here as it does not block understanding<br>   assert(zksnark_verify(proof, txs, old_merkle_root, new_merkle_root);<br>   global_merkle_tree_root = new_merkle_root;<br>}</pre><p>We can see that apart from the merkle root, the contract won’t store any states. For every state update, it needs the off-chain module to prepare the complete transaction input and proof. For those who are familiar with Stateless Ethereum, ZK-Rollup is actually very similar to Stateless Ethereum in this way.</p><h3>System Architecture of ZK-Rollup</h3><p>One ZK-Rollup system needs at least the following modules:</p><ol><li>Smart Contract on Chain:</li></ol><ul><li>To verify the validity of each merkle tree update, and maintain the correct merkle tree root;</li><li>In a situation where Rollup system is down, to make sure users are able to withdraw their rightful assets by directly calling the contract;</li><li>To coordinate between L1 and L2, ensuring users’ deposits can be processed in time and updated into the merkle tree.</li></ul><ol><li>Prover Cluster: To do immense cryptographic calculations to generate ZK-SNARK proof for each L2 Block. Usually a large-scale cluster is required, which consumes more than 99% of the computing resources in the system.</li><li>State Manager: To maintain the complete merkle tree. For each transaction, it updates the merkle tree and provides necessary data for Prover Cluster (e.g., merkle proof).</li><li>Other Business Modules: like a L2 browser. Besides, each Rollup system has their own specialized business modules. For example, Fluidex has a <a href="https://github.com/Fluidex/dingir-exchange">order matching engine</a>, which generates matched transactions from users’ orders, then sends them to the State Manager.</li></ol><h3>TPS limit of ZK-Rollup</h3><p>What is the main constraint on TPS of a ZK-Rollup system?</p><h3>Speed of proving</h3><p>Proving is the most resource consuming part of a ZK-Rollup system. Those who are new to ZK-Rollup usually mistakenly believe that speed of proving is the main constraint on TPS. Actually, as the proving of each L2 Block can be done completely in parallel, using a prover cluster with size of hundreds is a common practice. Therefore, although ZK-SNARK proofs do take long, it will mostly lead to a longer latency of withdrawing from L2 to L1, as well as a higher server cost for operators, but not a limitation on TPS.</p><h3>Recording data on-chain and ETH GAS limitations</h3><p>Well this is a real constraint on TPS. Let’s look back at the overall ZK-Rollup design. To ensure security/data availability, each layer-2 transaction should be recorded on chain. This part of data will be recorded in ETH transaction history as CALLDATA, with an average cost of 16 gas/byte (EIP-2028: <a href="https://eips.ethereum.org/EIPS/eip-2028">[1]</a>, <a href="https://blog.iden3.io/istanbul-zkrollup-ethereum-throughput-limits-analysis.html">[2]</a>). For a normal transfer/matched order, each transaction is estimated to be 40 bytes (<a href="https://vitalik.ca/general/2021/01/05/rollup.html">[1]</a>, <a href="https://github.com/Loopring/protocols/blob/master/packages/loopring_v3/DESIGN.md#data-availability">[2]</a>).</p><p>Let’s try estimating the TPS limit by gas limitations.</p><p>It takes ~13s for each ETH block to be mined, with maximum gas of 12.5 Million. Suppose a Groth16/Plonk ZK-SNARK verification costs 0.3–0.5 Million gas (<a href="https://github.com/matter-labs/awesome-zero-knowledge-proofs">[1]</a>, <a href="https://medium.com/matter-labs/zksync-v1-1-reddit-edition-recursion-up-to-3-000-tps-subscriptions-and-more-fea668b5b0ff">[2]</a>, <a href="https://blog.kyber.network/research-trade-offs-in-rollup-solutions-a1084d2b444">[3]</a>, <a href="https://zksync.io/">[4]</a>, <a href="https://ethresear.ch/t/on-chain-scaling-to-potentially-500-tx-sec-through-mass-tx-validation/3477">[5]</a>, <a href="https://ethresear.ch/t/roll-up-roll-back-snark-side-chain-17000-tps/3675/12">[6]</a>), then each ETH block could contain at most 12,000,000 / (40*16) ~= 20,000 transactions. So in this way, the TPS limit of ZK-Rollup would be 1500–2000. This is also the performance upper-bound claimed by many Rollup systems in whitepapers.</p><h3>Global state update on Merkle Tree</h3><p>This is a rarely discussed but crucial perspective. The TPS of a real-world ZK-Rollup system is actually more limited by this module, rather than proving speed or gas limitations discussed above.</p><p>To support a large number of users and assets, we need the Merkle Tree to have a certain depth. Assuming we are using a binary dense account_balance merkle tree as follows, and we intend to support 1 Million users and 1000 types of assets, then the depth of the merkle tree is required to be 30. Suppose each transaction will cause 5–10 times of verifications on the merkle proofs, then there’ll be ~200 hash calculations in total.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/0*sr36zzx_-zrvDqiN.png" /></figure><p>For performance considerations, we won’t use normal hash like SHA3 in a ZK-Rollup merkle tree. Instead, we’ll use a more ZK-SNARK compatible one like poseidon or rescue. According to <a href="https://github.com/Fluidex/state_keeper/blob/a80c40015984886b68a295a810c64a682ba13135/src/types/merkle_tree.rs#L326">test results from Fluidex</a>, each poseidon hash takes about 30us (tree depth of each test is 20, thus, each hash would be 57ms / 100 / 20 ~= 30us). So estimating from merkle tree perspective, the limit of a ZK-Rollup system would be 1 / 0.00003 / 200 = 160 TPS.</p><p>Therefore, <a href="https://github.com/Fluidex/state_keeper/blob/a255043cbe7c899c6a8d9cc46b170a40f20623c9/src/types/merkle_tree.rs#L127">parallel updating</a> on the merkle tree is essential to break through the 100–300 TPS level. Unlike computing ZK-SNARK proofs, which could be parallelized completely, to parallelize merkle tree updates requires more discretion, and is very hard to apply distributed computing on it. This is also a technical challenge.</p><p>The 100–300 TPS calculated above is close to many real-world ZK-Rollup system’s actual performance upper-bound.</p><h3>Economic Cost Analysis</h3><h3>ZK-Rollup normally needs thousands of CPU cores for proving</h3><p>Let’s still take <a href="https://github.com/fluidex/awesome-plonk">PLONK</a> <a href="https://github.com/Fluidex/circuits">circuits</a> used by Fluidex as a typical ZK-Rollup case. In our latest test, for each L2 Block with 100 transactions, it takes ~20min to run a proof on a 24 core server. To reach 100 TPS performance, we will need ~300 EC2 c5.12xlarge instances, which costs ~500 USD/h. This means each Layer 2 transaction will cost 0.001 USD in off-chain calculations. Note that we haven’t invested a lot on performance optimization yet, we expect there’ll be a lot to improve here in the future.</p><h3>On-chain gas cost much higher than off-chain server cost</h3><p>The cost of off-chain calculations mentioned above is actually a drop in the bucket compared to the on-chain GAS cost. Assuming each Layer 2 transaction needs 40 bytes of on-chain data, ETH is ~2000 USD, GAS price is 200 Gwei, then the cost of each transaction on-chain is ~2.6USD. This is much higher than the 0.001 USD off-chain. However, this is also much lower than a complex Layer 1 transaction, where GAS cost is usually at least tens of USD. That’s why we often say ZK-Rollup could bring at least two orders of magnitude cost saving.</p><h3>Low cost-efficiency Cloud GPU services</h3><p>Many developers might wonder what GPU could bring to computing power. In ZK-SNARK proving, GPUs could accelerate computing by ~3x-5x. But on the other hand, due to immaturity of virtualization, GPU from cloud services are disproportionately expensive compared to the cost of CPU. Such that there are even cases where <a href="https://minimaxir.com/2017/07/cpu-or-gpu/">CPU is cheaper than GPU</a> in deep learning model training. Therefore, if you are not building your own data center but using cloud services, using GPU for ZK proofs would be a low marginal utility choice.</p><p>Of course, all the above analysis data will be affected by system efficiency and ETH GAS price, but unlikely to deviate in orders of magnitude in a foreseeable future.</p><h3>Miscellaneous development experience</h3><h4>Why are ZK-SNARK logic descriptions called “circuits”?</h4><p>For anyone with software engineer experience, in the following code, only one of the if- branch and else- branch will be executed, rather than both executed and only one chosen.</p><pre>function binaryOp(op, arg1, arg2) {<br>  if (op == &quot;add&quot;) {<br>    return arg1 + arg2;<br>  } else {<br>    // assert(op == &#39;mul&#39;);<br>    return arg1 * arg2;<br>  }<br>}</pre><p>Such concept that “only one conditional branch will be executed” seems natural for software development, but it’s not the case for the design of hardware chip circuits. In development of sequential logic circuits in hardware, logics of all “branches” (if still called “branch”) will be executed at the time the sequence is triggered. The developer needs to choose and maintain correct global states from different “branches”.</p><p>In a ZKP system, program logic will eventually be converted into some immense polynomials (probably with hundreds of millions of terms), which is called arithmetization, such that proving of the program will be converted to proving of the polynomials. The polynomials are then constrained in the form of gate circuit. That’s also one of the reason why we call ZKP programs as circuits. Thus, the code has the same property as hardware circuits: code from all branches will be executed together. That’s why ZK proof code is called “circuits”. In addition, similar to hardware circuits, there are no recursion and complex loops in the ZK proof circuits, and the number of loops can only be constant (actually, loops will be unrolled as syntactic sugars, i.e., loop unrolling).</p><p>Therefore, when developing ZK proof circuits, developers need to reconsider their habits from software development. For example, when optimizing softwares, we could focus on the most frequently executed branch, and deprioritize the non-frequent ones. But in ZK proof circuits, as all branches will be executed, the non-frequent branches need to be considered as well.</p><h3>Opinions on DSL</h3><p>There are several choices for ZK proof circuit development, such as low-level computing libraries like <a href="https://github.com/HarryR/ethsnarks">ethsnarks</a> / <a href="https://github.com/zkcrypto/bellman">bellman</a>, or DSL like <a href="https://github.com/Zokrates/ZoKrates">ZoKrates</a> / <a href="https://github.com/iden3/circom">Circom</a> / <a href="https://github.com/matter-labs/zinc">Zinc</a>.</p><p>We chose Circom, which provides a just right level of abstraction. On the one hand, it improves the efficiency of reading/writing code, on the other hand, it doesn’t distort the details of the underlying circuits.</p><p>In comparison, developing with ethsnarks and bellman is of lower efficiency. Also, when the code is being reviewed, no matter internally or externally, too much “syntactic noise” prevents the reviewer from focusing on the core logic. Additionally, ZoKrates and Zinc provide a too high level of abstraction. For example, python-style control flow syntax in ZoKrates conceals the underlying circuits, and is not conducive to lower level optimizations (such as inline assembly of C/Rust).</p><p>As an analogy, ethsnarks / bellman is like assembly language in traditional development, while cirom is like C, and ZoKrates is like Python. However, ZoKrates toolchain is not as mature as Python interpreter. That’s why we’d rather use “C” (cirom in this case) as the our development language, instead of maintaining both “Python” (ZoKrates in this case) code and “CPython interpreter” (ZoKrates interpreter in this case) code.</p><p>However, Circom is essentially still a R1CS DSL. Fluidex actually uses PLONK proof system. We probably would make major changes on Circom to better utilize PLONK, including supports for custom gate, plookup, aggregation &amp; recursion, etc.</p><h3>It’s not easy to handle deposit / withdrawal</h3><p>It’s not easy to handle deposit / withdrawal correctly at all: for example, we need to consider block reverting, operations with different priorities, contract migrations, and so on.</p><p>And we should always deal with deposit &amp; withdrawal carefully, because it affects users’ assets on Ethereum layer 1 for real.</p><p>The following is a non-exhaustive list of things we need to take into consideration:</p><ul><li>If a committed L2 block is not verified in time, state should be reverted.</li><li>If the rollup fails to commit L2 blocks or submit proofs in time, or a priority operation is not processed for a long time, the rollup needs to be suspended and we should provide a way for user to withdraw funds.</li><li>Loopring also describes an interesting <a href="https://github.com/Loopring/protocols/blob/master/packages/loopring_v3/DESIGN.md#withdrawal-fee-griefing">Withdrawal Fee Griefing Attack</a>, and an solution to it.</li></ul><p>Hermez uses <em>WithdrawalDelayer</em> to manage withdrawals, to leave time for handling unexpected situations.</p><h3>Further Readings</h3><h3>Techinical Blogs</h3><ul><li><a href="https://vitalik.ca/general/2021/01/05/rollup.html">vitalik blog on rollup</a></li><li><a href="https://vitalik.ca/general/2021/01/26/snarks.html">vitalik blog on ZK-SNARK</a></li><li><a href="https://docs.ethhub.io/ethereum-roadmap/ethereum-2.0/stateless-clients/">Stateless Ethereum</a></li></ul><h3>Projects</h3><p>ZK-Rollup projects launched:</p><ul><li><a href="https://github.com/matter-labs/zksync">zksync</a>: the most complete open source code of ZK-Rollup, containing all modules for a ZK-Rollup system. It uses PLONK protocol, bellman for circuits, and Rust for off-chain code.</li><li><a href="https://github.com/hermeznetwork/">hermez</a>: similar to zksync. It uses Groth16 protocol, Circom for circuits, and Go for off-chain code.</li><li><a href="https://github.com/Loopring/protocols/tree/master/packages/loopring_v3">loopring</a>: only has circuit code and contract in open source. It uses Groth16 protocol, ethsnark for circuits. Off-chain code is not open sourced yet.</li></ul><p>ZK-Rollup projects under developing:</p><ul><li><a href="https://github.com/Fluidex">fluidex</a>: circuits, state manager, and matching engine in open sourced. It uses PLONK protocol, circom for circuits, and Rust for off-chain code.</li></ul><p>Non ZK-Rollup projects that use ZK-SNARK:</p><ul><li><a href="https://github.com/appliedzkp/maci/">MACI</a></li><li><a href="https://github.com/tornadocash">Tornado Cash</a></li></ul><h3>About Us</h3><p>We are the development team of <a href="https://www.fluidex.io/posts/2020-11-30-fluidex-a-zkrollup-layer2-dex/">Fluidex: A Layer 2 ZK-Rollup DEX on Ethereum</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c233640b541" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/zk-rollup-development-experience-sharing-part-i-6c233640b541">ZK-Rollup development experience sharing, Part I</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Announcing FluiDex: Building the first PLONK layer2 DEX on Ethereum]]></title>
            <link>https://fluid-dex.medium.com/announcing-fluidex-building-the-first-plonk-layer2-dex-on-ethereum-e19136304a5d?source=rss-8f18c7bd8194------2</link>
            <guid isPermaLink="false">https://medium.com/p/e19136304a5d</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[decentralized-exchange]]></category>
            <category><![CDATA[zksnark]]></category>
            <dc:creator><![CDATA[Fluid Dex]]></dc:creator>
            <pubDate>Sun, 13 Dec 2020 08:37:39 GMT</pubDate>
            <atom:updated>2021-06-13T11:09:59.788Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*FdWZ5GYnCZ6Xy8oB27ifog.png" /></figure><h3>Dex trading, but serious</h3><p>CEXs have been criticized a lot for their custody scheme. Recently, a top CEX in China ran into issues and users were not able to withdraw their funds for a month.</p><p>We believe in “Not your keys, not your coin”, and therefore want to build a better DEX for crypto trading.</p><p>Uniswap offers simple-to-use trading experience. We like the <strong>KISS</strong> (Keep it simple, stupid) principle behind it. However, we believe that there still lies a more promising market in terms of serious trading. With limit/market/stoploss/FOK/IOC/AON order supports, professional traders, who are likely to manage funds of larger scale, can build their more dazzling portfolios.</p><h3>Why, why, why…?</h3><h3>Why Ethereum</h3><p>Ethereum is still the most popular public chain where tokens are traded on. People have tried building DEXs / Swaps / liquidity farmings on other platforms but none of them retain a DAU like Ethereum’s. This gives us the reason and confidence to focus on Ethereum. Cross-chain projects like Ren and Keep can take care of interoperability with assets on other chains for us.</p><h3>Why layer 2</h3><p>There have been DEXs built on Ethereum like EtherDelta. However they suffer from the low TPS due to Ethereum layer 1. Users will suffer from more loss when there are wild price fluctuations, if they cannot react in time. Layer 2 solutions also help save gas fees.</p><h3>Why zkRollup</h3><p><a href="https://idex.io/">IDEX</a> targets at building a high-performance DEX using rollup as their layer 2 solution as well, but makes use of optimistic rollup.</p><p>Both optimistic rollup and zk rollup compress transactions on layer 2 and thus improve TPS. Rollups also manage to avoid data availability issues in Plasma.</p><p>Unlike using validity proof in zk rollup, optimistic rollup makes use of fraud proof and requires 1~2 week challenge period. This is unlikely to be acceptable for users when withdrawing funds.</p><h3>Why PLONK</h3><p><a href="https://loopring.org/">Loopring</a> shares a similar choice on zkRollup but chooses <a href="https://eprint.iacr.org/2016/260">Groth16</a> as their proof system.</p><p>In 2019, Vitalik Buterin wrote <a href="https://vitalik.ca/general/2019/09/22/plonk.html">an article explaining PLONK</a>. <a href="https://eprint.iacr.org/2019/953">PLONK</a> is a recent developed proof system supporting universal and updateable set up. To date, PLONK is also the most performant proof system supporting this scheme.</p><p>Supporting updateable set up means that, the set up is semi-trustless: it can be considered trustless as long as at least one participant is honest. Being universal means that the set up SRS (structured reference string) can be reused for different circuits: this again further mitigate the risks introduced by multiple set-ups.</p><p>And nowadays, with optimizations, PLONK can achieve the same performance as Groth16 in some scenarios. More and more projects are actively looking into using PLONK as their proof system, including AZTEC, zkSync and Dusk.</p><p><a href="https://www.deversifi.com/">DiversiFi</a> shares a similar goal to serve serious traders but chooses zkSTARKs instead of zkSNARKs. The “T“ (“transparency“) in STARK means completely trustless set up. However, removing the need for SRS introduces significantly larger proof size.</p><h3>Roadmap, and more coming…</h3><p>We are thrilled to release a toolkit called <a href="https://github.com/Fluidex/plonkit">plonkit</a> to work with <a href="https://github.com/iden3/circom">circom</a> DSL using PLONK. We plan to release a MVP to demo in the next a few months.</p><p>We keep in our mind that we want to build a professional and secure trading platform, and our future features include:</p><ul><li><a href="https://ethresear.ch/t/mass-migration-to-prevent-user-lockin-in-rollup/7701">massive migrations</a> to aggregate orders arross DEXs and hence offer better liquidity;</li><li>delegated orders for quant use; and</li><li>derivatives…</li></ul><p>Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e19136304a5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>