@aztec/stdlib 4.1.2 → 4.2.0-aztecnr-rc.2

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 (145) hide show
  1. package/dest/abi/buffer.d.ts +14 -4
  2. package/dest/abi/buffer.d.ts.map +1 -1
  3. package/dest/abi/buffer.js +25 -4
  4. package/dest/abi/decoder.d.ts +5 -44
  5. package/dest/abi/decoder.d.ts.map +1 -1
  6. package/dest/abi/decoder.js +12 -67
  7. package/dest/abi/function_selector.js +1 -1
  8. package/dest/abi/function_signature_decoder.d.ts +43 -0
  9. package/dest/abi/function_signature_decoder.d.ts.map +1 -0
  10. package/dest/abi/function_signature_decoder.js +66 -0
  11. package/dest/abi/index.d.ts +2 -1
  12. package/dest/abi/index.d.ts.map +1 -1
  13. package/dest/abi/index.js +1 -0
  14. package/dest/avm/avm_accumulated_data.js +2 -2
  15. package/dest/avm/avm_circuit_public_inputs.js +2 -2
  16. package/dest/block/l2_block_source.d.ts +5 -3
  17. package/dest/block/l2_block_source.d.ts.map +1 -1
  18. package/dest/checkpoint/validate.js +2 -2
  19. package/dest/epoch-helpers/index.d.ts +3 -1
  20. package/dest/epoch-helpers/index.d.ts.map +1 -1
  21. package/dest/epoch-helpers/index.js +6 -0
  22. package/dest/gas/gas_fees.d.ts +1 -1
  23. package/dest/gas/gas_fees.d.ts.map +1 -1
  24. package/dest/gas/gas_fees.js +4 -1
  25. package/dest/hash/hash.d.ts +19 -1
  26. package/dest/hash/hash.d.ts.map +1 -1
  27. package/dest/hash/hash.js +29 -0
  28. package/dest/interfaces/aztec-node-admin.d.ts +4 -1
  29. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  30. package/dest/interfaces/aztec-node.d.ts +2 -1
  31. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  32. package/dest/interfaces/block-builder.d.ts +25 -6
  33. package/dest/interfaces/block-builder.d.ts.map +1 -1
  34. package/dest/interfaces/configs.d.ts +7 -2
  35. package/dest/interfaces/configs.d.ts.map +1 -1
  36. package/dest/interfaces/configs.js +1 -0
  37. package/dest/interfaces/world_state.d.ts +5 -4
  38. package/dest/interfaces/world_state.d.ts.map +1 -1
  39. package/dest/kernel/claimed_length_array.js +1 -1
  40. package/dest/kernel/hints/private_kernel_reset_hints.d.ts +1 -1
  41. package/dest/kernel/hints/private_kernel_reset_hints.d.ts.map +1 -1
  42. package/dest/kernel/padded_side_effects.js +1 -1
  43. package/dest/kernel/private_to_avm_accumulated_data.js +2 -2
  44. package/dest/kernel/private_to_public_accumulated_data.js +2 -2
  45. package/dest/kernel/private_to_rollup_accumulated_data.js +1 -1
  46. package/dest/logs/index.d.ts +2 -1
  47. package/dest/logs/index.d.ts.map +1 -1
  48. package/dest/logs/index.js +1 -0
  49. package/dest/logs/message_context.d.ts +4 -7
  50. package/dest/logs/message_context.d.ts.map +1 -1
  51. package/dest/logs/message_context.js +23 -9
  52. package/dest/logs/pending_tagged_log.d.ts +2 -3
  53. package/dest/logs/pending_tagged_log.d.ts.map +1 -1
  54. package/dest/logs/pending_tagged_log.js +2 -2
  55. package/dest/logs/private_log.js +1 -1
  56. package/dest/logs/public_log.d.ts +1 -1
  57. package/dest/logs/public_log.d.ts.map +1 -1
  58. package/dest/logs/public_log.js +7 -1
  59. package/dest/logs/shared_secret_derivation.d.ts +11 -10
  60. package/dest/logs/shared_secret_derivation.d.ts.map +1 -1
  61. package/dest/logs/shared_secret_derivation.js +15 -9
  62. package/dest/logs/siloed_tag.d.ts +4 -1
  63. package/dest/logs/siloed_tag.d.ts.map +1 -1
  64. package/dest/logs/siloed_tag.js +7 -3
  65. package/dest/logs/tagging_index_range.d.ts +40 -0
  66. package/dest/logs/tagging_index_range.d.ts.map +1 -0
  67. package/dest/logs/tagging_index_range.js +8 -0
  68. package/dest/messaging/l1_to_l2_message.d.ts +3 -2
  69. package/dest/messaging/l1_to_l2_message.d.ts.map +1 -1
  70. package/dest/messaging/l1_to_l2_message.js +11 -13
  71. package/dest/noir/index.d.ts +3 -3
  72. package/dest/noir/index.d.ts.map +1 -1
  73. package/dest/parity/parity_base_private_inputs.js +1 -1
  74. package/dest/proofs/chonk_proof.d.ts +1 -1
  75. package/dest/proofs/chonk_proof.d.ts.map +1 -1
  76. package/dest/proofs/chonk_proof.js +7 -1
  77. package/dest/rollup/base_rollup_hints.js +2 -2
  78. package/dest/rollup/block_root_rollup_private_inputs.js +5 -5
  79. package/dest/rollup/checkpoint_rollup_public_inputs.js +1 -1
  80. package/dest/rollup/checkpoint_root_rollup_private_inputs.js +3 -3
  81. package/dest/rollup/root_rollup_public_inputs.js +1 -1
  82. package/dest/rollup/tree_snapshot_diff_hints.js +2 -2
  83. package/dest/tx/capsule.d.ts +6 -2
  84. package/dest/tx/capsule.d.ts.map +1 -1
  85. package/dest/tx/capsule.js +9 -3
  86. package/dest/tx/private_execution_result.d.ts +6 -6
  87. package/dest/tx/private_execution_result.d.ts.map +1 -1
  88. package/dest/tx/private_execution_result.js +6 -6
  89. package/dest/tx/profiling.d.ts +14 -2
  90. package/dest/tx/profiling.d.ts.map +1 -1
  91. package/dest/tx/profiling.js +13 -3
  92. package/dest/tx/protocol_contracts.js +2 -2
  93. package/dest/tx/validator/error_texts.d.ts +3 -1
  94. package/dest/tx/validator/error_texts.d.ts.map +1 -1
  95. package/dest/tx/validator/error_texts.js +3 -0
  96. package/dest/vks/vk_data.js +1 -1
  97. package/package.json +9 -9
  98. package/src/abi/buffer.ts +25 -4
  99. package/src/abi/decoder.ts +23 -78
  100. package/src/abi/function_selector.ts +1 -1
  101. package/src/abi/function_signature_decoder.ts +77 -0
  102. package/src/abi/index.ts +1 -0
  103. package/src/avm/avm_accumulated_data.ts +6 -6
  104. package/src/avm/avm_circuit_public_inputs.ts +4 -4
  105. package/src/block/l2_block_source.ts +4 -2
  106. package/src/checkpoint/validate.ts +2 -2
  107. package/src/epoch-helpers/index.ts +11 -0
  108. package/src/gas/README.md +123 -0
  109. package/src/gas/gas_fees.ts +7 -1
  110. package/src/hash/hash.ts +34 -0
  111. package/src/interfaces/aztec-node.ts +1 -0
  112. package/src/interfaces/block-builder.ts +27 -3
  113. package/src/interfaces/configs.ts +4 -1
  114. package/src/interfaces/world_state.ts +4 -3
  115. package/src/kernel/claimed_length_array.ts +2 -2
  116. package/src/kernel/hints/private_kernel_reset_hints.ts +5 -2
  117. package/src/kernel/hints/read_request_hints.ts +3 -3
  118. package/src/kernel/padded_side_effects.ts +3 -3
  119. package/src/kernel/private_to_avm_accumulated_data.ts +4 -4
  120. package/src/kernel/private_to_public_accumulated_data.ts +10 -10
  121. package/src/kernel/private_to_rollup_accumulated_data.ts +5 -5
  122. package/src/logs/index.ts +1 -0
  123. package/src/logs/message_context.ts +17 -7
  124. package/src/logs/pending_tagged_log.ts +1 -3
  125. package/src/logs/private_log.ts +1 -1
  126. package/src/logs/public_log.ts +11 -1
  127. package/src/logs/shared_secret_derivation.ts +21 -10
  128. package/src/logs/siloed_tag.ts +7 -2
  129. package/src/logs/tagging_index_range.ts +24 -0
  130. package/src/messaging/l1_to_l2_message.ts +12 -9
  131. package/src/noir/index.ts +2 -2
  132. package/src/parity/parity_base_private_inputs.ts +1 -1
  133. package/src/proofs/chonk_proof.ts +9 -1
  134. package/src/rollup/base_rollup_hints.ts +2 -2
  135. package/src/rollup/block_root_rollup_private_inputs.ts +8 -8
  136. package/src/rollup/checkpoint_rollup_public_inputs.ts +2 -2
  137. package/src/rollup/checkpoint_root_rollup_private_inputs.ts +4 -4
  138. package/src/rollup/root_rollup_public_inputs.ts +2 -2
  139. package/src/rollup/tree_snapshot_diff_hints.ts +5 -5
  140. package/src/tx/capsule.ts +10 -2
  141. package/src/tx/private_execution_result.ts +5 -5
  142. package/src/tx/profiling.ts +11 -2
  143. package/src/tx/protocol_contracts.ts +2 -2
  144. package/src/tx/validator/error_texts.ts +4 -0
  145. package/src/vks/vk_data.ts +1 -1
