@aztec/stdlib 2.1.0-rc.20 → 2.1.0-rc.22

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.
Files changed (38) hide show
  1. package/dest/block/l2_block_source.d.ts +29 -0
  2. package/dest/block/l2_block_source.d.ts.map +1 -1
  3. package/dest/interfaces/archiver.d.ts +1 -1
  4. package/dest/interfaces/archiver.d.ts.map +1 -1
  5. package/dest/interfaces/archiver.js +7 -0
  6. package/dest/interfaces/aztec-node-admin.d.ts +35 -34
  7. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  8. package/dest/interfaces/aztec-node-admin.js +2 -2
  9. package/dest/interfaces/aztec-node.d.ts +24 -0
  10. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  11. package/dest/interfaces/aztec-node.js +4 -0
  12. package/dest/interfaces/tx_provider.d.ts +1 -1
  13. package/dest/interfaces/tx_provider.d.ts.map +1 -1
  14. package/dest/interfaces/validator.d.ts +93 -1
  15. package/dest/interfaces/validator.d.ts.map +1 -1
  16. package/dest/interfaces/validator.js +6 -0
  17. package/dest/p2p/block_attestation.d.ts +4 -15
  18. package/dest/p2p/block_attestation.d.ts.map +1 -1
  19. package/dest/p2p/block_attestation.js +11 -26
  20. package/dest/p2p/block_proposal.d.ts +4 -8
  21. package/dest/p2p/block_proposal.d.ts.map +1 -1
  22. package/dest/p2p/block_proposal.js +10 -13
  23. package/dest/tests/mocks.d.ts.map +1 -1
  24. package/dest/tests/mocks.js +4 -4
  25. package/dest/zkpassport/index.d.ts +15 -9
  26. package/dest/zkpassport/index.d.ts.map +1 -1
  27. package/dest/zkpassport/index.js +17 -11
  28. package/package.json +8 -8
  29. package/src/block/l2_block_source.ts +32 -0
  30. package/src/interfaces/archiver.ts +9 -1
  31. package/src/interfaces/aztec-node-admin.ts +2 -2
  32. package/src/interfaces/aztec-node.ts +36 -0
  33. package/src/interfaces/tx_provider.ts +1 -0
  34. package/src/interfaces/validator.ts +14 -1
  35. package/src/p2p/block_attestation.ts +12 -36
  36. package/src/p2p/block_proposal.ts +9 -16
  37. package/src/tests/mocks.ts +4 -7
  38. package/src/zkpassport/index.ts +40 -28
@@ -1,5 +1,5 @@
1
1
  import { Buffer32 } from '@aztec/foundation/buffer';
2
- import { keccak256, recoverAddress } from '@aztec/foundation/crypto';
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';
@@ -7,8 +7,7 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
7
7
 
8
8
  import { z } from 'zod';
9
9
 
10
- import { type ZodFor, schemas } from '../schemas/index.js';
11
- import type { UInt32 } from '../types/index.js';
10
+ import type { ZodFor } from '../schemas/index.js';
12
11
  import { ConsensusPayload } from './consensus_payload.js';
13
12
  import { Gossipable } from './gossipable.js';
14
13
  import { SignatureDomainSeparator, getHashedSignaturePayloadEthSignedMessage } from './signature_utils.js';
