Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Overhaul crypto (Schnorr/Ristretto, HDKD, BIP39) #1795

Merged
merged 43 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6ec42d7
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Feb 14, 2019
f774028
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Feb 14, 2019
12f88af
Rijig to Ristretto
gavofyork Feb 14, 2019
8170cc9
Rebuild wasm
gavofyork Feb 14, 2019
ec6c7c9
adds compatibility test with the wasm module
kianenigma Feb 15, 2019
f8f5097
Merge branch 'gav-enable-ristretto' of github.com:paritytech/substrat…
kianenigma Feb 15, 2019
494e05b
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Mar 6, 2019
3491d5b
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Mar 7, 2019
af2061e
Add Ed25519-BIP39 support
gavofyork Mar 7, 2019
d80d906
Bump subkey version
gavofyork Mar 7, 2019
b7ad4f5
Update CLI output
gavofyork Mar 7, 2019
fd5503c
New keys.
gavofyork Mar 7, 2019
72fbadc
Standard phrase/password/path keys.
gavofyork Mar 8, 2019
fb1c40e
Subkey uses S-URI for secrets
gavofyork Mar 8, 2019
ddaffb0
Move everything to use new HDKD crypto.
gavofyork Mar 8, 2019
2142a38
Test fixes
gavofyork Mar 8, 2019
34259d6
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Mar 8, 2019
2ab6e42
Ignore old test vector.
gavofyork Mar 8, 2019
ca9c198
fix the ^^ old test vector.
kianenigma Mar 8, 2019
81b47bf
Fix tests
gavofyork Mar 10, 2019
fab9560
Test fixes
gavofyork Mar 10, 2019
fab1d97
Cleanups
gavofyork Mar 10, 2019
131a349
Fix broken key conversion logic in grandpa
gavofyork Mar 10, 2019
c284b91
Remove legacy Keyring usage
gavofyork Mar 10, 2019
d008f3b
Traitify `Pair`
gavofyork Mar 11, 2019
5dc4442
Replace Ed25519AuthorityId with ed25519::Public
gavofyork Mar 12, 2019
519a80e
Expunge Ed25519AuthorityId type!
gavofyork Mar 12, 2019
c019fa9
Replace Sr25519AuthorityId with sr25519::Public
gavofyork Mar 12, 2019
ab60208
Remove dodgy crypto type-punning conversions
gavofyork Mar 12, 2019
11e053e
Fix some tests
gavofyork Mar 12, 2019
5acdfb9
Avoid trait
gavofyork Mar 12, 2019
9837ddd
Deduplicate DeriveJunction string decode
gavofyork Mar 12, 2019
3e29972
Remove cruft code
gavofyork Mar 12, 2019
9fadc2b
Fix test
gavofyork Mar 12, 2019
c1fec25
Minor removals
gavofyork Mar 12, 2019
5c61823
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Mar 12, 2019
40dbc3f
Build fix
gavofyork Mar 12, 2019
d601233
Subkey supports sign and verify
gavofyork Mar 13, 2019
57de3e1
Inspect works for public key URIs
gavofyork Mar 13, 2019
2982704
Remove more crypto type-punning
gavofyork Mar 13, 2019
8a76fb1
Fix typo
gavofyork Mar 13, 2019
c11b5b5
Fix tests
gavofyork Mar 13, 2019
df6778a
Merge remote-tracking branch 'origin/master' into gav-enable-ristretto
gavofyork Mar 13, 2019
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
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use vergen::{ConstantsFlags, generate_cargo_keys};

const ERROR_MSG: &'static str = "Failed to generate metadata files";
const ERROR_MSG: &str = "Failed to generate metadata files";

