@lodestar/state-transition 1.52.0-dev.b76fc9b708 → 1.52.0-dev.b9e2dc8d93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/block/index.d.ts.map +1 -1
- package/lib/block/index.js +1 -1
- package/lib/block/index.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 +2 -2
- package/lib/block/processExecutionPayloadBid.js.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 +14 -5
- 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/upgradeStateToGloas.d.ts.map +1 -1
- package/lib/slot/upgradeStateToGloas.js +2 -0
- package/lib/slot/upgradeStateToGloas.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 +1 -0
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/interface.js.map +1 -1
- package/lib/stateView/nativeBeaconStateView.d.ts +1 -0
- package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.js +3 -0
- package/lib/stateView/nativeBeaconStateView.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.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/signatureSets.d.ts +23 -3
- package/lib/util/signatureSets.d.ts.map +1 -1
- package/lib/util/signatureSets.js +25 -0
- package/lib/util/signatureSets.js.map +1 -1
- package/package.json +9 -9
- package/src/block/index.ts +2 -1
- package/src/block/processExecutionPayloadBid.ts +3 -2
- package/src/signatureSets/index.ts +29 -5
- package/src/signatureSets/indexedAttestation.ts +32 -6
- package/src/slot/upgradeStateToGloas.ts +2 -0
- package/src/slot/upgradeStateToHeze.ts +0 -6
- package/src/stateView/beaconStateView.ts +9 -1
- package/src/stateView/interface.ts +1 -0
- package/src/stateView/nativeBeaconStateView.ts +4 -0
- package/src/util/epochShuffling.ts +5 -0
- package/src/util/gloas.ts +11 -0
- package/src/util/signatureSets.ts +45 -2
|
@@ -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
|
}
|
|
@@ -115,6 +115,8 @@ export function upgradeStateToGloas(
|
|
|
115
115
|
for (let i = 0; i < SLOTS_PER_HISTORICAL_ROOT; i++) {
|
|
116
116
|
stateGloasView.executionPayloadAvailability.set(i, true);
|
|
117
117
|
}
|
|
118
|
+
// process_slot of the last pre-fork slot ran with Fulu rules and did not unset the fork slot
|
|
119
|
+
stateGloasView.executionPayloadAvailability.set(stateFulu.slot % SLOTS_PER_HISTORICAL_ROOT, false);
|
|
118
120
|
stateGloasView.latestBlockHash = stateFulu.latestExecutionPayloadHeader.blockHash;
|
|
119
121
|
|
|
120
122
|
const stateGloas = getCachedBeaconState(stateGloasView, stateFulu);
|
|
@@ -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[];
|
|
@@ -958,6 +958,10 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
958
958
|
return this.binding.canBuilderCoverBid(builderIndex, bidAmount);
|
|
959
959
|
}
|
|
960
960
|
|
|
961
|
+
getBuilderBidLimit(builderIndex: BuilderIndex): number {
|
|
962
|
+
return this.binding.getBuilderBidLimit(builderIndex);
|
|
963
|
+
}
|
|
964
|
+
|
|
961
965
|
getEpochPTCs(epoch: Epoch): Uint32Array[] {
|
|
962
966
|
return this.binding.getEpochPTCs(epoch);
|
|
963
967
|
}
|
|
@@ -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/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
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import {BitArray} from "@chainsafe/ssz";
|
|
1
2
|
import {BLS_VERIFIER_SET_TYPE, type BlsSignatureSet, verifySignatureSets} from "@lodestar/native/bls-verifier";
|
|
2
|
-
import {Root} from "@lodestar/types";
|
|
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
|
}
|