Procházet zdrojové kódy

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

zero před 2 roky
rodič
revize
4d87af64f4

+ 1 - 1
Cargo.lock

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

+ 1 - 1
src/contract/dao/Cargo.toml

@@ -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"] }

+ 8 - 4
src/contract/dao/src/model.rs

@@ -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)
     }
 }
 

+ 1 - 1
src/sdk/src/crypto/mod.rs

@@ -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,
         },
     };