diff --git a/coins/monero/Cargo.toml b/coins/monero/Cargo.toml index d5ef2e70..08fabe41 100644 --- a/coins/monero/Cargo.toml +++ b/coins/monero/Cargo.toml @@ -46,6 +46,7 @@ monero-generators = { path = "generators", version = "0.3", default-features = f futures = { version = "0.3", default-features = false, features = ["alloc"], optional = true } +hex-literal = "0.4" hex = { version = "0.4", default-features = false, features = ["alloc"] } serde = { version = "1", default-features = false, features = ["derive"] } serde_json = { version = "1", default-features = false, features = ["alloc"] } @@ -61,8 +62,6 @@ dalek-ff-group = { path = "../../crypto/dalek-ff-group", version = "0.3", defaul monero-generators = { path = "generators", version = "0.3", default-features = false } [dev-dependencies] -hex-literal = "0.4" - tokio = { version = "1", features = ["full"] } monero-rpc = "0.3" diff --git a/coins/monero/src/block.rs b/coins/monero/src/block.rs index 9f5192c1..751b04f7 100644 --- a/coins/monero/src/block.rs +++ b/coins/monero/src/block.rs @@ -10,6 +10,11 @@ use crate::{ transaction::{Input, Transaction}, }; +const CORRECT_BLOCK_HASH_202612: [u8; 32] = + hex_literal::hex!("426d16cff04c71f8b16340b722dc4010a2dd3831c22041431f772547ba6e331a"); +const EXISTING_BLOCK_HASH_202612: [u8; 32] = + hex_literal::hex!("bbd604d2ba11ba27935e006ed39c9bfdd99b76bf4a50654bc1e1e61217962698"); + #[derive(Clone, PartialEq, Eq, Debug)] pub struct BlockHeader { pub major_version: u64, @@ -87,10 +92,12 @@ impl Block { } pub fn hash(&self) -> [u8; 32] { - // TODO: Handle block 202612 - // https://monero.stackexchange.com/questions/421/what-happened-at-block-202612 - // If this block's header is fully-equivalent to 202612, return the malformed hash instead - hash(&self.serialize_hashable()) + let hash = hash(&self.serialize_hashable()); + if hash == CORRECT_BLOCK_HASH_202612 { + return EXISTING_BLOCK_HASH_202612; + }; + + hash } pub fn serialize(&self) -> Vec { diff --git a/coins/monero/src/merkle.rs b/coins/monero/src/merkle.rs index df8258e5..1671adf2 100644 --- a/coins/monero/src/merkle.rs +++ b/coins/monero/src/merkle.rs @@ -39,7 +39,7 @@ pub fn merkle_root(root: [u8; 32], leafs: &[[u8; 32]]) -> [u8; 32] { // Do a traditional pairing off let mut new_hashes = Vec::with_capacity(hashes.len() / 2); - while hashes.len() > 2 { + while hashes.len() > 1 { let mut i = 0; while i < hashes.len() { new_hashes.push(hash(&[hashes[i], hashes[i + 1]].concat()));