@aztec/stdlib 0.82.2 → 0.82.3-nightly.20250403
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/avm/avm.d.ts +4648 -1474
- package/dest/avm/avm.d.ts.map +1 -1
- package/dest/avm/avm.js +182 -109
- package/dest/avm/avm_proving_request.d.ts +1867 -498
- package/dest/avm/avm_proving_request.d.ts.map +1 -1
- package/dest/block/l2_block_downloader/l2_block_stream.d.ts +10 -12
- package/dest/block/l2_block_downloader/l2_block_stream.d.ts.map +1 -1
- package/dest/block/l2_block_downloader/l2_block_stream.js +45 -11
- package/dest/config/config.d.ts +2 -2
- package/dest/config/config.d.ts.map +1 -1
- package/dest/config/config.js +4 -5
- package/dest/contract/interfaces/node-info.d.ts +2 -2
- package/dest/contract/interfaces/node-info.d.ts.map +1 -1
- package/dest/contract/interfaces/node-info.js +1 -1
- package/dest/database-version/version_manager.d.ts +4 -2
- package/dest/database-version/version_manager.d.ts.map +1 -1
- package/dest/database-version/version_manager.js +13 -9
- package/dest/epoch-helpers/index.d.ts +2 -0
- 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 +7 -0
- package/dest/file-store/factory.d.ts.map +1 -0
- package/dest/file-store/factory.js +46 -0
- package/dest/file-store/gcs.d.ts +22 -0
- package/dest/file-store/gcs.d.ts.map +1 -0
- package/dest/file-store/gcs.js +115 -0
- package/dest/file-store/http.d.ts +15 -0
- package/dest/file-store/http.d.ts.map +1 -0
- package/dest/file-store/http.js +53 -0
- package/dest/file-store/index.d.ts +3 -0
- package/dest/file-store/index.d.ts.map +1 -0
- package/dest/file-store/index.js +2 -0
- package/dest/file-store/interface.d.ts +24 -0
- package/dest/file-store/interface.d.ts.map +1 -0
- package/dest/file-store/interface.js +1 -0
- package/dest/file-store/local.d.ts +16 -0
- package/dest/file-store/local.d.ts.map +1 -0
- package/dest/file-store/local.js +40 -0
- package/dest/interfaces/aztec-node-admin.d.ts +9 -1
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-admin.js +2 -1
- package/dest/interfaces/aztec-node.d.ts +3 -0
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +2 -0
- package/dest/interfaces/p2p.d.ts +2 -0
- package/dest/interfaces/p2p.d.ts.map +1 -1
- package/dest/interfaces/p2p.js +2 -1
- package/dest/interfaces/prover-client.d.ts +3 -3
- package/dest/interfaces/prover-client.d.ts.map +1 -1
- package/dest/interfaces/prover-client.js +6 -4
- package/dest/interfaces/prover-node.d.ts +4 -0
- package/dest/interfaces/prover-node.d.ts.map +1 -1
- package/dest/interfaces/prover-node.js +5 -1
- package/dest/interfaces/proving-job.d.ts +1866 -497
- package/dest/interfaces/proving-job.d.ts.map +1 -1
- package/dest/interfaces/pxe.d.ts +7 -6
- package/dest/interfaces/pxe.d.ts.map +1 -1
- package/dest/interfaces/pxe.js +1 -1
- package/dest/interfaces/service.d.ts +3 -0
- package/dest/interfaces/service.d.ts.map +1 -1
- package/dest/interfaces/service.js +7 -0
- package/dest/interfaces/world_state.d.ts +13 -15
- package/dest/interfaces/world_state.d.ts.map +1 -1
- package/dest/keys/derivation.d.ts +1 -1
- package/dest/keys/derivation.d.ts.map +1 -1
- package/dest/keys/derivation.js +10 -2
- package/dest/logs/index.d.ts +2 -1
- package/dest/logs/index.d.ts.map +1 -1
- package/dest/logs/index.js +2 -1
- package/dest/logs/pending_tagged_log.d.ts +17 -0
- package/dest/logs/pending_tagged_log.d.ts.map +1 -0
- package/dest/logs/pending_tagged_log.js +45 -0
- package/dest/logs/{l1_payload/shared_secret_derivation.d.ts → shared_secret_derivation.d.ts} +4 -3
- package/dest/logs/shared_secret_derivation.d.ts.map +1 -0
- package/dest/logs/{l1_payload/shared_secret_derivation.js → shared_secret_derivation.js} +3 -5
- package/dest/logs/tx_scoped_l2_log.d.ts +6 -1
- package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
- package/dest/logs/tx_scoped_l2_log.js +12 -4
- package/dest/note/note.d.ts +45 -4
- package/dest/note/note.d.ts.map +1 -1
- package/dest/note/note.js +51 -4
- package/dest/proofs/proof.d.ts.map +1 -1
- package/dest/proofs/proof.js +33 -7
- package/dest/snapshots/download.d.ts +9 -0
- package/dest/snapshots/download.d.ts.map +1 -0
- package/dest/snapshots/download.js +37 -0
- package/dest/snapshots/index.d.ts +4 -0
- package/dest/snapshots/index.d.ts.map +1 -0
- package/dest/snapshots/index.js +3 -0
- package/dest/snapshots/types.d.ts +97 -0
- package/dest/snapshots/types.d.ts.map +1 -0
- package/dest/snapshots/types.js +27 -0
- package/dest/snapshots/upload.d.ts +5 -0
- package/dest/snapshots/upload.d.ts.map +1 -0
- package/dest/snapshots/upload.js +37 -0
- package/dest/tests/factories.d.ts +21 -7
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +78 -30
- package/dest/tests/mocks.d.ts +2 -1
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +5 -1
- package/dest/trees/merkle_tree_id.d.ts +8 -0
- package/dest/trees/merkle_tree_id.d.ts.map +1 -1
- package/dest/trees/merkle_tree_id.js +10 -0
- package/dest/trees/nullifier_leaf.d.ts +49 -15
- package/dest/trees/nullifier_leaf.d.ts.map +1 -1
- package/dest/trees/nullifier_leaf.js +45 -22
- package/dest/trees/nullifier_membership_witness.d.ts +34 -18
- package/dest/trees/nullifier_membership_witness.d.ts.map +1 -1
- package/dest/trees/protocol_contract_leaf.d.ts +0 -1
- package/dest/trees/protocol_contract_leaf.d.ts.map +1 -1
- package/dest/trees/protocol_contract_leaf.js +0 -3
- package/dest/trees/public_data_leaf.d.ts +59 -25
- package/dest/trees/public_data_leaf.d.ts.map +1 -1
- package/dest/trees/public_data_leaf.js +41 -30
- package/dest/trees/public_data_witness.d.ts +42 -24
- package/dest/trees/public_data_witness.d.ts.map +1 -1
- package/dest/trees/public_data_witness.js +6 -6
- package/dest/validators/index.d.ts +3 -0
- package/dest/validators/index.d.ts.map +1 -0
- package/dest/validators/index.js +1 -0
- package/dest/validators/schemas.d.ts +342 -0
- package/dest/validators/schemas.d.ts.map +1 -0
- package/dest/validators/schemas.js +40 -0
- package/dest/validators/types.d.ts +39 -0
- package/dest/validators/types.d.ts.map +1 -0
- package/dest/validators/types.js +1 -0
- package/dest/versioning/versioning.d.ts +1 -1
- package/dest/versioning/versioning.d.ts.map +1 -1
- package/dest/versioning/versioning.js +6 -6
- package/package.json +11 -8
- package/src/avm/avm.ts +183 -104
- package/src/block/l2_block_downloader/l2_block_stream.ts +64 -29
- package/src/config/config.ts +6 -6
- package/src/contract/interfaces/node-info.ts +3 -3
- package/src/database-version/version_manager.ts +12 -8
- package/src/epoch-helpers/index.ts +8 -0
- package/src/file-store/factory.ts +61 -0
- package/src/file-store/gcs.ts +121 -0
- package/src/file-store/http.ts +58 -0
- package/src/file-store/index.ts +2 -0
- package/src/file-store/interface.ts +19 -0
- package/src/file-store/local.ts +46 -0
- package/src/interfaces/aztec-node-admin.ts +11 -1
- package/src/interfaces/aztec-node.ts +7 -0
- package/src/interfaces/p2p.ts +4 -0
- package/src/interfaces/prover-client.ts +9 -7
- package/src/interfaces/prover-node.ts +10 -0
- package/src/interfaces/pxe.ts +14 -7
- package/src/interfaces/service.ts +13 -0
- package/src/interfaces/world_state.ts +17 -15
- package/src/keys/derivation.ts +12 -6
- package/src/logs/index.ts +2 -1
- package/src/logs/pending_tagged_log.ts +43 -0
- package/src/logs/{l1_payload/shared_secret_derivation.ts → shared_secret_derivation.ts} +4 -11
- package/src/logs/tx_scoped_l2_log.ts +13 -4
- package/src/note/note.ts +61 -5
- package/src/proofs/proof.ts +39 -5
- package/src/snapshots/download.ts +60 -0
- package/src/snapshots/index.ts +3 -0
- package/src/snapshots/types.ts +58 -0
- package/src/snapshots/upload.ts +55 -0
- package/src/tests/factories.ts +137 -53
- package/src/tests/mocks.ts +7 -0
- package/src/trees/merkle_tree_id.ts +12 -0
- package/src/trees/nullifier_leaf.ts +48 -21
- package/src/trees/protocol_contract_leaf.ts +0 -4
- package/src/trees/public_data_leaf.ts +40 -29
- package/src/trees/public_data_witness.ts +6 -6
- package/src/validators/index.ts +3 -0
- package/src/validators/schemas.ts +53 -0
- package/src/validators/types.ts +37 -0
- package/src/versioning/versioning.ts +8 -14
- package/dest/event/event.d.ts +0 -24
- package/dest/event/event.d.ts.map +0 -1
- package/dest/event/event.js +0 -13
- package/dest/event/event_metadata.d.ts +0 -38
- package/dest/event/event_metadata.d.ts.map +0 -1
- package/dest/event/event_metadata.js +0 -45
- package/dest/event/index.d.ts +0 -4
- package/dest/event/index.d.ts.map +0 -1
- package/dest/event/index.js +0 -3
- package/dest/event/l1_event_payload.d.ts +0 -52
- package/dest/event/l1_event_payload.d.ts.map +0 -1
- package/dest/event/l1_event_payload.js +0 -64
- package/dest/logs/l1_payload/encrypted_log_payload.d.ts +0 -50
- package/dest/logs/l1_payload/encrypted_log_payload.d.ts.map +0 -1
- package/dest/logs/l1_payload/encrypted_log_payload.js +0 -140
- package/dest/logs/l1_payload/encryption_util.d.ts +0 -24
- package/dest/logs/l1_payload/encryption_util.d.ts.map +0 -1
- package/dest/logs/l1_payload/encryption_util.js +0 -46
- package/dest/logs/l1_payload/index.d.ts +0 -3
- package/dest/logs/l1_payload/index.d.ts.map +0 -1
- package/dest/logs/l1_payload/index.js +0 -2
- package/dest/logs/l1_payload/payload.d.ts +0 -60
- package/dest/logs/l1_payload/payload.d.ts.map +0 -1
- package/dest/logs/l1_payload/payload.js +0 -61
- package/dest/logs/l1_payload/shared_secret_derivation.d.ts.map +0 -1
- package/src/event/event.ts +0 -16
- package/src/event/event_metadata.ts +0 -56
- package/src/event/index.ts +0 -3
- package/src/event/l1_event_payload.ts +0 -87
- package/src/logs/l1_payload/encrypted_log_payload.ts +0 -202
- package/src/logs/l1_payload/encryption_util.ts +0 -54
- package/src/logs/l1_payload/index.ts +0 -2
- package/src/logs/l1_payload/payload.ts +0 -73
package/src/avm/avm.ts
CHANGED
|
@@ -6,34 +6,16 @@ import { z } from 'zod';
|
|
|
6
6
|
|
|
7
7
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
8
8
|
import { PublicKeys } from '../keys/public_keys.js';
|
|
9
|
+
import { AppendOnlyTreeSnapshot } from '../trees/append_only_tree_snapshot.js';
|
|
10
|
+
import { MerkleTreeId } from '../trees/merkle_tree_id.js';
|
|
9
11
|
import { NullifierLeafPreimage } from '../trees/nullifier_leaf.js';
|
|
10
12
|
import { PublicDataTreeLeafPreimage } from '../trees/public_data_leaf.js';
|
|
11
13
|
import { AvmCircuitPublicInputs } from './avm_circuit_public_inputs.js';
|
|
12
14
|
import { serializeWithMessagePack } from './message_pack.js';
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
public readonly contractAddress: AztecAddress,
|
|
18
|
-
public readonly calldata: Fr[],
|
|
19
|
-
public isStaticCall: boolean,
|
|
20
|
-
) {}
|
|
21
|
-
|
|
22
|
-
static get schema() {
|
|
23
|
-
return z
|
|
24
|
-
.object({
|
|
25
|
-
msgSender: AztecAddress.schema,
|
|
26
|
-
contractAddress: AztecAddress.schema,
|
|
27
|
-
calldata: schemas.Fr.array(),
|
|
28
|
-
isStaticCall: z.boolean(),
|
|
29
|
-
})
|
|
30
|
-
.transform(
|
|
31
|
-
({ msgSender, contractAddress, calldata, isStaticCall }) =>
|
|
32
|
-
new AvmEnqueuedCallHint(msgSender, contractAddress, calldata, isStaticCall),
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
16
|
+
////////////////////////////////////////////////////////////////////////////
|
|
17
|
+
// Hints (contracts)
|
|
18
|
+
////////////////////////////////////////////////////////////////////////////
|
|
37
19
|
export class AvmContractClassHint {
|
|
38
20
|
constructor(
|
|
39
21
|
public readonly classId: Fr,
|
|
@@ -115,97 +97,192 @@ export class AvmContractInstanceHint {
|
|
|
115
97
|
}
|
|
116
98
|
}
|
|
117
99
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export class AvmNullifierWriteTreeHint {
|
|
133
|
-
constructor(public lowLeafRead: AvmNullifierReadTreeHint, public readonly insertionPath: Fr[]) {}
|
|
100
|
+
////////////////////////////////////////////////////////////////////////////
|
|
101
|
+
// Hints (merkle db)
|
|
102
|
+
////////////////////////////////////////////////////////////////////////////
|
|
103
|
+
// Hint for MerkleTreeDB.getSiblingPath.
|
|
104
|
+
export class AvmGetSiblingPathHint {
|
|
105
|
+
constructor(
|
|
106
|
+
public readonly hintKey: AppendOnlyTreeSnapshot,
|
|
107
|
+
// params
|
|
108
|
+
public readonly treeId: MerkleTreeId,
|
|
109
|
+
public readonly index: bigint,
|
|
110
|
+
// return
|
|
111
|
+
public readonly path: Fr[],
|
|
112
|
+
) {}
|
|
134
113
|
|
|
135
114
|
static get schema() {
|
|
136
115
|
return z
|
|
137
116
|
.object({
|
|
138
|
-
|
|
139
|
-
|
|
117
|
+
hintKey: AppendOnlyTreeSnapshot.schema,
|
|
118
|
+
treeId: z.number().int().nonnegative(),
|
|
119
|
+
index: schemas.BigInt,
|
|
120
|
+
path: schemas.Fr.array(),
|
|
140
121
|
})
|
|
141
|
-
.transform(({
|
|
122
|
+
.transform(({ hintKey, treeId, index, path }) => new AvmGetSiblingPathHint(hintKey, treeId, index, path));
|
|
142
123
|
}
|
|
143
124
|
}
|
|
144
125
|
|
|
145
|
-
|
|
126
|
+
// Hint for MerkleTreeDB.getPreviousValueIndex.
|
|
127
|
+
export class AvmGetPreviousValueIndexHint {
|
|
146
128
|
constructor(
|
|
147
|
-
public readonly
|
|
148
|
-
|
|
149
|
-
public readonly
|
|
129
|
+
public readonly hintKey: AppendOnlyTreeSnapshot,
|
|
130
|
+
// params
|
|
131
|
+
public readonly treeId: MerkleTreeId,
|
|
132
|
+
public readonly value: Fr,
|
|
133
|
+
// return
|
|
134
|
+
public readonly index: bigint,
|
|
135
|
+
public readonly alreadyPresent: boolean,
|
|
150
136
|
) {}
|
|
151
137
|
|
|
152
138
|
static get schema() {
|
|
153
139
|
return z
|
|
154
140
|
.object({
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
141
|
+
hintKey: AppendOnlyTreeSnapshot.schema,
|
|
142
|
+
treeId: z.number().int().nonnegative(),
|
|
143
|
+
value: schemas.Fr,
|
|
144
|
+
index: schemas.BigInt,
|
|
145
|
+
alreadyPresent: z.boolean(),
|
|
158
146
|
})
|
|
159
147
|
.transform(
|
|
160
|
-
({
|
|
161
|
-
new
|
|
148
|
+
({ hintKey, treeId, value, index, alreadyPresent }) =>
|
|
149
|
+
new AvmGetPreviousValueIndexHint(hintKey, treeId, value, index, alreadyPresent),
|
|
162
150
|
);
|
|
163
151
|
}
|
|
164
152
|
}
|
|
165
153
|
|
|
166
|
-
|
|
154
|
+
type IndexedTreeLeafPreimages = NullifierLeafPreimage | PublicDataTreeLeafPreimage;
|
|
155
|
+
type IndexedTreeLeafPreimagesClasses = typeof NullifierLeafPreimage | typeof PublicDataTreeLeafPreimage;
|
|
156
|
+
|
|
157
|
+
// Hint for MerkleTreeDB.getLeafPreimage.
|
|
158
|
+
// NOTE: I need this factory because in order to get hold of the schema, I need an actual instance of the class,
|
|
159
|
+
// having the type doesn't suffice since TS does type erasure in the end.
|
|
160
|
+
function AvmGetLeafPreimageHintFactory(klass: IndexedTreeLeafPreimagesClasses) {
|
|
161
|
+
return class AvmGetLeafPreimageHint {
|
|
162
|
+
constructor(
|
|
163
|
+
public readonly hintKey: AppendOnlyTreeSnapshot,
|
|
164
|
+
// params (tree id will be implicit)
|
|
165
|
+
public readonly index: bigint,
|
|
166
|
+
// return
|
|
167
|
+
public readonly leafPreimage: IndexedTreeLeafPreimages,
|
|
168
|
+
) {}
|
|
169
|
+
|
|
170
|
+
static get schema() {
|
|
171
|
+
return z
|
|
172
|
+
.object({
|
|
173
|
+
hintKey: AppendOnlyTreeSnapshot.schema,
|
|
174
|
+
index: schemas.BigInt,
|
|
175
|
+
leafPreimage: klass.schema,
|
|
176
|
+
})
|
|
177
|
+
.transform(({ hintKey, index, leafPreimage }) => new AvmGetLeafPreimageHint(hintKey, index, leafPreimage));
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Note: only supported for PUBLIC_DATA_TREE and NULLIFIER_TREE.
|
|
183
|
+
export class AvmGetLeafPreimageHintPublicDataTree extends AvmGetLeafPreimageHintFactory(PublicDataTreeLeafPreimage) {}
|
|
184
|
+
export class AvmGetLeafPreimageHintNullifierTree extends AvmGetLeafPreimageHintFactory(NullifierLeafPreimage) {}
|
|
185
|
+
|
|
186
|
+
// Hint for MerkleTreeDB.getLeafValue.
|
|
187
|
+
// Note: only supported for NOTE_HASH_TREE and L1_TO_L2_MESSAGE_TREE.
|
|
188
|
+
export class AvmGetLeafValueHint {
|
|
167
189
|
constructor(
|
|
168
|
-
public readonly
|
|
169
|
-
|
|
170
|
-
public readonly
|
|
190
|
+
public readonly hintKey: AppendOnlyTreeSnapshot,
|
|
191
|
+
// params
|
|
192
|
+
public readonly treeId: MerkleTreeId,
|
|
193
|
+
public readonly index: bigint,
|
|
194
|
+
// return
|
|
195
|
+
public readonly value: Fr,
|
|
171
196
|
) {}
|
|
172
197
|
|
|
173
|
-
static empty() {
|
|
174
|
-
return new AvmPublicDataReadTreeHint(PublicDataTreeLeafPreimage.empty(), Fr.ZERO, []);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
198
|
static get schema() {
|
|
178
199
|
return z
|
|
179
200
|
.object({
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
201
|
+
hintKey: AppendOnlyTreeSnapshot.schema,
|
|
202
|
+
treeId: z.number().int().nonnegative(),
|
|
203
|
+
index: schemas.BigInt,
|
|
204
|
+
value: schemas.Fr,
|
|
183
205
|
})
|
|
184
|
-
.transform(
|
|
185
|
-
({ leafPreimage, leafIndex, siblingPath }) =>
|
|
186
|
-
new AvmPublicDataReadTreeHint(leafPreimage, leafIndex, siblingPath),
|
|
187
|
-
);
|
|
206
|
+
.transform(({ hintKey, treeId, index, value }) => new AvmGetLeafValueHint(hintKey, treeId, index, value));
|
|
188
207
|
}
|
|
189
208
|
}
|
|
190
209
|
|
|
191
|
-
|
|
210
|
+
// Hint for MerkleTreeDB.sequentialInsert.
|
|
211
|
+
// NOTE: I need this factory because in order to get hold of the schema, I need an actual instance of the class,
|
|
212
|
+
// having the type doesn't suffice since TS does type erasure in the end.
|
|
213
|
+
function AvmSequentialInsertHintFactory(klass: IndexedTreeLeafPreimagesClasses) {
|
|
214
|
+
return class AvmSequentialInsertHint {
|
|
215
|
+
constructor(
|
|
216
|
+
public readonly hintKey: AppendOnlyTreeSnapshot,
|
|
217
|
+
public readonly stateAfter: AppendOnlyTreeSnapshot,
|
|
218
|
+
// params
|
|
219
|
+
public readonly treeId: MerkleTreeId,
|
|
220
|
+
public readonly leaf: InstanceType<IndexedTreeLeafPreimagesClasses>['leaf'],
|
|
221
|
+
// return
|
|
222
|
+
public readonly lowLeavesWitnessData: {
|
|
223
|
+
leaf: IndexedTreeLeafPreimages;
|
|
224
|
+
index: bigint;
|
|
225
|
+
path: Fr[];
|
|
226
|
+
},
|
|
227
|
+
public readonly insertionWitnessData: {
|
|
228
|
+
leaf: IndexedTreeLeafPreimages;
|
|
229
|
+
index: bigint;
|
|
230
|
+
path: Fr[];
|
|
231
|
+
},
|
|
232
|
+
) {}
|
|
233
|
+
|
|
234
|
+
static get schema() {
|
|
235
|
+
return z
|
|
236
|
+
.object({
|
|
237
|
+
hintKey: AppendOnlyTreeSnapshot.schema,
|
|
238
|
+
stateAfter: AppendOnlyTreeSnapshot.schema,
|
|
239
|
+
treeId: z.number().int().nonnegative(),
|
|
240
|
+
leaf: klass.leafSchema,
|
|
241
|
+
lowLeavesWitnessData: z.object({
|
|
242
|
+
leaf: klass.schema,
|
|
243
|
+
index: schemas.BigInt,
|
|
244
|
+
path: schemas.Fr.array(),
|
|
245
|
+
}),
|
|
246
|
+
insertionWitnessData: z.object({
|
|
247
|
+
leaf: klass.schema,
|
|
248
|
+
index: schemas.BigInt,
|
|
249
|
+
path: schemas.Fr.array(),
|
|
250
|
+
}),
|
|
251
|
+
})
|
|
252
|
+
.transform(
|
|
253
|
+
({ hintKey, stateAfter, treeId, leaf, lowLeavesWitnessData, insertionWitnessData }) =>
|
|
254
|
+
new AvmSequentialInsertHint(hintKey, stateAfter, treeId, leaf, lowLeavesWitnessData, insertionWitnessData),
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Note: only supported for PUBLIC_DATA_TREE and NULLIFIER_TREE.
|
|
261
|
+
export class AvmSequentialInsertHintPublicDataTree extends AvmSequentialInsertHintFactory(PublicDataTreeLeafPreimage) {}
|
|
262
|
+
export class AvmSequentialInsertHintNullifierTree extends AvmSequentialInsertHintFactory(NullifierLeafPreimage) {}
|
|
263
|
+
|
|
264
|
+
////////////////////////////////////////////////////////////////////////////
|
|
265
|
+
// Hints (other)
|
|
266
|
+
////////////////////////////////////////////////////////////////////////////
|
|
267
|
+
export class AvmEnqueuedCallHint {
|
|
192
268
|
constructor(
|
|
193
|
-
|
|
194
|
-
public readonly
|
|
195
|
-
public readonly
|
|
196
|
-
public
|
|
269
|
+
public readonly msgSender: AztecAddress,
|
|
270
|
+
public readonly contractAddress: AztecAddress,
|
|
271
|
+
public readonly calldata: Fr[],
|
|
272
|
+
public isStaticCall: boolean,
|
|
197
273
|
) {}
|
|
198
274
|
|
|
199
275
|
static get schema() {
|
|
200
276
|
return z
|
|
201
277
|
.object({
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
278
|
+
msgSender: AztecAddress.schema,
|
|
279
|
+
contractAddress: AztecAddress.schema,
|
|
280
|
+
calldata: schemas.Fr.array(),
|
|
281
|
+
isStaticCall: z.boolean(),
|
|
205
282
|
})
|
|
206
283
|
.transform(
|
|
207
|
-
({
|
|
208
|
-
new
|
|
284
|
+
({ msgSender, contractAddress, calldata, isStaticCall }) =>
|
|
285
|
+
new AvmEnqueuedCallHint(msgSender, contractAddress, calldata, isStaticCall),
|
|
209
286
|
);
|
|
210
287
|
}
|
|
211
288
|
}
|
|
@@ -213,16 +290,18 @@ export class AvmPublicDataWriteTreeHint {
|
|
|
213
290
|
export class AvmExecutionHints {
|
|
214
291
|
constructor(
|
|
215
292
|
public readonly enqueuedCalls: AvmEnqueuedCallHint[] = [],
|
|
293
|
+
// Contract hints.
|
|
216
294
|
public readonly contractInstances: AvmContractInstanceHint[] = [],
|
|
217
295
|
public readonly contractClasses: AvmContractClassHint[] = [],
|
|
218
296
|
public readonly bytecodeCommitments: AvmBytecodeCommitmentHint[] = [],
|
|
219
|
-
|
|
220
|
-
public readonly
|
|
221
|
-
public readonly
|
|
222
|
-
public readonly
|
|
223
|
-
public readonly
|
|
224
|
-
public readonly
|
|
225
|
-
public readonly
|
|
297
|
+
// Merkle DB hints.
|
|
298
|
+
public readonly getSiblingPathHints: AvmGetSiblingPathHint[] = [],
|
|
299
|
+
public readonly getPreviousValueIndexHints: AvmGetPreviousValueIndexHint[] = [],
|
|
300
|
+
public readonly getLeafPreimageHintsPublicDataTree: AvmGetLeafPreimageHintPublicDataTree[] = [],
|
|
301
|
+
public readonly getLeafPreimageHintsNullifierTree: AvmGetLeafPreimageHintNullifierTree[] = [],
|
|
302
|
+
public readonly getLeafValueHints: AvmGetLeafValueHint[] = [],
|
|
303
|
+
public readonly sequentialInsertHintsPublicDataTree: AvmSequentialInsertHintPublicDataTree[] = [],
|
|
304
|
+
public readonly sequentialInsertHintsNullifierTree: AvmSequentialInsertHintNullifierTree[] = [],
|
|
226
305
|
) {}
|
|
227
306
|
|
|
228
307
|
static empty() {
|
|
@@ -236,13 +315,13 @@ export class AvmExecutionHints {
|
|
|
236
315
|
contractInstances: AvmContractInstanceHint.schema.array(),
|
|
237
316
|
contractClasses: AvmContractClassHint.schema.array(),
|
|
238
317
|
bytecodeCommitments: AvmBytecodeCommitmentHint.schema.array(),
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
318
|
+
getSiblingPathHints: AvmGetSiblingPathHint.schema.array(),
|
|
319
|
+
getPreviousValueIndexHints: AvmGetPreviousValueIndexHint.schema.array(),
|
|
320
|
+
getLeafPreimageHintsPublicDataTree: AvmGetLeafPreimageHintPublicDataTree.schema.array(),
|
|
321
|
+
getLeafPreimageHintsNullifierTree: AvmGetLeafPreimageHintNullifierTree.schema.array(),
|
|
322
|
+
getLeafValueHints: AvmGetLeafValueHint.schema.array(),
|
|
323
|
+
sequentialInsertHintsPublicDataTree: AvmSequentialInsertHintPublicDataTree.schema.array(),
|
|
324
|
+
sequentialInsertHintsNullifierTree: AvmSequentialInsertHintNullifierTree.schema.array(),
|
|
246
325
|
})
|
|
247
326
|
.transform(
|
|
248
327
|
({
|
|
@@ -250,26 +329,26 @@ export class AvmExecutionHints {
|
|
|
250
329
|
contractInstances,
|
|
251
330
|
contractClasses,
|
|
252
331
|
bytecodeCommitments,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
332
|
+
getSiblingPathHints,
|
|
333
|
+
getPreviousValueIndexHints,
|
|
334
|
+
getLeafPreimageHintsPublicDataTree,
|
|
335
|
+
getLeafPreimageHintsNullifierTree,
|
|
336
|
+
getLeafValueHints,
|
|
337
|
+
sequentialInsertHintsPublicDataTree,
|
|
338
|
+
sequentialInsertHintsNullifierTree,
|
|
260
339
|
}) =>
|
|
261
340
|
new AvmExecutionHints(
|
|
262
341
|
enqueuedCalls,
|
|
263
342
|
contractInstances,
|
|
264
343
|
contractClasses,
|
|
265
344
|
bytecodeCommitments,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
345
|
+
getSiblingPathHints,
|
|
346
|
+
getPreviousValueIndexHints,
|
|
347
|
+
getLeafPreimageHintsPublicDataTree,
|
|
348
|
+
getLeafPreimageHintsNullifierTree,
|
|
349
|
+
getLeafValueHints,
|
|
350
|
+
sequentialInsertHintsPublicDataTree,
|
|
351
|
+
sequentialInsertHintsNullifierTree,
|
|
273
352
|
),
|
|
274
353
|
);
|
|
275
354
|
}
|
|
@@ -9,6 +9,7 @@ import type { PublishedL2Block } from '../published_l2_block.js';
|
|
|
9
9
|
export class L2BlockStream {
|
|
10
10
|
private readonly runningPromise: RunningPromise;
|
|
11
11
|
private isSyncing = false;
|
|
12
|
+
private hasStarted = false;
|
|
12
13
|
|
|
13
14
|
constructor(
|
|
14
15
|
private l2BlockSource: Pick<L2BlockSource, 'getPublishedBlocks' | 'getBlockHeader' | 'getL2Tips'>,
|
|
@@ -65,18 +66,31 @@ export class L2BlockStream {
|
|
|
65
66
|
|
|
66
67
|
// Check if there was a reorg and emit a chain-pruned event if so.
|
|
67
68
|
let latestBlockNumber = localTips.latest.number;
|
|
68
|
-
|
|
69
|
+
const sourceCache = new BlockHashCache([sourceTips.latest]);
|
|
70
|
+
while (!(await this.areBlockHashesEqualAt(latestBlockNumber, { sourceCache }))) {
|
|
69
71
|
latestBlockNumber--;
|
|
70
72
|
}
|
|
73
|
+
|
|
71
74
|
if (latestBlockNumber < localTips.latest.number) {
|
|
72
75
|
this.log.verbose(`Reorg detected. Pruning blocks from ${latestBlockNumber + 1} to ${localTips.latest.number}.`);
|
|
73
|
-
await this.emitEvent({
|
|
76
|
+
await this.emitEvent({
|
|
77
|
+
type: 'chain-pruned',
|
|
78
|
+
block: {
|
|
79
|
+
number: latestBlockNumber,
|
|
80
|
+
hash: sourceCache.get(latestBlockNumber) ?? (await this.getBlockHashFromSource(latestBlockNumber))!,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
// If we are just starting, use the starting block number from the options.
|
|
77
86
|
if (latestBlockNumber === 0 && this.opts.startingBlock !== undefined) {
|
|
78
87
|
latestBlockNumber = Math.max(this.opts.startingBlock - 1, 0);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Only log this entry once (for sanity)
|
|
91
|
+
if (!this.hasStarted) {
|
|
79
92
|
this.log.verbose(`Starting sync from block number ${latestBlockNumber}`);
|
|
93
|
+
this.hasStarted = true;
|
|
80
94
|
}
|
|
81
95
|
|
|
82
96
|
// Request new blocks from the source.
|
|
@@ -94,10 +108,13 @@ export class L2BlockStream {
|
|
|
94
108
|
|
|
95
109
|
// Update the proven and finalized tips.
|
|
96
110
|
if (localTips.proven !== undefined && sourceTips.proven.number !== localTips.proven.number) {
|
|
97
|
-
await this.emitEvent({
|
|
111
|
+
await this.emitEvent({
|
|
112
|
+
type: 'chain-proven',
|
|
113
|
+
block: sourceTips.proven,
|
|
114
|
+
});
|
|
98
115
|
}
|
|
99
116
|
if (localTips.finalized !== undefined && sourceTips.finalized.number !== localTips.finalized.number) {
|
|
100
|
-
await this.emitEvent({ type: 'chain-finalized',
|
|
117
|
+
await this.emitEvent({ type: 'chain-finalized', block: sourceTips.finalized });
|
|
101
118
|
}
|
|
102
119
|
} catch (err: any) {
|
|
103
120
|
if (err.name === 'AbortError') {
|
|
@@ -112,29 +129,31 @@ export class L2BlockStream {
|
|
|
112
129
|
* @param blockNumber - The block number to test.
|
|
113
130
|
* @param args - A cache of data already requested from source, to avoid re-requesting it.
|
|
114
131
|
*/
|
|
115
|
-
private async areBlockHashesEqualAt(blockNumber: number, args: { sourceCache:
|
|
132
|
+
private async areBlockHashesEqualAt(blockNumber: number, args: { sourceCache: BlockHashCache }) {
|
|
116
133
|
if (blockNumber === 0) {
|
|
117
134
|
return true;
|
|
118
135
|
}
|
|
119
136
|
const localBlockHash = await this.localData.getL2BlockHash(blockNumber);
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.log.trace(`Comparing block hashes for block ${blockNumber}`, {
|
|
127
|
-
localBlockHash,
|
|
128
|
-
sourceBlockHash,
|
|
129
|
-
sourceCacheNumber: args.sourceCache[0]?.number,
|
|
130
|
-
sourceCacheHash: args.sourceCache[0]?.hash,
|
|
131
|
-
});
|
|
137
|
+
const sourceBlockHashFromCache = args.sourceCache.get(blockNumber);
|
|
138
|
+
const sourceBlockHash = args.sourceCache.get(blockNumber) ?? (await this.getBlockHashFromSource(blockNumber));
|
|
139
|
+
if (!sourceBlockHashFromCache && sourceBlockHash) {
|
|
140
|
+
args.sourceCache.add({ number: blockNumber, hash: sourceBlockHash });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this.log.trace(`Comparing block hashes for block ${blockNumber}`, { localBlockHash, sourceBlockHash });
|
|
132
144
|
return localBlockHash === sourceBlockHash;
|
|
133
145
|
}
|
|
134
146
|
|
|
147
|
+
private getBlockHashFromSource(blockNumber: number) {
|
|
148
|
+
return this.l2BlockSource
|
|
149
|
+
.getBlockHeader(blockNumber)
|
|
150
|
+
.then(h => h?.hash())
|
|
151
|
+
.then(hash => hash?.toString());
|
|
152
|
+
}
|
|
153
|
+
|
|
135
154
|
private async emitEvent(event: L2BlockStreamEvent) {
|
|
136
155
|
this.log.debug(
|
|
137
|
-
`Emitting ${event.type} (${event.type === 'blocks-added' ? event.blocks.length : event.
|
|
156
|
+
`Emitting ${event.type} (${event.type === 'blocks-added' ? event.blocks.length : event.block.number})`,
|
|
138
157
|
);
|
|
139
158
|
await this.handler.handleBlockStreamEvent(event);
|
|
140
159
|
if (!this.isRunning() && !this.isSyncing) {
|
|
@@ -143,6 +162,26 @@ export class L2BlockStream {
|
|
|
143
162
|
}
|
|
144
163
|
}
|
|
145
164
|
|
|
165
|
+
class BlockHashCache {
|
|
166
|
+
private readonly cache: Map<number, string> = new Map();
|
|
167
|
+
|
|
168
|
+
constructor(initial: L2BlockId[] = []) {
|
|
169
|
+
for (const block of initial) {
|
|
170
|
+
this.add(block);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public add(block: L2BlockId) {
|
|
175
|
+
if (block.hash) {
|
|
176
|
+
this.cache.set(block.number, block.hash);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public get(blockNumber: number) {
|
|
181
|
+
return this.cache.get(blockNumber);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
146
185
|
/** Interface to the local view of the chain. Implemented by world-state and l2-tips-store. */
|
|
147
186
|
export interface L2BlockStreamLocalDataProvider {
|
|
148
187
|
getL2BlockHash(number: number): Promise<string | undefined>;
|
|
@@ -155,23 +194,19 @@ export interface L2BlockStreamEventHandler {
|
|
|
155
194
|
}
|
|
156
195
|
|
|
157
196
|
export type L2BlockStreamEvent =
|
|
158
|
-
| {
|
|
197
|
+
| /** Emits blocks added to the chain. */ {
|
|
159
198
|
type: 'blocks-added';
|
|
160
|
-
/** New blocks added to the chain. */
|
|
161
199
|
blocks: PublishedL2Block[];
|
|
162
200
|
}
|
|
163
|
-
| {
|
|
201
|
+
| /** Reports last correct block (new tip of the unproven chain). */ {
|
|
164
202
|
type: 'chain-pruned';
|
|
165
|
-
|
|
166
|
-
blockNumber: number;
|
|
203
|
+
block: L2BlockId;
|
|
167
204
|
}
|
|
168
|
-
| {
|
|
205
|
+
| /** Reports new proven block. */ {
|
|
169
206
|
type: 'chain-proven';
|
|
170
|
-
|
|
171
|
-
blockNumber: number;
|
|
207
|
+
block: L2BlockId;
|
|
172
208
|
}
|
|
173
|
-
| {
|
|
209
|
+
| /** Reports new finalized block (proven and finalized on L1). */ {
|
|
174
210
|
type: 'chain-finalized';
|
|
175
|
-
|
|
176
|
-
blockNumber: number;
|
|
211
|
+
block: L2BlockId;
|
|
177
212
|
};
|
package/src/config/config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { l1ContractAddressesMapping } from '@aztec/ethereum/l1-contract-addresses';
|
|
2
|
-
import {
|
|
2
|
+
import type { ConfigMappingsType } from '@aztec/foundation/config';
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
|
|
5
5
|
export { type AllowedElement, type SequencerConfig, SequencerConfigSchema } from '../interfaces/configs.js';
|
|
@@ -7,7 +7,7 @@ export { type AllowedElement, type SequencerConfig, SequencerConfigSchema } from
|
|
|
7
7
|
export const emptyChainConfig: ChainConfig = {
|
|
8
8
|
l1ChainId: 0,
|
|
9
9
|
l1Contracts: { rollupAddress: EthAddress.ZERO },
|
|
10
|
-
|
|
10
|
+
rollupVersion: 0,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export const chainConfigMappings: ConfigMappingsType<ChainConfig> = {
|
|
@@ -17,10 +17,10 @@ export const chainConfigMappings: ConfigMappingsType<ChainConfig> = {
|
|
|
17
17
|
defaultValue: 31337,
|
|
18
18
|
description: 'The chain ID of the ethereum host.',
|
|
19
19
|
},
|
|
20
|
-
|
|
21
|
-
env: '
|
|
20
|
+
rollupVersion: {
|
|
21
|
+
env: 'ROLLUP_VERSION',
|
|
22
22
|
description: 'The version of the rollup.',
|
|
23
|
-
|
|
23
|
+
parseEnv: (val: string) => (Number.isSafeInteger(parseInt(val, 10)) ? parseInt(val, 10) : undefined),
|
|
24
24
|
},
|
|
25
25
|
l1Contracts: {
|
|
26
26
|
description: 'The deployed L1 contract addresses',
|
|
@@ -33,7 +33,7 @@ export type ChainConfig = {
|
|
|
33
33
|
/** The chain id of the ethereum host. */
|
|
34
34
|
l1ChainId: number;
|
|
35
35
|
/** The version of the rollup. */
|
|
36
|
-
|
|
36
|
+
rollupVersion: number;
|
|
37
37
|
/** The address to the L1 contracts. */
|
|
38
38
|
l1Contracts: {
|
|
39
39
|
/** The address to rollup */
|
|
@@ -11,8 +11,8 @@ export interface NodeInfo {
|
|
|
11
11
|
nodeVersion: string;
|
|
12
12
|
/** L1 chain id. */
|
|
13
13
|
l1ChainId: number;
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
/** Rollup version. */
|
|
15
|
+
rollupVersion: number;
|
|
16
16
|
/** The node's ENR. */
|
|
17
17
|
enr: string | undefined;
|
|
18
18
|
/** The deployed l1 contract addresses */
|
|
@@ -25,7 +25,7 @@ export const NodeInfoSchema: ZodFor<NodeInfo> = z
|
|
|
25
25
|
.object({
|
|
26
26
|
nodeVersion: z.string(),
|
|
27
27
|
l1ChainId: z.number().int().nonnegative(),
|
|
28
|
-
|
|
28
|
+
rollupVersion: z.number().int().nonnegative(),
|
|
29
29
|
enr: z.string().optional(),
|
|
30
30
|
l1ContractAddresses: L1ContractAddressesSchema,
|
|
31
31
|
protocolContractAddresses: ProtocolContractAddressesSchema,
|
|
@@ -79,13 +79,15 @@ export class DatabaseVersion {
|
|
|
79
79
|
|
|
80
80
|
export type DatabaseVersionManagerFs = Pick<typeof fs, 'readFile' | 'writeFile' | 'rm' | 'mkdir'>;
|
|
81
81
|
|
|
82
|
+
export const DATABASE_VERSION_FILE_NAME = 'db_version';
|
|
83
|
+
|
|
82
84
|
/**
|
|
83
85
|
* A manager for handling database versioning and migrations.
|
|
84
86
|
* This class will check the version of data in a directory and either
|
|
85
87
|
* reset or upgrade based on version compatibility.
|
|
86
88
|
*/
|
|
87
89
|
export class DatabaseVersionManager<T> {
|
|
88
|
-
public static readonly VERSION_FILE =
|
|
90
|
+
public static readonly VERSION_FILE = DATABASE_VERSION_FILE_NAME;
|
|
89
91
|
|
|
90
92
|
private readonly versionFile: string;
|
|
91
93
|
private readonly currentVersion: DatabaseVersion;
|
|
@@ -119,6 +121,11 @@ export class DatabaseVersionManager<T> {
|
|
|
119
121
|
this.currentVersion = new DatabaseVersion(schemaVersion, rollupAddress);
|
|
120
122
|
}
|
|
121
123
|
|
|
124
|
+
static async writeVersion(version: DatabaseVersion, dataDir: string, fileSystem: DatabaseVersionManagerFs = fs) {
|
|
125
|
+
await fileSystem.mkdir(dataDir, { recursive: true });
|
|
126
|
+
return fileSystem.writeFile(join(dataDir, DatabaseVersionManager.VERSION_FILE), version.toBuffer());
|
|
127
|
+
}
|
|
128
|
+
|
|
122
129
|
/**
|
|
123
130
|
* Checks the stored version against the current version and handles the outcome
|
|
124
131
|
* by either resetting the data directory or calling an upgrade function
|
|
@@ -163,7 +170,7 @@ export class DatabaseVersionManager<T> {
|
|
|
163
170
|
needsReset = true;
|
|
164
171
|
}
|
|
165
172
|
} else {
|
|
166
|
-
this.log.warn('Rollup address changed, resetting data directory');
|
|
173
|
+
this.log.warn('Rollup address changed, resetting data directory', { versionFile: this.versionFile });
|
|
167
174
|
needsReset = true;
|
|
168
175
|
}
|
|
169
176
|
|
|
@@ -181,17 +188,14 @@ export class DatabaseVersionManager<T> {
|
|
|
181
188
|
/**
|
|
182
189
|
* Writes the current version to the version file
|
|
183
190
|
*/
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
await this.fileSystem.mkdir(this.dataDirectory, { recursive: true });
|
|
187
|
-
// Write the version file
|
|
188
|
-
await this.fileSystem.writeFile(this.versionFile, this.currentVersion.toBuffer());
|
|
191
|
+
public writeVersion(dir?: string): Promise<void> {
|
|
192
|
+
return DatabaseVersionManager.writeVersion(this.currentVersion, dir ?? this.dataDirectory, this.fileSystem);
|
|
189
193
|
}
|
|
190
194
|
|
|
191
195
|
/**
|
|
192
196
|
* Resets the data directory by deleting it and recreating it
|
|
193
197
|
*/
|
|
194
|
-
|
|
198
|
+
public async resetDataDirectory(): Promise<void> {
|
|
195
199
|
try {
|
|
196
200
|
await this.fileSystem.rm(this.dataDirectory, { recursive: true, force: true, maxRetries: 3 });
|
|
197
201
|
await this.fileSystem.mkdir(this.dataDirectory, { recursive: true });
|