@aztec/stdlib 0.80.0 → 0.81.0

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 (109) hide show
  1. package/dest/abi/contract_artifact.d.ts.map +1 -1
  2. package/dest/abi/contract_artifact.js +11 -0
  3. package/dest/avm/avm.d.ts +173 -405
  4. package/dest/avm/avm.d.ts.map +1 -1
  5. package/dest/avm/avm.js +34 -27
  6. package/dest/avm/avm_proving_request.d.ts +84 -186
  7. package/dest/avm/avm_proving_request.d.ts.map +1 -1
  8. package/dest/avm/public_data_write.d.ts +1 -0
  9. package/dest/avm/public_data_write.d.ts.map +1 -1
  10. package/dest/avm/public_data_write.js +3 -0
  11. package/dest/block/body.d.ts +1 -0
  12. package/dest/block/body.d.ts.map +1 -1
  13. package/dest/block/body.js +3 -0
  14. package/dest/block/index.d.ts +1 -0
  15. package/dest/block/index.d.ts.map +1 -1
  16. package/dest/block/index.js +1 -0
  17. package/dest/block/l2_block.d.ts +2 -1
  18. package/dest/block/l2_block.d.ts.map +1 -1
  19. package/dest/block/l2_block.js +3 -0
  20. package/dest/block/l2_block_downloader/l2_block_stream.d.ts +3 -3
  21. package/dest/block/l2_block_downloader/l2_block_stream.d.ts.map +1 -1
  22. package/dest/block/l2_block_downloader/l2_block_stream.js +2 -2
  23. package/dest/block/l2_block_source.d.ts +3 -0
  24. package/dest/block/l2_block_source.d.ts.map +1 -1
  25. package/dest/block/published_l2_block.d.ts +89 -0
  26. package/dest/block/published_l2_block.d.ts.map +1 -0
  27. package/dest/block/published_l2_block.js +32 -0
  28. package/dest/contract/interfaces/contract_data_source.d.ts +3 -9
  29. package/dest/contract/interfaces/contract_data_source.d.ts.map +1 -1
  30. package/dest/database-version/version_manager.js +1 -1
  31. package/dest/interfaces/archiver.d.ts.map +1 -1
  32. package/dest/interfaces/archiver.js +4 -3
  33. package/dest/interfaces/aztec-node.d.ts +1 -1
  34. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  35. package/dest/interfaces/aztec-node.js +2 -0
  36. package/dest/interfaces/proving-job.d.ts +106 -208
  37. package/dest/interfaces/proving-job.d.ts.map +1 -1
  38. package/dest/logs/contract_class_log.d.ts +1 -0
  39. package/dest/logs/contract_class_log.d.ts.map +1 -1
  40. package/dest/logs/contract_class_log.js +3 -0
  41. package/dest/logs/l1_payload/index.d.ts +1 -1
  42. package/dest/logs/l1_payload/index.d.ts.map +1 -1
  43. package/dest/logs/l1_payload/index.js +1 -1
  44. package/dest/logs/private_log.d.ts +2 -1
  45. package/dest/logs/private_log.d.ts.map +1 -1
  46. package/dest/logs/private_log.js +14 -3
  47. package/dest/logs/public_log.d.ts.map +1 -1
  48. package/dest/logs/public_log.js +4 -1
  49. package/dest/logs/tx_scoped_l2_log.d.ts +16 -28
  50. package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
  51. package/dest/logs/tx_scoped_l2_log.js +28 -19
  52. package/dest/note/extended_note.d.ts +10 -21
  53. package/dest/note/extended_note.d.ts.map +1 -1
  54. package/dest/note/extended_note.js +19 -28
  55. package/dest/note/notes_filter.d.ts +2 -2
  56. package/dest/note/notes_filter.d.ts.map +1 -1
  57. package/dest/note/notes_filter.js +1 -1
  58. package/dest/p2p/consensus_payload.d.ts +3 -1
  59. package/dest/p2p/consensus_payload.d.ts.map +1 -1
  60. package/dest/p2p/consensus_payload.js +3 -0
  61. package/dest/proofs/proof.d.ts +0 -1
  62. package/dest/proofs/proof.d.ts.map +1 -1
  63. package/dest/proofs/proof.js +2 -7
  64. package/dest/rollup/block_root_rollup.d.ts +1 -1
  65. package/dest/tests/factories.d.ts +3 -2
  66. package/dest/tests/factories.d.ts.map +1 -1
  67. package/dest/tests/factories.js +14 -8
  68. package/dest/tests/mocks.d.ts +2 -2
  69. package/dest/tests/mocks.d.ts.map +1 -1
  70. package/dest/tests/mocks.js +4 -5
  71. package/dest/trees/nullifier_membership_witness.d.ts +7 -7
  72. package/dest/trees/public_data_witness.d.ts +7 -7
  73. package/dest/tx/capsule.d.ts +2 -0
  74. package/dest/tx/capsule.d.ts.map +1 -1
  75. package/dest/tx/capsule.js +2 -0
  76. package/dest/tx/tx_effect.d.ts +1 -0
  77. package/dest/tx/tx_effect.d.ts.map +1 -1
  78. package/dest/tx/tx_effect.js +4 -1
  79. package/package.json +6 -6
  80. package/src/abi/contract_artifact.ts +11 -0
  81. package/src/avm/avm.ts +42 -39
  82. package/src/avm/public_data_write.ts +4 -0
  83. package/src/block/body.ts +6 -0
  84. package/src/block/index.ts +1 -0
  85. package/src/block/l2_block.ts +4 -0
  86. package/src/block/l2_block_downloader/l2_block_stream.ts +5 -5
  87. package/src/block/l2_block_source.ts +4 -0
  88. package/src/block/published_l2_block.ts +45 -0
  89. package/src/contract/interfaces/contract_data_source.ts +3 -10
  90. package/src/database-version/version_manager.ts +1 -1
  91. package/src/interfaces/archiver.ts +9 -6
  92. package/src/interfaces/aztec-node.ts +4 -1
  93. package/src/logs/contract_class_log.ts +8 -0
  94. package/src/logs/l1_payload/index.ts +1 -1
  95. package/src/logs/private_log.ts +13 -3
  96. package/src/logs/public_log.ts +11 -1
  97. package/src/logs/tx_scoped_l2_log.ts +28 -25
  98. package/src/note/extended_note.ts +17 -36
  99. package/src/note/notes_filter.ts +3 -3
  100. package/src/p2p/consensus_payload.ts +9 -0
  101. package/src/proofs/proof.ts +2 -8
  102. package/src/tests/factories.ts +15 -14
  103. package/src/tests/mocks.ts +4 -9
  104. package/src/tx/capsule.ts +2 -0
  105. package/src/tx/tx_effect.ts +23 -1
  106. package/dest/logs/l1_payload/l1_note_payload.d.ts +0 -82
  107. package/dest/logs/l1_payload/l1_note_payload.d.ts.map +0 -1
  108. package/dest/logs/l1_payload/l1_note_payload.js +0 -129
  109. package/src/logs/l1_payload/l1_note_payload.ts +0 -182
