diff --git a/contracts/license/CHANGELOG.md b/contracts/license/CHANGELOG.md index 809307b164..c8bcae8d87 100644 --- a/contracts/license/CHANGELOG.md +++ b/contracts/license/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Changed 'use_license' to check if license already nullified [#1051] - Changed 'get_licenses' to return values by adding 'pos' to every license returned [#1040] - Changed 'issue_license' by removing the 'pos' argument and self position determination [#1039] +- Fixed `license` tests error when creating `PublicParameters` from a slice ## [0.1.0] - 2023-07-13 diff --git a/contracts/license/tests/license.rs b/contracts/license/tests/license.rs index 64b2f412f3..b6a9c2266e 100644 --- a/contracts/license/tests/license.rs +++ b/contracts/license/tests/license.rs @@ -337,7 +337,8 @@ fn use_license_get_session() { let rng = &mut StdRng::seed_from_u64(0xbeef); let crs = get_common_reference_string().expect("getting CRS file works"); - let pp = unsafe { PublicParameters::from_slice_unchecked(crs.as_slice()) }; + let pp = PublicParameters::from_slice(crs.as_slice()) + .expect("PublicParameters failed to be created from slice."); let (prover, verifier) = Compiler::compile::(&pp, LABEL) .expect("Compiling circuit should succeed"); diff --git a/rusk-profile/src/lib.rs b/rusk-profile/src/lib.rs index 7d45c6ca8e..47b7a0a2bf 100644 --- a/rusk-profile/src/lib.rs +++ b/rusk-profile/src/lib.rs @@ -19,11 +19,12 @@ pub use theme::Theme; mod circuit; pub use circuit::Circuit; -/// HEX representaion of the SHA-256 hash of the CRS uncompressed bytes. +/// HEX representation of the SHA-256 hash of the CRS uncompressed bytes. +/// This is the hash of the contribution number 15 of the Dusk Trusted Setup. pub static CRS_17_HASH: &str = - "18b48f588fd4d1e88ef9e7b3cacfa29046f6f489c5c237a4b01ee4f0334772a5"; + "6161605616b62356cf09fa28252c672ef53b2c8489ad5f81d87af26e105f6059"; -const CRS_FNAME: &str = "dev-piecrust.crs"; +const CRS_FNAME: &str = "devnet-piecrust.crs"; fn extension(p: &Path) -> Option<&str> { p.extension()?.to_str() diff --git a/rusk-recovery/CHANGELOG.md b/rusk-recovery/CHANGELOG.md index 9a7c24c776..4b2e5cf741 100644 --- a/rusk-recovery/CHANGELOG.md +++ b/rusk-recovery/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed 'phoenix-core' dependency [#1139] - Added closure argument to the 'deploy' method [#1630] +- Update Plonk to 0.20 +- Download CRS from URL ### Removed diff --git a/rusk-recovery/Cargo.toml b/rusk-recovery/Cargo.toml index 084ae25106..3e4a1435f6 100644 --- a/rusk-recovery/Cargo.toml +++ b/rusk-recovery/Cargo.toml @@ -12,7 +12,7 @@ path = "src/lib.rs" [dependencies] dusk-bytes = "0.1" -dusk-plonk = { version = "0.19", features = ["rkyv-impl"] } +dusk-plonk = { version = "0.20", features = ["rkyv-impl"] } hex = "0.4" rand = "0.8" once_cell = "1.13" @@ -24,6 +24,9 @@ url = "2.3" flate2 = "1" tar = "0.4" cargo_toml = "0.15" +reqwest = "0.12" +tokio = { version = "1", features = ["full"] } +lazy_static = "1.5" license-circuits = { version = "0.1", path = "../circuits/license" } diff --git a/rusk-recovery/src/keys.rs b/rusk-recovery/src/keys.rs index aa99217b0a..0e3970e738 100644 --- a/rusk-recovery/src/keys.rs +++ b/rusk-recovery/src/keys.rs @@ -10,34 +10,54 @@ use execution_core::{ transfer::phoenix::TRANSCRIPT_LABEL, }; use once_cell::sync::Lazy; -use rand::rngs::StdRng; -use rand::SeedableRng; -use std::io; +use std::{ + io, + sync::{mpsc, Mutex}, + thread, +}; use rusk_profile::Circuit as CircuitProfile; +use lazy_static::lazy_static; use tracing::{info, warn}; mod circuits; +lazy_static! { + static ref CRS_URL: Mutex = Mutex::new(String::default()); +} + static PUB_PARAMS: Lazy = Lazy::new(|| { let theme = Theme::default(); info!("{} CRS from cache", theme.action("Fetching")); match rusk_profile::get_common_reference_string() { - Ok(buff) if rusk_profile::verify_common_reference_string(&buff) => unsafe { - let pp = PublicParameters::from_slice_unchecked(&buff[..]); + Ok(buff) if rusk_profile::verify_common_reference_string(&buff) => { + let pp = PublicParameters::from_slice(&buff[..]) + .expect("Creating PublicParameters from slice failed."); info!("{} CRS", theme.info("Loaded")); pp - }, + } _ => { - warn!("{} new CRS due to cache miss", theme.warn("Building")); - let mut rng = StdRng::seed_from_u64(0xbeef); - - let pp = PublicParameters::setup(1 << 17, &mut rng) - .expect("Cannot initialize Public Parameters"); - - rusk_profile::set_common_reference_string(pp.to_raw_var_bytes()) + warn!( + "{} CRS from server due to cache miss", + theme.warn("Fetching") + ); + let (tx, rx) = mpsc::channel(); + + thread::spawn(move || { + let pp_bytes = + fetch_pp().expect("PublicParameters download failed."); + tx.send(pp_bytes).unwrap(); + }) + .join() + .expect("PublicParameters download thread panicked"); + + let pp_bytes = rx.recv().unwrap(); + let pp = PublicParameters::from_slice(pp_bytes.as_slice()) + .expect("Creating PublicParameters from slice failed."); + + rusk_profile::set_common_reference_string(pp_bytes) .expect("Unable to write the CRS"); info!("{} CRS", theme.info("Cached")); @@ -47,6 +67,15 @@ static PUB_PARAMS: Lazy = Lazy::new(|| { } }); +#[tokio::main] +async fn fetch_pp() -> Result, Box> { + let crs_url = CRS_URL.lock().expect("Unlocking failed.").to_string(); + + let response = reqwest::get(crs_url).await?.bytes().await?; + + Ok(response.to_vec()) +} + fn check_circuits_cache( circuit_list: Vec, ) -> Result<(), io::Error> { @@ -116,7 +145,12 @@ fn run_stored_circuits_checks( check_circuits_cache(circuit_list).map(|_| ()) } -pub fn exec(keep_circuits: bool) -> Result<(), Box> { +pub fn exec( + keep_circuits: bool, + crs_url: String, +) -> Result<(), Box> { + *CRS_URL.lock().expect("Unlocking failed.") = crs_url; + // This force init is needed to check CRS and create it (if not available) // See also: https://github.com/dusk-network/rusk/issues/767 Lazy::force(&PUB_PARAMS); diff --git a/rusk/CHANGELOG.md b/rusk/CHANGELOG.md index 40b7d79493..02b65de283 100644 --- a/rusk/CHANGELOG.md +++ b/rusk/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add TLS support for HTTP server - Add iteration generator to FailedIterations [#1257] - Add `node` feature flag [#1144] +- Add `RUSK_CRS_URL` environment variable ### Changed diff --git a/rusk/src/bin/args/command.rs b/rusk/src/bin/args/command.rs index 4b130b3ac3..564855c2e9 100644 --- a/rusk/src/bin/args/command.rs +++ b/rusk/src/bin/args/command.rs @@ -18,6 +18,14 @@ pub enum Command { /// Keeps untracked keys #[clap(short, long, value_parser = BoolishValueParser::new(), env = "RUSK_KEEP_KEYS")] keep: bool, + + /// URL of the server to download the CRS from + #[clap( + long, + default_value = "https://nodes.dusk.network/trusted-setup", + env = "RUSK_CRS_URL" + )] + crs_url: String, }, #[cfg(feature = "recovery-state")] @@ -64,8 +72,8 @@ impl Command { output, } => super::state::recovery_state(init, force, output), #[cfg(feature = "recovery-keys")] - Self::RecoveryKeys { keep } => { - rusk_recovery_tools::keys::exec(keep) + Self::RecoveryKeys { keep, crs_url } => { + rusk_recovery_tools::keys::exec(keep, crs_url) } };