Skip to content

Commit

Permalink
Enable WASM compilation on proof mod
Browse files Browse the repository at this point in the history
  • Loading branch information
aterentic-ethernal committed Nov 25, 2024
1 parent 521f01c commit d6b78dd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.0.5

- Enable WASM compilation on proof mod
- Enable WASM compilation on utils and shutdown mods
- Allocate new port on each new dial attempt
- Set different dial conditions for bootstrap process and diagnostics API
Expand Down
10 changes: 5 additions & 5 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
# Internal deps
avail-rust = { workspace = true }
dusk-plonk = { workspace = true }

# 3rd-party
better-panic = "0.3.0"
codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full", "bit-vec"] }
color-eyre = { workspace = true }
derive_more = { version = "1", features = ["from"] }
dusk-bytes = "0.1.7"
futures = { workspace = true }
getrandom = { version = "0.2.15", features = ["js"] }
itertools = "0.10.5"
strip-ansi-escapes = "0.2.0"
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# Internal deps
dusk-plonk = { workspace = true }

# 3rd-party
async-std = { workspace = true }
async-stream = "0.3.5"
async-trait = { workspace = true }
Expand All @@ -39,7 +38,6 @@ derive_more = { version = "1", features = ["from"] }
futures = { workspace = true }
hex = { workspace = true }
hyper = { version = "0.14.23", features = ["full", "http1"] }
itertools = "0.10.5"
jsonrpsee-core = { version = "0.21.0", features = ["client"] }
libc = "0.2.150"
libp2p = { workspace = true }
Expand Down Expand Up @@ -79,7 +77,9 @@ strum = { version = "0.26.3", features = ["derive"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
blake2b_simd = "1.0.2"
rand = { workspace = true, features = ["std_rng"] }
thiserror-no-std = "2.0.2"
tokio_with_wasm = { version = "0.7.1", default-features = false, features = ["sync", "macros", "rt", "time"] }
web-time = "1.1.0"

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
hex-literal = "0.4.1"
Expand Down
1 change: 0 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub mod light_client;
pub mod maintenance;
#[cfg(not(target_arch = "wasm32"))]
pub mod network;
#[cfg(not(target_arch = "wasm32"))]
pub mod proof;
pub mod shutdown;
#[cfg(not(target_arch = "wasm32"))]
Expand Down
45 changes: 25 additions & 20 deletions core/src/proof.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
//! Parallelized proof verification
use avail_rust::kate_recovery::{
data::Cell,
matrix::{Dimensions, Position},
proof,
};
use color_eyre::eyre;
use dusk_plonk::commitment_scheme::kzg10::PublicParameters;
use futures::future::join_all;
use itertools::{Either, Itertools};

Check warning on line 8 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / cargo test

unused import: `Itertools`

Check failure on line 8 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / wasm

unused import: `Itertools`

Check failure on line 8 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / cargo clippy

unused import: `Itertools`
use std::sync::Arc;
use tokio::{task::JoinSet, time::Instant};
use tracing::{debug, Instrument};
#[cfg(not(target_arch = "wasm32"))]
use tokio::time::Instant;
use tracing::debug;
#[cfg(target_arch = "wasm32")]
use web_time::Instant;

mod core;

Check failure on line 16 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / cargo test

file not found for module `core`

Check failure on line 16 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / wasm

file not found for module `core`

Check failure on line 16 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / cargo clippy

file not found for module `core`

use crate::utils::spawn_in_span;

async fn verify_proof(
public_parameters: Arc<PublicParameters>,
dimensions: Dimensions,
commitment: [u8; 48],
cell: Cell,
) -> Result<(Position, bool), proof::Error> {
proof::verify(&public_parameters, dimensions, &commitment, &cell)
) -> Result<(Position, bool), core::Error> {

Check failure on line 25 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / cargo test

cannot find type `Error` in module `core`

Check failure on line 25 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / cargo test

cannot find type `Error` in module `core`

Check failure on line 25 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / wasm

cannot find type `Error` in module `core`

Check failure on line 25 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / cargo clippy

cannot find type `Error` in module `core`
core::verify(&public_parameters, dimensions, &commitment, &cell)

Check failure on line 26 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / cargo test

cannot find function `verify` in module `core`

Check failure on line 26 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / wasm

cannot find function `verify` in module `core`

Check failure on line 26 in core/src/proof.rs

View workflow job for this annotation

GitHub Actions / cargo clippy

cannot find function `verify` in module `core`
.map(|verified| (cell.position, verified))
}

Expand All @@ -36,24 +41,24 @@ pub async fn verify(

let start_time = Instant::now();

let mut tasks = JoinSet::new();

for cell in cells {
tasks.spawn(
verify_proof(
let tasks = cells
.iter()
.map(|cell| {
spawn_in_span(verify_proof(
public_parameters.clone(),
dimensions,
commitments[cell.position.row as usize],
cell.clone(),
)
.in_current_span(),
);
}
))
})
.collect::<Vec<_>>();

let join_results: Vec<_> = join_all(tasks)
.await
.into_iter()
.collect::<Result<_, _>>()?;

let mut results = Vec::with_capacity(cells.len());
while let Some(result) = tasks.join_next().await {
results.push(result??)
}
let results: Vec<(Position, bool)> = join_results.into_iter().collect::<Result<_, _>>()?;

debug!(block_num, duration = ?start_time.elapsed(), "Proof verification completed");

Expand Down

0 comments on commit d6b78dd

Please sign in to comment.