From 22ff73bdac46f571187417e40613acf07ec0bae9 Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Fri, 9 Aug 2024 11:10:11 +0200 Subject: [PATCH] node-data: change `Fault` hash algo to SHA3 Resolves #2081 --- node-data/src/ledger/faults.rs | 21 +++++++-------------- node-data/src/lib.rs | 4 +--- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/node-data/src/ledger/faults.rs b/node-data/src/ledger/faults.rs index 4da51ad0a3..960ffc0357 100644 --- a/node-data/src/ledger/faults.rs +++ b/node-data/src/ledger/faults.rs @@ -21,7 +21,6 @@ use execution_core::{ MultisigSignature as BlsMultisigSignature, }, stake::EPOCH, - BlsScalar, }; use thiserror::Error; use tracing::error; @@ -69,7 +68,7 @@ impl Fault { pub fn hash(&self) -> [u8; 32] { let mut b = vec![]; self.write(&mut b).expect("Write to a vec shall not fail"); - BlsScalar::hash_to_scalar(&b[..]).to_bytes() + sha3::Sha3_256::digest(&b[..]).into() } pub fn same(&self, other: &Fault) -> bool { @@ -87,26 +86,20 @@ impl Fault { match self { Fault::DoubleCandidate(a, b) => { let seed = Candidate::SIGN_SEED; - let a = BlsScalar::hash_to_scalar(&a.get_signed_data(seed)[..]) - .to_bytes(); - let b = BlsScalar::hash_to_scalar(&b.get_signed_data(seed)[..]) - .to_bytes(); + let a = sha3::Sha3_256::digest(a.get_signed_data(seed)).into(); + let b = sha3::Sha3_256::digest(b.get_signed_data(seed)).into(); (a, b) } Fault::DoubleRatificationVote(a, b) => { let seed = Ratification::SIGN_SEED; - let a = BlsScalar::hash_to_scalar(&a.get_signed_data(seed)[..]) - .to_bytes(); - let b = BlsScalar::hash_to_scalar(&b.get_signed_data(seed)[..]) - .to_bytes(); + let a = sha3::Sha3_256::digest(a.get_signed_data(seed)).into(); + let b = sha3::Sha3_256::digest(b.get_signed_data(seed)).into(); (a, b) } Fault::DoubleValidationVote(a, b) => { let seed = Validation::SIGN_SEED; - let a = BlsScalar::hash_to_scalar(&a.get_signed_data(seed)[..]) - .to_bytes(); - let b = BlsScalar::hash_to_scalar(&b.get_signed_data(seed)[..]) - .to_bytes(); + let a = sha3::Sha3_256::digest(a.get_signed_data(seed)).into(); + let b = sha3::Sha3_256::digest(b.get_signed_data(seed)).into(); (a, b) } } diff --git a/node-data/src/lib.rs b/node-data/src/lib.rs index 53927bc807..ad348f246b 100644 --- a/node-data/src/lib.rs +++ b/node-data/src/lib.rs @@ -11,8 +11,6 @@ pub mod message; use std::io::{self, Read, Write}; -use ledger::Hash; - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum StepName { Proposal = 0, @@ -77,7 +75,7 @@ pub trait Serializable { } } -impl Serializable for Hash { +impl Serializable for [u8; N] { fn write(&self, w: &mut W) -> io::Result<()> { w.write_all(&self[..]) }