Skip to content

Commit

Permalink
Merge pull request #2094 from dusk-network/fault-hash
Browse files Browse the repository at this point in the history
node-data: change `Fault` hash algo to SHA3
  • Loading branch information
herr-seppia authored Aug 21, 2024
2 parents 0e19962 + 22ff73b commit 359f5f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
21 changes: 7 additions & 14 deletions node-data/src/ledger/faults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use execution_core::{
MultisigSignature as BlsMultisigSignature,
},
stake::EPOCH,
BlsScalar,
};
use thiserror::Error;
use tracing::error;
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
Expand Down
4 changes: 1 addition & 3 deletions node-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,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,
Expand Down Expand Up @@ -78,7 +76,7 @@ pub trait Serializable {
}
}

impl Serializable for Hash {
impl<const N: usize> Serializable for [u8; N] {
fn write<W: Write>(&self, w: &mut W) -> io::Result<()> {
w.write_all(&self[..])
}
Expand Down

0 comments on commit 359f5f5

Please sign in to comment.