@aztec/simulator 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/README.md +6 -0
- package/dest/private/acvm/oracle/oracle.d.ts +3 -2
- package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.js +9 -6
- package/dest/private/acvm/oracle/typed_oracle.d.ts +4 -3
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/typed_oracle.js +4 -1
- package/dest/private/execution_data_provider.d.ts +20 -16
- package/dest/private/execution_data_provider.d.ts.map +1 -1
- package/dest/private/private_execution_oracle.d.ts +1 -1
- package/dest/private/private_execution_oracle.d.ts.map +1 -1
- package/dest/private/private_execution_oracle.js +2 -6
- package/dest/private/unconstrained_execution_oracle.d.ts +4 -2
- package/dest/private/unconstrained_execution_oracle.d.ts.map +1 -1
- package/dest/private/unconstrained_execution_oracle.js +5 -6
- package/dest/public/avm/avm_context.d.ts +3 -3
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +4 -2
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +9 -5
- package/dest/public/avm/avm_machine_state.d.ts +2 -0
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.js +2 -0
- package/dest/public/avm/avm_simulator.d.ts +2 -2
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +5 -6
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +2 -2
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +3 -4
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +0 -5
- package/dest/public/avm/fixtures/index.d.ts +6 -5
- package/dest/public/avm/fixtures/index.d.ts.map +1 -1
- package/dest/public/avm/fixtures/index.js +3 -3
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +3 -2
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/avm/fixtures/simple_contract_data_source.js +30 -6
- package/dest/public/avm/index.d.ts +0 -1
- package/dest/public/avm/index.d.ts.map +1 -1
- package/dest/public/avm/index.js +0 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +2 -0
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +8 -10
- package/dest/public/avm/serialization/instruction_serialization.d.ts +5 -2
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +25 -7
- package/dest/public/avm/test_utils.d.ts +1 -1
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/executor_metrics.d.ts +11 -3
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +40 -6
- package/dest/public/executor_metrics_interface.d.ts +10 -0
- package/dest/public/executor_metrics_interface.d.ts.map +1 -0
- package/dest/public/executor_metrics_interface.js +1 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +12 -6
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +39 -19
- package/dest/public/hinting_db_sources.d.ts +26 -3
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +134 -1
- package/dest/public/index.d.ts +1 -1
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_db_sources.d.ts +2 -3
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +26 -16
- package/dest/public/public_processor/public_processor.d.ts +4 -4
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +7 -28
- package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts +9 -0
- package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/apps_tests/amm_test.js +237 -0
- package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts +7 -0
- package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/apps_tests/token_test.js +109 -0
- package/dest/public/public_tx_simulator/index.d.ts +3 -0
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/index.js +2 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +23 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +58 -0
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +5 -5
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +10 -8
- 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 +25 -65
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +19 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +39 -0
- package/dest/public/state_manager/index.d.ts +2 -0
- package/dest/public/state_manager/index.d.ts.map +1 -0
- package/dest/public/state_manager/index.js +1 -0
- package/dest/public/{avm/journal → state_manager}/nullifiers.d.ts +1 -1
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -0
- package/dest/public/{avm/journal → state_manager}/public_storage.d.ts +1 -1
- package/dest/public/state_manager/public_storage.d.ts.map +1 -0
- package/dest/public/{avm/journal/journal.d.ts → state_manager/state_manager.d.ts} +10 -10
- package/dest/public/state_manager/state_manager.d.ts.map +1 -0
- package/dest/public/{avm/journal/journal.js → state_manager/state_manager.js} +5 -5
- package/dest/public/test_executor_metrics.d.ts +43 -0
- package/dest/public/test_executor_metrics.d.ts.map +1 -0
- package/dest/public/test_executor_metrics.js +158 -0
- package/package.json +14 -14
- package/src/private/acvm/oracle/oracle.ts +26 -5
- package/src/private/acvm/oracle/typed_oracle.ts +14 -3
- package/src/private/execution_data_provider.ts +34 -18
- package/src/private/private_execution_oracle.ts +2 -13
- package/src/private/unconstrained_execution_oracle.ts +22 -15
- package/src/public/avm/avm_context.ts +2 -2
- package/src/public/avm/avm_contract_call_result.ts +15 -3
- package/src/public/avm/avm_machine_state.ts +5 -0
- package/src/public/avm/avm_simulator.ts +20 -9
- package/src/public/avm/fixtures/avm_simulation_tester.ts +4 -4
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -7
- package/src/public/avm/fixtures/index.ts +7 -7
- package/src/public/avm/fixtures/simple_contract_data_source.ts +33 -6
- package/src/public/avm/index.ts +0 -1
- package/src/public/avm/opcodes/accrued_substate.ts +1 -1
- package/src/public/avm/opcodes/external_calls.ts +3 -0
- package/src/public/avm/opcodes/memory.ts +8 -10
- package/src/public/avm/serialization/instruction_serialization.ts +24 -9
- package/src/public/avm/test_utils.ts +1 -1
- package/src/public/executor_metrics.ts +54 -6
- package/src/public/executor_metrics_interface.ts +15 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +74 -18
- package/src/public/hinting_db_sources.ts +228 -3
- package/src/public/index.ts +1 -1
- package/src/public/public_db_sources.ts +36 -23
- package/src/public/public_processor/public_processor.ts +8 -28
- package/src/public/public_tx_simulator/apps_tests/amm_test.ts +316 -0
- package/src/public/public_tx_simulator/apps_tests/token_test.ts +138 -0
- package/src/public/public_tx_simulator/index.ts +2 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +111 -0
- package/src/public/public_tx_simulator/public_tx_context.ts +13 -17
- package/src/public/public_tx_simulator/public_tx_simulator.ts +35 -79
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +62 -0
- package/src/public/state_manager/index.ts +1 -0
- package/src/public/{avm/journal → state_manager}/nullifiers.ts +1 -1
- package/src/public/{avm/journal → state_manager}/public_storage.ts +1 -1
- package/src/public/{avm/journal/journal.ts → state_manager/state_manager.ts} +20 -13
- package/src/public/test_executor_metrics.ts +222 -0
- package/dest/public/avm/journal/index.d.ts +0 -2
- package/dest/public/avm/journal/index.d.ts.map +0 -1
- package/dest/public/avm/journal/index.js +0 -1
- package/dest/public/avm/journal/journal.d.ts.map +0 -1
- package/dest/public/avm/journal/nullifiers.d.ts.map +0 -1
- package/dest/public/avm/journal/public_storage.d.ts.map +0 -1
- package/src/public/avm/journal/index.ts +0 -1
- /package/dest/public/{avm/journal → state_manager}/nullifiers.js +0 -0
- /package/dest/public/{avm/journal → state_manager}/public_storage.js +0 -0
|
@@ -7,7 +7,7 @@ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server'
|
|
|
7
7
|
import { type FailedTx, GlobalVariables, NestedProcessReturnValues, type ProcessedTx, Tx, type TxValidator } from '@aztec/stdlib/tx';
|
|
8
8
|
import { type TelemetryClient, type Traceable, type Tracer } from '@aztec/telemetry-client';
|
|
9
9
|
import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
|
|
10
|
-
import { PublicTxSimulator } from '../public_tx_simulator/
|
|
10
|
+
import { type PublicTxSimulator } from '../public_tx_simulator/index.js';
|
|
11
11
|
/**
|
|
12
12
|
* Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
|
|
13
13
|
*/
|
|
@@ -43,7 +43,8 @@ export declare class PublicProcessor implements Traceable {
|
|
|
43
43
|
/**
|
|
44
44
|
* Run each tx through the public circuit and the public kernel circuit if needed.
|
|
45
45
|
* @param txs - Txs to process.
|
|
46
|
-
* @param
|
|
46
|
+
* @param limits - Limits for processing the txs.
|
|
47
|
+
* @param validator - Pre-process validator and nullifier cache to use for processing the txs.
|
|
47
48
|
* @returns The list of processed txs with their circuit simulation outputs.
|
|
48
49
|
*/
|
|
49
50
|
process(txs: Iterable<Tx> | AsyncIterable<Tx>, limits?: {
|
|
@@ -51,9 +52,8 @@ export declare class PublicProcessor implements Traceable {
|
|
|
51
52
|
maxBlockSize?: number;
|
|
52
53
|
maxBlockGas?: Gas;
|
|
53
54
|
deadline?: Date;
|
|
54
|
-
},
|
|
55
|
+
}, validator?: {
|
|
55
56
|
preprocessValidator?: TxValidator<Tx>;
|
|
56
|
-
postprocessValidator?: TxValidator<ProcessedTx>;
|
|
57
57
|
nullifierCache?: {
|
|
58
58
|
addNullifiers: (nullifiers: Buffer[]) => void;
|
|
59
59
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,KAAK,YAAY,EAAkC,MAAM,yBAAyB,CAAC;AAM5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAEjF,OAAO,EACL,KAAK,QAAQ,EACb,eAAe,EACf,yBAAyB,EACzB,KAAK,WAAW,EAChB,EAAE,EAEF,KAAK,WAAW,EAGjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,KAAK,YAAY,EAAkC,MAAM,yBAAyB,CAAC;AAM5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAEjF,OAAO,EACL,KAAK,QAAQ,EACb,eAAe,EACf,yBAAyB,EACzB,KAAK,WAAW,EAChB,EAAE,EAEF,KAAK,WAAW,EAGjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,KAAK,iBAAiB,EAA8B,MAAM,iCAAiC,CAAC;AAGrG;;GAEG;AACH,qBAAa,sBAAsB;IAE/B,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,eAAe;gBAFf,kBAAkB,EAAE,kBAAkB,EACtC,YAAY,EAAE,YAAY,EAC1B,eAAe,GAAE,eAAsC;IAGjE;;;;;;OAMG;IACI,MAAM,CACX,UAAU,EAAE,yBAAyB,EACrC,eAAe,EAAE,eAAe,EAChC,kBAAkB,EAAE,OAAO,GAC1B,eAAe;IAsBlB,SAAS,CAAC,uBAAuB,CAC/B,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,EAAE,OAAO,EAC3B,kBAAkB,EAAE,OAAO,EAC3B,eAAe,EAAE,eAAe,GAC/B,iBAAiB;CAUrB;AAS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edTxFromPri
|
|
|
19
19
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
20
20
|
import { ForkCheckpoint } from '@aztec/world-state/native';
|
|
21
21
|
import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
|
|
22
|
-
import {
|
|
22
|
+
import { TelemetryPublicTxSimulator } from '../public_tx_simulator/index.js';
|
|
23
23
|
import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
24
24
|
/**
|
|
25
25
|
* Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
|
|
@@ -45,7 +45,7 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
|
45
45
|
return new PublicProcessor(globalVariables, treesDB, contractsDB, publicTxSimulator, this.dateProvider, this.telemetryClient);
|
|
46
46
|
}
|
|
47
47
|
createPublicTxSimulator(treesDB, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient) {
|
|
48
|
-
return new
|
|
48
|
+
return new TelemetryPublicTxSimulator(treesDB, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
class PublicProcessorTimeoutError extends Error {
|
|
@@ -80,11 +80,12 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
80
80
|
/**
|
|
81
81
|
* Run each tx through the public circuit and the public kernel circuit if needed.
|
|
82
82
|
* @param txs - Txs to process.
|
|
83
|
-
* @param
|
|
83
|
+
* @param limits - Limits for processing the txs.
|
|
84
|
+
* @param validator - Pre-process validator and nullifier cache to use for processing the txs.
|
|
84
85
|
* @returns The list of processed txs with their circuit simulation outputs.
|
|
85
|
-
*/ async process(txs, limits = {},
|
|
86
|
+
*/ async process(txs, limits = {}, validator = {}) {
|
|
86
87
|
const { maxTransactions, maxBlockSize, deadline, maxBlockGas } = limits;
|
|
87
|
-
const { preprocessValidator,
|
|
88
|
+
const { preprocessValidator, nullifierCache } = validator;
|
|
88
89
|
const result = [];
|
|
89
90
|
const failed = [];
|
|
90
91
|
const timer = new Timer();
|
|
@@ -169,28 +170,6 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
169
170
|
await checkpoint.revert();
|
|
170
171
|
continue;
|
|
171
172
|
}
|
|
172
|
-
// Re-validate the transaction
|
|
173
|
-
if (postprocessValidator) {
|
|
174
|
-
// Only accept processed transactions that are not double-spends,
|
|
175
|
-
// public functions emitting nullifiers would pass earlier check but fail here.
|
|
176
|
-
// Note that we're checking all nullifiers generated in the private execution twice,
|
|
177
|
-
// we could store the ones already checked and skip them here as an optimization.
|
|
178
|
-
// TODO(palla/txs): Can we get into this case? AVM validates this. We should be able to remove it.
|
|
179
|
-
const result = await postprocessValidator.validateTx(processedTx);
|
|
180
|
-
if (result.result !== 'valid') {
|
|
181
|
-
const reason = result.reason.join(', ');
|
|
182
|
-
this.log.error(`Rejecting tx ${processedTx.hash} after processing: ${reason}.`);
|
|
183
|
-
failed.push({
|
|
184
|
-
tx,
|
|
185
|
-
error: new Error(`Tx failed post-process validation: ${reason}`)
|
|
186
|
-
});
|
|
187
|
-
// Need to revert the checkpoint here and don't go any further
|
|
188
|
-
await checkpoint.revert();
|
|
189
|
-
continue;
|
|
190
|
-
} else {
|
|
191
|
-
this.log.trace(`Tx ${txHash.toString()} is valid post processing.`);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
173
|
if (!tx.hasPublicCalls()) {
|
|
195
174
|
// If there are no public calls, perform all tree insertions for side effects from private
|
|
196
175
|
// When there are public calls, the PublicTxSimulator & AVM handle tree insertions.
|
|
@@ -347,7 +326,7 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
347
326
|
if (phase.reverted) {
|
|
348
327
|
this.metrics.recordRevertedPhase(phase.phase);
|
|
349
328
|
} else {
|
|
350
|
-
this.metrics.recordPhaseDuration(phase.phase, phase.durationMs);
|
|
329
|
+
this.metrics.recordPhaseDuration(phase.phase, phase.durationMs ?? 0);
|
|
351
330
|
}
|
|
352
331
|
});
|
|
353
332
|
const siloedContractClassLogs = await tx.filterContractClassLogs(tx.data.getNonEmptyContractClassLogsHashes(), true);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import { PublicTxSimulationTester } from '../../fixtures/public_tx_simulation_tester.js';
|
|
3
|
+
/**
|
|
4
|
+
* THIS TEST IS BRITTLE! If it breaks, don't try fixing it.
|
|
5
|
+
* `.skip` it or literally just delete it and notify AVM team.
|
|
6
|
+
* You do NOT need permission to remove this test!
|
|
7
|
+
*/
|
|
8
|
+
export declare function ammTest(tester: PublicTxSimulationTester, logger: Logger): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=amm_test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amm_test.d.ts","sourceRoot":"","sources":["../../../../src/public/public_tx_simulator/apps_tests/amm_test.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAKpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAIzF;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,iBAoG7E"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { AMMContractArtifact } from '@aztec/noir-contracts.js/AMM';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { deployToken } from './token_test.js';
|
|
5
|
+
const INITIAL_TOKEN_BALANCE = 1_000_000_000n;
|
|
6
|
+
/**
|
|
7
|
+
* THIS TEST IS BRITTLE! If it breaks, don't try fixing it.
|
|
8
|
+
* `.skip` it or literally just delete it and notify AVM team.
|
|
9
|
+
* You do NOT need permission to remove this test!
|
|
10
|
+
*/ export async function ammTest(tester, logger) {
|
|
11
|
+
const startTime = performance.now();
|
|
12
|
+
const admin = AztecAddress.fromNumber(42);
|
|
13
|
+
const sender = AztecAddress.fromNumber(111);
|
|
14
|
+
logger.debug(`Deploying tokens`);
|
|
15
|
+
const token0 = await deployToken(tester, admin, /*seed=*/ 0);
|
|
16
|
+
const token1 = await deployToken(tester, admin, /*seed=*/ 1);
|
|
17
|
+
const liquidityToken = await deployToken(tester, admin, /*seed=*/ 2);
|
|
18
|
+
logger.debug(`Deploying AMM`);
|
|
19
|
+
const constructorArgs = [
|
|
20
|
+
token0,
|
|
21
|
+
token1,
|
|
22
|
+
liquidityToken
|
|
23
|
+
];
|
|
24
|
+
const amm = await tester.registerAndDeployContract(constructorArgs, /*deployer=*/ admin, AMMContractArtifact, /*skipNullifierInsertion=*/ false, /*seed=*/ 3);
|
|
25
|
+
const ammConstructorResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'constructor', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
26
|
+
{
|
|
27
|
+
fnName: 'constructor',
|
|
28
|
+
args: constructorArgs,
|
|
29
|
+
address: amm.address
|
|
30
|
+
}
|
|
31
|
+
]);
|
|
32
|
+
expect(ammConstructorResult.revertCode.isOK()).toBe(true);
|
|
33
|
+
logger.debug(`Setting AMM as minter for liquidity token`);
|
|
34
|
+
// set the AMM as the minter for the liquidity token
|
|
35
|
+
const setMinterResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'set_minter', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
36
|
+
{
|
|
37
|
+
fnName: 'set_minter',
|
|
38
|
+
args: [
|
|
39
|
+
/*minter=*/ amm,
|
|
40
|
+
/*approve=*/ true
|
|
41
|
+
],
|
|
42
|
+
address: liquidityToken.address
|
|
43
|
+
}
|
|
44
|
+
]);
|
|
45
|
+
expect(setMinterResult.revertCode.isOK()).toBe(true);
|
|
46
|
+
logger.debug(`Adding liquidity`);
|
|
47
|
+
const amount0Max = INITIAL_TOKEN_BALANCE * 6n / 10n;
|
|
48
|
+
const amount0Min = INITIAL_TOKEN_BALANCE * 4n / 10n;
|
|
49
|
+
const amount1Max = INITIAL_TOKEN_BALANCE * 5n / 10n;
|
|
50
|
+
const amount1Min = INITIAL_TOKEN_BALANCE * 4n / 10n;
|
|
51
|
+
const addLiquidityResult = await addLiquidity(tester, sender, /*amm=*/ amm, /*token0=*/ token0, /*token1=*/ token1, /*liquidityToken=*/ liquidityToken, /*amount0Max=*/ amount0Max, /*amount1Max=*/ amount1Max, /*amount0Min=*/ amount0Min, /*amount1Min=*/ amount1Min);
|
|
52
|
+
expect(addLiquidityResult.revertCode.isOK()).toBe(true);
|
|
53
|
+
logger.debug(`Swapping tokens`);
|
|
54
|
+
const swapResult = await swapExactTokensForTokens(tester, sender, /*amm=*/ amm, /*tokenIn=*/ token0, /*tokenOut=*/ token1, /*amountIn=*/ amount0Min / 10n, /*amountOutMin=*/ amount1Min / 100n);
|
|
55
|
+
expect(swapResult.revertCode.isOK()).toBe(true);
|
|
56
|
+
logger.debug(`Removing liquidity`);
|
|
57
|
+
const removeLiquidityResult = await removeLiquidity(tester, sender, /*amm=*/ amm, /*token0=*/ token0, /*token1=*/ token1, /*liquidityToken=*/ liquidityToken, /*liquidity=*/ 100n, /*amount0Min=*/ 1n, /*amount1Min=*/ 1n);
|
|
58
|
+
expect(removeLiquidityResult.revertCode.isOK()).toBe(true);
|
|
59
|
+
const endTime = performance.now();
|
|
60
|
+
logger.info(`AMM public tx simulator test took ${endTime - startTime}ms\n`);
|
|
61
|
+
}
|
|
62
|
+
async function addLiquidity(tester, sender, amm, token0, token1, liquidityToken, amount0Max, amount1Max, amount0Min, amount1Min, _nonce) {
|
|
63
|
+
const refundToken0PartialNote = {
|
|
64
|
+
commitment: new Fr(42)
|
|
65
|
+
};
|
|
66
|
+
const refundToken1PartialNote = {
|
|
67
|
+
commitment: new Fr(66)
|
|
68
|
+
};
|
|
69
|
+
const liquidityPartialNote = {
|
|
70
|
+
commitment: new Fr(99)
|
|
71
|
+
};
|
|
72
|
+
return await tester.simulateTxWithLabel(/*txLabel=*/ 'add_liquidity', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
73
|
+
// token0.transfer_to_public enqueues a call to _increase_public_balance
|
|
74
|
+
{
|
|
75
|
+
sender: token0.address,
|
|
76
|
+
fnName: '_increase_public_balance',
|
|
77
|
+
args: [
|
|
78
|
+
/*to=*/ amm.address,
|
|
79
|
+
/*amount=*/ amount0Max
|
|
80
|
+
],
|
|
81
|
+
address: token0.address
|
|
82
|
+
},
|
|
83
|
+
// token0.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
84
|
+
{
|
|
85
|
+
sender: token0.address,
|
|
86
|
+
fnName: '_store_balances_set_partial_note',
|
|
87
|
+
args: [
|
|
88
|
+
refundToken0PartialNote
|
|
89
|
+
],
|
|
90
|
+
address: token0.address
|
|
91
|
+
},
|
|
92
|
+
// token1.transfer_to_public enqueues a call to _increase_public_balance
|
|
93
|
+
{
|
|
94
|
+
sender: token1.address,
|
|
95
|
+
fnName: '_increase_public_balance',
|
|
96
|
+
args: [
|
|
97
|
+
/*to=*/ amm.address,
|
|
98
|
+
/*amount=*/ amount1Max
|
|
99
|
+
],
|
|
100
|
+
address: token1.address
|
|
101
|
+
},
|
|
102
|
+
// token1.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
103
|
+
{
|
|
104
|
+
sender: token1.address,
|
|
105
|
+
fnName: '_store_balances_set_partial_note',
|
|
106
|
+
args: [
|
|
107
|
+
refundToken1PartialNote
|
|
108
|
+
],
|
|
109
|
+
address: token1.address
|
|
110
|
+
},
|
|
111
|
+
// liquidityToken.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
112
|
+
{
|
|
113
|
+
sender: liquidityToken.address,
|
|
114
|
+
fnName: '_store_balances_set_partial_note',
|
|
115
|
+
args: [
|
|
116
|
+
liquidityPartialNote
|
|
117
|
+
],
|
|
118
|
+
address: liquidityToken.address
|
|
119
|
+
},
|
|
120
|
+
// amm.add_liquidity enqueues a call to _add_liquidity
|
|
121
|
+
{
|
|
122
|
+
sender: amm.address,
|
|
123
|
+
fnName: '_add_liquidity',
|
|
124
|
+
args: [
|
|
125
|
+
/*config=*/ {
|
|
126
|
+
token0: token0.address,
|
|
127
|
+
token1: token1.address,
|
|
128
|
+
// eslint-disable-next-line camelcase
|
|
129
|
+
liquidity_token: liquidityToken.address
|
|
130
|
+
},
|
|
131
|
+
refundToken0PartialNote,
|
|
132
|
+
refundToken1PartialNote,
|
|
133
|
+
liquidityPartialNote,
|
|
134
|
+
amount0Max,
|
|
135
|
+
amount1Max,
|
|
136
|
+
amount0Min,
|
|
137
|
+
amount1Min
|
|
138
|
+
],
|
|
139
|
+
address: amm.address
|
|
140
|
+
}
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
async function swapExactTokensForTokens(tester, sender, amm, tokenIn, tokenOut, amountIn, amountOutMin, _nonce) {
|
|
144
|
+
const tokenOutPartialNote = {
|
|
145
|
+
commitment: new Fr(66)
|
|
146
|
+
};
|
|
147
|
+
return await tester.simulateTxWithLabel(/*txLabel=*/ 'swap_exact_tokens_for_tokens', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
148
|
+
// tokenIn.transfer_to_public enqueues a call to _increase_public_balance
|
|
149
|
+
{
|
|
150
|
+
sender: tokenIn.address,
|
|
151
|
+
fnName: '_increase_public_balance',
|
|
152
|
+
args: [
|
|
153
|
+
/*to=*/ amm.address,
|
|
154
|
+
/*amount=*/ amountIn
|
|
155
|
+
],
|
|
156
|
+
address: tokenIn.address
|
|
157
|
+
},
|
|
158
|
+
// tokenOut.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
159
|
+
{
|
|
160
|
+
sender: tokenOut.address,
|
|
161
|
+
fnName: '_store_balances_set_partial_note',
|
|
162
|
+
args: [
|
|
163
|
+
tokenOutPartialNote
|
|
164
|
+
],
|
|
165
|
+
address: tokenOut.address
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
sender: amm.address,
|
|
169
|
+
fnName: '_swap_exact_tokens_for_tokens',
|
|
170
|
+
args: [
|
|
171
|
+
tokenIn.address,
|
|
172
|
+
tokenOut.address,
|
|
173
|
+
amountIn,
|
|
174
|
+
amountOutMin,
|
|
175
|
+
tokenOutPartialNote
|
|
176
|
+
],
|
|
177
|
+
address: amm.address
|
|
178
|
+
}
|
|
179
|
+
]);
|
|
180
|
+
}
|
|
181
|
+
async function removeLiquidity(tester, sender, amm, token0, token1, liquidityToken, liquidity, amount0Min, amount1Min, _nonce) {
|
|
182
|
+
const token0PartialNote = {
|
|
183
|
+
commitment: new Fr(111)
|
|
184
|
+
};
|
|
185
|
+
const token1PartialNote = {
|
|
186
|
+
commitment: new Fr(222)
|
|
187
|
+
};
|
|
188
|
+
return await tester.simulateTxWithLabel(/*txLabel=*/ 'remove_liquidity', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
189
|
+
// liquidityToken.transfer_to_public enqueues a call to _increase_public_balance
|
|
190
|
+
{
|
|
191
|
+
sender: liquidityToken.address,
|
|
192
|
+
fnName: '_increase_public_balance',
|
|
193
|
+
args: [
|
|
194
|
+
/*to=*/ amm.address,
|
|
195
|
+
/*amount=*/ liquidity
|
|
196
|
+
],
|
|
197
|
+
address: liquidityToken.address
|
|
198
|
+
},
|
|
199
|
+
// token0.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
200
|
+
{
|
|
201
|
+
sender: token0.address,
|
|
202
|
+
fnName: '_store_balances_set_partial_note',
|
|
203
|
+
args: [
|
|
204
|
+
token0PartialNote
|
|
205
|
+
],
|
|
206
|
+
address: token0.address
|
|
207
|
+
},
|
|
208
|
+
// token1.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
209
|
+
{
|
|
210
|
+
sender: token1.address,
|
|
211
|
+
fnName: '_store_balances_set_partial_note',
|
|
212
|
+
args: [
|
|
213
|
+
token1PartialNote
|
|
214
|
+
],
|
|
215
|
+
address: token1.address
|
|
216
|
+
},
|
|
217
|
+
// amm.remove_liquidity enqueues a call to _remove_liquidity
|
|
218
|
+
{
|
|
219
|
+
sender: amm.address,
|
|
220
|
+
fnName: '_remove_liquidity',
|
|
221
|
+
args: [
|
|
222
|
+
/*config=*/ {
|
|
223
|
+
token0: token0.address,
|
|
224
|
+
token1: token1.address,
|
|
225
|
+
// eslint-disable-next-line camelcase
|
|
226
|
+
liquidity_token: liquidityToken.address
|
|
227
|
+
},
|
|
228
|
+
liquidity,
|
|
229
|
+
token0PartialNote,
|
|
230
|
+
token1PartialNote,
|
|
231
|
+
amount0Min,
|
|
232
|
+
amount1Min
|
|
233
|
+
],
|
|
234
|
+
address: amm.address
|
|
235
|
+
}
|
|
236
|
+
]);
|
|
237
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
4
|
+
import { PublicTxSimulationTester } from '../../fixtures/public_tx_simulation_tester.js';
|
|
5
|
+
export declare function tokenTest(tester: PublicTxSimulationTester, logger: Logger): Promise<void>;
|
|
6
|
+
export declare function deployToken(tester: PublicTxSimulationTester, admin: AztecAddress, seed?: number): Promise<ContractInstanceWithAddress>;
|
|
7
|
+
//# sourceMappingURL=token_test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token_test.d.ts","sourceRoot":"","sources":["../../../../src/public/public_tx_simulator/apps_tests/token_test.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAEzF,wBAAsB,SAAS,CAAC,MAAM,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,iBA4E/E;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,wBAAwB,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,SAAI,wCAwBhG"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
export async function tokenTest(tester, logger) {
|
|
5
|
+
const startTime = performance.now();
|
|
6
|
+
const admin = AztecAddress.fromNumber(42);
|
|
7
|
+
const sender = AztecAddress.fromNumber(111);
|
|
8
|
+
const receiver = AztecAddress.fromNumber(222);
|
|
9
|
+
const token = await deployToken(tester, admin);
|
|
10
|
+
const mintAmount = 100n;
|
|
11
|
+
const mintResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'mint_to_public', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
12
|
+
{
|
|
13
|
+
address: token.address,
|
|
14
|
+
fnName: 'mint_to_public',
|
|
15
|
+
args: [
|
|
16
|
+
/*to=*/ sender,
|
|
17
|
+
mintAmount
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
]);
|
|
21
|
+
expect(mintResult.revertCode.isOK()).toBe(true);
|
|
22
|
+
await checkBalance(tester, token, sender, sender, mintAmount);
|
|
23
|
+
const nonce = new Fr(0);
|
|
24
|
+
const transferAmount = 50n;
|
|
25
|
+
const transferResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'transfer_in_public', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
26
|
+
{
|
|
27
|
+
address: token.address,
|
|
28
|
+
fnName: 'transfer_in_public',
|
|
29
|
+
args: [
|
|
30
|
+
/*from=*/ sender,
|
|
31
|
+
/*to=*/ receiver,
|
|
32
|
+
transferAmount,
|
|
33
|
+
nonce
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
]);
|
|
37
|
+
expect(transferResult.revertCode.isOK()).toBe(true);
|
|
38
|
+
await checkBalance(tester, token, sender, receiver, mintAmount - transferAmount);
|
|
39
|
+
await checkBalance(tester, token, sender, receiver, transferAmount);
|
|
40
|
+
const balResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'balance_of_public', sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
41
|
+
{
|
|
42
|
+
address: token.address,
|
|
43
|
+
fnName: 'balance_of_public',
|
|
44
|
+
args: [
|
|
45
|
+
/*owner=*/ receiver
|
|
46
|
+
],
|
|
47
|
+
isStaticCall: true
|
|
48
|
+
}
|
|
49
|
+
]);
|
|
50
|
+
expect(balResult.revertCode.isOK()).toBe(true);
|
|
51
|
+
const burnResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'burn_public', /*sender=*/ receiver, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
52
|
+
{
|
|
53
|
+
address: token.address,
|
|
54
|
+
fnName: 'burn_public',
|
|
55
|
+
args: [
|
|
56
|
+
/*from=*/ receiver,
|
|
57
|
+
transferAmount,
|
|
58
|
+
nonce
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
]);
|
|
62
|
+
expect(burnResult.revertCode.isOK()).toBe(true);
|
|
63
|
+
await checkBalance(tester, token, sender, receiver, 0n);
|
|
64
|
+
const endTime = performance.now();
|
|
65
|
+
logger.info(`TokenContract public tx simulator test took ${endTime - startTime}ms\n`);
|
|
66
|
+
}
|
|
67
|
+
export async function deployToken(tester, admin, seed = 0) {
|
|
68
|
+
const constructorArgs = [
|
|
69
|
+
admin,
|
|
70
|
+
/*name=*/ 'Token',
|
|
71
|
+
/*symbol=*/ 'TOK',
|
|
72
|
+
/*decimals=*/ new Fr(18)
|
|
73
|
+
];
|
|
74
|
+
const token = await tester.registerAndDeployContract(constructorArgs, /*deployer=*/ admin, TokenContractArtifact, /*skipNullifierInsertion=*/ false, seed);
|
|
75
|
+
const result = await tester.simulateTxWithLabel(/*txLabel=*/ 'Token.constructor', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
76
|
+
{
|
|
77
|
+
fnName: 'constructor',
|
|
78
|
+
args: constructorArgs,
|
|
79
|
+
address: token.address
|
|
80
|
+
}
|
|
81
|
+
]);
|
|
82
|
+
expect(result.revertCode.isOK()).toBe(true);
|
|
83
|
+
return token;
|
|
84
|
+
}
|
|
85
|
+
async function checkBalance(tester, token, sender, account, expectedBalance) {
|
|
86
|
+
const balResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'balance_of_public', sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
87
|
+
{
|
|
88
|
+
address: token.address,
|
|
89
|
+
fnName: 'balance_of_public',
|
|
90
|
+
args: [
|
|
91
|
+
/*owner=*/ account
|
|
92
|
+
],
|
|
93
|
+
isStaticCall: true
|
|
94
|
+
}
|
|
95
|
+
]);
|
|
96
|
+
expect(balResult.revertCode.isOK()).toBe(true);
|
|
97
|
+
// should be 1 call with 1 return value that is expectedBalance
|
|
98
|
+
expect(balResult.processedPhases).toEqual([
|
|
99
|
+
expect.objectContaining({
|
|
100
|
+
returnValues: [
|
|
101
|
+
expect.objectContaining({
|
|
102
|
+
values: [
|
|
103
|
+
new Fr(expectedBalance)
|
|
104
|
+
]
|
|
105
|
+
})
|
|
106
|
+
]
|
|
107
|
+
})
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { Gas } from '@aztec/stdlib/gas';
|
|
3
|
+
import { type GlobalVariables, PublicCallRequestWithCalldata, Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
|
|
4
|
+
import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
|
|
5
|
+
import type { ExecutorMetricsInterface } from '../executor_metrics_interface.js';
|
|
6
|
+
import type { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
|
|
7
|
+
import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
8
|
+
import { PublicTxContext } from './public_tx_context.js';
|
|
9
|
+
import { type ProcessedPhase, type PublicTxResult, PublicTxSimulator } from './public_tx_simulator.js';
|
|
10
|
+
/**
|
|
11
|
+
* A public tx simulator that tracks miscellaneous simulation metrics without telemetry.
|
|
12
|
+
*/
|
|
13
|
+
export declare class MeasuredPublicTxSimulator extends PublicTxSimulator {
|
|
14
|
+
protected readonly metrics: ExecutorMetricsInterface;
|
|
15
|
+
constructor(treesDB: PublicTreesDB, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations: boolean | undefined, skipFeeEnforcement: boolean | undefined, metrics: ExecutorMetricsInterface);
|
|
16
|
+
simulate(tx: Tx, txLabel?: string): Promise<PublicTxResult>;
|
|
17
|
+
protected computeTxHash(tx: Tx): Promise<import("@aztec/stdlib/tx").TxHash>;
|
|
18
|
+
protected insertNonRevertiblesFromPrivate(context: PublicTxContext, tx: Tx): Promise<void>;
|
|
19
|
+
protected insertRevertiblesFromPrivate(context: PublicTxContext, tx: Tx): Promise<boolean>;
|
|
20
|
+
protected simulatePhase(phase: TxExecutionPhase, context: PublicTxContext): Promise<ProcessedPhase>;
|
|
21
|
+
protected simulateEnqueuedCallInternal(stateManager: PublicPersistableStateManager, callRequest: PublicCallRequestWithCalldata, allocatedGas: Gas, transactionFee: Fr, fnName: string): Promise<AvmFinalizedCallResult>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=measured_public_tx_simulator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measured_public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/measured_public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,KAAK,eAAe,EAAE,6BAA6B,EAAE,EAAE,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE7G,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAEvG;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,iBAAiB;IAO5D,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,wBAAwB;gBALpD,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,qBAAiB,EACnC,kBAAkB,qBAAiB,EAChB,OAAO,EAAE,wBAAwB;IAKhC,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,GAAE,MAAsB,GAAG,OAAO,CAAC,cAAc,CAAC;cAWvE,aAAa,CAAC,EAAE,EAAE,EAAE;cAOpB,+BAA+B,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE;cAMhE,4BAA4B,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;cAOhF,aAAa,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;cAOzF,4BAA4B,CACnD,YAAY,EAAE,6BAA6B,EAC3C,WAAW,EAAE,6BAA6B,EAC1C,YAAY,EAAE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC;CAsCnC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
2
|
+
import { PublicTxSimulator } from './public_tx_simulator.js';
|
|
3
|
+
/**
|
|
4
|
+
* A public tx simulator that tracks miscellaneous simulation metrics without telemetry.
|
|
5
|
+
*/ export class MeasuredPublicTxSimulator extends PublicTxSimulator {
|
|
6
|
+
metrics;
|
|
7
|
+
constructor(treesDB, contractsDB, globalVariables, doMerkleOperations = false, skipFeeEnforcement = false, metrics){
|
|
8
|
+
super(treesDB, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement), this.metrics = metrics;
|
|
9
|
+
}
|
|
10
|
+
async simulate(tx, txLabel = 'unlabeledTx') {
|
|
11
|
+
this.metrics.startRecordingTxSimulation(txLabel);
|
|
12
|
+
let avmResult;
|
|
13
|
+
try {
|
|
14
|
+
avmResult = await super.simulate(tx);
|
|
15
|
+
} finally{
|
|
16
|
+
this.metrics.stopRecordingTxSimulation(txLabel, avmResult?.revertCode);
|
|
17
|
+
}
|
|
18
|
+
return avmResult;
|
|
19
|
+
}
|
|
20
|
+
async computeTxHash(tx) {
|
|
21
|
+
const timer = new Timer();
|
|
22
|
+
const txHash = await super.computeTxHash(tx);
|
|
23
|
+
this.metrics.recordTxHashComputation(timer.ms());
|
|
24
|
+
return txHash;
|
|
25
|
+
}
|
|
26
|
+
async insertNonRevertiblesFromPrivate(context, tx) {
|
|
27
|
+
const timer = new Timer();
|
|
28
|
+
await super.insertNonRevertiblesFromPrivate(context, tx);
|
|
29
|
+
this.metrics.recordPrivateEffectsInsertion(timer.us(), 'non-revertible');
|
|
30
|
+
}
|
|
31
|
+
async insertRevertiblesFromPrivate(context, tx) {
|
|
32
|
+
const timer = new Timer();
|
|
33
|
+
const result = await super.insertRevertiblesFromPrivate(context, tx);
|
|
34
|
+
this.metrics.recordPrivateEffectsInsertion(timer.us(), 'revertible');
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
async simulatePhase(phase, context) {
|
|
38
|
+
const timer = new Timer();
|
|
39
|
+
const result = await super.simulatePhase(phase, context);
|
|
40
|
+
result.durationMs = timer.ms();
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
async simulateEnqueuedCallInternal(stateManager, callRequest, allocatedGas, transactionFee, fnName) {
|
|
44
|
+
const timer = new Timer();
|
|
45
|
+
const result = await super.simulateEnqueuedCallInternal(stateManager, callRequest, allocatedGas, transactionFee, fnName);
|
|
46
|
+
this.log.verbose(result.reverted ? `Simulation of enqueued public call ${fnName} reverted with reason ${result.revertReason}.` : `Simulation of enqueued public call ${fnName} completed successfully.`, {
|
|
47
|
+
eventName: 'avm-simulation',
|
|
48
|
+
appCircuitName: fnName,
|
|
49
|
+
duration: timer.ms()
|
|
50
|
+
});
|
|
51
|
+
if (result.reverted) {
|
|
52
|
+
this.metrics.recordEnqueuedCallSimulationFailure(fnName, timer.ms(), allocatedGas.sub(result.gasLeft).l2Gas, result.totalInstructions);
|
|
53
|
+
} else {
|
|
54
|
+
this.metrics.recordEnqueuedCallSimulation(fnName, timer.ms(), allocatedGas.sub(result.gasLeft).l2Gas, result.totalInstructions);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -4,10 +4,10 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
4
4
|
import type { SimulationError } from '@aztec/stdlib/errors';
|
|
5
5
|
import { Gas } from '@aztec/stdlib/gas';
|
|
6
6
|
import { type PrivateToPublicAccumulatedData } from '@aztec/stdlib/kernel';
|
|
7
|
-
import { type GlobalVariables, PublicCallRequestWithCalldata, type
|
|
7
|
+
import { type GlobalVariables, PublicCallRequestWithCalldata, type Tx, TxExecutionPhase, type TxHash } from '@aztec/stdlib/tx';
|
|
8
8
|
import type { PublicContractsDBInterface } from '../../server.js';
|
|
9
|
-
import { AvmPersistableStateManager } from '../avm/index.js';
|
|
10
9
|
import type { PublicTreesDB } from '../public_db_sources.js';
|
|
10
|
+
import { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
11
11
|
/**
|
|
12
12
|
* The transaction-level context for public execution.
|
|
13
13
|
*/
|
|
@@ -98,7 +98,7 @@ export declare class PublicTxContext {
|
|
|
98
98
|
/**
|
|
99
99
|
* Generate the public inputs for the AVM circuit.
|
|
100
100
|
*/
|
|
101
|
-
generateAvmCircuitPublicInputs(
|
|
101
|
+
generateAvmCircuitPublicInputs(): Promise<AvmCircuitPublicInputs>;
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* Thin wrapper around the state manager to handle forking and merging for phases.
|
|
@@ -114,9 +114,9 @@ declare class PhaseStateManager {
|
|
|
114
114
|
private readonly txStateManager;
|
|
115
115
|
private log;
|
|
116
116
|
private currentlyActiveStateManager;
|
|
117
|
-
constructor(txStateManager:
|
|
117
|
+
constructor(txStateManager: PublicPersistableStateManager);
|
|
118
118
|
fork(): Promise<void>;
|
|
119
|
-
getActiveStateManager():
|
|
119
|
+
getActiveStateManager(): PublicPersistableStateManager;
|
|
120
120
|
isForked(): boolean;
|
|
121
121
|
mergeForkedState(): Promise<void>;
|
|
122
122
|
discardForkedState(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_tx_context.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_context.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,EAAE,KAAK,sBAAsB,EAAE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