@aztec/stdlib 0.0.1-commit.9ee6fcc6 → 0.0.1-commit.9ef841308
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/abi/decoder.d.ts +5 -44
- package/dest/abi/decoder.d.ts.map +1 -1
- package/dest/abi/decoder.js +12 -67
- package/dest/abi/function_selector.js +1 -1
- package/dest/abi/function_signature_decoder.d.ts +43 -0
- package/dest/abi/function_signature_decoder.d.ts.map +1 -0
- package/dest/abi/function_signature_decoder.js +66 -0
- package/dest/abi/index.d.ts +2 -1
- package/dest/abi/index.d.ts.map +1 -1
- package/dest/abi/index.js +1 -0
- package/dest/epoch-helpers/index.d.ts +3 -1
- package/dest/epoch-helpers/index.d.ts.map +1 -1
- package/dest/epoch-helpers/index.js +3 -0
- package/dest/file-store/factory.d.ts +4 -3
- package/dest/file-store/factory.d.ts.map +1 -1
- package/dest/file-store/factory.js +2 -2
- package/dest/file-store/http.d.ts +9 -2
- package/dest/file-store/http.d.ts.map +1 -1
- package/dest/file-store/http.js +20 -9
- package/dest/file-store/index.d.ts +2 -1
- package/dest/file-store/index.d.ts.map +1 -1
- package/dest/hash/hash.d.ts +4 -1
- package/dest/hash/hash.d.ts.map +1 -1
- package/dest/hash/hash.js +5 -0
- package/dest/interfaces/aztec-node-admin.d.ts +1 -4
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/proving-job.d.ts +34 -34
- package/dest/interfaces/validator.d.ts +2 -10
- package/dest/interfaces/validator.d.ts.map +1 -1
- package/dest/interfaces/validator.js +0 -1
- package/dest/logs/message_context.d.ts +4 -7
- package/dest/logs/message_context.d.ts.map +1 -1
- package/dest/logs/message_context.js +23 -9
- package/dest/logs/pending_tagged_log.d.ts +2 -3
- package/dest/logs/pending_tagged_log.d.ts.map +1 -1
- package/dest/logs/pending_tagged_log.js +2 -2
- package/dest/logs/shared_secret_derivation.d.ts +11 -10
- package/dest/logs/shared_secret_derivation.d.ts.map +1 -1
- package/dest/logs/shared_secret_derivation.js +15 -9
- package/dest/logs/siloed_tag.d.ts +4 -1
- package/dest/logs/siloed_tag.d.ts.map +1 -1
- package/dest/logs/siloed_tag.js +7 -3
- 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/note/note_dao.d.ts +1 -1
- package/dest/note/note_dao.d.ts.map +1 -1
- package/dest/note/note_dao.js +1 -4
- 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/dest/tx/capsule.d.ts +6 -2
- package/dest/tx/capsule.d.ts.map +1 -1
- package/dest/tx/capsule.js +9 -3
- package/package.json +8 -8
- package/src/abi/decoder.ts +23 -78
- package/src/abi/function_selector.ts +1 -1
- package/src/abi/function_signature_decoder.ts +77 -0
- package/src/abi/index.ts +1 -0
- package/src/epoch-helpers/index.ts +8 -0
- package/src/file-store/factory.ts +13 -4
- package/src/file-store/http.ts +29 -10
- package/src/file-store/index.ts +1 -0
- package/src/hash/hash.ts +5 -0
- package/src/interfaces/validator.ts +1 -5
- package/src/logs/message_context.ts +17 -7
- package/src/logs/pending_tagged_log.ts +1 -3
- package/src/logs/shared_secret_derivation.ts +21 -10
- package/src/logs/siloed_tag.ts +7 -2
- package/src/messaging/l1_to_l2_message.ts +12 -9
- package/src/note/note_dao.ts +1 -4
- package/src/proofs/chonk_proof.ts +91 -5
- package/src/tx/capsule.ts +10 -2
|
@@ -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
|
}
|
package/dest/note/note_dao.d.ts
CHANGED
|
@@ -107,4 +107,4 @@ export declare class NoteDao {
|
|
|
107
107
|
getSize(): number;
|
|
108
108
|
static random({ note, contractAddress, owner, storageSlot, randomness, noteNonce, noteHash, siloedNullifier, txHash, l2BlockNumber, l2BlockHash, txIndexInBlock, noteIndexInTx }?: Partial<NoteDao>): Promise<NoteDao>;
|
|
109
109
|
}
|
|
110
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
110
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm90ZV9kYW8uZC50cyIs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IsU0FBdUIsRUFDdkIsUUFBc0IsRUFDdEIsZUFBNkIsRUFDN0IsTUFBd0IsRUFDeEIsYUFBNkQsRUFDN0QsV0FBb0MsRUFDcEMsY0FBZ0QsRUFDaEQsYUFBK0MsRUFDaEQsR0FBRSxPQUFPLENBQUMsT0FBTyxDQUFNLG9CQWdCdkI7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"note_dao.d.ts","sourceRoot":"","sources":["../../src/note/note_dao.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"note_dao.d.ts","sourceRoot":"","sources":["../../src/note/note_dao.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C;;;GAGG;AACH,qBAAa,OAAO;IAIhB,kFAAkF;IAC3E,IAAI,EAAE,IAAI;IACjB,8GAA8G;IACvG,eAAe,EAAE,YAAY;IACpC,6EAA6E;IACtE,KAAK,EAAE,YAAY;IAC1B;;;OAGG;IACI,WAAW,EAAE,EAAE;IACtB;;OAEG;IACI,UAAU,EAAE,EAAE;IACrB,gGAAgG;IACzF,SAAS,EAAE,EAAE;IAGpB;;;OAGG;IACI,QAAQ,EAAE,EAAE;IACnB;;;OAGG;IACI,eAAe,EAAE,EAAE;IAG1B;;OAEG;IACI,MAAM,EAAE,MAAM;IACrB;gBACY;IACL,aAAa,EAAE,W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@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';
|
|
@@ -105,9 +104,7 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
105
104
|
* Returns the size in bytes of the Note Dao.
|
|
106
105
|
* @returns - Its size in bytes.
|
|
107
106
|
*/ getSize() {
|
|
108
|
-
|
|
109
|
-
// 2 numbers for txIndexInBlock and noteIndexInTx (4 bytes each)
|
|
110
|
-
return noteSize + AztecAddress.SIZE_IN_BYTES * 2 + Fr.SIZE_IN_BYTES * 4 + TxHash.SIZE + Point.SIZE_IN_BYTES + 8;
|
|
107
|
+
return this.toBuffer().length;
|
|
111
108
|
}
|
|
112
109
|
static async random({ note = Note.random(), contractAddress = undefined, owner = undefined, storageSlot = Fr.random(), randomness = Fr.random(), noteNonce = Fr.random(), noteHash = Fr.random(), siloedNullifier = Fr.random(), txHash = TxHash.random(), l2BlockNumber = BlockNumber(Math.floor(Math.random() * 1000)), l2BlockHash = Fr.random().toString(), txIndexInBlock = Math.floor(Math.random() * 100), noteIndexInTx = Math.floor(Math.random() * 100) } = {}) {
|
|
113
110
|
return new NoteDao(note, contractAddress ?? await AztecAddress.random(), owner ?? await AztecAddress.random(), storageSlot, randomness, noteNonce, noteHash, siloedNullifier, txHash, l2BlockNumber, l2BlockHash, txIndexInBlock, noteIndexInTx);
|
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hvbmtfcHJvb2YuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wcm9vZnMvY2hvbmtfcHJvb2YudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUEsT0FBTy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0sQ0FBQyxLQUFLLCtCQUVYO0lBRUQsTUFBTSxLQUFLLE1BQU0sbUVBRWhCO0lBR0QsTUFBTSw0QkFFTDtJQUVELE1BQU0sQ0FBQyxVQUFVLENBQUMsTUFBTSxFQUFFLE1BQU0sR0FBRyxZQUFZLEdBQUcsMEJBQTBCLENBSzNFO0lBRU0sUUFBUSw0QkFFZDtJQUdELE1BQU0sQ0FBQyxlQUFlLENBQUMsTUFBTSxFQUFFLFVBQVUsRUFBRSxHQUFHLDBCQUEwQixDQUd2RTtDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chonk_proof.d.ts","sourceRoot":"","sources":["../../src/proofs/chonk_proof.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chonk_proof.d.ts","sourceRoot":"","sources":["../../src/proofs/chonk_proof.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAoC,MAAM,6BAA6B,CAAC;AAE7F;;;;;;;;GAQG;AAGH,qBAAa,UAAU;IAYZ,MAAM,EAAE,EAAE,EAAE;IAXrB;;;;OAIG;IACI,eAAe,CAAC,EAAE,MAAM,CAAC;IAEhC,YAIS,MAAM,EAAE,EAAE,EAAE,EACnB,eAAe,CAAC,EAAE,MAAM,EAMzB;IAEM,kBAAkB,CAAC,YAAY,EAAE,EAAE,EAAE,8BAE3C;IAEM,OAAO,YAEb;IAED,MAAM,CAAC,KAAK,eAEX;IAED,MAAM,CAAC,MAAM,eAYZ;IAED,MAAM,KAAK,MAAM,mDAEhB;IAGD,MAAM,4BAEL;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,UAAU,CAgB3D;IAED;;;;;;OAMG;IACH,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAkBzD;IAED;;;;OAIG;IACI,QAAQ,4BAOd;CACF;AAED,qBAAa,0BAA0B;IAW5B,sBAAsB,EAAE,EAAE,EAAE;IAVrC;;;;OAIG;IACI,eAAe,CAAC,EAAE,MAAM,CAAC;IAEhC,YAGS,sBAAsB,EAAE,EAAE,EAAE,EAKpC;IAEM,eAAe,SAGrB;IAEM,kBAAkB,eAIxB;IAEM,OAAO,YAEb;IAED,MAAM,CAAC,KAAK,+BAEX;IAED,MAAM,KAAK,MAAM,mEAEhB;IAGD,MAAM,4BAEL;IAED,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,0BAA0B,CAK3E;IAEM,QAAQ,4BAEd;IAGD,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,0BAA0B,CAGvE;CACF"}
|
|
@@ -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/dest/tx/capsule.d.ts
CHANGED
|
@@ -13,13 +13,17 @@ export declare class Capsule {
|
|
|
13
13
|
readonly storageSlot: Fr;
|
|
14
14
|
/** Data passed to the contract */
|
|
15
15
|
readonly data: Fr[];
|
|
16
|
+
/** Optional namespace for the capsule contents */
|
|
17
|
+
readonly scope?: AztecAddress | undefined;
|
|
16
18
|
constructor(
|
|
17
19
|
/** The address of the contract the capsule is for */
|
|
18
20
|
contractAddress: AztecAddress,
|
|
19
21
|
/** The storage slot of the capsule */
|
|
20
22
|
storageSlot: Fr,
|
|
21
23
|
/** Data passed to the contract */
|
|
22
|
-
data: Fr[]
|
|
24
|
+
data: Fr[],
|
|
25
|
+
/** Optional namespace for the capsule contents */
|
|
26
|
+
scope?: AztecAddress | undefined);
|
|
23
27
|
static get schema(): import("zod").ZodType<Capsule, any, string>;
|
|
24
28
|
toJSON(): `0x${string}`;
|
|
25
29
|
toBuffer(): Buffer<ArrayBufferLike>;
|
|
@@ -27,4 +31,4 @@ export declare class Capsule {
|
|
|
27
31
|
toString(): `0x${string}`;
|
|
28
32
|
static fromString(str: string): Capsule;
|
|
29
33
|
}
|
|
30
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
34
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2Fwc3VsZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3R4L2NhcHN1bGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sRUFBRSxZQUFZLEVBQXFCLE1BQU0sNkJBQTZCLENBQUM7QUFHOUUsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBR3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ACnB,IAAI,EAAE,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"capsule.d.ts","sourceRoot":"","sources":["../../src/tx/capsule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAG9E,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD;;;;GAIG;AACH,qBAAa,OAAO;IAEhB,qDAAqD;aACrC,eAAe,EAAE,YAAY;IAC7C,sCAAsC;aACtB,WAAW,EAAE,EAAE;IAC/B,mCAAmC;aACnB,IAAI,EAAE,EAAE,EAAE;IAC1B,kDAAkD;aAClC,KAAK,CAAC;IARxB;IACE,qDAAqD;IACrC,eAAe,EAAE,YAAY;IAC7C,sCAAsC;IACtB,WAAW,EAAE,EAAE;IAC/B,mCAAmC;IACnB,IAAI,EAAE,EAAE,EAAE;IAC1B,kDAAkD;IAClC,KAAK,CAAC,0BAAc,EAClC;IAEJ,MAAM,KAAK,MAAM,gDAEhB;IAED,MAAM,kBAEL;IAED,QAAQ,4BAIP;IAED,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,OAAO,CAOxD;IAED,QAAQ,kBAEP;IAED,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,WAE5B;CACF"}
|
package/dest/tx/capsule.js
CHANGED
|
@@ -12,10 +12,12 @@ import { Vector } from '../types/shared.js';
|
|
|
12
12
|
contractAddress;
|
|
13
13
|
storageSlot;
|
|
14
14
|
data;
|
|
15
|
-
|
|
15
|
+
scope;
|
|
16
|
+
constructor(/** The address of the contract the capsule is for */ contractAddress, /** The storage slot of the capsule */ storageSlot, /** Data passed to the contract */ data, /** Optional namespace for the capsule contents */ scope){
|
|
16
17
|
this.contractAddress = contractAddress;
|
|
17
18
|
this.storageSlot = storageSlot;
|
|
18
19
|
this.data = data;
|
|
20
|
+
this.scope = scope;
|
|
19
21
|
}
|
|
20
22
|
static get schema() {
|
|
21
23
|
return hexSchemaFor(Capsule);
|
|
@@ -24,11 +26,15 @@ import { Vector } from '../types/shared.js';
|
|
|
24
26
|
return this.toString();
|
|
25
27
|
}
|
|
26
28
|
toBuffer() {
|
|
27
|
-
return serializeToBuffer(this.contractAddress, this.storageSlot, new Vector(this.data));
|
|
29
|
+
return this.scope ? serializeToBuffer(this.contractAddress, this.storageSlot, new Vector(this.data), true, this.scope) : serializeToBuffer(this.contractAddress, this.storageSlot, new Vector(this.data), false);
|
|
28
30
|
}
|
|
29
31
|
static fromBuffer(buffer) {
|
|
30
32
|
const reader = BufferReader.asReader(buffer);
|
|
31
|
-
|
|
33
|
+
const contractAddress = AztecAddress.fromBuffer(reader);
|
|
34
|
+
const storageSlot = Fr.fromBuffer(reader);
|
|
35
|
+
const data = reader.readVector(Fr);
|
|
36
|
+
const hasScope = reader.readBoolean();
|
|
37
|
+
return new Capsule(contractAddress, storageSlot, data, hasScope ? AztecAddress.fromBuffer(reader) : undefined);
|
|
32
38
|
}
|
|
33
39
|
toString() {
|
|
34
40
|
return bufferToHex(this.toBuffer());
|
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.9ef841308",
|
|
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.9ef841308",
|
|
96
|
+
"@aztec/blob-lib": "0.0.1-commit.9ef841308",
|
|
97
|
+
"@aztec/constants": "0.0.1-commit.9ef841308",
|
|
98
|
+
"@aztec/ethereum": "0.0.1-commit.9ef841308",
|
|
99
|
+
"@aztec/foundation": "0.0.1-commit.9ef841308",
|
|
100
|
+
"@aztec/l1-artifacts": "0.0.1-commit.9ef841308",
|
|
101
|
+
"@aztec/noir-noirc_abi": "0.0.1-commit.9ef841308",
|
|
102
102
|
"@google-cloud/storage": "^7.15.0",
|
|
103
103
|
"axios": "^1.13.5",
|
|
104
104
|
"json-stringify-deterministic": "1.0.12",
|
package/src/abi/decoder.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
3
|
|
|
3
4
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
5
|
+
import type { AbiType } from './abi.js';
|
|
6
|
+
import { FunctionSelector } from './function_selector.js';
|
|
7
|
+
import {
|
|
8
|
+
isAztecAddressStruct,
|
|
9
|
+
isEthAddressStruct,
|
|
10
|
+
isFunctionSelectorStruct,
|
|
11
|
+
isOptionStruct,
|
|
12
|
+
isWrappedFieldStruct,
|
|
13
|
+
parseSignedInt,
|
|
14
|
+
} from './utils.js';
|
|
6
15
|
|
|
7
16
|
/**
|
|
8
17
|
* The type of our decoded ABI.
|
|
@@ -12,6 +21,9 @@ export type AbiDecoded =
|
|
|
12
21
|
| boolean
|
|
13
22
|
| string
|
|
14
23
|
| AztecAddress
|
|
24
|
+
| EthAddress
|
|
25
|
+
| FunctionSelector
|
|
26
|
+
| Fr
|
|
15
27
|
| AbiDecoded[]
|
|
16
28
|
| { [key: string]: AbiDecoded }
|
|
17
29
|
| undefined;
|
|
@@ -58,6 +70,15 @@ class AbiDecoder {
|
|
|
58
70
|
if (isAztecAddressStruct(abiType)) {
|
|
59
71
|
return new AztecAddress(this.getNextField().toBuffer());
|
|
60
72
|
}
|
|
73
|
+
if (isEthAddressStruct(abiType)) {
|
|
74
|
+
return EthAddress.fromField(this.getNextField());
|
|
75
|
+
}
|
|
76
|
+
if (isFunctionSelectorStruct(abiType)) {
|
|
77
|
+
return FunctionSelector.fromField(this.getNextField());
|
|
78
|
+
}
|
|
79
|
+
if (isWrappedFieldStruct(abiType)) {
|
|
80
|
+
return this.getNextField();
|
|
81
|
+
}
|
|
61
82
|
if (isOptionStruct(abiType)) {
|
|
62
83
|
const isSome = this.decodeNext(abiType.fields[0].type);
|
|
63
84
|
const value = this.decodeNext(abiType.fields[1].type);
|
|
@@ -123,79 +144,3 @@ class AbiDecoder {
|
|
|
123
144
|
export function decodeFromAbi(typ: AbiType[], buffer: Fr[]) {
|
|
124
145
|
return new AbiDecoder(typ, buffer.slice()).decode();
|
|
125
146
|
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Decodes the signature of a function from the name and parameters.
|
|
129
|
-
*/
|
|
130
|
-
export class FunctionSignatureDecoder {
|
|
131
|
-
private separator: string;
|
|
132
|
-
constructor(
|
|
133
|
-
private name: string,
|
|
134
|
-
private parameters: ABIParameter[],
|
|
135
|
-
private includeNames = false,
|
|
136
|
-
) {
|
|
137
|
-
this.separator = includeNames ? ', ' : ',';
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Decodes a single function parameter type for the function signature.
|
|
142
|
-
* @param param - The parameter type to decode.
|
|
143
|
-
* @returns A string representing the parameter type.
|
|
144
|
-
*/
|
|
145
|
-
private getParameterType(param: AbiType): string {
|
|
146
|
-
switch (param.kind) {
|
|
147
|
-
case 'field':
|
|
148
|
-
return 'Field';
|
|
149
|
-
case 'integer':
|
|
150
|
-
return param.sign === 'signed' ? `i${param.width}` : `u${param.width}`;
|
|
151
|
-
case 'boolean':
|
|
152
|
-
return 'bool';
|
|
153
|
-
case 'array':
|
|
154
|
-
return `[${this.getParameterType(param.type)};${param.length}]`;
|
|
155
|
-
case 'string':
|
|
156
|
-
return `str<${param.length}>`;
|
|
157
|
-
case 'struct':
|
|
158
|
-
return `(${param.fields.map(field => `${this.decodeParameter(field)}`).join(this.separator)})`;
|
|
159
|
-
default:
|
|
160
|
-
throw new Error(`Unsupported type: ${param.kind}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Decodes a single function parameter for the function signature.
|
|
166
|
-
* @param param - The parameter to decode.
|
|
167
|
-
* @returns A string representing the parameter type and optionally its name.
|
|
168
|
-
*/
|
|
169
|
-
private decodeParameter(param: ABIVariable): string {
|
|
170
|
-
const type = this.getParameterType(param.type);
|
|
171
|
-
return this.includeNames ? `${param.name}: ${type}` : type;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Decodes all the parameters and build the function signature
|
|
176
|
-
* @returns The function signature.
|
|
177
|
-
*/
|
|
178
|
-
public decode(): string {
|
|
179
|
-
return `${this.name}(${this.parameters.map(param => this.decodeParameter(param)).join(this.separator)})`;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Decodes a function signature from the name and parameters.
|
|
185
|
-
* @param name - The name of the function.
|
|
186
|
-
* @param parameters - The parameters of the function.
|
|
187
|
-
* @returns - The function signature.
|
|
188
|
-
*/
|
|
189
|
-
export function decodeFunctionSignature(name: string, parameters: ABIParameter[]) {
|
|
190
|
-
return new FunctionSignatureDecoder(name, parameters).decode();
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Decodes a function signature from the name and parameters including parameter names.
|
|
195
|
-
* @param name - The name of the function.
|
|
196
|
-
* @param parameters - The parameters of the function.
|
|
197
|
-
* @returns - The user-friendly function signature.
|
|
198
|
-
*/
|
|
199
|
-
export function decodeFunctionSignatureWithParameterNames(name: string, parameters: ABIParameter[]) {
|
|
200
|
-
return new FunctionSignatureDecoder(name, parameters, true).decode();
|
|
201
|
-
}
|
|
@@ -6,7 +6,7 @@ import { type ZodFor, hexSchemaFor } from '@aztec/foundation/schemas';
|
|
|
6
6
|
import { BufferReader, FieldReader, TypeRegistry } from '@aztec/foundation/serialize';
|
|
7
7
|
|
|
8
8
|
import type { ABIParameter } from './abi.js';
|
|
9
|
-
import { decodeFunctionSignature } from './
|
|
9
|
+
import { decodeFunctionSignature } from './function_signature_decoder.js';
|
|
10
10
|
import { Selector } from './selector.js';
|
|
11
11
|
|
|
12
12
|
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ABIParameter, ABIVariable, AbiType } from './abi.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decodes the signature of a function from the name and parameters.
|
|
5
|
+
*/
|
|
6
|
+
export class FunctionSignatureDecoder {
|
|
7
|
+
private separator: string;
|
|
8
|
+
constructor(
|
|
9
|
+
private name: string,
|
|
10
|
+
private parameters: ABIParameter[],
|
|
11
|
+
private includeNames = false,
|
|
12
|
+
) {
|
|
13
|
+
this.separator = includeNames ? ', ' : ',';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Decodes a single function parameter type for the function signature.
|
|
18
|
+
* @param param - The parameter type to decode.
|
|
19
|
+
* @returns A string representing the parameter type.
|
|
20
|
+
*/
|
|
21
|
+
private getParameterType(param: AbiType): string {
|
|
22
|
+
switch (param.kind) {
|
|
23
|
+
case 'field':
|
|
24
|
+
return 'Field';
|
|
25
|
+
case 'integer':
|
|
26
|
+
return param.sign === 'signed' ? `i${param.width}` : `u${param.width}`;
|
|
27
|
+
case 'boolean':
|
|
28
|
+
return 'bool';
|
|
29
|
+
case 'array':
|
|
30
|
+
return `[${this.getParameterType(param.type)};${param.length}]`;
|
|
31
|
+
case 'string':
|
|
32
|
+
return `str<${param.length}>`;
|
|
33
|
+
case 'struct':
|
|
34
|
+
return `(${param.fields.map(field => `${this.decodeParameter(field)}`).join(this.separator)})`;
|
|
35
|
+
default:
|
|
36
|
+
throw new Error(`Unsupported type: ${param.kind}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Decodes a single function parameter for the function signature.
|
|
42
|
+
* @param param - The parameter to decode.
|
|
43
|
+
* @returns A string representing the parameter type and optionally its name.
|
|
44
|
+
*/
|
|
45
|
+
private decodeParameter(param: ABIVariable): string {
|
|
46
|
+
const type = this.getParameterType(param.type);
|
|
47
|
+
return this.includeNames ? `${param.name}: ${type}` : type;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Decodes all the parameters and build the function signature
|
|
52
|
+
* @returns The function signature.
|
|
53
|
+
*/
|
|
54
|
+
public decode(): string {
|
|
55
|
+
return `${this.name}(${this.parameters.map(param => this.decodeParameter(param)).join(this.separator)})`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Decodes a function signature from the name and parameters.
|
|
61
|
+
* @param name - The name of the function.
|
|
62
|
+
* @param parameters - The parameters of the function.
|
|
63
|
+
* @returns - The function signature.
|
|
64
|
+
*/
|
|
65
|
+
export function decodeFunctionSignature(name: string, parameters: ABIParameter[]) {
|
|
66
|
+
return new FunctionSignatureDecoder(name, parameters).decode();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Decodes a function signature from the name and parameters including parameter names.
|
|
71
|
+
* @param name - The name of the function.
|
|
72
|
+
* @param parameters - The parameters of the function.
|
|
73
|
+
* @returns - The user-friendly function signature.
|
|
74
|
+
*/
|
|
75
|
+
export function decodeFunctionSignatureWithParameterNames(name: string, parameters: ABIParameter[]) {
|
|
76
|
+
return new FunctionSignatureDecoder(name, parameters, true).decode();
|
|
77
|
+
}
|
package/src/abi/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './abi.js';
|
|
2
2
|
export * from './buffer.js';
|
|
3
3
|
export * from './decoder.js';
|
|
4
|
+
export * from './function_signature_decoder.js';
|
|
4
5
|
export * from './encoder.js';
|
|
5
6
|
export * from './authorization_selector.js';
|
|
6
7
|
export * from './event_metadata_definition.js';
|
|
@@ -68,6 +68,14 @@ export function getNextL1SlotTimestamp(
|
|
|
68
68
|
return constants.l1GenesisTime + (currentL1Slot + 1n) * BigInt(constants.ethereumSlotDuration);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/** Returns the timestamp of the last L1 slot within a given L2 slot. */
|
|
72
|
+
export function getLastL1SlotTimestampForL2Slot(
|
|
73
|
+
slot: SlotNumber,
|
|
74
|
+
constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration' | 'ethereumSlotDuration'>,
|
|
75
|
+
): bigint {
|
|
76
|
+
return getTimestampForSlot(slot, constants) + BigInt(constants.slotDuration - constants.ethereumSlotDuration);
|
|
77
|
+
}
|
|
78
|
+
|
|
71
79
|
/** Returns the L2 slot number at the next L1 block based on the current timestamp. */
|
|
72
80
|
export function getSlotAtNextL1Block(
|
|
73
81
|
currentL1Timestamp: bigint,
|