Merge pull request #645 from nuttycom/fix_beta_lints

Fix problems identified by clippy's beta lints
This commit is contained in:
Kris Nuttycombe 2022-09-17 15:49:49 -06:00 committed by GitHub
commit 6cb0d21219
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 92 additions and 107 deletions

View File

@ -170,7 +170,7 @@ fn generate_hash(base_state: &Blake2bState, i: u32) -> Blake2bHash {
fn expand_array(vin: &[u8], bit_len: usize, byte_pad: usize) -> Vec<u8> {
assert!(bit_len >= 8);
assert!(8 * size_of::<u32>() >= 7 + bit_len);
assert!(u32::BITS as usize >= 7 + bit_len);
let out_width = (bit_len + 7) / 8 + byte_pad;
let out_len = 8 * out_width * vin.len() / bit_len;
@ -221,7 +221,7 @@ fn indices_from_minimal(p: Params, minimal: &[u8]) -> Result<Vec<u32>, Error> {
}
assert!(((c_bit_len + 1) + 7) / 8 <= size_of::<u32>());
let len_indices = 8 * size_of::<u32>() * minimal.len() / (c_bit_len + 1);
let len_indices = u32::BITS as usize * minimal.len() / (c_bit_len + 1);
let byte_pad = size_of::<u32>() - ((c_bit_len + 1) + 7) / 8;
let mut csr = Cursor::new(expand_array(minimal, c_bit_len + 1, byte_pad));

View File

@ -6,7 +6,7 @@ use crate::kind::unified::Encoding;
use crate::{kind::*, AddressKind, Network, ZcashAddress};
/// An error while attempting to parse a string as a Zcash address.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum ParseError {
/// The string is an invalid encoding.
InvalidEncoding,

View File

@ -7,9 +7,9 @@ pub(crate) const MAINNET: [u8; 2] = [0x16, 0x9a];
/// The prefix for a Base58Check-encoded testnet Sprout address.
///
/// Defined in the [Zcash Protocol Specification section 5.6.3][].
/// Defined in the [Zcash Protocol Specification section 5.6.3][sproutpaymentaddrencoding].
///
/// []: https://zips.z.cash/protocol/protocol.pdf#sproutpaymentaddrencoding
/// [sproutpaymentaddrencoding]: https://zips.z.cash/protocol/protocol.pdf#sproutpaymentaddrencoding
pub(crate) const TESTNET: [u8; 2] = [0x16, 0xb6];
pub(crate) type Data = [u8; 64];

View File

@ -105,7 +105,7 @@ impl Typecode {
}
/// An error while attempting to parse a string as a Zcash address.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum ParseError {
/// The unified container contains both P2PKH and P2SH items.
BothP2phkAndP2sh,

View File

@ -263,7 +263,7 @@ mod tests {
validate_chain(
&tests::network(),
&db_cache,
(&db_data).get_max_height_hash().unwrap(),
db_data.get_max_height_hash().unwrap(),
)
.unwrap();
@ -280,7 +280,7 @@ mod tests {
validate_chain(
&tests::network(),
&db_cache,
(&db_data).get_max_height_hash().unwrap(),
db_data.get_max_height_hash().unwrap(),
)
.unwrap();
@ -292,7 +292,7 @@ mod tests {
validate_chain(
&tests::network(),
&db_cache,
(&db_data).get_max_height_hash().unwrap(),
db_data.get_max_height_hash().unwrap(),
)
.unwrap();
@ -309,7 +309,7 @@ mod tests {
validate_chain(
&tests::network(),
&db_cache,
(&db_data).get_max_height_hash().unwrap(),
db_data.get_max_height_hash().unwrap(),
)
.unwrap();
@ -320,7 +320,7 @@ mod tests {
validate_chain(
&tests::network(),
&db_cache,
(&db_data).get_max_height_hash().unwrap(),
db_data.get_max_height_hash().unwrap(),
)
.unwrap();
}
@ -362,7 +362,7 @@ mod tests {
validate_chain(
&tests::network(),
&db_cache,
(&db_data).get_max_height_hash().unwrap(),
db_data.get_max_height_hash().unwrap(),
)
.unwrap();
@ -386,7 +386,7 @@ mod tests {
match validate_chain(
&tests::network(),
&db_cache,
(&db_data).get_max_height_hash().unwrap(),
db_data.get_max_height_hash().unwrap(),
) {
Err(SqliteClientError::BackendError(Error::InvalidChain(lower_bound, _))) => {
assert_eq!(lower_bound, sapling_activation_height() + 2)
@ -432,7 +432,7 @@ mod tests {
validate_chain(
&tests::network(),
&db_cache,
(&db_data).get_max_height_hash().unwrap(),
db_data.get_max_height_hash().unwrap(),
)
.unwrap();
@ -456,7 +456,7 @@ mod tests {
match validate_chain(
&tests::network(),
&db_cache,
(&db_data).get_max_height_hash().unwrap(),
db_data.get_max_height_hash().unwrap(),
) {
Err(SqliteClientError::BackendError(Error::InvalidChain(lower_bound, _))) => {
assert_eq!(lower_bound, sapling_activation_height() + 3)

View File

@ -1318,7 +1318,7 @@ mod tests {
);
// We can't get an anchor height, as we have not scanned any blocks.
assert_eq!((&db_data).get_target_and_anchor_heights(10).unwrap(), None);
assert_eq!(db_data.get_target_and_anchor_heights(10).unwrap(), None);
// An invalid account has zero balance
assert!(get_address(&db_data, AccountId::from(1)).is_err());

View File

@ -412,10 +412,7 @@ mod tests {
scan_cached_blocks(&tests::network(), &db_cache, &mut db_write, None).unwrap();
// Verified balance matches total balance
let (_, anchor_height) = (&db_data)
.get_target_and_anchor_heights(10)
.unwrap()
.unwrap();
let (_, anchor_height) = db_data.get_target_and_anchor_heights(10).unwrap().unwrap();
assert_eq!(get_balance(&db_data, AccountId::from(0)).unwrap(), value);
assert_eq!(
get_balance_at(&db_data, AccountId::from(0), anchor_height).unwrap(),
@ -428,10 +425,7 @@ mod tests {
scan_cached_blocks(&tests::network(), &db_cache, &mut db_write, None).unwrap();
// Verified balance does not include the second note
let (_, anchor_height2) = (&db_data)
.get_target_and_anchor_heights(10)
.unwrap()
.unwrap();
let (_, anchor_height2) = db_data.get_target_and_anchor_heights(10).unwrap().unwrap();
assert_eq!(
get_balance(&db_data, AccountId::from(0)).unwrap(),
(value + value).unwrap()
@ -790,10 +784,7 @@ mod tests {
scan_cached_blocks(&tests::network(), &db_cache, &mut db_write, None).unwrap();
// Verified balance matches total balance
let (_, anchor_height) = (&db_data)
.get_target_and_anchor_heights(10)
.unwrap()
.unwrap();
let (_, anchor_height) = db_data.get_target_and_anchor_heights(10).unwrap().unwrap();
assert_eq!(get_balance(&db_data, AccountId::from(0)).unwrap(), value);
assert_eq!(
get_balance_at(&db_data, AccountId::from(0), anchor_height).unwrap(),

View File

@ -35,10 +35,10 @@ use zcash_primitives::{
mod open {
pub const MODE: u32 = 0;
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub struct Precondition(pub [u8; 32]);
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub struct Witness(pub [u8; 32]);
}
@ -46,15 +46,15 @@ mod open {
mod close {
pub const MODE: u32 = 1;
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub struct Precondition(pub [u8; 32]);
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub struct Witness(pub [u8; 32]);
}
/// The precondition type for the demo extension.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum Precondition {
Open(open::Precondition),
Close(close::Precondition),
@ -74,7 +74,7 @@ impl Precondition {
/// Errors that may be produced during parsing and verification of demo preconditions and
/// witnesses.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
/// Parse error indicating that the payload of the condition or the witness was
/// not 32 bytes.
@ -156,7 +156,7 @@ impl ToPayload for Precondition {
}
/// The witness type for the demo extension.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum Witness {
Open(open::Witness),
Close(close::Witness),

View File

@ -23,7 +23,7 @@ pub const MAX_NODE_DATA_SIZE: usize = 32 + // subtree commitment
/// V1 node metadata.
#[repr(C)]
#[derive(Debug, Clone, Default)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct NodeData {
/// Consensus branch id, should be provided by deserializing node.
pub consensus_branch_id: u32,
@ -171,7 +171,7 @@ impl NodeData {
/// V2 node metadata.
#[derive(Debug, Clone, Default)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct V2 {
/// The V1 node data retained in V2.
pub v1: NodeData,

View File

@ -187,7 +187,7 @@ pub trait Parameters: Clone {
}
/// Marker struct for the production network.
#[derive(PartialEq, Copy, Clone, Debug)]
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct MainNetwork;
pub const MAIN_NETWORK: MainNetwork = MainNetwork;
@ -236,7 +236,7 @@ impl Parameters for MainNetwork {
}
/// Marker struct for the test network.
#[derive(PartialEq, Copy, Clone, Debug)]
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct TestNetwork;
pub const TEST_NETWORK: TestNetwork = TestNetwork;
@ -284,7 +284,7 @@ impl Parameters for TestNetwork {
}
}
#[derive(PartialEq, Copy, Clone, Debug)]
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum Network {
MainNetwork,
TestNetwork,
@ -445,7 +445,7 @@ pub const ZIP212_GRACE_PERIOD: u32 = 32256;
/// See [ZIP 200](https://zips.z.cash/zip-0200) for more details.
///
/// [`signature_hash`]: crate::transaction::sighash::signature_hash
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum BranchId {
/// The consensus rules at the launch of Zcash.
Sprout,

View File

@ -8,7 +8,7 @@ use crate::transaction::components::{
};
/// A typesafe wrapper for witness payloads
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AuthData(pub Vec<u8>);
/// Binary parsing capability for TZE preconditions & witnesses.
@ -37,7 +37,7 @@ pub trait ToPayload {
/// used inside of a transaction, and extension-specific types. The payload field of this struct is
/// treated as opaque to all but the extension corresponding to the encapsulated `extension_id`
/// value.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Precondition {
pub extension_id: u32,
pub mode: u32,
@ -69,7 +69,7 @@ impl Precondition {
/// used inside of a transaction, and extension-specific types. The payload field of this struct is
/// treated as opaque to all but the extension corresponding to the encapsulated `extension_id`
/// value.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Witness<T> {
pub extension_id: u32,
pub mode: u32,
@ -105,7 +105,7 @@ impl Witness<AuthData> {
}
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum Error<E> {
InvalidExtensionId(u32),
ProgramError(E),

View File

@ -20,5 +20,5 @@ pub fn prf_expand_vec(sk: &[u8], ts: &[&[u8]]) -> Blake2bHash {
}
/// An outgoing viewing key
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct OutgoingViewingKey(pub [u8; 32]);

View File

@ -29,7 +29,7 @@ enum OpCode {
}
/// A serialized script, used inside transparent inputs and outputs of a transaction.
#[derive(Clone, Debug, Default, PartialEq)]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Script(pub Vec<u8>);
impl Script {

View File

@ -28,7 +28,7 @@ where
}
/// Errors that may result from attempting to construct an invalid memo.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
InvalidUtf8(std::str::Utf8Error),
TooLong(usize),
@ -125,7 +125,7 @@ impl MemoBytes {
}
/// Type-safe wrapper around String to enforce memo length requirements.
#[derive(Clone, PartialEq)]
#[derive(Clone, PartialEq, Eq)]
pub struct TextMemo(String);
impl From<TextMemo> for String {

View File

@ -520,7 +520,7 @@ impl<Node: Hashable> IncrementalWitness<Node> {
}
/// A path from a position in a particular commitment tree to the root of that tree.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MerklePath<Node: Hashable> {
pub auth_path: Vec<(Node, bool)>,
pub position: u64,

View File

@ -71,7 +71,7 @@ pub fn merkle_hash(depth: usize, lhs: &[u8; 32], rhs: &[u8; 32]) -> [u8; 32] {
}
/// A node within the Sapling commitment tree.
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Node {
repr: [u8; 32],
}
@ -155,7 +155,7 @@ pub(crate) fn spend_sig_internal<R: RngCore>(
// Compute the signature's message for rk/spend_auth_sig
let mut data_to_be_signed = [0u8; 64];
data_to_be_signed[0..32].copy_from_slice(&rk.0.to_bytes());
(&mut data_to_be_signed[32..64]).copy_from_slice(&sighash[..]);
data_to_be_signed[32..64].copy_from_slice(&sighash[..]);
// Do the signing
rsk.sign(&data_to_be_signed, rng, SPENDING_KEY_GENERATOR)
@ -245,7 +245,7 @@ impl SaplingIvk {
}
}
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Diversifier(pub [u8; 11]);
impl Diversifier {
@ -381,7 +381,7 @@ impl ConstantTimeEq for Nullifier {
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct NoteValue(u64);
impl TryFrom<u64> for NoteValue {
@ -436,9 +436,7 @@ impl Note {
let mut note_contents = vec![];
// Writing the value in little endian
(&mut note_contents)
.write_u64::<LittleEndian>(self.value)
.unwrap();
note_contents.write_u64::<LittleEndian>(self.value).unwrap();
// Write g_d
note_contents.extend_from_slice(&self.g_d.to_bytes());

View File

@ -102,9 +102,9 @@ impl ExpandedSpendingKey {
/// [ZIP 32](https://zips.z.cash/zip-0032)
pub fn to_bytes(&self) -> [u8; 96] {
let mut result = [0u8; 96];
(&mut result[0..32]).copy_from_slice(&self.ask.to_repr());
(&mut result[32..64]).copy_from_slice(&self.nsk.to_repr());
(&mut result[64..96]).copy_from_slice(&self.ovk.0);
result[0..32].copy_from_slice(&self.ask.to_repr());
result[32..64].copy_from_slice(&self.nsk.to_repr());
result[64..96].copy_from_slice(&self.ovk.0);
result
}
}

View File

@ -3,7 +3,7 @@
use super::{test::TestVector, Personalization};
pub fn get_vectors<'a>() -> Vec<TestVector<'a>> {
return vec![
vec![
TestVector {
personalization: Personalization::NoteCommitment,
input_bits: vec![1, 1, 1, 1, 1, 1],
@ -711,5 +711,5 @@ pub fn get_vectors<'a>() -> Vec<TestVector<'a>> {
hash_u: "0x329e3bb2ca31ea6e13a986730237f6fd16b842a510cbabe851bdbcf57d75ee0d",
hash_v: "0x471d2109656afcb96d0609b371b132b97efcf72c6051064dd19fdc004799bfa9",
},
];
]
}

View File

@ -49,7 +49,7 @@ use crate::sapling::prover::mock::MockTxProver;
const DEFAULT_TX_EXPIRY_DELTA: u32 = 20;
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
ChangeIsNegative(Amount),
InvalidAmount,

View File

@ -45,7 +45,7 @@ impl Amount {
///
/// Returns an error if the amount is outside the range `{-MAX_MONEY..MAX_MONEY}`.
pub fn from_i64(amount: i64) -> Result<Self, ()> {
if -MAX_MONEY <= amount && amount <= MAX_MONEY {
if (-MAX_MONEY..=MAX_MONEY).contains(&amount) {
Ok(Amount(amount))
} else {
Err(())

View File

@ -28,7 +28,7 @@ pub trait Authorization: Debug {
type AuthSig: Clone + Debug;
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Unproven;
impl Authorization for Unproven {

View File

@ -37,7 +37,7 @@ use crate::{
/// with dummy outputs if necessary. See <https://github.com/zcash/zcash/issues/3615>.
const MIN_SHIELDED_OUTPUTS: usize = 2;
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
AnchorMismatch,
BindingSig,
@ -151,7 +151,7 @@ impl SaplingOutput {
}
/// Metadata about a transaction created by a [`SaplingBuilder`].
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SaplingMetadata {
spend_indices: Vec<usize>,
output_indices: Vec<usize>,
@ -560,7 +560,7 @@ pub mod testing {
},
merkle_tree::{testing::arb_commitment_tree, IncrementalWitness},
sapling::{
prover::{mock::MockTxProver, TxProver},
prover::mock::MockTxProver,
testing::{arb_node, arb_note, arb_positive_note_value},
Diversifier,
},
@ -605,11 +605,10 @@ pub mod testing {
}
let prover = MockTxProver;
let mut ctx = prover.new_sapling_proving_context();
let bundle = builder.build(
&prover,
&mut ctx,
&mut (),
&mut rng,
target_height.unwrap(),
None
@ -617,7 +616,7 @@ pub mod testing {
let (bundle, _) = bundle.apply_signatures(
&prover,
&mut ctx,
&mut (),
&mut rng,
&fake_sighash_bytes,
).unwrap();

View File

@ -15,7 +15,7 @@ pub trait Authorization: Debug {
type ScriptSig: Debug + Clone + PartialEq;
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Authorized;
impl Authorization for Authorized {
@ -89,7 +89,7 @@ impl<A: Authorization> Bundle<A> {
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OutPoint {
hash: [u8; 32],
n: u32,
@ -156,7 +156,7 @@ impl TxIn<Authorized> {
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TxOut {
pub value: Amount,
pub script_pubkey: Script,

View File

@ -25,7 +25,7 @@ use {
ripemd::Digest,
};
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
InvalidAddress,
InvalidAmount,

View File

@ -21,7 +21,7 @@ pub trait Authorization: Debug {
type Witness: Debug + Clone + PartialEq;
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Authorized;
impl Authorization for Authorized {
@ -57,7 +57,7 @@ impl<A: Authorization> Bundle<A> {
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OutPoint {
txid: TxId,
n: u32,
@ -88,7 +88,7 @@ impl OutPoint {
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TzeIn<Payload> {
pub prevout: OutPoint,
pub witness: tze::Witness<Payload>,
@ -166,7 +166,7 @@ impl TzeIn<<Authorized as Authorization>::Witness> {
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TzeOut {
pub value: Amount,
pub precondition: tze::Precondition,

View File

@ -14,7 +14,7 @@ use crate::{
},
};
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
InvalidAmount,
WitnessModeMismatch(u32, u32),
@ -42,7 +42,7 @@ pub struct TzeBuilder<'a, BuildCtx> {
vout: Vec<TzeOut>,
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Unauthorized;
impl Authorization for Unauthorized {

View File

@ -54,9 +54,7 @@ fn prevout_hash<TA: transparent::Authorization>(vin: &[TxIn<TA>]) -> Blake2bHash
fn sequence_hash<TA: transparent::Authorization>(vin: &[TxIn<TA>]) -> Blake2bHash {
let mut data = Vec::with_capacity(vin.len() * 4);
for t_in in vin {
(&mut data)
.write_u32::<LittleEndian>(t_in.sequence)
.unwrap();
data.write_u32::<LittleEndian>(t_in.sequence).unwrap();
}
Blake2bParams::new()
.hash_length(32)
@ -145,7 +143,7 @@ pub fn v4_signature_hash<
let hash_type = signable_input.hash_type();
if tx.version.has_overwinter() {
let mut personal = [0; 16];
(&mut personal[..12]).copy_from_slice(ZCASH_SIGHASH_PERSONALIZATION_PREFIX);
personal[..12].copy_from_slice(ZCASH_SIGHASH_PERSONALIZATION_PREFIX);
(&mut personal[12..])
.write_u32::<LittleEndian>(tx.consensus_branch_id.into())
.unwrap();
@ -252,8 +250,7 @@ pub fn v4_signature_hash<
bundle.vin[*index].prevout.write(&mut data).unwrap();
script_code.write(&mut data).unwrap();
data.extend_from_slice(&value.to_i64_le_bytes());
(&mut data)
.write_u32::<LittleEndian>(bundle.vin[*index].sequence)
data.write_u32::<LittleEndian>(bundle.vin[*index].sequence)
.unwrap();
h.update(&data);
} else {

View File

@ -87,7 +87,7 @@ pub(crate) fn transparent_sequence_hash<TransparentAuth: transparent::Authorizat
) -> Blake2bHash {
let mut h = hasher(ZCASH_SEQUENCE_HASH_PERSONALIZATION);
for t_in in vin {
(&mut h).write_u32::<LittleEndian>(t_in.sequence).unwrap();
h.write_u32::<LittleEndian>(t_in.sequence).unwrap();
}
h.finalize()
}
@ -368,7 +368,7 @@ pub(crate) fn to_hash(
#[cfg(feature = "zfuture")] tze_digests: Option<&TzeDigests<Blake2bHash>>,
) -> Blake2bHash {
let mut personal = [0; 16];
(&mut personal[..12]).copy_from_slice(ZCASH_TX_PERSONALIZATION_PREFIX);
personal[..12].copy_from_slice(ZCASH_TX_PERSONALIZATION_PREFIX);
(&mut personal[12..])
.write_u32::<LittleEndian>(consensus_branch_id.into())
.unwrap();
@ -513,7 +513,7 @@ impl TransactionDigest<Authorized> for BlockTxCommitmentDigester {
let digests = [transparent_digest, sapling_digest, orchard_digest];
let mut personal = [0; 16];
(&mut personal[..12]).copy_from_slice(ZCASH_AUTH_PERSONALIZATION_PREFIX);
personal[..12].copy_from_slice(ZCASH_AUTH_PERSONALIZATION_PREFIX);
(&mut personal[12..])
.write_u32::<LittleEndian>(consensus_branch_id.into())
.unwrap();

View File

@ -98,7 +98,7 @@ impl FvkTag {
}
/// A child index for a derived key
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ChildIndex {
NonHardened(u32),
Hardened(u32), // Hardened(n) == n + (1 << 31) == n' in path notation
@ -125,7 +125,7 @@ impl ChildIndex {
}
/// A BIP-32 chain code
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ChainCode([u8; 32]);
impl ChainCode {
@ -136,7 +136,7 @@ impl ChainCode {
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DiversifierIndex(pub [u8; 11]);
impl Default for DiversifierIndex {
@ -154,7 +154,7 @@ impl From<u32> for DiversifierIndex {
impl From<u64> for DiversifierIndex {
fn from(i: u64) -> Self {
let mut result = DiversifierIndex([0; 11]);
(&mut result.0[..8]).copy_from_slice(&i.to_le_bytes());
result.0[..8].copy_from_slice(&i.to_le_bytes());
result
}
}
@ -178,7 +178,7 @@ impl DiversifierIndex {
}
/// A key used to derive diversifiers for a particular child key
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DiversifierKey([u8; 32]);
impl DiversifierKey {
@ -437,19 +437,19 @@ impl ExtendedSpendingKey {
let depth = b[0];
let mut parent_fvk_tag = FvkTag([0; 4]);
(&mut parent_fvk_tag.0[..]).copy_from_slice(&b[1..5]);
parent_fvk_tag.0[..].copy_from_slice(&b[1..5]);
let mut ci_bytes = [0u8; 4];
(&mut ci_bytes[..]).copy_from_slice(&b[5..9]);
ci_bytes[..].copy_from_slice(&b[5..9]);
let child_index = ChildIndex::from_index(u32::from_le_bytes(ci_bytes));
let mut chain_code = ChainCode([0u8; 32]);
(&mut chain_code.0[..]).copy_from_slice(&b[9..41]);
chain_code.0[..].copy_from_slice(&b[9..41]);
let expsk = ExpandedSpendingKey::from_bytes(&b[41..137])?;
let mut dk = DiversifierKey([0u8; 32]);
(&mut dk.0[..]).copy_from_slice(&b[137..169]);
dk.0[..].copy_from_slice(&b[137..169]);
Ok(ExtendedSpendingKey {
depth,
@ -489,11 +489,11 @@ impl ExtendedSpendingKey {
pub fn to_bytes(&self) -> [u8; 169] {
let mut result = [0u8; 169];
result[0] = self.depth;
(&mut result[1..5]).copy_from_slice(&self.parent_fvk_tag.as_bytes()[..]);
(&mut result[5..9]).copy_from_slice(&self.child_index.value().to_le_bytes()[..]);
(&mut result[9..41]).copy_from_slice(&self.chain_code.as_bytes()[..]);
(&mut result[41..137]).copy_from_slice(&self.expsk.to_bytes()[..]);
(&mut result[137..169]).copy_from_slice(&self.dk.as_bytes()[..]);
result[1..5].copy_from_slice(&self.parent_fvk_tag.as_bytes()[..]);
result[5..9].copy_from_slice(&self.child_index.value().to_le_bytes()[..]);
result[9..41].copy_from_slice(&self.chain_code.as_bytes()[..]);
result[41..137].copy_from_slice(&self.expsk.to_bytes()[..]);
result[137..169].copy_from_slice(&self.dk.as_bytes()[..]);
result
}

View File

@ -243,7 +243,7 @@ impl SaplingProvingContext {
// Construct signature message
let mut data_to_be_signed = [0u8; 64];
data_to_be_signed[0..32].copy_from_slice(&bvk.0.to_bytes());
(&mut data_to_be_signed[32..64]).copy_from_slice(&sighash[..]);
data_to_be_signed[32..64].copy_from_slice(&sighash[..]);
// Sign
Ok(bsk.sign(

View File

@ -57,7 +57,7 @@ impl SaplingVerificationContextInner {
// Compute the signature's message for rk/spend_auth_sig
let mut data_to_be_signed = [0u8; 64];
data_to_be_signed[0..32].copy_from_slice(&rk.0.to_bytes());
(&mut data_to_be_signed[32..64]).copy_from_slice(&sighash_value[..]);
data_to_be_signed[32..64].copy_from_slice(&sighash_value[..]);
// Verify the spend_auth_sig
let rk_affine = rk.0.to_affine();
@ -158,7 +158,7 @@ impl SaplingVerificationContextInner {
// Compute the signature's message for bvk/binding_sig
let mut data_to_be_signed = [0u8; 64];
data_to_be_signed[0..32].copy_from_slice(&bvk.0.to_bytes());
(&mut data_to_be_signed[32..64]).copy_from_slice(&sighash_value[..]);
data_to_be_signed[32..64].copy_from_slice(&sighash_value[..]);
// Verify the binding_sig
binding_sig_verifier(bvk, data_to_be_signed, binding_sig)