@aztec/txe 0.77.1 → 0.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +7 -1
- package/dest/oracle/txe_oracle.d.ts +21 -15
- package/dest/oracle/txe_oracle.d.ts.map +1 -1
- package/dest/oracle/txe_oracle.js +75 -67
- package/dest/txe_service/txe_service.d.ts +3 -2
- package/dest/txe_service/txe_service.d.ts.map +1 -1
- package/dest/txe_service/txe_service.js +14 -28
- package/dest/util/{txe_database.d.ts → txe_account_data_provider.d.ts} +3 -4
- package/dest/util/txe_account_data_provider.d.ts.map +1 -0
- package/dest/util/{txe_database.js → txe_account_data_provider.js} +3 -6
- package/dest/util/txe_public_contract_data_source.js +1 -1
- package/package.json +12 -12
- package/src/index.ts +10 -1
- package/src/oracle/txe_oracle.ts +98 -82
- package/src/txe_service/txe_service.ts +14 -29
- package/src/util/{txe_database.ts → txe_account_data_provider.ts} +3 -6
- package/src/util/txe_public_contract_data_source.ts +1 -1
- package/dest/util/txe_database.d.ts.map +0 -1
package/dest/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AA+LpD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,iEAIhD"}
|
package/dest/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
|
|
2
2
|
import { AztecAddress, Fr, PublicKeys, deriveKeys, getContractInstanceFromDeployParams, loadContractArtifact } from '@aztec/aztec.js';
|
|
3
3
|
import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server';
|
|
4
|
+
import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
5
|
+
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
4
6
|
import { readFile, readdir } from 'fs/promises';
|
|
5
7
|
import { join } from 'path';
|
|
6
8
|
import { z } from 'zod';
|
|
@@ -20,6 +22,7 @@ const TXEForeignCallInputSchema = z.object({
|
|
|
20
22
|
});
|
|
21
23
|
class TXEDispatcher {
|
|
22
24
|
logger;
|
|
25
|
+
protocolContracts;
|
|
23
26
|
constructor(logger){
|
|
24
27
|
this.logger = logger;
|
|
25
28
|
}
|
|
@@ -111,7 +114,10 @@ class TXEDispatcher {
|
|
|
111
114
|
this.logger.debug(`Calling ${functionName} on session ${sessionId}`);
|
|
112
115
|
if (!TXESessions.has(sessionId) && functionName != 'reset') {
|
|
113
116
|
this.logger.debug(`Creating new session ${sessionId}`);
|
|
114
|
-
|
|
117
|
+
if (!this.protocolContracts) {
|
|
118
|
+
this.protocolContracts = await Promise.all(protocolContractNames.map((name)=>new BundledProtocolContractsProvider().getProtocolContractArtifact(name)));
|
|
119
|
+
}
|
|
120
|
+
TXESessions.set(sessionId, await TXEService.init(this.logger, this.protocolContracts));
|
|
115
121
|
}
|
|
116
122
|
switch(functionName){
|
|
117
123
|
case 'reset':
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import { type L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
|
|
4
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
-
import { type
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
5
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
6
|
+
import { KeyStore } from '@aztec/key-store';
|
|
7
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
8
|
+
import type { ProtocolContract } from '@aztec/protocol-contracts';
|
|
9
|
+
import { AddressDataProvider, ContractDataProvider } from '@aztec/pxe/server';
|
|
10
|
+
import { type MessageLoadOracleInputs, type NoteData, type TypedOracle } from '@aztec/simulator/client';
|
|
9
11
|
import { type PublicTxResult } from '@aztec/simulator/server';
|
|
10
12
|
import { type ContractArtifact, type FunctionAbi, FunctionSelector, type NoteSelector } from '@aztec/stdlib/abi';
|
|
11
13
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
@@ -18,14 +20,20 @@ import { IndexedTaggingSecret, type PrivateLog, type PublicLog } from '@aztec/st
|
|
|
18
20
|
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
19
21
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
20
22
|
import { BlockHeader } from '@aztec/stdlib/tx';
|
|
21
|
-
import {
|
|
22
|
-
import
|
|
23
|
+
import { NativeWorldStateService } from '@aztec/world-state/native';
|
|
24
|
+
import { TXEAccountDataProvider } from '../util/txe_account_data_provider.js';
|
|
23
25
|
export declare class TXE implements TypedOracle {
|
|
24
|
-
#private;
|
|
25
26
|
private logger;
|
|
26
|
-
private executionCache;
|
|
27
27
|
private keyStore;
|
|
28
|
-
private
|
|
28
|
+
private contractDataProvider;
|
|
29
|
+
private noteDataProvider;
|
|
30
|
+
private capsuleDataProvider;
|
|
31
|
+
private syncDataProvider;
|
|
32
|
+
private taggingDataProvider;
|
|
33
|
+
private addressDataProvider;
|
|
34
|
+
private authWitnessDataProvider;
|
|
35
|
+
private accountDataProvider;
|
|
36
|
+
private executionCache;
|
|
29
37
|
private contractAddress;
|
|
30
38
|
private nativeWorldStateService;
|
|
31
39
|
private baseFork;
|
|
@@ -36,9 +44,7 @@ export declare class TXE implements TypedOracle {
|
|
|
36
44
|
private isStaticCall;
|
|
37
45
|
private nestedCallReturndata;
|
|
38
46
|
private nestedCallSuccess;
|
|
39
|
-
private
|
|
40
|
-
private pxeDataProvider;
|
|
41
|
-
private viewDataOracle;
|
|
47
|
+
private pxeOracleInterface;
|
|
42
48
|
private publicDataWrites;
|
|
43
49
|
private uniqueNoteHashesFromPublic;
|
|
44
50
|
private siloedNullifiersFromPublic;
|
|
@@ -50,9 +56,8 @@ export declare class TXE implements TypedOracle {
|
|
|
50
56
|
private node;
|
|
51
57
|
private simulationProvider;
|
|
52
58
|
private noteCache;
|
|
53
|
-
debug: LogFn;
|
|
54
59
|
private constructor();
|
|
55
|
-
static create(logger: Logger,
|
|
60
|
+
static create(logger: Logger, store: AztecAsyncKVStore, protocolContracts: ProtocolContract[]): Promise<TXE>;
|
|
56
61
|
getNativeWorldStateService(): NativeWorldStateService;
|
|
57
62
|
getBaseFork(): MerkleTreeWriteOperations;
|
|
58
63
|
getChainId(): Promise<Fr>;
|
|
@@ -66,8 +71,9 @@ export declare class TXE implements TypedOracle {
|
|
|
66
71
|
setContractAddress(contractAddress: AztecAddress): void;
|
|
67
72
|
setBlockNumber(blockNumber: number): void;
|
|
68
73
|
getContractDataProvider(): ContractDataProvider;
|
|
69
|
-
getTXEDatabase(): TXEDatabase;
|
|
70
74
|
getKeyStore(): KeyStore;
|
|
75
|
+
getAccountDataProvider(): TXEAccountDataProvider;
|
|
76
|
+
getAddressDataProvider(): AddressDataProvider;
|
|
71
77
|
addContractInstance(contractInstance: ContractInstanceWithAddress): Promise<void>;
|
|
72
78
|
addContractArtifact(contractClassId: Fr, artifact: ContractArtifact): Promise<void>;
|
|
73
79
|
getPrivateContextInputs(blockNumber: number, sideEffectsCounter?: number, isStaticCall?: boolean): Promise<PrivateContextInputs>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"txe_oracle.d.ts","sourceRoot":"","sources":["../../src/oracle/txe_oracle.ts"],"names":[],"mappings":";;AACA,OAAO,EACL,KAAK,wBAAwB,EAS9B,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO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ASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, PRIVATE_CONTEXT_INPUTS_LENGTH, PUBLIC_DISPATCH_SELECTOR } from '@aztec/constants';
|
|
3
3
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
4
|
-
import { Schnorr, poseidon2Hash } from '@aztec/foundation/crypto';
|
|
4
|
+
import { Aes128, Schnorr, poseidon2Hash } from '@aztec/foundation/crypto';
|
|
5
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
6
|
-
import { applyStringFormatting
|
|
6
|
+
import { applyStringFormatting } from '@aztec/foundation/log';
|
|
7
7
|
import { Timer } from '@aztec/foundation/timer';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { KeyStore } from '@aztec/key-store';
|
|
9
|
+
import { AddressDataProvider, AuthWitnessDataProvider, CapsuleDataProvider, ContractDataProvider, NoteDataProvider, PXEOracleInterface, SyncDataProvider, TaggingDataProvider, enrichPublicSimulationError } from '@aztec/pxe/server';
|
|
10
|
+
import { ExecutionNoteCache, HashedValuesCache, Oracle, WASMSimulator, extractCallStack, extractPrivateCircuitPublicInputs, pickNotes, toACVMWitness, witnessMapToFields } from '@aztec/simulator/client';
|
|
10
11
|
import { createTxForPublicCalls } from '@aztec/simulator/public/fixtures';
|
|
11
12
|
import { ExecutionError, PublicTxSimulator, createSimulationError, resolveAssertionMessageFromError } from '@aztec/simulator/server';
|
|
12
13
|
import { FunctionSelector, countArgumentsSize } from '@aztec/stdlib/abi';
|
|
@@ -17,20 +18,27 @@ import { SimulationError } from '@aztec/stdlib/errors';
|
|
|
17
18
|
import { Gas, GasFees } from '@aztec/stdlib/gas';
|
|
18
19
|
import { computeNoteHashNonce, computePublicDataTreeLeafSlot, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
|
|
19
20
|
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
20
|
-
import {
|
|
21
|
-
import { IndexedTaggingSecret } from '@aztec/stdlib/logs';
|
|
21
|
+
import { deriveKeys } from '@aztec/stdlib/keys';
|
|
22
22
|
import { makeAppendOnlyTreeSnapshot, makeContentCommitment, makeGlobalVariables, makeHeader } from '@aztec/stdlib/testing';
|
|
23
23
|
import { AppendOnlyTreeSnapshot, MerkleTreeId, NullifierMembershipWitness, PublicDataTreeLeaf, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
24
24
|
import { BlockHeader, CallContext, GlobalVariables, PublicExecutionRequest, TxEffect, TxHash } from '@aztec/stdlib/tx';
|
|
25
|
-
import { ForkCheckpoint } from '@aztec/world-state/native';
|
|
25
|
+
import { ForkCheckpoint, NativeWorldStateService } from '@aztec/world-state/native';
|
|
26
26
|
import { TXENode } from '../node/txe_node.js';
|
|
27
|
+
import { TXEAccountDataProvider } from '../util/txe_account_data_provider.js';
|
|
27
28
|
import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
|
|
28
29
|
import { TXEWorldStateDB } from '../util/txe_world_state_db.js';
|
|
29
30
|
export class TXE {
|
|
30
31
|
logger;
|
|
31
|
-
executionCache;
|
|
32
32
|
keyStore;
|
|
33
|
-
|
|
33
|
+
contractDataProvider;
|
|
34
|
+
noteDataProvider;
|
|
35
|
+
capsuleDataProvider;
|
|
36
|
+
syncDataProvider;
|
|
37
|
+
taggingDataProvider;
|
|
38
|
+
addressDataProvider;
|
|
39
|
+
authWitnessDataProvider;
|
|
40
|
+
accountDataProvider;
|
|
41
|
+
executionCache;
|
|
34
42
|
contractAddress;
|
|
35
43
|
nativeWorldStateService;
|
|
36
44
|
baseFork;
|
|
@@ -42,9 +50,7 @@ export class TXE {
|
|
|
42
50
|
// Return/revert data of the latest nested call.
|
|
43
51
|
nestedCallReturndata;
|
|
44
52
|
nestedCallSuccess;
|
|
45
|
-
|
|
46
|
-
pxeDataProvider;
|
|
47
|
-
viewDataOracle;
|
|
53
|
+
pxeOracleInterface;
|
|
48
54
|
publicDataWrites;
|
|
49
55
|
uniqueNoteHashesFromPublic;
|
|
50
56
|
siloedNullifiersFromPublic;
|
|
@@ -56,12 +62,18 @@ export class TXE {
|
|
|
56
62
|
node;
|
|
57
63
|
simulationProvider;
|
|
58
64
|
noteCache;
|
|
59
|
-
|
|
60
|
-
constructor(logger, executionCache, keyStore, txeDatabase, contractAddress, nativeWorldStateService, baseFork){
|
|
65
|
+
constructor(logger, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, authWitnessDataProvider, accountDataProvider, executionCache, contractAddress, nativeWorldStateService, baseFork){
|
|
61
66
|
this.logger = logger;
|
|
62
|
-
this.executionCache = executionCache;
|
|
63
67
|
this.keyStore = keyStore;
|
|
64
|
-
this.
|
|
68
|
+
this.contractDataProvider = contractDataProvider;
|
|
69
|
+
this.noteDataProvider = noteDataProvider;
|
|
70
|
+
this.capsuleDataProvider = capsuleDataProvider;
|
|
71
|
+
this.syncDataProvider = syncDataProvider;
|
|
72
|
+
this.taggingDataProvider = taggingDataProvider;
|
|
73
|
+
this.addressDataProvider = addressDataProvider;
|
|
74
|
+
this.authWitnessDataProvider = authWitnessDataProvider;
|
|
75
|
+
this.accountDataProvider = accountDataProvider;
|
|
76
|
+
this.executionCache = executionCache;
|
|
65
77
|
this.contractAddress = contractAddress;
|
|
66
78
|
this.nativeWorldStateService = nativeWorldStateService;
|
|
67
79
|
this.baseFork = baseFork;
|
|
@@ -81,16 +93,30 @@ export class TXE {
|
|
|
81
93
|
this.CHAIN_ID = 1;
|
|
82
94
|
this.simulationProvider = new WASMSimulator();
|
|
83
95
|
this.noteCache = new ExecutionNoteCache(this.getTxRequestHash());
|
|
84
|
-
this.contractDataProvider = new ContractDataProvider(txeDatabase);
|
|
85
96
|
this.node = new TXENode(this.blockNumber, this.VERSION, this.CHAIN_ID, nativeWorldStateService, baseFork);
|
|
86
97
|
// Default msg_sender (for entrypoints) is now Fr.max_value rather than 0 addr (see #7190 & #7404)
|
|
87
98
|
this.msgSender = AztecAddress.fromField(Fr.MAX_FIELD_VALUE);
|
|
88
|
-
this.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
this.pxeOracleInterface = new PXEOracleInterface(this.node, this.keyStore, this.simulationProvider, this.contractDataProvider, this.noteDataProvider, this.capsuleDataProvider, this.syncDataProvider, this.taggingDataProvider, this.addressDataProvider, this.authWitnessDataProvider, this.logger);
|
|
100
|
+
}
|
|
101
|
+
static async create(logger, store, protocolContracts) {
|
|
102
|
+
const executionCache = new HashedValuesCache();
|
|
103
|
+
const nativeWorldStateService = await NativeWorldStateService.tmp();
|
|
104
|
+
const baseFork = await nativeWorldStateService.fork();
|
|
105
|
+
const addressDataProvider = new AddressDataProvider(store);
|
|
106
|
+
const authWitnessDataProvider = new AuthWitnessDataProvider(store);
|
|
107
|
+
const contractDataProvider = new ContractDataProvider(store);
|
|
108
|
+
const noteDataProvider = await NoteDataProvider.create(store);
|
|
109
|
+
const syncDataProvider = new SyncDataProvider(store);
|
|
110
|
+
const taggingDataProvider = new TaggingDataProvider(store);
|
|
111
|
+
const capsuleDataProvider = new CapsuleDataProvider(store);
|
|
112
|
+
const keyStore = new KeyStore(store);
|
|
113
|
+
const accountDataProvider = new TXEAccountDataProvider(store);
|
|
114
|
+
// Register protocol contracts.
|
|
115
|
+
for (const { contractClass, instance, artifact } of protocolContracts){
|
|
116
|
+
await contractDataProvider.addContractArtifact(contractClass.id, artifact);
|
|
117
|
+
await contractDataProvider.addContractInstance(instance);
|
|
118
|
+
}
|
|
119
|
+
return new TXE(logger, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, authWitnessDataProvider, accountDataProvider, executionCache, await AztecAddress.random(), nativeWorldStateService, baseFork);
|
|
94
120
|
}
|
|
95
121
|
// Utils
|
|
96
122
|
getNativeWorldStateService() {
|
|
@@ -133,17 +159,20 @@ export class TXE {
|
|
|
133
159
|
getContractDataProvider() {
|
|
134
160
|
return this.contractDataProvider;
|
|
135
161
|
}
|
|
136
|
-
getTXEDatabase() {
|
|
137
|
-
return this.txeDatabase;
|
|
138
|
-
}
|
|
139
162
|
getKeyStore() {
|
|
140
163
|
return this.keyStore;
|
|
141
164
|
}
|
|
165
|
+
getAccountDataProvider() {
|
|
166
|
+
return this.accountDataProvider;
|
|
167
|
+
}
|
|
168
|
+
getAddressDataProvider() {
|
|
169
|
+
return this.addressDataProvider;
|
|
170
|
+
}
|
|
142
171
|
async addContractInstance(contractInstance) {
|
|
143
|
-
await this.
|
|
172
|
+
await this.contractDataProvider.addContractInstance(contractInstance);
|
|
144
173
|
}
|
|
145
174
|
async addContractArtifact(contractClassId, artifact) {
|
|
146
|
-
await this.
|
|
175
|
+
await this.contractDataProvider.addContractArtifact(contractClassId, artifact);
|
|
147
176
|
}
|
|
148
177
|
async getPrivateContextInputs(blockNumber, sideEffectsCounter = this.sideEffectCounter, isStaticCall = false) {
|
|
149
178
|
if (blockNumber > this.blockNumber) {
|
|
@@ -169,14 +198,14 @@ export class TXE {
|
|
|
169
198
|
return deriveKeys(secret);
|
|
170
199
|
}
|
|
171
200
|
async addAuthWitness(address, messageHash) {
|
|
172
|
-
const account = await this.
|
|
201
|
+
const account = await this.accountDataProvider.getAccount(address);
|
|
173
202
|
const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
|
|
174
203
|
const schnorr = new Schnorr();
|
|
175
204
|
const signature = await schnorr.constructSignature(messageHash.toBuffer(), privateKey);
|
|
176
205
|
const authWitness = new AuthWitness(messageHash, [
|
|
177
206
|
...signature.toBuffer()
|
|
178
207
|
]);
|
|
179
|
-
return this.
|
|
208
|
+
return this.authWitnessDataProvider.addAuthWitness(authWitness.requestHash, authWitness.witness);
|
|
180
209
|
}
|
|
181
210
|
async addPublicDataWrites(writes) {
|
|
182
211
|
this.publicDataWrites.push(...writes);
|
|
@@ -326,16 +355,16 @@ export class TXE {
|
|
|
326
355
|
return header;
|
|
327
356
|
}
|
|
328
357
|
getCompleteAddress(account) {
|
|
329
|
-
return Promise.resolve(this.
|
|
358
|
+
return Promise.resolve(this.accountDataProvider.getAccount(account));
|
|
330
359
|
}
|
|
331
360
|
getAuthWitness(messageHash) {
|
|
332
|
-
return this.
|
|
361
|
+
return this.pxeOracleInterface.getAuthWitness(messageHash);
|
|
333
362
|
}
|
|
334
363
|
async getNotes(storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status) {
|
|
335
364
|
// Nullified pending notes are already removed from the list.
|
|
336
365
|
const pendingNotes = this.noteCache.getNotes(this.contractAddress, storageSlot);
|
|
337
366
|
const pendingNullifiers = this.noteCache.getNullifiers(this.contractAddress);
|
|
338
|
-
const dbNotes = await this.
|
|
367
|
+
const dbNotes = await this.pxeOracleInterface.getNotes(this.contractAddress, storageSlot, status);
|
|
339
368
|
const dbNotesFiltered = dbNotes.filter((n)=>!pendingNullifiers.has(n.siloedNullifier.value));
|
|
340
369
|
const notes = pickNotes([
|
|
341
370
|
...dbNotesFiltered,
|
|
@@ -649,7 +678,7 @@ export class TXE {
|
|
|
649
678
|
// Poor man's revert handling
|
|
650
679
|
if (!executionResult.revertCode.isOK()) {
|
|
651
680
|
if (executionResult.revertReason && executionResult.revertReason instanceof SimulationError) {
|
|
652
|
-
await enrichPublicSimulationError(executionResult.revertReason, this.contractDataProvider, this.
|
|
681
|
+
await enrichPublicSimulationError(executionResult.revertReason, this.contractDataProvider, this.logger);
|
|
653
682
|
throw new Error(executionResult.revertReason.message);
|
|
654
683
|
} else {
|
|
655
684
|
throw new Error(`Enqueued public function call reverted: ${executionResult.revertReason}`);
|
|
@@ -681,46 +710,24 @@ export class TXE {
|
|
|
681
710
|
});
|
|
682
711
|
}
|
|
683
712
|
async incrementAppTaggingSecretIndexAsSender(sender, recipient) {
|
|
684
|
-
|
|
685
|
-
const [index] = await this.txeDatabase.getTaggingSecretsIndexesAsSender([
|
|
686
|
-
appSecret
|
|
687
|
-
]);
|
|
688
|
-
await this.txeDatabase.setTaggingSecretsIndexesAsSender([
|
|
689
|
-
new IndexedTaggingSecret(appSecret, index + 1)
|
|
690
|
-
]);
|
|
713
|
+
await this.pxeOracleInterface.incrementAppTaggingSecretIndexAsSender(this.contractAddress, sender, recipient);
|
|
691
714
|
}
|
|
692
715
|
async getIndexedTaggingSecretAsSender(sender, recipient) {
|
|
693
|
-
|
|
694
|
-
const [index] = await this.txeDatabase.getTaggingSecretsIndexesAsSender([
|
|
695
|
-
secret
|
|
696
|
-
]);
|
|
697
|
-
return new IndexedTaggingSecret(secret, index);
|
|
698
|
-
}
|
|
699
|
-
async #calculateAppTaggingSecret(contractAddress, sender, recipient) {
|
|
700
|
-
const senderCompleteAddress = await this.getCompleteAddress(sender);
|
|
701
|
-
const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);
|
|
702
|
-
const secretPoint = await computeTaggingSecretPoint(senderCompleteAddress, senderIvsk, recipient);
|
|
703
|
-
// Silo the secret to the app so it can't be used to track other app's notes
|
|
704
|
-
const appSecret = poseidon2Hash([
|
|
705
|
-
secretPoint.x,
|
|
706
|
-
secretPoint.y,
|
|
707
|
-
contractAddress
|
|
708
|
-
]);
|
|
709
|
-
return appSecret;
|
|
716
|
+
return await this.pxeOracleInterface.getIndexedTaggingSecretAsSender(this.contractAddress, sender, recipient);
|
|
710
717
|
}
|
|
711
718
|
async syncNotes() {
|
|
712
|
-
const taggedLogsByRecipient = await this.
|
|
719
|
+
const taggedLogsByRecipient = await this.pxeOracleInterface.syncTaggedLogs(this.contractAddress, await this.getBlockNumber(), undefined);
|
|
713
720
|
for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()){
|
|
714
|
-
await this.
|
|
721
|
+
await this.pxeOracleInterface.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient));
|
|
715
722
|
}
|
|
716
|
-
await this.
|
|
723
|
+
await this.pxeOracleInterface.removeNullifiedNotes(this.contractAddress);
|
|
717
724
|
return Promise.resolve();
|
|
718
725
|
}
|
|
719
726
|
deliverNote(_contractAddress, _storageSlot, _nonce, _content, _noteHash, _nullifier, _txHash, _recipient) {
|
|
720
727
|
throw new Error('deliverNote');
|
|
721
728
|
}
|
|
722
729
|
async getLogByTag(tag) {
|
|
723
|
-
return await this.
|
|
730
|
+
return await this.pxeOracleInterface.getLogByTag(tag);
|
|
724
731
|
}
|
|
725
732
|
// AVM oracles
|
|
726
733
|
async avmOpcodeCall(targetContractAddress, args, isStaticCall) {
|
|
@@ -796,30 +803,31 @@ export class TXE {
|
|
|
796
803
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
797
804
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
798
805
|
}
|
|
799
|
-
return this.
|
|
806
|
+
return this.pxeOracleInterface.storeCapsule(this.contractAddress, slot, capsule);
|
|
800
807
|
}
|
|
801
808
|
loadCapsule(contractAddress, slot) {
|
|
802
809
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
803
810
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
804
811
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
805
812
|
}
|
|
806
|
-
return this.
|
|
813
|
+
return this.pxeOracleInterface.loadCapsule(this.contractAddress, slot);
|
|
807
814
|
}
|
|
808
815
|
deleteCapsule(contractAddress, slot) {
|
|
809
816
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
810
817
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
811
818
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
812
819
|
}
|
|
813
|
-
return this.
|
|
820
|
+
return this.pxeOracleInterface.deleteCapsule(this.contractAddress, slot);
|
|
814
821
|
}
|
|
815
822
|
copyCapsule(contractAddress, srcSlot, dstSlot, numEntries) {
|
|
816
823
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
817
824
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
818
825
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
819
826
|
}
|
|
820
|
-
return this.
|
|
827
|
+
return this.pxeOracleInterface.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries);
|
|
821
828
|
}
|
|
822
829
|
aes128Decrypt(ciphertext, iv, symKey) {
|
|
823
|
-
|
|
830
|
+
const aes128 = new Aes128();
|
|
831
|
+
return aes128.decryptBufferCBC(ciphertext, iv, symKey);
|
|
824
832
|
}
|
|
825
833
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { type ContractInstanceWithAddress } from '@aztec/aztec.js';
|
|
2
2
|
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
-
import {
|
|
3
|
+
import type { ProtocolContract } from '@aztec/protocol-contracts';
|
|
4
|
+
import type { TypedOracle } from '@aztec/simulator/client';
|
|
4
5
|
import { type ContractArtifact } from '@aztec/stdlib/abi';
|
|
5
6
|
import { type ForeignCallArray, type ForeignCallSingle } from '../util/encoding.js';
|
|
6
7
|
export declare class TXEService {
|
|
7
8
|
private logger;
|
|
8
9
|
private typedOracle;
|
|
9
10
|
constructor(logger: Logger, typedOracle: TypedOracle);
|
|
10
|
-
static init(logger: Logger): Promise<TXEService>;
|
|
11
|
+
static init(logger: Logger, protocolContracts: ProtocolContract[]): Promise<TXEService>;
|
|
11
12
|
getPrivateContextInputs(blockNumber: ForeignCallSingle): Promise<{
|
|
12
13
|
values: (string | ForeignCallArray)[];
|
|
13
14
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"txe_service.d.ts","sourceRoot":"","sources":["../../src/txe_service/txe_service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,2BAA2B,EAAM,MAAM,i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AE,aAAa,EAAE,iBAAiB;;;IAQ5F,gBAAgB;;;IAKhB,oBAAoB;;;IAK1B,qBAAqB;;;IAKf,gBAAgB;;;IAKhB,gBAAgB;;;IAKtB,uBAAuB;;;IAKvB,uBAAuB,CAAC,QAAQ,EAAE,iBAAiB,EAAE,QAAQ,EAAE,iBAAiB;;;IAS1E,aAAa,CACjB,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,gBAAgB;;;IAyBlB,mBAAmB,CACvB,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,gBAAgB;;;IAyBxB,oBAAoB;;;CAIrB"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { Fr } from '@aztec/aztec.js';
|
|
2
2
|
import { DEPLOYER_CONTRACT_ADDRESS } from '@aztec/constants';
|
|
3
|
-
import { KeyStore } from '@aztec/key-store';
|
|
4
3
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
5
|
-
import {
|
|
6
|
-
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
7
|
-
import { enrichPublicSimulationError } from '@aztec/pxe';
|
|
8
|
-
import { HashedValuesCache } from '@aztec/simulator/client';
|
|
4
|
+
import { enrichPublicSimulationError } from '@aztec/pxe/server';
|
|
9
5
|
import { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
10
6
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
11
7
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -13,11 +9,9 @@ import { computePartialAddress } from '@aztec/stdlib/contract';
|
|
|
13
9
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
14
10
|
import { computePublicDataTreeLeafSlot, siloNullifier } from '@aztec/stdlib/hash';
|
|
15
11
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
16
|
-
import { NativeWorldStateService } from '@aztec/world-state';
|
|
17
12
|
import { TXE } from '../oracle/txe_oracle.js';
|
|
18
13
|
import { addressFromSingle, arrayToBoundedVec, bufferToU8Array, fromArray, fromSingle, fromUintArray, toArray, toForeignCallResult, toSingle } from '../util/encoding.js';
|
|
19
14
|
import { ExpectedFailureError } from '../util/expected_failure_error.js';
|
|
20
|
-
import { TXEDatabase } from '../util/txe_database.js';
|
|
21
15
|
export class TXEService {
|
|
22
16
|
logger;
|
|
23
17
|
typedOracle;
|
|
@@ -25,22 +19,10 @@ export class TXEService {
|
|
|
25
19
|
this.logger = logger;
|
|
26
20
|
this.typedOracle = typedOracle;
|
|
27
21
|
}
|
|
28
|
-
static async init(logger) {
|
|
29
|
-
const store = await openTmpStore('test');
|
|
30
|
-
const executionCache = new HashedValuesCache();
|
|
31
|
-
const nativeWorldStateService = await NativeWorldStateService.tmp();
|
|
32
|
-
const baseFork = await nativeWorldStateService.fork();
|
|
33
|
-
const keyStore = new KeyStore(store);
|
|
34
|
-
const txeDatabase = new TXEDatabase(store);
|
|
35
|
-
// Register protocol contracts.
|
|
36
|
-
const provider = new BundledProtocolContractsProvider();
|
|
37
|
-
for (const name of protocolContractNames){
|
|
38
|
-
const { contractClass, instance, artifact } = await provider.getProtocolContractArtifact(name);
|
|
39
|
-
await txeDatabase.addContractArtifact(contractClass.id, artifact);
|
|
40
|
-
await txeDatabase.addContractInstance(instance);
|
|
41
|
-
}
|
|
22
|
+
static async init(logger, protocolContracts) {
|
|
42
23
|
logger.debug(`TXE service initialized`);
|
|
43
|
-
const
|
|
24
|
+
const store = await openTmpStore('test');
|
|
25
|
+
const txe = await TXE.create(logger, store, protocolContracts);
|
|
44
26
|
const service = new TXEService(logger, txe);
|
|
45
27
|
await service.advanceBlocksBy(toSingle(new Fr(1n)));
|
|
46
28
|
return service;
|
|
@@ -110,8 +92,10 @@ export class TXEService {
|
|
|
110
92
|
const secretFr = fromSingle(secret);
|
|
111
93
|
// This is a footgun !
|
|
112
94
|
const completeAddress = await keyStore.addAccount(secretFr, secretFr);
|
|
113
|
-
const
|
|
114
|
-
await
|
|
95
|
+
const accountDataProvider = this.typedOracle.getAccountDataProvider();
|
|
96
|
+
await accountDataProvider.setAccount(completeAddress.address, completeAddress);
|
|
97
|
+
const addressDataProvider = this.typedOracle.getAddressDataProvider();
|
|
98
|
+
await addressDataProvider.addCompleteAddress(completeAddress);
|
|
115
99
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
116
100
|
return toForeignCallResult([
|
|
117
101
|
toSingle(completeAddress.address),
|
|
@@ -124,8 +108,10 @@ export class TXEService {
|
|
|
124
108
|
await this.typedOracle.addContractArtifact(instance.currentContractClassId, artifact);
|
|
125
109
|
const keyStore = this.typedOracle.getKeyStore();
|
|
126
110
|
const completeAddress = await keyStore.addAccount(fromSingle(secret), await computePartialAddress(instance));
|
|
127
|
-
const
|
|
128
|
-
await
|
|
111
|
+
const accountDataProvider = this.typedOracle.getAccountDataProvider();
|
|
112
|
+
await accountDataProvider.setAccount(completeAddress.address, completeAddress);
|
|
113
|
+
const addressDataProvider = this.typedOracle.getAddressDataProvider();
|
|
114
|
+
await addressDataProvider.addCompleteAddress(completeAddress);
|
|
129
115
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
130
116
|
return toForeignCallResult([
|
|
131
117
|
toSingle(completeAddress.address),
|
|
@@ -556,7 +542,7 @@ export class TXEService {
|
|
|
556
542
|
// Poor man's revert handling
|
|
557
543
|
if (!result.revertCode.isOK()) {
|
|
558
544
|
if (result.revertReason && result.revertReason instanceof SimulationError) {
|
|
559
|
-
await enrichPublicSimulationError(result.revertReason, this.typedOracle.getContractDataProvider(), this.
|
|
545
|
+
await enrichPublicSimulationError(result.revertReason, this.typedOracle.getContractDataProvider(), this.logger);
|
|
560
546
|
throw new Error(result.revertReason.message);
|
|
561
547
|
} else {
|
|
562
548
|
throw new Error(`Public function call reverted: ${result.revertReason}`);
|
|
@@ -569,7 +555,7 @@ export class TXEService {
|
|
|
569
555
|
// Poor man's revert handling
|
|
570
556
|
if (!result.revertCode.isOK()) {
|
|
571
557
|
if (result.revertReason && result.revertReason instanceof SimulationError) {
|
|
572
|
-
await enrichPublicSimulationError(result.revertReason, this.typedOracle.getContractDataProvider(), this.
|
|
558
|
+
await enrichPublicSimulationError(result.revertReason, this.typedOracle.getContractDataProvider(), this.logger);
|
|
573
559
|
throw new Error(result.revertReason.message);
|
|
574
560
|
} else {
|
|
575
561
|
throw new Error(`Public function call reverted: ${result.revertReason}`);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
|
-
import { KVPxeDatabase } from '@aztec/pxe';
|
|
3
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
3
|
import { CompleteAddress } from '@aztec/stdlib/contract';
|
|
5
|
-
export declare class
|
|
4
|
+
export declare class TXEAccountDataProvider {
|
|
6
5
|
#private;
|
|
7
|
-
constructor(
|
|
6
|
+
constructor(store: AztecAsyncKVStore);
|
|
8
7
|
getAccount(key: AztecAddress): Promise<CompleteAddress>;
|
|
9
8
|
setAccount(key: AztecAddress, value: CompleteAddress): Promise<void>;
|
|
10
9
|
}
|
|
11
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=txe_account_data_provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"txe_account_data_provider.d.ts","sourceRoot":"","sources":["../../src/util/txe_account_data_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,sBAAsB;;gBAGrB,KAAK,EAAE,iBAAiB;IAI9B,UAAU,CAAC,GAAG,EAAE,YAAY;IAQ5B,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe;CAG3D"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { KVPxeDatabase } from '@aztec/pxe';
|
|
2
1
|
import { CompleteAddress } from '@aztec/stdlib/contract';
|
|
3
|
-
export class
|
|
2
|
+
export class TXEAccountDataProvider {
|
|
4
3
|
#accounts;
|
|
5
|
-
constructor(
|
|
6
|
-
|
|
7
|
-
this.#accounts = db.openMap('accounts');
|
|
4
|
+
constructor(store){
|
|
5
|
+
this.#accounts = store.openMap('accounts');
|
|
8
6
|
}
|
|
9
7
|
async getAccount(key) {
|
|
10
8
|
const completeAddress = await this.#accounts.getAsync(key.toString());
|
|
@@ -15,6 +13,5 @@ export class TXEDatabase extends KVPxeDatabase {
|
|
|
15
13
|
}
|
|
16
14
|
async setAccount(key, value) {
|
|
17
15
|
await this.#accounts.set(key.toString(), value.toBuffer());
|
|
18
|
-
await this.addCompleteAddress(value);
|
|
19
16
|
}
|
|
20
17
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PUBLIC_DISPATCH_SELECTOR } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { PrivateFunctionsTree } from '@aztec/pxe';
|
|
3
|
+
import { PrivateFunctionsTree } from '@aztec/pxe/server';
|
|
4
4
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
5
|
import { computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
6
6
|
export class TXEPublicContractDataSource {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/txe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dest/index.js",
|
|
6
6
|
"bin": "./dest/bin/index.js",
|
|
@@ -59,17 +59,17 @@
|
|
|
59
59
|
]
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@aztec/accounts": "0.
|
|
63
|
-
"@aztec/aztec.js": "0.
|
|
64
|
-
"@aztec/constants": "0.
|
|
65
|
-
"@aztec/foundation": "0.
|
|
66
|
-
"@aztec/key-store": "0.
|
|
67
|
-
"@aztec/kv-store": "0.
|
|
68
|
-
"@aztec/protocol-contracts": "0.
|
|
69
|
-
"@aztec/pxe": "0.
|
|
70
|
-
"@aztec/simulator": "0.
|
|
71
|
-
"@aztec/stdlib": "0.
|
|
72
|
-
"@aztec/world-state": "0.
|
|
62
|
+
"@aztec/accounts": "0.78.0",
|
|
63
|
+
"@aztec/aztec.js": "0.78.0",
|
|
64
|
+
"@aztec/constants": "0.78.0",
|
|
65
|
+
"@aztec/foundation": "0.78.0",
|
|
66
|
+
"@aztec/key-store": "0.78.0",
|
|
67
|
+
"@aztec/kv-store": "0.78.0",
|
|
68
|
+
"@aztec/protocol-contracts": "0.78.0",
|
|
69
|
+
"@aztec/pxe": "0.78.0",
|
|
70
|
+
"@aztec/simulator": "0.78.0",
|
|
71
|
+
"@aztec/stdlib": "0.78.0",
|
|
72
|
+
"@aztec/world-state": "0.78.0",
|
|
73
73
|
"zod": "^3.23.8"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
} from '@aztec/aztec.js';
|
|
12
12
|
import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server';
|
|
13
13
|
import type { Logger } from '@aztec/foundation/log';
|
|
14
|
+
import { type ProtocolContract, protocolContractNames } from '@aztec/protocol-contracts';
|
|
15
|
+
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
14
16
|
import type { ApiSchemaFor, ZodFor } from '@aztec/stdlib/schemas';
|
|
15
17
|
|
|
16
18
|
import { readFile, readdir } from 'fs/promises';
|
|
@@ -59,6 +61,8 @@ const TXEForeignCallInputSchema = z.object({
|
|
|
59
61
|
}) satisfies ZodFor<TXEForeignCallInput>;
|
|
60
62
|
|
|
61
63
|
class TXEDispatcher {
|
|
64
|
+
private protocolContracts!: ProtocolContract[];
|
|
65
|
+
|
|
62
66
|
constructor(private logger: Logger) {}
|
|
63
67
|
|
|
64
68
|
async #processDeployInputs({ inputs, root_path: rootPath, package_name: packageName }: TXEForeignCallInput) {
|
|
@@ -162,7 +166,12 @@ class TXEDispatcher {
|
|
|
162
166
|
|
|
163
167
|
if (!TXESessions.has(sessionId) && functionName != 'reset') {
|
|
164
168
|
this.logger.debug(`Creating new session ${sessionId}`);
|
|
165
|
-
|
|
169
|
+
if (!this.protocolContracts) {
|
|
170
|
+
this.protocolContracts = await Promise.all(
|
|
171
|
+
protocolContractNames.map(name => new BundledProtocolContractsProvider().getProtocolContractArtifact(name)),
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
TXESessions.set(sessionId, await TXEService.init(this.logger, this.protocolContracts));
|
|
166
175
|
}
|
|
167
176
|
|
|
168
177
|
switch (functionName) {
|
package/src/oracle/txe_oracle.ts
CHANGED
|
@@ -11,20 +11,31 @@ import {
|
|
|
11
11
|
PUBLIC_DISPATCH_SELECTOR,
|
|
12
12
|
} from '@aztec/constants';
|
|
13
13
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
14
|
-
import { Schnorr, poseidon2Hash } from '@aztec/foundation/crypto';
|
|
14
|
+
import { Aes128, Schnorr, poseidon2Hash } from '@aztec/foundation/crypto';
|
|
15
15
|
import { Fr } from '@aztec/foundation/fields';
|
|
16
|
-
import { type
|
|
16
|
+
import { type Logger, applyStringFormatting } from '@aztec/foundation/log';
|
|
17
17
|
import { Timer } from '@aztec/foundation/timer';
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
18
|
+
import { KeyStore } from '@aztec/key-store';
|
|
19
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
20
|
+
import type { ProtocolContract } from '@aztec/protocol-contracts';
|
|
21
|
+
import {
|
|
22
|
+
AddressDataProvider,
|
|
23
|
+
AuthWitnessDataProvider,
|
|
24
|
+
CapsuleDataProvider,
|
|
25
|
+
ContractDataProvider,
|
|
26
|
+
NoteDataProvider,
|
|
27
|
+
PXEOracleInterface,
|
|
28
|
+
SyncDataProvider,
|
|
29
|
+
TaggingDataProvider,
|
|
30
|
+
enrichPublicSimulationError,
|
|
31
|
+
} from '@aztec/pxe/server';
|
|
20
32
|
import {
|
|
21
33
|
ExecutionNoteCache,
|
|
22
|
-
|
|
34
|
+
HashedValuesCache,
|
|
23
35
|
type MessageLoadOracleInputs,
|
|
24
36
|
type NoteData,
|
|
25
37
|
Oracle,
|
|
26
38
|
type TypedOracle,
|
|
27
|
-
UnconstrainedExecutionOracle,
|
|
28
39
|
WASMSimulator,
|
|
29
40
|
extractCallStack,
|
|
30
41
|
extractPrivateCircuitPublicInputs,
|
|
@@ -62,7 +73,7 @@ import {
|
|
|
62
73
|
} from '@aztec/stdlib/hash';
|
|
63
74
|
import type { MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
64
75
|
import { type KeyValidationRequest, PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
65
|
-
import {
|
|
76
|
+
import { deriveKeys } from '@aztec/stdlib/keys';
|
|
66
77
|
import { ContractClassLog, LogWithTxData } from '@aztec/stdlib/logs';
|
|
67
78
|
import { IndexedTaggingSecret, type PrivateLog, type PublicLog } from '@aztec/stdlib/logs';
|
|
68
79
|
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
@@ -83,10 +94,10 @@ import {
|
|
|
83
94
|
PublicDataWitness,
|
|
84
95
|
} from '@aztec/stdlib/trees';
|
|
85
96
|
import { BlockHeader, CallContext, GlobalVariables, PublicExecutionRequest, TxEffect, TxHash } from '@aztec/stdlib/tx';
|
|
86
|
-
import { ForkCheckpoint,
|
|
97
|
+
import { ForkCheckpoint, NativeWorldStateService } from '@aztec/world-state/native';
|
|
87
98
|
|
|
88
99
|
import { TXENode } from '../node/txe_node.js';
|
|
89
|
-
import
|
|
100
|
+
import { TXEAccountDataProvider } from '../util/txe_account_data_provider.js';
|
|
90
101
|
import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
|
|
91
102
|
import { TXEWorldStateDB } from '../util/txe_world_state_db.js';
|
|
92
103
|
|
|
@@ -100,9 +111,7 @@ export class TXE implements TypedOracle {
|
|
|
100
111
|
private nestedCallReturndata: Fr[] = [];
|
|
101
112
|
private nestedCallSuccess: boolean = false;
|
|
102
113
|
|
|
103
|
-
private
|
|
104
|
-
private pxeDataProvider: PXEDataProvider;
|
|
105
|
-
private viewDataOracle: UnconstrainedExecutionOracle;
|
|
114
|
+
private pxeOracleInterface: PXEOracleInterface;
|
|
106
115
|
|
|
107
116
|
private publicDataWrites: PublicDataWrite[] = [];
|
|
108
117
|
private uniqueNoteHashesFromPublic: Fr[] = [];
|
|
@@ -121,57 +130,77 @@ export class TXE implements TypedOracle {
|
|
|
121
130
|
|
|
122
131
|
private noteCache: ExecutionNoteCache;
|
|
123
132
|
|
|
124
|
-
debug: LogFn;
|
|
125
|
-
|
|
126
133
|
private constructor(
|
|
127
134
|
private logger: Logger,
|
|
128
|
-
private executionCache: HashedValuesCache,
|
|
129
135
|
private keyStore: KeyStore,
|
|
130
|
-
private
|
|
136
|
+
private contractDataProvider: ContractDataProvider,
|
|
137
|
+
private noteDataProvider: NoteDataProvider,
|
|
138
|
+
private capsuleDataProvider: CapsuleDataProvider,
|
|
139
|
+
private syncDataProvider: SyncDataProvider,
|
|
140
|
+
private taggingDataProvider: TaggingDataProvider,
|
|
141
|
+
private addressDataProvider: AddressDataProvider,
|
|
142
|
+
private authWitnessDataProvider: AuthWitnessDataProvider,
|
|
143
|
+
private accountDataProvider: TXEAccountDataProvider,
|
|
144
|
+
private executionCache: HashedValuesCache,
|
|
131
145
|
private contractAddress: AztecAddress,
|
|
132
146
|
private nativeWorldStateService: NativeWorldStateService,
|
|
133
147
|
private baseFork: MerkleTreeWriteOperations,
|
|
134
148
|
) {
|
|
135
149
|
this.noteCache = new ExecutionNoteCache(this.getTxRequestHash());
|
|
136
|
-
this.contractDataProvider = new ContractDataProvider(txeDatabase);
|
|
137
150
|
|
|
138
151
|
this.node = new TXENode(this.blockNumber, this.VERSION, this.CHAIN_ID, nativeWorldStateService, baseFork);
|
|
139
|
-
|
|
140
152
|
// Default msg_sender (for entrypoints) is now Fr.max_value rather than 0 addr (see #7190 & #7404)
|
|
141
153
|
this.msgSender = AztecAddress.fromField(Fr.MAX_FIELD_VALUE);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
keyStore,
|
|
154
|
+
|
|
155
|
+
this.pxeOracleInterface = new PXEOracleInterface(
|
|
145
156
|
this.node,
|
|
157
|
+
this.keyStore,
|
|
146
158
|
this.simulationProvider,
|
|
147
159
|
this.contractDataProvider,
|
|
160
|
+
this.noteDataProvider,
|
|
161
|
+
this.capsuleDataProvider,
|
|
162
|
+
this.syncDataProvider,
|
|
163
|
+
this.taggingDataProvider,
|
|
164
|
+
this.addressDataProvider,
|
|
165
|
+
this.authWitnessDataProvider,
|
|
166
|
+
this.logger,
|
|
148
167
|
);
|
|
168
|
+
}
|
|
149
169
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
this.pxeDataProvider, // note: PXEDataProvider implements ExecutionDataProvider
|
|
155
|
-
/* log, */
|
|
156
|
-
/* scopes, */
|
|
157
|
-
);
|
|
170
|
+
static async create(logger: Logger, store: AztecAsyncKVStore, protocolContracts: ProtocolContract[]) {
|
|
171
|
+
const executionCache = new HashedValuesCache();
|
|
172
|
+
const nativeWorldStateService = await NativeWorldStateService.tmp();
|
|
173
|
+
const baseFork = await nativeWorldStateService.fork();
|
|
158
174
|
|
|
159
|
-
|
|
160
|
-
|
|
175
|
+
const addressDataProvider = new AddressDataProvider(store);
|
|
176
|
+
const authWitnessDataProvider = new AuthWitnessDataProvider(store);
|
|
177
|
+
const contractDataProvider = new ContractDataProvider(store);
|
|
178
|
+
const noteDataProvider = await NoteDataProvider.create(store);
|
|
179
|
+
const syncDataProvider = new SyncDataProvider(store);
|
|
180
|
+
const taggingDataProvider = new TaggingDataProvider(store);
|
|
181
|
+
const capsuleDataProvider = new CapsuleDataProvider(store);
|
|
182
|
+
const keyStore = new KeyStore(store);
|
|
183
|
+
|
|
184
|
+
const accountDataProvider = new TXEAccountDataProvider(store);
|
|
185
|
+
|
|
186
|
+
// Register protocol contracts.
|
|
187
|
+
for (const { contractClass, instance, artifact } of protocolContracts) {
|
|
188
|
+
await contractDataProvider.addContractArtifact(contractClass.id, artifact);
|
|
189
|
+
await contractDataProvider.addContractInstance(instance);
|
|
190
|
+
}
|
|
161
191
|
|
|
162
|
-
static async create(
|
|
163
|
-
logger: Logger,
|
|
164
|
-
executionCache: HashedValuesCache,
|
|
165
|
-
keyStore: KeyStore,
|
|
166
|
-
txeDatabase: TXEDatabase,
|
|
167
|
-
nativeWorldStateService: NativeWorldStateService,
|
|
168
|
-
baseFork: MerkleTreeWriteOperations,
|
|
169
|
-
) {
|
|
170
192
|
return new TXE(
|
|
171
193
|
logger,
|
|
172
|
-
executionCache,
|
|
173
194
|
keyStore,
|
|
174
|
-
|
|
195
|
+
contractDataProvider,
|
|
196
|
+
noteDataProvider,
|
|
197
|
+
capsuleDataProvider,
|
|
198
|
+
syncDataProvider,
|
|
199
|
+
taggingDataProvider,
|
|
200
|
+
addressDataProvider,
|
|
201
|
+
authWitnessDataProvider,
|
|
202
|
+
accountDataProvider,
|
|
203
|
+
executionCache,
|
|
175
204
|
await AztecAddress.random(),
|
|
176
205
|
nativeWorldStateService,
|
|
177
206
|
baseFork,
|
|
@@ -233,20 +262,24 @@ export class TXE implements TypedOracle {
|
|
|
233
262
|
return this.contractDataProvider;
|
|
234
263
|
}
|
|
235
264
|
|
|
236
|
-
getTXEDatabase() {
|
|
237
|
-
return this.txeDatabase;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
265
|
getKeyStore() {
|
|
241
266
|
return this.keyStore;
|
|
242
267
|
}
|
|
243
268
|
|
|
269
|
+
getAccountDataProvider() {
|
|
270
|
+
return this.accountDataProvider;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
getAddressDataProvider() {
|
|
274
|
+
return this.addressDataProvider;
|
|
275
|
+
}
|
|
276
|
+
|
|
244
277
|
async addContractInstance(contractInstance: ContractInstanceWithAddress) {
|
|
245
|
-
await this.
|
|
278
|
+
await this.contractDataProvider.addContractInstance(contractInstance);
|
|
246
279
|
}
|
|
247
280
|
|
|
248
281
|
async addContractArtifact(contractClassId: Fr, artifact: ContractArtifact) {
|
|
249
|
-
await this.
|
|
282
|
+
await this.contractDataProvider.addContractArtifact(contractClassId, artifact);
|
|
250
283
|
}
|
|
251
284
|
|
|
252
285
|
async getPrivateContextInputs(
|
|
@@ -287,12 +320,12 @@ export class TXE implements TypedOracle {
|
|
|
287
320
|
}
|
|
288
321
|
|
|
289
322
|
async addAuthWitness(address: AztecAddress, messageHash: Fr) {
|
|
290
|
-
const account = await this.
|
|
323
|
+
const account = await this.accountDataProvider.getAccount(address);
|
|
291
324
|
const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
|
|
292
325
|
const schnorr = new Schnorr();
|
|
293
326
|
const signature = await schnorr.constructSignature(messageHash.toBuffer(), privateKey);
|
|
294
327
|
const authWitness = new AuthWitness(messageHash, [...signature.toBuffer()]);
|
|
295
|
-
return this.
|
|
328
|
+
return this.authWitnessDataProvider.addAuthWitness(authWitness.requestHash, authWitness.witness);
|
|
296
329
|
}
|
|
297
330
|
|
|
298
331
|
async addPublicDataWrites(writes: PublicDataWrite[]) {
|
|
@@ -501,11 +534,11 @@ export class TXE implements TypedOracle {
|
|
|
501
534
|
}
|
|
502
535
|
|
|
503
536
|
getCompleteAddress(account: AztecAddress) {
|
|
504
|
-
return Promise.resolve(this.
|
|
537
|
+
return Promise.resolve(this.accountDataProvider.getAccount(account));
|
|
505
538
|
}
|
|
506
539
|
|
|
507
540
|
getAuthWitness(messageHash: Fr) {
|
|
508
|
-
return this.
|
|
541
|
+
return this.pxeOracleInterface.getAuthWitness(messageHash);
|
|
509
542
|
}
|
|
510
543
|
|
|
511
544
|
async getNotes(
|
|
@@ -528,7 +561,7 @@ export class TXE implements TypedOracle {
|
|
|
528
561
|
const pendingNotes = this.noteCache.getNotes(this.contractAddress, storageSlot);
|
|
529
562
|
|
|
530
563
|
const pendingNullifiers = this.noteCache.getNullifiers(this.contractAddress);
|
|
531
|
-
const dbNotes = await this.
|
|
564
|
+
const dbNotes = await this.pxeOracleInterface.getNotes(this.contractAddress, storageSlot, status);
|
|
532
565
|
const dbNotesFiltered = dbNotes.filter(n => !pendingNullifiers.has((n.siloedNullifier as Fr).value));
|
|
533
566
|
|
|
534
567
|
const notes = pickNotes<NoteData>([...dbNotesFiltered, ...pendingNotes], {
|
|
@@ -986,12 +1019,7 @@ export class TXE implements TypedOracle {
|
|
|
986
1019
|
// Poor man's revert handling
|
|
987
1020
|
if (!executionResult.revertCode.isOK()) {
|
|
988
1021
|
if (executionResult.revertReason && executionResult.revertReason instanceof SimulationError) {
|
|
989
|
-
await enrichPublicSimulationError(
|
|
990
|
-
executionResult.revertReason,
|
|
991
|
-
this.contractDataProvider,
|
|
992
|
-
this.txeDatabase,
|
|
993
|
-
this.logger,
|
|
994
|
-
);
|
|
1022
|
+
await enrichPublicSimulationError(executionResult.revertReason, this.contractDataProvider, this.logger);
|
|
995
1023
|
throw new Error(executionResult.revertReason.message);
|
|
996
1024
|
} else {
|
|
997
1025
|
throw new Error(`Enqueued public function call reverted: ${executionResult.revertReason}`);
|
|
@@ -1043,38 +1071,25 @@ export class TXE implements TypedOracle {
|
|
|
1043
1071
|
}
|
|
1044
1072
|
|
|
1045
1073
|
async incrementAppTaggingSecretIndexAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<void> {
|
|
1046
|
-
|
|
1047
|
-
const [index] = await this.txeDatabase.getTaggingSecretsIndexesAsSender([appSecret]);
|
|
1048
|
-
await this.txeDatabase.setTaggingSecretsIndexesAsSender([new IndexedTaggingSecret(appSecret, index + 1)]);
|
|
1074
|
+
await this.pxeOracleInterface.incrementAppTaggingSecretIndexAsSender(this.contractAddress, sender, recipient);
|
|
1049
1075
|
}
|
|
1050
1076
|
|
|
1051
1077
|
async getIndexedTaggingSecretAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<IndexedTaggingSecret> {
|
|
1052
|
-
|
|
1053
|
-
const [index] = await this.txeDatabase.getTaggingSecretsIndexesAsSender([secret]);
|
|
1054
|
-
return new IndexedTaggingSecret(secret, index);
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
async #calculateAppTaggingSecret(contractAddress: AztecAddress, sender: AztecAddress, recipient: AztecAddress) {
|
|
1058
|
-
const senderCompleteAddress = await this.getCompleteAddress(sender);
|
|
1059
|
-
const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);
|
|
1060
|
-
const secretPoint = await computeTaggingSecretPoint(senderCompleteAddress, senderIvsk, recipient);
|
|
1061
|
-
// Silo the secret to the app so it can't be used to track other app's notes
|
|
1062
|
-
const appSecret = poseidon2Hash([secretPoint.x, secretPoint.y, contractAddress]);
|
|
1063
|
-
return appSecret;
|
|
1078
|
+
return await this.pxeOracleInterface.getIndexedTaggingSecretAsSender(this.contractAddress, sender, recipient);
|
|
1064
1079
|
}
|
|
1065
1080
|
|
|
1066
1081
|
async syncNotes() {
|
|
1067
|
-
const taggedLogsByRecipient = await this.
|
|
1082
|
+
const taggedLogsByRecipient = await this.pxeOracleInterface.syncTaggedLogs(
|
|
1068
1083
|
this.contractAddress,
|
|
1069
1084
|
await this.getBlockNumber(),
|
|
1070
1085
|
undefined,
|
|
1071
1086
|
);
|
|
1072
1087
|
|
|
1073
1088
|
for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) {
|
|
1074
|
-
await this.
|
|
1089
|
+
await this.pxeOracleInterface.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient));
|
|
1075
1090
|
}
|
|
1076
1091
|
|
|
1077
|
-
await this.
|
|
1092
|
+
await this.pxeOracleInterface.removeNullifiedNotes(this.contractAddress);
|
|
1078
1093
|
|
|
1079
1094
|
return Promise.resolve();
|
|
1080
1095
|
}
|
|
@@ -1093,7 +1108,7 @@ export class TXE implements TypedOracle {
|
|
|
1093
1108
|
}
|
|
1094
1109
|
|
|
1095
1110
|
async getLogByTag(tag: Fr): Promise<LogWithTxData | null> {
|
|
1096
|
-
return await this.
|
|
1111
|
+
return await this.pxeOracleInterface.getLogByTag(tag);
|
|
1097
1112
|
}
|
|
1098
1113
|
|
|
1099
1114
|
// AVM oracles
|
|
@@ -1192,7 +1207,7 @@ export class TXE implements TypedOracle {
|
|
|
1192
1207
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
1193
1208
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
1194
1209
|
}
|
|
1195
|
-
return this.
|
|
1210
|
+
return this.pxeOracleInterface.storeCapsule(this.contractAddress, slot, capsule);
|
|
1196
1211
|
}
|
|
1197
1212
|
|
|
1198
1213
|
loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
|
|
@@ -1200,7 +1215,7 @@ export class TXE implements TypedOracle {
|
|
|
1200
1215
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
1201
1216
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
1202
1217
|
}
|
|
1203
|
-
return this.
|
|
1218
|
+
return this.pxeOracleInterface.loadCapsule(this.contractAddress, slot);
|
|
1204
1219
|
}
|
|
1205
1220
|
|
|
1206
1221
|
deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
|
|
@@ -1208,7 +1223,7 @@ export class TXE implements TypedOracle {
|
|
|
1208
1223
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
1209
1224
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
1210
1225
|
}
|
|
1211
|
-
return this.
|
|
1226
|
+
return this.pxeOracleInterface.deleteCapsule(this.contractAddress, slot);
|
|
1212
1227
|
}
|
|
1213
1228
|
|
|
1214
1229
|
copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
|
|
@@ -1216,10 +1231,11 @@ export class TXE implements TypedOracle {
|
|
|
1216
1231
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
1217
1232
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
1218
1233
|
}
|
|
1219
|
-
return this.
|
|
1234
|
+
return this.pxeOracleInterface.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries);
|
|
1220
1235
|
}
|
|
1221
1236
|
|
|
1222
1237
|
aes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer> {
|
|
1223
|
-
|
|
1238
|
+
const aes128 = new Aes128();
|
|
1239
|
+
return aes128.decryptBufferCBC(ciphertext, iv, symKey);
|
|
1224
1240
|
}
|
|
1225
1241
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { type ContractInstanceWithAddress, Fr } from '@aztec/aztec.js';
|
|
2
2
|
import { DEPLOYER_CONTRACT_ADDRESS } from '@aztec/constants';
|
|
3
3
|
import type { Logger } from '@aztec/foundation/log';
|
|
4
|
-
import { KeyStore } from '@aztec/key-store';
|
|
5
4
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { HashedValuesCache, type TypedOracle } from '@aztec/simulator/client';
|
|
5
|
+
import type { ProtocolContract } from '@aztec/protocol-contracts';
|
|
6
|
+
import { enrichPublicSimulationError } from '@aztec/pxe/server';
|
|
7
|
+
import type { TypedOracle } from '@aztec/simulator/client';
|
|
10
8
|
import { type ContractArtifact, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
11
9
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
12
10
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -14,7 +12,6 @@ import { computePartialAddress } from '@aztec/stdlib/contract';
|
|
|
14
12
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
15
13
|
import { computePublicDataTreeLeafSlot, siloNullifier } from '@aztec/stdlib/hash';
|
|
16
14
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
17
|
-
import { NativeWorldStateService } from '@aztec/world-state';
|
|
18
15
|
|
|
19
16
|
import { TXE } from '../oracle/txe_oracle.js';
|
|
20
17
|
import {
|
|
@@ -31,28 +28,14 @@ import {
|
|
|
31
28
|
toSingle,
|
|
32
29
|
} from '../util/encoding.js';
|
|
33
30
|
import { ExpectedFailureError } from '../util/expected_failure_error.js';
|
|
34
|
-
import { TXEDatabase } from '../util/txe_database.js';
|
|
35
31
|
|
|
36
32
|
export class TXEService {
|
|
37
33
|
constructor(private logger: Logger, private typedOracle: TypedOracle) {}
|
|
38
34
|
|
|
39
|
-
static async init(logger: Logger) {
|
|
40
|
-
const store = await openTmpStore('test');
|
|
41
|
-
const executionCache = new HashedValuesCache();
|
|
42
|
-
const nativeWorldStateService = await NativeWorldStateService.tmp();
|
|
43
|
-
const baseFork = await nativeWorldStateService.fork();
|
|
44
|
-
|
|
45
|
-
const keyStore = new KeyStore(store);
|
|
46
|
-
const txeDatabase = new TXEDatabase(store);
|
|
47
|
-
// Register protocol contracts.
|
|
48
|
-
const provider = new BundledProtocolContractsProvider();
|
|
49
|
-
for (const name of protocolContractNames) {
|
|
50
|
-
const { contractClass, instance, artifact } = await provider.getProtocolContractArtifact(name);
|
|
51
|
-
await txeDatabase.addContractArtifact(contractClass.id, artifact);
|
|
52
|
-
await txeDatabase.addContractInstance(instance);
|
|
53
|
-
}
|
|
35
|
+
static async init(logger: Logger, protocolContracts: ProtocolContract[]) {
|
|
54
36
|
logger.debug(`TXE service initialized`);
|
|
55
|
-
const
|
|
37
|
+
const store = await openTmpStore('test');
|
|
38
|
+
const txe = await TXE.create(logger, store, protocolContracts);
|
|
56
39
|
const service = new TXEService(logger, txe);
|
|
57
40
|
await service.advanceBlocksBy(toSingle(new Fr(1n)));
|
|
58
41
|
return service;
|
|
@@ -140,8 +123,10 @@ export class TXEService {
|
|
|
140
123
|
const secretFr = fromSingle(secret);
|
|
141
124
|
// This is a footgun !
|
|
142
125
|
const completeAddress = await keyStore.addAccount(secretFr, secretFr);
|
|
143
|
-
const
|
|
144
|
-
await
|
|
126
|
+
const accountDataProvider = (this.typedOracle as TXE).getAccountDataProvider();
|
|
127
|
+
await accountDataProvider.setAccount(completeAddress.address, completeAddress);
|
|
128
|
+
const addressDataProvider = (this.typedOracle as TXE).getAddressDataProvider();
|
|
129
|
+
await addressDataProvider.addCompleteAddress(completeAddress);
|
|
145
130
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
146
131
|
return toForeignCallResult([
|
|
147
132
|
toSingle(completeAddress.address),
|
|
@@ -156,8 +141,10 @@ export class TXEService {
|
|
|
156
141
|
|
|
157
142
|
const keyStore = (this.typedOracle as TXE).getKeyStore();
|
|
158
143
|
const completeAddress = await keyStore.addAccount(fromSingle(secret), await computePartialAddress(instance));
|
|
159
|
-
const
|
|
160
|
-
await
|
|
144
|
+
const accountDataProvider = (this.typedOracle as TXE).getAccountDataProvider();
|
|
145
|
+
await accountDataProvider.setAccount(completeAddress.address, completeAddress);
|
|
146
|
+
const addressDataProvider = (this.typedOracle as TXE).getAddressDataProvider();
|
|
147
|
+
await addressDataProvider.addCompleteAddress(completeAddress);
|
|
161
148
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
162
149
|
return toForeignCallResult([
|
|
163
150
|
toSingle(completeAddress.address),
|
|
@@ -715,7 +702,6 @@ export class TXEService {
|
|
|
715
702
|
await enrichPublicSimulationError(
|
|
716
703
|
result.revertReason,
|
|
717
704
|
(this.typedOracle as TXE).getContractDataProvider(),
|
|
718
|
-
(this.typedOracle as TXE).getTXEDatabase(),
|
|
719
705
|
this.logger,
|
|
720
706
|
);
|
|
721
707
|
throw new Error(result.revertReason.message);
|
|
@@ -745,7 +731,6 @@ export class TXEService {
|
|
|
745
731
|
await enrichPublicSimulationError(
|
|
746
732
|
result.revertReason,
|
|
747
733
|
(this.typedOracle as TXE).getContractDataProvider(),
|
|
748
|
-
(this.typedOracle as TXE).getTXEDatabase(),
|
|
749
734
|
this.logger,
|
|
750
735
|
);
|
|
751
736
|
throw new Error(result.revertReason.message);
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
2
|
-
import { KVPxeDatabase } from '@aztec/pxe';
|
|
3
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
3
|
import { CompleteAddress } from '@aztec/stdlib/contract';
|
|
5
4
|
|
|
6
|
-
export class
|
|
5
|
+
export class TXEAccountDataProvider {
|
|
7
6
|
#accounts: AztecAsyncMap<string, Buffer>;
|
|
8
7
|
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
11
|
-
this.#accounts = db.openMap('accounts');
|
|
8
|
+
constructor(store: AztecAsyncKVStore) {
|
|
9
|
+
this.#accounts = store.openMap('accounts');
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
async getAccount(key: AztecAddress) {
|
|
@@ -21,6 +19,5 @@ export class TXEDatabase extends KVPxeDatabase {
|
|
|
21
19
|
|
|
22
20
|
async setAccount(key: AztecAddress, value: CompleteAddress) {
|
|
23
21
|
await this.#accounts.set(key.toString(), value.toBuffer());
|
|
24
|
-
await this.addCompleteAddress(value);
|
|
25
22
|
}
|
|
26
23
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PUBLIC_DISPATCH_SELECTOR } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { PrivateFunctionsTree } from '@aztec/pxe';
|
|
3
|
+
import { PrivateFunctionsTree } from '@aztec/pxe/server';
|
|
4
4
|
import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
6
|
import {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"txe_database.d.ts","sourceRoot":"","sources":["../../src/util/txe_database.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,WAAY,SAAQ,aAAa;;gBAGhC,EAAE,EAAE,iBAAiB;IAK3B,UAAU,CAAC,GAAG,EAAE,YAAY;IAQ5B,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe;CAI3D"}
|