@aztec/simulator 0.42.0 → 0.43.0
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/acvm/oracle/oracle.d.ts +3 -2
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +17 -6
- package/dest/acvm/oracle/typed_oracle.d.ts +3 -2
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +8 -5
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +3 -1
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +2 -4
- package/dest/avm/fixtures/index.d.ts +4 -1
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +11 -6
- package/dest/avm/journal/journal.d.ts +3 -3
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +18 -13
- package/dest/avm/journal/trace.d.ts +3 -3
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace.js +7 -6
- package/dest/avm/journal/trace_types.d.ts +4 -0
- package/dest/avm/journal/trace_types.d.ts.map +1 -1
- package/dest/avm/journal/trace_types.js +1 -5
- package/dest/avm/opcodes/accrued_substate.d.ts +2 -2
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +36 -21
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +12 -9
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +11 -8
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +7 -5
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +20 -24
- package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/avm/opcodes/control_flow.js +4 -2
- package/dest/avm/opcodes/ec_add.d.ts +19 -0
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -0
- package/dest/avm/opcodes/ec_add.js +78 -0
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +8 -3
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +10 -2
- package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction_impl.js +4 -2
- package/dest/avm/opcodes/memory.d.ts +1 -1
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +14 -12
- package/dest/avm/opcodes/multi_scalar_mul.d.ts +16 -0
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -0
- package/dest/avm/opcodes/multi_scalar_mul.js +95 -0
- package/dest/avm/opcodes/storage.d.ts +1 -1
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +11 -8
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +5 -1
- package/dest/avm/serialization/instruction_serialization.d.ts +3 -1
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +4 -2
- package/dest/client/client_execution_context.d.ts +15 -3
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +31 -17
- package/dest/client/simulator.d.ts +2 -1
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +17 -9
- package/dest/public/abstract_phase_manager.d.ts +10 -11
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +75 -53
- package/dest/public/app_logic_phase_manager.d.ts +3 -3
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/public/app_logic_phase_manager.js +3 -3
- package/dest/public/db_interfaces.d.ts +1 -0
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/execution.d.ts +1 -15
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -51
- package/dest/public/executor.d.ts +1 -1
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +15 -8
- package/dest/public/hints_builder.d.ts +1 -1
- package/dest/public/index.d.ts +6 -6
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +7 -7
- package/dest/public/phase_manager_factory.d.ts +3 -3
- package/dest/public/phase_manager_factory.d.ts.map +1 -1
- package/dest/public/phase_manager_factory.js +5 -5
- package/dest/public/public_db_sources.d.ts +3 -1
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +54 -8
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +4 -5
- package/dest/public/setup_phase_manager.d.ts +3 -3
- package/dest/public/setup_phase_manager.d.ts.map +1 -1
- package/dest/public/setup_phase_manager.js +3 -3
- package/dest/public/tail_phase_manager.d.ts +3 -3
- package/dest/public/tail_phase_manager.d.ts.map +1 -1
- package/dest/public/tail_phase_manager.js +3 -3
- package/dest/public/teardown_phase_manager.d.ts +3 -3
- package/dest/public/teardown_phase_manager.d.ts.map +1 -1
- package/dest/public/teardown_phase_manager.js +3 -3
- package/dest/public/transitional_adaptors.d.ts +1 -1
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +9 -3
- package/package.json +8 -8
- package/src/acvm/oracle/oracle.ts +35 -6
- package/src/acvm/oracle/typed_oracle.ts +20 -4
- package/src/avm/avm_gas.ts +2 -0
- package/src/avm/avm_memory_types.ts +1 -3
- package/src/avm/fixtures/index.ts +12 -8
- package/src/avm/journal/journal.ts +26 -21
- package/src/avm/journal/trace.ts +8 -11
- package/src/avm/journal/trace_types.ts +3 -0
- package/src/avm/opcodes/accrued_substate.ts +53 -20
- package/src/avm/opcodes/arithmetic.ts +17 -8
- package/src/avm/opcodes/bitwise.ts +13 -8
- package/src/avm/opcodes/comparators.ts +9 -4
- package/src/avm/opcodes/contract.ts +22 -26
- package/src/avm/opcodes/control_flow.ts +3 -1
- package/src/avm/opcodes/ec_add.ts +92 -0
- package/src/avm/opcodes/external_calls.ts +8 -2
- package/src/avm/opcodes/hashing.ts +11 -1
- package/src/avm/opcodes/instruction_impl.ts +4 -1
- package/src/avm/opcodes/memory.ts +18 -11
- package/src/avm/opcodes/multi_scalar_mul.ts +114 -0
- package/src/avm/opcodes/storage.ts +10 -10
- package/src/avm/serialization/bytecode_serialization.ts +4 -0
- package/src/avm/serialization/instruction_serialization.ts +2 -0
- package/src/client/client_execution_context.ts +46 -18
- package/src/client/simulator.ts +18 -8
- package/src/public/abstract_phase_manager.ts +77 -59
- package/src/public/app_logic_phase_manager.ts +2 -2
- package/src/public/db_interfaces.ts +2 -0
- package/src/public/execution.ts +0 -69
- package/src/public/executor.ts +17 -8
- package/src/public/index.ts +6 -12
- package/src/public/phase_manager_factory.ts +6 -6
- package/src/public/public_db_sources.ts +62 -7
- package/src/public/public_processor.ts +4 -7
- package/src/public/setup_phase_manager.ts +2 -2
- package/src/public/tail_phase_manager.ts +2 -2
- package/src/public/teardown_phase_manager.ts +2 -2
- package/src/public/transitional_adaptors.ts +42 -2
- package/dest/public/utils.d.ts +0 -8
- package/dest/public/utils.d.ts.map +0 -1
- package/dest/public/utils.js +0 -38
- package/src/public/utils.ts +0 -39
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { MerkleTreeId, NullifierMembershipWitness, type Tx } from '@aztec/circuit-types';
|
|
2
|
+
import { type PublicDBAccessStats } from '@aztec/circuit-types/stats';
|
|
2
3
|
import {
|
|
3
4
|
type AztecAddress,
|
|
4
5
|
ContractClassRegisteredEvent,
|
|
5
6
|
ContractInstanceDeployedEvent,
|
|
6
7
|
Fr,
|
|
7
|
-
|
|
8
|
+
FunctionSelector,
|
|
8
9
|
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
9
10
|
type NULLIFIER_TREE_HEIGHT,
|
|
10
11
|
type NullifierLeafPreimage,
|
|
@@ -12,7 +13,8 @@ import {
|
|
|
12
13
|
} from '@aztec/circuits.js';
|
|
13
14
|
import { computeL1ToL2MessageNullifier, computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
|
|
14
15
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
15
|
-
import {
|
|
16
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
17
|
+
import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer';
|
|
16
18
|
import {
|
|
17
19
|
type CommitmentsDB,
|
|
18
20
|
MessageLoadOracleInputs,
|
|
@@ -45,7 +47,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
|
45
47
|
public addNewContracts(tx: Tx): Promise<void> {
|
|
46
48
|
// Extract contract class and instance data from logs and add to cache for this block
|
|
47
49
|
const logs = tx.unencryptedLogs.unrollLogs();
|
|
48
|
-
ContractClassRegisteredEvent.fromLogs(logs,
|
|
50
|
+
ContractClassRegisteredEvent.fromLogs(logs, ClassRegistererAddress).forEach(e => {
|
|
49
51
|
this.log.debug(`Adding class ${e.contractClassId.toString()} to public execution contract cache`);
|
|
50
52
|
this.classCache.set(e.contractClassId.toString(), e.toContractClassPublic());
|
|
51
53
|
});
|
|
@@ -68,7 +70,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
|
68
70
|
// Let's say we have two txs adding the same contract on the same block. If the 2nd one reverts,
|
|
69
71
|
// wouldn't that accidentally remove the contract added on the first one?
|
|
70
72
|
const logs = tx.unencryptedLogs.unrollLogs();
|
|
71
|
-
ContractClassRegisteredEvent.fromLogs(logs,
|
|
73
|
+
ContractClassRegisteredEvent.fromLogs(logs, ClassRegistererAddress).forEach(e =>
|
|
72
74
|
this.classCache.delete(e.contractClassId.toString()),
|
|
73
75
|
);
|
|
74
76
|
ContractInstanceDeployedEvent.fromLogs(logs).forEach(e => this.instanceCache.delete(e.address.toString()));
|
|
@@ -94,6 +96,22 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
|
94
96
|
}
|
|
95
97
|
return contractClass.publicFunctions.find(f => f.selector.equals(selector))?.bytecode;
|
|
96
98
|
}
|
|
99
|
+
|
|
100
|
+
public async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
101
|
+
const artifact = await this.db.getContractArtifact(address);
|
|
102
|
+
if (!artifact) {
|
|
103
|
+
return Promise.resolve(undefined);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const f = artifact.functions.find(f =>
|
|
107
|
+
FunctionSelector.fromNameAndParameters(f.name, f.parameters).equals(selector),
|
|
108
|
+
);
|
|
109
|
+
if (!f) {
|
|
110
|
+
return Promise.resolve(undefined);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return Promise.resolve(`${artifact.name}:${f.name}`);
|
|
114
|
+
}
|
|
97
115
|
}
|
|
98
116
|
|
|
99
117
|
/**
|
|
@@ -196,11 +214,14 @@ export class WorldStatePublicDB implements PublicStateDB {
|
|
|
196
214
|
* Implements WorldState db using a world state database.
|
|
197
215
|
*/
|
|
198
216
|
export class WorldStateDB implements CommitmentsDB {
|
|
217
|
+
private log = createDebugLogger('aztec:sequencer:world-state-db');
|
|
218
|
+
|
|
199
219
|
constructor(private db: MerkleTreeOperations) {}
|
|
200
220
|
|
|
201
221
|
public async getNullifierMembershipWitnessAtLatestBlock(
|
|
202
222
|
nullifier: Fr,
|
|
203
223
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
224
|
+
const timer = new Timer();
|
|
204
225
|
const index = await this.db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer());
|
|
205
226
|
if (!index) {
|
|
206
227
|
return undefined;
|
|
@@ -218,6 +239,12 @@ export class WorldStateDB implements CommitmentsDB {
|
|
|
218
239
|
return undefined;
|
|
219
240
|
}
|
|
220
241
|
|
|
242
|
+
this.log.debug(`[DB] Fetched nullifier membership`, {
|
|
243
|
+
eventName: 'public-db-access',
|
|
244
|
+
duration: timer.ms(),
|
|
245
|
+
operation: 'get-nullifier-membership-witness-at-latest-block',
|
|
246
|
+
} satisfies PublicDBAccessStats);
|
|
247
|
+
|
|
221
248
|
return new NullifierMembershipWitness(BigInt(index), leafPreimage as NullifierLeafPreimage, siblingPath);
|
|
222
249
|
}
|
|
223
250
|
|
|
@@ -232,6 +259,7 @@ export class WorldStateDB implements CommitmentsDB {
|
|
|
232
259
|
|
|
233
260
|
// We iterate over messages until we find one whose nullifier is not in the nullifier tree --> we need to check
|
|
234
261
|
// for nullifiers because messages can have duplicates.
|
|
262
|
+
const timer = new Timer();
|
|
235
263
|
do {
|
|
236
264
|
messageIndex = (await this.db.findLeafIndexAfter(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, messageHash, startIndex))!;
|
|
237
265
|
if (messageIndex === undefined) {
|
|
@@ -249,18 +277,45 @@ export class WorldStateDB implements CommitmentsDB {
|
|
|
249
277
|
messageIndex,
|
|
250
278
|
);
|
|
251
279
|
|
|
280
|
+
this.log.debug(`[DB] Fetched L1 to L2 message membership`, {
|
|
281
|
+
eventName: 'public-db-access',
|
|
282
|
+
duration: timer.ms(),
|
|
283
|
+
operation: 'get-l1-to-l2-message-membership-witness',
|
|
284
|
+
} satisfies PublicDBAccessStats);
|
|
285
|
+
|
|
252
286
|
return new MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>(messageIndex, siblingPath);
|
|
253
287
|
}
|
|
254
288
|
|
|
255
289
|
public async getL1ToL2LeafValue(leafIndex: bigint): Promise<Fr | undefined> {
|
|
256
|
-
|
|
290
|
+
const timer = new Timer();
|
|
291
|
+
const leafValue = await this.db.getLeafValue(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, leafIndex);
|
|
292
|
+
this.log.debug(`[DB] Fetched L1 to L2 message leaf value`, {
|
|
293
|
+
eventName: 'public-db-access',
|
|
294
|
+
duration: timer.ms(),
|
|
295
|
+
operation: 'get-l1-to-l2-message-leaf-value',
|
|
296
|
+
} satisfies PublicDBAccessStats);
|
|
297
|
+
return leafValue;
|
|
257
298
|
}
|
|
258
299
|
|
|
259
300
|
public async getCommitmentIndex(commitment: Fr): Promise<bigint | undefined> {
|
|
260
|
-
|
|
301
|
+
const timer = new Timer();
|
|
302
|
+
const index = await this.db.findLeafIndex(MerkleTreeId.NOTE_HASH_TREE, commitment);
|
|
303
|
+
this.log.debug(`[DB] Fetched commitment index`, {
|
|
304
|
+
eventName: 'public-db-access',
|
|
305
|
+
duration: timer.ms(),
|
|
306
|
+
operation: 'get-commitment-index',
|
|
307
|
+
} satisfies PublicDBAccessStats);
|
|
308
|
+
return index;
|
|
261
309
|
}
|
|
262
310
|
|
|
263
311
|
public async getNullifierIndex(nullifier: Fr): Promise<bigint | undefined> {
|
|
264
|
-
|
|
312
|
+
const timer = new Timer();
|
|
313
|
+
const index = await this.db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer());
|
|
314
|
+
this.log.debug(`[DB] Fetched nullifier index`, {
|
|
315
|
+
eventName: 'public-db-access',
|
|
316
|
+
duration: timer.ms(),
|
|
317
|
+
operation: 'get-nullifier-index',
|
|
318
|
+
} satisfies PublicDBAccessStats);
|
|
319
|
+
return index;
|
|
265
320
|
}
|
|
266
321
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
type FailedTx,
|
|
4
4
|
NestedProcessReturnValues,
|
|
5
5
|
type ProcessedTx,
|
|
6
|
+
PublicKernelType,
|
|
6
7
|
type PublicProvingRequest,
|
|
7
8
|
type SimulationError,
|
|
8
9
|
Tx,
|
|
@@ -32,11 +33,7 @@ import {
|
|
|
32
33
|
import { type ContractDataSource } from '@aztec/types/contracts';
|
|
33
34
|
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
34
35
|
|
|
35
|
-
import {
|
|
36
|
-
type AbstractPhaseManager,
|
|
37
|
-
PublicKernelPhase,
|
|
38
|
-
publicKernelPhaseToKernelType,
|
|
39
|
-
} from './abstract_phase_manager.js';
|
|
36
|
+
import { type AbstractPhaseManager } from './abstract_phase_manager.js';
|
|
40
37
|
import { PhaseManagerFactory } from './phase_manager_factory.js';
|
|
41
38
|
import { ContractsDataSourcePublicDB, WorldStateDB, WorldStatePublicDB } from './public_db_sources.js';
|
|
42
39
|
import { RealPublicKernelCircuitSimulator } from './public_kernel.js';
|
|
@@ -231,8 +228,8 @@ export class PublicProcessor {
|
|
|
231
228
|
const gasUsed: ProcessedTx['gasUsed'] = {};
|
|
232
229
|
while (phase) {
|
|
233
230
|
const output = await phase.handle(tx, publicKernelPublicInput);
|
|
234
|
-
gasUsed[
|
|
235
|
-
if (phase.phase ===
|
|
231
|
+
gasUsed[phase.phase] = output.gasUsed;
|
|
232
|
+
if (phase.phase === PublicKernelType.APP_LOGIC) {
|
|
236
233
|
returnValues = output.returnValues;
|
|
237
234
|
}
|
|
238
235
|
publicProvingRequests.push(...output.publicProvingRequests);
|
|
@@ -3,7 +3,7 @@ import { type GlobalVariables, type Header, type PublicKernelCircuitPublicInputs
|
|
|
3
3
|
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
4
4
|
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
5
5
|
|
|
6
|
-
import { AbstractPhaseManager,
|
|
6
|
+
import { AbstractPhaseManager, makeAvmProvingRequest } from './abstract_phase_manager.js';
|
|
7
7
|
import { type ContractsDataSourcePublicDB } from './public_db_sources.js';
|
|
8
8
|
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
9
9
|
|
|
@@ -19,7 +19,7 @@ export class SetupPhaseManager extends AbstractPhaseManager {
|
|
|
19
19
|
historicalHeader: Header,
|
|
20
20
|
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
21
21
|
protected publicStateDB: PublicStateDB,
|
|
22
|
-
phase:
|
|
22
|
+
phase: PublicKernelType = PublicKernelType.SETUP,
|
|
23
23
|
) {
|
|
24
24
|
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
25
25
|
}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
14
14
|
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
15
15
|
|
|
16
|
-
import { AbstractPhaseManager
|
|
16
|
+
import { AbstractPhaseManager } from './abstract_phase_manager.js';
|
|
17
17
|
import { type ContractsDataSourcePublicDB } from './public_db_sources.js';
|
|
18
18
|
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
19
19
|
|
|
@@ -26,7 +26,7 @@ export class TailPhaseManager extends AbstractPhaseManager {
|
|
|
26
26
|
historicalHeader: Header,
|
|
27
27
|
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
28
28
|
protected publicStateDB: PublicStateDB,
|
|
29
|
-
phase:
|
|
29
|
+
phase: PublicKernelType = PublicKernelType.TAIL,
|
|
30
30
|
) {
|
|
31
31
|
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
32
32
|
}
|
|
@@ -11,7 +11,7 @@ import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
|
11
11
|
|
|
12
12
|
import { inspect } from 'util';
|
|
13
13
|
|
|
14
|
-
import { AbstractPhaseManager,
|
|
14
|
+
import { AbstractPhaseManager, makeAvmProvingRequest } from './abstract_phase_manager.js';
|
|
15
15
|
import { type ContractsDataSourcePublicDB } from './public_db_sources.js';
|
|
16
16
|
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
17
17
|
|
|
@@ -27,7 +27,7 @@ export class TeardownPhaseManager extends AbstractPhaseManager {
|
|
|
27
27
|
historicalHeader: Header,
|
|
28
28
|
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
29
29
|
protected publicStateDB: PublicStateDB,
|
|
30
|
-
phase:
|
|
30
|
+
phase: PublicKernelType = PublicKernelType.TEARDOWN,
|
|
31
31
|
) {
|
|
32
32
|
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
33
33
|
}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
// All code in this file needs to die once the public executor is phased out in favor of the AVM.
|
|
2
2
|
import { UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
AvmContractInstanceHint,
|
|
5
|
+
AvmExecutionHints,
|
|
6
|
+
AvmExternalCallHint,
|
|
7
|
+
AvmKeyValueHint,
|
|
8
|
+
CallContext,
|
|
9
|
+
Gas,
|
|
10
|
+
type GasSettings,
|
|
11
|
+
type GlobalVariables,
|
|
12
|
+
type Header,
|
|
13
|
+
} from '@aztec/circuits.js';
|
|
4
14
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
15
|
|
|
6
16
|
import { promisify } from 'util';
|
|
@@ -9,6 +19,8 @@ import { gunzip } from 'zlib';
|
|
|
9
19
|
import { type AvmContext } from '../avm/avm_context.js';
|
|
10
20
|
import { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
|
|
11
21
|
import { type AvmContractCallResults } from '../avm/avm_message_call_result.js';
|
|
22
|
+
import { type PartialPublicExecutionResult } from '../avm/journal/journal.js';
|
|
23
|
+
import { type WorldStateAccessTrace } from '../avm/journal/trace.js';
|
|
12
24
|
import { Mov } from '../avm/opcodes/memory.js';
|
|
13
25
|
import { createSimulationError } from '../common/errors.js';
|
|
14
26
|
import { type PublicExecution, type PublicExecutionResult } from './execution.js';
|
|
@@ -67,6 +79,34 @@ export function createPublicExecution(
|
|
|
67
79
|
return execution;
|
|
68
80
|
}
|
|
69
81
|
|
|
82
|
+
function computeHints(trace: WorldStateAccessTrace, executionResult: PartialPublicExecutionResult): AvmExecutionHints {
|
|
83
|
+
return new AvmExecutionHints(
|
|
84
|
+
trace.publicStorageReads.map(read => new AvmKeyValueHint(read.counter, read.value)),
|
|
85
|
+
trace.noteHashChecks.map(check => new AvmKeyValueHint(check.counter, new Fr(check.exists ? 1 : 0))),
|
|
86
|
+
trace.nullifierChecks.map(check => new AvmKeyValueHint(check.counter, new Fr(check.exists ? 1 : 0))),
|
|
87
|
+
trace.l1ToL2MessageChecks.map(check => new AvmKeyValueHint(check.counter, new Fr(check.exists ? 1 : 0))),
|
|
88
|
+
executionResult.nestedExecutions.map(nested => {
|
|
89
|
+
const gasUsed = new Gas(
|
|
90
|
+
nested.startGasLeft.daGas - nested.endGasLeft.daGas,
|
|
91
|
+
nested.startGasLeft.l2Gas - nested.endGasLeft.l2Gas,
|
|
92
|
+
);
|
|
93
|
+
return new AvmExternalCallHint(/*success=*/ new Fr(nested.reverted ? 0 : 1), nested.returnValues, gasUsed);
|
|
94
|
+
}),
|
|
95
|
+
trace.gotContractInstances.map(
|
|
96
|
+
instance =>
|
|
97
|
+
new AvmContractInstanceHint(
|
|
98
|
+
instance.address,
|
|
99
|
+
new Fr(instance.exists ? 1 : 0),
|
|
100
|
+
instance.salt,
|
|
101
|
+
instance.deployer,
|
|
102
|
+
instance.contractClassId,
|
|
103
|
+
instance.initializationHash,
|
|
104
|
+
instance.publicKeysHash,
|
|
105
|
+
),
|
|
106
|
+
),
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
70
110
|
export function convertAvmResultsToPxResult(
|
|
71
111
|
avmResult: AvmContractCallResults,
|
|
72
112
|
startSideEffectCounter: number,
|
|
@@ -95,7 +135,7 @@ export function convertAvmResultsToPxResult(
|
|
|
95
135
|
transactionFee: endAvmContext.environment.transactionFee,
|
|
96
136
|
bytecode: bytecode,
|
|
97
137
|
calldata: endAvmContext.environment.calldata,
|
|
98
|
-
avmHints: endPersistableState.trace.
|
|
138
|
+
avmHints: computeHints(endPersistableState.trace, endPersistableState.transitionalExecutionResult),
|
|
99
139
|
};
|
|
100
140
|
}
|
|
101
141
|
|
package/dest/public/utils.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
|
|
2
|
-
/**
|
|
3
|
-
* Looks at the side effects of a transaction and returns the highest counter
|
|
4
|
-
* @param tx - A transaction
|
|
5
|
-
* @returns The highest side effect counter in the transaction so far
|
|
6
|
-
*/
|
|
7
|
-
export declare function lastSideEffectCounter(inputs: PublicKernelCircuitPublicInputs): number;
|
|
8
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/public/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,+BAA+B,GAAG,MAAM,CA+BrF"}
|
package/dest/public/utils.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Looks at the side effects of a transaction and returns the highest counter
|
|
3
|
-
* @param tx - A transaction
|
|
4
|
-
* @returns The highest side effect counter in the transaction so far
|
|
5
|
-
*/
|
|
6
|
-
export function lastSideEffectCounter(inputs) {
|
|
7
|
-
const sideEffectCounters = [
|
|
8
|
-
...inputs.endNonRevertibleData.newNoteHashes,
|
|
9
|
-
...inputs.endNonRevertibleData.newNullifiers,
|
|
10
|
-
...inputs.endNonRevertibleData.noteEncryptedLogsHashes,
|
|
11
|
-
...inputs.endNonRevertibleData.encryptedLogsHashes,
|
|
12
|
-
...inputs.endNonRevertibleData.unencryptedLogsHashes,
|
|
13
|
-
...inputs.endNonRevertibleData.publicCallStack,
|
|
14
|
-
...inputs.endNonRevertibleData.publicDataUpdateRequests,
|
|
15
|
-
...inputs.end.newNoteHashes,
|
|
16
|
-
...inputs.end.newNullifiers,
|
|
17
|
-
...inputs.end.noteEncryptedLogsHashes,
|
|
18
|
-
...inputs.end.encryptedLogsHashes,
|
|
19
|
-
...inputs.end.unencryptedLogsHashes,
|
|
20
|
-
...inputs.end.publicCallStack,
|
|
21
|
-
...inputs.end.publicDataUpdateRequests,
|
|
22
|
-
];
|
|
23
|
-
let max = 0;
|
|
24
|
-
for (const sideEffect of sideEffectCounters) {
|
|
25
|
-
if ('startSideEffectCounter' in sideEffect) {
|
|
26
|
-
// look at both start and end counters because for enqueued public calls start > 0 while end === 0
|
|
27
|
-
max = Math.max(max, sideEffect.startSideEffectCounter.toNumber(), sideEffect.endSideEffectCounter.toNumber());
|
|
28
|
-
}
|
|
29
|
-
else if ('counter' in sideEffect) {
|
|
30
|
-
max = Math.max(max, sideEffect.counter);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
throw new Error('Unknown side effect type');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return max;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHVibGljL3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBOzs7O0dBSUc7QUFDSCxNQUFNLFVBQVUscUJBQXFCLENBQUMsTUFBdUM7SUFDM0UsTUFBTSxrQkFBa0IsR0FBRztRQUN6QixHQUFHLE1BQU0sQ0FBQyxvQkFBb0IsQ0FBQyxhQUFhO1FBQzVDLEdBQUcsTUFBTSxDQUFDLG9CQUFvQixDQUFDLGFBQWE7UUFDNUMsR0FBRyxNQUFNLENBQUMsb0JBQW9CLENBQUMsdUJBQXVCO1FBQ3RELEdBQUcsTUFBTSxDQUFDLG9CQUFvQixDQUFDLG1CQUFtQjtRQUNsRCxHQUFHLE1BQU0sQ0FBQyxvQkFBb0IsQ0FBQyxxQkFBcUI7UUFDcEQsR0FBRyxNQUFNLENBQUMsb0JBQW9CLENBQUMsZUFBZTtRQUM5QyxHQUFHLE1BQU0sQ0FBQyxvQkFBb0IsQ0FBQyx3QkFBd0I7UUFDdkQsR0FBRyxNQUFNLENBQUMsR0FBRyxDQUFDLGFBQWE7UUFDM0IsR0FBRyxNQUFNLENBQUMsR0FBRyxDQUFDLGFBQWE7UUFDM0IsR0FBRyxNQUFNLENBQUMsR0FBRyxDQUFDLHVCQUF1QjtRQUNyQyxHQUFHLE1BQU0sQ0FBQyxHQUFHLENBQUMsbUJBQW1CO1FBQ2pDLEdBQUcsTUFBTSxDQUFDLEdBQUcsQ0FBQyxxQkFBcUI7UUFDbkMsR0FBRyxNQUFNLENBQUMsR0FBRyxDQUFDLGVBQWU7UUFDN0IsR0FBRyxNQUFNLENBQUMsR0FBRyxDQUFDLHdCQUF3QjtLQUN2QyxDQUFDO0lBRUYsSUFBSSxHQUFHLEdBQUcsQ0FBQyxDQUFDO0lBQ1osS0FBSyxNQUFNLFVBQVUsSUFBSSxrQkFBa0IsRUFBRSxDQUFDO1FBQzVDLElBQUksd0JBQXdCLElBQUksVUFBVSxFQUFFLENBQUM7WUFDM0Msa0dBQWtHO1lBQ2xHLEdBQUcsR0FBRyxJQUFJLENBQUMsR0FBRyxDQUFDLEdBQUcsRUFBRSxVQUFVLENBQUMsc0JBQXNCLENBQUMsUUFBUSxFQUFFLEVBQUUsVUFBVSxDQUFDLG9CQUFvQixDQUFDLFFBQVEsRUFBRSxDQUFDLENBQUM7UUFDaEgsQ0FBQzthQUFNLElBQUksU0FBUyxJQUFJLFVBQVUsRUFBRSxDQUFDO1lBQ25DLEdBQUcsR0FBRyxJQUFJLENBQUMsR0FBRyxDQUFDLEdBQUcsRUFBRSxVQUFVLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDMUMsQ0FBQzthQUFNLENBQUM7WUFDTixNQUFNLElBQUksS0FBSyxDQUFDLDBCQUEwQixDQUFDLENBQUM7UUFDOUMsQ0FBQztJQUNILENBQUM7SUFFRCxPQUFPLEdBQUcsQ0FBQztBQUNiLENBQUMifQ==
|
package/src/public/utils.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Looks at the side effects of a transaction and returns the highest counter
|
|
5
|
-
* @param tx - A transaction
|
|
6
|
-
* @returns The highest side effect counter in the transaction so far
|
|
7
|
-
*/
|
|
8
|
-
export function lastSideEffectCounter(inputs: PublicKernelCircuitPublicInputs): number {
|
|
9
|
-
const sideEffectCounters = [
|
|
10
|
-
...inputs.endNonRevertibleData.newNoteHashes,
|
|
11
|
-
...inputs.endNonRevertibleData.newNullifiers,
|
|
12
|
-
...inputs.endNonRevertibleData.noteEncryptedLogsHashes,
|
|
13
|
-
...inputs.endNonRevertibleData.encryptedLogsHashes,
|
|
14
|
-
...inputs.endNonRevertibleData.unencryptedLogsHashes,
|
|
15
|
-
...inputs.endNonRevertibleData.publicCallStack,
|
|
16
|
-
...inputs.endNonRevertibleData.publicDataUpdateRequests,
|
|
17
|
-
...inputs.end.newNoteHashes,
|
|
18
|
-
...inputs.end.newNullifiers,
|
|
19
|
-
...inputs.end.noteEncryptedLogsHashes,
|
|
20
|
-
...inputs.end.encryptedLogsHashes,
|
|
21
|
-
...inputs.end.unencryptedLogsHashes,
|
|
22
|
-
...inputs.end.publicCallStack,
|
|
23
|
-
...inputs.end.publicDataUpdateRequests,
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
let max = 0;
|
|
27
|
-
for (const sideEffect of sideEffectCounters) {
|
|
28
|
-
if ('startSideEffectCounter' in sideEffect) {
|
|
29
|
-
// look at both start and end counters because for enqueued public calls start > 0 while end === 0
|
|
30
|
-
max = Math.max(max, sideEffect.startSideEffectCounter.toNumber(), sideEffect.endSideEffectCounter.toNumber());
|
|
31
|
-
} else if ('counter' in sideEffect) {
|
|
32
|
-
max = Math.max(max, sideEffect.counter);
|
|
33
|
-
} else {
|
|
34
|
-
throw new Error('Unknown side effect type');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return max;
|
|
39
|
-
}
|