dao: replace use of blake3 hash with blake2b. See code comments for explanation of the rationale

This commit is contained in:
zero
2024-01-10 10:58:00 +01:00
parent 6b238fdb9a
commit 4d87af64f4
4 changed files with 11 additions and 7 deletions

2
Cargo.lock generated
View File

@@ -1955,7 +1955,7 @@ dependencies = [
name = "darkfi_dao_contract"
version = "0.4.1"
dependencies = [
"blake3 1.5.0",
"blake2b_simd",
"bs58",
"chacha20poly1305",
"darkfi",

View File

@@ -9,7 +9,7 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]
[dependencies]
blake3 = "1.5.0"
blake2b_simd = "1.0.2"
bs58 = "0.5.0"
darkfi-sdk = { path = "../../sdk" }
darkfi-serial = { path = "../../serial", features = ["derive", "crypto"] }

View File

@@ -118,12 +118,16 @@ pub trait VecAuthCallCommit {
impl VecAuthCallCommit for Vec<DaoAuthCall> {
fn commit(&self) -> pallas::Base {
let mut hasher = blake3::Hasher::new();
// Hash a bunch of data, then convert it so pallas::Base
// see https://docs.rs/ff/0.13.0/ff/trait.FromUniformBytes.html
// We essentially create a really large value and reduce it modulo the field
// to diminish the statistical significance of any overlap.
let mut hasher =
blake2b_simd::Params::new().hash_length(64).personal(b"justDAOthings").to_state();
self.encode(&mut hasher).unwrap();
let hash = hasher.finalize();
let bytes = hash.as_bytes();
let raw_base: [u64; 4] = Decodable::decode(&mut bytes.as_slice()).unwrap();
pallas::Base::from_raw(raw_base)
let bytes = hash.as_array();
pallas::Base::from_uniform_bytes(bytes)
}
}

View File

@@ -73,7 +73,7 @@ pub mod pasta_prelude {
pub use pasta_curves::{
arithmetic::{CurveAffine, CurveExt},
group::{
ff::{Field, PrimeField},
ff::{Field, FromUniformBytes, PrimeField},
Curve, Group,
},
};