From 6d4ecff24b470b89992acd7314581379e66a0a9f Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Thu, 29 Apr 2021 00:21:37 -0400 Subject: [PATCH] Pin halo2 commit and update usage of pasta_curves accordingly --- Cargo.lock | 2 +- zebra-chain/Cargo.toml | 3 ++- zebra-chain/src/orchard/commitment.rs | 28 ++++++++++++++++----------- zebra-chain/src/orchard/keys.rs | 22 ++++++++++++--------- zebra-chain/src/orchard/sinsemilla.rs | 9 ++++++--- 5 files changed, 39 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 475205b5..d0f14a96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1510,7 +1510,7 @@ checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" [[package]] name = "halo2" version = "0.0.1" -source = "git+https://github.com/zcash/halo2.git?branch=main#b079624ea78b4a07d44cb3c725dd734093577062" +source = "git+https://github.com/zcash/halo2.git?rev=dda60a363001373d564156ad0334e2022d85a5b4#dda60a363001373d564156ad0334e2022d85a5b4" dependencies = [ "blake2b_simd", "crossbeam-utils 0.8.0", diff --git a/zebra-chain/Cargo.toml b/zebra-chain/Cargo.toml index 31c13225..ce2bf852 100644 --- a/zebra-chain/Cargo.toml +++ b/zebra-chain/Cargo.toml @@ -29,7 +29,8 @@ fpe = "0.4" funty = "=1.1.0" futures = "0.3" group = "0.9" -halo2 = { git = "https://github.com/zcash/halo2.git", branch = "main" } +# TODO: replace w/ crate version when released: https://github.com/ZcashFoundation/zebra/issues/2083 +halo2 = { git = "https://github.com/zcash/halo2.git", rev = "dda60a363001373d564156ad0334e2022d85a5b4"} hex = "0.4" jubjub = "0.6.0" lazy_static = "1.4.0" diff --git a/zebra-chain/src/orchard/commitment.rs b/zebra-chain/src/orchard/commitment.rs index a4180ff9..b49e8739 100644 --- a/zebra-chain/src/orchard/commitment.rs +++ b/zebra-chain/src/orchard/commitment.rs @@ -5,7 +5,7 @@ use std::{convert::TryFrom, fmt, io}; use bitvec::prelude::*; use group::{prime::PrimeCurveAffine, GroupEncoding}; use halo2::{ - arithmetic::{CurveAffine, FieldExt}, + arithmetic::{Coordinates, CurveAffine, FieldExt}, pasta::pallas, }; use lazy_static::lazy_static; @@ -61,10 +61,12 @@ impl fmt::Debug for NoteCommitment { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut d = f.debug_struct("NoteCommitment"); - match self.0.get_xy().into() { - Some((x, y)) => d - .field("x", &hex::encode(x.to_bytes())) - .field("y", &hex::encode(y.to_bytes())) + let option: Option> = self.0.coordinates().into(); + + match option { + Some(coordinates) => d + .field("x", &hex::encode(coordinates.x().to_bytes())) + .field("y", &hex::encode(coordinates.y().to_bytes())) .finish(), None => d .field("x", &hex::encode(pallas::Base::zero().to_bytes())) @@ -167,9 +169,11 @@ impl NoteCommitment { /// /// https://zips.z.cash/protocol/nu5.pdf#concreteextractorpallas pub fn extract_x(&self) -> pallas::Base { - match self.0.get_xy().into() { + let option: Option> = self.0.coordinates().into(); + + match option { // If Some, it's not the identity. - Some((x, _)) => x, + Some(coordinates) => *coordinates.x(), _ => pallas::Base::zero(), } } @@ -208,10 +212,12 @@ impl fmt::Debug for ValueCommitment { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut d = f.debug_struct("ValueCommitment"); - match self.0.get_xy().into() { - Some((x, y)) => d - .field("x", &hex::encode(x.to_bytes())) - .field("y", &hex::encode(y.to_bytes())) + let option: Option> = self.0.coordinates().into(); + + match option { + Some(coordinates) => d + .field("x", &hex::encode(coordinates.x().to_bytes())) + .field("y", &hex::encode(coordinates.y().to_bytes())) .finish(), None => d .field("x", &hex::encode(pallas::Base::zero().to_bytes())) diff --git a/zebra-chain/src/orchard/keys.rs b/zebra-chain/src/orchard/keys.rs index d41fe91b..4a210ae2 100644 --- a/zebra-chain/src/orchard/keys.rs +++ b/zebra-chain/src/orchard/keys.rs @@ -20,7 +20,7 @@ use bitvec::prelude::*; use fpe::ff1::{BinaryNumeralString, FF1}; use group::{Group, GroupEncoding}; use halo2::{ - arithmetic::{CurveAffine, FieldExt}, + arithmetic::{Coordinates, CurveAffine, FieldExt}, pasta::pallas, }; use rand_core::{CryptoRng, RngCore}; @@ -854,10 +854,12 @@ impl fmt::Debug for TransmissionKey { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut d = f.debug_struct("TransmissionKey"); - match self.0.get_xy().into() { - Some((x, y)) => d - .field("x", &hex::encode(x.to_bytes())) - .field("y", &hex::encode(y.to_bytes())) + let option: Option> = self.0.coordinates().into(); + + match option { + Some(coordinates) => d + .field("x", &hex::encode(coordinates.x().to_bytes())) + .field("y", &hex::encode(coordinates.y().to_bytes())) .finish(), None => d .field("x", &hex::encode(pallas::Base::zero().to_bytes())) @@ -917,10 +919,12 @@ impl fmt::Debug for EphemeralPublicKey { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut d = f.debug_struct("EphemeralPublicKey"); - match self.0.get_xy().into() { - Some((x, y)) => d - .field("x", &hex::encode(x.to_bytes())) - .field("y", &hex::encode(y.to_bytes())) + let option: Option> = self.0.coordinates().into(); + + match option { + Some(coordinates) => d + .field("x", &hex::encode(coordinates.x().to_bytes())) + .field("y", &hex::encode(coordinates.y().to_bytes())) .finish(), None => d .field("x", &hex::encode(pallas::Base::zero().to_bytes())) diff --git a/zebra-chain/src/orchard/sinsemilla.rs b/zebra-chain/src/orchard/sinsemilla.rs index a11d358c..2abefd5f 100644 --- a/zebra-chain/src/orchard/sinsemilla.rs +++ b/zebra-chain/src/orchard/sinsemilla.rs @@ -3,7 +3,7 @@ use bitvec::prelude::*; use halo2::{ - arithmetic::{CurveAffine, CurveExt}, + arithmetic::{Coordinates, CurveAffine, CurveExt}, pasta::pallas, }; @@ -13,9 +13,12 @@ use halo2::{ /// /// [concreteextractorpallas]: https://zips.z.cash/protocol/nu5.pdf#concreteextractorpallas pub fn extract_p(point: pallas::Point) -> pallas::Base { - match pallas::Affine::from(point).get_xy().into() { + let option: Option> = + pallas::Affine::from(point).coordinates().into(); + + match option { // If Some, it's not the identity. - Some((x, _)) => x, + Some(coordinates) => *coordinates.x(), _ => pallas::Base::zero(), } }