-
Notifications
You must be signed in to change notification settings - Fork 637
feat(tools): add EthProofValidator #10026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ManuelArto
wants to merge
17
commits into
NethermindEth:master
Choose a base branch
from
ManuelArto:feature/eth-proof-validator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,199
−0
Open
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
02cedcf
feat(tools/EthProofValidator): implement Ethereum block proof validat…
ManuelArto ffd4dda
fix(tools/EthProofValidator): add panic handling in verifiers and rem…
ManuelArto f46edb7
feat(tools/EthProofValidator): enhance block validation and proof pro…
ManuelArto 7821481
refactor(tools/EthProofValidator): reorganize project structure and u…
ManuelArto 5b39505
refactor(tools/EthProofValidator): update namespaces
ManuelArto 496d4eb
refactor(tools/EthProofValidator): used LibraryImport over DllImport
ManuelArto 79b10f9
fix(tools/EthProofValidator): use pattern matching for null checks
ManuelArto e298613
refactor(tools/EthProofValidator): remove unused Dockerfile and .dock…
ManuelArto fb86b9c
feat(tools/EthProofValidator): add Airbender verifier
ManuelArto 0bd6db6
fix(tools/EthProofValidator): correct vkBinary validation logic in Re…
ManuelArto c68d999
fix(tools/EthProofValidator): implement fallback verification for zis…
ManuelArto ea40923
Add to build workflow
rubo 3e1eb8d
feat(tools/EthProofValidator): replace binary file dependencies with …
ManuelArto 9d144a0
fix(tools/EthProofValidator): change vk_ptr type from IntPtr to nint …
ManuelArto f942a2a
feat(tools/EthProofValidator): implement `System.CommandLine` for arg…
ManuelArto e6568d8
fix(tools/EthProofValidator): update BuildRustDependency to trigger o…
ManuelArto ae22cc6
Merge remote-tracking branch 'upstream/master' into feature/eth-proof…
ManuelArto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Ignore build and output directories | ||
| bin/ | ||
| obj/ | ||
| out/ | ||
| build/ | ||
|
|
||
| # Ignore IDE-specific files and directories | ||
| .vscode/ | ||
| .vs/ | ||
| .idea/ | ||
| *.suo | ||
| *.user | ||
| *.userosscache | ||
| *.sln.docstates | ||
|
|
||
| # Ignore source control specific files | ||
| .git/ | ||
|
|
||
| # Ignore Rust build artifacts | ||
| native-zk-verifier/target/ | ||
|
|
||
| # Ignore test directories and files | ||
| test/ | ||
|
|
||
| # Ignore temporary files | ||
| *.tmp | ||
| *.log | ||
| *.bak | ||
| *.swp | ||
| *.*~ | ||
|
|
||
| # Ignore package manager files (if any) | ||
| packages/ | ||
| *.nupkg | ||
|
|
||
| # Ignore macOS specific files | ||
| .DS_Store | ||
|
|
||
| # Ignore Linux specific files | ||
| *.pyc | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| *.swp | ||
| *.*~ | ||
| project.lock.json | ||
| .DS_Store | ||
| *.pyc | ||
| nupkg/ | ||
|
|
||
| # Visual Studio Code | ||
| .vscode/* | ||
| !.vscode/settings.json | ||
|
|
||
| # Rider | ||
| .idea/ | ||
|
|
||
| # Visual Studio | ||
| .vs/ | ||
|
|
||
| # Fleet | ||
| .fleet/ | ||
|
|
||
| # Code Rush | ||
| .cr/ | ||
|
|
||
| # User-specific files | ||
| *.suo | ||
| *.user | ||
| *.userosscache | ||
| *.sln.docstates | ||
|
|
||
| # Build results | ||
| [Dd]ebug/ | ||
| [Dd]ebugPublic/ | ||
| [Rr]elease/ | ||
| [Rr]eleases/ | ||
| x64/ | ||
| x86/ | ||
| build/ | ||
| bld/ | ||
| [Bb]in/ | ||
| [Oo]bj/ | ||
| [Oo]ut/ | ||
| msbuild.log | ||
| msbuild.err | ||
| msbuild.wrn | ||
|
|
||
| # Node.js build artifacts | ||
| node_modules/ | ||
| package-lock.json | ||
| package.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build | ||
|
|
||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| build-essential \ | ||
| clang \ | ||
| pkg-config \ | ||
| libssl-dev \ | ||
| ca-certificates \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
| ENV PATH="/root/.cargo/bin:${PATH}" | ||
|
|
||
| WORKDIR /src | ||
|
|
||
| COPY . . | ||
|
|
||
| # This will automatically trigger the 'cargo build' via the .csproj target | ||
| RUN dotnet publish EthProofValidator.csproj -c Release -o /app/publish | ||
|
|
||
| # Copy the compiled native library to the publish directory | ||
| RUN cp /src/native-zk-verifier/target/release/libnative_zk_verifier.so /app/publish/ | ||
|
|
||
| FROM mcr.microsoft.com/dotnet/runtime:10.0 AS runtime | ||
| WORKDIR /app | ||
|
|
||
| COPY --from=build /app/publish . | ||
|
|
||
| ENTRYPOINT ["dotnet", "EthProofValidator.dll"] | ||
|
|
rubo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
rubo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <RootNamespace>EthProofValidator</RootNamespace> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
rubo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| </ItemGroup> | ||
|
|
||
| <Target Name="BuildRustDependency" BeforeTargets="Build"> | ||
| <Exec Command="cargo build --release" WorkingDirectory="native-zk-verifier" /> | ||
| <ItemGroup> | ||
| <NativeLibs Include="native-zk-verifier/target/release/libnative_zk_verifier.so" Condition="$([MSBuild]::IsOSPlatform('Linux'))" /> | ||
| <NativeLibs Include="native-zk-verifier/target/release/native_zk_verifier.dll" Condition="$([MSBuild]::IsOSPlatform('Windows'))" /> | ||
| <NativeLibs Include="native-zk-verifier/target/release/libnative_zk_verifier.dylib" Condition="$([MSBuild]::IsOSPlatform('OSX'))" /> | ||
| </ItemGroup> | ||
| <Copy SourceFiles="@(NativeLibs)" DestinationFolder="$(OutputPath)" /> | ||
| </Target> | ||
|
|
||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # .NET ETH Proofs ZK Verifier | ||
|
|
||
| This project serves as a Proof of Concept for a .NET application designed to validate **Ethereum block proofs** aggregated by [Ethproofs.org](https://ethproofs.org/). | ||
|
|
||
| **Ethproofs.org** is a block proof explorer for Ethereum that aggregates data from various zkVM (Zero-Knowledge Virtual Machine) teams. It provides a comprehensive overview of proven blocks and allows users to explore proof metadata. | ||
|
|
||
| This application acts as a wrapper for various native ZK verifiers implemented in Rust, enabling .NET applications to verify these cryptographic proofs. It supports multiple proof systems (such as OpenVM, Pico, Zisk, etc.) to validate the execution of Ethereum blocks, contributing to the goal of enabling full ZK light clients and validating Ethereum state with a single proof. | ||
|
|
||
| The project demonstrates how to bridge .NET and high-performance Rust-based ZK verifiers to interact with the growing ecosystem of Ethereum zkVMs. | ||
|
|
||
| This project specifically focuses on multi-GPU ZK verifiers, as they are currently the only ones that provide Real-Time Proving (RTP). | ||
|
|
||
| ## Important Disclaimer | ||
|
|
||
| This project is strictly connected to [Ethproofs.org](https://ethproofs.org/). Due to the dynamic nature of the Ethereum proof ecosystem, `ethproofs.org` frequently updates its provers and verification keys. Therefore, this project requires active maintenance to ensure compatibility and correct functionality with the latest changes from `ethproofs.org`. | ||
|
|
||
| ## Project Structure | ||
|
|
||
| The repository is composed of two main parts: | ||
|
|
||
| - **`src/`**: The main C# .NET project (EthProofValidator). This contains the application logic, models, and interfaces for interacting with the ZK verifiers. | ||
| - **`native-zk-verifier/`**: A Rust project that implements the actual ZK verifier logic for different proof systems (e.g., Zisk, OpenVM, Pico, SP1 Hypercube). The .NET application communicates with this Rust library. | ||
|
|
||
| ## Building and Running | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - .NET SDK (e.g., .NET 10) | ||
| - Rust Toolchain (e.g., `rustup`) | ||
|
|
||
| ### Build Steps | ||
|
|
||
| 1. **Build the .NET Application (includes Rust Verifiers)**: | ||
| Navigate to the root directory of the .NET project and build the C# application. This process will automatically build the Rust verifier library and copy the necessary native libraries into the output directory. | ||
|
|
||
| ```bash | ||
| dotnet build | ||
| ``` | ||
|
|
||
| ### Running the Application | ||
|
|
||
| After building both components, you can run the .NET application from the root directory: | ||
|
|
||
| ```bash | ||
| dotnet run <LatestBlockId> <BlockCount> | ||
| ``` | ||
|
|
||
| This will execute the `Program.cs` which should then utilize the compiled Rust verifiers. | ||
|
|
||
| ## Demo Behavior | ||
|
|
||
| The current implementation in `src/Program.cs` is configured to run a demonstration that validates a sequence of Ethereum blocks. | ||
| It defines a `LatestBlockId` validates the preceding `BlockCount` blocks (currently set to 25). | ||
| The application sequentially attempts to fetch and validate the proofs for each of these blocks, printing the elapsed time for each validation to the console. | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Rust build artifacts | ||
| debug/ | ||
| target/ | ||
| Cargo.lock | ||
|
|
||
| # WASM-specific build outputs | ||
| verifier/pkg/ | ||
| pkg/ | ||
| pkg-node/ | ||
| pkg-web/ | ||
| dist/ | ||
| build/ | ||
|
|
||
| # Node.js dependencies (if using npm/yarn for frontend) | ||
| example/eth_wasm/node_modules/ | ||
| example/wasm_example/node_modules/ | ||
| node_modules/ | ||
| package-lock.json | ||
| yarn.lock | ||
|
|
||
| # Environment files | ||
| .env | ||
| .env.local | ||
|
|
||
| # OS-specific files | ||
| .DS_Store | ||
| Thumbs.db | ||
rubo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| [package] | ||
| name = "native-zk-verifier" | ||
| edition = "2021" | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib"] | ||
|
|
||
| [dependencies] | ||
| # Zisk / ZKCLoud | ||
| proofman-verifier = { git = "https://github.com/0xPolygonHermez/pil2-proofman.git", tag = "v0.15.0" } | ||
| # OpenVM | ||
| verify-stark = { git = "https://github.com/openvm-org/openvm.git", branch = "feat/v1-verify-stark", package = "verify-stark" } | ||
| # Pico | ||
| pico-prism-vm = { git = "https://github.com/ethproofs/pico.git", package = "pico-vm", branch = "ethproofs-pico-prism" } | ||
| # SP1 | ||
| sp1-verifier = { git = "https://github.com/succinctlabs/hypercube-verifier.git", branch = "ethproofs_demo" } | ||
|
|
||
| # Serialization | ||
| serde = { version = "1.0", features = ["derive"] } | ||
| bincode = "1.3" | ||
|
|
||
| # Error handling | ||
| anyhow = "1.0" | ||
|
|
||
| # Serialization | ||
| bitcode = { version = "0.6.5", default-features = false, features = ["serde"] } | ||
|
|
||
| # Optimize for size in release builds | ||
| [profile.release] | ||
| opt-level = 3 # Max speed | ||
| lto = true # Link Time Optimization (makes code faster) | ||
| strip = true # Remove symbols to make the .dll smaller | ||
|
|
2 changes: 2 additions & 0 deletions
2
tools/EthProofValidator/native-zk-verifier/rust-toolchain.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [toolchain] | ||
| channel = "nightly" | ||
rubo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| use std::slice; | ||
| use std::panic; | ||
|
|
||
| mod verifiers; | ||
| use verifiers::{ Verifier, VerifierType, openvm::OpenVmVerifier, pico::PicoVerifier, sp1_hypercube::Sp1HypercubeVerifier, zisk::ZiskVerifier }; | ||
|
|
||
| #[no_mangle] | ||
| pub extern "C" fn verify( | ||
| zk_type: u32, | ||
| proof_ptr: *const u8, | ||
| proof_len: usize, | ||
| vk_ptr: *const u8, | ||
| vk_len: usize, | ||
| ) -> i32 { | ||
| // Check for null pointers from C# safety | ||
| if proof_ptr.is_null() || vk_ptr.is_null() { | ||
| return -1; | ||
| } | ||
|
|
||
| // Wrap the raw pointers in Rust slices (zero-copy) | ||
| let proof = unsafe { slice::from_raw_parts(proof_ptr, proof_len) }; | ||
| let vk = unsafe { slice::from_raw_parts(vk_ptr, vk_len) }; | ||
|
|
||
| let verifier_type = match VerifierType::try_from(zk_type) { | ||
| Ok(t) => t, | ||
| Err(_) => return -1, | ||
| }; | ||
|
|
||
| // Catch panics from the underlying verifier libraries | ||
| let panic_result = panic::catch_unwind(|| { | ||
| match verifier_type { | ||
| VerifierType::Zisk => ZiskVerifier::verify(proof, vk), | ||
| VerifierType::OpenVm => OpenVmVerifier::verify(proof, vk), | ||
| VerifierType::Pico => PicoVerifier::verify(proof, vk), | ||
| VerifierType::Sp1Hypercube => Sp1HypercubeVerifier::verify(proof, vk), | ||
| } | ||
| }); | ||
|
|
||
| match panic_result { | ||
| Ok(verification_result) => match verification_result { | ||
| Ok(true) => 1, | ||
| Ok(false) => 0, | ||
| Err(_) => -1, | ||
| }, | ||
| Err(_) => -1, | ||
| } | ||
| } | ||
|
|
36 changes: 36 additions & 0 deletions
36
tools/EthProofValidator/native-zk-verifier/src/verifiers/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| use anyhow::Result; | ||
|
|
||
| #[repr(u32)] | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum VerifierType { | ||
| Zisk = 0, | ||
| OpenVm = 1, | ||
| Pico = 2, | ||
| Sp1Hypercube = 3, | ||
| } | ||
|
|
||
| impl TryFrom<u32> for VerifierType { | ||
| type Error = anyhow::Error; | ||
|
|
||
| fn try_from(value: u32) -> Result<Self> { | ||
| match value { | ||
| 0 => Ok(VerifierType::Zisk), | ||
| 1 => Ok(VerifierType::OpenVm), | ||
| 2 => Ok(VerifierType::Pico), | ||
| 3 => Ok(VerifierType::Sp1Hypercube), | ||
| _ => Err(anyhow::anyhow!("Unknown verifier type: {}", value)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub trait Verifier { | ||
| fn verify(proof: &[u8], vk: &[u8]) -> Result<bool>; | ||
| } | ||
|
|
||
| pub mod zisk; | ||
| pub mod openvm; | ||
| pub mod pico; | ||
| pub mod sp1_hypercube; |
28 changes: 28 additions & 0 deletions
28
tools/EthProofValidator/native-zk-verifier/src/verifiers/openvm.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| use super::Verifier; | ||
| use anyhow::{Result}; | ||
| use verify_stark::{verify_vm_stark_proof, vk::VmStarkVerifyingKey}; | ||
|
|
||
| pub struct OpenVmVerifier; | ||
|
|
||
| impl Verifier for OpenVmVerifier { | ||
| fn verify(proof: &[u8], vk: &[u8]) -> Result<bool> { | ||
| // Deserialize the verification key from bitcode bytes | ||
| let vk: VmStarkVerifyingKey = match bitcode::deserialize(vk) { | ||
| Ok(vk) => vk, | ||
| Err(e) => { | ||
| return Err(anyhow::anyhow!("Failed to deserialize OpenVM verification key: {:?}", e)); | ||
| } | ||
| }; | ||
|
|
||
| // Verify the proof using the OpenVM verify-stark library | ||
| match verify_vm_stark_proof(&vk, proof) { | ||
| Ok(()) => Ok(true), | ||
| Err(e) => { | ||
| return Err(anyhow::anyhow!("OpenVM verification failed: {:?}", e)); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.