Skip to content

Commit 56761d3

Browse files
committed
Add tx_sighash to VerifiedUnminedTx
1 parent 4564f18 commit 56761d3

File tree

10 files changed

+39
-11
lines changed

10 files changed

+39
-11
lines changed

zebra-chain/src/tests/vectors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
block::Block,
99
parameters::Network,
1010
serialization::ZcashDeserializeInto,
11-
transaction::{UnminedTx, VerifiedUnminedTx},
11+
transaction::{SigHash, UnminedTx, VerifiedUnminedTx},
1212
};
1313

1414
use zebra_test::vectors::{
@@ -74,6 +74,7 @@ impl Network {
7474
transaction,
7575
Amount::try_from(1_000_000).expect("valid amount"),
7676
0,
77+
SigHash([0; 32]),
7778
)
7879
.ok()
7980
})

zebra-chain/src/transaction/arbitrary.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use crate::{
1515
primitives::{Bctv14Proof, Groth16Proof, Halo2Proof, ZkSnarkProof},
1616
sapling::{self, AnchorVariant, PerSpendAnchor, SharedAnchor},
1717
serialization::{self, ZcashDeserializeInto},
18-
sprout, transparent,
18+
sprout,
19+
transaction::SigHash,
20+
transparent,
1921
value_balance::{ValueBalance, ValueBalanceError},
2022
LedgerState,
2123
};
@@ -942,6 +944,7 @@ impl Arbitrary for VerifiedUnminedTx {
942944
any::<f32>(),
943945
serialization::arbitrary::datetime_u32(),
944946
any::<block::Height>(),
947+
any::<[u8; 32]>().prop_map(SigHash),
945948
)
946949
.prop_map(
947950
|(
@@ -952,6 +955,7 @@ impl Arbitrary for VerifiedUnminedTx {
952955
fee_weight_ratio,
953956
time,
954957
height,
958+
tx_sighash,
955959
)| {
956960
if unpaid_actions > conventional_actions {
957961
unpaid_actions = conventional_actions;
@@ -969,6 +973,7 @@ impl Arbitrary for VerifiedUnminedTx {
969973
fee_weight_ratio,
970974
time: Some(time),
971975
height: Some(height),
976+
tx_sighash,
972977
}
973978
},
974979
)

zebra-chain/src/transaction/unmined.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
block::Height,
2323
serialization::ZcashSerialize,
2424
transaction::{
25-
AuthDigest, Hash,
25+
AuthDigest, Hash, SigHash,
2626
Transaction::{self, *},
2727
WtxId,
2828
},
@@ -369,6 +369,9 @@ pub struct VerifiedUnminedTx {
369369
/// The tip height when the transaction was added to the mempool, or None if
370370
/// it has not reached the mempool yet.
371371
pub height: Option<Height>,
372+
373+
/// The shielded sighash for this transaction.
374+
pub tx_sighash: SigHash,
372375
}
373376

374377
impl fmt::Debug for VerifiedUnminedTx {
@@ -396,6 +399,7 @@ impl VerifiedUnminedTx {
396399
transaction: UnminedTx,
397400
miner_fee: Amount<NonNegative>,
398401
legacy_sigop_count: u32,
402+
tx_sighash: SigHash,
399403
) -> Result<Self, zip317::Error> {
400404
let fee_weight_ratio = zip317::conventional_fee_weight_ratio(&transaction, miner_fee);
401405
let conventional_actions = zip317::conventional_actions(&transaction.transaction);
@@ -412,6 +416,7 @@ impl VerifiedUnminedTx {
412416
unpaid_actions,
413417
time: None,
414418
height: None,
419+
tx_sighash,
415420
})
416421
}
417422

zebra-consensus/src/transaction.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ where
413413
tx_id,
414414
miner_fee: Some(verified_tx.miner_fee),
415415
sigops: verified_tx.sigops,
416-
tx_sighash: SigHash([0u8; 32]) // FIXME: use verified_tx.tx_sighash instead
416+
tx_sighash: verified_tx.tx_sighash,
417417
});
418418
}
419419

