@lodestar/state-transition 1.39.0-dev.b37f2bd1bd → 1.39.0-dev.b6d377a93c
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 +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/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/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/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
|
@@ -1,15 +1,16 @@
|
|
|
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 {SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
|
|
3
4
|
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
4
|
-
import {CachedBeaconStateAllForks} from "../types.js";
|
|
5
5
|
import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Extract signatures to allow validating all block signatures at once
|
|
9
9
|
*/
|
|
10
10
|
export function getProposerSlashingSignatureSets(
|
|
11
|
+
config: BeaconConfig,
|
|
11
12
|
index2pubkey: Index2PubkeyCache,
|
|
12
|
-
|
|
13
|
+
stateSlot: Slot,
|
|
13
14
|
proposerSlashing: phase0.ProposerSlashing
|
|
14
15
|
): ISignatureSet[] {
|
|
15
16
|
const pubkey = index2pubkey[proposerSlashing.signedHeader1.message.proposerIndex];
|
|
@@ -17,11 +18,7 @@ export function getProposerSlashingSignatureSets(
|
|
|
17
18
|
// In state transition, ProposerSlashing headers are only partially validated. Their slot could be higher than the
|
|
18
19
|
// clock and the slashing would still be valid. Must use bigint variants to hash correctly to all possible values
|
|
19
20
|
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
|
-
);
|
|
21
|
+
const domain = config.getDomain(stateSlot, DOMAIN_BEACON_PROPOSER, Number(signedHeader.message.slot as bigint));
|
|
25
22
|
|
|
26
23
|
return {
|
|
27
24
|
type: SignatureSetType.single,
|
|
@@ -33,11 +30,14 @@ export function getProposerSlashingSignatureSets(
|
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
export function getProposerSlashingsSignatureSets(
|
|
33
|
+
config: BeaconConfig,
|
|
36
34
|
index2pubkey: Index2PubkeyCache,
|
|
37
|
-
state: CachedBeaconStateAllForks,
|
|
38
35
|
signedBlock: SignedBeaconBlock
|
|
39
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;
|
|
40
40
|
return signedBlock.message.body.proposerSlashings.flatMap((proposerSlashing) =>
|
|
41
|
-
getProposerSlashingSignatureSets(index2pubkey,
|
|
41
|
+
getProposerSlashingSignatureSets(config, index2pubkey, blockSlot, proposerSlashing)
|
|
42
42
|
);
|
|
43
43
|
}
|
|
@@ -1,7 +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
4
|
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
4
|
-
import {CachedBeaconStateAllForks} from "../types.js";
|
|
5
5
|
import {
|
|
6
6
|
ISignatureSet,
|
|
7
7
|
SignatureSetType,
|
|
@@ -11,24 +11,26 @@ import {
|
|
|
11
11
|
} from "../util/index.js";
|
|
12
12
|
|
|
13
13
|
export function verifyRandaoSignature(
|
|
14
|
+
config: BeaconConfig,
|
|
14
15
|
index2pubkey: Index2PubkeyCache,
|
|
15
|
-
state: CachedBeaconStateAllForks,
|
|
16
16
|
block: BeaconBlock
|
|
17
17
|
): boolean {
|
|
18
|
-
return verifySignatureSet(getRandaoRevealSignatureSet(
|
|
18
|
+
return verifySignatureSet(getRandaoRevealSignatureSet(config, index2pubkey, block));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Extract signatures to allow validating all block signatures at once
|
|
23
23
|
*/
|
|
24
24
|
export function getRandaoRevealSignatureSet(
|
|
25
|
+
config: BeaconConfig,
|
|
25
26
|
index2pubkey: Index2PubkeyCache,
|
|
26
|
-
state: CachedBeaconStateAllForks,
|
|
27
27
|
block: BeaconBlock
|
|
28
28
|
): ISignatureSet {
|
|
29
29
|
// should not get epoch from epochCtx
|
|
30
30
|
const epoch = computeEpochAtSlot(block.slot);
|
|
31
|
-
|
|
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);
|
|
32
34
|
|
|
33
35
|
return {
|
|
34
36
|
type: SignatureSetType.single,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
2
|
+
import {SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
|
|
2
3
|
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
3
|
-
import {CachedBeaconStateAllForks} from "../types.js";
|
|
4
4
|
import {
|
|
5
5
|
ISignatureSet,
|
|
6
6
|
SignatureSetType,
|
|
@@ -10,23 +10,25 @@ import {
|
|
|
10
10
|
} from "../util/index.js";
|
|
11
11
|
|
|
12
12
|
export function verifyVoluntaryExitSignature(
|
|
13
|
+
config: BeaconConfig,
|
|
13
14
|
index2pubkey: Index2PubkeyCache,
|
|
14
|
-
|
|
15
|
+
stateSlot: Slot,
|
|
15
16
|
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
16
17
|
): boolean {
|
|
17
|
-
return verifySignatureSet(getVoluntaryExitSignatureSet(index2pubkey,
|
|
18
|
+
return verifySignatureSet(getVoluntaryExitSignatureSet(config, index2pubkey, stateSlot, signedVoluntaryExit));
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Extract signatures to allow validating all block signatures at once
|
|
22
23
|
*/
|
|
23
24
|
export function getVoluntaryExitSignatureSet(
|
|
25
|
+
config: BeaconConfig,
|
|
24
26
|
index2pubkey: Index2PubkeyCache,
|
|
25
|
-
|
|
27
|
+
stateSlot: Slot,
|
|
26
28
|
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
27
29
|
): ISignatureSet {
|
|
28
|
-
const
|
|
29
|
-
const domain =
|
|
30
|
+
const messageSlot = computeStartSlotAtEpoch(signedVoluntaryExit.message.epoch);
|
|
31
|
+
const domain = config.getDomainForVoluntaryExit(stateSlot, messageSlot);
|
|
30
32
|
|
|
31
33
|
return {
|
|
32
34
|
type: SignatureSetType.single,
|
|
@@ -37,11 +39,14 @@ export function getVoluntaryExitSignatureSet(
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
export function getVoluntaryExitsSignatureSets(
|
|
42
|
+
config: BeaconConfig,
|
|
40
43
|
index2pubkey: Index2PubkeyCache,
|
|
41
|
-
state: CachedBeaconStateAllForks,
|
|
42
44
|
signedBlock: SignedBeaconBlock
|
|
43
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;
|
|
44
49
|
return signedBlock.message.body.voluntaryExits.map((voluntaryExit) =>
|
|
45
|
-
getVoluntaryExitSignatureSet(index2pubkey,
|
|
50
|
+
getVoluntaryExitSignatureSet(config, index2pubkey, blockSlot, voluntaryExit)
|
|
46
51
|
);
|
|
47
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.epochCtx.index2pubkey,
|
|
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
|
@@ -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;
|