Skip to content

Commit

Permalink
pczt: Verify tx version before using v5_signature_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Dec 9, 2024
1 parent 4b2ffd3 commit 0cceac1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pczt/src/roles/io_finalizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
FLAG_SHIELDED_MODIFIABLE, FLAG_TRANSPARENT_INPUTS_MODIFIABLE,
FLAG_TRANSPARENT_OUTPUTS_MODIFIABLE,
},
Pczt,
Pczt, V5_TX_VERSION, V5_VERSION_GROUP_ID,
};

use super::signer::pczt_to_tx_data;
Expand Down Expand Up @@ -65,6 +65,13 @@ impl IoFinalizer {
let txid_parts = tx_data.digest(TxIdDigester);

// TODO: Pick sighash based on tx version.
match (global.tx_version, global.version_group_id) {
(V5_TX_VERSION, V5_VERSION_GROUP_ID) => Ok(()),
(version, version_group_id) => Err(Error::UnsupportedTxVersion {
version,
version_group_id,
}),
}?;
let shielded_sighash = v5_signature_hash(&tx_data, &SignableInput::Shielded, &txid_parts)
.as_ref()
.try_into()
Expand Down Expand Up @@ -97,6 +104,7 @@ pub enum Error {
SaplingParse(sapling::pczt::ParseError),
Sign(super::signer::Error),
TransparentParse(transparent::pczt::ParseError),
UnsupportedTxVersion { version: u32, version_group_id: u32 },
}

impl From<super::signer::Error> for Error {
Expand Down
7 changes: 7 additions & 0 deletions pczt/src/roles/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ impl Signer {
let txid_parts = tx_data.digest(TxIdDigester);

// TODO: Pick sighash based on tx version.
match (global.tx_version, global.version_group_id) {
(V5_TX_VERSION, V5_VERSION_GROUP_ID) => Ok(()),
(version, version_group_id) => Err(Error::Global(GlobalError::UnsupportedTxVersion {
version,
version_group_id,
})),
}?;
let shielded_sighash = v5_signature_hash(&tx_data, &SignableInput::Shielded, &txid_parts)
.as_ref()
.try_into()
Expand Down

0 comments on commit 0cceac1

Please sign in to comment.