@aztec/pxe 5.0.0-rc.2 → 5.0.1
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/block_synchronizer/block_synchronizer.d.ts +5 -3
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +7 -1
- package/dest/contract/contract_class_service.d.ts +31 -0
- package/dest/contract/contract_class_service.d.ts.map +1 -0
- package/dest/contract/contract_class_service.js +68 -0
- package/dest/{contract_sync → contract}/contract_sync_service.d.ts +7 -6
- package/dest/contract/contract_sync_service.d.ts.map +1 -0
- package/dest/{contract_sync → contract}/contract_sync_service.js +10 -30
- package/dest/contract/helpers.d.ts +7 -0
- package/dest/contract/helpers.d.ts.map +1 -0
- package/dest/contract/helpers.js +20 -0
- package/dest/contract_function_simulator/anchored_contract_data.d.ts +36 -0
- package/dest/contract_function_simulator/anchored_contract_data.d.ts.map +1 -0
- package/dest/contract_function_simulator/anchored_contract_data.js +54 -0
- package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +39 -0
- package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/aztec_node_read_cache.js +60 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +9 -3
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +31 -14
- package/dest/contract_function_simulator/execution_note_cache.d.ts +3 -9
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.js +8 -28
- package/dest/contract_function_simulator/index.d.ts +4 -2
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +2 -1
- package/dest/contract_function_simulator/noir-structs/fact.d.ts +5 -5
- package/dest/contract_function_simulator/noir-structs/fact.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/fact.js +2 -2
- package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts +3 -3
- package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/fact_collection.js +3 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +7 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts +11 -0
- package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/pending_tagged_log.js +4 -0
- package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts +2 -2
- package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/provided_secret.js +1 -1
- package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts +8 -1
- package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.js +17 -0
- package/dest/contract_function_simulator/oracle/acir_callback.d.ts +7 -2
- package/dest/contract_function_simulator/oracle/acir_callback.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/acir_callback.js +55 -11
- package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts +39 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_registry.js +107 -0
- package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +11 -7
- package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle_registry.js +50 -10
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +48 -9
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +51 -30
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +10 -2
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +73 -32
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +23 -16
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +105 -60
- package/dest/debug/pxe_debug_utils.d.ts +2 -2
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.d.ts +2 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +1 -0
- 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 +2 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +1 -0
- 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/store.d.ts +14 -0
- package/dest/entrypoints/client/store.d.ts.map +1 -0
- package/dest/entrypoints/client/store.js +28 -0
- package/dest/entrypoints/server/index.d.ts +6 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +4 -1
- package/dest/entrypoints/server/store.d.ts +18 -0
- package/dest/entrypoints/server/store.d.ts.map +1 -0
- package/dest/entrypoints/server/store.js +28 -0
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +8 -2
- package/dest/error_enriching.d.ts +5 -3
- package/dest/error_enriching.d.ts.map +1 -1
- package/dest/error_enriching.js +12 -10
- package/dest/hooks/execution_hooks.d.ts +15 -4
- package/dest/hooks/execution_hooks.d.ts.map +1 -1
- package/dest/hooks/index.d.ts +3 -2
- package/dest/hooks/index.d.ts.map +1 -1
- package/dest/hooks/index.js +1 -0
- package/dest/hooks/resolve_custom_request.d.ts +23 -0
- package/dest/hooks/resolve_custom_request.d.ts.map +1 -0
- package/dest/hooks/resolve_custom_request.js +3 -0
- package/dest/hooks/resolve_tagging_secret_strategy.d.ts +10 -1
- package/dest/hooks/resolve_tagging_secret_strategy.d.ts.map +1 -1
- package/dest/hooks/resolve_tagging_secret_strategy.js +3 -3
- package/dest/logs/log_service.d.ts +5 -3
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +38 -17
- package/dest/notes/note_service.d.ts +1 -1
- package/dest/notes/note_service.js +1 -1
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +6 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +17 -36
- package/dest/private_kernel/private_kernel_oracle.d.ts +4 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +17 -5
- package/dest/pxe.d.ts +81 -46
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +138 -104
- package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +1 -1
- package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -1
- package/dest/storage/backwards_compatibility_tests/schema_tests.js +31 -7
- package/dest/storage/contract_store/contract_store.d.ts +27 -24
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +63 -74
- package/dest/storage/fact_store/fact_service.d.ts +6 -4
- package/dest/storage/fact_store/fact_service.d.ts.map +1 -1
- package/dest/storage/fact_store/fact_service.js +19 -4
- package/dest/storage/fact_store/fact_store.d.ts +1 -1
- package/dest/storage/fact_store/fact_store.js +1 -1
- package/dest/storage/fact_store/index.d.ts +2 -1
- package/dest/storage/fact_store/index.d.ts.map +1 -1
- package/dest/storage/fact_store/index.js +1 -0
- package/dest/storage/fact_store/origin_state.d.ts +57 -0
- package/dest/storage/fact_store/origin_state.d.ts.map +1 -0
- package/dest/storage/fact_store/origin_state.js +53 -0
- package/dest/storage/metadata.d.ts +2 -2
- package/dest/storage/metadata.d.ts.map +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/store_identity.d.ts +35 -0
- package/dest/storage/store_identity.d.ts.map +1 -0
- package/dest/storage/store_identity.js +44 -0
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -3
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +48 -11
- package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts +17 -6
- package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/tagging_secret_sources_store.js +24 -11
- package/dest/tagging/constants.d.ts +2 -2
- package/dest/tagging/constants.d.ts.map +1 -1
- package/dest/tagging/constants.js +18 -9
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +6 -2
- package/package.json +17 -17
- package/src/block_synchronizer/block_synchronizer.ts +9 -1
- package/src/contract/contract_class_service.ts +83 -0
- package/src/{contract_sync → contract}/contract_sync_service.ts +18 -37
- package/src/contract/helpers.ts +35 -0
- package/src/contract_function_simulator/anchored_contract_data.ts +74 -0
- package/src/contract_function_simulator/aztec_node_read_cache.ts +89 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +56 -14
- package/src/contract_function_simulator/execution_note_cache.ts +7 -28
- package/src/contract_function_simulator/index.ts +7 -1
- package/src/contract_function_simulator/noir-structs/fact.ts +4 -4
- package/src/contract_function_simulator/noir-structs/fact_collection.ts +9 -4
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +6 -0
- package/src/contract_function_simulator/noir-structs/pending_tagged_log.ts +12 -0
- package/src/contract_function_simulator/noir-structs/provided_secret.ts +1 -1
- package/src/contract_function_simulator/noir-structs/resolved_tagging_strategy.ts +21 -0
- package/src/contract_function_simulator/oracle/acir_callback.ts +58 -12
- package/src/contract_function_simulator/oracle/legacy_oracle_registry.ts +147 -0
- package/src/contract_function_simulator/oracle/oracle_registry.ts +37 -7
- package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +49 -32
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +92 -41
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +149 -71
- package/src/debug/pxe_debug_utils.ts +1 -1
- package/src/entrypoints/client/bundle/index.ts +1 -0
- package/src/entrypoints/client/bundle/utils.ts +16 -4
- package/src/entrypoints/client/lazy/index.ts +1 -0
- package/src/entrypoints/client/lazy/utils.ts +16 -4
- package/src/entrypoints/client/store.ts +38 -0
- package/src/entrypoints/server/index.ts +6 -1
- package/src/entrypoints/server/store.ts +47 -0
- package/src/entrypoints/server/utils.ts +21 -7
- package/src/error_enriching.ts +26 -10
- package/src/hooks/execution_hooks.ts +14 -3
- package/src/hooks/index.ts +2 -0
- package/src/hooks/resolve_custom_request.ts +24 -0
- package/src/hooks/resolve_tagging_secret_strategy.ts +14 -0
- package/src/logs/log_service.ts +35 -11
- package/src/notes/note_service.ts +1 -1
- package/src/oracle_version.ts +2 -2
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +11 -1
- package/src/private_kernel/private_kernel_execution_prover.ts +22 -52
- package/src/private_kernel/private_kernel_oracle.ts +23 -4
- package/src/pxe.ts +212 -143
- package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +6 -6
- package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +1 -1
- package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +12 -12
- package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +11 -3
- package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +12 -4
- package/src/storage/backwards_compatibility_tests/__snapshots__/TaggingSecretSourcesStore.json +3 -3
- package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +1 -1
- package/src/storage/backwards_compatibility_tests/schema_tests.ts +38 -4
- package/src/storage/contract_store/contract_store.ts +85 -92
- package/src/storage/fact_store/fact_service.ts +29 -5
- package/src/storage/fact_store/fact_store.ts +1 -1
- package/src/storage/fact_store/index.ts +10 -0
- package/src/storage/fact_store/origin_state.ts +75 -0
- package/src/storage/metadata.ts +1 -1
- package/src/storage/store_identity.ts +72 -0
- package/src/storage/tagging_store/sender_tagging_store.ts +62 -15
- package/src/storage/tagging_store/tagging_secret_sources_store.ts +36 -15
- package/src/tagging/constants.ts +19 -9
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +1 -1
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +6 -2
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +0 -6
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +0 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +0 -51
- package/dest/contract_sync/contract_sync_service.d.ts.map +0 -1
- package/dest/contract_sync/helpers.d.ts +0 -28
- package/dest/contract_sync/helpers.d.ts.map +0 -1
- package/dest/contract_sync/helpers.js +0 -48
- package/src/contract_function_simulator/proxied_contract_data_source.ts +0 -60
- package/src/contract_sync/helpers.ts +0 -79
|
@@ -22,30 +22,45 @@ import type { NullifierMembershipWitness } from '@aztec/stdlib/trees';
|
|
|
22
22
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
23
23
|
import type { VerificationKeyAsFields } from '@aztec/stdlib/vks';
|
|
24
24
|
|
|
25
|
+
import type { ContractClassService } from '../contract/contract_class_service.js';
|
|
26
|
+
import { AnchoredContractData } from '../contract_function_simulator/anchored_contract_data.js';
|
|
25
27
|
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* Provides functionality needed by the private kernel for interacting with our state trees.
|
|
29
31
|
*/
|
|
30
32
|
export class PrivateKernelOracle {
|
|
33
|
+
private readonly anchoredContractData: AnchoredContractData;
|
|
34
|
+
|
|
31
35
|
constructor(
|
|
32
36
|
private contractStore: ContractStore,
|
|
37
|
+
contractClassService: ContractClassService,
|
|
33
38
|
private keyStore: KeyStore,
|
|
34
39
|
private node: AztecNode,
|
|
35
40
|
private blockHeader: BlockHeader,
|
|
36
|
-
) {
|
|
41
|
+
) {
|
|
42
|
+
// Kernels never use contract overrides (those are confined to simulations, which skip proving), so this view is
|
|
43
|
+
// built without them.
|
|
44
|
+
this.anchoredContractData = new AnchoredContractData(contractStore, contractClassService, blockHeader);
|
|
45
|
+
}
|
|
37
46
|
|
|
38
47
|
/** Retrieves the preimage of a contract address from the registered contract instances db. */
|
|
39
48
|
public async getContractAddressPreimage(
|
|
40
49
|
address: AztecAddress,
|
|
41
50
|
): Promise<ContractInstanceWithAddress & { saltedInitializationHash: Fr }> {
|
|
42
|
-
const instance = await this.
|
|
51
|
+
const instance = await this.anchoredContractData.getContractInstance(address);
|
|
43
52
|
if (!instance) {
|
|
44
53
|
throw new Error(`Contract instance not found when getting address preimage. Contract address: ${address}.`);
|
|
45
54
|
}
|
|
55
|
+
// Local instance existence was checked above, so resolution below cannot come back empty.
|
|
56
|
+
const currentContractClassId = await this.anchoredContractData.getCurrentClassId(address);
|
|
57
|
+
if (!currentContractClassId) {
|
|
58
|
+
throw new Error(`Could not resolve the current class id for registered contract ${address}.`);
|
|
59
|
+
}
|
|
46
60
|
return {
|
|
47
61
|
saltedInitializationHash: await computeSaltedInitializationHash(instance),
|
|
48
62
|
...instance,
|
|
63
|
+
currentContractClassId,
|
|
49
64
|
};
|
|
50
65
|
}
|
|
51
66
|
|
|
@@ -114,8 +129,12 @@ export class PrivateKernelOracle {
|
|
|
114
129
|
}
|
|
115
130
|
|
|
116
131
|
/** Use debug data to get the function name corresponding to a selector. */
|
|
117
|
-
public getDebugFunctionName(
|
|
118
|
-
|
|
132
|
+
public async getDebugFunctionName(
|
|
133
|
+
contractAddress: AztecAddress,
|
|
134
|
+
selector: FunctionSelector,
|
|
135
|
+
): Promise<string | undefined> {
|
|
136
|
+
const classId = await this.anchoredContractData.getCurrentClassId(contractAddress);
|
|
137
|
+
return classId ? this.contractStore.getDebugFunctionName(classId, selector) : undefined;
|
|
119
138
|
}
|
|
120
139
|
|
|
121
140
|
/**
|
package/src/pxe.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundatio
|
|
|
6
6
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
7
7
|
import { Timer } from '@aztec/foundation/timer';
|
|
8
8
|
import { KeyStore } from '@aztec/key-store';
|
|
9
|
+
import type { AccountPrivacyKeys, AccountPrivacySecretKeys } from '@aztec/key-store';
|
|
9
10
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
10
11
|
import { type ProtocolContractsProvider, protocolContractNames } from '@aztec/protocol-contracts';
|
|
11
12
|
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
@@ -13,6 +14,7 @@ import {
|
|
|
13
14
|
type ContractArtifact,
|
|
14
15
|
EventSelector,
|
|
15
16
|
FunctionCall,
|
|
17
|
+
type FunctionSelector,
|
|
16
18
|
FunctionType,
|
|
17
19
|
decodeFunctionSignature,
|
|
18
20
|
} from '@aztec/stdlib/abi';
|
|
@@ -21,10 +23,11 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
21
23
|
import { GENESIS_BLOCK_HEADER_HASH, type L2TipsProvider } from '@aztec/stdlib/block';
|
|
22
24
|
import {
|
|
23
25
|
CompleteAddress,
|
|
26
|
+
type ContractInstancePreimage,
|
|
27
|
+
type ContractInstancePreimageWithAddress,
|
|
24
28
|
type ContractInstanceWithAddress,
|
|
25
29
|
type PartialAddress,
|
|
26
30
|
computeContractAddressFromInstance,
|
|
27
|
-
getContractClassFromArtifact,
|
|
28
31
|
} from '@aztec/stdlib/contract';
|
|
29
32
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
30
33
|
import type { AztecNode, AztecNodeDebug, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
|
|
@@ -33,6 +36,8 @@ import type {
|
|
|
33
36
|
PrivateKernelExecutionProofOutput,
|
|
34
37
|
PrivateKernelTailCircuitPublicInputs,
|
|
35
38
|
} from '@aztec/stdlib/kernel';
|
|
39
|
+
import { computeAddressSecret } from '@aztec/stdlib/keys';
|
|
40
|
+
import { deriveEcdhSharedSecretPoint, protectFromForgery } from '@aztec/stdlib/logs';
|
|
36
41
|
import {
|
|
37
42
|
BlockHeader,
|
|
38
43
|
type ContractOverrides,
|
|
@@ -55,15 +60,14 @@ import { inspect } from 'util';
|
|
|
55
60
|
|
|
56
61
|
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
57
62
|
import type { PXEConfig } from './config/index.js';
|
|
63
|
+
import { ContractClassService } from './contract/contract_class_service.js';
|
|
64
|
+
import { ContractSyncService } from './contract/contract_sync_service.js';
|
|
58
65
|
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
59
66
|
import {
|
|
60
67
|
ContractFunctionSimulator,
|
|
61
68
|
generateSimulatedProvingResult,
|
|
62
69
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
63
|
-
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
64
70
|
import { displayDebugLogs } from './contract_logging.js';
|
|
65
|
-
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
66
|
-
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
67
71
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
68
72
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
69
73
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
@@ -85,7 +89,10 @@ import { openPxeStores } from './storage/open_pxe_stores.js';
|
|
|
85
89
|
import { PrivateEventStore } from './storage/private_event_store/private_event_store.js';
|
|
86
90
|
import { RecipientTaggingStore } from './storage/tagging_store/recipient_tagging_store.js';
|
|
87
91
|
import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store.js';
|
|
88
|
-
import {
|
|
92
|
+
import {
|
|
93
|
+
type SharedSecretKind,
|
|
94
|
+
TaggingSecretSourcesStore,
|
|
95
|
+
} from './storage/tagging_store/tagging_secret_sources_store.js';
|
|
89
96
|
import { persistSenderTaggingIndexRangesForTx } from './tagging/index.js';
|
|
90
97
|
|
|
91
98
|
export type PackedPrivateEvent = InTx & {
|
|
@@ -189,18 +196,33 @@ export type PXECreateArgs = {
|
|
|
189
196
|
hooks?: ExecutionHooks;
|
|
190
197
|
};
|
|
191
198
|
|
|
192
|
-
/**
|
|
193
|
-
* A source from which PXE derives the tagging secrets it scans for to discover incoming private logs.
|
|
194
|
-
*
|
|
195
|
-
* - `address-derived`: derives a shared secret via ECDH from an external `sender` address against every account
|
|
196
|
-
* registered in this PXE (present and future), so registering one sender applies it to all of them. The address is
|
|
197
|
-
* not secret, so unlike `arbitrary-secret` it can be reused freely across recipients.
|
|
198
|
-
* - `arbitrary-secret`: a shared secret point provided directly, scoped to a single recipient. It bypasses ECDH, so it
|
|
199
|
-
* must not be reused across recipients (each would then be able to find the others' tags).
|
|
200
|
-
*/
|
|
199
|
+
/** A source from which PXE derives the tagging secrets it scans for to discover incoming private logs. */
|
|
201
200
|
export type TaggingSecretSource =
|
|
201
|
+
/**
|
|
202
|
+
* Derives a shared secret via ECDH from an external `sender` address against every account registered in this PXE
|
|
203
|
+
* (present and future), so registering one sender applies it to all of them. The address is not secret, so unlike
|
|
204
|
+
* `arbitrary-secret` it can be reused freely across recipients.
|
|
205
|
+
*/
|
|
202
206
|
| { kind: 'address-derived'; sender: AztecAddress }
|
|
203
|
-
|
|
207
|
+
/**
|
|
208
|
+
* A shared secret point provided directly, scoped to a single recipient. It bypasses ECDH, so it must not be
|
|
209
|
+
* reused across recipients (each would then be able to find the others' tags).
|
|
210
|
+
*/
|
|
211
|
+
| { kind: 'arbitrary-secret'; recipient: AztecAddress; secret: Point }
|
|
212
|
+
/**
|
|
213
|
+
* A handshake known by the x-coordinate of its ephemeral public key (the value a recipient learns while authorizing
|
|
214
|
+
* an interactive handshake, which emits no discoverable announcement). The ephemeral key's y-coordinate is always
|
|
215
|
+
* positive by protocol construction, so the x-coordinate alone identifies it.
|
|
216
|
+
*/
|
|
217
|
+
| { kind: 'handshake'; recipient: AztecAddress; ephPk: Fr };
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The registered form of a {@link TaggingSecretSource}.
|
|
221
|
+
*/
|
|
222
|
+
export type RegisteredTaggingSecretSource =
|
|
223
|
+
| Exclude<TaggingSecretSource, { kind: 'handshake' }>
|
|
224
|
+
/** A handshake's resolved shared secret, derived at registration from the handshake's ephemeral key. */
|
|
225
|
+
| { kind: 'handshake'; recipient: AztecAddress; secret: Point };
|
|
204
226
|
|
|
205
227
|
/**
|
|
206
228
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
@@ -224,6 +246,7 @@ export class PXE {
|
|
|
224
246
|
private addressStore: AddressStore,
|
|
225
247
|
private privateEventStore: PrivateEventStore,
|
|
226
248
|
private contractSyncService: ContractSyncService,
|
|
249
|
+
private contractClassService: ContractClassService,
|
|
227
250
|
private txResolver: TxResolverService,
|
|
228
251
|
private l2TipsStore: L2TipsProvider,
|
|
229
252
|
private simulator: CircuitSimulator,
|
|
@@ -292,9 +315,11 @@ export class PXE {
|
|
|
292
315
|
l2TipsStore,
|
|
293
316
|
factStore,
|
|
294
317
|
} = openPxeStores(store, initialBlockHash);
|
|
318
|
+
const contractClassService = new ContractClassService(node, contractStore);
|
|
295
319
|
const contractSyncService = new ContractSyncService(
|
|
296
320
|
node,
|
|
297
321
|
contractStore,
|
|
322
|
+
contractClassService,
|
|
298
323
|
noteStore,
|
|
299
324
|
createLogger('pxe:contract_sync', bindings),
|
|
300
325
|
);
|
|
@@ -309,6 +334,7 @@ export class PXE {
|
|
|
309
334
|
factStore,
|
|
310
335
|
l2TipsStore,
|
|
311
336
|
contractSyncService,
|
|
337
|
+
contractClassService,
|
|
312
338
|
config,
|
|
313
339
|
bindings,
|
|
314
340
|
);
|
|
@@ -345,6 +371,7 @@ export class PXE {
|
|
|
345
371
|
addressStore,
|
|
346
372
|
privateEventStore,
|
|
347
373
|
contractSyncService,
|
|
374
|
+
contractClassService,
|
|
348
375
|
txResolver,
|
|
349
376
|
l2TipsStore,
|
|
350
377
|
simulator,
|
|
@@ -376,10 +403,10 @@ export class PXE {
|
|
|
376
403
|
// Internal methods
|
|
377
404
|
|
|
378
405
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
379
|
-
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
380
|
-
|
|
381
406
|
return new ContractFunctionSimulator({
|
|
382
|
-
contractStore:
|
|
407
|
+
contractStore: this.contractStore,
|
|
408
|
+
contractClassService: this.contractClassService,
|
|
409
|
+
overrides: overrides?.contracts,
|
|
383
410
|
noteStore: this.noteStore,
|
|
384
411
|
keyStore: this.keyStore,
|
|
385
412
|
addressStore: this.addressStore,
|
|
@@ -398,6 +425,30 @@ export class PXE {
|
|
|
398
425
|
});
|
|
399
426
|
}
|
|
400
427
|
|
|
428
|
+
/** Best-effort debug function name for the class `address` runs at `anchorBlockHeader`. Used for log display only. */
|
|
429
|
+
async #getDebugFunctionName(
|
|
430
|
+
address: AztecAddress,
|
|
431
|
+
selector: FunctionSelector,
|
|
432
|
+
anchorBlockHeader: BlockHeader,
|
|
433
|
+
): Promise<string> {
|
|
434
|
+
try {
|
|
435
|
+
const classId = await this.contractClassService.getCurrentClassId(address, anchorBlockHeader);
|
|
436
|
+
return classId ? await this.contractStore.getDebugFunctionName(classId, selector) : `${address}:${selector}`;
|
|
437
|
+
} catch {
|
|
438
|
+
return `${address}:${selector}`;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/** Best-effort debug contract name for the class `address` runs at `anchorBlockHeader`. Used for log display only. */
|
|
443
|
+
async #getDebugContractName(address: AztecAddress, anchorBlockHeader: BlockHeader): Promise<string | undefined> {
|
|
444
|
+
try {
|
|
445
|
+
const classId = await this.contractClassService.getCurrentClassId(address, anchorBlockHeader);
|
|
446
|
+
return classId ? await this.contractStore.getDebugContractName(classId) : undefined;
|
|
447
|
+
} catch {
|
|
448
|
+
return undefined;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
401
452
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
402
453
|
let contextStr = '';
|
|
403
454
|
if (context.length > 0) {
|
|
@@ -461,7 +512,14 @@ export class PXE {
|
|
|
461
512
|
|
|
462
513
|
async #registerPreloadedContracts() {
|
|
463
514
|
const contracts = await this.preloadedContractsProvider.getPreloadedContracts();
|
|
464
|
-
await Promise.all(
|
|
515
|
+
await Promise.all(
|
|
516
|
+
contracts.map(async ({ instance, artifact }) => {
|
|
517
|
+
if (artifact) {
|
|
518
|
+
await this.registerContractClass(artifact);
|
|
519
|
+
}
|
|
520
|
+
await this.registerContract(instance);
|
|
521
|
+
}),
|
|
522
|
+
);
|
|
465
523
|
this.log.verbose(`Registered preloaded contracts in pxe`, {
|
|
466
524
|
contracts: contracts.map(({ instance }) => instance.address.toString()),
|
|
467
525
|
});
|
|
@@ -507,7 +565,7 @@ export class PXE {
|
|
|
507
565
|
return result;
|
|
508
566
|
} catch (err) {
|
|
509
567
|
if (err instanceof SimulationError) {
|
|
510
|
-
await enrichSimulationError(err, this.contractStore, this.log);
|
|
568
|
+
await enrichSimulationError(err, this.contractStore, this.contractClassService, anchorBlockHeader, this.log);
|
|
511
569
|
}
|
|
512
570
|
throw err;
|
|
513
571
|
}
|
|
@@ -542,7 +600,8 @@ export class PXE {
|
|
|
542
600
|
return { result, offchainEffects };
|
|
543
601
|
} catch (err) {
|
|
544
602
|
if (err instanceof SimulationError) {
|
|
545
|
-
|
|
603
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
604
|
+
await enrichSimulationError(err, this.contractStore, this.contractClassService, anchorBlockHeader, this.log);
|
|
546
605
|
}
|
|
547
606
|
throw err;
|
|
548
607
|
}
|
|
@@ -566,7 +625,14 @@ export class PXE {
|
|
|
566
625
|
} catch (err) {
|
|
567
626
|
if (err instanceof SimulationError) {
|
|
568
627
|
try {
|
|
569
|
-
|
|
628
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
629
|
+
await enrichPublicSimulationError(
|
|
630
|
+
err,
|
|
631
|
+
this.contractStore,
|
|
632
|
+
this.contractClassService,
|
|
633
|
+
anchorBlockHeader,
|
|
634
|
+
this.log,
|
|
635
|
+
);
|
|
570
636
|
} catch (enrichErr) {
|
|
571
637
|
this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
|
|
572
638
|
}
|
|
@@ -593,7 +659,13 @@ export class PXE {
|
|
|
593
659
|
anchorBlockHeader: BlockHeader,
|
|
594
660
|
config: PrivateKernelExecutionProverConfig,
|
|
595
661
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
596
|
-
const kernelOracle = new PrivateKernelOracle(
|
|
662
|
+
const kernelOracle = new PrivateKernelOracle(
|
|
663
|
+
this.contractStore,
|
|
664
|
+
this.contractClassService,
|
|
665
|
+
this.keyStore,
|
|
666
|
+
this.node,
|
|
667
|
+
anchorBlockHeader,
|
|
668
|
+
);
|
|
597
669
|
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
598
670
|
kernelOracle,
|
|
599
671
|
proofCreator,
|
|
@@ -637,11 +709,11 @@ export class PXE {
|
|
|
637
709
|
}
|
|
638
710
|
|
|
639
711
|
/**
|
|
640
|
-
* Returns the contract instance
|
|
712
|
+
* Returns the address preimage of the contract instance at a given address, if it's registered in the PXE.
|
|
641
713
|
* @param address - The contract address.
|
|
642
|
-
* @returns The contract instance if found, undefined otherwise.
|
|
714
|
+
* @returns The contract instance address preimage if found, undefined otherwise.
|
|
643
715
|
*/
|
|
644
|
-
public getContractInstance(address: AztecAddress): Promise<
|
|
716
|
+
public getContractInstance(address: AztecAddress): Promise<ContractInstancePreimageWithAddress | undefined> {
|
|
645
717
|
return this.contractStore.getContractInstance(address);
|
|
646
718
|
}
|
|
647
719
|
|
|
@@ -655,18 +727,22 @@ export class PXE {
|
|
|
655
727
|
}
|
|
656
728
|
|
|
657
729
|
/**
|
|
658
|
-
* Registers a user account in PXE
|
|
659
|
-
*
|
|
660
|
-
* the
|
|
661
|
-
*
|
|
730
|
+
* Registers a user account in PXE.
|
|
731
|
+
*
|
|
732
|
+
* PXE holds the account's four privacy secret keys but only the *public* message-signing and fallback keys: their
|
|
733
|
+
* secret keys are withheld, since PXE is not trusted to hold them.
|
|
662
734
|
*
|
|
663
|
-
*
|
|
735
|
+
* Does nothing if the account is already registered.
|
|
736
|
+
*
|
|
737
|
+
* The four privacy secret keys can be retrieved later with {@link getAccountSecretKeys}.
|
|
738
|
+
*
|
|
739
|
+
* @param keys - The account's privacy keys: four secret keys plus the message-signing and fallback public keys.
|
|
664
740
|
* @param partialAddress - The partial address of the account contract corresponding to the account being registered.
|
|
665
741
|
* @returns The complete address of the account.
|
|
666
742
|
*/
|
|
667
|
-
public async registerAccount(
|
|
743
|
+
public async registerAccount(keys: AccountPrivacyKeys, partialAddress: PartialAddress): Promise<CompleteAddress> {
|
|
668
744
|
const accounts = await this.keyStore.getAccounts();
|
|
669
|
-
const accountCompleteAddress = await this.keyStore.addAccount(
|
|
745
|
+
const accountCompleteAddress = await this.keyStore.addAccount(keys, partialAddress);
|
|
670
746
|
if (accounts.some(a => a.equals(accountCompleteAddress.address))) {
|
|
671
747
|
this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
|
|
672
748
|
return accountCompleteAddress;
|
|
@@ -679,6 +755,24 @@ export class PXE {
|
|
|
679
755
|
return accountCompleteAddress;
|
|
680
756
|
}
|
|
681
757
|
|
|
758
|
+
/**
|
|
759
|
+
* Retrieves the four privacy secret keys PXE holds for a registered account (nullifier-hiding, incoming-viewing,
|
|
760
|
+
* outgoing-viewing, tagging).
|
|
761
|
+
*
|
|
762
|
+
* These do NOT grant control over an account's assets, e.g. they are insufficient to impersonate the account or to
|
|
763
|
+
* spend notes, but they _do_ guard the account's privacy. Parties that have knowledge of these keys can decrypt all
|
|
764
|
+
* messages sent to the account, discover all of their on-chain activity, including notes, events, etc.
|
|
765
|
+
*
|
|
766
|
+
* Security is paramount when handling these keys, which should itself be a very rare occurrence. Other than exporting
|
|
767
|
+
* and then importing an account into a separate PXE/wallet, there is typically no need for a wallet to ever access
|
|
768
|
+
* these keys. Applications should NEVER be given access to them.
|
|
769
|
+
*
|
|
770
|
+
* @throws If the account is not registered.
|
|
771
|
+
*/
|
|
772
|
+
public getAccountSecretKeys(account: AztecAddress): Promise<AccountPrivacySecretKeys> {
|
|
773
|
+
return this.keyStore.getAccountSecretKeys(account);
|
|
774
|
+
}
|
|
775
|
+
|
|
682
776
|
/**
|
|
683
777
|
* Registers a source from which this PXE derives the tagging secrets it scans for to discover incoming private logs.
|
|
684
778
|
* See {@link TaggingSecretSource} for the meaning of each variant. Does nothing if the source is already registered.
|
|
@@ -695,7 +789,14 @@ export class PXE {
|
|
|
695
789
|
wasAdded = await this.#registerSender(source.sender);
|
|
696
790
|
break;
|
|
697
791
|
case 'arbitrary-secret':
|
|
698
|
-
wasAdded = await this.#
|
|
792
|
+
wasAdded = await this.#registerSharedSecret(source.recipient, 'arbitrary-secret', source.secret);
|
|
793
|
+
break;
|
|
794
|
+
case 'handshake':
|
|
795
|
+
wasAdded = await this.#registerSharedSecret(
|
|
796
|
+
source.recipient,
|
|
797
|
+
'handshake',
|
|
798
|
+
await this.#deriveHandshakeSecret(source.recipient, source.ephPk),
|
|
799
|
+
);
|
|
699
800
|
break;
|
|
700
801
|
default: {
|
|
701
802
|
const _: never = source;
|
|
@@ -710,9 +811,10 @@ export class PXE {
|
|
|
710
811
|
}
|
|
711
812
|
|
|
712
813
|
/**
|
|
713
|
-
* Removes a previously registered tagging secret source
|
|
814
|
+
* Removes a previously registered tagging secret source, identified by its registered form (see
|
|
815
|
+
* {@link getTaggingSecretSources}). Does nothing if it was not registered.
|
|
714
816
|
*/
|
|
715
|
-
public async removeTaggingSecretSource(source:
|
|
817
|
+
public async removeTaggingSecretSource(source: RegisteredTaggingSecretSource): Promise<void> {
|
|
716
818
|
switch (source.kind) {
|
|
717
819
|
case 'address-derived': {
|
|
718
820
|
const { sender } = source;
|
|
@@ -724,13 +826,14 @@ export class PXE {
|
|
|
724
826
|
);
|
|
725
827
|
break;
|
|
726
828
|
}
|
|
727
|
-
case 'arbitrary-secret':
|
|
728
|
-
|
|
729
|
-
const
|
|
829
|
+
case 'arbitrary-secret':
|
|
830
|
+
case 'handshake': {
|
|
831
|
+
const { kind, recipient, secret } = source;
|
|
832
|
+
const wasRemoved = await this.taggingSecretSourcesStore.removeSharedSecret(recipient, kind, secret);
|
|
730
833
|
this.log.info(
|
|
731
834
|
wasRemoved
|
|
732
|
-
? `Removed shared secret for recipient:\n ${recipient.toString()}`
|
|
733
|
-
: `
|
|
835
|
+
? `Removed ${kind} shared secret for recipient:\n ${recipient.toString()}`
|
|
836
|
+
: `No ${kind} shared secret registered for recipient:\n ${recipient.toString()}`,
|
|
734
837
|
);
|
|
735
838
|
break;
|
|
736
839
|
}
|
|
@@ -742,24 +845,24 @@ export class PXE {
|
|
|
742
845
|
}
|
|
743
846
|
|
|
744
847
|
/**
|
|
745
|
-
* Retrieves the tagging secret sources registered in this PXE. Without a filter it
|
|
746
|
-
* `{ kind }` to narrow to a single variant. See {@link
|
|
848
|
+
* Retrieves the tagging secret sources registered in this PXE, in their registered form. Without a filter it
|
|
849
|
+
* returns every source; pass `{ kind }` to narrow to a single variant. See {@link RegisteredTaggingSecretSource}.
|
|
747
850
|
*/
|
|
748
|
-
public getTaggingSecretSources<K extends
|
|
851
|
+
public getTaggingSecretSources<K extends RegisteredTaggingSecretSource['kind']>(filter: {
|
|
749
852
|
kind: K;
|
|
750
|
-
}): Promise<Extract<
|
|
751
|
-
public getTaggingSecretSources(): Promise<
|
|
853
|
+
}): Promise<Extract<RegisteredTaggingSecretSource, { kind: K }>[]>;
|
|
854
|
+
public getTaggingSecretSources(): Promise<RegisteredTaggingSecretSource[]>;
|
|
752
855
|
public async getTaggingSecretSources(filter?: {
|
|
753
|
-
kind?:
|
|
754
|
-
}): Promise<
|
|
856
|
+
kind?: RegisteredTaggingSecretSource['kind'];
|
|
857
|
+
}): Promise<RegisteredTaggingSecretSource[]> {
|
|
755
858
|
const [senders, secrets] = await Promise.all([
|
|
756
859
|
this.taggingSecretSourcesStore.getSenders(),
|
|
757
860
|
this.taggingSecretSourcesStore.getAllSharedSecrets(),
|
|
758
861
|
]);
|
|
759
862
|
|
|
760
|
-
const sources:
|
|
761
|
-
...senders.map((sender):
|
|
762
|
-
...secrets.map(({ recipient, secret }):
|
|
863
|
+
const sources: RegisteredTaggingSecretSource[] = [
|
|
864
|
+
...senders.map((sender): RegisteredTaggingSecretSource => ({ kind: 'address-derived', sender })),
|
|
865
|
+
...secrets.map(({ recipient, kind, secret }): RegisteredTaggingSecretSource => ({ kind, recipient, secret })),
|
|
763
866
|
];
|
|
764
867
|
|
|
765
868
|
return filter?.kind ? sources.filter(source => source.kind === filter.kind) : sources;
|
|
@@ -786,8 +889,39 @@ export class PXE {
|
|
|
786
889
|
return wasAdded;
|
|
787
890
|
}
|
|
788
891
|
|
|
789
|
-
/**
|
|
790
|
-
|
|
892
|
+
/**
|
|
893
|
+
* Derives the shared secret of a handshake from its ephemeral public key: the raw ECDH secret
|
|
894
|
+
* `S = addressSecret(recipient) * ephPk` with the forgery protection applied,
|
|
895
|
+
* matching the protected secret the registry stores and the derivation the recipient-side scan uses for
|
|
896
|
+
* handshakes discovered onchain. The ephemeral key is reconstructed from its x-coordinate with a positive y,
|
|
897
|
+
* matching how the protocol generates it.
|
|
898
|
+
*
|
|
899
|
+
* @throws If `ephPk` is not the x-coordinate of a Grumpkin curve point, or if `recipient` is not an account of
|
|
900
|
+
* this PXE, since the derivation needs its keys.
|
|
901
|
+
*/
|
|
902
|
+
async #deriveHandshakeSecret(recipient: AztecAddress, ephPk: Fr): Promise<Point> {
|
|
903
|
+
let ephPkPoint: Point;
|
|
904
|
+
try {
|
|
905
|
+
ephPkPoint = await Point.fromXAndSign(ephPk, true);
|
|
906
|
+
} catch {
|
|
907
|
+
throw new Error(`Ephemeral public key x-coordinate ${ephPk} does not correspond to a Grumpkin curve point.`);
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
const completeAddress = await this.addressStore.getCompleteAddress(recipient);
|
|
911
|
+
if (!completeAddress || !(await this.keyStore.hasAccount(recipient))) {
|
|
912
|
+
throw new Error(
|
|
913
|
+
`Recipient ${recipient} is not an account of this PXE. A handshake's shared secret can only be derived for an account whose keys are held.`,
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
const ivskM = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
|
|
918
|
+
const addressSecret = await computeAddressSecret(await completeAddress.getPreaddress(), ivskM);
|
|
919
|
+
const rawSecret = await deriveEcdhSharedSecretPoint(addressSecret, ephPkPoint);
|
|
920
|
+
return protectFromForgery(rawSecret, ephPkPoint, await recipient.toAddressPoint());
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/** Registers a resolved shared secret scoped to a recipient. Returns whether it was newly added. */
|
|
924
|
+
async #registerSharedSecret(recipient: AztecAddress, kind: SharedSecretKind, secret: Point): Promise<boolean> {
|
|
791
925
|
if (!(await recipient.isValid())) {
|
|
792
926
|
throw new Error(
|
|
793
927
|
`Recipient ${recipient} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register a shared secret for it.`,
|
|
@@ -798,11 +932,11 @@ export class PXE {
|
|
|
798
932
|
throw new Error(`Shared secret ${secret} is not a valid non-zero point on the Grumpkin curve.`);
|
|
799
933
|
}
|
|
800
934
|
|
|
801
|
-
const wasAdded = await this.taggingSecretSourcesStore.addSharedSecret(recipient, secret);
|
|
935
|
+
const wasAdded = await this.taggingSecretSourcesStore.addSharedSecret(recipient, kind, secret);
|
|
802
936
|
this.log.info(
|
|
803
937
|
wasAdded
|
|
804
|
-
? `Added shared secret for recipient:\n ${recipient.toString()}`
|
|
805
|
-
:
|
|
938
|
+
? `Added ${kind} shared secret for recipient:\n ${recipient.toString()}`
|
|
939
|
+
: `${kind} shared secret already registered for recipient:\n ${recipient.toString()}`,
|
|
806
940
|
);
|
|
807
941
|
return wasAdded;
|
|
808
942
|
}
|
|
@@ -828,98 +962,33 @@ export class PXE {
|
|
|
828
962
|
*/
|
|
829
963
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
830
964
|
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
965
|
+
// Publishing the artifact's public function signatures to the node is part of "registering a class", so that
|
|
966
|
+
// node-side debugging works regardless of which entrypoint (registerContractClass or registerContract) was used.
|
|
967
|
+
const publicFunctionSignatures = artifact.functions
|
|
968
|
+
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
969
|
+
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
970
|
+
if (publicFunctionSignatures.length > 0) {
|
|
971
|
+
await this.nodeDebug?.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
972
|
+
}
|
|
831
973
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
832
974
|
}
|
|
833
975
|
|
|
834
976
|
/**
|
|
835
|
-
*
|
|
836
|
-
*
|
|
837
|
-
*
|
|
838
|
-
*
|
|
977
|
+
* Registers a deployed contract instance so its private state can be synced and its functions simulated. The
|
|
978
|
+
* artifact for the class the instance runs must be registered separately via {@link registerContractClass}, before
|
|
979
|
+
* or after this call; registration performs no validation, so a missing or mismatched artifact only surfaces when
|
|
980
|
+
* the contract is later simulated. This is automatically called by aztec.js when deploying a contract.
|
|
839
981
|
*
|
|
840
|
-
* @param
|
|
841
|
-
|
|
842
|
-
public async registerContract(contract: { instance: ContractInstanceWithAddress; artifact?: ContractArtifact }) {
|
|
843
|
-
const { instance } = contract;
|
|
844
|
-
let { artifact } = contract;
|
|
845
|
-
|
|
846
|
-
if (artifact) {
|
|
847
|
-
// If the user provides an artifact, validate it against the expected class id and register it
|
|
848
|
-
const contractClass = await getContractClassFromArtifact(artifact);
|
|
849
|
-
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
850
|
-
throw new Error(
|
|
851
|
-
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
852
|
-
);
|
|
853
|
-
}
|
|
854
|
-
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
855
|
-
if (!computedAddress.equals(instance.address)) {
|
|
856
|
-
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
860
|
-
|
|
861
|
-
const publicFunctionSignatures = artifact.functions
|
|
862
|
-
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
863
|
-
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
864
|
-
if (publicFunctionSignatures.length > 0) {
|
|
865
|
-
await this.nodeDebug?.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
866
|
-
}
|
|
867
|
-
} else {
|
|
868
|
-
// Otherwise, make sure there is an artifact already registered for that class id
|
|
869
|
-
artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
|
|
870
|
-
if (!artifact) {
|
|
871
|
-
throw new Error(
|
|
872
|
-
`Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`,
|
|
873
|
-
);
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
await this.contractStore.addContractInstance(instance);
|
|
878
|
-
this.log.info(
|
|
879
|
-
`Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`,
|
|
880
|
-
);
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
/**
|
|
884
|
-
* Updates a deployed contract in the PXE. This is used to update the contract artifact when
|
|
885
|
-
* an update has happened, so the new code can be used in the simulation of local transactions.
|
|
886
|
-
* This is called by aztec.js when instantiating a contract in a given address with a mismatching artifact.
|
|
887
|
-
* @param contractAddress - The address of the contract to update.
|
|
888
|
-
* @param artifact - The updated artifact for the contract.
|
|
889
|
-
* @throws If the artifact's contract class is not found in the PXE or if the contract class is different from
|
|
890
|
-
* the current one (current one from the point of view of the node to which the PXE is connected).
|
|
982
|
+
* @param instance - The address preimage of the contract instance to register. The address is derived from it.
|
|
983
|
+
* @returns The address of the registered instance.
|
|
891
984
|
*/
|
|
892
|
-
public
|
|
893
|
-
//
|
|
894
|
-
// class while we're simulating it.
|
|
985
|
+
public registerContract(instance: ContractInstancePreimage): Promise<AztecAddress> {
|
|
986
|
+
// Run inside the job queue so we can't race a concurrent simulation while writing the instance to the store.
|
|
895
987
|
return this.#putInJobQueue(async () => {
|
|
896
|
-
const
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
const contractClass = await getContractClassFromArtifact(artifact);
|
|
901
|
-
await this.#maybeSync();
|
|
902
|
-
|
|
903
|
-
const header = await this.anchorBlockStore.getBlockHeader();
|
|
904
|
-
|
|
905
|
-
const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
|
|
906
|
-
if (!contractClass.id.equals(currentClassId)) {
|
|
907
|
-
throw new Error('Could not update contract to a class different from the current one.');
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
const publicFunctionSignatures = artifact.functions
|
|
911
|
-
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
912
|
-
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
913
|
-
if (publicFunctionSignatures.length > 0) {
|
|
914
|
-
await this.nodeDebug?.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
currentInstance.currentContractClassId = contractClass.id;
|
|
918
|
-
await Promise.all([
|
|
919
|
-
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
920
|
-
this.contractStore.addContractInstance(currentInstance),
|
|
921
|
-
]);
|
|
922
|
-
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
988
|
+
const address = await computeContractAddressFromInstance(instance);
|
|
989
|
+
await this.contractStore.addContractInstance({ ...instance, address });
|
|
990
|
+
this.log.info(`Added contract at ${address}`, { address });
|
|
991
|
+
return address;
|
|
923
992
|
});
|
|
924
993
|
}
|
|
925
994
|
|
|
@@ -1181,7 +1250,7 @@ export class PXE {
|
|
|
1181
1250
|
if (skipKernels) {
|
|
1182
1251
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
1183
1252
|
privateExecutionResult,
|
|
1184
|
-
(addr, sel) => this
|
|
1253
|
+
(addr, sel) => this.#getDebugFunctionName(addr, sel, anchorBlockHeader),
|
|
1185
1254
|
this.node,
|
|
1186
1255
|
));
|
|
1187
1256
|
} else {
|
|
@@ -1208,7 +1277,7 @@ export class PXE {
|
|
|
1208
1277
|
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement, overrides);
|
|
1209
1278
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
1210
1279
|
if (publicOutput?.debugLogs?.length) {
|
|
1211
|
-
await displayDebugLogs(publicOutput.debugLogs, addr => this
|
|
1280
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.#getDebugContractName(addr, anchorBlockHeader));
|
|
1212
1281
|
}
|
|
1213
1282
|
}
|
|
1214
1283
|
|