diff --git a/beacon_chain/spec/datatypes/base.nim b/beacon_chain/spec/datatypes/base.nim index 03c29ccac..77ad03934 100644 --- a/beacon_chain/spec/datatypes/base.nim +++ b/beacon_chain/spec/datatypes/base.nim @@ -530,11 +530,9 @@ const DOMAIN_CONTRIBUTION_AND_PROOF* = DomainType([byte 0x09, 0x00, 0x00, 0x00]) func getImmutableValidatorData*(validator: Validator): ImmutableValidatorData2 = - let cookedKey = validator.pubkey.load() # Loading the pubkey is slow! - doAssert cookedKey.isSome, - "Cannot parse validator key: " & toHex(validator.pubkey) + let cookedKey = validator.pubkey.loadValid() # `Validator` has valid key ImmutableValidatorData2( - pubkey: cookedKey.get(), + pubkey: cookedKey, withdrawal_credentials: validator.withdrawal_credentials) template makeLimitedUInt*(T: untyped, limit: SomeUnsignedInt) = diff --git a/beacon_chain/spec/signatures.nim b/beacon_chain/spec/signatures.nim index 35b0855a1..f1fea6301 100644 --- a/beacon_chain/spec/signatures.nim +++ b/beacon_chain/spec/signatures.nim @@ -200,13 +200,24 @@ func get_deposit_signature*(message: DepositMessage, version: Version, blsSign(privkey, signing_root.data) proc verify_deposit_signature*(preset: RuntimeConfig, - deposit: DepositData): bool = + deposit: DepositData, + pubkey: CookedPubKey): bool = let deposit_message = deposit.getDepositMessage() signing_root = compute_deposit_signing_root( preset.GENESIS_FORK_VERSION, deposit_message) - blsVerify(deposit.pubkey, signing_root.data, deposit.signature) + blsVerify(pubkey, signing_root.data, deposit.signature) + +proc verify_deposit_signature*(preset: RuntimeConfig, + deposit: DepositData): bool = + # Deposits come with compressed public keys; uncompressing them is expensive. + # `blsVerify` fills an internal cache when using `ValidatorPubKey`. + # To avoid filling this cache unnecessarily, uncompress explicitly here. + let pubkey = deposit.pubkey.load() # Loading the pubkey is slow! + if pubkey.isNone: + return false + verify_deposit_signature(preset, deposit, pubkey.get) func compute_voluntary_exit_signing_root*( fork: Fork, genesis_validators_root: Eth2Digest,