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

Derive the threshold account keypair and x25519 keypair from mnemonic using HKDF #709

Merged
merged 40 commits into from
Apr 15, 2024

Conversation

ameba23
Copy link
Contributor

@ameba23 ameba23 commented Apr 4, 2024

This addresses TOB-ENTROPY-13 by deriving both sr25519 and x25519 keypairs from a common secret, rather than one from the other.

It uses HKDF. TLDR - take a look at the functions in helpers/validator - that is the important thing thats changed.

@ameba23 ameba23 marked this pull request as draft April 4, 2024 13:31
Copy link

vercel bot commented Apr 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
entropy-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2024 9:27am

@ameba23 ameba23 marked this pull request as ready for review April 10, 2024 12:04
@ameba23 ameba23 requested review from HCastano and JesseAbram April 10, 2024 12:04
Copy link
Member

@JesseAbram JesseAbram left a comment

Choose a reason for hiding this comment

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

need more clarity on the changing keys in the chain_spec, other than that looks good

}

/// For testing where we sometimes don't have access to the kvdb, derive directly from the mnemnic
#[cfg(test)]
Copy link
Member

Choose a reason for hiding this comment

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

can you move this to the bottom of the file plz

@@ -63,17 +63,17 @@ pub mod tss_account_id {
/// The `DEFAULT_ALICE_MNEMONIC` is used to derive the following `AccountId`.
/// Mnemonic: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click"
pub static ref ALICE: sp_runtime::AccountId32 =
super::hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"].into();
super::hex!["306bdb49cbbe7104e3621abab3c9d31698b159f48dafe567abb7ea5d872ed329"].into();
Copy link
Member

Choose a reason for hiding this comment

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

I get why the others are changing but why are these changing?

Copy link
Contributor Author

@ameba23 ameba23 Apr 11, 2024

Choose a reason for hiding this comment

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

They change because we now use the mnemonic as input for the key derivation function, and derive the sr25519 keypair from it. This means we can still recover both sr25519 and x25519 keypairs from the same mnemonic. We could keep these the same by continuing to use sr25519::Pair::from_phrase and also using the mnemonic as input to HKDF. But i'm not sure whether the auditors would like it.

let sig_recovery = <sr25519::Pair as Pair>::verify(
&signing_result.clone().unwrap().1,
BASE64_STANDARD.decode(signing_result.unwrap().0).unwrap(),
&sr25519::Public(sk.public().0),
&sr25519::Public(TSS_ACCOUNTS[i].0),
Copy link
Member

Choose a reason for hiding this comment

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

oh ya, this is way less hacky lol

@@ -24,25 +24,37 @@ lazy_static! {
pub static ref BOB_STASH_ADDRESS: AccountId32 =
hex!["fe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e"].into(); // subkey inspect //Bob//stash
pub static ref TSS_ACCOUNTS: Vec<AccountId32> = vec![
hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"].into(),
hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"].into()
hex!["306bdb49cbbe7104e3621abab3c9d31698b159f48dafe567abb7ea5d872ed329"].into(),
Copy link
Member

Choose a reason for hiding this comment

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

I mean same here, why are these changing

];
pub static ref X25519_PUBLIC_KEYS: Vec<[u8; 32]> = vec![
vec![
10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155, 124, 195, 141,
148, 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247, 58, 34,
8, 22, 19, 230, 107, 217, 249, 190, 14, 142, 155, 252, 156, 229, 120, 11, 180, 35, 83, 245,
Copy link
Member

Choose a reason for hiding this comment

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

actually now that I think about it, these should not change either

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These one change because they are also now derived from the mnemonic. Before they were derived from the hash of the sr25519 secret key.

Copy link
Member

Choose a reason for hiding this comment

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

ok this makes sense I now understand this, but not the account IDs

@ameba23 ameba23 merged commit e7e7619 into master Apr 15, 2024
13 checks passed
@ameba23 ameba23 deleted the peg/hkdf branch April 15, 2024 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants