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

Paired-key Crypto Scheme #1705

Merged
merged 42 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5d3dce1
First definition for pair public keys
drskalman Aug 3, 2023
be890d4
Two example of implementation of pair for demonestration
drskalman Aug 3, 2023
fb6a018
- implement paired crypto `Public` as tuple of two `Public`s - unsuce…
drskalman Aug 14, 2023
62ef8b1
keep both public key object and their continous serialization in pair…
drskalman Aug 21, 2023
8d4e523
implement PassBy and From<Pair> for paired_crypto
drskalman Aug 21, 2023
eea74e2
implement rest of aux traits for `paired_crypto::Public` implement so…
drskalman Aug 22, 2023
f407d87
Attempt to implement trait `Pair` for `pair_cyrpto::Pair`
drskalman Aug 29, 2023
2606cc4
- Implement trait `Pair` for `paired_crypto::Pair` - Implement a pair…
drskalman Aug 31, 2023
00933da
implement sgin and verify for
drskalman Sep 5, 2023
e7719ab
Actually implementing `paired_crypto::{Pair, Public, Signatrue}` for …
drskalman Sep 10, 2023
7a9b677
Implement and pass all test for `paired_crypto`
drskalman Sep 11, 2023
a01a814
- move to signle seed for both schemes in `primitives/core/src/paired…
drskalman Sep 25, 2023
7c02658
replace `hex!` → `array_bytes::hex2xx`
drskalman Sep 25, 2023
7f8d958
Apply suggestions from `paired_crypto` code review on type nam, hash …
drskalman Oct 5, 2023
eef2cec
Do not panic in `paired::Signature::try_from`
drskalman Oct 5, 2023
efb215f
Remove `DoublePair` trait.
drskalman Oct 5, 2023
65584bd
Do not empty implement `paired::Pair`
drskalman Oct 5, 2023
e047f75
Use `paired_crypto::Seed` instead of `[u8; SECURE_SEED_LEN]`
drskalman Oct 5, 2023
c12b82e
use `ecdsa::PUBLIC_KEY_SERIALIZED_SIZE` and `ecdsa::SIGNATURE_SERIALI…
drskalman Oct 5, 2023
dba854a
Remove `paired::DoublePair` impl as well
drskalman Oct 5, 2023
5182c86
- Implement `BytesArray` for both ecdsa and bls Signatures
drskalman Oct 5, 2023
17d0077
Implement encode_and_decode_(public_key/signature)_works test for pai…
drskalman Oct 5, 2023
a740589
cargo fmt
drskalman Oct 5, 2023
7e34167
Merge branch 'master' into skalman-paired-crypto-scheme
drskalman Oct 5, 2023
6c0c107
Cleanup
davxy Oct 7, 2023
67152d8
Remove TODO
davxy Oct 7, 2023
a0cc64e
Merge pull request #1 from davxy/skalman-paired-crypto-scheme
drskalman Oct 7, 2023
685c21d
Put (De)serialization under `serde` feature instead of `std` in bls a…
drskalman Oct 7, 2023
9b46ba8
cargo +nightly fmt
drskalman Oct 7, 2023
9fbd4d2
Make clippy happy
davxy Oct 7, 2023
b28d0ad
Fix
davxy Oct 7, 2023
78c75e3
More tweaks
davxy Oct 7, 2023
96acd6c
Ss58 requires serde
davxy Oct 7, 2023
3c4311a
Tweaks
davxy Oct 8, 2023
6aa8281
Fix typo
davxy Oct 8, 2023
f568441
- replace `unwrap` with `expect`
drskalman Oct 10, 2023
1e3b915
Merge branch 'skalman-paired-crypto-scheme' of https://github.com/w3f…
drskalman Oct 10, 2023
f07f05a
Rename `TraitPair` -> `PairT`
drskalman Oct 10, 2023
a6da3f5
Remove internal Left and Right Public and Signature objects.
drskalman Oct 10, 2023
a069dcd
Trivial things
davxy Oct 11, 2023
808a53d
Update substrate/primitives/core/src/paired_crypto.rs
drskalman Oct 11, 2023
616f503
Merge branch 'master' into skalman-paired-crypto-scheme
drskalman Oct 11, 2023
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
23 changes: 11 additions & 12 deletions substrate/primitives/core/src/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ trait BlsBound: EngineBLS + HardJunctionId + Send + Sync + 'static {}

impl<T: EngineBLS + HardJunctionId + Send + Sync + 'static> BlsBound for T {}

