@aztec/simulator 0.56.0 → 0.58.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 +2 -5
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +7 -38
- package/dest/acvm/oracle/typed_oracle.d.ts +4 -8
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +1 -10
- package/dest/avm/avm_execution_environment.d.ts +2 -3
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +3 -4
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +2 -3
- package/dest/avm/avm_memory_types.d.ts +10 -5
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +31 -16
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +5 -2
- package/dest/avm/errors.d.ts +1 -1
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +12 -3
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +4 -4
- package/dest/avm/journal/journal.d.ts +2 -1
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +8 -8
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +54 -47
- package/dest/avm/opcodes/addressing_mode.d.ts +3 -2
- package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/avm/opcodes/addressing_mode.js +25 -21
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +7 -6
- package/dest/avm/opcodes/bitwise.d.ts +3 -3
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +19 -16
- package/dest/avm/opcodes/commitment.d.ts.map +1 -1
- package/dest/avm/opcodes/commitment.js +6 -5
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +7 -6
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +8 -6
- package/dest/avm/opcodes/control_flow.js +7 -7
- package/dest/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/avm/opcodes/conversion.js +11 -10
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/avm/opcodes/ec_add.js +25 -15
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +6 -5
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +37 -26
- package/dest/avm/opcodes/hashing.d.ts +1 -3
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +39 -48
- package/dest/avm/opcodes/instruction.d.ts +2 -6
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +3 -9
- package/dest/avm/opcodes/instruction_impl.d.ts +1 -2
- package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction_impl.js +2 -5
- package/dest/avm/opcodes/memory.d.ts +0 -12
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +24 -54
- package/dest/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/avm/opcodes/misc.js +10 -9
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
- package/dest/avm/opcodes/multi_scalar_mul.js +35 -20
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +13 -11
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +2 -3
- package/dest/avm/serialization/instruction_serialization.d.ts +32 -34
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +34 -37
- package/dest/avm/test_utils.d.ts +1 -2
- package/dest/avm/test_utils.d.ts.map +1 -1
- package/dest/avm/test_utils.js +1 -1
- package/dest/client/client_execution_context.d.ts +6 -30
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +36 -54
- package/dest/client/db_oracle.d.ts +1 -2
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/index.d.ts +1 -1
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +2 -2
- package/dest/client/private_execution.d.ts +12 -3
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +29 -23
- package/dest/client/simulator.d.ts +2 -3
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +1 -1
- package/dest/client/view_data_oracle.d.ts +1 -2
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +1 -1
- package/dest/common/debug_fn_name.d.ts +4 -0
- package/dest/common/debug_fn_name.d.ts.map +1 -0
- package/dest/common/debug_fn_name.js +15 -0
- package/dest/common/index.d.ts +0 -1
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +1 -2
- package/dest/public/db_interfaces.d.ts +1 -2
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/dual_side_effect_trace.d.ts +76 -0
- package/dest/public/dual_side_effect_trace.d.ts.map +1 -0
- package/dest/public/dual_side_effect_trace.js +109 -0
- package/dest/public/enqueued_call_side_effect_trace.d.ts +114 -0
- package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -0
- package/dest/public/enqueued_call_side_effect_trace.js +314 -0
- package/dest/public/enqueued_call_simulator.d.ts +2 -2
- package/dest/public/enqueued_call_simulator.d.ts.map +1 -1
- package/dest/public/enqueued_call_simulator.js +20 -10
- package/dest/public/enqueued_calls_processor.d.ts +2 -2
- package/dest/public/enqueued_calls_processor.d.ts.map +1 -1
- package/dest/public/enqueued_calls_processor.js +3 -5
- package/dest/public/execution.d.ts +11 -5
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +13 -1
- package/dest/public/executor.d.ts +7 -6
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +24 -15
- package/dest/public/fee_payment.d.ts +1 -1
- package/dest/public/fee_payment.d.ts.map +1 -1
- package/dest/public/fee_payment.js +4 -7
- package/dest/public/hints_builder.d.ts +2 -2
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +2 -2
- package/dest/public/public_db_sources.d.ts +4 -5
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +15 -11
- package/dest/public/public_kernel_tail_simulator.d.ts +3 -3
- package/dest/public/public_kernel_tail_simulator.d.ts.map +1 -1
- package/dest/public/public_kernel_tail_simulator.js +1 -1
- package/dest/public/public_processor.d.ts +7 -10
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +9 -10
- package/dest/public/side_effect_errors.d.ts +4 -0
- package/dest/public/side_effect_errors.d.ts.map +1 -0
- package/dest/public/side_effect_errors.js +7 -0
- package/dest/public/side_effect_trace.d.ts +3 -4
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +54 -29
- package/dest/public/side_effect_trace_interface.d.ts +1 -1
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/package.json +12 -9
- package/src/acvm/oracle/oracle.ts +8 -86
- package/src/acvm/oracle/typed_oracle.ts +8 -33
- package/src/avm/avm_execution_environment.ts +1 -3
- package/src/avm/avm_gas.ts +1 -2
- package/src/avm/avm_memory_types.ts +38 -16
- package/src/avm/avm_simulator.ts +7 -1
- package/src/avm/errors.ts +11 -3
- package/src/avm/fixtures/index.ts +2 -3
- package/src/avm/journal/journal.ts +14 -10
- package/src/avm/opcodes/accrued_substate.ts +53 -61
- package/src/avm/opcodes/addressing_mode.ts +27 -24
- package/src/avm/opcodes/arithmetic.ts +6 -8
- package/src/avm/opcodes/bitwise.ts +18 -18
- package/src/avm/opcodes/commitment.ts +6 -7
- package/src/avm/opcodes/comparators.ts +6 -8
- package/src/avm/opcodes/contract.ts +7 -8
- package/src/avm/opcodes/control_flow.ts +6 -6
- package/src/avm/opcodes/conversion.ts +10 -12
- package/src/avm/opcodes/ec_add.ts +29 -24
- package/src/avm/opcodes/environment_getters.ts +5 -4
- package/src/avm/opcodes/external_calls.ts +37 -30
- package/src/avm/opcodes/hashing.ts +38 -63
- package/src/avm/opcodes/instruction.ts +3 -10
- package/src/avm/opcodes/instruction_impl.ts +0 -3
- package/src/avm/opcodes/memory.ts +23 -67
- package/src/avm/opcodes/misc.ts +9 -11
- package/src/avm/opcodes/multi_scalar_mul.ts +31 -26
- package/src/avm/opcodes/storage.ts +12 -10
- package/src/avm/serialization/bytecode_serialization.ts +0 -2
- package/src/avm/serialization/instruction_serialization.ts +1 -4
- package/src/avm/test_utils.ts +1 -2
- package/src/client/client_execution_context.ts +46 -97
- package/src/client/db_oracle.ts +6 -2
- package/src/client/index.ts +1 -1
- package/src/client/private_execution.ts +45 -15
- package/src/client/simulator.ts +2 -3
- package/src/client/view_data_oracle.ts +1 -2
- package/src/common/debug_fn_name.ts +22 -0
- package/src/common/index.ts +0 -1
- package/src/public/db_interfaces.ts +5 -2
- package/src/public/dual_side_effect_trace.ts +173 -0
- package/src/public/enqueued_call_side_effect_trace.ts +552 -0
- package/src/public/enqueued_call_simulator.ts +35 -14
- package/src/public/enqueued_calls_processor.ts +4 -6
- package/src/public/execution.ts +15 -6
- package/src/public/executor.ts +42 -19
- package/src/public/fee_payment.ts +4 -6
- package/src/public/hints_builder.ts +9 -11
- package/src/public/public_db_sources.ts +31 -22
- package/src/public/public_kernel_tail_simulator.ts +3 -3
- package/src/public/public_processor.ts +17 -13
- package/src/public/side_effect_errors.ts +6 -0
- package/src/public/side_effect_trace.ts +74 -29
- package/src/public/side_effect_trace_interface.ts +2 -2
- package/dest/client/execution_result.d.ts +0 -104
- package/dest/client/execution_result.d.ts.map +0 -1
- package/dest/client/execution_result.js +0 -136
- package/dest/common/return_values.d.ts +0 -11
- package/dest/common/return_values.d.ts.map +0 -1
- package/dest/common/return_values.js +0 -13
- package/src/client/execution_result.ts +0 -228
- package/src/common/return_values.ts +0 -18
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
2
|
+
type MerkleTreeReadOperations,
|
|
3
3
|
type NestedProcessReturnValues,
|
|
4
4
|
type ProcessedTx,
|
|
5
5
|
ProvingRequestType,
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
} from '@aztec/circuits.js';
|
|
29
29
|
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
30
30
|
import { Timer } from '@aztec/foundation/timer';
|
|
31
|
-
import { ProtocolCircuitVks, getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types';
|
|
31
|
+
import { ProtocolCircuitVks, TubeVk, getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types';
|
|
32
32
|
|
|
33
33
|
import { inspect } from 'util';
|
|
34
34
|
|
|
@@ -93,7 +93,7 @@ export class EnqueuedCallsProcessor {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
static create(
|
|
96
|
-
db:
|
|
96
|
+
db: MerkleTreeReadOperations,
|
|
97
97
|
publicExecutor: PublicExecutor,
|
|
98
98
|
publicKernelSimulator: PublicKernelCircuitSimulator,
|
|
99
99
|
globalVariables: GlobalVariables,
|
|
@@ -377,9 +377,7 @@ export class EnqueuedCallsProcessor {
|
|
|
377
377
|
// The proof is not used in simulation.
|
|
378
378
|
const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH);
|
|
379
379
|
|
|
380
|
-
const vk = isFromPrivate
|
|
381
|
-
? ProtocolCircuitVks.PrivateKernelTailToPublicArtifact
|
|
382
|
-
: ProtocolCircuitVks.PublicKernelMergeArtifact;
|
|
380
|
+
const vk = isFromPrivate ? TubeVk : ProtocolCircuitVks.PublicKernelMergeArtifact;
|
|
383
381
|
const vkIndex = getVKIndex(vk);
|
|
384
382
|
const siblingPath = getVKSiblingPath(vkIndex);
|
|
385
383
|
|
package/src/public/execution.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
NestedProcessReturnValues,
|
|
2
3
|
type PublicExecutionRequest,
|
|
3
4
|
type SimulationError,
|
|
4
5
|
type UnencryptedFunctionL2Logs,
|
|
@@ -21,8 +22,6 @@ import {
|
|
|
21
22
|
} from '@aztec/circuits.js';
|
|
22
23
|
import { computeVarArgsHash } from '@aztec/circuits.js/hash';
|
|
23
24
|
|
|
24
|
-
import { type Gas as AvmGas } from '../avm/avm_gas.js';
|
|
25
|
-
|
|
26
25
|
/**
|
|
27
26
|
* The public function execution result.
|
|
28
27
|
*/
|
|
@@ -35,9 +34,9 @@ export interface PublicExecutionResult {
|
|
|
35
34
|
/** The side effect counter after executing this function call */
|
|
36
35
|
endSideEffectCounter: Fr;
|
|
37
36
|
/** How much gas was available for this public execution. */
|
|
38
|
-
startGasLeft:
|
|
37
|
+
startGasLeft: Gas;
|
|
39
38
|
/** How much gas was left after this public execution. */
|
|
40
|
-
endGasLeft:
|
|
39
|
+
endGasLeft: Gas;
|
|
41
40
|
/** Transaction fee set for this tx. */
|
|
42
41
|
transactionFee: Fr;
|
|
43
42
|
|
|
@@ -86,8 +85,6 @@ export interface PublicExecutionResult {
|
|
|
86
85
|
*/
|
|
87
86
|
allUnencryptedLogs: UnencryptedFunctionL2Logs;
|
|
88
87
|
|
|
89
|
-
// TODO(dbanks12): add contract instance read requests
|
|
90
|
-
|
|
91
88
|
/** The requests to call public functions made by this call. */
|
|
92
89
|
publicCallRequests: PublicInnerCallRequest[];
|
|
93
90
|
/** The results of nested calls. */
|
|
@@ -100,6 +97,18 @@ export interface PublicExecutionResult {
|
|
|
100
97
|
functionName: string;
|
|
101
98
|
}
|
|
102
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Recursively accummulate the return values of a call result and its nested executions,
|
|
102
|
+
* so they can be retrieved in order.
|
|
103
|
+
* @param executionResult
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
export function accumulatePublicReturnValues(executionResult: PublicExecutionResult): NestedProcessReturnValues {
|
|
107
|
+
const acc = new NestedProcessReturnValues(executionResult.returnValues);
|
|
108
|
+
acc.nested = executionResult.nestedExecutions.map(nestedExecution => accumulatePublicReturnValues(nestedExecution));
|
|
109
|
+
return acc;
|
|
110
|
+
}
|
|
111
|
+
|
|
103
112
|
export function collectExecutionResults(result: PublicExecutionResult): PublicExecutionResult[] {
|
|
104
113
|
return [result, ...result.nestedExecutions.map(collectExecutionResults)].flat();
|
|
105
114
|
}
|
package/src/public/executor.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { type PublicExecutionRequest } from '@aztec/circuit-types';
|
|
2
2
|
import { type AvmSimulationStats } from '@aztec/circuit-types/stats';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type CombinedConstantData,
|
|
5
|
+
Fr,
|
|
6
|
+
Gas,
|
|
7
|
+
type GlobalVariables,
|
|
8
|
+
type Nullifier,
|
|
9
|
+
PublicAccumulatedDataArrayLengths,
|
|
10
|
+
PublicValidationRequestArrayLengths,
|
|
11
|
+
type TxContext,
|
|
12
|
+
} from '@aztec/circuits.js';
|
|
4
13
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
5
14
|
import { Timer } from '@aztec/foundation/timer';
|
|
6
15
|
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
@@ -10,6 +19,9 @@ import { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
|
|
|
10
19
|
import { AvmMachineState } from '../avm/avm_machine_state.js';
|
|
11
20
|
import { AvmSimulator } from '../avm/avm_simulator.js';
|
|
12
21
|
import { AvmPersistableStateManager } from '../avm/journal/index.js';
|
|
22
|
+
import { getPublicFunctionDebugName } from '../common/debug_fn_name.js';
|
|
23
|
+
import { DualSideEffectTrace } from './dual_side_effect_trace.js';
|
|
24
|
+
import { PublicEnqueuedCallSideEffectTrace } from './enqueued_call_side_effect_trace.js';
|
|
13
25
|
import { type PublicExecutionResult } from './execution.js';
|
|
14
26
|
import { ExecutorMetrics } from './executor_metrics.js';
|
|
15
27
|
import { type WorldStateDB } from './public_db_sources.js';
|
|
@@ -21,7 +33,7 @@ import { PublicSideEffectTrace } from './side_effect_trace.js';
|
|
|
21
33
|
export class PublicExecutor {
|
|
22
34
|
metrics: ExecutorMetrics;
|
|
23
35
|
|
|
24
|
-
constructor(private readonly worldStateDB: WorldStateDB,
|
|
36
|
+
constructor(private readonly worldStateDB: WorldStateDB, client: TelemetryClient) {
|
|
25
37
|
this.metrics = new ExecutorMetrics(client, 'PublicExecutor');
|
|
26
38
|
}
|
|
27
39
|
|
|
@@ -30,45 +42,50 @@ export class PublicExecutor {
|
|
|
30
42
|
/**
|
|
31
43
|
* Executes a public execution request.
|
|
32
44
|
* @param executionRequest - The execution to run.
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
45
|
+
* @param constants - The constants (including global variables) to use.
|
|
46
|
+
* @param allocatedGas - The gas available at the start of this enqueued call.
|
|
35
47
|
* @param txContext - Transaction context.
|
|
36
48
|
* @param pendingSiloedNullifiers - The pending nullifier set from earlier parts of this TX.
|
|
37
49
|
* @param transactionFee - Fee offered for this TX.
|
|
38
50
|
* @param startSideEffectCounter - The counter of the first side-effect generated by this simulation.
|
|
51
|
+
* @param previousValidationRequestArrayLengths - Side effect array lengths from previous kernel
|
|
52
|
+
* @param previousAccumulatedDataArrayLengths - Side effect array lengths from previous kernel
|
|
39
53
|
* @returns The result of execution, including the results of all nested calls.
|
|
40
54
|
*/
|
|
41
55
|
public async simulate(
|
|
42
56
|
executionRequest: PublicExecutionRequest,
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
constants: CombinedConstantData,
|
|
58
|
+
allocatedGas: Gas,
|
|
45
59
|
_txContext: TxContext,
|
|
46
60
|
pendingSiloedNullifiers: Nullifier[],
|
|
47
61
|
transactionFee: Fr = Fr.ZERO,
|
|
48
62
|
startSideEffectCounter: number = 0,
|
|
63
|
+
previousValidationRequestArrayLengths: PublicValidationRequestArrayLengths = PublicValidationRequestArrayLengths.empty(),
|
|
64
|
+
previousAccumulatedDataArrayLengths: PublicAccumulatedDataArrayLengths = PublicAccumulatedDataArrayLengths.empty(),
|
|
49
65
|
): Promise<PublicExecutionResult> {
|
|
50
66
|
const address = executionRequest.contractAddress;
|
|
51
67
|
const selector = executionRequest.callContext.functionSelector;
|
|
52
|
-
const fnName =
|
|
68
|
+
const fnName = await getPublicFunctionDebugName(this.worldStateDB, address, selector, executionRequest.args);
|
|
53
69
|
|
|
54
|
-
PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}.`);
|
|
70
|
+
PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}@${address}.`);
|
|
55
71
|
const timer = new Timer();
|
|
56
72
|
|
|
57
|
-
const
|
|
73
|
+
const innerCallTrace = new PublicSideEffectTrace(startSideEffectCounter);
|
|
74
|
+
const enqueuedCallTrace = new PublicEnqueuedCallSideEffectTrace(
|
|
75
|
+
startSideEffectCounter,
|
|
76
|
+
previousValidationRequestArrayLengths,
|
|
77
|
+
previousAccumulatedDataArrayLengths,
|
|
78
|
+
);
|
|
79
|
+
const trace = new DualSideEffectTrace(innerCallTrace, enqueuedCallTrace);
|
|
58
80
|
const avmPersistableState = AvmPersistableStateManager.newWithPendingSiloedNullifiers(
|
|
59
81
|
this.worldStateDB,
|
|
60
82
|
trace,
|
|
61
83
|
pendingSiloedNullifiers.map(n => n.value),
|
|
62
84
|
);
|
|
63
85
|
|
|
64
|
-
const avmExecutionEnv = createAvmExecutionEnvironment(
|
|
65
|
-
executionRequest,
|
|
66
|
-
this.header,
|
|
67
|
-
globalVariables,
|
|
68
|
-
transactionFee,
|
|
69
|
-
);
|
|
86
|
+
const avmExecutionEnv = createAvmExecutionEnvironment(executionRequest, constants.globalVariables, transactionFee);
|
|
70
87
|
|
|
71
|
-
const avmMachineState = new AvmMachineState(
|
|
88
|
+
const avmMachineState = new AvmMachineState(allocatedGas);
|
|
72
89
|
const avmContext = new AvmContext(avmPersistableState, avmExecutionEnv, avmMachineState);
|
|
73
90
|
const simulator = new AvmSimulator(avmContext);
|
|
74
91
|
const avmResult = await simulator.execute();
|
|
@@ -94,7 +111,7 @@ export class PublicExecutor {
|
|
|
94
111
|
|
|
95
112
|
const publicExecutionResult = trace.toPublicExecutionResult(
|
|
96
113
|
avmExecutionEnv,
|
|
97
|
-
/*startGasLeft=*/
|
|
114
|
+
/*startGasLeft=*/ allocatedGas,
|
|
98
115
|
/*endGasLeft=*/ Gas.from(avmContext.machineState.gasLeft),
|
|
99
116
|
bytecode,
|
|
100
117
|
avmResult,
|
|
@@ -107,6 +124,14 @@ export class PublicExecutor {
|
|
|
107
124
|
this.metrics.recordFunctionSimulation(bytecode.length, timer.ms());
|
|
108
125
|
}
|
|
109
126
|
|
|
127
|
+
const _vmCircuitPublicInputs = enqueuedCallTrace.toVMCircuitPublicInputs(
|
|
128
|
+
constants,
|
|
129
|
+
avmExecutionEnv,
|
|
130
|
+
/*startGasLeft=*/ allocatedGas,
|
|
131
|
+
/*endGasLeft=*/ Gas.from(avmContext.machineState.gasLeft),
|
|
132
|
+
avmResult,
|
|
133
|
+
);
|
|
134
|
+
|
|
110
135
|
return publicExecutionResult;
|
|
111
136
|
}
|
|
112
137
|
}
|
|
@@ -120,7 +145,6 @@ export class PublicExecutor {
|
|
|
120
145
|
*/
|
|
121
146
|
function createAvmExecutionEnvironment(
|
|
122
147
|
executionRequest: PublicExecutionRequest,
|
|
123
|
-
header: Header,
|
|
124
148
|
globalVariables: GlobalVariables,
|
|
125
149
|
transactionFee: Fr,
|
|
126
150
|
): AvmExecutionEnvironment {
|
|
@@ -131,7 +155,6 @@ function createAvmExecutionEnvironment(
|
|
|
131
155
|
executionRequest.callContext.functionSelector,
|
|
132
156
|
/*contractCallDepth=*/ Fr.zero(),
|
|
133
157
|
transactionFee,
|
|
134
|
-
header,
|
|
135
158
|
globalVariables,
|
|
136
159
|
executionRequest.callContext.isStaticCall,
|
|
137
160
|
executionRequest.callContext.isDelegateCall,
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { FEE_JUICE_ADDRESS } from '@aztec/circuits.js';
|
|
2
1
|
import { computePublicDataTreeLeafSlot, deriveStorageSlotInMap } from '@aztec/circuits.js/hash';
|
|
3
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
2
|
+
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
-
import {
|
|
4
|
+
import { ProtocolContractAddress, ProtocolContractArtifact } from '@aztec/protocol-contracts';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Computes the storage slot within the Fee Juice contract for the balance of the fee payer.
|
|
9
8
|
*/
|
|
10
9
|
export function computeFeePayerBalanceStorageSlot(feePayer: AztecAddress) {
|
|
11
|
-
return deriveStorageSlotInMap(
|
|
10
|
+
return deriveStorageSlotInMap(ProtocolContractArtifact.FeeJuice.storageLayout.balances.slot, feePayer);
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
/**
|
|
@@ -18,7 +17,6 @@ export function computeFeePayerBalanceLeafSlot(feePayer: AztecAddress): Fr {
|
|
|
18
17
|
if (feePayer.isZero()) {
|
|
19
18
|
return Fr.ZERO;
|
|
20
19
|
}
|
|
21
|
-
const feeJuice = AztecAddress.fromBigInt(FEE_JUICE_ADDRESS);
|
|
22
20
|
const balanceSlot = computeFeePayerBalanceStorageSlot(feePayer);
|
|
23
|
-
return computePublicDataTreeLeafSlot(
|
|
21
|
+
return computePublicDataTreeLeafSlot(ProtocolContractAddress.FeeJuice, balanceSlot);
|
|
24
22
|
}
|
|
@@ -29,10 +29,10 @@ import {
|
|
|
29
29
|
import { makeTuple } from '@aztec/foundation/array';
|
|
30
30
|
import { type Tuple } from '@aztec/foundation/serialize';
|
|
31
31
|
import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
|
|
32
|
-
import { type
|
|
32
|
+
import { type MerkleTreeReadOperations } from '@aztec/world-state';
|
|
33
33
|
|
|
34
34
|
export class HintsBuilder {
|
|
35
|
-
constructor(private db:
|
|
35
|
+
constructor(private db: MerkleTreeReadOperations) {}
|
|
36
36
|
|
|
37
37
|
async getNoteHashReadRequestsHints(
|
|
38
38
|
readRequests: Tuple<TreeLeafReadRequest, typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX>,
|
|
@@ -49,15 +49,13 @@ export class HintsBuilder {
|
|
|
49
49
|
nullifierReadRequests: Tuple<ScopedReadRequest, typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX>,
|
|
50
50
|
pendingNullifiers: Tuple<Nullifier, typeof MAX_NULLIFIERS_PER_TX>,
|
|
51
51
|
) {
|
|
52
|
-
return (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
)
|
|
60
|
-
).hints;
|
|
52
|
+
return await buildSiloedNullifierReadRequestHints(
|
|
53
|
+
this,
|
|
54
|
+
nullifierReadRequests,
|
|
55
|
+
pendingNullifiers,
|
|
56
|
+
MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
57
|
+
MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
58
|
+
);
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
getNullifierNonExistentReadRequestHints(
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
MerkleTreeId,
|
|
3
|
+
type MerkleTreeReadOperations,
|
|
4
|
+
type MerkleTreeWriteOperations,
|
|
5
|
+
NullifierMembershipWitness,
|
|
6
|
+
type Tx,
|
|
7
|
+
} from '@aztec/circuit-types';
|
|
2
8
|
import { type PublicDBAccessStats } from '@aztec/circuit-types/stats';
|
|
3
9
|
import {
|
|
4
10
|
type AztecAddress,
|
|
11
|
+
type ContractClassPublic,
|
|
5
12
|
ContractClassRegisteredEvent,
|
|
13
|
+
type ContractDataSource,
|
|
6
14
|
ContractInstanceDeployedEvent,
|
|
15
|
+
type ContractInstanceWithAddress,
|
|
7
16
|
Fr,
|
|
8
17
|
FunctionSelector,
|
|
9
18
|
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
@@ -14,19 +23,13 @@ import {
|
|
|
14
23
|
import { computeL1ToL2MessageNullifier, computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
|
|
15
24
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
16
25
|
import { Timer } from '@aztec/foundation/timer';
|
|
17
|
-
import {
|
|
26
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
18
27
|
import {
|
|
19
28
|
type CommitmentsDB,
|
|
20
29
|
MessageLoadOracleInputs,
|
|
21
30
|
type PublicContractsDB,
|
|
22
31
|
type PublicStateDB,
|
|
23
32
|
} from '@aztec/simulator';
|
|
24
|
-
import {
|
|
25
|
-
type ContractClassPublic,
|
|
26
|
-
type ContractDataSource,
|
|
27
|
-
type ContractInstanceWithAddress,
|
|
28
|
-
} from '@aztec/types/contracts';
|
|
29
|
-
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
30
33
|
|
|
31
34
|
/**
|
|
32
35
|
* Implements the PublicContractsDB using a ContractDataSource.
|
|
@@ -47,7 +50,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
|
47
50
|
public addNewContracts(tx: Tx): Promise<void> {
|
|
48
51
|
// Extract contract class and instance data from logs and add to cache for this block
|
|
49
52
|
const logs = tx.unencryptedLogs.unrollLogs();
|
|
50
|
-
ContractClassRegisteredEvent.fromLogs(logs,
|
|
53
|
+
ContractClassRegisteredEvent.fromLogs(logs, ProtocolContractAddress.ContractClassRegisterer).forEach(e => {
|
|
51
54
|
this.log.debug(`Adding class ${e.contractClassId.toString()} to public execution contract cache`);
|
|
52
55
|
this.classCache.set(e.contractClassId.toString(), e.toContractClassPublic());
|
|
53
56
|
});
|
|
@@ -70,7 +73,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
|
70
73
|
// Let's say we have two txs adding the same contract on the same block. If the 2nd one reverts,
|
|
71
74
|
// wouldn't that accidentally remove the contract added on the first one?
|
|
72
75
|
const logs = tx.unencryptedLogs.unrollLogs();
|
|
73
|
-
ContractClassRegisteredEvent.fromLogs(logs,
|
|
76
|
+
ContractClassRegisteredEvent.fromLogs(logs, ProtocolContractAddress.ContractClassRegisterer).forEach(e =>
|
|
74
77
|
this.classCache.delete(e.contractClassId.toString()),
|
|
75
78
|
);
|
|
76
79
|
ContractInstanceDeployedEvent.fromLogs(logs).forEach(e => this.instanceCache.delete(e.address.toString()));
|
|
@@ -124,7 +127,7 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
|
|
|
124
127
|
private publicCheckpointedWriteCache: Map<bigint, Fr> = new Map();
|
|
125
128
|
private publicUncommittedWriteCache: Map<bigint, Fr> = new Map();
|
|
126
129
|
|
|
127
|
-
constructor(private db:
|
|
130
|
+
constructor(private db: MerkleTreeWriteOperations, dataSource: ContractDataSource) {
|
|
128
131
|
super(dataSource);
|
|
129
132
|
}
|
|
130
133
|
|
|
@@ -149,17 +152,7 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
|
|
|
149
152
|
return committed;
|
|
150
153
|
}
|
|
151
154
|
|
|
152
|
-
|
|
153
|
-
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
154
|
-
return Fr.ZERO;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const preimage = (await this.db.getLeafPreimage(
|
|
158
|
-
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
159
|
-
lowLeafResult.index,
|
|
160
|
-
)) as PublicDataTreeLeafPreimage;
|
|
161
|
-
|
|
162
|
-
return preimage.value;
|
|
155
|
+
return await readPublicState(this.db, contract, slot);
|
|
163
156
|
}
|
|
164
157
|
|
|
165
158
|
/**
|
|
@@ -325,3 +318,19 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
|
|
|
325
318
|
return Promise.resolve();
|
|
326
319
|
}
|
|
327
320
|
}
|
|
321
|
+
|
|
322
|
+
export async function readPublicState(db: MerkleTreeReadOperations, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
323
|
+
const leafSlot = computePublicDataTreeLeafSlot(contract, slot).toBigInt();
|
|
324
|
+
|
|
325
|
+
const lowLeafResult = await db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
|
|
326
|
+
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
327
|
+
return Fr.ZERO;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const preimage = (await db.getLeafPreimage(
|
|
331
|
+
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
332
|
+
lowLeafResult.index,
|
|
333
|
+
)) as PublicDataTreeLeafPreimage;
|
|
334
|
+
|
|
335
|
+
return preimage.value;
|
|
336
|
+
}
|
|
@@ -11,19 +11,19 @@ import {
|
|
|
11
11
|
mergeAccumulatedData,
|
|
12
12
|
} from '@aztec/circuits.js';
|
|
13
13
|
import { ProtocolCircuitVks, getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types';
|
|
14
|
-
import { type
|
|
14
|
+
import { type MerkleTreeReadOperations } from '@aztec/world-state';
|
|
15
15
|
|
|
16
16
|
import { HintsBuilder } from './hints_builder.js';
|
|
17
17
|
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
18
18
|
|
|
19
19
|
export class PublicKernelTailSimulator {
|
|
20
20
|
constructor(
|
|
21
|
-
private db:
|
|
21
|
+
private db: MerkleTreeReadOperations,
|
|
22
22
|
private publicKernelSimulator: PublicKernelCircuitSimulator,
|
|
23
23
|
private hintsBuilder: HintsBuilder,
|
|
24
24
|
) {}
|
|
25
25
|
|
|
26
|
-
static create(db:
|
|
26
|
+
static create(db: MerkleTreeReadOperations, publicKernelSimulator: PublicKernelCircuitSimulator) {
|
|
27
27
|
const hintsBuilder = new HintsBuilder(db);
|
|
28
28
|
return new PublicKernelTailSimulator(db, publicKernelSimulator, hintsBuilder);
|
|
29
29
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type FailedTx,
|
|
3
|
+
type MerkleTreeWriteOperations,
|
|
3
4
|
NestedProcessReturnValues,
|
|
4
5
|
type ProcessedTx,
|
|
5
6
|
type ProcessedTxHandler,
|
|
@@ -9,9 +10,8 @@ import {
|
|
|
9
10
|
validateProcessedTx,
|
|
10
11
|
} from '@aztec/circuit-types';
|
|
11
12
|
import {
|
|
12
|
-
AztecAddress,
|
|
13
13
|
ContractClassRegisteredEvent,
|
|
14
|
-
|
|
14
|
+
type ContractDataSource,
|
|
15
15
|
type GlobalVariables,
|
|
16
16
|
type Header,
|
|
17
17
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
@@ -21,10 +21,8 @@ import {
|
|
|
21
21
|
import { times } from '@aztec/foundation/collection';
|
|
22
22
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
23
23
|
import { Timer } from '@aztec/foundation/timer';
|
|
24
|
-
import {
|
|
24
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
25
25
|
import { Attributes, type TelemetryClient, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
26
|
-
import { type ContractDataSource } from '@aztec/types/contracts';
|
|
27
|
-
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
28
26
|
|
|
29
27
|
import { type SimulationProvider } from '../providers/index.js';
|
|
30
28
|
import { EnqueuedCallsProcessor } from './enqueued_calls_processor.js';
|
|
@@ -40,7 +38,6 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
|
40
38
|
*/
|
|
41
39
|
export class PublicProcessorFactory {
|
|
42
40
|
constructor(
|
|
43
|
-
private merkleTree: MerkleTreeOperations,
|
|
44
41
|
private contractDataSource: ContractDataSource,
|
|
45
42
|
private simulator: SimulationProvider,
|
|
46
43
|
private telemetryClient: TelemetryClient,
|
|
@@ -52,12 +49,16 @@ export class PublicProcessorFactory {
|
|
|
52
49
|
* @param globalVariables - The global variables for the block being processed.
|
|
53
50
|
* @returns A new instance of a PublicProcessor.
|
|
54
51
|
*/
|
|
55
|
-
public create(
|
|
56
|
-
|
|
52
|
+
public create(
|
|
53
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
54
|
+
maybeHistoricalHeader: Header | undefined,
|
|
55
|
+
globalVariables: GlobalVariables,
|
|
56
|
+
): PublicProcessor {
|
|
57
|
+
const { telemetryClient } = this;
|
|
57
58
|
const historicalHeader = maybeHistoricalHeader ?? merkleTree.getInitialHeader();
|
|
58
59
|
|
|
59
60
|
const worldStateDB = new WorldStateDB(merkleTree, this.contractDataSource);
|
|
60
|
-
const publicExecutor = new PublicExecutor(worldStateDB,
|
|
61
|
+
const publicExecutor = new PublicExecutor(worldStateDB, telemetryClient);
|
|
61
62
|
const publicKernelSimulator = new RealPublicKernelCircuitSimulator(this.simulator);
|
|
62
63
|
|
|
63
64
|
return PublicProcessor.create(
|
|
@@ -79,7 +80,7 @@ export class PublicProcessorFactory {
|
|
|
79
80
|
export class PublicProcessor {
|
|
80
81
|
private metrics: PublicProcessorMetrics;
|
|
81
82
|
constructor(
|
|
82
|
-
protected db:
|
|
83
|
+
protected db: MerkleTreeWriteOperations,
|
|
83
84
|
protected publicExecutor: PublicExecutor,
|
|
84
85
|
protected publicKernel: PublicKernelCircuitSimulator,
|
|
85
86
|
protected globalVariables: GlobalVariables,
|
|
@@ -93,7 +94,7 @@ export class PublicProcessor {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
static create(
|
|
96
|
-
db:
|
|
97
|
+
db: MerkleTreeWriteOperations,
|
|
97
98
|
publicExecutor: PublicExecutor,
|
|
98
99
|
publicKernelSimulator: PublicKernelCircuitSimulator,
|
|
99
100
|
globalVariables: GlobalVariables,
|
|
@@ -216,7 +217,7 @@ export class PublicProcessor {
|
|
|
216
217
|
return finalPublicDataUpdateRequests;
|
|
217
218
|
}
|
|
218
219
|
|
|
219
|
-
const feeJuiceAddress =
|
|
220
|
+
const feeJuiceAddress = ProtocolContractAddress.FeeJuice;
|
|
220
221
|
const balanceSlot = computeFeePayerBalanceStorageSlot(feePayer);
|
|
221
222
|
const leafSlot = computeFeePayerBalanceLeafSlot(feePayer);
|
|
222
223
|
const txFee = tx.data.getTransactionFee(this.globalVariables.gasFees);
|
|
@@ -269,7 +270,10 @@ export class PublicProcessor {
|
|
|
269
270
|
});
|
|
270
271
|
|
|
271
272
|
this.metrics.recordClassRegistration(
|
|
272
|
-
...ContractClassRegisteredEvent.fromLogs(
|
|
273
|
+
...ContractClassRegisteredEvent.fromLogs(
|
|
274
|
+
tx.unencryptedLogs.unrollLogs(),
|
|
275
|
+
ProtocolContractAddress.ContractClassRegisterer,
|
|
276
|
+
),
|
|
273
277
|
);
|
|
274
278
|
|
|
275
279
|
const phaseCount = processedPhases.length;
|