@lodestar/state-transition 1.39.0-dev.2fe8de2346 → 1.39.0-dev.84b481ddb5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/block/index.d.ts.map +1 -1
- package/lib/block/index.js +4 -2
- package/lib/block/index.js.map +1 -1
- package/lib/block/isValidIndexedAttestation.d.ts +3 -2
- package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
- package/lib/block/isValidIndexedAttestation.js +4 -4
- package/lib/block/isValidIndexedAttestation.js.map +1 -1
- package/lib/block/processAttestationPhase0.d.ts.map +1 -1
- package/lib/block/processAttestationPhase0.js +1 -1
- package/lib/block/processAttestationPhase0.js.map +1 -1
- package/lib/block/processAttestationsAltair.d.ts.map +1 -1
- package/lib/block/processAttestationsAltair.js +1 -1
- package/lib/block/processAttestationsAltair.js.map +1 -1
- package/lib/block/processAttesterSlashing.js +1 -1
- package/lib/block/processAttesterSlashing.js.map +1 -1
- package/lib/block/processExecutionPayload.d.ts.map +1 -1
- package/lib/block/processExecutionPayload.js +6 -4
- package/lib/block/processExecutionPayload.js.map +1 -1
- package/lib/block/processProposerSlashing.d.ts.map +1 -1
- package/lib/block/processProposerSlashing.js +1 -1
- package/lib/block/processProposerSlashing.js.map +1 -1
- package/lib/block/processRandao.js +1 -1
- package/lib/block/processRandao.js.map +1 -1
- package/lib/block/processSyncCommittee.d.ts +2 -1
- package/lib/block/processSyncCommittee.d.ts.map +1 -1
- package/lib/block/processSyncCommittee.js +3 -3
- package/lib/block/processSyncCommittee.js.map +1 -1
- package/lib/block/processVoluntaryExit.d.ts.map +1 -1
- package/lib/block/processVoluntaryExit.js +2 -1
- package/lib/block/processVoluntaryExit.js.map +1 -1
- package/lib/cache/stateCache.d.ts +1 -0
- package/lib/cache/stateCache.d.ts.map +1 -1
- package/lib/cache/stateCache.js.map +1 -1
- package/lib/signatureSets/attesterSlashings.d.ts +4 -3
- package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
- package/lib/signatureSets/attesterSlashings.js +6 -6
- package/lib/signatureSets/attesterSlashings.js.map +1 -1
- package/lib/signatureSets/index.d.ts +2 -1
- package/lib/signatureSets/index.d.ts.map +1 -1
- package/lib/signatureSets/index.js +8 -8
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/signatureSets/indexedAttestation.d.ts +5 -4
- package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
- package/lib/signatureSets/indexedAttestation.js +8 -8
- package/lib/signatureSets/indexedAttestation.js.map +1 -1
- package/lib/signatureSets/proposer.d.ts +3 -2
- package/lib/signatureSets/proposer.d.ts.map +1 -1
- package/lib/signatureSets/proposer.js +3 -4
- package/lib/signatureSets/proposer.js.map +1 -1
- package/lib/signatureSets/proposerSlashings.d.ts +3 -2
- package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
- package/lib/signatureSets/proposerSlashings.js +4 -4
- package/lib/signatureSets/proposerSlashings.js.map +1 -1
- package/lib/signatureSets/randao.d.ts +3 -2
- package/lib/signatureSets/randao.d.ts.map +1 -1
- package/lib/signatureSets/randao.js +4 -4
- package/lib/signatureSets/randao.js.map +1 -1
- package/lib/signatureSets/voluntaryExits.d.ts +4 -3
- package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
- package/lib/signatureSets/voluntaryExits.js +6 -6
- package/lib/signatureSets/voluntaryExits.js.map +1 -1
- package/lib/stateTransition.d.ts.map +1 -1
- package/lib/stateTransition.js +2 -1
- package/lib/stateTransition.js.map +1 -1
- package/lib/util/execution.d.ts +11 -1
- package/lib/util/execution.d.ts.map +1 -1
- package/lib/util/execution.js +26 -1
- package/lib/util/execution.js.map +1 -1
- package/package.json +6 -6
- package/src/block/index.ts +6 -2
- package/src/block/isValidIndexedAttestation.ts +5 -2
- package/src/block/processAttestationPhase0.ts +1 -0
- package/src/block/processAttestationsAltair.ts +7 -1
- package/src/block/processAttesterSlashing.ts +1 -1
- package/src/block/processExecutionPayload.ts +14 -8
- package/src/block/processProposerSlashing.ts +6 -1
- package/src/block/processRandao.ts +1 -1
- package/src/block/processSyncCommittee.ts +10 -2
- package/src/block/processVoluntaryExit.ts +4 -1
- package/src/cache/stateCache.ts +1 -0
- package/src/signatureSets/attesterSlashings.ts +7 -3
- package/src/signatureSets/index.ts +9 -6
- package/src/signatureSets/indexedAttestation.ts +9 -3
- package/src/signatureSets/proposer.ts +4 -2
- package/src/signatureSets/proposerSlashings.ts +5 -6
- package/src/signatureSets/randao.ts +5 -2
- package/src/signatureSets/voluntaryExits.ts +7 -3
- package/src/stateTransition.ts +4 -1
- package/src/util/execution.ts +39 -0
|
@@ -3,7 +3,11 @@ import {ForkName, ForkSeq, isForkPostDeneb} from "@lodestar/params";
|
|
|
3
3
|
import {BeaconBlockBody, BlindedBeaconBlockBody, deneb, isExecutionPayload} from "@lodestar/types";
|
|
4
4
|
import {toHex, toRootHex} from "@lodestar/utils";
|
|
5
5
|
import {CachedBeaconStateBellatrix, CachedBeaconStateCapella} from "../types.js";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
executionPayloadToPayloadHeader,
|
|
8
|
+
getFullOrBlindedPayloadFromBody,
|
|
9
|
+
isMergeTransitionComplete,
|
|
10
|
+
} from "../util/execution.js";
|
|
7
11
|
import {computeEpochAtSlot, computeTimeAtSlot, getRandaoMix} from "../util/index.js";
|
|
8
12
|
import {BlockExternalData, ExecutionPayloadStatus} from "./externalData.js";
|
|
9
13
|
|
|
@@ -17,13 +21,15 @@ export function processExecutionPayload(
|
|
|
17
21
|
const forkName = ForkName[ForkSeq[fork] as ForkName];
|
|
18
22
|
// Verify consistency of the parent hash, block number, base fee per gas and gas limit
|
|
19
23
|
// with respect to the previous execution payload header
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
if (isMergeTransitionComplete(state)) {
|
|
25
|
+
const {latestExecutionPayloadHeader} = state;
|
|
26
|
+
if (!byteArrayEquals(payload.parentHash, latestExecutionPayloadHeader.blockHash)) {
|
|
27
|
+
throw Error(
|
|
28
|
+
`Invalid execution payload parentHash ${toRootHex(payload.parentHash)} latest blockHash ${toRootHex(
|
|
29
|
+
latestExecutionPayloadHeader.blockHash
|
|
30
|
+
)}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
// Verify random
|
|
@@ -77,7 +77,12 @@ export function assertValidProposerSlashing(
|
|
|
77
77
|
|
|
78
78
|
// verify signatures
|
|
79
79
|
if (verifySignatures) {
|
|
80
|
-
const signatureSets = getProposerSlashingSignatureSets(
|
|
80
|
+
const signatureSets = getProposerSlashingSignatureSets(
|
|
81
|
+
state.config,
|
|
82
|
+
state.epochCtx.index2pubkey,
|
|
83
|
+
state,
|
|
84
|
+
proposerSlashing
|
|
85
|
+
);
|
|
81
86
|
for (let i = 0; i < signatureSets.length; i++) {
|
|
82
87
|
if (!verifySignatureSet(signatureSets[i])) {
|
|
83
88
|
throw new Error(`ProposerSlashing header${i + 1} signature invalid`);
|
|
@@ -17,7 +17,7 @@ export function processRandao(state: CachedBeaconStateAllForks, block: BeaconBlo
|
|
|
17
17
|
const randaoReveal = block.body.randaoReveal;
|
|
18
18
|
|
|
19
19
|
// verify RANDAO reveal
|
|
20
|
-
if (verifySignature && !verifyRandaoSignature(epochCtx.index2pubkey, state, block)) {
|
|
20
|
+
if (verifySignature && !verifyRandaoSignature(state.config, epochCtx.index2pubkey, state, block)) {
|
|
21
21
|
throw new Error("RANDAO reveal is an invalid signature");
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {byteArrayEquals} from "@chainsafe/ssz";
|
|
2
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
2
3
|
import {DOMAIN_SYNC_COMMITTEE, SYNC_COMMITTEE_SIZE} from "@lodestar/params";
|
|
3
4
|
import {altair, ssz} from "@lodestar/types";
|
|
4
5
|
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
@@ -24,7 +25,13 @@ export function processSyncAggregate(
|
|
|
24
25
|
if (verifySignatures) {
|
|
25
26
|
// This is to conform to the spec - we want the signature to be verified
|
|
26
27
|
const participantIndices = block.body.syncAggregate.syncCommitteeBits.intersectValues(committeeIndices);
|
|
27
|
-
const signatureSet = getSyncCommitteeSignatureSet(
|
|
28
|
+
const signatureSet = getSyncCommitteeSignatureSet(
|
|
29
|
+
state.config,
|
|
30
|
+
state.epochCtx.index2pubkey,
|
|
31
|
+
state,
|
|
32
|
+
block,
|
|
33
|
+
participantIndices
|
|
34
|
+
);
|
|
28
35
|
// When there's no participation we consider the signature valid and just ignore i
|
|
29
36
|
if (signatureSet !== null && !verifySignatureSet(signatureSet)) {
|
|
30
37
|
throw Error("Sync committee signature invalid");
|
|
@@ -64,6 +71,7 @@ export function processSyncAggregate(
|
|
|
64
71
|
}
|
|
65
72
|
|
|
66
73
|
export function getSyncCommitteeSignatureSet(
|
|
74
|
+
config: BeaconConfig,
|
|
67
75
|
index2pubkey: Index2PubkeyCache,
|
|
68
76
|
state: CachedBeaconStateAllForks,
|
|
69
77
|
block: altair.BeaconBlock,
|
|
@@ -107,7 +115,7 @@ export function getSyncCommitteeSignatureSet(
|
|
|
107
115
|
throw Error("Empty sync committee signature is not infinity");
|
|
108
116
|
}
|
|
109
117
|
|
|
110
|
-
const domain =
|
|
118
|
+
const domain = config.getDomain(state.slot, DOMAIN_SYNC_COMMITTEE, previousSlot);
|
|
111
119
|
|
|
112
120
|
return {
|
|
113
121
|
type: SignatureSetType.aggregate,
|
|
@@ -74,7 +74,10 @@ export function getVoluntaryExitValidity(
|
|
|
74
74
|
return VoluntaryExitValidity.pendingWithdrawals;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
if (
|
|
77
|
+
if (
|
|
78
|
+
verifySignature &&
|
|
79
|
+
!verifyVoluntaryExitSignature(state.config, epochCtx.index2pubkey, state, signedVoluntaryExit)
|
|
80
|
+
) {
|
|
78
81
|
return VoluntaryExitValidity.invalidSignature;
|
|
79
82
|
}
|
|
80
83
|
|
package/src/cache/stateCache.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from "./types.js";
|
|
18
18
|
|
|
19
19
|
export type BeaconStateCache = {
|
|
20
|
+
/** @deprecated should not access config outside of state-transition package */
|
|
20
21
|
config: BeaconConfig;
|
|
21
22
|
epochCtx: EpochCache;
|
|
22
23
|
/** Count of clones created from this BeaconStateCache instance. readonly to prevent accidental usage downstream */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {DOMAIN_BEACON_ATTESTER} from "@lodestar/params";
|
|
2
3
|
import {AttesterSlashing, IndexedAttestationBigint, SignedBeaconBlock, ssz} from "@lodestar/types";
|
|
3
4
|
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
@@ -6,33 +7,36 @@ import {ISignatureSet, SignatureSetType, computeSigningRoot, computeStartSlotAtE
|
|
|
6
7
|
|
|
7
8
|
/** Get signature sets from all AttesterSlashing objects in a block */
|
|
8
9
|
export function getAttesterSlashingsSignatureSets(
|
|
10
|
+
config: BeaconConfig,
|
|
9
11
|
index2pubkey: Index2PubkeyCache,
|
|
10
12
|
state: CachedBeaconStateAllForks,
|
|
11
13
|
signedBlock: SignedBeaconBlock
|
|
12
14
|
): ISignatureSet[] {
|
|
13
15
|
return signedBlock.message.body.attesterSlashings.flatMap((attesterSlashing) =>
|
|
14
|
-
getAttesterSlashingSignatureSets(index2pubkey, state, attesterSlashing)
|
|
16
|
+
getAttesterSlashingSignatureSets(config, index2pubkey, state, attesterSlashing)
|
|
15
17
|
);
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
/** Get signature sets from a single AttesterSlashing object */
|
|
19
21
|
export function getAttesterSlashingSignatureSets(
|
|
22
|
+
config: BeaconConfig,
|
|
20
23
|
index2pubkey: Index2PubkeyCache,
|
|
21
24
|
state: CachedBeaconStateAllForks,
|
|
22
25
|
attesterSlashing: AttesterSlashing
|
|
23
26
|
): ISignatureSet[] {
|
|
24
27
|
return [attesterSlashing.attestation1, attesterSlashing.attestation2].map((attestation) =>
|
|
25
|
-
getIndexedAttestationBigintSignatureSet(index2pubkey, state, attestation)
|
|
28
|
+
getIndexedAttestationBigintSignatureSet(config, index2pubkey, state, attestation)
|
|
26
29
|
);
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
export function getIndexedAttestationBigintSignatureSet(
|
|
33
|
+
config: BeaconConfig,
|
|
30
34
|
index2pubkey: Index2PubkeyCache,
|
|
31
35
|
state: CachedBeaconStateAllForks,
|
|
32
36
|
indexedAttestation: IndexedAttestationBigint
|
|
33
37
|
): ISignatureSet {
|
|
34
38
|
const slot = computeStartSlotAtEpoch(Number(indexedAttestation.data.target.epoch as bigint));
|
|
35
|
-
const domain =
|
|
39
|
+
const domain = config.getDomain(state.slot, DOMAIN_BEACON_ATTESTER, slot);
|
|
36
40
|
|
|
37
41
|
return {
|
|
38
42
|
type: SignatureSetType.aggregate,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {ForkSeq} from "@lodestar/params";
|
|
2
3
|
import {IndexedAttestation, SignedBeaconBlock, altair, capella} from "@lodestar/types";
|
|
3
4
|
import {getSyncCommitteeSignatureSet} from "../block/processSyncCommittee.js";
|
|
@@ -26,6 +27,7 @@ export * from "./voluntaryExits.js";
|
|
|
26
27
|
* Deposits are not included because they can legally have invalid signatures.
|
|
27
28
|
*/
|
|
28
29
|
export function getBlockSignatureSets(
|
|
30
|
+
config: BeaconConfig,
|
|
29
31
|
index2pubkey: Index2PubkeyCache,
|
|
30
32
|
state: CachedBeaconStateAllForks,
|
|
31
33
|
signedBlock: SignedBeaconBlock,
|
|
@@ -39,20 +41,21 @@ export function getBlockSignatureSets(
|
|
|
39
41
|
const fork = state.config.getForkSeq(signedBlock.message.slot);
|
|
40
42
|
|
|
41
43
|
const signatureSets = [
|
|
42
|
-
getRandaoRevealSignatureSet(index2pubkey, state, signedBlock.message),
|
|
43
|
-
...getProposerSlashingsSignatureSets(index2pubkey, state, signedBlock),
|
|
44
|
-
...getAttesterSlashingsSignatureSets(index2pubkey, state, signedBlock),
|
|
45
|
-
...getAttestationsSignatureSets(index2pubkey, state, signedBlock, indexedAttestations),
|
|
46
|
-
...getVoluntaryExitsSignatureSets(index2pubkey, state, signedBlock),
|
|
44
|
+
getRandaoRevealSignatureSet(config, index2pubkey, state, signedBlock.message),
|
|
45
|
+
...getProposerSlashingsSignatureSets(config, index2pubkey, state, signedBlock),
|
|
46
|
+
...getAttesterSlashingsSignatureSets(config, index2pubkey, state, signedBlock),
|
|
47
|
+
...getAttestationsSignatureSets(config, index2pubkey, state, signedBlock, indexedAttestations),
|
|
48
|
+
...getVoluntaryExitsSignatureSets(config, index2pubkey, state, signedBlock),
|
|
47
49
|
];
|
|
48
50
|
|
|
49
51
|
if (!opts?.skipProposerSignature) {
|
|
50
|
-
signatureSets.push(getBlockProposerSignatureSet(index2pubkey, state, signedBlock));
|
|
52
|
+
signatureSets.push(getBlockProposerSignatureSet(config, index2pubkey, state, signedBlock));
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
// Only after altair fork, validate tSyncCommitteeSignature
|
|
54
56
|
if (fork >= ForkSeq.altair) {
|
|
55
57
|
const syncCommitteeSignatureSet = getSyncCommitteeSignatureSet(
|
|
58
|
+
config,
|
|
56
59
|
index2pubkey,
|
|
57
60
|
state as CachedBeaconStateAltair,
|
|
58
61
|
(signedBlock as altair.SignedBeaconBlock).message
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {DOMAIN_BEACON_ATTESTER} from "@lodestar/params";
|
|
2
3
|
import {IndexedAttestation, SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
|
|
3
4
|
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
@@ -10,16 +11,18 @@ import {
|
|
|
10
11
|
} from "../util/index.js";
|
|
11
12
|
|
|
12
13
|
export function getAttestationDataSigningRoot(
|
|
14
|
+
config: BeaconConfig,
|
|
13
15
|
state: CachedBeaconStateAllForks,
|
|
14
16
|
data: phase0.AttestationData
|
|
15
17
|
): Uint8Array {
|
|
16
18
|
const slot = computeStartSlotAtEpoch(data.target.epoch);
|
|
17
|
-
const domain =
|
|
19
|
+
const domain = config.getDomain(state.slot, DOMAIN_BEACON_ATTESTER, slot);
|
|
18
20
|
|
|
19
21
|
return computeSigningRoot(ssz.phase0.AttestationData, data, domain);
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
export function getAttestationWithIndicesSignatureSet(
|
|
25
|
+
config: BeaconConfig,
|
|
23
26
|
index2pubkey: Index2PubkeyCache,
|
|
24
27
|
state: CachedBeaconStateAllForks,
|
|
25
28
|
attestation: Pick<phase0.Attestation, "data" | "signature">,
|
|
@@ -27,17 +30,19 @@ export function getAttestationWithIndicesSignatureSet(
|
|
|
27
30
|
): ISignatureSet {
|
|
28
31
|
return createAggregateSignatureSetFromComponents(
|
|
29
32
|
attestingIndices.map((i) => index2pubkey[i]),
|
|
30
|
-
getAttestationDataSigningRoot(state, attestation.data),
|
|
33
|
+
getAttestationDataSigningRoot(config, state, attestation.data),
|
|
31
34
|
attestation.signature
|
|
32
35
|
);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
export function getIndexedAttestationSignatureSet(
|
|
39
|
+
config: BeaconConfig,
|
|
36
40
|
index2pubkey: Index2PubkeyCache,
|
|
37
41
|
state: CachedBeaconStateAllForks,
|
|
38
42
|
indexedAttestation: IndexedAttestation
|
|
39
43
|
): ISignatureSet {
|
|
40
44
|
return getAttestationWithIndicesSignatureSet(
|
|
45
|
+
config,
|
|
41
46
|
index2pubkey,
|
|
42
47
|
state,
|
|
43
48
|
indexedAttestation,
|
|
@@ -46,6 +51,7 @@ export function getIndexedAttestationSignatureSet(
|
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
export function getAttestationsSignatureSets(
|
|
54
|
+
config: BeaconConfig,
|
|
49
55
|
index2pubkey: Index2PubkeyCache,
|
|
50
56
|
state: CachedBeaconStateAllForks,
|
|
51
57
|
signedBlock: SignedBeaconBlock,
|
|
@@ -57,6 +63,6 @@ export function getAttestationsSignatureSets(
|
|
|
57
63
|
);
|
|
58
64
|
}
|
|
59
65
|
return indexedAttestations.map((indexedAttestation) =>
|
|
60
|
-
getIndexedAttestationSignatureSet(index2pubkey, state, indexedAttestation)
|
|
66
|
+
getIndexedAttestationSignatureSet(config, index2pubkey, state, indexedAttestation)
|
|
61
67
|
);
|
|
62
68
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
|
|
2
3
|
import {SignedBeaconBlock, SignedBlindedBeaconBlock, Slot, isBlindedBeaconBlock, phase0, ssz} from "@lodestar/types";
|
|
3
4
|
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
@@ -6,20 +7,21 @@ import {computeSigningRoot} from "../util/index.js";
|
|
|
6
7
|
import {ISignatureSet, SignatureSetType, verifySignatureSet} from "../util/signatureSets.js";
|
|
7
8
|
|
|
8
9
|
export function verifyProposerSignature(
|
|
10
|
+
config: BeaconConfig,
|
|
9
11
|
index2pubkey: Index2PubkeyCache,
|
|
10
12
|
state: CachedBeaconStateAllForks,
|
|
11
13
|
signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
|
|
12
14
|
): boolean {
|
|
13
|
-
const signatureSet = getBlockProposerSignatureSet(index2pubkey, state, signedBlock);
|
|
15
|
+
const signatureSet = getBlockProposerSignatureSet(config, index2pubkey, state, signedBlock);
|
|
14
16
|
return verifySignatureSet(signatureSet);
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export function getBlockProposerSignatureSet(
|
|
20
|
+
config: BeaconConfig,
|
|
18
21
|
index2pubkey: Index2PubkeyCache,
|
|
19
22
|
state: CachedBeaconStateAllForks,
|
|
20
23
|
signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
|
|
21
24
|
): ISignatureSet {
|
|
22
|
-
const {config} = state;
|
|
23
25
|
const domain = config.getDomain(state.slot, DOMAIN_BEACON_PROPOSER, signedBlock.message.slot);
|
|
24
26
|
|
|
25
27
|
const blockType = isBlindedBeaconBlock(signedBlock.message)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
|
|
2
3
|
import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
|
|
3
4
|
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
@@ -8,6 +9,7 @@ import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index
|
|
|
8
9
|
* Extract signatures to allow validating all block signatures at once
|
|
9
10
|
*/
|
|
10
11
|
export function getProposerSlashingSignatureSets(
|
|
12
|
+
config: BeaconConfig,
|
|
11
13
|
index2pubkey: Index2PubkeyCache,
|
|
12
14
|
state: CachedBeaconStateAllForks,
|
|
13
15
|
proposerSlashing: phase0.ProposerSlashing
|
|
@@ -17,11 +19,7 @@ export function getProposerSlashingSignatureSets(
|
|
|
17
19
|
// In state transition, ProposerSlashing headers are only partially validated. Their slot could be higher than the
|
|
18
20
|
// clock and the slashing would still be valid. Must use bigint variants to hash correctly to all possible values
|
|
19
21
|
return [proposerSlashing.signedHeader1, proposerSlashing.signedHeader2].map((signedHeader): ISignatureSet => {
|
|
20
|
-
const domain =
|
|
21
|
-
state.slot,
|
|
22
|
-
DOMAIN_BEACON_PROPOSER,
|
|
23
|
-
Number(signedHeader.message.slot as bigint)
|
|
24
|
-
);
|
|
22
|
+
const domain = config.getDomain(state.slot, DOMAIN_BEACON_PROPOSER, Number(signedHeader.message.slot as bigint));
|
|
25
23
|
|
|
26
24
|
return {
|
|
27
25
|
type: SignatureSetType.single,
|
|
@@ -33,11 +31,12 @@ export function getProposerSlashingSignatureSets(
|
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
export function getProposerSlashingsSignatureSets(
|
|
34
|
+
config: BeaconConfig,
|
|
36
35
|
index2pubkey: Index2PubkeyCache,
|
|
37
36
|
state: CachedBeaconStateAllForks,
|
|
38
37
|
signedBlock: SignedBeaconBlock
|
|
39
38
|
): ISignatureSet[] {
|
|
40
39
|
return signedBlock.message.body.proposerSlashings.flatMap((proposerSlashing) =>
|
|
41
|
-
getProposerSlashingSignatureSets(index2pubkey, state, proposerSlashing)
|
|
40
|
+
getProposerSlashingSignatureSets(config, index2pubkey, state, proposerSlashing)
|
|
42
41
|
);
|
|
43
42
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {DOMAIN_RANDAO} from "@lodestar/params";
|
|
2
3
|
import {BeaconBlock, ssz} from "@lodestar/types";
|
|
3
4
|
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
@@ -11,24 +12,26 @@ import {
|
|
|
11
12
|
} from "../util/index.js";
|
|
12
13
|
|
|
13
14
|
export function verifyRandaoSignature(
|
|
15
|
+
config: BeaconConfig,
|
|
14
16
|
index2pubkey: Index2PubkeyCache,
|
|
15
17
|
state: CachedBeaconStateAllForks,
|
|
16
18
|
block: BeaconBlock
|
|
17
19
|
): boolean {
|
|
18
|
-
return verifySignatureSet(getRandaoRevealSignatureSet(index2pubkey, state, block));
|
|
20
|
+
return verifySignatureSet(getRandaoRevealSignatureSet(config, index2pubkey, state, block));
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* Extract signatures to allow validating all block signatures at once
|
|
23
25
|
*/
|
|
24
26
|
export function getRandaoRevealSignatureSet(
|
|
27
|
+
config: BeaconConfig,
|
|
25
28
|
index2pubkey: Index2PubkeyCache,
|
|
26
29
|
state: CachedBeaconStateAllForks,
|
|
27
30
|
block: BeaconBlock
|
|
28
31
|
): ISignatureSet {
|
|
29
32
|
// should not get epoch from epochCtx
|
|
30
33
|
const epoch = computeEpochAtSlot(block.slot);
|
|
31
|
-
const domain =
|
|
34
|
+
const domain = config.getDomain(state.slot, DOMAIN_RANDAO, block.slot);
|
|
32
35
|
|
|
33
36
|
return {
|
|
34
37
|
type: SignatureSetType.single,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
|
|
2
3
|
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
3
4
|
import {CachedBeaconStateAllForks} from "../types.js";
|
|
@@ -10,23 +11,25 @@ import {
|
|
|
10
11
|
} from "../util/index.js";
|
|
11
12
|
|
|
12
13
|
export function verifyVoluntaryExitSignature(
|
|
14
|
+
config: BeaconConfig,
|
|
13
15
|
index2pubkey: Index2PubkeyCache,
|
|
14
16
|
state: CachedBeaconStateAllForks,
|
|
15
17
|
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
16
18
|
): boolean {
|
|
17
|
-
return verifySignatureSet(getVoluntaryExitSignatureSet(index2pubkey, state, signedVoluntaryExit));
|
|
19
|
+
return verifySignatureSet(getVoluntaryExitSignatureSet(config, index2pubkey, state, signedVoluntaryExit));
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Extract signatures to allow validating all block signatures at once
|
|
22
24
|
*/
|
|
23
25
|
export function getVoluntaryExitSignatureSet(
|
|
26
|
+
config: BeaconConfig,
|
|
24
27
|
index2pubkey: Index2PubkeyCache,
|
|
25
28
|
state: CachedBeaconStateAllForks,
|
|
26
29
|
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
27
30
|
): ISignatureSet {
|
|
28
31
|
const slot = computeStartSlotAtEpoch(signedVoluntaryExit.message.epoch);
|
|
29
|
-
const domain =
|
|
32
|
+
const domain = config.getDomainForVoluntaryExit(state.slot, slot);
|
|
30
33
|
|
|
31
34
|
return {
|
|
32
35
|
type: SignatureSetType.single,
|
|
@@ -37,11 +40,12 @@ export function getVoluntaryExitSignatureSet(
|
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
export function getVoluntaryExitsSignatureSets(
|
|
43
|
+
config: BeaconConfig,
|
|
40
44
|
index2pubkey: Index2PubkeyCache,
|
|
41
45
|
state: CachedBeaconStateAllForks,
|
|
42
46
|
signedBlock: SignedBeaconBlock
|
|
43
47
|
): ISignatureSet[] {
|
|
44
48
|
return signedBlock.message.body.voluntaryExits.map((voluntaryExit) =>
|
|
45
|
-
getVoluntaryExitSignatureSet(index2pubkey, state, voluntaryExit)
|
|
49
|
+
getVoluntaryExitSignatureSet(config, index2pubkey, state, voluntaryExit)
|
|
46
50
|
);
|
|
47
51
|
}
|
package/src/stateTransition.ts
CHANGED
|
@@ -111,7 +111,10 @@ export function stateTransition(
|
|
|
111
111
|
postState = processSlotsWithTransientCache(postState, blockSlot, options, {metrics, validatorMonitor});
|
|
112
112
|
|
|
113
113
|
// Verify proposer signature only
|
|
114
|
-
if (
|
|
114
|
+
if (
|
|
115
|
+
verifyProposer &&
|
|
116
|
+
!verifyProposerSignature(postState.config, postState.epochCtx.index2pubkey, postState, signedBlock)
|
|
117
|
+
) {
|
|
115
118
|
throw new Error("Invalid block signature");
|
|
116
119
|
}
|
|
117
120
|
|
package/src/util/execution.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {ForkName, ForkPostBellatrix, ForkPreGloas, ForkSeq} from "@lodestar/para
|
|
|
2
2
|
import {
|
|
3
3
|
BeaconBlock,
|
|
4
4
|
BeaconBlockBody,
|
|
5
|
+
BlindedBeaconBlock,
|
|
5
6
|
BlindedBeaconBlockBody,
|
|
6
7
|
ExecutionPayload,
|
|
7
8
|
ExecutionPayloadHeader,
|
|
@@ -9,16 +10,54 @@ import {
|
|
|
9
10
|
capella,
|
|
10
11
|
deneb,
|
|
11
12
|
isBlindedBeaconBlockBody,
|
|
13
|
+
isExecutionPayload,
|
|
12
14
|
ssz,
|
|
13
15
|
} from "@lodestar/types";
|
|
14
16
|
import {
|
|
15
17
|
BeaconStateAllForks,
|
|
18
|
+
BeaconStateBellatrix,
|
|
16
19
|
BeaconStateCapella,
|
|
17
20
|
BeaconStateExecutions,
|
|
18
21
|
CachedBeaconStateAllForks,
|
|
19
22
|
CachedBeaconStateExecutions,
|
|
20
23
|
} from "../types.js";
|
|
21
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Execution enabled = merge is done.
|
|
27
|
+
* When (A) state has execution data OR (B) block has execution data
|
|
28
|
+
*/
|
|
29
|
+
export function isExecutionEnabled(state: BeaconStateExecutions, block: BeaconBlock | BlindedBeaconBlock): boolean {
|
|
30
|
+
if (isMergeTransitionComplete(state)) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Throws if not post-bellatrix block. A fork-guard before isExecutionEnabled() prevents this from happening
|
|
35
|
+
const payload = getFullOrBlindedPayload(block);
|
|
36
|
+
|
|
37
|
+
return isExecutionPayload(payload)
|
|
38
|
+
? !ssz.bellatrix.ExecutionPayload.equals(payload, ssz.bellatrix.ExecutionPayload.defaultValue())
|
|
39
|
+
: !ssz.bellatrix.ExecutionPayloadHeader.equals(
|
|
40
|
+
state.latestExecutionPayloadHeader,
|
|
41
|
+
ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Merge is complete when the state includes execution layer data:
|
|
47
|
+
* state.latestExecutionPayloadHeader NOT EMPTY or state is post-capella
|
|
48
|
+
*/
|
|
49
|
+
export function isMergeTransitionComplete(state: BeaconStateExecutions): boolean {
|
|
50
|
+
if (isCapellaStateType(state)) {
|
|
51
|
+
// All networks have completed the merge transition before capella
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return !ssz.bellatrix.ExecutionPayloadHeader.equals(
|
|
56
|
+
(state as BeaconStateBellatrix).latestExecutionPayloadHeader,
|
|
57
|
+
ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
22
61
|
/** Type guard for bellatrix.BeaconState */
|
|
23
62
|
export function isExecutionStateType(state: BeaconStateAllForks): state is BeaconStateExecutions {
|
|
24
63
|
return (state as BeaconStateExecutions).latestExecutionPayloadHeader !== undefined;
|