@aztec/txe 0.0.1-commit.4eabbdb → 0.0.1-commit.5358163d3
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 +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +82 -50
- package/dest/oracle/interfaces.d.ts +4 -3
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.d.ts +6 -7
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +25 -15
- package/dest/rpc_translator.d.ts +1 -1
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +15 -3
- package/dest/state_machine/dummy_p2p_client.d.ts +2 -2
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +1 -1
- package/dest/txe_session.d.ts +9 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +12 -12
- package/dest/util/txe_public_contract_data_source.d.ts +2 -3
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +5 -22
- package/package.json +15 -15
- package/src/index.ts +83 -49
- package/src/oracle/interfaces.ts +5 -0
- package/src/oracle/txe_oracle_top_level_context.ts +38 -14
- package/src/rpc_translator.ts +16 -1
- package/src/state_machine/dummy_p2p_client.ts +1 -1
- package/src/txe_session.ts +19 -15
- package/src/util/txe_public_contract_data_source.ts +10 -36
- package/dest/util/txe_contract_store.d.ts +0 -12
- package/dest/util/txe_contract_store.d.ts.map +0 -1
- package/dest/util/txe_contract_store.js +0 -22
- package/src/util/txe_contract_store.ts +0 -36
|
@@ -16,6 +16,7 @@ import type { AccessScopes } from '@aztec/pxe/client/lazy';
|
|
|
16
16
|
import {
|
|
17
17
|
AddressStore,
|
|
18
18
|
CapsuleStore,
|
|
19
|
+
type ContractStore,
|
|
19
20
|
NoteStore,
|
|
20
21
|
ORACLE_VERSION,
|
|
21
22
|
PrivateEventStore,
|
|
@@ -84,7 +85,6 @@ import { ForkCheckpoint } from '@aztec/world-state';
|
|
|
84
85
|
import { DEFAULT_ADDRESS } from '../constants.js';
|
|
85
86
|
import type { TXEStateMachine } from '../state_machine/index.js';
|
|
86
87
|
import type { TXEAccountStore } from '../util/txe_account_store.js';
|
|
87
|
-
import type { TXEContractStore } from '../util/txe_contract_store.js';
|
|
88
88
|
import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
|
|
89
89
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
|
|
90
90
|
import type { ITxeExecutionOracle } from './interfaces.js';
|
|
@@ -97,7 +97,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
97
97
|
|
|
98
98
|
constructor(
|
|
99
99
|
private stateMachine: TXEStateMachine,
|
|
100
|
-
private contractStore:
|
|
100
|
+
private contractStore: ContractStore,
|
|
101
101
|
private noteStore: NoteStore,
|
|
102
102
|
private keyStore: KeyStore,
|
|
103
103
|
private addressStore: AddressStore,
|
|
@@ -107,7 +107,6 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
107
107
|
private senderAddressBookStore: SenderAddressBookStore,
|
|
108
108
|
private capsuleStore: CapsuleStore,
|
|
109
109
|
private privateEventStore: PrivateEventStore,
|
|
110
|
-
private jobId: string,
|
|
111
110
|
private nextBlockTimestamp: bigint,
|
|
112
111
|
private version: Fr,
|
|
113
112
|
private chainId: Fr,
|
|
@@ -172,6 +171,25 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
172
171
|
return { txHash: txEffects.txHash, noteHashes: txEffects.noteHashes, nullifiers: txEffects.nullifiers };
|
|
173
172
|
}
|
|
174
173
|
|
|
174
|
+
async syncContractNonOracleMethod(contractAddress: AztecAddress, scope: AztecAddress, jobId: string) {
|
|
175
|
+
if (contractAddress.equals(DEFAULT_ADDRESS)) {
|
|
176
|
+
this.logger.debug(`Skipping sync in txeGetPrivateEvents because the events correspond to the default address.`);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
181
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(
|
|
182
|
+
contractAddress,
|
|
183
|
+
null,
|
|
184
|
+
async (call, execScopes) => {
|
|
185
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
186
|
+
},
|
|
187
|
+
blockHeader,
|
|
188
|
+
jobId,
|
|
189
|
+
[scope],
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
175
193
|
async txeGetPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress) {
|
|
176
194
|
return (
|
|
177
195
|
await this.privateEventStore.getPrivateEvents(selector, {
|
|
@@ -211,7 +229,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
211
229
|
await this.txeAddAccount(artifact, instance, secret);
|
|
212
230
|
} else {
|
|
213
231
|
await this.contractStore.addContractInstance(instance);
|
|
214
|
-
await this.contractStore.addContractArtifact(
|
|
232
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
215
233
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
216
234
|
}
|
|
217
235
|
}
|
|
@@ -221,7 +239,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
221
239
|
|
|
222
240
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
223
241
|
await this.contractStore.addContractInstance(instance);
|
|
224
|
-
await this.contractStore.addContractArtifact(
|
|
242
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
225
243
|
|
|
226
244
|
const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
|
|
227
245
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
@@ -285,6 +303,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
285
303
|
args: Fr[],
|
|
286
304
|
argsHash: Fr = Fr.zero(),
|
|
287
305
|
isStaticCall: boolean = false,
|
|
306
|
+
jobId: string,
|
|
288
307
|
) {
|
|
289
308
|
this.logger.verbose(
|
|
290
309
|
`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
@@ -304,7 +323,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
304
323
|
|
|
305
324
|
// Sync notes before executing private function to discover notes from previous transactions
|
|
306
325
|
const utilityExecutor = async (call: FunctionCall, execScopes: AccessScopes) => {
|
|
307
|
-
await this.executeUtilityCall(call, execScopes);
|
|
326
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
308
327
|
};
|
|
309
328
|
|
|
310
329
|
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
@@ -313,7 +332,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
313
332
|
functionSelector,
|
|
314
333
|
utilityExecutor,
|
|
315
334
|
blockHeader,
|
|
316
|
-
|
|
335
|
+
jobId,
|
|
317
336
|
effectiveScopes,
|
|
318
337
|
);
|
|
319
338
|
|
|
@@ -360,7 +379,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
360
379
|
capsuleStore: this.capsuleStore,
|
|
361
380
|
privateEventStore: this.privateEventStore,
|
|
362
381
|
contractSyncService: this.stateMachine.contractSyncService,
|
|
363
|
-
jobId
|
|
382
|
+
jobId,
|
|
364
383
|
totalPublicCalldataCount: 0,
|
|
365
384
|
sideEffectCounter: minRevertibleSideEffectCounter,
|
|
366
385
|
scopes: effectiveScopes,
|
|
@@ -659,7 +678,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
659
678
|
return returnValues ?? [];
|
|
660
679
|
}
|
|
661
680
|
|
|
662
|
-
async txeExecuteUtilityFunction(
|
|
681
|
+
async txeExecuteUtilityFunction(
|
|
682
|
+
targetContractAddress: AztecAddress,
|
|
683
|
+
functionSelector: FunctionSelector,
|
|
684
|
+
args: Fr[],
|
|
685
|
+
jobId: string,
|
|
686
|
+
) {
|
|
663
687
|
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
664
688
|
if (!artifact) {
|
|
665
689
|
throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
|
|
@@ -671,10 +695,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
671
695
|
targetContractAddress,
|
|
672
696
|
functionSelector,
|
|
673
697
|
async (call, execScopes) => {
|
|
674
|
-
await this.executeUtilityCall(call, execScopes);
|
|
698
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
675
699
|
},
|
|
676
700
|
blockHeader,
|
|
677
|
-
|
|
701
|
+
jobId,
|
|
678
702
|
'ALL_SCOPES',
|
|
679
703
|
);
|
|
680
704
|
|
|
@@ -689,10 +713,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
689
713
|
returnTypes: [],
|
|
690
714
|
});
|
|
691
715
|
|
|
692
|
-
return this.executeUtilityCall(call, 'ALL_SCOPES');
|
|
716
|
+
return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
|
|
693
717
|
}
|
|
694
718
|
|
|
695
|
-
private async executeUtilityCall(call: FunctionCall, scopes: AccessScopes): Promise<Fr[]> {
|
|
719
|
+
private async executeUtilityCall(call: FunctionCall, scopes: AccessScopes, jobId: string): Promise<Fr[]> {
|
|
696
720
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
697
721
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
698
722
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
@@ -719,7 +743,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
719
743
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
720
744
|
capsuleStore: this.capsuleStore,
|
|
721
745
|
privateEventStore: this.privateEventStore,
|
|
722
|
-
jobId
|
|
746
|
+
jobId,
|
|
723
747
|
scopes,
|
|
724
748
|
});
|
|
725
749
|
const acirExecutionResult = await new WASMSimulator()
|
package/src/rpc_translator.ts
CHANGED
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
toSingle,
|
|
31
31
|
} from './util/encoding.js';
|
|
32
32
|
|
|
33
|
-
const MAX_EVENT_LEN =
|
|
33
|
+
const MAX_EVENT_LEN = 10; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN
|
|
34
34
|
const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
|
|
35
35
|
|
|
36
36
|
export class UnavailableOracleError extends Error {
|
|
@@ -285,6 +285,13 @@ export class RPCTranslator {
|
|
|
285
285
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
286
286
|
const scope = addressFromSingle(foreignScope);
|
|
287
287
|
|
|
288
|
+
// TODO(F-335): Avoid doing the following 2 calls here.
|
|
289
|
+
{
|
|
290
|
+
await this.handlerAsTxe().syncContractNonOracleMethod(contractAddress, scope, this.stateHandler.getCurrentJob());
|
|
291
|
+
// We cycle job to commit the stores after the contract sync.
|
|
292
|
+
await this.stateHandler.cycleJob();
|
|
293
|
+
}
|
|
294
|
+
|
|
288
295
|
const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
|
|
289
296
|
|
|
290
297
|
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
@@ -1038,8 +1045,11 @@ export class RPCTranslator {
|
|
|
1038
1045
|
args,
|
|
1039
1046
|
argsHash,
|
|
1040
1047
|
isStaticCall,
|
|
1048
|
+
this.stateHandler.getCurrentJob(),
|
|
1041
1049
|
);
|
|
1042
1050
|
|
|
1051
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1052
|
+
await this.stateHandler.cycleJob();
|
|
1043
1053
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1044
1054
|
}
|
|
1045
1055
|
|
|
@@ -1056,8 +1066,11 @@ export class RPCTranslator {
|
|
|
1056
1066
|
targetContractAddress,
|
|
1057
1067
|
functionSelector,
|
|
1058
1068
|
args,
|
|
1069
|
+
this.stateHandler.getCurrentJob(),
|
|
1059
1070
|
);
|
|
1060
1071
|
|
|
1072
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1073
|
+
await this.stateHandler.cycleJob();
|
|
1061
1074
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1062
1075
|
}
|
|
1063
1076
|
|
|
@@ -1074,6 +1087,8 @@ export class RPCTranslator {
|
|
|
1074
1087
|
|
|
1075
1088
|
const returnValues = await this.handlerAsTxe().txePublicCallNewFlow(from, address, calldata, isStaticCall);
|
|
1076
1089
|
|
|
1090
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1091
|
+
await this.stateHandler.cycleJob();
|
|
1077
1092
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1078
1093
|
}
|
|
1079
1094
|
|
|
@@ -21,7 +21,7 @@ import type { BlockProposal, CheckpointAttestation, CheckpointProposal, TopicTyp
|
|
|
21
21
|
import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
22
22
|
|
|
23
23
|
export class DummyP2P implements P2P {
|
|
24
|
-
public
|
|
24
|
+
public validateTxsReceivedInBlockProposal(_txs: Tx[]): Promise<void> {
|
|
25
25
|
return Promise.resolve();
|
|
26
26
|
}
|
|
27
27
|
|
package/src/txe_session.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { KeyStore } from '@aztec/key-store';
|
|
5
5
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
-
import type { ProtocolContract } from '@aztec/protocol-contracts';
|
|
7
6
|
import type { AccessScopes } from '@aztec/pxe/client/lazy';
|
|
8
7
|
import {
|
|
9
8
|
AddressStore,
|
|
10
9
|
AnchorBlockStore,
|
|
11
10
|
CapsuleStore,
|
|
11
|
+
ContractStore,
|
|
12
12
|
JobCoordinator,
|
|
13
13
|
NoteService,
|
|
14
14
|
NoteStore,
|
|
@@ -55,7 +55,6 @@ import { TXEArchiver } from './state_machine/archiver.js';
|
|
|
55
55
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
56
56
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
57
57
|
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
58
|
-
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
59
58
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
60
59
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
61
60
|
|
|
@@ -114,6 +113,10 @@ export interface TXESessionStateHandler {
|
|
|
114
113
|
enterPublicState(contractAddress?: AztecAddress): Promise<void>;
|
|
115
114
|
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
|
|
116
115
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
116
|
+
|
|
117
|
+
// TODO(F-335): Exposing the job info is abstraction breakage - drop the following 2 functions.
|
|
118
|
+
cycleJob(): Promise<string>;
|
|
119
|
+
getCurrentJob(): string;
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
/**
|
|
@@ -132,7 +135,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
132
135
|
| IPrivateExecutionOracle
|
|
133
136
|
| IAvmExecutionOracle
|
|
134
137
|
| ITxeExecutionOracle,
|
|
135
|
-
private contractStore:
|
|
138
|
+
private contractStore: ContractStore,
|
|
136
139
|
private noteStore: NoteStore,
|
|
137
140
|
private keyStore: KeyStore,
|
|
138
141
|
private addressStore: AddressStore,
|
|
@@ -149,12 +152,11 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
149
152
|
private nextBlockTimestamp: bigint,
|
|
150
153
|
) {}
|
|
151
154
|
|
|
152
|
-
static async init(
|
|
155
|
+
static async init(contractStore: ContractStore) {
|
|
153
156
|
const store = await openTmpStore('txe-session');
|
|
154
157
|
|
|
155
158
|
const addressStore = new AddressStore(store);
|
|
156
159
|
const privateEventStore = new PrivateEventStore(store);
|
|
157
|
-
const contractStore = new TXEContractStore(store);
|
|
158
160
|
const noteStore = new NoteStore(store);
|
|
159
161
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
160
162
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
@@ -173,12 +175,6 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
173
175
|
noteStore,
|
|
174
176
|
]);
|
|
175
177
|
|
|
176
|
-
// Register protocol contracts.
|
|
177
|
-
for (const { contractClass, instance, artifact } of protocolContracts) {
|
|
178
|
-
await contractStore.addContractArtifact(contractClass.id, artifact);
|
|
179
|
-
await contractStore.addContractInstance(instance);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
178
|
const archiver = new TXEArchiver(store);
|
|
183
179
|
const anchorBlockStore = new AnchorBlockStore(store);
|
|
184
180
|
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
@@ -201,7 +197,6 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
201
197
|
senderAddressBookStore,
|
|
202
198
|
capsuleStore,
|
|
203
199
|
privateEventStore,
|
|
204
|
-
initialJobId,
|
|
205
200
|
nextBlockTimestamp,
|
|
206
201
|
version,
|
|
207
202
|
chainId,
|
|
@@ -262,6 +257,17 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
262
257
|
}
|
|
263
258
|
}
|
|
264
259
|
|
|
260
|
+
getCurrentJob(): string {
|
|
261
|
+
return this.currentJobId;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Commits the current job and begins a new one. Returns the new job ID. */
|
|
265
|
+
async cycleJob(): Promise<string> {
|
|
266
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
267
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
268
|
+
return this.currentJobId;
|
|
269
|
+
}
|
|
270
|
+
|
|
265
271
|
async enterTopLevelState() {
|
|
266
272
|
switch (this.state.name) {
|
|
267
273
|
case 'PRIVATE': {
|
|
@@ -285,8 +291,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
285
291
|
}
|
|
286
292
|
|
|
287
293
|
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
288
|
-
await this.
|
|
289
|
-
this.currentJobId = this.jobCoordinator.beginJob();
|
|
294
|
+
await this.cycleJob();
|
|
290
295
|
|
|
291
296
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
292
297
|
this.stateMachine,
|
|
@@ -300,7 +305,6 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
300
305
|
this.senderAddressBookStore,
|
|
301
306
|
this.capsuleStore,
|
|
302
307
|
this.privateEventStore,
|
|
303
|
-
this.currentJobId,
|
|
304
308
|
this.nextBlockTimestamp,
|
|
305
309
|
this.version,
|
|
306
310
|
this.chainId,
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import type { ContractStore } from '@aztec/pxe/server';
|
|
4
|
-
import { type ContractArtifact, FunctionSelector
|
|
4
|
+
import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
-
import {
|
|
7
|
-
type ContractClassPublic,
|
|
8
|
-
type ContractDataSource,
|
|
9
|
-
type ContractInstanceWithAddress,
|
|
10
|
-
computePrivateFunctionsRoot,
|
|
11
|
-
computePublicBytecodeCommitment,
|
|
12
|
-
getContractClassPrivateFunctionFromArtifact,
|
|
13
|
-
} from '@aztec/stdlib/contract';
|
|
6
|
+
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
14
7
|
|
|
15
8
|
export class TXEPublicContractDataSource implements ContractDataSource {
|
|
16
|
-
#privateFunctionsRoot: Map<string, Buffer> = new Map();
|
|
17
9
|
constructor(
|
|
18
10
|
private blockNumber: BlockNumber,
|
|
19
11
|
private contractStore: ContractStore,
|
|
@@ -24,42 +16,24 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
24
16
|
}
|
|
25
17
|
|
|
26
18
|
async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
|
|
27
|
-
const contractClass = await this.contractStore.
|
|
19
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
28
20
|
if (!contractClass) {
|
|
29
21
|
return;
|
|
30
22
|
}
|
|
31
|
-
const artifact = await this.contractStore.getContractArtifact(id);
|
|
32
|
-
if (!artifact) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let privateFunctionsRoot;
|
|
37
|
-
if (!this.#privateFunctionsRoot.has(id.toString())) {
|
|
38
|
-
const privateFunctions = await Promise.all(
|
|
39
|
-
artifact.functions
|
|
40
|
-
.filter(fn => fn.functionType === FunctionType.PRIVATE)
|
|
41
|
-
.map(fn => getContractClassPrivateFunctionFromArtifact(fn)),
|
|
42
|
-
);
|
|
43
|
-
privateFunctionsRoot = await computePrivateFunctionsRoot(privateFunctions);
|
|
44
|
-
this.#privateFunctionsRoot.set(id.toString(), privateFunctionsRoot.toBuffer());
|
|
45
|
-
} else {
|
|
46
|
-
privateFunctionsRoot = Fr.fromBuffer(this.#privateFunctionsRoot.get(id.toString())!);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
23
|
return {
|
|
50
|
-
id,
|
|
51
|
-
artifactHash: contractClass
|
|
52
|
-
packedBytecode: contractClass
|
|
53
|
-
privateFunctionsRoot,
|
|
54
|
-
version: contractClass
|
|
24
|
+
id: contractClass.id,
|
|
25
|
+
artifactHash: contractClass.artifactHash,
|
|
26
|
+
packedBytecode: contractClass.packedBytecode,
|
|
27
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
28
|
+
version: contractClass.version,
|
|
55
29
|
privateFunctions: [],
|
|
56
30
|
utilityFunctions: [],
|
|
57
31
|
};
|
|
58
32
|
}
|
|
59
33
|
|
|
60
34
|
async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
|
|
61
|
-
const contractClass = await this.contractStore.
|
|
62
|
-
return contractClass
|
|
35
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
36
|
+
return contractClass?.publicBytecodeCommitment;
|
|
63
37
|
}
|
|
64
38
|
|
|
65
39
|
async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
|
-
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
-
import { ContractStore } from '@aztec/pxe/server';
|
|
4
|
-
export type ContractArtifactWithHash = ContractArtifact & {
|
|
5
|
-
artifactHash: Fr;
|
|
6
|
-
};
|
|
7
|
-
export declare class TXEContractStore extends ContractStore {
|
|
8
|
-
#private;
|
|
9
|
-
addContractArtifact(id: Fr, artifact: ContractArtifact | ContractArtifactWithHash): Promise<void>;
|
|
10
|
-
getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | ContractArtifactWithHash | undefined>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX2NvbnRyYWN0X3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbC90eGVfY29udHJhY3Rfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM1RCxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFDNUMsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRWxELE1BQU0sTUFBTSx3QkFBd0IsR0FBRyxnQkFBZ0IsR0FBRztJQUFFLFlBQVksRUFBRSxFQUFFLENBQUE7Q0FBRSxDQUFDO0FBTy9FLHFCQUFhLGdCQUFpQixTQUFRLGFBQWE7O0lBRzNCLG1CQUFtQixDQUN2QyxFQUFFLEVBQUUsRUFBRSxFQUNOLFFBQVEsRUFBRSxnQkFBZ0IsR0FBRyx3QkFBd0IsR0FDcEQsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUtmO0lBRXFCLG1CQUFtQixDQUN2QyxlQUFlLEVBQUUsRUFBRSxHQUNsQixPQUFPLENBQUMsZ0JBQWdCLEdBQUcsd0JBQXdCLEdBQUcsU0FBUyxDQUFDLENBUWxFO0NBQ0YifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"txe_contract_store.d.ts","sourceRoot":"","sources":["../../src/util/txe_contract_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,wBAAwB,GAAG,gBAAgB,GAAG;IAAE,YAAY,EAAE,EAAE,CAAA;CAAE,CAAC;AAO/E,qBAAa,gBAAiB,SAAQ,aAAa;;IAG3B,mBAAmB,CACvC,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,gBAAgB,GAAG,wBAAwB,GACpD,OAAO,CAAC,IAAI,CAAC,CAKf;IAEqB,mBAAmB,CACvC,eAAe,EAAE,EAAE,GAClB,OAAO,CAAC,gBAAgB,GAAG,wBAAwB,GAAG,SAAS,CAAC,CAQlE;CACF"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/aztec.js/fields';
|
|
2
|
-
import { ContractStore } from '@aztec/pxe/server';
|
|
3
|
-
/*
|
|
4
|
-
* A contract store that stores contract artifacts with their hashes. Since
|
|
5
|
-
* TXE typically deploys the same contract again and again for multiple tests, caching
|
|
6
|
-
* the *very* expensive artifact hash computation improves testing speed significantly.
|
|
7
|
-
*/ export class TXEContractStore extends ContractStore {
|
|
8
|
-
#artifactHashes = new Map();
|
|
9
|
-
async addContractArtifact(id, artifact) {
|
|
10
|
-
if ('artifactHash' in artifact) {
|
|
11
|
-
this.#artifactHashes.set(id.toString(), artifact.artifactHash.toBuffer());
|
|
12
|
-
}
|
|
13
|
-
await super.addContractArtifact(id, artifact);
|
|
14
|
-
}
|
|
15
|
-
async getContractArtifact(contractClassId) {
|
|
16
|
-
const artifact = await super.getContractArtifact(contractClassId);
|
|
17
|
-
if (artifact && this.#artifactHashes.has(contractClassId.toString())) {
|
|
18
|
-
artifact.artifactHash = Fr.fromBuffer(this.#artifactHashes.get(contractClassId.toString()));
|
|
19
|
-
}
|
|
20
|
-
return artifact;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
|
-
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
-
import { ContractStore } from '@aztec/pxe/server';
|
|
4
|
-
|
|
5
|
-
export type ContractArtifactWithHash = ContractArtifact & { artifactHash: Fr };
|
|
6
|
-
|
|
7
|
-
/*
|
|
8
|
-
* A contract store that stores contract artifacts with their hashes. Since
|
|
9
|
-
* TXE typically deploys the same contract again and again for multiple tests, caching
|
|
10
|
-
* the *very* expensive artifact hash computation improves testing speed significantly.
|
|
11
|
-
*/
|
|
12
|
-
export class TXEContractStore extends ContractStore {
|
|
13
|
-
#artifactHashes: Map<string, Buffer> = new Map();
|
|
14
|
-
|
|
15
|
-
public override async addContractArtifact(
|
|
16
|
-
id: Fr,
|
|
17
|
-
artifact: ContractArtifact | ContractArtifactWithHash,
|
|
18
|
-
): Promise<void> {
|
|
19
|
-
if ('artifactHash' in artifact) {
|
|
20
|
-
this.#artifactHashes.set(id.toString(), artifact.artifactHash.toBuffer());
|
|
21
|
-
}
|
|
22
|
-
await super.addContractArtifact(id, artifact);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public override async getContractArtifact(
|
|
26
|
-
contractClassId: Fr,
|
|
27
|
-
): Promise<ContractArtifact | ContractArtifactWithHash | undefined> {
|
|
28
|
-
const artifact = await super.getContractArtifact(contractClassId);
|
|
29
|
-
if (artifact && this.#artifactHashes.has(contractClassId.toString())) {
|
|
30
|
-
(artifact as ContractArtifactWithHash).artifactHash = Fr.fromBuffer(
|
|
31
|
-
this.#artifactHashes.get(contractClassId.toString())!,
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
return artifact;
|
|
35
|
-
}
|
|
36
|
-
}
|