@aztec/stdlib 3.0.0-nightly.20251013 → 3.0.0-nightly.20251015

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 (60) hide show
  1. package/dest/abi/abi.d.ts +8 -8
  2. package/dest/abi/abi.js +1 -1
  3. package/dest/abi/contract_artifact.js +3 -0
  4. package/dest/abi/function_call.d.ts +7 -2
  5. package/dest/abi/function_call.d.ts.map +1 -1
  6. package/dest/abi/function_call.js +6 -2
  7. package/dest/avm/avm.d.ts +54 -54
  8. package/dest/avm/avm_proving_request.d.ts +30 -30
  9. package/dest/contract/interfaces/contract_instance.d.ts +2 -2
  10. package/dest/interfaces/proving-job.d.ts +30 -30
  11. package/dest/kernel/private_call_data.d.ts +1 -1
  12. package/dest/kernel/private_circuit_public_inputs.d.ts +1 -1
  13. package/dest/kernel/private_to_public_accumulated_data.d.ts +1 -1
  14. package/dest/kernel/private_to_rollup_accumulated_data.d.ts +1 -1
  15. package/dest/keys/derivation.d.ts +0 -2
  16. package/dest/keys/derivation.d.ts.map +1 -1
  17. package/dest/keys/derivation.js +1 -21
  18. package/dest/logs/directional_app_tagging_secret.d.ts +40 -0
  19. package/dest/logs/directional_app_tagging_secret.d.ts.map +1 -0
  20. package/dest/logs/directional_app_tagging_secret.js +64 -0
  21. package/dest/logs/index.d.ts +1 -0
  22. package/dest/logs/index.d.ts.map +1 -1
  23. package/dest/logs/index.js +1 -0
  24. package/dest/logs/indexed_tagging_secret.d.ts +32 -26
  25. package/dest/logs/indexed_tagging_secret.d.ts.map +1 -1
  26. package/dest/logs/indexed_tagging_secret.js +7 -50
  27. package/dest/noir/index.d.ts +2 -0
  28. package/dest/noir/index.d.ts.map +1 -1
  29. package/dest/rollup/base_rollup_hints.d.ts +2 -2
  30. package/dest/rollup/block_root_rollup_private_inputs.d.ts +5 -5
  31. package/dest/rollup/checkpoint_rollup_public_inputs.d.ts +1 -0
  32. package/dest/rollup/checkpoint_rollup_public_inputs.d.ts.map +1 -1
  33. package/dest/rollup/checkpoint_rollup_public_inputs.js +3 -0
  34. package/dest/rollup/checkpoint_root_rollup_private_inputs.d.ts +1 -1
  35. package/dest/rollup/tree_snapshot_diff_hints.d.ts +1 -1
  36. package/dest/tests/factories.d.ts +2 -1
  37. package/dest/tests/factories.d.ts.map +1 -1
  38. package/dest/tests/factories.js +15 -9
  39. package/dest/tests/mocks.d.ts +3 -1
  40. package/dest/tests/mocks.d.ts.map +1 -1
  41. package/dest/tests/mocks.js +4 -2
  42. package/dest/trees/merkle_tree_id.d.ts +4 -4
  43. package/dest/trees/nullifier_membership_witness.d.ts +3 -3
  44. package/dest/tx/private_execution_result.d.ts +5 -0
  45. package/dest/tx/private_execution_result.d.ts.map +1 -1
  46. package/dest/tx/private_execution_result.js +7 -3
  47. package/dest/tx/simulated_tx.d.ts +3 -3
  48. package/package.json +8 -8
  49. package/src/abi/abi.ts +1 -1
  50. package/src/abi/contract_artifact.ts +3 -0
  51. package/src/abi/function_call.ts +5 -1
  52. package/src/keys/derivation.ts +1 -26
  53. package/src/logs/directional_app_tagging_secret.ts +78 -0
  54. package/src/logs/index.ts +1 -0
  55. package/src/logs/indexed_tagging_secret.ts +21 -44
  56. package/src/noir/index.ts +2 -0
  57. package/src/rollup/checkpoint_rollup_public_inputs.ts +4 -0
  58. package/src/tests/factories.ts +11 -4
  59. package/src/tests/mocks.ts +5 -0
  60. package/src/tx/private_execution_result.ts +6 -0
