-
-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
237 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 27 additions & 11 deletions
38
packages/beacon-state-transition/src/allForks/signatureSets/attesterSlashings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,40 @@ | ||
import {allForks, phase0} from "@chainsafe/lodestar-types"; | ||
import {ISignatureSet} from "../../util"; | ||
import {allForks, phase0, ssz} from "@chainsafe/lodestar-types"; | ||
import {computeSigningRoot, computeStartSlotAtEpoch, ISignatureSet, SignatureSetType} from "../../util"; | ||
import {CachedBeaconStateAllForks} from "../../types"; | ||
import {getIndexedAttestationSignatureSet} from "./indexedAttestation"; | ||
import {DOMAIN_BEACON_ATTESTER} from "@chainsafe/lodestar-params"; | ||
|
||
/** Get signature sets from all AttesterSlashing objects in a block */ | ||
export function getAttesterSlashingsSignatureSets( | ||
state: CachedBeaconStateAllForks, | ||
signedBlock: allForks.SignedBeaconBlock | ||
): ISignatureSet[] { | ||
return signedBlock.message.body.attesterSlashings | ||
.map((attesterSlashing) => getAttesterSlashingSignatureSets(state, attesterSlashing)) | ||
.flat(1); | ||
} | ||
|
||
/** Get signature sets from a single AttesterSlashing object */ | ||
export function getAttesterSlashingSignatureSets( | ||
state: CachedBeaconStateAllForks, | ||
attesterSlashing: phase0.AttesterSlashing | ||
): ISignatureSet[] { | ||
return [attesterSlashing.attestation1, attesterSlashing.attestation2].map((attestation) => | ||
getIndexedAttestationSignatureSet(state, attestation) | ||
getIndexedAttestationBnSignatureSet(state, attestation) | ||
); | ||
} | ||
|
||
/** Get signature sets from all AttesterSlashing objects in a block */ | ||
export function getAttesterSlashingsSignatureSets( | ||
export function getIndexedAttestationBnSignatureSet( | ||
state: CachedBeaconStateAllForks, | ||
signedBlock: allForks.SignedBeaconBlock | ||
): ISignatureSet[] { | ||
return signedBlock.message.body.attesterSlashings | ||
.map((attesterSlashing) => getAttesterSlashingSignatureSets(state, attesterSlashing)) | ||
.flat(1); | ||
indexedAttestation: phase0.IndexedAttestationBn | ||
): ISignatureSet { | ||
const {index2pubkey} = state.epochCtx; | ||
const slot = computeStartSlotAtEpoch(Number(indexedAttestation.data.target.epoch as bigint)); | ||
const domain = state.config.getDomain(DOMAIN_BEACON_ATTESTER, slot); | ||
|
||
return { | ||
type: SignatureSetType.aggregate, | ||
pubkeys: indexedAttestation.attestingIndices.map((i) => index2pubkey[i]), | ||
signingRoot: computeSigningRoot(ssz.phase0.AttestationDataBn, indexedAttestation.data, domain), | ||
signature: indexedAttestation.signature, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.