UNPKG

@lodestar/beacon-node

Version:

A Typescript implementation of the beacon chain

41 lines 2.21 kB
import { assertValidAttesterSlashing, getAttesterSlashableIndices, getAttesterSlashingSignatureSets, } from "@lodestar/state-transition"; import { AttesterSlashingError, AttesterSlashingErrorCode, GossipAction } from "../errors/index.js"; export async function validateApiAttesterSlashing(chain, attesterSlashing) { const prioritizeBls = true; return validateAttesterSlashing(chain, attesterSlashing, prioritizeBls); } export async function validateGossipAttesterSlashing(chain, attesterSlashing) { return validateAttesterSlashing(chain, attesterSlashing); } export async function validateAttesterSlashing(chain, attesterSlashing, prioritizeBls = false) { // [IGNORE] At least one index in the intersection of the attesting indices of each attestation has not yet been seen // in any prior attester_slashing (i.e. // attester_slashed_indices = set(attestation_1.attesting_indices).intersection(attestation_2.attesting_indices // ), verify if any(attester_slashed_indices.difference(prior_seen_attester_slashed_indices))). const intersectingIndices = getAttesterSlashableIndices(attesterSlashing); if (chain.opPool.hasSeenAttesterSlashing(intersectingIndices)) { throw new AttesterSlashingError(GossipAction.IGNORE, { code: AttesterSlashingErrorCode.ALREADY_EXISTS, }); } const state = chain.getHeadState(); // [REJECT] All of the conditions within process_attester_slashing pass validation. try { // verifySignature = false, verified in batch below assertValidAttesterSlashing(state, attesterSlashing, false); } catch (e) { throw new AttesterSlashingError(GossipAction.REJECT, { code: AttesterSlashingErrorCode.INVALID, error: e, }); } const signatureSets = getAttesterSlashingSignatureSets(state, attesterSlashing); if (!(await chain.bls.verifySignatureSets(signatureSets, { batchable: true, priority: prioritizeBls }))) { throw new AttesterSlashingError(GossipAction.REJECT, { code: AttesterSlashingErrorCode.INVALID, error: Error("Invalid signature"), }); } } //# sourceMappingURL=attesterSlashing.js.map