@aztec/simulator 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928
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/README.md +4 -4
- package/dest/client.d.ts +1 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +0 -2
- package/dest/private/acvm_wasm.d.ts +1 -1
- package/dest/private/acvm_wasm.d.ts.map +1 -1
- package/dest/private/acvm_wasm.js +3 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts +36 -23
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +65 -69
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +7 -19
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.js +38 -42
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.js +11 -14
- package/dest/public/avm/avm_gas.js +3 -3
- package/dest/public/avm/avm_simulator.js +1 -1
- package/dest/public/avm/calldata.d.ts +1 -1
- package/dest/public/avm/calldata.d.ts.map +1 -1
- package/dest/public/avm/calldata.js +3 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +18 -3
- package/dest/public/avm/fixtures/utils.d.ts +1 -1
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
- package/dest/public/avm/fixtures/utils.js +4 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts +2 -2
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +3 -4
- package/dest/public/avm/opcodes/contract.d.ts +3 -2
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +5 -1
- package/dest/public/avm/opcodes/ec_add.d.ts +2 -4
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +13 -27
- package/dest/public/avm/serialization/bytecode_serialization.js +3 -3
- package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +1 -1
- package/dest/public/contracts_db_checkpoint.d.ts +2 -2
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
- package/dest/public/contracts_db_checkpoint.js +1 -1
- package/dest/public/fixtures/amm_test.js +4 -4
- package/dest/public/fixtures/bulk_test.d.ts +1 -1
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
- package/dest/public/fixtures/bulk_test.js +33 -6
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.js +2 -2
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +8 -1
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +91 -2
- package/dest/public/fixtures/opcode_spammer.d.ts +1 -1
- package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
- package/dest/public/fixtures/opcode_spammer.js +8 -16
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +6 -5
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +38 -9
- package/dest/public/fixtures/token_test.js +3 -3
- package/dest/public/fixtures/utils.d.ts +2 -2
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +21 -20
- package/dest/public/hinting_db_sources.d.ts +5 -5
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +8 -7
- package/dest/public/public_db_sources.d.ts +6 -3
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +16 -10
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +5 -5
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +5 -5
- package/dest/public/public_processor/public_processor.d.ts +8 -5
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +121 -67
- package/dest/public/public_processor/public_processor_metrics.d.ts +4 -1
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +8 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +5 -4
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +2 -3
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +2 -2
- package/dest/public/public_tx_simulator/factories.d.ts +2 -2
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/factories.js +2 -2
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +7 -3
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +8 -10
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +6 -2
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +14 -9
- package/dest/public/state_manager/state_manager.js +1 -1
- package/dest/public/test_executor_metrics.d.ts +6 -1
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +22 -0
- package/package.json +16 -16
- package/src/client.ts +0 -2
- package/src/private/acvm_wasm.ts +4 -1
- package/src/private/circuit_recording/circuit_recorder.ts +84 -78
- package/src/private/circuit_recording/file_circuit_recorder.ts +38 -48
- package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
- package/src/public/avm/avm_gas.ts +2 -2
- package/src/public/avm/avm_simulator.ts +1 -1
- package/src/public/avm/calldata.ts +3 -2
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +23 -3
- package/src/public/avm/fixtures/utils.ts +4 -1
- package/src/public/avm/opcodes/accrued_substate.ts +3 -4
- package/src/public/avm/opcodes/contract.ts +5 -1
- package/src/public/avm/opcodes/ec_add.ts +12 -31
- package/src/public/avm/opcodes/external_calls.ts +1 -1
- package/src/public/avm/serialization/bytecode_serialization.ts +2 -2
- package/src/public/avm/serialization/instruction_serialization.ts +1 -1
- package/src/public/contracts_db_checkpoint.ts +1 -1
- package/src/public/fixtures/amm_test.ts +4 -4
- package/src/public/fixtures/bulk_test.ts +31 -6
- package/src/public/fixtures/custom_bytecode_tester.ts +2 -2
- package/src/public/fixtures/custom_bytecode_tests.ts +209 -2
- package/src/public/fixtures/opcode_spammer.ts +10 -18
- package/src/public/fixtures/public_tx_simulation_tester.ts +45 -5
- package/src/public/fixtures/token_test.ts +3 -3
- package/src/public/fixtures/utils.ts +23 -24
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +1 -1
- package/src/public/hinting_db_sources.ts +10 -7
- package/src/public/public_db_sources.ts +21 -14
- package/src/public/public_processor/guarded_merkle_tree.ts +6 -6
- package/src/public/public_processor/public_processor.ts +158 -88
- package/src/public/public_processor/public_processor_metrics.ts +12 -0
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +5 -4
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +2 -3
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +2 -2
- package/src/public/public_tx_simulator/factories.ts +2 -1
- package/src/public/public_tx_simulator/public_tx_context.ts +8 -10
- package/src/public/public_tx_simulator/public_tx_simulator.ts +14 -10
- package/src/public/state_manager/state_manager.ts +1 -1
- package/src/public/test_executor_metrics.ts +24 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PUBLIC_TX_L2_GAS_OVERHEAD, TX_DA_GAS_OVERHEAD } from '@aztec/constants';
|
|
2
2
|
import { asyncMap } from '@aztec/foundation/async-map';
|
|
3
3
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -27,6 +27,8 @@ import { SimpleContractDataSource } from './simple_contract_data_source.js';
|
|
|
27
27
|
import { type TestPrivateInsertions, createTxForPublicCalls } from './utils.js';
|
|
28
28
|
|
|
29
29
|
const DEFAULT_GAS_FEES = new GasFees(2, 3);
|
|
30
|
+
const TEARDOWN_DA_GAS_LIMIT = 98_304;
|
|
31
|
+
const TEARDOWN_L2_GAS_LIMIT = 817_500;
|
|
30
32
|
|
|
31
33
|
export type TestEnqueuedCall = {
|
|
32
34
|
sender?: AztecAddress;
|
|
@@ -112,6 +114,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
112
114
|
feePayer: AztecAddress = sender,
|
|
113
115
|
/* need some unique first nullifier for note-nonce computations */
|
|
114
116
|
privateInsertions: TestPrivateInsertions = { nonRevertible: { nullifiers: [new Fr(420000 + this.txCount)] } },
|
|
117
|
+
gasLimits?: Gas,
|
|
115
118
|
): Promise<Tx> {
|
|
116
119
|
const setupCallRequests = await asyncMap(setupCalls, call =>
|
|
117
120
|
this.#createPubicCallRequestForCall(call, call.sender ?? sender),
|
|
@@ -131,9 +134,10 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
131
134
|
teardownCallRequest,
|
|
132
135
|
feePayer,
|
|
133
136
|
/*gasUsedByPrivate*/ teardownCall
|
|
134
|
-
? new Gas(
|
|
135
|
-
: Gas
|
|
137
|
+
? new Gas(TEARDOWN_DA_GAS_LIMIT + TX_DA_GAS_OVERHEAD, TEARDOWN_L2_GAS_LIMIT + PUBLIC_TX_L2_GAS_OVERHEAD)
|
|
138
|
+
: new Gas(TX_DA_GAS_OVERHEAD, PUBLIC_TX_L2_GAS_OVERHEAD),
|
|
136
139
|
defaultGlobals(),
|
|
140
|
+
gasLimits,
|
|
137
141
|
);
|
|
138
142
|
}
|
|
139
143
|
|
|
@@ -146,8 +150,9 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
146
150
|
/* need some unique first nullifier for note-nonce computations */
|
|
147
151
|
privateInsertions?: TestPrivateInsertions,
|
|
148
152
|
txLabel: string = 'unlabeledTx',
|
|
153
|
+
gasLimits?: Gas,
|
|
149
154
|
): Promise<PublicTxResult> {
|
|
150
|
-
const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions);
|
|
155
|
+
const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions, gasLimits);
|
|
151
156
|
|
|
152
157
|
await this.setFeePayerBalance(feePayer);
|
|
153
158
|
|
|
@@ -161,6 +166,8 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
161
166
|
}
|
|
162
167
|
const avmResult = await this.simulator.simulate(tx, fullTxLabel);
|
|
163
168
|
|
|
169
|
+
await this.#recordBytecodeSizes(fullTxLabel, [...setupCalls, ...appCalls, ...(teardownCall ? [teardownCall] : [])]);
|
|
170
|
+
|
|
164
171
|
// Something like this is often useful for debugging:
|
|
165
172
|
//if (avmResult.revertReason) {
|
|
166
173
|
// // resolve / enrich revert reason
|
|
@@ -190,8 +197,18 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
190
197
|
teardownCall?: TestEnqueuedCall,
|
|
191
198
|
feePayer?: AztecAddress,
|
|
192
199
|
privateInsertions?: TestPrivateInsertions,
|
|
200
|
+
gasLimits?: Gas,
|
|
193
201
|
): Promise<PublicTxResult> {
|
|
194
|
-
return await this.simulateTx(
|
|
202
|
+
return await this.simulateTx(
|
|
203
|
+
sender,
|
|
204
|
+
setupCalls,
|
|
205
|
+
appCalls,
|
|
206
|
+
teardownCall,
|
|
207
|
+
feePayer,
|
|
208
|
+
privateInsertions,
|
|
209
|
+
txLabel,
|
|
210
|
+
gasLimits,
|
|
211
|
+
);
|
|
195
212
|
}
|
|
196
213
|
|
|
197
214
|
/**
|
|
@@ -209,6 +226,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
209
226
|
teardownCall?: TestEnqueuedCall,
|
|
210
227
|
feePayer?: AztecAddress,
|
|
211
228
|
privateInsertions?: TestPrivateInsertions,
|
|
229
|
+
gasLimits?: Gas,
|
|
212
230
|
): Promise<PublicTxResult> {
|
|
213
231
|
return await this.simulateTxWithLabel(
|
|
214
232
|
txLabel,
|
|
@@ -218,6 +236,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
218
236
|
teardownCall,
|
|
219
237
|
feePayer,
|
|
220
238
|
privateInsertions,
|
|
239
|
+
gasLimits,
|
|
221
240
|
);
|
|
222
241
|
}
|
|
223
242
|
|
|
@@ -277,6 +296,27 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
277
296
|
|
|
278
297
|
return new PublicCallRequestWithCalldata(request, calldata);
|
|
279
298
|
}
|
|
299
|
+
|
|
300
|
+
// WARNING: Deduplicates by artifact name, so two different artifacts with the same name
|
|
301
|
+
// in a single tx would only record the first one's bytecode size.
|
|
302
|
+
async #recordBytecodeSizes(txLabel: string, calls: TestEnqueuedCall[]) {
|
|
303
|
+
const seenArtifactNames = new Set<string>();
|
|
304
|
+
for (const call of calls) {
|
|
305
|
+
const artifact = await this.contractDataSource.getContractArtifact(call.address);
|
|
306
|
+
if (!artifact || seenArtifactNames.has(artifact.name)) {
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
seenArtifactNames.add(artifact.name);
|
|
310
|
+
const instance = await this.contractDataSource.getContract(call.address);
|
|
311
|
+
if (!instance) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
const contractClass = await this.contractDataSource.getContractClass(instance.currentContractClassId);
|
|
315
|
+
if (contractClass) {
|
|
316
|
+
this.metrics.recordBytecodeSize(txLabel, artifact.name, contractClass.packedBytecode.length);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
280
320
|
}
|
|
281
321
|
|
|
282
322
|
export function defaultGlobals() {
|
|
@@ -21,9 +21,9 @@ export async function tokenTest(
|
|
|
21
21
|
) {
|
|
22
22
|
const timer = new Timer();
|
|
23
23
|
|
|
24
|
-
const admin = AztecAddress.
|
|
25
|
-
const sender = AztecAddress.
|
|
26
|
-
const receiver = AztecAddress.
|
|
24
|
+
const admin = AztecAddress.fromNumberUnsafe(42);
|
|
25
|
+
const sender = AztecAddress.fromNumberUnsafe(111);
|
|
26
|
+
const receiver = AztecAddress.fromNumberUnsafe(222);
|
|
27
27
|
|
|
28
28
|
const token = await setUpToken(tester, tokenArtifact, admin, expectToBeTrue);
|
|
29
29
|
|
|
@@ -2,10 +2,8 @@ import {
|
|
|
2
2
|
CONTRACT_CLASS_PUBLISHED_MAGIC_VALUE,
|
|
3
3
|
CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS,
|
|
4
4
|
CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
DEFAULT_TEARDOWN_DA_GAS_LIMIT,
|
|
8
|
-
DEFAULT_TEARDOWN_L2_GAS_LIMIT,
|
|
5
|
+
MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT,
|
|
6
|
+
MAX_PROCESSABLE_L2_GAS,
|
|
9
7
|
PRIVATE_LOG_SIZE_IN_FIELDS,
|
|
10
8
|
} from '@aztec/constants';
|
|
11
9
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
@@ -38,6 +36,9 @@ import {
|
|
|
38
36
|
|
|
39
37
|
import { strict as assert } from 'assert';
|
|
40
38
|
|
|
39
|
+
const TEARDOWN_DA_GAS_LIMIT = 98_304;
|
|
40
|
+
const TEARDOWN_L2_GAS_LIMIT = 817_500;
|
|
41
|
+
|
|
41
42
|
export type TestPrivateInsertions = {
|
|
42
43
|
revertible?: {
|
|
43
44
|
nullifiers?: Fr[];
|
|
@@ -62,13 +63,14 @@ export async function createTxForPublicCalls(
|
|
|
62
63
|
feePayer = AztecAddress.zero(),
|
|
63
64
|
gasUsedByPrivate: Gas = Gas.empty(),
|
|
64
65
|
globals: GlobalVariables = GlobalVariables.empty(),
|
|
66
|
+
gasLimits?: Gas,
|
|
65
67
|
): Promise<Tx> {
|
|
66
68
|
assert(
|
|
67
69
|
setupCallRequests.length > 0 || appCallRequests.length > 0 || teardownCallRequest !== undefined,
|
|
68
70
|
"Can't create public tx with no enqueued calls",
|
|
69
71
|
);
|
|
70
72
|
// use max limits
|
|
71
|
-
|
|
73
|
+
gasLimits = gasLimits ?? new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
|
|
72
74
|
|
|
73
75
|
const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
|
|
74
76
|
|
|
@@ -127,20 +129,18 @@ export async function createTxForPublicCalls(
|
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
const maxFeesPerGas = feePayer.isZero() ? GasFees.empty() : new GasFees(10, 10);
|
|
130
|
-
const teardownGasLimits = teardownCallRequest
|
|
131
|
-
? new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT)
|
|
132
|
-
: Gas.empty();
|
|
132
|
+
const teardownGasLimits = teardownCallRequest ? new Gas(TEARDOWN_DA_GAS_LIMIT, TEARDOWN_L2_GAS_LIMIT) : Gas.empty();
|
|
133
133
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, maxFeesPerGas, GasFees.empty());
|
|
134
134
|
const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
|
|
135
135
|
const header = BlockHeader.empty({ globalVariables: globals });
|
|
136
136
|
const constantData = new TxConstantData(header, txContext, Fr.zero(), Fr.zero());
|
|
137
|
-
const
|
|
137
|
+
const expirationTimestamp = 0n; // Not used in the simulator.
|
|
138
138
|
|
|
139
139
|
const txData = new PrivateKernelTailCircuitPublicInputs(
|
|
140
140
|
constantData,
|
|
141
141
|
/*gasUsed=*/ gasUsedByPrivate,
|
|
142
142
|
feePayer,
|
|
143
|
-
|
|
143
|
+
expirationTimestamp,
|
|
144
144
|
forPublic,
|
|
145
145
|
);
|
|
146
146
|
|
|
@@ -163,7 +163,7 @@ export async function createTxForPrivateOnly(
|
|
|
163
163
|
gasUsedByPrivate: Gas = new Gas(10, 10),
|
|
164
164
|
): Promise<Tx> {
|
|
165
165
|
// use max limits
|
|
166
|
-
const gasLimits = new Gas(
|
|
166
|
+
const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
|
|
167
167
|
|
|
168
168
|
const forRollup = PartialPrivateTailPublicInputsForRollup.empty();
|
|
169
169
|
|
|
@@ -171,13 +171,13 @@ export async function createTxForPrivateOnly(
|
|
|
171
171
|
const gasSettings = new GasSettings(gasLimits, Gas.empty(), maxFeesPerGas, GasFees.empty());
|
|
172
172
|
const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
|
|
173
173
|
const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
|
|
174
|
-
const
|
|
174
|
+
const expirationTimestamp = 0n; // Not used in the simulator.
|
|
175
175
|
|
|
176
176
|
const txData = new PrivateKernelTailCircuitPublicInputs(
|
|
177
177
|
constantData,
|
|
178
178
|
/*gasUsed=*/ gasUsedByPrivate,
|
|
179
179
|
feePayer,
|
|
180
|
-
|
|
180
|
+
expirationTimestamp,
|
|
181
181
|
/*forPublic=*/ undefined,
|
|
182
182
|
forRollup,
|
|
183
183
|
);
|
|
@@ -228,17 +228,15 @@ export async function addNewContractInstanceToTx(
|
|
|
228
228
|
contractInstance: ContractInstanceWithAddress,
|
|
229
229
|
skipNullifierInsertion = false,
|
|
230
230
|
) {
|
|
231
|
-
//
|
|
232
|
-
// is not broadcast in such private logs
|
|
231
|
+
// Only ivpk_m is broadcast as a point (x, y); the other five keys are hashes.
|
|
233
232
|
const publicKeysAsFields = [
|
|
234
|
-
contractInstance.publicKeys.
|
|
235
|
-
contractInstance.publicKeys.
|
|
236
|
-
contractInstance.publicKeys.
|
|
237
|
-
contractInstance.publicKeys.
|
|
238
|
-
contractInstance.publicKeys.
|
|
239
|
-
contractInstance.publicKeys.
|
|
240
|
-
contractInstance.publicKeys.
|
|
241
|
-
contractInstance.publicKeys.masterTaggingPublicKey.y,
|
|
233
|
+
contractInstance.publicKeys.npkMHash,
|
|
234
|
+
contractInstance.publicKeys.ivpkM.x,
|
|
235
|
+
contractInstance.publicKeys.ivpkM.y,
|
|
236
|
+
contractInstance.publicKeys.ovpkMHash,
|
|
237
|
+
contractInstance.publicKeys.tpkMHash,
|
|
238
|
+
contractInstance.publicKeys.mspkMHash,
|
|
239
|
+
contractInstance.publicKeys.fbpkMHash,
|
|
242
240
|
];
|
|
243
241
|
const logFields = [
|
|
244
242
|
CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG,
|
|
@@ -247,6 +245,7 @@ export async function addNewContractInstanceToTx(
|
|
|
247
245
|
new Fr(contractInstance.salt),
|
|
248
246
|
contractInstance.currentContractClassId,
|
|
249
247
|
contractInstance.initializationHash,
|
|
248
|
+
contractInstance.immutablesHash,
|
|
250
249
|
...publicKeysAsFields,
|
|
251
250
|
contractInstance.deployer.toField(),
|
|
252
251
|
];
|
|
@@ -256,7 +255,7 @@ export async function addNewContractInstanceToTx(
|
|
|
256
255
|
);
|
|
257
256
|
|
|
258
257
|
const contractAddressNullifier = await siloNullifier(
|
|
259
|
-
AztecAddress.
|
|
258
|
+
AztecAddress.fromNumberUnsafe(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS),
|
|
260
259
|
contractInstance.address.toField(),
|
|
261
260
|
);
|
|
262
261
|
|
|
@@ -146,7 +146,7 @@ async function createTxFromHint(cppTx: AvmTxHint): Promise<Tx> {
|
|
|
146
146
|
constants,
|
|
147
147
|
cppTx.gasUsedByPrivate,
|
|
148
148
|
cppTx.feePayer,
|
|
149
|
-
0n, //
|
|
149
|
+
0n, // expirationTimestamp
|
|
150
150
|
forPublic,
|
|
151
151
|
undefined, // forRollup - not needed for public simulation
|
|
152
152
|
);
|
|
@@ -83,6 +83,7 @@ export class HintingPublicContractsDB implements PublicContractsDBInterface {
|
|
|
83
83
|
instance.currentContractClassId,
|
|
84
84
|
instance.originalContractClassId,
|
|
85
85
|
instance.initializationHash,
|
|
86
|
+
instance.immutablesHash,
|
|
86
87
|
instance.publicKeys,
|
|
87
88
|
),
|
|
88
89
|
);
|
|
@@ -410,12 +411,12 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
410
411
|
}
|
|
411
412
|
}
|
|
412
413
|
|
|
413
|
-
public async createCheckpoint(): Promise<
|
|
414
|
+
public async createCheckpoint(): Promise<number> {
|
|
414
415
|
const actionCounter = this.checkpointActionCounter++;
|
|
415
416
|
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
416
417
|
const treesStateHash = await this.getTreesStateHash();
|
|
417
418
|
|
|
418
|
-
await this.db.createCheckpoint();
|
|
419
|
+
const depth = await this.db.createCheckpoint();
|
|
419
420
|
this.checkpointStack.push(this.nextCheckpointId++);
|
|
420
421
|
const newCheckpointId = this.getCurrentCheckpointId();
|
|
421
422
|
|
|
@@ -424,14 +425,16 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
424
425
|
HintingMerkleWriteOperations.log.trace(
|
|
425
426
|
`[createCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
|
|
426
427
|
);
|
|
428
|
+
|
|
429
|
+
return depth;
|
|
427
430
|
}
|
|
428
431
|
|
|
429
|
-
public
|
|
430
|
-
throw new Error('
|
|
432
|
+
public commitAllCheckpointsTo(_depth: number): Promise<void> {
|
|
433
|
+
throw new Error('commitAllCheckpointsTo is not supported in HintingMerkleWriteOperations.');
|
|
431
434
|
}
|
|
432
435
|
|
|
433
|
-
public
|
|
434
|
-
throw new Error('
|
|
436
|
+
public revertAllCheckpointsTo(_depth: number): Promise<void> {
|
|
437
|
+
throw new Error('revertAllCheckpointsTo is not supported in HintingMerkleWriteOperations.');
|
|
435
438
|
}
|
|
436
439
|
|
|
437
440
|
public async commitCheckpoint(): Promise<void> {
|
|
@@ -572,7 +575,7 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
572
575
|
return await this.db.close();
|
|
573
576
|
}
|
|
574
577
|
|
|
575
|
-
async [Symbol.
|
|
578
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
576
579
|
await this.close();
|
|
577
580
|
}
|
|
578
581
|
|
|
@@ -55,10 +55,11 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
55
55
|
this.log = createLogger('simulator:contracts-data-source', bindings);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
/** Parses raw log data from the C++/NAPI bridge and inserts the resulting contracts into the current checkpoint. */
|
|
59
|
+
public addContractsFromLogs(contractDeploymentData: ContractDeploymentData): void {
|
|
59
60
|
const currentState = this.getCurrentState();
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
this.addContractClassesFromEvents(
|
|
62
63
|
ContractClassPublishedEvent.extractContractClassEvents(contractDeploymentData.getContractClassLogs()),
|
|
63
64
|
currentState,
|
|
64
65
|
);
|
|
@@ -69,10 +70,18 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
69
70
|
);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
public
|
|
73
|
+
public addNewContracts(tx: Tx): void {
|
|
73
74
|
const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
this.addContractsFromLogs(contractDeploymentData.getNonRevertibleContractDeploymentData());
|
|
76
|
+
this.addContractsFromLogs(contractDeploymentData.getRevertibleContractDeploymentData());
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Inserts typed contract instances directly into the current checkpoint. */
|
|
80
|
+
public addContracts(contractInstances?: ContractInstanceWithAddress[]): void {
|
|
81
|
+
const currentState = this.getCurrentState();
|
|
82
|
+
for (const instance of contractInstances ?? []) {
|
|
83
|
+
currentState.addInstance(instance.address, instance);
|
|
84
|
+
}
|
|
76
85
|
}
|
|
77
86
|
|
|
78
87
|
/**
|
|
@@ -81,7 +90,7 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
81
90
|
*/
|
|
82
91
|
public createCheckpoint(): void {
|
|
83
92
|
const currentState = this.getCurrentState();
|
|
84
|
-
const newState = currentState.
|
|
93
|
+
const newState = currentState.fork();
|
|
85
94
|
this.contractStateStack.push(newState);
|
|
86
95
|
}
|
|
87
96
|
|
|
@@ -174,17 +183,15 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
174
183
|
return await this.dataSource.getDebugFunctionName(address, selector);
|
|
175
184
|
}
|
|
176
185
|
|
|
177
|
-
private
|
|
186
|
+
private addContractClassesFromEvents(
|
|
178
187
|
contractClassEvents: ContractClassPublishedEvent[],
|
|
179
188
|
state: ContractsDbCheckpoint,
|
|
180
189
|
) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}),
|
|
187
|
-
);
|
|
190
|
+
for (const event of contractClassEvents) {
|
|
191
|
+
this.log.debug(`Adding class ${event.contractClassId.toString()} to contract state`);
|
|
192
|
+
const contractClass = event.toContractClassPublic();
|
|
193
|
+
state.addClass(event.contractClassId, contractClass);
|
|
194
|
+
}
|
|
188
195
|
}
|
|
189
196
|
|
|
190
197
|
private addContractInstancesFromEvents(
|
|
@@ -82,7 +82,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
|
|
|
82
82
|
return this.guardAndPush(() => this.target.close());
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
async [Symbol.
|
|
85
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
86
86
|
await this.close();
|
|
87
87
|
}
|
|
88
88
|
getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo> {
|
|
@@ -134,7 +134,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
|
|
|
134
134
|
): Promise<(BlockNumber | undefined)[]> {
|
|
135
135
|
return this.guardAndPush(() => this.target.getBlockNumbersForLeafIndices(treeId, leafIndices));
|
|
136
136
|
}
|
|
137
|
-
createCheckpoint(): Promise<
|
|
137
|
+
createCheckpoint(): Promise<number> {
|
|
138
138
|
return this.guardAndPush(() => this.target.createCheckpoint());
|
|
139
139
|
}
|
|
140
140
|
commitCheckpoint(): Promise<void> {
|
|
@@ -143,11 +143,11 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
|
|
|
143
143
|
revertCheckpoint(): Promise<void> {
|
|
144
144
|
return this.guardAndPush(() => this.target.revertCheckpoint());
|
|
145
145
|
}
|
|
146
|
-
|
|
147
|
-
return this.guardAndPush(() => this.target.
|
|
146
|
+
commitAllCheckpointsTo(depth: number): Promise<void> {
|
|
147
|
+
return this.guardAndPush(() => this.target.commitAllCheckpointsTo(depth));
|
|
148
148
|
}
|
|
149
|
-
|
|
150
|
-
return this.guardAndPush(() => this.target.
|
|
149
|
+
revertAllCheckpointsTo(depth: number): Promise<void> {
|
|
150
|
+
return this.guardAndPush(() => this.target.revertAllCheckpointsTo(depth));
|
|
151
151
|
}
|
|
152
152
|
findSiblingPaths<ID extends MerkleTreeId>(
|
|
153
153
|
treeId: ID,
|