@aztec/stdlib 0.0.1-commit.3fd054f6 → 0.0.1-commit.42ee6df9b

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 (108) hide show
  1. package/dest/abi/decoder.d.ts +5 -44
  2. package/dest/abi/decoder.d.ts.map +1 -1
  3. package/dest/abi/decoder.js +12 -67
  4. package/dest/abi/function_selector.js +1 -1
  5. package/dest/abi/function_signature_decoder.d.ts +43 -0
  6. package/dest/abi/function_signature_decoder.d.ts.map +1 -0
  7. package/dest/abi/function_signature_decoder.js +66 -0
  8. package/dest/abi/index.d.ts +2 -1
  9. package/dest/abi/index.d.ts.map +1 -1
  10. package/dest/abi/index.js +1 -0
  11. package/dest/block/l2_block_source.d.ts +80 -3
  12. package/dest/block/l2_block_source.d.ts.map +1 -1
  13. package/dest/block/l2_block_source.js +1 -0
  14. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +1 -1
  15. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
  16. package/dest/block/l2_block_stream/l2_tips_store_base.js +17 -4
  17. package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
  18. package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
  19. package/dest/block/test/l2_tips_store_test_suite.js +3 -2
  20. package/dest/checkpoint/checkpoint.d.ts +7 -1
  21. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  22. package/dest/checkpoint/checkpoint.js +9 -1
  23. package/dest/checkpoint/checkpoint_data.d.ts +71 -5
  24. package/dest/checkpoint/checkpoint_data.d.ts.map +1 -1
  25. package/dest/checkpoint/checkpoint_data.js +10 -0
  26. package/dest/epoch-helpers/index.d.ts +5 -1
  27. package/dest/epoch-helpers/index.d.ts.map +1 -1
  28. package/dest/epoch-helpers/index.js +6 -0
  29. package/dest/file-store/factory.d.ts +4 -3
  30. package/dest/file-store/factory.d.ts.map +1 -1
  31. package/dest/file-store/factory.js +2 -2
  32. package/dest/file-store/http.d.ts +9 -2
  33. package/dest/file-store/http.d.ts.map +1 -1
  34. package/dest/file-store/http.js +20 -9
  35. package/dest/file-store/index.d.ts +2 -1
  36. package/dest/file-store/index.d.ts.map +1 -1
  37. package/dest/hash/hash.d.ts +4 -1
  38. package/dest/hash/hash.d.ts.map +1 -1
  39. package/dest/hash/hash.js +5 -0
  40. package/dest/interfaces/archiver.d.ts +1 -1
  41. package/dest/interfaces/archiver.d.ts.map +1 -1
  42. package/dest/interfaces/archiver.js +3 -1
  43. package/dest/interfaces/aztec-node-admin.d.ts +1 -4
  44. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  45. package/dest/interfaces/proving-job.d.ts +34 -34
  46. package/dest/interfaces/validator.d.ts +2 -10
  47. package/dest/interfaces/validator.d.ts.map +1 -1
  48. package/dest/interfaces/validator.js +0 -1
  49. package/dest/logs/extended_directional_app_tagging_secret.d.ts +4 -4
  50. package/dest/logs/extended_directional_app_tagging_secret.d.ts.map +1 -1
  51. package/dest/logs/extended_directional_app_tagging_secret.js +12 -5
  52. package/dest/logs/message_context.d.ts +4 -7
  53. package/dest/logs/message_context.d.ts.map +1 -1
  54. package/dest/logs/message_context.js +23 -9
  55. package/dest/logs/pending_tagged_log.d.ts +2 -3
  56. package/dest/logs/pending_tagged_log.d.ts.map +1 -1
  57. package/dest/logs/pending_tagged_log.js +2 -2
  58. package/dest/logs/shared_secret_derivation.d.ts +11 -10
  59. package/dest/logs/shared_secret_derivation.d.ts.map +1 -1
  60. package/dest/logs/shared_secret_derivation.js +15 -9
  61. package/dest/logs/siloed_tag.d.ts +4 -1
  62. package/dest/logs/siloed_tag.d.ts.map +1 -1
  63. package/dest/logs/siloed_tag.js +7 -3
  64. package/dest/messaging/l1_to_l2_message.d.ts +3 -2
  65. package/dest/messaging/l1_to_l2_message.d.ts.map +1 -1
  66. package/dest/messaging/l1_to_l2_message.js +11 -13
  67. package/dest/note/note_dao.d.ts +1 -1
  68. package/dest/note/note_dao.d.ts.map +1 -1
  69. package/dest/note/note_dao.js +1 -4
  70. package/dest/proofs/chonk_proof.d.ts +46 -2
  71. package/dest/proofs/chonk_proof.d.ts.map +1 -1
  72. package/dest/proofs/chonk_proof.js +85 -10
  73. package/dest/tests/factories.d.ts +1 -1
  74. package/dest/tests/factories.d.ts.map +1 -1
  75. package/dest/tests/factories.js +10 -0
  76. package/dest/tx/capsule.d.ts +6 -2
  77. package/dest/tx/capsule.d.ts.map +1 -1
  78. package/dest/tx/capsule.js +9 -3
  79. package/dest/tx/global_variable_builder.d.ts +14 -2
  80. package/dest/tx/global_variable_builder.d.ts.map +1 -1
  81. package/package.json +8 -8
  82. package/src/abi/decoder.ts +23 -78
  83. package/src/abi/function_selector.ts +1 -1
  84. package/src/abi/function_signature_decoder.ts +77 -0
  85. package/src/abi/index.ts +1 -0
  86. package/src/block/l2_block_source.ts +10 -2
  87. package/src/block/l2_block_stream/l2_tips_store_base.ts +24 -12
  88. package/src/block/test/l2_tips_store_test_suite.ts +8 -1
  89. package/src/checkpoint/checkpoint.ts +11 -1
  90. package/src/checkpoint/checkpoint_data.ts +40 -4
  91. package/src/epoch-helpers/index.ts +13 -0
  92. package/src/file-store/factory.ts +13 -4
  93. package/src/file-store/http.ts +29 -10
  94. package/src/file-store/index.ts +1 -0
  95. package/src/hash/hash.ts +5 -0
  96. package/src/interfaces/archiver.ts +3 -1
  97. package/src/interfaces/validator.ts +1 -5
  98. package/src/logs/extended_directional_app_tagging_secret.ts +19 -8
  99. package/src/logs/message_context.ts +17 -7
  100. package/src/logs/pending_tagged_log.ts +1 -3
  101. package/src/logs/shared_secret_derivation.ts +21 -10
  102. package/src/logs/siloed_tag.ts +7 -2
  103. package/src/messaging/l1_to_l2_message.ts +12 -9
  104. package/src/note/note_dao.ts +1 -4
  105. package/src/proofs/chonk_proof.ts +91 -5
  106. package/src/tests/factories.ts +4 -0
  107. package/src/tx/capsule.ts +10 -2
  108. package/src/tx/global_variable_builder.ts +15 -0
