@lodestar/state-transition 1.38.0 → 1.39.0-dev.100ab480bb
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 +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 +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 +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 +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
package/lib/util/execution.js
CHANGED
|
@@ -8,40 +8,22 @@ export function isExecutionEnabled(state, block) {
|
|
|
8
8
|
if (isMergeTransitionComplete(state)) {
|
|
9
9
|
return true;
|
|
10
10
|
}
|
|
11
|
-
// Throws if not post-bellatrix block. A fork-guard
|
|
11
|
+
// Throws if not post-bellatrix block. A fork-guard before isExecutionEnabled() prevents this from happening
|
|
12
12
|
const payload = getFullOrBlindedPayload(block);
|
|
13
|
-
// Note: spec says to check all payload is zero-ed. However a state-root cannot be zero for any non-empty payload
|
|
14
|
-
// TODO: Consider comparing with the payload root if this assumption is not correct.
|
|
15
|
-
// return !byteArrayEquals(payload.stateRoot, ZERO_HASH);
|
|
16
|
-
// UPDATE: stateRoot comparision should have been enough with zero hash, but spec tests were failing
|
|
17
|
-
// Revisit this later to fix specs and make this efficient
|
|
18
13
|
return isExecutionPayload(payload)
|
|
19
14
|
? !ssz.bellatrix.ExecutionPayload.equals(payload, ssz.bellatrix.ExecutionPayload.defaultValue())
|
|
20
|
-
: !ssz.bellatrix.ExecutionPayloadHeader.equals(state.latestExecutionPayloadHeader,
|
|
21
|
-
// TODO: Performance
|
|
22
|
-
ssz.bellatrix.ExecutionPayloadHeader.defaultValue());
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Merge block is the SINGLE block that transitions from POW to POS.
|
|
26
|
-
* state has no execution data AND this block has execution data
|
|
27
|
-
*/
|
|
28
|
-
export function isMergeTransitionBlock(state, body) {
|
|
29
|
-
return (!isMergeTransitionComplete(state) &&
|
|
30
|
-
!ssz.bellatrix.ExecutionPayload.equals(body.executionPayload, ssz.bellatrix.ExecutionPayload.defaultValue()));
|
|
15
|
+
: !ssz.bellatrix.ExecutionPayloadHeader.equals(state.latestExecutionPayloadHeader, ssz.bellatrix.ExecutionPayloadHeader.defaultValue());
|
|
31
16
|
}
|
|
32
17
|
/**
|
|
33
18
|
* Merge is complete when the state includes execution layer data:
|
|
34
|
-
* state.latestExecutionPayloadHeader NOT EMPTY
|
|
19
|
+
* state.latestExecutionPayloadHeader NOT EMPTY or state is post-capella
|
|
35
20
|
*/
|
|
36
21
|
export function isMergeTransitionComplete(state) {
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
ssz.bellatrix.ExecutionPayloadHeader.defaultValue());
|
|
22
|
+
if (isCapellaStateType(state)) {
|
|
23
|
+
// All networks have completed the merge transition before capella
|
|
24
|
+
return true;
|
|
41
25
|
}
|
|
42
|
-
return !ssz.
|
|
43
|
-
// TODO: Performance
|
|
44
|
-
ssz.capella.ExecutionPayloadHeader.defaultValue());
|
|
26
|
+
return !ssz.bellatrix.ExecutionPayloadHeader.equals(state.latestExecutionPayloadHeader, ssz.bellatrix.ExecutionPayloadHeader.defaultValue());
|
|
45
27
|
}
|
|
46
28
|
/** Type guard for bellatrix.BeaconState */
|
|
47
29
|
export function isExecutionStateType(state) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../../src/util/execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACpF,OAAO,EAUL,wBAAwB,EACxB,kBAAkB,EAClB,GAAG,GACJ,MAAM,iBAAiB,CAAC;AAUzB;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAA4B,EAAE,KAAuC;IACtG,IAAI,yBAAyB,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,
|
|
1
|
+
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../../src/util/execution.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ChainSafe/lodestar/issues"
|
|
13
13
|
},
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.39.0-dev.100ab480bb",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -62,10 +62,10 @@
|
|
|
62
62
|
"@chainsafe/pubkey-index-map": "^3.0.0",
|
|
63
63
|
"@chainsafe/ssz": "^1.2.2",
|
|
64
64
|
"@chainsafe/swap-or-not-shuffle": "^1.2.1",
|
|
65
|
-
"@lodestar/config": "
|
|
66
|
-
"@lodestar/params": "
|
|
67
|
-
"@lodestar/types": "
|
|
68
|
-
"@lodestar/utils": "
|
|
65
|
+
"@lodestar/config": "1.39.0-dev.100ab480bb",
|
|
66
|
+
"@lodestar/params": "1.39.0-dev.100ab480bb",
|
|
67
|
+
"@lodestar/types": "1.39.0-dev.100ab480bb",
|
|
68
|
+
"@lodestar/utils": "1.39.0-dev.100ab480bb",
|
|
69
69
|
"bigint-buffer": "^1.1.5"
|
|
70
70
|
},
|
|
71
71
|
"keywords": [
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"beacon",
|
|
75
75
|
"blockchain"
|
|
76
76
|
],
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "965887079f9e859a8e118d8799fc814f98e65228"
|
|
78
78
|
}
|
package/src/block/index.ts
CHANGED
|
@@ -68,8 +68,8 @@ export function processBlock(
|
|
|
68
68
|
// on the randao_mix computed with the reveal of the previous block.
|
|
69
69
|
// TODO GLOAS: We call processExecutionPayload somewhere else post-gloas
|
|
70
70
|
if (
|
|
71
|
-
fork >= ForkSeq.bellatrix &&
|
|
72
71
|
fork < ForkSeq.gloas &&
|
|
72
|
+
fork >= ForkSeq.bellatrix &&
|
|
73
73
|
isExecutionEnabled(state as CachedBeaconStateBellatrix, block)
|
|
74
74
|
) {
|
|
75
75
|
processExecutionPayload(fork, state as CachedBeaconStateBellatrix, block.body, externalData);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {ForkSeq, MAX_COMMITTEES_PER_SLOT, MAX_VALIDATORS_PER_COMMITTEE} from "@lodestar/params";
|
|
2
3
|
import {IndexedAttestation, IndexedAttestationBigint} from "@lodestar/types";
|
|
4
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
3
5
|
import {getIndexedAttestationBigintSignatureSet, getIndexedAttestationSignatureSet} from "../signatureSets/index.js";
|
|
4
6
|
import {CachedBeaconStateAllForks} from "../types.js";
|
|
5
7
|
import {verifySignatureSet} from "../util/index.js";
|
|
@@ -8,6 +10,8 @@ import {verifySignatureSet} from "../util/index.js";
|
|
|
8
10
|
* Check if `indexedAttestation` has sorted and unique indices and a valid aggregate signature.
|
|
9
11
|
*/
|
|
10
12
|
export function isValidIndexedAttestation(
|
|
13
|
+
config: BeaconConfig,
|
|
14
|
+
index2pubkey: Index2PubkeyCache,
|
|
11
15
|
state: CachedBeaconStateAllForks,
|
|
12
16
|
indexedAttestation: IndexedAttestation,
|
|
13
17
|
verifySignature: boolean
|
|
@@ -17,12 +21,14 @@ export function isValidIndexedAttestation(
|
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
if (verifySignature) {
|
|
20
|
-
return verifySignatureSet(getIndexedAttestationSignatureSet(state, indexedAttestation));
|
|
24
|
+
return verifySignatureSet(getIndexedAttestationSignatureSet(config, index2pubkey, state.slot, indexedAttestation));
|
|
21
25
|
}
|
|
22
26
|
return true;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
export function isValidIndexedAttestationBigint(
|
|
30
|
+
config: BeaconConfig,
|
|
31
|
+
index2pubkey: Index2PubkeyCache,
|
|
26
32
|
state: CachedBeaconStateAllForks,
|
|
27
33
|
indexedAttestation: IndexedAttestationBigint,
|
|
28
34
|
verifySignature: boolean
|
|
@@ -32,7 +38,9 @@ export function isValidIndexedAttestationBigint(
|
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
if (verifySignature) {
|
|
35
|
-
return verifySignatureSet(
|
|
41
|
+
return verifySignatureSet(
|
|
42
|
+
getIndexedAttestationBigintSignatureSet(config, index2pubkey, state.slot, indexedAttestation)
|
|
43
|
+
);
|
|
36
44
|
}
|
|
37
45
|
return true;
|
|
38
46
|
}
|
|
@@ -50,7 +50,15 @@ export function processAttestationPhase0(
|
|
|
50
50
|
state.previousEpochAttestations.push(pendingAttestation);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
if (
|
|
53
|
+
if (
|
|
54
|
+
!isValidIndexedAttestation(
|
|
55
|
+
state.config,
|
|
56
|
+
epochCtx.index2pubkey,
|
|
57
|
+
state,
|
|
58
|
+
epochCtx.getIndexedAttestation(ForkSeq.phase0, attestation),
|
|
59
|
+
verifySignature
|
|
60
|
+
)
|
|
61
|
+
) {
|
|
54
62
|
throw new Error("Attestation is not valid");
|
|
55
63
|
}
|
|
56
64
|
}
|
|
@@ -64,7 +64,13 @@ export function processAttestationsAltair(
|
|
|
64
64
|
// TODO: Why should we verify an indexed attestation that we just created? If it's just for the signature
|
|
65
65
|
// we can verify only that and nothing else.
|
|
66
66
|
if (verifySignature) {
|
|
67
|
-
const sigSet = getAttestationWithIndicesSignatureSet(
|
|
67
|
+
const sigSet = getAttestationWithIndicesSignatureSet(
|
|
68
|
+
state.config,
|
|
69
|
+
epochCtx.index2pubkey,
|
|
70
|
+
state.slot,
|
|
71
|
+
attestation,
|
|
72
|
+
attestingIndices
|
|
73
|
+
);
|
|
68
74
|
if (!verifySignatureSet(sigSet)) {
|
|
69
75
|
throw new Error("Attestation signature is not valid");
|
|
70
76
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {ForkSeq} from "@lodestar/params";
|
|
2
2
|
import {AttesterSlashing} from "@lodestar/types";
|
|
3
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
3
4
|
import {CachedBeaconStateAllForks} from "../types.js";
|
|
4
5
|
import {getAttesterSlashableIndices, isSlashableAttestationData, isSlashableValidator} from "../util/index.js";
|
|
5
6
|
import {isValidIndexedAttestationBigint} from "./isValidIndexedAttestation.js";
|
|
@@ -17,7 +18,8 @@ export function processAttesterSlashing(
|
|
|
17
18
|
attesterSlashing: AttesterSlashing,
|
|
18
19
|
verifySignatures = true
|
|
19
20
|
): void {
|
|
20
|
-
|
|
21
|
+
const {epochCtx} = state;
|
|
22
|
+
assertValidAttesterSlashing(epochCtx.index2pubkey, state, attesterSlashing, verifySignatures);
|
|
21
23
|
|
|
22
24
|
const intersectingIndices = getAttesterSlashableIndices(attesterSlashing);
|
|
23
25
|
|
|
@@ -25,7 +27,7 @@ export function processAttesterSlashing(
|
|
|
25
27
|
const validators = state.validators; // Get the validators sub tree once for all indices
|
|
26
28
|
// Spec requires to sort indexes beforehand
|
|
27
29
|
for (const index of intersectingIndices.sort((a, b) => a - b)) {
|
|
28
|
-
if (isSlashableValidator(validators.getReadonly(index),
|
|
30
|
+
if (isSlashableValidator(validators.getReadonly(index), epochCtx.epoch)) {
|
|
29
31
|
slashValidator(fork, state, index);
|
|
30
32
|
slashedAny = true;
|
|
31
33
|
}
|
|
@@ -37,6 +39,7 @@ export function processAttesterSlashing(
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
export function assertValidAttesterSlashing(
|
|
42
|
+
index2pubkey: Index2PubkeyCache,
|
|
40
43
|
state: CachedBeaconStateAllForks,
|
|
41
44
|
attesterSlashing: AttesterSlashing,
|
|
42
45
|
verifySignatures = true
|
|
@@ -52,7 +55,7 @@ export function assertValidAttesterSlashing(
|
|
|
52
55
|
// be higher than the clock and the slashing would still be valid. Same applies to attestation data index, which
|
|
53
56
|
// can be any arbitrary value. Must use bigint variants to hash correctly to all possible values
|
|
54
57
|
for (const [i, attestation] of [attestation1, attestation2].entries()) {
|
|
55
|
-
if (!isValidIndexedAttestationBigint(state, attestation, verifySignatures)) {
|
|
58
|
+
if (!isValidIndexedAttestationBigint(state.config, index2pubkey, state, attestation, verifySignatures)) {
|
|
56
59
|
throw new Error(`AttesterSlashing attestation${i} is invalid`);
|
|
57
60
|
}
|
|
58
61
|
}
|
|
@@ -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(
|
|
20
|
+
if (verifySignature && !verifyRandaoSignature(config, epochCtx.index2pubkey, block)) {
|
|
21
21
|
throw new Error("RANDAO reveal is an invalid signature");
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -1,6 +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";
|
|
5
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
6
|
+
import {SyncCommitteeCache} from "../cache/syncCommitteeCache.js";
|
|
4
7
|
import {G2_POINT_AT_INFINITY} from "../constants/index.js";
|
|
5
8
|
import {CachedBeaconStateAllForks} from "../types.js";
|
|
6
9
|
import {
|
|
@@ -23,7 +26,13 @@ export function processSyncAggregate(
|
|
|
23
26
|
if (verifySignatures) {
|
|
24
27
|
// This is to conform to the spec - we want the signature to be verified
|
|
25
28
|
const participantIndices = block.body.syncAggregate.syncCommitteeBits.intersectValues(committeeIndices);
|
|
26
|
-
const signatureSet = getSyncCommitteeSignatureSet(
|
|
29
|
+
const signatureSet = getSyncCommitteeSignatureSet(
|
|
30
|
+
state.config,
|
|
31
|
+
state.epochCtx.index2pubkey,
|
|
32
|
+
state.epochCtx.currentSyncCommitteeIndexed,
|
|
33
|
+
block,
|
|
34
|
+
participantIndices
|
|
35
|
+
);
|
|
27
36
|
// When there's no participation we consider the signature valid and just ignore i
|
|
28
37
|
if (signatureSet !== null && !verifySignatureSet(signatureSet)) {
|
|
29
38
|
throw Error("Sync committee signature invalid");
|
|
@@ -63,12 +72,13 @@ export function processSyncAggregate(
|
|
|
63
72
|
}
|
|
64
73
|
|
|
65
74
|
export function getSyncCommitteeSignatureSet(
|
|
66
|
-
|
|
75
|
+
config: BeaconConfig,
|
|
76
|
+
index2pubkey: Index2PubkeyCache,
|
|
77
|
+
currentSyncCommitteeIndexed: SyncCommitteeCache,
|
|
67
78
|
block: altair.BeaconBlock,
|
|
68
79
|
/** Optional parameter to prevent computing it twice */
|
|
69
80
|
participantIndices?: number[]
|
|
70
81
|
): ISignatureSet | null {
|
|
71
|
-
const {epochCtx} = state;
|
|
72
82
|
const {syncAggregate} = block.body;
|
|
73
83
|
const signature = syncAggregate.syncCommitteeSignature;
|
|
74
84
|
|
|
@@ -92,7 +102,7 @@ export function getSyncCommitteeSignatureSet(
|
|
|
92
102
|
const rootSigned = block.parentRoot;
|
|
93
103
|
|
|
94
104
|
if (!participantIndices) {
|
|
95
|
-
const committeeIndices =
|
|
105
|
+
const committeeIndices = currentSyncCommitteeIndexed.validatorIndices;
|
|
96
106
|
participantIndices = syncAggregate.syncCommitteeBits.intersectValues(committeeIndices);
|
|
97
107
|
}
|
|
98
108
|
|
|
@@ -106,11 +116,13 @@ export function getSyncCommitteeSignatureSet(
|
|
|
106
116
|
throw Error("Empty sync committee signature is not infinity");
|
|
107
117
|
}
|
|
108
118
|
|
|
109
|
-
|
|
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);
|
|
110
122
|
|
|
111
123
|
return {
|
|
112
124
|
type: SignatureSetType.aggregate,
|
|
113
|
-
pubkeys: participantIndices.map((i) =>
|
|
125
|
+
pubkeys: participantIndices.map((i) => index2pubkey[i]),
|
|
114
126
|
signingRoot: computeSigningRoot(ssz.Root, rootSigned, domain),
|
|
115
127
|
signature,
|
|
116
128
|
};
|
|
@@ -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
|
|
package/src/cache/epochCache.ts
CHANGED
|
@@ -108,9 +108,6 @@ export class EpochCache {
|
|
|
108
108
|
/**
|
|
109
109
|
* Unique globally shared pubkey registry. There should only exist one for the entire application.
|
|
110
110
|
*
|
|
111
|
-
* TODO: this is a hack, we need a safety mechanism in case a bad eth1 majority vote is in,
|
|
112
|
-
* or handle non finalized data differently, or use an immutable.js structure for cheap copies
|
|
113
|
-
*
|
|
114
111
|
* $VALIDATOR_COUNT x 192 char String -> Number Map
|
|
115
112
|
*/
|
|
116
113
|
pubkey2index: PubkeyIndexMap;
|
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 */
|
package/src/index.ts
CHANGED
|
@@ -27,8 +27,7 @@ export {
|
|
|
27
27
|
createEmptyEpochCacheImmutableData,
|
|
28
28
|
} from "./cache/epochCache.js";
|
|
29
29
|
export {type EpochTransitionCache, beforeProcessEpoch} from "./cache/epochTransitionCache.js";
|
|
30
|
-
|
|
31
|
-
export {type Index2PubkeyCache} from "./cache/pubkeyCache.js";
|
|
30
|
+
export {type Index2PubkeyCache, syncPubkeys} from "./cache/pubkeyCache.js";
|
|
32
31
|
// Main state caches
|
|
33
32
|
export {
|
|
34
33
|
type BeaconStateCache,
|
|
@@ -41,6 +40,7 @@ export {
|
|
|
41
40
|
export * from "./constants/index.js";
|
|
42
41
|
export type {EpochTransitionStep} from "./epoch/index.js";
|
|
43
42
|
export {type BeaconStateTransitionMetrics, getMetrics} from "./metrics.js";
|
|
43
|
+
export * from "./rewards/index.js";
|
|
44
44
|
export * from "./signatureSets/index.js";
|
|
45
45
|
export * from "./stateTransition.js";
|
|
46
46
|
export type {
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
|
|
2
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
3
|
+
import {
|
|
4
|
+
EFFECTIVE_BALANCE_INCREMENT,
|
|
5
|
+
ForkName,
|
|
6
|
+
INACTIVITY_PENALTY_QUOTIENT_ALTAIR,
|
|
7
|
+
MAX_EFFECTIVE_BALANCE,
|
|
8
|
+
MAX_EFFECTIVE_BALANCE_ELECTRA,
|
|
9
|
+
PARTICIPATION_FLAG_WEIGHTS,
|
|
10
|
+
TIMELY_HEAD_FLAG_INDEX,
|
|
11
|
+
TIMELY_SOURCE_FLAG_INDEX,
|
|
12
|
+
TIMELY_TARGET_FLAG_INDEX,
|
|
13
|
+
WEIGHT_DENOMINATOR,
|
|
14
|
+
isForkPostElectra,
|
|
15
|
+
} from "@lodestar/params";
|
|
16
|
+
import {ValidatorIndex, rewards} from "@lodestar/types";
|
|
17
|
+
import {fromHex} from "@lodestar/utils";
|
|
18
|
+
import {EpochTransitionCache, beforeProcessEpoch} from "../cache/epochTransitionCache.js";
|
|
19
|
+
import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../types.js";
|
|
20
|
+
import {
|
|
21
|
+
FLAG_ELIGIBLE_ATTESTER,
|
|
22
|
+
FLAG_PREV_HEAD_ATTESTER_UNSLASHED,
|
|
23
|
+
FLAG_PREV_SOURCE_ATTESTER_UNSLASHED,
|
|
24
|
+
FLAG_PREV_TARGET_ATTESTER_UNSLASHED,
|
|
25
|
+
hasMarkers,
|
|
26
|
+
isInInactivityLeak,
|
|
27
|
+
} from "../util/index.js";
|
|
28
|
+
|
|
29
|
+
/** Attestations penalty with respect to effective balance in Gwei */
|
|
30
|
+
type AttestationsPenalty = {target: number; source: number; effectiveBalance: number};
|
|
31
|
+
|
|
32
|
+
const defaultAttestationsReward = {head: 0, target: 0, source: 0, inclusionDelay: 0, inactivity: 0};
|
|
33
|
+
const defaultAttestationsPenalty = {target: 0, source: 0};
|
|
34
|
+
|
|
35
|
+
export async function computeAttestationsRewards(
|
|
36
|
+
config: BeaconConfig,
|
|
37
|
+
pubkey2index: PubkeyIndexMap,
|
|
38
|
+
state: CachedBeaconStateAllForks,
|
|
39
|
+
validatorIds?: (ValidatorIndex | string)[]
|
|
40
|
+
): Promise<rewards.AttestationsRewards> {
|
|
41
|
+
const fork = config.getForkName(state.slot);
|
|
42
|
+
if (fork === ForkName.phase0) {
|
|
43
|
+
throw Error("Unsupported fork. Attestations rewards calculation is not available in phase0");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const stateAltair = state as CachedBeaconStateAltair;
|
|
47
|
+
const transitionCache = beforeProcessEpoch(stateAltair);
|
|
48
|
+
|
|
49
|
+
const [idealRewards, penalties] = computeIdealAttestationsRewardsAndPenaltiesAltair(
|
|
50
|
+
config,
|
|
51
|
+
stateAltair,
|
|
52
|
+
transitionCache
|
|
53
|
+
);
|
|
54
|
+
const totalRewards = computeTotalAttestationsRewardsAltair(
|
|
55
|
+
config,
|
|
56
|
+
pubkey2index,
|
|
57
|
+
stateAltair,
|
|
58
|
+
transitionCache,
|
|
59
|
+
idealRewards,
|
|
60
|
+
penalties,
|
|
61
|
+
validatorIds
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return {idealRewards, totalRewards};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function computeIdealAttestationsRewardsAndPenaltiesAltair(
|
|
68
|
+
config: BeaconConfig,
|
|
69
|
+
state: CachedBeaconStateAllForks,
|
|
70
|
+
transitionCache: EpochTransitionCache
|
|
71
|
+
): [rewards.IdealAttestationsReward[], AttestationsPenalty[]] {
|
|
72
|
+
const baseRewardPerIncrement = transitionCache.baseRewardPerIncrement;
|
|
73
|
+
const activeBalanceByIncrement = transitionCache.totalActiveStakeByIncrement;
|
|
74
|
+
const fork = config.getForkName(state.slot);
|
|
75
|
+
const maxEffectiveBalance = isForkPostElectra(fork) ? MAX_EFFECTIVE_BALANCE_ELECTRA : MAX_EFFECTIVE_BALANCE;
|
|
76
|
+
const maxEffectiveBalanceByIncrement = Math.floor(maxEffectiveBalance / EFFECTIVE_BALANCE_INCREMENT);
|
|
77
|
+
|
|
78
|
+
const idealRewards = Array.from({length: maxEffectiveBalanceByIncrement + 1}, (_, effectiveBalanceByIncrement) => ({
|
|
79
|
+
...defaultAttestationsReward,
|
|
80
|
+
effectiveBalance: effectiveBalanceByIncrement * EFFECTIVE_BALANCE_INCREMENT,
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
const attestationsPenalties: AttestationsPenalty[] = Array.from(
|
|
84
|
+
{length: maxEffectiveBalanceByIncrement + 1},
|
|
85
|
+
(_, effectiveBalanceByIncrement) => ({
|
|
86
|
+
...defaultAttestationsPenalty,
|
|
87
|
+
effectiveBalance: effectiveBalanceByIncrement * EFFECTIVE_BALANCE_INCREMENT,
|
|
88
|
+
})
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i < PARTICIPATION_FLAG_WEIGHTS.length; i++) {
|
|
92
|
+
const weight = PARTICIPATION_FLAG_WEIGHTS[i];
|
|
93
|
+
|
|
94
|
+
let unslashedStakeByIncrement: number;
|
|
95
|
+
let flagName: keyof rewards.IdealAttestationsReward;
|
|
96
|
+
|
|
97
|
+
switch (i) {
|
|
98
|
+
case TIMELY_SOURCE_FLAG_INDEX: {
|
|
99
|
+
unslashedStakeByIncrement = transitionCache.prevEpochUnslashedStake.sourceStakeByIncrement;
|
|
100
|
+
flagName = "source";
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case TIMELY_TARGET_FLAG_INDEX: {
|
|
104
|
+
unslashedStakeByIncrement = transitionCache.prevEpochUnslashedStake.targetStakeByIncrement;
|
|
105
|
+
flagName = "target";
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case TIMELY_HEAD_FLAG_INDEX: {
|
|
109
|
+
unslashedStakeByIncrement = transitionCache.prevEpochUnslashedStake.headStakeByIncrement;
|
|
110
|
+
flagName = "head";
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
default: {
|
|
114
|
+
throw Error(`Unable to retrieve unslashed stake. Unknown participation flag index: ${i}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
for (
|
|
119
|
+
let effectiveBalanceByIncrement = 0;
|
|
120
|
+
effectiveBalanceByIncrement <= maxEffectiveBalanceByIncrement;
|
|
121
|
+
effectiveBalanceByIncrement++
|
|
122
|
+
) {
|
|
123
|
+
const baseReward = effectiveBalanceByIncrement * baseRewardPerIncrement;
|
|
124
|
+
const rewardNumerator = baseReward * weight * unslashedStakeByIncrement;
|
|
125
|
+
// Both idealReward and penalty are rounded to nearest integer. Loss of precision is minimal as unit is gwei
|
|
126
|
+
const idealReward = Math.round(rewardNumerator / activeBalanceByIncrement / WEIGHT_DENOMINATOR);
|
|
127
|
+
const penalty = Math.round((baseReward * weight) / WEIGHT_DENOMINATOR); // Positive number indicates penalty
|
|
128
|
+
|
|
129
|
+
const idealAttestationsReward = idealRewards[effectiveBalanceByIncrement];
|
|
130
|
+
idealAttestationsReward[flagName] = isInInactivityLeak(state) ? 0 : idealReward; // No attestations rewards during inactivity leak
|
|
131
|
+
|
|
132
|
+
if (flagName !== "head") {
|
|
133
|
+
const attestationPenalty = attestationsPenalties[effectiveBalanceByIncrement];
|
|
134
|
+
attestationPenalty[flagName] = penalty;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return [idealRewards, attestationsPenalties];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Same calculation as `getRewardsAndPenaltiesAltair` but returns the breakdown of rewards instead of aggregated
|
|
143
|
+
function computeTotalAttestationsRewardsAltair(
|
|
144
|
+
config: BeaconConfig,
|
|
145
|
+
pubkey2index: PubkeyIndexMap,
|
|
146
|
+
state: CachedBeaconStateAltair,
|
|
147
|
+
transitionCache: EpochTransitionCache,
|
|
148
|
+
idealRewards: rewards.IdealAttestationsReward[],
|
|
149
|
+
penalties: AttestationsPenalty[],
|
|
150
|
+
validatorIds: (ValidatorIndex | string)[] = []
|
|
151
|
+
): rewards.TotalAttestationsReward[] {
|
|
152
|
+
const rewards = [];
|
|
153
|
+
const {flags} = transitionCache;
|
|
154
|
+
const {epochCtx} = state;
|
|
155
|
+
const validatorIndices = validatorIds
|
|
156
|
+
.map((id) => (typeof id === "number" ? id : pubkey2index.get(fromHex(id))))
|
|
157
|
+
.filter((index) => index !== undefined); // Validator indices to include in the result
|
|
158
|
+
|
|
159
|
+
const inactivityPenaltyDenominator = config.INACTIVITY_SCORE_BIAS * INACTIVITY_PENALTY_QUOTIENT_ALTAIR;
|
|
160
|
+
|
|
161
|
+
for (let i = 0; i < flags.length; i++) {
|
|
162
|
+
if (validatorIndices.length && !validatorIndices.includes(i)) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const flag = flags[i];
|
|
167
|
+
if (!hasMarkers(flag, FLAG_ELIGIBLE_ATTESTER)) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const effectiveBalanceIncrement = epochCtx.effectiveBalanceIncrements[i];
|
|
172
|
+
|
|
173
|
+
const currentRewards = {...defaultAttestationsReward, validatorIndex: i};
|
|
174
|
+
|
|
175
|
+
if (hasMarkers(flag, FLAG_PREV_SOURCE_ATTESTER_UNSLASHED)) {
|
|
176
|
+
currentRewards.source = idealRewards[effectiveBalanceIncrement].source;
|
|
177
|
+
} else {
|
|
178
|
+
currentRewards.source = penalties[effectiveBalanceIncrement].source * -1; // Negative reward to indicate penalty
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (hasMarkers(flag, FLAG_PREV_TARGET_ATTESTER_UNSLASHED)) {
|
|
182
|
+
currentRewards.target = idealRewards[effectiveBalanceIncrement].target;
|
|
183
|
+
} else {
|
|
184
|
+
currentRewards.target = penalties[effectiveBalanceIncrement].target * -1;
|
|
185
|
+
|
|
186
|
+
// Also incur inactivity penalty if not voting target correctly
|
|
187
|
+
const inactivityPenaltyNumerator =
|
|
188
|
+
effectiveBalanceIncrement * EFFECTIVE_BALANCE_INCREMENT * state.inactivityScores.get(i);
|
|
189
|
+
currentRewards.inactivity = Math.floor(inactivityPenaltyNumerator / inactivityPenaltyDenominator) * -1;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (hasMarkers(flag, FLAG_PREV_HEAD_ATTESTER_UNSLASHED)) {
|
|
193
|
+
currentRewards.head = idealRewards[effectiveBalanceIncrement].head;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
rewards.push(currentRewards);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return rewards;
|
|
200
|
+
}
|