risc0 / risc0

RISC Zero is a zero-knowledge verifiable general computing platform based on zk-STARKs and the RISC-V microarchitecture.

Home Page:https://risczero.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Arkworks not compatible with Risc-0

MBelegris opened this issue · comments

Bug Report

I am trying to peform bls signature verification in Risc-0 and am using Arkworks to do so. I create a new risc-0 project and cargo add ark-ff, ark-std (which work) and then add ark-ec or any ark curve and it does not build. It throws an error related to ahash:

guest_code_for_zk_proof: error[E0658]: use of unstable library feature 'build_hasher_simple_hash_one'
guest_code_for_zk_proof:    --> /home/mike/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ahash-0.8.11/src/random_state.rs:463:5
guest_code_for_zk_proof:     |
guest_code_for_zk_proof: 463 | /     fn hash_one<T: Hash>(&self, x: T) -> u64 {
guest_code_for_zk_proof: 464 | |         RandomState::hash_one(self, x)
guest_code_for_zk_proof: 465 | |     }
guest_code_for_zk_proof:     | |_____^
guest_code_for_zk_proof:     |
guest_code_for_zk_proof:     = note: see issue #86161 <https://github.com/rust-lang/rust/issues/86161> for more information
guest_code_for_zk_proof:     = help: add `#![feature(build_hasher_simple_hash_one)]` to the crate attributes to enable
guest_code_for_zk_proof: 
guest_code_for_zk_proof: For more information about this error, try `rustc --explain E0658`.
guest_code_for_zk_proof: error: could not compile `ahash` (lib) due to 1 previous error

Steps to Reproduce

  1. cargo risczero new my_project --guest-name guest_code_for_zk_proof
  2. In guest code: cargo add ark-std ark-ff ark-ec
  3. cargo build

Expected behavior

Should build with no error.

Your Environment

  • risc0-zkvm version: 0.20.1
  • Rust version: 1.76.0
  • Platform/OS: Ubuntu
  • ark-ec = "0.4.2"
  • ark-ff = "0.4.2"
  • ark-std = "0.4.0"

You issue seems to be related to the crate ahash not having access to getrandom in the guest. You have, at least, two options:

  1. enable the getrandom feature on the risc0-zkvm crate
  2. Add something like this to your guest dependencies: ahash = { version = "=0.8.6", default-features = false, features = ["compile-time-rng"] }

The first option will expose a getrandom implementation that uses the sys_random ecall, i.e., your guest will get randomness from the host.
The second option will generate random numbers at compile time and embed them in the binary.

Fixed: I used the second method and it works. Thank you