Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Halo2 verifier service #2645

Merged
merged 22 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ecf1fad
First pass at async Halo2 verification service
dconnolly Aug 20, 2021
225300c
Halo2 verifier service and test
dconnolly Nov 6, 2021
1aff29d
Remove redundant conversion
dconnolly Nov 6, 2021
506f04a
Test async halo2 verifier service with pre-computed Orchard shielded …
dconnolly Nov 11, 2021
77fea70
Fix typo
dconnolly Nov 11, 2021
820021f
Assert future result is_ok() in Halo2 verifier test
dconnolly Nov 11, 2021
a13956f
Shorten tower::Service trait constraints for Halo2 verifier tests
dconnolly Nov 11, 2021
57f4855
Remove commented out trait constraints
dconnolly Nov 11, 2021
fac0b3e
.expect() vs .unwrap() to parse orchard::redpallas::VerificationKey
dconnolly Nov 11, 2021
3fc6c5d
Use .to_vec() for some test vectors
dconnolly Nov 12, 2021
4ec0842
Fix self-referential Display impl
dconnolly Nov 12, 2021
93dbeee
Fix deps
dconnolly Nov 12, 2021
804cfaf
Distinguish orchard vs zebra_chain::orchard imports
dconnolly Nov 12, 2021
e907547
Add test that halo2 verifier fails with malformed proof inputs
dconnolly Nov 12, 2021
b50b8ce
Use thiserror for Halo2Error
dconnolly Nov 13, 2021
ce93931
Use ZcashFoundation/orchard instead of dconnolly/orchard
dconnolly Nov 13, 2021
09dc2af
Add a link to the issue to remove the zfnd fork of orchard crate
dconnolly Nov 13, 2021
148fa71
Update zebra-consensus/Cargo.toml
dconnolly Nov 15, 2021
6946e79
Add note
dconnolly Nov 16, 2021
f19cc64
Move artificial Orchard shielded data test vectors to zebra-test
dconnolly Nov 16, 2021
0ac71f7
Align brackets
dconnolly Nov 16, 2021
6607633
Tidy some trait constraints and debug statements
dconnolly Nov 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ panic = "abort"
# TODO: remove these after a new librustzcash release.
# These are librustzcash requirements specified in its workspace Cargo.toml that we must replicate here
incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree", rev = "b7bd6246122a6e9ace8edb51553fbf5228906cbb" }
orchard = { git = "https://github.com/zcash/orchard.git", rev = "2c8241f25b943aa05203eacf9905db117c69bd29" }
# TODO: replace with upstream orchard when these changes are merged
# https://github.com/ZcashFoundation/zebra/issues/3056
orchard = { git = "https://github.com/ZcashFoundation/orchard.git", rev = "568e24cd5f129158375d7ac7d98c89ebff4f982f" }
zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "53d0a51d33a421cb76d3e3124d1e4c1c9036068e" }
zcash_primitives = { git = "https://github.com/zcash/librustzcash.git", rev = "53d0a51d33a421cb76d3e3124d1e4c1c9036068e" }
2 changes: 1 addition & 1 deletion zebra-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ hex = "0.4"
incrementalmerkletree = "0.1.0"
jubjub = "0.8.0"
lazy_static = "1.4.0"
orchard = { git = "https://github.com/zcash/orchard.git", rev = "2c8241f25b943aa05203eacf9905db117c69bd29" }
orchard = "0.0"
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
rand_core = "0.6"
ripemd160 = "0.9"
secp256k1 = { version = "0.20.3", features = ["serde"] }
Expand Down
6 changes: 6 additions & 0 deletions zebra-chain/src/orchard/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,12 @@ impl fmt::Debug for EphemeralPublicKey {

impl Eq for EphemeralPublicKey {}

impl From<EphemeralPublicKey> for [u8; 32] {
fn from(epk: EphemeralPublicKey) -> [u8; 32] {
epk.0.to_bytes()
}
}

impl From<&EphemeralPublicKey> for [u8; 32] {
fn from(epk: &EphemeralPublicKey) -> [u8; 32] {
epk.0.to_bytes()
Expand Down
48 changes: 36 additions & 12 deletions zebra-chain/src/orchard/note/ciphertexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ use crate::serialization::{serde_helpers, SerializationError, ZcashDeserialize,
///
/// Corresponds to the Orchard 'encCiphertext's
#[derive(Deserialize, Serialize)]
pub struct EncryptedNote(#[serde(with = "serde_helpers::BigArray")] pub [u8; 580]);

impl fmt::Debug for EncryptedNote {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("EncryptedNote")
.field(&hex::encode(&self.0[..]))
.finish()
}
}
pub struct EncryptedNote(#[serde(with = "serde_helpers::BigArray")] pub(crate) [u8; 580]);

// These impls all only exist because of array length restrictions.
// TODO: use const generics https://github.com/ZcashFoundation/zebra/issues/2042
Expand All @@ -29,14 +21,34 @@ impl Clone for EncryptedNote {
}
}

impl fmt::Debug for EncryptedNote {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("EncryptedNote")
.field(&hex::encode(&self.0[..]))
.finish()
}
}

impl Eq for EncryptedNote {}

impl From<[u8; 580]> for EncryptedNote {
fn from(bytes: [u8; 580]) -> Self {
EncryptedNote(bytes)
}
}

impl From<EncryptedNote> for [u8; 580] {
fn from(enc_ciphertext: EncryptedNote) -> Self {
enc_ciphertext.0
}
}

impl PartialEq for EncryptedNote {
fn eq(&self, other: &Self) -> bool {
self.0[..] == other.0[..]
}
}

impl Eq for EncryptedNote {}

impl ZcashSerialize for EncryptedNote {
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
writer.write_all(&self.0[..])?;
Expand All @@ -56,7 +68,7 @@ impl ZcashDeserialize for EncryptedNote {
///
/// Corresponds to Orchard's 'outCiphertext'
#[derive(Deserialize, Serialize)]
pub struct WrappedNoteKey(#[serde(with = "serde_helpers::BigArray")] pub [u8; 80]);
pub struct WrappedNoteKey(#[serde(with = "serde_helpers::BigArray")] pub(crate) [u8; 80]);

impl fmt::Debug for WrappedNoteKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand All @@ -78,6 +90,18 @@ impl Clone for WrappedNoteKey {
}
}

impl From<[u8; 80]> for WrappedNoteKey {
fn from(bytes: [u8; 80]) -> Self {
WrappedNoteKey(bytes)
}
}

impl From<WrappedNoteKey> for [u8; 80] {
fn from(out_ciphertext: WrappedNoteKey) -> Self {
out_ciphertext.0
}
}

impl PartialEq for WrappedNoteKey {
fn eq(&self, other: &Self) -> bool {
self.0[..] == other.0[..]
Expand Down
4 changes: 2 additions & 2 deletions zebra-chain/src/sapling/note/ciphertexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::serialization::{serde_helpers, SerializationError, ZcashDeserialize,
///
/// Corresponds to the Sapling 'encCiphertext's
#[derive(Deserialize, Serialize)]
pub struct EncryptedNote(#[serde(with = "serde_helpers::BigArray")] pub [u8; 580]);
pub struct EncryptedNote(#[serde(with = "serde_helpers::BigArray")] pub(crate) [u8; 580]);

impl fmt::Debug for EncryptedNote {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -55,7 +55,7 @@ impl ZcashDeserialize for EncryptedNote {
///
/// Corresponds to Sapling's 'outCiphertext'
#[derive(Deserialize, Serialize)]
pub struct WrappedNoteKey(#[serde(with = "serde_helpers::BigArray")] pub [u8; 80]);
pub struct WrappedNoteKey(#[serde(with = "serde_helpers::BigArray")] pub(crate) [u8; 80]);

impl fmt::Debug for WrappedNoteKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
6 changes: 5 additions & 1 deletion zebra-consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ bellman = "0.11.1"
bls12_381 = "0.6.0"
chrono = "0.4.19"
displaydoc = "0.2.2"
halo2 = "=0.1.0-beta.1"
jubjub = "0.8.0"
lazy_static = "1.4.0"
once_cell = "1.8"
# TODO: replace with upstream orchard when these changes are merged
dconnolly marked this conversation as resolved.
Show resolved Hide resolved
# https://github.com/ZcashFoundation/zebra/issues/3056
orchard = "0.0.0"
rand = "0.8"
serde = { version = "1", features = ["serde_derive"] }

Expand All @@ -42,7 +46,7 @@ proptest-derive = { version = "0.3.0", optional = true }

[dev-dependencies]
color-eyre = "0.5.11"
halo2 = "=0.1.0-beta.1"
hex = "0.4.3"
proptest = "0.10"
proptest-derive = "0.3.0"
rand07 = { package = "rand", version = "0.7" }
Expand Down
1 change: 1 addition & 0 deletions zebra-consensus/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub mod ed25519;
pub mod groth16;
pub mod halo2;
pub mod redjubjub;
pub mod redpallas;

Expand Down
Loading