Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blake2 as built in hash function and make HashingAlgorithm non-exhaustive #881

Merged
merged 5 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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
Expand All @@ -16,6 +16,7 @@ At the moment this project **does not** adhere to
- 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not sure if this counts as a breaking change. I think old JSON encoded signature requests will still work. But the shared type HashingAlgorithm has changed so strictly speaking this probably is breaking.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this would be breaking for the entropy-shared crate since: a) we added a new field to a public enum and b) with the addition of non_exhaustive existing callers now need to handle the wildcard case.

We should also add this PR to the Added section.


### 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())
},
_ => return Err(UserErr::UnknownHashingAlgorithm),
}
}
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