@aztec/txe 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
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/AuthRegistry-QVGDDH5X.js +3 -0
- package/dest/AuthRegistry-QVGDDH5X.js.map +7 -0
- package/dest/ContractClassRegistry-VWR3F42P.js +3 -0
- package/dest/ContractClassRegistry-VWR3F42P.js.map +7 -0
- package/dest/ContractInstanceRegistry-FHIWE33X.js +3 -0
- package/dest/ContractInstanceRegistry-FHIWE33X.js.map +7 -0
- package/dest/FeeJuice-SAOWVGG7.js +3 -0
- package/dest/FeeJuice-SAOWVGG7.js.map +7 -0
- package/dest/HandshakeRegistry-GY5CPEPS.js +3 -0
- package/dest/HandshakeRegistry-GY5CPEPS.js.map +7 -0
- package/dest/MultiCallEntrypoint-QG5H33ZZ.js +3 -0
- package/dest/MultiCallEntrypoint-QG5H33ZZ.js.map +7 -0
- package/dest/SchnorrAccount-NME3E45O.js +3 -0
- package/dest/SchnorrAccount-NME3E45O.js.map +7 -0
- package/dest/SchnorrInitializerlessAccount-WTGXU6SW.js +3 -0
- package/dest/SchnorrInitializerlessAccount-WTGXU6SW.js.map +7 -0
- package/dest/bin/check_txe_oracle_version.d.ts +2 -0
- package/dest/bin/check_txe_oracle_version.d.ts.map +1 -0
- package/dest/bin/check_txe_oracle_version.js +53 -0
- package/dest/bin/index.js +3 -30
- package/dest/bin/index.js.map +7 -0
- package/dest/bin/oracle_test_server.d.ts +3 -0
- package/dest/bin/oracle_test_server.d.ts.map +1 -0
- package/dest/bin/oracle_test_server.js +41 -0
- package/dest/chunk-32UHX7YY.js +3 -0
- package/dest/chunk-32UHX7YY.js.map +7 -0
- package/dest/chunk-GSUKUCKV.js +260 -0
- package/dest/chunk-GSUKUCKV.js.map +7 -0
- package/dest/chunk-UP4KKUVA.js +304 -0
- package/dest/chunk-UP4KKUVA.js.map +7 -0
- package/dest/constants.d.ts +7 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +10 -0
- package/dest/dispatcher_pool.d.ts +67 -0
- package/dest/dispatcher_pool.d.ts.map +1 -0
- package/dest/dispatcher_pool.js +286 -0
- package/dest/index.d.ts +51 -7
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +75 -158
- package/dest/metafile.json +38759 -0
- package/dest/msgpackr_fr_extension.d.ts +2 -0
- package/dest/msgpackr_fr_extension.d.ts.map +1 -0
- package/dest/msgpackr_fr_extension.js +21 -0
- package/dest/oracle/interfaces.d.ts +71 -30
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/tagging_secret_strategy.d.ts +12 -0
- package/dest/oracle/tagging_secret_strategy.d.ts.map +1 -0
- package/dest/oracle/tagging_secret_strategy.js +12 -0
- package/dest/oracle/test-resolver/default_fixtures.d.ts +16 -0
- package/dest/oracle/test-resolver/default_fixtures.d.ts.map +1 -0
- package/dest/oracle/test-resolver/default_fixtures.js +200 -0
- package/dest/oracle/test-resolver/index.d.ts +9 -0
- package/dest/oracle/test-resolver/index.d.ts.map +1 -0
- package/dest/oracle/test-resolver/index.js +32 -0
- package/dest/oracle/test-resolver/resolver.d.ts +48 -0
- package/dest/oracle/test-resolver/resolver.d.ts.map +1 -0
- package/dest/oracle/test-resolver/resolver.js +181 -0
- package/dest/oracle/txe_oracle_public_context.d.ts +40 -16
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +69 -23
- package/dest/oracle/txe_oracle_registry.d.ts +172 -0
- package/dest/oracle/txe_oracle_registry.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_registry.js +767 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts +79 -30
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +653 -285
- package/dest/oracle/txe_oracle_version.d.ts +17 -0
- package/dest/oracle/txe_oracle_version.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_version.js +14 -0
- package/dest/oracle/txe_private_execution_oracle.d.ts +17 -0
- package/dest/oracle/txe_private_execution_oracle.d.ts.map +1 -0
- package/dest/oracle/txe_private_execution_oracle.js +15 -0
- package/dest/rpc_server.d.ts +14 -0
- package/dest/rpc_server.d.ts.map +1 -0
- package/dest/rpc_server.js +78 -0
- package/dest/rpc_translator.d.ts +115 -216
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +901 -560
- package/dest/server.bundle.js +3 -0
- package/dest/server.bundle.js.map +7 -0
- package/dest/state_machine/archiver.d.ts +23 -58
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +76 -112
- package/dest/state_machine/dummy_p2p_client.d.ts +31 -17
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +63 -25
- package/dest/state_machine/global_variable_builder.d.ts +10 -5
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +20 -5
- package/dest/state_machine/index.d.ts +14 -8
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +84 -27
- package/dest/state_machine/mock_epoch_cache.d.ts +24 -8
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +43 -9
- package/dest/state_machine/synchronizer.d.ts +14 -6
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +23 -10
- package/dest/txe_session.d.ts +102 -20
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +442 -75
- package/dest/utils/block_creation.d.ts +20 -6
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +40 -6
- package/dest/utils/encoding.d.ts +192 -0
- package/dest/utils/encoding.d.ts.map +1 -0
- package/dest/{util → utils}/encoding.js +8 -3
- package/dest/{util → utils}/expected_failure_error.d.ts +1 -1
- package/dest/utils/expected_failure_error.d.ts.map +1 -0
- package/dest/utils/tx_effect_creation.d.ts +2 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +3 -7
- package/dest/utils/txe_account_store.d.ts +10 -0
- package/dest/utils/txe_account_store.d.ts.map +1 -0
- package/dest/{util/txe_account_data_provider.js → utils/txe_account_store.js} +1 -1
- package/dest/utils/txe_artifact_resolver.d.ts +37 -0
- package/dest/utils/txe_artifact_resolver.d.ts.map +1 -0
- package/dest/utils/txe_artifact_resolver.js +161 -0
- package/dest/utils/txe_public_contract_data_source.d.ts +20 -0
- package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -0
- package/dest/utils/txe_public_contract_data_source.js +51 -0
- package/dest/worker.bundle.js +3 -0
- package/dest/worker.bundle.js.map +7 -0
- package/dest/worker.d.ts +2 -0
- package/dest/worker.d.ts.map +1 -0
- package/dest/worker.js +92 -0
- package/package.json +39 -22
- package/src/bin/check_txe_oracle_version.ts +67 -0
- package/src/bin/index.ts +11 -2
- package/src/bin/oracle_test_server.ts +51 -0
- package/src/constants.ts +13 -0
- package/src/dispatcher_pool.ts +317 -0
- package/src/index.ts +113 -201
- package/src/msgpackr_fr_extension.ts +23 -0
- package/src/oracle/interfaces.ts +77 -35
- package/src/oracle/tagging_secret_strategy.ts +25 -0
- package/src/oracle/test-resolver/default_fixtures.ts +271 -0
- package/src/oracle/test-resolver/index.ts +44 -0
- package/src/oracle/test-resolver/resolver.ts +245 -0
- package/src/oracle/txe_oracle_public_context.ts +82 -27
- package/src/oracle/txe_oracle_registry.ts +556 -0
- package/src/oracle/txe_oracle_top_level_context.ts +555 -189
- package/src/oracle/txe_oracle_version.ts +17 -0
- package/src/oracle/txe_private_execution_oracle.ts +30 -0
- package/src/rpc_server.ts +87 -0
- package/src/rpc_translator.ts +1115 -923
- package/src/state_machine/archiver.ts +81 -132
- package/src/state_machine/dummy_p2p_client.ts +96 -38
- package/src/state_machine/global_variable_builder.ts +28 -10
- package/src/state_machine/index.ts +118 -44
- package/src/state_machine/mock_epoch_cache.ts +53 -14
- package/src/state_machine/synchronizer.ts +32 -12
- package/src/txe_session.ts +727 -123
- package/src/utils/block_creation.ts +50 -16
- package/src/{util → utils}/encoding.ts +9 -3
- package/src/utils/tx_effect_creation.ts +3 -13
- package/src/{util/txe_account_data_provider.ts → utils/txe_account_store.ts} +1 -1
- package/src/utils/txe_artifact_resolver.ts +217 -0
- package/src/utils/txe_public_contract_data_source.ts +60 -0
- package/src/worker.ts +98 -0
- package/dest/util/encoding.d.ts +0 -121
- package/dest/util/encoding.d.ts.map +0 -1
- package/dest/util/expected_failure_error.d.ts.map +0 -1
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.js +0 -22
- package/dest/util/txe_public_contract_data_source.d.ts +0 -21
- package/dest/util/txe_public_contract_data_source.d.ts.map +0 -1
- package/dest/util/txe_public_contract_data_source.js +0 -67
- package/src/util/txe_contract_data_provider.ts +0 -36
- package/src/util/txe_public_contract_data_source.ts +0 -86
- /package/dest/{util → utils}/expected_failure_error.js +0 -0
- /package/src/{util → utils}/expected_failure_error.ts +0 -0
|
@@ -1,157 +1,351 @@
|
|
|
1
|
-
|
|
1
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() {
|
|
16
|
+
try {
|
|
17
|
+
inner.call(this);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return Promise.reject(e);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
env.stack.push({
|
|
23
|
+
value: value,
|
|
24
|
+
dispose: dispose,
|
|
25
|
+
async: async
|
|
26
|
+
});
|
|
27
|
+
} else if (async) {
|
|
28
|
+
env.stack.push({
|
|
29
|
+
async: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
function _ts_dispose_resources(env) {
|
|
35
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
36
|
+
var e = new Error(message);
|
|
37
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
38
|
+
};
|
|
39
|
+
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
|
|
40
|
+
function fail(e) {
|
|
41
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
42
|
+
env.hasError = true;
|
|
43
|
+
}
|
|
44
|
+
var r, s = 0;
|
|
45
|
+
function next() {
|
|
46
|
+
while(r = env.stack.pop()){
|
|
47
|
+
try {
|
|
48
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
49
|
+
if (r.dispose) {
|
|
50
|
+
var result = r.dispose.call(r.value);
|
|
51
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
52
|
+
fail(e);
|
|
53
|
+
return next();
|
|
54
|
+
});
|
|
55
|
+
} else s |= 1;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
fail(e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
61
|
+
if (env.hasError) throw env.error;
|
|
62
|
+
}
|
|
63
|
+
return next();
|
|
64
|
+
})(env);
|
|
65
|
+
}
|
|
66
|
+
import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, MAX_PRIVATE_LOGS_PER_TX, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
67
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { Schnorr } from '@aztec/foundation/crypto';
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
68
|
+
import { Schnorr } from '@aztec/foundation/crypto/schnorr';
|
|
69
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
70
|
import { LogLevels, applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
6
71
|
import { TestDateProvider } from '@aztec/foundation/timer';
|
|
7
|
-
import {
|
|
8
|
-
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache,
|
|
72
|
+
import { AnchoredContractData, CapsuleService, FactService, ORACLE_VERSION_MAJOR, composeHooks, enrichPublicSimulationError } from '@aztec/pxe/server';
|
|
73
|
+
import { CONTRACT_INSTANCE, ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, PrivateExecutionOracle, TransientArrayService, UtilityExecutionOracle, buildACIRCallback, executePrivateFunction, generateSimulatedProvingResult } from '@aztec/pxe/simulator';
|
|
9
74
|
import { ExecutionError, WASMSimulator, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness, witnessMapToFields } from '@aztec/simulator/client';
|
|
10
|
-
import {
|
|
11
|
-
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
75
|
+
import { GuardedMerkleTreeOperations, PublicContractsDB, PublicProcessor, PublicTxSimulator } from '@aztec/simulator/server';
|
|
76
|
+
import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
12
77
|
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
13
78
|
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
14
79
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
-
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
16
80
|
import { computePartialAddress } from '@aztec/stdlib/contract';
|
|
17
|
-
import { Gas, GasFees
|
|
81
|
+
import { Gas, GasFees } from '@aztec/stdlib/gas';
|
|
18
82
|
import { computeCalldataHash, computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
|
|
19
83
|
import { PartialPrivateTailPublicInputsForPublic, PrivateKernelTailCircuitPublicInputs, PrivateToPublicAccumulatedData, PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
84
|
+
import { deriveKeys, hashPublicKey } from '@aztec/stdlib/keys';
|
|
85
|
+
import { AppTaggingSecretKind } from '@aztec/stdlib/logs';
|
|
86
|
+
import { L1Actor, L1ToL2Message, L2Actor } from '@aztec/stdlib/messaging';
|
|
20
87
|
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
21
|
-
import {
|
|
88
|
+
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
22
89
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
23
90
|
import { CallContext, HashedValues, PrivateExecutionResult, Tx, TxConstantData, TxContext, TxEffect, TxHash, collectNested } from '@aztec/stdlib/tx';
|
|
24
|
-
import { ForkCheckpoint } from '@aztec/world-state';
|
|
25
|
-
import {
|
|
26
|
-
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees,
|
|
91
|
+
import { ForkCheckpoint } from '@aztec/world-state/native';
|
|
92
|
+
import { DEFAULT_ADDRESS, MAX_PRIVATE_EVENTS_PER_TXE_QUERY, MAX_PRIVATE_EVENT_LEN } from '../constants.js';
|
|
93
|
+
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
|
|
94
|
+
import { TXEPublicContractDataSource } from '../utils/txe_public_contract_data_source.js';
|
|
95
|
+
import { makeResolveTaggingSecretStrategyHook } from './tagging_secret_strategy.js';
|
|
27
96
|
export class TXEOracleTopLevelContext {
|
|
28
97
|
stateMachine;
|
|
29
|
-
|
|
98
|
+
contractStore;
|
|
99
|
+
noteStore;
|
|
30
100
|
keyStore;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
101
|
+
addressStore;
|
|
102
|
+
accountStore;
|
|
103
|
+
senderTaggingStore;
|
|
104
|
+
recipientTaggingStore;
|
|
105
|
+
taggingSecretSourcesStore;
|
|
106
|
+
capsuleStore;
|
|
107
|
+
factStore;
|
|
108
|
+
privateEventStore;
|
|
34
109
|
nextBlockTimestamp;
|
|
35
110
|
version;
|
|
36
111
|
chainId;
|
|
37
112
|
authwits;
|
|
113
|
+
taggingSecretStrategies;
|
|
114
|
+
authorizeAllUtilityCallTargets;
|
|
115
|
+
artifactResolver;
|
|
116
|
+
rootPath;
|
|
117
|
+
packageName;
|
|
38
118
|
isMisc;
|
|
39
119
|
isTxe;
|
|
40
120
|
logger;
|
|
41
|
-
constructor(stateMachine,
|
|
121
|
+
constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, taggingSecretSourcesStore, capsuleStore, factStore, privateEventStore, nextBlockTimestamp, version, chainId, authwits, taggingSecretStrategies, authorizeAllUtilityCallTargets, artifactResolver, rootPath, packageName){
|
|
42
122
|
this.stateMachine = stateMachine;
|
|
43
|
-
this.
|
|
123
|
+
this.contractStore = contractStore;
|
|
124
|
+
this.noteStore = noteStore;
|
|
44
125
|
this.keyStore = keyStore;
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
126
|
+
this.addressStore = addressStore;
|
|
127
|
+
this.accountStore = accountStore;
|
|
128
|
+
this.senderTaggingStore = senderTaggingStore;
|
|
129
|
+
this.recipientTaggingStore = recipientTaggingStore;
|
|
130
|
+
this.taggingSecretSourcesStore = taggingSecretSourcesStore;
|
|
131
|
+
this.capsuleStore = capsuleStore;
|
|
132
|
+
this.factStore = factStore;
|
|
133
|
+
this.privateEventStore = privateEventStore;
|
|
48
134
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
49
135
|
this.version = version;
|
|
50
136
|
this.chainId = chainId;
|
|
51
137
|
this.authwits = authwits;
|
|
138
|
+
this.taggingSecretStrategies = taggingSecretStrategies;
|
|
139
|
+
this.authorizeAllUtilityCallTargets = authorizeAllUtilityCallTargets;
|
|
140
|
+
this.artifactResolver = artifactResolver;
|
|
141
|
+
this.rootPath = rootPath;
|
|
142
|
+
this.packageName = packageName;
|
|
52
143
|
this.isMisc = true;
|
|
53
144
|
this.isTxe = true;
|
|
54
145
|
this.logger = createLogger('txe:top_level_context');
|
|
55
146
|
this.logger.debug('Entering Top Level Context');
|
|
56
147
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
148
|
+
contractOracleVersion;
|
|
149
|
+
assertCompatibleOracleVersion(major, minor) {
|
|
150
|
+
if (major !== ORACLE_VERSION_MAJOR) {
|
|
151
|
+
const hint = major > ORACLE_VERSION_MAJOR ? 'The contract was compiled with a newer version of Aztec.nr than this aztec cli version supports. Upgrade your aztec cli version to a compatible version.' : 'The contract was compiled with an older version of Aztec.nr than this aztec cli version supports. Recompile the contract with a compatible version of Aztec.nr.';
|
|
152
|
+
throw new Error(`Incompatible aztec cli version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle major version ${ORACLE_VERSION_MAJOR}, got ${major})`);
|
|
60
153
|
}
|
|
154
|
+
this.contractOracleVersion = {
|
|
155
|
+
major,
|
|
156
|
+
minor
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
// Prefixed with "nonOracleFunction" as it is not used as an oracle handler.
|
|
160
|
+
nonOracleFunctionGetContractOracleVersion() {
|
|
161
|
+
return this.contractOracleVersion;
|
|
61
162
|
}
|
|
62
163
|
// This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
|
|
63
164
|
// setup.
|
|
64
|
-
|
|
165
|
+
getRandomField() {
|
|
65
166
|
return Fr.random();
|
|
66
167
|
}
|
|
67
168
|
// We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
|
|
68
|
-
|
|
169
|
+
log(level, message, _fieldsSize, fields) {
|
|
69
170
|
if (!LogLevels[level]) {
|
|
70
|
-
throw new Error(`Invalid
|
|
171
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
71
172
|
}
|
|
72
173
|
const levelName = LogLevels[level];
|
|
73
174
|
this.logger[levelName](`${applyStringFormatting(message, fields)}`, {
|
|
74
175
|
module: `${this.logger.module}:debug_log`
|
|
75
176
|
});
|
|
177
|
+
return Promise.resolve();
|
|
178
|
+
}
|
|
179
|
+
getDefaultAddress() {
|
|
180
|
+
return DEFAULT_ADDRESS;
|
|
76
181
|
}
|
|
77
|
-
async
|
|
182
|
+
async getNextBlockNumber() {
|
|
78
183
|
return BlockNumber(await this.getLastBlockNumber() + 1);
|
|
79
184
|
}
|
|
80
|
-
|
|
185
|
+
getNextBlockTimestamp() {
|
|
81
186
|
return Promise.resolve(this.nextBlockTimestamp);
|
|
82
187
|
}
|
|
83
|
-
async
|
|
84
|
-
return (await this.stateMachine.node.
|
|
188
|
+
async getLastBlockTimestamp() {
|
|
189
|
+
return (await this.stateMachine.node.getBlockData('latest')).header.globalVariables.timestamp;
|
|
85
190
|
}
|
|
86
|
-
async
|
|
87
|
-
const
|
|
191
|
+
async getLastTxEffects() {
|
|
192
|
+
const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
|
|
193
|
+
const block = await this.stateMachine.archiver.getBlock({
|
|
194
|
+
number: latestBlockNumber
|
|
195
|
+
});
|
|
88
196
|
if (block.body.txEffects.length != 1) {
|
|
89
197
|
// Note that calls like env.mine() will result in blocks with no transactions, hitting this
|
|
90
198
|
throw new Error(`Expected a single transaction in the last block, found ${block.body.txEffects.length}`);
|
|
91
199
|
}
|
|
92
200
|
const txEffects = block.body.txEffects[0];
|
|
201
|
+
const privateLogs = txEffects.privateLogs;
|
|
202
|
+
if (privateLogs.length > MAX_PRIVATE_LOGS_PER_TX) {
|
|
203
|
+
throw new Error(`${privateLogs.length} private logs exceed max ${MAX_PRIVATE_LOGS_PER_TX}`);
|
|
204
|
+
}
|
|
93
205
|
return {
|
|
94
206
|
txHash: txEffects.txHash,
|
|
95
207
|
noteHashes: txEffects.noteHashes,
|
|
96
|
-
nullifiers: txEffects.nullifiers
|
|
208
|
+
nullifiers: txEffects.nullifiers,
|
|
209
|
+
privateLogs
|
|
97
210
|
};
|
|
98
211
|
}
|
|
99
|
-
async
|
|
212
|
+
async syncContractNonOracleMethod(contractAddress, scope, jobId) {
|
|
213
|
+
if (contractAddress.equals(DEFAULT_ADDRESS)) {
|
|
214
|
+
this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
218
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(contractAddress, null, async (call, execScopes)=>{
|
|
219
|
+
await this.executeUtilityCall(call, {
|
|
220
|
+
scopes: execScopes,
|
|
221
|
+
jobId
|
|
222
|
+
});
|
|
223
|
+
}, blockHeader, jobId, [
|
|
224
|
+
scope
|
|
225
|
+
]);
|
|
226
|
+
}
|
|
227
|
+
async getPrivateEvents(selector, contractAddress, scope) {
|
|
228
|
+
const events = (await this.privateEventStore.getPrivateEvents(selector, {
|
|
229
|
+
contractAddress,
|
|
230
|
+
scopes: [
|
|
231
|
+
scope
|
|
232
|
+
],
|
|
233
|
+
fromBlock: 0,
|
|
234
|
+
toBlock: await this.getLastBlockNumber() + 1
|
|
235
|
+
})).map((e)=>e.packedEvent);
|
|
236
|
+
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
237
|
+
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
238
|
+
}
|
|
239
|
+
if (events.some((e)=>e.length > MAX_PRIVATE_EVENT_LEN)) {
|
|
240
|
+
throw new Error(`Some private event has length larger than maxLen ${MAX_PRIVATE_EVENT_LEN}`);
|
|
241
|
+
}
|
|
242
|
+
return events;
|
|
243
|
+
}
|
|
244
|
+
async advanceBlocksBy(blocks) {
|
|
100
245
|
this.logger.debug(`time traveling ${blocks} blocks`);
|
|
101
246
|
for(let i = 0; i < blocks; i++){
|
|
102
247
|
await this.mineBlock();
|
|
103
248
|
}
|
|
104
249
|
}
|
|
105
|
-
|
|
250
|
+
advanceTimestampBy(duration) {
|
|
106
251
|
this.logger.debug(`time traveling ${duration} seconds`);
|
|
107
252
|
this.nextBlockTimestamp += duration;
|
|
108
253
|
}
|
|
109
|
-
|
|
254
|
+
deploymentNullifier(address) {
|
|
255
|
+
return siloNullifier(AztecAddress.fromNumberUnsafe(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS), address.toField());
|
|
256
|
+
}
|
|
257
|
+
async deploy(contractPath, initializer, args, secret, salt, deployer) {
|
|
258
|
+
const { artifact, instance } = await this.artifactResolver.resolveDeployArtifact({
|
|
259
|
+
rootPath: this.rootPath,
|
|
260
|
+
packageName: this.packageName,
|
|
261
|
+
contractPath,
|
|
262
|
+
initializer,
|
|
263
|
+
args,
|
|
264
|
+
secret,
|
|
265
|
+
salt,
|
|
266
|
+
deployer
|
|
267
|
+
});
|
|
110
268
|
// Emit deployment nullifier
|
|
111
269
|
await this.mineBlock({
|
|
112
270
|
nullifiers: [
|
|
113
|
-
await
|
|
271
|
+
await this.deploymentNullifier(instance.address)
|
|
114
272
|
]
|
|
115
273
|
});
|
|
116
274
|
if (!secret.equals(Fr.ZERO)) {
|
|
117
|
-
await this.
|
|
275
|
+
await this.registerContractAndAddAccount(artifact, instance, secret);
|
|
118
276
|
} else {
|
|
119
|
-
await this.
|
|
120
|
-
await this.
|
|
277
|
+
await this.contractStore.addContractInstance(instance);
|
|
278
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
121
279
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
122
280
|
}
|
|
281
|
+
return CONTRACT_INSTANCE.serialization.fn(instance).flat();
|
|
123
282
|
}
|
|
124
|
-
|
|
283
|
+
/**
|
|
284
|
+
* Mines a single block containing only the deployment nullifiers for the contracts at the given addresses.
|
|
285
|
+
*/ async mineDeploymentNullifiers(addresses) {
|
|
286
|
+
await this.mineBlock({
|
|
287
|
+
nullifiers: await Promise.all(addresses.map((address)=>this.deploymentNullifier(address)))
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
async addAccount(secret) {
|
|
291
|
+
const { artifact, instance } = await this.artifactResolver.resolveAccountArtifact(secret);
|
|
292
|
+
return this.registerContractAndAddAccount(artifact, instance, secret);
|
|
293
|
+
}
|
|
294
|
+
async registerContractAndAddAccount(artifact, instance, secret) {
|
|
125
295
|
const partialAddress = await computePartialAddress(instance);
|
|
126
296
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
127
|
-
await this.
|
|
128
|
-
await this.
|
|
129
|
-
const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
|
|
130
|
-
await this.
|
|
131
|
-
await this.
|
|
297
|
+
await this.contractStore.addContractInstance(instance);
|
|
298
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
299
|
+
const completeAddress = await this.keyStore.addAccount(await deriveKeys(secret), partialAddress);
|
|
300
|
+
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
301
|
+
await this.addressStore.addCompleteAddress(completeAddress);
|
|
132
302
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
133
303
|
return completeAddress;
|
|
134
304
|
}
|
|
135
|
-
async
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
await this.
|
|
139
|
-
await this.addressDataProvider.addCompleteAddress(completeAddress);
|
|
305
|
+
async createAccount(secret, partialAddress) {
|
|
306
|
+
const completeAddress = await this.keyStore.addAccount(await deriveKeys(secret), partialAddress);
|
|
307
|
+
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
308
|
+
await this.addressStore.addCompleteAddress(completeAddress);
|
|
140
309
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
141
310
|
return completeAddress;
|
|
142
311
|
}
|
|
143
|
-
async
|
|
144
|
-
const account = await this.
|
|
145
|
-
const
|
|
312
|
+
async addAuthWitness(address, messageHash) {
|
|
313
|
+
const account = await this.accountStore.getAccount(address);
|
|
314
|
+
const ivpkMHash = await hashPublicKey(account.publicKeys.ivpkM);
|
|
315
|
+
const privateKey = await this.keyStore.getMasterSecretKey(ivpkMHash);
|
|
146
316
|
const schnorr = new Schnorr();
|
|
147
|
-
const signature = await schnorr.constructSignature(messageHash
|
|
148
|
-
const authWitness = new AuthWitness(messageHash,
|
|
149
|
-
...signature.toBuffer()
|
|
150
|
-
]);
|
|
317
|
+
const signature = await schnorr.constructSignature(messageHash, privateKey);
|
|
318
|
+
const authWitness = new AuthWitness(messageHash, signature.toLimbFields());
|
|
151
319
|
this.authwits.set(authWitness.requestHash.toString(), authWitness);
|
|
152
320
|
}
|
|
321
|
+
setTaggingSecretStrategies(unconstrainedStrategy, constrainedStrategy) {
|
|
322
|
+
const apply = (mode, strategy)=>{
|
|
323
|
+
if (strategy.isSome()) {
|
|
324
|
+
this.taggingSecretStrategies.set(mode, strategy.value);
|
|
325
|
+
} else {
|
|
326
|
+
this.taggingSecretStrategies.delete(mode);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
apply(AppTaggingSecretKind.UNCONSTRAINED, unconstrainedStrategy);
|
|
330
|
+
apply(AppTaggingSecretKind.CONSTRAINED, constrainedStrategy);
|
|
331
|
+
}
|
|
332
|
+
setAuthorizeAllUtilityCallTargets(authorizeAll) {
|
|
333
|
+
this.authorizeAllUtilityCallTargets = authorizeAll;
|
|
334
|
+
}
|
|
335
|
+
async sendL1ToL2Message(content, secretHash, sender, recipient) {
|
|
336
|
+
// Messages are appended to the tree, so the next free slot is simply the current tree size.
|
|
337
|
+
const { size } = await this.stateMachine.synchronizer.getCommitted().getTreeInfo(MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
|
|
338
|
+
const leafIndex = new Fr(size);
|
|
339
|
+
const message = new L1ToL2Message(new L1Actor(sender, this.chainId.toNumber()), new L2Actor(recipient, this.version.toNumber()), content, secretHash, leafIndex);
|
|
340
|
+
await this.mineBlock({
|
|
341
|
+
l1ToL2Messages: [
|
|
342
|
+
message.hash()
|
|
343
|
+
]
|
|
344
|
+
});
|
|
345
|
+
return leafIndex;
|
|
346
|
+
}
|
|
153
347
|
async mineBlock(options = {}) {
|
|
154
|
-
const blockNumber = await this.
|
|
348
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
155
349
|
const txEffect = TxEffect.empty();
|
|
156
350
|
txEffect.nullifiers = [
|
|
157
351
|
getSingleTxBlockRequestHash(blockNumber),
|
|
@@ -159,241 +353,356 @@ export class TXEOracleTopLevelContext {
|
|
|
159
353
|
];
|
|
160
354
|
txEffect.txHash = new TxHash(new Fr(blockNumber));
|
|
161
355
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
162
|
-
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
163
|
-
const
|
|
356
|
+
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees, options.l1ToL2Messages ?? []);
|
|
357
|
+
const globals = makeGlobalVariables(undefined, {
|
|
164
358
|
blockNumber,
|
|
165
359
|
timestamp: this.nextBlockTimestamp,
|
|
166
360
|
version: this.version,
|
|
167
361
|
chainId: this.chainId
|
|
168
|
-
})
|
|
362
|
+
});
|
|
363
|
+
const block = await makeTXEBlock(forkedWorldTrees, globals, [
|
|
169
364
|
txEffect
|
|
170
|
-
])
|
|
365
|
+
]);
|
|
171
366
|
await forkedWorldTrees.close();
|
|
172
367
|
this.logger.info(`Created block ${blockNumber} with timestamp ${block.header.globalVariables.timestamp}`);
|
|
173
|
-
await this.stateMachine.handleL2Block(block);
|
|
368
|
+
await this.stateMachine.handleL2Block(block, options.l1ToL2Messages ?? []);
|
|
174
369
|
}
|
|
175
|
-
async
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
const blockNumber = await this.txeGetNextBlockNumber();
|
|
183
|
-
const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
|
|
184
|
-
const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
|
|
185
|
-
const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
|
|
186
|
-
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
187
|
-
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
188
|
-
const blockHeader = await this.pxeOracleInterface.getAnchorBlockHeader();
|
|
189
|
-
const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
|
|
190
|
-
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
191
|
-
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
192
|
-
const simulator = new WASMSimulator();
|
|
193
|
-
const privateExecutionOracle = new PrivateExecutionOracle(argsHash, txContext, callContext, /** Header of a block whose state is used during private execution (not the block the transaction is included in). */ blockHeader, /** List of transient auth witnesses to be used during this simulation */ Array.from(this.authwits.values()), /** List of transient auth witnesses to be used during this simulation */ [], HashedValuesCache.create([
|
|
194
|
-
new HashedValues(args, argsHash)
|
|
195
|
-
]), noteCache, taggingIndexCache, this.pxeOracleInterface, 0, 1, undefined, undefined, /**
|
|
196
|
-
* In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
|
|
197
|
-
* contract would perform, including setting senderForTags.
|
|
198
|
-
*/ from, simulator);
|
|
199
|
-
// Note: This is a slight modification of simulator.run without any of the checks. Maybe we should modify simulator.run with a boolean value to skip checks.
|
|
200
|
-
let result;
|
|
201
|
-
let executionResult;
|
|
370
|
+
async privateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false, additionalScopes = [], jobId, authorizedUtilityCallTargets, gasSettings) {
|
|
371
|
+
const env = {
|
|
372
|
+
stack: [],
|
|
373
|
+
error: void 0,
|
|
374
|
+
hasError: false
|
|
375
|
+
};
|
|
202
376
|
try {
|
|
203
|
-
|
|
204
|
-
const
|
|
377
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
378
|
+
const anchoredContractData = new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, blockHeader);
|
|
379
|
+
this.logger.verbose(`Executing external function ${await anchoredContractData.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
|
|
380
|
+
const artifact = await anchoredContractData.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
381
|
+
if (!artifact) {
|
|
382
|
+
const message = functionSelector.equals(await FunctionSelector.fromSignature('verify_private_authwit(Field)')) ? 'Found no account contract artifact for a private authwit check - use `create_contract_account` instead of `create_light_account` for authwit support.' : 'Function Artifact does not exist';
|
|
383
|
+
throw new Error(message);
|
|
384
|
+
}
|
|
385
|
+
const scopes = from === undefined ? additionalScopes : [
|
|
386
|
+
from,
|
|
387
|
+
...additionalScopes
|
|
388
|
+
];
|
|
389
|
+
// Sync notes before executing private function to discover notes from previous transactions
|
|
390
|
+
const utilityExecutor = async (call, execScopes)=>{
|
|
391
|
+
await this.executeUtilityCall(call, {
|
|
392
|
+
scopes: execScopes,
|
|
393
|
+
jobId
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader, jobId, scopes);
|
|
397
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
398
|
+
const msgSender = from ?? AztecAddress.NULL_MSG_SENDER;
|
|
399
|
+
const callContext = new CallContext(msgSender, targetContractAddress, functionSelector, isStaticCall);
|
|
400
|
+
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
401
|
+
const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
|
|
402
|
+
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
403
|
+
// In production, the account contract sets the min revertible counter before calling the app function.
|
|
404
|
+
// Since TXE bypasses the account contract, we simulate this by setting minRevertibleSideEffectCounter to 1,
|
|
405
|
+
// marking all side effects as revertible.
|
|
406
|
+
const minRevertibleSideEffectCounter = 1;
|
|
407
|
+
await noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
|
|
408
|
+
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
409
|
+
const simulator = new WASMSimulator();
|
|
410
|
+
const transientArrayService = new TransientArrayService();
|
|
411
|
+
const privateExecutionOracle = new PrivateExecutionOracle({
|
|
412
|
+
argsHash,
|
|
413
|
+
txContext,
|
|
414
|
+
txRequestSalt: Fr.ZERO,
|
|
415
|
+
callContext,
|
|
416
|
+
anchorBlockHeader: blockHeader,
|
|
417
|
+
utilityExecutor,
|
|
418
|
+
authWitnesses: Array.from(this.authwits.values()),
|
|
419
|
+
capsules: [],
|
|
420
|
+
executionCache: HashedValuesCache.create([
|
|
421
|
+
new HashedValues(args, argsHash)
|
|
422
|
+
]),
|
|
423
|
+
noteCache,
|
|
424
|
+
taggingIndexCache,
|
|
425
|
+
anchoredContractData,
|
|
426
|
+
noteStore: this.noteStore,
|
|
427
|
+
keyStore: this.keyStore,
|
|
428
|
+
addressStore: this.addressStore,
|
|
429
|
+
aztecNode: this.stateMachine.node,
|
|
430
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
431
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
432
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
433
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
434
|
+
factService: new FactService(this.factStore, scopes),
|
|
435
|
+
privateEventStore: this.privateEventStore,
|
|
436
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
437
|
+
jobId,
|
|
438
|
+
totalPublicCalldataCount: 0,
|
|
439
|
+
sideEffectCounter: minRevertibleSideEffectCounter,
|
|
440
|
+
scopes,
|
|
441
|
+
// In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
|
|
442
|
+
// contract would perform, including setting senderForTags.
|
|
443
|
+
senderForTags: from,
|
|
444
|
+
simulator,
|
|
445
|
+
txResolver: this.stateMachine.txResolver,
|
|
446
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
447
|
+
hooks: composeHooks({
|
|
448
|
+
authorizeUtilityCall: this.buildAuthorizeUtilityCallHook(isStaticCall ? 'private view' : 'private', authorizedUtilityCallTargets),
|
|
449
|
+
resolveTaggingSecretStrategy: makeResolveTaggingSecretStrategyHook(this.taggingSecretStrategies)
|
|
450
|
+
}),
|
|
451
|
+
transientArrayService
|
|
452
|
+
});
|
|
453
|
+
// Note: This is a slight modification of simulator.run without any of the checks. Maybe we should modify simulator.run with a boolean value to skip checks.
|
|
454
|
+
let result;
|
|
455
|
+
let executionResult;
|
|
456
|
+
try {
|
|
457
|
+
executionResult = await executePrivateFunction(simulator, privateExecutionOracle, artifact, targetContractAddress, functionSelector);
|
|
458
|
+
const publicCallRequests = collectNested([
|
|
459
|
+
executionResult
|
|
460
|
+
], (r)=>r.publicInputs.publicCallRequests.getActiveItems().map((r)=>r.inner).concat(r.publicInputs.publicTeardownCallRequest.isEmpty() ? [] : [
|
|
461
|
+
r.publicInputs.publicTeardownCallRequest
|
|
462
|
+
]));
|
|
463
|
+
const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
|
|
464
|
+
const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
|
|
465
|
+
return new HashedValues(calldata, r.calldataHash);
|
|
466
|
+
}));
|
|
467
|
+
const nonceGenerator = noteCache.getNonceGenerator();
|
|
468
|
+
result = new PrivateExecutionResult(executionResult, nonceGenerator, publicFunctionsCalldata);
|
|
469
|
+
} catch (err) {
|
|
470
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
|
|
471
|
+
}
|
|
472
|
+
// According to the protocol rules, there must be at least one nullifier in the tx. The first nullifier is used as
|
|
473
|
+
// the nonce generator for the note hashes.
|
|
474
|
+
// We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
|
|
475
|
+
const { publicInputs } = await generateSimulatedProvingResult(result, (addr, sel)=>anchoredContractData.getDebugFunctionName(addr, sel), this.stateMachine.node, minRevertibleSideEffectCounter);
|
|
476
|
+
const globals = makeGlobalVariables();
|
|
477
|
+
globals.blockNumber = blockNumber;
|
|
478
|
+
globals.timestamp = this.nextBlockTimestamp;
|
|
479
|
+
globals.chainId = this.chainId;
|
|
480
|
+
globals.version = this.version;
|
|
481
|
+
globals.gasFees = GasFees.empty();
|
|
482
|
+
const forkedWorldTrees = _ts_add_disposable_resource(env, await this.stateMachine.synchronizer.nativeWorldStateService.fork(), true);
|
|
483
|
+
const bindings = this.logger.getBindings();
|
|
484
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore), bindings);
|
|
485
|
+
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
486
|
+
const config = PublicSimulatorConfig.from({
|
|
487
|
+
skipFeeEnforcement: true,
|
|
488
|
+
collectDebugLogs: true,
|
|
489
|
+
collectHints: false,
|
|
490
|
+
collectStatistics: false,
|
|
491
|
+
collectCallMetadata: true
|
|
492
|
+
});
|
|
493
|
+
// The AVM simulator reads this fork's contracts DB, scoped by fork id, for each simulation.
|
|
494
|
+
const forkId = forkedWorldTrees.getRevision().forkId;
|
|
495
|
+
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, new PublicTxSimulator(this.stateMachine.synchronizer.avmSimulator, globals, contractsDB, forkId, config, bindings), new TestDateProvider(), undefined, createLogger('simulator:public-processor', bindings));
|
|
496
|
+
const tx = await Tx.create({
|
|
497
|
+
data: publicInputs,
|
|
498
|
+
chonkProof: ChonkProof.empty(),
|
|
499
|
+
contractClassLogFields: [],
|
|
500
|
+
publicFunctionCalldata: result.publicFunctionCalldata
|
|
501
|
+
});
|
|
502
|
+
let checkpoint;
|
|
503
|
+
if (isStaticCall) {
|
|
504
|
+
checkpoint = await ForkCheckpoint.new(forkedWorldTrees);
|
|
505
|
+
}
|
|
506
|
+
const results = await processor.process([
|
|
507
|
+
tx
|
|
508
|
+
]);
|
|
509
|
+
const [processedTx] = results[0];
|
|
510
|
+
const failedTxs = results[1];
|
|
511
|
+
if (failedTxs.length !== 0) {
|
|
512
|
+
throw new Error(`Public execution has failed: ${failedTxs[0].error}`);
|
|
513
|
+
} else if (!processedTx.revertCode.isOK()) {
|
|
514
|
+
if (processedTx.revertReason) {
|
|
515
|
+
try {
|
|
516
|
+
await enrichPublicSimulationError(processedTx.revertReason, this.contractStore, this.stateMachine.contractClassService, await this.stateMachine.anchorBlockStore.getBlockHeader(), this.logger);
|
|
517
|
+
// eslint-disable-next-line no-empty
|
|
518
|
+
} catch {}
|
|
519
|
+
throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
|
|
520
|
+
} else {
|
|
521
|
+
throw new Error('Contract execution has reverted');
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
// Walk the nested private-call tree and collect every offchain effect the transaction emitted.
|
|
525
|
+
// PXE stores these on each `PrivateCallExecutionResult` and they never reach TXE via the
|
|
526
|
+
// `aztec_utl_emitOffchainEffect` foreign-call path (that path only fires at the top-level), so
|
|
527
|
+
// we pull them out here and the RPC wrapper will hand them to `TXESession` for buffering.
|
|
528
|
+
const offchainEffects = collectNested([
|
|
205
529
|
executionResult
|
|
206
|
-
], (r)=>r.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
// TXE's top level context does not track side effect counters, and as such, minRevertibleSideEffectCounter is always 0.
|
|
214
|
-
// This has the unfortunate consequence of always producing revertible nullifiers, which means we
|
|
215
|
-
// must set the firstNullifierHint to Fr.ZERO so the txRequestHash is always used as nonce generator
|
|
216
|
-
result = new PrivateExecutionResult(executionResult, Fr.ZERO, publicFunctionsCalldata);
|
|
217
|
-
} catch (err) {
|
|
218
|
-
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
|
|
219
|
-
}
|
|
220
|
-
// According to the protocol rules, the nonce generator for the note hashes
|
|
221
|
-
// can either be the first nullifier in the tx or the hash of the initial tx request
|
|
222
|
-
// if there are none.
|
|
223
|
-
const nonceGenerator = result.firstNullifier.equals(Fr.ZERO) ? protocolNullifier : result.firstNullifier;
|
|
224
|
-
const { publicInputs } = await generateSimulatedProvingResult(result, nonceGenerator, this.contractDataProvider);
|
|
225
|
-
const globals = makeGlobalVariables();
|
|
226
|
-
globals.blockNumber = blockNumber;
|
|
227
|
-
globals.timestamp = this.nextBlockTimestamp;
|
|
228
|
-
globals.chainId = this.chainId;
|
|
229
|
-
globals.version = this.version;
|
|
230
|
-
globals.gasFees = GasFees.empty();
|
|
231
|
-
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
232
|
-
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractDataProvider));
|
|
233
|
-
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
234
|
-
const config = PublicSimulatorConfig.from({
|
|
235
|
-
skipFeeEnforcement: true,
|
|
236
|
-
collectDebugLogs: true,
|
|
237
|
-
collectHints: false,
|
|
238
|
-
collectStatistics: false,
|
|
239
|
-
collectCallMetadata: true
|
|
240
|
-
});
|
|
241
|
-
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config), new TestDateProvider());
|
|
242
|
-
const tx = await Tx.create({
|
|
243
|
-
data: publicInputs,
|
|
244
|
-
chonkProof: ChonkProof.empty(),
|
|
245
|
-
contractClassLogFields: [],
|
|
246
|
-
publicFunctionCalldata: result.publicFunctionCalldata
|
|
247
|
-
});
|
|
248
|
-
let checkpoint;
|
|
249
|
-
if (isStaticCall) {
|
|
250
|
-
checkpoint = await ForkCheckpoint.new(forkedWorldTrees);
|
|
251
|
-
}
|
|
252
|
-
const results = await processor.process([
|
|
253
|
-
tx
|
|
254
|
-
]);
|
|
255
|
-
const [processedTx] = results[0];
|
|
256
|
-
const failedTxs = results[1];
|
|
257
|
-
if (failedTxs.length !== 0) {
|
|
258
|
-
throw new Error(`Public execution has failed: ${failedTxs[0].error}`);
|
|
259
|
-
} else if (!processedTx.revertCode.isOK()) {
|
|
260
|
-
if (processedTx.revertReason) {
|
|
261
|
-
try {
|
|
262
|
-
await enrichPublicSimulationError(processedTx.revertReason, this.contractDataProvider, this.logger);
|
|
263
|
-
// eslint-disable-next-line no-empty
|
|
264
|
-
} catch {}
|
|
265
|
-
throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
|
|
266
|
-
} else {
|
|
267
|
-
throw new Error('Contract execution has reverted');
|
|
530
|
+
], (r)=>r.offchainEffects.map((e)=>e.data));
|
|
531
|
+
if (isStaticCall) {
|
|
532
|
+
await checkpoint.revert();
|
|
533
|
+
return {
|
|
534
|
+
returnValues: executionResult.returnValues ?? [],
|
|
535
|
+
offchainEffects
|
|
536
|
+
};
|
|
268
537
|
}
|
|
538
|
+
const txEffect = TxEffect.empty();
|
|
539
|
+
txEffect.noteHashes = processedTx.txEffect.noteHashes;
|
|
540
|
+
txEffect.nullifiers = processedTx.txEffect.nullifiers;
|
|
541
|
+
txEffect.privateLogs = processedTx.txEffect.privateLogs;
|
|
542
|
+
txEffect.publicLogs = processedTx.txEffect.publicLogs;
|
|
543
|
+
txEffect.publicDataWrites = processedTx.txEffect.publicDataWrites;
|
|
544
|
+
txEffect.txHash = new TxHash(new Fr(blockNumber));
|
|
545
|
+
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
|
|
546
|
+
await forkedWorldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
547
|
+
const l2Block = await makeTXEBlock(forkedWorldTrees, globals, [
|
|
548
|
+
txEffect
|
|
549
|
+
]);
|
|
550
|
+
await this.stateMachine.handleL2Block(l2Block);
|
|
551
|
+
return {
|
|
552
|
+
returnValues: executionResult.returnValues ?? [],
|
|
553
|
+
offchainEffects
|
|
554
|
+
};
|
|
555
|
+
} catch (e) {
|
|
556
|
+
env.error = e;
|
|
557
|
+
env.hasError = true;
|
|
558
|
+
} finally{
|
|
559
|
+
const result = _ts_dispose_resources(env);
|
|
560
|
+
if (result) await result;
|
|
269
561
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const inputsForPublic = new PartialPrivateTailPublicInputsForPublic(nonRevertibleAccumulatedData, revertibleAccumulatedData, PublicCallRequest.empty());
|
|
331
|
-
const constantData = new TxConstantData(anchorBlockHeader, txContext, Fr.zero(), Fr.zero());
|
|
332
|
-
const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*includeByTimestamp=*/ 0n, inputsForPublic, undefined);
|
|
333
|
-
const tx = await Tx.create({
|
|
334
|
-
data: txData,
|
|
335
|
-
chonkProof: ChonkProof.empty(),
|
|
336
|
-
contractClassLogFields: [],
|
|
337
|
-
publicFunctionCalldata: [
|
|
338
|
-
calldataHashedValues
|
|
339
|
-
]
|
|
340
|
-
});
|
|
341
|
-
let checkpoint;
|
|
342
|
-
if (isStaticCall) {
|
|
343
|
-
checkpoint = await ForkCheckpoint.new(forkedWorldTrees);
|
|
344
|
-
}
|
|
345
|
-
const results = await processor.process([
|
|
346
|
-
tx
|
|
347
|
-
]);
|
|
348
|
-
const [processedTx] = results[0];
|
|
349
|
-
const failedTxs = results[1];
|
|
350
|
-
if (failedTxs.length !== 0) {
|
|
351
|
-
throw new Error(`Public execution has failed: ${failedTxs[0].error}`);
|
|
352
|
-
} else if (!processedTx.revertCode.isOK()) {
|
|
353
|
-
if (processedTx.revertReason) {
|
|
354
|
-
try {
|
|
355
|
-
await enrichPublicSimulationError(processedTx.revertReason, this.contractDataProvider, this.logger);
|
|
356
|
-
// eslint-disable-next-line no-empty
|
|
357
|
-
} catch {}
|
|
358
|
-
throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
|
|
359
|
-
} else {
|
|
360
|
-
throw new Error('Contract execution has reverted');
|
|
562
|
+
}
|
|
563
|
+
async publicCallNewFlow(from, targetContractAddress, calldata, isStaticCall, gasSettings) {
|
|
564
|
+
const env = {
|
|
565
|
+
stack: [],
|
|
566
|
+
error: void 0,
|
|
567
|
+
hasError: false
|
|
568
|
+
};
|
|
569
|
+
try {
|
|
570
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
571
|
+
const anchoredContractData = new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlockHeader);
|
|
572
|
+
this.logger.verbose(`Executing public function ${await anchoredContractData.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`);
|
|
573
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
574
|
+
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
575
|
+
const calldataHash = await computeCalldataHash(calldata);
|
|
576
|
+
const calldataHashedValues = new HashedValues(calldata, calldataHash);
|
|
577
|
+
const globals = makeGlobalVariables();
|
|
578
|
+
globals.blockNumber = blockNumber;
|
|
579
|
+
globals.timestamp = this.nextBlockTimestamp;
|
|
580
|
+
globals.chainId = this.chainId;
|
|
581
|
+
globals.version = this.version;
|
|
582
|
+
globals.gasFees = GasFees.empty();
|
|
583
|
+
const forkedWorldTrees = _ts_add_disposable_resource(env, await this.stateMachine.synchronizer.nativeWorldStateService.fork(), true);
|
|
584
|
+
const bindings2 = this.logger.getBindings();
|
|
585
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore), bindings2);
|
|
586
|
+
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
587
|
+
const config = PublicSimulatorConfig.from({
|
|
588
|
+
skipFeeEnforcement: true,
|
|
589
|
+
collectDebugLogs: true,
|
|
590
|
+
collectHints: false,
|
|
591
|
+
collectStatistics: false,
|
|
592
|
+
collectCallMetadata: true
|
|
593
|
+
});
|
|
594
|
+
// The AVM simulator reads this fork's contracts DB, scoped by fork id, for each simulation.
|
|
595
|
+
const forkId2 = forkedWorldTrees.getRevision().forkId;
|
|
596
|
+
const simulator = new PublicTxSimulator(this.stateMachine.synchronizer.avmSimulator, globals, contractsDB, forkId2, config, bindings2);
|
|
597
|
+
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, simulator, new TestDateProvider(), undefined, createLogger('simulator:public-processor', bindings2));
|
|
598
|
+
// We're simulating a scenario in which private execution immediately enqueues a public call and halts. The private
|
|
599
|
+
// kernel init would in this case inject a nullifier with the transaction request hash as a non-revertible
|
|
600
|
+
// side-effect, which the AVM then expects to exist in order to use it as the nonce generator when siloing notes as
|
|
601
|
+
// unique.
|
|
602
|
+
const nonRevertibleAccumulatedData = PrivateToPublicAccumulatedData.empty();
|
|
603
|
+
nonRevertibleAccumulatedData.nullifiers[0] = getSingleTxBlockRequestHash(blockNumber);
|
|
604
|
+
// The enqueued public call itself we make be revertible so that the public execution is itself revertible, as tests
|
|
605
|
+
// may require producing reverts.
|
|
606
|
+
const revertibleAccumulatedData = PrivateToPublicAccumulatedData.empty();
|
|
607
|
+
revertibleAccumulatedData.publicCallRequests[0] = new PublicCallRequest(from ?? AztecAddress.NULL_MSG_SENDER, targetContractAddress, isStaticCall, calldataHash);
|
|
608
|
+
const inputsForPublic = new PartialPrivateTailPublicInputsForPublic(nonRevertibleAccumulatedData, revertibleAccumulatedData, PublicCallRequest.empty());
|
|
609
|
+
const constantData = new TxConstantData(anchorBlockHeader, txContext, Fr.zero(), Fr.zero());
|
|
610
|
+
const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*expirationTimestamp=*/ 0n, inputsForPublic, undefined);
|
|
611
|
+
const tx = await Tx.create({
|
|
612
|
+
data: txData,
|
|
613
|
+
chonkProof: ChonkProof.empty(),
|
|
614
|
+
contractClassLogFields: [],
|
|
615
|
+
publicFunctionCalldata: [
|
|
616
|
+
calldataHashedValues
|
|
617
|
+
]
|
|
618
|
+
});
|
|
619
|
+
let checkpoint;
|
|
620
|
+
if (isStaticCall) {
|
|
621
|
+
checkpoint = await ForkCheckpoint.new(forkedWorldTrees);
|
|
361
622
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
623
|
+
const results = await processor.process([
|
|
624
|
+
tx
|
|
625
|
+
]);
|
|
626
|
+
const [processedTx] = results[0];
|
|
627
|
+
const failedTxs = results[1];
|
|
628
|
+
if (failedTxs.length !== 0) {
|
|
629
|
+
throw new Error(`Public execution has failed: ${failedTxs[0].error}`);
|
|
630
|
+
} else if (!processedTx.revertCode.isOK()) {
|
|
631
|
+
if (processedTx.revertReason) {
|
|
632
|
+
try {
|
|
633
|
+
await enrichPublicSimulationError(processedTx.revertReason, this.contractStore, this.stateMachine.contractClassService, anchorBlockHeader, this.logger);
|
|
634
|
+
// eslint-disable-next-line no-empty
|
|
635
|
+
} catch {}
|
|
636
|
+
throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
|
|
637
|
+
} else {
|
|
638
|
+
throw new Error('Contract execution has reverted');
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
const returnValues = results[3][0].values;
|
|
642
|
+
if (isStaticCall) {
|
|
643
|
+
await checkpoint.revert();
|
|
644
|
+
return returnValues ?? [];
|
|
645
|
+
}
|
|
646
|
+
const txEffect = TxEffect.empty();
|
|
647
|
+
txEffect.noteHashes = processedTx.txEffect.noteHashes;
|
|
648
|
+
txEffect.nullifiers = processedTx.txEffect.nullifiers;
|
|
649
|
+
txEffect.privateLogs = processedTx.txEffect.privateLogs;
|
|
650
|
+
txEffect.publicLogs = processedTx.txEffect.publicLogs;
|
|
651
|
+
txEffect.publicDataWrites = processedTx.txEffect.publicDataWrites;
|
|
652
|
+
txEffect.txHash = new TxHash(new Fr(blockNumber));
|
|
653
|
+
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
|
|
654
|
+
await forkedWorldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
655
|
+
const l2Block = await makeTXEBlock(forkedWorldTrees, globals, [
|
|
656
|
+
txEffect
|
|
657
|
+
]);
|
|
658
|
+
await this.stateMachine.handleL2Block(l2Block);
|
|
367
659
|
return returnValues ?? [];
|
|
660
|
+
} catch (e) {
|
|
661
|
+
env.error = e;
|
|
662
|
+
env.hasError = true;
|
|
663
|
+
} finally{
|
|
664
|
+
const result = _ts_dispose_resources(env);
|
|
665
|
+
if (result) await result;
|
|
368
666
|
}
|
|
369
|
-
const txEffect = TxEffect.empty();
|
|
370
|
-
txEffect.noteHashes = processedTx.txEffect.noteHashes;
|
|
371
|
-
txEffect.nullifiers = processedTx.txEffect.nullifiers;
|
|
372
|
-
txEffect.privateLogs = processedTx.txEffect.privateLogs;
|
|
373
|
-
txEffect.publicLogs = processedTx.txEffect.publicLogs;
|
|
374
|
-
txEffect.publicDataWrites = processedTx.txEffect.publicDataWrites;
|
|
375
|
-
txEffect.txHash = new TxHash(new Fr(blockNumber));
|
|
376
|
-
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
|
|
377
|
-
await forkedWorldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
378
|
-
const body = new Body([
|
|
379
|
-
txEffect
|
|
380
|
-
]);
|
|
381
|
-
const l2Block = new L2Block(makeAppendOnlyTreeSnapshot(), await makeTXEBlockHeader(forkedWorldTrees, globals), body);
|
|
382
|
-
await this.stateMachine.handleL2Block(l2Block);
|
|
383
|
-
await forkedWorldTrees.close();
|
|
384
|
-
return returnValues ?? [];
|
|
385
667
|
}
|
|
386
|
-
async
|
|
387
|
-
const
|
|
668
|
+
async executeUtilityFunction(from, targetContractAddress, functionSelector, args, jobId, authorizedUtilityCallTargets) {
|
|
669
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
670
|
+
const anchoredContractData = new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, blockHeader);
|
|
671
|
+
const artifact = await anchoredContractData.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
388
672
|
if (!artifact) {
|
|
389
673
|
throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
|
|
390
674
|
}
|
|
391
|
-
|
|
675
|
+
// Sync notes before executing utility function to discover notes from previous transactions
|
|
676
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, async (call, execScopes)=>{
|
|
677
|
+
await this.executeUtilityCall(call, {
|
|
678
|
+
scopes: execScopes,
|
|
679
|
+
jobId
|
|
680
|
+
});
|
|
681
|
+
}, blockHeader, jobId, await this.keyStore.getAccounts());
|
|
682
|
+
const call = FunctionCall.from({
|
|
392
683
|
name: artifact.name,
|
|
684
|
+
to: targetContractAddress,
|
|
393
685
|
selector: functionSelector,
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
686
|
+
type: FunctionType.UTILITY,
|
|
687
|
+
hideMsgSender: false,
|
|
688
|
+
isStatic: false,
|
|
689
|
+
args,
|
|
690
|
+
returnTypes: []
|
|
691
|
+
});
|
|
692
|
+
return this.executeUtilityCall(call, {
|
|
693
|
+
from,
|
|
694
|
+
scopes: await this.keyStore.getAccounts(),
|
|
695
|
+
jobId,
|
|
696
|
+
authorizedUtilityCallTargets
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
async executeUtilityCall(call, { from = AztecAddress.NULL_MSG_SENDER, scopes, jobId, authorizedUtilityCallTargets = [] }) {
|
|
700
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
701
|
+
const anchoredContractData = new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlockHeader);
|
|
702
|
+
const entryPointArtifact = await anchoredContractData.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
703
|
+
if (!entryPointArtifact) {
|
|
704
|
+
throw new Error(`Cannot run function ${call.selector} on ${call.to}: the contract is not registered.`);
|
|
705
|
+
}
|
|
397
706
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
398
707
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
399
708
|
}
|
|
@@ -402,8 +711,47 @@ export class TXEOracleTopLevelContext {
|
|
|
402
711
|
selector: call.selector
|
|
403
712
|
});
|
|
404
713
|
try {
|
|
405
|
-
const
|
|
406
|
-
const
|
|
714
|
+
const simulator = new WASMSimulator();
|
|
715
|
+
const utilityExecutor = async (syncCall, execScopes)=>{
|
|
716
|
+
await this.executeUtilityCall(syncCall, {
|
|
717
|
+
scopes: execScopes,
|
|
718
|
+
jobId
|
|
719
|
+
});
|
|
720
|
+
};
|
|
721
|
+
const oracle = new UtilityExecutionOracle({
|
|
722
|
+
callContext: CallContext.from({
|
|
723
|
+
msgSender: from,
|
|
724
|
+
contractAddress: call.to,
|
|
725
|
+
functionSelector: call.selector,
|
|
726
|
+
isStaticCall: true
|
|
727
|
+
}),
|
|
728
|
+
authWitnesses: [],
|
|
729
|
+
capsules: [],
|
|
730
|
+
anchorBlockHeader,
|
|
731
|
+
anchoredContractData,
|
|
732
|
+
noteStore: this.noteStore,
|
|
733
|
+
keyStore: this.keyStore,
|
|
734
|
+
addressStore: this.addressStore,
|
|
735
|
+
aztecNode: this.stateMachine.node,
|
|
736
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
737
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
738
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
739
|
+
factService: new FactService(this.factStore, scopes),
|
|
740
|
+
privateEventStore: this.privateEventStore,
|
|
741
|
+
txResolver: this.stateMachine.txResolver,
|
|
742
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
743
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
744
|
+
jobId,
|
|
745
|
+
scopes,
|
|
746
|
+
simulator,
|
|
747
|
+
hooks: composeHooks({
|
|
748
|
+
authorizeUtilityCall: this.buildAuthorizeUtilityCallHook('utility', authorizedUtilityCallTargets)
|
|
749
|
+
}),
|
|
750
|
+
utilityExecutor,
|
|
751
|
+
// Execution-tree root (top-level utility run or contract sync): own store; nested frames inherit it.
|
|
752
|
+
transientArrayService: new TransientArrayService()
|
|
753
|
+
});
|
|
754
|
+
const acirExecutionResult = await simulator.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, buildACIRCallback(oracle)).catch((err)=>{
|
|
407
755
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
408
756
|
throw new ExecutionError(err.message, {
|
|
409
757
|
contractAddress: call.to,
|
|
@@ -412,21 +760,41 @@ export class TXEOracleTopLevelContext {
|
|
|
412
760
|
cause: err
|
|
413
761
|
});
|
|
414
762
|
});
|
|
415
|
-
this.logger.verbose(`Utility
|
|
763
|
+
this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
|
|
416
764
|
return witnessMapToFields(acirExecutionResult.returnWitness);
|
|
417
765
|
} catch (err) {
|
|
418
|
-
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility
|
|
766
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
|
|
419
767
|
}
|
|
420
768
|
}
|
|
421
769
|
close() {
|
|
422
770
|
this.logger.debug('Exiting Top Level Context');
|
|
423
|
-
return
|
|
424
|
-
this.nextBlockTimestamp,
|
|
425
|
-
this.authwits
|
|
426
|
-
|
|
771
|
+
return {
|
|
772
|
+
nextBlockTimestamp: this.nextBlockTimestamp,
|
|
773
|
+
authwits: this.authwits,
|
|
774
|
+
taggingSecretStrategies: this.taggingSecretStrategies,
|
|
775
|
+
authorizeAllUtilityCallTargets: this.authorizeAllUtilityCallTargets
|
|
776
|
+
};
|
|
427
777
|
}
|
|
428
778
|
async getLastBlockNumber() {
|
|
429
|
-
const
|
|
430
|
-
return
|
|
779
|
+
const block = await this.stateMachine.node.getBlock('latest');
|
|
780
|
+
return block ? block.header.globalVariables.blockNumber : BlockNumber.ZERO;
|
|
781
|
+
}
|
|
782
|
+
buildAuthorizeUtilityCallHook(callerContext, authorizedTargets) {
|
|
783
|
+
if (this.authorizeAllUtilityCallTargets) {
|
|
784
|
+
return authorizeAllUtilityCallsHook;
|
|
785
|
+
}
|
|
786
|
+
if (authorizedTargets.length === 0) {
|
|
787
|
+
return undefined;
|
|
788
|
+
}
|
|
789
|
+
return (req)=>Promise.resolve({
|
|
790
|
+
authorized: req.callerContext === callerContext && authorizedTargets.some((t)=>t.equals(req.target))
|
|
791
|
+
});
|
|
431
792
|
}
|
|
432
793
|
}
|
|
794
|
+
/**
|
|
795
|
+
* An `authorizeUtilityCall` hook that authorizes every cross-contract utility call.
|
|
796
|
+
*
|
|
797
|
+
* Backs the `aztec_txe_setAuthorizeAllUtilityCallTargets` oracle.
|
|
798
|
+
*/ export const authorizeAllUtilityCallsHook = ()=>Promise.resolve({
|
|
799
|
+
authorized: true
|
|
800
|
+
});
|