Skip to content

Commit

Permalink
TX hash mismatch for non-canonical TXs
Browse files Browse the repository at this point in the history
This only concerns the free-floating `hash_transaction()`.

Fixes #314
  • Loading branch information
rooooooooob committed Mar 11, 2024
1 parent 28c9f4d commit 7d55113
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion chain/rust/src/crypto/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn hash_auxiliary_data(auxiliary_data: &AuxiliaryData) -> AuxiliaryDataHash
}

pub fn hash_transaction(tx_body: &TransactionBody) -> TransactionHash {
TransactionHash::from(blake2b256(tx_body.to_canonical_cbor_bytes().as_ref()))
TransactionHash::from(blake2b256(tx_body.to_cbor_bytes().as_ref()))
}

pub fn hash_plutus_data(plutus_data: &PlutusData) -> DatumHash {
Expand Down
7 changes: 1 addition & 6 deletions chain/rust/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ use cbor_encodings::{
TransactionWitnessSetEncoding,
};
use cml_core::ordered_hash_map::OrderedHashMap;
use cml_core::serialization::{LenEncoding, Serialize, StringEncoding};
use cml_crypto::blake2b256;
use cml_core::serialization::{LenEncoding, StringEncoding};
use std::collections::BTreeMap;

#[derive(
Expand Down Expand Up @@ -376,10 +375,6 @@ impl TransactionBody {
encodings: None,
}
}

pub fn hash(&self) -> [u8; 32] {
blake2b256(&self.to_cbor_bytes())
}
}

#[derive(
Expand Down
12 changes: 10 additions & 2 deletions chain/rust/src/transaction/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ use crate::{
transaction::{DatumOption, ScriptRef, TransactionOutput},
Value,
};
use cml_crypto::{DatumHash, Ed25519KeyHash};
use cml_crypto::{DatumHash, Ed25519KeyHash, TransactionHash};

use super::{AlonzoFormatTxOut, ConwayFormatTxOut, NativeScript, TransactionWitnessSet};
use super::{
AlonzoFormatTxOut, ConwayFormatTxOut, NativeScript, TransactionBody, TransactionWitnessSet,
};

impl TransactionBody {
pub fn hash(&self) -> TransactionHash {
crate::crypto::hash::hash_transaction(self)
}
}

impl TransactionOutput {
pub fn new(
Expand Down

0 comments on commit 7d55113

Please sign in to comment.