mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 13:09:24 +00:00
Fix for block 202612 and fix merkel root calculations
This commit is contained in:
@@ -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 }
|
futures = { version = "0.3", default-features = false, features = ["alloc"], optional = true }
|
||||||
|
|
||||||
|
hex-literal = "0.4"
|
||||||
hex = { version = "0.4", default-features = false, features = ["alloc"] }
|
hex = { version = "0.4", default-features = false, features = ["alloc"] }
|
||||||
serde = { version = "1", default-features = false, features = ["derive"] }
|
serde = { version = "1", default-features = false, features = ["derive"] }
|
||||||
serde_json = { version = "1", default-features = false, features = ["alloc"] }
|
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 }
|
monero-generators = { path = "generators", version = "0.3", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
hex-literal = "0.4"
|
|
||||||
|
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
monero-rpc = "0.3"
|
monero-rpc = "0.3"
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ use crate::{
|
|||||||
transaction::{Input, Transaction},
|
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)]
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
pub struct BlockHeader {
|
pub struct BlockHeader {
|
||||||
pub major_version: u64,
|
pub major_version: u64,
|
||||||
@@ -87,10 +92,12 @@ impl Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash(&self) -> [u8; 32] {
|
pub fn hash(&self) -> [u8; 32] {
|
||||||
// TODO: Handle block 202612
|
let hash = hash(&self.serialize_hashable());
|
||||||
// https://monero.stackexchange.com/questions/421/what-happened-at-block-202612
|
if hash == CORRECT_BLOCK_HASH_202612 {
|
||||||
// If this block's header is fully-equivalent to 202612, return the malformed hash instead
|
return EXISTING_BLOCK_HASH_202612;
|
||||||
hash(&self.serialize_hashable())
|
};
|
||||||
|
|
||||||
|
hash
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize(&self) -> Vec<u8> {
|
pub fn serialize(&self) -> Vec<u8> {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ pub fn merkle_root(root: [u8; 32], leafs: &[[u8; 32]]) -> [u8; 32] {
|
|||||||
|
|
||||||
// Do a traditional pairing off
|
// Do a traditional pairing off
|
||||||
let mut new_hashes = Vec::with_capacity(hashes.len() / 2);
|
let mut new_hashes = Vec::with_capacity(hashes.len() / 2);
|
||||||
while hashes.len() > 2 {
|
while hashes.len() > 1 {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < hashes.len() {
|
while i < hashes.len() {
|
||||||
new_hashes.push(hash(&[hashes[i], hashes[i + 1]].concat()));
|
new_hashes.push(hash(&[hashes[i], hashes[i + 1]].concat()));
|
||||||
|
|||||||
Reference in New Issue
Block a user