@aztec/simulator 0.57.0 → 0.59.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.js +2 -2
- package/dest/acvm/oracle/typed_oracle.d.ts +1 -2
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +1 -1
- package/dest/avm/avm_gas.js +2 -2
- package/dest/avm/avm_memory_types.d.ts +7 -3
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +29 -14
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +5 -2
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +3 -3
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +2 -3
- package/dest/avm/opcodes/accrued_substate.js +17 -17
- package/dest/avm/opcodes/arithmetic.js +2 -2
- 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 +9 -8
- package/dest/avm/opcodes/comparators.js +2 -2
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +4 -3
- package/dest/avm/opcodes/control_flow.js +1 -1
- package/dest/avm/opcodes/conversion.js +4 -4
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/avm/opcodes/ec_add.js +18 -9
- package/dest/avm/opcodes/external_calls.js +10 -10
- package/dest/avm/opcodes/hashing.js +8 -8
- 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.js +3 -3
- package/dest/avm/opcodes/misc.js +4 -4
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
- package/dest/avm/opcodes/multi_scalar_mul.js +24 -9
- package/dest/avm/opcodes/storage.js +2 -2
- package/dest/avm/serialization/instruction_serialization.js +2 -2
- 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.map +1 -1
- package/dest/client/client_execution_context.js +7 -3
- 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 -0
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +2 -1
- package/dest/client/private_execution.d.ts +10 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +25 -5
- 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/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 +18 -7
- 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 +3 -4
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -1
- package/dest/public/executor.d.ts +6 -4
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +18 -9
- 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 +1 -1
- 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 -11
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +8 -12
- package/dest/public/side_effect_trace.d.ts +1 -2
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +2 -2
- package/package.json +9 -9
- package/src/acvm/oracle/oracle.ts +1 -1
- package/src/acvm/oracle/typed_oracle.ts +6 -2
- package/src/avm/avm_gas.ts +1 -1
- package/src/avm/avm_memory_types.ts +28 -11
- package/src/avm/avm_simulator.ts +7 -1
- package/src/avm/fixtures/index.ts +2 -2
- package/src/avm/journal/journal.ts +3 -4
- package/src/avm/opcodes/accrued_substate.ts +17 -17
- package/src/avm/opcodes/arithmetic.ts +1 -1
- package/src/avm/opcodes/bitwise.ts +8 -7
- package/src/avm/opcodes/comparators.ts +1 -1
- package/src/avm/opcodes/contract.ts +3 -2
- package/src/avm/opcodes/control_flow.ts +1 -1
- package/src/avm/opcodes/conversion.ts +4 -4
- package/src/avm/opcodes/ec_add.ts +15 -8
- package/src/avm/opcodes/external_calls.ts +10 -10
- package/src/avm/opcodes/hashing.ts +8 -8
- package/src/avm/opcodes/instruction_impl.ts +0 -3
- package/src/avm/opcodes/memory.ts +3 -3
- package/src/avm/opcodes/misc.ts +4 -4
- package/src/avm/opcodes/multi_scalar_mul.ts +20 -12
- package/src/avm/opcodes/storage.ts +2 -2
- package/src/avm/serialization/instruction_serialization.ts +1 -1
- package/src/avm/test_utils.ts +1 -2
- package/src/client/client_execution_context.ts +6 -1
- package/src/client/db_oracle.ts +6 -2
- package/src/client/index.ts +1 -0
- package/src/client/private_execution.ts +36 -6
- package/src/client/view_data_oracle.ts +1 -2
- 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 +33 -11
- package/src/public/enqueued_calls_processor.ts +4 -6
- package/src/public/execution.ts +2 -4
- package/src/public/executor.ts +38 -9
- package/src/public/fee_payment.ts +4 -6
- package/src/public/hints_builder.ts +2 -2
- 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 +16 -16
- package/src/public/side_effect_trace.ts +2 -2
package/src/public/execution.ts
CHANGED
|
@@ -22,8 +22,6 @@ import {
|
|
|
22
22
|
} from '@aztec/circuits.js';
|
|
23
23
|
import { computeVarArgsHash } from '@aztec/circuits.js/hash';
|
|
24
24
|
|
|
25
|
-
import { type Gas as AvmGas } from '../avm/avm_gas.js';
|
|
26
|
-
|
|
27
25
|
/**
|
|
28
26
|
* The public function execution result.
|
|
29
27
|
*/
|
|
@@ -36,9 +34,9 @@ export interface PublicExecutionResult {
|
|
|
36
34
|
/** The side effect counter after executing this function call */
|
|
37
35
|
endSideEffectCounter: Fr;
|
|
38
36
|
/** How much gas was available for this public execution. */
|
|
39
|
-
startGasLeft:
|
|
37
|
+
startGasLeft: Gas;
|
|
40
38
|
/** How much gas was left after this public execution. */
|
|
41
|
-
endGasLeft:
|
|
39
|
+
endGasLeft: Gas;
|
|
42
40
|
/** Transaction fee set for this tx. */
|
|
43
41
|
transactionFee: Fr;
|
|
44
42
|
|
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';
|
|
@@ -11,6 +20,8 @@ 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';
|
|
13
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';
|
|
14
25
|
import { type PublicExecutionResult } from './execution.js';
|
|
15
26
|
import { ExecutorMetrics } from './executor_metrics.js';
|
|
16
27
|
import { type WorldStateDB } from './public_db_sources.js';
|
|
@@ -31,22 +42,26 @@ export class PublicExecutor {
|
|
|
31
42
|
/**
|
|
32
43
|
* Executes a public execution request.
|
|
33
44
|
* @param executionRequest - The execution to run.
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
45
|
+
* @param constants - The constants (including global variables) to use.
|
|
46
|
+
* @param allocatedGas - The gas available at the start of this enqueued call.
|
|
36
47
|
* @param txContext - Transaction context.
|
|
37
48
|
* @param pendingSiloedNullifiers - The pending nullifier set from earlier parts of this TX.
|
|
38
49
|
* @param transactionFee - Fee offered for this TX.
|
|
39
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
|
|
40
53
|
* @returns The result of execution, including the results of all nested calls.
|
|
41
54
|
*/
|
|
42
55
|
public async simulate(
|
|
43
56
|
executionRequest: PublicExecutionRequest,
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
constants: CombinedConstantData,
|
|
58
|
+
allocatedGas: Gas,
|
|
46
59
|
_txContext: TxContext,
|
|
47
60
|
pendingSiloedNullifiers: Nullifier[],
|
|
48
61
|
transactionFee: Fr = Fr.ZERO,
|
|
49
62
|
startSideEffectCounter: number = 0,
|
|
63
|
+
previousValidationRequestArrayLengths: PublicValidationRequestArrayLengths = PublicValidationRequestArrayLengths.empty(),
|
|
64
|
+
previousAccumulatedDataArrayLengths: PublicAccumulatedDataArrayLengths = PublicAccumulatedDataArrayLengths.empty(),
|
|
50
65
|
): Promise<PublicExecutionResult> {
|
|
51
66
|
const address = executionRequest.contractAddress;
|
|
52
67
|
const selector = executionRequest.callContext.functionSelector;
|
|
@@ -55,16 +70,22 @@ export class PublicExecutor {
|
|
|
55
70
|
PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}@${address}.`);
|
|
56
71
|
const timer = new Timer();
|
|
57
72
|
|
|
58
|
-
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);
|
|
59
80
|
const avmPersistableState = AvmPersistableStateManager.newWithPendingSiloedNullifiers(
|
|
60
81
|
this.worldStateDB,
|
|
61
82
|
trace,
|
|
62
83
|
pendingSiloedNullifiers.map(n => n.value),
|
|
63
84
|
);
|
|
64
85
|
|
|
65
|
-
const avmExecutionEnv = createAvmExecutionEnvironment(executionRequest, globalVariables, transactionFee);
|
|
86
|
+
const avmExecutionEnv = createAvmExecutionEnvironment(executionRequest, constants.globalVariables, transactionFee);
|
|
66
87
|
|
|
67
|
-
const avmMachineState = new AvmMachineState(
|
|
88
|
+
const avmMachineState = new AvmMachineState(allocatedGas);
|
|
68
89
|
const avmContext = new AvmContext(avmPersistableState, avmExecutionEnv, avmMachineState);
|
|
69
90
|
const simulator = new AvmSimulator(avmContext);
|
|
70
91
|
const avmResult = await simulator.execute();
|
|
@@ -90,7 +111,7 @@ export class PublicExecutor {
|
|
|
90
111
|
|
|
91
112
|
const publicExecutionResult = trace.toPublicExecutionResult(
|
|
92
113
|
avmExecutionEnv,
|
|
93
|
-
/*startGasLeft=*/
|
|
114
|
+
/*startGasLeft=*/ allocatedGas,
|
|
94
115
|
/*endGasLeft=*/ Gas.from(avmContext.machineState.gasLeft),
|
|
95
116
|
bytecode,
|
|
96
117
|
avmResult,
|
|
@@ -103,6 +124,14 @@ export class PublicExecutor {
|
|
|
103
124
|
this.metrics.recordFunctionSimulation(bytecode.length, timer.ms());
|
|
104
125
|
}
|
|
105
126
|
|
|
127
|
+
const _vmCircuitPublicInputs = enqueuedCallTrace.toVMCircuitPublicInputs(
|
|
128
|
+
constants,
|
|
129
|
+
avmExecutionEnv,
|
|
130
|
+
/*startGasLeft=*/ allocatedGas,
|
|
131
|
+
/*endGasLeft=*/ Gas.from(avmContext.machineState.gasLeft),
|
|
132
|
+
avmResult,
|
|
133
|
+
);
|
|
134
|
+
|
|
106
135
|
return publicExecutionResult;
|
|
107
136
|
}
|
|
108
137
|
}
|
|
@@ -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>,
|
|
@@ -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,8 +49,12 @@ 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);
|
|
@@ -70,10 +71,6 @@ export class PublicProcessorFactory {
|
|
|
70
71
|
this.telemetryClient,
|
|
71
72
|
);
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
-
public getInitialHeader() {
|
|
75
|
-
return this.merkleTree.getInitialHeader();
|
|
76
|
-
}
|
|
77
74
|
}
|
|
78
75
|
|
|
79
76
|
/**
|
|
@@ -83,7 +80,7 @@ export class PublicProcessorFactory {
|
|
|
83
80
|
export class PublicProcessor {
|
|
84
81
|
private metrics: PublicProcessorMetrics;
|
|
85
82
|
constructor(
|
|
86
|
-
protected db:
|
|
83
|
+
protected db: MerkleTreeWriteOperations,
|
|
87
84
|
protected publicExecutor: PublicExecutor,
|
|
88
85
|
protected publicKernel: PublicKernelCircuitSimulator,
|
|
89
86
|
protected globalVariables: GlobalVariables,
|
|
@@ -97,7 +94,7 @@ export class PublicProcessor {
|
|
|
97
94
|
}
|
|
98
95
|
|
|
99
96
|
static create(
|
|
100
|
-
db:
|
|
97
|
+
db: MerkleTreeWriteOperations,
|
|
101
98
|
publicExecutor: PublicExecutor,
|
|
102
99
|
publicKernelSimulator: PublicKernelCircuitSimulator,
|
|
103
100
|
globalVariables: GlobalVariables,
|
|
@@ -220,7 +217,7 @@ export class PublicProcessor {
|
|
|
220
217
|
return finalPublicDataUpdateRequests;
|
|
221
218
|
}
|
|
222
219
|
|
|
223
|
-
const feeJuiceAddress =
|
|
220
|
+
const feeJuiceAddress = ProtocolContractAddress.FeeJuice;
|
|
224
221
|
const balanceSlot = computeFeePayerBalanceStorageSlot(feePayer);
|
|
225
222
|
const leafSlot = computeFeePayerBalanceLeafSlot(feePayer);
|
|
226
223
|
const txFee = tx.data.getTransactionFee(this.globalVariables.gasFees);
|
|
@@ -273,7 +270,10 @@ export class PublicProcessor {
|
|
|
273
270
|
});
|
|
274
271
|
|
|
275
272
|
this.metrics.recordClassRegistration(
|
|
276
|
-
...ContractClassRegisteredEvent.fromLogs(
|
|
273
|
+
...ContractClassRegisteredEvent.fromLogs(
|
|
274
|
+
tx.unencryptedLogs.unrollLogs(),
|
|
275
|
+
ProtocolContractAddress.ContractClassRegisterer,
|
|
276
|
+
),
|
|
277
277
|
);
|
|
278
278
|
|
|
279
279
|
const phaseCount = processedPhases.length;
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
AvmKeyValueHint,
|
|
7
7
|
AztecAddress,
|
|
8
8
|
CallContext,
|
|
9
|
+
type ContractInstanceWithAddress,
|
|
9
10
|
ContractStorageRead,
|
|
10
11
|
ContractStorageUpdateRequest,
|
|
11
12
|
EthAddress,
|
|
@@ -30,7 +31,6 @@ import {
|
|
|
30
31
|
} from '@aztec/circuits.js';
|
|
31
32
|
import { Fr } from '@aztec/foundation/fields';
|
|
32
33
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
33
|
-
import { type ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
34
34
|
|
|
35
35
|
import { type AvmContractCallResult } from '../avm/avm_contract_call_result.js';
|
|
36
36
|
import { type AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
|
|
@@ -222,7 +222,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
222
222
|
instance.deployer,
|
|
223
223
|
instance.contractClassId,
|
|
224
224
|
instance.initializationHash,
|
|
225
|
-
instance.
|
|
225
|
+
instance.publicKeys,
|
|
226
226
|
),
|
|
227
227
|
);
|
|
228
228
|
this.logger.debug(`CONTRACT_INSTANCE cnt: ${this.sideEffectCounter}`);
|