@aztec/stdlib 0.0.1-commit.cbf2c2d5d → 0.0.1-commit.ce4f8c4f2
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.
- package/dest/messaging/l1_to_l2_message.d.ts +3 -2
- package/dest/messaging/l1_to_l2_message.d.ts.map +1 -1
- package/dest/messaging/l1_to_l2_message.js +11 -13
- package/dest/proofs/chonk_proof.d.ts +46 -2
- package/dest/proofs/chonk_proof.d.ts.map +1 -1
- package/dest/proofs/chonk_proof.js +85 -10
- package/package.json +8 -8
- package/src/messaging/l1_to_l2_message.ts +12 -9
- package/src/proofs/chonk_proof.ts +91 -5
|
@@ -3,6 +3,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { BufferReader } from '@aztec/foundation/serialize';
|
|
4
4
|
import { SiblingPath } from '@aztec/foundation/trees';
|
|
5
5
|
import type { AztecAddress } from '../aztec-address/index.js';
|
|
6
|
+
import type { BlockParameter } from '../block/block_parameter.js';
|
|
6
7
|
import type { AztecNode } from '../interfaces/aztec-node.js';
|
|
7
8
|
import { L1Actor } from './l1_actor.js';
|
|
8
9
|
import { L2Actor } from './l2_actor.js';
|
|
@@ -44,5 +45,5 @@ export declare class L1ToL2Message {
|
|
|
44
45
|
static empty(): L1ToL2Message;
|
|
45
46
|
static random(): Promise<L1ToL2Message>;
|
|
46
47
|
}
|
|
47
|
-
export declare function getNonNullifiedL1ToL2MessageWitness(node: AztecNode, contractAddress: AztecAddress, messageHash: Fr, secret: Fr): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]>;
|
|
48
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
48
|
+
export declare function getNonNullifiedL1ToL2MessageWitness(node: AztecNode, contractAddress: AztecAddress, messageHash: Fr, secret: Fr, referenceBlock?: BlockParameter): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]>;
|
|
49
|
+
//# s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AK,EAAE,EAAE,EACvB;IAEJ;;;OAGG;IACH,QAAQ,IAAI,EAAE,EAAE,CAEf;IAED,QAAQ,IAAI,MAAM,CAEjB;IAED,IAAI,IAAI,EAAE,CAET;IAED,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,aAAa,CAQ9D;IAED,QAAQ,IAAI,MAAM,CAEjB;IAED,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAG7C;IAED,MAAM,CAAC,KAAK,IAAI,aAAa,CAE5B;IAED,OAAa,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,CAE5C;CACF;AAGD,wBAAsB,mCAAmC,CACvD,IAAI,EAAE,SAAS,EACf,eAAe,EAAE,YAAY,EAC7B,WAAW,EAAE,EAAE,EACf,MAAM,EAAE,EAAE,EACV,cAAc,GAAE,cAAyB,GACxC,OAAO,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC,CAiBjE"}
|
|
@@ -63,21 +63,19 @@ import { L2Actor } from './l2_actor.js';
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
// This functionality is not on the node because we do not want to pass the node the secret, and give the node the ability to derive a valid nullifer for an L1 to L2 message.
|
|
66
|
-
export async function getNonNullifiedL1ToL2MessageWitness(node, contractAddress, messageHash, secret) {
|
|
67
|
-
const response = await node.getL1ToL2MessageMembershipWitness('latest', messageHash);
|
|
68
|
-
if (!response) {
|
|
69
|
-
throw new Error(`No L1 to L2 message found for message hash ${messageHash.toString()}`);
|
|
70
|
-
}
|
|
71
|
-
const [messageIndex, siblingPath] = response;
|
|
66
|
+
export async function getNonNullifiedL1ToL2MessageWitness(node, contractAddress, messageHash, secret, referenceBlock = 'latest') {
|
|
72
67
|
const messageNullifier = await computeL1ToL2MessageNullifier(contractAddress, messageHash, secret);
|
|
73
|
-
const [
|
|
74
|
-
|
|
68
|
+
const [l1ToL2Response, nullifierResponse] = await Promise.all([
|
|
69
|
+
node.getL1ToL2MessageMembershipWitness(referenceBlock, messageHash),
|
|
70
|
+
node.findLeavesIndexes(referenceBlock, MerkleTreeId.NULLIFIER_TREE, [
|
|
71
|
+
messageNullifier
|
|
72
|
+
])
|
|
75
73
|
]);
|
|
76
|
-
if (
|
|
74
|
+
if (!l1ToL2Response) {
|
|
75
|
+
throw new Error(`No L1 to L2 message found for message hash ${messageHash.toString()}`);
|
|
76
|
+
}
|
|
77
|
+
if (nullifierResponse[0] !== undefined) {
|
|
77
78
|
throw new Error(`No non-nullified L1 to L2 message found for message hash ${messageHash.toString()}`);
|
|
78
79
|
}
|
|
79
|
-
return
|
|
80
|
-
messageIndex,
|
|
81
|
-
siblingPath
|
|
82
|
-
];
|
|
80
|
+
return l1ToL2Response;
|
|
83
81
|
}
|
|
@@ -1,19 +1,63 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
|
+
/**
|
|
4
|
+
* Serialization format detection for ChonkProof is size-based:
|
|
5
|
+
* - UNCOMPRESSED (legacy): [field_count=1632: uint32] [fields...] → total ≈ 52KB (>= 40KB)
|
|
6
|
+
* - COMPRESSED: [byte_count: uint32] [compressed_bytes] → total ≈ 35KB (< 40KB)
|
|
7
|
+
*
|
|
8
|
+
* Detection: if the first uint32 equals CHONK_PROOF_LENGTH (1632), it's legacy format
|
|
9
|
+
* (field count). Otherwise, it's compressed format (byte count). The old uncompressed
|
|
10
|
+
* format is never smaller than 40KB; compressed proofs are always smaller than 40KB.
|
|
11
|
+
*/
|
|
3
12
|
export declare class ChonkProof {
|
|
4
13
|
fields: Fr[];
|
|
5
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Optional compressed proof bytes from chonk compression (point compression + u256 encoding).
|
|
16
|
+
* When set, toBuffer() will serialize in compressed format (~1.7x smaller).
|
|
17
|
+
* When reading from compressed format, this is populated and fields are decompressed on demand.
|
|
18
|
+
*/
|
|
19
|
+
compressedProof?: Buffer;
|
|
20
|
+
constructor(fields: Fr[], compressedProof?: Buffer);
|
|
6
21
|
attachPublicInputs(publicInputs: Fr[]): ChonkProofWithPublicInputs;
|
|
7
22
|
isEmpty(): boolean;
|
|
8
23
|
static empty(): ChonkProof;
|
|
9
24
|
static random(): ChonkProof;
|
|
10
25
|
static get schema(): import("zod").ZodType<ChonkProof, any, string>;
|
|
11
26
|
toJSON(): Buffer<ArrayBufferLike>;
|
|
27
|
+
/**
|
|
28
|
+
* Deserialize a ChonkProof from a buffer.
|
|
29
|
+
* Supports both legacy (field elements) and compressed (chonk compression) formats.
|
|
30
|
+
*
|
|
31
|
+
* Size-based format detection:
|
|
32
|
+
* - First uint32 == CHONK_PROOF_LENGTH (1632): legacy format, read field elements
|
|
33
|
+
* Total proof data ≈ 52KB (always >= 40KB)
|
|
34
|
+
* - Otherwise: compressed format, first uint32 is byte count of compressed data
|
|
35
|
+
* Total proof data ≈ 35KB (always < 40KB)
|
|
36
|
+
*/
|
|
12
37
|
static fromBuffer(buffer: Buffer | BufferReader): ChonkProof;
|
|
38
|
+
/**
|
|
39
|
+
* Create a ChonkProof from compressed bytes by decompressing via the BarretenbergSync API.
|
|
40
|
+
* The compressed format uses point compression and u256 encoding (from PR #20645).
|
|
41
|
+
*
|
|
42
|
+
* @param compressed - Compressed proof bytes from chonk compression
|
|
43
|
+
* @returns ChonkProof with both fields and compressed bytes populated
|
|
44
|
+
*/
|
|
45
|
+
static fromCompressedBytes(compressed: Buffer): ChonkProof;
|
|
46
|
+
/**
|
|
47
|
+
* Serialize the proof to a buffer.
|
|
48
|
+
* If compressed bytes are available, uses the compressed format (~1.7x smaller).
|
|
49
|
+
* Otherwise falls back to legacy field element format.
|
|
50
|
+
*/
|
|
13
51
|
toBuffer(): Buffer<ArrayBufferLike>;
|
|
14
52
|
}
|
|
15
53
|
export declare class ChonkProofWithPublicInputs {
|
|
16
54
|
fieldsWithPublicInputs: Fr[];
|
|
55
|
+
/**
|
|
56
|
+
* Optional compressed proof bytes (covers the full proof WITH public inputs).
|
|
57
|
+
* Set by the prover when using chonk compression. Flows through to ChonkProof
|
|
58
|
+
* via removePublicInputs() so the Tx can serialize in compressed format.
|
|
59
|
+
*/
|
|
60
|
+
compressedProof?: Buffer;
|
|
17
61
|
constructor(fieldsWithPublicInputs: Fr[]);
|
|
18
62
|
getPublicInputs(): Fr[];
|
|
19
63
|
removePublicInputs(): ChonkProof;
|
|
@@ -25,4 +69,4 @@ export declare class ChonkProofWithPublicInputs {
|
|
|
25
69
|
toBuffer(): Buffer<ArrayBufferLike>;
|
|
26
70
|
static fromBufferArray(fields: Uint8Array[]): ChonkProofWithPublicInputs;
|
|
27
71
|
}
|
|
28
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
72
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hvbmtfcHJvb2YuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wcm9vZnMvY2hvbmtfcHJvb2YudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sRUFBRSxZQUFZLEVBQW9DLE1BQU0sNkJBQTZCLENBQUM7QUFFN0Y7Ozs7Ozs7O0dBUUc7QUFHSCxxQkFBYSxVQUFVO0lBWVosTUFBTSxFQUFFLEVBQUUsRUFBRTtJQVhyQjs7OztPQUlHO0lBQ0ksZUFBZSxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBRWhDLFlBSVMsTUFBTSxFQUFFLEVBQUUsRUFBRSxFQUNuQixlQUFlLENBQUMsRUFBRSxNQUFNLEVBTXpCO0lBRU0sa0JBQWtCLENBQUMsWUFBWSxFQUFFLEVBQUUsRUFBRSw4QkFFM0M7SUFFTSxPQUFPLFlBRWI7SUFFRCxNQUFNLENBQ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
@@ -1,20 +1,35 @@
|
|
|
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
|
-
|
|
7
|
+
import { BufferReader, numToUInt32BE, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
8
|
+
/**
|
|
9
|
+
* Serialization format detection for ChonkProof is size-based:
|
|
10
|
+
* - UNCOMPRESSED (legacy): [field_count=1632: uint32] [fields...] → total ≈ 52KB (>= 40KB)
|
|
11
|
+
* - COMPRESSED: [byte_count: uint32] [compressed_bytes] → total ≈ 35KB (< 40KB)
|
|
12
|
+
*
|
|
13
|
+
* Detection: if the first uint32 equals CHONK_PROOF_LENGTH (1632), it's legacy format
|
|
14
|
+
* (field count). Otherwise, it's compressed format (byte count). The old uncompressed
|
|
15
|
+
* format is never smaller than 40KB; compressed proofs are always smaller than 40KB.
|
|
16
|
+
*/ // CHONK: "Client Honk" - An UltraHonk variant with incremental folding and delayed non-native arithmetic.
|
|
8
17
|
export class ChonkProof {
|
|
9
18
|
fields;
|
|
19
|
+
/**
|
|
20
|
+
* Optional compressed proof bytes from chonk compression (point compression + u256 encoding).
|
|
21
|
+
* When set, toBuffer() will serialize in compressed format (~1.7x smaller).
|
|
22
|
+
* When reading from compressed format, this is populated and fields are decompressed on demand.
|
|
23
|
+
*/ compressedProof;
|
|
10
24
|
constructor(// The proof fields.
|
|
11
25
|
// For native verification, attach public inputs via `attachPublicInputs(publicInputs)`.
|
|
12
26
|
// Not using Tuple here due to the length being too high.
|
|
13
|
-
fields){
|
|
27
|
+
fields, compressedProof){
|
|
14
28
|
this.fields = fields;
|
|
15
29
|
if (fields.length !== CHONK_PROOF_LENGTH) {
|
|
16
30
|
throw new Error(`Invalid ChonkProof length: ${fields.length}`);
|
|
17
31
|
}
|
|
32
|
+
this.compressedProof = compressedProof;
|
|
18
33
|
}
|
|
19
34
|
attachPublicInputs(publicInputs) {
|
|
20
35
|
return new ChonkProofWithPublicInputs([
|
|
@@ -48,18 +63,77 @@ export class ChonkProof {
|
|
|
48
63
|
toJSON() {
|
|
49
64
|
return this.toBuffer();
|
|
50
65
|
}
|
|
51
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Deserialize a ChonkProof from a buffer.
|
|
68
|
+
* Supports both legacy (field elements) and compressed (chonk compression) formats.
|
|
69
|
+
*
|
|
70
|
+
* Size-based format detection:
|
|
71
|
+
* - First uint32 == CHONK_PROOF_LENGTH (1632): legacy format, read field elements
|
|
72
|
+
* Total proof data ≈ 52KB (always >= 40KB)
|
|
73
|
+
* - Otherwise: compressed format, first uint32 is byte count of compressed data
|
|
74
|
+
* Total proof data ≈ 35KB (always < 40KB)
|
|
75
|
+
*/ static fromBuffer(buffer) {
|
|
52
76
|
const reader = BufferReader.asReader(buffer);
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
const firstUint32 = reader.readNumber();
|
|
78
|
+
if (firstUint32 === CHONK_PROOF_LENGTH) {
|
|
79
|
+
// Legacy format: firstUint32 is the field count (1632)
|
|
80
|
+
// Widen to `number` to prevent TS from narrowing to literal 1632,
|
|
81
|
+
// which would cause Tuple<Fr, 1632> to exceed the recursion limit.
|
|
82
|
+
const fieldCount = firstUint32;
|
|
83
|
+
const proof = reader.readArray(fieldCount, Fr);
|
|
84
|
+
return new ChonkProof(proof);
|
|
85
|
+
}
|
|
86
|
+
// Compressed format: firstUint32 is the compressed byte count
|
|
87
|
+
const compressedBytes = reader.readBytes(firstUint32);
|
|
88
|
+
return ChonkProof.fromCompressedBytes(Buffer.from(compressedBytes));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create a ChonkProof from compressed bytes by decompressing via the BarretenbergSync API.
|
|
92
|
+
* The compressed format uses point compression and u256 encoding (from PR #20645).
|
|
93
|
+
*
|
|
94
|
+
* @param compressed - Compressed proof bytes from chonk compression
|
|
95
|
+
* @returns ChonkProof with both fields and compressed bytes populated
|
|
96
|
+
*/ static fromCompressedBytes(compressed) {
|
|
97
|
+
const api = BarretenbergSync.getSingleton();
|
|
98
|
+
const result = api.chonkDecompressProof({
|
|
99
|
+
compressedProof: new Uint8Array(compressed)
|
|
100
|
+
});
|
|
101
|
+
// Flatten the structured bb.js ChonkProof into flat Fr[] field elements
|
|
102
|
+
const flatFields = flattenChonkProofFields(result.proof);
|
|
103
|
+
const fields = flatFields.map((f)=>Fr.fromBuffer(Buffer.from(f)));
|
|
104
|
+
// The decompressed proof includes public inputs in hidingOinkProof.
|
|
105
|
+
// Since ChonkProof stores fields WITHOUT public inputs, strip them.
|
|
106
|
+
// The number of public inputs = total fields - CHONK_PROOF_LENGTH
|
|
107
|
+
if (fields.length > CHONK_PROOF_LENGTH) {
|
|
108
|
+
const numPubInputs = fields.length - CHONK_PROOF_LENGTH;
|
|
109
|
+
const proofFields = fields.slice(numPubInputs);
|
|
110
|
+
return new ChonkProof(proofFields, compressed);
|
|
111
|
+
}
|
|
112
|
+
return new ChonkProof(fields, compressed);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Serialize the proof to a buffer.
|
|
116
|
+
* If compressed bytes are available, uses the compressed format (~1.7x smaller).
|
|
117
|
+
* Otherwise falls back to legacy field element format.
|
|
118
|
+
*/ toBuffer() {
|
|
119
|
+
if (this.compressedProof) {
|
|
120
|
+
// Compressed format: [compressed_byte_count: uint32] [compressed_bytes]
|
|
121
|
+
return Buffer.concat([
|
|
122
|
+
numToUInt32BE(this.compressedProof.length),
|
|
123
|
+
this.compressedProof
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
// Legacy format: [field_count=1632: uint32] [fields...]
|
|
58
127
|
return serializeToBuffer(this.fields.length, this.fields);
|
|
59
128
|
}
|
|
60
129
|
}
|
|
61
130
|
export class ChonkProofWithPublicInputs {
|
|
62
131
|
fieldsWithPublicInputs;
|
|
132
|
+
/**
|
|
133
|
+
* Optional compressed proof bytes (covers the full proof WITH public inputs).
|
|
134
|
+
* Set by the prover when using chonk compression. Flows through to ChonkProof
|
|
135
|
+
* via removePublicInputs() so the Tx can serialize in compressed format.
|
|
136
|
+
*/ compressedProof;
|
|
63
137
|
constructor(// The proof fields with public inputs.
|
|
64
138
|
// For recursive verification, use without public inputs via `removePublicInputs()`.
|
|
65
139
|
fieldsWithPublicInputs){
|
|
@@ -74,7 +148,8 @@ export class ChonkProofWithPublicInputs {
|
|
|
74
148
|
}
|
|
75
149
|
removePublicInputs() {
|
|
76
150
|
const numPublicInputs = this.fieldsWithPublicInputs.length - CHONK_PROOF_LENGTH;
|
|
77
|
-
|
|
151
|
+
// Flow compressed proof bytes through so the ChonkProof can serialize efficiently
|
|
152
|
+
return new ChonkProof(this.fieldsWithPublicInputs.slice(numPublicInputs), this.compressedProof);
|
|
78
153
|
}
|
|
79
154
|
isEmpty() {
|
|
80
155
|
return this.fieldsWithPublicInputs.every((field)=>field.isZero());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/stdlib",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.ce4f8c4f2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"inherits": [
|
|
6
6
|
"../package.common.json",
|
|
@@ -92,13 +92,13 @@
|
|
|
92
92
|
},
|
|
93
93
|
"dependencies": {
|
|
94
94
|
"@aws-sdk/client-s3": "^3.892.0",
|
|
95
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
96
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
97
|
-
"@aztec/constants": "0.0.1-commit.
|
|
98
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
99
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
100
|
-
"@aztec/l1-artifacts": "0.0.1-commit.
|
|
101
|
-
"@aztec/noir-noirc_abi": "0.0.1-commit.
|
|
95
|
+
"@aztec/bb.js": "0.0.1-commit.ce4f8c4f2",
|
|
96
|
+
"@aztec/blob-lib": "0.0.1-commit.ce4f8c4f2",
|
|
97
|
+
"@aztec/constants": "0.0.1-commit.ce4f8c4f2",
|
|
98
|
+
"@aztec/ethereum": "0.0.1-commit.ce4f8c4f2",
|
|
99
|
+
"@aztec/foundation": "0.0.1-commit.ce4f8c4f2",
|
|
100
|
+
"@aztec/l1-artifacts": "0.0.1-commit.ce4f8c4f2",
|
|
101
|
+
"@aztec/noir-noirc_abi": "0.0.1-commit.ce4f8c4f2",
|
|
102
102
|
"@google-cloud/storage": "^7.15.0",
|
|
103
103
|
"axios": "^1.13.5",
|
|
104
104
|
"json-stringify-deterministic": "1.0.12",
|
|
@@ -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
|
|
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 [
|
|
87
|
+
const [l1ToL2Response, nullifierResponse] = await Promise.all([
|
|
88
|
+
node.getL1ToL2MessageMembershipWitness(referenceBlock, messageHash),
|
|
89
|
+
node.findLeavesIndexes(referenceBlock, MerkleTreeId.NULLIFIER_TREE, [messageNullifier]),
|
|
90
|
+
]);
|
|
89
91
|
|
|
90
|
-
|
|
92
|
+
if (!l1ToL2Response) {
|
|
93
|
+
throw new Error(`No L1 to L2 message found for message hash ${messageHash.toString()}`);
|
|
94
|
+
}
|
|
91
95
|
|
|
92
|
-
|
|
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
|
|
100
|
+
return l1ToL2Response;
|
|
98
101
|
}
|
|
@@ -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
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
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() {
|