CVE-2025-61588
Description
RISC Zero is a zero-knowledge verifiable general computing platform based on zk-STARKs and the RISC-V microarchitecture. In versions 2.0.2 and below of risc0-zkvm-platform, when the zkVM guest calls sys_read, the host is able to use a crafted response to write to an arbitrary memory location in the guest. This capability can be leveraged to execute arbitrary code within the guest. As sys_read is the mechanism by which input is requested by the guest, all guest programs built with the affected versions are vulnerable. This critically compromises the soundness guarantees of the guest program. Other affected packages include risc0-aggregation versions below 0.9, risc0-zkos-v1compat below 2.1.0, risc0-zkvm versions between 3.0.0-rc.1 and 3.0.1. This issue has been fixed in the following versions: risc0-zkvm-platform 2.1.0, risc0-zkos-v1compat 2.1.0, risc0-aggregation 0.9, and risc0-zkvm 2.3.2 and 3.0.3.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
risc0-zkvm-platformcrates.io | < 2.1.0 | 2.1.0 |
risc0-zkos-v1compatcrates.io | < 2.1.0 | 2.1.0 |
risc0-aggregationcrates.io | < 0.9 | 0.9 |
risc0-zkvmcrates.io | < 2.3.2 | 2.3.2 |
risc0-zkvmcrates.io | >= 3.0.0, < 3.0.3 | 3.0.3 |
Affected products
1Patches
13f00e1fa0159Refactor guest I/O with host (#3351)
54 files changed · +1910 −554
benchmarks/Cargo.lock+25 −1 modified@@ -2940,6 +2940,27 @@ dependencies = [ "libc", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.99", +] + [[package]] name = "number_prefix" version = "0.4.0" @@ -3910,6 +3931,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -3992,13 +4014,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.1", "libm", + "num_enum", + "paste", "stability", ]
benchmarks/methods/guest/Cargo.lock+31 −1 modified@@ -1129,6 +1129,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", +] + [[package]] name = "objc" version = "0.2.7" @@ -1449,6 +1470,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1503,13 +1525,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1554,6 +1578,12 @@ dependencies = [ "semver", ] +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "safe_arch" version = "0.7.4"
Cargo.lock+25 −1 modified@@ -5576,6 +5576,27 @@ dependencies = [ "libc", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + [[package]] name = "number_prefix" version = "0.4.0" @@ -7155,6 +7176,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -7284,7 +7306,7 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", @@ -7293,6 +7315,8 @@ dependencies = [ "getrandom 0.2.16", "getrandom 0.3.2", "libm", + "num_enum", + "paste", "stability", ]
Cargo.toml+1 −1 modified@@ -65,7 +65,7 @@ risc0-sys = { version = "1.5.1", default-features = false, path = "risc0/sys" } risc0-zkos-v1compat = { version = "2.1.0", path = "risc0/zkos/v1compat" } risc0-zkp = { version = "3.0.2", default-features = false, path = "risc0/zkp" } risc0-zkvm = { version = "4.0.0", default-features = false, path = "risc0/zkvm" } -risc0-zkvm-platform = { version = "2.0.5", default-features = false, path = "risc0/zkvm/platform" } +risc0-zkvm-platform = { version = "2.1.0", default-features = false, path = "risc0/zkvm/platform" } rzup = { version = "0.6.0", default-features = false, path = "rzup" } sppark = "0.1.12"
examples/bevy/methods/guest/Cargo.lock+31 −1 modified@@ -1125,6 +1125,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1435,6 +1456,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1489,13 +1511,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1531,6 +1555,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "scopeguard" version = "1.2.0"
examples/bls12_381/methods/guest/Cargo.lock+31 −1 modified@@ -833,6 +833,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.98", +] + [[package]] name = "objc" version = "0.2.7" @@ -1109,6 +1130,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1163,13 +1185,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1205,6 +1229,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.25"
examples/bn254/methods/guest/Cargo.lock+31 −1 modified@@ -803,6 +803,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.98", +] + [[package]] name = "objc" version = "0.2.7" @@ -1068,6 +1089,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1122,13 +1144,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1170,6 +1194,12 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.25"
examples/Cargo.lock+25 −1 modified@@ -3509,6 +3509,27 @@ dependencies = [ "libc", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.99", +] + [[package]] name = "number_prefix" version = "0.4.0" @@ -4656,6 +4677,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -4753,13 +4775,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.1", "libm", + "num_enum", + "paste", "stability", ]
examples/chess/methods/guest/Cargo.lock+31 −1 modified@@ -803,6 +803,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1075,6 +1096,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1129,13 +1151,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1171,6 +1195,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
examples/c-kzg/methods/guest/Cargo.lock+31 −1 modified@@ -847,6 +847,27 @@ dependencies = [ "libc", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1119,6 +1140,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1173,13 +1195,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1215,6 +1239,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
examples/composition/methods/guest/Cargo.lock+25 −1 modified@@ -1192,6 +1192,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1583,6 +1604,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1637,13 +1659,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ]
examples/digital-signature/methods/guest/Cargo.lock+31 −1 modified@@ -767,6 +767,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1039,6 +1060,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1093,13 +1115,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1135,6 +1159,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
examples/ecdsa/k256/methods/guest/Cargo.lock+31 −1 modified@@ -902,6 +902,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1207,6 +1228,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1261,13 +1283,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1303,6 +1327,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "sec1" version = "0.7.3"
examples/ecdsa/p256/methods/guest/Cargo.lock+31 −1 modified@@ -878,6 +878,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1217,6 +1238,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1271,13 +1293,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1313,6 +1337,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "sec1" version = "0.7.3"
examples/groth16-verifier/methods/guest/Cargo.lock+31 −1 modified@@ -786,6 +786,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1058,6 +1079,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1112,13 +1134,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1154,6 +1178,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
examples/hello-world/methods/guest/Cargo.lock+31 −1 modified@@ -766,6 +766,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1038,6 +1059,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1092,13 +1114,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1134,6 +1158,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
examples/json/methods/guest/Cargo.lock+31 −1 modified@@ -792,6 +792,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1064,6 +1085,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1118,13 +1140,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1160,6 +1184,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "search_json" version = "0.12.0"
examples/jwt-validator/methods/guest/Cargo.lock+31 −1 modified@@ -978,6 +978,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1265,6 +1286,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1319,13 +1341,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1381,6 +1405,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "ryu" version = "1.0.18"
examples/keccak/methods/guest/Cargo.lock+31 −1 modified@@ -785,6 +785,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + [[package]] name = "objc" version = "0.2.7" @@ -1037,6 +1058,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1091,13 +1113,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1133,6 +1157,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.26"
examples/password-checker/methods/guest/Cargo.lock+31 −1 modified@@ -787,6 +787,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1086,6 +1107,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1140,13 +1162,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1182,6 +1206,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
examples/profiling/methods/guest/Cargo.lock+31 −1 modified@@ -851,6 +851,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1129,6 +1150,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1183,13 +1205,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1225,6 +1249,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "safe_arch" version = "0.7.2"
examples/prorata/methods/guest/Cargo.lock+31 −1 modified@@ -805,6 +805,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1097,6 +1118,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1151,13 +1173,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1214,6 +1238,12 @@ dependencies = [ "rust_decimal", ] +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "ryu" version = "1.0.18"
examples/sha/methods/guest/Cargo.lock+31 −1 modified@@ -786,6 +786,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1058,6 +1079,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1112,13 +1134,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1154,6 +1178,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
examples/smartcore-ml/methods/guest/Cargo.lock+31 −1 modified@@ -856,6 +856,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1128,6 +1149,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1182,13 +1204,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1224,6 +1248,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
examples/voting-machine/methods/guest/Cargo.lock+31 −1 modified@@ -759,6 +759,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1031,6 +1052,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1085,13 +1107,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1127,6 +1151,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
examples/waldo/methods/guest/Cargo.lock+31 −1 modified@@ -828,6 +828,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.95", +] + [[package]] name = "objc" version = "0.2.7" @@ -1080,6 +1101,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1134,13 +1156,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1176,6 +1200,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.24"
examples/wasm/methods/guest/Cargo.lock+31 −1 modified@@ -784,6 +784,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1056,6 +1077,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1110,13 +1132,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1152,6 +1176,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
examples/wordle/methods/guest/Cargo.lock+31 −1 modified@@ -778,6 +778,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1050,6 +1071,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1104,13 +1126,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1146,6 +1170,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
examples/xgboost/methods/guest/Cargo.lock+31 −1 modified@@ -823,6 +823,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1119,6 +1140,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1173,13 +1195,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1237,6 +1261,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "ryu" version = "1.0.18"
risc0/bigint2/methods/guest/Cargo.lock+31 −1 modified@@ -912,6 +912,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1219,6 +1240,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1273,13 +1295,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1315,6 +1339,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "sec1" version = "0.7.3"
risc0/build/src/docker.rs+1 −1 modified@@ -262,7 +262,7 @@ mod test { compare_image_id( &guest_list, "hello_commit", - "91d654f4e393d80f1771f70e7996e47e346bdfe011a0925279871fd25adab260", + "4e201003c21c0bc0b60844ff589cb17dfaafdd77146cc49c1c3cc4a21cff91d3", ); } }
risc0/circuit/keccak/methods/guest/Cargo.lock+31 −1 modified@@ -771,6 +771,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1033,6 +1054,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1087,13 +1109,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1129,6 +1153,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
risc0/povw/guests/log-builder/Cargo.lock+25 −1 modified@@ -1126,6 +1126,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", +] + [[package]] name = "objc" version = "0.2.7" @@ -1475,6 +1496,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1529,13 +1551,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.16", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ]
risc0/zkos/v1compat/Cargo.toml+4 −0 modified@@ -14,6 +14,10 @@ path = "src/main.rs" [dependencies] include_bytes_aligned = "0.1" no_std_strings = "0.1.3" +risc0-zkvm-platform = { workspace = true } [package.metadata.risc0] kernel = true + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(rust_analyzer)'] }
risc0/zkos/v1compat/elfs/v1compat.elf+0 −0 modifiedrisc0/zkos/v1compat/src/kernel.s+10 −34 modified@@ -26,7 +26,6 @@ .equ HOST_ECALL_SHA, 4 .equ HOST_ECALL_BIGINT, 5 .equ WORD_SIZE, 4 -.equ MAX_IO_BYTES, 1024 .equ DIGEST_WORDS, 8 .equ REG_SP, 2 .equ REG_T0, 5 @@ -40,6 +39,7 @@ .equ REG_A5, 15 .equ REG_A6, 16 .equ REG_T3, 28 +.equ REG_T6, 31 .equ USER_MODE, 0 .equ MACHINE_MODE, 1 @@ -65,7 +65,6 @@ _start: li tp, USER_REGS_ADDR la s1, _ecall_table li s2, ECALL_TABLE_SIZE - li s3, MAX_IO_BYTES # Load the user program entry into MEPC li a0, USER_START_ADDR @@ -83,23 +82,23 @@ _ecall_table: j _ecall_software j _ecall_sha j _ecall_bigint - fence # user + unimp # user j _ecall_bigint2 j _ecall_poseidon2 _ecall_dispatch: # load t0 from userspace lw a0, REG_T0 * WORD_SIZE (tp) # check that ecall request is within range - bge a0, s2, 1f + bgeu a0, s2, 1f # adjust index so that it points to word sized entries slli a0, a0, 2 # compute the table entry add a1, s1, a0 # jump into dispatch table jr a1 1: - fence # panic + unimp # panic _ecall_halt: # copy output digest from pointer in a1 to GLOBAL_OUTPUT_ADDR @@ -143,7 +142,7 @@ _ecall_halt: mret 1: - fence + unimp # return a word of the input digest to the user _ecall_input: @@ -165,41 +164,18 @@ _ecall_input: mret 1: - fence # panic + unimp # panic _ecall_software: - # prepare a software ecall - li a7, HOST_ECALL_READ - lw a0, REG_A2 * WORD_SIZE (tp) # syscall_ptr -> fd - lw a1, REG_A0 * WORD_SIZE (tp) # from_host_ptr -> buf - lw a2, REG_A1 * WORD_SIZE (tp) # from_host_len -> len - slli a2, a2, 2 - - # check if length is > 1024 - bltu s3, a2, 1f - - # call the host - ecall - - # read (a0, a1) back from host - # fd == 0 means read (a0, a1) from host - li a0, 0 - # read into user registers starting at a0 - addi a1, tp, REG_A0 * WORD_SIZE - # read two words from host - li a2, 2 * WORD_SIZE - # call the host - ecall - - # return back to userspace - mret -1: + lw a0, REG_T6 * WORD_SIZE (tp) # user/kernel syscall nr + lw a1, REG_A2 * WORD_SIZE (tp) # syscall_ptr + lw a2, REG_A0 * WORD_SIZE (tp) # from_host_ptr + lw a3, REG_A1 * WORD_SIZE (tp) # from_host_len call ecall_software # return back to userspace mret - _ecall_sha: lw a0, REG_A0 * WORD_SIZE (tp) # out_state lw a1, REG_A1 * WORD_SIZE (tp) # in_state
risc0/zkos/v1compat/src/main.rs+437 −187 modified@@ -18,7 +18,7 @@ #[cfg(not(target_os = "zkvm"))] fn main() {} -#[cfg(target_os = "zkvm")] +#[cfg(any(target_os = "zkvm", rust_analyzer))] #[allow(static_mut_refs)] mod zkvm { use core::{ @@ -27,6 +27,7 @@ mod zkvm { mem::MaybeUninit, }; use include_bytes_aligned::include_bytes_aligned; + use risc0_zkvm_platform::syscall::Syscall; const MACHINE_MODE: u32 = 1; const HOST_ECALL_READ: u32 = 1; @@ -72,9 +73,15 @@ mod zkvm { pub temp_size: u32, } - fn assert_user_ptr(ptr: usize) { - if ptr >= USER_END_ADDR { - unsafe { illegal_instruction() }; + fn assert_user_ptr<T>(ptr: *const T) { + if ptr as usize >= USER_END_ADDR { + illegal_instruction(); + } + } + + fn assert_user_raw_slice(ptr: *const u8, nbytes: u32) { + if nbytes > 0 && (ptr as usize).saturating_add(nbytes as usize) > USER_END_ADDR { + illegal_instruction() } } @@ -86,73 +93,75 @@ mod zkvm { y: *const [u32; BIGINT_WIDTH_WORDS], modulus: *const [u32; BIGINT_WIDTH_WORDS], ) { - assert_user_ptr(result as usize); - assert_user_ptr(x as usize); - assert_user_ptr(y as usize); - assert_user_ptr(modulus as usize); + assert_user_ptr(result); + assert_user_ptr(x); + assert_user_ptr(y); + assert_user_ptr(modulus); if op != BIGINT_OP_MULTIPLY { illegal_instruction(); } - let mod_zero = (*modulus).iter().all(|e| *e == 0); - let blob_ptr = if mod_zero { - MUL_256.as_ptr() - } else { - MODMUL_256.as_ptr() - }; - let header = blob_ptr as *const BigIntBlobHeader; - let nondet_program_ptr = (header.add(1)) as *const u32; - let verify_program_ptr = nondet_program_ptr.add((*header).nondet_program_size as usize); - let consts_ptr = verify_program_ptr.add((*header).verify_program_size as usize); - let temp_space = ((*header).temp_size as usize) << 2; - - if mod_zero { - let mut temp_result = MaybeUninit::<[[u32; BIGINT_WIDTH_WORDS]; 2]>::uninit(); - - asm!("sub sp, sp, {temp_space}", temp_space = in(reg) temp_space); - host_ecall_bigint_3( - nondet_program_ptr, - verify_program_ptr, - consts_ptr, - blob_ptr, - x as *const u32, - y as *const u32, - temp_result.as_mut_ptr() as *const u32, - ); - asm!("add sp, sp, {temp_space}", temp_space = in(reg) temp_space); - - let temp_result = temp_result.assume_init(); - - // Check for overflow of the result - if temp_result[1].iter().any(|e| *e != 0) { - illegal_instruction(); - } + unsafe { + let mod_zero = (*modulus).iter().all(|e| *e == 0); + let blob_ptr = if mod_zero { + MUL_256.as_ptr() + } else { + MODMUL_256.as_ptr() + }; + let header = blob_ptr as *const BigIntBlobHeader; + let nondet_program_ptr = (header.add(1)) as *const u32; + let verify_program_ptr = nondet_program_ptr.add((*header).nondet_program_size as usize); + let consts_ptr = verify_program_ptr.add((*header).verify_program_size as usize); + let temp_space = ((*header).temp_size as usize) << 2; + + if mod_zero { + let mut temp_result = MaybeUninit::<[[u32; BIGINT_WIDTH_WORDS]; 2]>::uninit(); + + asm!("sub sp, sp, {temp_space}", temp_space = in(reg) temp_space); + host_ecall_bigint_3( + nondet_program_ptr, + verify_program_ptr, + consts_ptr, + blob_ptr, + x as *const u32, + y as *const u32, + temp_result.as_mut_ptr() as *const u32, + ); + asm!("add sp, sp, {temp_space}", temp_space = in(reg) temp_space); + + let temp_result = temp_result.assume_init(); + + // Check for overflow of the result + if temp_result[1].iter().any(|e| *e != 0) { + illegal_instruction(); + } - (*result).copy_from_slice(&temp_result[0]); - } else { - asm!("sub sp, sp, {temp_space}", temp_space = in(reg) temp_space); - host_ecall_bigint_4( - nondet_program_ptr, - verify_program_ptr, - consts_ptr, - blob_ptr, - x as *const u32, - y as *const u32, - modulus as *const u32, - result as *const u32, - ); - asm!("add sp, sp, {temp_space}", temp_space = in(reg) temp_space); + (*result).copy_from_slice(&temp_result[0]); + } else { + asm!("sub sp, sp, {temp_space}", temp_space = in(reg) temp_space); + host_ecall_bigint_4( + nondet_program_ptr, + verify_program_ptr, + consts_ptr, + blob_ptr, + x as *const u32, + y as *const u32, + modulus as *const u32, + result as *const u32, + ); + asm!("add sp, sp, {temp_space}", temp_space = in(reg) temp_space); + } } } #[inline(always)] - unsafe fn illegal_instruction() -> ! { - asm!("fence", options(noreturn)); + fn illegal_instruction() -> ! { + unsafe { asm!("unimp", options(noreturn)) } } #[inline(always)] - unsafe fn host_ecall_bigint_3( + fn host_ecall_bigint_3( nondet_program_ptr: *const u32, verify_program_ptr: *const u32, consts_ptr: *const u32, @@ -161,21 +170,23 @@ mod zkvm { a2: *const u32, a3: *const u32, ) { - asm!("ecall", - in("a7") HOST_ECALL_BIGINT, - in("t0") MACHINE_MODE, - in("t1") nondet_program_ptr, - in("t2") verify_program_ptr, - in("t3") consts_ptr, - in("a0") blob_ptr, - in("a1") a1, - in("a2") a2, - in("a3") a3, - ); + unsafe { + asm!("ecall", + in("a7") HOST_ECALL_BIGINT, + in("t0") MACHINE_MODE, + in("t1") nondet_program_ptr, + in("t2") verify_program_ptr, + in("t3") consts_ptr, + in("a0") blob_ptr, + in("a1") a1, + in("a2") a2, + in("a3") a3, + ) + }; } #[inline(always)] - unsafe fn host_ecall_bigint_4( + fn host_ecall_bigint_4( nondet_program_ptr: *const u32, verify_program_ptr: *const u32, consts_ptr: *const u32, @@ -185,123 +196,44 @@ mod zkvm { a3: *const u32, a4: *const u32, ) { - asm!("ecall", - in("a7") HOST_ECALL_BIGINT, - in("t0") MACHINE_MODE, - in("t1") nondet_program_ptr, - in("t2") verify_program_ptr, - in("t3") consts_ptr, - in("a0") blob_ptr, - in("a1") a1, - in("a2") a2, - in("a3") a3, - in("a4") a4, - ); - } - - /// This is called from kernel.s when the ecall_software buffer size if greater than 1024. It - /// tries to chunk the host_ecall_read calls up. Only sys_read, sys_random, sys_slice_io - /// support this. - /// - /// Other syscalls either require a buffer of size zero, or they will error if the first call - /// doesn't return all the data. - #[unsafe(no_mangle)] - unsafe extern "C" fn ecall_software(fd: u32, mut buf: *const u8, mut len: u32) { - // use no_std_strings::{str256, str_format}; - // let msg = str_format!(str256, "ecall_software_slow({fd:#010x}, {buf:?}, {len})"); - // print(msg.to_str()); - - let (mut nbytes, mut last_word) = (0u32, 0u32); - - let mut read_loop = || -> bool { - while len > MAX_IO_BYTES { - let rlen = host_ecall_read(fd, buf, MAX_IO_BYTES); - let (a0, a1) = read_a0_a1(); - nbytes += a0; - last_word = a1; - if rlen < MAX_IO_BYTES { - return false; - } - buf = buf.add(rlen as usize); - len -= rlen; - } - true + unsafe { + asm!("ecall", + in("a7") HOST_ECALL_BIGINT, + in("t0") MACHINE_MODE, + in("t1") nondet_program_ptr, + in("t2") verify_program_ptr, + in("t3") consts_ptr, + in("a0") blob_ptr, + in("a1") a1, + in("a2") a2, + in("a3") a3, + in("a4") a4, + ) }; - - if read_loop() && len > 0 { - host_ecall_read(fd, buf, len); - let (a0, a1) = read_a0_a1(); - nbytes += a0; - last_word = a1; - } - - set_ureg(REG_A0, nbytes); - set_ureg(REG_A1, last_word); } - unsafe fn host_ecall_read(fd: u32, buf: *const u8, len: u32) -> u32 { - // For sys_read and sys_getenv this contains the length, so we need to update it. - // For sys_argv this register is unused, so it doesn't matter. - // For sys_random this register is unused, so it doesn't matter. - // For other syscalls, we might clobber something, but they'll error because length is > 0 - set_ureg(REG_A4, len); - - let rlen: u32; - asm!("ecall", - in("a7") HOST_ECALL_READ, - inout("a0") fd => rlen, - in("a1") buf, - in("a2") len, - ); - rlen - } - - unsafe fn read_a0_a1() -> (u32, u32) { - let mut buf = [0, 0]; - asm!("ecall", - in("a7") HOST_ECALL_READ, - in("a0") 0, - in("a1") buf.as_mut_ptr(), - in("a2") 2 * WORD_SIZE, - ); - (buf[0], buf[1]) + fn set_ureg(idx: usize, word: u32) { + let base = USER_REGS_ADDR as *mut u32; + unsafe { base.add(idx).write_volatile(word) }; } - unsafe fn set_ureg(idx: usize, word: u32) { + #[allow(dead_code)] + fn get_ureg(idx: usize) -> u32 { let base = USER_REGS_ADDR as *mut u32; - core::ptr::write_volatile(base.add(idx), word); + unsafe { base.add(idx).read_volatile() } } - // fn print(msg: &str) { - // let msg = msg.as_bytes(); - // unsafe { - // sys_log(msg.as_ptr(), msg.len()); - // } - // } - - // unsafe fn sys_log(msg_ptr: *const u8, msg_len: usize) { - // asm!("ecall", - // in("a7") HOST_ECALL_WRITE, - // in("a0") 0, - // in("a1") msg_ptr, - // in("a2") msg_len, - // ); - // } + #[allow(dead_code)] + fn print(msg: &str) { + let msg = msg.as_bytes(); + host_ecall_write(0, msg.as_ptr(), msg.len()); + } #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { use no_std_strings::{str_format, str256}; let msg = str_format!(str256, "{}", info); - unsafe { sys_panic(msg.as_ptr(), msg.len()) } - } - - unsafe fn sys_panic(msg_ptr: *const u8, msg_len: usize) -> ! { - asm!("ecall", - in("a7") HOST_ECALL_WRITE, - in("a0") 1, - in("a1") msg_ptr, - in("a2") msg_len, - ); + host_ecall_write(1, msg.as_ptr(), msg.len()); illegal_instruction() } @@ -313,33 +245,351 @@ mod zkvm { block2_ptr: *const u32, mut count: u32, ) { - let mut data_ptr = if block2_ptr == block1_ptr.add(DIGEST_WORDS) { + let mut data_ptr = if block2_ptr == unsafe { block1_ptr.add(DIGEST_WORDS) } { block1_ptr } else { static mut TEMP_BLOCK: [u32; BLOCK_WORDS] = [0u32; BLOCK_WORDS]; let block1 = core::ptr::slice_from_raw_parts(block1_ptr, DIGEST_WORDS); let block2 = core::ptr::slice_from_raw_parts(block2_ptr, DIGEST_WORDS); - TEMP_BLOCK[..DIGEST_WORDS].copy_from_slice(&*block1); - TEMP_BLOCK[DIGEST_WORDS..].copy_from_slice(&*block2); - TEMP_BLOCK.as_ptr() as *const u32 + unsafe { + TEMP_BLOCK[..DIGEST_WORDS].copy_from_slice(&*block1); + TEMP_BLOCK[DIGEST_WORDS..].copy_from_slice(&*block2); + TEMP_BLOCK.as_ptr() as *const u32 + } }; loop { let chunk = min(count, MAX_SHA_COUNT); - asm!("ecall", - in("a7") HOST_ECALL_SHA, - in("a0") in_state, - in("a1") out_state, - in("a2") data_ptr, - in("a3") chunk, - in("a4") SHA_K.as_ptr(), - ); + unsafe { + asm!("ecall", + in("a7") HOST_ECALL_SHA, + in("a0") in_state, + in("a1") out_state, + in("a2") data_ptr, + in("a3") chunk, + in("a4") SHA_K.as_ptr(), + ) + }; count -= chunk; if count == 0 { break; } - data_ptr = data_ptr.add(chunk as usize * BLOCK_WORDS); + data_ptr = unsafe { data_ptr.add(chunk as usize * BLOCK_WORDS) }; in_state = out_state; } } + + #[unsafe(no_mangle)] + unsafe extern "C" fn ecall_software(nr: usize, fd: u32, buf: *mut u8, len: u32) { + match Syscall::from(nr) { + Syscall::Argc => sys_argc(fd), + Syscall::Argv => sys_argv(fd, buf, len), + Syscall::CycleCount => sys_cycle_count(fd), + Syscall::Exit => sys_exit(fd), + Syscall::Fork => sys_fork(fd), + Syscall::Getenv => sys_getenv(fd, buf, len), + Syscall::Keccak => sys_keccak(fd, buf, len), + Syscall::Log => sys_log(fd), + Syscall::Panic => sys_panic(fd), + Syscall::Pipe => sys_pipe(fd, buf, len), + Syscall::Random => sys_random(fd, buf, len), + Syscall::Read => sys_read(fd, buf, len), + Syscall::User => sys_user(fd, buf, len), + Syscall::VerifyIntegrity => sys_verify_integrity(fd), + Syscall::VerifyIntegrity2 => sys_verify_integrity2(fd), + Syscall::Write => sys_write(fd), + Syscall::Unknown(_) => unimplemented!(), + } + } + + fn host_ecall_write(fd: u32, msg_ptr: *const u8, msg_len: usize) -> u32 { + let rlen: u32; + unsafe { + asm!("ecall", + in("a7") HOST_ECALL_WRITE, + inout("a0") fd => rlen, + in("a1") msg_ptr, + in("a2") msg_len, + ) + }; + rlen + } + + fn host_ecall_read(fd: u32, ptr: *mut u8, nbytes: u32) -> u32 { + let rlen: u32; + unsafe { + asm!("ecall", + in("a7") HOST_ECALL_READ, + inout("a0") fd => rlen, + in("a1") ptr, + in("a2") nbytes, + ) + }; + rlen + } + + fn host_ecall_read_trunc(fd: u32, ptr: *mut u8, nbytes: u32) -> u32 { + let nbytes = min(nbytes, MAX_IO_BYTES); + host_ecall_read(fd, ptr, nbytes) + } + + fn host_syscall(fd: u32) -> u32 { + host_ecall_read(fd, core::ptr::null_mut(), 0) + } + + fn read_a0_a1() -> (u32, u32) { + let mut buf = [0u32, 0u32]; + host_ecall_read( + 0, + buf.as_mut_ptr() as *mut u8, + core::mem::size_of_val(&buf) as u32, + ); + (buf[0], buf[1]) + } + + fn host_syscall_a0_a1(fd: u32) -> (u32, u32) { + host_syscall(fd); + read_a0_a1() + } + + // word-oriented + // sys_keccak + // sys_pipe + + // word-oriented, truncated + // sys_argv + // sys_getenv + + // word-oriented, chunked + // sys_random + + // byte-oriented, chunked + // sys_read + + fn sys_argc(fd: u32) { + // a0: from_host -> argc + // a1: from_host_words + // a2: syscall_name + + let (a0, _a1) = host_syscall_a0_a1(fd); + set_ureg(REG_A0, a0); + } + + fn sys_argv(fd: u32, buf: *mut u8, nwords: u32) { + // a0: from_host -> arg_len + // a1: from_host_words + // a2: syscall_name + // a3: arg_index + + // Truncate the requested size since: + // 1. The rv32im circuit can only transfer a max of 1KB. + // 2. The host-side can only handle a single chunk. + host_ecall_read_trunc(fd, buf, nwords * WORD_SIZE); + let (a0, _a1) = read_a0_a1(); + set_ureg(REG_A0, a0); + } + + fn sys_cycle_count(fd: u32) { + // a0: from_host -> hi + // a1: from_host_words -> lo + // a2: syscall_name + + let (a0, a1) = host_syscall_a0_a1(fd); + set_ureg(REG_A0, a0); + set_ureg(REG_A1, a1); + } + + fn sys_exit(fd: u32) { + // a0: from_host -> ret + // a1: from_host_words + // a2: syscall_name + + let (a0, _a1) = host_syscall_a0_a1(fd); + set_ureg(REG_A0, a0); + } + + fn sys_fork(fd: u32) { + // a0: from_host -> ret + // a1: from_host_words + // a2: syscall_name + + let (a0, _a1) = host_syscall_a0_a1(fd); + set_ureg(REG_A0, a0); + } + + fn sys_getenv(fd: u32, buf: *mut u8, nwords: u32) { + // a0: from_host -> var_len + // a1: from_host_words + // a2: syscall_name + // a3: varname + // a4: varname_len + + // Truncate the requested size since: + // 1. The rv32im circuit can only transfer a max of 1KB. + // 2. The host-side can only handle a single chunk. + host_ecall_read_trunc(fd, buf, nwords * WORD_SIZE); + let (a0, _a1) = read_a0_a1(); + set_ureg(REG_A0, a0); + } + + fn sys_keccak(fd: u32, buf: *mut u8, nwords: u32) { + // a0: from_host -> ret + // a1: from_host_words + // a2: syscall_name + // a3: keccak_mode + // a4: in_state/claim_digest + // a5: reserved/control_root + + // Truncate the requested size since: + // 1. The rv32im circuit can only transfer a max of 1KB. + // 2. The host-side can only handle a single chunk. + host_ecall_read_trunc(fd, buf, nwords * WORD_SIZE); + let (a0, _a1) = read_a0_a1(); + set_ureg(REG_A0, a0); + } + + fn sys_log(fd: u32) { + // a0: from_host + // a1: from_host_words + // a2: syscall_name + // a3: msg_ptr + // a4: msg_len + + host_syscall(fd); + } + + fn sys_panic(fd: u32) { + // a0: from_host + // a1: from_host_words + // a2: syscall_name + // a3: msg_ptr + // a4: msg_len + + host_syscall(fd); + } + + fn sys_pipe(fd: u32, buf: *mut u8, nwords: u32) { + // a0: from_host -> ret + // a1: from_host_words + // a2: syscall_name + + // Truncate the requested size since: + // 1. The rv32im circuit can only transfer a max of 1KB. + // 2. The host-side can only handle a single chunk. + host_ecall_read_trunc(fd, buf, nwords * WORD_SIZE); + let (a0, _a1) = read_a0_a1(); + set_ureg(REG_A0, a0); + } + + fn sys_random(fd: u32, buf: *mut u8, nwords: u32) { + // a0: from_host + // a1: from_host_words + // a2: syscall_name + + // The usermode `sys_rand` signature defines `recv_buf` as `*mut u32`. + // It's assumed that `buf` will always be aligned. + let nbytes = nwords * WORD_SIZE; + assert_user_raw_slice(buf, nbytes); + let slice = unsafe { core::slice::from_raw_parts_mut(buf, nbytes as usize) }; + for chunk in slice.chunks_mut(MAX_IO_BYTES as usize) { + host_ecall_read(fd, chunk.as_mut_ptr(), chunk.len() as u32); + } + } + + fn sys_read(fd: u32, buf: *mut u8, nbytes: u32) { + // a0: from_host -> nread_bytes + // a1: from_host_words -> final_word + // a2: syscall_name + // a3: fd + // a4: nbytes + + assert_user_raw_slice(buf, nbytes); + let slice = unsafe { core::slice::from_raw_parts_mut(buf as *mut u8, nbytes as usize) }; + let user_nbytes = get_ureg(REG_A4); + + let mut total_bytes = 0u32; + for chunk in slice.chunks_mut(MAX_IO_BYTES as usize) { + let nbytes = chunk.len() as u32; + set_ureg(REG_A4, nbytes); + + // Read protocol with host expects a "main" read of whole words, then sends any final + // partial words in a seconds read for user (a0, a1). + let nbytes_main = (nbytes / WORD_SIZE) * WORD_SIZE; + host_ecall_read(fd, chunk.as_mut_ptr(), nbytes_main); + + let (nread_bytes, final_word) = read_a0_a1(); + if nread_bytes > nbytes { + // Host returned an invalid number of bytes read. + illegal_instruction() + } + + // SAFETY: With the check that nread_bytes <= nbytes, which is the chunk size, + // total_bytes can never exceed the size of the slice; this will not overflow. + total_bytes += nread_bytes; + + // final_word handling + // NOTE: If true, this implies that nbytes % WORD_SIZE != 0 in combination with the + // length check above. + if nread_bytes > nbytes_main { + let final_bytes = final_word.to_le_bytes(); + let pos = nbytes_main as usize; + let bytes_remain = (nread_bytes - nbytes_main) as usize; + chunk[pos..pos + bytes_remain].copy_from_slice(&final_bytes[..bytes_remain]); + } + + // short read + if (nread_bytes as usize) < chunk.len() { + break; + } + } + + set_ureg(REG_A0, total_bytes); + set_ureg(REG_A4, user_nbytes); + } + + fn sys_user(fd: u32, buf: *mut u8, nwords: u32) { + // a0: from_host + // a1: from_host_words + // a2: syscall_name + + // Truncate the requested size since: + // 1. The rv32im circuit can only transfer a max of 1KB. + // 2. The host-side can only handle a single chunk. + host_ecall_read_trunc(fd, buf, nwords * WORD_SIZE); + let (a0, _a1) = read_a0_a1(); + set_ureg(REG_A0, a0); + } + + fn sys_verify_integrity(fd: u32) { + // a0: from_host -> ret + // a1: from_host_words + // a2: syscall_name + // a3: buf_ptr + // a4: buf_nbytes + + let (a0, _a1) = host_syscall_a0_a1(fd); + set_ureg(REG_A0, a0); + } + + fn sys_verify_integrity2(fd: u32) { + // a0: from_host -> ret + // a1: from_host_words + // a2: syscall_name + // a3: buf_ptr + // a4: buf_nbytes + + let (a0, _a1) = host_syscall_a0_a1(fd); + set_ureg(REG_A0, a0); + } + + fn sys_write(fd: u32) { + // a0: from_host + // a1: from_host_words + // a2: syscall_name + // a3: fd + // a4: buf_ptr + // a5: buf_nbytes + + host_syscall(fd); + } }
risc0/zkvm/examples/datasheet.rs+2 −47 modified@@ -40,7 +40,6 @@ use tabled::{Table, Tabled, settings::Style}; /// Powers-of-two for cycles, paired with the number of loop iterations used to /// achieve that many cycles. const CYCLES_PO2_ITERS: &[(u32, u32)] = &[ - (14, 1), // 14, 16K (15, 1024 * 8), // 15, 32K (16, 1024 * 16), // 16, 64K (17, 1024 * 32), // 17, 128K @@ -56,7 +55,7 @@ const CYCLES_PO2_ITERS: &[(u32, u32)] = &[ const MIN_CYCLES_PO2: usize = CYCLES_PO2_ITERS[0].0 as usize; /// The number of iterations of the LOOP_ELF needed to fill up a po2=20 segment. -const ITERATIONS_FULL_PO2_20_SEGMENT: usize = 1024 * 495 + 790; +const ITERATIONS_FULL_PO2_20_SEGMENT: usize = 1024 * 494 + 817; /// The maximum number of cycles in a segment that can be reserved (for fitting the /// potential next instruction and for lookup table + control when proving) @@ -141,9 +140,6 @@ enum Command { Groth16, #[command(name = "bigint2")] BigInt2, - ZethShapella30, - ZethShapella50, - ZethShapella100, } #[derive(Default)] @@ -189,9 +185,6 @@ impl Datasheet { #[cfg(any(feature = "docker", feature = "cuda"))] Command::Groth16 => self.groth16(), Command::BigInt2 => self.bigint2(), - Command::ZethShapella30 => self.shapella30(), - Command::ZethShapella50 => self.shapella50(), - Command::ZethShapella100 => self.shapella100(), } } @@ -317,7 +310,7 @@ impl Datasheet { let ctx = VerifierContext::default(); let prover = get_prover_server(&opts).unwrap(); - let (po2, iters) = CYCLES_PO2_ITERS[1]; + let (po2, iters) = CYCLES_PO2_ITERS[0]; let env = ExecutorEnv::builder() .write_slice(&iters.to_le_bytes()) @@ -553,44 +546,6 @@ impl Datasheet { self.bigint2_prove_segment(&session, &segment); } - fn shapella_segment(&mut self, name: &str, bytes: &[u8]) { - // "shapella" is the name of ethereum block 17034870 - // this test runs one segment of a zeth run on that block - println!("{name}"); - let segment = risc0_circuit_rv32im::execute::Segment::decode(bytes).unwrap(); - - let start = Instant::now(); - segment.execute().unwrap(); - let duration = start.elapsed(); - - let total_cycles = segment.suspend_cycle; - let throughput = (total_cycles as f64) / duration.as_secs_f64(); - self.results.push(PerformanceData { - name: name.into(), - hashfn: "N/A".into(), - cycles: total_cycles.into(), - duration, - ram: 0, - seal: 0, - throughput, - }); - } - - fn shapella30(&mut self) { - let bytes: &[u8] = include_bytes!("shapella-30.bin"); - self.shapella_segment("zeth_shapella_30", bytes); - } - - fn shapella50(&mut self) { - let bytes: &[u8] = include_bytes!("shapella-50.bin"); - self.shapella_segment("zeth_shapella_50", bytes); - } - - fn shapella100(&mut self) { - let bytes: &[u8] = include_bytes!("shapella-100.bin"); - self.shapella_segment("zeth_shapella_100", bytes); - } - fn warmup(&self) { println!("warmup");
risc0/zkvm/examples/loop.bin+0 −0 modifiedrisc0/zkvm/examples/loop.s+3 −2 modified@@ -24,11 +24,12 @@ _start: # NOTE: We don't check for errors since we assume the host will provide # correct input li t0, 2 # `ecall::SOFTWARE` + li t6, 12 # `Syscall::Read` la a0, count # Set syscall buffer pointer - li a1, 1 # Set syscall buffer length in words + li a1, 4 # Set syscall buffer length in bytes la a2, sys_read # Set syscall name C string li a3, 0 # Set read file to `STDIN_FILENO` - li a4, 4 # Set read length to 1 word + li a4, 4 # Set read length to 1 word (in bytes) ecall # `ecall(t0, a0, a1, a2, a3, a4)` # Prepare loop.
risc0/zkvm/methods/cfg/Cargo.lock+31 −1 modified@@ -759,6 +759,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1034,6 +1055,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1095,13 +1117,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1137,6 +1161,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
risc0/zkvm/methods/cpp-crates/Cargo.lock+33 −3 modified@@ -819,6 +819,27 @@ dependencies = [ "libc", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -836,9 +857,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pin-project-lite" @@ -1095,6 +1116,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1158,13 +1180,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.12", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1200,6 +1224,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.22"
risc0/zkvm/methods/env/Cargo.lock+31 −1 modified@@ -778,6 +778,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1050,6 +1071,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1111,13 +1133,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1153,6 +1177,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
risc0/zkvm/methods/guest/Cargo.lock+25 −1 modified@@ -1289,6 +1289,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", +] + [[package]] name = "objc" version = "0.2.7" @@ -1705,6 +1726,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1789,13 +1811,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.1", "libm", + "num_enum", + "paste", "stability", ]
risc0/zkvm/methods/heap/Cargo.lock+31 −1 modified@@ -814,6 +814,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1089,6 +1110,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1151,7 +1173,7 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", @@ -1160,6 +1182,8 @@ dependencies = [ "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1207,6 +1231,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
risc0/zkvm/methods/rand2/Cargo.lock+31 −1 modified@@ -752,6 +752,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + [[package]] name = "objc" version = "0.2.7" @@ -1004,6 +1025,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1066,13 +1088,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.2", "libm", + "num_enum", + "paste", "stability", ] @@ -1108,6 +1132,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.26"
risc0/zkvm/methods/rand/Cargo.lock+31 −1 modified@@ -759,6 +759,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1031,6 +1052,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1093,13 +1115,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ] @@ -1135,6 +1159,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "semver" version = "1.0.23"
risc0/zkvm/methods/std/Cargo.lock+25 −1 modified@@ -1305,6 +1305,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1747,6 +1768,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1826,13 +1848,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ]
risc0/zkvm/methods/std-ext/Cargo.lock+25 −1 modified@@ -1305,6 +1305,27 @@ dependencies = [ "libm", ] +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "objc" version = "0.2.7" @@ -1747,6 +1768,7 @@ version = "2.1.0" dependencies = [ "include_bytes_aligned", "no_std_strings", + "risc0-zkvm-platform", ] [[package]] @@ -1826,13 +1848,15 @@ dependencies = [ [[package]] name = "risc0-zkvm-platform" -version = "2.0.5" +version = "2.1.0" dependencies = [ "bytemuck", "cfg-if", "getrandom 0.2.15", "getrandom 0.3.3", "libm", + "num_enum", + "paste", "stability", ]
risc0/zkvm/platform/Cargo.toml+6 −2 modified@@ -1,14 +1,16 @@ [package] name = "risc0-zkvm-platform" description = "RISC Zero zero-knowledge VM" -version = "2.0.5" +version = "2.1.0" edition = { workspace = true } license = { workspace = true } homepage = { workspace = true } repository = { workspace = true } [dependencies] cfg-if = "1.0" +num_enum = { version = "0.7.4", default-features = false } +paste = "1.0.15" stability = "0.2" # This crate should have as few dependencies as possible so it can be @@ -20,7 +22,9 @@ embedded-alloc = { version = "0.6.0", features = [ "allocator_api", ], optional = true } getrandom = { version = "0.3", optional = true } -getrandom-v2 = { version = "0.2", package = "getrandom", features = ["custom"], optional = true } +getrandom-v2 = { version = "0.2", package = "getrandom", features = [ + "custom", +], optional = true } libm = { version = "0.2", optional = true } [package.metadata.docs.rs]
risc0/zkvm/platform/src/syscall.rs+170 −188 modified@@ -16,6 +16,9 @@ use core::arch::asm; use core::{cmp::min, ffi::CStr, ptr::null_mut, slice, str::Utf8Error}; +use num_enum::{FromPrimitive, IntoPrimitive}; +use paste::paste; + use crate::WORD_SIZE; pub mod ecall { @@ -149,15 +152,40 @@ pub mod nr { declare_syscall!(pub SYS_LOG); declare_syscall!(pub SYS_PANIC); declare_syscall!(pub SYS_PIPE); - declare_syscall!(pub SYS_PROVE_KECCAK); - declare_syscall!(pub SYS_PROVE_ZKR); + #[deprecated] + pub const SYS_PROVE_KECCAK: &str = ""; + #[deprecated] + pub const SYS_PROVE_ZKR: &str = ""; declare_syscall!(pub SYS_RANDOM); declare_syscall!(pub SYS_READ); declare_syscall!(pub SYS_VERIFY_INTEGRITY); declare_syscall!(pub SYS_VERIFY_INTEGRITY2); declare_syscall!(pub SYS_WRITE); } +#[repr(usize)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, IntoPrimitive, FromPrimitive)] +pub enum Syscall { + #[num_enum(catch_all)] + Unknown(usize) = 0, + Argc = 1, + Argv = 2, + CycleCount = 3, + Exit = 4, + Fork = 5, + Getenv = 6, + Keccak = 7, + Log = 8, + Panic = 9, + Pipe = 10, + Random = 11, + Read = 12, + User = 13, + VerifyIntegrity = 14, + VerifyIntegrity2 = 15, + Write = 16, +} + impl SyscallName { /// Converts a static C string to a system call name, if it is UTF-8. #[inline] @@ -199,63 +227,60 @@ pub struct Return(pub u32, pub u32); macro_rules! impl_syscall { ($func_name:ident - // Ugh, unfortunately we can't make this a regular macro list since the asm macro - // doesn't expand register names so in($register) doesn't work. - $(, $a0:ident - $(, $a1:ident - $(, $a2: ident - $(, $a3: ident - $(, $a4: ident - )? - )? - )? - )? - )?) => { + // Ugh, unfortunately we can't make this a regular macro list since the asm macro + // doesn't expand register names so in($register) doesn't work. + $(, $a0:ident $(, $a1:ident $(, $a2: ident $(, $a3: ident $(, $a4: ident )? )? )? )? )? + ) => { /// Invoke a raw system call /// /// # Safety /// /// `from_host` must be aligned and dereferenceable. #[cfg_attr(feature = "export-syscalls", unsafe(no_mangle))] - pub unsafe extern "C" fn $func_name(syscall: SyscallName, - from_host: *mut u32, - from_host_words: usize - $(,$a0: u32 - $(,$a1: u32 - $(,$a2: u32 - $(,$a3: u32 - $(,$a4: u32 - )? - )? - )? - )? - )? + #[deprecated] + pub unsafe extern "C" fn $func_name( + syscall_name: SyscallName, + from_host: *mut u32, + from_host_words: usize + $(,$a0: u32 $(,$a1: u32 $(,$a2: u32 $(,$a3: u32 $(,$a4: u32)? )? )? )? )? ) -> Return { - #[cfg(target_os = "zkvm")] { - let a0: u32; - let a1: u32; - unsafe { - ::core::arch::asm!( - "ecall", - in("t0") $crate::syscall::ecall::SOFTWARE, - inlateout("a0") from_host => a0, - inlateout("a1") from_host_words => a1, - in("a2") syscall.as_ptr() - $(,in("a3") $a0 - $(,in("a4") $a1 - $(,in("a5") $a2 - $(,in("a6") $a3 - $(,in("a7") $a4 - )? - )? - )? - )? - )?); + unimplemented!(); + } + + + paste! { + /// Invoke a raw system call + /// + /// # Safety + /// + /// `from_host` must be aligned and dereferenceable. + #[cfg_attr(feature = "export-syscalls", unsafe(no_mangle))] + pub unsafe extern "C" fn [<$func_name _nr>] ( + syscall: usize, + syscall_name: SyscallName, + from_host: *mut u32, + from_host_words: usize + $(,$a0: u32 $(,$a1: u32 $(,$a2: u32 $(,$a3: u32 $(,$a4: u32)? )? )? )? )? + ) -> Return { + #[cfg(target_os = "zkvm")] { + let a0: u32; + let a1: u32; + unsafe { + ::core::arch::asm!( + "ecall", + in("t0") $crate::syscall::ecall::SOFTWARE, + in("t6") syscall, + inlateout("a0") from_host => a0, + inlateout("a1") from_host_words => a1, + in("a2") syscall_name.as_ptr() + $(,in("a3") $a0 $(,in("a4") $a1 $(,in("a5") $a2 $(,in("a6") $a3 $(,in("a7") $a4 )? )? )? )? )? + ); + } + Return(a0, a1) } - Return(a0, a1) + #[cfg(not(target_os = "zkvm"))] + unimplemented!() } - #[cfg(not(target_os = "zkvm"))] - unimplemented!() } } } @@ -495,15 +520,24 @@ pub unsafe extern "C" fn sys_bigint( /// `recv_buf` must be aligned and dereferenceable. #[cfg_attr(feature = "export-syscalls", unsafe(no_mangle))] pub unsafe extern "C" fn sys_rand(recv_buf: *mut u32, words: usize) { - unsafe { syscall_0(nr::SYS_RANDOM, recv_buf, words) }; + unsafe { syscall_0_nr(Syscall::Random.into(), nr::SYS_RANDOM, recv_buf, words) }; } /// # Safety /// /// `msg_ptr` must be aligned and dereferenceable. #[cfg_attr(feature = "export-syscalls", unsafe(no_mangle))] pub unsafe extern "C" fn sys_panic(msg_ptr: *const u8, len: usize) -> ! { - unsafe { syscall_2(nr::SYS_PANIC, null_mut(), 0, msg_ptr as u32, len as u32) }; + unsafe { + syscall_2_nr( + Syscall::Panic.into(), + nr::SYS_PANIC, + null_mut(), + 0, + msg_ptr as u32, + len as u32, + ) + }; // As a fallback for non-compliant hosts, issue an illegal instruction. #[cfg(target_os = "zkvm")] @@ -518,15 +552,39 @@ pub unsafe extern "C" fn sys_panic(msg_ptr: *const u8, len: usize) -> ! { /// `msg_ptr` must be aligned and dereferenceable. #[cfg_attr(feature = "export-syscalls", unsafe(no_mangle))] pub unsafe extern "C" fn sys_log(msg_ptr: *const u8, len: usize) { - unsafe { syscall_2(nr::SYS_LOG, null_mut(), 0, msg_ptr as u32, len as u32) }; + unsafe { + syscall_2_nr( + Syscall::Log.into(), + nr::SYS_LOG, + null_mut(), + 0, + msg_ptr as u32, + len as u32, + ) + }; } #[cfg_attr(feature = "export-syscalls", unsafe(no_mangle))] pub extern "C" fn sys_cycle_count() -> u64 { - let Return(hi, lo) = unsafe { syscall_0(nr::SYS_CYCLE_COUNT, null_mut(), 0) }; + let Return(hi, lo) = unsafe { + syscall_0_nr( + Syscall::CycleCount.into(), + nr::SYS_CYCLE_COUNT, + null_mut(), + 0, + ) + }; ((hi as u64) << 32) + lo as u64 } +#[allow(dead_code)] +fn print(msg: &str) { + let msg = msg.as_bytes(); + unsafe { + sys_log(msg.as_ptr(), msg.len()); + } +} + /// Reads the given number of bytes into the given buffer, posix-style. Returns /// the number of bytes actually read. On end of file, returns 0. /// @@ -540,72 +598,19 @@ pub extern "C" fn sys_cycle_count() -> u64 { /// /// `recv_ptr` must be aligned and dereferenceable. #[cfg_attr(feature = "export-syscalls", unsafe(no_mangle))] -pub unsafe extern "C" fn sys_read(fd: u32, recv_ptr: *mut u8, nread: usize) -> usize { - // The SYS_READ system call can do a given number of word-aligned reads - // efficiently. The semantics of the system call are: - // - // (nread, word) = syscall_2(nr::SYS_READ, outbuf, - // num_words_in_outbuf, fd, nbytes); - // - // This reads exactly nbytes from the file descriptor, and fills the words - // in outbuf, followed by up to 4 bytes returned in "word", and fills - // the rest with NULs. It returns the number of bytes read. - // - // sys_read exposes this as a byte-aligned read by: - // * Copies any unaligned bytes at the start or end of the region. - - // Fills 0-3 bytes from a u32 into memory, returning the pointer afterwards. - unsafe fn fill_from_word(mut ptr: *mut u8, mut word: u32, nfill: usize) -> *mut u8 { - debug_assert!(nfill < 4, "nfill={nfill}"); - for _ in 0..nfill { - unsafe { *ptr = (word & 0xFF) as u8 }; - word >>= 8; - ptr = unsafe { ptr.add(1) }; - } - ptr - } - - // Determine how many bytes at the beginning of the buffer we have - // to read in order to become word-aligned. - let ptr_offset = (recv_ptr as usize) & (WORD_SIZE - 1); - let (main_ptr, main_requested, nread_first) = if ptr_offset == 0 { - (recv_ptr, nread, 0) - } else { - let unaligned_at_start = min(nread, WORD_SIZE - ptr_offset); - // Read unaligned bytes into "firstword". - let Return(nread_first, firstword) = - unsafe { syscall_2(nr::SYS_READ, null_mut(), 0, fd, unaligned_at_start as u32) }; - debug_assert_eq!(nread_first as usize, unaligned_at_start); - - // Align up to a word boundary to do the main copy. - let main_ptr = unsafe { fill_from_word(recv_ptr, firstword, unaligned_at_start) }; - if nread == unaligned_at_start { - // We only read part of a word, and don't have to read any full words. - return nread; - } - (main_ptr, nread - unaligned_at_start, nread_first as usize) - }; - - // Copy in all of the word-aligned data - let main_words = main_requested / WORD_SIZE; - let (nread_main, lastword) = - unsafe { sys_read_internal(fd, main_ptr as *mut u32, main_words, main_requested) }; - debug_assert!(nread_main <= main_requested); - let read_words = nread_main / WORD_SIZE; - - // Copy in individual bytes after the word-aligned section. - let unaligned_at_end = main_requested % WORD_SIZE; - - // The last 0-3 bytes are returned in lastword. Write those to complete the _requested_ read amount. - unsafe { - fill_from_word( - main_ptr.add(main_words * WORD_SIZE), - lastword, - unaligned_at_end, +pub unsafe extern "C" fn sys_read(fd: u32, recv_ptr: *mut u8, nbytes: usize) -> usize { + let Return(nbytes_read, final_word) = unsafe { + syscall_2_nr( + Syscall::Read.into(), + nr::SYS_READ, + recv_ptr as *mut u32, + nbytes, + fd, + nbytes as u32, ) }; - nread_first + nread_main + nbytes_read as usize } /// Reads up to the given number of words into the buffer [recv_buf, @@ -628,72 +633,36 @@ pub unsafe extern "C" fn sys_read(fd: u32, recv_ptr: *mut u8, nread: usize) -> u /// `nwords' size. #[cfg_attr(feature = "export-syscalls", unsafe(no_mangle))] pub unsafe extern "C" fn sys_read_words(fd: u32, recv_ptr: *mut u32, nwords: usize) -> usize { - unsafe { sys_read_internal(fd, recv_ptr, nwords, nwords * WORD_SIZE).0 } -} - -unsafe fn sys_read_internal( - fd: u32, - recv_ptr: *mut u32, - nwords: usize, - nbytes: usize, -) -> (usize, u32) { - let mut nwords_remain = nwords; - let mut nbytes_remain = nbytes; - let mut nread_total_bytes = 0; - let mut recv_ptr = recv_ptr; - let mut final_word = 0; - while nbytes_remain > 0 { - debug_assert!( - final_word == 0, - "host returned non-zero final word on a fully aligned read" - ); - let chunk_len = min(nbytes_remain, MAX_BUF_BYTES) as u32; - let Return(nread_bytes, last_word) = unsafe { - syscall_2( - nr::SYS_READ, - recv_ptr, - min(nwords_remain, MAX_BUF_WORDS), - fd, - chunk_len, - ) - }; - let nread_bytes = nread_bytes as usize; - let nread_words = nread_bytes / WORD_SIZE; - recv_ptr = unsafe { recv_ptr.add(nread_words) }; - final_word = last_word; - nwords_remain -= nread_words; - nread_total_bytes += nread_bytes; - nbytes_remain -= nread_bytes; - if nread_bytes < chunk_len as usize { - // We've reached EOF, and the host has returned a partial word. - break; - } - } - (nread_total_bytes, final_word) + let nbytes = nwords * WORD_SIZE; + let Return(nbytes_read, final_word) = unsafe { + syscall_2_nr( + Syscall::Read.into(), + nr::SYS_READ, + recv_ptr, + nbytes, + fd, + nbytes as u32, + ) + }; + nbytes_read as usize } /// # Safety /// /// `write_ptr` must be aligned and dereferenceable. #[cfg_attr(feature = "export-syscalls", unsafe(no_mangle))] pub unsafe extern "C" fn sys_write(fd: u32, write_ptr: *const u8, nbytes: usize) { - let mut nbytes_remain = nbytes; - let mut write_ptr = write_ptr; - while nbytes_remain > 0 { - let nbytes = min(nbytes_remain, MAX_BUF_BYTES); - unsafe { - syscall_3( - nr::SYS_WRITE, - null_mut(), - 0, - fd, - write_ptr as u32, - nbytes as u32, - ) - }; - write_ptr = unsafe { write_ptr.add(nbytes) }; - nbytes_remain -= nbytes; - } + unsafe { + syscall_3_nr( + Syscall::Write.into(), + nr::SYS_WRITE, + null_mut(), + 0, + fd, + write_ptr as u32, + nbytes as u32, + ) + }; } // Some environment variable names are considered safe by default to use in the guest, provided by @@ -747,7 +716,8 @@ pub unsafe extern "C" fn sys_getenv( } } let Return(a0, _) = unsafe { - syscall_2( + syscall_2_nr( + Syscall::Getenv.into(), nr::SYS_GETENV, out_words, out_nwords, @@ -772,7 +742,7 @@ pub extern "C" fn sys_argc() -> usize { const MSG: &[u8] = "sys_argc is disabled; can be enabled with the sys-args feature flag on risc0-zkvm-platform".as_bytes(); unsafe { sys_panic(MSG.as_ptr(), MSG.len()) }; } - let Return(a0, _) = unsafe { syscall_0(nr::SYS_ARGC, null_mut(), 0) }; + let Return(a0, _) = unsafe { syscall_0_nr(Syscall::Argc.into(), nr::SYS_ARGC, null_mut(), 0) }; a0 as usize } @@ -803,7 +773,15 @@ pub unsafe extern "C" fn sys_argv( const MSG: &[u8] = "sys_argv is disabled; can be enabled with the sys-args feature flag on risc0-zkvm-platform".as_bytes(); unsafe { sys_panic(MSG.as_ptr(), MSG.len()) }; } - let Return(a0, _) = unsafe { syscall_1(nr::SYS_ARGV, out_words, out_nwords, arg_index as u32) }; + let Return(a0, _) = unsafe { + syscall_1_nr( + Syscall::Argv.into(), + nr::SYS_ARGV, + out_words, + out_nwords, + arg_index as u32, + ) + }; a0 as usize } @@ -873,9 +851,10 @@ pub unsafe extern "C" fn sys_verify_integrity( to_host[..DIGEST_WORDS].copy_from_slice(unsafe { claim_digest.as_ref().unwrap_unchecked() }); to_host[DIGEST_WORDS..].copy_from_slice(unsafe { control_root.as_ref().unwrap_unchecked() }); + // Send the claim_digest to the host via software ecall. let Return(a0, _) = unsafe { - // Send the claim_digest to the host via software ecall. - syscall_2( + syscall_2_nr( + Syscall::VerifyIntegrity.into(), nr::SYS_VERIFY_INTEGRITY, null_mut(), 0, @@ -909,9 +888,10 @@ pub unsafe extern "C" fn sys_verify_integrity2( to_host[..DIGEST_WORDS].copy_from_slice(unsafe { claim_digest.as_ref().unwrap_unchecked() }); to_host[DIGEST_WORDS..].copy_from_slice(unsafe { control_root.as_ref().unwrap_unchecked() }); + // Send the claim_digest to the host via software ecall. let Return(a0, _) = unsafe { - // Send the claim_digest to the host via software ecall. - syscall_2( + syscall_2_nr( + Syscall::VerifyIntegrity2.into(), nr::SYS_VERIFY_INTEGRITY2, null_mut(), 0, @@ -949,7 +929,7 @@ unsafe extern "C" { #[cfg(feature = "export-syscalls")] #[unsafe(no_mangle)] pub extern "C" fn sys_fork() -> i32 { - let Return(a0, _) = unsafe { syscall_0(nr::SYS_FORK, null_mut(), 0) }; + let Return(a0, _) = unsafe { syscall_0_nr(Syscall::Fork.into(), nr::SYS_FORK, null_mut(), 0) }; a0 as i32 } @@ -972,7 +952,7 @@ pub extern "C" fn sys_fork() -> i32 { #[cfg(feature = "export-syscalls")] #[unsafe(no_mangle)] pub unsafe extern "C" fn sys_pipe(pipefd: *mut u32) -> i32 { - let Return(a0, _) = unsafe { syscall_0(nr::SYS_PIPE, pipefd, 2) }; + let Return(a0, _) = unsafe { syscall_0_nr(Syscall::Pipe.into(), nr::SYS_PIPE, pipefd, 2) }; a0 as i32 } @@ -982,7 +962,7 @@ pub unsafe extern "C" fn sys_pipe(pipefd: *mut u32) -> i32 { #[cfg(feature = "export-syscalls")] #[unsafe(no_mangle)] pub extern "C" fn sys_exit(status: i32) -> ! { - let Return(a0, _) = unsafe { syscall_0(nr::SYS_EXIT, null_mut(), 0) }; + let Return(a0, _) = unsafe { syscall_0_nr(Syscall::Exit.into(), nr::SYS_EXIT, null_mut(), 0) }; #[allow(clippy::empty_loop)] loop { // prevent dishonest provers from relying on the ability to prove the @@ -999,7 +979,8 @@ pub unsafe extern "C" fn sys_keccak( out_state: *mut [u64; KECCACK_STATE_DWORDS], ) -> i32 { let Return(a0, _) = unsafe { - syscall_3( + syscall_3_nr( + Syscall::Keccak.into(), nr::SYS_KECCAK, out_state as *mut u32, KECCACK_STATE_WORDS, @@ -1030,7 +1011,8 @@ pub unsafe extern "C" fn sys_prove_keccak( control_root: *const [u32; DIGEST_WORDS], ) { let Return(a0, _) = unsafe { - syscall_3( + syscall_3_nr( + Syscall::Keccak.into(), nr::SYS_KECCAK, null_mut(), 0,
risc0/zkvm/src/guest/env/mod.rs+4 −3 modified@@ -85,8 +85,8 @@ use bytemuck::Pod; use risc0_zkvm_platform::{ WORD_SIZE, align_up, fileno, syscall::{ - self, SyscallName, sys_cycle_count, sys_exit, sys_fork, sys_halt, sys_input, sys_log, - sys_pause, syscall_2, + self, Syscall, SyscallName, sys_cycle_count, sys_exit, sys_fork, sys_halt, sys_input, + sys_log, sys_pause, syscall_2_nr, }, }; use serde::{Serialize, de::DeserializeOwned}; @@ -193,7 +193,8 @@ pub fn pause(exit_code: u8) { /// Exchange data with the host. pub fn syscall(syscall: SyscallName, to_host: &[u8], from_host: &mut [u32]) -> syscall::Return { unsafe { - syscall_2( + syscall_2_nr( + Syscall::User.into(), syscall, from_host.as_mut_ptr(), from_host.len(),
risc0/zkvm/src/host/server/exec/profiler.rs+11 −7 modified@@ -55,6 +55,8 @@ use crate::{TraceCallback, TraceEvent}; type GimliReader = EndianRcSlice<RunTimeEndian>; type ObjectContext = Context<GimliReader>; +const USER_END_ADDR: u32 = 0xc000_0000; + /// Operations effecting the function call stack. #[derive(Debug)] enum CallStackOp { @@ -652,16 +654,18 @@ impl TraceCallback for Profiler { self.add_cycles_to_current_stack(cycles); - let mut update_stack = false; + if pc <= USER_END_ADDR { + let mut update_stack = false; - if let Some(op) = extract_call_stack_op(orig_insn) { - self.handle_function_call(op, pc, orig_pc, &mut update_stack)?; - } + if let Some(op) = extract_call_stack_op(orig_insn) { + self.handle_function_call(op, pc, orig_pc, &mut update_stack)?; + } - self.handle_inline_functions(pc, &mut update_stack); + self.handle_inline_functions(pc, &mut update_stack); - if update_stack { - self.update_stack(pc); + if update_stack { + self.update_stack(pc); + } } // Update pc, insn, and cycle
risc0/zkvm/src/host/server/exec/tests.rs+67 −40 modified@@ -49,9 +49,11 @@ use crate::{ }; fn execute_elf(env: ExecutorEnv, elf: &[u8]) -> Result<Session> { - ExecutorImpl::from_elf(env, elf) + let session = ExecutorImpl::from_elf(env, elf) .unwrap() - .run_with_callback(|segment| Ok(Box::new(SimpleSegmentRef::new(segment)))) + .run_with_callback(|segment| Ok(Box::new(SimpleSegmentRef::new(segment))))?; + session.log(); + Ok(session) } fn multi_test(spec: MultiTestSpec) { @@ -485,53 +487,78 @@ fn posix_style_read() { } } +#[rstest] +#[case(0, 0, b"abcdefghijkl")] +#[case(0, 1, b"abcdefghijkl")] +#[case(0, 2, b"abcdefghijkl")] +#[case(0, 3, b"abcdefghijkl")] +#[case(0, 4, b"\0\0\0\0efghijkl")] +#[case(0, 5, b"\0\0\0\0efghijkl")] +#[case(0, 6, b"\0\0\0\0efghijkl")] +#[case(0, 7, b"\0\0\0\0efghijkl")] +#[case(1, 0, b"Abcdefghijkl")] +#[case(1, 1, b"Abcdefghijkl")] +#[case(1, 2, b"Abcdefghijkl")] +#[case(1, 3, b"A\0\0\0efghijkl")] +#[case(1, 4, b"A\0\0\0efghijkl")] +#[case(1, 5, b"A\0\0\0efghijkl")] +#[case(1, 6, b"A\0\0\0efghijkl")] +#[case(1, 7, b"A\0\0\0\0\0\0\0ijkl")] +#[case(2, 0, b"ABcdefghijkl")] +#[case(2, 1, b"ABcdefghijkl")] +#[case(2, 2, b"AB\0\0efghijkl")] +#[case(2, 3, b"AB\0\0efghijkl")] +#[case(2, 4, b"AB\0\0efghijkl")] +#[case(2, 5, b"AB\0\0efghijkl")] +#[case(2, 6, b"AB\0\0\0\0\0\0ijkl")] +#[case(2, 7, b"AB\0\0\0\0\0\0ijkl")] +#[case(3, 0, b"ABCdefghijkl")] +#[case(3, 1, b"ABC\0efghijkl")] +#[case(3, 2, b"ABC\0efghijkl")] +#[case(3, 3, b"ABC\0efghijkl")] +#[case(3, 4, b"ABC\0efghijkl")] +#[case(3, 5, b"ABC\0\0\0\0\0ijkl")] +#[case(3, 6, b"ABC\0\0\0\0\0ijkl")] +#[case(3, 7, b"ABC\0\0\0\0\0ijkl")] #[test_log::test] -fn short_read_combinations() { +fn short_read_combinations( + #[case] read_len: usize, + #[case] excess_buffer: usize, + #[case] expected: &[u8], +) { const FD: u32 = 123; // Initial buffer to read bytes on top of. let buf: Vec<u8> = (b'a'..=b'l').collect(); // Input to read bytes from. let readbuf: Vec<u8> = (b'A'..b'L').collect(); - for read_len in 0..WORD_SIZE { - for excess_buffer in 0..WORD_SIZE * 2 { - let buffer = read_len + excess_buffer; - let mut expected = buf.to_vec(); - - expected[..read_len].copy_from_slice(&readbuf[..read_len]); + let buffer = read_len + excess_buffer; - // The current behaviour of the read call for more bytes than available is to write - // zeroes for the remaining bytes. - expected[read_len..buffer].fill(0); - - let spec = MultiTestSpec::SysRead { - fd: FD, - buf: buf.to_vec(), - pos_and_len: vec![(0, buffer as u32)], - }; - let env = ExecutorEnv::builder() - .read_fd(FD, &readbuf[..read_len]) - .write(&spec) - .unwrap() - .build() - .unwrap(); - let session = execute_elf(env, MULTI_TEST_ELF).unwrap(); - assert_eq!(session.exit_code, ExitCode::Halted(0)); + let spec = MultiTestSpec::SysRead { + fd: FD, + buf: buf.to_vec(), + pos_and_len: vec![(0, buffer as u32)], + }; + let env = ExecutorEnv::builder() + .read_fd(FD, &readbuf[..read_len]) + .write(&spec) + .unwrap() + .build() + .unwrap(); + let session = execute_elf(env, MULTI_TEST_ELF).unwrap(); + assert_eq!(session.exit_code, ExitCode::Halted(0)); - let (actual, num_read): (Vec<u8>, Vec<usize>) = - session.journal.unwrap().decode().unwrap(); - assert_eq!( - [read_len].as_slice(), - &num_read, - "length mismatch, length {read_len} buffer: {buffer}" - ); - assert_eq!( - from_utf8(&actual).unwrap(), - from_utf8(&expected).unwrap(), - "length {read_len}, buffer {buffer}" - ); - } - } + let (actual, num_read): (Vec<u8>, Vec<usize>) = session.journal.unwrap().decode().unwrap(); + assert_eq!( + [read_len].as_slice(), + &num_read, + "length mismatch, length {read_len} buffer: {buffer}" + ); + assert_eq!( + from_utf8(&actual).unwrap(), + from_utf8(expected).unwrap(), + "length {read_len}, buffer {buffer}" + ); } #[test_log::test]
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
5News mentions
0No linked articles in our index yet.