@aztec/stdlib 2.1.0-rc.2 → 2.1.0-rc.21
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/dest/block/attestation_info.d.ts +30 -0
- package/dest/block/attestation_info.d.ts.map +1 -0
- package/dest/block/attestation_info.js +39 -0
- package/dest/block/index.d.ts +1 -0
- package/dest/block/index.d.ts.map +1 -1
- package/dest/block/index.js +1 -0
- package/dest/block/l2_block_source.d.ts +29 -0
- package/dest/block/l2_block_source.d.ts.map +1 -1
- package/dest/block/published_l2_block.d.ts +0 -2
- package/dest/block/published_l2_block.d.ts.map +1 -1
- package/dest/block/published_l2_block.js +0 -6
- package/dest/interfaces/archiver.d.ts.map +1 -1
- package/dest/interfaces/archiver.js +7 -0
- package/dest/interfaces/aztec-node-admin.d.ts +38 -34
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-admin.js +2 -2
- package/dest/interfaces/aztec-node.d.ts +24 -0
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +4 -0
- package/dest/interfaces/configs.d.ts +5 -0
- package/dest/interfaces/configs.d.ts.map +1 -1
- package/dest/interfaces/configs.js +2 -1
- package/dest/interfaces/p2p.d.ts +2 -0
- package/dest/interfaces/p2p.d.ts.map +1 -1
- package/dest/interfaces/p2p.js +2 -1
- package/dest/interfaces/tx_provider.d.ts +1 -1
- package/dest/interfaces/tx_provider.d.ts.map +1 -1
- package/dest/interfaces/validator.d.ts +93 -1
- package/dest/interfaces/validator.d.ts.map +1 -1
- package/dest/interfaces/validator.js +6 -0
- package/dest/p2p/block_attestation.d.ts +44 -9
- package/dest/p2p/block_attestation.d.ts.map +1 -1
- package/dest/p2p/block_attestation.js +35 -16
- package/dest/p2p/block_proposal.d.ts +4 -8
- package/dest/p2p/block_proposal.d.ts.map +1 -1
- package/dest/p2p/block_proposal.js +10 -13
- package/dest/p2p/gossipable.d.ts +2 -4
- package/dest/p2p/gossipable.d.ts.map +1 -1
- package/dest/p2p/gossipable.js +5 -14
- package/dest/tests/mocks.d.ts +3 -1
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +33 -11
- package/dest/zkpassport/index.d.ts +15 -9
- package/dest/zkpassport/index.d.ts.map +1 -1
- package/dest/zkpassport/index.js +17 -11
- package/package.json +9 -9
- package/src/block/attestation_info.ts +62 -0
- package/src/block/index.ts +1 -0
- package/src/block/l2_block_source.ts +32 -0
- package/src/block/published_l2_block.ts +0 -11
- package/src/interfaces/archiver.ts +8 -0
- package/src/interfaces/aztec-node-admin.ts +2 -2
- package/src/interfaces/aztec-node.ts +36 -0
- package/src/interfaces/configs.ts +3 -0
- package/src/interfaces/p2p.ts +4 -0
- package/src/interfaces/tx_provider.ts +1 -0
- package/src/interfaces/validator.ts +14 -1
- package/src/p2p/block_attestation.ts +43 -16
- package/src/p2p/block_proposal.ts +9 -16
- package/src/p2p/gossipable.ts +6 -16
- package/src/tests/mocks.ts +53 -17
- package/src/zkpassport/index.ts +40 -28
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { keccak256,
|
|
2
|
+
import { keccak256, tryRecoverAddress } from '@aztec/foundation/crypto';
|
|
3
3
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
5
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
@@ -8,7 +8,6 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
|
8
8
|
import type { L2BlockInfo } from '../block/l2_block_info.js';
|
|
9
9
|
import { TxHash } from '../tx/index.js';
|
|
10
10
|
import { Tx } from '../tx/tx.js';
|
|
11
|
-
import type { UInt32 } from '../types/index.js';
|
|
12
11
|
import { ConsensusPayload } from './consensus_payload.js';
|
|
13
12
|
import { Gossipable } from './gossipable.js';
|
|
14
13
|
import {
|
|
@@ -40,9 +39,6 @@ export class BlockProposal extends Gossipable {
|
|
|
40
39
|
private sender: EthAddress | undefined;
|
|
41
40
|
|
|
42
41
|
constructor(
|
|
43
|
-
/** The number of the block */
|
|
44
|
-
public readonly blockNumber: UInt32,
|
|
45
|
-
|
|
46
42
|
/** The payload of the message, and what the signature is over */
|
|
47
43
|
public readonly payload: ConsensusPayload,
|
|
48
44
|
|
|
@@ -71,9 +67,8 @@ export class BlockProposal extends Gossipable {
|
|
|
71
67
|
return this.payload.header.slotNumber;
|
|
72
68
|
}
|
|
73
69
|
|
|
74
|
-
toBlockInfo(): L2BlockInfo {
|
|
70
|
+
toBlockInfo(): Omit<L2BlockInfo, 'blockNumber'> {
|
|
75
71
|
return {
|
|
76
|
-
blockNumber: this.blockNumber,
|
|
77
72
|
slotNumber: this.slotNumber.toNumber(),
|
|
78
73
|
lastArchive: this.payload.header.lastArchiveRoot,
|
|
79
74
|
timestamp: this.payload.header.timestamp,
|
|
@@ -83,7 +78,6 @@ export class BlockProposal extends Gossipable {
|
|
|
83
78
|
}
|
|
84
79
|
|
|
85
80
|
static async createProposalFromSigner(
|
|
86
|
-
blockNumber: UInt32,
|
|
87
81
|
payload: ConsensusPayload,
|
|
88
82
|
txHashes: TxHash[],
|
|
89
83
|
// Note(md): Provided separately to tx hashes such that this function can be optional
|
|
@@ -93,17 +87,18 @@ export class BlockProposal extends Gossipable {
|
|
|
93
87
|
const hashed = getHashedSignaturePayload(payload, SignatureDomainSeparator.blockProposal);
|
|
94
88
|
const sig = await payloadSigner(hashed);
|
|
95
89
|
|
|
96
|
-
return new BlockProposal(
|
|
90
|
+
return new BlockProposal(payload, sig, txHashes, txs);
|
|
97
91
|
}
|
|
98
92
|
|
|
99
93
|
/**Get Sender
|
|
100
94
|
* Lazily evaluate the sender of the proposal; result is cached
|
|
95
|
+
* @returns The sender address, or undefined if signature recovery fails
|
|
101
96
|
*/
|
|
102
|
-
getSender() {
|
|
97
|
+
getSender(): EthAddress | undefined {
|
|
103
98
|
if (!this.sender) {
|
|
104
99
|
const hashed = getHashedSignaturePayloadEthSignedMessage(this.payload, SignatureDomainSeparator.blockProposal);
|
|
105
100
|
// Cache the sender for later use
|
|
106
|
-
this.sender =
|
|
101
|
+
this.sender = tryRecoverAddress(hashed, this.signature);
|
|
107
102
|
}
|
|
108
103
|
|
|
109
104
|
return this.sender;
|
|
@@ -114,7 +109,7 @@ export class BlockProposal extends Gossipable {
|
|
|
114
109
|
}
|
|
115
110
|
|
|
116
111
|
toBuffer(): Buffer {
|
|
117
|
-
const buffer: any[] = [this.
|
|
112
|
+
const buffer: any[] = [this.payload, this.signature, this.txHashes.length, this.txHashes];
|
|
118
113
|
if (this.txs) {
|
|
119
114
|
buffer.push(this.txs.length);
|
|
120
115
|
buffer.push(this.txs);
|
|
@@ -125,22 +120,20 @@ export class BlockProposal extends Gossipable {
|
|
|
125
120
|
static fromBuffer(buf: Buffer | BufferReader): BlockProposal {
|
|
126
121
|
const reader = BufferReader.asReader(buf);
|
|
127
122
|
|
|
128
|
-
const blockNumber = reader.readNumber();
|
|
129
123
|
const payload = reader.readObject(ConsensusPayload);
|
|
130
124
|
const sig = reader.readObject(Signature);
|
|
131
125
|
const txHashes = reader.readArray(reader.readNumber(), TxHash);
|
|
132
126
|
|
|
133
127
|
if (!reader.isEmpty()) {
|
|
134
128
|
const txs = reader.readArray(reader.readNumber(), Tx);
|
|
135
|
-
return new BlockProposal(
|
|
129
|
+
return new BlockProposal(payload, sig, txHashes, txs);
|
|
136
130
|
}
|
|
137
131
|
|
|
138
|
-
return new BlockProposal(
|
|
132
|
+
return new BlockProposal(payload, sig, txHashes);
|
|
139
133
|
}
|
|
140
134
|
|
|
141
135
|
getSize(): number {
|
|
142
136
|
return (
|
|
143
|
-
4 /* blockNumber */ +
|
|
144
137
|
this.payload.getSize() +
|
|
145
138
|
this.signature.getSize() +
|
|
146
139
|
4 /* txHashes.length */ +
|
package/src/p2p/gossipable.ts
CHANGED
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { BufferReader,
|
|
2
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
3
|
|
|
4
4
|
import type { TopicType } from './topic_type.js';
|
|
5
5
|
|
|
6
6
|
export class P2PMessage {
|
|
7
|
-
constructor(
|
|
8
|
-
public readonly publishTime: Date,
|
|
9
|
-
public readonly id: Buffer32,
|
|
10
|
-
public readonly payload: Buffer,
|
|
11
|
-
) {}
|
|
7
|
+
constructor(public readonly payload: Buffer) {}
|
|
12
8
|
|
|
13
|
-
static
|
|
14
|
-
return new P2PMessage(
|
|
9
|
+
static fromGossipable(message: Gossipable): P2PMessage {
|
|
10
|
+
return new P2PMessage(message.toBuffer());
|
|
15
11
|
}
|
|
16
12
|
|
|
17
13
|
static fromMessageData(messageData: Buffer): P2PMessage {
|
|
18
14
|
const reader = new BufferReader(messageData);
|
|
19
|
-
const publishTime = reader.readUInt64();
|
|
20
|
-
const id = Buffer32.fromBuffer(reader);
|
|
21
15
|
const payload = reader.readBuffer();
|
|
22
|
-
return new P2PMessage(
|
|
16
|
+
return new P2PMessage(payload);
|
|
23
17
|
}
|
|
24
18
|
|
|
25
19
|
toMessageData(): Buffer {
|
|
26
|
-
return serializeToBuffer([
|
|
27
|
-
bigintToUInt64BE(BigInt(this.publishTime.getTime())),
|
|
28
|
-
this.id,
|
|
29
|
-
serializeToBuffer(this.payload.length, this.payload),
|
|
30
|
-
]);
|
|
20
|
+
return serializeToBuffer([serializeToBuffer(this.payload.length, this.payload)]);
|
|
31
21
|
}
|
|
32
22
|
}
|
|
33
23
|
|
package/src/tests/mocks.ts
CHANGED
|
@@ -248,6 +248,8 @@ export const randomDeployedContract = async () => {
|
|
|
248
248
|
|
|
249
249
|
export interface MakeConsensusPayloadOptions {
|
|
250
250
|
signer?: Secp256k1Signer;
|
|
251
|
+
attesterSigner?: Secp256k1Signer;
|
|
252
|
+
proposerSigner?: Secp256k1Signer;
|
|
251
253
|
header?: BlockHeader;
|
|
252
254
|
archive?: Fr;
|
|
253
255
|
stateReference?: StateReference;
|
|
@@ -286,31 +288,65 @@ export const makeAndSignCommitteeAttestationsAndSigners = (
|
|
|
286
288
|
};
|
|
287
289
|
|
|
288
290
|
export const makeBlockProposal = (options?: MakeConsensusPayloadOptions): BlockProposal => {
|
|
289
|
-
const {
|
|
290
|
-
SignatureDomainSeparator.blockProposal,
|
|
291
|
-
options,
|
|
292
|
-
);
|
|
291
|
+
const { payload, signature } = makeAndSignConsensusPayload(SignatureDomainSeparator.blockProposal, options);
|
|
293
292
|
const txHashes = options?.txHashes ?? [0, 1, 2, 3, 4, 5].map(() => TxHash.random());
|
|
294
|
-
return new BlockProposal(
|
|
293
|
+
return new BlockProposal(payload, signature, txHashes, options?.txs ?? []);
|
|
295
294
|
};
|
|
296
295
|
|
|
297
296
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/8028)
|
|
298
297
|
export const makeBlockAttestation = (options?: MakeConsensusPayloadOptions): BlockAttestation => {
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
298
|
+
const header = options?.header ?? makeHeader(1);
|
|
299
|
+
const {
|
|
300
|
+
signer,
|
|
301
|
+
attesterSigner = signer ?? Secp256k1Signer.random(),
|
|
302
|
+
proposerSigner = signer ?? Secp256k1Signer.random(),
|
|
303
|
+
archive = Fr.random(),
|
|
304
|
+
stateReference = header.state,
|
|
305
|
+
} = options ?? {};
|
|
306
|
+
|
|
307
|
+
const payload = ConsensusPayload.fromFields({
|
|
308
|
+
header: header.toPropose(),
|
|
309
|
+
archive,
|
|
310
|
+
stateReference,
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// Sign as attester
|
|
314
|
+
const attestationHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockAttestation);
|
|
315
|
+
const attestationSignature = attesterSigner.sign(attestationHash);
|
|
316
|
+
|
|
317
|
+
// Sign as proposer
|
|
318
|
+
const proposalHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockProposal);
|
|
319
|
+
const proposerSignature = proposerSigner.sign(proposalHash);
|
|
320
|
+
|
|
321
|
+
return new BlockAttestation(payload, attestationSignature, proposerSignature);
|
|
304
322
|
};
|
|
305
323
|
|
|
306
|
-
export const makeBlockAttestationFromBlock = (
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
324
|
+
export const makeBlockAttestationFromBlock = (
|
|
325
|
+
block: L2Block,
|
|
326
|
+
attesterSigner?: Secp256k1Signer,
|
|
327
|
+
proposerSigner?: Secp256k1Signer,
|
|
328
|
+
): BlockAttestation => {
|
|
329
|
+
const header = block.header;
|
|
330
|
+
const archive = block.archive.root;
|
|
331
|
+
const stateReference = block.header.state;
|
|
332
|
+
|
|
333
|
+
const payload = ConsensusPayload.fromFields({
|
|
334
|
+
header: header.toPropose(),
|
|
335
|
+
archive,
|
|
336
|
+
stateReference,
|
|
313
337
|
});
|
|
338
|
+
|
|
339
|
+
// Sign as attester
|
|
340
|
+
const attestationHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockAttestation);
|
|
341
|
+
const attestationSigner = attesterSigner ?? Secp256k1Signer.random();
|
|
342
|
+
const attestationSignature = attestationSigner.sign(attestationHash);
|
|
343
|
+
|
|
344
|
+
// Sign as proposer
|
|
345
|
+
const proposalHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockProposal);
|
|
346
|
+
const proposalSignerToUse = proposerSigner ?? Secp256k1Signer.random();
|
|
347
|
+
const proposerSignature = proposalSignerToUse.sign(proposalHash);
|
|
348
|
+
|
|
349
|
+
return new BlockAttestation(payload, attestationSignature, proposerSignature);
|
|
314
350
|
};
|
|
315
351
|
|
|
316
352
|
export async function randomPublishedL2Block(
|
package/src/zkpassport/index.ts
CHANGED
|
@@ -5,15 +5,21 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
|
5
5
|
import { withoutHexPrefix } from '@aztec/foundation/string';
|
|
6
6
|
|
|
7
7
|
export type ViemZkPassportProofParams = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
proofVerificationData: {
|
|
9
|
+
vkeyHash: `0x${string}`;
|
|
10
|
+
proof: `0x${string}`;
|
|
11
|
+
publicInputs: `0x${string}`[];
|
|
12
|
+
};
|
|
13
|
+
commitments: {
|
|
14
|
+
committedInputs: `0x${string}`;
|
|
15
|
+
committedInputCounts: bigint[];
|
|
16
|
+
};
|
|
17
|
+
serviceConfig: {
|
|
18
|
+
validityPeriodInSeconds: bigint;
|
|
19
|
+
domain: string;
|
|
20
|
+
scope: string;
|
|
21
|
+
devMode: boolean;
|
|
22
|
+
};
|
|
17
23
|
};
|
|
18
24
|
|
|
19
25
|
// NOTE: Must match the ZkPassportProofParams struct in the zkpassport verifier contract
|
|
@@ -64,7 +70,7 @@ export class ZkPassportProofParams {
|
|
|
64
70
|
publicInputs,
|
|
65
71
|
committedInputs,
|
|
66
72
|
committedInputCounts,
|
|
67
|
-
BigInt(
|
|
73
|
+
BigInt(7 * 24 * 60 * 60), // 7 days
|
|
68
74
|
'sequencer.alpha-testnet.aztec.network',
|
|
69
75
|
'personhood',
|
|
70
76
|
);
|
|
@@ -87,29 +93,35 @@ export class ZkPassportProofParams {
|
|
|
87
93
|
|
|
88
94
|
static fromViem(params: ViemZkPassportProofParams) {
|
|
89
95
|
return new ZkPassportProofParams(
|
|
90
|
-
params.devMode,
|
|
91
|
-
Buffer32.fromString(params.vkeyHash),
|
|
92
|
-
Buffer.from(withoutHexPrefix(params.proof), 'hex'),
|
|
93
|
-
params.publicInputs.map(input => Fr.fromString(input)),
|
|
94
|
-
Buffer.from(withoutHexPrefix(params.committedInputs), 'hex'),
|
|
95
|
-
params.committedInputCounts,
|
|
96
|
-
params.validityPeriodInSeconds,
|
|
97
|
-
params.domain,
|
|
98
|
-
params.scope,
|
|
96
|
+
params.serviceConfig.devMode,
|
|
97
|
+
Buffer32.fromString(params.proofVerificationData.vkeyHash),
|
|
98
|
+
Buffer.from(withoutHexPrefix(params.proofVerificationData.proof), 'hex'),
|
|
99
|
+
params.proofVerificationData.publicInputs.map(input => Fr.fromString(input)),
|
|
100
|
+
Buffer.from(withoutHexPrefix(params.commitments.committedInputs), 'hex'),
|
|
101
|
+
params.commitments.committedInputCounts,
|
|
102
|
+
params.serviceConfig.validityPeriodInSeconds,
|
|
103
|
+
params.serviceConfig.domain,
|
|
104
|
+
params.serviceConfig.scope,
|
|
99
105
|
);
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
toViem(): ViemZkPassportProofParams {
|
|
103
109
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
serviceConfig: {
|
|
111
|
+
devMode: this.devMode,
|
|
112
|
+
validityPeriodInSeconds: this.validityPeriodInSeconds,
|
|
113
|
+
domain: this.domain,
|
|
114
|
+
scope: this.scope,
|
|
115
|
+
},
|
|
116
|
+
proofVerificationData: {
|
|
117
|
+
vkeyHash: this.vkeyHash.toString(),
|
|
118
|
+
proof: `0x${this.proof.toString('hex')}`,
|
|
119
|
+
publicInputs: this.publicInputs.map(input => input.toString()),
|
|
120
|
+
},
|
|
121
|
+
commitments: {
|
|
122
|
+
committedInputs: `0x${this.committedInputs.toString('hex')}`,
|
|
123
|
+
committedInputCounts: this.committedInputCounts,
|
|
124
|
+
},
|
|
113
125
|
};
|
|
114
126
|
}
|
|
115
127
|
}
|