From c102d9d1f9931794e4b0131f097a858e499e7aae Mon Sep 17 00:00:00 2001 From: Kirk Baird Date: Tue, 28 Apr 2020 18:27:33 +1000 Subject: [PATCH] Update SecretKey to 32 bytes (#1072) * Update SecretKey to 32 bytes Signed-off-by: Kirk Baird * Stop test from padding to 48 bytes Signed-off-by: Kirk Baird * Fix keypair file secret key length Signed-off-by: Kirk Baird --- Cargo.lock | 16 ++++++++-------- eth2/types/src/test_utils/keypairs_file.rs | 2 +- eth2/utils/bls/Cargo.toml | 2 +- eth2/utils/bls/src/lib.rs | 2 +- eth2/utils/bls/src/secret_key.rs | 5 ++--- eth2/utils/eth2_interop_keypairs/Cargo.toml | 2 +- eth2/utils/eth2_interop_keypairs/src/lib.rs | 2 +- tests/ef_tests/src/cases/bls_sign_msg.rs | 8 -------- 8 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d1eecd785..cbf59a0c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,7 +82,7 @@ dependencies = [ [[package]] name = "amcl" version = "0.2.0" -source = "git+https://github.com/sigp/milagro_bls?tag=v1.0.0#ac3e5c3a48aed7ea810ac411655963f5177430b7" +source = "git+https://github.com/sigp/milagro_bls?tag=v1.0.1#2ccdd4b517c1ab3debe10277deed9d1b1cbbe9ce" dependencies = [ "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -370,7 +370,7 @@ dependencies = [ "eth2_ssz 0.1.2", "eth2_ssz_types 0.2.0", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "milagro_bls 1.0.0 (git+https://github.com/sigp/milagro_bls?tag=v1.0.0)", + "milagro_bls 1.0.1 (git+https://github.com/sigp/milagro_bls?tag=v1.0.1)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1185,7 +1185,7 @@ dependencies = [ "eth2_hashing 0.1.1", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "milagro_bls 1.0.0 (git+https://github.com/sigp/milagro_bls?tag=v1.0.0)", + "milagro_bls 1.0.1 (git+https://github.com/sigp/milagro_bls?tag=v1.0.1)", "num-bigint 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2524,10 +2524,10 @@ dependencies = [ [[package]] name = "milagro_bls" -version = "1.0.0" -source = "git+https://github.com/sigp/milagro_bls?tag=v1.0.0#ac3e5c3a48aed7ea810ac411655963f5177430b7" +version = "1.0.1" +source = "git+https://github.com/sigp/milagro_bls?tag=v1.0.1#2ccdd4b517c1ab3debe10277deed9d1b1cbbe9ce" dependencies = [ - "amcl 0.2.0 (git+https://github.com/sigp/milagro_bls?tag=v1.0.0)", + "amcl 0.2.0 (git+https://github.com/sigp/milagro_bls?tag=v1.0.1)", "hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5186,7 +5186,7 @@ dependencies = [ "checksum aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" "checksum ahash 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6f33b5018f120946c1dcf279194f238a9f146725593ead1c08fa47ff22b0b5d3" "checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" -"checksum amcl 0.2.0 (git+https://github.com/sigp/milagro_bls?tag=v1.0.0)" = "" +"checksum amcl 0.2.0 (git+https://github.com/sigp/milagro_bls?tag=v1.0.1)" = "" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum arc-swap 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d663a8e9a99154b5fb793032533f6328da35e23aac63d5c152279aa8ba356825" "checksum arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" @@ -5381,7 +5381,7 @@ dependencies = [ "checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" "checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" "checksum memoffset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8" -"checksum milagro_bls 1.0.0 (git+https://github.com/sigp/milagro_bls?tag=v1.0.0)" = "" +"checksum milagro_bls 1.0.1 (git+https://github.com/sigp/milagro_bls?tag=v1.0.1)" = "" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum mime 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" "checksum mime_guess 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" diff --git a/eth2/types/src/test_utils/keypairs_file.rs b/eth2/types/src/test_utils/keypairs_file.rs index 13b1b17f2..8d45b7f51 100644 --- a/eth2/types/src/test_utils/keypairs_file.rs +++ b/eth2/types/src/test_utils/keypairs_file.rs @@ -5,7 +5,7 @@ use std::io::{Error, ErrorKind, Read, Write}; use std::path::Path; pub const PUBLIC_KEY_BYTES_LEN: usize = 96; -pub const SECRET_KEY_BYTES_LEN: usize = 48; +pub const SECRET_KEY_BYTES_LEN: usize = 32; pub const BATCH_SIZE: usize = 1_000; // ~15MB diff --git a/eth2/utils/bls/Cargo.toml b/eth2/utils/bls/Cargo.toml index 706bb7ed6..25a577834 100644 --- a/eth2/utils/bls/Cargo.toml +++ b/eth2/utils/bls/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Paul Hauner "] edition = "2018" [dependencies] -milagro_bls = { git = "https://github.com/sigp/milagro_bls", tag = "v1.0.0" } +milagro_bls = { git = "https://github.com/sigp/milagro_bls", tag = "v1.0.1" } eth2_hashing = "0.1.0" hex = "0.3" rand = "0.7.2" diff --git a/eth2/utils/bls/src/lib.rs b/eth2/utils/bls/src/lib.rs index a057d85bb..2d6b56a64 100644 --- a/eth2/utils/bls/src/lib.rs +++ b/eth2/utils/bls/src/lib.rs @@ -56,7 +56,7 @@ mod reals { pub const BLS_AGG_SIG_BYTE_SIZE: usize = 96; pub const BLS_SIG_BYTE_SIZE: usize = 96; -pub const BLS_SECRET_KEY_BYTE_SIZE: usize = 48; +pub const BLS_SECRET_KEY_BYTE_SIZE: usize = 32; pub const BLS_PUBLIC_KEY_BYTE_SIZE: usize = 48; use eth2_hashing::hash; diff --git a/eth2/utils/bls/src/secret_key.rs b/eth2/utils/bls/src/secret_key.rs index a930e65cc..893ab1669 100644 --- a/eth2/utils/bls/src/secret_key.rs +++ b/eth2/utils/bls/src/secret_key.rs @@ -80,9 +80,8 @@ mod tests { #[test] pub fn test_ssz_round_trip() { let byte_key = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 211, 210, 129, 231, 69, 162, 234, - 16, 15, 244, 214, 126, 201, 0, 85, 28, 239, 82, 121, 208, 190, 223, 6, 169, 202, 86, - 236, 197, 218, 3, 69, + 3, 211, 210, 129, 231, 69, 162, 234, 16, 15, 244, 214, 126, 201, 0, 85, 28, 239, 82, + 121, 208, 190, 223, 6, 169, 202, 86, 236, 197, 218, 3, 69, ]; let original = SecretKey::from_bytes(&byte_key).unwrap(); diff --git a/eth2/utils/eth2_interop_keypairs/Cargo.toml b/eth2/utils/eth2_interop_keypairs/Cargo.toml index edfec7ffb..30509a8f9 100644 --- a/eth2/utils/eth2_interop_keypairs/Cargo.toml +++ b/eth2/utils/eth2_interop_keypairs/Cargo.toml @@ -11,7 +11,7 @@ lazy_static = "1.4.0" num-bigint = "0.2.3" eth2_hashing = "0.1.0" hex = "0.3" -milagro_bls = { git = "https://github.com/sigp/milagro_bls", tag = "v1.0.0" } +milagro_bls = { git = "https://github.com/sigp/milagro_bls", tag = "v1.0.1" } serde_yaml = "0.8.11" serde = "1.0.102" serde_derive = "1.0.102" diff --git a/eth2/utils/eth2_interop_keypairs/src/lib.rs b/eth2/utils/eth2_interop_keypairs/src/lib.rs index 94b0b207f..f80b45c18 100644 --- a/eth2/utils/eth2_interop_keypairs/src/lib.rs +++ b/eth2/utils/eth2_interop_keypairs/src/lib.rs @@ -27,7 +27,7 @@ use std::convert::TryInto; use std::fs::File; use std::path::PathBuf; -pub const PRIVATE_KEY_BYTES: usize = 48; +pub const PRIVATE_KEY_BYTES: usize = 32; pub const PUBLIC_KEY_BYTES: usize = 48; pub const HASH_BYTES: usize = 32; diff --git a/tests/ef_tests/src/cases/bls_sign_msg.rs b/tests/ef_tests/src/cases/bls_sign_msg.rs index 53b09e4fd..3eae6eb15 100644 --- a/tests/ef_tests/src/cases/bls_sign_msg.rs +++ b/tests/ef_tests/src/cases/bls_sign_msg.rs @@ -23,7 +23,6 @@ impl Case for BlsSign { // Convert private_key and message to required types let mut sk = hex::decode(&self.input.privkey[2..]) .map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?; - pad_to_48(&mut sk); let sk = SecretKey::from_bytes(&sk).unwrap(); let msg = hex::decode(&self.input.message[2..]) .map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?; @@ -37,10 +36,3 @@ impl Case for BlsSign { compare_result::, Vec>(&Ok(signature.as_bytes()), &Some(decoded)) } } - -// Increase the size of an array to 48 bytes -fn pad_to_48(array: &mut Vec) { - while array.len() < 48 { - array.insert(0, 0); - } -}