MCPcopy Index your code
hub / github.com/DelphinusLab/zkWasm

github.com/DelphinusLab/zkWasm @explorer-integration-5.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release explorer-integration-5.0 ↗ · + Follow
1,242 symbols 2,958 edges 216 files 34 documented · 3% updated 4mo ago★ 54311 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Overview:

The mission of DelphinusLab is to provide Web2 developers with a concise toolset to leverage the power of Web3 in their applications. The ZKWASM (ZKSNARK virtual machine that supports Web Assembly) serves as a trustless layer between rich applications running on WASM runtime and smart contracts on chain.

WASM (or WebAssembly) is an open standard binary code format similar to assembly. Its initial objective was to provide an alternative to java-script with improved performance for the current web ecosystem. Benefiting from its platform independence, front-end flexibility (can be compiled from the majority of languages including C, C++, assembly script, rust, etc.), good isolated runtime and speed comes closer to the speed of a native binary, its usage is arising in distributed cloud and edge computing. Recently it has become a popular binary format for users to run customized functions on AWS Lambda, Open Yurt, AZURE, etc.

The idea of ZKWASM is derived from ZKSNARK (Zero-Knowledge Succinct Non-Interactive Argument of Knowledge) which is a combination of SNARG (Succinct non-interactive arguments) and zero-knowledge proof. In general, the adoption of ZKSNARK usually requires implementing a program in arithmetic circuits or circuit-friendly languages (Pinocchio, TinyRAM, Buffet/Pequin, Geppetto, xJsnark framework, ZoKrates) that forms a barrier for existing programs to leverage its power. An alternative approach is, instead of applying ZKSNARK on the source code, applying it on the bytecode level of a virtual machine and implementing a zksnark-backed virtual machine. In this work, we take the approach of writing the whole WASM virtual machine in ZKSNARK circuits so that existing WASM applications can benefit from ZKSNARK by simply running on the ZKWASM, without any modification. Therefore, the cloud service provider can prove to any user that the computation result is computed honestly and no private information is leaked.

Circuit Details:

https://ieeexplore.ieee.org/document/10587123

Quick start with ZKWASM command line

Dependency

Make sure the following packages are installed.

clang lld

Install Instructions

git clone --recurse-submodules https://github.com/DelphinusLab/zkwasm
cargo build

Setup input:

wasm code

Runtime input:

input of wasm function and the top level function must be zkmain

Proving target:

simulation of wasm execution of target wasm bytecode with particular inputs are correct.

Command line:

Setup via WASM image:

delphinus-cli --params <PARAMS> <NAME> setup [OPTIONS] --wasm <WASM>

with OPTIONS:

    -h, --help
            Print help information

        --host <HOST_MODE>
            Specify execution host environment for the runtime [default: default] [possible values:
            default, standard]

    -k <K>
            Size of the circuit. [default: 18]

        --phantom <PHANTOM_FUNCTIONS>
            Specify phantom functions whose body will be ignored in the circuit

        --wasm <WASM>
            Path to the Wasm image

Single prove and verify:

cargo run --release -- --params <PARAMS> <NAME> prove [OPTIONS] --wasm <WASM> --output <OUTPUT>

with OPTIONS:

        --ctxin <CONTEXT_INPUT>
            Context inputs with format value:type where type=i64|bytes|bytes-packed, values can be
            separated by `,` or multiple occurrences of `--ctxin`

        --ctxout [<CONTEXT_OUTPUT>...]
            Path to context output

        --file
            Enabling the file backend for table to support enormous execution trace. It may reduce
            the speed of execution.

    -h, --help
            Print help information

    -m, --mock
            Enable mock test before proving

    -o, --output <OUTPUT>
            Path to output directory

        --private <PRIVATE_INPUT>
            Private inputs with format value:type where type=i64|bytes|bytes-packed, values can be
            separated by `,` or multiple occurrences of `--private`

        --public <PUBLIC_INPUT>
            Public inputs with format value:type where type=i64|bytes|bytes-packed, values can be
            separated by `,` or multiple occurrences of `--public`

        --wasm <WASM>
            Path to the Wasm image
cargo run --release -- --params <PARAMS> <NAME> verify --output <OUTPUT>