// Secret key serialized size
/// Secret key serialized size
#[cfg(feature = "full_crypto")]
const SECRET_KEY_SERIALIZED_SIZE: usize =
<SecretKey<TinyBLS381> as SerializableToBytes>::SERIALIZED_BYTES_SIZE;

// Public key serialized size
const PUBLIC_KEY_SERIALIZED_SIZE: usize =
/// Public key serialized size
pub const PUBLIC_KEY_SERIALIZED_SIZE: usize =
<DoublePublicKey<TinyBLS381> as SerializableToBytes>::SERIALIZED_BYTES_SIZE;

// Signature serialized size
const SIGNATURE_SERIALIZED_SIZE: usize =
/// Signature serialized size
pub const SIGNATURE_SERIALIZED_SIZE: usize =
<DoubleSignature<TinyBLS381> as SerializableToBytes>::SERIALIZED_BYTES_SIZE;

/// A secret seed.
Expand Down Expand Up @@ -258,7 +258,7 @@ impl<T> sp_std::fmt::Debug for Public<T> {
}
}

#[cfg(feature = "std")]
#[cfg(feature = "serde")]
impl<T: BlsBound> Serialize for Public<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -268,7 +268,7 @@ impl<T: BlsBound> Serialize for Public<T> {
}
}

#[cfg(feature = "std")]
#[cfg(feature = "serde")]
impl<'de, T: BlsBound> Deserialize<'de> for Public<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down Expand Up @@ -330,7 +330,7 @@ impl<T> TryFrom<&[u8]> for Signature<T> {
}
}

#[cfg(feature = "std")]
#[cfg(feature = "serde")]
impl<T> Serialize for Signature<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -340,7 +340,7 @@ impl<T> Serialize for Signature<T> {
}
}

#[cfg(feature = "std")]
#[cfg(feature = "serde")]
impl<'de, T> Deserialize<'de> for Signature<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down Expand Up @@ -529,11 +529,10 @@ mod test {
);
}

// Only passes if the seed = (seed mod ScalarField)
#[test]
fn seed_and_derive_should_work() {
let seed = array_bytes::hex2array_unchecked(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f00",
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60",
);
let pair = Pair::from_seed(&seed);
// we are using hash to field so this is not going to work
Expand All @@ -543,7 +542,7 @@ mod test {
assert_eq!(
derived.to_raw_vec(),
array_bytes::hex2array_unchecked::<_, 32>(
"a4f2269333b3e87c577aa00c4a2cd650b3b30b2e8c286a47c251279ff3a26e0d"
"3a0626d095148813cd1642d38254f1cfff7eb8cc1a2fc83b2a135377c3554c12"
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ macro_rules! impl_from_entropy_base {
[$type; 17], [$type; 18], [$type; 19], [$type; 20], [$type; 21], [$type; 22], [$type; 23], [$type; 24],
[$type; 25], [$type; 26], [$type; 27], [$type; 28], [$type; 29], [$type; 30], [$type; 31], [$type; 32],
[$type; 36], [$type; 40], [$type; 44], [$type; 48], [$type; 56], [$type; 64], [$type; 72], [$type; 80],
[$type; 96], [$type; 112], [$type; 128], [$type; 160], [$type; 192], [$type; 224], [$type; 256]
[$type; 96], [$type; 112], [$type; 128], [$type; 160], [$type; 177], [$type; 192], [$type; 224], [$type; 256]
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/core/src/hexdisplay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ macro_rules! impl_non_endians {
impl_non_endians!(
[u8; 1], [u8; 2], [u8; 3], [u8; 4], [u8; 5], [u8; 6], [u8; 7], [u8; 8], [u8; 10], [u8; 12],
[u8; 14], [u8; 16], [u8; 20], [u8; 24], [u8; 28], [u8; 32], [u8; 40], [u8; 48], [u8; 56],
[u8; 64], [u8; 65], [u8; 80], [u8; 96], [u8; 112], [u8; 128], [u8; 144]
[u8; 64], [u8; 65], [u8; 80], [u8; 96], [u8; 112], [u8; 128], [u8; 144], [u8; 177]
);

/// Format into ASCII + # + hex, suitable for storage key preimages.
Expand Down
1 change: 1 addition & 0 deletions substrate/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub use paste;
pub mod bandersnatch;
#[cfg(feature = "bls-experimental")]
pub mod bls;
pub mod paired_crypto;
pub mod defer;
pub mod ecdsa;
pub mod ed25519;
Expand Down
Loading