SECBIT’s Analysis of ZKP Circuits

Loopring 3.0's circuit code is hard to digest for those without hands-on experience with ZKP or libsnark. Therefore we’d like to share some diagrams drawn by SECBIT and hope they will be helpful for teams who plan to use libsnark to compose circuits.

Deposit Circuit

All deposit requests are on-chain. The same circuit is also used to create new DEX accounts, reset trading keys, and cancel existing orders.

On-chain Withdrawal Circuit

This circuit enables users to request withdrawals on-chain with an Ethereum transaction. Such withdrawal requests will be processed by the relayer within a limited time window enforced by the protocol. The downside of on-chain withdrawal is that users pay both withdrawal handling fee as well as Ethereum transaction gas.

Off-chain Withdrawal Circuit

This circuit enables users to request withdrawals without any Ethereum transactions. Relayer is recommended but not required to support off-chain withdrawal requests.

Trade Settlement Circuit

This circuit contains the core trading logic and had been optimized to minimize calldata size.

Order Cancellation Circuit

Users can use off-chain cancellation requests to ensure orders are canceled by the relayer. However, in most cases, setting order TTL (time-to-live) is a much better approach to obsolete orders (and can be used together with Order Aliasing to safely extend the lifetime of the order when necessary).