@aztec/txe 0.0.1-commit.64b6bbb → 0.0.1-commit.684755437
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 +88 -54
- package/dest/oracle/interfaces.d.ts +29 -28
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +13 -13
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +12 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -23
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +55 -46
- package/dest/rpc_translator.d.ts +82 -82
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +241 -148
- package/dest/state_machine/dummy_p2p_client.d.ts +8 -5
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +13 -4
- package/dest/state_machine/index.d.ts +1 -1
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.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 +24 -21
- 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 +89 -52
- package/src/oracle/interfaces.ts +32 -31
- package/src/oracle/txe_oracle_public_context.ts +12 -12
- package/src/oracle/txe_oracle_top_level_context.ts +68 -45
- package/src/rpc_translator.ts +254 -156
- package/src/state_machine/dummy_p2p_client.ts +19 -7
- package/src/state_machine/index.ts +1 -0
- package/src/txe_session.ts +29 -20
- 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
|
@@ -36,7 +36,6 @@ export class TXEOracleTopLevelContext {
|
|
|
36
36
|
senderAddressBookStore;
|
|
37
37
|
capsuleStore;
|
|
38
38
|
privateEventStore;
|
|
39
|
-
jobId;
|
|
40
39
|
nextBlockTimestamp;
|
|
41
40
|
version;
|
|
42
41
|
chainId;
|
|
@@ -44,7 +43,7 @@ export class TXEOracleTopLevelContext {
|
|
|
44
43
|
isMisc;
|
|
45
44
|
isTxe;
|
|
46
45
|
logger;
|
|
47
|
-
constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore,
|
|
46
|
+
constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, authwits){
|
|
48
47
|
this.stateMachine = stateMachine;
|
|
49
48
|
this.contractStore = contractStore;
|
|
50
49
|
this.noteStore = noteStore;
|
|
@@ -56,7 +55,6 @@ export class TXEOracleTopLevelContext {
|
|
|
56
55
|
this.senderAddressBookStore = senderAddressBookStore;
|
|
57
56
|
this.capsuleStore = capsuleStore;
|
|
58
57
|
this.privateEventStore = privateEventStore;
|
|
59
|
-
this.jobId = jobId;
|
|
60
58
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
61
59
|
this.version = version;
|
|
62
60
|
this.chainId = chainId;
|
|
@@ -66,18 +64,18 @@ export class TXEOracleTopLevelContext {
|
|
|
66
64
|
this.logger = createLogger('txe:top_level_context');
|
|
67
65
|
this.logger.debug('Entering Top Level Context');
|
|
68
66
|
}
|
|
69
|
-
|
|
67
|
+
assertCompatibleOracleVersion(version) {
|
|
70
68
|
if (version !== ORACLE_VERSION) {
|
|
71
69
|
throw new Error(`Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`);
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
72
|
// This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
|
|
75
73
|
// setup.
|
|
76
|
-
|
|
74
|
+
getRandomField() {
|
|
77
75
|
return Fr.random();
|
|
78
76
|
}
|
|
79
77
|
// We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
|
|
80
|
-
|
|
78
|
+
log(level, message, fields) {
|
|
81
79
|
if (!LogLevels[level]) {
|
|
82
80
|
throw new Error(`Invalid log level: ${level}`);
|
|
83
81
|
}
|
|
@@ -87,19 +85,19 @@ export class TXEOracleTopLevelContext {
|
|
|
87
85
|
});
|
|
88
86
|
return Promise.resolve();
|
|
89
87
|
}
|
|
90
|
-
|
|
88
|
+
getDefaultAddress() {
|
|
91
89
|
return DEFAULT_ADDRESS;
|
|
92
90
|
}
|
|
93
|
-
async
|
|
91
|
+
async getNextBlockNumber() {
|
|
94
92
|
return BlockNumber(await this.getLastBlockNumber() + 1);
|
|
95
93
|
}
|
|
96
|
-
|
|
94
|
+
getNextBlockTimestamp() {
|
|
97
95
|
return Promise.resolve(this.nextBlockTimestamp);
|
|
98
96
|
}
|
|
99
|
-
async
|
|
97
|
+
async getLastBlockTimestamp() {
|
|
100
98
|
return (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.timestamp;
|
|
101
99
|
}
|
|
102
|
-
async
|
|
100
|
+
async getLastTxEffects() {
|
|
103
101
|
const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
|
|
104
102
|
const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
|
|
105
103
|
if (block.body.txEffects.length != 1) {
|
|
@@ -113,7 +111,19 @@ export class TXEOracleTopLevelContext {
|
|
|
113
111
|
nullifiers: txEffects.nullifiers
|
|
114
112
|
};
|
|
115
113
|
}
|
|
116
|
-
async
|
|
114
|
+
async syncContractNonOracleMethod(contractAddress, scope, jobId) {
|
|
115
|
+
if (contractAddress.equals(DEFAULT_ADDRESS)) {
|
|
116
|
+
this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
120
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(contractAddress, null, async (call, execScopes)=>{
|
|
121
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
122
|
+
}, blockHeader, jobId, [
|
|
123
|
+
scope
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
async getPrivateEvents(selector, contractAddress, scope) {
|
|
117
127
|
return (await this.privateEventStore.getPrivateEvents(selector, {
|
|
118
128
|
contractAddress,
|
|
119
129
|
scopes: [
|
|
@@ -123,17 +133,17 @@ export class TXEOracleTopLevelContext {
|
|
|
123
133
|
toBlock: await this.getLastBlockNumber() + 1
|
|
124
134
|
})).map((e)=>e.packedEvent);
|
|
125
135
|
}
|
|
126
|
-
async
|
|
136
|
+
async advanceBlocksBy(blocks) {
|
|
127
137
|
this.logger.debug(`time traveling ${blocks} blocks`);
|
|
128
138
|
for(let i = 0; i < blocks; i++){
|
|
129
139
|
await this.mineBlock();
|
|
130
140
|
}
|
|
131
141
|
}
|
|
132
|
-
|
|
142
|
+
advanceTimestampBy(duration) {
|
|
133
143
|
this.logger.debug(`time traveling ${duration} seconds`);
|
|
134
144
|
this.nextBlockTimestamp += duration;
|
|
135
145
|
}
|
|
136
|
-
async
|
|
146
|
+
async deploy(artifact, instance, secret) {
|
|
137
147
|
// Emit deployment nullifier
|
|
138
148
|
await this.mineBlock({
|
|
139
149
|
nullifiers: [
|
|
@@ -141,25 +151,25 @@ export class TXEOracleTopLevelContext {
|
|
|
141
151
|
]
|
|
142
152
|
});
|
|
143
153
|
if (!secret.equals(Fr.ZERO)) {
|
|
144
|
-
await this.
|
|
154
|
+
await this.addAccount(artifact, instance, secret);
|
|
145
155
|
} else {
|
|
146
156
|
await this.contractStore.addContractInstance(instance);
|
|
147
|
-
await this.contractStore.addContractArtifact(
|
|
157
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
148
158
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
149
159
|
}
|
|
150
160
|
}
|
|
151
|
-
async
|
|
161
|
+
async addAccount(artifact, instance, secret) {
|
|
152
162
|
const partialAddress = await computePartialAddress(instance);
|
|
153
163
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
154
164
|
await this.contractStore.addContractInstance(instance);
|
|
155
|
-
await this.contractStore.addContractArtifact(
|
|
165
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
156
166
|
const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
|
|
157
167
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
158
168
|
await this.addressStore.addCompleteAddress(completeAddress);
|
|
159
169
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
160
170
|
return completeAddress;
|
|
161
171
|
}
|
|
162
|
-
async
|
|
172
|
+
async createAccount(secret) {
|
|
163
173
|
// This is a foot gun !
|
|
164
174
|
const completeAddress = await this.keyStore.addAccount(secret, secret);
|
|
165
175
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
@@ -167,7 +177,7 @@ export class TXEOracleTopLevelContext {
|
|
|
167
177
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
168
178
|
return completeAddress;
|
|
169
179
|
}
|
|
170
|
-
async
|
|
180
|
+
async addAuthWitness(address, messageHash) {
|
|
171
181
|
const account = await this.accountStore.getAccount(address);
|
|
172
182
|
const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
|
|
173
183
|
const schnorr = new Schnorr();
|
|
@@ -178,7 +188,7 @@ export class TXEOracleTopLevelContext {
|
|
|
178
188
|
this.authwits.set(authWitness.requestHash.toString(), authWitness);
|
|
179
189
|
}
|
|
180
190
|
async mineBlock(options = {}) {
|
|
181
|
-
const blockNumber = await this.
|
|
191
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
182
192
|
const txEffect = TxEffect.empty();
|
|
183
193
|
txEffect.nullifiers = [
|
|
184
194
|
getSingleTxBlockRequestHash(blockNumber),
|
|
@@ -200,26 +210,25 @@ export class TXEOracleTopLevelContext {
|
|
|
200
210
|
this.logger.info(`Created block ${blockNumber} with timestamp ${block.header.globalVariables.timestamp}`);
|
|
201
211
|
await this.stateMachine.handleL2Block(block);
|
|
202
212
|
}
|
|
203
|
-
async
|
|
213
|
+
async privateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false, jobId) {
|
|
204
214
|
this.logger.verbose(`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
|
|
205
215
|
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
206
216
|
if (!artifact) {
|
|
207
217
|
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';
|
|
208
218
|
throw new Error(message);
|
|
209
219
|
}
|
|
210
|
-
// When `from` is the zero address (
|
|
211
|
-
//
|
|
212
|
-
|
|
213
|
-
const effectiveScopes = from.isZero() ? undefined : [
|
|
220
|
+
// When `from` is the zero address (e.g. when deploying a new account contract), we return an
|
|
221
|
+
// empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
|
|
222
|
+
const effectiveScopes = from.isZero() ? [] : [
|
|
214
223
|
from
|
|
215
224
|
];
|
|
216
225
|
// Sync notes before executing private function to discover notes from previous transactions
|
|
217
|
-
const utilityExecutor = async (call)=>{
|
|
218
|
-
await this.executeUtilityCall(call,
|
|
226
|
+
const utilityExecutor = async (call, execScopes)=>{
|
|
227
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
219
228
|
};
|
|
220
229
|
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
221
|
-
await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader,
|
|
222
|
-
const blockNumber = await this.
|
|
230
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader, jobId, effectiveScopes);
|
|
231
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
223
232
|
const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
|
|
224
233
|
const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
|
|
225
234
|
const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
|
|
@@ -258,7 +267,7 @@ export class TXEOracleTopLevelContext {
|
|
|
258
267
|
capsuleStore: this.capsuleStore,
|
|
259
268
|
privateEventStore: this.privateEventStore,
|
|
260
269
|
contractSyncService: this.stateMachine.contractSyncService,
|
|
261
|
-
jobId
|
|
270
|
+
jobId,
|
|
262
271
|
totalPublicCalldataCount: 0,
|
|
263
272
|
sideEffectCounter: minRevertibleSideEffectCounter,
|
|
264
273
|
scopes: effectiveScopes,
|
|
@@ -278,7 +287,7 @@ export class TXEOracleTopLevelContext {
|
|
|
278
287
|
r.publicInputs.publicTeardownCallRequest
|
|
279
288
|
]));
|
|
280
289
|
const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
|
|
281
|
-
const calldata = await privateExecutionOracle.
|
|
290
|
+
const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
|
|
282
291
|
return new HashedValues(calldata, r.calldataHash);
|
|
283
292
|
}));
|
|
284
293
|
noteCache.finish();
|
|
@@ -290,7 +299,7 @@ export class TXEOracleTopLevelContext {
|
|
|
290
299
|
// According to the protocol rules, there must be at least one nullifier in the tx. The first nullifier is used as
|
|
291
300
|
// the nonce generator for the note hashes.
|
|
292
301
|
// We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
|
|
293
|
-
const { publicInputs } = await generateSimulatedProvingResult(result, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), minRevertibleSideEffectCounter);
|
|
302
|
+
const { publicInputs } = await generateSimulatedProvingResult(result, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), this.stateMachine.node, minRevertibleSideEffectCounter);
|
|
294
303
|
const globals = makeGlobalVariables();
|
|
295
304
|
globals.blockNumber = blockNumber;
|
|
296
305
|
globals.timestamp = this.nextBlockTimestamp;
|
|
@@ -358,9 +367,9 @@ export class TXEOracleTopLevelContext {
|
|
|
358
367
|
await forkedWorldTrees.close();
|
|
359
368
|
return executionResult.returnValues ?? [];
|
|
360
369
|
}
|
|
361
|
-
async
|
|
370
|
+
async publicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
|
|
362
371
|
this.logger.verbose(`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`);
|
|
363
|
-
const blockNumber = await this.
|
|
372
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
364
373
|
const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
|
|
365
374
|
const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
|
|
366
375
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
@@ -399,7 +408,7 @@ export class TXEOracleTopLevelContext {
|
|
|
399
408
|
revertibleAccumulatedData.publicCallRequests[0] = new PublicCallRequest(from, targetContractAddress, isStaticCall, calldataHash);
|
|
400
409
|
const inputsForPublic = new PartialPrivateTailPublicInputsForPublic(nonRevertibleAccumulatedData, revertibleAccumulatedData, PublicCallRequest.empty());
|
|
401
410
|
const constantData = new TxConstantData(anchorBlockHeader, txContext, Fr.zero(), Fr.zero());
|
|
402
|
-
const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*
|
|
411
|
+
const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*expirationTimestamp=*/ 0n, inputsForPublic, undefined);
|
|
403
412
|
const tx = await Tx.create({
|
|
404
413
|
data: txData,
|
|
405
414
|
chonkProof: ChonkProof.empty(),
|
|
@@ -452,16 +461,16 @@ export class TXEOracleTopLevelContext {
|
|
|
452
461
|
await forkedWorldTrees.close();
|
|
453
462
|
return returnValues ?? [];
|
|
454
463
|
}
|
|
455
|
-
async
|
|
464
|
+
async executeUtilityFunction(targetContractAddress, functionSelector, args, jobId) {
|
|
456
465
|
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
457
466
|
if (!artifact) {
|
|
458
467
|
throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
|
|
459
468
|
}
|
|
460
469
|
// Sync notes before executing utility function to discover notes from previous transactions
|
|
461
470
|
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
462
|
-
await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, async (call)=>{
|
|
463
|
-
await this.executeUtilityCall(call);
|
|
464
|
-
}, blockHeader,
|
|
471
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, async (call, execScopes)=>{
|
|
472
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
473
|
+
}, blockHeader, jobId, 'ALL_SCOPES');
|
|
465
474
|
const call = FunctionCall.from({
|
|
466
475
|
name: artifact.name,
|
|
467
476
|
to: targetContractAddress,
|
|
@@ -472,9 +481,9 @@ export class TXEOracleTopLevelContext {
|
|
|
472
481
|
args,
|
|
473
482
|
returnTypes: []
|
|
474
483
|
});
|
|
475
|
-
return this.executeUtilityCall(call);
|
|
484
|
+
return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
|
|
476
485
|
}
|
|
477
|
-
async executeUtilityCall(call, scopes) {
|
|
486
|
+
async executeUtilityCall(call, scopes, jobId) {
|
|
478
487
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
479
488
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
480
489
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
@@ -499,7 +508,7 @@ export class TXEOracleTopLevelContext {
|
|
|
499
508
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
500
509
|
capsuleStore: this.capsuleStore,
|
|
501
510
|
privateEventStore: this.privateEventStore,
|
|
502
|
-
jobId
|
|
511
|
+
jobId,
|
|
503
512
|
scopes
|
|
504
513
|
});
|
|
505
514
|
const acirExecutionResult = await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
|
|
@@ -511,10 +520,10 @@ export class TXEOracleTopLevelContext {
|
|
|
511
520
|
cause: err
|
|
512
521
|
});
|
|
513
522
|
});
|
|
514
|
-
this.logger.verbose(`Utility
|
|
523
|
+
this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
|
|
515
524
|
return witnessMapToFields(acirExecutionResult.returnWitness);
|
|
516
525
|
} catch (err) {
|
|
517
|
-
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility
|
|
526
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
|
|
518
527
|
}
|
|
519
528
|
}
|
|
520
529
|
close() {
|