@aztec/stdlib 4.2.0-nightly.20260325 → 4.2.0-nightly.20260330
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/block/l2_block_source.d.ts +3 -4
- package/dest/block/l2_block_source.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/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/logs/tx_scoped_l2_log.d.ts +3 -1
- package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
- package/dest/logs/tx_scoped_l2_log.js +7 -0
- 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/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 +9 -9
- 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/block/l2_block_source.ts +2 -3
- package/src/hash/hash.ts +5 -0
- 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/logs/tx_scoped_l2_log.ts +16 -0
- package/src/messaging/l1_to_l2_message.ts +12 -9
- package/src/note/note_dao.ts +1 -4
- package/src/tx/capsule.ts +10 -2
- package/src/tx/tx_receipt.ts +1 -1
package/src/hash/hash.ts
CHANGED
|
@@ -98,6 +98,11 @@ export function computeProtocolNullifier(txRequestHash: Fr): Promise<Fr> {
|
|
|
98
98
|
return siloNullifier(AztecAddress.fromBigInt(NULL_MSG_SENDER_CONTRACT_ADDRESS), txRequestHash);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/** Domain-separates a raw log tag with the given domain separator. */
|
|
102
|
+
export function computeLogTag(rawTag: number | bigint | boolean | Fr | Buffer, domSep: DomainSeparator): Promise<Fr> {
|
|
103
|
+
return poseidon2HashWithSeparator([new Fr(rawTag)], domSep);
|
|
104
|
+
}
|
|
105
|
+
|
|
101
106
|
export function computeSiloedPrivateLogFirstField(contract: AztecAddress, field: Fr): Promise<Fr> {
|
|
102
107
|
return poseidon2HashWithSeparator([contract, field], DomainSeparator.PRIVATE_LOG_FIRST_FIELD);
|
|
103
108
|
}
|
|
@@ -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
|
|
46
|
-
|
|
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
|
|
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
|
|
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
|
-
*
|
|
8
|
-
*
|
|
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
|
-
* @
|
|
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
|
|
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
|
-
|
|
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
|
}
|
package/src/logs/siloed_tag.ts
CHANGED
|
@@ -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
|
-
|
|
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);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BlockNumber, BlockNumberSchema } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { times } from '@aztec/foundation/collection';
|
|
2
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { schemas as foundationSchemas } from '@aztec/foundation/schemas';
|
|
4
5
|
import {
|
|
@@ -83,6 +84,21 @@ export class TxScopedL2Log {
|
|
|
83
84
|
return new TxScopedL2Log(txHash, blockNumber, blockTimestamp, logData, noteHashes, firstNullifier);
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
static getBlockNumberFromBuffer(buffer: Buffer) {
|
|
88
|
+
return BlockNumber(buffer.readUint32BE(Fr.SIZE_IN_BYTES));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static random() {
|
|
92
|
+
return new TxScopedL2Log(
|
|
93
|
+
TxHash.fromField(Fr.random()),
|
|
94
|
+
BlockNumber(Math.floor(Math.random() * 100000) + 1),
|
|
95
|
+
BigInt(Math.floor(Date.now() / 1000)),
|
|
96
|
+
times(3, Fr.random),
|
|
97
|
+
times(3, Fr.random),
|
|
98
|
+
Fr.random(),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
86
102
|
equals(other: TxScopedL2Log) {
|
|
87
103
|
return (
|
|
88
104
|
this.txHash.equals(other.txHash) &&
|
|
@@ -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
|
}
|
package/src/note/note_dao.ts
CHANGED
|
@@ -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
|
-
|
|
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({
|
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
|
|
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
|
-
|
|
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() {
|
package/src/tx/tx_receipt.ts
CHANGED
|
@@ -15,7 +15,7 @@ export enum TxStatus {
|
|
|
15
15
|
PROPOSED = 'proposed',
|
|
16
16
|
CHECKPOINTED = 'checkpointed',
|
|
17
17
|
PROVEN = 'proven',
|
|
18
|
-
FINALIZED = 'finalized',
|
|
18
|
+
FINALIZED = 'finalized',
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/** Tx status sorted by finalization progress. */
|