Skip to content

Commit

Permalink
Implement Async Batch verification API for groth16
Browse files Browse the repository at this point in the history
This PR is the first step in getting a groth16 proving system fully
integrated with the rest of zebra. This PR implements the initial async
API, but none of the actual batching logic necessary for our eventual
verifier design.

Once the batch verification API from bellman has been implemented we
will need to swap out the "Batch" type defined in this crate with the
new `batch::Verifier` defined in bellman.
  • Loading branch information
yaahc committed Feb 5, 2021
1 parent 1e156a5 commit 0d9287f
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 44 deletions.
125 changes: 114 additions & 11 deletions Cargo.lock

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

20 changes: 18 additions & 2 deletions tower-batch/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ use super::{

use crate::semaphore::Semaphore;
use futures_core::ready;
use std::task::{Context, Poll};
use std::{
fmt,
task::{Context, Poll},
};
use tokio::sync::{mpsc, oneshot};
use tower::Service;

/// Allows batch processing of requests.
///
/// See the module documentation for more details.
#[derive(Debug)]
pub struct Batch<T, Request>
where
T: Service<BatchControl<Request>>,
Expand All @@ -35,6 +37,20 @@ where
handle: Handle,
}

impl<T, Request> fmt::Debug for Batch<T, Request>
where
T: Service<BatchControl<Request>>,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = std::any::type_name::<Self>();
f.debug_struct(name)
.field("tx", &self.tx)
.field("semaphore", &self.semaphore)
.field("handle", &self.handle)
.finish()
}
}

impl<T, Request> Batch<T, Request>
where
T: Service<BatchControl<Request>>,
Expand Down
3 changes: 3 additions & 0 deletions zebra-consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ once_cell = "1.5"
rand = "0.7"
redjubjub = "0.2"
serde = { version = "1", features = ["serde_derive"] }
bellman = "0.8"
bls12_381 = "0.3.1"

futures = "0.3.12"
futures-util = "0.3.6"
Expand All @@ -28,6 +30,7 @@ tower-batch = { path = "../tower-batch/" }
zebra-chain = { path = "../zebra-chain" }
zebra-state = { path = "../zebra-state" }
zebra-script = { path = "../zebra-script" }
pairing = "0.18.0"

[dev-dependencies]
color-eyre = "0.5.10"
Expand Down
8 changes: 8 additions & 0 deletions zebra-consensus/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@ pub mod redjubjub;

/// The maximum batch size for any of the batch verifiers.
const MAX_BATCH_SIZE: usize = 64;

/// The maximum latency bound for any of the batch verifiers.
const MAX_BATCH_LATENCY: std::time::Duration = std::time::Duration::from_millis(100);

/// The size of the buffer in the broadcast channels used by batch verifiers.
///
/// This bound limits the number of concurrent batches for each verifier.
/// If tasks delay checking for verifier results, and the bound is too small,
/// new batches will be rejected with `RecvError`s.
const BROADCAST_BUFFER_SIZE: usize = 512;
Loading

0 comments on commit 0d9287f

Please sign in to comment.