Skip to content

Commit

Permalink
fix!: remove tari prefix and only allow one mergemining tag (#5722)
Browse files Browse the repository at this point in the history
Remove the merge mining tag. There can now only be one merge mining tag
in a block

BREAKING CHANGE: Merge mining hash has changed
  • Loading branch information
stringhandler authored Sep 4, 2023
1 parent 403b0c6 commit 3a7c227
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions base_layer/core/src/blocks/block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,10 @@ impl BlockHeader {
}

pub fn merge_mining_hash(&self) -> FixedHash {
let mut mining_hash = self.mining_hash();
mining_hash[0..4].copy_from_slice(b"TARI"); // Maybe put this in a `const`
mining_hash
// let mining_hash = self.mining_hash();
// At a later stage if we want to allow other coins to be merge mined, we can add a prefix
// mining_hash[0..4].copy_from_slice(b"TARI"); // Maybe put this in a `const`
self.mining_hash()
}

#[inline]
Expand Down
11 changes: 6 additions & 5 deletions base_layer/core/src/proof_of_work/monero_rx/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ pub fn verify_header(header: &BlockHeader) -> Result<MoneroPowData, MergeMineErr
// and that only 1 tari header is found

let mut is_found = false;
let mut already_seen_mmfield = false;
for item in extra_field.0 {
if let SubField::MergeMining(Some(depth), merge_mining_hash) = item {
if is_found && &merge_mining_hash.as_bytes()[0..4] == b"TARI" {
if already_seen_mmfield {
return Err(MergeMineError::ValidationError(
"More than one Tari header found in coinbase".to_string(),
"More than one merge mining tag found in coinbase".to_string(),
));
}
already_seen_mmfield = true;
if depth == VarInt(0) && merge_mining_hash.as_bytes() == expected_merge_mining_hash.as_slice() {
is_found = true;
}
Expand Down Expand Up @@ -550,10 +552,9 @@ mod test {
};
let hash = block_header.merge_mining_hash();
append_merge_mining_tag(&mut block, hash).unwrap();
#[allow(clippy::redundant_clone)]
let mut block_header2 = block_header.clone();
block_header2.version = 1;
let hash2 = block_header.merge_mining_hash();
let hash2 = block_header2.merge_mining_hash();
append_merge_mining_tag(&mut block, hash2).unwrap();
let count = 1 + (u16::try_from(block.tx_hashes.len()).unwrap());
let mut hashes = Vec::with_capacity(count as usize);
Expand Down Expand Up @@ -582,7 +583,7 @@ mod test {
block_header.pow = pow;
let err = verify_header(&block_header).unwrap_err();
unpack_enum!(MergeMineError::ValidationError(details) = err);
assert!(details.contains("More than one Tari header found in coinbase"));
assert!(details.contains("More than one merge mining tag found in coinbase"));
}

#[test]
Expand Down

0 comments on commit 3a7c227

Please sign in to comment.