@lodestar/state-transition 1.40.0-dev.3be9500fa9 → 1.40.0-dev.45b04262dc
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 -0
- package/lib/block/index.d.ts.map +1 -1
- package/lib/block/index.js +1 -0
- package/lib/block/index.js.map +1 -1
- package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
- package/lib/block/isValidIndexedAttestation.js +2 -2
- package/lib/block/isValidIndexedAttestation.js.map +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.d.ts.map +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -1
- package/lib/block/processAttestationsAltair.d.ts.map +1 -1
- package/lib/block/processAttestationsAltair.js +3 -4
- package/lib/block/processAttestationsAltair.js.map +1 -1
- package/lib/block/processBlockHeader.d.ts.map +1 -1
- package/lib/block/processBlockHeader.js +1 -2
- package/lib/block/processBlockHeader.js.map +1 -1
- package/lib/block/processBlsToExecutionChange.d.ts.map +1 -1
- package/lib/block/processBlsToExecutionChange.js +1 -2
- package/lib/block/processBlsToExecutionChange.js.map +1 -1
- package/lib/block/processConsolidationRequest.d.ts +1 -2
- package/lib/block/processConsolidationRequest.d.ts.map +1 -1
- package/lib/block/processConsolidationRequest.js +5 -4
- package/lib/block/processConsolidationRequest.js.map +1 -1
- package/lib/block/processDepositRequest.d.ts +8 -2
- package/lib/block/processDepositRequest.d.ts.map +1 -1
- package/lib/block/processDepositRequest.js +81 -8
- package/lib/block/processDepositRequest.js.map +1 -1
- package/lib/block/processExecutionPayload.d.ts.map +1 -1
- package/lib/block/processExecutionPayload.js +1 -2
- package/lib/block/processExecutionPayload.js.map +1 -1
- package/lib/block/processExecutionPayloadBid.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadBid.js +17 -31
- package/lib/block/processExecutionPayloadBid.js.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.js +27 -27
- package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
- package/lib/block/processOperations.js +2 -2
- package/lib/block/processOperations.js.map +1 -1
- package/lib/block/processPayloadAttestation.d.ts.map +1 -1
- package/lib/block/processPayloadAttestation.js +1 -1
- package/lib/block/processPayloadAttestation.js.map +1 -1
- package/lib/block/processProposerSlashing.js +2 -2
- package/lib/block/processProposerSlashing.js.map +1 -1
- package/lib/block/processSyncCommittee.d.ts +1 -2
- package/lib/block/processSyncCommittee.d.ts.map +1 -1
- package/lib/block/processSyncCommittee.js +6 -6
- package/lib/block/processSyncCommittee.js.map +1 -1
- package/lib/block/processVoluntaryExit.d.ts +1 -1
- package/lib/block/processVoluntaryExit.d.ts.map +1 -1
- package/lib/block/processVoluntaryExit.js +45 -3
- package/lib/block/processVoluntaryExit.js.map +1 -1
- package/lib/block/processWithdrawalRequest.js +1 -1
- package/lib/block/processWithdrawalRequest.js.map +1 -1
- package/lib/block/processWithdrawals.d.ts +1 -0
- package/lib/block/processWithdrawals.d.ts.map +1 -1
- package/lib/block/processWithdrawals.js +122 -68
- package/lib/block/processWithdrawals.js.map +1 -1
- package/lib/epoch/processBuilderPendingPayments.d.ts.map +1 -1
- package/lib/epoch/processBuilderPendingPayments.js +1 -4
- package/lib/epoch/processBuilderPendingPayments.js.map +1 -1
- package/lib/epoch/processPendingAttestations.d.ts.map +1 -1
- package/lib/epoch/processPendingAttestations.js +1 -1
- package/lib/epoch/processPendingAttestations.js.map +1 -1
- package/lib/signatureSets/attesterSlashings.d.ts +3 -4
- package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
- package/lib/signatureSets/attesterSlashings.js +6 -6
- package/lib/signatureSets/attesterSlashings.js.map +1 -1
- package/lib/signatureSets/blsToExecutionChange.d.ts +3 -3
- package/lib/signatureSets/blsToExecutionChange.d.ts.map +1 -1
- package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
- package/lib/signatureSets/executionPayloadBid.d.ts +4 -0
- package/lib/signatureSets/executionPayloadBid.d.ts.map +1 -0
- package/lib/signatureSets/executionPayloadBid.js +8 -0
- package/lib/signatureSets/executionPayloadBid.js.map +1 -0
- package/lib/signatureSets/executionPayloadEnvelope.d.ts +4 -0
- package/lib/signatureSets/executionPayloadEnvelope.d.ts.map +1 -0
- package/lib/signatureSets/executionPayloadEnvelope.js +8 -0
- package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -0
- package/lib/signatureSets/index.d.ts +3 -2
- package/lib/signatureSets/index.d.ts.map +1 -1
- package/lib/signatureSets/index.js +10 -8
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/signatureSets/indexedAttestation.d.ts +3 -4
- package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
- package/lib/signatureSets/indexedAttestation.js +6 -6
- package/lib/signatureSets/indexedAttestation.js.map +1 -1
- package/lib/signatureSets/indexedPayloadAttestation.d.ts +5 -4
- package/lib/signatureSets/indexedPayloadAttestation.d.ts.map +1 -1
- package/lib/signatureSets/indexedPayloadAttestation.js +3 -3
- package/lib/signatureSets/indexedPayloadAttestation.js.map +1 -1
- package/lib/signatureSets/proposer.d.ts +3 -3
- package/lib/signatureSets/proposer.d.ts.map +1 -1
- package/lib/signatureSets/proposer.js +12 -12
- package/lib/signatureSets/proposer.js.map +1 -1
- package/lib/signatureSets/proposerSlashings.d.ts +2 -3
- package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
- package/lib/signatureSets/proposerSlashings.js +6 -6
- package/lib/signatureSets/proposerSlashings.js.map +1 -1
- package/lib/signatureSets/randao.d.ts +1 -1
- package/lib/signatureSets/randao.d.ts.map +1 -1
- package/lib/signatureSets/randao.js +4 -4
- 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 +6 -6
- package/lib/signatureSets/voluntaryExits.js.map +1 -1
- package/lib/slot/index.d.ts.map +1 -1
- package/lib/slot/index.js +1 -1
- package/lib/slot/index.js.map +1 -1
- package/lib/util/electra.d.ts.map +1 -1
- package/lib/util/electra.js +1 -2
- package/lib/util/electra.js.map +1 -1
- package/lib/util/gloas.d.ts +46 -5
- package/lib/util/gloas.d.ts.map +1 -1
- package/lib/util/gloas.js +92 -6
- package/lib/util/gloas.js.map +1 -1
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +1 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/interop.js +1 -1
- package/lib/util/interop.js.map +1 -1
- package/lib/util/loadState/findModifiedInactivityScores.d.ts +1 -1
- package/lib/util/loadState/findModifiedInactivityScores.d.ts.map +1 -1
- package/lib/util/loadState/findModifiedInactivityScores.js +3 -2
- package/lib/util/loadState/findModifiedInactivityScores.js.map +1 -1
- package/lib/util/loadState/findModifiedValidators.d.ts +2 -2
- package/lib/util/loadState/findModifiedValidators.d.ts.map +1 -1
- package/lib/util/loadState/findModifiedValidators.js +4 -3
- package/lib/util/loadState/findModifiedValidators.js.map +1 -1
- package/lib/util/loadState/loadValidator.d.ts.map +1 -1
- package/lib/util/loadState/loadValidator.js +3 -2
- package/lib/util/loadState/loadValidator.js.map +1 -1
- package/lib/util/signatureSets.d.ts +38 -5
- package/lib/util/signatureSets.d.ts.map +1 -1
- package/lib/util/signatureSets.js +48 -6
- package/lib/util/signatureSets.js.map +1 -1
- package/lib/util/validator.d.ts +6 -1
- package/lib/util/validator.d.ts.map +1 -1
- package/lib/util/validator.js +26 -16
- package/lib/util/validator.js.map +1 -1
- package/package.json +8 -8
- package/src/block/index.ts +1 -0
- package/src/block/isValidIndexedAttestation.ts +3 -2
- package/src/block/isValidIndexedPayloadAttestation.ts +4 -1
- package/src/block/processAttestationsAltair.ts +3 -10
- package/src/block/processBlockHeader.ts +1 -2
- package/src/block/processBlsToExecutionChange.ts +1 -2
- package/src/block/processConsolidationRequest.ts +5 -5
- package/src/block/processDepositRequest.ts +101 -8
- package/src/block/processExecutionPayload.ts +1 -2
- package/src/block/processExecutionPayloadBid.ts +21 -44
- package/src/block/processExecutionPayloadEnvelope.ts +35 -32
- package/src/block/processOperations.ts +2 -2
- package/src/block/processPayloadAttestation.ts +1 -1
- package/src/block/processProposerSlashing.ts +2 -2
- package/src/block/processSyncCommittee.ts +4 -7
- package/src/block/processVoluntaryExit.ts +60 -5
- package/src/block/processWithdrawalRequest.ts +1 -1
- package/src/block/processWithdrawals.ts +169 -72
- package/src/epoch/processBuilderPendingPayments.ts +1 -5
- package/src/epoch/processPendingAttestations.ts +1 -1
- package/src/signatureSets/attesterSlashings.ts +3 -7
- package/src/signatureSets/blsToExecutionChange.ts +3 -3
- package/src/signatureSets/executionPayloadBid.ts +14 -0
- package/src/signatureSets/executionPayloadEnvelope.ts +13 -0
- package/src/signatureSets/index.ts +8 -9
- package/src/signatureSets/indexedAttestation.ts +2 -7
- package/src/signatureSets/indexedPayloadAttestation.ts +9 -7
- package/src/signatureSets/proposer.ts +8 -12
- package/src/signatureSets/proposerSlashings.ts +4 -7
- package/src/signatureSets/randao.ts +4 -8
- package/src/signatureSets/voluntaryExits.ts +5 -10
- package/src/slot/index.ts +1 -1
- package/src/util/electra.ts +1 -4
- package/src/util/gloas.ts +117 -11
- package/src/util/index.ts +1 -0
- package/src/util/interop.ts +1 -1
- package/src/util/loadState/findModifiedInactivityScores.ts +4 -2
- package/src/util/loadState/findModifiedValidators.ts +4 -3
- package/src/util/loadState/loadValidator.ts +3 -2
- package/src/util/signatureSets.ts +84 -8
- package/src/util/validator.ts +31 -16
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import {PublicKey, Signature, fastAggregateVerify, verify} from "@chainsafe/blst";
|
|
1
|
+
import {PublicKey, Signature, aggregatePublicKeys, fastAggregateVerify, verify} from "@chainsafe/blst";
|
|
2
2
|
import {Root} from "@lodestar/types";
|
|
3
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
3
4
|
|
|
4
5
|
export enum SignatureSetType {
|
|
5
6
|
single = "single",
|
|
6
7
|
aggregate = "aggregate",
|
|
8
|
+
/**
|
|
9
|
+
* Single signature with validator index instead of pubkey.
|
|
10
|
+
* Pubkey lookup is deferred to verification time.
|
|
11
|
+
*/
|
|
12
|
+
indexed = "indexed",
|
|
7
13
|
}
|
|
8
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Single signature with pubkey directly.
|
|
17
|
+
* Used when pubkey comes from the message itself (e.g. BLS to execution change).
|
|
18
|
+
*/
|
|
9
19
|
export type SingleSignatureSet = {
|
|
10
20
|
type: SignatureSetType.single;
|
|
11
21
|
pubkey: PublicKey;
|
|
@@ -13,16 +23,57 @@ export type SingleSignatureSet = {
|
|
|
13
23
|
signature: Uint8Array;
|
|
14
24
|
};
|
|
15
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Single signature with validator index.
|
|
28
|
+
* Pubkey is looked up at verification time.
|
|
29
|
+
*/
|
|
30
|
+
export type IndexedSignatureSet = {
|
|
31
|
+
type: SignatureSetType.indexed;
|
|
32
|
+
index: number;
|
|
33
|
+
signingRoot: Root;
|
|
34
|
+
signature: Uint8Array;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Aggregate signature with validator indices.
|
|
39
|
+
* Pubkeys are looked up and aggregated at verification time.
|
|
40
|
+
*/
|
|
16
41
|
export type AggregatedSignatureSet = {
|
|
17
42
|
type: SignatureSetType.aggregate;
|
|
18
|
-
|
|
43
|
+
indices: number[];
|
|
19
44
|
signingRoot: Root;
|
|
20
45
|
signature: Uint8Array;
|
|
21
46
|
};
|
|
22
47
|
|
|
23
|
-
export type ISignatureSet = SingleSignatureSet | AggregatedSignatureSet;
|
|
48
|
+
export type ISignatureSet = SingleSignatureSet | IndexedSignatureSet | AggregatedSignatureSet;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the pubkey for a signature set, performing aggregation if necessary.
|
|
52
|
+
* Requires index2pubkey cache for indexed and aggregate sets.
|
|
53
|
+
*/
|
|
54
|
+
export function getSignatureSetPubkey(signatureSet: ISignatureSet, index2pubkey: Index2PubkeyCache): PublicKey {
|
|
55
|
+
switch (signatureSet.type) {
|
|
56
|
+
case SignatureSetType.single:
|
|
57
|
+
return signatureSet.pubkey;
|
|
58
|
+
|
|
59
|
+
case SignatureSetType.indexed:
|
|
60
|
+
return index2pubkey[signatureSet.index];
|
|
61
|
+
|
|
62
|
+
case SignatureSetType.aggregate: {
|
|
63
|
+
const pubkeys = signatureSet.indices.map((i) => index2pubkey[i]);
|
|
64
|
+
return aggregatePublicKeys(pubkeys);
|
|
65
|
+
}
|
|
24
66
|
|
|
25
|
-
|
|
67
|
+
default:
|
|
68
|
+
throw Error("Unknown signature set type");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function verifySignatureSet(signatureSet: SingleSignatureSet, index2pubkey?: Index2PubkeyCache): boolean;
|
|
73
|
+
export function verifySignatureSet(signatureSet: IndexedSignatureSet, index2pubkey: Index2PubkeyCache): boolean;
|
|
74
|
+
export function verifySignatureSet(signatureSet: AggregatedSignatureSet, index2pubkey: Index2PubkeyCache): boolean;
|
|
75
|
+
export function verifySignatureSet(signatureSet: ISignatureSet, index2pubkey: Index2PubkeyCache): boolean;
|
|
76
|
+
export function verifySignatureSet(signatureSet: ISignatureSet, index2pubkey?: Index2PubkeyCache): boolean {
|
|
26
77
|
// All signatures are not trusted and must be group checked (p2.subgroup_check)
|
|
27
78
|
const signature = Signature.fromBytes(signatureSet.signature, true);
|
|
28
79
|
|
|
@@ -30,8 +81,20 @@ export function verifySignatureSet(signatureSet: ISignatureSet): boolean {
|
|
|
30
81
|
case SignatureSetType.single:
|
|
31
82
|
return verify(signatureSet.signingRoot, signatureSet.pubkey, signature);
|
|
32
83
|
|
|
33
|
-
case SignatureSetType.
|
|
34
|
-
|
|
84
|
+
case SignatureSetType.indexed: {
|
|
85
|
+
if (!index2pubkey) {
|
|
86
|
+
throw Error("index2pubkey required for indexed signature set");
|
|
87
|
+
}
|
|
88
|
+
return verify(signatureSet.signingRoot, index2pubkey[signatureSet.index], signature);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
case SignatureSetType.aggregate: {
|
|
92
|
+
if (!index2pubkey) {
|
|
93
|
+
throw Error("index2pubkey required for aggregate signature set");
|
|
94
|
+
}
|
|
95
|
+
const pubkeys = signatureSet.indices.map((i) => index2pubkey[i]);
|
|
96
|
+
return fastAggregateVerify(signatureSet.signingRoot, pubkeys, signature);
|
|
97
|
+
}
|
|
35
98
|
|
|
36
99
|
default:
|
|
37
100
|
throw Error("Unknown signature set type");
|
|
@@ -51,14 +114,27 @@ export function createSingleSignatureSetFromComponents(
|
|
|
51
114
|
};
|
|
52
115
|
}
|
|
53
116
|
|
|
117
|
+
export function createIndexedSignatureSetFromComponents(
|
|
118
|
+
index: number,
|
|
119
|
+
signingRoot: Root,
|
|
120
|
+
signature: Uint8Array
|
|
121
|
+
): IndexedSignatureSet {
|
|
122
|
+
return {
|
|
123
|
+
type: SignatureSetType.indexed,
|
|
124
|
+
index,
|
|
125
|
+
signingRoot,
|
|
126
|
+
signature,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
54
130
|
export function createAggregateSignatureSetFromComponents(
|
|
55
|
-
|
|
131
|
+
indices: number[],
|
|
56
132
|
signingRoot: Root,
|
|
57
133
|
signature: Uint8Array
|
|
58
134
|
): AggregatedSignatureSet {
|
|
59
135
|
return {
|
|
60
136
|
type: SignatureSetType.aggregate,
|
|
61
|
-
|
|
137
|
+
indices,
|
|
62
138
|
signingRoot,
|
|
63
139
|
signature,
|
|
64
140
|
};
|
package/src/util/validator.ts
CHANGED
|
@@ -2,13 +2,15 @@ import {ChainForkConfig} from "@lodestar/config";
|
|
|
2
2
|
import {
|
|
3
3
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
4
4
|
ForkSeq,
|
|
5
|
+
MAX_EFFECTIVE_BALANCE,
|
|
5
6
|
MAX_EFFECTIVE_BALANCE_ELECTRA,
|
|
6
7
|
MIN_ACTIVATION_BALANCE,
|
|
7
8
|
} from "@lodestar/params";
|
|
8
9
|
import {Epoch, ValidatorIndex, phase0} from "@lodestar/types";
|
|
9
10
|
import {intDiv} from "@lodestar/utils";
|
|
10
11
|
import {BeaconStateAllForks, CachedBeaconStateElectra, CachedBeaconStateGloas, EpochCache} from "../types.js";
|
|
11
|
-
import {
|
|
12
|
+
import {hasEth1WithdrawalCredential} from "./capella.js";
|
|
13
|
+
import {hasCompoundingWithdrawalCredential, hasExecutionWithdrawalCredential} from "./electra.js";
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Check if [[validator]] is active
|
|
@@ -94,8 +96,35 @@ export function getMaxEffectiveBalance(withdrawalCredentials: Uint8Array): numbe
|
|
|
94
96
|
return MIN_ACTIVATION_BALANCE;
|
|
95
97
|
}
|
|
96
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Check if validator is partially withdrawable.
|
|
101
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/electra/beacon-chain.md#modified-is_partially_withdrawable_validator
|
|
102
|
+
*/
|
|
103
|
+
export function isPartiallyWithdrawableValidator(fork: ForkSeq, validator: phase0.Validator, balance: number): boolean {
|
|
104
|
+
const isPostElectra = fork >= ForkSeq.electra;
|
|
105
|
+
|
|
106
|
+
// Check withdrawal credentials
|
|
107
|
+
const hasWithdrawableCredentials = isPostElectra
|
|
108
|
+
? hasExecutionWithdrawalCredential(validator.withdrawalCredentials)
|
|
109
|
+
: hasEth1WithdrawalCredential(validator.withdrawalCredentials);
|
|
110
|
+
|
|
111
|
+
if (!hasWithdrawableCredentials) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Get max effective balance based on fork
|
|
116
|
+
const maxEffectiveBalance = isPostElectra
|
|
117
|
+
? getMaxEffectiveBalance(validator.withdrawalCredentials)
|
|
118
|
+
: MAX_EFFECTIVE_BALANCE;
|
|
119
|
+
|
|
120
|
+
// Check if at max effective balance and has excess balance
|
|
121
|
+
const hasMaxEffectiveBalance = validator.effectiveBalance === maxEffectiveBalance;
|
|
122
|
+
const hasExcessBalance = balance > maxEffectiveBalance;
|
|
123
|
+
|
|
124
|
+
return hasMaxEffectiveBalance && hasExcessBalance;
|
|
125
|
+
}
|
|
126
|
+
|
|
97
127
|
export function getPendingBalanceToWithdraw(
|
|
98
|
-
fork: ForkSeq,
|
|
99
128
|
state: CachedBeaconStateElectra | CachedBeaconStateGloas,
|
|
100
129
|
validatorIndex: ValidatorIndex
|
|
101
130
|
): number {
|
|
@@ -106,19 +135,5 @@ export function getPendingBalanceToWithdraw(
|
|
|
106
135
|
}
|
|
107
136
|
}
|
|
108
137
|
|
|
109
|
-
if (fork >= ForkSeq.gloas) {
|
|
110
|
-
const stateGloas = state as CachedBeaconStateGloas;
|
|
111
|
-
for (const item of stateGloas.builderPendingWithdrawals.getAllReadonly()) {
|
|
112
|
-
if (item.builderIndex === validatorIndex) {
|
|
113
|
-
total += item.amount;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
for (const item of stateGloas.builderPendingPayments.getAllReadonly()) {
|
|
117
|
-
if (item.withdrawal.builderIndex === validatorIndex) {
|
|
118
|
-
total += item.withdrawal.amount;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
138
|
return total;
|
|
124
139
|
}
|