Skip to content

Commit

Permalink
Validate transaction version
Browse files Browse the repository at this point in the history
  • Loading branch information
ssantos21 committed Sep 2, 2024
1 parent e0a0857 commit 8de6633
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub enum MercuryError {
LocktimeNotBlockHeightError,
LocktimeTooLow,
LocktimeTooHigh,
TransactionVersionError,
TransactionSequenceDifferentThanZeroError,
BitcoinConsensusEncodeError,
MusigNonceGenError,
Expand Down
8 changes: 6 additions & 2 deletions lib/src/transfer/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ pub fn validate_signature_scheme(
break;
}

if verify_if_locktime_is_reasonable(&backup_tx.tx, current_blockheight, lockheight_init).is_err() {
if verify_if_locktime_is_reasonable_and_tx_version(&backup_tx.tx, current_blockheight, lockheight_init).is_err() {
println!("locktime is not reasonable");
sig_scheme_validation = false;
break;
Expand Down Expand Up @@ -405,10 +405,14 @@ pub fn verify_transaction_sequence(tx_n_hex: &str) -> Result<(), MercuryError> {
Ok(())
}

pub fn verify_if_locktime_is_reasonable(tx_n_hex: &str, current_blockheight: u32, lockheight_init:u32) -> Result<(), MercuryError> {
pub fn verify_if_locktime_is_reasonable_and_tx_version(tx_n_hex: &str, current_blockheight: u32, lockheight_init:u32) -> Result<(), MercuryError> {

let tx_n: Transaction = bitcoin::consensus::encode::deserialize(&hex::decode(&tx_n_hex)?)?;

if tx_n.version != 2 {
return Err(MercuryError::TransactionVersionError);
}

let lock_time = tx_n.lock_time;

if !(lock_time.is_block_height()) {
Expand Down

0 comments on commit 8de6633

Please sign in to comment.