Implement returning of public values for other zkVMs (#109)

This commit is contained in:
Han
2025-08-28 11:24:52 +08:00
committed by GitHub
parent 44044a1858
commit 54aa24c9a4
20 changed files with 426 additions and 246 deletions

223
Cargo.lock generated
View File

@@ -1678,6 +1678,7 @@ dependencies = [
"lock_api",
"once_cell",
"parking_lot_core",
"rayon",
]
[[package]]
@@ -2337,6 +2338,7 @@ dependencies = [
"anyhow",
"borsh",
"build-utils",
"bytemuck",
"cargo_metadata 0.19.2",
"risc0-build",
"risc0-zkvm",
@@ -4630,8 +4632,8 @@ dependencies = [
[[package]]
name = "openvm"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"bytemuck",
"num-bigint 0.4.6",
@@ -4643,9 +4645,10 @@ dependencies = [
[[package]]
name = "openvm-algebra-circuit"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"cfg-if",
"derive-new 0.6.0",
"derive_more 1.0.0",
"eyre",
@@ -4671,8 +4674,8 @@ dependencies = [
[[package]]
name = "openvm-algebra-complex-macros"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-macros-common",
"quote",
@@ -4681,8 +4684,8 @@ dependencies = [
[[package]]
name = "openvm-algebra-guest"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"halo2curves-axiom",
"num-bigint 0.4.6",
@@ -4697,8 +4700,8 @@ dependencies = [
[[package]]
name = "openvm-algebra-moduli-macros"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"num-bigint 0.4.6",
"num-prime",
@@ -4709,8 +4712,8 @@ dependencies = [
[[package]]
name = "openvm-algebra-transpiler"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-algebra-guest",
"openvm-instructions",
@@ -4723,9 +4726,10 @@ dependencies = [
[[package]]
name = "openvm-bigint-circuit"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"cfg-if",
"derive-new 0.6.0",
"derive_more 1.0.0",
"openvm-bigint-transpiler",
@@ -4745,8 +4749,8 @@ dependencies = [
[[package]]
name = "openvm-bigint-guest"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-platform",
"strum_macros 0.26.4",
@@ -4754,8 +4758,8 @@ dependencies = [
[[package]]
name = "openvm-bigint-transpiler"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-bigint-guest",
"openvm-instructions",
@@ -4769,8 +4773,8 @@ dependencies = [
[[package]]
name = "openvm-build"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"cargo_metadata 0.18.1",
"eyre",
@@ -4781,10 +4785,11 @@ dependencies = [
[[package]]
name = "openvm-circuit"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"backtrace",
"cfg-if",
"dashmap",
"derivative",
"derive-new 0.6.0",
@@ -4803,6 +4808,7 @@ dependencies = [
"openvm-stark-backend",
"openvm-stark-sdk",
"p3-baby-bear 0.1.0 (git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb)",
"p3-field 0.1.0 (git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb)",
"rand 0.8.5",
"rustc-hash 2.1.1",
"serde",
@@ -4814,8 +4820,8 @@ dependencies = [
[[package]]
name = "openvm-circuit-derive"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"itertools 0.14.0",
"proc-macro2",
@@ -4825,14 +4831,15 @@ dependencies = [
[[package]]
name = "openvm-circuit-primitives"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"derive-new 0.6.0",
"itertools 0.14.0",
"num-bigint 0.4.6",
"num-traits",
"openvm-circuit-primitives-derive",
"openvm-cuda-builder",
"openvm-stark-backend",
"rand 0.8.5",
"tracing",
@@ -4840,8 +4847,8 @@ dependencies = [
[[package]]
name = "openvm-circuit-primitives-derive"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"itertools 0.14.0",
"quote",
@@ -4850,8 +4857,8 @@ dependencies = [
[[package]]
name = "openvm-continuations"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"derivative",
"openvm-circuit",
@@ -4863,10 +4870,19 @@ dependencies = [
"static_assertions",
]
[[package]]
name = "openvm-cuda-builder"
version = "1.2.0-rc.6"
source = "git+https://github.com/openvm-org/stark-backend.git?tag=v1.2.0-rc.6#ba4e49e1c48abb247720c43eba392fbb5c9eea51"
dependencies = [
"cc",
"glob",
]
[[package]]
name = "openvm-custom-insn"
version = "0.1.0"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"proc-macro2",
"quote",
@@ -4875,9 +4891,10 @@ dependencies = [
[[package]]
name = "openvm-ecc-circuit"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"cfg-if",
"derive-new 0.6.0",
"derive_more 1.0.0",
"halo2curves-axiom",
@@ -4903,8 +4920,8 @@ dependencies = [
[[package]]
name = "openvm-ecc-guest"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"ecdsa",
"elliptic-curve",
@@ -4922,8 +4939,8 @@ dependencies = [
[[package]]
name = "openvm-ecc-sw-macros"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-macros-common",
"quote",
@@ -4932,8 +4949,8 @@ dependencies = [
[[package]]
name = "openvm-ecc-transpiler"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-ecc-guest",
"openvm-instructions",
@@ -4946,8 +4963,8 @@ dependencies = [
[[package]]
name = "openvm-instructions"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"backtrace",
"derive-new 0.6.0",
@@ -4963,8 +4980,8 @@ dependencies = [
[[package]]
name = "openvm-instructions-derive"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"quote",
"syn 2.0.101",
@@ -4972,9 +4989,10 @@ dependencies = [
[[package]]
name = "openvm-keccak256-circuit"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"cfg-if",
"derive-new 0.6.0",
"derive_more 1.0.0",
"itertools 0.14.0",
@@ -4996,16 +5014,16 @@ dependencies = [
[[package]]
name = "openvm-keccak256-guest"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-platform",
]
[[package]]
name = "openvm-keccak256-transpiler"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-instructions",
"openvm-instructions-derive",
@@ -5018,22 +5036,23 @@ dependencies = [
[[package]]
name = "openvm-macros-common"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"syn 2.0.101",
]
[[package]]
name = "openvm-mod-circuit-builder"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"itertools 0.14.0",
"num-bigint 0.4.6",
"num-traits",
"openvm-circuit",
"openvm-circuit-primitives",
"openvm-cuda-builder",
"openvm-instructions",
"openvm-stark-backend",
"openvm-stark-sdk",
@@ -5043,9 +5062,10 @@ dependencies = [
[[package]]
name = "openvm-native-circuit"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"cfg-if",
"derive-new 0.6.0",
"derive_more 1.0.0",
"eyre",
@@ -5061,6 +5081,7 @@ dependencies = [
"openvm-rv32im-transpiler",
"openvm-stark-backend",
"openvm-stark-sdk",
"p3-field 0.1.0 (git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb)",
"rand 0.8.5",
"serde",
"static_assertions",
@@ -5069,8 +5090,8 @@ dependencies = [
[[package]]
name = "openvm-native-compiler"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"backtrace",
"itertools 0.14.0",
@@ -5091,8 +5112,8 @@ dependencies = [
[[package]]
name = "openvm-native-compiler-derive"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"quote",
"syn 2.0.101",
@@ -5100,8 +5121,8 @@ dependencies = [
[[package]]
name = "openvm-native-recursion"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"cfg-if",
"itertools 0.14.0",
@@ -5124,8 +5145,8 @@ dependencies = [
[[package]]
name = "openvm-native-transpiler"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-instructions",
"openvm-transpiler",
@@ -5134,9 +5155,10 @@ dependencies = [
[[package]]
name = "openvm-pairing-circuit"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"cfg-if",
"derive-new 0.6.0",
"derive_more 1.0.0",
"eyre",
@@ -5162,8 +5184,8 @@ dependencies = [
[[package]]
name = "openvm-pairing-guest"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"halo2curves-axiom",
"hex-literal",
@@ -5183,8 +5205,8 @@ dependencies = [
[[package]]
name = "openvm-pairing-transpiler"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-instructions",
"openvm-pairing-guest",
@@ -5196,8 +5218,8 @@ dependencies = [
[[package]]
name = "openvm-platform"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"libm",
"openvm-custom-insn",
@@ -5206,11 +5228,12 @@ dependencies = [
[[package]]
name = "openvm-poseidon2-air"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"derivative",
"lazy_static",
"openvm-cuda-builder",
"openvm-stark-backend",
"openvm-stark-sdk",
"p3-monty-31 0.1.0 (git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb)",
@@ -5223,8 +5246,8 @@ dependencies = [
[[package]]
name = "openvm-rv32-adapters"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"derive-new 0.6.0",
"itertools 0.14.0",
@@ -5240,9 +5263,10 @@ dependencies = [
[[package]]
name = "openvm-rv32im-circuit"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"cfg-if",
"derive-new 0.6.0",
"derive_more 1.0.0",
"eyre",
@@ -5262,8 +5286,8 @@ dependencies = [
[[package]]
name = "openvm-rv32im-guest"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-custom-insn",
"p3-field 0.1.0 (git+https://github.com/Plonky3/Plonky3.git?rev=539bbc84085efb609f4f62cb03cf49588388abdb)",
@@ -5272,8 +5296,8 @@ dependencies = [
[[package]]
name = "openvm-rv32im-transpiler"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-instructions",
"openvm-instructions-derive",
@@ -5288,11 +5312,12 @@ dependencies = [
[[package]]
name = "openvm-sdk"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"bitcode",
"bon",
"cfg-if",
"clap",
"derivative",
"derive_more 1.0.0",
@@ -5341,8 +5366,8 @@ dependencies = [
[[package]]
name = "openvm-sha256-air"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-circuit-primitives",
"openvm-stark-backend",
@@ -5352,9 +5377,10 @@ dependencies = [
[[package]]
name = "openvm-sha256-circuit"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"cfg-if",
"derive-new 0.6.0",
"derive_more 1.0.0",
"openvm-circuit",
@@ -5374,16 +5400,16 @@ dependencies = [
[[package]]
name = "openvm-sha256-guest"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-platform",
]
[[package]]
name = "openvm-sha256-transpiler"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"openvm-instructions",
"openvm-instructions-derive",
@@ -5396,8 +5422,8 @@ dependencies = [
[[package]]
name = "openvm-stark-backend"
version = "1.2.0-rc.0"
source = "git+https://github.com/openvm-org/stark-backend.git?tag=v1.2.0-rc.1#2bf6fd20e3c77cabe01f830d06e6439ea101f98e"
version = "1.2.0-rc.6"
source = "git+https://github.com/openvm-org/stark-backend.git?tag=v1.2.0-rc.6#ba4e49e1c48abb247720c43eba392fbb5c9eea51"
dependencies = [
"bitcode",
"cfg-if",
@@ -5416,13 +5442,14 @@ dependencies = [
"rustc-hash 2.1.1",
"serde",
"thiserror 1.0.69",
"tikv-jemallocator",
"tracing",
]
[[package]]
name = "openvm-stark-sdk"
version = "1.2.0-rc.0"
source = "git+https://github.com/openvm-org/stark-backend.git?tag=v1.2.0-rc.1#2bf6fd20e3c77cabe01f830d06e6439ea101f98e"
version = "1.2.0-rc.6"
source = "git+https://github.com/openvm-org/stark-backend.git?tag=v1.2.0-rc.6#ba4e49e1c48abb247720c43eba392fbb5c9eea51"
dependencies = [
"dashmap",
"derivative",
@@ -5458,8 +5485,8 @@ dependencies = [
[[package]]
name = "openvm-transpiler"
version = "1.4.0-rc.4"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.4#ae8f139f6f094364f2287d8ca2e756bd3b4db48e"
version = "1.4.0-rc.8"
source = "git+https://github.com/openvm-org/openvm.git?tag=v1.4.0-rc.8#c33320cce6f6a5c030c04306bef5d2d7bfc05bce"
dependencies = [
"elf",
"eyre",
@@ -9356,8 +9383,10 @@ dependencies = [
name = "test-utils"
version = "0.0.11"
dependencies = [
"bincode",
"rand 0.9.2",
"serde",
"sha2",
"zkvm-interface",
]

View File

@@ -42,6 +42,7 @@ rand = "0.9.2"
serde = "1.0.219"
serde_json = "1.0.142"
serde_yaml = "0.9.34"
sha2 = "0.10.9"
tempfile = "3.20.0"
thiserror = "2.0.12"
toml = "0.8.23"
@@ -59,12 +60,12 @@ jolt-sdk = { git = "https://github.com/a16z/jolt.git", rev = "55b9830a3944dde55d
nexus-sdk = { git = "https://github.com/nexus-xyz/nexus-zkvm.git", tag = "v0.3.4" }
# OpenVM dependencies
openvm-build = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0-rc.4", default-features = false }
openvm-circuit = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0-rc.4", default-features = false }
openvm-continuations = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0-rc.4", default-features = false }
openvm-sdk = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0-rc.4", default-features = false }
openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", tag = "v1.2.0-rc.1" }
openvm-transpiler = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0-rc.4", default-features = false }
openvm-build = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0-rc.8" }
openvm-circuit = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0-rc.8" }
openvm-continuations = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0-rc.8" }
openvm-sdk = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0-rc.8" }
openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", tag = "v1.2.0-rc.6" }
openvm-transpiler = { git = "https://github.com/openvm-org/openvm.git", tag = "v1.4.0-rc.8" }
# Pico dependencies
pico-vm = { git = "https://github.com/brevis-network/pico.git", tag = "v1.1.4" }

View File

@@ -75,6 +75,8 @@ pub enum VerifyError {
Verify(#[source] SdkError),
#[error("Deserialize proof failed: {0}")]
DeserializeProof(io::Error),
#[error(transparent)]
Common(#[from] CommonError),
}
#[derive(Debug, Error)]
@@ -89,4 +91,6 @@ pub enum CommonError {
AggKeyGen(SdkError),
#[error("Initialize prover failed: {0}")]
ProverInit(SdkError),
#[error("Invalid public value")]
InvalidPublicValue,
}

View File

@@ -11,7 +11,7 @@ use openvm_sdk::{
config::{AppConfig, DEFAULT_APP_LOG_BLOWUP, DEFAULT_LEAF_LOG_BLOWUP, SdkVmConfig},
keygen::AggVerifyingKey,
};
use openvm_stark_sdk::config::FriParameters;
use openvm_stark_sdk::{config::FriParameters, openvm_stark_backend::p3_field::PrimeField32};
use openvm_transpiler::{elf::Elf, openvm_platform::memory::MEM_SIZE};
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use std::{fs, io::Read, path::Path, sync::Arc, time::Instant};
@@ -140,13 +140,10 @@ impl zkVM for EreOpenVM {
serialize_inputs(&mut stdin, inputs);
let start = Instant::now();
let _outputs = sdk
let public_values = sdk
.execute(self.app_exe.clone(), stdin)
.map_err(|e| OpenVMError::from(ExecuteError::Execute(e)))?;
// TODO: Public values
let public_values = Vec::new();
Ok((
public_values,
ProgramExecutionReport {
@@ -180,13 +177,11 @@ impl zkVM for EreOpenVM {
}))?;
}
let public_values = extract_public_values(&proof.user_public_values)?;
let proof_bytes = proof
.encode_to_vec()
.map_err(|e| OpenVMError::from(ProveError::SerializeProof(e)))?;
// TODO: Public values
let public_values = Vec::new();
Ok((
public_values,
proof_bytes,
@@ -201,8 +196,7 @@ impl zkVM for EreOpenVM {
Sdk::verify_proof(&self.agg_vk, self.app_commit, &proof)
.map_err(|e| OpenVMError::Verify(VerifyError::Verify(e)))?;
// TODO: Public values
let public_values = Vec::new();
let public_values = extract_public_values(&proof.user_public_values)?;
Ok(public_values)
}
@@ -215,8 +209,10 @@ impl zkVM for EreOpenVM {
SDK_VERSION
}
fn deserialize_from<R: Read, T: DeserializeOwned>(&self, _reader: R) -> Result<T, zkVMError> {
todo!()
fn deserialize_from<R: Read, T: DeserializeOwned>(&self, _: R) -> Result<T, zkVMError> {
Err(zkVMError::other(
"public values de/serialization is not supported",
))
}
}
@@ -231,12 +227,24 @@ fn serialize_inputs(stdin: &mut StdIn, inputs: &Input) {
}
}
/// Extract public values in bytes from field elements.
///
/// The public values revealed in guest program will be flatten into `Vec<u8>`
/// then converted to field elements `Vec<F>`, so here we try to downcast it.
fn extract_public_values(user_public_values: &[F]) -> Result<Vec<u8>, CommonError> {
user_public_values
.iter()
.map(|v| u8::try_from(v.as_canonical_u32()).ok())
.collect::<Option<_>>()
.ok_or(CommonError::InvalidPublicValue)
}
#[cfg(test)]
mod tests {
use super::*;
use std::sync::OnceLock;
use test_utils::host::{
BasicProgramIo, run_zkvm_execute, run_zkvm_prove, testing_guest_directory,
BasicProgramIo, Io, run_zkvm_execute, run_zkvm_prove, testing_guest_directory,
};
fn basic_program() -> OpenVMProgram {
@@ -265,8 +273,9 @@ mod tests {
fn test_execute() {
let zkvm = basic_program_ere_openvm();
let io = BasicProgramIo::valid();
run_zkvm_execute(&zkvm, &io);
let io = BasicProgramIo::valid().into_output_hashed_io();
let public_values = run_zkvm_execute(&zkvm, &io);
assert_eq!(io.deserialize_outputs(&zkvm, &public_values), io.outputs());
}
#[test]
@@ -286,8 +295,9 @@ mod tests {
fn test_prove() {
let zkvm = basic_program_ere_openvm();
let io = BasicProgramIo::valid();
run_zkvm_prove(&zkvm, &io);
let io = BasicProgramIo::valid().into_output_hashed_io();
let public_values = run_zkvm_prove(&zkvm, &io);
assert_eq!(io.deserialize_outputs(&zkvm, &public_values), io.outputs());
}
#[test]

View File

@@ -77,15 +77,12 @@ impl zkVM for ErePico {
serialize_inputs(&mut stdin, inputs);
let start = Instant::now();
let emulation_result = client.emulate(stdin);
// TODO: Public values
let public_values = Vec::new();
let (total_num_cycles, public_values) = client.emulate(stdin);
Ok((
public_values,
ProgramExecutionReport {
total_num_cycles: emulation_result.0,
total_num_cycles,
execution_duration: start.elapsed(),
..Default::default()
},
@@ -147,8 +144,8 @@ impl zkVM for ErePico {
SDK_VERSION
}
fn deserialize_from<R: Read, T: DeserializeOwned>(&self, _reader: R) -> Result<T, zkVMError> {
todo!()
fn deserialize_from<R: Read, T: DeserializeOwned>(&self, reader: R) -> Result<T, zkVMError> {
bincode::deserialize_from(reader).map_err(zkVMError::other)
}
}
@@ -167,7 +164,7 @@ fn serialize_inputs(stdin: &mut EmulatorStdinBuilder<Vec<u8>>, inputs: &Input) {
mod tests {
use super::*;
use std::{panic, sync::OnceLock};
use test_utils::host::{BasicProgramIo, run_zkvm_execute, testing_guest_directory};
use test_utils::host::{BasicProgramIo, Io, run_zkvm_execute, testing_guest_directory};
static BASIC_PRORGAM: OnceLock<Vec<u8>> = OnceLock::new();
@@ -193,7 +190,8 @@ mod tests {
let zkvm = ErePico::new(program, ProverResourceType::Cpu);
let io = BasicProgramIo::valid();
run_zkvm_execute(&zkvm, &io);
let public_values = run_zkvm_execute(&zkvm, &io);
assert_eq!(io.deserialize_outputs(&zkvm, &public_values), io.outputs());
}
#[test]

View File

@@ -8,6 +8,7 @@ license.workspace = true
[dependencies]
anyhow.workspace = true
borsh.workspace = true
bytemuck.workspace = true
cargo_metadata.workspace = true
serde = { workspace = true, features = ["derive", "rc"] }
thiserror.workspace = true

View File

@@ -8,8 +8,12 @@ use borsh::{BorshDeserialize, BorshSerialize};
use risc0_zkvm::{
DEFAULT_MAX_PO2, DefaultProver, ExecutorEnv, ExecutorEnvBuilder, ExternalProver, InnerReceipt,
Journal, ProverOpts, Receipt, ReceiptClaim, SuccinctReceipt, default_executor, default_prover,
serde::{Deserializer, WordRead},
};
use serde::{
Deserialize, Serialize,
de::{DeserializeOwned, Error},
};
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use std::{env, io::Read, ops::RangeInclusive, path::Path, rc::Rc, time::Instant};
use zkvm_interface::{
Compiler, Input, InputItem, ProgramExecutionReport, ProgramProvingReport, Proof,
@@ -141,8 +145,7 @@ impl zkVM for EreRisc0 {
.execute(env, &self.program.elf)
.map_err(zkVMError::other)?;
// TODO: Public values
let public_values = Vec::new();
let public_values = session_info.journal.bytes.clone();
Ok((
public_values,
@@ -196,12 +199,10 @@ impl zkVM for EreRisc0 {
.map_err(zkVMError::other)?;
let proving_time = now.elapsed();
let public_values = prove_info.receipt.journal.bytes.clone();
let proof = borsh::to_vec(&Risc0ProofWithPublicValues::from(prove_info.receipt))
.map_err(zkVMError::other)?;
// TODO: Public values
let public_values = Vec::new();
Ok((
public_values,
proof,
@@ -218,8 +219,7 @@ impl zkVM for EreRisc0 {
.verify(self.program.image_id)
.map_err(zkVMError::other)?;
// TODO: Public values
let public_values = Vec::new();
let public_values = receipt.journal.bytes.clone();
Ok(public_values)
}
@@ -232,8 +232,29 @@ impl zkVM for EreRisc0 {
SDK_VERSION
}
fn deserialize_from<R: Read, T: DeserializeOwned>(&self, _reader: R) -> Result<T, zkVMError> {
todo!()
fn deserialize_from<R: Read, T: DeserializeOwned>(&self, reader: R) -> Result<T, zkVMError> {
struct WordReadAdapter<R>(R);
impl<R: Read> WordRead for WordReadAdapter<R> {
fn read_words(&mut self, words: &mut [u32]) -> risc0_zkvm::serde::Result<()> {
let bytes = bytemuck::cast_slice_mut(words);
self.0
.read_exact(bytes)
.map_err(risc0_zkvm::serde::Error::custom)
}
fn read_padded_bytes(&mut self, bytes: &mut [u8]) -> risc0_zkvm::serde::Result<()> {
let mut padded_bytes = vec![0u8; bytes.len().next_multiple_of(4) - bytes.len()];
self.0
.read_exact(bytes)
.map_err(risc0_zkvm::serde::Error::custom)?;
self.0
.read_exact(&mut padded_bytes)
.map_err(risc0_zkvm::serde::Error::custom)
}
}
T::deserialize(&mut Deserializer::new(WordReadAdapter(reader))).map_err(zkVMError::other)
}
}
@@ -262,7 +283,7 @@ mod tests {
use super::*;
use std::sync::OnceLock;
use test_utils::host::{
BasicProgramIo, run_zkvm_execute, run_zkvm_prove, testing_guest_directory,
BasicProgramIo, Io, run_zkvm_execute, run_zkvm_prove, testing_guest_directory,
};
static BASIC_PRORGAM: OnceLock<Risc0Program> = OnceLock::new();
@@ -283,7 +304,8 @@ mod tests {
let zkvm = EreRisc0::new(program, ProverResourceType::Cpu).unwrap();
let io = BasicProgramIo::valid();
run_zkvm_execute(&zkvm, &io);
let public_values = run_zkvm_execute(&zkvm, &io);
assert_eq!(io.deserialize_outputs(&zkvm, &public_values), io.outputs());
}
#[test]
@@ -306,7 +328,8 @@ mod tests {
let zkvm = EreRisc0::new(program, ProverResourceType::Cpu).unwrap();
let io = BasicProgramIo::valid();
run_zkvm_prove(&zkvm, &io);
let public_values = run_zkvm_prove(&zkvm, &io);
assert_eq!(io.deserialize_outputs(&zkvm, &public_values), io.outputs());
}
#[test]

View File

@@ -134,15 +134,6 @@ pub enum VerifyError {
},
#[error("Invalid proof: {0}")]
InvalidProof(String),
#[error("Invalid public values: {0}")]
DeserializePublicValues(serde_json::Error),
#[error("Invalid public value: {0}")]
ParsePublicValue(ParseIntError),
#[error("Unexpected ROM digest")]
UnexpectedRomDigest {
preprocessed: RomDigest,
public_values: Vec<u64>,
},
}
#[derive(Debug, Error)]
@@ -167,4 +158,17 @@ pub enum CommonError {
},
#[error("`cargo-zisk check-setup` failed with status: {status}")]
CargoZiskCheckSetupFailed { status: ExitStatus },
#[error("Invalid public values: {0}")]
DeserializePublicValues(serde_json::Error),
#[error("Parse public value failed: {0}")]
ParsePublicValue(ParseIntError),
#[error("Invalid public value")]
InvalidPublicValue,
#[error("Public values length {0}, but expected at least 5")]
InvalidPublicValuesLength(usize),
#[error("Unexpected ROM digest")]
UnexpectedRomDigest {
preprocessed: RomDigest,
proved: RomDigest,
},
}

View File

@@ -98,6 +98,8 @@ impl zkVM for EreZisk {
.arg(tempdir.elf_path())
.arg("--inputs")
.arg(tempdir.input_path())
.arg("--output")
.arg(tempdir.execution_output_path())
.arg("--stats") // NOTE: enable stats in order to get total steps.
.stderr(Stdio::inherit())
.output()
@@ -122,8 +124,9 @@ impl zkVM for EreZisk {
})
.ok_or(ZiskError::Execute(ExecuteError::TotalStepsNotFound))?;
// TODO: Public values
let public_values = Vec::new();
let public_values = tempdir
.read_execution_output()
.map_err(|e| ZiskError::Execute(ExecuteError::TempDir(e)))?;
Ok((
public_values,
@@ -143,7 +146,7 @@ impl zkVM for EreZisk {
check_setup()?;
// Run ELF specific setup
rom_setup(&self.elf)?;
let preprocessed_rom_digest = rom_setup(&self.elf)?;
// Obtain the prove lock to make sure proving can't be called concurrently.
let _guard = PROVE_LOCK
@@ -244,19 +247,30 @@ impl zkVM for EreZisk {
// Read proof and public values.
let public_values = tempdir
.read_public_values()
.map_err(|e| ZiskError::Prove(ProveError::TempDir(e)))?;
let proof_with_public_values = ZiskProofWithPublicValues {
proof: tempdir
.read_proof()
.map_err(|e| ZiskError::Prove(ProveError::TempDir(e)))?,
public_values: tempdir
.read_public_values()
.map_err(|e| ZiskError::Prove(ProveError::TempDir(e)))?,
public_values,
};
let bytes = bincode::serialize(&proof_with_public_values)
.map_err(|err| ZiskError::Prove(ProveError::Bincode(err)))?;
// TODO: Public values
let public_values = Vec::new();
// Deserialize public values.
let (proved_rom_digest, public_values) =
deserialize_public_values(&proof_with_public_values.public_values)?;
// The proved ROM digest should be equal to preprocessed one.
if proved_rom_digest != preprocessed_rom_digest {
return Err(CommonError::UnexpectedRomDigest {
preprocessed: preprocessed_rom_digest,
proved: proved_rom_digest,
})?;
}
Ok((
public_values,
@@ -267,7 +281,7 @@ impl zkVM for EreZisk {
fn verify(&self, bytes: &[u8]) -> Result<PublicValues, zkVMError> {
// Run ELF specific setup
let rom_digest = rom_setup(&self.elf)?;
let preprocessed_rom_digest = rom_setup(&self.elf)?;
// Write proof and public values to file.
@@ -300,26 +314,18 @@ impl zkVM for EreZisk {
)))?
}
// Deserialize public values as json string sequence.
let public_values =
serde_json::from_slice::<Vec<String>>(&proof_with_public_values.public_values)
.map_err(|e| ZiskError::Verify(VerifyError::DeserializePublicValues(e)))?
.into_iter()
.map(|v| v.parse())
.collect::<Result<Vec<u64>, _>>()
.map_err(|e| ZiskError::Verify(VerifyError::ParsePublicValue(e)))?;
// Deserialize public values.
let (proved_rom_digest, public_values) =
deserialize_public_values(&proof_with_public_values.public_values)?;
// The first 4 elements of public values should be equal to preprocessed ROM digest.
if public_values.len() < 4 || public_values[..4] != rom_digest {
Err(ZiskError::Verify(VerifyError::UnexpectedRomDigest {
preprocessed: rom_digest,
public_values,
}))?
// The proved ROM digest should be equal to preprocessed one.
if proved_rom_digest != preprocessed_rom_digest {
return Err(CommonError::UnexpectedRomDigest {
preprocessed: preprocessed_rom_digest,
proved: proved_rom_digest,
})?;
}
// TODO: Public values
let public_values = Vec::new();
Ok(public_values)
}
@@ -352,6 +358,42 @@ fn serialize_inputs(inputs: &Input) -> Result<Vec<u8>, bincode::Error> {
})
}
/// Deserialize public values as json string sequence, and parse the `RomDigest`
/// and user set public values as `Vec<u8>`.
fn deserialize_public_values(public_values: &[u8]) -> Result<(RomDigest, Vec<u8>), CommonError> {
let public_values = serde_json::from_slice::<Vec<String>>(public_values)
.map_err(CommonError::DeserializePublicValues)?
.into_iter()
.map(|v| v.parse())
.collect::<Result<Vec<u64>, _>>()
.map_err(CommonError::ParsePublicValue)?;
// The public values contain at least the `RomDigest` and the number of user
// set public values.
if public_values.len() < 5 {
return Err(CommonError::InvalidPublicValuesLength(public_values.len()));
}
// The first 4 elements of public values should be ROM digest.
let rom_digest = public_values[..4].try_into().unwrap();
// The 5-th element should be the number of user set public values.
let num_user_public_values = public_values[4] as usize;
// The rest elements should be user set public values and should be `u32`.
let public_values = public_values[5..]
.iter()
.map(|v| Some(u32::try_from(*v).ok()?.to_le_bytes()))
.take(num_user_public_values)
.collect::<Option<Vec<_>>>()
.ok_or(CommonError::InvalidPublicValue)?
.into_iter()
.flatten()
.collect();
Ok((rom_digest, public_values))
}
fn dot_zisk_dir_path() -> PathBuf {
PathBuf::from(std::env::var("HOME").expect("env `$HOME` should be set")).join(".zisk")
}
@@ -500,6 +542,10 @@ impl ZiskTempDir {
fs::File::create(self.input_path()).and_then(|mut file| file.write_all(input))
}
fn read_execution_output(&self) -> io::Result<Vec<u8>> {
fs::read(self.execution_output_path())
}
fn read_proof(&self) -> io::Result<Vec<u8>> {
fs::read(self.proof_path())
}
@@ -537,6 +583,10 @@ impl ZiskTempDir {
self.tempdir.path().join("output")
}
fn execution_output_path(&self) -> PathBuf {
self.output_dir_path().join("execution_output.bin")
}
fn public_values_path(&self) -> PathBuf {
self.output_dir_path().join("publics.json")
}
@@ -551,7 +601,7 @@ mod tests {
use super::*;
use std::sync::OnceLock;
use test_utils::host::{
BasicProgramIo, run_zkvm_execute, run_zkvm_prove, testing_guest_directory,
BasicProgramIo, Io, run_zkvm_execute, run_zkvm_prove, testing_guest_directory,
};
static BASIC_PRORGAM: OnceLock<Vec<u8>> = OnceLock::new();
@@ -571,8 +621,9 @@ mod tests {
let program = basic_program();
let zkvm = EreZisk::new(program, ProverResourceType::Cpu);
let io = BasicProgramIo::valid();
run_zkvm_execute(&zkvm, &io);
let io = BasicProgramIo::valid().into_output_hashed_io();
let public_values = run_zkvm_execute(&zkvm, &io);
assert_eq!(io.deserialize_outputs(&zkvm, &public_values), io.outputs());
}
#[test]
@@ -594,8 +645,9 @@ mod tests {
let program = basic_program();
let zkvm = EreZisk::new(program, ProverResourceType::Cpu);
let io = BasicProgramIo::valid();
run_zkvm_prove(&zkvm, &io);
let io = BasicProgramIo::valid().into_output_hashed_io();
let public_values = run_zkvm_prove(&zkvm, &io);
assert_eq!(io.deserialize_outputs(&zkvm, &public_values), io.outputs());
}
#[test]

View File

@@ -6,8 +6,10 @@ rust-version.workspace = true
license.workspace = true
[dependencies]
bincode.workspace = true
rand = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
sha2.workspace = true
# Local dependencies
zkvm-interface = { workspace = true, optional = true }

View File

@@ -1,7 +1,29 @@
use alloc::vec::Vec;
use core::iter;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
pub const BASIC_PROGRAM_BYTES_LENGTH: usize = 32;
pub struct BasicProgramCore;
impl BasicProgramCore {
pub const BYTES_LENGTH: usize = 32;
pub fn outputs(inputs: (Vec<u8>, BasicStruct)) -> (Vec<u8>, BasicStruct) {
let (bytes, basic_struct) = inputs;
(bytes.iter().rev().copied().collect(), basic_struct.output())
}
pub fn sha256_outputs(outputs: (Vec<u8>, BasicStruct)) -> [u8; 32] {
let (rev_bytes, basic_struct) = outputs;
Sha256::digest(
iter::empty()
.chain(rev_bytes)
.chain(bincode::serialize(&basic_struct).unwrap())
.collect::<Vec<_>>(),
)
.into()
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct BasicStruct {

View File

@@ -1,6 +1,6 @@
use crate::guest::{BASIC_PROGRAM_BYTES_LENGTH, BasicStruct};
use crate::guest::{BasicProgramCore, BasicStruct};
use rand::{Rng, rng};
use std::{fmt::Debug, io::Read, path::PathBuf};
use std::{fmt::Debug, io::Read, marker::PhantomData, path::PathBuf};
use zkvm_interface::{Input, PublicValues, zkVM};
fn workspace() -> PathBuf {
@@ -76,10 +76,7 @@ impl Io for BasicProgramIo {
}
fn outputs(&self) -> Self::Output {
(
self.bytes.iter().rev().copied().collect(),
self.basic_struct.output(),
)
BasicProgramCore::outputs((self.bytes.clone(), self.basic_struct.clone()))
}
fn deserialize_outputs(&self, zkvm: &impl zkVM, mut bytes: &[u8]) -> Self::Output {
@@ -94,11 +91,18 @@ impl BasicProgramIo {
pub fn valid() -> Self {
let rng = &mut rng();
Self {
bytes: rng.random_iter().take(BASIC_PROGRAM_BYTES_LENGTH).collect(),
bytes: rng
.random_iter()
.take(BasicProgramCore::BYTES_LENGTH)
.collect(),
basic_struct: BasicStruct::random(rng),
}
}
pub fn into_output_hashed_io(self) -> impl Io {
OutputHashedIo::new(self, BasicProgramCore::sha256_outputs)
}
/// Empty input that should trigger deserialization failure in guest
/// program.
pub fn empty() -> Input {
@@ -118,8 +122,48 @@ impl BasicProgramIo {
/// program.
pub fn invalid_data() -> Input {
let mut inputs = Input::new();
inputs.write_bytes(vec![0; BASIC_PROGRAM_BYTES_LENGTH + 1]);
inputs.write_bytes(vec![0; BasicProgramCore::BYTES_LENGTH + 1]);
inputs.write(BasicStruct::default());
inputs
}
}
pub struct OutputHashedIo<T, H, D> {
inner: T,
hasher: H,
_marker: PhantomData<D>,
}
impl<T, H, D> OutputHashedIo<T, H, D> {
pub fn new(inner: T, hasher: H) -> Self {
Self {
inner,
hasher,
_marker: PhantomData,
}
}
}
impl<T, H, D> Io for OutputHashedIo<T, H, D>
where
T: Io,
H: Fn(T::Output) -> D,
D: Clone + Debug + Default + PartialEq + AsMut<[u8]>,
{
type Output = D;
fn inputs(&self) -> Input {
self.inner.inputs()
}
fn outputs(&self) -> Self::Output {
(self.hasher)(self.inner.outputs())
}
fn deserialize_outputs(&self, _: &impl zkVM, bytes: &[u8]) -> Self::Output {
let mut digest = D::default();
assert_eq!(digest.as_mut().len(), bytes.len());
digest.as_mut().copy_from_slice(bytes);
digest
}
}

View File

@@ -28,7 +28,7 @@ ensure_tool_installed "rustup" "to manage Rust toolchains"
ensure_tool_installed "git" "to install cargo-openvm from a git repository"
ensure_tool_installed "cargo" "to build and install Rust packages"
OPENVM_CLI_VERSION_TAG="v1.4.0-rc.4"
OPENVM_CLI_VERSION_TAG="v1.4.0-rc.8"
# Install cargo-openvm using the specified toolchain and version tag
echo "Installing cargo-openvm (version ${OPENVM_CLI_VERSION_TAG}) from GitHub repository (openvm-org/openvm)..."

View File

@@ -7,5 +7,5 @@ edition = "2021"
[dependencies]
bincode = "1.3.3"
openvm = { git = "https://github.com/openvm-org/openvm.git", features = ["std"], tag = "v1.2.0" }
openvm = { git = "https://github.com/openvm-org/openvm.git", features = ["std"], tag = "v1.4.0-rc.8" }
test-utils = { path = "../../../crates/test-utils" }

View File

@@ -0,0 +1,4 @@
[app_vm_config.rv32i]
[app_vm_config.rv32m]
[app_vm_config.io]
[app_vm_config.sha256]

View File

@@ -1,6 +1,5 @@
use core::array::from_fn;
use openvm::io::{read, read_vec, reveal_u32};
use test_utils::guest::{BasicStruct, BASIC_PROGRAM_BYTES_LENGTH};
use openvm::io::{read, read_vec, reveal_bytes32};
use test_utils::guest::{BasicProgramCore, BasicStruct};
fn main() {
// Read `bytes`.
@@ -10,21 +9,14 @@ fn main() {
let basic_struct = read::<BasicStruct>();
// Check `bytes` length is as expected.
assert_eq!(bytes.len(), BASIC_PROGRAM_BYTES_LENGTH);
assert_eq!(bytes.len(), BasicProgramCore::BYTES_LENGTH);
// Do some computation on `basic_struct`.
let basic_struct_output = basic_struct.output();
// Do some computation on `bytes` and `basic_struct`.
let outputs = BasicProgramCore::outputs((bytes, basic_struct));
// Write reversed `bytes` and `basic_struct_output`
let public_values = core::iter::empty()
.chain(bytes.into_iter().rev())
.chain(bincode::serialize(&basic_struct_output).unwrap())
.collect::<Vec<_>>();
public_values
.chunks(4)
.enumerate()
.for_each(|(idx, bytes)| {
let bytes = from_fn(|i| bytes.get(i).copied().unwrap_or_default());
reveal_u32(u32::from_le_bytes(bytes), idx);
});
// Hash `outputs` into digest.
let digest = BasicProgramCore::sha256_outputs(outputs);
// Write `digest`
reveal_bytes32(digest);
}

View File

@@ -1,7 +1,7 @@
#![no_main]
use pico_sdk::io::{commit, commit_bytes, read_as, read_vec};
use test_utils::guest::{BasicStruct, BASIC_PROGRAM_BYTES_LENGTH};
use test_utils::guest::{BasicProgramCore, BasicStruct};
pico_sdk::entrypoint!(main);
@@ -13,12 +13,12 @@ pub fn main() {
let basic_struct = read_as::<BasicStruct>();
// Check `bytes` length is as expected.
assert_eq!(bytes.len(), BASIC_PROGRAM_BYTES_LENGTH);
assert_eq!(bytes.len(), BasicProgramCore::BYTES_LENGTH);
// Do some computation on `basic_struct`.
let basic_struct_output = basic_struct.output();
// Do some computation on `bytes` and `basic_struct`.
let (rev_bytes, basic_struct_output) = BasicProgramCore::outputs((bytes, basic_struct));
// Write reversed `bytes` and `basic_struct_output`
commit_bytes(&bytes.into_iter().rev().collect::<Vec<_>>());
// Write `rev_bytes` and `basic_struct_output`
commit_bytes(&rev_bytes);
commit(&basic_struct_output);
}

View File

@@ -1,5 +1,5 @@
use risc0_zkvm::guest::env;
use test_utils::guest::{BasicStruct, BASIC_PROGRAM_BYTES_LENGTH};
use test_utils::guest::{BasicProgramCore, BasicStruct};
fn main() {
// Read `bytes`.
@@ -9,12 +9,12 @@ fn main() {
let basic_struct = env::read::<BasicStruct>();
// Check `bytes` length is as expected.
assert_eq!(bytes.len(), BASIC_PROGRAM_BYTES_LENGTH);
assert_eq!(bytes.len(), BasicProgramCore::BYTES_LENGTH);
// Do some computation on `basic_struct`.
let basic_struct_output = basic_struct.output();
// Do some computation on `bytes` and `basic_struct`.
let (rev_bytes, basic_struct_output) = BasicProgramCore::outputs((bytes, basic_struct));
// Write reversed `bytes` and `basic_struct_output`
env::commit_slice(&bytes.into_iter().rev().collect::<Vec<_>>());
// Write `rev_bytes` and `basic_struct_output`
env::commit_slice(&rev_bytes);
env::commit(&basic_struct_output);
}

View File

@@ -1,6 +1,6 @@
#![no_main]
use test_utils::guest::{BasicStruct, BASIC_PROGRAM_BYTES_LENGTH};
use test_utils::guest::{BasicProgramCore, BasicStruct};
sp1_zkvm::entrypoint!(main);
@@ -12,12 +12,12 @@ pub fn main() {
let basic_struct = sp1_zkvm::io::read::<BasicStruct>();
// Check `bytes` length is as expected.
assert_eq!(bytes.len(), BASIC_PROGRAM_BYTES_LENGTH);
assert_eq!(bytes.len(), BasicProgramCore::BYTES_LENGTH);
// Do some computation on `basic_struct`.
let basic_struct_output = basic_struct.output();
// Do some computation on `bytes` and `basic_struct`.
let (rev_bytes, basic_struct_output) = BasicProgramCore::outputs((bytes, basic_struct));
// Write reversed `bytes` and `basic_struct_output`
sp1_zkvm::io::commit_slice(&bytes.into_iter().rev().collect::<Vec<_>>());
// Write `rev_bytes` and `basic_struct_output`
sp1_zkvm::io::commit_slice(&rev_bytes);
sp1_zkvm::io::commit(&basic_struct_output);
}

View File

@@ -1,7 +1,6 @@
#![no_main]
use core::array::from_fn;
use test_utils::guest::{BasicStruct, BASIC_PROGRAM_BYTES_LENGTH};
use test_utils::guest::{BasicProgramCore, BasicStruct};
ziskos::entrypoint!(main);
@@ -19,21 +18,16 @@ fn main() {
assert!(input.is_empty());
// Check `bytes` length is as expected.
assert_eq!(bytes.len(), BASIC_PROGRAM_BYTES_LENGTH);
assert_eq!(bytes.len(), BasicProgramCore::BYTES_LENGTH);
// Do some computation on `basic_struct`.
let basic_struct_output = basic_struct.output();
// Do some computation on `bytes` and `basic_struct`.
let outputs = BasicProgramCore::outputs((bytes, basic_struct));
// Write reversed `bytes` and `basic_struct_output`
let public_values = core::iter::empty()
.chain(bytes.into_iter().rev())
.chain(bincode::serialize(&basic_struct_output).unwrap())
.collect::<Vec<_>>();
public_values
.chunks(4)
.enumerate()
.for_each(|(idx, bytes)| {
let bytes = from_fn(|i| bytes.get(i).copied().unwrap_or_default());
ziskos::set_output(idx, u32::from_le_bytes(bytes));
});
// Hash `outputs` into digest.
let digest = BasicProgramCore::sha256_outputs(outputs);
// Write `digest`
digest.chunks_exact(4).enumerate().for_each(|(idx, bytes)| {
ziskos::set_output(idx, u32::from_le_bytes(bytes.try_into().unwrap()))
});
}