@@ -33,9 +32,6 @@ export class BlockAttestation extends Gossipable {
33
32
  private proposer: EthAddress | undefined;
34
33
 
35
34
  constructor(
36
- /** The block number of the attestation. */
37
- public readonly blockNumber: UInt32,
38
-
39
35
  /** The payload of the message, and what the signature is over */
40
36
  public readonly payload: ConsensusPayload,
41
37
 
@@ -51,12 +47,11 @@ export class BlockAttestation extends Gossipable {
51
47
  static get schema(): ZodFor<BlockAttestation> {
52
48
  return z
53
49
  .object({
54
- blockNumber: schemas.UInt32,
55
50
  payload: ConsensusPayload.schema,
56
51
  signature: Signature.schema,
57
52
  proposerSignature: Signature.schema,
58
53
  })
59
- .transform(obj => new BlockAttestation(obj.blockNumber, obj.payload, obj.signature, obj.proposerSignature));
54
+ .transform(obj => new BlockAttestation(obj.payload, obj.signature, obj.proposerSignature));
60
55
  }
61
56
 
62
57
  override generateP2PMessageIdentifier(): Promise<Buffer32> {
@@ -73,41 +68,29 @@ export class BlockAttestation extends Gossipable {
73
68
 
74
69
  /**
75
70
  * Lazily evaluate and cache the signer of the attestation
76
- * @returns The signer of the attestation
71
+ * @returns The signer of the attestation, or undefined if signature recovery fails
77
72
  */
78
- getSender(): EthAddress {
73
+ getSender(): EthAddress | undefined {
79
74
  if (!this.sender) {
80
75
  // Recover the sender from the attestation
81
76
  const hashed = getHashedSignaturePayloadEthSignedMessage(this.payload, SignatureDomainSeparator.blockAttestation);
82
77
  // Cache the sender for later use
83
- this.sender = recoverAddress(hashed, this.signature);
78
+ this.sender = tryRecoverAddress(hashed, this.signature);
84
79
  }
85
80
 
86
81
  return this.sender;
87
82
  }
88
83
 
89
- /**
90
- * Tries to get the sender of the attestation
91
- * @returns The sender of the attestation or undefined if it fails during recovery
92
- */
93
- tryGetSender(): EthAddress | undefined {
94
- try {
95
- return this.getSender();
96
- } catch {
97
- return undefined;
98
- }
99
- }
100
-
101
84
  /**
102
85
  * Lazily evaluate and cache the proposer of the block
103
86
  * @returns The proposer of the block
104
87
  */
105
- getProposer(): EthAddress {
88
+ getProposer(): EthAddress | undefined {
106
89
  if (!this.proposer) {
107
90
  // Recover the proposer from the proposal signature
108
91
  const hashed = getHashedSignaturePayloadEthSignedMessage(this.payload, SignatureDomainSeparator.blockProposal);
109
92
  // Cache the proposer for later use
110
- this.proposer = recoverAddress(hashed, this.proposerSignature);
93
+ this.proposer = tryRecoverAddress(hashed, this.proposerSignature);
111
94
  }
112
95
 
113
96
  return this.proposer;
@@ -118,13 +101,12 @@ export class BlockAttestation extends Gossipable {
118
101
  }
119
102
 
120
103
  toBuffer(): Buffer {
121
- return serializeToBuffer([this.blockNumber, this.payload, this.signature, this.proposerSignature]);
104
+ return serializeToBuffer([this.payload, this.signature, this.proposerSignature]);
122
105
  }
123
106
 
124
107
  static fromBuffer(buf: Buffer | BufferReader): BlockAttestation {
125
108
  const reader = BufferReader.asReader(buf);
126
109
  return new BlockAttestation(
127
- reader.readNumber(),
128
110
  reader.readObject(ConsensusPayload),
129
111
  reader.readObject(Signature),
130
112
  reader.readObject(Signature),
@@ -132,25 +114,19 @@ export class BlockAttestation extends Gossipable {
132
114
  }
133
115
 
134
116
  static empty(): BlockAttestation {
135
- return new BlockAttestation(0, ConsensusPayload.empty(), Signature.empty(), Signature.empty());
117
+ return new BlockAttestation(ConsensusPayload.empty(), Signature.empty(), Signature.empty());
136
118
  }
137
119
 
138
120
  static random(): BlockAttestation {
139
- return new BlockAttestation(
140
- Math.floor(Math.random() * 1000) + 1,
141
- ConsensusPayload.random(),
142
- Signature.random(),
143
- Signature.random(),
144
- );
121
+ return new BlockAttestation(ConsensusPayload.random(), Signature.random(), Signature.random());
145
122
  }
146
123
 
147
124
  getSize(): number {
148
- return 4 /* blockNumber */ + this.payload.getSize() + this.signature.getSize() + this.proposerSignature.getSize();
125
+ return this.payload.getSize() + this.signature.getSize() + this.proposerSignature.getSize();
149
126
  }
150
127
 
151
128
  toInspect() {
152
129
  return {
153
- blockNumber: this.blockNumber,
154
130
  payload: this.payload.toInspect(),
155
131
  signature: this.signature.toString(),
156
132
  proposerSignature: this.proposerSignature.toString(),
@@ -1,5 +1,5 @@
1
1
  import { Buffer32 } from '@aztec/foundation/buffer';
2
- import { keccak256, recoverAddress } from '@aztec/foundation/crypto';
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(blockNumber, payload, sig, txHashes, txs);
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 = recoverAddress(hashed, this.signature);
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.blockNumber, this.payload, this.signature, this.txHashes.length, this.txHashes];
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(blockNumber, payload, sig, txHashes, txs);
129
+ return new BlockProposal(payload, sig, txHashes, txs);
136
130
  }
137
131
 
138
- return new BlockProposal(blockNumber, payload, sig, txHashes);
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 */ +
@@ -288,12 +288,9 @@ export const makeAndSignCommitteeAttestationsAndSigners = (
288
288
  };
289
289
 
290
290
  export const makeBlockProposal = (options?: MakeConsensusPayloadOptions): BlockProposal => {
291
- const { blockNumber, payload, signature } = makeAndSignConsensusPayload(
292
- SignatureDomainSeparator.blockProposal,
293
- options,
294
- );
291
+ const { payload, signature } = makeAndSignConsensusPayload(SignatureDomainSeparator.blockProposal, options);
295
292
  const txHashes = options?.txHashes ?? [0, 1, 2, 3, 4, 5].map(() => TxHash.random());
296
- return new BlockProposal(blockNumber, payload, signature, txHashes, options?.txs ?? []);
293
+ return new BlockProposal(payload, signature, txHashes, options?.txs ?? []);
297
294
  };
298
295
 
299
296
  // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8028)
@@ -321,7 +318,7 @@ export const makeBlockAttestation = (options?: MakeConsensusPayloadOptions): Blo
321
318
  const proposalHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockProposal);
322
319
  const proposerSignature = proposerSigner.sign(proposalHash);
323
320
 
324
- return new BlockAttestation(header.globalVariables.blockNumber, payload, attestationSignature, proposerSignature);
321
+ return new BlockAttestation(payload, attestationSignature, proposerSignature);
325
322
  };
326
323
 
327
324
  export const makeBlockAttestationFromBlock = (
@@ -349,7 +346,7 @@ export const makeBlockAttestationFromBlock = (
349
346
  const proposalSignerToUse = proposerSigner ?? Secp256k1Signer.random();
350
347
  const proposerSignature = proposalSignerToUse.sign(proposalHash);
351
348
 
352
- return new BlockAttestation(header.globalVariables.blockNumber, payload, attestationSignature, proposerSignature);
349
+ return new BlockAttestation(payload, attestationSignature, proposerSignature);
353
350
  };
354
351
 
355
352
  export async function randomPublishedL2Block(
@@ -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
- vkeyHash: `0x${string}`;
9
- proof: `0x${string}`;
10
- publicInputs: `0x${string}`[];
11
- committedInputs: `0x${string}`;
12
- committedInputCounts: bigint[];
13
- validityPeriodInSeconds: bigint;
14
- domain: string;
15
- scope: string;
16
- devMode: boolean;
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(100 * 60 * 60 * 24),
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
- devMode: this.devMode,
105
- vkeyHash: this.vkeyHash.toString(),
106
- proof: `0x${this.proof.toString('hex')}`,
107
- publicInputs: this.publicInputs.map(input => input.toString()),
108
- committedInputs: `0x${this.committedInputs.toString('hex')}`,
109
- committedInputCounts: this.committedInputCounts,
110
- validityPeriodInSeconds: this.validityPeriodInSeconds,
111
- domain: this.domain,
112
- scope: this.scope,
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
  }