@aztec/pxe 0.0.0-test.1 → 0.0.1-fake-ceab37513c
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/bin/check_oracle_version.d.ts +2 -0
- package/dest/bin/check_oracle_version.d.ts.map +1 -0
- package/dest/bin/check_oracle_version.js +29 -0
- package/dest/bin/index.js +22 -2
- package/dest/config/index.d.ts +2 -7
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +8 -17
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +56 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -0
- package/dest/contract_function_simulator/contract_function_simulator.js +245 -0
- package/dest/contract_function_simulator/execution_data_provider.d.ts +285 -0
- package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -0
- package/dest/contract_function_simulator/execution_data_provider.js +14 -0
- package/dest/contract_function_simulator/execution_note_cache.d.ts +93 -0
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/execution_note_cache.js +180 -0
- package/dest/contract_function_simulator/hashed_values_cache.d.ts +28 -0
- package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/hashed_values_cache.js +36 -0
- package/dest/contract_function_simulator/index.d.ts +12 -0
- package/dest/contract_function_simulator/index.d.ts.map +1 -0
- package/dest/contract_function_simulator/index.js +11 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +20 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +37 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +15 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +25 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +17 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +61 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +21 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +42 -0
- package/dest/contract_function_simulator/oracle/index.d.ts +14 -0
- package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/index.js +2 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +19 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +24 -0
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +22 -0
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +49 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +56 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/oracle.js +325 -0
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +48 -0
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/private_execution.js +132 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +220 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +366 -0
- package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +87 -0
- package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/typed_oracle.js +146 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +166 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +270 -0
- package/dest/contract_function_simulator/pick_notes.d.ts +85 -0
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -0
- package/dest/contract_function_simulator/pick_notes.js +51 -0
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +6 -0
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -0
- package/dest/contract_function_simulator/proxied_contract_data_source.js +62 -0
- package/dest/contract_function_simulator/proxied_node.d.ts +9 -0
- package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -0
- package/dest/contract_function_simulator/proxied_node.js +27 -0
- package/dest/{pxe_oracle_interface/index.d.ts → contract_function_simulator/pxe_oracle_interface.d.ts} +46 -47
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -0
- package/dest/{pxe_oracle_interface/index.js → contract_function_simulator/pxe_oracle_interface.js} +256 -247
- package/dest/contract_function_simulator/tagging_utils.d.ts.map +1 -0
- package/dest/entrypoints/client/bundle/index.d.ts +1 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +11 -5
- package/dest/entrypoints/client/lazy/index.d.ts +1 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +11 -5
- package/dest/entrypoints/{client/pxe_creation_options.d.ts → pxe_creation_options.d.ts} +4 -1
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -0
- package/dest/entrypoints/server/index.d.ts +2 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +2 -2
- package/dest/entrypoints/server/utils.d.ts +18 -7
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +49 -22
- package/dest/oracle_version.d.ts +3 -0
- package/dest/oracle_version.d.ts.map +1 -0
- package/dest/oracle_version.js +10 -0
- package/dest/{kernel_prover → private_kernel}/hints/build_private_kernel_reset_private_inputs.d.ts +6 -6
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -0
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +271 -0
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +41 -0
- package/dest/private_kernel/hints/index.d.ts +3 -0
- package/dest/private_kernel/hints/index.d.ts.map +1 -0
- package/dest/{kernel_prover → private_kernel}/hints/index.js +1 -0
- package/dest/private_kernel/index.d.ts +3 -0
- package/dest/private_kernel/index.d.ts.map +1 -0
- package/dest/private_kernel/index.js +2 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +37 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -0
- package/dest/{kernel_prover/kernel_prover.js → private_kernel/private_kernel_execution_prover.js} +151 -88
- package/dest/{kernel_prover/proving_data_oracle.d.ts → private_kernel/private_kernel_oracle.d.ts} +17 -28
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -0
- package/dest/private_kernel/private_kernel_oracle.js +4 -0
- package/dest/{kernel_oracle/index.d.ts → private_kernel/private_kernel_oracle_impl.d.ts} +6 -6
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -0
- package/dest/{kernel_oracle/index.js → private_kernel/private_kernel_oracle_impl.js} +19 -9
- package/dest/pxe_service/error_enriching.d.ts.map +1 -1
- package/dest/pxe_service/error_enriching.js +23 -18
- package/dest/pxe_service/pxe_service.d.ts +25 -35
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +527 -400
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +13 -2
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -1
- package/dest/storage/capsule_data_provider/capsule_data_provider.js +86 -21
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts +10 -44
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
- package/dest/storage/contract_data_provider/contract_data_provider.js +93 -68
- package/dest/storage/contract_data_provider/index.d.ts +0 -1
- package/dest/storage/contract_data_provider/index.d.ts.map +1 -1
- package/dest/storage/contract_data_provider/index.js +0 -1
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts +2 -41
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +1 -1
- package/dest/storage/contract_data_provider/private_functions_tree.js +9 -61
- package/dest/storage/index.d.ts +2 -2
- package/dest/storage/index.d.ts.map +1 -1
- package/dest/storage/index.js +2 -2
- package/dest/storage/metadata.d.ts +2 -0
- package/dest/storage/metadata.d.ts.map +1 -0
- package/dest/storage/metadata.js +1 -0
- package/dest/storage/note_data_provider/note_dao.d.ts +16 -22
- package/dest/storage/note_data_provider/note_dao.d.ts.map +1 -1
- package/dest/storage/note_data_provider/note_dao.js +16 -20
- package/dest/storage/note_data_provider/note_data_provider.d.ts +2 -2
- package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
- package/dest/storage/note_data_provider/note_data_provider.js +49 -38
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +37 -0
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +1 -0
- package/dest/storage/private_event_data_provider/private_event_data_provider.js +96 -0
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts +1 -1
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +1 -1
- package/dest/storage/sync_data_provider/sync_data_provider.js +2 -2
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +4 -4
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +1 -1
- package/dest/storage/tagging_data_provider/tagging_data_provider.js +29 -12
- package/dest/synchronizer/synchronizer.d.ts +7 -9
- package/dest/synchronizer/synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/synchronizer.js +17 -18
- package/dest/test/pxe_test_suite.d.ts.map +1 -1
- package/dest/test/pxe_test_suite.js +4 -4
- package/package.json +34 -29
- package/src/bin/check_oracle_version.ts +36 -0
- package/src/bin/index.ts +26 -2
- package/src/config/index.ts +9 -23
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +464 -0
- package/src/contract_function_simulator/execution_data_provider.ts +361 -0
- package/src/contract_function_simulator/execution_note_cache.ts +217 -0
- package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
- package/src/contract_function_simulator/index.ts +11 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +47 -0
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +27 -0
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +64 -0
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +52 -0
- package/src/contract_function_simulator/oracle/index.ts +16 -0
- package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +23 -0
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +52 -0
- package/src/contract_function_simulator/oracle/oracle.ts +550 -0
- package/src/contract_function_simulator/oracle/private_execution.ts +215 -0
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +564 -0
- package/src/contract_function_simulator/oracle/typed_oracle.ts +289 -0
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +383 -0
- package/src/contract_function_simulator/pick_notes.ts +141 -0
- package/src/contract_function_simulator/proxied_contract_data_source.ts +66 -0
- package/src/contract_function_simulator/proxied_node.ts +33 -0
- package/src/{pxe_oracle_interface/index.ts → contract_function_simulator/pxe_oracle_interface.ts} +420 -325
- package/src/entrypoints/client/bundle/index.ts +1 -1
- package/src/entrypoints/client/bundle/utils.ts +25 -17
- package/src/entrypoints/client/lazy/index.ts +1 -1
- package/src/entrypoints/client/lazy/utils.ts +26 -13
- package/src/entrypoints/{client/pxe_creation_options.ts → pxe_creation_options.ts} +4 -1
- package/src/entrypoints/server/index.ts +2 -2
- package/src/entrypoints/server/utils.ts +88 -36
- package/src/oracle_version.ts +11 -0
- package/src/{kernel_prover → private_kernel}/hints/build_private_kernel_reset_private_inputs.ts +158 -142
- package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +58 -0
- package/src/{kernel_prover → private_kernel}/hints/index.ts +1 -0
- package/src/private_kernel/index.ts +2 -0
- package/src/{kernel_prover/kernel_prover.ts → private_kernel/private_kernel_execution_prover.ts} +185 -112
- package/src/{kernel_prover/proving_data_oracle.ts → private_kernel/private_kernel_oracle.ts} +17 -29
- package/src/{kernel_oracle/index.ts → private_kernel/private_kernel_oracle_impl.ts} +30 -15
- package/src/pxe_service/error_enriching.ts +31 -26
- package/src/pxe_service/pxe_service.ts +718 -528
- package/src/storage/capsule_data_provider/capsule_data_provider.ts +98 -21
- package/src/storage/contract_data_provider/contract_data_provider.ts +114 -75
- package/src/storage/contract_data_provider/index.ts +0 -1
- package/src/storage/contract_data_provider/private_functions_tree.ts +11 -75
- package/src/storage/index.ts +2 -3
- package/src/storage/metadata.ts +1 -0
- package/src/storage/note_data_provider/note_dao.ts +19 -27
- package/src/storage/note_data_provider/note_data_provider.ts +81 -76
- package/src/storage/private_event_data_provider/private_event_data_provider.ts +134 -0
- package/src/storage/sync_data_provider/sync_data_provider.ts +3 -3
- package/src/storage/tagging_data_provider/tagging_data_provider.ts +44 -13
- package/src/synchronizer/synchronizer.ts +21 -21
- package/src/test/pxe_test_suite.ts +6 -4
- package/dest/entrypoints/client/pxe_creation_options.d.ts.map +0 -1
- package/dest/kernel_oracle/index.d.ts.map +0 -1
- package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
- package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +0 -270
- package/dest/kernel_prover/hints/index.d.ts +0 -2
- package/dest/kernel_prover/hints/index.d.ts.map +0 -1
- package/dest/kernel_prover/index.d.ts +0 -3
- package/dest/kernel_prover/index.d.ts.map +0 -1
- package/dest/kernel_prover/index.js +0 -2
- package/dest/kernel_prover/kernel_prover.d.ts +0 -38
- package/dest/kernel_prover/kernel_prover.d.ts.map +0 -1
- package/dest/kernel_prover/proving_data_oracle.d.ts.map +0 -1
- package/dest/kernel_prover/proving_data_oracle.js +0 -4
- package/dest/note_decryption_utils/add_public_values_to_payload.d.ts +0 -11
- package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +0 -1
- package/dest/note_decryption_utils/add_public_values_to_payload.js +0 -47
- package/dest/pxe_http/index.d.ts +0 -2
- package/dest/pxe_http/index.d.ts.map +0 -1
- package/dest/pxe_http/index.js +0 -1
- package/dest/pxe_http/pxe_http_server.d.ts +0 -16
- package/dest/pxe_http/pxe_http_server.d.ts.map +0 -1
- package/dest/pxe_http/pxe_http_server.js +0 -27
- package/dest/pxe_oracle_interface/index.d.ts.map +0 -1
- package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +0 -1
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts +0 -11
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts.map +0 -1
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.js +0 -20
- package/dest/storage/auth_witness_data_provider/index.d.ts +0 -2
- package/dest/storage/auth_witness_data_provider/index.d.ts.map +0 -1
- package/dest/storage/auth_witness_data_provider/index.js +0 -1
- package/src/kernel_prover/index.ts +0 -2
- package/src/note_decryption_utils/add_public_values_to_payload.ts +0 -64
- package/src/pxe_http/index.ts +0 -1
- package/src/pxe_http/pxe_http_server.ts +0 -29
- package/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts +0 -34
- package/src/storage/auth_witness_data_provider/index.ts +0 -1
- /package/dest/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.d.ts +0 -0
- /package/dest/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.js +0 -0
- /package/dest/entrypoints/{client/pxe_creation_options.js → pxe_creation_options.js} +0 -0
- /package/src/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check_oracle_version.d.ts","sourceRoot":"","sources":["../../src/bin/check_oracle_version.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { keccak256String } from '@aztec/foundation/crypto';
|
|
2
|
+
import deterministicStringify from 'json-stringify-deterministic';
|
|
3
|
+
import { Oracle } from '../contract_function_simulator/oracle/oracle.js';
|
|
4
|
+
import { TypedOracle } from '../contract_function_simulator/oracle/typed_oracle.js';
|
|
5
|
+
import { ORACLE_INTERFACE_HASH } from '../oracle_version.js';
|
|
6
|
+
// Create a minimal mock implementation of TypedOracle to instantiate the Oracle class for interface verification.
|
|
7
|
+
class OracleMock extends TypedOracle {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Verifies that the Oracle interface matches the expected interface hash.
|
|
11
|
+
*
|
|
12
|
+
* The Oracle interface needs to be versioned to ensure compatibility between Aztec.nr and PXE. This function computes
|
|
13
|
+
* a hash of the Oracle interface and compares it against a known hash. If they don't match, it means the interface has
|
|
14
|
+
* changed and the ORACLE_VERSION constant needs to be incremented and the ORACLE_INTERFACE_HASH constant needs to be
|
|
15
|
+
* updated.
|
|
16
|
+
*
|
|
17
|
+
* TODO(#16581): The following only takes into consideration changes to the oracles defined in Oracle.ts and omits TXE
|
|
18
|
+
* oracles. Ensure this checks TXE oracles as well. This hasn't been implemented yet since we don't have a clean TXE
|
|
19
|
+
* oracle interface like we do in PXE (i.e., there is no single Oracle class that contains only the oracles).
|
|
20
|
+
*/ function assertOracleInterfaceMatches() {
|
|
21
|
+
const oracle = new Oracle(new OracleMock());
|
|
22
|
+
// We use keccak256 here just because we already have it in the dependencies.
|
|
23
|
+
const oracleInterfaceHash = keccak256String(deterministicStringify(oracle.toACIRCallback()));
|
|
24
|
+
if (oracleInterfaceHash !== ORACLE_INTERFACE_HASH) {
|
|
25
|
+
// This check exists only to notify you when you need to update the ORACLE_VERSION constant.
|
|
26
|
+
throw new Error(`The TypedOracle interface has changed, which implies a breaking change in the aztec.nr/PXE oracle interface. Update ORACLE_INTERFACE_HASH to ${oracleInterfaceHash} and bump ORACLE_VERSION in pxe/src/oracle_version.ts.`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
assertOracleInterfaceMatches();
|
package/dest/bin/index.js
CHANGED
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --no-warnings
|
|
2
|
+
import { createNamespacedSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server';
|
|
2
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
|
|
4
|
+
import { PXESchema, createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
|
|
5
|
+
import http from 'http';
|
|
4
6
|
import { getPXEServiceConfig } from '../config/index.js';
|
|
5
7
|
import { createPXEService } from '../entrypoints/server/utils.js';
|
|
6
|
-
import { startPXEHttpServer } from '../pxe_http/index.js';
|
|
7
8
|
const { PXE_PORT = 8080, AZTEC_NODE_URL = 'http://localhost:8079' } = process.env;
|
|
8
9
|
const logger = createLogger('pxe:service');
|
|
10
|
+
/**
|
|
11
|
+
* Creates an http server that forwards calls to the PXE and starts it on the given port.
|
|
12
|
+
* @param pxeService - PXE that answers queries to the created HTTP server.
|
|
13
|
+
* @param port - Port to listen in.
|
|
14
|
+
* @param maxBatchSize - Maximum allowed batch size for JSON RPC batch requests.
|
|
15
|
+
* @returns A running http server.
|
|
16
|
+
*/ function startPXEHttpServer(pxeService, port, opts = {}) {
|
|
17
|
+
const rpcServer = createNamespacedSafeJsonRpcServer({
|
|
18
|
+
pxe: [
|
|
19
|
+
pxeService,
|
|
20
|
+
PXESchema
|
|
21
|
+
]
|
|
22
|
+
}, opts);
|
|
23
|
+
const app = rpcServer.getApp();
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
25
|
+
const httpServer = http.createServer(app.callback());
|
|
26
|
+
httpServer.listen(port);
|
|
27
|
+
return httpServer;
|
|
28
|
+
}
|
|
9
29
|
/**
|
|
10
30
|
* Create and start a new PXE HTTP Server
|
|
11
31
|
*/ async function main() {
|
package/dest/config/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type ConfigMappingsType } from '@aztec/foundation/config';
|
|
2
2
|
import { type DataStoreConfig } from '@aztec/kv-store/config';
|
|
3
3
|
import { type ChainConfig } from '@aztec/stdlib/config';
|
|
4
|
-
import type { Network } from '@aztec/stdlib/network';
|
|
5
4
|
export { getPackageInfo } from './package_info.js';
|
|
6
5
|
/**
|
|
7
6
|
* Temporary configuration until WASM can be used instead of native
|
|
@@ -22,15 +21,11 @@ export interface KernelProverConfig {
|
|
|
22
21
|
* Configuration settings for the PXE.
|
|
23
22
|
*/
|
|
24
23
|
export interface PXEConfig {
|
|
25
|
-
/**
|
|
26
|
-
|
|
24
|
+
/** Maximum amount of blocks to pull from the stream in one request when synchronizing */
|
|
25
|
+
l2BlockBatchSize: number;
|
|
27
26
|
}
|
|
28
27
|
export type PXEServiceConfig = PXEConfig & KernelProverConfig & BBProverConfig & DataStoreConfig & ChainConfig;
|
|
29
28
|
export type CliPXEOptions = {
|
|
30
|
-
/** External Aztec network to connect to. e.g. devnet */
|
|
31
|
-
network?: Network;
|
|
32
|
-
/** API Key required by the external network's node */
|
|
33
|
-
apiKey?: string;
|
|
34
29
|
/** Custom Aztec Node URL to connect to */
|
|
35
30
|
nodeUrl?: string;
|
|
36
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAKxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,KAAK,WAAW,EAAuB,MAAM,sBAAsB,CAAC;AAE7E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AACD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,yFAAyF;IACzF,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,kBAAkB,GAAG,cAAc,GAAG,eAAe,GAAG,WAAW,CAAC;AAE/G,MAAM,MAAM,aAAa,GAAG;IAC1B,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,kBAAkB,CAAC,gBAAgB,CA0BlE,CAAC;AAEF;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,CAEtD;AAED,eAAO,MAAM,oBAAoB,EAAE,kBAAkB,CAAC,aAAa,CAKlE,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,kBAAkB,CAAC,aAAa,GAAG,gBAAgB,CAWrF,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,GAAG,gBAAgB,CAQnE"}
|
package/dest/config/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
1
|
import { booleanConfigHelper, getConfigFromMappings, numberConfigHelper, parseBooleanEnv } from '@aztec/foundation/config';
|
|
3
2
|
import { dataConfigMappings } from '@aztec/kv-store/config';
|
|
4
3
|
import { chainConfigMappings } from '@aztec/stdlib/config';
|
|
@@ -6,10 +5,10 @@ export { getPackageInfo } from './package_info.js';
|
|
|
6
5
|
export const pxeConfigMappings = {
|
|
7
6
|
...dataConfigMappings,
|
|
8
7
|
...chainConfigMappings,
|
|
9
|
-
|
|
10
|
-
env: '
|
|
11
|
-
...numberConfigHelper(
|
|
12
|
-
description: '
|
|
8
|
+
l2BlockBatchSize: {
|
|
9
|
+
env: 'PXE_L2_BLOCK_BATCH_SIZE',
|
|
10
|
+
...numberConfigHelper(50),
|
|
11
|
+
description: 'Maximum amount of blocks to pull from the stream in one request when synchronizing'
|
|
13
12
|
},
|
|
14
13
|
bbBinaryPath: {
|
|
15
14
|
env: 'BB_BINARY_PATH',
|
|
@@ -27,7 +26,7 @@ export const pxeConfigMappings = {
|
|
|
27
26
|
proverEnabled: {
|
|
28
27
|
env: 'PXE_PROVER_ENABLED',
|
|
29
28
|
description: 'Enable real proofs',
|
|
30
|
-
...booleanConfigHelper()
|
|
29
|
+
...booleanConfigHelper(true)
|
|
31
30
|
}
|
|
32
31
|
};
|
|
33
32
|
/**
|
|
@@ -36,15 +35,6 @@ export const pxeConfigMappings = {
|
|
|
36
35
|
return getConfigFromMappings(pxeConfigMappings);
|
|
37
36
|
}
|
|
38
37
|
export const pxeCliConfigMappings = {
|
|
39
|
-
network: {
|
|
40
|
-
env: 'NETWORK',
|
|
41
|
-
parseEnv: (val)=>val,
|
|
42
|
-
description: 'External Aztec network to connect to. e.g. devnet'
|
|
43
|
-
},
|
|
44
|
-
apiKey: {
|
|
45
|
-
env: 'API_KEY',
|
|
46
|
-
description: "API Key required by the external network's node"
|
|
47
|
-
},
|
|
48
38
|
nodeUrl: {
|
|
49
39
|
env: 'AZTEC_NODE_URL',
|
|
50
40
|
description: 'Custom Aztec Node URL to connect to'
|
|
@@ -58,7 +48,8 @@ export const allPxeConfigMappings = {
|
|
|
58
48
|
env: 'PXE_PROVER_ENABLED',
|
|
59
49
|
parseEnv: (val)=>parseBooleanEnv(val) || !!process.env.NETWORK,
|
|
60
50
|
description: 'Enable real proofs',
|
|
61
|
-
isBoolean: true
|
|
51
|
+
isBoolean: true,
|
|
52
|
+
defaultValue: true
|
|
62
53
|
}
|
|
63
54
|
};
|
|
64
55
|
/**
|
|
@@ -69,6 +60,6 @@ export const allPxeConfigMappings = {
|
|
|
69
60
|
return {
|
|
70
61
|
...pxeConfig,
|
|
71
62
|
...cliOptions,
|
|
72
|
-
proverEnabled: pxeConfig.proverEnabled
|
|
63
|
+
proverEnabled: pxeConfig.proverEnabled
|
|
73
64
|
};
|
|
74
65
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { type CircuitSimulator } from '@aztec/simulator/client';
|
|
3
|
+
import type { AbiDecoded, FunctionCall } from '@aztec/stdlib/abi';
|
|
4
|
+
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
|
+
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
6
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
+
import { type PrivateKernelExecutionProofOutput, PrivateKernelTailCircuitPublicInputs } from '@aztec/stdlib/kernel';
|
|
8
|
+
import { PrivateExecutionResult, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
9
|
+
import type { ContractDataProvider } from '../storage/index.js';
|
|
10
|
+
import type { ExecutionDataProvider } from './execution_data_provider.js';
|
|
11
|
+
/**
|
|
12
|
+
* The contract function simulator.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ContractFunctionSimulator {
|
|
15
|
+
private executionDataProvider;
|
|
16
|
+
private simulator;
|
|
17
|
+
private log;
|
|
18
|
+
constructor(executionDataProvider: ExecutionDataProvider, simulator: CircuitSimulator);
|
|
19
|
+
/**
|
|
20
|
+
* Runs a private function.
|
|
21
|
+
* @param request - The transaction request.
|
|
22
|
+
* @param entryPointArtifact - The artifact of the entry point function.
|
|
23
|
+
* @param contractAddress - The address of the contract (should match request.origin)
|
|
24
|
+
* @param msgSender - The address calling the function. This can be replaced to simulate a call from another contract
|
|
25
|
+
* or a specific account.
|
|
26
|
+
* @param senderForTags - The address that is used as a tagging sender when emitting private logs. Returned from
|
|
27
|
+
* the `privateGetSenderForTags` oracle.
|
|
28
|
+
* @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
29
|
+
* @returns The result of the execution.
|
|
30
|
+
*/
|
|
31
|
+
run(request: TxExecutionRequest, contractAddress: AztecAddress, selector: FunctionSelector, msgSender?: AztecAddress, senderForTags?: AztecAddress, scopes?: AztecAddress[]): Promise<PrivateExecutionResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Runs a utility function.
|
|
34
|
+
* @param call - The function call to execute.
|
|
35
|
+
* @param authwits - Authentication witnesses required for the function call.
|
|
36
|
+
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
37
|
+
* accounts if not specified.
|
|
38
|
+
* @returns A decoded ABI value containing the function's return data.
|
|
39
|
+
*/
|
|
40
|
+
runUtility(call: FunctionCall, authwits: AuthWitness[], scopes?: AztecAddress[]): Promise<AbiDecoded>;
|
|
41
|
+
getStats(): import("./execution_data_provider.js").ExecutionStats;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Generates the final public inputs of the tail kernel circuit, an empty ClientIVC proof
|
|
45
|
+
* and the execution steps for a `PrivateExecutionResult` as if it had been
|
|
46
|
+
* processed by the private kernel prover. This skips many of the checks performed by the kernels
|
|
47
|
+
* (allowing state overrides) and is much faster, while still generating a valid
|
|
48
|
+
* output that can be sent to the node for public simulation
|
|
49
|
+
* @param privateExecutionResult - The result of the private execution.
|
|
50
|
+
* @param nonceGenerator - A nonce generator for note hashes. According to the protocol rules,
|
|
51
|
+
* it can either be the first nullifier in the tx or the hash of the initial tx request if there are none.
|
|
52
|
+
* @param contractDataProvider - A provider for contract data in order to get function names and debug info.
|
|
53
|
+
* @returns The simulated proving result.
|
|
54
|
+
*/
|
|
55
|
+
export declare function generateSimulatedProvingResult(privateExecutionResult: PrivateExecutionResult, nonceGenerator: Fr, contractDataProvider: ContractDataProvider): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>>;
|
|
56
|
+
//# sourceMappingURL=contract_function_simulator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract_function_simulator.d.ts","sourceRoot":"","sources":["../../src/contract_function_simulator/contract_function_simulator.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAK9C,OAAO,EACL,KAAK,gBAAgB,EAOtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAA+B,MAAM,mBAAmB,CAAC;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG3D,OAAO,EAIL,KAAK,iCAAiC,EACtC,oCAAoC,EAKrC,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EAGL,sBAAsB,EAEtB,kBAAkB,EAEnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAQ1E;;GAEG;AACH,qBAAa,yBAAyB;IAIlC,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,SAAS;IAJnB,OAAO,CAAC,GAAG,CAAS;gBAGV,qBAAqB,EAAE,qBAAqB,EAC5C,SAAS,EAAE,gBAAgB;IAKrC;;;;;;;;;;;OAWG;IACU,GAAG,CACd,OAAO,EAAE,kBAAkB,EAC3B,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,gBAAgB,EAC1B,SAAS,eAA6C,EACtD,aAAa,CAAC,EAAE,YAAY,EAC5B,MAAM,CAAC,EAAE,YAAY,EAAE,GACtB,OAAO,CAAC,sBAAsB,CAAC;IAiGlC;;;;;;;OAOG;IACU,UAAU,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IA0ClH,QAAQ;CAGT;AAYD;;;;;;;;;;;GAWG;AACH,wBAAsB,8BAA8B,CAClD,sBAAsB,EAAE,sBAAsB,EAC9C,cAAc,EAAE,EAAE,EAClB,oBAAoB,EAAE,oBAAoB,GACzC,OAAO,CAAC,iCAAiC,CAAC,oCAAoC,CAAC,CAAC,CA+LlF"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { MAX_CONTRACT_CLASS_LOGS_PER_TX, MAX_ENQUEUED_CALLS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_LOGS_PER_TX } from '@aztec/constants';
|
|
2
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto';
|
|
4
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
7
|
+
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
8
|
+
import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
|
|
9
|
+
import { ExecutionError, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness, witnessMapToFields } from '@aztec/simulator/client';
|
|
10
|
+
import { FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
|
|
11
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
13
|
+
import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
|
|
14
|
+
import { PartialPrivateTailPublicInputsForPublic, PartialPrivateTailPublicInputsForRollup, PrivateKernelTailCircuitPublicInputs, PrivateToPublicAccumulatedData, PrivateToRollupAccumulatedData, PublicCallRequest, ScopedLogHash } from '@aztec/stdlib/kernel';
|
|
15
|
+
import { PrivateLog } from '@aztec/stdlib/logs';
|
|
16
|
+
import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
|
|
17
|
+
import { ClientIvcProof } from '@aztec/stdlib/proofs';
|
|
18
|
+
import { CallContext, HashedValues, PrivateExecutionResult, TxConstantData, collectNested } from '@aztec/stdlib/tx';
|
|
19
|
+
import { ExecutionNoteCache } from './execution_note_cache.js';
|
|
20
|
+
import { HashedValuesCache } from './hashed_values_cache.js';
|
|
21
|
+
import { Oracle } from './oracle/oracle.js';
|
|
22
|
+
import { executePrivateFunction, verifyCurrentClassId } from './oracle/private_execution.js';
|
|
23
|
+
import { PrivateExecutionOracle } from './oracle/private_execution_oracle.js';
|
|
24
|
+
import { UtilityExecutionOracle } from './oracle/utility_execution_oracle.js';
|
|
25
|
+
/**
|
|
26
|
+
* The contract function simulator.
|
|
27
|
+
*/ export class ContractFunctionSimulator {
|
|
28
|
+
executionDataProvider;
|
|
29
|
+
simulator;
|
|
30
|
+
log;
|
|
31
|
+
constructor(executionDataProvider, simulator){
|
|
32
|
+
this.executionDataProvider = executionDataProvider;
|
|
33
|
+
this.simulator = simulator;
|
|
34
|
+
this.log = createLogger('simulator');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Runs a private function.
|
|
38
|
+
* @param request - The transaction request.
|
|
39
|
+
* @param entryPointArtifact - The artifact of the entry point function.
|
|
40
|
+
* @param contractAddress - The address of the contract (should match request.origin)
|
|
41
|
+
* @param msgSender - The address calling the function. This can be replaced to simulate a call from another contract
|
|
42
|
+
* or a specific account.
|
|
43
|
+
* @param senderForTags - The address that is used as a tagging sender when emitting private logs. Returned from
|
|
44
|
+
* the `privateGetSenderForTags` oracle.
|
|
45
|
+
* @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
46
|
+
* @returns The result of the execution.
|
|
47
|
+
*/ async run(request, contractAddress, selector, msgSender = AztecAddress.fromField(Fr.MAX_FIELD_VALUE), senderForTags, scopes) {
|
|
48
|
+
const simulatorSetupTimer = new Timer();
|
|
49
|
+
const header = await this.executionDataProvider.getBlockHeader();
|
|
50
|
+
await verifyCurrentClassId(contractAddress, this.executionDataProvider);
|
|
51
|
+
const entryPointArtifact = await this.executionDataProvider.getFunctionArtifact(contractAddress, selector);
|
|
52
|
+
if (entryPointArtifact.functionType !== FunctionType.PRIVATE) {
|
|
53
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as private`);
|
|
54
|
+
}
|
|
55
|
+
if (request.origin !== contractAddress) {
|
|
56
|
+
this.log.warn(`Request origin does not match contract address in simulation. Request origin: ${request.origin}, contract address: ${contractAddress}`);
|
|
57
|
+
}
|
|
58
|
+
// reserve the first side effect for the tx hash (inserted by the private kernel)
|
|
59
|
+
const startSideEffectCounter = 1;
|
|
60
|
+
const callContext = new CallContext(msgSender, contractAddress, await FunctionSelector.fromNameAndParameters(entryPointArtifact.name, entryPointArtifact.parameters), entryPointArtifact.isStatic);
|
|
61
|
+
const txRequestHash = await request.toTxRequest().hash();
|
|
62
|
+
const noteCache = new ExecutionNoteCache(txRequestHash);
|
|
63
|
+
const privateExecutionOracle = new PrivateExecutionOracle(request.firstCallArgsHash, request.txContext, callContext, header, request.authWitnesses, request.capsules, HashedValuesCache.create(request.argsOfCalls), noteCache, this.executionDataProvider, this.simulator, 0, startSideEffectCounter, undefined, scopes, senderForTags);
|
|
64
|
+
const setupTime = simulatorSetupTimer.ms();
|
|
65
|
+
try {
|
|
66
|
+
// Note: any nested private function calls are made recursively within this
|
|
67
|
+
// function call. So this execution result is the result of executing _all_
|
|
68
|
+
// private functions of this tx (the results of those executions are contained
|
|
69
|
+
// within executionResult.nestedExecutionResults).
|
|
70
|
+
const executionResult = await executePrivateFunction(this.simulator, privateExecutionOracle, entryPointArtifact, contractAddress, request.functionSelector);
|
|
71
|
+
const simulatorTeardownTimer = new Timer();
|
|
72
|
+
const { usedTxRequestHashForNonces } = noteCache.finish();
|
|
73
|
+
const firstNullifierHint = usedTxRequestHashForNonces ? Fr.ZERO : noteCache.getAllNullifiers()[0];
|
|
74
|
+
const publicCallRequests = collectNested([
|
|
75
|
+
executionResult
|
|
76
|
+
], (r)=>r.publicInputs.publicCallRequests.getActiveItems().map((r)=>r.inner).concat(r.publicInputs.publicTeardownCallRequest.isEmpty() ? [] : [
|
|
77
|
+
r.publicInputs.publicTeardownCallRequest
|
|
78
|
+
]));
|
|
79
|
+
const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
|
|
80
|
+
const calldata = await privateExecutionOracle.privateLoadFromExecutionCache(r.calldataHash);
|
|
81
|
+
return new HashedValues(calldata, r.calldataHash);
|
|
82
|
+
}));
|
|
83
|
+
const teardownTime = simulatorTeardownTimer.ms();
|
|
84
|
+
// Add simulator overhead to topmost call in the stack
|
|
85
|
+
if (executionResult.profileResult) {
|
|
86
|
+
executionResult.profileResult.timings.witgen += setupTime + teardownTime;
|
|
87
|
+
}
|
|
88
|
+
// Not to be confused with a PrivateCallExecutionResult. This is a superset
|
|
89
|
+
// of the PrivateCallExecutionResult, containing also firstNullifierHint
|
|
90
|
+
// and publicFunctionsCalldata.
|
|
91
|
+
return new PrivateExecutionResult(executionResult, firstNullifierHint, publicFunctionsCalldata);
|
|
92
|
+
} catch (err) {
|
|
93
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// docs:start:execute_utility_function
|
|
97
|
+
/**
|
|
98
|
+
* Runs a utility function.
|
|
99
|
+
* @param call - The function call to execute.
|
|
100
|
+
* @param authwits - Authentication witnesses required for the function call.
|
|
101
|
+
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
102
|
+
* accounts if not specified.
|
|
103
|
+
* @returns A decoded ABI value containing the function's return data.
|
|
104
|
+
*/ async runUtility(call, authwits, scopes) {
|
|
105
|
+
await verifyCurrentClassId(call.to, this.executionDataProvider);
|
|
106
|
+
const entryPointArtifact = await this.executionDataProvider.getFunctionArtifact(call.to, call.selector);
|
|
107
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
108
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
109
|
+
}
|
|
110
|
+
const oracle = new UtilityExecutionOracle(call.to, authwits, [], this.executionDataProvider, undefined, scopes);
|
|
111
|
+
try {
|
|
112
|
+
this.log.verbose(`Executing utility function ${entryPointArtifact.name}`, {
|
|
113
|
+
contract: call.to,
|
|
114
|
+
selector: call.selector
|
|
115
|
+
});
|
|
116
|
+
const initialWitness = toACVMWitness(0, call.args);
|
|
117
|
+
const acirExecutionResult = await this.simulator.executeUserCircuit(initialWitness, entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
|
|
118
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
119
|
+
throw new ExecutionError(err.message, {
|
|
120
|
+
contractAddress: call.to,
|
|
121
|
+
functionSelector: call.selector
|
|
122
|
+
}, extractCallStack(err, entryPointArtifact.debug), {
|
|
123
|
+
cause: err
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness);
|
|
127
|
+
this.log.verbose(`Utility simulation for ${call.to}.${call.selector} completed`);
|
|
128
|
+
return decodeFromAbi(entryPointArtifact.returnTypes, returnWitness);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// docs:end:execute_utility_function
|
|
134
|
+
getStats() {
|
|
135
|
+
return this.executionDataProvider.getStats();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
class OrderedSideEffect {
|
|
139
|
+
sideEffect;
|
|
140
|
+
counter;
|
|
141
|
+
constructor(sideEffect, counter){
|
|
142
|
+
this.sideEffect = sideEffect;
|
|
143
|
+
this.counter = counter;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Generates the final public inputs of the tail kernel circuit, an empty ClientIVC proof
|
|
148
|
+
* and the execution steps for a `PrivateExecutionResult` as if it had been
|
|
149
|
+
* processed by the private kernel prover. This skips many of the checks performed by the kernels
|
|
150
|
+
* (allowing state overrides) and is much faster, while still generating a valid
|
|
151
|
+
* output that can be sent to the node for public simulation
|
|
152
|
+
* @param privateExecutionResult - The result of the private execution.
|
|
153
|
+
* @param nonceGenerator - A nonce generator for note hashes. According to the protocol rules,
|
|
154
|
+
* it can either be the first nullifier in the tx or the hash of the initial tx request if there are none.
|
|
155
|
+
* @param contractDataProvider - A provider for contract data in order to get function names and debug info.
|
|
156
|
+
* @returns The simulated proving result.
|
|
157
|
+
*/ export async function generateSimulatedProvingResult(privateExecutionResult, nonceGenerator, contractDataProvider) {
|
|
158
|
+
const siloedNoteHashes = [];
|
|
159
|
+
const nullifiers = [];
|
|
160
|
+
const taggedPrivateLogs = [];
|
|
161
|
+
const l2ToL1Messages = [];
|
|
162
|
+
const contractClassLogsHashes = [];
|
|
163
|
+
const publicCallRequests = [];
|
|
164
|
+
const executionSteps = [];
|
|
165
|
+
let publicTeardownCallRequest;
|
|
166
|
+
const executions = [
|
|
167
|
+
privateExecutionResult.entrypoint
|
|
168
|
+
];
|
|
169
|
+
while(executions.length !== 0){
|
|
170
|
+
const execution = executions.shift();
|
|
171
|
+
executions.unshift(...execution.nestedExecutionResults);
|
|
172
|
+
const { contractAddress } = execution.publicInputs.callContext;
|
|
173
|
+
const noteHashesFromExecution = await Promise.all(execution.publicInputs.noteHashes.getActiveItems().filter((noteHash)=>!noteHash.isEmpty()).map(async (noteHash)=>new OrderedSideEffect(await siloNoteHash(contractAddress, noteHash.value), noteHash.counter)));
|
|
174
|
+
const nullifiersFromExecution = await Promise.all(execution.publicInputs.nullifiers.getActiveItems().map(async (nullifier)=>new OrderedSideEffect(await siloNullifier(contractAddress, nullifier.value), nullifier.counter)));
|
|
175
|
+
const privateLogsFromExecution = await Promise.all(execution.publicInputs.privateLogs.getActiveItems().map(async (metadata)=>{
|
|
176
|
+
metadata.log.fields[0] = await poseidon2Hash([
|
|
177
|
+
contractAddress,
|
|
178
|
+
metadata.log.fields[0]
|
|
179
|
+
]);
|
|
180
|
+
return new OrderedSideEffect(metadata.log, metadata.counter);
|
|
181
|
+
}));
|
|
182
|
+
siloedNoteHashes.push(...noteHashesFromExecution);
|
|
183
|
+
taggedPrivateLogs.push(...privateLogsFromExecution);
|
|
184
|
+
nullifiers.push(...nullifiersFromExecution);
|
|
185
|
+
l2ToL1Messages.push(...execution.publicInputs.l2ToL1Msgs.getActiveItems().map((message)=>new OrderedSideEffect(message.message.scope(contractAddress), message.counter)));
|
|
186
|
+
contractClassLogsHashes.push(...execution.publicInputs.contractClassLogsHashes.getActiveItems().map((contractClassLogHash)=>new OrderedSideEffect(contractClassLogHash.logHash.scope(contractAddress), contractClassLogHash.counter)));
|
|
187
|
+
publicCallRequests.push(...execution.publicInputs.publicCallRequests.getActiveItems().map((callRequest)=>new OrderedSideEffect(callRequest.inner, callRequest.counter)));
|
|
188
|
+
if (publicTeardownCallRequest !== undefined && !execution.publicInputs.publicTeardownCallRequest.isEmpty()) {
|
|
189
|
+
throw new Error('Trying to set multiple teardown requests');
|
|
190
|
+
}
|
|
191
|
+
publicTeardownCallRequest = execution.publicInputs.publicTeardownCallRequest.isEmpty() ? publicTeardownCallRequest : execution.publicInputs.publicTeardownCallRequest;
|
|
192
|
+
executionSteps.push({
|
|
193
|
+
functionName: await contractDataProvider.getDebugFunctionName(execution.publicInputs.callContext.contractAddress, execution.publicInputs.callContext.functionSelector),
|
|
194
|
+
timings: execution.profileResult?.timings ?? {
|
|
195
|
+
witgen: 0,
|
|
196
|
+
oracles: {}
|
|
197
|
+
},
|
|
198
|
+
bytecode: execution.acir,
|
|
199
|
+
vk: execution.vk,
|
|
200
|
+
witness: execution.partialWitness
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
const constantData = new TxConstantData(privateExecutionResult.entrypoint.publicInputs.historicalHeader, privateExecutionResult.entrypoint.publicInputs.txContext, getVKTreeRoot(), protocolContractTreeRoot);
|
|
204
|
+
const hasPublicCalls = privateExecutionResult.publicFunctionCalldata.length !== 0;
|
|
205
|
+
let inputsForRollup;
|
|
206
|
+
let inputsForPublic;
|
|
207
|
+
const sortByCounter = (a, b)=>a.counter - b.counter;
|
|
208
|
+
const getEffect = (orderedSideEffect)=>orderedSideEffect.sideEffect;
|
|
209
|
+
const sortedNullifiers = nullifiers.sort(sortByCounter).map(getEffect);
|
|
210
|
+
// If the tx generated no nullifiers, the nonce generator (txRequest hash)
|
|
211
|
+
// is injected as the first nullifier as per protocol rules.
|
|
212
|
+
if (sortedNullifiers.length === 0) {
|
|
213
|
+
sortedNullifiers.push(nonceGenerator);
|
|
214
|
+
}
|
|
215
|
+
// Private only
|
|
216
|
+
if (privateExecutionResult.publicFunctionCalldata.length === 0) {
|
|
217
|
+
// In case the tx only contains private functions, we must make the note hashes unique by using the
|
|
218
|
+
// nonce generator and their index in the tx.
|
|
219
|
+
const uniqueNoteHashes = await Promise.all(siloedNoteHashes.sort(sortByCounter).map(async (orderedSideEffect, i)=>{
|
|
220
|
+
const siloedNoteHash = orderedSideEffect.sideEffect;
|
|
221
|
+
const nonce = await computeNoteHashNonce(nonceGenerator, i);
|
|
222
|
+
const uniqueNoteHash = await computeUniqueNoteHash(nonce, siloedNoteHash);
|
|
223
|
+
return uniqueNoteHash;
|
|
224
|
+
}));
|
|
225
|
+
const accumulatedDataForRollup = new PrivateToRollupAccumulatedData(padArrayEnd(uniqueNoteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX), padArrayEnd(sortedNullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX), padArrayEnd(l2ToL1Messages.sort(sortByCounter).map(getEffect), ScopedL2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_TX), padArrayEnd(taggedPrivateLogs.sort(sortByCounter).map(getEffect), PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX), padArrayEnd(contractClassLogsHashes.sort(sortByCounter).map(getEffect), ScopedLogHash.empty(), MAX_CONTRACT_CLASS_LOGS_PER_TX));
|
|
226
|
+
inputsForRollup = new PartialPrivateTailPublicInputsForRollup(accumulatedDataForRollup);
|
|
227
|
+
} else {
|
|
228
|
+
const nonRevertibleData = PrivateToPublicAccumulatedData.empty();
|
|
229
|
+
// The nullifier array contains the nonce generator in position 0
|
|
230
|
+
// Here we remove it from the revertible data and
|
|
231
|
+
// add it as the first non-revertible nullifier (we can't have dupes!)
|
|
232
|
+
// This is because public processor will use that first non-revertible nullifier
|
|
233
|
+
// as the nonce generator for the note hashes in the revertible part of the tx.
|
|
234
|
+
const [firstNullifier] = sortedNullifiers.splice(0, 1);
|
|
235
|
+
nonRevertibleData.nullifiers[0] = firstNullifier;
|
|
236
|
+
const revertibleData = new PrivateToPublicAccumulatedData(padArrayEnd(siloedNoteHashes.sort(sortByCounter).map(getEffect), Fr.ZERO, MAX_NOTE_HASHES_PER_TX), padArrayEnd(sortedNullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX), padArrayEnd(l2ToL1Messages.sort(sortByCounter).map(getEffect), ScopedL2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_TX), padArrayEnd(taggedPrivateLogs.sort(sortByCounter).map(getEffect), PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX), padArrayEnd(contractClassLogsHashes.sort(sortByCounter).map(getEffect), ScopedLogHash.empty(), MAX_CONTRACT_CLASS_LOGS_PER_TX), padArrayEnd(publicCallRequests.sort(sortByCounter).map(getEffect), PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX));
|
|
237
|
+
inputsForPublic = new PartialPrivateTailPublicInputsForPublic(nonRevertibleData, revertibleData, publicTeardownCallRequest ?? PublicCallRequest.empty());
|
|
238
|
+
}
|
|
239
|
+
const publicInputs = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*includeByTimestamp=*/ 0n, hasPublicCalls ? inputsForPublic : undefined, !hasPublicCalls ? inputsForRollup : undefined);
|
|
240
|
+
return {
|
|
241
|
+
publicInputs,
|
|
242
|
+
clientIvcProof: ClientIvcProof.empty(),
|
|
243
|
+
executionSteps: executionSteps
|
|
244
|
+
};
|
|
245
|
+
}
|