From 9dc8d76d68889a66824bb12c345fba9427ae039e Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Fri, 16 Oct 2020 12:50:29 -0700 Subject: [PATCH] consensus: add stub groth16::Verifier Co-authored-by: Deirdre Connolly --- Cargo.lock | 1 + zebra-consensus/Cargo.toml | 3 +- zebra-consensus/src/primitives.rs | 1 + zebra-consensus/src/primitives/groth16.rs | 55 +++++++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 zebra-consensus/src/primitives/groth16.rs diff --git a/Cargo.lock b/Cargo.lock index d4b115a7..58904032 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3186,6 +3186,7 @@ dependencies = [ "displaydoc", "futures", "futures-util", + "jubjub 0.5.1", "metrics", "once_cell", "rand 0.7.3", diff --git a/zebra-consensus/Cargo.toml b/zebra-consensus/Cargo.toml index 8270752b..1752e9d5 100644 --- a/zebra-consensus/Cargo.toml +++ b/zebra-consensus/Cargo.toml @@ -8,6 +8,8 @@ edition = "2018" [dependencies] chrono = "0.4.19" color-eyre = "0.5" +displaydoc = "0.1.7" +jubjub = "0.5.1" once_cell = "1.4" rand = "0.7" redjubjub = "0.2" @@ -28,7 +30,6 @@ tower-batch = { path = "../tower-batch/" } zebra-chain = { path = "../zebra-chain" } zebra-state = { path = "../zebra-state" } zebra-script = { path = "../zebra-script" } -displaydoc = "0.1.7" [dev-dependencies] rand = "0.7" diff --git a/zebra-consensus/src/primitives.rs b/zebra-consensus/src/primitives.rs index 4887c127..47b28023 100644 --- a/zebra-consensus/src/primitives.rs +++ b/zebra-consensus/src/primitives.rs @@ -1,5 +1,6 @@ //! Asynchronous verification of cryptographic primitives. +pub mod groth16; pub mod redjubjub; /// The maximum batch size for any of the batch verifiers. diff --git a/zebra-consensus/src/primitives/groth16.rs b/zebra-consensus/src/primitives/groth16.rs new file mode 100644 index 00000000..63471068 --- /dev/null +++ b/zebra-consensus/src/primitives/groth16.rs @@ -0,0 +1,55 @@ +use std::{ + future::Future, + pin::Pin, + task::{Context, Poll}, +}; + +use tower::Service; + +use zebra_chain::primitives::Groth16Proof; + +use crate::BoxError; + +/// Provides verification of Groth16 proofs for a specific statement. +/// +/// Groth16 proofs require a proof verification key; the [`Verifier`] type is +/// responsible for ownership of the PVK. +pub struct Verifier { + // XXX this needs to hold on to a verification key +} + +impl Verifier { + /// Create a new Groth16 verifier, supplying the encoding of the verification key. + pub fn new(_encoded_verification_key: &[u8]) -> Result { + // parse and turn into a bellman type, + // so that users don't have to have the entire bellman api + unimplemented!(); + } +} + +// XXX this is copied from the WIP batch bellman impl, +// in the future, replace with a re export + +pub struct Item { + pub proof: Groth16Proof, + pub public_inputs: Vec, +} + +// XXX in the future, Verifier will implement +// Service>> and be wrapped in a Batch +// to get a Service +// but for now, just implement Service and do unbatched verif. +//impl Service> for Verifier { +impl Service for Verifier { + type Response = (); + type Error = BoxError; + type Future = Pin> + Send + 'static>>; + + fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { + Poll::Ready(Ok(())) + } + + fn call(&mut self, _req: Item) -> Self::Future { + unimplemented!() + } +}