@lodestar/state-transition 1.41.0-dev.702f7932c2 → 1.41.0-dev.8578102bd2
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/externalData.d.ts +2 -1
- package/lib/block/externalData.d.ts.map +1 -1
- package/lib/block/externalData.js +6 -2
- package/lib/block/externalData.js.map +1 -1
- package/lib/block/index.d.ts +3 -3
- package/lib/block/index.js.map +1 -1
- package/lib/block/initiateValidatorExit.js.map +1 -1
- package/lib/block/isValidIndexedAttestation.d.ts +3 -3
- 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/isValidIndexedPayloadAttestation.js +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -1
- package/lib/block/processAttestationPhase0.js +1 -1
- package/lib/block/processAttestationPhase0.js.map +1 -1
- package/lib/block/processAttestations.js.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 -2
- package/lib/block/processAttesterSlashing.d.ts.map +1 -1
- package/lib/block/processAttesterSlashing.js +3 -3
- package/lib/block/processAttesterSlashing.js.map +1 -1
- package/lib/block/processBlobKzgCommitments.js.map +1 -1
- package/lib/block/processBlockHeader.js.map +1 -1
- package/lib/block/processBlsToExecutionChange.js.map +1 -1
- package/lib/block/processConsolidationRequest.js.map +1 -1
- package/lib/block/processDeposit.js.map +1 -1
- package/lib/block/processDepositRequest.d.ts +1 -1
- package/lib/block/processDepositRequest.d.ts.map +1 -1
- package/lib/block/processDepositRequest.js +6 -5
- package/lib/block/processDepositRequest.js.map +1 -1
- package/lib/block/processEth1Data.js.map +1 -1
- package/lib/block/processExecutionPayload.js.map +1 -1
- package/lib/block/processExecutionPayloadBid.d.ts +1 -1
- package/lib/block/processExecutionPayloadBid.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadBid.js +5 -0
- package/lib/block/processExecutionPayloadBid.js.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.d.ts +5 -2
- package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.js +25 -24
- package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
- package/lib/block/processOperations.js.map +1 -1
- package/lib/block/processPayloadAttestation.d.ts +1 -1
- package/lib/block/processPayloadAttestation.js.map +1 -1
- package/lib/block/processProposerSlashing.d.ts +2 -2
- package/lib/block/processProposerSlashing.d.ts.map +1 -1
- package/lib/block/processProposerSlashing.js +3 -3
- package/lib/block/processProposerSlashing.js.map +1 -1
- package/lib/block/processRandao.js +1 -1
- package/lib/block/processRandao.js.map +1 -1
- package/lib/block/processSyncCommittee.js +1 -1
- package/lib/block/processSyncCommittee.js.map +1 -1
- package/lib/block/processVoluntaryExit.js +3 -2
- package/lib/block/processVoluntaryExit.js.map +1 -1
- package/lib/block/processWithdrawalRequest.js +2 -2
- package/lib/block/processWithdrawalRequest.js.map +1 -1
- package/lib/block/processWithdrawals.d.ts.map +1 -1
- package/lib/block/processWithdrawals.js +9 -1
- package/lib/block/processWithdrawals.js.map +1 -1
- package/lib/block/slashValidator.js.map +1 -1
- package/lib/block/types.js +2 -1
- package/lib/block/types.js.map +1 -1
- package/lib/cache/effectiveBalanceIncrements.js.map +1 -1
- package/lib/cache/epochCache.d.ts +11 -18
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +43 -41
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/cache/epochTransitionCache.js.map +1 -1
- package/lib/cache/pubkeyCache.d.ts +21 -6
- package/lib/cache/pubkeyCache.d.ts.map +1 -1
- package/lib/cache/pubkeyCache.js +39 -14
- package/lib/cache/pubkeyCache.js.map +1 -1
- package/lib/cache/rewardCache.js.map +1 -1
- package/lib/cache/stateCache.d.ts +1 -1
- package/lib/cache/stateCache.d.ts.map +1 -1
- package/lib/cache/stateCache.js +3 -7
- package/lib/cache/stateCache.js.map +1 -1
- package/lib/cache/syncCommitteeCache.d.ts +3 -2
- package/lib/cache/syncCommitteeCache.d.ts.map +1 -1
- package/lib/cache/syncCommitteeCache.js +4 -4
- package/lib/cache/syncCommitteeCache.js.map +1 -1
- package/lib/epoch/computeUnrealizedCheckpoints.js.map +1 -1
- package/lib/epoch/getAttestationDeltas.js.map +1 -1
- package/lib/epoch/getRewardsAndPenalties.js.map +1 -1
- package/lib/epoch/index.d.ts +1 -1
- package/lib/epoch/index.js +2 -1
- package/lib/epoch/index.js.map +1 -1
- package/lib/epoch/processBuilderPendingPayments.d.ts +1 -1
- package/lib/epoch/processBuilderPendingPayments.js.map +1 -1
- package/lib/epoch/processEffectiveBalanceUpdates.js.map +1 -1
- package/lib/epoch/processEth1DataReset.js.map +1 -1
- package/lib/epoch/processHistoricalRootsUpdate.js.map +1 -1
- package/lib/epoch/processHistoricalSummariesUpdate.js.map +1 -1
- package/lib/epoch/processInactivityUpdates.js.map +1 -1
- package/lib/epoch/processJustificationAndFinalization.js.map +1 -1
- package/lib/epoch/processParticipationFlagUpdates.js.map +1 -1
- package/lib/epoch/processParticipationRecordUpdates.js.map +1 -1
- package/lib/epoch/processPendingAttestations.js.map +1 -1
- package/lib/epoch/processPendingConsolidations.js.map +1 -1
- package/lib/epoch/processPendingDeposits.js.map +1 -1
- package/lib/epoch/processProposerLookahead.js.map +1 -1
- package/lib/epoch/processRandaoMixesReset.js.map +1 -1
- package/lib/epoch/processRegistryUpdates.js.map +1 -1
- package/lib/epoch/processRewardsAndPenalties.js.map +1 -1
- package/lib/epoch/processSlashings.js.map +1 -1
- package/lib/epoch/processSlashingsReset.js.map +1 -1
- package/lib/epoch/processSyncCommitteeUpdates.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/lightClient/proofs.d.ts +10 -0
- package/lib/lightClient/proofs.d.ts.map +1 -0
- package/lib/lightClient/proofs.js +63 -0
- package/lib/lightClient/proofs.js.map +1 -0
- package/lib/lightClient/types.d.ts +34 -0
- package/lib/lightClient/types.d.ts.map +1 -0
- package/lib/lightClient/types.js +2 -0
- package/lib/lightClient/types.js.map +1 -0
- package/lib/metrics.d.ts.map +1 -1
- package/lib/metrics.js.map +1 -1
- package/lib/rewards/attestationsRewards.d.ts +2 -2
- package/lib/rewards/attestationsRewards.d.ts.map +1 -1
- package/lib/rewards/attestationsRewards.js +4 -4
- package/lib/rewards/attestationsRewards.js.map +1 -1
- package/lib/rewards/blockRewards.js.map +1 -1
- package/lib/rewards/syncCommitteeRewards.d.ts +2 -2
- package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
- package/lib/rewards/syncCommitteeRewards.js +5 -2
- package/lib/rewards/syncCommitteeRewards.js.map +1 -1
- package/lib/signatureSets/attesterSlashings.js.map +1 -1
- package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
- package/lib/signatureSets/executionPayloadBid.js.map +1 -1
- package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -1
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/signatureSets/indexedAttestation.js.map +1 -1
- package/lib/signatureSets/indexedPayloadAttestation.d.ts +3 -4
- package/lib/signatureSets/indexedPayloadAttestation.d.ts.map +1 -1
- package/lib/signatureSets/indexedPayloadAttestation.js +4 -4
- package/lib/signatureSets/indexedPayloadAttestation.js.map +1 -1
- package/lib/signatureSets/proposer.d.ts +2 -2
- package/lib/signatureSets/proposer.d.ts.map +1 -1
- package/lib/signatureSets/proposer.js +2 -2
- package/lib/signatureSets/proposer.js.map +1 -1
- package/lib/signatureSets/proposerSlashings.js.map +1 -1
- package/lib/signatureSets/randao.d.ts +2 -2
- package/lib/signatureSets/randao.d.ts.map +1 -1
- package/lib/signatureSets/randao.js +2 -2
- package/lib/signatureSets/randao.js.map +1 -1
- package/lib/signatureSets/voluntaryExits.d.ts +2 -2
- package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
- package/lib/signatureSets/voluntaryExits.js +2 -2
- package/lib/signatureSets/voluntaryExits.js.map +1 -1
- package/lib/slot/index.js.map +1 -1
- package/lib/slot/upgradeStateToAltair.js.map +1 -1
- package/lib/slot/upgradeStateToBellatrix.js.map +1 -1
- package/lib/slot/upgradeStateToCapella.js.map +1 -1
- package/lib/slot/upgradeStateToDeneb.js.map +1 -1
- package/lib/slot/upgradeStateToElectra.js.map +1 -1
- package/lib/slot/upgradeStateToFulu.js.map +1 -1
- package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
- package/lib/slot/upgradeStateToGloas.js +50 -0
- package/lib/slot/upgradeStateToGloas.js.map +1 -1
- package/lib/stateTransition.d.ts +2 -1
- package/lib/stateTransition.d.ts.map +1 -1
- package/lib/stateTransition.js +6 -3
- package/lib/stateTransition.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +144 -0
- package/lib/stateView/beaconStateView.d.ts.map +1 -0
- package/lib/stateView/beaconStateView.js +496 -0
- package/lib/stateView/beaconStateView.js.map +1 -0
- package/lib/stateView/index.d.ts +3 -0
- package/lib/stateView/index.d.ts.map +1 -0
- package/lib/stateView/index.js +3 -0
- package/lib/stateView/index.js.map +1 -0
- package/lib/stateView/interface.d.ts +118 -0
- package/lib/stateView/interface.d.ts.map +1 -0
- package/lib/stateView/interface.js +2 -0
- package/lib/stateView/interface.js.map +1 -0
- package/lib/testUtils/cache.d.ts +2 -0
- package/lib/testUtils/cache.d.ts.map +1 -0
- package/lib/testUtils/cache.js +7 -0
- package/lib/testUtils/cache.js.map +1 -0
- package/lib/testUtils/index.d.ts +6 -0
- package/lib/testUtils/index.d.ts.map +1 -0
- package/lib/testUtils/index.js +6 -0
- package/lib/testUtils/index.js.map +1 -0
- package/lib/testUtils/infura.d.ts +3 -0
- package/lib/testUtils/infura.d.ts.map +1 -0
- package/lib/testUtils/infura.js +8 -0
- package/lib/testUtils/infura.js.map +1 -0
- package/lib/testUtils/interop.d.ts +2 -0
- package/lib/testUtils/interop.d.ts.map +1 -0
- package/lib/testUtils/interop.js +24 -0
- package/lib/testUtils/interop.js.map +1 -0
- package/lib/testUtils/params.d.ts +18 -0
- package/lib/testUtils/params.d.ts.map +1 -0
- package/lib/testUtils/params.js +20 -0
- package/lib/testUtils/params.js.map +1 -0
- package/lib/testUtils/state.d.ts +20 -0
- package/lib/testUtils/state.d.ts.map +1 -0
- package/lib/testUtils/state.js +78 -0
- package/lib/testUtils/state.js.map +1 -0
- package/lib/testUtils/testFileCache.d.ts +17 -0
- package/lib/testUtils/testFileCache.d.ts.map +1 -0
- package/lib/testUtils/testFileCache.js +96 -0
- package/lib/testUtils/testFileCache.js.map +1 -0
- package/lib/testUtils/util.d.ts +50 -0
- package/lib/testUtils/util.d.ts.map +1 -0
- package/lib/testUtils/util.js +329 -0
- package/lib/testUtils/util.js.map +1 -0
- package/lib/util/aggregator.js.map +1 -1
- package/lib/util/altair.js.map +1 -1
- package/lib/util/array.js.map +1 -1
- package/lib/util/attestation.js.map +1 -1
- package/lib/util/attesterStatus.js.map +1 -1
- package/lib/util/balance.js.map +1 -1
- package/lib/util/blindedBlock.js.map +1 -1
- package/lib/util/blockRoot.js.map +1 -1
- package/lib/util/capella.js.map +1 -1
- package/lib/util/computeAnchorCheckpoint.js.map +1 -1
- package/lib/util/deposit.js.map +1 -1
- package/lib/util/domain.js.map +1 -1
- package/lib/util/electra.js.map +1 -1
- package/lib/util/epoch.js.map +1 -1
- package/lib/util/epochShuffling.js.map +1 -1
- package/lib/util/execution.js.map +1 -1
- package/lib/util/finality.js.map +1 -1
- package/lib/util/fulu.js.map +1 -1
- package/lib/util/genesis.js.map +1 -1
- package/lib/util/gloas.d.ts.map +1 -1
- package/lib/util/gloas.js +10 -3
- package/lib/util/gloas.js.map +1 -1
- package/lib/util/interop.js.map +1 -1
- package/lib/util/loadState/findModifiedInactivityScores.js.map +1 -1
- package/lib/util/loadState/findModifiedValidators.js.map +1 -1
- package/lib/util/loadState/loadState.js.map +1 -1
- package/lib/util/loadState/loadValidator.js.map +1 -1
- package/lib/util/rootCache.d.ts.map +1 -1
- package/lib/util/rootCache.js.map +1 -1
- package/lib/util/seed.d.ts +20 -12
- package/lib/util/seed.d.ts.map +1 -1
- package/lib/util/seed.js +80 -72
- package/lib/util/seed.js.map +1 -1
- package/lib/util/shuffling.js +2 -1
- package/lib/util/shuffling.js.map +1 -1
- package/lib/util/signatureSets.d.ts +7 -7
- package/lib/util/signatureSets.d.ts.map +1 -1
- package/lib/util/signatureSets.js +20 -13
- package/lib/util/signatureSets.js.map +1 -1
- package/lib/util/signingRoot.js.map +1 -1
- package/lib/util/slot.js.map +1 -1
- package/lib/util/sszBytes.js.map +1 -1
- package/lib/util/syncCommittee.js.map +1 -1
- package/lib/util/targetUnslashedBalance.js.map +1 -1
- package/lib/util/validator.js.map +1 -1
- package/lib/util/weakSubjectivity.js +1 -1
- package/lib/util/weakSubjectivity.js.map +1 -1
- package/package.json +14 -9
- package/src/block/externalData.ts +2 -0
- package/src/block/index.ts +3 -3
- package/src/block/isValidIndexedAttestation.ts +5 -5
- package/src/block/isValidIndexedPayloadAttestation.ts +4 -4
- package/src/block/processAttestationPhase0.ts +1 -1
- package/src/block/processAttestationsAltair.ts +2 -2
- package/src/block/processAttesterSlashing.ts +4 -4
- package/src/block/processDepositRequest.ts +8 -5
- package/src/block/processExecutionPayloadBid.ts +12 -4
- package/src/block/processExecutionPayloadEnvelope.ts +40 -37
- package/src/block/processOperations.ts +1 -1
- package/src/block/processPayloadAttestation.ts +2 -2
- package/src/block/processProposerSlashing.ts +4 -4
- package/src/block/processRandao.ts +1 -1
- package/src/block/processSyncCommittee.ts +1 -1
- package/src/block/processVoluntaryExit.ts +1 -1
- package/src/block/processWithdrawalRequest.ts +2 -2
- package/src/block/processWithdrawals.ts +11 -2
- package/src/cache/epochCache.ts +62 -54
- package/src/cache/pubkeyCache.ts +62 -21
- package/src/cache/stateCache.ts +4 -8
- package/src/cache/syncCommitteeCache.ts +4 -5
- package/src/epoch/index.ts +1 -1
- package/src/epoch/processBuilderPendingPayments.ts +2 -2
- package/src/index.ts +3 -1
- package/src/lightClient/proofs.ts +83 -0
- package/src/lightClient/types.ts +33 -0
- package/src/rewards/attestationsRewards.ts +5 -5
- package/src/rewards/syncCommitteeRewards.ts +6 -5
- package/src/signatureSets/indexedPayloadAttestation.ts +4 -6
- package/src/signatureSets/proposer.ts +3 -3
- package/src/signatureSets/randao.ts +3 -7
- package/src/signatureSets/voluntaryExits.ts +3 -3
- package/src/slot/upgradeStateToGloas.ts +74 -0
- package/src/stateTransition.ts +2 -1
- package/src/stateView/beaconStateView.ts +744 -0
- package/src/stateView/index.ts +2 -0
- package/src/stateView/interface.ts +196 -0
- package/src/testUtils/cache.ts +8 -0
- package/src/testUtils/index.ts +5 -0
- package/src/testUtils/infura.ts +10 -0
- package/src/testUtils/interop.ts +29 -0
- package/src/testUtils/params.ts +23 -0
- package/src/testUtils/state.ts +110 -0
- package/src/testUtils/testFileCache.ts +127 -0
- package/src/testUtils/util.ts +429 -0
- package/src/util/gloas.ts +11 -3
- package/src/util/seed.ts +106 -89
- package/src/util/signatureSets.ts +23 -17
- package/src/util/weakSubjectivity.ts +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {Tree} from "@chainsafe/persistent-merkle-tree";
|
|
2
|
+
import {
|
|
3
|
+
BLOCK_BODY_EXECUTION_PAYLOAD_GINDEX,
|
|
4
|
+
FINALIZED_ROOT_GINDEX,
|
|
5
|
+
FINALIZED_ROOT_GINDEX_ELECTRA,
|
|
6
|
+
ForkName,
|
|
7
|
+
ForkPostBellatrix,
|
|
8
|
+
isForkPostElectra,
|
|
9
|
+
} from "@lodestar/params";
|
|
10
|
+
import {BeaconBlockBody, SSZTypesFor, ssz} from "@lodestar/types";
|
|
11
|
+
import {BeaconStateAllForks, CachedBeaconStateAllForks} from "../types.js";
|
|
12
|
+
import {SyncCommitteeWitness} from "./types.js";
|
|
13
|
+
|
|
14
|
+
export function getSyncCommitteesWitness(fork: ForkName, state: BeaconStateAllForks): SyncCommitteeWitness {
|
|
15
|
+
const n1 = state.node;
|
|
16
|
+
let witness: Uint8Array[];
|
|
17
|
+
let currentSyncCommitteeRoot: Uint8Array;
|
|
18
|
+
let nextSyncCommitteeRoot: Uint8Array;
|
|
19
|
+
|
|
20
|
+
if (isForkPostElectra(fork)) {
|
|
21
|
+
const n2 = n1.left;
|
|
22
|
+
const n5 = n2.right;
|
|
23
|
+
const n10 = n5.left;
|
|
24
|
+
const n21 = n10.right;
|
|
25
|
+
const n43 = n21.right;
|
|
26
|
+
|
|
27
|
+
currentSyncCommitteeRoot = n43.left.root; // n86
|
|
28
|
+
nextSyncCommitteeRoot = n43.right.root; // n87
|
|
29
|
+
|
|
30
|
+
// Witness branch is sorted by descending gindex
|
|
31
|
+
witness = [
|
|
32
|
+
n21.left.root, // 42
|
|
33
|
+
n10.left.root, // 20
|
|
34
|
+
n5.right.root, // 11
|
|
35
|
+
n2.left.root, // 4
|
|
36
|
+
n1.right.root, // 3
|
|
37
|
+
];
|
|
38
|
+
} else {
|
|
39
|
+
const n3 = n1.right; // [1]0110
|
|
40
|
+
const n6 = n3.left; // 1[0]110
|
|
41
|
+
const n13 = n6.right; // 10[1]10
|
|
42
|
+
const n27 = n13.right; // 101[1]0
|
|
43
|
+
currentSyncCommitteeRoot = n27.left.root; // n54 1011[0]
|
|
44
|
+
nextSyncCommitteeRoot = n27.right.root; // n55 1011[1]
|
|
45
|
+
|
|
46
|
+
// Witness branch is sorted by descending gindex
|
|
47
|
+
witness = [
|
|
48
|
+
n13.left.root, // 26
|
|
49
|
+
n6.left.root, // 12
|
|
50
|
+
n3.right.root, // 7
|
|
51
|
+
n1.left.root, // 2
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
witness,
|
|
57
|
+
currentSyncCommitteeRoot,
|
|
58
|
+
nextSyncCommitteeRoot,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function getNextSyncCommitteeBranch(syncCommitteesWitness: SyncCommitteeWitness): Uint8Array[] {
|
|
63
|
+
// Witness branch is sorted by descending gindex
|
|
64
|
+
return [syncCommitteesWitness.currentSyncCommitteeRoot, ...syncCommitteesWitness.witness];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function getCurrentSyncCommitteeBranch(syncCommitteesWitness: SyncCommitteeWitness): Uint8Array[] {
|
|
68
|
+
// Witness branch is sorted by descending gindex
|
|
69
|
+
return [syncCommitteesWitness.nextSyncCommitteeRoot, ...syncCommitteesWitness.witness];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function getFinalizedRootProof(state: CachedBeaconStateAllForks): Uint8Array[] {
|
|
73
|
+
const finalizedRootGindex = state.epochCtx.isPostElectra() ? FINALIZED_ROOT_GINDEX_ELECTRA : FINALIZED_ROOT_GINDEX;
|
|
74
|
+
return new Tree(state.node).getSingleProof(BigInt(finalizedRootGindex));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getBlockBodyExecutionHeaderProof(
|
|
78
|
+
fork: ForkPostBellatrix,
|
|
79
|
+
body: BeaconBlockBody<ForkPostBellatrix>
|
|
80
|
+
): Uint8Array[] {
|
|
81
|
+
const bodyView = (ssz[fork].BeaconBlockBody as SSZTypesFor<ForkPostBellatrix, "BeaconBlockBody">).toView(body);
|
|
82
|
+
return new Tree(bodyView.node).getSingleProof(BigInt(BLOCK_BODY_EXECUTION_PAYLOAD_GINDEX));
|
|
83
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We aren't creating the sync committee proofs separately because our ssz library automatically adds leaves to composite types,
|
|
3
|
+
* so they're already included in the state proof, currently with no way to specify otherwise
|
|
4
|
+
*
|
|
5
|
+
* remove two offsets so the # of offsets in the state proof will be the # expected
|
|
6
|
+
* This is a hack, but properly setting the offsets in the state proof would require either removing witnesses needed for the committees
|
|
7
|
+
* or setting the roots of the committees in the state proof
|
|
8
|
+
* this will always be 1, syncProofLeavesLength
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* With empty state (minimal)
|
|
12
|
+
* - `genesisTime = 0xffffffff`
|
|
13
|
+
* - `genesisValidatorsRoot = Buffer.alloc(32, 1)`
|
|
14
|
+
*
|
|
15
|
+
* Proof:
|
|
16
|
+
* ```
|
|
17
|
+
* offsets: [ 5, 4, 3, 2, 1 ]
|
|
18
|
+
* leaves: [
|
|
19
|
+
* '0xffffffff00000000000000000000000000000000000000000000000000000000',
|
|
20
|
+
* '0x0101010101010101010101010101010101010101010101010101010101010101',
|
|
21
|
+
* '0xb11b8bcf59425d6c99019cca1d2c2e47b51a2f74917a67ad132274f43e13ec43',
|
|
22
|
+
* '0x74bd1f2437cdf74b0904ee525d8da070a3fa27570942bf42cbab3dc5939600f0',
|
|
23
|
+
* '0x7f06739e5a42360c56e519a511675901c95402ea9877edc0d9a87471b1374a6a',
|
|
24
|
+
* '0x9f534204ba3c0b69fcb42a11987bfcbc5aea0463e5b0614312ded4b62cf3a380'
|
|
25
|
+
* ]
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type SyncCommitteeWitness = {
|
|
29
|
+
/** Vector[Bytes32, 4] or Vector[Bytes32, 5] depending on the fork */
|
|
30
|
+
witness: Uint8Array[];
|
|
31
|
+
currentSyncCommitteeRoot: Uint8Array;
|
|
32
|
+
nextSyncCommitteeRoot: Uint8Array;
|
|
33
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
|
|
2
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
3
2
|
import {
|
|
4
3
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
@@ -16,6 +15,7 @@ import {
|
|
|
16
15
|
import {ValidatorIndex, rewards} from "@lodestar/types";
|
|
17
16
|
import {fromHex} from "@lodestar/utils";
|
|
18
17
|
import {EpochTransitionCache, beforeProcessEpoch} from "../cache/epochTransitionCache.js";
|
|
18
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
19
19
|
import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../types.js";
|
|
20
20
|
import {
|
|
21
21
|
FLAG_ELIGIBLE_ATTESTER,
|
|
@@ -34,7 +34,7 @@ const defaultAttestationsPenalty = {target: 0, source: 0};
|
|
|
34
34
|
|
|
35
35
|
export async function computeAttestationsRewards(
|
|
36
36
|
config: BeaconConfig,
|
|
37
|
-
|
|
37
|
+
pubkeyCache: PubkeyCache,
|
|
38
38
|
state: CachedBeaconStateAllForks,
|
|
39
39
|
validatorIds?: (ValidatorIndex | string)[]
|
|
40
40
|
): Promise<rewards.AttestationsRewards> {
|
|
@@ -53,7 +53,7 @@ export async function computeAttestationsRewards(
|
|
|
53
53
|
);
|
|
54
54
|
const totalRewards = computeTotalAttestationsRewardsAltair(
|
|
55
55
|
config,
|
|
56
|
-
|
|
56
|
+
pubkeyCache,
|
|
57
57
|
stateAltair,
|
|
58
58
|
transitionCache,
|
|
59
59
|
idealRewards,
|
|
@@ -142,7 +142,7 @@ function computeIdealAttestationsRewardsAndPenaltiesAltair(
|
|
|
142
142
|
// Same calculation as `getRewardsAndPenaltiesAltair` but returns the breakdown of rewards instead of aggregated
|
|
143
143
|
function computeTotalAttestationsRewardsAltair(
|
|
144
144
|
config: BeaconConfig,
|
|
145
|
-
|
|
145
|
+
pubkeyCache: PubkeyCache,
|
|
146
146
|
state: CachedBeaconStateAltair,
|
|
147
147
|
transitionCache: EpochTransitionCache,
|
|
148
148
|
idealRewards: rewards.IdealAttestationsReward[],
|
|
@@ -153,7 +153,7 @@ function computeTotalAttestationsRewardsAltair(
|
|
|
153
153
|
const {flags} = transitionCache;
|
|
154
154
|
const {epochCtx} = state;
|
|
155
155
|
const validatorIndices = validatorIds
|
|
156
|
-
.map((id) => (typeof id === "number" ? id :
|
|
156
|
+
.map((id) => (typeof id === "number" ? id : pubkeyCache.getIndex(fromHex(id))))
|
|
157
157
|
.filter((index) => index !== undefined); // Validator indices to include in the result
|
|
158
158
|
|
|
159
159
|
const inactivityPenaltyDenominator = config.INACTIVITY_SCORE_BIAS * INACTIVITY_PENALTY_QUOTIENT_ALTAIR;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {ForkName, SYNC_COMMITTEE_SIZE} from "@lodestar/params";
|
|
3
3
|
import {BeaconBlock, ValidatorIndex, altair, rewards} from "@lodestar/types";
|
|
4
|
-
import {
|
|
4
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
5
5
|
import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../cache/stateCache.js";
|
|
6
6
|
|
|
7
7
|
export async function computeSyncCommitteeRewards(
|
|
8
8
|
config: BeaconConfig,
|
|
9
|
-
|
|
9
|
+
pubkeyCache: PubkeyCache,
|
|
10
10
|
block: BeaconBlock,
|
|
11
11
|
preState: CachedBeaconStateAllForks,
|
|
12
12
|
validatorIds: (ValidatorIndex | string)[] = []
|
|
@@ -47,9 +47,10 @@ export async function computeSyncCommitteeRewards(
|
|
|
47
47
|
|
|
48
48
|
if (validatorIds.length) {
|
|
49
49
|
const filtersSet = new Set(validatorIds);
|
|
50
|
-
return rewards.filter(
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
return rewards.filter((reward) => {
|
|
51
|
+
const pubkeyHex = pubkeyCache.get(reward.validatorIndex)?.toHex();
|
|
52
|
+
return filtersSet.has(reward.validatorIndex) || (pubkeyHex !== undefined && filtersSet.has(pubkeyHex));
|
|
53
|
+
});
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
return rewards;
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {DOMAIN_PTC_ATTESTER} from "@lodestar/params";
|
|
3
|
-
import {
|
|
4
|
-
import {CachedBeaconStateGloas} from "../types.js";
|
|
3
|
+
import {gloas, ssz} from "@lodestar/types";
|
|
5
4
|
import {ISignatureSet, computeSigningRoot, createAggregateSignatureSetFromComponents} from "../util/index.js";
|
|
6
5
|
|
|
7
6
|
export function getIndexedPayloadAttestationSignatureSet(
|
|
8
|
-
|
|
7
|
+
config: BeaconConfig,
|
|
9
8
|
indexedPayloadAttestation: gloas.IndexedPayloadAttestation
|
|
10
9
|
): ISignatureSet {
|
|
11
10
|
return createAggregateSignatureSetFromComponents(
|
|
12
11
|
indexedPayloadAttestation.attestingIndices,
|
|
13
|
-
getPayloadAttestationDataSigningRoot(
|
|
12
|
+
getPayloadAttestationDataSigningRoot(config, indexedPayloadAttestation.data),
|
|
14
13
|
indexedPayloadAttestation.signature
|
|
15
14
|
);
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
export function getPayloadAttestationDataSigningRoot(
|
|
19
18
|
config: BeaconConfig,
|
|
20
|
-
stateSlot: Slot,
|
|
21
19
|
data: gloas.PayloadAttestationData
|
|
22
20
|
): Uint8Array {
|
|
23
|
-
const domain = config.getDomain(
|
|
21
|
+
const domain = config.getDomain(data.slot, DOMAIN_PTC_ATTESTER);
|
|
24
22
|
|
|
25
23
|
return computeSigningRoot(ssz.gloas.PayloadAttestationData, data, domain);
|
|
26
24
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
|
|
3
3
|
import {SignedBeaconBlock, SignedBlindedBeaconBlock, Slot, isBlindedBeaconBlock, phase0, ssz} from "@lodestar/types";
|
|
4
|
-
import {
|
|
4
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
5
5
|
import {computeSigningRoot} from "../util/index.js";
|
|
6
6
|
import {ISignatureSet, SignatureSetType, verifySignatureSet} from "../util/signatureSets.js";
|
|
7
7
|
|
|
8
8
|
export function verifyProposerSignature(
|
|
9
9
|
config: BeaconConfig,
|
|
10
|
-
|
|
10
|
+
pubkeyCache: PubkeyCache,
|
|
11
11
|
signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
|
|
12
12
|
): boolean {
|
|
13
13
|
const signatureSet = getBlockProposerSignatureSet(config, signedBlock);
|
|
14
|
-
return verifySignatureSet(signatureSet,
|
|
14
|
+
return verifySignatureSet(signatureSet, pubkeyCache);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function getBlockProposerSignatureSet(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {DOMAIN_RANDAO} from "@lodestar/params";
|
|
3
3
|
import {BeaconBlock, ssz} from "@lodestar/types";
|
|
4
|
-
import {
|
|
4
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
5
5
|
import {
|
|
6
6
|
ISignatureSet,
|
|
7
7
|
SignatureSetType,
|
|
@@ -10,12 +10,8 @@ import {
|
|
|
10
10
|
verifySignatureSet,
|
|
11
11
|
} from "../util/index.js";
|
|
12
12
|
|
|
13
|
-
export function verifyRandaoSignature(
|
|
14
|
-
config
|
|
15
|
-
index2pubkey: Index2PubkeyCache,
|
|
16
|
-
block: BeaconBlock
|
|
17
|
-
): boolean {
|
|
18
|
-
return verifySignatureSet(getRandaoRevealSignatureSet(config, block), index2pubkey);
|
|
13
|
+
export function verifyRandaoSignature(config: BeaconConfig, pubkeyCache: PubkeyCache, block: BeaconBlock): boolean {
|
|
14
|
+
return verifySignatureSet(getRandaoRevealSignatureSet(config, block), pubkeyCache);
|
|
19
15
|
}
|
|
20
16
|
|
|
21
17
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
|
|
3
|
-
import {
|
|
3
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
4
4
|
import {
|
|
5
5
|
ISignatureSet,
|
|
6
6
|
SignatureSetType,
|
|
@@ -11,11 +11,11 @@ import {
|
|
|
11
11
|
|
|
12
12
|
export function verifyVoluntaryExitSignature(
|
|
13
13
|
config: BeaconConfig,
|
|
14
|
-
|
|
14
|
+
pubkeyCache: PubkeyCache,
|
|
15
15
|
stateSlot: Slot,
|
|
16
16
|
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
17
17
|
): boolean {
|
|
18
|
-
return verifySignatureSet(getVoluntaryExitSignatureSet(config, stateSlot, signedVoluntaryExit),
|
|
18
|
+
return verifySignatureSet(getVoluntaryExitSignatureSet(config, stateSlot, signedVoluntaryExit), pubkeyCache);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import {SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params";
|
|
2
2
|
import {ssz} from "@lodestar/types";
|
|
3
|
+
import {toHex} from "@lodestar/utils";
|
|
4
|
+
import {isValidDepositSignature} from "../block/processDeposit.js";
|
|
5
|
+
import {applyDepositForBuilder} from "../block/processDepositRequest.js";
|
|
3
6
|
import {getCachedBeaconState} from "../cache/stateCache.js";
|
|
4
7
|
import {CachedBeaconStateFulu, CachedBeaconStateGloas} from "../types.js";
|
|
8
|
+
import {isBuilderWithdrawalCredential} from "../util/gloas.js";
|
|
9
|
+
import {isValidatorKnown} from "../util/index.js";
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* Upgrade a state from Fulu to Gloas.
|
|
@@ -64,6 +69,9 @@ export function upgradeStateToGloas(stateFulu: CachedBeaconStateFulu): CachedBea
|
|
|
64
69
|
|
|
65
70
|
const stateGloas = getCachedBeaconState(stateGloasView, stateFulu);
|
|
66
71
|
|
|
72
|
+
// Process pending builder deposits at the fork boundary
|
|
73
|
+
onboardBuildersFromPendingDeposits(stateGloas);
|
|
74
|
+
|
|
67
75
|
stateGloas.commit();
|
|
68
76
|
// Clear cache to ensure the cache of fulu fields is not used by new gloas fields
|
|
69
77
|
// biome-ignore lint/complexity/useLiteralKeys: It is a protected attribute
|
|
@@ -71,3 +79,69 @@ export function upgradeStateToGloas(stateFulu: CachedBeaconStateFulu): CachedBea
|
|
|
71
79
|
|
|
72
80
|
return stateGloas;
|
|
73
81
|
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Applies any pending deposits for builders to onboard builders during the fork transition
|
|
85
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.2/specs/gloas/fork.md#new-onboard_builders_from_pending_deposits
|
|
86
|
+
*/
|
|
87
|
+
function onboardBuildersFromPendingDeposits(state: CachedBeaconStateGloas): void {
|
|
88
|
+
// Track pubkeys of new validators to keep their deposits pending
|
|
89
|
+
const validatorPubkeys = new Set<string>();
|
|
90
|
+
|
|
91
|
+
// Track pubkeys of new builders added when applying deposits
|
|
92
|
+
const builderPubkeys = new Set<string>();
|
|
93
|
+
|
|
94
|
+
const remainingPendingDeposits = ssz.electra.PendingDeposits.defaultViewDU();
|
|
95
|
+
for (let i = 0; i < state.pendingDeposits.length; i++) {
|
|
96
|
+
const deposit = state.pendingDeposits.getReadonly(i);
|
|
97
|
+
|
|
98
|
+
const validatorIndex = state.epochCtx.getValidatorIndex(deposit.pubkey);
|
|
99
|
+
const pubkeyHex = toHex(deposit.pubkey);
|
|
100
|
+
|
|
101
|
+
// Deposits for existing validators stay in pending queue
|
|
102
|
+
if (isValidatorKnown(state, validatorIndex) || validatorPubkeys.has(pubkeyHex)) {
|
|
103
|
+
remainingPendingDeposits.push(deposit);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// If the pubkey is associated with a builder that was created in a previous iteration
|
|
108
|
+
// or it is a builder deposit, try to apply the deposit to the new/existing builder
|
|
109
|
+
const isExistingBuilder = builderPubkeys.has(pubkeyHex);
|
|
110
|
+
const hasBuilderCredentials = isBuilderWithdrawalCredential(deposit.withdrawalCredentials);
|
|
111
|
+
if (isExistingBuilder || hasBuilderCredentials) {
|
|
112
|
+
const buildersLenBefore = state.builders.length;
|
|
113
|
+
applyDepositForBuilder(
|
|
114
|
+
state,
|
|
115
|
+
deposit.pubkey,
|
|
116
|
+
deposit.withdrawalCredentials,
|
|
117
|
+
deposit.amount,
|
|
118
|
+
deposit.signature,
|
|
119
|
+
deposit.slot
|
|
120
|
+
);
|
|
121
|
+
// Track newly added builders for subsequent iterations
|
|
122
|
+
if (!isExistingBuilder && state.builders.length > buildersLenBefore) {
|
|
123
|
+
builderPubkeys.add(pubkeyHex);
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// If there is a pending deposit for a new validator that has a valid signature, track the
|
|
129
|
+
// pubkey so that subsequent builder deposits for the same pubkey stay in pending (applied to
|
|
130
|
+
// the validator later) rather than creating a builder. Deposits with invalid signatures are
|
|
131
|
+
// dropped here since they would fail in apply_pending_deposit anyway.
|
|
132
|
+
if (
|
|
133
|
+
isValidDepositSignature(
|
|
134
|
+
state.config,
|
|
135
|
+
deposit.pubkey,
|
|
136
|
+
deposit.withdrawalCredentials,
|
|
137
|
+
deposit.amount,
|
|
138
|
+
deposit.signature
|
|
139
|
+
)
|
|
140
|
+
) {
|
|
141
|
+
validatorPubkeys.add(pubkeyHex);
|
|
142
|
+
remainingPendingDeposits.push(deposit);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
state.pendingDeposits = remainingPendingDeposits;
|
|
147
|
+
}
|
package/src/stateTransition.ts
CHANGED
|
@@ -76,6 +76,7 @@ export enum StateHashTreeRootSource {
|
|
|
76
76
|
prepareNextEpoch = "prepare_next_epoch",
|
|
77
77
|
regenState = "regen_state",
|
|
78
78
|
computeNewStateRoot = "compute_new_state_root",
|
|
79
|
+
computeEnvelopeStateRoot = "compute_envelope_state_root",
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
/**
|
|
@@ -111,7 +112,7 @@ export function stateTransition(
|
|
|
111
112
|
postState = processSlotsWithTransientCache(postState, blockSlot, options, {metrics, validatorMonitor});
|
|
112
113
|
|
|
113
114
|
// Verify proposer signature only
|
|
114
|
-
if (verifyProposer && !verifyProposerSignature(postState.config, postState.epochCtx.
|
|
115
|
+
if (verifyProposer && !verifyProposerSignature(postState.config, postState.epochCtx.pubkeyCache, signedBlock)) {
|
|
115
116
|
throw new Error("Invalid block signature");
|
|
116
117
|
}
|
|
117
118
|
|