Skip to content

Commit

Permalink
Add blake2 as built in hash function and make HashingAlgorithm non-…
Browse files Browse the repository at this point in the history
…exhaustive (#881)

* Add blake2 as built in hash fn and make HashingAlgorithm non-exaustive

* Changelog

* Clippy

* Update hashes_test

* Changelog
  • Loading branch information
ameba23 authored Jun 10, 2024
1 parent 76044df commit 1f608e5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
At the moment this project **does not** adhere to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [[Unreleased]](https://github.com/entropyxyz/entropy-core/compare/release/v0.1.0...master)
## [Unreleased](https://github.com/entropyxyz/entropy-core/compare/release/v0.1.0...master)

### Breaking Changes
- In [#866](https://github.com/entropyxyz/entropy-core/pull/866) timestamp was removed from `UserSignatureRequest` and replaced with block_number. Thus check_stale now uses block_number for stale checks
- In [#881](https://github.com/entropyxyz/entropy-core/pull/881) the `HashingAlgorithm` enum is
given an additional variant `Blake2_256` and marked as `non_exhaustive` meaning we must handle the
case that an unknown variant is added in the future.

### Added
- Add a way to change program modification account ([#843](https://github.com/entropyxyz/entropy-core/pull/843))
- Add support for `--mnemonic-file` and `THRESHOLD_SERVER_MNEMONIC` ([#864](https://github.com/entropyxyz/entropy-core/pull/864))
- Add validator helpers to cli ([#870](https://github.com/entropyxyz/entropy-core/pull/870))
- Add blake2 as built in hash function and make HashingAlgorithm non-exhaustive ([#881](https://github.com/entropyxyz/entropy-core/pull/881)

### Changed
- Move TSS mnemonic out of keystore [#853](https://github.com/entropyxyz/entropy-core/pull/853)
Expand Down
2 changes: 2 additions & 0 deletions crates/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ pub struct OcwMessageProactiveRefresh {
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "std", serde(rename = "hash"))]
#[cfg_attr(feature = "std", serde(rename_all = "lowercase"))]
#[non_exhaustive]
pub enum HashingAlgorithm {
Sha1,
Sha2,
Sha3,
Keccak,
Blake2_256,
Custom(usize),
}

Expand Down
4 changes: 3 additions & 1 deletion crates/threshold-signature-server/src/helpers/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use reqwest::StatusCode;
use sha1::{Digest as Sha1Digest, Sha1};
use sha2::{Digest as Sha256Digest, Sha256};
use sha3::{Digest as Sha3Digest, Keccak256, Sha3_256};
use sp_core::{sr25519, Pair};
use sp_core::{hashing::blake2_256, sr25519, Pair};
use subxt::{backend::legacy::LegacyRpcMethods, tx::PairSigner, utils::AccountId32, OnlineClient};
use synedrion::KeyShare;
use tokio::time::timeout;
Expand Down Expand Up @@ -212,9 +212,11 @@ pub async fn compute_hash(
hash.copy_from_slice(&result);
Ok(hash)
},
HashingAlgorithm::Blake2_256 => Ok(blake2_256(message)),
HashingAlgorithm::Custom(i) => {
let program = get_program(api, rpc, &programs_data[*i].program_pointer).await?;
runtime.custom_hash(program.as_slice(), message).map_err(|e| e.into())
},
_ => Err(UserErr::UnknownHashingAlgorithm),
}
}
1 change: 1 addition & 0 deletions crates/threshold-signature-server/src/node_info/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async fn hashes_test() {
HashingAlgorithm::Sha2,
HashingAlgorithm::Sha3,
HashingAlgorithm::Keccak,
HashingAlgorithm::Blake2_256,
HashingAlgorithm::Custom(0),
]
);
Expand Down
2 changes: 2 additions & 0 deletions crates/threshold-signature-server/src/user/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ pub enum UserErr {
SubstrateClient(#[from] entropy_client::substrate::SubstrateError),
#[error("Cannot get subgroup signers: {0}")]
SubgroupGet(#[from] entropy_client::user::SubgroupGetError),
#[error("Unknown hashing algorthim - user is using a newer version than us")]
UnknownHashingAlgorithm,
}

impl From<hkdf::InvalidLength> for UserErr {
Expand Down

0 comments on commit 1f608e5

Please sign in to comment.