@@ -0,0 +1,78 @@
1
+ import { Grumpkin, poseidon2Hash } from '@aztec/foundation/crypto';
2
+ import { type Fq, Fr, type Point } from '@aztec/foundation/fields';
3
+
4
+ import { z } from 'zod';
5
+
6
+ import type { AztecAddress } from '../aztec-address/index.js';
7
+ import type { CompleteAddress } from '../contract/complete_address.js';
8
+ import { computeAddressSecret, computePreaddress } from '../keys/derivation.js';
9
+
10
+ /**
11
+ * Directional application tagging secret used for log tagging.
12
+ *
13
+ * "Directional" because the derived secret is bound to the recipient
14
+ * address: A→B differs from B→A even with the same participants and app.
15
+ *
16
+ * Note: It's a bit unfortunate that this type resides in `stdlib` as the rest of the tagging functionality resides
17
+ * in `pxe/src/tagging`. We need to use this type in `IndexedTaggingSecret` that in turn is used by other types
18
+ * in stdlib hence there doesn't seem to be a good way around this.
19
+ */
20
+ export class DirectionalAppTaggingSecret {
21
+ private constructor(public readonly value: Fr) {}
22
+
23
+ /**
24
+ * Derives shared tagging secret and from that, the app address and recipient derives the directional app tagging
25
+ * secret.
26
+ *
27
+ * @param localAddress - The complete address of entity A in the shared tagging secret derivation scheme
28
+ * @param localIvsk - The incoming viewing secret key of entity A
29
+ * @param externalAddress - The address of entity B in the shared tagging secret derivation scheme
30
+ * @param app - Contract address to silo the secret to
31
+ * @param recipient - Recipient of the log. Defines the "direction of the secret".
32
+ * @returns The secret that can be used along with an index to compute a tag to be included in a log.
33
+ */
34
+ static async compute(
35
+ localAddress: CompleteAddress,
36
+ localIvsk: Fq,
37
+ externalAddress: AztecAddress,
38
+ app: AztecAddress,
39
+ recipient: AztecAddress,
40
+ ): Promise<DirectionalAppTaggingSecret> {
41
+ const taggingSecretPoint = await computeSharedTaggingSecret(localAddress, localIvsk, externalAddress);
42
+ const appTaggingSecret = await poseidon2Hash([taggingSecretPoint.x, taggingSecretPoint.y, app]);
43
+ const directionalAppTaggingSecret = await poseidon2Hash([appTaggingSecret, recipient]);
44
+
45
+ return new DirectionalAppTaggingSecret(directionalAppTaggingSecret);
46
+ }
47
+
48
+ toString(): string {
49
+ return this.value.toString();
50
+ }
51
+
52
+ static fromString(str: string): DirectionalAppTaggingSecret {
53
+ return new DirectionalAppTaggingSecret(Fr.fromString(str));
54
+ }
55
+ }
56
+
57
+ // Returns shared tagging secret computed with Diffie-Hellman key exchange.
58
+ async function computeSharedTaggingSecret(
59
+ localAddress: CompleteAddress,
60
+ localIvsk: Fq,
61
+ externalAddress: AztecAddress,
62
+ ): Promise<Point> {
63
+ const knownPreaddress = await computePreaddress(await localAddress.publicKeys.hash(), localAddress.partialAddress);
64
+ // TODO: #8970 - Computation of address point from x coordinate might fail
65
+ const externalAddressPoint = await externalAddress.toAddressPoint();
66
+ const curve = new Grumpkin();
67
+ // Given A (local complete address) -> B (external address) and h == preaddress
68
+ // Compute shared secret as S = (h_A + local_ivsk_A) * Addr_Point_B
69
+
70
+ // Beware! h_a + local_ivsk_a (also known as the address secret) can lead to an address point with a negative
71
+ // y-coordinate, since there's two possible candidates computeAddressSecret takes care of selecting the one that
72
+ // leads to a positive y-coordinate, which is the only valid address point
73
+ return curve.mul(externalAddressPoint, await computeAddressSecret(knownPreaddress, localIvsk));
74
+ }
75
+
76
+ export const DirectionalAppTaggingSecretSchema = z.object({
77
+ value: Fr.schema,
78
+ });
package/src/logs/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './log_with_tx_data.js';
2
+ export * from './directional_app_tagging_secret.js';
2
3
  export * from './indexed_tagging_secret.js';
3
4
  export * from './contract_class_log.js';
4
5
  export * from './public_log.js';
@@ -1,48 +1,25 @@
1
- import { poseidon2Hash } from '@aztec/foundation/crypto';
2
- import { Fr } from '@aztec/foundation/fields';
1
+ import { schemas } from '@aztec/foundation/schemas';
3
2
 
