Skip to content

Commit

Permalink
node_data: Replace rusk_abi::Hasher with BlsScalar::hash_to_scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
moCello committed Jul 23, 2024
1 parent f5315bf commit fdfb0bd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 0 additions & 1 deletion node-data/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub use attestation::{
use crate::bls::PublicKeyBytes;
use crate::Serializable;

use rusk_abi::hash::Hasher;
use sha3::Digest;
use std::io::{self, Read, Write};

Expand Down
22 changes: 14 additions & 8 deletions node-data/src/ledger/faults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{

use dusk_bytes::Serializable as DuskSerializeble;
use execution_core::{
stake::EPOCH, BlsAggPublicKey, BlsSigError, BlsSignature,
stake::EPOCH, BlsAggPublicKey, BlsScalar, BlsSigError, BlsSignature,
};
use thiserror::Error;
use tracing::error;
Expand Down Expand Up @@ -62,7 +62,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");
Hasher::digest(b).to_bytes()
BlsScalar::hash_to_scalar(&b[..]).to_bytes()
}

pub fn same(&self, other: &Fault) -> bool {
Expand All @@ -80,20 +80,26 @@ impl Fault {
match self {
Fault::DoubleCandidate(a, b) => {
let seed = Candidate::SIGN_SEED;
let a = Hasher::digest(a.get_signed_data(seed)).to_bytes();
let b = Hasher::digest(b.get_signed_data(seed)).to_bytes();
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();
(a, b)
}
Fault::DoubleRatificationVote(a, b) => {
let seed = Ratification::SIGN_SEED;
let a = Hasher::digest(a.get_signed_data(seed)).to_bytes();
let b = Hasher::digest(b.get_signed_data(seed)).to_bytes();
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();
(a, b)
}
Fault::DoubleValidationVote(a, b) => {
let seed = Validation::SIGN_SEED;
let a = Hasher::digest(a.get_signed_data(seed)).to_bytes();
let b = Hasher::digest(b.get_signed_data(seed)).to_bytes();
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();
(a, b)
}
}
Expand Down
8 changes: 4 additions & 4 deletions node-data/src/ledger/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use super::*;

use execution_core::transfer::Transaction as ProtocolTransaction;
use execution_core::BlsScalar;

#[derive(Debug, Clone)]
pub struct Transaction {
Expand Down Expand Up @@ -42,7 +41,7 @@ impl Transaction {
/// ### Returns
/// An array of 32 bytes representing the hash of the transaction.
pub fn hash(&self) -> [u8; 32] {
Hasher::digest(self.inner.to_var_bytes()).to_bytes()
BlsScalar::hash_to_scalar(&self.inner.to_var_bytes()[..]).to_bytes()
}

/// Computes the transaction ID.
Expand All @@ -56,7 +55,7 @@ impl Transaction {
/// ### Returns
/// An array of 32 bytes representing the transaction ID.
pub fn id(&self) -> [u8; 32] {
Hasher::digest(self.inner.to_hash_input_bytes()).to_bytes()
self.inner.hash().to_bytes()
}

pub fn gas_price(&self) -> u64 {
Expand Down Expand Up @@ -93,6 +92,7 @@ impl Eq for SpentTransaction {}
#[cfg(any(feature = "faker", test))]
pub mod faker {
use super::*;
use crate::ledger::Dummy;
use execution_core::transfer::{
ContractCall, ContractExec, Fee, PhoenixPayload,
};
Expand Down

0 comments on commit fdfb0bd

Please sign in to comment.