@lodestar/state-transition 1.51.0 → 1.52.0-dev.03eb33e6f1
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 +1 -1
- package/lib/block/index.d.ts.map +1 -1
- package/lib/block/index.js +2 -2
- package/lib/block/index.js.map +1 -1
- package/lib/block/processDeposit.d.ts.map +1 -1
- package/lib/block/processDeposit.js +1 -1
- package/lib/block/processDeposit.js.map +1 -1
- package/lib/block/processOperations.d.ts +1 -1
- package/lib/block/processOperations.d.ts.map +1 -1
- package/lib/block/processOperations.js +1 -1
- package/lib/block/processOperations.js.map +1 -1
- package/lib/cache/epochCache.d.ts +2 -2
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +1 -1
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/cache/syncCommitteeCache.d.ts +1 -1
- package/lib/cache/syncCommitteeCache.d.ts.map +1 -1
- package/lib/epoch/index.d.ts +2 -2
- package/lib/epoch/index.d.ts.map +1 -1
- package/lib/epoch/index.js +2 -2
- package/lib/epoch/index.js.map +1 -1
- package/lib/epoch/processSyncCommitteeUpdates.js +1 -1
- package/lib/epoch/processSyncCommitteeUpdates.js.map +1 -1
- package/lib/lightClient/spec/store.d.ts +1 -1
- package/lib/lightClient/spec/store.d.ts.map +1 -1
- package/lib/lightClient/spec/utils.d.ts.map +1 -1
- package/lib/lightClient/spec/utils.js +1 -1
- package/lib/lightClient/spec/utils.js.map +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.d.ts.map +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.js +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.js.map +1 -1
- package/lib/rewards/attestationsRewards.d.ts +1 -1
- package/lib/rewards/attestationsRewards.d.ts.map +1 -1
- package/lib/rewards/syncCommitteeRewards.d.ts +1 -1
- package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
- package/lib/signatureSets/index.d.ts +3 -1
- package/lib/signatureSets/index.d.ts.map +1 -1
- package/lib/signatureSets/index.js +1 -1
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/signatureSets/indexedAttestation.d.ts +6 -2
- package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
- package/lib/signatureSets/indexedAttestation.js +27 -4
- package/lib/signatureSets/indexedAttestation.js.map +1 -1
- package/lib/slot/upgradeStateToHeze.d.ts.map +1 -1
- package/lib/slot/upgradeStateToHeze.js +0 -4
- package/lib/slot/upgradeStateToHeze.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +1 -0
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +7 -1
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/interface.d.ts +2 -1
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/interface.js.map +1 -1
- package/lib/stateView/nativeBeaconStateView.d.ts +2 -2
- package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.js +6 -22
- package/lib/stateView/nativeBeaconStateView.js.map +1 -1
- package/lib/stateView/stateViewFactory.d.ts.map +1 -1
- package/lib/stateView/stateViewFactory.js +4 -5
- package/lib/stateView/stateViewFactory.js.map +1 -1
- package/lib/testUtils/interopPubkeyCache.js +1 -1
- package/lib/testUtils/interopPubkeyCache.js.map +1 -1
- package/lib/testUtils/state.d.ts.map +1 -1
- package/lib/testUtils/state.js +1 -1
- package/lib/testUtils/state.js.map +1 -1
- package/lib/testUtils/util.d.ts +1 -1
- package/lib/testUtils/util.d.ts.map +1 -1
- package/lib/testUtils/util.js +2 -2
- package/lib/testUtils/util.js.map +1 -1
- package/lib/util/blindedBlock.d.ts.map +1 -1
- package/lib/util/blindedBlock.js +4 -12
- package/lib/util/blindedBlock.js.map +1 -1
- package/lib/util/epochShuffling.d.ts +4 -0
- package/lib/util/epochShuffling.d.ts.map +1 -1
- package/lib/util/epochShuffling.js +1 -1
- package/lib/util/epochShuffling.js.map +1 -1
- package/lib/util/genesis.d.ts.map +1 -1
- package/lib/util/genesis.js +8 -1
- package/lib/util/genesis.js.map +1 -1
- package/lib/util/gloas.d.ts +5 -0
- package/lib/util/gloas.d.ts.map +1 -1
- package/lib/util/gloas.js +10 -0
- package/lib/util/gloas.js.map +1 -1
- package/lib/util/interop.d.ts +1 -1
- package/lib/util/interop.d.ts.map +1 -1
- package/lib/util/interop.js +1 -1
- package/lib/util/interop.js.map +1 -1
- package/lib/util/seed.js +1 -1
- package/lib/util/seed.js.map +1 -1
- package/lib/util/signatureSets.d.ts +24 -4
- package/lib/util/signatureSets.d.ts.map +1 -1
- package/lib/util/signatureSets.js +26 -1
- package/lib/util/signatureSets.js.map +1 -1
- package/lib/util/syncCommittee.d.ts.map +1 -1
- package/lib/util/syncCommittee.js +1 -1
- package/lib/util/syncCommittee.js.map +1 -1
- package/package.json +9 -9
- package/src/block/index.ts +11 -12
- package/src/block/processDeposit.ts +2 -2
- package/src/block/processOperations.ts +5 -5
- package/src/cache/epochCache.ts +2 -2
- package/src/cache/syncCommitteeCache.ts +1 -1
- package/src/epoch/index.ts +14 -15
- package/src/epoch/processSyncCommitteeUpdates.ts +1 -1
- package/src/lightClient/spec/store.ts +1 -1
- package/src/lightClient/spec/utils.ts +1 -1
- package/src/lightClient/spec/validateLightClientUpdate.ts +1 -1
- package/src/rewards/attestationsRewards.ts +1 -1
- package/src/rewards/syncCommitteeRewards.ts +1 -1
- package/src/signatureSets/index.ts +4 -2
- package/src/signatureSets/indexedAttestation.ts +32 -6
- package/src/slot/upgradeStateToHeze.ts +0 -6
- package/src/stateView/beaconStateView.ts +9 -1
- package/src/stateView/interface.ts +1 -2
- package/src/stateView/nativeBeaconStateView.ts +7 -26
- package/src/stateView/stateViewFactory.ts +4 -5
- package/src/testUtils/interopPubkeyCache.ts +1 -1
- package/src/testUtils/state.ts +1 -1
- package/src/testUtils/util.ts +2 -2
- package/src/util/blindedBlock.ts +4 -12
- package/src/util/epochShuffling.ts +6 -1
- package/src/util/genesis.ts +9 -1
- package/src/util/gloas.ts +11 -0
- package/src/util/interop.ts +1 -1
- package/src/util/seed.ts +1 -1
- package/src/util/signatureSets.ts +46 -3
- package/src/util/syncCommittee.ts +1 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
|
-
import {DOMAIN_BEACON_ATTESTER} from "@lodestar/params";
|
|
3
|
-
import {IndexedAttestation, SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
|
|
2
|
+
import {DOMAIN_BEACON_ATTESTER, ForkSeq} from "@lodestar/params";
|
|
3
|
+
import {IndexedAttestation, SignedBeaconBlock, Slot, electra, phase0, ssz} from "@lodestar/types";
|
|
4
4
|
import {
|
|
5
|
+
EpochShuffling,
|
|
5
6
|
ISignatureSet,
|
|
7
|
+
SignatureSetType,
|
|
6
8
|
computeSigningRoot,
|
|
7
9
|
computeStartSlotAtEpoch,
|
|
8
10
|
createAggregateSignatureSetFromComponents,
|
|
@@ -45,10 +47,15 @@ export function getIndexedAttestationSignatureSet(
|
|
|
45
47
|
);
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
/**
|
|
51
|
+
* `shufflings[i]` is the shuffling of attestation `i`. Attestations whose shuffling has committee pubkeys get a
|
|
52
|
+
* committee signature set.
|
|
53
|
+
*/
|
|
48
54
|
export function getAttestationsSignatureSets(
|
|
49
55
|
config: BeaconConfig,
|
|
50
56
|
signedBlock: SignedBeaconBlock,
|
|
51
|
-
indexedAttestations: IndexedAttestation[]
|
|
57
|
+
indexedAttestations: IndexedAttestation[],
|
|
58
|
+
shufflings?: EpochShuffling[]
|
|
52
59
|
): ISignatureSet[] {
|
|
53
60
|
if (indexedAttestations.length !== signedBlock.message.body.attestations.length) {
|
|
54
61
|
throw Error(
|
|
@@ -58,7 +65,26 @@ export function getAttestationsSignatureSets(
|
|
|
58
65
|
// the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
|
|
59
66
|
// and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
|
|
60
67
|
const blockSlot = signedBlock.message.slot;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
68
|
+
const fork = config.getForkSeq(blockSlot);
|
|
69
|
+
return indexedAttestations.map((indexedAttestation, i) => {
|
|
70
|
+
const committeePubkeysId = shufflings?.[i]?.committeePubkeysId;
|
|
71
|
+
if (committeePubkeysId === undefined) {
|
|
72
|
+
return getIndexedAttestationSignatureSet(config, blockSlot, indexedAttestation);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const attestation = signedBlock.message.body.attestations[i];
|
|
76
|
+
return {
|
|
77
|
+
type: SignatureSetType.committee,
|
|
78
|
+
indices: indexedAttestation.attestingIndices,
|
|
79
|
+
committeePubkeysId,
|
|
80
|
+
slot: attestation.data.slot,
|
|
81
|
+
committeeIndices:
|
|
82
|
+
fork >= ForkSeq.electra
|
|
83
|
+
? (attestation as electra.Attestation).committeeBits.getTrueBitIndexes()
|
|
84
|
+
: [attestation.data.index],
|
|
85
|
+
aggregationBits: attestation.aggregationBits,
|
|
86
|
+
signingRoot: getAttestationDataSigningRoot(config, blockSlot, attestation.data),
|
|
87
|
+
signature: attestation.signature,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
64
90
|
}
|
|
@@ -7,12 +7,6 @@ import {CachedBeaconStateGloas, CachedBeaconStateHeze} from "../types.js";
|
|
|
7
7
|
* Spec: heze/fork.md `upgrade_to_heze`.
|
|
8
8
|
*/
|
|
9
9
|
export function upgradeStateToHeze(stateGloas: CachedBeaconStateGloas): CachedBeaconStateHeze {
|
|
10
|
-
// In Heze, the old deposit mechanism must be fully drained before the fork
|
|
11
|
-
if (BigInt(stateGloas.eth1DepositIndex) !== stateGloas.depositRequestsStartIndex) {
|
|
12
|
-
throw new Error(
|
|
13
|
-
`Cannot upgrade to Heze: legacy deposit mechanism still active eth1DepositIndex=${stateGloas.eth1DepositIndex} depositRequestsStartIndex=${stateGloas.depositRequestsStartIndex}`
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
10
|
const {config} = stateGloas;
|
|
17
11
|
|
|
18
12
|
ssz.gloas.BeaconState.commitViewDU(stateGloas);
|
|
@@ -63,7 +63,7 @@ import {
|
|
|
63
63
|
isGloasStateType,
|
|
64
64
|
isMergeTransitionComplete,
|
|
65
65
|
} from "../util/execution.js";
|
|
66
|
-
import {canBuilderCoverBid} from "../util/gloas.js";
|
|
66
|
+
import {canBuilderCoverBid, getBuilderBidLimit} from "../util/gloas.js";
|
|
67
67
|
import {loadState} from "../util/loadState/loadState.js";
|
|
68
68
|
import {PreVerifyBuilderDepositsResult, preVerifyBuilderDepositsPreGloas} from "../util/preVerifyBuilderDeposits.js";
|
|
69
69
|
import {getRandaoMix} from "../util/seed.js";
|
|
@@ -469,6 +469,14 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
469
469
|
return canBuilderCoverBid(this.cachedState as CachedBeaconStateGloas, builderIndex, bidAmount);
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
+
getBuilderBidLimit(builderIndex: BuilderIndex): number {
|
|
473
|
+
if (this.config.getForkSeq(this.cachedState.slot) < ForkSeq.gloas) {
|
|
474
|
+
throw new Error("Builders are not supported before Gloas");
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return getBuilderBidLimit(this.cachedState as CachedBeaconStateGloas, builderIndex);
|
|
478
|
+
}
|
|
479
|
+
|
|
472
480
|
/**
|
|
473
481
|
* Return the PTCs for an epoch
|
|
474
482
|
*/
|
|
@@ -293,6 +293,7 @@ export interface IBeaconStateViewGloas extends IBeaconStateViewFulu {
|
|
|
293
293
|
getBuilder(index: BuilderIndex): gloas.Builder;
|
|
294
294
|
getBuildersLength(): number;
|
|
295
295
|
canBuilderCoverBid(builderIndex: BuilderIndex, bidAmount: number): boolean;
|
|
296
|
+
getBuilderBidLimit(builderIndex: BuilderIndex): number;
|
|
296
297
|
getEpochPTCs(epoch: Epoch): Uint32Array[];
|
|
297
298
|
getPayloadTimelinessCommittee(slot: Slot): Uint32Array;
|
|
298
299
|
getIndicesInPayloadTimelinessCommittee(validatorIndex: ValidatorIndex, slot: Slot): number[];
|
|
@@ -348,8 +349,6 @@ export type IBeaconStateViewNative = Omit<
|
|
|
348
349
|
| "pendingConsolidations"
|
|
349
350
|
| "pendingDeposits"
|
|
350
351
|
| "pendingPartialWithdrawals"
|
|
351
|
-
| "preVerifyBuilderDepositsPreGloas"
|
|
352
|
-
| "clearPreGloasBuilderDepositCache"
|
|
353
352
|
| "processSlots"
|
|
354
353
|
| "proposerLookahead"
|
|
355
354
|
| "stateTransition"
|
|
@@ -40,7 +40,6 @@ import {SyncCommitteeWitness} from "../lightClient/types.js";
|
|
|
40
40
|
import {StateTransitionModules, StateTransitionOpts} from "../stateTransition.js";
|
|
41
41
|
import {EpochShuffling} from "../util/epochShuffling.js";
|
|
42
42
|
import {PreVerifyBuilderDepositsResult} from "../util/preVerifyBuilderDeposits.js";
|
|
43
|
-
import {getStateSlotFromBytes} from "../util/sszBytes.js";
|
|
44
43
|
import {computeNewStateRootStateTransitionOpts, getComputeNewStateRootResult} from "./computeNewStateRoot.js";
|
|
45
44
|
import {
|
|
46
45
|
BlockSTFInput,
|
|
@@ -52,12 +51,6 @@ import {
|
|
|
52
51
|
isStatePostGloas,
|
|
53
52
|
} from "./interface.js";
|
|
54
53
|
|
|
55
|
-
export function assertNativeForkSupported(config: BeaconConfig, slot: Slot): void {
|
|
56
|
-
if (config.getForkSeq(slot) > ForkSeq.gloas) {
|
|
57
|
-
throw Error(`Native state transition does not support ${config.getForkName(slot)}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
54
|
/**
|
|
62
55
|
* Wraps a native binding (the auto-generated JS interface produced by a `.node`
|
|
63
56
|
* file) and exposes it as a fully-conformant `IBeaconStateViewLatestFork`.
|
|
@@ -619,7 +612,6 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
619
612
|
seedValidatorsBytes?: Uint8Array,
|
|
620
613
|
opts?: {preloadValidatorsAndBalances?: boolean}
|
|
621
614
|
): IBeaconStateView {
|
|
622
|
-
assertNativeForkSupported(this.config, getStateSlotFromBytes(stateBytes));
|
|
623
615
|
return new NativeBeaconStateView(this.config, this.binding.loadOtherState(stateBytes, seedValidatorsBytes, opts));
|
|
624
616
|
}
|
|
625
617
|
|
|
@@ -685,7 +677,6 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
685
677
|
options: StateTransitionOpts,
|
|
686
678
|
_modules: StateTransitionModules
|
|
687
679
|
): IBeaconStateView {
|
|
688
|
-
assertNativeForkSupported(this.config, block.message.slot);
|
|
689
680
|
const isBlinded = isBlindedBeaconBlock(block.message);
|
|
690
681
|
const signedBlockBytes =
|
|
691
682
|
ssz ??
|
|
@@ -698,7 +689,6 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
698
689
|
}
|
|
699
690
|
|
|
700
691
|
processSlots(slot: Slot, opts?: {dontTransferCache?: boolean}, _modules?: StateTransitionModules): IBeaconStateView {
|
|
701
|
-
assertNativeForkSupported(this.config, slot);
|
|
702
692
|
return new NativeBeaconStateView(this.config, this.binding.processSlots(slot, opts));
|
|
703
693
|
}
|
|
704
694
|
|
|
@@ -908,25 +898,12 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
908
898
|
return this.cachedProposerLookahead;
|
|
909
899
|
}
|
|
910
900
|
|
|
911
|
-
preVerifyBuilderDepositsPreGloas(
|
|
912
|
-
|
|
913
|
-
_maxDurationMs: number
|
|
914
|
-
): PreVerifyBuilderDepositsResult {
|
|
915
|
-
// The native fork upgrade verifies directly; it does not maintain a warm-up cache.
|
|
916
|
-
return {
|
|
917
|
-
validBuilderSignaturesCount: 0,
|
|
918
|
-
invalidBuilderSignaturesCount: 0,
|
|
919
|
-
validValidatorSignaturesCount: 0,
|
|
920
|
-
invalidValidatorSignaturesCount: 0,
|
|
921
|
-
scannedPendingDeposits: 0,
|
|
922
|
-
totalCachedDeposits: 0,
|
|
923
|
-
totalBuilderPubkeys: 0,
|
|
924
|
-
pendingDepositsCount: this.pendingDepositsCount,
|
|
925
|
-
};
|
|
901
|
+
preVerifyBuilderDepositsPreGloas(maxBuilderDeposits: number, maxDurationMs: number): PreVerifyBuilderDepositsResult {
|
|
902
|
+
return this.binding.preVerifyBuilderDepositsPreGloas(maxBuilderDeposits, maxDurationMs);
|
|
926
903
|
}
|
|
927
904
|
|
|
928
905
|
clearPreGloasBuilderDepositCache(): void {
|
|
929
|
-
|
|
906
|
+
this.binding.clearPreGloasBuilderDepositCache();
|
|
930
907
|
}
|
|
931
908
|
|
|
932
909
|
// ─── gloas ───────────────────────────────────────────────────────────────
|
|
@@ -981,6 +958,10 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
981
958
|
return this.binding.canBuilderCoverBid(builderIndex, bidAmount);
|
|
982
959
|
}
|
|
983
960
|
|
|
961
|
+
getBuilderBidLimit(builderIndex: BuilderIndex): number {
|
|
962
|
+
return this.binding.getBuilderBidLimit(builderIndex);
|
|
963
|
+
}
|
|
964
|
+
|
|
984
965
|
getEpochPTCs(epoch: Epoch): Uint32Array[] {
|
|
985
966
|
return this.binding.getEpochPTCs(epoch);
|
|
986
967
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import bindings from "@chainsafe/lodestar-z";
|
|
2
|
-
import {pubkeyCache} from "@chainsafe/lodestar-z/pubkeys";
|
|
3
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
|
+
import bindings from "@lodestar/native";
|
|
3
|
+
import {pubkeyCache} from "@lodestar/native/pubkeys";
|
|
4
4
|
import {createCachedBeaconState} from "../cache/stateCache.js";
|
|
5
|
-
import {
|
|
5
|
+
import {getStateTypeFromBytes} from "../util/sszBytes.js";
|
|
6
6
|
import {BeaconStateView} from "./beaconStateView.js";
|
|
7
7
|
import {IBeaconStateView, IBeaconStateViewNative} from "./interface.js";
|
|
8
|
-
import {NativeBeaconStateView
|
|
8
|
+
import {NativeBeaconStateView} from "./nativeBeaconStateView.js";
|
|
9
9
|
|
|
10
10
|
// ---- createBeaconStateView (startup path) ----
|
|
11
11
|
|
|
@@ -62,7 +62,6 @@ export function createBeaconStateViewForHistoricalRegen(opts: RegenNodeJSOpts |
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
function createNativeBeaconStateView(config: BeaconConfig, stateBytes: Uint8Array): IBeaconStateView {
|
|
65
|
-
assertNativeForkSupported(config, getStateSlotFromBytes(stateBytes));
|
|
66
65
|
const nativeConfig = new bindings.BeaconConfig(config, config.genesisValidatorsRoot);
|
|
67
66
|
return new NativeBeaconStateView(
|
|
68
67
|
config,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {pubkeyCache} from "@
|
|
3
|
+
import {pubkeyCache} from "@lodestar/native/pubkeys";
|
|
4
4
|
import {interopSecretKey} from "../util/interop.js";
|
|
5
5
|
import {testCachePath} from "./cache.js";
|
|
6
6
|
|
package/src/testUtils/state.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {pubkeyCache} from "@chainsafe/lodestar-z/pubkeys";
|
|
2
1
|
import {ChainForkConfig, createBeaconConfig} from "@lodestar/config";
|
|
3
2
|
import {config, config as minimalConfig} from "@lodestar/config/default";
|
|
3
|
+
import {pubkeyCache} from "@lodestar/native/pubkeys";
|
|
4
4
|
import {
|
|
5
5
|
EPOCHS_PER_HISTORICAL_VECTOR,
|
|
6
6
|
EPOCHS_PER_SLASHINGS_VECTOR,
|
package/src/testUtils/util.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {PublicKey, SecretKey} from "@chainsafe/lodestar-z/blst";
|
|
2
|
-
import {pubkeyCache} from "@chainsafe/lodestar-z/pubkeys";
|
|
3
1
|
import {BitArray, fromHexString} from "@chainsafe/ssz";
|
|
4
2
|
import {BeaconConfig, createBeaconConfig, createChainForkConfig} from "@lodestar/config";
|
|
5
3
|
import {config} from "@lodestar/config/default";
|
|
4
|
+
import {PublicKey, SecretKey} from "@lodestar/native/blst";
|
|
5
|
+
import {pubkeyCache} from "@lodestar/native/pubkeys";
|
|
6
6
|
import {
|
|
7
7
|
BUILDER_WITHDRAWAL_PREFIX,
|
|
8
8
|
DOMAIN_DEPOSIT,
|
package/src/util/blindedBlock.ts
CHANGED
|
@@ -33,13 +33,9 @@ export function blindedOrFullBlockHashTreeRoot(
|
|
|
33
33
|
): Root {
|
|
34
34
|
return isBlindedBeaconBlock(blindedOrFull)
|
|
35
35
|
? // Blinded
|
|
36
|
-
config
|
|
37
|
-
.getPostBellatrixForkTypes(blindedOrFull.slot)
|
|
38
|
-
.BlindedBeaconBlock.hashTreeRoot(blindedOrFull)
|
|
36
|
+
config.getPostBellatrixForkTypes(blindedOrFull.slot).BlindedBeaconBlock.hashTreeRoot(blindedOrFull)
|
|
39
37
|
: // Full
|
|
40
|
-
config
|
|
41
|
-
.getForkTypes(blindedOrFull.slot)
|
|
42
|
-
.BeaconBlock.hashTreeRoot(blindedOrFull);
|
|
38
|
+
config.getForkTypes(blindedOrFull.slot).BeaconBlock.hashTreeRoot(blindedOrFull);
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
export function blindedOrFullBlockToHeader(
|
|
@@ -48,13 +44,9 @@ export function blindedOrFullBlockToHeader(
|
|
|
48
44
|
): BeaconBlockHeader {
|
|
49
45
|
const bodyRoot = isBlindedBeaconBlock(blindedOrFull)
|
|
50
46
|
? // Blinded
|
|
51
|
-
config
|
|
52
|
-
.getPostBellatrixForkTypes(blindedOrFull.slot)
|
|
53
|
-
.BlindedBeaconBlockBody.hashTreeRoot(blindedOrFull.body)
|
|
47
|
+
config.getPostBellatrixForkTypes(blindedOrFull.slot).BlindedBeaconBlockBody.hashTreeRoot(blindedOrFull.body)
|
|
54
48
|
: // Full
|
|
55
|
-
config
|
|
56
|
-
.getForkTypes(blindedOrFull.slot)
|
|
57
|
-
.BeaconBlockBody.hashTreeRoot(blindedOrFull.body);
|
|
49
|
+
config.getForkTypes(blindedOrFull.slot).BeaconBlockBody.hashTreeRoot(blindedOrFull.body);
|
|
58
50
|
|
|
59
51
|
return {
|
|
60
52
|
slot: blindedOrFull.slot,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {unshuffleList} from "@chainsafe/lodestar-z/shuffle";
|
|
2
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
|
+
import {unshuffleList} from "@lodestar/native/shuffle";
|
|
3
3
|
import {
|
|
4
4
|
DOMAIN_BEACON_ATTESTER,
|
|
5
5
|
GENESIS_SLOT,
|
|
@@ -54,6 +54,11 @@ export type EpochShuffling = {
|
|
|
54
54
|
* Committees per slot, for fast attestation verification
|
|
55
55
|
*/
|
|
56
56
|
committeesPerSlot: number;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Native committee aggregate pubkeys of this shuffling, set once `computeCommitteePubkeys()` resolves
|
|
60
|
+
*/
|
|
61
|
+
committeePubkeysId?: number;
|
|
57
62
|
};
|
|
58
63
|
|
|
59
64
|
export function computeCommitteeCount(activeValidatorCount: number): number {
|
package/src/util/genesis.ts
CHANGED
|
@@ -8,9 +8,10 @@ import {
|
|
|
8
8
|
GENESIS_EPOCH,
|
|
9
9
|
GENESIS_SLOT,
|
|
10
10
|
MAX_EFFECTIVE_BALANCE,
|
|
11
|
+
MIN_SEED_LOOKAHEAD,
|
|
11
12
|
UNSET_DEPOSIT_REQUESTS_START_INDEX,
|
|
12
13
|
} from "@lodestar/params";
|
|
13
|
-
import {Bytes32, Root, TimeSeconds, phase0, ssz} from "@lodestar/types";
|
|
14
|
+
import {Bytes32, Root, TimeSeconds, ValidatorIndex, phase0, ssz} from "@lodestar/types";
|
|
14
15
|
import {applyDeposit, processDeposit} from "../block/processDeposit.js";
|
|
15
16
|
import {EpochCacheImmutableData} from "../cache/epochCache.js";
|
|
16
17
|
import {createCachedBeaconState} from "../cache/stateCache.js";
|
|
@@ -26,6 +27,7 @@ import {
|
|
|
26
27
|
import {newFilledArray} from "./array.js";
|
|
27
28
|
import {getTemporaryBlockHeader} from "./blockRoot.js";
|
|
28
29
|
import {computeEpochAtSlot} from "./epoch.js";
|
|
30
|
+
import {computeProposerIndices} from "./seed.js";
|
|
29
31
|
import {getNextSyncCommittee} from "./syncCommittee.js";
|
|
30
32
|
import {getActiveValidatorIndices, getMaxEffectiveBalance} from "./validator.js";
|
|
31
33
|
|
|
@@ -352,6 +354,12 @@ export function initializeBeaconStateFromEth1(
|
|
|
352
354
|
// Fulu retires the legacy bridge after the genesis deposits.
|
|
353
355
|
stateFulu.depositRequestsStartIndex = BigInt(stateFulu.eth1DepositIndex);
|
|
354
356
|
}
|
|
357
|
+
const proposerLookahead: ValidatorIndex[] = [];
|
|
358
|
+
for (let epoch = GENESIS_EPOCH; epoch <= GENESIS_EPOCH + MIN_SEED_LOOKAHEAD; epoch++) {
|
|
359
|
+
const activeIndices = getActiveValidatorIndices(state, epoch);
|
|
360
|
+
proposerLookahead.push(...computeProposerIndices(fork, state, {activeIndices}, epoch));
|
|
361
|
+
}
|
|
362
|
+
stateFulu.proposerLookahead = ssz.fulu.ProposerLookahead.toViewDU(proposerLookahead);
|
|
355
363
|
}
|
|
356
364
|
|
|
357
365
|
if (fork >= ForkSeq.gloas) {
|
package/src/util/gloas.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {computePayloadTimelinessCommitteesForEpoch} from "./seed.js";
|
|
|
25
25
|
import {createSingleSignatureSetFromComponents, verifySignatureSet} from "./signatureSets.js";
|
|
26
26
|
import {computeSigningRoot} from "./signingRoot.js";
|
|
27
27
|
import {getActiveValidatorIndices} from "./validator.js";
|
|
28
|
+
import {ETH_TO_GWEI} from "./weakSubjectivity.js";
|
|
28
29
|
|
|
29
30
|
export function isBuilderWithdrawalCredential(withdrawalCredentials: Uint8Array): boolean {
|
|
30
31
|
return withdrawalCredentials[0] === BUILDER_WITHDRAWAL_PREFIX;
|
|
@@ -161,6 +162,16 @@ export function canBuilderCoverBid(
|
|
|
161
162
|
return builder.balance - minBalance >= bidAmount;
|
|
162
163
|
}
|
|
163
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Return the number of bids the builder may submit for each slot and parent.
|
|
167
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-beta.5/specs/gloas/p2p-interface.md#new-get_builder_bid_limit
|
|
168
|
+
*/
|
|
169
|
+
export function getBuilderBidLimit(state: CachedBeaconStateGloas, builderIndex: BuilderIndex): number {
|
|
170
|
+
const builder = state.builders.getReadonly(builderIndex);
|
|
171
|
+
const pendingBalance = getPendingBalanceToWithdrawForBuilder(state, builderIndex);
|
|
172
|
+
return Math.floor(Math.max(builder.balance - pendingBalance, 0) / ETH_TO_GWEI);
|
|
173
|
+
}
|
|
174
|
+
|
|
164
175
|
/**
|
|
165
176
|
* Initiate a builder exit by setting their withdrawable epoch.
|
|
166
177
|
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-initiate_builder_exit
|
package/src/util/interop.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {toBufferBE} from "@vekexasia/bigint-buffer2";
|
|
2
2
|
import {digest} from "@chainsafe/as-sha256";
|
|
3
|
-
import {SecretKey} from "@
|
|
3
|
+
import {SecretKey} from "@lodestar/native/blst";
|
|
4
4
|
import {bytesToBigInt, intToBytes} from "@lodestar/utils";
|
|
5
5
|
|
|
6
6
|
let curveOrder: bigint;
|
package/src/util/seed.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
computePtcIndicesForEpoch,
|
|
4
4
|
computeProposerIndex as nativeComputeProposerIndex,
|
|
5
5
|
computeSyncCommitteeIndices as nativeComputeSyncCommitteeIndices,
|
|
6
|
-
} from "@
|
|
6
|
+
} from "@lodestar/native/shuffle";
|
|
7
7
|
import {
|
|
8
8
|
DOMAIN_BEACON_PROPOSER,
|
|
9
9
|
DOMAIN_PTC_ATTESTER,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {BitArray} from "@chainsafe/ssz";
|
|
2
|
+
import {BLS_VERIFIER_SET_TYPE, type BlsSignatureSet, verifySignatureSets} from "@lodestar/native/bls-verifier";
|
|
3
|
+
import {Root, Slot} from "@lodestar/types";
|
|
3
4
|
|
|
4
5
|
export enum SignatureSetType {
|
|
5
6
|
single = "single",
|
|
@@ -9,6 +10,11 @@ export enum SignatureSetType {
|
|
|
9
10
|
* Pubkey lookup is deferred to verification time.
|
|
10
11
|
*/
|
|
11
12
|
indexed = "indexed",
|
|
13
|
+
/**
|
|
14
|
+
* Aggregate signature of an attestation over whole committees of one slot.
|
|
15
|
+
* Pubkeys come from the committee aggregates of the shuffling, see `computeCommitteePubkeys()`.
|
|
16
|
+
*/
|
|
17
|
+
committee = "committee",
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
/**
|
|
@@ -44,7 +50,22 @@ export type AggregatedSignatureSet = {
|
|
|
44
50
|
signature: Uint8Array;
|
|
45
51
|
};
|
|
46
52
|
|
|
47
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Aggregate signature of an attestation over the committees `committeeIndices` of `slot`.
|
|
55
|
+
* `indices` lists the participants, aggregated instead when the committee pubkeys are not cached.
|
|
56
|
+
*/
|
|
57
|
+
export type CommitteeSignatureSet = {
|
|
58
|
+
type: SignatureSetType.committee;
|
|
59
|
+
indices: number[];
|
|
60
|
+
committeePubkeysId: number;
|
|
61
|
+
slot: Slot;
|
|
62
|
+
committeeIndices: number[];
|
|
63
|
+
aggregationBits: BitArray;
|
|
64
|
+
signingRoot: Root;
|
|
65
|
+
signature: Uint8Array;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type ISignatureSet = SingleSignatureSet | IndexedSignatureSet | AggregatedSignatureSet | CommitteeSignatureSet;
|
|
48
69
|
|
|
49
70
|
export function toBlsSignatureSet(signatureSet: ISignatureSet): BlsSignatureSet {
|
|
50
71
|
switch (signatureSet.type) {
|
|
@@ -81,6 +102,28 @@ export function toBlsSignatureSet(signatureSet: ISignatureSet): BlsSignatureSet
|
|
|
81
102
|
};
|
|
82
103
|
}
|
|
83
104
|
|
|
105
|
+
case SignatureSetType.committee: {
|
|
106
|
+
const indices = new Uint32Array(signatureSet.indices.length);
|
|
107
|
+
for (const [i, index] of signatureSet.indices.entries()) {
|
|
108
|
+
if (!Number.isInteger(index) || index < 0 || index > 0xffffffff) {
|
|
109
|
+
throw new RangeError(`Invalid validator index ${index}`);
|
|
110
|
+
}
|
|
111
|
+
indices[i] = index;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
type: BLS_VERIFIER_SET_TYPE.committee,
|
|
116
|
+
indices,
|
|
117
|
+
committeePubkeysId: signatureSet.committeePubkeysId,
|
|
118
|
+
slot: signatureSet.slot,
|
|
119
|
+
committeeIndices: Uint32Array.from(signatureSet.committeeIndices),
|
|
120
|
+
aggregationBits: signatureSet.aggregationBits.uint8Array,
|
|
121
|
+
bitLen: signatureSet.aggregationBits.bitLen,
|
|
122
|
+
message: signatureSet.signingRoot,
|
|
123
|
+
signature: signatureSet.signature,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
84
127
|
default:
|
|
85
128
|
throw Error("Unknown signature set type");
|
|
86
129
|
}
|