diff --git a/Cargo.lock b/Cargo.lock index 54df9ed3..17c64a7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3836,12 +3836,11 @@ dependencies = [ [[package]] name = "serde-big-array" -version = "0.3.2" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18b20e7752957bbe9661cff4e0bb04d183d0948cdab2ea58cdb9df36a61dfe62" +checksum = "3323f09a748af288c3dc2474ea6803ee81f118321775bffa3ac8f7e65c5e90e7" dependencies = [ "serde", - "serde_derive", ] [[package]] diff --git a/zebra-chain/Cargo.toml b/zebra-chain/Cargo.toml index b32a191f..610bb842 100644 --- a/zebra-chain/Cargo.toml +++ b/zebra-chain/Cargo.toml @@ -39,7 +39,7 @@ rand_core = "0.6.3" ripemd160 = "0.9" serde = { version = "1.0.136", features = ["serde_derive", "rc"] } secp256k1 = { version = "0.21.3", features = ["serde"] } -serde-big-array = "0.3.2" +serde-big-array = "0.4.1" sha2 = { version = "0.9.9", features=["compress"] } static_assertions = "1.1.0" subtle = "2.4.1" diff --git a/zebra-chain/src/lib.rs b/zebra-chain/src/lib.rs index 0c30728b..755cd48c 100644 --- a/zebra-chain/src/lib.rs +++ b/zebra-chain/src/lib.rs @@ -11,8 +11,6 @@ #[macro_use] extern crate serde; -#[macro_use] -extern crate serde_big_array; #[macro_use] extern crate bitflags; diff --git a/zebra-chain/src/orchard/note/ciphertexts.rs b/zebra-chain/src/orchard/note/ciphertexts.rs index 29a09a0c..ecc69002 100644 --- a/zebra-chain/src/orchard/note/ciphertexts.rs +++ b/zebra-chain/src/orchard/note/ciphertexts.rs @@ -1,12 +1,14 @@ use std::{fmt, io}; -use crate::serialization::{serde_helpers, SerializationError, ZcashDeserialize, ZcashSerialize}; +use serde_big_array::BigArray; + +use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; /// A ciphertext component for encrypted output notes. /// /// Corresponds to the Orchard 'encCiphertext's #[derive(Deserialize, Serialize)] -pub struct EncryptedNote(#[serde(with = "serde_helpers::BigArray")] pub(crate) [u8; 580]); +pub struct EncryptedNote(#[serde(with = "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 @@ -68,7 +70,7 @@ impl ZcashDeserialize for EncryptedNote { /// /// Corresponds to Orchard's 'outCiphertext' #[derive(Deserialize, Serialize)] -pub struct WrappedNoteKey(#[serde(with = "serde_helpers::BigArray")] pub(crate) [u8; 80]); +pub struct WrappedNoteKey(#[serde(with = "BigArray")] pub(crate) [u8; 80]); impl fmt::Debug for WrappedNoteKey { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/zebra-chain/src/primitives/proofs/bctv14.rs b/zebra-chain/src/primitives/proofs/bctv14.rs index 8fd22da0..9d7e51d0 100644 --- a/zebra-chain/src/primitives/proofs/bctv14.rs +++ b/zebra-chain/src/primitives/proofs/bctv14.rs @@ -1,12 +1,13 @@ use std::{fmt, io}; use serde::{Deserialize, Serialize}; +use serde_big_array::BigArray; -use crate::serialization::{serde_helpers, SerializationError, ZcashDeserialize, ZcashSerialize}; +use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; /// An encoding of a BCTV14 proof, as used in Zcash. #[derive(Serialize, Deserialize)] -pub struct Bctv14Proof(#[serde(with = "serde_helpers::BigArray")] pub [u8; 296]); +pub struct Bctv14Proof(#[serde(with = "BigArray")] pub [u8; 296]); impl fmt::Debug for Bctv14Proof { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/zebra-chain/src/primitives/proofs/groth16.rs b/zebra-chain/src/primitives/proofs/groth16.rs index 8e4b9add..f2bca69e 100644 --- a/zebra-chain/src/primitives/proofs/groth16.rs +++ b/zebra-chain/src/primitives/proofs/groth16.rs @@ -1,11 +1,13 @@ -use serde::{Deserialize, Serialize}; use std::{fmt, io}; -use crate::serialization::{serde_helpers, SerializationError, ZcashDeserialize, ZcashSerialize}; +use serde::{Deserialize, Serialize}; +use serde_big_array::BigArray; + +use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; /// An encoding of a Groth16 proof, as used in Zcash. #[derive(Serialize, Deserialize)] -pub struct Groth16Proof(#[serde(with = "serde_helpers::BigArray")] pub [u8; 192]); +pub struct Groth16Proof(#[serde(with = "BigArray")] pub [u8; 192]); impl fmt::Debug for Groth16Proof { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/zebra-chain/src/primitives/zcash_history.rs b/zebra-chain/src/primitives/zcash_history.rs index 5dd4bef6..0df4c3d7 100644 --- a/zebra-chain/src/primitives/zcash_history.rs +++ b/zebra-chain/src/primitives/zcash_history.rs @@ -9,6 +9,7 @@ mod tests; use std::{collections::BTreeMap, convert::TryInto, io, sync::Arc}; +use serde_big_array::BigArray; pub use zcash_history::{V1, V2}; use crate::{ @@ -18,8 +19,6 @@ use crate::{ sapling, }; -big_array! { BigArray; zcash_history::MAX_ENTRY_SIZE } - /// A trait to represent a version of `Tree`. pub trait Version: zcash_history::Version { /// Convert a Block into the NodeData for this version. diff --git a/zebra-chain/src/sapling/note/ciphertexts.rs b/zebra-chain/src/sapling/note/ciphertexts.rs index 9bdd443c..394e78f6 100644 --- a/zebra-chain/src/sapling/note/ciphertexts.rs +++ b/zebra-chain/src/sapling/note/ciphertexts.rs @@ -1,12 +1,14 @@ use std::{fmt, io}; -use crate::serialization::{serde_helpers, SerializationError, ZcashDeserialize, ZcashSerialize}; +use serde_big_array::BigArray; + +use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; /// A ciphertext component for encrypted output notes. /// /// Corresponds to the Sapling 'encCiphertext's #[derive(Deserialize, Serialize)] -pub struct EncryptedNote(#[serde(with = "serde_helpers::BigArray")] pub(crate) [u8; 580]); +pub struct EncryptedNote(#[serde(with = "BigArray")] pub(crate) [u8; 580]); impl fmt::Debug for EncryptedNote { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -55,7 +57,7 @@ impl ZcashDeserialize for EncryptedNote { /// /// Corresponds to Sapling's 'outCiphertext' #[derive(Deserialize, Serialize)] -pub struct WrappedNoteKey(#[serde(with = "serde_helpers::BigArray")] pub(crate) [u8; 80]); +pub struct WrappedNoteKey(#[serde(with = "BigArray")] pub(crate) [u8; 80]); impl fmt::Debug for WrappedNoteKey { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/zebra-chain/src/serialization/serde_helpers.rs b/zebra-chain/src/serialization/serde_helpers.rs index 9d462543..f87d28c9 100644 --- a/zebra-chain/src/serialization/serde_helpers.rs +++ b/zebra-chain/src/serialization/serde_helpers.rs @@ -1,17 +1,5 @@ use group::GroupEncoding; use halo2::{arithmetic::FieldExt, pasta::pallas}; -use serde_big_array::big_array; - -big_array! { - BigArray; - + 1344, // `EquihashSolution` - 80, // `sapling::OutCiphertext` - 580, // `sapling::EncryptedCiphertext` - 601, // `sprout::EncryptedCiphertext` - 296, // `Bctv14Proof` - 196, // `Groth16Proof` -} - #[derive(Deserialize, Serialize)] #[serde(remote = "jubjub::AffinePoint")] pub struct AffinePoint { diff --git a/zebra-chain/src/sprout/note/ciphertexts.rs b/zebra-chain/src/sprout/note/ciphertexts.rs index 818ca0ef..b6d07a6f 100644 --- a/zebra-chain/src/sprout/note/ciphertexts.rs +++ b/zebra-chain/src/sprout/note/ciphertexts.rs @@ -1,14 +1,15 @@ use std::{fmt, io}; use serde::{Deserialize, Serialize}; +use serde_big_array::BigArray; -use crate::serialization::{serde_helpers, SerializationError, ZcashDeserialize, ZcashSerialize}; +use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; /// A ciphertext component for encrypted output notes. /// /// Corresponds to the Sprout 'encCiphertext's #[derive(Serialize, Deserialize)] -pub struct EncryptedNote(#[serde(with = "serde_helpers::BigArray")] pub [u8; 601]); +pub struct EncryptedNote(#[serde(with = "BigArray")] pub [u8; 601]); impl fmt::Debug for EncryptedNote { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/zebra-chain/src/work/equihash.rs b/zebra-chain/src/work/equihash.rs index a7d7666b..38f34abf 100644 --- a/zebra-chain/src/work/equihash.rs +++ b/zebra-chain/src/work/equihash.rs @@ -2,11 +2,13 @@ use std::{fmt, io}; +use serde_big_array::BigArray; + use crate::{ block::Header, serialization::{ - serde_helpers, zcash_serialize_bytes, SerializationError, ZcashDeserialize, - ZcashDeserializeInto, ZcashSerialize, + zcash_serialize_bytes, SerializationError, ZcashDeserialize, ZcashDeserializeInto, + ZcashSerialize, }, }; @@ -28,7 +30,7 @@ pub(crate) const SOLUTION_SIZE: usize = 1344; /// The size of an Equihash solution in bytes is always 1344 so the /// length of this type is fixed. #[derive(Deserialize, Serialize)] -pub struct Solution(#[serde(with = "serde_helpers::BigArray")] pub [u8; SOLUTION_SIZE]); +pub struct Solution(#[serde(with = "BigArray")] pub [u8; SOLUTION_SIZE]); impl Solution { /// The length of the portion of the header used as input when verifying