From 70857b0eeddee0fab848d9831df328581b53a42c Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 31 Jul 2019 16:18:31 +0100 Subject: [PATCH] Pass Script to signature_hash by reference --- zcash_primitives/src/transaction/sighash.rs | 4 +- zcash_primitives/src/transaction/tests.rs | 48 ++++++++++----------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/zcash_primitives/src/transaction/sighash.rs b/zcash_primitives/src/transaction/sighash.rs index 41c6da258..f6dcd30d4 100644 --- a/zcash_primitives/src/transaction/sighash.rs +++ b/zcash_primitives/src/transaction/sighash.rs @@ -154,7 +154,7 @@ pub fn signature_hash_data( tx: &TransactionData, consensus_branch_id: u32, hash_type: u32, - transparent_input: Option<(usize, Script, Amount)>, + transparent_input: Option<(usize, &Script, Amount)>, ) -> Vec { let sigversion = SigHashVersion::from_tx(tx); match sigversion { @@ -232,7 +232,7 @@ pub fn signature_hash( tx: &Transaction, consensus_branch_id: u32, hash_type: u32, - transparent_input: Option<(usize, Script, Amount)>, + transparent_input: Option<(usize, &Script, Amount)>, ) -> Vec { signature_hash_data(tx, consensus_branch_id, hash_type, transparent_input) } diff --git a/zcash_primitives/src/transaction/tests.rs b/zcash_primitives/src/transaction/tests.rs index 99c7a953e..19b110ad2 100644 --- a/zcash_primitives/src/transaction/tests.rs +++ b/zcash_primitives/src/transaction/tests.rs @@ -212,7 +212,7 @@ fn tx_write_rejects_unexpected_binding_sig() { fn zip_0143() { struct TestVector { tx: Vec, - script_code: Vec, + script_code: Script, transparent_input: Option, hash_type: u32, amount: i64, @@ -229,7 +229,7 @@ fn zip_0143() { 0xb2, 0x83, 0x5a, 0x08, 0x05, 0x75, 0x02, 0x00, 0x02, 0x51, 0x51, 0x48, 0x1c, 0xdd, 0x86, 0xb3, 0xcc, 0x43, 0x18, 0x00, ], - script_code: vec![0x6a, 0x00, 0x00, 0x00, 0x63, 0xac, 0x53], + script_code: Script(vec![0x6a, 0x00, 0x00, 0x00, 0x63, 0xac, 0x53]), transparent_input: None, hash_type: 1, amount: 1672704339313879, @@ -518,7 +518,7 @@ fn zip_0143() { 0xb1, 0xfa, 0x45, 0xad, 0x61, 0xce, 0x9a, 0x1c, 0x47, 0x27, 0xb7, 0xaa, 0xa5, 0x35, 0x62, 0xf5, 0x23, 0xe7, 0x39, 0x52, ], - script_code: vec![0x53], + script_code: Script(vec![0x53]), transparent_input: Some(1), hash_type: 3, amount: 365293780364847, @@ -678,7 +678,7 @@ fn zip_0143() { 0x62, 0x91, 0x85, 0x00, 0x2c, 0x72, 0xc0, 0x12, 0xc4, 0x14, 0xd2, 0x38, 0x2a, 0x6d, 0x47, 0xc7, 0xb3, 0xde, 0xab, 0xa7, ], - script_code: vec![0xac, 0x00], + script_code: Script(vec![0xac, 0x00]), transparent_input: Some(0), hash_type: 3, amount: 711752082734717, @@ -960,7 +960,7 @@ fn zip_0143() { 0xce, 0x1f, 0xca, 0x2c, 0x63, 0xfe, 0x06, 0xb7, 0x98, 0x9d, 0x58, 0x4f, 0xa7, 0xd7, 0x82, 0xa8, 0x8c, 0x1e, 0x7d, 0x64, 0xb6, 0xfb, 0xf5, 0x5e, 0x35, ], - script_code: vec![0x6a, 0x53, 0x53, 0x63], + script_code: Script(vec![0x6a, 0x53, 0x53, 0x63]), transparent_input: None, hash_type: 1, amount: 379068098637835, @@ -1119,7 +1119,7 @@ fn zip_0143() { 0xc1, 0xc4, 0xf2, 0xca, 0xcd, 0xa3, 0x0b, 0xdb, 0x69, 0x30, 0x65, 0x3c, 0x0c, 0xc4, 0x48, 0x6e, 0x60, 0xe8, 0x9f, 0xa8, 0x49, 0xb3, ], - script_code: vec![0x53, 0x52], + script_code: Script(vec![0x53, 0x52]), transparent_input: Some(0), hash_type: 3, amount: 1437866676382615, @@ -1139,7 +1139,7 @@ fn zip_0143() { 0x08, 0xf0, 0x83, 0x05, 0x00, 0x09, 0x63, 0x6a, 0x52, 0x63, 0x51, 0x63, 0x00, 0x6a, 0xac, 0x9a, 0xbc, 0xef, 0x2a, 0x99, 0x08, 0x73, 0x19, 0x00, ], - script_code: vec![0x63], + script_code: Script(vec![0x63]), transparent_input: None, hash_type: 1, amount: 1993227025071196, @@ -1162,7 +1162,7 @@ fn zip_0143() { 0x87, 0x01, 0xff, 0x01, 0x86, 0xd2, 0x6f, 0xee, 0x28, 0xca, 0x06, 0x00, 0x01, 0xac, 0x5a, 0xa7, 0x27, 0xab, 0x79, 0x85, 0xda, 0x0e, 0x00, ], - script_code: vec![0x65, 0x53, 0x51], + script_code: Script(vec![0x65, 0x53, 0x51]), transparent_input: Some(1), hash_type: 130, amount: 449567650863240, @@ -1444,7 +1444,7 @@ fn zip_0143() { 0xba, 0xfe, 0xc8, 0x84, 0x0c, 0x2d, 0x25, 0x5b, 0xf5, 0xad, 0x61, 0xc4, 0x60, 0xf9, 0x8f, 0xeb, 0x82, 0xa1, 0x0f, 0xa1, 0xc0, ], - script_code: vec![0x65, 0x6a, 0x65, 0x51, 0x52, 0x65, 0x63], + script_code: Script(vec![0x65, 0x6a, 0x65, 0x51, 0x52, 0x65, 0x63]), transparent_input: None, hash_type: 1, amount: 1712463999734827, @@ -1602,7 +1602,7 @@ fn zip_0143() { 0xd9, 0xa9, 0xd9, 0xf5, 0x4f, 0xb2, 0xfe, 0x8f, 0x9f, 0x05, 0xcd, 0x11, 0x1e, 0xe4, 0x6c, 0x47, 0x10, 0xf6, 0xf6, 0x3a, 0x62, 0x69, 0x45, 0x57, ], - script_code: vec![0x53, 0x52, 0x00], + script_code: Script(vec![0x53, 0x52, 0x00]), transparent_input: Some(1), hash_type: 1, amount: 1564816348934332, @@ -1885,7 +1885,7 @@ fn zip_0143() { 0x54, 0xa7, 0x89, 0x73, 0x5b, 0x03, 0x49, 0xc4, 0xd5, 0x1c, 0x88, 0x9d, 0x08, 0x95, 0x2d, 0xdd, 0x54, 0x88, 0xbe, 0x95, 0x56, 0x05, 0x94, 0xe6, ], - script_code: vec![0x52, 0x63, 0x53, 0x51, 0x65], + script_code: Script(vec![0x52, 0x63, 0x53, 0x51, 0x65]), transparent_input: Some(0), hash_type: 2, amount: 483959951916902, @@ -1903,7 +1903,7 @@ fn zip_0143() { let transparent_input = if let Some(n) = tv.transparent_input { Some(( n as usize, - Script(tv.script_code), + &tv.script_code, Amount::from_nonnegative_i64(tv.amount).unwrap(), )) } else { @@ -1921,7 +1921,7 @@ fn zip_0143() { fn zip_0243() { struct TestVector { tx: Vec, - script_code: Vec, + script_code: Script, transparent_input: Option, hash_type: u32, amount: i64, @@ -2229,7 +2229,7 @@ fn zip_0243() { 0xe4, 0x62, 0xef, 0xf9, 0xba, 0x8b, 0x3f, 0x4b, 0xfa, 0xa1, 0x30, 0x0c, 0x26, 0x92, 0x5a, 0x87, ], - script_code: vec![0x63], + script_code: Script(vec![0x63]), transparent_input: None, hash_type: 1, amount: 1969273897303781, @@ -2462,7 +2462,7 @@ fn zip_0243() { 0xed, 0x6a, 0x9f, 0x08, 0x46, 0x4d, 0x56, 0x55, 0x93, 0xe1, 0xa6, 0x3b, 0x93, 0x85, 0x36, 0xb4, 0x92, 0x44, 0xe9, 0x7d, ], - script_code: vec![], + script_code: Script(vec![]), transparent_input: Some(1), hash_type: 2, amount: 652655344020909, @@ -3048,7 +3048,7 @@ fn zip_0243() { 0x76, 0xc5, 0x3b, 0x4d, 0xf7, 0x95, 0x39, 0x81, 0xd5, 0x5a, 0x96, 0xa6, 0xdc, 0xff, 0x99, 0x04, 0xa9, 0x08, 0x42, 0xe5, 0xba, 0xfe, 0xc8, 0x84, 0x0c, 0x2d, ], - script_code: vec![0x53, 0x63, 0x63, 0x51, 0xac, 0x00, 0x51], + script_code: Script(vec![0x53, 0x63, 0x63, 0x51, 0xac, 0x00, 0x51]), transparent_input: None, hash_type: 1, amount: 1345602751504862, @@ -3369,7 +3369,7 @@ fn zip_0243() { 0xde, 0x7f, 0x8e, 0x6a, 0x5c, 0x62, 0xa7, 0x77, 0xd1, 0x75, 0x00, 0x2a, 0x13, 0x7d, 0xe8, 0x5b, 0x88, ], - script_code: vec![], + script_code: Script(vec![]), transparent_input: None, hash_type: 1, amount: 1039204199089370, @@ -3519,7 +3519,7 @@ fn zip_0243() { 0xb5, 0x58, 0x02, 0x9a, 0x36, 0x02, 0x4d, 0x2e, 0x79, 0x0f, 0xc6, 0xfd, 0x66, 0x7f, 0x17, 0x6e, 0x0a, 0xa9, 0x9d, 0xd1, 0xd7, 0x2b, 0x57, ], - script_code: vec![0x6a, 0x51, 0x65, 0xac], + script_code: Script(vec![0x6a, 0x51, 0x65, 0xac]), transparent_input: None, hash_type: 1, amount: 691732482992802, @@ -3919,7 +3919,7 @@ fn zip_0243() { 0x30, 0x3a, 0x3a, 0xb9, 0xbb, 0x2e, 0xe3, 0x79, 0xb9, 0xaf, 0xcd, 0x1f, 0x6a, 0x3c, 0xb9, 0x00, 0x0b, 0xb1, 0x4e, ], - script_code: vec![0x53, 0x63, 0x63, 0xac, 0x63, 0x52], + script_code: Script(vec![0x53, 0x63, 0x63, 0xac, 0x63, 0x52]), transparent_input: None, hash_type: 1, amount: 1152393991505765, @@ -4083,7 +4083,7 @@ fn zip_0243() { 0x53, 0xf1, 0xd0, 0xc8, 0x65, 0xa9, 0x4a, 0xa4, 0x56, 0xdc, 0xd1, 0x8a, 0x39, 0xe2, 0xf5, 0x85, 0xd9, 0xbe, 0xa8, ], - script_code: vec![0x63, 0x00, 0x6a, 0x53, 0x63, 0x6a, 0xac, 0x00], + script_code: Script(vec![0x63, 0x00, 0x6a, 0x53, 0x63, 0x6a, 0xac, 0x00]), transparent_input: None, hash_type: 1, amount: 1788797765223798, @@ -4681,7 +4681,7 @@ fn zip_0243() { 0x31, 0xbd, 0x7c, 0x52, 0x22, 0xb6, 0x70, 0x61, 0x6e, 0x4b, 0x6c, 0xa8, 0xa2, 0x35, 0x50, 0xca, 0xd8, 0xac, 0x0d, 0xdb, 0x76, 0x45, 0xe2, 0xb9, 0x71, 0x3b, 0xe7, ], - script_code: vec![0x6a, 0x00, 0x00, 0x65, 0x53, 0xac, 0x63, 0x53, 0x63], + script_code: Script(vec![0x6a, 0x00, 0x00, 0x65, 0x53, 0xac, 0x63, 0x53, 0x63]), transparent_input: None, hash_type: 1, amount: 1871432121379810, @@ -5190,7 +5190,7 @@ fn zip_0243() { 0x1b, 0x48, 0x09, 0x8e, 0xba, 0x2c, 0x2e, 0xc2, 0x0a, 0x0a, 0xc0, 0x44, 0x3b, 0xa8, 0xe9, 0x48, 0x7b, 0xcf, 0x7d, ], - script_code: vec![0xac, 0x53, 0x63, 0x52, 0x6a, 0x51, 0xac], + script_code: Script(vec![0xac, 0x53, 0x63, 0x52, 0x6a, 0x51, 0xac]), transparent_input: None, hash_type: 1, amount: 1501997449504444, @@ -5380,7 +5380,7 @@ fn zip_0243() { 0xfb, 0x34, 0x1e, 0xf5, 0xff, 0xb4, 0x2b, 0xc2, 0xab, 0xc5, 0x08, 0xff, 0x23, 0x12, 0x48, 0xf2, 0xc2, 0xdc, 0x15, 0x77, 0x0d, 0x33, 0x72, 0x2b, 0x9c, 0x9d, 0xae, ], - script_code: vec![0xac, 0x65], + script_code: Script(vec![0xac, 0x65]), transparent_input: Some(0), hash_type: 3, amount: 391892287957268, @@ -5398,7 +5398,7 @@ fn zip_0243() { let transparent_input = if let Some(n) = tv.transparent_input { Some(( n as usize, - Script(tv.script_code), + &tv.script_code, Amount::from_nonnegative_i64(tv.amount).unwrap(), )) } else {