Brevis 백서

Brevis

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 5쪽 중 3쪽

ree (referred to as appHash in Tendermint terms), which can then be used to verify transactions using the Merkle proof verification spec standard- ized by ICS-23 [13]. A particularly useful application of ICS-23 is verifying Cosmos IBC transactions in a trust-minimized manner. We will follow up with an example of the BNB chain. 4.3.3. BNB Chain T endermint and PoA Light Client for BNB Chain. The BNB chain adopts a two-layer architecture, comprising the base layer, referred to as the BNB Beacon Chain (BBC), and the execution layer, called the BNB Smart Chain (BSC). The BBC utilizes Tendermint consensus, while the BSC employs a Proof-of-Authority (PoA) consensus called Parlia, which is largely based on Clique [5]. Parlia features a set of authorized validators that produce BSC blocks in a round-robin fashion. Each BSC block is signed off by one of the validators in the set. As a specialized Tendermint application, the BBC manages the election and updates of the BSC validator set. Every 24 hours, a new set of BSC validators is elected and synchronized to the BSC via an IBC-like cross-chain mechanism that predates the official IBC specification. The BSC then verifies the validator set update via its own Tendermint light client, which is a system-level precompile contract implemented in Go, rendering gas costs inconsequential. To verify a transaction on BSC on another EVM-based chain, one must implement an on-chain Proof-of-Authority light client. Since each PoA header is signed via a single secp256k1 key for which the EVM has a precompile, verifying a PoA header is not gas- 19 intensive. However, as PoA is not Byzantine fault-tolerant on its own, we took an extra step to verify the validity of the PoA validator set using our Tendermint light client, assisted by zk-based Ed25519 verification. The BBC Tendermint header containing the “BSC validator set update” IBC package is synchronized to the Tendermint light client contract and verified, with the updated BSC validator set stored on-chain in the PoA light client. Subsequently, each BSC block header can be verified trivially by checking that it was signed by one of the validators. 5. Brevis zkQueryNet Brevis zkQueryNet offers a comprehensive network of Zero-Knowledge Query Engines (ZQEs) that can be directly integrated into smart contracts. For application develop- ers, zkQueryNet provides a standardized and user-friendly Agent Smart Contract API and an actor-based design pattern, enabling them to build decentralized applications (dApps) that rely on arbitrary data query computation results from any combina- tion of blockchains. For ZQE providers, zkQueryNet offers a unified Keeper service and interfaces for their Provers and Query Services to be seamlessly integrated into Brevis. ZK Query Net ZK Query Engine ZK Query Engine ZK Query Engine Query Service Query Prover zkAggregator Rollup Application’s Blockchain 6 2 3 3 5 KeeperAgent Smart ContractAPP Storage Root 1 7 48 Figure 4. A Walk Through of zkQueryNet As illustrated in Figure 4, we provide a step-by-step walkthrough of how a smart contract interacts with zkQueryNet: (1) When a smart contract needs to obtain certain data, it issues a query by calling a zkQueryNet’s Agent smart contract using a standard interface. (2) This query is picked up by zkQueryNet Keeper, which routes the query to the corresponding ZQE. (3) Upon receiving the query, the ZQE’s Query Service parses the query and gen- 20 erates the data computation results. Next, the ZQE’s Query Prover generates a proof based on the query input, relevant block headers, and results. (4) The Query Prover then posts the query results, along with proofs, to zkAg- gregatorRollup by calling the InsertQueryResults interface. Once verified, the query and the results are stored in zkAggregatorRollup. The details about the InsertQueryResults interface will be specified in Section 6. (5) After the zkAggregatorRollup’s block containing the verified query is committed to the application’s local blockchain, the Keeper calls the FetchAttestedData interface to zkAggregatorRollup and obtains an inclusion proof for the query result, which can be verified by the Agent Smart Contract. (6) The Agent Smart Contract then calls the handler function of the application to deliver the query results. (7) The application smart contract executes the corresponding business logic based on the returned data. 5.1. Agent Smart Contract and Application Design Pattern A shared Agent Smart Contract is deployed on each blockchain to act as an interface between the applications’ smart contracts and other components of the zkQueryNet system. The Agent Smart Contract is shared among all ZQEs and provides the fol- lowing interfaces: uint256 query ( uint256 engine_id , uint256 deadline , bool cache_result , bytes [] q u e r y _ i n p u t ) ; bool d e l i v e r R e s u l t ( uint256 query_id , bytes [] query_result , bytes [] proof ) ; bool r e g i s t e r E n g i n e ( uint256 en gi ne _i d ) ; bool r e m o v e E n g i n e ( uint256 en gi ne _i d ) ; The query function serves as the entry point of Brevis. Any smart contract that wants to utilize the data query and computation capabilities of Brevis must first call query. In the function call, a smart contract must specify the ZQE it intends to use via 21 engine id. Additionally, a deadline must be specified to inform other components of zkQueryNet about the optimal scheduling and to prevent stale data from being used. If the query result needs to be reused by other smart contracts on the same chain, cache result should be set as true. Finally, query input is the serialized Query API call based on the chosen ZQE. This function will first emit an event containing all the aforementioned parameters. As a query often involves data access, computation, and ZK proof generation pro- cesses from the ZQE, it is unreasonable to expect the query function to return results immediately. Instead, the function returns a unique query id deterministically gen- erated based on the query function’s calldata. Consequently, application developers must employ an asynchronous design pattern when interacting with the Agent Smart Contract, recording the query id and any metadata in the application smart contracts. On the application side, a handler function with the following signature is required to handle the returned query results later: bool h a n d l e Q u e r y R e s u l t ( uint256 query_id , byte [] q u e r y _ r e s u l t ) When the query result is zk-verified and stored in zkAggregatorRollup, and the corresponding rollup block is committed to the application’s blockchain, the Keeper will call the FetchAttestedData interface to zkAggregatorRollup using query id and obtain the query result as well as its proof, which can attest to the inclusion of the query result in the committed rollup Verkle tree. The Keeper will then call the deliverResult function, which first checks if the deadline has passed. If not, the function further validates the inclusion of the query result using the proof. After the validation is completed within deliverResult, handleQueryResult is called with the query id and query result. This handler function is expected to be part of the asynchronous query flow, matching the result with the pending query and executing the corresponding business logic. With the Agent Smart Contract concealing all the common “logistics”, developers are provided with a clean and user-friendly interface to integrate their dApps with Brevis. It should be noted that the current version of the Brevis whitepaper does not cover economics and incentive mechanisms. Once a complete economics mechanism is in place, we expect the Agent Smart Contract’s interface to be expanded with the functionality to commit to pricing and deadlines, along with a staking and slashing 22 mechanism for addressing missed Service Level Agreements. We will cover the eco- nomic incentive mechanisms in a different paper. 5.2. ZK Query Engine Network The ZK Query Engine Network forms the core of the zkQueryNet system, where queries are transformed into zk-attested results. Anticipating a diverse range of future use cases for Brevis, we have designed the ZK Query Engine Network as an open marketplace, allowing any ZK Query Engine to be easily integrated. A ZK Query Engine in Brevis comprises two parts: Query Service and Query Prover. Query Service is responsible for defining Query APIs and generating the query results. In terms of query results generation, it operates similarly to off-chain data analytic platforms, where data is gathered via off-chain blockchain RPCs or from other data platforms. Query APIs are the distinguishing factors for different ZQEs at the application usage level. The design of Query APIs spans a wide spectrum, ranging from highly specific to highly generalized. Below, we provide some illustrative examples: • Highly specific: uint256 get retention uniswap(uint256 start, uint256 end) retrieves the 7-day retention of active users on Uniswap for a cohort be- tween block number start and end. • More general: uint256 get active traders by filter(string dex name, uint256 start, uint256 end, byte[] filter) returns the Verkle root of all users from the DEX with dex name, between block number start and end, matching a specific filter with simple syntax. It is also possible to present a more generalized indexing abstraction akin to relational databases or graph databases and use standard query languages such as SQL or GraphQL or some Domain Specific Languages (DSLs) and light-weight VM to process and compute on the requested data. • Highly generalized: Pushing to the other end of the spectrum, it is possible to use a fully general zk-enabled virtual machine as the processing layer. Developers can build with highest level of flexibility at the tradeoff for significant performance overhead. Although highly generalized Query APIs are possible, we envision that most pro- 23 duction APIs will lean toward the more specific end of the spectrum using DSLs and specific APIs. This is because there is a trade-off between the level of generaliza- tion and the performance of Query Provers. Consequently, high-frequency use cases will naturally favor highly specific designs to reduce access costs. Nevertheless, some generic solutions will be available for less-frequent use cases or those requiring a high degree of flexibility. For each ZQE, an on-chain serializer smart contract should be available to generate the serialized Query API call for the query function in the Agent Smart Contract. Once the Query Service generates a result for the query, the Query Prover cre- ates a ZK proof attesting that the API call parameters, combined with all relevant block headers already attested by zkFabric, indeed produce the query result. This is where the majority of the work occurs. Different ZQEs will implement their own query stack in a ZK-verifiable manner, utilizing low-level circuit frameworks like Circom [4], Halo2 [12], or gnark [6], or high-level VM/compiler frameworks such as RISC0 [20], zkW ASM [31], and zkLL VM [29]. Following proof generation, the Query Prover will submit query and query result along with the proof to zkAggregatorRollup by calling the InsertQueryResults in- terface (refer to Section 6 for details about this interface). Upon successful verification, query and query result will be stored in zkAggregatorRollup’s query result store. At this stage, the zk-attested query result is integrated into the on-chain world. Please refer to Section 6 for details on how applications can access these query results from zkAggregatorRollup’s state roots. 5.3. Keeper Network The Keeper Network is a trust-free component in zkQueryNet that connects ZQEs to the rest of the system. First, it is utilized to relay query events emitted from the Agent Smart Contract to the Query Service and Query Prover. Once the query result is verified and stored in zkAggregatorRollup, it retrieves the query results and their inclusion proof from the rollup and delivers them back to the application through the Agent Smart Contract. It is crucial to emphasize that the Keeper and other off-chain components in zkQueryNet do not introduce any trust assumptions into Brevis . This is because they are either used to generate ZK proofs that are verifiable on a chain 24 or simply act as message relayers that cannot alter the content of the message. A query made by a dApp solely relies on the security of the blockchains that the query referred to. With the Keeper Network being permissionless and trust-free, it is possible to implement customized Keepers to obtain query results directly and implement customized callbacks to smart contracts. 6. Brevis zkAggregatorRollup On top of zkFabric and zkQueryNet, we introduce zkAggregatorRollup, an aggregation layer that verifies and stores the block headers from zkFabric and the query results from zkQueryNet. In other words, it serves as a “rollup” of information from zkFabric and zkQueryNet, and commits (compressed) information to different blockchains that Brevis connects to. Additionally, it acts as a store for attested block headers and query results. We denote Brevis supported and connected blockchains collectively as Base Chains in this white paper. More specifically, zkAggregatorRollup fulfills the following functionalities: (1) Verify the validity of the block headers generated from zkFabric and the query results generated from zkQueryNet by checking their validity proofs. (2) Store the verified block headers and query results in a data structure, which can be later retrieved and verified from any Base Chain the rollup is connected to. (3) Commit the rollup state root to Base Chains and prove the validity of the root update by generating aggregate proofs for computations performed in steps 1 and 2. Although it is possible to achieve the above functionalities by making zkAggrega- torRollup a Turing-complete virtual machine, we opt to implement the rollup as a lightweight state machine that (1) maintains a storage/state commitment data struc- ture, and (2) recursively verifies ZKP from zkFabric and zkQueryNet. Moreover, it is worth discussing the necessity of introducing this aggregation layer (instead of verifying, committing, and storing the block headers and the query results directly on each connected blockchain). The primary benefit offered by zkAggrega- torRollup is the significant reduction in on-chain verification costs, in the following aspects: 25 • Without this aggregation layer, each chain would need to store the block headers for every other chain, resulting in O(N 2) “connections” for N blockchains. By introducing zkAggregatorRollup, each blockchain only needs to store the state root for the rollup, reducing the overall connections to O(N ). • The zkAggregatorRollup aggregates multiple proofs for block headers/query re- sults and submits a single proof for verification on each connected blockchain. Consequently, the on-chain verification costs for block headers and query results are efficiently amortized. In the remainder of this section, we present the system design for zkAggregator- Rollup and outline several challenges encountered while constructing the rollup. 6.1. System Overview 6.1.1. System Components The current architecture of zkAggregatorRollup comprises four system components (see Figure 5): • Rollup Sequencer receives block headers from zkFabric and query results from zkQueryNet, verifies their validity, inserts block headers and query results into storage, and commits them to each Base Chain. • Rollup Prover Network generates validity proofs to demonstrate that the block headers and query results are verified and that the rollup storage is accu- rately updated. • Base Chain Rollup Contract , deployed on all Base Chains, verifies the va- lidity proofs of each rollup block, and stores the corresponding state roots. • Data Availability Layer provides data availability for zkAggregatorRollup. The DA layer can leverage existing solutions such as Celestia and Eigenlayer. It is important to note that Brevis zkAggregatorRollup differs from traditional L2 rollup chains in that zkAggregatorRollup commits to multiple Base Chains, making it an “omnichain” rollup. The reason that zkAggregatorRollup can perform this multi- blockchain commitment is that, unlike commonly referred L2 rollups, zkAggregator- Rollup does not involve BaseChain → Rollup deposits nor Rollup → BaseChain withdrawals and is a “rollup-transaction-only” rollup, where the “rollup transactions” 26 zkFabric generate single-block proof insert_block_headers commit state roots and prove insert_query_results fetch_attested_data return data and inclusion proof dispatch proof aggregation job generate multi-block aggregate proof Rollup Sequencer Block header store Query results store zk verifier Ethereum rollup contract BNB Chain rollup contract Aptos rollup contract ......DA layer Verkle tree update block header validity proofs query results validity proofs zkAggregateRollup Prover Network ...... Prover 2 Prover 1 Verkle Tree Circuit Aggregation Circuit Recursive Proo f Verification Circuit zkQueryNet Figure 5. Brevis zkAggregatorRollup Architecture are state tree updates and recursive proof verification for block headers and query results. 6.1.2. Data Store As mentioned above, zkAggregatorRollup maintains data stores for attested block headers (called “ block header store ”) and query results (called “ query result store”). In our case, the data is immutable after being attested and inserted, so each data store is an append-only key-value store with a state commitment scheme that allows for efficient data inclusion proof in Base Chain smart contracts. Additionally, it is often the case that a batch of block headers (or query results) needs to be inserted, fetched, or verified, so the data store should also support efficient batch insertions, range queries, and inclusion proofs for a batch of data. Finally, key-value insertion and state update in the data store should be zk-friendly so that they can be proved in a ZK circuit. While there are many choices for the data store (e.g., Merkle Patricia Tree [14], Sparse Merkle Tree [38], IA VL+[8]), we use the Verkle Tree[27] to store attested block headers and query results. The Verkle tree combines polynomial commitment with the Merkle tree, making wider branching factors more efficient and reducing tree depth. As a result, it significantly reduces the data inclusion proof size, especially when the 27 tree contains a large number of elements. Moreover, the Verkle tree also supports efficient inclusion proof for a batch of data: by employing random linear combinations of polynomials, a batch of data inclusion can be proved with a single polynomial opening proof. In zkAggregatorRollup, there are two Verkle trees: Tb for storage of block headers and Tq for storage of query results. For the block header Verkle tree Tb, the key is the “(chain ID, block number)” pair, enabling efficient range queries (e.g., retrieve headers of block 1234 to block 1256 of chain ID 1) using the prefix. For the query results Verkle tree Tq, the key is the query ID. Data Availability .Various ways can be used to provide data availability. For exam- ple, we can use any existing DA layer solutions (e.g., Celestia, Eigenlayer) or run a full node for zkAggregatorRollup to access the data. There is no trust assumption about the data availability provider since data validity will be verified via inclusion proof on Base Chains. For brevity, this paper does not delve into the detailed data structure of Verkle trees nor discuss the data serialization scheme. 6.1.3. Interfaces with Other Modules zkAggregatorRollup interacts with zkFabric and zkQueryNet in the following ways: • InsertBlockHeaders (zkF abric→ zkAggregatorRollup): zkFabric may in- voke this interface to submit a batch of block headers along with th
프로젝트로 돌아가기