Add ZIP-244 test vectors.
This commit is contained in:
parent
6348400cf4
commit
df0095ebba
|
@ -374,7 +374,7 @@ impl<'a, P: consensus::Parameters, R: RngCore> Builder<'a, P, R> {
|
|||
// for now we need to continue to compute it here.
|
||||
let shielded_sig_commitment = signature_hash(
|
||||
&unauthed_tx,
|
||||
SignableInput::Shielded,
|
||||
&SignableInput::Shielded,
|
||||
&txid_parts,
|
||||
SIGHASH_ALL,
|
||||
);
|
||||
|
|
|
@ -203,7 +203,7 @@ impl Bundle<Unauthorized> {
|
|||
.map(|(i, info)| {
|
||||
let sighash = signature_hash(
|
||||
mtx,
|
||||
SignableInput::transparent(i, &info.coin.script_pubkey, info.coin.value),
|
||||
&SignableInput::transparent(i, &info.coin.script_pubkey, info.coin.value),
|
||||
txid_parts_cache,
|
||||
SIGHASH_ALL,
|
||||
);
|
||||
|
|
|
@ -119,7 +119,7 @@ pub fn signature_hash<
|
|||
A: Authorization<SaplingAuth = SA>,
|
||||
>(
|
||||
tx: &TransactionData<A>,
|
||||
signable_input: SignableInput<'a>,
|
||||
signable_input: &SignableInput<'a>,
|
||||
txid_parts: &TxDigests<Blake2bHash>,
|
||||
hash_type: u32,
|
||||
) -> SignatureHash {
|
||||
|
|
|
@ -140,7 +140,7 @@ pub fn v4_signature_hash<
|
|||
A: Authorization<SaplingAuth = SA>,
|
||||
>(
|
||||
tx: &TransactionData<A>,
|
||||
signable_input: SignableInput<'_>,
|
||||
signable_input: &SignableInput<'_>,
|
||||
hash_type: u32,
|
||||
) -> Blake2bHash {
|
||||
if tx.version.has_overwinter() {
|
||||
|
@ -191,7 +191,7 @@ pub fn v4_signature_hash<
|
|||
.as_bytes(),
|
||||
);
|
||||
} else if (hash_type & SIGHASH_MASK) == SIGHASH_SINGLE {
|
||||
match (tx.transparent_bundle.as_ref(), &signable_input) {
|
||||
match (tx.transparent_bundle.as_ref(), signable_input) {
|
||||
(Some(b), SignableInput::Transparent(input)) if input.index() < b.vout.len() => {
|
||||
h.update(single_output_hash(&b.vout[input.index()]).as_bytes())
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ fn tze_input_sigdigests<A: tze::Authorization>(
|
|||
pub fn v5_signature_hash<A: Authorization>(
|
||||
tx: &TransactionData<A>,
|
||||
txid_parts: &TxDigests<Blake2bHash>,
|
||||
signable_input: SignableInput<'_>,
|
||||
signable_input: &SignableInput<'_>,
|
||||
hash_type: u32,
|
||||
) -> Blake2bHash {
|
||||
match signable_input {
|
||||
|
@ -146,7 +146,7 @@ pub fn v5_signature_hash<A: Authorization>(
|
|||
txid_parts.header_digest,
|
||||
Some(&transparent_input_sigdigests(
|
||||
bundle,
|
||||
&input,
|
||||
input,
|
||||
txid_digests,
|
||||
hash_type,
|
||||
)),
|
||||
|
@ -172,7 +172,7 @@ pub fn v5_signature_hash<A: Authorization>(
|
|||
txid_parts.sapling_digest,
|
||||
txid_parts.orchard_digest,
|
||||
#[cfg(feature = "zfuture")]
|
||||
Some(&tze_input_sigdigests(bundle, &input, txid_digests)),
|
||||
Some(&tze_input_sigdigests(bundle, input, txid_digests)),
|
||||
)
|
||||
} else {
|
||||
panic!("It is not possible to sign a tze input with missing bundle data.")
|
||||
|
|
|
@ -2,10 +2,18 @@ use std::ops::Deref;
|
|||
|
||||
use proptest::prelude::*;
|
||||
|
||||
use crate::consensus::BranchId;
|
||||
use crate::{
|
||||
consensus::BranchId,
|
||||
legacy::Script
|
||||
};
|
||||
|
||||
use super::{
|
||||
components::Amount, sighash::SignableInput, sighash_v4::v4_signature_hash, testing::arb_tx,
|
||||
components::Amount,
|
||||
sighash::{SignableInput, SIGHASH_ALL, SIGHASH_ANYONECANPAY, SIGHASH_NONE, SIGHASH_SINGLE},
|
||||
txid::TxIdDigester,
|
||||
sighash_v4::v4_signature_hash,
|
||||
sighash_v5::v5_signature_hash,
|
||||
testing::arb_tx,
|
||||
Transaction,
|
||||
};
|
||||
|
||||
|
@ -124,7 +132,7 @@ fn zip_0143() {
|
|||
};
|
||||
|
||||
assert_eq!(
|
||||
v4_signature_hash(tx.deref(), signable_input, tv.hash_type).as_ref(),
|
||||
v4_signature_hash(tx.deref(), &signable_input, tv.hash_type).as_ref(),
|
||||
tv.sighash
|
||||
);
|
||||
}
|
||||
|
@ -144,8 +152,86 @@ fn zip_0243() {
|
|||
};
|
||||
|
||||
assert_eq!(
|
||||
v4_signature_hash(tx.deref(), signable_input, tv.hash_type).as_ref(),
|
||||
v4_signature_hash(tx.deref(), &signable_input, tv.hash_type).as_ref(),
|
||||
tv.sighash
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zip_0244() {
|
||||
for tv in self::data::zip_0244::make_test_vectors() {
|
||||
let tx = Transaction::read(&tv.tx[..], BranchId::Nu5).unwrap();
|
||||
let txid_parts = tx.deref().digest(TxIdDigester);
|
||||
assert_eq!(tx.txid.as_ref(), &tv.txid);
|
||||
|
||||
match tv.transparent_input {
|
||||
Some(n) => {
|
||||
let script = Script(tv.script_code.unwrap());
|
||||
let signable_input = SignableInput::transparent(
|
||||
n as usize,
|
||||
&script,
|
||||
Amount::from_nonnegative_i64(tv.amount.unwrap()).unwrap(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
v5_signature_hash(tx.deref(), &txid_parts, &signable_input, SIGHASH_ALL).as_ref(),
|
||||
&tv.sighash_all
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
v5_signature_hash(tx.deref(), &txid_parts, &signable_input, SIGHASH_NONE)
|
||||
.as_ref(),
|
||||
&tv.sighash_none.unwrap()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
v5_signature_hash(tx.deref(), &txid_parts, &signable_input, SIGHASH_SINGLE)
|
||||
.as_ref(),
|
||||
&tv.sighash_single.unwrap()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
v5_signature_hash(
|
||||
tx.deref(),
|
||||
&txid_parts,
|
||||
&signable_input,
|
||||
SIGHASH_ALL | SIGHASH_ANYONECANPAY
|
||||
)
|
||||
.as_ref(),
|
||||
&tv.sighash_all_anyone.unwrap()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
v5_signature_hash(
|
||||
tx.deref(),
|
||||
&txid_parts,
|
||||
&signable_input,
|
||||
SIGHASH_NONE | SIGHASH_ANYONECANPAY
|
||||
)
|
||||
.as_ref(),
|
||||
&tv.sighash_none_anyone.unwrap()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
v5_signature_hash(
|
||||
tx.deref(),
|
||||
&txid_parts,
|
||||
&signable_input,
|
||||
SIGHASH_SINGLE | SIGHASH_ANYONECANPAY
|
||||
)
|
||||
.as_ref(),
|
||||
&tv.sighash_single_anyone.unwrap()
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
let signable_input = SignableInput::Shielded;
|
||||
|
||||
assert_eq!(
|
||||
v5_signature_hash(tx.deref(), &txid_parts, &signable_input, SIGHASH_ALL).as_ref(),
|
||||
tv.sighash_all
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue