@aztec/simulator 0.86.0 → 0.87.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/common/errors.d.ts +3 -6
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/errors.js +50 -31
- package/dest/private/acvm/acvm.d.ts +0 -2
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/acvm.js +2 -2
- package/dest/private/acvm/deserialize.d.ts +0 -2
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.d.ts +2 -2
- package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.js +30 -33
- package/dest/private/acvm/oracle/typed_oracle.d.ts +1 -3
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/private/acvm/serialize.d.ts +8 -2
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +26 -0
- package/dest/private/index.d.ts +3 -0
- package/dest/private/index.d.ts.map +1 -1
- package/dest/private/index.js +3 -0
- package/dest/private/private_execution.d.ts.map +1 -1
- package/dest/private/private_execution.js +7 -1
- package/dest/private/providers/acvm_native.d.ts +0 -2
- package/dest/private/providers/acvm_native.d.ts.map +1 -1
- package/dest/private/providers/acvm_native.js +1 -1
- package/dest/private/providers/circuit_recording/circuit_recorder.d.ts +0 -2
- package/dest/private/providers/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/providers/simulation_provider.d.ts.map +1 -1
- package/dest/private/providers/simulation_provider.js +14 -16
- package/dest/private/simulator.d.ts.map +1 -1
- package/dest/private/utility_execution_oracle.d.ts +0 -2
- package/dest/private/utility_execution_oracle.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +2 -2
- package/dest/public/avm/avm_execution_environment.d.ts +2 -1
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +4 -2
- package/dest/public/avm/avm_gas.d.ts +0 -15
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_gas.js +0 -18
- package/dest/public/avm/avm_memory_types.d.ts +84 -86
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.d.ts +1 -3
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +3 -3
- package/dest/public/avm/avm_simulator_interface.d.ts +0 -2
- package/dest/public/avm/avm_simulator_interface.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +1 -1
- package/dest/public/avm/fixtures/utils.d.ts +0 -10
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
- package/dest/public/avm/fixtures/utils.js +0 -42
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +7 -7
- package/dest/public/avm/opcodes/addressing_mode.d.ts +7 -6
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.js +18 -15
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +1 -1
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.js +2 -2
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.js +1 -1
- package/dest/public/avm/opcodes/contract.d.ts +1 -2
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +8 -9
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.js +1 -1
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +1 -1
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +1 -1
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts +6 -6
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +22 -22
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +3 -3
- package/dest/public/avm/opcodes/instruction.d.ts +0 -2
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.d.ts +4 -4
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +16 -16
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +18 -11
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/opcodes/storage.js +2 -2
- package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -2
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -2
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -2
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/executor_metrics.d.ts +3 -3
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +6 -6
- package/dest/public/executor_metrics_interface.d.ts +1 -1
- package/dest/public/executor_metrics_interface.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +3 -3
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +19 -26
- package/dest/public/hinting_db_sources.d.ts +0 -2
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +9 -2
- package/dest/public/public_processor/public_processor.d.ts +5 -7
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +10 -7
- package/dest/public/public_tx_simulator/apps_tests/amm_test.js +5 -5
- package/dest/public/public_tx_simulator/apps_tests/token_test.js +6 -6
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +3 -3
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +37 -34
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +2 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +15 -4
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +2 -2
- package/dest/public/side_effect_trace.d.ts +2 -39
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +8 -32
- package/dest/public/side_effect_trace_interface.d.ts +0 -4
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.d.ts +6 -4
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +6 -3
- package/dest/public/test_executor_metrics.d.ts +5 -4
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +47 -11
- package/dest/public/unique_class_ids.d.ts.map +1 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/package.json +18 -17
- package/src/common/errors.ts +77 -41
- package/src/private/acvm/acvm.ts +2 -2
- package/src/private/acvm/oracle/oracle.ts +38 -31
- package/src/private/acvm/oracle/typed_oracle.ts +1 -1
- package/src/private/acvm/serialize.ts +35 -0
- package/src/private/index.ts +3 -0
- package/src/private/pick_notes.ts +4 -4
- package/src/private/private_execution.ts +8 -0
- package/src/private/providers/acvm_native.ts +6 -2
- package/src/private/providers/simulation_provider.ts +14 -16
- package/src/private/simulator.ts +4 -1
- package/src/public/avm/avm_contract_call_result.ts +2 -2
- package/src/public/avm/avm_execution_environment.ts +7 -1
- package/src/public/avm/avm_gas.ts +0 -20
- package/src/public/avm/avm_simulator.ts +3 -1
- package/src/public/avm/fixtures/initializers.ts +1 -0
- package/src/public/avm/fixtures/utils.ts +0 -66
- package/src/public/avm/opcodes/accrued_substate.ts +31 -11
- package/src/public/avm/opcodes/addressing_mode.ts +23 -20
- package/src/public/avm/opcodes/arithmetic.ts +2 -1
- package/src/public/avm/opcodes/bitwise.ts +9 -3
- package/src/public/avm/opcodes/comparators.ts +2 -1
- package/src/public/avm/opcodes/contract.ts +7 -6
- package/src/public/avm/opcodes/control_flow.ts +7 -2
- package/src/public/avm/opcodes/conversion.ts +2 -1
- package/src/public/avm/opcodes/ec_add.ts +2 -1
- package/src/public/avm/opcodes/environment_getters.ts +7 -2
- package/src/public/avm/opcodes/external_calls.ts +26 -14
- package/src/public/avm/opcodes/hashing.ts +17 -5
- package/src/public/avm/opcodes/memory.ts +33 -15
- package/src/public/avm/opcodes/misc.ts +23 -15
- package/src/public/avm/opcodes/storage.ts +9 -3
- package/src/public/avm/serialization/buffer_cursor.ts +4 -1
- package/src/public/executor_metrics.ts +11 -6
- package/src/public/executor_metrics_interface.ts +1 -1
- package/src/public/fixtures/public_tx_simulation_tester.ts +3 -2
- package/src/public/fixtures/utils.ts +21 -28
- package/src/public/hinting_db_sources.ts +17 -4
- package/src/public/public_processor/public_processor.ts +11 -5
- package/src/public/public_tx_simulator/apps_tests/amm_test.ts +5 -5
- package/src/public/public_tx_simulator/apps_tests/token_test.ts +6 -6
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +3 -2
- package/src/public/public_tx_simulator/public_tx_context.ts +96 -81
- package/src/public/public_tx_simulator/public_tx_simulator.ts +14 -3
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +10 -1
- package/src/public/side_effect_trace.ts +7 -111
- package/src/public/side_effect_trace_interface.ts +0 -4
- package/src/public/state_manager/state_manager.ts +13 -5
- package/src/public/test_executor_metrics.ts +60 -13
- package/src/public/avm/opcodes/.eslintrc.cjs +0 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/public/fixtures/utils.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/public/fixtures/utils.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAC/F,OAAO,EAAE,GAAG,EAAwB,MAAM,mBAAmB,CAAC;AAY9D,OAAO,EAGL,6BAA6B,EAC7B,EAAE,EAGH,MAAM,kBAAkB,CAAC;AAI1B;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,EAAE,EAClB,iBAAiB,EAAE,6BAA6B,EAAE,EAClD,eAAe,EAAE,6BAA6B,EAAE,EAChD,mBAAmB,CAAC,EAAE,6BAA6B,EACnD,QAAQ,eAAsB,EAC9B,gBAAgB,GAAE,GAAiB,GAClC,EAAE,CA2CJ;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,eAAsB,EAAE,gBAAgB,GAAE,GAAqB,GAAG,EAAE,CAoBlH;AAED,wBAAsB,uBAAuB,CAC3C,EAAE,EAAE,EAAE,EACN,aAAa,EAAE,mBAAmB,EAClC,sBAAsB,UAAQ,iBA6B/B;AAED,wBAAsB,0BAA0B,CAC9C,EAAE,EAAE,EAAE,EACN,gBAAgB,EAAE,2BAA2B,EAC7C,sBAAsB,UAAQ,iBA0C/B"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEFAULT_GAS_LIMIT, DEPLOYER_CONTRACT_ADDRESS, MAX_L2_GAS_PER_TX_PUBLIC_PORTION, PRIVATE_LOG_SIZE_IN_FIELDS, REGISTERER_CONTRACT_ADDRESS, REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE } from '@aztec/constants';
|
|
2
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
2
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { assertLength } from '@aztec/foundation/serialize';
|
|
4
4
|
import { DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_TAG } from '@aztec/protocol-contracts';
|
|
5
5
|
import { bufferAsFields } from '@aztec/stdlib/abi';
|
|
6
6
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
7
|
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
8
8
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
9
|
-
import { PartialPrivateTailPublicInputsForPublic, PartialPrivateTailPublicInputsForRollup, PrivateKernelTailCircuitPublicInputs, RollupValidationRequests,
|
|
10
|
-
import {
|
|
9
|
+
import { LogHash, PartialPrivateTailPublicInputsForPublic, PartialPrivateTailPublicInputsForRollup, PrivateKernelTailCircuitPublicInputs, RollupValidationRequests, countAccumulatedItems } from '@aztec/stdlib/kernel';
|
|
10
|
+
import { ContractClassLogFields, PrivateLog } from '@aztec/stdlib/logs';
|
|
11
11
|
import { ClientIvcProof } from '@aztec/stdlib/proofs';
|
|
12
12
|
import { BlockHeader, HashedValues, Tx, TxConstantData, TxContext } from '@aztec/stdlib/tx';
|
|
13
13
|
import { strict as assert } from 'assert';
|
|
@@ -20,12 +20,11 @@ import { strict as assert } from 'assert';
|
|
|
20
20
|
const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
|
|
21
21
|
// TODO(#9269): Remove this fake nullifier method as we move away from 1st nullifier as hash.
|
|
22
22
|
forPublic.nonRevertibleAccumulatedData.nullifiers[0] = firstNullifier;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
forPublic.nonRevertibleAccumulatedData.publicCallRequests[setupCallRequests.length - i - 1] = setupCallRequests[i].request;
|
|
23
|
+
for(let i = 0; i < setupCallRequests.length; i++){
|
|
24
|
+
forPublic.nonRevertibleAccumulatedData.publicCallRequests[i] = setupCallRequests[i].request;
|
|
26
25
|
}
|
|
27
|
-
for(let i =
|
|
28
|
-
forPublic.revertibleAccumulatedData.publicCallRequests[
|
|
26
|
+
for(let i = 0; i < appCallRequests.length; i++){
|
|
27
|
+
forPublic.revertibleAccumulatedData.publicCallRequests[i] = appCallRequests[i].request;
|
|
29
28
|
}
|
|
30
29
|
if (teardownCallRequest) {
|
|
31
30
|
forPublic.publicTeardownCallRequest = teardownCallRequest.request;
|
|
@@ -65,16 +64,13 @@ export async function addNewContractClassToTx(tx, contractClass, skipNullifierIn
|
|
|
65
64
|
new Fr(contractClass.privateFunctionsRoot),
|
|
66
65
|
...bufferAsFields(contractClass.packedBytecode, Math.ceil(contractClass.packedBytecode.length / 31) + 1)
|
|
67
66
|
];
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
new Fr(contractClassLog.getEmittedLength()),
|
|
76
|
-
new Fr(REGISTERER_CONTRACT_ADDRESS)
|
|
77
|
-
]);
|
|
67
|
+
const contractAddress = new AztecAddress(new Fr(REGISTERER_CONTRACT_ADDRESS));
|
|
68
|
+
const emittedLength = contractClassLogFields.length;
|
|
69
|
+
const log = ContractClassLogFields.fromEmittedFields(contractClassLogFields);
|
|
70
|
+
const contractClassLogHash = LogHash.from({
|
|
71
|
+
value: await log.hash(),
|
|
72
|
+
length: emittedLength
|
|
73
|
+
}).scope(contractAddress);
|
|
78
74
|
const accumulatedData = tx.data.forPublic ? tx.data.forPublic.revertibleAccumulatedData : tx.data.forRollup.end;
|
|
79
75
|
if (!skipNullifierInsertion) {
|
|
80
76
|
const nextNullifierIndex = countAccumulatedItems(accumulatedData.nullifiers);
|
|
@@ -82,7 +78,7 @@ export async function addNewContractClassToTx(tx, contractClass, skipNullifierIn
|
|
|
82
78
|
}
|
|
83
79
|
const nextLogIndex = countAccumulatedItems(accumulatedData.contractClassLogsHashes);
|
|
84
80
|
accumulatedData.contractClassLogsHashes[nextLogIndex] = contractClassLogHash;
|
|
85
|
-
tx.contractClassLogs.push(
|
|
81
|
+
tx.contractClassLogs.push(log);
|
|
86
82
|
}
|
|
87
83
|
export async function addNewContractInstanceToTx(tx, contractInstance, skipNullifierInsertion = false) {
|
|
88
84
|
// can't use publicKeys.toFields() because it includes isInfinite which
|
|
@@ -97,7 +93,7 @@ export async function addNewContractInstanceToTx(tx, contractInstance, skipNulli
|
|
|
97
93
|
contractInstance.publicKeys.masterTaggingPublicKey.x,
|
|
98
94
|
contractInstance.publicKeys.masterTaggingPublicKey.y
|
|
99
95
|
];
|
|
100
|
-
const
|
|
96
|
+
const logFields = [
|
|
101
97
|
DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_TAG,
|
|
102
98
|
contractInstance.address.toField(),
|
|
103
99
|
new Fr(contractInstance.version),
|
|
@@ -105,12 +101,9 @@ export async function addNewContractInstanceToTx(tx, contractInstance, skipNulli
|
|
|
105
101
|
contractInstance.currentContractClassId,
|
|
106
102
|
contractInstance.initializationHash,
|
|
107
103
|
...publicKeysAsFields,
|
|
108
|
-
contractInstance.deployer.toField()
|
|
109
|
-
new Fr(0),
|
|
110
|
-
new Fr(0),
|
|
111
|
-
new Fr(0)
|
|
104
|
+
contractInstance.deployer.toField()
|
|
112
105
|
];
|
|
113
|
-
const contractInstanceLog = new PrivateLog(
|
|
106
|
+
const contractInstanceLog = new PrivateLog(padArrayEnd(logFields, Fr.ZERO, PRIVATE_LOG_SIZE_IN_FIELDS), logFields.length);
|
|
114
107
|
const contractAddressNullifier = await siloNullifier(AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS), contractInstance.address.toField());
|
|
115
108
|
const accumulatedData = tx.data.forPublic ? tx.data.forPublic.revertibleAccumulatedData : tx.data.forRollup.end;
|
|
116
109
|
if (!skipNullifierInsertion) {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
2
|
import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
5
3
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hinting_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/hinting_db_sources.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hinting_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/hinting_db_sources.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAOL,KAAK,iBAAiB,EASvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE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wBAAwB,SAAS,MAAM,EACvC,EAAE,SAAS,aAAa,EAExB,MAAM,EAAE,EAAE,EACV,MAAM,EAAE,MAAM,EAAE,EAChB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,oBAAoB,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAAC;IAIzD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,eAAe,CAAC,EAAE,SAAS,YAAY,EAClD,MAAM,EAAE,EAAE,EACV,MAAM,EAAE,kBAAkB,CAAC,EAAE,CAAC,EAAE,GAC/B,OAAO,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;IAIrB,oBAAoB,CAAC,EAAE,SAAS,YAAY,EACvD,MAAM,EAAE,EAAE,EACV,MAAM,EAAE,kBAAkB,CAAC,EAAE,CAAC,EAAE,EAChC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;IAIrB,6BAA6B,CAAC,EAAE,SAAS,YAAY,EAChE,MAAM,EAAE,EAAE,EACV,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;CAGnC"}
|
|
@@ -161,8 +161,15 @@ import { strict as assert } from 'assert';
|
|
|
161
161
|
assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
|
|
162
162
|
// We need to process each leaf individually because we need the sibling path after insertion, to be able to constraint the insertion.
|
|
163
163
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/13380): This can be changed if the world state appendLeaves returns the sibling paths.
|
|
164
|
-
|
|
165
|
-
await this.appendLeafInternal(treeId,
|
|
164
|
+
if (leaves.length === 1) {
|
|
165
|
+
await this.appendLeafInternal(treeId, leaves[0]);
|
|
166
|
+
return;
|
|
167
|
+
} else {
|
|
168
|
+
// TODO(dbanks12): NON-HINTING! We skip hinting here for now because:
|
|
169
|
+
// 1. We only ever append multiple leaves (for now) when padding (all empty leaves).
|
|
170
|
+
// 2. We don't need hints per-item when padding.
|
|
171
|
+
// 3. In order to get per-item hints today, you need to append one-at-a-time (mentioned above), which is VERY slow.
|
|
172
|
+
await this.db.appendLeaves(treeId, leaves);
|
|
166
173
|
}
|
|
167
174
|
}
|
|
168
175
|
async createCheckpoint() {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import { type DateProvider } from '@aztec/foundation/timer';
|
|
1
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
2
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
5
3
|
import { Gas } from '@aztec/stdlib/gas';
|
|
6
4
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
@@ -15,7 +13,7 @@ export declare class PublicProcessorFactory {
|
|
|
15
13
|
private contractDataSource;
|
|
16
14
|
private dateProvider;
|
|
17
15
|
protected telemetryClient: TelemetryClient;
|
|
18
|
-
constructor(contractDataSource: ContractDataSource, dateProvider
|
|
16
|
+
constructor(contractDataSource: ContractDataSource, dateProvider?: DateProvider, telemetryClient?: TelemetryClient);
|
|
19
17
|
/**
|
|
20
18
|
* Creates a new instance of a PublicProcessor.
|
|
21
19
|
* @param historicalHeader - The header of a block previous to the one in which the tx is included.
|
|
@@ -23,8 +21,8 @@ export declare class PublicProcessorFactory {
|
|
|
23
21
|
* @param skipFeeEnforcement - Allows disabling balance checks for fee estimations.
|
|
24
22
|
* @returns A new instance of a PublicProcessor.
|
|
25
23
|
*/
|
|
26
|
-
create(merkleTree: MerkleTreeWriteOperations, globalVariables: GlobalVariables, skipFeeEnforcement: boolean): PublicProcessor;
|
|
27
|
-
protected createPublicTxSimulator(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations: boolean, skipFeeEnforcement: boolean): PublicTxSimulator;
|
|
24
|
+
create(merkleTree: MerkleTreeWriteOperations, globalVariables: GlobalVariables, skipFeeEnforcement: boolean, clientInitiatedSimulation?: boolean): PublicProcessor;
|
|
25
|
+
protected createPublicTxSimulator(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations: boolean, skipFeeEnforcement: boolean, clientInitiatedSimulation: boolean): PublicTxSimulator;
|
|
28
26
|
}
|
|
29
27
|
/**
|
|
30
28
|
* Converts Txs lifted from the P2P module into ProcessedTx objects by executing
|
|
@@ -57,7 +55,7 @@ export declare class PublicProcessor implements Traceable {
|
|
|
57
55
|
nullifierCache?: {
|
|
58
56
|
addNullifiers: (nullifiers: Buffer[]) => void;
|
|
59
57
|
};
|
|
60
|
-
}): Promise<[ProcessedTx[], FailedTx[], NestedProcessReturnValues[]]>;
|
|
58
|
+
}): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[]]>;
|
|
61
59
|
private processTx;
|
|
62
60
|
private doTreeInsertionsForPrivateOnlyTx;
|
|
63
61
|
/** Processes the given tx within deadline. Returns timeout if deadline is hit. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAkC,MAAM,yBAAyB,CAAC;AAMvF,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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AA6C;IAK1D,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;;;OAMG;IACU,OAAO,CAClB,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EACrC,MAAM,GAAE;QACN,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,GAAG,CAAC;QAClB,QAAQ,CAAC,EAAE,IAAI,CAAC;KACZ,EACN,SAAS,GAAE;QACT,mBAAmB,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC;QACtC,cAAc,CAAC,EAAE;YAAE,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;SAAE,CAAC;KAC/D,GACL,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,yBAAyB,EAAE,CAAC,CAAC;YA8I5D,SAAS;YA2BT,gCAAgC;IAoC9C,kFAAkF;YACpE,uBAAuB;IA+BrC;;;;OAIG;YACW,gCAAgC;YA0BhC,oBAAoB;YAsCpB,wBAAwB;CA8CvC"}
|
|
@@ -8,7 +8,7 @@ import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT
|
|
|
8
8
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
9
9
|
import { Fr } from '@aztec/foundation/fields';
|
|
10
10
|
import { createLogger } from '@aztec/foundation/log';
|
|
11
|
-
import { Timer, elapsed, executeTimeout } from '@aztec/foundation/timer';
|
|
11
|
+
import { DateProvider, Timer, elapsed, executeTimeout } from '@aztec/foundation/timer';
|
|
12
12
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
13
13
|
import { ContractClassRegisteredEvent } from '@aztec/protocol-contracts/class-registerer';
|
|
14
14
|
import { computeFeePayerBalanceLeafSlot, computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
@@ -27,7 +27,7 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
|
27
27
|
contractDataSource;
|
|
28
28
|
dateProvider;
|
|
29
29
|
telemetryClient;
|
|
30
|
-
constructor(contractDataSource, dateProvider, telemetryClient = getTelemetryClient()){
|
|
30
|
+
constructor(contractDataSource, dateProvider = new DateProvider(), telemetryClient = getTelemetryClient()){
|
|
31
31
|
this.contractDataSource = contractDataSource;
|
|
32
32
|
this.dateProvider = dateProvider;
|
|
33
33
|
this.telemetryClient = telemetryClient;
|
|
@@ -38,13 +38,13 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
|
38
38
|
* @param globalVariables - The global variables for the block being processed.
|
|
39
39
|
* @param skipFeeEnforcement - Allows disabling balance checks for fee estimations.
|
|
40
40
|
* @returns A new instance of a PublicProcessor.
|
|
41
|
-
*/ create(merkleTree, globalVariables, skipFeeEnforcement) {
|
|
41
|
+
*/ create(merkleTree, globalVariables, skipFeeEnforcement, clientInitiatedSimulation = false) {
|
|
42
42
|
const contractsDB = new PublicContractsDB(this.contractDataSource);
|
|
43
|
-
const publicTxSimulator = this.createPublicTxSimulator(merkleTree, contractsDB, globalVariables, /*doMerkleOperations=*/ true, skipFeeEnforcement);
|
|
43
|
+
const publicTxSimulator = this.createPublicTxSimulator(merkleTree, contractsDB, globalVariables, /*doMerkleOperations=*/ true, skipFeeEnforcement, clientInitiatedSimulation);
|
|
44
44
|
return new PublicProcessor(globalVariables, merkleTree, contractsDB, publicTxSimulator, this.dateProvider, this.telemetryClient);
|
|
45
45
|
}
|
|
46
|
-
createPublicTxSimulator(merkleTree, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement) {
|
|
47
|
-
return new TelemetryPublicTxSimulator(merkleTree, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, this.telemetryClient);
|
|
46
|
+
createPublicTxSimulator(merkleTree, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, clientInitiatedSimulation) {
|
|
47
|
+
return new TelemetryPublicTxSimulator(merkleTree, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, clientInitiatedSimulation, this.telemetryClient);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
class PublicProcessorTimeoutError extends Error {
|
|
@@ -86,6 +86,7 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
86
86
|
const { maxTransactions, maxBlockSize, deadline, maxBlockGas } = limits;
|
|
87
87
|
const { preprocessValidator, nullifierCache } = validator;
|
|
88
88
|
const result = [];
|
|
89
|
+
const usedTxs = [];
|
|
89
90
|
const failed = [];
|
|
90
91
|
const timer = new Timer();
|
|
91
92
|
let totalSizeInBytes = 0;
|
|
@@ -173,6 +174,7 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
173
174
|
// I'd rather pass the validators the processedTx as well and let them deal with it.
|
|
174
175
|
nullifierCache?.addNullifiers(processedTx.txEffect.nullifiers.map((n)=>n.toBuffer()));
|
|
175
176
|
result.push(processedTx);
|
|
177
|
+
usedTxs.push(tx);
|
|
176
178
|
returns = returns.concat(returnValues);
|
|
177
179
|
totalPublicGas = totalPublicGas.add(processedTx.gasUsed.publicGas);
|
|
178
180
|
totalBlockGas = totalBlockGas.add(processedTx.gasUsed.totalGas);
|
|
@@ -211,6 +213,7 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
211
213
|
return [
|
|
212
214
|
result,
|
|
213
215
|
failed,
|
|
216
|
+
usedTxs,
|
|
214
217
|
returns
|
|
215
218
|
];
|
|
216
219
|
}
|
|
@@ -247,7 +250,7 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
247
250
|
await this.merkleTree.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, padArrayEnd(processedTx.txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
|
|
248
251
|
try {
|
|
249
252
|
await this.merkleTree.batchInsert(MerkleTreeId.NULLIFIER_TREE, padArrayEnd(processedTx.txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((n)=>n.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
|
|
250
|
-
} catch
|
|
253
|
+
} catch {
|
|
251
254
|
if (txValidator) {
|
|
252
255
|
// Ideally the validator has already caught this above, but just in case:
|
|
253
256
|
throw new Error(`Transaction ${processedTx.hash} invalid after processing public functions`);
|
|
@@ -22,7 +22,7 @@ const INITIAL_TOKEN_BALANCE = 1_000_000_000n;
|
|
|
22
22
|
liquidityToken
|
|
23
23
|
];
|
|
24
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=*/ [
|
|
25
|
+
const ammConstructorResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'AMM/constructor', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
26
26
|
{
|
|
27
27
|
fnName: 'constructor',
|
|
28
28
|
args: constructorArgs,
|
|
@@ -32,7 +32,7 @@ const INITIAL_TOKEN_BALANCE = 1_000_000_000n;
|
|
|
32
32
|
expect(ammConstructorResult.revertCode.isOK()).toBe(true);
|
|
33
33
|
logger.debug(`Setting AMM as minter for liquidity token`);
|
|
34
34
|
// set the AMM as the minter for the liquidity token
|
|
35
|
-
const setMinterResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'set_minter', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
35
|
+
const setMinterResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'AMM/set_minter', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
36
36
|
{
|
|
37
37
|
fnName: 'set_minter',
|
|
38
38
|
args: [
|
|
@@ -69,7 +69,7 @@ async function addLiquidity(tester, sender, amm, token0, token1, liquidityToken,
|
|
|
69
69
|
const liquidityPartialNote = {
|
|
70
70
|
commitment: new Fr(99)
|
|
71
71
|
};
|
|
72
|
-
return await tester.simulateTxWithLabel(/*txLabel=*/ 'add_liquidity', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
72
|
+
return await tester.simulateTxWithLabel(/*txLabel=*/ 'AMM/add_liquidity', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
73
73
|
// token0.transfer_to_public enqueues a call to _increase_public_balance
|
|
74
74
|
{
|
|
75
75
|
sender: token0.address,
|
|
@@ -144,7 +144,7 @@ async function swapExactTokensForTokens(tester, sender, amm, tokenIn, tokenOut,
|
|
|
144
144
|
const tokenOutPartialNote = {
|
|
145
145
|
commitment: new Fr(66)
|
|
146
146
|
};
|
|
147
|
-
return await tester.simulateTxWithLabel(/*txLabel=*/ 'swap_exact_tokens_for_tokens', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
147
|
+
return await tester.simulateTxWithLabel(/*txLabel=*/ 'AMM/swap_exact_tokens_for_tokens', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
148
148
|
// tokenIn.transfer_to_public enqueues a call to _increase_public_balance
|
|
149
149
|
{
|
|
150
150
|
sender: tokenIn.address,
|
|
@@ -185,7 +185,7 @@ async function removeLiquidity(tester, sender, amm, token0, token1, liquidityTok
|
|
|
185
185
|
const token1PartialNote = {
|
|
186
186
|
commitment: new Fr(222)
|
|
187
187
|
};
|
|
188
|
-
return await tester.simulateTxWithLabel(/*txLabel=*/ 'remove_liquidity', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
188
|
+
return await tester.simulateTxWithLabel(/*txLabel=*/ 'AMM/remove_liquidity', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
189
189
|
// liquidityToken.transfer_to_public enqueues a call to _increase_public_balance
|
|
190
190
|
{
|
|
191
191
|
sender: liquidityToken.address,
|
|
@@ -8,7 +8,7 @@ export async function tokenTest(tester, logger) {
|
|
|
8
8
|
const receiver = AztecAddress.fromNumber(222);
|
|
9
9
|
const token = await deployToken(tester, admin);
|
|
10
10
|
const mintAmount = 100n;
|
|
11
|
-
const mintResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'mint_to_public', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
11
|
+
const mintResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'Token/mint_to_public', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
12
12
|
{
|
|
13
13
|
address: token.address,
|
|
14
14
|
fnName: 'mint_to_public',
|
|
@@ -22,7 +22,7 @@ export async function tokenTest(tester, logger) {
|
|
|
22
22
|
await checkBalance(tester, token, sender, sender, mintAmount);
|
|
23
23
|
const nonce = new Fr(0);
|
|
24
24
|
const transferAmount = 50n;
|
|
25
|
-
const transferResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'transfer_in_public', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
25
|
+
const transferResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'Token/transfer_in_public', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
26
26
|
{
|
|
27
27
|
address: token.address,
|
|
28
28
|
fnName: 'transfer_in_public',
|
|
@@ -37,7 +37,7 @@ export async function tokenTest(tester, logger) {
|
|
|
37
37
|
expect(transferResult.revertCode.isOK()).toBe(true);
|
|
38
38
|
await checkBalance(tester, token, sender, receiver, mintAmount - transferAmount);
|
|
39
39
|
await checkBalance(tester, token, sender, receiver, transferAmount);
|
|
40
|
-
const balResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'balance_of_public', sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
40
|
+
const balResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'Token/balance_of_public', sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
41
41
|
{
|
|
42
42
|
address: token.address,
|
|
43
43
|
fnName: 'balance_of_public',
|
|
@@ -48,7 +48,7 @@ export async function tokenTest(tester, logger) {
|
|
|
48
48
|
}
|
|
49
49
|
]);
|
|
50
50
|
expect(balResult.revertCode.isOK()).toBe(true);
|
|
51
|
-
const burnResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'burn_public', /*sender=*/ receiver, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
51
|
+
const burnResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'Token/burn_public', /*sender=*/ receiver, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
52
52
|
{
|
|
53
53
|
address: token.address,
|
|
54
54
|
fnName: 'burn_public',
|
|
@@ -72,7 +72,7 @@ export async function deployToken(tester, admin, seed = 0) {
|
|
|
72
72
|
/*decimals=*/ new Fr(18)
|
|
73
73
|
];
|
|
74
74
|
const token = await tester.registerAndDeployContract(constructorArgs, /*deployer=*/ admin, TokenContractArtifact, /*skipNullifierInsertion=*/ false, seed);
|
|
75
|
-
const result = await tester.simulateTxWithLabel(/*txLabel=*/ 'Token
|
|
75
|
+
const result = await tester.simulateTxWithLabel(/*txLabel=*/ 'Token/constructor', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
76
76
|
{
|
|
77
77
|
fnName: 'constructor',
|
|
78
78
|
args: constructorArgs,
|
|
@@ -83,7 +83,7 @@ export async function deployToken(tester, admin, seed = 0) {
|
|
|
83
83
|
return token;
|
|
84
84
|
}
|
|
85
85
|
async function checkBalance(tester, token, sender, account, expectedBalance) {
|
|
86
|
-
const balResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'balance_of_public', sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
86
|
+
const balResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'Token/balance_of_public', sender, /*setupCalls=*/ [], /*appCalls=*/ [
|
|
87
87
|
{
|
|
88
88
|
address: token.address,
|
|
89
89
|
fnName: 'balance_of_public',
|
|
@@ -13,7 +13,7 @@ import { type ProcessedPhase, type PublicTxResult, PublicTxSimulator } from './p
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class MeasuredPublicTxSimulator extends PublicTxSimulator {
|
|
15
15
|
protected readonly metrics: ExecutorMetricsInterface;
|
|
16
|
-
constructor(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations: boolean | undefined, skipFeeEnforcement: boolean | undefined, metrics: ExecutorMetricsInterface);
|
|
16
|
+
constructor(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations: boolean | undefined, skipFeeEnforcement: boolean | undefined, clientInitiatedSimulation: boolean | undefined, metrics: ExecutorMetricsInterface);
|
|
17
17
|
simulate(tx: Tx, txLabel?: string): Promise<PublicTxResult>;
|
|
18
18
|
protected computeTxHash(tx: Tx): Promise<import("@aztec/stdlib/tx").TxHash>;
|
|
19
19
|
protected insertNonRevertiblesFromPrivate(context: PublicTxContext, tx: Tx): Promise<void>;
|
|
@@ -1 +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,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,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,MAAM,yBAAyB,CAAC;AACjE,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;
|
|
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,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,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,MAAM,yBAAyB,CAAC;AACjE,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;IAQ5D,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,wBAAwB;gBANpD,UAAU,EAAE,yBAAyB,EACrC,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,EAAE,OAAO,YAAQ,EACnC,kBAAkB,EAAE,OAAO,YAAQ,EACnC,yBAAyB,EAAE,OAAO,YAAQ,EACvB,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"}
|
|
@@ -4,8 +4,8 @@ import { PublicTxSimulator } from './public_tx_simulator.js';
|
|
|
4
4
|
* A public tx simulator that tracks miscellaneous simulation metrics without telemetry.
|
|
5
5
|
*/ export class MeasuredPublicTxSimulator extends PublicTxSimulator {
|
|
6
6
|
metrics;
|
|
7
|
-
constructor(merkleTree, contractsDB, globalVariables, doMerkleOperations = false, skipFeeEnforcement = false, metrics){
|
|
8
|
-
super(merkleTree, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement), this.metrics = metrics;
|
|
7
|
+
constructor(merkleTree, contractsDB, globalVariables, doMerkleOperations = false, skipFeeEnforcement = false, clientInitiatedSimulation = false, metrics){
|
|
8
|
+
super(merkleTree, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, clientInitiatedSimulation), this.metrics = metrics;
|
|
9
9
|
}
|
|
10
10
|
async simulate(tx, txLabel = 'unlabeledTx') {
|
|
11
11
|
this.metrics.startRecordingTxSimulation(txLabel);
|
|
@@ -43,7 +43,7 @@ import { PublicTxSimulator } from './public_tx_simulator.js';
|
|
|
43
43
|
async simulateEnqueuedCallInternal(stateManager, callRequest, allocatedGas, transactionFee, fnName) {
|
|
44
44
|
const timer = new Timer();
|
|
45
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.`, {
|
|
46
|
+
this.log.verbose(result.reverted ? `Simulation of enqueued public call ${fnName} reverted with reason ${result.revertReason?.message}.` : `Simulation of enqueued public call ${fnName} completed successfully.`, {
|
|
47
47
|
eventName: 'avm-simulation',
|
|
48
48
|
appCircuitName: fnName,
|
|
49
49
|
duration: timer.ms()
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import {
|
|
2
|
+
import { AvmCircuitPublicInputs, RevertCode } from '@aztec/stdlib/avm';
|
|
3
3
|
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';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_tx_context.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"public_tx_context.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_context.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EAAsB,sBAAsB,EAAmB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC5G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAA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L_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX } from '@aztec/constants';
|
|
1
|
+
import { MAX_ENQUEUED_CALLS_PER_TX, MAX_L2_GAS_PER_TX_PUBLIC_PORTION, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_PUBLIC_LOGS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX } from '@aztec/constants';
|
|
2
2
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import {
|
|
6
|
-
import { PublicDataWrite, RevertCode } from '@aztec/stdlib/avm';
|
|
5
|
+
import { AvmAccumulatedData, AvmCircuitPublicInputs, PublicDataWrite, RevertCode } from '@aztec/stdlib/avm';
|
|
7
6
|
import { computeTransactionFee } from '@aztec/stdlib/fees';
|
|
8
7
|
import { Gas } from '@aztec/stdlib/gas';
|
|
9
|
-
import { PrivateToAvmAccumulatedData, PrivateToAvmAccumulatedDataArrayLengths, PublicCallRequest, countAccumulatedItems
|
|
8
|
+
import { PrivateToAvmAccumulatedData, PrivateToAvmAccumulatedDataArrayLengths, PublicCallRequest, countAccumulatedItems } from '@aztec/stdlib/kernel';
|
|
9
|
+
import { PublicLog } from '@aztec/stdlib/logs';
|
|
10
|
+
import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
|
|
10
11
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
11
|
-
import {
|
|
12
|
+
import { TxExecutionPhase } from '@aztec/stdlib/tx';
|
|
12
13
|
import { strict as assert } from 'assert';
|
|
13
14
|
import { inspect } from 'util';
|
|
14
|
-
import {
|
|
15
|
+
import { SideEffectTrace } from '../side_effect_trace.js';
|
|
15
16
|
import { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
16
17
|
import { getCallRequestsWithCalldataByPhase } from '../utils.js';
|
|
17
18
|
/**
|
|
@@ -60,8 +61,7 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
|
|
|
60
61
|
}
|
|
61
62
|
static async create(treesDB, contractsDB, tx, globalVariables, doMerkleOperations) {
|
|
62
63
|
const nonRevertibleAccumulatedDataFromPrivate = tx.data.forPublic.nonRevertibleAccumulatedData;
|
|
63
|
-
const
|
|
64
|
-
const trace = new SideEffectTrace(/*startSideEffectCounter=*/ 0, previousAccumulatedDataArrayLengths);
|
|
64
|
+
const trace = new SideEffectTrace();
|
|
65
65
|
const firstNullifier = nonRevertibleAccumulatedDataFromPrivate.nullifiers[0];
|
|
66
66
|
// Transaction level state manager that will be forked for revertible phases.
|
|
67
67
|
const txStateManager = PublicPersistableStateManager.create(treesDB, contractsDB, trace, doMerkleOperations, firstNullifier, globalVariables.blockNumber.toNumber());
|
|
@@ -86,7 +86,7 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
|
|
|
86
86
|
* If in setup, throw an error (transaction will be thrown out).
|
|
87
87
|
* NOTE: this does not "halt" the entire transaction execution.
|
|
88
88
|
*/ revert(phase, revertReason = undefined, culprit = '') {
|
|
89
|
-
this.log.warn(`${TxExecutionPhase[phase]} phase reverted! ${culprit} failed with reason: ${revertReason}`);
|
|
89
|
+
this.log.warn(`${TxExecutionPhase[phase]} phase reverted! ${culprit} failed with reason: ${revertReason?.message}`);
|
|
90
90
|
if (revertReason && !this.revertReason) {
|
|
91
91
|
// don't override revertReason
|
|
92
92
|
// (if app logic and teardown both revert, we want app logic's reason)
|
|
@@ -211,35 +211,38 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
|
|
|
211
211
|
*/ async generateAvmCircuitPublicInputs() {
|
|
212
212
|
assert(this.halted, 'Can only get AvmCircuitPublicInputs after tx execution ends');
|
|
213
213
|
const stateManager = this.state.getActiveStateManager();
|
|
214
|
-
//
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
// Temporary overrides as these entries aren't yet populated in trace
|
|
223
|
-
avmCircuitPublicInputs.previousNonRevertibleAccumulatedDataArrayLengths = getArrayLengths(this.nonRevertibleAccumulatedDataFromPrivate);
|
|
224
|
-
avmCircuitPublicInputs.previousRevertibleAccumulatedDataArrayLengths = getArrayLengths(this.revertibleAccumulatedDataFromPrivate);
|
|
225
|
-
avmCircuitPublicInputs.previousNonRevertibleAccumulatedData = convertAccumulatedData(this.nonRevertibleAccumulatedDataFromPrivate);
|
|
226
|
-
avmCircuitPublicInputs.previousRevertibleAccumulatedData = convertAccumulatedData(this.revertibleAccumulatedDataFromPrivate);
|
|
227
|
-
const msgsFromPrivate = this.revertCode.isOK() ? mergeAccumulatedData(avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.l2ToL1Msgs, avmCircuitPublicInputs.previousRevertibleAccumulatedData.l2ToL1Msgs) : avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.l2ToL1Msgs;
|
|
228
|
-
avmCircuitPublicInputs.accumulatedData.l2ToL1Msgs = assertLength(mergeAccumulatedData(msgsFromPrivate, avmCircuitPublicInputs.accumulatedData.l2ToL1Msgs), MAX_L2_TO_L1_MSGS_PER_TX);
|
|
214
|
+
// We get the side effects from the AVM.
|
|
215
|
+
// The AVM will already have handled the conditional insertion of most private side-effects.
|
|
216
|
+
// (depending on the revert code of each stage). Only l2ToL1Msgs and publicLogs still need to be "merged".
|
|
217
|
+
const { publicDataWrites: avmPublicDataWrites, noteHashes: avmNoteHashes, nullifiers: avmNullifiers, l2ToL1Msgs: avmL2ToL1Msgs, publicLogs: avmPublicLogs } = this.trace.getSideEffects();
|
|
218
|
+
// Private generates PrivateLogs, and public execution generates PublicLogs.
|
|
219
|
+
// Since these are two different categories, they should not be merged.
|
|
220
|
+
const finalPublicLogs = avmPublicLogs;
|
|
221
|
+
// We squash public data writes.
|
|
229
222
|
// Maps slot to value. Maps in TS are iterable in insertion order, which is exactly what we want for
|
|
230
223
|
// squashing "to the left", where the first occurrence of a slot uses the value of the last write to it,
|
|
231
|
-
// and the rest occurrences are omitted
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
squashedPublicDataWrites
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
224
|
+
// and the rest occurrences are omitted.
|
|
225
|
+
// Note: you can't write public state from private, so we only squash what we got from the AVM.
|
|
226
|
+
const finalPublicDataWrites = (()=>{
|
|
227
|
+
const squashedPublicDataWrites = new Map();
|
|
228
|
+
for (const publicDataWrite of avmPublicDataWrites){
|
|
229
|
+
squashedPublicDataWrites.set(publicDataWrite.leafSlot.toBigInt(), publicDataWrite.newValue);
|
|
230
|
+
}
|
|
231
|
+
return Array.from(squashedPublicDataWrites.entries()).map(([slot, value])=>new PublicDataWrite(new Fr(slot), value));
|
|
232
|
+
})();
|
|
233
|
+
const accumulatedData = new AvmAccumulatedData(/*noteHashes=*/ padArrayEnd(avmNoteHashes.map((n)=>n.value), Fr.zero(), MAX_NOTE_HASHES_PER_TX), /*nullifiers=*/ padArrayEnd(avmNullifiers.map((n)=>n.value), Fr.zero(), MAX_NULLIFIERS_PER_TX), /*l2ToL1Msgs=*/ padArrayEnd(avmL2ToL1Msgs, ScopedL2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_TX), /*publicLogs=*/ padArrayEnd(finalPublicLogs, PublicLog.empty(), MAX_PUBLIC_LOGS_PER_TX), /*publicDataWrites=*/ padArrayEnd(finalPublicDataWrites, PublicDataWrite.empty(), MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX));
|
|
234
|
+
// Now we finally have enough information to pad the trees.
|
|
235
|
+
// NOTE(fcarreiro): a bit weird that a method that generates the PIs does this,
|
|
236
|
+
// but we do need the end tree snapshots. We can consider moving things to the caller.
|
|
237
|
+
const numNoteHashesToPad = MAX_NOTE_HASHES_PER_TX - avmNoteHashes.length;
|
|
238
|
+
const numNullifiersToPad = MAX_NULLIFIERS_PER_TX - avmNullifiers.length;
|
|
238
239
|
await stateManager.padTree(MerkleTreeId.NOTE_HASH_TREE, numNoteHashesToPad);
|
|
239
|
-
const numNullifiersToPad = MAX_NULLIFIERS_PER_TX - countAccumulatedItems(avmCircuitPublicInputs.accumulatedData.nullifiers);
|
|
240
240
|
await stateManager.padTree(MerkleTreeId.NULLIFIER_TREE, numNullifiersToPad);
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
const endTreeSnapshots = await stateManager.getTreeSnapshots();
|
|
242
|
+
// This converts the private accumulated data to the avm accumulated data format.
|
|
243
|
+
const convertAccumulatedData = (from)=>new PrivateToAvmAccumulatedData(from.noteHashes, from.nullifiers, from.l2ToL1Msgs);
|
|
244
|
+
const getArrayLengths = (from)=>new PrivateToAvmAccumulatedDataArrayLengths(countAccumulatedItems(from.noteHashes), countAccumulatedItems(from.nullifiers), countAccumulatedItems(from.l2ToL1Msgs));
|
|
245
|
+
return new AvmCircuitPublicInputs(this.globalVariables, this.startTreeSnapshots, /*startGasUsed=*/ this.gasUsedByPrivate, this.gasSettings, this.feePayer, /*publicSetupCallRequests=*/ padArrayEnd(this.setupCallRequests.map((r)=>r.request), PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX), /*publicAppLogicCallRequests=*/ padArrayEnd(this.appLogicCallRequests.map((r)=>r.request), PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX), /*publicTeardownCallRequests=*/ this.teardownCallRequests.length > 0 ? this.teardownCallRequests[0].request : PublicCallRequest.empty(), getArrayLengths(this.nonRevertibleAccumulatedDataFromPrivate), getArrayLengths(this.revertibleAccumulatedDataFromPrivate), convertAccumulatedData(this.nonRevertibleAccumulatedDataFromPrivate), convertAccumulatedData(this.revertibleAccumulatedDataFromPrivate), endTreeSnapshots, this.getTotalGasUsed(), accumulatedData, /*transactionFee=*/ this.getTransactionFeeUnsafe(), /*isReverted=*/ !this.revertCode.isOK());
|
|
243
246
|
}
|
|
244
247
|
}
|
|
245
248
|
/**
|
|
@@ -31,8 +31,9 @@ export declare class PublicTxSimulator {
|
|
|
31
31
|
private globalVariables;
|
|
32
32
|
private doMerkleOperations;
|
|
33
33
|
private skipFeeEnforcement;
|
|
34
|
+
private clientInitiatedSimulation;
|
|
34
35
|
protected log: Logger;
|
|
35
|
-
constructor(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations?: boolean, skipFeeEnforcement?: boolean);
|
|
36
|
+
constructor(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations?: boolean, skipFeeEnforcement?: boolean, clientInitiatedSimulation?: boolean);
|
|
36
37
|
/**
|
|
37
38
|
* Simulate a transaction's public portion including all of its phases.
|
|
38
39
|
* @param tx - The transaction to simulate.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAIL,KAAK,iBAAiB,EAEtB,KAAK,UAAU,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,KAAK,eAAe,EACpB,yBAAyB,EACzB,6BAA6B,EAC7B,EAAE,EACF,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAIjF,OAAO,EAAE,KAAK,iBAAiB,EAAiB,MAAM,yBAAyB,CA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