@lodestar/state-transition 1.39.0-dev.3bf4734ba9 → 1.39.0-dev.46c9c672fd
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/processBlsToExecutionChange.d.ts +3 -1
- package/lib/block/processBlsToExecutionChange.d.ts.map +1 -1
- package/lib/block/processBlsToExecutionChange.js +7 -11
- package/lib/block/processBlsToExecutionChange.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 +2 -2
- package/lib/block/processRandao.js.map +1 -1
- package/lib/block/processSyncCommittee.d.ts +3 -1
- package/lib/block/processSyncCommittee.d.ts.map +1 -1
- package/lib/block/processSyncCommittee.js +6 -4
- 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/block/processWithdrawals.d.ts +3 -3
- package/lib/block/processWithdrawals.d.ts.map +1 -1
- package/lib/block/processWithdrawals.js +152 -105
- package/lib/block/processWithdrawals.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 +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/rewards/attestationsRewards.d.ts +6 -0
- package/lib/rewards/attestationsRewards.d.ts.map +1 -0
- package/lib/rewards/attestationsRewards.js +113 -0
- package/lib/rewards/attestationsRewards.js.map +1 -0
- package/lib/rewards/blockRewards.d.ts +13 -0
- package/lib/rewards/blockRewards.d.ts.map +1 -0
- package/lib/rewards/blockRewards.js +95 -0
- package/lib/rewards/blockRewards.js.map +1 -0
- package/lib/rewards/index.d.ts +4 -0
- package/lib/rewards/index.d.ts.map +1 -0
- package/lib/rewards/index.js +4 -0
- package/lib/rewards/index.js.map +1 -0
- package/lib/rewards/syncCommitteeRewards.d.ts +6 -0
- package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -0
- package/lib/rewards/syncCommitteeRewards.js +36 -0
- package/lib/rewards/syncCommitteeRewards.js.map +1 -0
- package/lib/signatureSets/attesterSlashings.d.ts +5 -5
- package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
- package/lib/signatureSets/attesterSlashings.js +10 -7
- package/lib/signatureSets/attesterSlashings.js.map +1 -1
- package/lib/signatureSets/blsToExecutionChange.d.ts +1 -2
- package/lib/signatureSets/blsToExecutionChange.d.ts.map +1 -1
- package/lib/signatureSets/blsToExecutionChange.js +2 -2
- package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
- package/lib/signatureSets/index.d.ts +3 -2
- 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 +6 -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 -6
- package/lib/signatureSets/proposer.d.ts.map +1 -1
- package/lib/signatureSets/proposer.js +12 -11
- package/lib/signatureSets/proposer.js.map +1 -1
- package/lib/signatureSets/proposerSlashings.d.ts +4 -4
- package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
- package/lib/signatureSets/proposerSlashings.js +7 -4
- package/lib/signatureSets/proposerSlashings.js.map +1 -1
- package/lib/signatureSets/randao.d.ts +3 -3
- package/lib/signatureSets/randao.d.ts.map +1 -1
- package/lib/signatureSets/randao.js +6 -4
- package/lib/signatureSets/randao.js.map +1 -1
- package/lib/signatureSets/voluntaryExits.d.ts +5 -5
- package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
- package/lib/signatureSets/voluntaryExits.js +10 -7
- 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 +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 +14 -11
- package/src/block/index.ts +6 -2
- package/src/block/isValidIndexedAttestation.ts +7 -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/processBlsToExecutionChange.ts +13 -14
- package/src/block/processExecutionPayload.ts +14 -8
- package/src/block/processProposerSlashing.ts +6 -1
- package/src/block/processRandao.ts +2 -2
- package/src/block/processSyncCommittee.ts +15 -4
- package/src/block/processVoluntaryExit.ts +4 -1
- package/src/block/processWithdrawals.ts +230 -135
- package/src/cache/epochCache.ts +0 -3
- package/src/cache/stateCache.ts +1 -0
- package/src/index.ts +2 -2
- package/src/rewards/attestationsRewards.ts +200 -0
- package/src/rewards/blockRewards.ts +147 -0
- package/src/rewards/index.ts +3 -0
- package/src/rewards/syncCommitteeRewards.ts +59 -0
- package/src/signatureSets/attesterSlashings.ts +14 -9
- package/src/signatureSets/blsToExecutionChange.ts +2 -3
- package/src/signatureSets/index.ts +14 -11
- package/src/signatureSets/indexedAttestation.ts +18 -11
- package/src/signatureSets/proposer.ts +14 -12
- package/src/signatureSets/proposerSlashings.ts +10 -10
- package/src/signatureSets/randao.ts +7 -5
- package/src/signatureSets/voluntaryExits.ts +14 -9
- package/src/stateTransition.ts +1 -1
- package/src/util/execution.ts +39 -0
|
@@ -55,7 +55,7 @@ export function assertValidAttesterSlashing(
|
|
|
55
55
|
// be higher than the clock and the slashing would still be valid. Same applies to attestation data index, which
|
|
56
56
|
// can be any arbitrary value. Must use bigint variants to hash correctly to all possible values
|
|
57
57
|
for (const [i, attestation] of [attestation1, attestation2].entries()) {
|
|
58
|
-
if (!isValidIndexedAttestationBigint(index2pubkey, state, attestation, verifySignatures)) {
|
|
58
|
+
if (!isValidIndexedAttestationBigint(state.config, index2pubkey, state, attestation, verifySignatures)) {
|
|
59
59
|
throw new Error(`AttesterSlashing attestation${i} is invalid`);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {digest} from "@chainsafe/as-sha256";
|
|
2
2
|
import {byteArrayEquals} from "@chainsafe/ssz";
|
|
3
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
3
4
|
import {BLS_WITHDRAWAL_PREFIX, ETH1_ADDRESS_WITHDRAWAL_PREFIX} from "@lodestar/params";
|
|
4
5
|
import {capella} from "@lodestar/types";
|
|
6
|
+
import {Validator} from "@lodestar/types/phase0";
|
|
5
7
|
import {toHex} from "@lodestar/utils";
|
|
6
8
|
import {verifyBlsToExecutionChangeSignature} from "../signatureSets/index.js";
|
|
7
9
|
import {CachedBeaconStateCapella} from "../types.js";
|
|
@@ -12,12 +14,18 @@ export function processBlsToExecutionChange(
|
|
|
12
14
|
): void {
|
|
13
15
|
const addressChange = signedBlsToExecutionChange.message;
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
if (addressChange.validatorIndex >= state.validators.length) {
|
|
18
|
+
throw Error(
|
|
19
|
+
`withdrawalValidatorIndex ${addressChange.validatorIndex} >= state.validators len ${state.validators.length}`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const validator = state.validators.get(addressChange.validatorIndex);
|
|
24
|
+
const validation = isValidBlsToExecutionChange(state.config, validator, signedBlsToExecutionChange, true);
|
|
16
25
|
if (!validation.valid) {
|
|
17
26
|
throw validation.error;
|
|
18
27
|
}
|
|
19
28
|
|
|
20
|
-
const validator = state.validators.get(addressChange.validatorIndex);
|
|
21
29
|
const newWithdrawalCredentials = new Uint8Array(32);
|
|
22
30
|
newWithdrawalCredentials[0] = ETH1_ADDRESS_WITHDRAWAL_PREFIX;
|
|
23
31
|
newWithdrawalCredentials.set(addressChange.toExecutionAddress, 12);
|
|
@@ -27,22 +35,13 @@ export function processBlsToExecutionChange(
|
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
export function isValidBlsToExecutionChange(
|
|
30
|
-
|
|
38
|
+
config: BeaconConfig,
|
|
39
|
+
validator: Validator,
|
|
31
40
|
signedBLSToExecutionChange: capella.SignedBLSToExecutionChange,
|
|
32
41
|
verifySignature = true
|
|
33
42
|
): {valid: true} | {valid: false; error: Error} {
|
|
34
43
|
const addressChange = signedBLSToExecutionChange.message;
|
|
35
44
|
|
|
36
|
-
if (addressChange.validatorIndex >= state.validators.length) {
|
|
37
|
-
return {
|
|
38
|
-
valid: false,
|
|
39
|
-
error: Error(
|
|
40
|
-
`withdrawalValidatorIndex ${addressChange.validatorIndex} > state.validators len ${state.validators.length}`
|
|
41
|
-
),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const validator = state.validators.getReadonly(addressChange.validatorIndex);
|
|
46
45
|
const {withdrawalCredentials} = validator;
|
|
47
46
|
if (withdrawalCredentials[0] !== BLS_WITHDRAWAL_PREFIX) {
|
|
48
47
|
return {
|
|
@@ -65,7 +64,7 @@ export function isValidBlsToExecutionChange(
|
|
|
65
64
|
};
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
if (verifySignature && !verifyBlsToExecutionChangeSignature(
|
|
67
|
+
if (verifySignature && !verifyBlsToExecutionChangeSignature(config, signedBLSToExecutionChange)) {
|
|
69
68
|
return {
|
|
70
69
|
valid: false,
|
|
71
70
|
error: Error(
|
|
@@ -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.slot,
|
|
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`);
|
|
@@ -12,12 +12,12 @@ import {getRandaoMix} from "../util/index.js";
|
|
|
12
12
|
* PERF: Fixed work independent of block contents.
|
|
13
13
|
*/
|
|
14
14
|
export function processRandao(state: CachedBeaconStateAllForks, block: BeaconBlock, verifySignature = true): void {
|
|
15
|
-
const {epochCtx} = state;
|
|
15
|
+
const {epochCtx, config} = state;
|
|
16
16
|
const epoch = epochCtx.epoch;
|
|
17
17
|
const randaoReveal = block.body.randaoReveal;
|
|
18
18
|
|
|
19
19
|
// verify RANDAO reveal
|
|
20
|
-
if (verifySignature && !verifyRandaoSignature(epochCtx.index2pubkey,
|
|
20
|
+
if (verifySignature && !verifyRandaoSignature(config, epochCtx.index2pubkey, block)) {
|
|
21
21
|
throw new Error("RANDAO reveal is an invalid signature");
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -1,7 +1,9 @@
|
|
|
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";
|
|
6
|
+
import {SyncCommitteeCache} from "../cache/syncCommitteeCache.js";
|
|
5
7
|
import {G2_POINT_AT_INFINITY} from "../constants/index.js";
|
|
6
8
|
import {CachedBeaconStateAllForks} from "../types.js";
|
|
7
9
|
import {
|
|
@@ -24,7 +26,13 @@ export function processSyncAggregate(
|
|
|
24
26
|
if (verifySignatures) {
|
|
25
27
|
// This is to conform to the spec - we want the signature to be verified
|
|
26
28
|
const participantIndices = block.body.syncAggregate.syncCommitteeBits.intersectValues(committeeIndices);
|
|
27
|
-
const signatureSet = getSyncCommitteeSignatureSet(
|
|
29
|
+
const signatureSet = getSyncCommitteeSignatureSet(
|
|
30
|
+
state.config,
|
|
31
|
+
state.epochCtx.index2pubkey,
|
|
32
|
+
state.epochCtx.currentSyncCommitteeIndexed,
|
|
33
|
+
block,
|
|
34
|
+
participantIndices
|
|
35
|
+
);
|
|
28
36
|
// When there's no participation we consider the signature valid and just ignore i
|
|
29
37
|
if (signatureSet !== null && !verifySignatureSet(signatureSet)) {
|
|
30
38
|
throw Error("Sync committee signature invalid");
|
|
@@ -64,8 +72,9 @@ export function processSyncAggregate(
|
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
export function getSyncCommitteeSignatureSet(
|
|
75
|
+
config: BeaconConfig,
|
|
67
76
|
index2pubkey: Index2PubkeyCache,
|
|
68
|
-
|
|
77
|
+
currentSyncCommitteeIndexed: SyncCommitteeCache,
|
|
69
78
|
block: altair.BeaconBlock,
|
|
70
79
|
/** Optional parameter to prevent computing it twice */
|
|
71
80
|
participantIndices?: number[]
|
|
@@ -93,7 +102,7 @@ export function getSyncCommitteeSignatureSet(
|
|
|
93
102
|
const rootSigned = block.parentRoot;
|
|
94
103
|
|
|
95
104
|
if (!participantIndices) {
|
|
96
|
-
const committeeIndices =
|
|
105
|
+
const committeeIndices = currentSyncCommitteeIndexed.validatorIndices;
|
|
97
106
|
participantIndices = syncAggregate.syncCommitteeBits.intersectValues(committeeIndices);
|
|
98
107
|
}
|
|
99
108
|
|
|
@@ -107,7 +116,9 @@ export function getSyncCommitteeSignatureSet(
|
|
|
107
116
|
throw Error("Empty sync committee signature is not infinity");
|
|
108
117
|
}
|
|
109
118
|
|
|
110
|
-
|
|
119
|
+
// the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
|
|
120
|
+
// and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
|
|
121
|
+
const domain = config.getDomain(block.slot, DOMAIN_SYNC_COMMITTEE, previousSlot);
|
|
111
122
|
|
|
112
123
|
return {
|
|
113
124
|
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.slot, signedVoluntaryExit)
|
|
80
|
+
) {
|
|
78
81
|
return VoluntaryExitValidity.invalidSignature;
|
|
79
82
|
}
|
|
80
83
|
|