@@ -23,14 +23,14 @@ import { computeAddressSecret, computePreaddress } from '../keys/derivation.js';
23
23
  * doesn't seem to be a good way around this.
24
24
  */
25
25
  export class ExtendedDirectionalAppTaggingSecret {
26
- private constructor(
26
+ constructor(
27
27
  public readonly secret: Fr,
28
28
  public readonly app: AztecAddress,
29
29
  ) {}
30
30
 
31
31
  /**
32
32
  * Derives shared tagging secret and from that, the app address and recipient derives the directional app tagging
33
- * secret.
33
+ * secret. Returns undefined if `externalAddress` is an invalid address.
34
34
  *
35
35
  * @param localAddress - The complete address of entity A in the shared tagging secret derivation scheme
36
36
  * @param localIvsk - The incoming viewing secret key of entity A
@@ -45,8 +45,12 @@ export class ExtendedDirectionalAppTaggingSecret {
45
45
  externalAddress: AztecAddress,
46
46
  app: AztecAddress,
47
47
  recipient: AztecAddress,
48
- ): Promise<ExtendedDirectionalAppTaggingSecret> {
48
+ ): Promise<ExtendedDirectionalAppTaggingSecret | undefined> {
49
49
  const taggingSecretPoint = await computeSharedTaggingSecret(localAddress, localIvsk, externalAddress);
50
+ if (!taggingSecretPoint) {
51
+ return undefined;
52
+ }
53
+
50
54
  const appTaggingSecret = await poseidon2Hash([taggingSecretPoint.x, taggingSecretPoint.y, app]);
51
55
  const directionalAppTaggingSecret = await poseidon2Hash([appTaggingSecret, recipient]);
52
56
 
@@ -63,18 +67,25 @@ export class ExtendedDirectionalAppTaggingSecret {
63
67
  }
64
68
  }
65
69
 
66
- // Returns shared tagging secret computed with Diffie-Hellman key exchange.
70
+ // Returns shared tagging secret computed with Diffie-Hellman key exchange, or undefined if `externalAddress` is an
71
+ // invalid address.
67
72
  async function computeSharedTaggingSecret(
68
73
  localAddress: CompleteAddress,
69
74
  localIvsk: Fq,
70
75
  externalAddress: AztecAddress,
71
- ): Promise<Point> {
72
- const knownPreaddress = await computePreaddress(await localAddress.publicKeys.hash(), localAddress.partialAddress);
73
- // TODO: #8970 - Computation of address point from x coordinate might fail
74
- const externalAddressPoint = await externalAddress.toAddressPoint();
76
+ ): Promise<Point | undefined> {
75
77
  // Given A (local complete address) -> B (external address) and h == preaddress
76
78
  // Compute shared secret as S = (h_A + local_ivsk_A) * Addr_Point_B
77
79
 
80
+ const knownPreaddress = await computePreaddress(await localAddress.publicKeys.hash(), localAddress.partialAddress);
81
+
82
+ // An invalid address has no corresponding address point
83
+ if (!(await externalAddress.isValid())) {
84
+ return undefined;
85
+ }
86
+
87
+ const externalAddressPoint = await externalAddress.toAddressPoint();
88
+
78
89
  // Beware! h_a + local_ivsk_a (also known as the address secret) can lead to an address point with a negative
79
90
  // y-coordinate, since there's two possible candidates computeAddressSecret takes care of selecting the one that
80
91
  // leads to a positive y-coordinate, which is the only valid address point
@@ -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[] {
@@ -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);
@@ -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
  }
@@ -1,6 +1,5 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { Point } from '@aztec/foundation/curves/grumpkin';
4
3
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
5
4
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
5
  import { Note } from '@aztec/stdlib/note';
@@ -148,9 +147,7 @@ export class NoteDao {
148
147
  * @returns - Its size in bytes.
149
148
  */
150
149
  public getSize() {
151
- const noteSize = 4 + this.note.items.length * Fr.SIZE_IN_BYTES;
152
- // 2 numbers for txIndexInBlock and noteIndexInTx (4 bytes each)
153
- return noteSize + AztecAddress.SIZE_IN_BYTES * 2 + Fr.SIZE_IN_BYTES * 4 + TxHash.SIZE + Point.SIZE_IN_BYTES + 8;
150
+ return this.toBuffer().length;
154
151
  }
155
152
 
156
153
  static async random({
@@ -1,21 +1,41 @@
1
+ import { BarretenbergSync, flattenChonkProofFields } from '@aztec/bb.js';
1
2
  import { CHONK_PROOF_LENGTH } from '@aztec/constants';
2
3
  import { times } from '@aztec/foundation/collection';
3
4
  import { randomBytes } from '@aztec/foundation/crypto/random';
4
5
  import { Fr } from '@aztec/foundation/curves/bn254';
5
6
  import { bufferSchemaFor } from '@aztec/foundation/schemas';
6
- import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
7
+ import { BufferReader, numToUInt32BE, serializeToBuffer } from '@aztec/foundation/serialize';
8
+
9
+ /**
10
+ * Serialization format detection for ChonkProof is size-based:
11
+ * - UNCOMPRESSED (legacy): [field_count=1632: uint32] [fields...] → total ≈ 52KB (>= 40KB)
12
+ * - COMPRESSED: [byte_count: uint32] [compressed_bytes] → total ≈ 35KB (< 40KB)
13
+ *
14
+ * Detection: if the first uint32 equals CHONK_PROOF_LENGTH (1632), it's legacy format
15
+ * (field count). Otherwise, it's compressed format (byte count). The old uncompressed
16
+ * format is never smaller than 40KB; compressed proofs are always smaller than 40KB.
17
+ */
7
18
 
8
19
  // CHONK: "Client Honk" - An UltraHonk variant with incremental folding and delayed non-native arithmetic.
9
20
  export class ChonkProof {
21
+ /**
22
+ * Optional compressed proof bytes from chonk compression (point compression + u256 encoding).
23
+ * When set, toBuffer() will serialize in compressed format (~1.7x smaller).
24
+ * When reading from compressed format, this is populated and fields are decompressed on demand.
25
+ */
26
+ public compressedProof?: Buffer;
27
+
10
28
  constructor(
11
29
  // The proof fields.
12
30
  // For native verification, attach public inputs via `attachPublicInputs(publicInputs)`.
13
31
  // Not using Tuple here due to the length being too high.
14
32
  public fields: Fr[],
33
+ compressedProof?: Buffer,
15
34
  ) {
16
35
  if (fields.length !== CHONK_PROOF_LENGTH) {
17
36
  throw new Error(`Invalid ChonkProof length: ${fields.length}`);
18
37
  }
38
+ this.compressedProof = compressedProof;
19
39
  }
20
40
 
21
41
  public attachPublicInputs(publicInputs: Fr[]) {
@@ -53,19 +73,84 @@ export class ChonkProof {
53
73
  return this.toBuffer();
54
74
  }
55
75
 
76
+ /**
77
+ * Deserialize a ChonkProof from a buffer.
78
+ * Supports both legacy (field elements) and compressed (chonk compression) formats.
79
+ *
80
+ * Size-based format detection:
81
+ * - First uint32 == CHONK_PROOF_LENGTH (1632): legacy format, read field elements
82
+ * Total proof data ≈ 52KB (always >= 40KB)
83
+ * - Otherwise: compressed format, first uint32 is byte count of compressed data
84
+ * Total proof data ≈ 35KB (always < 40KB)
85
+ */
56
86
  static fromBuffer(buffer: Buffer | BufferReader): ChonkProof {
57
87
  const reader = BufferReader.asReader(buffer);
58
- const proofLength = reader.readNumber();
59
- const proof = reader.readArray(proofLength, Fr);
60
- return new ChonkProof(proof);
88
+ const firstUint32 = reader.readNumber();
89
+
90
+ if (firstUint32 === CHONK_PROOF_LENGTH) {
91
+ // Legacy format: firstUint32 is the field count (1632)
92
+ // Widen to `number` to prevent TS from narrowing to literal 1632,
93
+ // which would cause Tuple<Fr, 1632> to exceed the recursion limit.
94
+ const fieldCount: number = firstUint32;
95
+ const proof = reader.readArray(fieldCount, Fr);
96
+ return new ChonkProof(proof);
97
+ }
98
+
99
+ // Compressed format: firstUint32 is the compressed byte count
100
+ const compressedBytes = reader.readBytes(firstUint32);
101
+ return ChonkProof.fromCompressedBytes(Buffer.from(compressedBytes));
102
+ }
103
+
104
+ /**
105
+ * Create a ChonkProof from compressed bytes by decompressing via the BarretenbergSync API.
106
+ * The compressed format uses point compression and u256 encoding (from PR #20645).
107
+ *
108
+ * @param compressed - Compressed proof bytes from chonk compression
109
+ * @returns ChonkProof with both fields and compressed bytes populated
110
+ */
111
+ static fromCompressedBytes(compressed: Buffer): ChonkProof {
112
+ const api = BarretenbergSync.getSingleton();
113
+ const result = api.chonkDecompressProof({ compressedProof: new Uint8Array(compressed) });
114
+
115
+ // Flatten the structured bb.js ChonkProof into flat Fr[] field elements
116
+ const flatFields = flattenChonkProofFields(result.proof);
117
+ const fields = flatFields.map(f => Fr.fromBuffer(Buffer.from(f)));
118
+
119
+ // The decompressed proof includes public inputs in hidingOinkProof.
120
+ // Since ChonkProof stores fields WITHOUT public inputs, strip them.
121
+ // The number of public inputs = total fields - CHONK_PROOF_LENGTH
122
+ if (fields.length > CHONK_PROOF_LENGTH) {
123
+ const numPubInputs = fields.length - CHONK_PROOF_LENGTH;
124
+ const proofFields = fields.slice(numPubInputs);
125
+ return new ChonkProof(proofFields, compressed);
126
+ }
127
+
128
+ return new ChonkProof(fields, compressed);
61
129
  }
62
130
 
131
+ /**
132
+ * Serialize the proof to a buffer.
133
+ * If compressed bytes are available, uses the compressed format (~1.7x smaller).
134
+ * Otherwise falls back to legacy field element format.
135
+ */
63
136
  public toBuffer() {
137
+ if (this.compressedProof) {
138
+ // Compressed format: [compressed_byte_count: uint32] [compressed_bytes]
139
+ return Buffer.concat([numToUInt32BE(this.compressedProof.length), this.compressedProof]);
140
+ }
141
+ // Legacy format: [field_count=1632: uint32] [fields...]
64
142
  return serializeToBuffer(this.fields.length, this.fields);
65
143
  }
66
144
  }
67
145
 
68
146
  export class ChonkProofWithPublicInputs {
147
+ /**
148
+ * Optional compressed proof bytes (covers the full proof WITH public inputs).
149
+ * Set by the prover when using chonk compression. Flows through to ChonkProof
150
+ * via removePublicInputs() so the Tx can serialize in compressed format.
151
+ */
152
+ public compressedProof?: Buffer;
153
+
69
154
  constructor(
70
155
  // The proof fields with public inputs.
71
156
  // For recursive verification, use without public inputs via `removePublicInputs()`.
@@ -83,7 +168,8 @@ export class ChonkProofWithPublicInputs {
83
168
 
84
169
  public removePublicInputs() {
85
170
  const numPublicInputs = this.fieldsWithPublicInputs.length - CHONK_PROOF_LENGTH;
86
- return new ChonkProof(this.fieldsWithPublicInputs.slice(numPublicInputs));
171
+ // Flow compressed proof bytes through so the ChonkProof can serialize efficiently
172
+ return new ChonkProof(this.fieldsWithPublicInputs.slice(numPublicInputs), this.compressedProof);
87
173
  }
88
174
 
89
175
  public isEmpty() {
@@ -1715,6 +1715,10 @@ export function makeL2Tips(
1715
1715
  block: { number: bn, hash },
1716
1716
  checkpoint: { number: cpn, hash: cph },
1717
1717
  },
1718
+ proposedCheckpoint: {
1719
+ block: { number: bn, hash },
1720
+ checkpoint: { number: cpn, hash: cph },
1721
+ },
1718
1722
  proven: {
1719
1723
  block: { number: bn, hash },
1720
1724
  checkpoint: { number: cpn, hash: cph },
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() {
@@ -1,3 +1,5 @@
1
+ import type { FeeHeader } from '@aztec/ethereum/contracts';
2
+ import type { CheckpointNumber } from '@aztec/foundation/branded-types';
1
3
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
4
  import type { SlotNumber } from '@aztec/foundation/schemas';
3
5
 
@@ -6,6 +8,18 @@ import type { GasFees } from '../gas/gas_fees.js';
6
8
  import type { UInt32 } from '../types/index.js';
7
9
  import type { CheckpointGlobalVariables, GlobalVariables } from './global_variables.js';
8
10
 
11
+ /** Fee header fields needed for pipelining overrides. */
12
+ export type ForceProposedFeeHeader = {
13
+ checkpointNumber: CheckpointNumber;
14
+ feeHeader: FeeHeader;
15
+ };
16
+
17
+ /** Options for building checkpoint global variables during pipelining. */
18
+ export type BuildCheckpointGlobalVariablesOpts = {
19
+ forcePendingCheckpointNumber?: CheckpointNumber;
20
+ forceProposedFeeHeader?: ForceProposedFeeHeader;
21
+ };
22
+
9
23
  /**
10
24
  * Interface for building global variables for Aztec blocks.
11
25
  */
@@ -32,5 +46,6 @@ export interface GlobalVariableBuilder {
32
46
  coinbase: EthAddress,
33
47
  feeRecipient: AztecAddress,
34
48
  slotNumber: SlotNumber,
49
+ opts?: BuildCheckpointGlobalVariablesOpts,
35
50
  ): Promise<CheckpointGlobalVariables>;
36
51
  }