fn main() {
generate_cargo_keys(ConstantsFlags::all()).expect(ERROR_MSG);
Expand Down
7 changes: 3 additions & 4 deletions core/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,16 @@ mod tests {
use codec::Encode;
use std::cell::RefCell;
use consensus_common::{Environment, Proposer};
use test_client::keyring::Keyring;
use test_client::{self, runtime::{Extrinsic, Transfer}};
use test_client::{self, runtime::{Extrinsic, Transfer}, AccountKeyring};

fn extrinsic(nonce: u64) -> Extrinsic {
let tx = Transfer {
amount: Default::default(),
nonce,
from: Keyring::Alice.to_raw_public().into(),
from: AccountKeyring::Alice.into(),
to: Default::default(),
};
let signature = Keyring::from_raw_public(tx.from.to_fixed_bytes()).unwrap().sign(&tx.encode()).into();
let signature = AccountKeyring::from_public(&tx.from).unwrap().sign(&tx.encode()).into();
Extrinsic::Transfer(tx, signature)
}

Expand Down
5 changes: 4 additions & 1 deletion core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ use substrate_telemetry::TelemetryEndpoints;

const MAX_NODE_NAME_LENGTH: usize = 32;

/// The root phrase for our development network keys.
pub const DEV_PHRASE: &str = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";

/// Executable version. Used to pass version information from the root crate.
pub struct VersionInfo {
/// Implemtation name.
Expand Down Expand Up @@ -387,7 +390,7 @@ where
}

if cli.shared_params.dev {
config.keys.push("Alice".into());
config.keys.push(format!("{}//Alice", DEV_PHRASE));
}

let rpc_interface: &str = if cli.rpc_external { "0.0.0.0" } else { "127.0.0.1" };
Expand Down
87 changes: 44 additions & 43 deletions core/client/db/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ pub(crate) mod tests {
use super::*;

type Block = RawBlock<ExtrinsicWrapper<u32>>;
type AuthorityId = AuthorityIdFor<Block>;

pub fn default_header(parent: &Hash, number: u64) -> Header {
Header {
Expand Down Expand Up @@ -831,10 +832,10 @@ pub(crate) mod tests {
let checks = vec![
(0, None),
(1, None),
(2, Some(vec![[1u8; 32].into()])),
(3, Some(vec![[1u8; 32].into()])),
(4, Some(vec![[1u8; 32].into(), [2u8; 32].into()])),
(5, Some(vec![[1u8; 32].into(), [2u8; 32].into()])),
(2, Some(vec![AuthorityId::from_raw([1u8; 32])])),
(3, Some(vec![AuthorityId::from_raw([1u8; 32])])),
(4, Some(vec![AuthorityId::from_raw([1u8; 32]), AuthorityId::from_raw([2u8; 32])])),
(5, Some(vec![AuthorityId::from_raw([1u8; 32]), AuthorityId::from_raw([2u8; 32])])),
(6, None),
(7, None), // block will work for 'future' block too
];
Expand All @@ -843,13 +844,13 @@ pub(crate) mod tests {
run_checks(&db, 0, &checks);
let hash1 = insert_final_block(&db, None, || default_header(&hash0, 1));
run_checks(&db, 1, &checks);
let hash2 = insert_final_block(&db, Some(vec![[1u8; 32].into()]), || default_header(&hash1, 2));
let hash2 = insert_final_block(&db, Some(vec![AuthorityId::from_raw([1u8; 32])]), || default_header(&hash1, 2));
run_checks(&db, 2, &checks);
let hash3 = insert_final_block(&db, Some(vec![[1u8; 32].into()]), || default_header(&hash2, 3));
let hash3 = insert_final_block(&db, Some(vec![AuthorityId::from_raw([1u8; 32])]), || default_header(&hash2, 3));
run_checks(&db, 3, &checks);
let hash4 = insert_final_block(&db, Some(vec![[1u8; 32].into(), [2u8; 32].into()]), || default_header(&hash3, 4));
let hash4 = insert_final_block(&db, Some(vec![AuthorityId::from_raw([1u8; 32]), AuthorityId::from_raw([2u8; 32])]), || default_header(&hash3, 4));
run_checks(&db, 4, &checks);
let hash5 = insert_final_block(&db, Some(vec![[1u8; 32].into(), [2u8; 32].into()]), || default_header(&hash4, 5));
let hash5 = insert_final_block(&db, Some(vec![AuthorityId::from_raw([1u8; 32]), AuthorityId::from_raw([2u8; 32])]), || default_header(&hash4, 5));
run_checks(&db, 5, &checks);
let hash6 = insert_final_block(&db, None, || default_header(&hash5, 6));
run_checks(&db, 7, &checks);
Expand All @@ -861,9 +862,9 @@ pub(crate) mod tests {
// some older non-best blocks are inserted
// ... -> B2(1) -> B2_1(1) -> B2_2(2)
// => the cache ignores all writes before best finalized block
let hash2_1 = insert_non_best_block(&db, Some(vec![[1u8; 32].into()]), || default_header(&hash2, 3));
let hash2_1 = insert_non_best_block(&db, Some(vec![AuthorityId::from_raw([1u8; 32])]), || default_header(&hash2, 3));
assert_eq!(None, db.cache().authorities_at(BlockId::Hash(hash2_1)));
let hash2_2 = insert_non_best_block(&db, Some(vec![[1u8; 32].into(), [2u8; 32].into()]), || default_header(&hash2_1, 4));
let hash2_2 = insert_non_best_block(&db, Some(vec![AuthorityId::from_raw([1u8; 32]), AuthorityId::from_raw([2u8; 32])]), || default_header(&hash2_1, 4));
assert_eq!(None, db.cache().authorities_at(BlockId::Hash(hash2_2)));
}

Expand All @@ -874,39 +875,39 @@ pub(crate) mod tests {
// \> B6_1_1(5)
// \> B6_1_2(6) -> B6_1_3(7)

let hash7 = insert_block(&db, Some(vec![[3u8; 32].into()]), || default_header(&hash6, 7));
let hash7 = insert_block(&db, Some(vec![AuthorityId::from_raw([3u8; 32])]), || default_header(&hash6, 7));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), Some(vec![[3u8; 32].into()]));
let hash8 = insert_block(&db, Some(vec![[3u8; 32].into()]), || default_header(&hash7, 8));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), Some(vec![AuthorityId::from_raw([3u8; 32])]));
let hash8 = insert_block(&db, Some(vec![AuthorityId::from_raw([3u8; 32])]), || default_header(&hash7, 8));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), Some(vec![[3u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash8)), Some(vec![[3u8; 32].into()]));
let hash6_1 = insert_block(&db, Some(vec![[4u8; 32].into()]), || default_header(&hash6, 7));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), Some(vec![AuthorityId::from_raw([3u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash8)), Some(vec![AuthorityId::from_raw([3u8; 32])]));
let hash6_1 = insert_block(&db, Some(vec![AuthorityId::from_raw([4u8; 32])]), || default_header(&hash6, 7));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), Some(vec![[3u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash8)), Some(vec![[3u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1)), Some(vec![[4u8; 32].into()]));
let hash6_1_1 = insert_non_best_block(&db, Some(vec![[5u8; 32].into()]), || default_header(&hash6_1, 8));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), Some(vec![AuthorityId::from_raw([3u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash8)), Some(vec![AuthorityId::from_raw([3u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1)), Some(vec![AuthorityId::from_raw([4u8; 32])]));
let hash6_1_1 = insert_non_best_block(&db, Some(vec![AuthorityId::from_raw([5u8; 32])]), || default_header(&hash6_1, 8));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), Some(vec![[3u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash8)), Some(vec![[3u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1)), Some(vec![[4u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_1)), Some(vec![[5u8; 32].into()]));
let hash6_1_2 = insert_non_best_block(&db, Some(vec![[6u8; 32].into()]), || default_header(&hash6_1, 8));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), Some(vec![AuthorityId::from_raw([3u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash8)), Some(vec![AuthorityId::from_raw([3u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1)), Some(vec![AuthorityId::from_raw([4u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_1)), Some(vec![AuthorityId::from_raw([5u8; 32])]));
let hash6_1_2 = insert_non_best_block(&db, Some(vec![AuthorityId::from_raw([6u8; 32])]), || default_header(&hash6_1, 8));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), Some(vec![[3u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash8)), Some(vec![[3u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1)), Some(vec![[4u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_1)), Some(vec![[5u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_2)), Some(vec![[6u8; 32].into()]));
let hash6_2 = insert_block(&db, Some(vec![[4u8; 32].into()]), || default_header(&hash6_1, 8));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), Some(vec![AuthorityId::from_raw([3u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash8)), Some(vec![AuthorityId::from_raw([3u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1)), Some(vec![AuthorityId::from_raw([4u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_1)), Some(vec![AuthorityId::from_raw([5u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_2)), Some(vec![AuthorityId::from_raw([6u8; 32])]));
let hash6_2 = insert_block(&db, Some(vec![AuthorityId::from_raw([4u8; 32])]), || default_header(&hash6_1, 8));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), Some(vec![[3u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash8)), Some(vec![[3u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1)), Some(vec![[4u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_1)), Some(vec![[5u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_2)), Some(vec![[6u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_2)), Some(vec![[4u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), Some(vec![AuthorityId::from_raw([3u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash8)), Some(vec![AuthorityId::from_raw([3u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1)), Some(vec![AuthorityId::from_raw([4u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_1)), Some(vec![AuthorityId::from_raw([5u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_2)), Some(vec![AuthorityId::from_raw([6u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_2)), Some(vec![AuthorityId::from_raw([4u8; 32])]));

(hash7, hash8, hash6_1, hash6_2, hash6_1_1, hash6_1_2)
};
Expand All @@ -917,19 +918,19 @@ pub(crate) mod tests {
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash8)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1)), Some(vec![[4u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_1)), Some(vec![[5u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_2)), Some(vec![[6u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_2)), Some(vec![[4u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1)), Some(vec![AuthorityId::from_raw([4u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_1)), Some(vec![AuthorityId::from_raw([5u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_2)), Some(vec![AuthorityId::from_raw([6u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_2)), Some(vec![AuthorityId::from_raw([4u8; 32])]));
// finalize block hash6_2
db.finalize_header(BlockId::Hash(hash6_2)).unwrap();
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash7)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash8)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1)), Some(vec![[4u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1)), Some(vec![AuthorityId::from_raw([4u8; 32])]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_1)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_1_2)), None);
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_2)), Some(vec![[4u8; 32].into()]));
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_2)), Some(vec![AuthorityId::from_raw([4u8; 32])]));
}
}

Expand Down
Loading