@@ -597,6 +597,7 @@ where
597597
tx,
598598
miner_fee.expect("fee should have been checked earlier"),
599599
sigops,
600+
tx_sighash
600601
)?;
601602

602603
if let Some(mut mempool) = mempool {

zebra-rpc/src/methods/tests/vectors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use zebra_chain::{
2323
NetworkKind,
2424
},
2525
serialization::{DateTime32, ZcashDeserializeInto, ZcashSerialize},
26-
transaction::{zip317, UnminedTxId, VerifiedUnminedTx},
26+
transaction::{zip317, SigHash, UnminedTxId, VerifiedUnminedTx},
2727
work::difficulty::{CompactDifficulty, ExpandedDifficulty, ParameterDifficulty as _, U256},
2828
};
2929
use zebra_consensus::MAX_BLOCK_SIGOPS;
@@ -2322,6 +2322,7 @@ async fn gbt_with(net: Network, addr: ZcashAddress) {
23222322
fee_weight_ratio: 1.0,
23232323
time: None,
23242324
height: None,
2325+
tx_sighash: SigHash([0; 32]),
23252326
};
23262327

23272328
let next_fake_tip_hash =

zebrad/src/components/inbound/tests/fake_peer_set.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use zebra_chain::{
1515
fmt::humantime_seconds,
1616
parameters::Network::{self, *},
1717
serialization::{DateTime32, ZcashDeserializeInto},
18-
transaction::{UnminedTx, UnminedTxId, VerifiedUnminedTx},
18+
transaction::{SigHash, UnminedTx, UnminedTxId, VerifiedUnminedTx},
1919
};
2020
use zebra_consensus::{error::TransactionError, transaction, Config as ConsensusConfig};
2121
use zebra_network::{
@@ -171,6 +171,7 @@ async fn mempool_push_transaction() -> Result<(), crate::BoxError> {
171171
transaction,
172172
Amount::try_from(1_000_000).expect("valid amount"),
173173
0,
174+
SigHash([0; 32]),
174175
)
175176
.expect("verification should pass"),
176177
));
@@ -279,6 +280,7 @@ async fn mempool_advertise_transaction_ids() -> Result<(), crate::BoxError> {
279280
transaction,
280281
Amount::try_from(1_000_000).expect("valid amount"),
281282
0,
283+
SigHash([0; 32]),
282284
)
283285
.expect("verification should pass"),
284286
));
@@ -381,6 +383,7 @@ async fn mempool_transaction_expiration() -> Result<(), crate::BoxError> {
381383
transaction,
382384
Amount::try_from(1_000_000).expect("valid amount"),
383385
0,
386+
SigHash([0; 32]),
384387
)
385388
.expect("verification should pass"),
386389
));
@@ -520,6 +523,7 @@ async fn mempool_transaction_expiration() -> Result<(), crate::BoxError> {
520523
transaction,
521524
Amount::try_from(1_000_000).expect("valid amount"),
522525
0,
526+
SigHash([0; 32]),
523527
)
524528
.expect("verification should pass"),
525529
));

zebrad/src/components/mempool/storage/tests/prop.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use zebra_chain::{
1616
sapling,
1717
serialization::AtLeastOne,
1818
sprout,
19-
transaction::{self, JoinSplitData, Transaction, UnminedTxId, VerifiedUnminedTx},
19+
transaction::{self, JoinSplitData, SigHash, Transaction, UnminedTxId, VerifiedUnminedTx},
2020
transparent, LedgerState,
2121
};
2222

@@ -490,13 +490,15 @@ impl SpendConflictTestInput {
490490
// make sure miner fee is big enough for all cases
491491
Amount::try_from(1_000_000).expect("valid amount"),
492492
0,
493+
SigHash([0; 32]),
493494
)
494495
.expect("verification should pass"),
495496
VerifiedUnminedTx::new(
496497
second.0.into(),
497498
// make sure miner fee is big enough for all cases
498499
Amount::try_from(1_000_000).expect("valid amount"),
499500
0,
501+
SigHash([0; 32]),
500502
)
501503
.expect("verification should pass"),
502504
)
@@ -523,13 +525,15 @@ impl SpendConflictTestInput {
523525
// make sure miner fee is big enough for all cases
524526
Amount::try_from(1_000_000).expect("valid amount"),
525527
0,
528+
SigHash([0; 32]),
526529
)
527530
.expect("verification should pass"),
528531
VerifiedUnminedTx::new(
529532
second.0.into(),
530533
// make sure miner fee is big enough for all cases
531534
Amount::try_from(1_000_000).expect("valid amount"),
532535
0,
536+
SigHash([0; 32]),
533537
)
534538
.expect("verification should pass"),
535539
)
@@ -966,7 +970,10 @@ impl OrchardSpendConflict {
966970
///
967971
/// The transaction will then conflict with any other transaction with the same new nullifier.
968972
// TODO: Consider adding support of OrchardZSA.
969-
pub fn apply_to(self, orchard_shielded_data: &mut Option<orchard::ShieldedData<orchard::OrchardVanilla>>) {
973+
pub fn apply_to(
974+
self,
975+
orchard_shielded_data: &mut Option<orchard::ShieldedData<orchard::OrchardVanilla>>,
976+
) {
970977
if let Some(shielded_data) = orchard_shielded_data.as_mut() {
971978
shielded_data
972979
.actions

zebrad/src/components/mempool/storage/tests/vectors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use zebra_chain::{
1111
amount::{Amount, NonNegative},
1212
block::{Block, Height},
1313
parameters::Network,
14+
transaction::SigHash,
1415
};
1516

1617
use crate::components::mempool::{storage::*, Mempool};
@@ -275,6 +276,7 @@ fn mempool_expired_basic_for_network(network: Network) -> Result<()> {
275276
tx.into(),
276277
Amount::try_from(1_000_000).expect("valid amount"),
277278
0,
279+
SigHash([0; 32]),
278280
)
279281
.expect("verification should pass"),
280282
Vec::new(),

zebrad/src/components/mempool/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
use zebra_chain::{
1414
amount::{Amount, NonNegative},
1515
parameters::NetworkKind,
16-
transaction::{Transaction, UnminedTx, VerifiedUnminedTx},
16+
transaction::{SigHash, Transaction, UnminedTx, VerifiedUnminedTx},
1717
transparent::{self, Address},
1818
};
1919

@@ -110,7 +110,7 @@ pub fn standard_verified_unmined_tx_strategy() -> BoxedStrategy<VerifiedUnminedT
110110
let unmined_tx = UnminedTx::from(transaction);
111111
let miner_fee = unmined_tx.conventional_fee;
112112

113-
VerifiedUnminedTx::new(unmined_tx, miner_fee, 0)
113+
VerifiedUnminedTx::new(unmined_tx, miner_fee, 0, SigHash([0; 32]))
114114
.expect("standardized transaction should pass ZIP-317 checks")
115115
})
116116
.boxed()

zebrad/src/components/mempool/tests/vector.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use zebra_chain::{
1515
fmt::humantime_seconds,
1616
parameters::Network,
1717
serialization::ZcashDeserializeInto,
18-
transaction::{Transaction, VerifiedUnminedTx},
18+
transaction::{SigHash, Transaction, VerifiedUnminedTx},
1919
transparent::{self, OutPoint},
2020
};
2121
use zebra_consensus::transaction as tx;
@@ -951,6 +951,7 @@ async fn mempool_reverifies_after_tip_change() -> Result<(), Report> {
951951
transaction,
952952
Amount::try_from(1_000_000).expect("invalid value"),
953953
0,
954+
SigHash([0; 32]),
954955
)
955956
.expect("verification should pass"),
956957
));
@@ -1011,6 +1012,7 @@ async fn mempool_reverifies_after_tip_change() -> Result<(), Report> {
10111012
transaction,
10121013
Amount::try_from(1_000_000).expect("invalid value"),
10131014
0,
1015+
SigHash([0; 32]),
10141016
)
10151017
.expect("verification should pass"),
10161018
));

0 commit comments

Comments
 (0)