**Motivation:**
In the rapidly evolving landscape of blockchain technology, addressing the constraints of traditional light clients is crucial for the widespread adoption and efficient operation of the Ethereum network. Historically, light clients have strained full nodes by incrementally requesting block state, posing challenges to network scalability. While the integration of Verkle trees has marked a significant advancement, allowing smoother transitions for lightweight clients between blocks, ensuring accurate state root confirmation remains a lingering concern. The incapacity of light clients to handle zero-knowledge proofs further complicates matters. Overcoming these challenges is pivotal to empowering light clients and optimizing the Ethereum network for a seamless and inclusive decentralized future.
**Project Description:**
Our approach involves leveraging the zkevm circuit to create a witness generator for the Merkle Patricia Trie circuit within zkevm-circuits.
- Built upon geth, the system transforms eth_getProof output into the MPT circuit witness, verifying trie state modifications.
- The MPT circuit ensures the correctness of trie state modifications.
- The zk circuit subscribes to chain events, generating a witness and corresponding zkp for each new block. We've enhanced this proof-of-concept to send the zkp to portal light clients, enabling verification. Additionally, for each produced block on the chain, a witness is generated.
- The zkp of the witness guarantees the equality of the state we sent the zkp for with the stateroot of the block.
- Subsequently, zkps of the last state from a randomly generated zk-circuit block are sent to Trin light clients via the API endpoint.
We've implemented a script for Zero Knowledge Proof (ZKP) Integration with Trin API:
- This allows sending a pre-generated zkp of the witness to the Trin API endpoint.
- We've defined a new RPC method to store content on the remote node, calling the portal_historyStore endpoint with the pre-generated ZKP, using `match client.store_with_proof`.
Our code showcases the integration of a pre-generated Zero Knowledge Proof (ZKP) with the Trin API. It incorporates enhanced error handling, API endpoint configurability, and meaningful messages for improved reporting.
**Configuration Steps:**
4. Replace the API Endpoint: Open main.rs and replace the api_endpoint variable with the actual URL of your Ethereum node’s JSON-RPC API.
```rust
let api_endpoint = "http://localhost:8545"; // Trin API endpoint
```
5. Run the Code: Execute `cargo run`.
6. Verify Output: Upon success, messages indicating the connection to the Ethereum node and the status of ZKP storage and retrieval will be displayed. In case of errors, detailed error messages for troubleshooting will be shown.
**Configuration:**
- Adjust the api_endpoint variable in main.rs with the URL of your Ethereum node’s JSON-RPC API.
**Error Handling:**
- The code includes error handling for serialization, API connection, and ZKP storage errors. Detailed error messages are printed to the console for easier debugging.
**Notes:**
- The code assumes a pre-generated ZKP. Replace the pre_generated_zkp variable with your actual ZKP.
- Ensure Trin API version and dependencies are compatible with the specified versions in the Cargo.toml file.
Next, we aim to propagate the received zkps to all Trin peers, allowing light clients to verify the state. Our implementation utilizes the `async-std`, `discv5`, and `tokio` libraries to create a distributed discovery network with zero-knowledge proof (ZKP) messages.
The implementation involves defining a `ZeroKnowledgeProof` structure and a `MessageType` enum to represent different message types. Asynchronous functions, such as `handle_discv5_events` and `handle_zkp_messages`, process Discv5 events and ZKP messages, respectively. The `send_findnode_request` function sends FINDNODE requests with optional ZKP messages to specified nodes asynchronously.
In the `main` function, a Discv5 node is created, and tasks are spawned to handle Discv5 events, ZKP messages, and periodic ZKP message sending. The program simulates FINDNODE requests to two nodes with appended ZKP messages asynchronously. A Tokio interval is used to periodically send ZKP messages to the network. The main function waits for the completion of all tasks using `task::try_join!`.
Note: Ensure the required dependencies are present in your Cargo.toml file, and the code is expected to be run in an async runtime environment.
Finally, we've implemented a ZKP verifier for Trin, enabling each node to verify the state in a stateless manner by ensuring the proof of the last state sent is equal to the state root of the block. To enhance trustlessness and decentralization, Trin can validate the current state via Helios nodes, ensuring the correctness of the state transition.