@@ -158,11 +158,11 @@ export class ReadRequestResetHints<
158
158
  > {
159
159
  const reader = BufferReader.asReader(buffer);
160
160
  return new ReadRequestResetHints(
161
- reader.readArray(readRequestLen, ReadRequestAction),
162
- reader.readArray(numPendingReads, PendingReadHint),
161
+ reader.readArray(readRequestLen, ReadRequestAction) as Tuple<ReadRequestAction, READ_REQUEST_LEN>,
162
+ reader.readArray(numPendingReads, PendingReadHint) as Tuple<PendingReadHint, PENDING_READ_HINTS_LEN>,
163
163
  reader.readArray(numSettledReads, {
164
164
  fromBuffer: r => SettledReadHint.fromBuffer(r, treeHeight, leafPreimageFromBuffer),
165
- }),
165
+ }) as Tuple<SettledReadHint<TREE_HEIGHT, LEAF_PREIMAGE>, SETTLED_READ_HINTS_LEN>,
166
166
  );
167
167
  }
168
168
 
@@ -19,9 +19,9 @@ export class PaddedSideEffects {
19
19
  static fromBuffer(buffer: Buffer | BufferReader) {
20
20
  const reader = BufferReader.asReader(buffer);
21
21
  return new PaddedSideEffects(
22
- reader.readArray(MAX_NOTE_HASHES_PER_TX, Fr),
23
- reader.readArray(MAX_NULLIFIERS_PER_TX, Fr),
24
- reader.readArray(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
22
+ reader.readTuple(MAX_NOTE_HASHES_PER_TX, Fr),
23
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, Fr),
24
+ reader.readTuple(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
25
25
  );
26
26
  }
27
27
 
@@ -73,7 +73,7 @@ export class PrivateToAvmAccumulatedData {
73
73
  return new this(
74
74
  reader.readFieldArray(MAX_NOTE_HASHES_PER_TX),
75
75
  reader.readFieldArray(MAX_NULLIFIERS_PER_TX),
76
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
76
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
77
77
  );
78
78
  }
79
79
 
@@ -94,9 +94,9 @@ export class PrivateToAvmAccumulatedData {
94
94
  static fromBuffer(buffer: Buffer | BufferReader) {
95
95
  const reader = BufferReader.asReader(buffer);
96
96
  return new PrivateToAvmAccumulatedData(
97
- reader.readArray(MAX_NOTE_HASHES_PER_TX, Fr),
98
- reader.readArray(MAX_NULLIFIERS_PER_TX, Fr),
99
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
97
+ reader.readTuple(MAX_NOTE_HASHES_PER_TX, Fr),
98
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, Fr),
99
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
100
100
  );
101
101
  }
102
102
 
@@ -62,10 +62,10 @@ export class PrivateToPublicAccumulatedData {
62
62
  return new this(
63
63
  reader.readFieldArray(MAX_NOTE_HASHES_PER_TX),
64
64
  reader.readFieldArray(MAX_NULLIFIERS_PER_TX),
65
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
66
- reader.readArray(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
67
- reader.readArray(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash),
68
- reader.readArray(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
65
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
66
+ reader.readTuple(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
67
+ reader.readTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash),
68
+ reader.readTuple(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
69
69
  );
70
70
  }
71
71
 
@@ -76,12 +76,12 @@ export class PrivateToPublicAccumulatedData {
76
76
  static fromBuffer(buffer: Buffer | BufferReader) {
77
77
  const reader = BufferReader.asReader(buffer);
78
78
  return new PrivateToPublicAccumulatedData(
79
- reader.readArray(MAX_NOTE_HASHES_PER_TX, Fr),
80
- reader.readArray(MAX_NULLIFIERS_PER_TX, Fr),
81
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
82
- reader.readArray(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
83
- reader.readArray(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash),
84
- reader.readArray(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
79
+ reader.readTuple(MAX_NOTE_HASHES_PER_TX, Fr),
80
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, Fr),
81
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
82
+ reader.readTuple(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
83
+ reader.readTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash),
84
+ reader.readTuple(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
85
85
  );
86
86
  }
87
87
 
@@ -95,11 +95,11 @@ export class PrivateToRollupAccumulatedData {
95
95
  static fromBuffer(buffer: Buffer | BufferReader): PrivateToRollupAccumulatedData {
96
96
  const reader = BufferReader.asReader(buffer);
97
97
  return new PrivateToRollupAccumulatedData(
98
- reader.readArray(MAX_NOTE_HASHES_PER_TX, Fr),
99
- reader.readArray(MAX_NULLIFIERS_PER_TX, Fr),
100
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
101
- reader.readArray(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
102
- reader.readArray(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash),
98
+ reader.readTuple(MAX_NOTE_HASHES_PER_TX, Fr),
99
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, Fr),
100
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
101
+ reader.readTuple(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
102
+ reader.readTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash),
103
103
  );
104
104
  }
105
105
 
package/src/logs/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './extended_directional_app_tagging_secret.js';
2
2
  export * from './pre_tag.js';
3
+ export * from './tagging_index_range.js';
3
4
  export * from './contract_class_log.js';
4
5
  export * from './public_log.js';
5
6
  export * from './private_log.js';
@@ -1,8 +1,7 @@
1
1
  import { MAX_NOTE_HASHES_PER_TX } from '@aztec/constants';
2
+ import { range } from '@aztec/foundation/array';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
4
 
4
- import type { AztecAddress } from '../aztec-address/index.js';
5
- import type { TxEffect } from '../tx/tx_effect.js';
6
5
  import type { TxHash } from '../tx/tx_hash.js';
7
6
 
8
7
  /**
@@ -19,7 +18,6 @@ export class MessageContext {
19
18
  public txHash: TxHash,
20
19
  public uniqueNoteHashesInTx: Fr[],
21
20
  public firstNullifierInTx: Fr,
22
- public recipient: AztecAddress,
23
21
  ) {}
24
22
 
25
23
  toFields(): Fr[] {
@@ -27,7 +25,6 @@ export class MessageContext {
27
25
  this.txHash.hash,
28
26
  ...serializeBoundedVec(this.uniqueNoteHashesInTx, MAX_NOTE_HASHES_PER_TX),
29
27
  this.firstNullifierInTx,
30
- this.recipient.toField(),
31
28
  ];
32
29
  }
33
30
 
@@ -37,13 +34,22 @@ export class MessageContext {
37
34
  tx_hash: this.txHash.hash,
38
35
  unique_note_hashes_in_tx: this.uniqueNoteHashesInTx,
39
36
  first_nullifier_in_tx: this.firstNullifierInTx,
40
- recipient: this.recipient,
41
37
  };
42
38
  /* eslint-enable camelcase */
43
39
  }
44
40
 
45
- static fromTxEffectAndRecipient(txEffect: TxEffect, recipient: AztecAddress): MessageContext {
46
- return new MessageContext(txEffect.txHash, txEffect.noteHashes, txEffect.nullifiers[0], recipient);
41
+ static toEmptyFields(): Fr[] {
42
+ const serializationLen =
43
+ 1 /* txHash */ + MAX_NOTE_HASHES_PER_TX + 1 /* uniqueNoteHashesInTx BVec */ + 1; /* firstNullifierInTx */
44
+ return range(serializationLen).map(_ => Fr.zero());
45
+ }
46
+
47
+ static toSerializedOption(response: MessageContext | null): Fr[] {
48
+ if (response) {
49
+ return [new Fr(1), ...response.toFields()];
50
+ } else {
51
+ return [new Fr(0), ...MessageContext.toEmptyFields()];
52
+ }
47
53
  }
48
54
  }
49
55
 
@@ -55,6 +61,10 @@ export class MessageContext {
55
61
  * @dev Copied over from pending_tagged_log.ts.
56
62
  */
57
63
  function serializeBoundedVec(values: Fr[], maxLength: number): Fr[] {
64
+ if (values.length > maxLength) {
65
+ throw new Error(`Attempted to serialize ${values} values into a BoundedVec with max length ${maxLength}`);
66
+ }
67
+
58
68
  const lengthDiff = maxLength - values.length;
59
69
  const zeroPaddingArray = Array(lengthDiff).fill(Fr.ZERO);
60
70
  const storage = values.concat(zeroPaddingArray);
@@ -1,7 +1,6 @@
1
1
  import { PRIVATE_LOG_SIZE_IN_FIELDS } from '@aztec/constants';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
3
 
4
- import type { AztecAddress } from '../aztec-address/index.js';
5
4
  import type { TxHash } from '../tx/tx_hash.js';
6
5
  import { MessageContext } from './message_context.js';
7
6
 
@@ -17,9 +16,8 @@ export class PendingTaggedLog {
17
16
  txHash: TxHash,
18
17
  uniqueNoteHashesInTx: Fr[],
19
18
  firstNullifierInTx: Fr,
20
- recipient: AztecAddress,
21
19
  ) {
22
- this.context = new MessageContext(txHash, uniqueNoteHashesInTx, firstNullifierInTx, recipient);
20
+ this.context = new MessageContext(txHash, uniqueNoteHashesInTx, firstNullifierInTx);
23
21
  }
24
22
 
25
23
  toFields(): Fr[] {
@@ -73,7 +73,7 @@ export class PrivateLog {
73
73
 
74
74
  static fromBuffer(buffer: Buffer | BufferReader) {
75
75
  const reader = BufferReader.asReader(buffer);
76
- return new PrivateLog(reader.readArray(PRIVATE_LOG_SIZE_IN_FIELDS, Fr), reader.readNumber());
76
+ return new PrivateLog(reader.readTuple(PRIVATE_LOG_SIZE_IN_FIELDS, Fr), reader.readNumber());
77
77
  }
78
78
 
79
79
  static random(tag = Fr.random()) {
@@ -1,4 +1,8 @@
1
- import { FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH, PUBLIC_LOG_HEADER_LENGTH } from '@aztec/constants';
1
+ import {
2
+ FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH,
3
+ MAX_PUBLIC_LOG_SIZE_IN_FIELDS,
4
+ PUBLIC_LOG_HEADER_LENGTH,
5
+ } from '@aztec/constants';
2
6
  import type { FieldsOf } from '@aztec/foundation/array';
3
7
  import { Fr } from '@aztec/foundation/curves/bn254';
4
8
  import { type ZodFor, schemas } from '@aztec/foundation/schemas';
@@ -76,6 +80,9 @@ export class FlatPublicLogs {
76
80
  static fromBuffer(buffer: Buffer | BufferReader) {
77
81
  const reader = BufferReader.asReader(buffer);
78
82
  const length = reader.readNumber();
83
+ if (length > FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH) {
84
+ throw new Error(`FlatPublicLogs length ${length} exceeds maximum ${FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH}`);
85
+ }
79
86
  return this.fromUnpaddedPayload(reader.readArray(length, Fr));
80
87
  }
81
88
 
@@ -171,6 +178,9 @@ export class PublicLog {
171
178
  static fromBuffer(buffer: Buffer | BufferReader) {
172
179
  const reader = BufferReader.asReader(buffer);
173
180
  const fieldsLength = reader.readNumber();
181
+ if (fieldsLength > MAX_PUBLIC_LOG_SIZE_IN_FIELDS) {
182
+ throw new Error(`PublicLog fields length ${fieldsLength} exceeds maximum ${MAX_PUBLIC_LOG_SIZE_IN_FIELDS}`);
183
+ }
174
184
  return new PublicLog(reader.readObject(AztecAddress), reader.readArray(fieldsLength, Fr));
175
185
  }
176
186
 
@@ -1,26 +1,37 @@
1
+ import { DomainSeparator } from '@aztec/constants';
1
2
  import { Grumpkin } from '@aztec/foundation/crypto/grumpkin';
2
- import type { GrumpkinScalar, Point } from '@aztec/foundation/curves/grumpkin';
3
+ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
4
+ import type { Fr } from '@aztec/foundation/curves/bn254';
5
+ import type { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
3
6
 
7
+ import type { AztecAddress } from '../aztec-address/index.js';
4
8
  import type { PublicKey } from '../keys/public_key.js';
5
9
 
6
10
  /**
7
- * Derive an Elliptic Curve Diffie-Hellman (ECDH) Shared Secret.
8
- * The function takes in an ECDH public key, a private key, and a Grumpkin instance to compute
9
- * the shared secret.
11
+ * Derives an app-siloed ECDH shared secret.
12
+ *
13
+ * Computes the raw ECDH shared secret `S = secretKey * publicKey`, then app-silos it:
14
+ * `s_app = h(DOM_SEP__APP_SILOED_ECDH_SHARED_SECRET, S.x, S.y, contractAddress)`
10
15
  *
11
16
  * @param secretKey - The secret key used to derive shared secret.
12
17
  * @param publicKey - The public key used to derive shared secret.
13
- * @returns A derived shared secret.
18
+ * @param contractAddress - The address of the calling contract, used for app-siloing.
19
+ * @returns The app-siloed shared secret as a Field.
14
20
  * @throws If the publicKey is zero.
15
- *
16
- * TODO(#12656): This function is kept around because of the utilityGetSharedSecret oracle. Nuke this once returning
17
- * the app-siloed secret.
18
21
  */
19
- export function deriveEcdhSharedSecret(secretKey: GrumpkinScalar, publicKey: PublicKey): Promise<Point> {
22
+ export async function deriveAppSiloedSharedSecret(
23
+ secretKey: GrumpkinScalar,
24
+ publicKey: PublicKey,
25
+ contractAddress: AztecAddress,
26
+ ): Promise<Fr> {
20
27
  if (publicKey.isZero()) {
21
28
  throw new Error(
22
29
  `Attempting to derive a shared secret with a zero public key. You have probably passed a zero public key in your Noir code somewhere thinking that the note won't be broadcast... but it was.`,
23
30
  );
24
31
  }
25
- return Grumpkin.mul(publicKey, secretKey);
32
+ const rawSharedSecret = await Grumpkin.mul(publicKey, secretKey);
33
+ return poseidon2HashWithSeparator(
34
+ [rawSharedSecret.x, rawSharedSecret.y, contractAddress],
35
+ DomainSeparator.APP_SILOED_ECDH_SHARED_SECRET,
36
+ );
26
37
  }
@@ -1,8 +1,9 @@
1
+ import { DomainSeparator } from '@aztec/constants';
1
2
  import type { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import type { ZodFor } from '@aztec/foundation/schemas';
3
4
 
4
5
  import type { AztecAddress } from '../aztec-address/index.js';
5
- import { computeSiloedPrivateLogFirstField } from '../hash/hash.js';
6
+ import { computeLogTag, computeSiloedPrivateLogFirstField } from '../hash/hash.js';
6
7
  import { schemas } from '../schemas/schemas.js';
7
8
  import type { PreTag } from './pre_tag.js';
8
9
  import { Tag } from './tag.js';
@@ -24,9 +25,13 @@ export class SiloedTag {
24
25
 
25
26
  static async compute(preTag: PreTag): Promise<SiloedTag> {
26
27
  const tag = await Tag.compute(preTag);
27
- return SiloedTag.computeFromTagAndApp(tag, preTag.extendedSecret.app);
28
+ const logTag = await computeLogTag(tag.value, DomainSeparator.UNCONSTRAINED_MSG_LOG_TAG);
29
+ return SiloedTag.computeFromTagAndApp(new Tag(logTag), preTag.extendedSecret.app);
28
30
  }
29
31
 
32
+ /**
33
+ * Unlike `compute`, this expects a tag whose value is already domain-separated.
34
+ */
30
35
  static async computeFromTagAndApp(tag: Tag, app: AztecAddress): Promise<SiloedTag> {
31
36
  const siloedTag = await computeSiloedPrivateLogFirstField(app, tag.value);
32
37
  return new SiloedTag(siloedTag);
@@ -0,0 +1,24 @@
1
+ import { schemas } from '@aztec/foundation/schemas';
2
+
3
+ import { z } from 'zod';
4
+
5
+ import {
6
+ type ExtendedDirectionalAppTaggingSecret,
7
+ ExtendedDirectionalAppTaggingSecretSchema,
8
+ } from './extended_directional_app_tagging_secret.js';
9
+
10
+ /**
11
+ * Represents a range of tagging indexes for a given extended directional app tagging secret. Used to track the lowest
12
+ * and highest indexes used in a transaction for a given (sender, recipient, app/contract) tuple.
13
+ */
14
+ export type TaggingIndexRange = {
15
+ extendedSecret: ExtendedDirectionalAppTaggingSecret;
16
+ lowestIndex: number;
17
+ highestIndex: number;
18
+ };
19
+
20
+ export const TaggingIndexRangeSchema = z.object({
21
+ extendedSecret: ExtendedDirectionalAppTaggingSecretSchema,
22
+ lowestIndex: schemas.Integer,
23
+ highestIndex: schemas.Integer,
24
+ });
@@ -6,6 +6,7 @@ import { bufferToHex } from '@aztec/foundation/string';
6
6
  import { SiblingPath } from '@aztec/foundation/trees';
7
7
 
8
8
  import type { AztecAddress } from '../aztec-address/index.js';
9
+ import type { BlockParameter } from '../block/block_parameter.js';
9
10
  import { computeL1ToL2MessageNullifier } from '../hash/hash.js';
10
11
  import type { AztecNode } from '../interfaces/aztec-node.js';
11
12
  import { MerkleTreeId } from '../trees/merkle_tree_id.js';
@@ -79,20 +80,22 @@ export async function getNonNullifiedL1ToL2MessageWitness(
79
80
  contractAddress: AztecAddress,
80
81
  messageHash: Fr,
81
82
  secret: Fr,
83
+ referenceBlock: BlockParameter = 'latest',
82
84
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
83
- const response = await node.getL1ToL2MessageMembershipWitness('latest', messageHash);
84
- if (!response) {
85
- throw new Error(`No L1 to L2 message found for message hash ${messageHash.toString()}`);
86
- }
85
+ const messageNullifier = await computeL1ToL2MessageNullifier(contractAddress, messageHash, secret);
87
86
 
88
- const [messageIndex, siblingPath] = response;
87
+ const [l1ToL2Response, nullifierResponse] = await Promise.all([
88
+ node.getL1ToL2MessageMembershipWitness(referenceBlock, messageHash),
89
+ node.findLeavesIndexes(referenceBlock, MerkleTreeId.NULLIFIER_TREE, [messageNullifier]),
90
+ ]);
89
91
 
90
- const messageNullifier = await computeL1ToL2MessageNullifier(contractAddress, messageHash, secret);
92
+ if (!l1ToL2Response) {
93
+ throw new Error(`No L1 to L2 message found for message hash ${messageHash.toString()}`);
94
+ }
91
95
 
92
- const [nullifierIndex] = await node.findLeavesIndexes('latest', MerkleTreeId.NULLIFIER_TREE, [messageNullifier]);
93
- if (nullifierIndex !== undefined) {
96
+ if (nullifierResponse[0] !== undefined) {
94
97
  throw new Error(`No non-nullified L1 to L2 message found for message hash ${messageHash.toString()}`);
95
98
  }
96
99
 
97
- return [messageIndex, siblingPath];
100
+ return l1ToL2Response;
98
101
  }
package/src/noir/index.ts CHANGED
@@ -19,7 +19,7 @@ export const AZTEC_VIEW_ATTRIBUTE = 'abi_view';
19
19
  export interface NoirFunctionAbi {
20
20
  /** The parameters of the function. */
21
21
  parameters: ABIParameter[];
22
- /** The return type of the function. */
22
+ /** The return type of the function, or null for void functions. */
23
23
  return_type: {
24
24
  /**
25
25
  * The type of the return value.
@@ -29,7 +29,7 @@ export interface NoirFunctionAbi {
29
29
  * The visibility of the return value.
30
30
  */
31
31
  visibility: ABIParameterVisibility;
32
- };
32
+ } | null;
33
33
  /** Mapping of error selector => error type */
34
34
  error_types: Partial<Record<string, AbiErrorType>>;
35
35
  }
@@ -41,7 +41,7 @@ export class ParityBasePrivateInputs {
41
41
  */
42
42
  static fromBuffer(buffer: Buffer | BufferReader) {
43
43
  const reader = BufferReader.asReader(buffer);
44
- return new ParityBasePrivateInputs(reader.readArray(NUM_MSGS_PER_BASE_PARITY, Fr), Fr.fromBuffer(reader));
44
+ return new ParityBasePrivateInputs(reader.readTuple(NUM_MSGS_PER_BASE_PARITY, Fr), Fr.fromBuffer(reader));
45
45
  }
46
46
 
47
47
  /**
@@ -56,7 +56,10 @@ export class ChonkProof {
56
56
  static fromBuffer(buffer: Buffer | BufferReader): ChonkProof {
57
57
  const reader = BufferReader.asReader(buffer);
58
58
  const proofLength = reader.readNumber();
59
- const proof = reader.readArray(proofLength, Fr);
59
+ if (proofLength !== CHONK_PROOF_LENGTH) {
60
+ throw new Error(`Invalid ChonkProof length from buffer: ${proofLength}, expected ${CHONK_PROOF_LENGTH}`);
61
+ }
62
+ const proof = reader.readArray(CHONK_PROOF_LENGTH, Fr);
60
63
  return new ChonkProof(proof);
61
64
  }
62
65
 
@@ -106,6 +109,11 @@ export class ChonkProofWithPublicInputs {
106
109
  static fromBuffer(buffer: Buffer | BufferReader): ChonkProofWithPublicInputs {
107
110
  const reader = BufferReader.asReader(buffer);
108
111
  const proofLength = reader.readNumber();
112
+ if (proofLength < CHONK_PROOF_LENGTH) {
113
+ throw new Error(
114
+ `Invalid ChonkProofWithPublicInputs length from buffer: ${proofLength}, expected at least ${CHONK_PROOF_LENGTH}`,
115
+ );
116
+ }
109
117
  const proof = reader.readArray(proofLength, Fr);
110
118
  return new ChonkProofWithPublicInputs(proof);
111
119
  }
@@ -86,7 +86,7 @@ export class PrivateBaseRollupHints {
86
86
  reader.readObject(SpongeBlob),
87
87
  reader.readObject(TreeSnapshotDiffHints),
88
88
  reader.readObject(PublicDataTreeLeafPreimage),
89
- reader.readArray(ARCHIVE_HEIGHT, Fr),
89
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
90
90
  makeTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, () => reader.readObject(ContractClassLogFields)),
91
91
  reader.readObject(BlockConstantData),
92
92
  );
@@ -163,7 +163,7 @@ export class PublicBaseRollupHints {
163
163
  return new PublicBaseRollupHints(
164
164
  reader.readObject(SpongeBlob),
165
165
  reader.readObject(AppendOnlyTreeSnapshot),
166
- reader.readArray(ARCHIVE_HEIGHT, Fr),
166
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
167
167
  makeTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, () => reader.readObject(ContractClassLogFields)),
168
168
  );
169
169
  }
@@ -60,8 +60,8 @@ export class BlockRootFirstRollupPrivateInputs {
60
60
  ProofData.fromBuffer(reader, ParityPublicInputs),
61
61
  [ProofData.fromBuffer(reader, TxRollupPublicInputs), ProofData.fromBuffer(reader, TxRollupPublicInputs)],
62
62
  AppendOnlyTreeSnapshot.fromBuffer(reader),
63
- reader.readArray(L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
64
- reader.readArray(ARCHIVE_HEIGHT, Fr),
63
+ reader.readTuple(L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
64
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
65
65
  );
66
66
  }
67
67
 
@@ -124,8 +124,8 @@ export class BlockRootSingleTxFirstRollupPrivateInputs {
124
124
  ProofData.fromBuffer(reader, ParityPublicInputs),
125
125
  ProofData.fromBuffer(reader, TxRollupPublicInputs),
126
126
  AppendOnlyTreeSnapshot.fromBuffer(reader),
127
- reader.readArray(L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
128
- reader.readArray(ARCHIVE_HEIGHT, Fr),
127
+ reader.readTuple(L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
128
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
129
129
  );
130
130
  }
131
131
 
@@ -206,8 +206,8 @@ export class BlockRootEmptyTxFirstRollupPrivateInputs {
206
206
  StateReference.fromBuffer(reader),
207
207
  CheckpointConstantData.fromBuffer(reader),
208
208
  reader.readUInt64(),
209
- reader.readArray(L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
210
- reader.readArray(ARCHIVE_HEIGHT, Fr),
209
+ reader.readTuple(L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
210
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
211
211
  );
212
212
  }
213
213
 
@@ -248,7 +248,7 @@ export class BlockRootRollupPrivateInputs {
248
248
  const reader = BufferReader.asReader(buffer);
249
249
  return new BlockRootRollupPrivateInputs(
250
250
  [ProofData.fromBuffer(reader, TxRollupPublicInputs), ProofData.fromBuffer(reader, TxRollupPublicInputs)],
251
- reader.readArray(ARCHIVE_HEIGHT, Fr),
251
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
252
252
  );
253
253
  }
254
254
 
@@ -289,7 +289,7 @@ export class BlockRootSingleTxRollupPrivateInputs {
289
289
  const reader = BufferReader.asReader(buffer);
290
290
  return new BlockRootSingleTxRollupPrivateInputs(
291
291
  ProofData.fromBuffer(reader, TxRollupPublicInputs),
292
- reader.readArray(ARCHIVE_HEIGHT, Fr),
292
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
293
293
  );
294
294
  }
295
295
 
@@ -65,8 +65,8 @@ export class CheckpointRollupPublicInputs {
65
65
  reader.readObject(AppendOnlyTreeSnapshot),
66
66
  reader.readObject(AppendOnlyTreeSnapshot),
67
67
  reader.readObject(AppendOnlyTreeSnapshot),
68
- reader.readArray(MAX_CHECKPOINTS_PER_EPOCH, Fr),
69
- reader.readArray(MAX_CHECKPOINTS_PER_EPOCH, FeeRecipient),
68
+ reader.readTuple(MAX_CHECKPOINTS_PER_EPOCH, Fr),
69
+ reader.readTuple(MAX_CHECKPOINTS_PER_EPOCH, FeeRecipient),
70
70
  reader.readObject(BlobAccumulator),
71
71
  reader.readObject(BlobAccumulator),
72
72
  reader.readObject(FinalBlobBatchingChallenges),
@@ -81,15 +81,15 @@ export class CheckpointRootRollupHints {
81
81
  const reader = BufferReader.asReader(buffer);
82
82
  return new CheckpointRootRollupHints(
83
83
  BlockHeader.fromBuffer(reader),
84
- reader.readArray(ARCHIVE_HEIGHT, Fr),
84
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
85
85
  reader.readObject(AppendOnlyTreeSnapshot),
86
- reader.readArray(OUT_HASH_TREE_HEIGHT, Fr),
86
+ reader.readTuple(OUT_HASH_TREE_HEIGHT, Fr),
87
87
  reader.readObject(BlobAccumulator),
88
88
  reader.readObject(FinalBlobBatchingChallenges),
89
89
  // Below line gives error 'Type instantiation is excessively deep and possibly infinite. ts(2589)'
90
- // reader.readArray(FIELDS_PER_BLOB, Fr),
90
+ // reader.readTuple(FIELDS_PER_BLOB, Fr),
91
91
  Array.from({ length: FIELDS_PER_BLOB * BLOBS_PER_CHECKPOINT }, () => Fr.fromBuffer(reader)),
92
- reader.readArray(BLOBS_PER_CHECKPOINT, BLS12Point),
92
+ reader.readTuple(BLOBS_PER_CHECKPOINT, BLS12Point),
93
93
  Fr.fromBuffer(reader),
94
94
  );
95
95
  }
@@ -68,8 +68,8 @@ export class RootRollupPublicInputs {
68
68
  Fr.fromBuffer(reader),
69
69
  Fr.fromBuffer(reader),
70
70
  Fr.fromBuffer(reader),
71
- reader.readArray(MAX_CHECKPOINTS_PER_EPOCH, Fr),
72
- reader.readArray(MAX_CHECKPOINTS_PER_EPOCH, FeeRecipient),
71
+ reader.readTuple(MAX_CHECKPOINTS_PER_EPOCH, Fr),
72
+ reader.readTuple(MAX_CHECKPOINTS_PER_EPOCH, FeeRecipient),
73
73
  EpochConstantData.fromBuffer(reader),
74
74
  reader.readObject(FinalBlobAccumulator),
75
75
  );
@@ -85,14 +85,14 @@ export class TreeSnapshotDiffHints {
85
85
  static fromBuffer(buffer: Buffer | BufferReader): TreeSnapshotDiffHints {
86
86
  const reader = BufferReader.asReader(buffer);
87
87
  return new TreeSnapshotDiffHints(
88
- reader.readArray(NOTE_HASH_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
89
- reader.readArray(MAX_NULLIFIERS_PER_TX, NullifierLeafPreimage),
90
- reader.readArray(MAX_NULLIFIERS_PER_TX, {
88
+ reader.readTuple(NOTE_HASH_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
89
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, NullifierLeafPreimage),
90
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, {
91
91
  fromBuffer: buffer => MembershipWitness.fromBuffer(buffer, NULLIFIER_TREE_HEIGHT),
92
92
  }),
93
- reader.readArray(MAX_NULLIFIERS_PER_TX, Fr),
93
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, Fr),
94
94
  reader.readNumbers(MAX_NULLIFIERS_PER_TX),
95
- reader.readArray(NULLIFIER_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
95
+ reader.readTuple(NULLIFIER_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
96
96
  MembershipWitness.fromBuffer(reader, PUBLIC_DATA_TREE_HEIGHT),
97
97
  );
98
98
  }
package/src/tx/capsule.ts CHANGED
@@ -19,6 +19,8 @@ export class Capsule {
19
19
  public readonly storageSlot: Fr,
20
20
  /** Data passed to the contract */
21
21
  public readonly data: Fr[],
22
+ /** Optional namespace for the capsule contents */
23
+ public readonly scope?: AztecAddress,
22
24
  ) {}
23
25
 
24
26
  static get schema() {
@@ -30,12 +32,18 @@ export class Capsule {
30
32
  }
31
33
 
32
34
  toBuffer() {
33
- return serializeToBuffer(this.contractAddress, this.storageSlot, new Vector(this.data));
35
+ return this.scope
36
+ ? serializeToBuffer(this.contractAddress, this.storageSlot, new Vector(this.data), true, this.scope)
37
+ : serializeToBuffer(this.contractAddress, this.storageSlot, new Vector(this.data), false);
34
38
  }
35
39
 
36
40
  static fromBuffer(buffer: Buffer | BufferReader): Capsule {
37
41
  const reader = BufferReader.asReader(buffer);
38
- return new Capsule(AztecAddress.fromBuffer(reader), Fr.fromBuffer(reader), reader.readVector(Fr));
42
+ const contractAddress = AztecAddress.fromBuffer(reader);
43
+ const storageSlot = Fr.fromBuffer(reader);
44
+ const data = reader.readVector(Fr);
45
+ const hasScope = reader.readBoolean();
46
+ return new Capsule(contractAddress, storageSlot, data, hasScope ? AztecAddress.fromBuffer(reader) : undefined);
39
47
  }
40
48
 
41
49
  toString() {
@@ -11,7 +11,7 @@ import { PrivateCircuitPublicInputs } from '../kernel/private_circuit_public_inp
11
11
  import type { IsEmpty } from '../kernel/utils/interfaces.js';
12
12
  import { sortByCounter } from '../kernel/utils/order_and_comparison.js';
13
13
  import { ContractClassLog, ContractClassLogFields } from '../logs/contract_class_log.js';
14
- import { type PreTag, PreTagSchema } from '../logs/pre_tag.js';
14
+ import { type TaggingIndexRange, TaggingIndexRangeSchema } from '../logs/tagging_index_range.js';
15
15
  import { Note } from '../note/note.js';
16
16
  import { type ZodFor, mapSchema, schemas } from '../schemas/index.js';
17
17
  import { HashedValues } from './hashed_values.js';
@@ -137,8 +137,8 @@ export class PrivateCallExecutionResult {
137
137
  public returnValues: Fr[],
138
138
  /** The offchain effects emitted during execution of this function call via the `emit_offchain_effect` oracle. */
139
139
  public offchainEffects: { data: Fr[] }[],
140
- /** The pre-tags used in this tx to compute tags for private logs */
141
- public preTags: PreTag[],
140
+ /** The tagging index ranges used in this tx to compute tags for private logs */
141
+ public taggingIndexRanges: TaggingIndexRange[],
142
142
  /** The nested executions. */
143
143
  public nestedExecutionResults: PrivateCallExecutionResult[],
144
144
  /**
@@ -161,7 +161,7 @@ export class PrivateCallExecutionResult {
161
161
  noteHashNullifierCounterMap: mapSchema(z.coerce.number(), z.number()),
162
162
  returnValues: z.array(schemas.Fr),
163
163
  offchainEffects: z.array(z.object({ data: z.array(schemas.Fr) })),
164
- preTags: z.array(PreTagSchema),
164
+ taggingIndexRanges: z.array(TaggingIndexRangeSchema),
165
165
  nestedExecutionResults: z.array(z.lazy(() => PrivateCallExecutionResult.schema)),
166
166
  contractClassLogs: z.array(CountedContractClassLog.schema),
167
167
  })
@@ -178,7 +178,7 @@ export class PrivateCallExecutionResult {
178
178
  fields.noteHashNullifierCounterMap,
179
179
  fields.returnValues,
180
180
  fields.offchainEffects,
181
- fields.preTags,
181
+ fields.taggingIndexRanges,
182
182
  fields.nestedExecutionResults,
183
183
  fields.contractClassLogs,
184
184
  );