@@ -4,7 +4,6 @@ import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';
4
4
 
5
5
  import { z } from 'zod';
6
6
 
7
- import { NoteSelector } from '../abi/note_selector.js';
8
7
  import { AztecAddress } from '../aztec-address/index.js';
9
8
  import { type ZodFor, schemas } from '../schemas/index.js';
10
9
  import { TxHash } from '../tx/tx_hash.js';
@@ -17,54 +16,43 @@ export class ExtendedNote {
17
16
  constructor(
18
17
  /** The note as emitted from the Noir contract. */
19
18
  public note: Note,
20
- /** The owner whose public key was used to encrypt the note. */
21
- public owner: AztecAddress,
19
+ /** The address whose public key was used to encrypt the note. */
20
+ public recipient: AztecAddress,
22
21
  /** The contract address this note is created in. */
23
22
  public contractAddress: AztecAddress,
24
23
  /** The specific storage location of the note on the contract. */
25
24
  public storageSlot: Fr,
26
- /** The type identifier of the note on the contract. */
27
- public noteTypeId: NoteSelector,
28
25
  /** The hash of the tx the note was created in. */
29
26
  public txHash: TxHash,
30
27
  ) {}
31
28
 
32
29
  toBuffer(): Buffer {
33
- return serializeToBuffer([
34
- this.note,
35
- this.owner,
36
- this.contractAddress,
37
- this.storageSlot,
38
- this.noteTypeId,
39
- this.txHash,
40
- ]);
30
+ return serializeToBuffer([this.note, this.recipient, this.contractAddress, this.storageSlot, this.txHash]);
41
31
  }
42
32
 
43
33
  static fromBuffer(buffer: Buffer | BufferReader) {
44
34
  const reader = BufferReader.asReader(buffer);
45
35
 
46
36
  const note = reader.readObject(Note);
47
- const owner = reader.readObject(AztecAddress);
37
+ const recipient = reader.readObject(AztecAddress);
48
38
  const contractAddress = reader.readObject(AztecAddress);
49
39
  const storageSlot = reader.readObject(Fr);
50
- const noteTypeId = reader.readObject(NoteSelector);
51
40
  const txHash = reader.readObject(TxHash);
52
41
 
53
- return new this(note, owner, contractAddress, storageSlot, noteTypeId, txHash);
42
+ return new this(note, recipient, contractAddress, storageSlot, txHash);
54
43
  }
55
44
 
56
45
  static get schema(): ZodFor<ExtendedNote> {
57
46
  return z
58
47
  .object({
59
48
  note: Note.schema,
60
- owner: schemas.AztecAddress,
49
+ recipient: schemas.AztecAddress,
61
50
  contractAddress: schemas.AztecAddress,
62
51
  storageSlot: schemas.Fr,
63
- noteTypeId: schemas.NoteSelector,
64
52
  txHash: TxHash.schema,
65
53
  })
66
- .transform(({ note, owner, contractAddress, storageSlot, noteTypeId, txHash }) => {
67
- return new ExtendedNote(note, owner, contractAddress, storageSlot, noteTypeId, txHash);
54
+ .transform(({ note, recipient, contractAddress, storageSlot, txHash }) => {
55
+ return new ExtendedNote(note, recipient, contractAddress, storageSlot, txHash);
68
56
  });
69
57
  }
70
58
 
@@ -82,7 +70,6 @@ export class ExtendedNote {
82
70
  await AztecAddress.random(),
83
71
  await AztecAddress.random(),
84
72
  Fr.random(),
85
- NoteSelector.random(),
86
73
  TxHash.random(),
87
74
  );
88
75
  }
@@ -92,45 +79,41 @@ export class UniqueNote extends ExtendedNote {
92
79
  constructor(
93
80
  /** The note as emitted from the Noir contract. */
94
81
  note: Note,
95
- /** The owner whose public key was used to encrypt the note. */
96
- owner: AztecAddress,
82
+ /** The recipient whose public key was used to encrypt the note. */
83
+ recipient: AztecAddress,
97
84
  /** The contract address this note is created in. */
98
85
  contractAddress: AztecAddress,
99
86
  /** The specific storage location of the note on the contract. */
100
87
  storageSlot: Fr,
101
- /** The type identifier of the note on the contract. */
102
- noteTypeId: NoteSelector,
103
88
  /** The hash of the tx the note was created in. */
104
89
  txHash: TxHash,
105
90
  /** The nonce of the note. */
106
91
  public nonce: Fr,
107
92
  ) {
108
- super(note, owner, contractAddress, storageSlot, noteTypeId, txHash);
93
+ super(note, recipient, contractAddress, storageSlot, txHash);
109
94
  }
110
95
 
111
96
  static override get schema() {
112
97
  return z
113
98
  .object({
114
99
  note: Note.schema,
115
- owner: schemas.AztecAddress,
100
+ recipient: schemas.AztecAddress,
116
101
  contractAddress: schemas.AztecAddress,
117
102
  storageSlot: schemas.Fr,
118
- noteTypeId: schemas.NoteSelector,
119
103
  txHash: TxHash.schema,
120
104
  nonce: schemas.Fr,
121
105
  })
122
- .transform(({ note, owner, contractAddress, storageSlot, noteTypeId, txHash, nonce }) => {
123
- return new UniqueNote(note, owner, contractAddress, storageSlot, noteTypeId, txHash, nonce);
106
+ .transform(({ note, recipient, contractAddress, storageSlot, txHash, nonce }) => {
107
+ return new UniqueNote(note, recipient, contractAddress, storageSlot, txHash, nonce);
124
108
  });
125
109
  }
126
110
 
127
111
  override toBuffer(): Buffer {
128
112
  return serializeToBuffer([
129
113
  this.note,
130
- this.owner,
114
+ this.recipient,
131
115
  this.contractAddress,
132
116
  this.storageSlot,
133
- this.noteTypeId,
134
117
  this.txHash,
135
118
  this.nonce,
136
119
  ]);
@@ -142,7 +125,6 @@ export class UniqueNote extends ExtendedNote {
142
125
  await AztecAddress.random(),
143
126
  await AztecAddress.random(),
144
127
  Fr.random(),
145
- NoteSelector.random(),
146
128
  TxHash.random(),
147
129
  Fr.random(),
148
130
  );
@@ -152,14 +134,13 @@ export class UniqueNote extends ExtendedNote {
152
134
  const reader = BufferReader.asReader(buffer);
153
135
 
154
136
  const note = reader.readObject(Note);
155
- const owner = reader.readObject(AztecAddress);
137
+ const recipient = reader.readObject(AztecAddress);
156
138
  const contractAddress = reader.readObject(AztecAddress);
157
139
  const storageSlot = reader.readObject(Fr);
158
- const noteTypeId = reader.readObject(NoteSelector);
159
140
  const txHash = reader.readObject(TxHash);
160
141
  const nonce = reader.readObject(Fr);
161
142
 
162
- return new this(note, owner, contractAddress, storageSlot, noteTypeId, txHash, nonce);
143
+ return new this(note, recipient, contractAddress, storageSlot, txHash, nonce);
163
144
  }
164
145
 
165
146
  static override fromString(str: string) {
@@ -18,8 +18,8 @@ export type NotesFilter = {
18
18
  contractAddress?: AztecAddress;
19
19
  /** The specific storage location of the note on the contract. */
20
20
  storageSlot?: Fr;
21
- /** The owner of the note (whose public key was used to encrypt the note). */
22
- owner?: AztecAddress;
21
+ /** The recipient of the note (whose public key was used to encrypt the note). */
22
+ recipient?: AztecAddress;
23
23
  /** The status of the note. Defaults to 'ACTIVE'. */
24
24
  status?: NoteStatus;
25
25
  /** The siloed nullifier for the note. */
@@ -32,7 +32,7 @@ export const NotesFilterSchema: ZodFor<NotesFilter> = z.object({
32
32
  txHash: TxHash.schema.optional(),
33
33
  contractAddress: schemas.AztecAddress.optional(),
34
34
  storageSlot: schemas.Fr.optional(),
35
- owner: schemas.AztecAddress.optional(),
35
+ recipient: schemas.AztecAddress.optional(),
36
36
  status: z.nativeEnum(NoteStatus).optional(),
37
37
  siloedNullifier: schemas.Fr.optional(),
38
38
  scopes: z.array(schemas.AztecAddress).optional(),
@@ -7,6 +7,7 @@ import type { FieldsOf } from '@aztec/foundation/types';
7
7
  import { encodeAbiParameters, parseAbiParameters } from 'viem';
8
8
  import { z } from 'zod';
9
9
 
10
+ import type { L2Block } from '../block/l2_block.js';
10
11
  import { BlockHeader } from '../tx/block_header.js';
11
12
  import { TxHash } from '../tx/tx_hash.js';
12
13
  import type { Signable, SignatureDomainSeparator } from './signature_utils.js';
@@ -73,6 +74,14 @@ export class ConsensusPayload implements Signable {
73
74
  return new ConsensusPayload(fields.header, fields.archive, fields.txHashes);
74
75
  }
75
76
 
77
+ static fromBlock(block: L2Block): ConsensusPayload {
78
+ return new ConsensusPayload(
79
+ block.header,
80
+ block.archive.root,
81
+ block.body.txEffects.map(tx => tx.txHash),
82
+ );
83
+ }
84
+
76
85
  static empty(): ConsensusPayload {
77
86
  return new ConsensusPayload(BlockHeader.empty(), Fr.ZERO, []);
78
87
  }
@@ -18,9 +18,6 @@ export class Proof {
18
18
  // Honk proofs start with a 4 byte length prefix
19
19
  // the proof metadata starts immediately after
20
20
  private readonly metadataOffset = 4;
21
- // the metadata is 3 Frs long
22
- // the public inputs are after it
23
- private readonly publicInputsOffset = 100;
24
21
 
25
22
  constructor(
26
23
  /**
@@ -65,15 +62,12 @@ export class Proof {
65
62
  }
66
63
 
67
64
  public withoutPublicInputs(): Buffer {
68
- return Buffer.concat([
69
- this.buffer.subarray(this.metadataOffset, this.publicInputsOffset),
70
- this.buffer.subarray(this.publicInputsOffset + Fr.SIZE_IN_BYTES * this.numPublicInputs),
71
- ]);
65
+ return Buffer.concat([this.buffer.subarray(this.metadataOffset + Fr.SIZE_IN_BYTES * this.numPublicInputs)]);
72
66
  }
73
67
 
74
68
  public extractPublicInputs(): Fr[] {
75
69
  const reader = BufferReader.asReader(
76
- this.buffer.subarray(this.publicInputsOffset, this.publicInputsOffset + Fr.SIZE_IN_BYTES * this.numPublicInputs),
70
+ this.buffer.subarray(this.metadataOffset, this.metadataOffset + Fr.SIZE_IN_BYTES * this.numPublicInputs),
77
71
  );
78
72
  return reader.readArray(this.numPublicInputs, Fr);
79
73
  }
@@ -56,6 +56,7 @@ import { ContractStorageUpdateRequest } from '../avm/contract_storage_update_req
56
56
  import {
57
57
  AvmAccumulatedData,
58
58
  AvmAppendTreeHint,
59
+ AvmBytecodeCommitmentHint,
59
60
  AvmCircuitInputs,
60
61
  AvmCircuitPublicInputs,
61
62
  AvmContractClassHint,
@@ -1337,7 +1338,6 @@ export function makeAvmStorageUpdateTreeHints(seed = 0): AvmPublicDataWriteTreeH
1337
1338
  export function makeAvmContractInstanceHint(seed = 0): AvmContractInstanceHint {
1338
1339
  return new AvmContractInstanceHint(
1339
1340
  new AztecAddress(new Fr(seed)),
1340
- true /* exists */,
1341
1341
  new Fr(seed + 0x2),
1342
1342
  new AztecAddress(new Fr(seed + 0x3)),
1343
1343
  new Fr(seed + 0x4),
@@ -1349,8 +1349,6 @@ export function makeAvmContractInstanceHint(seed = 0): AvmContractInstanceHint {
1349
1349
  new Point(new Fr(seed + 0x11), new Fr(seed + 0x12), false),
1350
1350
  new Point(new Fr(seed + 0x13), new Fr(seed + 0x14), false),
1351
1351
  ),
1352
- makeAvmPublicDataReadTreeHints(seed + 0x2000),
1353
- makeArray(4, i => new Fr(i), seed + 0x3000),
1354
1352
  );
1355
1353
  }
1356
1354
 
@@ -1358,22 +1356,23 @@ export function makeAvmContractInstanceHint(seed = 0): AvmContractInstanceHint {
1358
1356
  * @param seed - The seed to use for generating the state reference.
1359
1357
  * @returns AvmContractClassHint.
1360
1358
  */
1361
- export async function makeAvmContractClassHint(seed = 0): Promise<AvmContractClassHint> {
1359
+ export function makeAvmContractClassHint(seed = 0): AvmContractClassHint {
1362
1360
  const bytecode = makeBytes(32, seed + 0x5);
1363
- return new AvmContractClassHint(
1364
- new Fr(seed),
1365
- true /* exists */,
1366
- new Fr(seed + 0x2),
1367
- new Fr(seed + 0x3),
1368
- await computePublicBytecodeCommitment(bytecode),
1369
- bytecode,
1370
- );
1361
+ return new AvmContractClassHint(new Fr(seed), new Fr(seed + 0x2), new Fr(seed + 0x3), bytecode);
1362
+ }
1363
+
1364
+ export async function makeAvmBytecodeCommitmentHint(seed = 0): Promise<AvmBytecodeCommitmentHint> {
1365
+ const classId = new Fr(seed + 2);
1366
+ const bytecode = makeBytes(32, seed + 0x5);
1367
+ return new AvmBytecodeCommitmentHint(classId, await computePublicBytecodeCommitment(bytecode));
1371
1368
  }
1372
1369
 
1373
1370
  export function makeAvmEnqueuedCallHint(seed = 0): AvmEnqueuedCallHint {
1374
1371
  return new AvmEnqueuedCallHint(
1375
1372
  new AztecAddress(new Fr(seed)),
1373
+ new AztecAddress(new Fr(seed + 2)),
1376
1374
  makeArray((seed % 20) + 4, i => new Fr(i), seed + 0x1000),
1375
+ /*isStaticCall=*/ false,
1377
1376
  );
1378
1377
  }
1379
1378
 
@@ -1392,8 +1391,9 @@ export async function makeAvmExecutionHints(
1392
1391
 
1393
1392
  const fields = {
1394
1393
  enqueuedCalls: makeArray(baseLength, makeAvmEnqueuedCallHint, seed + 0x4100),
1395
- contractInstances: makeArray(baseLength + 5, makeAvmContractInstanceHint, seed + 0x4700),
1396
- contractClasses: await makeArrayAsync(baseLength + 5, makeAvmContractClassHint, seed + 0x4900),
1394
+ contractInstances: makeArray(baseLength + 2, makeAvmContractInstanceHint, seed + 0x4700),
1395
+ contractClasses: makeArray(baseLength + 5, makeAvmContractClassHint, seed + 0x4900),
1396
+ bytecodeCommitments: await makeArrayAsync(baseLength + 5, makeAvmBytecodeCommitmentHint, seed + 0x4900),
1397
1397
  publicDataReads: makeArray(baseLength + 7, makeAvmStorageReadTreeHints, seed + 0x4900),
1398
1398
  publicDataWrites: makeArray(baseLength + 8, makeAvmStorageUpdateTreeHints, seed + 0x4a00),
1399
1399
  nullifierReads: makeArray(baseLength + 9, makeAvmNullifierReadTreeHints, seed + 0x4b00),
@@ -1408,6 +1408,7 @@ export async function makeAvmExecutionHints(
1408
1408
  fields.enqueuedCalls,
1409
1409
  fields.contractInstances,
1410
1410
  fields.contractClasses,
1411
+ fields.bytecodeCommitments,
1411
1412
  fields.publicDataReads,
1412
1413
  fields.publicDataWrites,
1413
1414
  fields.nullifierReads,
@@ -4,7 +4,6 @@ import { Secp256k1Signer, randomBytes } from '@aztec/foundation/crypto';
4
4
  import { Fr } from '@aztec/foundation/fields';
5
5
 
6
6
  import type { ContractArtifact } from '../abi/abi.js';
7
- import { NoteSelector } from '../abi/note_selector.js';
8
7
  import { AztecAddress } from '../aztec-address/index.js';
9
8
  import { computeContractAddressFromInstance } from '../contract/contract_address.js';
10
9
  import { getContractClassFromArtifact } from '../contract/contract_class.js';
@@ -46,37 +45,33 @@ export const randomTxHash = (): TxHash => TxHash.random();
46
45
 
47
46
  export const randomExtendedNote = async ({
48
47
  note = Note.random(),
49
- owner = undefined,
48
+ recipient = undefined,
50
49
  contractAddress = undefined,
51
50
  txHash = randomTxHash(),
52
51
  storageSlot = Fr.random(),
53
- noteTypeId = NoteSelector.random(),
54
52
  }: Partial<ExtendedNote> = {}) => {
55
53
  return new ExtendedNote(
56
54
  note,
57
- owner ?? (await AztecAddress.random()),
55
+ recipient ?? (await AztecAddress.random()),
58
56
  contractAddress ?? (await AztecAddress.random()),
59
57
  storageSlot,
60
- noteTypeId,
61
58
  txHash,
62
59
  );
63
60
  };
64
61
 
65
62
  export const randomUniqueNote = async ({
66
63
  note = Note.random(),
67
- owner = undefined,
64
+ recipient = undefined,
68
65
  contractAddress = undefined,
69
66
  txHash = randomTxHash(),
70
67
  storageSlot = Fr.random(),
71
- noteTypeId = NoteSelector.random(),
72
68
  nonce = Fr.random(),
73
69
  }: Partial<UniqueNote> = {}) => {
74
70
  return new UniqueNote(
75
71
  note,
76
- owner ?? (await AztecAddress.random()),
72
+ recipient ?? (await AztecAddress.random()),
77
73
  contractAddress ?? (await AztecAddress.random()),
78
74
  storageSlot,
79
- noteTypeId,
80
75
  txHash,
81
76
  nonce,
82
77
  );
package/src/tx/capsule.ts CHANGED
@@ -8,6 +8,8 @@ import { Vector } from '../types/shared.js';
8
8
 
9
9
  /**
10
10
  * Read-only data that is passed to the contract through an oracle during a transaction execution.
11
+ * TODO(#12425): Check whether this is always used to represent a transient capsule and if so, rename to
12
+ * TransientCapsule.
11
13
  */
12
14
  export class Capsule {
13
15
  constructor(
@@ -158,6 +158,28 @@ export class TxEffect {
158
158
  ]);
159
159
  }
160
160
 
161
+ equals(other: TxEffect): boolean {
162
+ return (
163
+ this.revertCode.equals(other.revertCode) &&
164
+ this.txHash.equals(other.txHash) &&
165
+ this.transactionFee.equals(other.transactionFee) &&
166
+ this.noteHashes.length === other.noteHashes.length &&
167
+ this.noteHashes.every((h, i) => h.equals(other.noteHashes[i])) &&
168
+ this.nullifiers.length === other.nullifiers.length &&
169
+ this.nullifiers.every((h, i) => h.equals(other.nullifiers[i])) &&
170
+ this.l2ToL1Msgs.length === other.l2ToL1Msgs.length &&
171
+ this.l2ToL1Msgs.every((h, i) => h.equals(other.l2ToL1Msgs[i])) &&
172
+ this.publicDataWrites.length === other.publicDataWrites.length &&
173
+ this.publicDataWrites.every((h, i) => h.equals(other.publicDataWrites[i])) &&
174
+ this.privateLogs.length === other.privateLogs.length &&
175
+ this.privateLogs.every((h, i) => h.equals(other.privateLogs[i])) &&
176
+ this.publicLogs.length === other.publicLogs.length &&
177
+ this.publicLogs.every((h, i) => h.equals(other.publicLogs[i])) &&
178
+ this.contractClassLogs.length === other.contractClassLogs.length &&
179
+ this.contractClassLogs.every((h, i) => h.equals(other.contractClassLogs[i]))
180
+ );
181
+ }
182
+
161
183
  /** Returns the size of this tx effect in bytes as serialized onto DA. */
162
184
  getDASize() {
163
185
  return this.toBlobFields().length * Fr.SIZE_IN_BYTES;
@@ -223,7 +245,7 @@ export class TxEffect {
223
245
  makeTuple(MAX_L2_TO_L1_MSGS_PER_TX, Fr.random),
224
246
  makeTuple(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, () => new PublicDataWrite(Fr.random(), Fr.random())),
225
247
  makeTuple(MAX_PRIVATE_LOGS_PER_TX, () => new PrivateLog(makeTuple(PRIVATE_LOG_SIZE_IN_FIELDS, Fr.random))),
226
- await makeTupleAsync(numPublicCallsPerTx * numPublicLogsPerCall, PublicLog.random),
248
+ await makeTupleAsync(numPublicCallsPerTx * numPublicLogsPerCall, async () => await PublicLog.random()),
227
249
  await makeTupleAsync(MAX_CONTRACT_CLASS_LOGS_PER_TX, ContractClassLog.random),
228
250
  );
229
251
  }
@@ -1,82 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- import { type Fq, Fr } from '@aztec/foundation/fields';
4
- import { BufferReader } from '@aztec/foundation/serialize';
5
- import { NoteSelector } from '../../abi/note_selector.js';
6
- import { AztecAddress } from '../../aztec-address/index.js';
7
- import type { PrivateLog } from '../private_log.js';
8
- import { PublicLog } from '../public_log.js';
9
- /**
10
- * A class which wraps note data which is pushed on L1.
11
- * @remarks This data is required to compute a nullifier/to spend a note. Along with that this class contains
12
- * the necessary functionality to encrypt and decrypt the data.
13
- */
14
- export declare class L1NotePayload {
15
- /**
16
- * Address of the contract this tx is interacting with.
17
- */
18
- contractAddress: AztecAddress;
19
- /**
20
- * Storage slot of the underlying note.
21
- */
22
- storageSlot: Fr;
23
- /**
24
- * Type identifier for the underlying note, required to determine how to compute its hash and nullifier.
25
- */
26
- noteTypeId: NoteSelector;
27
- /**
28
- * Note values delivered encrypted.
29
- * @dev Note that to recreate the correct note we need to merge privateNoteValues and publicNoteValues. To do that
30
- * we need access to the contract ABI (that is done in the NoteProcessor).
31
- */
32
- privateNoteValues: Fr[];
33
- /**
34
- * Note values delivered in plaintext.
35
- * @dev Note that to recreate the correct note we need to merge privateNoteValues and publicNoteValues. To do that
36
- * we need access to the contract ABI (that is done in the NoteProcessor).
37
- */
38
- publicNoteValues: Fr[];
39
- constructor(
40
- /**
41
- * Address of the contract this tx is interacting with.
42
- */
43
- contractAddress: AztecAddress,
44
- /**
45
- * Storage slot of the underlying note.
46
- */
47
- storageSlot: Fr,
48
- /**
49
- * Type identifier for the underlying note, required to determine how to compute its hash and nullifier.
50
- */
51
- noteTypeId: NoteSelector,
52
- /**
53
- * Note values delivered encrypted.
54
- * @dev Note that to recreate the correct note we need to merge privateNoteValues and publicNoteValues. To do that
55
- * we need access to the contract ABI (that is done in the NoteProcessor).
56
- */
57
- privateNoteValues: Fr[],
58
- /**
59
- * Note values delivered in plaintext.
60
- * @dev Note that to recreate the correct note we need to merge privateNoteValues and publicNoteValues. To do that
61
- * we need access to the contract ABI (that is done in the NoteProcessor).
62
- */
63
- publicNoteValues: Fr[]);
64
- static fromIncomingBodyPlaintextContractAndPublicValues(plaintext: Buffer, contractAddress: AztecAddress, publicNoteValues: Fr[]): L1NotePayload | undefined;
65
- static decryptAsIncoming(log: PrivateLog, sk: Fq): Promise<L1NotePayload | undefined>;
66
- static decryptAsIncomingFromPublic(log: PublicLog, sk: Fq): Promise<L1NotePayload | undefined>;
67
- /**
68
- * Serializes the L1NotePayload object into a Buffer.
69
- * @returns Buffer representation of the L1NotePayload object.
70
- */
71
- toIncomingBodyPlaintext(): Buffer;
72
- /**
73
- * Create a random L1NotePayload object (useful for testing purposes).
74
- * @param contract - The address of a contract the note was emitted from.
75
- * @returns A random L1NotePayload object.
76
- */
77
- static random(contract?: AztecAddress): Promise<L1NotePayload>;
78
- equals(other: L1NotePayload): boolean;
79
- toBuffer(): Buffer;
80
- static fromBuffer(buffer: Buffer | BufferReader): L1NotePayload;
81
- }
82
- //# sourceMappingURL=l1_note_payload.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"l1_note_payload.d.ts","sourceRoot":"","sources":["../../../src/logs/l1_payload/l1_note_payload.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C;;;;GAIG;AACH,qBAAa,aAAa;IAEtB;;OAEG;IACI,eAAe,EAAE,YAAY;IACpC;;OAEG;IACI,WAAW,EAAE,EAAE;IACtB;;OAEG;IACI,UAAU,EAAE,YAAY;IAC/B;;;;OAIG;IACI,iBAAiB,EAAE,EAAE,EAAE;IAC9B;;;;OAIG;IACI,gBAAgB,EAAE,EAAE,EAAE;;IAvB7B;;OAEG;IACI,eAAe,EAAE,YAAY;IACpC;;OAEG;IACI,WAAW,EAAE,EAAE;IACtB;;OAEG;IACI,UAAU,EAAE,YAAY;IAC/B;;;;OAIG;IACI,iBAAiB,EAAE,EAAE,EAAE;IAC9B;;;;OAIG;IACI,gBAAgB,EAAE,EAAE,EAAE;IAG/B,MAAM,CAAC,gDAAgD,CACrD,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,YAAY,EAC7B,gBAAgB,EAAE,EAAE,EAAE,GACrB,aAAa,GAAG,SAAS;WAgBf,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;WAa9E,2BAA2B,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAkBpG;;;OAGG;IACH,uBAAuB;IAKvB;;;;OAIG;WACU,MAAM,CAAC,QAAQ,CAAC,EAAE,YAAY;IAgBpC,MAAM,CAAC,KAAK,EAAE,aAAa;IAUlC,QAAQ;IAUR,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;CAUhD"}
@@ -1,129 +0,0 @@
1
- import { randomInt } from '@aztec/foundation/crypto';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
- import { NoteSelector } from '../../abi/note_selector.js';
5
- import { AztecAddress } from '../../aztec-address/index.js';
6
- import { Vector } from '../../types/index.js';
7
- import { EncryptedLogPayload } from './encrypted_log_payload.js';
8
- /**
9
- * A class which wraps note data which is pushed on L1.
10
- * @remarks This data is required to compute a nullifier/to spend a note. Along with that this class contains
11
- * the necessary functionality to encrypt and decrypt the data.
12
- */ export class L1NotePayload {
13
- contractAddress;
14
- storageSlot;
15
- noteTypeId;
16
- privateNoteValues;
17
- publicNoteValues;
18
- constructor(/**
19
- * Address of the contract this tx is interacting with.
20
- */ contractAddress, /**
21
- * Storage slot of the underlying note.
22
- */ storageSlot, /**
23
- * Type identifier for the underlying note, required to determine how to compute its hash and nullifier.
24
- */ noteTypeId, /**
25
- * Note values delivered encrypted.
26
- * @dev Note that to recreate the correct note we need to merge privateNoteValues and publicNoteValues. To do that
27
- * we need access to the contract ABI (that is done in the NoteProcessor).
28
- */ privateNoteValues, /**
29
- * Note values delivered in plaintext.
30
- * @dev Note that to recreate the correct note we need to merge privateNoteValues and publicNoteValues. To do that
31
- * we need access to the contract ABI (that is done in the NoteProcessor).
32
- */ publicNoteValues){
33
- this.contractAddress = contractAddress;
34
- this.storageSlot = storageSlot;
35
- this.noteTypeId = noteTypeId;
36
- this.privateNoteValues = privateNoteValues;
37
- this.publicNoteValues = publicNoteValues;
38
- }
39
- static fromIncomingBodyPlaintextContractAndPublicValues(plaintext, contractAddress, publicNoteValues) {
40
- try {
41
- const reader = BufferReader.asReader(plaintext);
42
- const fields = reader.readArray(plaintext.length / Fr.SIZE_IN_BYTES, Fr);
43
- const storageSlot = fields[0];
44
- const noteTypeId = NoteSelector.fromField(fields[1]);
45
- const privateNoteValues = fields.slice(2);
46
- return new L1NotePayload(contractAddress, storageSlot, noteTypeId, privateNoteValues, publicNoteValues);
47
- } catch (e) {
48
- return undefined;
49
- }
50
- }
51
- static async decryptAsIncoming(log, sk) {
52
- const decryptedLog = await EncryptedLogPayload.decryptAsIncoming(log.fields, sk);
53
- if (!decryptedLog) {
54
- return undefined;
55
- }
56
- return this.fromIncomingBodyPlaintextContractAndPublicValues(decryptedLog.incomingBodyPlaintext, decryptedLog.contractAddress, /* publicValues */ []);
57
- }
58
- static async decryptAsIncomingFromPublic(log, sk) {
59
- const { privateValues, publicValues } = parseLogFromPublic(log);
60
- if (!privateValues) {
61
- return undefined;
62
- }
63
- const decryptedLog = await EncryptedLogPayload.decryptAsIncoming(privateValues, sk);
64
- if (!decryptedLog) {
65
- return undefined;
66
- }
67
- return this.fromIncomingBodyPlaintextContractAndPublicValues(decryptedLog.incomingBodyPlaintext, decryptedLog.contractAddress, publicValues);
68
- }
69
- /**
70
- * Serializes the L1NotePayload object into a Buffer.
71
- * @returns Buffer representation of the L1NotePayload object.
72
- */ toIncomingBodyPlaintext() {
73
- const fields = [
74
- this.storageSlot,
75
- this.noteTypeId.toField(),
76
- ...this.privateNoteValues
77
- ];
78
- return serializeToBuffer(fields);
79
- }
80
- /**
81
- * Create a random L1NotePayload object (useful for testing purposes).
82
- * @param contract - The address of a contract the note was emitted from.
83
- * @returns A random L1NotePayload object.
84
- */ static async random(contract) {
85
- const numPrivateNoteValues = randomInt(2) + 1;
86
- const privateNoteValues = Array.from({
87
- length: numPrivateNoteValues
88
- }, ()=>Fr.random());
89
- const numPublicNoteValues = randomInt(2) + 1;
90
- const publicNoteValues = Array.from({
91
- length: numPublicNoteValues
92
- }, ()=>Fr.random());
93
- return new L1NotePayload(contract ?? await AztecAddress.random(), Fr.random(), NoteSelector.random(), privateNoteValues, publicNoteValues);
94
- }
95
- equals(other) {
96
- return this.contractAddress.equals(other.contractAddress) && this.storageSlot.equals(other.storageSlot) && this.noteTypeId.equals(other.noteTypeId) && this.privateNoteValues.every((value, index)=>value.equals(other.privateNoteValues[index])) && this.publicNoteValues.every((value, index)=>value.equals(other.publicNoteValues[index]));
97
- }
98
- toBuffer() {
99
- return serializeToBuffer(this.contractAddress, this.storageSlot, this.noteTypeId, new Vector(this.privateNoteValues), new Vector(this.publicNoteValues));
100
- }
101
- static fromBuffer(buffer) {
102
- const reader = BufferReader.asReader(buffer);
103
- return new L1NotePayload(reader.readObject(AztecAddress), reader.readObject(Fr), reader.readObject(NoteSelector), reader.readVector(Fr), reader.readVector(Fr));
104
- }
105
- }
106
- /**
107
- * Parse the given log into an array of public values and an encrypted log.
108
- *
109
- * @param log - Log to be parsed.
110
- * @returns An object containing the public values, encrypted log, and ciphertext length.
111
- */ function parseLogFromPublic(log) {
112
- // Extract lengths from the log
113
- // See aztec_nr/aztec/src/macros/note/mod.nr to see how the "finalization_log" is encoded.
114
- // Each length is stored in 2 bytes with a 0 separator byte between them:
115
- // [ publicLen[0], publicLen[1], 0, privateLen[0], privateLen[1] ]
116
- // Search the codebase for "disgusting encoding" to see other hardcoded instances of this encoding, that you might need to change if you ever find yourself here.
117
- const lengths = log.log[0].toBuffer().subarray(-5);
118
- const publicValuesLength = lengths.readUint16BE();
119
- const privateValuesLength = lengths.readUint16BE(3);
120
- // Now we get the fields corresponding to the values generated from private.
121
- // Note: +1 for the length values in position 0
122
- const privateValues = log.log.slice(1, 1 + privateValuesLength);
123
- // At last we load the public values
124
- const publicValues = log.log.slice(1 + privateValuesLength, 1 + privateValuesLength + publicValuesLength);
125
- return {
126
- publicValues,
127
- privateValues
128
- };
129
- }