Merge pull request #645 from nuttycom/fix_beta_lints
Fix problems identified by clippy's beta lints
This commit is contained in:
commit
6cb0d21219
|
@ -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> {
|
fn expand_array(vin: &[u8], bit_len: usize, byte_pad: usize) -> Vec<u8> {
|
||||||
assert!(bit_len >= 8);
|
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_width = (bit_len + 7) / 8 + byte_pad;
|
||||||
let out_len = 8 * out_width * vin.len() / bit_len;
|
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>());
|
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 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));
|
let mut csr = Cursor::new(expand_array(minimal, c_bit_len + 1, byte_pad));
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::kind::unified::Encoding;
|
||||||
use crate::{kind::*, AddressKind, Network, ZcashAddress};
|
use crate::{kind::*, AddressKind, Network, ZcashAddress};
|
||||||
|
|
||||||
/// An error while attempting to parse a string as a Zcash address.
|
/// An error while attempting to parse a string as a Zcash address.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum ParseError {
|
pub enum ParseError {
|
||||||
/// The string is an invalid encoding.
|
/// The string is an invalid encoding.
|
||||||
InvalidEncoding,
|
InvalidEncoding,
|
||||||
|
|
|
@ -7,9 +7,9 @@ pub(crate) const MAINNET: [u8; 2] = [0x16, 0x9a];
|
||||||
|
|
||||||
/// The prefix for a Base58Check-encoded testnet Sprout address.
|
/// 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) const TESTNET: [u8; 2] = [0x16, 0xb6];
|
||||||
|
|
||||||
pub(crate) type Data = [u8; 64];
|
pub(crate) type Data = [u8; 64];
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl Typecode {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error while attempting to parse a string as a Zcash address.
|
/// An error while attempting to parse a string as a Zcash address.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum ParseError {
|
pub enum ParseError {
|
||||||
/// The unified container contains both P2PKH and P2SH items.
|
/// The unified container contains both P2PKH and P2SH items.
|
||||||
BothP2phkAndP2sh,
|
BothP2phkAndP2sh,
|
||||||
|
|
|
@ -263,7 +263,7 @@ mod tests {
|
||||||
validate_chain(
|
validate_chain(
|
||||||
&tests::network(),
|
&tests::network(),
|
||||||
&db_cache,
|
&db_cache,
|
||||||
(&db_data).get_max_height_hash().unwrap(),
|
db_data.get_max_height_hash().unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -280,7 +280,7 @@ mod tests {
|
||||||
validate_chain(
|
validate_chain(
|
||||||
&tests::network(),
|
&tests::network(),
|
||||||
&db_cache,
|
&db_cache,
|
||||||
(&db_data).get_max_height_hash().unwrap(),
|
db_data.get_max_height_hash().unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ mod tests {
|
||||||
validate_chain(
|
validate_chain(
|
||||||
&tests::network(),
|
&tests::network(),
|
||||||
&db_cache,
|
&db_cache,
|
||||||
(&db_data).get_max_height_hash().unwrap(),
|
db_data.get_max_height_hash().unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -309,7 +309,7 @@ mod tests {
|
||||||
validate_chain(
|
validate_chain(
|
||||||
&tests::network(),
|
&tests::network(),
|
||||||
&db_cache,
|
&db_cache,
|
||||||
(&db_data).get_max_height_hash().unwrap(),
|
db_data.get_max_height_hash().unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -320,7 +320,7 @@ mod tests {
|
||||||
validate_chain(
|
validate_chain(
|
||||||
&tests::network(),
|
&tests::network(),
|
||||||
&db_cache,
|
&db_cache,
|
||||||
(&db_data).get_max_height_hash().unwrap(),
|
db_data.get_max_height_hash().unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,7 @@ mod tests {
|
||||||
validate_chain(
|
validate_chain(
|
||||||
&tests::network(),
|
&tests::network(),
|
||||||
&db_cache,
|
&db_cache,
|
||||||
(&db_data).get_max_height_hash().unwrap(),
|
db_data.get_max_height_hash().unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -386,7 +386,7 @@ mod tests {
|
||||||
match validate_chain(
|
match validate_chain(
|
||||||
&tests::network(),
|
&tests::network(),
|
||||||
&db_cache,
|
&db_cache,
|
||||||
(&db_data).get_max_height_hash().unwrap(),
|
db_data.get_max_height_hash().unwrap(),
|
||||||
) {
|
) {
|
||||||
Err(SqliteClientError::BackendError(Error::InvalidChain(lower_bound, _))) => {
|
Err(SqliteClientError::BackendError(Error::InvalidChain(lower_bound, _))) => {
|
||||||
assert_eq!(lower_bound, sapling_activation_height() + 2)
|
assert_eq!(lower_bound, sapling_activation_height() + 2)
|
||||||
|
@ -432,7 +432,7 @@ mod tests {
|
||||||
validate_chain(
|
validate_chain(
|
||||||
&tests::network(),
|
&tests::network(),
|
||||||
&db_cache,
|
&db_cache,
|
||||||
(&db_data).get_max_height_hash().unwrap(),
|
db_data.get_max_height_hash().unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -456,7 +456,7 @@ mod tests {
|
||||||
match validate_chain(
|
match validate_chain(
|
||||||
&tests::network(),
|
&tests::network(),
|
||||||
&db_cache,
|
&db_cache,
|
||||||
(&db_data).get_max_height_hash().unwrap(),
|
db_data.get_max_height_hash().unwrap(),
|
||||||
) {
|
) {
|
||||||
Err(SqliteClientError::BackendError(Error::InvalidChain(lower_bound, _))) => {
|
Err(SqliteClientError::BackendError(Error::InvalidChain(lower_bound, _))) => {
|
||||||
assert_eq!(lower_bound, sapling_activation_height() + 3)
|
assert_eq!(lower_bound, sapling_activation_height() + 3)
|
||||||
|
|
|
@ -1318,7 +1318,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
// We can't get an anchor height, as we have not scanned any blocks.
|
// 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
|
// An invalid account has zero balance
|
||||||
assert!(get_address(&db_data, AccountId::from(1)).is_err());
|
assert!(get_address(&db_data, AccountId::from(1)).is_err());
|
||||||
|
|
|
@ -412,10 +412,7 @@ mod tests {
|
||||||
scan_cached_blocks(&tests::network(), &db_cache, &mut db_write, None).unwrap();
|
scan_cached_blocks(&tests::network(), &db_cache, &mut db_write, None).unwrap();
|
||||||
|
|
||||||
// Verified balance matches total balance
|
// Verified balance matches total balance
|
||||||
let (_, anchor_height) = (&db_data)
|
let (_, anchor_height) = db_data.get_target_and_anchor_heights(10).unwrap().unwrap();
|
||||||
.get_target_and_anchor_heights(10)
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(get_balance(&db_data, AccountId::from(0)).unwrap(), value);
|
assert_eq!(get_balance(&db_data, AccountId::from(0)).unwrap(), value);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_balance_at(&db_data, AccountId::from(0), anchor_height).unwrap(),
|
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();
|
scan_cached_blocks(&tests::network(), &db_cache, &mut db_write, None).unwrap();
|
||||||
|
|
||||||
// Verified balance does not include the second note
|
// Verified balance does not include the second note
|
||||||
let (_, anchor_height2) = (&db_data)
|
let (_, anchor_height2) = db_data.get_target_and_anchor_heights(10).unwrap().unwrap();
|
||||||
.get_target_and_anchor_heights(10)
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_balance(&db_data, AccountId::from(0)).unwrap(),
|
get_balance(&db_data, AccountId::from(0)).unwrap(),
|
||||||
(value + value).unwrap()
|
(value + value).unwrap()
|
||||||
|
@ -790,10 +784,7 @@ mod tests {
|
||||||
scan_cached_blocks(&tests::network(), &db_cache, &mut db_write, None).unwrap();
|
scan_cached_blocks(&tests::network(), &db_cache, &mut db_write, None).unwrap();
|
||||||
|
|
||||||
// Verified balance matches total balance
|
// Verified balance matches total balance
|
||||||
let (_, anchor_height) = (&db_data)
|
let (_, anchor_height) = db_data.get_target_and_anchor_heights(10).unwrap().unwrap();
|
||||||
.get_target_and_anchor_heights(10)
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(get_balance(&db_data, AccountId::from(0)).unwrap(), value);
|
assert_eq!(get_balance(&db_data, AccountId::from(0)).unwrap(), value);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_balance_at(&db_data, AccountId::from(0), anchor_height).unwrap(),
|
get_balance_at(&db_data, AccountId::from(0), anchor_height).unwrap(),
|
||||||
|
|
|
@ -35,10 +35,10 @@ use zcash_primitives::{
|
||||||
mod open {
|
mod open {
|
||||||
pub const MODE: u32 = 0;
|
pub const MODE: u32 = 0;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct Precondition(pub [u8; 32]);
|
pub struct Precondition(pub [u8; 32]);
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct Witness(pub [u8; 32]);
|
pub struct Witness(pub [u8; 32]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,15 +46,15 @@ mod open {
|
||||||
mod close {
|
mod close {
|
||||||
pub const MODE: u32 = 1;
|
pub const MODE: u32 = 1;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct Precondition(pub [u8; 32]);
|
pub struct Precondition(pub [u8; 32]);
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct Witness(pub [u8; 32]);
|
pub struct Witness(pub [u8; 32]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The precondition type for the demo extension.
|
/// The precondition type for the demo extension.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Precondition {
|
pub enum Precondition {
|
||||||
Open(open::Precondition),
|
Open(open::Precondition),
|
||||||
Close(close::Precondition),
|
Close(close::Precondition),
|
||||||
|
@ -74,7 +74,7 @@ impl Precondition {
|
||||||
|
|
||||||
/// Errors that may be produced during parsing and verification of demo preconditions and
|
/// Errors that may be produced during parsing and verification of demo preconditions and
|
||||||
/// witnesses.
|
/// witnesses.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Parse error indicating that the payload of the condition or the witness was
|
/// Parse error indicating that the payload of the condition or the witness was
|
||||||
/// not 32 bytes.
|
/// not 32 bytes.
|
||||||
|
@ -156,7 +156,7 @@ impl ToPayload for Precondition {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The witness type for the demo extension.
|
/// The witness type for the demo extension.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Witness {
|
pub enum Witness {
|
||||||
Open(open::Witness),
|
Open(open::Witness),
|
||||||
Close(close::Witness),
|
Close(close::Witness),
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub const MAX_NODE_DATA_SIZE: usize = 32 + // subtree commitment
|
||||||
/// V1 node metadata.
|
/// V1 node metadata.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
#[cfg_attr(test, derive(PartialEq))]
|
#[cfg_attr(test, derive(PartialEq, Eq))]
|
||||||
pub struct NodeData {
|
pub struct NodeData {
|
||||||
/// Consensus branch id, should be provided by deserializing node.
|
/// Consensus branch id, should be provided by deserializing node.
|
||||||
pub consensus_branch_id: u32,
|
pub consensus_branch_id: u32,
|
||||||
|
@ -171,7 +171,7 @@ impl NodeData {
|
||||||
|
|
||||||
/// V2 node metadata.
|
/// V2 node metadata.
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
#[cfg_attr(test, derive(PartialEq))]
|
#[cfg_attr(test, derive(PartialEq, Eq))]
|
||||||
pub struct V2 {
|
pub struct V2 {
|
||||||
/// The V1 node data retained in V2.
|
/// The V1 node data retained in V2.
|
||||||
pub v1: NodeData,
|
pub v1: NodeData,
|
||||||
|
|
|
@ -187,7 +187,7 @@ pub trait Parameters: Clone {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Marker struct for the production network.
|
/// Marker struct for the production network.
|
||||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||||
pub struct MainNetwork;
|
pub struct MainNetwork;
|
||||||
|
|
||||||
pub const MAIN_NETWORK: MainNetwork = MainNetwork;
|
pub const MAIN_NETWORK: MainNetwork = MainNetwork;
|
||||||
|
@ -236,7 +236,7 @@ impl Parameters for MainNetwork {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Marker struct for the test network.
|
/// Marker struct for the test network.
|
||||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||||
pub struct TestNetwork;
|
pub struct TestNetwork;
|
||||||
|
|
||||||
pub const TEST_NETWORK: TestNetwork = 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 {
|
pub enum Network {
|
||||||
MainNetwork,
|
MainNetwork,
|
||||||
TestNetwork,
|
TestNetwork,
|
||||||
|
@ -445,7 +445,7 @@ pub const ZIP212_GRACE_PERIOD: u32 = 32256;
|
||||||
/// See [ZIP 200](https://zips.z.cash/zip-0200) for more details.
|
/// See [ZIP 200](https://zips.z.cash/zip-0200) for more details.
|
||||||
///
|
///
|
||||||
/// [`signature_hash`]: crate::transaction::sighash::signature_hash
|
/// [`signature_hash`]: crate::transaction::sighash::signature_hash
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum BranchId {
|
pub enum BranchId {
|
||||||
/// The consensus rules at the launch of Zcash.
|
/// The consensus rules at the launch of Zcash.
|
||||||
Sprout,
|
Sprout,
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::transaction::components::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A typesafe wrapper for witness payloads
|
/// A typesafe wrapper for witness payloads
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct AuthData(pub Vec<u8>);
|
pub struct AuthData(pub Vec<u8>);
|
||||||
|
|
||||||
/// Binary parsing capability for TZE preconditions & witnesses.
|
/// 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
|
/// 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`
|
/// treated as opaque to all but the extension corresponding to the encapsulated `extension_id`
|
||||||
/// value.
|
/// value.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Precondition {
|
pub struct Precondition {
|
||||||
pub extension_id: u32,
|
pub extension_id: u32,
|
||||||
pub mode: 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
|
/// 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`
|
/// treated as opaque to all but the extension corresponding to the encapsulated `extension_id`
|
||||||
/// value.
|
/// value.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Witness<T> {
|
pub struct Witness<T> {
|
||||||
pub extension_id: u32,
|
pub extension_id: u32,
|
||||||
pub mode: u32,
|
pub mode: u32,
|
||||||
|
@ -105,7 +105,7 @@ impl Witness<AuthData> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Error<E> {
|
pub enum Error<E> {
|
||||||
InvalidExtensionId(u32),
|
InvalidExtensionId(u32),
|
||||||
ProgramError(E),
|
ProgramError(E),
|
||||||
|
|
|
@ -20,5 +20,5 @@ pub fn prf_expand_vec(sk: &[u8], ts: &[&[u8]]) -> Blake2bHash {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An outgoing viewing key
|
/// An outgoing viewing key
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub struct OutgoingViewingKey(pub [u8; 32]);
|
pub struct OutgoingViewingKey(pub [u8; 32]);
|
||||||
|
|
|
@ -29,7 +29,7 @@ enum OpCode {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A serialized script, used inside transparent inputs and outputs of a transaction.
|
/// 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>);
|
pub struct Script(pub Vec<u8>);
|
||||||
|
|
||||||
impl Script {
|
impl Script {
|
||||||
|
|
|
@ -28,7 +28,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Errors that may result from attempting to construct an invalid memo.
|
/// Errors that may result from attempting to construct an invalid memo.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
InvalidUtf8(std::str::Utf8Error),
|
InvalidUtf8(std::str::Utf8Error),
|
||||||
TooLong(usize),
|
TooLong(usize),
|
||||||
|
@ -125,7 +125,7 @@ impl MemoBytes {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type-safe wrapper around String to enforce memo length requirements.
|
/// Type-safe wrapper around String to enforce memo length requirements.
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub struct TextMemo(String);
|
pub struct TextMemo(String);
|
||||||
|
|
||||||
impl From<TextMemo> for String {
|
impl From<TextMemo> for String {
|
||||||
|
|
|
@ -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.
|
/// 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 struct MerklePath<Node: Hashable> {
|
||||||
pub auth_path: Vec<(Node, bool)>,
|
pub auth_path: Vec<(Node, bool)>,
|
||||||
pub position: u64,
|
pub position: u64,
|
||||||
|
|
|
@ -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.
|
/// A node within the Sapling commitment tree.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub struct Node {
|
pub struct Node {
|
||||||
repr: [u8; 32],
|
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
|
// Compute the signature's message for rk/spend_auth_sig
|
||||||
let mut data_to_be_signed = [0u8; 64];
|
let mut data_to_be_signed = [0u8; 64];
|
||||||
data_to_be_signed[0..32].copy_from_slice(&rk.0.to_bytes());
|
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
|
// Do the signing
|
||||||
rsk.sign(&data_to_be_signed, rng, SPENDING_KEY_GENERATOR)
|
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]);
|
pub struct Diversifier(pub [u8; 11]);
|
||||||
|
|
||||||
impl Diversifier {
|
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);
|
pub struct NoteValue(u64);
|
||||||
|
|
||||||
impl TryFrom<u64> for NoteValue {
|
impl TryFrom<u64> for NoteValue {
|
||||||
|
@ -436,9 +436,7 @@ impl Note {
|
||||||
let mut note_contents = vec![];
|
let mut note_contents = vec![];
|
||||||
|
|
||||||
// Writing the value in little endian
|
// Writing the value in little endian
|
||||||
(&mut note_contents)
|
note_contents.write_u64::<LittleEndian>(self.value).unwrap();
|
||||||
.write_u64::<LittleEndian>(self.value)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Write g_d
|
// Write g_d
|
||||||
note_contents.extend_from_slice(&self.g_d.to_bytes());
|
note_contents.extend_from_slice(&self.g_d.to_bytes());
|
||||||
|
|
|
@ -102,9 +102,9 @@ impl ExpandedSpendingKey {
|
||||||
/// [ZIP 32](https://zips.z.cash/zip-0032)
|
/// [ZIP 32](https://zips.z.cash/zip-0032)
|
||||||
pub fn to_bytes(&self) -> [u8; 96] {
|
pub fn to_bytes(&self) -> [u8; 96] {
|
||||||
let mut result = [0u8; 96];
|
let mut result = [0u8; 96];
|
||||||
(&mut result[0..32]).copy_from_slice(&self.ask.to_repr());
|
result[0..32].copy_from_slice(&self.ask.to_repr());
|
||||||
(&mut result[32..64]).copy_from_slice(&self.nsk.to_repr());
|
result[32..64].copy_from_slice(&self.nsk.to_repr());
|
||||||
(&mut result[64..96]).copy_from_slice(&self.ovk.0);
|
result[64..96].copy_from_slice(&self.ovk.0);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use super::{test::TestVector, Personalization};
|
use super::{test::TestVector, Personalization};
|
||||||
|
|
||||||
pub fn get_vectors<'a>() -> Vec<TestVector<'a>> {
|
pub fn get_vectors<'a>() -> Vec<TestVector<'a>> {
|
||||||
return vec![
|
vec![
|
||||||
TestVector {
|
TestVector {
|
||||||
personalization: Personalization::NoteCommitment,
|
personalization: Personalization::NoteCommitment,
|
||||||
input_bits: vec![1, 1, 1, 1, 1, 1],
|
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_u: "0x329e3bb2ca31ea6e13a986730237f6fd16b842a510cbabe851bdbcf57d75ee0d",
|
||||||
hash_v: "0x471d2109656afcb96d0609b371b132b97efcf72c6051064dd19fdc004799bfa9",
|
hash_v: "0x471d2109656afcb96d0609b371b132b97efcf72c6051064dd19fdc004799bfa9",
|
||||||
},
|
},
|
||||||
];
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ use crate::sapling::prover::mock::MockTxProver;
|
||||||
|
|
||||||
const DEFAULT_TX_EXPIRY_DELTA: u32 = 20;
|
const DEFAULT_TX_EXPIRY_DELTA: u32 = 20;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
ChangeIsNegative(Amount),
|
ChangeIsNegative(Amount),
|
||||||
InvalidAmount,
|
InvalidAmount,
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl Amount {
|
||||||
///
|
///
|
||||||
/// Returns an error if the amount is outside the range `{-MAX_MONEY..MAX_MONEY}`.
|
/// Returns an error if the amount is outside the range `{-MAX_MONEY..MAX_MONEY}`.
|
||||||
pub fn from_i64(amount: i64) -> Result<Self, ()> {
|
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))
|
Ok(Amount(amount))
|
||||||
} else {
|
} else {
|
||||||
Err(())
|
Err(())
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub trait Authorization: Debug {
|
||||||
type AuthSig: Clone + Debug;
|
type AuthSig: Clone + Debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub struct Unproven;
|
pub struct Unproven;
|
||||||
|
|
||||||
impl Authorization for Unproven {
|
impl Authorization for Unproven {
|
||||||
|
|
|
@ -37,7 +37,7 @@ use crate::{
|
||||||
/// with dummy outputs if necessary. See <https://github.com/zcash/zcash/issues/3615>.
|
/// with dummy outputs if necessary. See <https://github.com/zcash/zcash/issues/3615>.
|
||||||
const MIN_SHIELDED_OUTPUTS: usize = 2;
|
const MIN_SHIELDED_OUTPUTS: usize = 2;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
AnchorMismatch,
|
AnchorMismatch,
|
||||||
BindingSig,
|
BindingSig,
|
||||||
|
@ -151,7 +151,7 @@ impl SaplingOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Metadata about a transaction created by a [`SaplingBuilder`].
|
/// Metadata about a transaction created by a [`SaplingBuilder`].
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct SaplingMetadata {
|
pub struct SaplingMetadata {
|
||||||
spend_indices: Vec<usize>,
|
spend_indices: Vec<usize>,
|
||||||
output_indices: Vec<usize>,
|
output_indices: Vec<usize>,
|
||||||
|
@ -560,7 +560,7 @@ pub mod testing {
|
||||||
},
|
},
|
||||||
merkle_tree::{testing::arb_commitment_tree, IncrementalWitness},
|
merkle_tree::{testing::arb_commitment_tree, IncrementalWitness},
|
||||||
sapling::{
|
sapling::{
|
||||||
prover::{mock::MockTxProver, TxProver},
|
prover::mock::MockTxProver,
|
||||||
testing::{arb_node, arb_note, arb_positive_note_value},
|
testing::{arb_node, arb_note, arb_positive_note_value},
|
||||||
Diversifier,
|
Diversifier,
|
||||||
},
|
},
|
||||||
|
@ -605,11 +605,10 @@ pub mod testing {
|
||||||
}
|
}
|
||||||
|
|
||||||
let prover = MockTxProver;
|
let prover = MockTxProver;
|
||||||
let mut ctx = prover.new_sapling_proving_context();
|
|
||||||
|
|
||||||
let bundle = builder.build(
|
let bundle = builder.build(
|
||||||
&prover,
|
&prover,
|
||||||
&mut ctx,
|
&mut (),
|
||||||
&mut rng,
|
&mut rng,
|
||||||
target_height.unwrap(),
|
target_height.unwrap(),
|
||||||
None
|
None
|
||||||
|
@ -617,7 +616,7 @@ pub mod testing {
|
||||||
|
|
||||||
let (bundle, _) = bundle.apply_signatures(
|
let (bundle, _) = bundle.apply_signatures(
|
||||||
&prover,
|
&prover,
|
||||||
&mut ctx,
|
&mut (),
|
||||||
&mut rng,
|
&mut rng,
|
||||||
&fake_sighash_bytes,
|
&fake_sighash_bytes,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub trait Authorization: Debug {
|
||||||
type ScriptSig: Debug + Clone + PartialEq;
|
type ScriptSig: Debug + Clone + PartialEq;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub struct Authorized;
|
pub struct Authorized;
|
||||||
|
|
||||||
impl Authorization for 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 {
|
pub struct OutPoint {
|
||||||
hash: [u8; 32],
|
hash: [u8; 32],
|
||||||
n: u32,
|
n: u32,
|
||||||
|
@ -156,7 +156,7 @@ impl TxIn<Authorized> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct TxOut {
|
pub struct TxOut {
|
||||||
pub value: Amount,
|
pub value: Amount,
|
||||||
pub script_pubkey: Script,
|
pub script_pubkey: Script,
|
||||||
|
|
|
@ -25,7 +25,7 @@ use {
|
||||||
ripemd::Digest,
|
ripemd::Digest,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
InvalidAddress,
|
InvalidAddress,
|
||||||
InvalidAmount,
|
InvalidAmount,
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub trait Authorization: Debug {
|
||||||
type Witness: Debug + Clone + PartialEq;
|
type Witness: Debug + Clone + PartialEq;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub struct Authorized;
|
pub struct Authorized;
|
||||||
|
|
||||||
impl Authorization for 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 {
|
pub struct OutPoint {
|
||||||
txid: TxId,
|
txid: TxId,
|
||||||
n: u32,
|
n: u32,
|
||||||
|
@ -88,7 +88,7 @@ impl OutPoint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct TzeIn<Payload> {
|
pub struct TzeIn<Payload> {
|
||||||
pub prevout: OutPoint,
|
pub prevout: OutPoint,
|
||||||
pub witness: tze::Witness<Payload>,
|
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 struct TzeOut {
|
||||||
pub value: Amount,
|
pub value: Amount,
|
||||||
pub precondition: tze::Precondition,
|
pub precondition: tze::Precondition,
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
InvalidAmount,
|
InvalidAmount,
|
||||||
WitnessModeMismatch(u32, u32),
|
WitnessModeMismatch(u32, u32),
|
||||||
|
@ -42,7 +42,7 @@ pub struct TzeBuilder<'a, BuildCtx> {
|
||||||
vout: Vec<TzeOut>,
|
vout: Vec<TzeOut>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub struct Unauthorized;
|
pub struct Unauthorized;
|
||||||
|
|
||||||
impl Authorization for Unauthorized {
|
impl Authorization for Unauthorized {
|
||||||
|
|
|
@ -54,9 +54,7 @@ fn prevout_hash<TA: transparent::Authorization>(vin: &[TxIn<TA>]) -> Blake2bHash
|
||||||
fn sequence_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);
|
let mut data = Vec::with_capacity(vin.len() * 4);
|
||||||
for t_in in vin {
|
for t_in in vin {
|
||||||
(&mut data)
|
data.write_u32::<LittleEndian>(t_in.sequence).unwrap();
|
||||||
.write_u32::<LittleEndian>(t_in.sequence)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
Blake2bParams::new()
|
Blake2bParams::new()
|
||||||
.hash_length(32)
|
.hash_length(32)
|
||||||
|
@ -145,7 +143,7 @@ pub fn v4_signature_hash<
|
||||||
let hash_type = signable_input.hash_type();
|
let hash_type = signable_input.hash_type();
|
||||||
if tx.version.has_overwinter() {
|
if tx.version.has_overwinter() {
|
||||||
let mut personal = [0; 16];
|
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..])
|
(&mut personal[12..])
|
||||||
.write_u32::<LittleEndian>(tx.consensus_branch_id.into())
|
.write_u32::<LittleEndian>(tx.consensus_branch_id.into())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -252,8 +250,7 @@ pub fn v4_signature_hash<
|
||||||
bundle.vin[*index].prevout.write(&mut data).unwrap();
|
bundle.vin[*index].prevout.write(&mut data).unwrap();
|
||||||
script_code.write(&mut data).unwrap();
|
script_code.write(&mut data).unwrap();
|
||||||
data.extend_from_slice(&value.to_i64_le_bytes());
|
data.extend_from_slice(&value.to_i64_le_bytes());
|
||||||
(&mut data)
|
data.write_u32::<LittleEndian>(bundle.vin[*index].sequence)
|
||||||
.write_u32::<LittleEndian>(bundle.vin[*index].sequence)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
h.update(&data);
|
h.update(&data);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -87,7 +87,7 @@ pub(crate) fn transparent_sequence_hash<TransparentAuth: transparent::Authorizat
|
||||||
) -> Blake2bHash {
|
) -> Blake2bHash {
|
||||||
let mut h = hasher(ZCASH_SEQUENCE_HASH_PERSONALIZATION);
|
let mut h = hasher(ZCASH_SEQUENCE_HASH_PERSONALIZATION);
|
||||||
for t_in in vin {
|
for t_in in vin {
|
||||||
(&mut h).write_u32::<LittleEndian>(t_in.sequence).unwrap();
|
h.write_u32::<LittleEndian>(t_in.sequence).unwrap();
|
||||||
}
|
}
|
||||||
h.finalize()
|
h.finalize()
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,7 @@ pub(crate) fn to_hash(
|
||||||
#[cfg(feature = "zfuture")] tze_digests: Option<&TzeDigests<Blake2bHash>>,
|
#[cfg(feature = "zfuture")] tze_digests: Option<&TzeDigests<Blake2bHash>>,
|
||||||
) -> Blake2bHash {
|
) -> Blake2bHash {
|
||||||
let mut personal = [0; 16];
|
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..])
|
(&mut personal[12..])
|
||||||
.write_u32::<LittleEndian>(consensus_branch_id.into())
|
.write_u32::<LittleEndian>(consensus_branch_id.into())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -513,7 +513,7 @@ impl TransactionDigest<Authorized> for BlockTxCommitmentDigester {
|
||||||
let digests = [transparent_digest, sapling_digest, orchard_digest];
|
let digests = [transparent_digest, sapling_digest, orchard_digest];
|
||||||
|
|
||||||
let mut personal = [0; 16];
|
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..])
|
(&mut personal[12..])
|
||||||
.write_u32::<LittleEndian>(consensus_branch_id.into())
|
.write_u32::<LittleEndian>(consensus_branch_id.into())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -98,7 +98,7 @@ impl FvkTag {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A child index for a derived key
|
/// A child index for a derived key
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum ChildIndex {
|
pub enum ChildIndex {
|
||||||
NonHardened(u32),
|
NonHardened(u32),
|
||||||
Hardened(u32), // Hardened(n) == n + (1 << 31) == n' in path notation
|
Hardened(u32), // Hardened(n) == n + (1 << 31) == n' in path notation
|
||||||
|
@ -125,7 +125,7 @@ impl ChildIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A BIP-32 chain code
|
/// A BIP-32 chain code
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub struct ChainCode([u8; 32]);
|
pub struct ChainCode([u8; 32]);
|
||||||
|
|
||||||
impl ChainCode {
|
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]);
|
pub struct DiversifierIndex(pub [u8; 11]);
|
||||||
|
|
||||||
impl Default for DiversifierIndex {
|
impl Default for DiversifierIndex {
|
||||||
|
@ -154,7 +154,7 @@ impl From<u32> for DiversifierIndex {
|
||||||
impl From<u64> for DiversifierIndex {
|
impl From<u64> for DiversifierIndex {
|
||||||
fn from(i: u64) -> Self {
|
fn from(i: u64) -> Self {
|
||||||
let mut result = DiversifierIndex([0; 11]);
|
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
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ impl DiversifierIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A key used to derive diversifiers for a particular child key
|
/// 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]);
|
pub struct DiversifierKey([u8; 32]);
|
||||||
|
|
||||||
impl DiversifierKey {
|
impl DiversifierKey {
|
||||||
|
@ -437,19 +437,19 @@ impl ExtendedSpendingKey {
|
||||||
let depth = b[0];
|
let depth = b[0];
|
||||||
|
|
||||||
let mut parent_fvk_tag = FvkTag([0; 4]);
|
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];
|
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 child_index = ChildIndex::from_index(u32::from_le_bytes(ci_bytes));
|
||||||
|
|
||||||
let mut chain_code = ChainCode([0u8; 32]);
|
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 expsk = ExpandedSpendingKey::from_bytes(&b[41..137])?;
|
||||||
|
|
||||||
let mut dk = DiversifierKey([0u8; 32]);
|
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 {
|
Ok(ExtendedSpendingKey {
|
||||||
depth,
|
depth,
|
||||||
|
@ -489,11 +489,11 @@ impl ExtendedSpendingKey {
|
||||||
pub fn to_bytes(&self) -> [u8; 169] {
|
pub fn to_bytes(&self) -> [u8; 169] {
|
||||||
let mut result = [0u8; 169];
|
let mut result = [0u8; 169];
|
||||||
result[0] = self.depth;
|
result[0] = self.depth;
|
||||||
(&mut result[1..5]).copy_from_slice(&self.parent_fvk_tag.as_bytes()[..]);
|
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()[..]);
|
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()[..]);
|
result[9..41].copy_from_slice(&self.chain_code.as_bytes()[..]);
|
||||||
(&mut result[41..137]).copy_from_slice(&self.expsk.to_bytes()[..]);
|
result[41..137].copy_from_slice(&self.expsk.to_bytes()[..]);
|
||||||
(&mut result[137..169]).copy_from_slice(&self.dk.as_bytes()[..]);
|
result[137..169].copy_from_slice(&self.dk.as_bytes()[..]);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,7 +243,7 @@ impl SaplingProvingContext {
|
||||||
// Construct signature message
|
// Construct signature message
|
||||||
let mut data_to_be_signed = [0u8; 64];
|
let mut data_to_be_signed = [0u8; 64];
|
||||||
data_to_be_signed[0..32].copy_from_slice(&bvk.0.to_bytes());
|
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
|
// Sign
|
||||||
Ok(bsk.sign(
|
Ok(bsk.sign(
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl SaplingVerificationContextInner {
|
||||||
// Compute the signature's message for rk/spend_auth_sig
|
// Compute the signature's message for rk/spend_auth_sig
|
||||||
let mut data_to_be_signed = [0u8; 64];
|
let mut data_to_be_signed = [0u8; 64];
|
||||||
data_to_be_signed[0..32].copy_from_slice(&rk.0.to_bytes());
|
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
|
// Verify the spend_auth_sig
|
||||||
let rk_affine = rk.0.to_affine();
|
let rk_affine = rk.0.to_affine();
|
||||||
|
@ -158,7 +158,7 @@ impl SaplingVerificationContextInner {
|
||||||
// Compute the signature's message for bvk/binding_sig
|
// Compute the signature's message for bvk/binding_sig
|
||||||
let mut data_to_be_signed = [0u8; 64];
|
let mut data_to_be_signed = [0u8; 64];
|
||||||
data_to_be_signed[0..32].copy_from_slice(&bvk.0.to_bytes());
|
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
|
// Verify the binding_sig
|
||||||
binding_sig_verifier(bvk, data_to_be_signed, binding_sig)
|
binding_sig_verifier(bvk, data_to_be_signed, binding_sig)
|
||||||
|
|
Loading…
Reference in New Issue