Update schnorrkel to 0.7.0 (#3261)

* Update schnorrkel to `0.7.0`

* Apply suggestions from code review

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* Increase `spec_version`
This commit is contained in:
Bastian Köcher
2019-07-30 23:46:05 +02:00
committed by DemiMarie-parity
parent c1640ef5da
commit a5fa1ddd99
9 changed files with 46 additions and 41 deletions
+12 -15
View File
@@ -3261,19 +3261,16 @@ dependencies = [
[[package]]
name = "schnorrkel"
version = "0.1.1"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"curve25519-dalek 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"merlin 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"zeroize 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4138,11 +4135,11 @@ dependencies = [
"parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"schnorrkel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-primitives 2.0.0",
"srml-balances 2.0.0",
"srml-system 2.0.0",
"substrate-bip39 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"substrate-bip39 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"substrate-primitives 2.0.0",
"tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -4176,12 +4173,12 @@ dependencies = [
[[package]]
name = "substrate-bip39"
version = "0.2.2"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"schnorrkel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -4334,7 +4331,7 @@ dependencies = [
"parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"schnorrkel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-io 2.0.0",
"sr-primitives 2.0.0",
"sr-version 2.0.0",
@@ -4360,7 +4357,7 @@ name = "substrate-consensus-babe-primitives"
version = "2.0.0"
dependencies = [
"parity-codec 4.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"schnorrkel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"substrate-client 2.0.0",
@@ -4663,11 +4660,11 @@ dependencies = [
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"schnorrkel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-std 2.0.0",
"substrate-bip39 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"substrate-bip39 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"substrate-serializer 2.0.0",
"tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"twox-hash 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -6241,7 +6238,7 @@ dependencies = [
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
"checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421"
"checksum schannel 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f6abf258d99c3c1c5c2131d99d064e94b7b3dd5f416483057f308fea253339"
"checksum schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b5eff518f9bed3d803a0d002af0ab96339b0ebbedde3bec98a684986134b7a39"
"checksum schnorrkel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a115d35c9d693bbea4c2b30132cd218c1af3e1adbc1b650855f8b816c81a3bc0"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d"
"checksum sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f5adf8fbd58e1b1b52699dc8bed2630faecb6d8c7bee77d009d6bbe4af569b9"
@@ -6280,7 +6277,7 @@ dependencies = [
"checksum structopt-derive 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "53010261a84b37689f9ed7d395165029f9cc7abb9f56bbfe86bee2597ed25107"
"checksum strum 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1810e25f576e7ffce1ff5243b37066da5ded0310b3274c20baaeccb1145b2806"
"checksum strum_macros 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "572a2f4e53dd4c3483fd79e5cc10ddd773a3acb1169bbfe8762365e107110579"
"checksum substrate-bip39 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d69ace596e9ca97837cc41f8edcfc4e0a997f227d5fc153d1010b60a0fe9acda"
"checksum substrate-bip39 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "03c1026336961c7ad6d2777e649e0a8cc5db4fdfb84b317198a505ebfc552def"
"checksum substrate-wasm-builder-runner 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f52ecbff6cc3d6e5c6401828e15937b680f459d6803ce238f01fe615bc40d071"
"checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee"
"checksum subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01dca13cf6c3b179864ab3292bd794e757618d35a7766b7c46050c614ba00829"
+1 -1
View File
@@ -28,7 +28,7 @@ futures01 = { package = "futures", version = "0.1" }
futures-timer = "0.2.1"
parking_lot = "0.8.0"
log = "0.4.6"
schnorrkel = "0.1.1"
schnorrkel = "0.7.0"
rand = "0.6.5"
merlin = "1.0.3"
@@ -12,7 +12,7 @@ sr-primitives = { path = "../../../sr-primitives", default-features = false }
primitives = { package = "substrate-primitives", path = "../../../primitives", default-features = false }
slots = { package = "substrate-consensus-slots", path = "../../slots", optional = true }
parity-codec = { version = "4.1.1", default-features = false }
schnorrkel = { version = "0.1.1", optional = true }
schnorrkel = { version = "0.7.0", optional = true }
[features]
default = ["std"]
+1 -1
View File
@@ -837,7 +837,7 @@ fn claim_slot(
let threshold = calculate_threshold(c, authorities, authority_index);
get_keypair(key)
.vrf_sign_n_check(transcript, |inout| check(inout, threshold))
.vrf_sign_after_check(transcript, |inout| check(inout, threshold))
.map(|s|(s, authority_index))
}
+2 -2
View File
@@ -19,10 +19,10 @@ hash256-std-hasher = { version = "0.14.0", default-features = false }
ed25519-dalek = { version = "1.0.0-pre.1", optional = true }
base58 = { version = "0.1", optional = true }
blake2-rfc = { version = "0.2.18", optional = true }
schnorrkel = { version = "0.1.1", optional = true }
schnorrkel = { version = "0.7.0", optional = true }
rand = { version = "0.6", optional = true }
sha2 = { version = "0.8", optional = true }
substrate-bip39 = { version = "0.2.2", optional = true }
substrate-bip39 = { version = "0.3", optional = true }
tiny-bip39 = { version = "0.6.1", optional = true }
hex = { version = "0.3", optional = true }
regex = { version = "1.1", optional = true }
+2 -1
View File
@@ -38,7 +38,7 @@ use zeroize::Zeroize;
pub const DEV_PHRASE: &str = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
/// The address of the associated root phrase for our publicly known keys.
pub const DEV_ADDRESS: &str = "5DfhGyQdFobKM8NsWvEeAKk5EQQgYe9AydgJ7rMB6E1EqRzV";
pub const DEV_ADDRESS: &str = "5H3ZzXYeCi95F7FUfMWdCVMoaXMbcWgi3E98TqcS18fZ3vn3";
/// The infallible type.
#[derive(Debug)]
@@ -400,6 +400,7 @@ impl<T: AsMut<[u8]> + AsRef<[u8]> + Default + Derive> Ss58Codec for T {
// Invalid checksum.
return Err(PublicError::InvalidChecksum);
}
res.as_mut().copy_from_slice(&d[1..len+1]);
Ok((res, ver))
}
+23 -16
View File
@@ -56,7 +56,7 @@ pub struct Pair(Keypair);
impl Clone for Pair {
fn clone(&self) -> Self {
Pair(schnorrkel::Keypair {
public: self.0.public.clone(),
public: self.0.public,
secret: schnorrkel::SecretKey::from_bytes(&self.0.secret.to_bytes()[..])
.expect("key is always the correct size; qed")
})
@@ -112,14 +112,14 @@ impl UncheckedFrom<H256> for Public {
}
#[cfg(feature = "std")]
impl ::std::fmt::Display for Public {
impl std::fmt::Display for Public {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(f, "{}", self.to_ss58check())
}
}
#[cfg(feature = "std")]
impl ::std::fmt::Debug for Public {
impl std::fmt::Debug for Public {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
let s = self.to_ss58check();
write!(f, "{} ({}...)", crate::hexdisplay::HexDisplay::from(&self.0), &s[0..8])
@@ -142,7 +142,7 @@ impl<'de> Deserialize<'de> for Public {
}
#[cfg(feature = "std")]
impl ::std::hash::Hash for Public {
impl std::hash::Hash for Public {
fn hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
self.0.hash(state);
}
@@ -170,7 +170,7 @@ impl Default for Signature {
impl PartialEq for Signature {
fn eq(&self, b: &Self) -> bool {
&self.0[..] == &b.0[..]
self.0[..] == b.0[..]
}
}
@@ -376,7 +376,7 @@ impl AsRef<schnorrkel::Keypair> for Pair {
/// Derive a single hard junction.
#[cfg(feature = "std")]
fn derive_hard_junction(secret: &SecretKey, cc: &[u8; CHAIN_CODE_LENGTH]) -> SecretKey {
secret.hard_derive_mini_secret_key(Some(ChainCode(cc.clone())), b"").0.expand()
secret.hard_derive_mini_secret_key(Some(ChainCode(*cc)), b"").0.expand()
}
/// The raw secret seed, which can be used to recreate the `Pair`.
@@ -475,15 +475,20 @@ impl TraitPair for Pair {
}
/// Verify a signature on a message. Returns true if the signature is good.
fn verify<P: AsRef<Self::Public>, M: AsRef<[u8]>>(sig: &Self::Signature, message: M, pubkey: P) -> bool {
fn verify<P: AsRef<Self::Public>, M: AsRef<[u8]>>(
sig: &Self::Signature,
message: M,
pubkey: P
) -> bool {
let signature: schnorrkel::Signature = match schnorrkel::Signature::from_bytes(&sig.as_ref()) {
Ok(some_signature) => some_signature,
Err(_) => return false
};
match PublicKey::from_bytes(pubkey.as_ref().as_slice()) {
Ok(pk) => pk.verify(
signing_context(SIGNING_CTX).bytes(message.as_ref()), &signature
),
signing_context(SIGNING_CTX).bytes(message.as_ref()),
&signature,
).is_ok(),
Err(_) => false,
}
}
@@ -496,8 +501,9 @@ impl TraitPair for Pair {
};
match PublicKey::from_bytes(pubkey.as_ref()) {
Ok(pk) => pk.verify(
signing_context(SIGNING_CTX).bytes(message.as_ref()), &signature
),
signing_context(SIGNING_CTX).bytes(message.as_ref()),
&signature,
).is_ok(),
Err(_) => false,
}
}
@@ -570,7 +576,7 @@ mod test {
);
assert_eq!(
Pair::from_string("/Alice", None).unwrap().public(),
Public::from_string("/Alice").unwrap()
Public::from_string("/Alice").unwrap(),
);
}
@@ -624,10 +630,11 @@ mod test {
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
));
let public = pair.public();
assert_eq!(
public,
Public::from_raw(hex!(
"44a996beb1eef7bdcab976ab6d2ca26104834164ecf28fb375600576fcc6eb0f"
"dad55a57ecb21977bebe0cbf898c3e3f7572207209b097db369282a0ef9f7354"
))
);
let message = b"";
@@ -646,13 +653,13 @@ mod test {
#[test]
fn seeded_pair_should_work() {
let pair = Pair::from_seed(b"12345678901234567890123456789012");
let public = pair.public();
assert_eq!(
public,
Public::from_raw(hex!(
"741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63"
"46ba66b7d19b0be8050209efe63264519327386425bd3c719e2a8925dfc4b052"
))
);
let message = hex!("2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee00000000000000000200d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a4500000000000000");
@@ -680,7 +687,7 @@ mod test {
);
let public = pk.public();
let js_signature = Signature::from_raw(
hex!("28a854d54903e056f89581c691c1f7d2ff39f8f896c9e9c22475e60902cc2b3547199e0e91fa32902028f2ca2355e8cdd16cfe19ba5e8b658c94aa80f3b81a00")
hex!("d2b776d10d3ba8ea160df887fe1ade3c2a5d38cef72ec1ae58eb9a75017d954f6eaefc2ad6f94e5831f4298f974c98da76075f280769ceaf8b86b89deb028682")
);
assert!(Pair::verify(&js_signature, b"SUBSTRATE", public));
}
+2 -2
View File
@@ -79,8 +79,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to equal spec_version. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 123,
impl_version: 125,
spec_version: 124,
impl_version: 124,
apis: RUNTIME_API_VERSIONS,
};
+2 -2
View File
@@ -13,8 +13,8 @@ rand = "0.6"
clap = { version = "~2.32", features = ["yaml"] }
tiny-bip39 = "0.6.0"
rustc-hex = "2.0"
substrate-bip39 = "0.2.2"
schnorrkel = "0.1.1"
substrate-bip39 = "0.3"
schnorrkel = "0.7.0"
hex = "0.3"
hex-literal = "0.2"
parity-codec = "4.1.1"