@lodestar/state-transition 1.40.0-dev.c7b6a784da → 1.40.0-dev.cfd894719f
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/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 +2 -2
- package/lib/block/processAttestationsAltair.js.map +1 -1
- package/lib/block/processExecutionPayloadBid.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadBid.js +4 -4
- package/lib/block/processExecutionPayloadBid.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 +5 -5
- package/lib/block/processSyncCommittee.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 +5 -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 +2 -2
- package/lib/signatureSets/indexedPayloadAttestation.js +1 -1
- 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/util/gloas.d.ts +10 -9
- package/lib/util/gloas.d.ts.map +1 -1
- 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/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/package.json +7 -7
- package/src/block/isValidIndexedAttestation.ts +3 -2
- package/src/block/isValidIndexedPayloadAttestation.ts +4 -1
- package/src/block/processAttestationsAltair.ts +2 -8
- package/src/block/processExecutionPayloadBid.ts +4 -4
- package/src/block/processProposerSlashing.ts +2 -2
- package/src/block/processSyncCommittee.ts +3 -6
- package/src/signatureSets/attesterSlashings.ts +3 -7
- package/src/signatureSets/blsToExecutionChange.ts +3 -3
- package/src/signatureSets/executionPayloadBid.ts +15 -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 +3 -3
- 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/util/gloas.ts +19 -11
- package/src/util/index.ts +1 -0
- package/src/util/signatureSets.ts +84 -8
|
@@ -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
|
};
|