@aztec/simulator 0.0.1-commit.b9865e97 → 0.0.1-commit.be03c316
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/client.d.ts +1 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +0 -2
- 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/testing/base_avm_simulation_tester.js +1 -1
- package/dest/public/avm/testing/utils.js +1 -1
- package/dest/public/avm_simulator.d.ts +28 -0
- package/dest/public/avm_simulator.d.ts.map +1 -0
- package/dest/public/avm_simulator.js +4 -0
- package/dest/public/avm_simulator_pool.d.ts +45 -0
- package/dest/public/avm_simulator_pool.d.ts.map +1 -0
- package/dest/public/avm_simulator_pool.js +197 -0
- package/dest/public/cdb/generated/api_types.d.ts +171 -0
- package/dest/public/cdb/generated/api_types.d.ts.map +1 -0
- package/dest/public/cdb/generated/api_types.js +314 -0
- package/dest/public/cdb/generated/server.d.ts +26 -0
- package/dest/public/cdb/generated/server.d.ts.map +1 -0
- package/dest/public/cdb/generated/server.js +135 -0
- package/dest/public/cdb_ipc_server.d.ts +33 -0
- package/dest/public/cdb_ipc_server.d.ts.map +1 -0
- package/dest/public/cdb_ipc_server.js +153 -0
- package/dest/public/fixtures/amm_test.js +2 -2
- package/dest/public/fixtures/bulk_test.js +2 -2
- 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/index.d.ts +2 -1
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +1 -0
- package/dest/public/fixtures/public_processor_test_env.d.ts +30 -0
- package/dest/public/fixtures/public_processor_test_env.d.ts.map +1 -0
- package/dest/public/fixtures/public_processor_test_env.js +73 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +9 -5
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +29 -38
- package/dest/public/fixtures/token_test.js +3 -3
- package/dest/public/fixtures/utils.d.ts +1 -1
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +5 -3
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +7 -2
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +15 -6
- package/dest/public/index.d.ts +5 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +2 -1
- package/dest/public/public_db_sources.d.ts +2 -2
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +1 -1
- package/dest/public/public_processor/public_processor.d.ts +8 -4
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +17 -13
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +6 -12
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.js +8 -21
- package/dest/public/public_tx_simulator/factories.d.ts +5 -5
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/factories.js +5 -5
- package/dest/public/public_tx_simulator/index.d.ts +3 -3
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/index.js +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +16 -16
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +59 -58
- package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +10 -8
- package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator_base.js +11 -8
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +5 -5
- package/dest/public/test_executor_metrics.d.ts +1 -6
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +0 -22
- package/package.json +21 -17
- package/src/client.ts +0 -2
- 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/testing/base_avm_simulation_tester.ts +1 -1
- package/src/public/avm/testing/utils.ts +1 -1
- package/src/public/avm_simulator.ts +29 -0
- package/src/public/avm_simulator_pool.ts +226 -0
- package/src/public/cdb/generated/api_types.ts +457 -0
- package/src/public/cdb/generated/server.ts +109 -0
- package/src/public/cdb_ipc_server.ts +197 -0
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +2 -2
- package/src/public/fixtures/custom_bytecode_tester.ts +2 -2
- package/src/public/fixtures/index.ts +1 -0
- package/src/public/fixtures/public_processor_test_env.ts +88 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +37 -48
- package/src/public/fixtures/token_test.ts +3 -3
- package/src/public/fixtures/utils.ts +6 -11
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +28 -10
- package/src/public/index.ts +4 -0
- package/src/public/public_db_sources.ts +1 -1
- package/src/public/public_processor/public_processor.ts +22 -15
- package/src/public/public_tx_simulator/dumping_public_tx_simulator.ts +13 -29
- package/src/public/public_tx_simulator/factories.ts +24 -7
- package/src/public/public_tx_simulator/index.ts +5 -2
- package/src/public/public_tx_simulator/public_tx_simulator.ts +70 -81
- package/src/public/public_tx_simulator/public_tx_simulator_base.ts +8 -6
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +5 -5
- package/src/public/test_executor_metrics.ts +0 -24
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +0 -19
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +0 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +0 -99
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +0 -125
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
3
3
|
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
4
|
-
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
5
4
|
import type { GlobalVariables, ProtocolContracts, Tx } from '@aztec/stdlib/tx';
|
|
6
5
|
|
|
6
|
+
import type { AvmSimulator } from '../avm_simulator.js';
|
|
7
7
|
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Shared base for public tx simulators
|
|
11
|
-
*
|
|
12
|
-
* and
|
|
10
|
+
* Shared base for public tx simulators: holds the common configuration, the {@link AvmSimulator} used
|
|
11
|
+
* to run the transaction's public calls, the contracts DB and fork id that scope the simulation's
|
|
12
|
+
* contract-data lookups, the logger, and the tx-hash helper. Concrete simulators extend this and
|
|
13
|
+
* implement `simulate`.
|
|
13
14
|
*/
|
|
14
15
|
export abstract class PublicTxSimulatorBase {
|
|
15
16
|
protected log: Logger;
|
|
@@ -17,9 +18,10 @@ export abstract class PublicTxSimulatorBase {
|
|
|
17
18
|
protected readonly bindings?: LoggerBindings;
|
|
18
19
|
|
|
19
20
|
constructor(
|
|
20
|
-
protected
|
|
21
|
-
protected contractsDB: PublicContractsDB,
|
|
21
|
+
protected avmSimulator: AvmSimulator,
|
|
22
22
|
protected globalVariables: GlobalVariables,
|
|
23
|
+
protected contractsDB: PublicContractsDB,
|
|
24
|
+
protected forkId: number,
|
|
23
25
|
config?: Partial<PublicSimulatorConfig>,
|
|
24
26
|
protected protocolContracts: ProtocolContracts = ProtocolContractsList,
|
|
25
27
|
bindings?: LoggerBindings,
|
|
@@ -5,14 +5,14 @@ export interface PublicTxSimulatorInterface {
|
|
|
5
5
|
simulate(tx: Tx): Promise<PublicTxResult>;
|
|
6
6
|
/**
|
|
7
7
|
* Cancel the current simulation if one is in progress.
|
|
8
|
-
* This signals the underlying simulator
|
|
8
|
+
* This signals the underlying simulator to stop at the next safe point.
|
|
9
9
|
* Safe to call even if no simulation is in progress.
|
|
10
10
|
* Optional - not all implementations support cancellation.
|
|
11
11
|
*
|
|
12
12
|
* @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* Cancellation is cooperative: signaling it only sets a flag the simulator
|
|
14
|
+
* checks at certain points, so if it's mid slow-operation it won't stop until
|
|
15
|
+
* that completes.
|
|
16
16
|
* @returns Promise that resolves when cancellation is signaled (and optionally when simulation stops)
|
|
17
17
|
*/
|
|
18
18
|
cancel?(waitTimeoutMs?: number): Promise<void>;
|
|
@@ -22,7 +22,7 @@ export interface MeasuredPublicTxSimulatorInterface {
|
|
|
22
22
|
simulate(tx: Tx, txLabel: string): Promise<PublicTxResult>;
|
|
23
23
|
/**
|
|
24
24
|
* Cancel the current simulation if one is in progress.
|
|
25
|
-
* This signals the underlying simulator
|
|
25
|
+
* This signals the underlying simulator to stop at the next safe point.
|
|
26
26
|
* Safe to call even if no simulation is in progress.
|
|
27
27
|
* Optional - not all implementations support cancellation.
|
|
28
28
|
*
|
|
@@ -21,7 +21,6 @@ export interface PublicTxMetrics {
|
|
|
21
21
|
totalDurationMs: number;
|
|
22
22
|
manaUsed: number | undefined;
|
|
23
23
|
totalInstructionsExecuted: number;
|
|
24
|
-
bytecodeSizes: { contractName: string; sizeBytes: number }[];
|
|
25
24
|
nonRevertiblePrivateInsertionsUs: number | undefined;
|
|
26
25
|
revertiblePrivateInsertionsUs: number | undefined;
|
|
27
26
|
enqueuedCalls: PublicEnqueuedCallMetrics[];
|
|
@@ -63,7 +62,6 @@ function createEmptyTxMetrics(): PublicTxMetrics {
|
|
|
63
62
|
totalDurationMs: 0,
|
|
64
63
|
manaUsed: 0,
|
|
65
64
|
totalInstructionsExecuted: 0,
|
|
66
|
-
bytecodeSizes: [],
|
|
67
65
|
nonRevertiblePrivateInsertionsUs: undefined,
|
|
68
66
|
revertiblePrivateInsertionsUs: undefined,
|
|
69
67
|
enqueuedCalls: [],
|
|
@@ -174,12 +172,6 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
|
|
|
174
172
|
}
|
|
175
173
|
}
|
|
176
174
|
|
|
177
|
-
recordBytecodeSize(txLabel: string, contractName: string, sizeBytes: number) {
|
|
178
|
-
const txMetrics = this.txMetrics.get(txLabel);
|
|
179
|
-
assert(txMetrics, `Cannot record bytecode size for unknown tx label: ${txLabel}`);
|
|
180
|
-
txMetrics.bytecodeSizes.push({ contractName, sizeBytes });
|
|
181
|
-
}
|
|
182
|
-
|
|
183
175
|
recordProverMetrics(txLabel: string, metrics: Partial<PublicTxMetrics>) {
|
|
184
176
|
if (!this.txMetrics.has(txLabel)) {
|
|
185
177
|
this.txMetrics.set(txLabel, createEmptyTxMetrics());
|
|
@@ -224,15 +216,6 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
|
|
|
224
216
|
) {
|
|
225
217
|
pretty += `${INDENT0}Total instructions executed: ${fmtNum(txMetrics.totalInstructionsExecuted)}\n`;
|
|
226
218
|
}
|
|
227
|
-
if (
|
|
228
|
-
(filter === PublicTxMetricsFilter.TOTALS || filter === PublicTxMetricsFilter.ALL) &&
|
|
229
|
-
txMetrics.bytecodeSizes.length > 0
|
|
230
|
-
) {
|
|
231
|
-
pretty += `${INDENT0}Bytecode sizes:\n`;
|
|
232
|
-
for (const { contractName, sizeBytes } of txMetrics.bytecodeSizes) {
|
|
233
|
-
pretty += `${INDENT1}${contractName}: ${fmtNum(sizeBytes, 'bytes')}\n`;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
219
|
if (filter === PublicTxMetricsFilter.DURATIONS || filter === PublicTxMetricsFilter.ALL) {
|
|
237
220
|
pretty += `${INDENT0}Private insertions:\n`;
|
|
238
221
|
pretty += `${INDENT1}Non-revertible: ${fmtNum(txMetrics.nonRevertiblePrivateInsertionsUs! / 1_000, 'ms')}\n`;
|
|
@@ -404,13 +387,6 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
|
|
|
404
387
|
});
|
|
405
388
|
}
|
|
406
389
|
}
|
|
407
|
-
for (const { contractName, sizeBytes } of txMetrics.bytecodeSizes) {
|
|
408
|
-
data.push({
|
|
409
|
-
name: `${txLabel}/bytecodeSizeBytes/${contractName}`,
|
|
410
|
-
value: sizeBytes,
|
|
411
|
-
unit: 'bytes',
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
390
|
}
|
|
415
391
|
return JSON.stringify(data, null, indent);
|
|
416
392
|
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type LoggerBindings } from '@aztec/foundation/log';
|
|
2
|
-
import type { ContractProvider } from '@aztec/native';
|
|
3
|
-
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
4
|
-
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
5
|
-
export declare class ContractProviderForCpp implements ContractProvider {
|
|
6
|
-
private contractsDB;
|
|
7
|
-
private globalVariables;
|
|
8
|
-
private log;
|
|
9
|
-
constructor(contractsDB: PublicContractsDB, globalVariables: GlobalVariables, bindings?: LoggerBindings);
|
|
10
|
-
getContractInstance: (address: string) => Promise<Buffer<ArrayBufferLike> | undefined>;
|
|
11
|
-
getContractClass: (classId: string) => Promise<Buffer<ArrayBufferLike> | undefined>;
|
|
12
|
-
addContracts: (contractDeploymentDataBuffer: Buffer<ArrayBufferLike>) => Promise<void>;
|
|
13
|
-
getBytecodeCommitment: (classId: string) => Promise<Buffer<ArrayBufferLike> | undefined>;
|
|
14
|
-
getDebugFunctionName: (address: string, selector: string) => Promise<string | undefined>;
|
|
15
|
-
createCheckpoint: () => Promise<void>;
|
|
16
|
-
commitCheckpoint: () => Promise<void>;
|
|
17
|
-
revertCheckpoint: () => Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3RfcHJvdmlkZXJfZm9yX2NwcC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3B1YmxpYy9wdWJsaWNfdHhfc2ltdWxhdG9yL2NvbnRyYWN0X3Byb3ZpZGVyX2Zvcl9jcHAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFlLEtBQUssY0FBYyxFQUFnQixNQUFNLHVCQUF1QixDQUFDO0FBQ3ZGLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0sZUFBZSxDQUFDO0FBS3RELE9BQU8sS0FBSyxFQUFFLGVBQWUsRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBRXhELE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFFakUscUJBQWEsc0JBQXVCLFlBQVcsZ0JBQWdCO0lBSTNELE9BQU8sQ0FBQyxXQUFXO0lBQ25CLE9BQU8sQ0FBQyxlQUFlO0lBSnpCLE9BQU8sQ0FBQyxHQUFHLENBQVM7SUFFcEIsWUFDVSxXQUFXLEVBQUUsaUJBQWlCLEVBQzlCLGVBQWUsRUFBRSxlQUFlLEVBQ3hDLFFBQVEsQ0FBQyxFQUFFLGNBQWMsRUFHMUI7SUFFTSxtQkFBbUIsb0VBYXhCO0lBRUssZ0JBQWdCLG9FQWVyQjtJQUdLLFlBQVksMkVBV2pCO0lBRUsscUJBQXFCLG9FQWdCMUI7SUFFSyxvQkFBb0IscUVBc0J6QjtJQUVLLGdCQUFnQixzQkFHckI7SUFFSyxnQkFBZ0Isc0JBR3JCO0lBRUssZ0JBQWdCLHNCQUdyQjtDQUNIIn0=
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contract_provider_for_cpp.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/contract_provider_for_cpp.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AACvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAKtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,qBAAa,sBAAuB,YAAW,gBAAgB;IAI3D,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,eAAe;IAJzB,OAAO,CAAC,GAAG,CAAS;IAEpB,YACU,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EACxC,QAAQ,CAAC,EAAE,cAAc,EAG1B;IAEM,mBAAmB,oEAaxB;IAEK,gBAAgB,oEAerB;IAGK,YAAY,2EAWjB;IAEK,qBAAqB,oEAgB1B;IAEK,oBAAoB,qEAsBzB;IAEK,gBAAgB,sBAGrB;IAEK,gBAAgB,sBAGrB;IAEK,gBAAgB,sBAGrB;CACH"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
4
|
-
import { deserializeFromMessagePack, serializeWithMessagePack } from '@aztec/stdlib/avm';
|
|
5
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
-
import { ContractDeploymentData } from '@aztec/stdlib/contract';
|
|
7
|
-
export class ContractProviderForCpp {
|
|
8
|
-
contractsDB;
|
|
9
|
-
globalVariables;
|
|
10
|
-
log;
|
|
11
|
-
constructor(contractsDB, globalVariables, bindings){
|
|
12
|
-
this.contractsDB = contractsDB;
|
|
13
|
-
this.globalVariables = globalVariables;
|
|
14
|
-
this.getContractInstance = async (address)=>{
|
|
15
|
-
this.log.trace(`Contract provider callback: getContractInstance(${address})`);
|
|
16
|
-
const aztecAddr = AztecAddress.fromString(address);
|
|
17
|
-
const instance = await this.contractsDB.getContractInstance(aztecAddr, this.globalVariables.timestamp);
|
|
18
|
-
if (!instance) {
|
|
19
|
-
this.log.debug(`Contract instance not found: ${address}`);
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
return serializeWithMessagePack(instance);
|
|
23
|
-
};
|
|
24
|
-
this.getContractClass = async (classId)=>{
|
|
25
|
-
this.log.trace(`Contract provider callback: getContractClass(${classId})`);
|
|
26
|
-
// Parse classId string to Fr
|
|
27
|
-
const classIdFr = Fr.fromString(classId);
|
|
28
|
-
// Fetch contract class from the contracts DB
|
|
29
|
-
const contractClass = await this.contractsDB.getContractClass(classIdFr);
|
|
30
|
-
if (!contractClass) {
|
|
31
|
-
this.log.debug(`Contract class not found: ${classId}`);
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
return serializeWithMessagePack(contractClass);
|
|
35
|
-
};
|
|
36
|
-
this.addContracts = async (contractDeploymentDataBuffer)=>{
|
|
37
|
-
this.log.trace(`Contract provider callback: addContracts`);
|
|
38
|
-
const rawData = deserializeFromMessagePack(contractDeploymentDataBuffer);
|
|
39
|
-
// Construct ContractDeploymentData from plain object.
|
|
40
|
-
const contractDeploymentData = ContractDeploymentData.fromPlainObject(rawData);
|
|
41
|
-
// Add contracts to the contracts DB
|
|
42
|
-
this.log.trace(`Calling contractsDB.addContractsFromLogs`);
|
|
43
|
-
this.contractsDB.addContractsFromLogs(contractDeploymentData);
|
|
44
|
-
};
|
|
45
|
-
this.getBytecodeCommitment = async (classId)=>{
|
|
46
|
-
this.log.trace(`Contract provider callback: getBytecodeCommitment(${classId})`);
|
|
47
|
-
// Parse classId string to Fr
|
|
48
|
-
const classIdFr = Fr.fromString(classId);
|
|
49
|
-
// Fetch bytecode commitment from the contracts DB
|
|
50
|
-
const commitment = await this.contractsDB.getBytecodeCommitment(classIdFr);
|
|
51
|
-
if (!commitment) {
|
|
52
|
-
this.log.debug(`Bytecode commitment not found: ${classId}`);
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
// Serialize the Fr to buffer
|
|
56
|
-
return serializeWithMessagePack(commitment);
|
|
57
|
-
};
|
|
58
|
-
this.getDebugFunctionName = async (address, selector)=>{
|
|
59
|
-
this.log.trace(`Contract provider callback: getDebugFunctionName(${address}, ${selector})`);
|
|
60
|
-
// Parse address and selector strings
|
|
61
|
-
const aztecAddr = AztecAddress.fromString(address);
|
|
62
|
-
const selectorFr = Fr.fromString(selector);
|
|
63
|
-
const functionSelector = FunctionSelector.fromFieldOrUndefined(selectorFr);
|
|
64
|
-
if (!functionSelector) {
|
|
65
|
-
this.log.trace(`calldata[0] is not a function selector: ${selector}`);
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
// Fetch debug function name from the contracts DB
|
|
69
|
-
const name = await this.contractsDB.getDebugFunctionName(aztecAddr, functionSelector);
|
|
70
|
-
if (!name) {
|
|
71
|
-
this.log.trace(`Debug function name not found for ${address}:${selector}`);
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
return name;
|
|
75
|
-
};
|
|
76
|
-
this.createCheckpoint = ()=>{
|
|
77
|
-
this.log.trace(`Contract provider callback: createCheckpoint`);
|
|
78
|
-
return Promise.resolve(this.contractsDB.createCheckpoint());
|
|
79
|
-
};
|
|
80
|
-
this.commitCheckpoint = ()=>{
|
|
81
|
-
this.log.trace(`Contract provider callback: commitCheckpoint`);
|
|
82
|
-
return Promise.resolve(this.contractsDB.commitCheckpoint());
|
|
83
|
-
};
|
|
84
|
-
this.revertCheckpoint = ()=>{
|
|
85
|
-
this.log.trace(`Contract provider callback: revertCheckpoint`);
|
|
86
|
-
return Promise.resolve(this.contractsDB.revertCheckpoint());
|
|
87
|
-
};
|
|
88
|
-
this.log = createLogger('simulator:contract_provider_for_cpp', bindings);
|
|
89
|
-
}
|
|
90
|
-
getContractInstance;
|
|
91
|
-
getContractClass;
|
|
92
|
-
// eslint-disable-next-line require-await
|
|
93
|
-
addContracts;
|
|
94
|
-
getBytecodeCommitment;
|
|
95
|
-
getDebugFunctionName;
|
|
96
|
-
createCheckpoint;
|
|
97
|
-
commitCheckpoint;
|
|
98
|
-
revertCheckpoint;
|
|
99
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
-
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import type { ContractProvider } from '@aztec/native';
|
|
4
|
-
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
|
-
import { deserializeFromMessagePack, serializeWithMessagePack } from '@aztec/stdlib/avm';
|
|
6
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
-
import { ContractDeploymentData } from '@aztec/stdlib/contract';
|
|
8
|
-
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
9
|
-
|
|
10
|
-
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
11
|
-
|
|
12
|
-
export class ContractProviderForCpp implements ContractProvider {
|
|
13
|
-
private log: Logger;
|
|
14
|
-
|
|
15
|
-
constructor(
|
|
16
|
-
private contractsDB: PublicContractsDB,
|
|
17
|
-
private globalVariables: GlobalVariables,
|
|
18
|
-
bindings?: LoggerBindings,
|
|
19
|
-
) {
|
|
20
|
-
this.log = createLogger('simulator:contract_provider_for_cpp', bindings);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public getContractInstance = async (address: string): Promise<Buffer | undefined> => {
|
|
24
|
-
this.log.trace(`Contract provider callback: getContractInstance(${address})`);
|
|
25
|
-
|
|
26
|
-
const aztecAddr = AztecAddress.fromString(address);
|
|
27
|
-
|
|
28
|
-
const instance = await this.contractsDB.getContractInstance(aztecAddr, this.globalVariables.timestamp);
|
|
29
|
-
|
|
30
|
-
if (!instance) {
|
|
31
|
-
this.log.debug(`Contract instance not found: ${address}`);
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return serializeWithMessagePack(instance);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
public getContractClass = async (classId: string): Promise<Buffer | undefined> => {
|
|
39
|
-
this.log.trace(`Contract provider callback: getContractClass(${classId})`);
|
|
40
|
-
|
|
41
|
-
// Parse classId string to Fr
|
|
42
|
-
const classIdFr = Fr.fromString(classId);
|
|
43
|
-
|
|
44
|
-
// Fetch contract class from the contracts DB
|
|
45
|
-
const contractClass = await this.contractsDB.getContractClass(classIdFr);
|
|
46
|
-
|
|
47
|
-
if (!contractClass) {
|
|
48
|
-
this.log.debug(`Contract class not found: ${classId}`);
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return serializeWithMessagePack(contractClass);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// eslint-disable-next-line require-await
|
|
56
|
-
public addContracts = async (contractDeploymentDataBuffer: Buffer): Promise<void> => {
|
|
57
|
-
this.log.trace(`Contract provider callback: addContracts`);
|
|
58
|
-
|
|
59
|
-
const rawData: any = deserializeFromMessagePack(contractDeploymentDataBuffer);
|
|
60
|
-
|
|
61
|
-
// Construct ContractDeploymentData from plain object.
|
|
62
|
-
const contractDeploymentData = ContractDeploymentData.fromPlainObject(rawData);
|
|
63
|
-
|
|
64
|
-
// Add contracts to the contracts DB
|
|
65
|
-
this.log.trace(`Calling contractsDB.addContractsFromLogs`);
|
|
66
|
-
this.contractsDB.addContractsFromLogs(contractDeploymentData);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
public getBytecodeCommitment = async (classId: string): Promise<Buffer | undefined> => {
|
|
70
|
-
this.log.trace(`Contract provider callback: getBytecodeCommitment(${classId})`);
|
|
71
|
-
|
|
72
|
-
// Parse classId string to Fr
|
|
73
|
-
const classIdFr = Fr.fromString(classId);
|
|
74
|
-
|
|
75
|
-
// Fetch bytecode commitment from the contracts DB
|
|
76
|
-
const commitment = await this.contractsDB.getBytecodeCommitment(classIdFr);
|
|
77
|
-
|
|
78
|
-
if (!commitment) {
|
|
79
|
-
this.log.debug(`Bytecode commitment not found: ${classId}`);
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Serialize the Fr to buffer
|
|
84
|
-
return serializeWithMessagePack(commitment);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
public getDebugFunctionName = async (address: string, selector: string): Promise<string | undefined> => {
|
|
88
|
-
this.log.trace(`Contract provider callback: getDebugFunctionName(${address}, ${selector})`);
|
|
89
|
-
|
|
90
|
-
// Parse address and selector strings
|
|
91
|
-
const aztecAddr = AztecAddress.fromString(address);
|
|
92
|
-
const selectorFr = Fr.fromString(selector);
|
|
93
|
-
const functionSelector = FunctionSelector.fromFieldOrUndefined(selectorFr);
|
|
94
|
-
|
|
95
|
-
if (!functionSelector) {
|
|
96
|
-
this.log.trace(`calldata[0] is not a function selector: ${selector}`);
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Fetch debug function name from the contracts DB
|
|
101
|
-
const name = await this.contractsDB.getDebugFunctionName(aztecAddr, functionSelector);
|
|
102
|
-
|
|
103
|
-
if (!name) {
|
|
104
|
-
this.log.trace(`Debug function name not found for ${address}:${selector}`);
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return name;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
public createCheckpoint = (): Promise<void> => {
|
|
112
|
-
this.log.trace(`Contract provider callback: createCheckpoint`);
|
|
113
|
-
return Promise.resolve(this.contractsDB.createCheckpoint());
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
public commitCheckpoint = (): Promise<void> => {
|
|
117
|
-
this.log.trace(`Contract provider callback: commitCheckpoint`);
|
|
118
|
-
return Promise.resolve(this.contractsDB.commitCheckpoint());
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
public revertCheckpoint = (): Promise<void> => {
|
|
122
|
-
this.log.trace(`Contract provider callback: revertCheckpoint`);
|
|
123
|
-
return Promise.resolve(this.contractsDB.revertCheckpoint());
|
|
124
|
-
};
|
|
125
|
-
}
|