Add test for tze txn parsing.

This commit is contained in:
Kris Nuttycombe 2020-06-05 17:20:28 -06:00
parent 93ffd94af0
commit 8299f336d3
5 changed files with 43 additions and 5 deletions

View File

@ -13,3 +13,7 @@ members = [
lto = true lto = true
panic = 'abort' panic = 'abort'
codegen-units = 1 codegen-units = 1
[profile.dev]
debug = true
opt-level = 0

View File

@ -75,7 +75,7 @@ impl<'a> demo::Context for Context<'a> {
} }
/// Wire identifier for the dummy network upgrade epoch. /// Wire identifier for the dummy network upgrade epoch.
pub const V1_EPOCH_ID: u32 = 0x7473_6554; pub const NEXT_BRANCH_ID: u32 = 0x7374f403;
/// A set of demo TZEs associated with the dummy network upgrade. /// A set of demo TZEs associated with the dummy network upgrade.
struct EpochV1; struct EpochV1;
@ -102,8 +102,9 @@ impl Epoch for EpochV1 {
pub fn epoch_for_branch(consensus_branch_id: u32) -> Option<Box<dyn Epoch<Error = String>>> { pub fn epoch_for_branch(consensus_branch_id: u32) -> Option<Box<dyn Epoch<Error = String>>> {
// Map from consensus branch IDs to epochs. // Map from consensus branch IDs to epochs.
let _tmp_branch_id = NEXT_BRANCH_ID;
match consensus_branch_id { match consensus_branch_id {
V1_EPOCH_ID => Some(Box::new(EpochV1)), NEXT_BRANCH_ID => Some(Box::new(EpochV1)),
_ => None, _ => None,
} }
} }

View File

@ -231,6 +231,7 @@ impl Transaction {
} else { } else {
(vec![], vec![]) (vec![], vec![])
}; };
let lock_time = reader.read_u32::<LittleEndian>()?; let lock_time = reader.read_u32::<LittleEndian>()?;
let expiry_height = if is_overwinter_v3 || is_sapling_v4 || has_tze { let expiry_height = if is_overwinter_v3 || is_sapling_v4 || has_tze {
reader.read_u32::<LittleEndian>()? reader.read_u32::<LittleEndian>()?

View File

@ -47,6 +47,7 @@ enum SigHashVersion {
Sprout, Sprout,
Overwinter, Overwinter,
Sapling, Sapling,
Next,
} }
impl SigHashVersion { impl SigHashVersion {
@ -55,7 +56,7 @@ impl SigHashVersion {
match tx.version_group_id { match tx.version_group_id {
OVERWINTER_VERSION_GROUP_ID => SigHashVersion::Overwinter, OVERWINTER_VERSION_GROUP_ID => SigHashVersion::Overwinter,
SAPLING_VERSION_GROUP_ID => SigHashVersion::Sapling, SAPLING_VERSION_GROUP_ID => SigHashVersion::Sapling,
FUTURE_VERSION_GROUP_ID => SigHashVersion::Sapling, //FIXME FUTURE_VERSION_GROUP_ID => SigHashVersion::Next,
_ => unimplemented!(), _ => unimplemented!(),
} }
} else { } else {
@ -193,7 +194,7 @@ pub fn signature_hash_data<'a>(
) -> Vec<u8> { ) -> Vec<u8> {
let sigversion = SigHashVersion::from_tx(tx); let sigversion = SigHashVersion::from_tx(tx);
match sigversion { match sigversion {
SigHashVersion::Overwinter | SigHashVersion::Sapling => { SigHashVersion::Overwinter | SigHashVersion::Sapling | SigHashVersion::Next => {
let mut personal = [0; 16]; let mut personal = [0; 16];
(&mut personal[..12]).copy_from_slice(ZCASH_SIGHASH_PERSONALIZATION_PREFIX); (&mut personal[..12]).copy_from_slice(ZCASH_SIGHASH_PERSONALIZATION_PREFIX);
(&mut personal[12..]) (&mut personal[12..])
@ -262,11 +263,12 @@ pub fn signature_hash_data<'a>(
.unwrap(); .unwrap();
h.update(&data); h.update(&data);
} }
SignableInput::Tze { SignableInput::Tze {
index, index,
precondition, precondition,
value, value,
} => { } if sigversion == SigHashVersion::Next => {
let mut data = ZCASH_TZE_SIGNED_INPUT_DOMAIN_SEPARATOR.to_vec(); let mut data = ZCASH_TZE_SIGNED_INPUT_DOMAIN_SEPARATOR.to_vec();
tx.tze_inputs[index].prevout.write(&mut data).unwrap(); tx.tze_inputs[index].prevout.write(&mut data).unwrap();

View File

@ -66,6 +66,36 @@ fn tx_write_rejects_unexpected_binding_sig() {
} }
} }
#[test]
fn test_tze_tx_parse() {
let txn_bytes = vec![
0xFF, 0xFF, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0x52, 0x52, 0x52, 0x52,
0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52,
0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x30, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x20, 0xd9, 0x81, 0x80, 0x87, 0xde, 0x72, 0x44, 0xab, 0xc1, 0xb5, 0xfc,
0xf2, 0x8e, 0x55, 0xe4, 0x2c, 0x7f, 0xf9, 0xc6, 0x78, 0xc0, 0x60, 0x51, 0x81, 0xf3, 0x7a,
0xc5, 0xd7, 0x41, 0x4a, 0x7b, 0x95, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
let tx = Transaction::read(&txn_bytes[..]);
match tx {
Ok(tx) => assert!(!tx.tze_inputs.is_empty()),
Err(e) => assert!(
false,
format!(
"An error occurred parsing a serialized TZE transaction: {}",
e
)
),
}
}
mod data; mod data;
#[test] #[test]
fn zip_0143() { fn zip_0143() {