Skip to content

Commit

Permalink
feat(eos): <- skip validation when encountering default producer key …
Browse files Browse the repository at this point in the history
…values
  • Loading branch information
gskapka committed Feb 16, 2024
1 parent e9c4bc0 commit e88a54f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions common/eos/src/eos_constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::eos_crypto::eos_public_key::EosPublicKey;
lazy_static! {
pub static ref EOS_DEFAULT_PUB_KEY: EosPublicKey = EosPublicKey::default();
pub static ref EOS_DEFAULT_PUB_KEY_STRING: String = EOS_DEFAULT_PUB_KEY.to_string();
}

pub const MEMO: &str = "";
Expand Down
22 changes: 16 additions & 6 deletions common/eos/src/validate_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use secp256k1::Message;
use crate::{
bitcoin_crate_alias::hashes::{sha256, Hash},
eos_block_header::{EosBlockHeaderV1, EosBlockHeaderV2},
eos_constants::EOS_DEFAULT_PUB_KEY_STRING,
eos_crypto::{eos_public_key::EosPublicKey, eos_signature::EosSignature},
eos_producer_key::EosProducerKeyV1,
eos_producer_schedule::{EosProducerScheduleV1, EosProducerScheduleV2},
Expand Down Expand Up @@ -148,12 +149,21 @@ pub fn check_block_signature_is_valid(
let recovered_key =
recover_block_signer_public_key(msig_enabled, block_mroot, producer_signature, block_header, v2_schedule)?
.to_string();
debug!(" Producer: {}", block_header.producer);
debug!(" Signing key: {}", signing_key);
debug!("Recovered key: {}", recovered_key);
match signing_key == recovered_key {
true => Ok(()),
_ => Err("✘ Block signature not valid!".into()),

debug!(" producer: {}", block_header.producer);
debug!(" signing key: {}", signing_key);
debug!("recovered key: {}", recovered_key);

if recovered_key == *EOS_DEFAULT_PUB_KEY_STRING {
// NOTE: When we encounter an old format EOS key we replace it with the default instead,
// since they're otherwise unparseable by the secp256k1 crate.
warn!("producer key is old format - skipping block signature validation");
Ok(())
} else if signing_key == recovered_key {
info!("block signature is valid");
Ok(())
} else {
Err("block signature not valid!".into())
}
}

Expand Down

0 comments on commit e88a54f

Please sign in to comment.