mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 13:28:33 +00:00
Store pubkey cache decompressed on disk (#5897)
* Support uncompressed keys in crypto/bls
* Use uncompressed keys in cache
* Implement DB upgrade
* Implement downgrade
* More logging on v20 upgrade
* Revert "More logging on v20 upgrade"
This reverts commit cc5789b9d3.
* Merge remote-tracking branch 'origin/unstable' into uncompressed-pubkeys
* Add a little more logging
* Merge remote-tracking branch 'origin/unstable' into uncompressed-pubkeys
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
use crate::{
|
||||
generic_aggregate_public_key::TAggregatePublicKey,
|
||||
generic_aggregate_signature::TAggregateSignature,
|
||||
generic_public_key::{GenericPublicKey, TPublicKey, PUBLIC_KEY_BYTES_LEN},
|
||||
generic_public_key::{
|
||||
GenericPublicKey, TPublicKey, PUBLIC_KEY_BYTES_LEN, PUBLIC_KEY_UNCOMPRESSED_BYTES_LEN,
|
||||
},
|
||||
generic_secret_key::TSecretKey,
|
||||
generic_signature::{TSignature, SIGNATURE_BYTES_LEN},
|
||||
Error, Hash256, ZeroizeHash, INFINITY_SIGNATURE,
|
||||
BlstError, Error, Hash256, ZeroizeHash, INFINITY_SIGNATURE,
|
||||
};
|
||||
pub use blst::min_pk as blst_core;
|
||||
use blst::{blst_scalar, BLST_ERROR};
|
||||
@@ -121,6 +123,10 @@ impl TPublicKey for blst_core::PublicKey {
|
||||
self.compress()
|
||||
}
|
||||
|
||||
fn serialize_uncompressed(&self) -> [u8; PUBLIC_KEY_UNCOMPRESSED_BYTES_LEN] {
|
||||
blst_core::PublicKey::serialize(self)
|
||||
}
|
||||
|
||||
fn deserialize(bytes: &[u8]) -> Result<Self, Error> {
|
||||
// key_validate accepts uncompressed bytes too so enforce byte length here.
|
||||
// It also does subgroup checks, noting infinity check is done in `generic_public_key.rs`.
|
||||
@@ -132,6 +138,19 @@ impl TPublicKey for blst_core::PublicKey {
|
||||
}
|
||||
Self::key_validate(bytes).map_err(Into::into)
|
||||
}
|
||||
|
||||
fn deserialize_uncompressed(bytes: &[u8]) -> Result<Self, Error> {
|
||||
if bytes.len() != PUBLIC_KEY_UNCOMPRESSED_BYTES_LEN {
|
||||
return Err(Error::InvalidByteLength {
|
||||
got: bytes.len(),
|
||||
expected: PUBLIC_KEY_UNCOMPRESSED_BYTES_LEN,
|
||||
});
|
||||
}
|
||||
// Ensure we use the `blst` function rather than the one from this trait.
|
||||
let result: Result<Self, BlstError> = Self::deserialize(bytes);
|
||||
let key = result?;
|
||||
Ok(key)
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper that allows for `PartialEq` and `Clone` impls.
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use crate::{
|
||||
generic_aggregate_public_key::TAggregatePublicKey,
|
||||
generic_aggregate_signature::TAggregateSignature,
|
||||
generic_public_key::{GenericPublicKey, TPublicKey, PUBLIC_KEY_BYTES_LEN},
|
||||
generic_public_key::{
|
||||
GenericPublicKey, TPublicKey, PUBLIC_KEY_BYTES_LEN, PUBLIC_KEY_UNCOMPRESSED_BYTES_LEN,
|
||||
},
|
||||
generic_secret_key::{TSecretKey, SECRET_KEY_BYTES_LEN},
|
||||
generic_signature::{TSignature, SIGNATURE_BYTES_LEN},
|
||||
Error, Hash256, ZeroizeHash, INFINITY_PUBLIC_KEY, INFINITY_SIGNATURE,
|
||||
@@ -46,11 +48,19 @@ impl TPublicKey for PublicKey {
|
||||
self.0
|
||||
}
|
||||
|
||||
fn serialize_uncompressed(&self) -> [u8; PUBLIC_KEY_UNCOMPRESSED_BYTES_LEN] {
|
||||
panic!("fake_crypto does not support uncompressed keys")
|
||||
}
|
||||
|
||||
fn deserialize(bytes: &[u8]) -> Result<Self, Error> {
|
||||
let mut pubkey = Self::infinity();
|
||||
pubkey.0[..].copy_from_slice(&bytes[0..PUBLIC_KEY_BYTES_LEN]);
|
||||
Ok(pubkey)
|
||||
}
|
||||
|
||||
fn deserialize_uncompressed(_: &[u8]) -> Result<Self, Error> {
|
||||
panic!("fake_crypto does not support uncompressed keys")
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for PublicKey {}
|
||||
|
||||
Reference in New Issue
Block a user