4
- import type { AztecAddress } from '../aztec-address/index.js';
3
+ import { z } from 'zod';
5
4
 
6
- export class IndexedTaggingSecret {
7
- constructor(
8
- public appTaggingSecret: Fr,
9
- public index: number,
10
- ) {
11
- if (index < 0) {
12
- throw new Error('IndexedTaggingSecret index out of bounds');
13
- }
14
- }
5
+ import {
6
+ type DirectionalAppTaggingSecret,
7
+ DirectionalAppTaggingSecretSchema,
8
+ } from './directional_app_tagging_secret.js';
15
9
 
16
- toFields(): Fr[] {
17
- return [this.appTaggingSecret, new Fr(this.index)];
18
- }
10
+ /**
11
+ * Represents a preimage of a private log tag (see `Tag` in `pxe/src/tagging`).
12
+ *
13
+ * Note: It's a bit unfortunate that this type resides in `stdlib` as the rest of the tagging functionality resides
14
+ * in `pxe/src/tagging`. But this type is used by other types in stdlib hence there doesn't seem to be a good way
15
+ * around this.
16
+ */
17
+ export type IndexedTaggingSecret = {
18
+ secret: DirectionalAppTaggingSecret;
19
+ index: number;
20
+ };
19
21
 
20
- static fromFields(serialized: Fr[]) {
21
- return new this(serialized[0], serialized[1].toNumber());
22
- }
23
-
24
- /**
25
- * Computes the tag based on the app tagging secret, recipient and index.
26
- * @dev By including the recipient we achieve "directionality" of the tag (when sending a note in the other
27
- * direction, the tag will be different).
28
- * @param recipient The recipient of the note
29
- * @returns The tag.
30
- */
31
- computeTag(recipient: AztecAddress) {
32
- return poseidon2Hash([this.appTaggingSecret, recipient, this.index]);
33
- }
34
-
35
- /**
36
- * Computes the siloed tag.
37
- * @dev We do this second layer of siloing (one was already done as the tagging secret is app-siloed) because kernels
38
- * do that to protect against contract impersonation attacks. This extra layer of siloing in kernels ensures that
39
- * a malicious contract cannot emit a note with a tag corresponding to another contract.
40
- * @param recipient The recipient of the note
41
- * @param app The app address
42
- * @returns The siloed tag.
43
- */
44
- async computeSiloedTag(recipient: AztecAddress, app: AztecAddress) {
45
- const tag = await this.computeTag(recipient);
46
- return poseidon2Hash([app, tag]);
47
- }
48
- }
22
+ export const IndexedTaggingSecretSchema = z.object({
23
+ secret: DirectionalAppTaggingSecretSchema,
24
+ index: schemas.Integer,
25
+ });
package/src/noir/index.ts CHANGED
@@ -64,6 +64,8 @@ interface NoirFunctionEntry {
64
64
  export interface NoirCompiledContract {
65
65
  /** The name of the contract. */
66
66
  name: string;
67
+ /** Is the contract's public bytecode transpiled? */
68
+ transpiled?: boolean;
67
69
  /** The functions of the contract. */
68
70
  functions: NoirFunctionEntry[];
69
71
  /** The events of the contract */
@@ -118,6 +118,10 @@ export class FeeRecipient {
118
118
  return serializeToFields(...FeeRecipient.getFields(this));
119
119
  }
120
120
 
121
+ static empty() {
122
+ return new FeeRecipient(EthAddress.ZERO, Fr.ZERO);
123
+ }
124
+
121
125
  isEmpty() {
122
126
  return this.value.isZero() && this.recipient.isZero();
123
127
  }
@@ -88,6 +88,7 @@ import {
88
88
  computeContractClassId,
89
89
  computePublicBytecodeCommitment,
90
90
  } from '../contract/index.js';
91
+ import { computeEffectiveGasFees } from '../fees/transaction_fee.js';
91
92
  import { Gas, GasFees, GasSettings, type GasUsed } from '../gas/index.js';
92
93
  import { computeCalldataHash } from '../hash/hash.js';
93
94
  import type { MerkleTreeReadOperations } from '../interfaces/merkle_tree_operations.js';
@@ -1544,6 +1545,8 @@ export async function makeBloatedProcessedTx({
1544
1545
  newL1ToL2Snapshot = AppendOnlyTreeSnapshot.empty(),
1545
1546
  feePayer,
1546
1547
  feePaymentPublicDataWrite,
1548
+ // The default gasUsed is the tx overhead.
1549
+ gasUsed = Gas.from({ daGas: FIXED_DA_GAS, l2Gas: FIXED_L2_GAS }),
1547
1550
  privateOnly = false,
1548
1551
  }: {
1549
1552
  seed?: number;
@@ -1558,6 +1561,7 @@ export async function makeBloatedProcessedTx({
1558
1561
  protocolContracts?: ProtocolContracts;
1559
1562
  feePayer?: AztecAddress;
1560
1563
  feePaymentPublicDataWrite?: PublicDataWrite;
1564
+ gasUsed?: Gas;
1561
1565
  privateOnly?: boolean;
1562
1566
  } = {}) {
1563
1567
  seed *= 0x1000; // Avoid clashing with the previous mock values if seed only increases by 1.
@@ -1573,22 +1577,21 @@ export async function makeBloatedProcessedTx({
1573
1577
  txConstantData.protocolContractsHash = await protocolContracts.hash();
1574
1578
 
1575
1579
  const tx = !privateOnly
1576
- ? await mockTx(seed, { feePayer })
1580
+ ? await mockTx(seed, { feePayer, gasUsed })
1577
1581
  : await mockTx(seed, {
1578
1582
  numberOfNonRevertiblePublicCallRequests: 0,
1579
1583
  numberOfRevertiblePublicCallRequests: 0,
1580
1584
  feePayer,
1585
+ gasUsed,
1581
1586
  });
1582
1587
  tx.data.constants = txConstantData;
1583
1588
 
1584
- // No side effects were created in mockTx. The default gasUsed is the tx overhead.
1585
- tx.data.gasUsed = Gas.from({ daGas: FIXED_DA_GAS, l2Gas: FIXED_L2_GAS });
1589
+ const transactionFee = tx.data.gasUsed.computeFee(globalVariables.gasFees);
1586
1590
 
1587
1591
  if (privateOnly) {
1588
1592
  const data = makePrivateToRollupAccumulatedData(seed + 0x1000);
1589
1593
  clearContractClassLogs(data);
1590
1594
 
1591
- const transactionFee = tx.data.gasUsed.computeFee(globalVariables.gasFees);
1592
1595
  feePaymentPublicDataWrite ??= new PublicDataWrite(Fr.random(), Fr.random());
1593
1596
 
1594
1597
  tx.data.forRollup!.end = data;
@@ -1612,6 +1615,7 @@ export async function makeBloatedProcessedTx({
1612
1615
  avmOutput.protocolContracts = protocolContracts;
1613
1616
  avmOutput.startTreeSnapshots.l1ToL2MessageTree = newL1ToL2Snapshot;
1614
1617
  avmOutput.endTreeSnapshots.l1ToL2MessageTree = newL1ToL2Snapshot;
1618
+ avmOutput.effectiveGasFees = computeEffectiveGasFees(globalVariables.gasFees, gasSettings);
1615
1619
  // Assign data from private.
1616
1620
  avmOutput.globalVariables = globalVariables;
1617
1621
  avmOutput.startGasUsed = tx.data.gasUsed;
@@ -1654,6 +1658,9 @@ export async function makeBloatedProcessedTx({
1654
1658
  );
1655
1659
  avmOutput.accumulatedDataArrayLengths = avmOutput.accumulatedData.getArrayLengths();
1656
1660
  avmOutput.gasSettings = gasSettings;
1661
+ // Note: The fee is computed from the tx's gas used, which only includes the gas used in private. But this shouldn't
1662
+ // be a problem for the tests.
1663
+ avmOutput.transactionFee = transactionFee;
1657
1664
 
1658
1665
  const avmCircuitInputs = await makeAvmCircuitInputs(seed + 0x3000, { publicInputs: avmOutput });
1659
1666
  avmCircuitInputs.hints.startingTreeRoots.l1ToL2MessageTree = newL1ToL2Snapshot;
@@ -14,6 +14,7 @@ import { computeContractAddressFromInstance } from '../contract/contract_address
14
14
  import { getContractClassFromArtifact } from '../contract/contract_class.js';
15
15
  import { SerializableContractInstance } from '../contract/contract_instance.js';
16
16
  import type { ContractInstanceWithAddress } from '../contract/index.js';
17
+ import { Gas } from '../gas/gas.js';
17
18
  import { GasFees } from '../gas/gas_fees.js';
18
19
  import { GasSettings } from '../gas/gas_settings.js';
19
20
  import { Nullifier } from '../kernel/nullifier.js';
@@ -84,6 +85,7 @@ export const mockTx = async (
84
85
  feePayer,
85
86
  clientIvcProof = ClientIvcProof.random(),
86
87
  maxPriorityFeesPerGas,
88
+ gasUsed = Gas.empty(),
87
89
  chainId = Fr.ZERO,
88
90
  version = Fr.ZERO,
89
91
  vkTreeRoot = Fr.ZERO,
@@ -97,6 +99,7 @@ export const mockTx = async (
97
99
  feePayer?: AztecAddress;
98
100
  clientIvcProof?: ClientIvcProof;
99
101
  maxPriorityFeesPerGas?: GasFees;
102
+ gasUsed?: Gas;
100
103
  chainId?: Fr;
101
104
  version?: Fr;
102
105
  vkTreeRoot?: Fr;
@@ -115,6 +118,7 @@ export const mockTx = async (
115
118
  maxPriorityFeesPerGas,
116
119
  });
117
120
  data.feePayer = feePayer ?? (await AztecAddress.random());
121
+ data.gasUsed = gasUsed;
118
122
  data.constants.txContext.chainId = chainId;
119
123
  data.constants.txContext.version = version;
120
124
  data.constants.vkTreeRoot = vkTreeRoot;
@@ -184,6 +188,7 @@ const emptyPrivateCallExecutionResult = () =>
184
188
  [],
185
189
  [],
186
190
  [],
191
+ [],
187
192
  );
188
193
 
189
194
  const emptyPrivateExecutionResult = () => new PrivateExecutionResult(emptyPrivateCallExecutionResult(), Fr.zero(), []);
@@ -10,6 +10,7 @@ import { PrivateCircuitPublicInputs } from '../kernel/private_circuit_public_inp
10
10
  import type { IsEmpty } from '../kernel/utils/interfaces.js';
11
11
  import { sortByCounter } from '../kernel/utils/order_and_comparison.js';
12
12
  import { ContractClassLog, ContractClassLogFields } from '../logs/contract_class_log.js';
13
+ import { type IndexedTaggingSecret, IndexedTaggingSecretSchema } from '../logs/indexed_tagging_secret.js';
13
14
  import { Note } from '../note/note.js';
14
15
  import { type ZodFor, mapSchema, schemas } from '../schemas/index.js';
15
16
  import type { UInt32 } from '../types/index.js';
@@ -135,6 +136,8 @@ export class PrivateCallExecutionResult {
135
136
  public returnValues: Fr[],
136
137
  /** The offchain effects emitted during execution of this function call via the `emit_offchain_effect` oracle. */
137
138
  public offchainEffects: { data: Fr[] }[],
139
+ /** The tagging indexes incremented by this execution along with the directional app tagging secrets. */
140
+ public indexedTaggingSecrets: IndexedTaggingSecret[],
138
141
  /** The nested executions. */
139
142
  public nestedExecutionResults: PrivateCallExecutionResult[],
140
143
  /**
@@ -158,6 +161,7 @@ export class PrivateCallExecutionResult {
158
161
  noteHashNullifierCounterMap: mapSchema(z.coerce.number(), z.number()),
159
162
  returnValues: z.array(schemas.Fr),
160
163
  offchainEffects: z.array(z.object({ data: z.array(schemas.Fr) })),
164
+ indexedTaggingSecrets: z.array(IndexedTaggingSecretSchema),
161
165
  nestedExecutionResults: z.array(z.lazy(() => PrivateCallExecutionResult.schema)),
162
166
  contractClassLogs: z.array(CountedContractClassLog.schema),
163
167
  })
@@ -175,6 +179,7 @@ export class PrivateCallExecutionResult {
175
179
  fields.noteHashNullifierCounterMap,
176
180
  fields.returnValues,
177
181
  fields.offchainEffects,
182
+ fields.indexedTaggingSecrets,
178
183
  fields.nestedExecutionResults,
179
184
  fields.contractClassLogs,
180
185
  );
@@ -195,6 +200,7 @@ export class PrivateCallExecutionResult {
195
200
  data: [Fr.random()],
196
201
  },
197
202
  ],
203
+ [],
198
204
  await timesParallel(nested, () => PrivateCallExecutionResult.random(0)),
199
205
  [new CountedContractClassLog(await ContractClassLog.random(), randomInt(10))],
200
206
  );