@lodestar/state-transition 1.38.0 → 1.39.0-dev.075956b855
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.js +2 -2
- package/lib/block/index.js.map +1 -1
- package/lib/block/isValidIndexedAttestation.d.ts +4 -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.d.ts +2 -1
- package/lib/block/processAttesterSlashing.d.ts.map +1 -1
- package/lib/block/processAttesterSlashing.js +5 -4
- package/lib/block/processAttesterSlashing.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 +2 -2
- package/lib/block/processRandao.js.map +1 -1
- package/lib/block/processSyncCommittee.d.ts +4 -1
- package/lib/block/processSyncCommittee.d.ts.map +1 -1
- package/lib/block/processSyncCommittee.js +7 -6
- 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/epochCache.d.ts +0 -3
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +0 -3
- package/lib/cache/epochCache.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/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/signatureSets/attesterSlashings.d.ts +6 -5
- package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
- package/lib/signatureSets/attesterSlashings.js +11 -8
- package/lib/signatureSets/attesterSlashings.js.map +1 -1
- package/lib/signatureSets/index.d.ts +5 -3
- package/lib/signatureSets/index.d.ts.map +1 -1
- package/lib/signatureSets/index.js +10 -10
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/signatureSets/indexedAttestation.d.ts +7 -6
- package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
- package/lib/signatureSets/indexedAttestation.js +12 -9
- package/lib/signatureSets/indexedAttestation.js.map +1 -1
- package/lib/signatureSets/proposer.d.ts +6 -4
- package/lib/signatureSets/proposer.d.ts.map +1 -1
- package/lib/signatureSets/proposer.js +15 -13
- package/lib/signatureSets/proposer.js.map +1 -1
- package/lib/signatureSets/proposerSlashings.d.ts +5 -4
- package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
- package/lib/signatureSets/proposerSlashings.js +8 -6
- package/lib/signatureSets/proposerSlashings.js.map +1 -1
- package/lib/signatureSets/randao.d.ts +4 -3
- package/lib/signatureSets/randao.d.ts.map +1 -1
- package/lib/signatureSets/randao.js +7 -6
- package/lib/signatureSets/randao.js.map +1 -1
- package/lib/signatureSets/voluntaryExits.d.ts +6 -5
- package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
- package/lib/signatureSets/voluntaryExits.js +11 -9
- package/lib/signatureSets/voluntaryExits.js.map +1 -1
- package/lib/stateTransition.js +1 -1
- package/lib/stateTransition.js.map +1 -1
- package/lib/util/execution.d.ts +2 -7
- package/lib/util/execution.d.ts.map +1 -1
- package/lib/util/execution.js +7 -25
- package/lib/util/execution.js.map +1 -1
- package/package.json +6 -6
- package/src/block/index.ts +1 -1
- package/src/block/isValidIndexedAttestation.ts +10 -2
- package/src/block/processAttestationPhase0.ts +9 -1
- package/src/block/processAttestationsAltair.ts +7 -1
- package/src/block/processAttesterSlashing.ts +6 -3
- package/src/block/processProposerSlashing.ts +6 -1
- package/src/block/processRandao.ts +2 -2
- package/src/block/processSyncCommittee.ts +18 -6
- package/src/block/processVoluntaryExit.ts +4 -1
- package/src/cache/epochCache.ts +0 -3
- package/src/cache/stateCache.ts +1 -0
- package/src/index.ts +1 -2
- package/src/signatureSets/attesterSlashings.ts +19 -10
- package/src/signatureSets/index.ts +18 -12
- package/src/signatureSets/indexedAttestation.ts +30 -12
- package/src/signatureSets/proposer.ts +19 -10
- package/src/signatureSets/proposerSlashings.ts +14 -12
- package/src/signatureSets/randao.ts +17 -7
- package/src/signatureSets/voluntaryExits.ts +19 -11
- package/src/stateTransition.ts +1 -1
- package/src/util/execution.ts +8 -29
|
@@ -1,38 +1,47 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {DOMAIN_BEACON_ATTESTER} from "@lodestar/params";
|
|
2
|
-
import {AttesterSlashing, IndexedAttestationBigint, SignedBeaconBlock, ssz} from "@lodestar/types";
|
|
3
|
-
import {
|
|
3
|
+
import {AttesterSlashing, IndexedAttestationBigint, SignedBeaconBlock, Slot, ssz} from "@lodestar/types";
|
|
4
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
4
5
|
import {ISignatureSet, SignatureSetType, computeSigningRoot, computeStartSlotAtEpoch} from "../util/index.js";
|
|
5
6
|
|
|
6
7
|
/** Get signature sets from all AttesterSlashing objects in a block */
|
|
7
8
|
export function getAttesterSlashingsSignatureSets(
|
|
8
|
-
|
|
9
|
+
config: BeaconConfig,
|
|
10
|
+
index2pubkey: Index2PubkeyCache,
|
|
9
11
|
signedBlock: SignedBeaconBlock
|
|
10
12
|
): ISignatureSet[] {
|
|
13
|
+
// the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
|
|
14
|
+
// and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
|
|
15
|
+
const blockSlot = signedBlock.message.slot;
|
|
11
16
|
return signedBlock.message.body.attesterSlashings.flatMap((attesterSlashing) =>
|
|
12
|
-
getAttesterSlashingSignatureSets(
|
|
17
|
+
getAttesterSlashingSignatureSets(config, index2pubkey, blockSlot, attesterSlashing)
|
|
13
18
|
);
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
/** Get signature sets from a single AttesterSlashing object */
|
|
17
22
|
export function getAttesterSlashingSignatureSets(
|
|
18
|
-
|
|
23
|
+
config: BeaconConfig,
|
|
24
|
+
index2pubkey: Index2PubkeyCache,
|
|
25
|
+
stateSlot: Slot,
|
|
19
26
|
attesterSlashing: AttesterSlashing
|
|
20
27
|
): ISignatureSet[] {
|
|
21
28
|
return [attesterSlashing.attestation1, attesterSlashing.attestation2].map((attestation) =>
|
|
22
|
-
getIndexedAttestationBigintSignatureSet(
|
|
29
|
+
getIndexedAttestationBigintSignatureSet(config, index2pubkey, stateSlot, attestation)
|
|
23
30
|
);
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
export function getIndexedAttestationBigintSignatureSet(
|
|
27
|
-
|
|
34
|
+
config: BeaconConfig,
|
|
35
|
+
index2pubkey: Index2PubkeyCache,
|
|
36
|
+
stateSlot: Slot,
|
|
28
37
|
indexedAttestation: IndexedAttestationBigint
|
|
29
38
|
): ISignatureSet {
|
|
30
|
-
const
|
|
31
|
-
const domain =
|
|
39
|
+
const messageSlot = computeStartSlotAtEpoch(Number(indexedAttestation.data.target.epoch as bigint));
|
|
40
|
+
const domain = config.getDomain(stateSlot, DOMAIN_BEACON_ATTESTER, messageSlot);
|
|
32
41
|
|
|
33
42
|
return {
|
|
34
43
|
type: SignatureSetType.aggregate,
|
|
35
|
-
pubkeys: indexedAttestation.attestingIndices.map((i) =>
|
|
44
|
+
pubkeys: indexedAttestation.attestingIndices.map((i) => index2pubkey[i]),
|
|
36
45
|
signingRoot: computeSigningRoot(ssz.phase0.AttestationDataBigint, indexedAttestation.data, domain),
|
|
37
46
|
signature: indexedAttestation.signature,
|
|
38
47
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
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";
|
|
4
|
-
import {
|
|
5
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
6
|
+
import {SyncCommitteeCache} from "../cache/syncCommitteeCache.js";
|
|
5
7
|
import {ISignatureSet} from "../util/index.js";
|
|
6
8
|
import {getAttesterSlashingsSignatureSets} from "./attesterSlashings.js";
|
|
7
9
|
import {getBlsToExecutionChangeSignatureSets} from "./blsToExecutionChange.js";
|
|
@@ -14,7 +16,7 @@ import {getVoluntaryExitsSignatureSets} from "./voluntaryExits.js";
|
|
|
14
16
|
export * from "./attesterSlashings.js";
|
|
15
17
|
export * from "./blsToExecutionChange.js";
|
|
16
18
|
export * from "./indexedAttestation.js";
|
|
17
|
-
export * from "./indexedPayloadAttestation.
|
|
19
|
+
export * from "./indexedPayloadAttestation.js";
|
|
18
20
|
export * from "./proposer.js";
|
|
19
21
|
export * from "./proposerSlashings.js";
|
|
20
22
|
export * from "./randao.js";
|
|
@@ -25,7 +27,9 @@ export * from "./voluntaryExits.js";
|
|
|
25
27
|
* Deposits are not included because they can legally have invalid signatures.
|
|
26
28
|
*/
|
|
27
29
|
export function getBlockSignatureSets(
|
|
28
|
-
|
|
30
|
+
config: BeaconConfig,
|
|
31
|
+
index2pubkey: Index2PubkeyCache,
|
|
32
|
+
currentSyncCommitteeIndexed: SyncCommitteeCache,
|
|
29
33
|
signedBlock: SignedBeaconBlock,
|
|
30
34
|
indexedAttestations: IndexedAttestation[],
|
|
31
35
|
opts?: {
|
|
@@ -34,24 +38,26 @@ export function getBlockSignatureSets(
|
|
|
34
38
|
}
|
|
35
39
|
): ISignatureSet[] {
|
|
36
40
|
// fork based validations
|
|
37
|
-
const fork =
|
|
41
|
+
const fork = config.getForkSeq(signedBlock.message.slot);
|
|
38
42
|
|
|
39
43
|
const signatureSets = [
|
|
40
|
-
getRandaoRevealSignatureSet(
|
|
41
|
-
...getProposerSlashingsSignatureSets(
|
|
42
|
-
...getAttesterSlashingsSignatureSets(
|
|
43
|
-
...getAttestationsSignatureSets(
|
|
44
|
-
...getVoluntaryExitsSignatureSets(
|
|
44
|
+
getRandaoRevealSignatureSet(config, index2pubkey, signedBlock.message),
|
|
45
|
+
...getProposerSlashingsSignatureSets(config, index2pubkey, signedBlock),
|
|
46
|
+
...getAttesterSlashingsSignatureSets(config, index2pubkey, signedBlock),
|
|
47
|
+
...getAttestationsSignatureSets(config, index2pubkey, signedBlock, indexedAttestations),
|
|
48
|
+
...getVoluntaryExitsSignatureSets(config, index2pubkey, signedBlock),
|
|
45
49
|
];
|
|
46
50
|
|
|
47
51
|
if (!opts?.skipProposerSignature) {
|
|
48
|
-
signatureSets.push(getBlockProposerSignatureSet(
|
|
52
|
+
signatureSets.push(getBlockProposerSignatureSet(config, index2pubkey, signedBlock));
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
// Only after altair fork, validate tSyncCommitteeSignature
|
|
52
56
|
if (fork >= ForkSeq.altair) {
|
|
53
57
|
const syncCommitteeSignatureSet = getSyncCommitteeSignatureSet(
|
|
54
|
-
|
|
58
|
+
config,
|
|
59
|
+
index2pubkey,
|
|
60
|
+
currentSyncCommitteeIndexed,
|
|
55
61
|
(signedBlock as altair.SignedBeaconBlock).message
|
|
56
62
|
);
|
|
57
63
|
// There may be no participants in this syncCommitteeSignature, so it must not be validated
|
|
@@ -63,7 +69,7 @@ export function getBlockSignatureSets(
|
|
|
63
69
|
// only after capella fork
|
|
64
70
|
if (fork >= ForkSeq.capella) {
|
|
65
71
|
const blsToExecutionChangeSignatureSets = getBlsToExecutionChangeSignatureSets(
|
|
66
|
-
|
|
72
|
+
config,
|
|
67
73
|
signedBlock as capella.SignedBeaconBlock
|
|
68
74
|
);
|
|
69
75
|
if (blsToExecutionChangeSignatureSets.length > 0) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {DOMAIN_BEACON_ATTESTER} from "@lodestar/params";
|
|
2
|
-
import {IndexedAttestation, SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
|
|
3
|
-
import {
|
|
3
|
+
import {IndexedAttestation, SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
|
|
4
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
4
5
|
import {
|
|
5
6
|
ISignatureSet,
|
|
6
7
|
computeSigningRoot,
|
|
@@ -9,36 +10,48 @@ import {
|
|
|
9
10
|
} from "../util/index.js";
|
|
10
11
|
|
|
11
12
|
export function getAttestationDataSigningRoot(
|
|
12
|
-
|
|
13
|
+
config: BeaconConfig,
|
|
14
|
+
stateSlot: Slot,
|
|
13
15
|
data: phase0.AttestationData
|
|
14
16
|
): Uint8Array {
|
|
15
|
-
const
|
|
16
|
-
const domain =
|
|
17
|
+
const messageSlot = computeStartSlotAtEpoch(data.target.epoch);
|
|
18
|
+
const domain = config.getDomain(stateSlot, DOMAIN_BEACON_ATTESTER, messageSlot);
|
|
17
19
|
|
|
18
20
|
return computeSigningRoot(ssz.phase0.AttestationData, data, domain);
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export function getAttestationWithIndicesSignatureSet(
|
|
22
|
-
|
|
24
|
+
config: BeaconConfig,
|
|
25
|
+
index2pubkey: Index2PubkeyCache,
|
|
26
|
+
stateSlot: Slot,
|
|
23
27
|
attestation: Pick<phase0.Attestation, "data" | "signature">,
|
|
24
28
|
attestingIndices: number[]
|
|
25
29
|
): ISignatureSet {
|
|
26
30
|
return createAggregateSignatureSetFromComponents(
|
|
27
|
-
attestingIndices.map((i) =>
|
|
28
|
-
getAttestationDataSigningRoot(
|
|
31
|
+
attestingIndices.map((i) => index2pubkey[i]),
|
|
32
|
+
getAttestationDataSigningRoot(config, stateSlot, attestation.data),
|
|
29
33
|
attestation.signature
|
|
30
34
|
);
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
export function getIndexedAttestationSignatureSet(
|
|
34
|
-
|
|
38
|
+
config: BeaconConfig,
|
|
39
|
+
index2pubkey: Index2PubkeyCache,
|
|
40
|
+
stateSlot: Slot,
|
|
35
41
|
indexedAttestation: IndexedAttestation
|
|
36
42
|
): ISignatureSet {
|
|
37
|
-
return getAttestationWithIndicesSignatureSet(
|
|
43
|
+
return getAttestationWithIndicesSignatureSet(
|
|
44
|
+
config,
|
|
45
|
+
index2pubkey,
|
|
46
|
+
stateSlot,
|
|
47
|
+
indexedAttestation,
|
|
48
|
+
indexedAttestation.attestingIndices
|
|
49
|
+
);
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
export function getAttestationsSignatureSets(
|
|
41
|
-
|
|
53
|
+
config: BeaconConfig,
|
|
54
|
+
index2pubkey: Index2PubkeyCache,
|
|
42
55
|
signedBlock: SignedBeaconBlock,
|
|
43
56
|
indexedAttestations: IndexedAttestation[]
|
|
44
57
|
): ISignatureSet[] {
|
|
@@ -47,5 +60,10 @@ export function getAttestationsSignatureSets(
|
|
|
47
60
|
`Indexed attestations length mismatch: got ${indexedAttestations.length}, expected ${signedBlock.message.body.attestations.length}`
|
|
48
61
|
);
|
|
49
62
|
}
|
|
50
|
-
|
|
63
|
+
// the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
|
|
64
|
+
// and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
|
|
65
|
+
const blockSlot = signedBlock.message.slot;
|
|
66
|
+
return indexedAttestations.map((indexedAttestation) =>
|
|
67
|
+
getIndexedAttestationSignatureSet(config, index2pubkey, blockSlot, indexedAttestation)
|
|
68
|
+
);
|
|
51
69
|
}
|
|
@@ -1,23 +1,29 @@
|
|
|
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";
|
|
4
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
3
5
|
import {CachedBeaconStateAllForks} from "../types.js";
|
|
4
6
|
import {computeSigningRoot} from "../util/index.js";
|
|
5
7
|
import {ISignatureSet, SignatureSetType, verifySignatureSet} from "../util/signatureSets.js";
|
|
6
8
|
|
|
7
9
|
export function verifyProposerSignature(
|
|
8
|
-
|
|
10
|
+
config: BeaconConfig,
|
|
11
|
+
index2pubkey: Index2PubkeyCache,
|
|
9
12
|
signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
|
|
10
13
|
): boolean {
|
|
11
|
-
const signatureSet = getBlockProposerSignatureSet(
|
|
14
|
+
const signatureSet = getBlockProposerSignatureSet(config, index2pubkey, signedBlock);
|
|
12
15
|
return verifySignatureSet(signatureSet);
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
export function getBlockProposerSignatureSet(
|
|
16
|
-
|
|
19
|
+
config: BeaconConfig,
|
|
20
|
+
index2pubkey: Index2PubkeyCache,
|
|
17
21
|
signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
|
|
18
22
|
): ISignatureSet {
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
// the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
|
|
24
|
+
// and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
|
|
25
|
+
const blockSlot = signedBlock.message.slot;
|
|
26
|
+
const domain = config.getDomain(blockSlot, DOMAIN_BEACON_PROPOSER, blockSlot);
|
|
21
27
|
|
|
22
28
|
const blockType = isBlindedBeaconBlock(signedBlock.message)
|
|
23
29
|
? config.getPostBellatrixForkTypes(signedBlock.message.slot).BlindedBeaconBlock
|
|
@@ -25,37 +31,40 @@ export function getBlockProposerSignatureSet(
|
|
|
25
31
|
|
|
26
32
|
return {
|
|
27
33
|
type: SignatureSetType.single,
|
|
28
|
-
pubkey:
|
|
34
|
+
pubkey: index2pubkey[signedBlock.message.proposerIndex],
|
|
29
35
|
signingRoot: computeSigningRoot(blockType, signedBlock.message, domain),
|
|
30
36
|
signature: signedBlock.signature,
|
|
31
37
|
};
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
export function getBlockHeaderProposerSignatureSetByParentStateSlot(
|
|
41
|
+
index2pubkey: Index2PubkeyCache,
|
|
35
42
|
parentState: CachedBeaconStateAllForks,
|
|
36
43
|
signedBlockHeader: phase0.SignedBeaconBlockHeader
|
|
37
44
|
) {
|
|
38
|
-
return getBlockHeaderProposerSignatureSet(parentState, signedBlockHeader, parentState.slot);
|
|
45
|
+
return getBlockHeaderProposerSignatureSet(index2pubkey, parentState, signedBlockHeader, parentState.slot);
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
export function getBlockHeaderProposerSignatureSetByHeaderSlot(
|
|
49
|
+
index2pubkey: Index2PubkeyCache,
|
|
42
50
|
headState: CachedBeaconStateAllForks,
|
|
43
51
|
signedBlockHeader: phase0.SignedBeaconBlockHeader
|
|
44
52
|
) {
|
|
45
|
-
return getBlockHeaderProposerSignatureSet(headState, signedBlockHeader, signedBlockHeader.message.slot);
|
|
53
|
+
return getBlockHeaderProposerSignatureSet(index2pubkey, headState, signedBlockHeader, signedBlockHeader.message.slot);
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
function getBlockHeaderProposerSignatureSet(
|
|
57
|
+
index2pubkey: Index2PubkeyCache,
|
|
49
58
|
state: CachedBeaconStateAllForks,
|
|
50
59
|
signedBlockHeader: phase0.SignedBeaconBlockHeader,
|
|
51
60
|
domainSlot: Slot
|
|
52
61
|
): ISignatureSet {
|
|
53
|
-
const {config
|
|
62
|
+
const {config} = state;
|
|
54
63
|
const domain = config.getDomain(domainSlot, DOMAIN_BEACON_PROPOSER, signedBlockHeader.message.slot);
|
|
55
64
|
|
|
56
65
|
return {
|
|
57
66
|
type: SignatureSetType.single,
|
|
58
|
-
pubkey:
|
|
67
|
+
pubkey: index2pubkey[signedBlockHeader.message.proposerIndex],
|
|
59
68
|
signingRoot: computeSigningRoot(ssz.phase0.BeaconBlockHeader, signedBlockHeader.message, domain),
|
|
60
69
|
signature: signedBlockHeader.signature,
|
|
61
70
|
};
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
|
|
2
|
-
import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
|
|
3
|
-
import {
|
|
3
|
+
import {SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
|
|
4
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
4
5
|
import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Extract signatures to allow validating all block signatures at once
|
|
8
9
|
*/
|
|
9
10
|
export function getProposerSlashingSignatureSets(
|
|
10
|
-
|
|
11
|
+
config: BeaconConfig,
|
|
12
|
+
index2pubkey: Index2PubkeyCache,
|
|
13
|
+
stateSlot: Slot,
|
|
11
14
|
proposerSlashing: phase0.ProposerSlashing
|
|
12
15
|
): ISignatureSet[] {
|
|
13
|
-
const
|
|
14
|
-
const pubkey = epochCtx.index2pubkey[proposerSlashing.signedHeader1.message.proposerIndex];
|
|
16
|
+
const pubkey = index2pubkey[proposerSlashing.signedHeader1.message.proposerIndex];
|
|
15
17
|
|
|
16
18
|
// In state transition, ProposerSlashing headers are only partially validated. Their slot could be higher than the
|
|
17
19
|
// clock and the slashing would still be valid. Must use bigint variants to hash correctly to all possible values
|
|
18
20
|
return [proposerSlashing.signedHeader1, proposerSlashing.signedHeader2].map((signedHeader): ISignatureSet => {
|
|
19
|
-
const domain =
|
|
20
|
-
state.slot,
|
|
21
|
-
DOMAIN_BEACON_PROPOSER,
|
|
22
|
-
Number(signedHeader.message.slot as bigint)
|
|
23
|
-
);
|
|
21
|
+
const domain = config.getDomain(stateSlot, DOMAIN_BEACON_PROPOSER, Number(signedHeader.message.slot as bigint));
|
|
24
22
|
|
|
25
23
|
return {
|
|
26
24
|
type: SignatureSetType.single,
|
|
@@ -32,10 +30,14 @@ export function getProposerSlashingSignatureSets(
|
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
export function getProposerSlashingsSignatureSets(
|
|
35
|
-
|
|
33
|
+
config: BeaconConfig,
|
|
34
|
+
index2pubkey: Index2PubkeyCache,
|
|
36
35
|
signedBlock: SignedBeaconBlock
|
|
37
36
|
): ISignatureSet[] {
|
|
37
|
+
// the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
|
|
38
|
+
// and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
|
|
39
|
+
const blockSlot = signedBlock.message.slot;
|
|
38
40
|
return signedBlock.message.body.proposerSlashings.flatMap((proposerSlashing) =>
|
|
39
|
-
getProposerSlashingSignatureSets(
|
|
41
|
+
getProposerSlashingSignatureSets(config, index2pubkey, blockSlot, proposerSlashing)
|
|
40
42
|
);
|
|
41
43
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {DOMAIN_RANDAO} from "@lodestar/params";
|
|
2
3
|
import {BeaconBlock, ssz} from "@lodestar/types";
|
|
3
|
-
import {
|
|
4
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
4
5
|
import {
|
|
5
6
|
ISignatureSet,
|
|
6
7
|
SignatureSetType,
|
|
@@ -9,22 +10,31 @@ import {
|
|
|
9
10
|
verifySignatureSet,
|
|
10
11
|
} from "../util/index.js";
|
|
11
12
|
|
|
12
|
-
export function verifyRandaoSignature(
|
|
13
|
-
|
|
13
|
+
export function verifyRandaoSignature(
|
|
14
|
+
config: BeaconConfig,
|
|
15
|
+
index2pubkey: Index2PubkeyCache,
|
|
16
|
+
block: BeaconBlock
|
|
17
|
+
): boolean {
|
|
18
|
+
return verifySignatureSet(getRandaoRevealSignatureSet(config, index2pubkey, block));
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
/**
|
|
17
22
|
* Extract signatures to allow validating all block signatures at once
|
|
18
23
|
*/
|
|
19
|
-
export function getRandaoRevealSignatureSet(
|
|
20
|
-
|
|
24
|
+
export function getRandaoRevealSignatureSet(
|
|
25
|
+
config: BeaconConfig,
|
|
26
|
+
index2pubkey: Index2PubkeyCache,
|
|
27
|
+
block: BeaconBlock
|
|
28
|
+
): ISignatureSet {
|
|
21
29
|
// should not get epoch from epochCtx
|
|
22
30
|
const epoch = computeEpochAtSlot(block.slot);
|
|
23
|
-
|
|
31
|
+
// the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
|
|
32
|
+
// and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
|
|
33
|
+
const domain = config.getDomain(block.slot, DOMAIN_RANDAO, block.slot);
|
|
24
34
|
|
|
25
35
|
return {
|
|
26
36
|
type: SignatureSetType.single,
|
|
27
|
-
pubkey:
|
|
37
|
+
pubkey: index2pubkey[block.proposerIndex],
|
|
28
38
|
signingRoot: computeSigningRoot(ssz.Epoch, epoch, domain),
|
|
29
39
|
signature: block.body.randaoReveal,
|
|
30
40
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
2
|
+
import {SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
|
|
3
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
3
4
|
import {
|
|
4
5
|
ISignatureSet,
|
|
5
6
|
SignatureSetType,
|
|
@@ -9,36 +10,43 @@ import {
|
|
|
9
10
|
} from "../util/index.js";
|
|
10
11
|
|
|
11
12
|
export function verifyVoluntaryExitSignature(
|
|
12
|
-
|
|
13
|
+
config: BeaconConfig,
|
|
14
|
+
index2pubkey: Index2PubkeyCache,
|
|
15
|
+
stateSlot: Slot,
|
|
13
16
|
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
14
17
|
): boolean {
|
|
15
|
-
return verifySignatureSet(getVoluntaryExitSignatureSet(
|
|
18
|
+
return verifySignatureSet(getVoluntaryExitSignatureSet(config, index2pubkey, stateSlot, signedVoluntaryExit));
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* Extract signatures to allow validating all block signatures at once
|
|
20
23
|
*/
|
|
21
24
|
export function getVoluntaryExitSignatureSet(
|
|
22
|
-
|
|
25
|
+
config: BeaconConfig,
|
|
26
|
+
index2pubkey: Index2PubkeyCache,
|
|
27
|
+
stateSlot: Slot,
|
|
23
28
|
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
24
29
|
): ISignatureSet {
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const domain = state.config.getDomainForVoluntaryExit(state.slot, slot);
|
|
30
|
+
const messageSlot = computeStartSlotAtEpoch(signedVoluntaryExit.message.epoch);
|
|
31
|
+
const domain = config.getDomainForVoluntaryExit(stateSlot, messageSlot);
|
|
28
32
|
|
|
29
33
|
return {
|
|
30
34
|
type: SignatureSetType.single,
|
|
31
|
-
pubkey:
|
|
35
|
+
pubkey: index2pubkey[signedVoluntaryExit.message.validatorIndex],
|
|
32
36
|
signingRoot: computeSigningRoot(ssz.phase0.VoluntaryExit, signedVoluntaryExit.message, domain),
|
|
33
37
|
signature: signedVoluntaryExit.signature,
|
|
34
38
|
};
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
export function getVoluntaryExitsSignatureSets(
|
|
38
|
-
|
|
42
|
+
config: BeaconConfig,
|
|
43
|
+
index2pubkey: Index2PubkeyCache,
|
|
39
44
|
signedBlock: SignedBeaconBlock
|
|
40
45
|
): ISignatureSet[] {
|
|
46
|
+
// the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
|
|
47
|
+
// and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
|
|
48
|
+
const blockSlot = signedBlock.message.slot;
|
|
41
49
|
return signedBlock.message.body.voluntaryExits.map((voluntaryExit) =>
|
|
42
|
-
getVoluntaryExitSignatureSet(
|
|
50
|
+
getVoluntaryExitSignatureSet(config, index2pubkey, blockSlot, voluntaryExit)
|
|
43
51
|
);
|
|
44
52
|
}
|
package/src/stateTransition.ts
CHANGED
|
@@ -111,7 +111,7 @@ export function stateTransition(
|
|
|
111
111
|
postState = processSlotsWithTransientCache(postState, blockSlot, options, {metrics, validatorMonitor});
|
|
112
112
|
|
|
113
113
|
// Verify proposer signature only
|
|
114
|
-
if (verifyProposer && !verifyProposerSignature(postState, signedBlock)) {
|
|
114
|
+
if (verifyProposer && !verifyProposerSignature(postState.config, postState.epochCtx.index2pubkey, signedBlock)) {
|
|
115
115
|
throw new Error("Invalid block signature");
|
|
116
116
|
}
|
|
117
117
|
|
package/src/util/execution.ts
CHANGED
|
@@ -31,51 +31,30 @@ export function isExecutionEnabled(state: BeaconStateExecutions, block: BeaconBl
|
|
|
31
31
|
return true;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
// Throws if not post-bellatrix block. A fork-guard
|
|
34
|
+
// Throws if not post-bellatrix block. A fork-guard before isExecutionEnabled() prevents this from happening
|
|
35
35
|
const payload = getFullOrBlindedPayload(block);
|
|
36
|
-
// Note: spec says to check all payload is zero-ed. However a state-root cannot be zero for any non-empty payload
|
|
37
|
-
// TODO: Consider comparing with the payload root if this assumption is not correct.
|
|
38
|
-
// return !byteArrayEquals(payload.stateRoot, ZERO_HASH);
|
|
39
36
|
|
|
40
|
-
// UPDATE: stateRoot comparision should have been enough with zero hash, but spec tests were failing
|
|
41
|
-
// Revisit this later to fix specs and make this efficient
|
|
42
37
|
return isExecutionPayload(payload)
|
|
43
38
|
? !ssz.bellatrix.ExecutionPayload.equals(payload, ssz.bellatrix.ExecutionPayload.defaultValue())
|
|
44
39
|
: !ssz.bellatrix.ExecutionPayloadHeader.equals(
|
|
45
40
|
state.latestExecutionPayloadHeader,
|
|
46
|
-
// TODO: Performance
|
|
47
41
|
ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
|
|
48
42
|
);
|
|
49
43
|
}
|
|
50
44
|
|
|
51
|
-
/**
|
|
52
|
-
* Merge block is the SINGLE block that transitions from POW to POS.
|
|
53
|
-
* state has no execution data AND this block has execution data
|
|
54
|
-
*/
|
|
55
|
-
export function isMergeTransitionBlock(state: BeaconStateExecutions, body: bellatrix.BeaconBlockBody): boolean {
|
|
56
|
-
return (
|
|
57
|
-
!isMergeTransitionComplete(state) &&
|
|
58
|
-
!ssz.bellatrix.ExecutionPayload.equals(body.executionPayload, ssz.bellatrix.ExecutionPayload.defaultValue())
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
45
|
/**
|
|
63
46
|
* Merge is complete when the state includes execution layer data:
|
|
64
|
-
* state.latestExecutionPayloadHeader NOT EMPTY
|
|
47
|
+
* state.latestExecutionPayloadHeader NOT EMPTY or state is post-capella
|
|
65
48
|
*/
|
|
66
49
|
export function isMergeTransitionComplete(state: BeaconStateExecutions): boolean {
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// TODO: Performance
|
|
71
|
-
ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
|
|
72
|
-
);
|
|
50
|
+
if (isCapellaStateType(state)) {
|
|
51
|
+
// All networks have completed the merge transition before capella
|
|
52
|
+
return true;
|
|
73
53
|
}
|
|
74
54
|
|
|
75
|
-
return !ssz.
|
|
76
|
-
state.latestExecutionPayloadHeader,
|
|
77
|
-
|
|
78
|
-
ssz.capella.ExecutionPayloadHeader.defaultValue()
|
|
55
|
+
return !ssz.bellatrix.ExecutionPayloadHeader.equals(
|
|
56
|
+
(state as BeaconStateBellatrix).latestExecutionPayloadHeader,
|
|
57
|
+
ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
|
|
79
58
|
);
|
|
80
59
|
}
|
|
81
60
|
|