Batch prove and verify:

Please see zkWASM continuation batcher at https://github.com/DelphinusLab/continuation-batcher for batching proof with host circuits and verifier generation in smart contracts.

Operations Spec [WIP]

We use z3 (https://github.com/Z3Prover/z3) to check that all operations are compiled to zkp circuits correctly.

[This is a WIP project, only sample code are provided here. Please contact xgao@zoyoe.com for state circuit customization and application integration.

Issue tracking:

  • chore: non-feature requirements such as CI/CD, building script or work flow enhancement.
  • feat: feature need, we could use feat(circuit), feat(lang), feat(CLI) to categorize features
  • bug: bug report, we also could use bug(circuit), bug(lang) to categorize bugs
  • doc: documents related issues.

Project Bootstrap:

  • C project: There is a project template for compiling C to wasm with limited host functions (foreign circuits). (see https://github.com/DelphinusLab/zkWasm-C)
  • Rust project demo: https://github.com/xgaozoyoe/zkWasm-Rust-Demo
  • Assembly script demo: https://github.com/DelphinusLab/zkWasm-AssemblyScript-Demo
  • Browser based project: See https://github.com/zkcrossteam/g1024/ for how to utilize zkWASM in javascript, how to generate proofs using PAAS service and verify it on chain (contact xgao@zoyoe.com for details about PAAS testnet).

Extension points exported contracts — how you extend this code

ForeignContext (Interface)
Context of the plugin. # Examples ``` use delphinus_zkwasm::runtime::host::ForeignContext; struct Context { acc: u64, [16 …
crates/zkwasm/src/runtime/host/mod.rs
ArgBuilder (Interface)
(no doc) [11 implementers]
crates/cli/src/app_builder.rs
PluginFlushStrategy (Interface)
(no doc) [4 implementers]
crates/host/src/lib.rs
FromBn (Interface)
(no doc) [2 implementers]
crates/specs/src/encode/mod.rs
EventTableOpcodeConfigBuilder (Interface)
(no doc) [27 implementers]
crates/zkwasm/src/circuits/etable/mod.rs
GroupedForeign (Interface)
(no doc) [1 implementers]
crates/host/src/lib.rs
SliceBackend (Interface)
(no doc) [2 implementers]
crates/specs/src/slice_backend/mod.rs
EventTableOpcodeConfig (Interface)
(no doc) [30 implementers]
crates/zkwasm/src/circuits/etable/mod.rs

Core symbols most depended-on inside this repo

unwrap
called by 426
crates/specs/src/etable.rs
expr
called by 328
crates/zkwasm/src/circuits/image_table/mod.rs
alloc_bit_cell
called by 100
crates/zkwasm/src/circuits/etable/allocator.rs
map
called by 98
crates/specs/src/state.rs
push
called by 91
crates/zkwasm/src/circuits/etable/constraint_builder.rs
iter
called by 76
crates/specs/src/itable.rs
assign_bool
called by 55
crates/zkwasm/src/circuits/cell.rs
alloc_unlimited_cell
called by 52
crates/zkwasm/src/circuits/etable/allocator.rs

Shape

Method 733
Class 255
Function 176
Enum 43
Interface 35

Languages

Rust99%
C1%
Python1%
C++1%

Modules by API surface

crates/zkwasm/src/circuits/etable/allocator.rs36 symbols
crates/zkwasm/src/runtime/monitor/plugins/table/transaction/v2.rs31 symbols
crates/specs/src/itable.rs28 symbols
crates/zkwasm/src/circuits/etable/mod.rs27 symbols
crates/specs/src/jtable.rs22 symbols
crates/cli/src/app_builder.rs20 symbols
crates/zkwasm/src/circuits/utils/image_table.rs19 symbols
crates/zkwasm/src/circuits/mtable/allocator.rs19 symbols
crates/host/src/lib.rs19 symbols
crates/zkwasm/src/runtime/monitor/plugins/table/transaction/v1.rs16 symbols
crates/zkwasm/src/runtime/monitor/plugins/table/mod.rs16 symbols
crates/zkwasm/src/circuits/cell.rs16 symbols

For agents

$ claude mcp add zkWasm \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page