Skip to content

Commit

Permalink
Initial VerifyHal implementation (risc0#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaub authored Sep 2, 2022
1 parent bff01ac commit 6882672
Show file tree
Hide file tree
Showing 24 changed files with 412 additions and 322 deletions.
86 changes: 4 additions & 82 deletions Cargo-guest.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,16 @@ version = 3

[[package]]
name = "anyhow"
version = "1.0.62"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305"
checksum = "a26fa4d7e3f2eebadf743988fc8aec9fa9a9e82611acafd77c1462ed6262440a"

[[package]]
name = "array-init"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfb6d71005dc22a708c7496eee5c8dc0300ee47355de6256c3b35b12b5fef596"

[[package]]
name = "block-buffer"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324"
dependencies = [
"generic-array",
]

[[package]]
name = "bytemuck"
version = "1.12.1"
Expand All @@ -49,35 +40,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "cpufeatures"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc948ebb96241bb40ab73effeb80d9f93afaad49359d159a5e61be51619fe813"
dependencies = [
"libc",
]

[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]

[[package]]
name = "digest"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
dependencies = [
"block-buffer",
"crypto-common",
]

[[package]]
name = "direct-cargo-bazel-deps"
version = "0.0.1"
Expand All @@ -91,25 +53,8 @@ dependencies = [
"rand",
"rand_core",
"serde",
"sha2",
]

[[package]]
name = "generic-array"
version = "0.14.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
dependencies = [
"typenum",
"version_check",
]

[[package]]
name = "libc"
version = "0.2.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5"

[[package]]
name = "log"
version = "0.4.17"
Expand All @@ -121,9 +66,9 @@ dependencies = [

[[package]]
name = "paste"
version = "1.0.8"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9423e2b32f7a043629287a536f21951e8c6a82482d0acb1eeebfc90bc2225b22"
checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1"

[[package]]
name = "proc-macro2"
Expand Down Expand Up @@ -178,17 +123,6 @@ dependencies = [
"syn",
]

[[package]]
name = "sha2"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]

[[package]]
name = "syn"
version = "1.0.99"
Expand All @@ -200,20 +134,8 @@ dependencies = [
"unicode-ident",
]

[[package]]
name = "typenum"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"

[[package]]
name = "unicode-ident"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"

[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
57 changes: 24 additions & 33 deletions Cargo-host.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ dependencies = [

[[package]]
name = "anyhow"
version = "1.0.62"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305"
checksum = "a26fa4d7e3f2eebadf743988fc8aec9fa9a9e82611acafd77c1462ed6262440a"

[[package]]
name = "array-init"
Expand Down Expand Up @@ -258,9 +258,9 @@ dependencies = [

[[package]]
name = "clap"
version = "3.2.18"
version = "3.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15f2ea93df33549dbe2e8eecd1ca55269d63ae0b3ba1f55db030817d1c2867f"
checksum = "68d43934757334b5c0519ff882e1ab9647ac0258b47c24c4f490d78e42697fd5"
dependencies = [
"atty",
"bitflags",
Expand Down Expand Up @@ -476,9 +476,9 @@ dependencies = [

[[package]]
name = "cxx"
version = "1.0.73"
version = "1.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "873c2e83af70859af2aaecd1f5d862f3790b747b1f4f50fb45a931d000ac0422"
checksum = "1d32d767d2d7d8126dc126b959f5bb3ddb07f7f5c4c21351983444c9826786b1"
dependencies = [
"cc",
"cxxbridge-flags",
Expand All @@ -488,9 +488,9 @@ dependencies = [

[[package]]
name = "cxx-build"
version = "1.0.73"
version = "1.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b49edea7163bbc7a39e3d829b4b0b66a9d30486973152842b7413f2c7b5632bf"
checksum = "5326718a190b4a42e517ab8471c286cb1b6310a631672d56dc0e61fa044daee4"
dependencies = [
"cc",
"codespan-reporting",
Expand All @@ -503,15 +503,15 @@ dependencies = [

[[package]]
name = "cxxbridge-flags"
version = "1.0.73"
version = "1.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46b787c15af80277db5c88c6ac6c502ae545e622f010e06f95e540d34931acf"
checksum = "53253a86460ad0d1f851f49ab57b45bfb5cfddf558ff714994fb599a64f0fc7a"

[[package]]
name = "cxxbridge-macro"
version = "1.0.73"
version = "1.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ba3f3a7efa46626878fb5d324fabca4d19d2956b6ae97ce43044ef4515f5abc"
checksum = "0e0e3dabc3f3f2c071a64cb39066234442bc0c15c7dbb64762e228cf0431589f"
dependencies = [
"proc-macro2",
"quote",
Expand Down Expand Up @@ -801,9 +801,9 @@ dependencies = [

[[package]]
name = "httparse"
version = "1.7.1"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c"
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"

[[package]]
name = "httpdate"
Expand Down Expand Up @@ -1234,9 +1234,9 @@ dependencies = [

[[package]]
name = "paste"
version = "1.0.8"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9423e2b32f7a043629287a536f21951e8c6a82482d0acb1eeebfc90bc2225b22"
checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1"

[[package]]
name = "pbkdf2"
Expand Down Expand Up @@ -1561,7 +1561,7 @@ dependencies = [
name = "risc0-make-id"
version = "0.11.1"
dependencies = [
"clap 3.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 3.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
"risc0-zkvm",
]

Expand All @@ -1573,7 +1573,7 @@ dependencies = [
"assert_cmd",
"assert_fs",
"bytemuck",
"clap 3.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 3.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger",
"risc0-zkvm",
"risc0-zkvm-methods",
Expand Down Expand Up @@ -1625,7 +1625,6 @@ dependencies = [
"risc0-zkp",
"risc0-zkvm-circuit",
"risc0-zkvm-methods",
"risc0-zkvm-methods-verify",
"risc0-zkvm-platform",
"risc0-zkvm-sys",
"serde",
Expand Down Expand Up @@ -1671,14 +1670,6 @@ dependencies = [
"serde",
]

[[package]]
name = "risc0-zkvm-methods-verify"
version = "0.1.0"
dependencies = [
"risc0-build",
"serde",
]

[[package]]
name = "risc0-zkvm-platform"
version = "0.11.1"
Expand Down Expand Up @@ -1869,9 +1860,9 @@ dependencies = [

[[package]]
name = "sha1"
version = "0.10.1"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c77f4e7f65455545c2153c1253d25056825e77ee2533f0e41deb65a93a34852f"
checksum = "5cf2781a4ca844dd4f9b608a1791eea19830df0ad3cdd9988cd05f1c66ccb63a"
dependencies = [
"cfg-if",
"cpufeatures",
Expand All @@ -1880,9 +1871,9 @@ dependencies = [

[[package]]
name = "sha2"
version = "0.10.2"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676"
checksum = "899bf02746a2c92bf1053d9327dadb252b01af1f81f90cdb902411f518bc7215"
dependencies = [
"cfg-if",
"cpufeatures",
Expand All @@ -1900,9 +1891,9 @@ dependencies = [

[[package]]
name = "socket2"
version = "0.4.6"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10c98bba371b9b22a71a9414e420f92ddeb2369239af08200816169d5e2dd7aa"
checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd"
dependencies = [
"libc",
"winapi",
Expand Down
5 changes: 0 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@ crates_repository(
"cfg-if": crate.spec(version = "1.0"),
"log": crate.spec(version = "0.4"),
"paste": crate.spec(version = "1.0"),
"sha2": crate.spec(
default_features = False,
features = ["compress"],
version = "0.10",
),
"rand": crate.spec(
default_features = False,
features = ["small_rng"],
Expand Down
2 changes: 1 addition & 1 deletion risc0/zkp/rust/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ risc0_rust_library_pair(
"@crates_guest//:rand",
"@crates_guest//:rand_core",
"@crates_guest//:serde",
"@crates_guest//:sha2",
],
guest_features = ["verify"],
guest_proc_macro_deps = [
Expand All @@ -34,6 +33,7 @@ risc0_rust_library_pair(
],
host_features = [
"hal",
"host",
"prove",
"std",
"verify",
Expand Down
7 changes: 4 additions & 3 deletions risc0/zkp/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ harness = false
anyhow = { version = "1.0", default-features = false }
array-init = { version = "2.0", optional = true }
bytemuck = { version = "1.9", features = ["derive"] }
log = "0.4"
log = { version = "0.4", optional = true }
ndarray = { version = "0.15", optional = true, features = ["rayon"] }
paste = "1.0"
rand = { version = "0.8", default-features = false, features = ["small_rng"] }
Expand All @@ -29,8 +29,9 @@ criterion = "0.3"
rand = { version = "0.8", features = ["small_rng"] }

[features]
default = ["prove", "std", "verify"]
default = ["host", "prove", "std", "verify"]
hal = ["dep:ndarray", "dep:rayon"]
prove = ["dep:array-init", "dep:sha2", "hal", "rand/std", "rand/std_rng"]
host = ["dep:log"]
prove = ["dep:array-init", "dep:log", "dep:sha2", "hal", "rand/std", "rand/std_rng"]
std = []
verify = []
6 changes: 5 additions & 1 deletion risc0/zkp/rust/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use anyhow::{bail, Result};
use crate::{
core::{fp::Fp, fp4::Fp4},
field::Elem,
taps::TapSet,
taps::{RegisterGroup, TapSet},
INV_RATE,
};

Expand Down Expand Up @@ -258,6 +258,10 @@ pub trait PolyExt {

pub trait TapsProvider {
fn get_taps(&self) -> &'static TapSet<'static>;

fn code_size(&self) -> usize {
self.get_taps().group_size(RegisterGroup::Code)
}
}

pub trait CircuitInfo {
Expand Down
2 changes: 1 addition & 1 deletion risc0/zkp/rust/src/core/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use alloc::vec;
use super::fp4::Fp4;
use crate::field::Elem;

/// Evaluate a polynomial whose coeffients are in the extension field at a
/// Evaluate a polynomial whose coefficients are in the extension field at a
/// point.
pub fn poly_eval(coeffs: &[Fp4], x: Fp4) -> Fp4 {
let mut mul = Fp4::ONE;
Expand Down
Loading

0 comments on commit 6882672

Please sign in to comment.