@aztec/simulator 0.35.0 → 0.36.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/acvm/oracle/oracle.d.ts +6 -5
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +30 -23
- package/dest/acvm/oracle/typed_oracle.d.ts +15 -21
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +10 -10
- package/dest/avm/avm_execution_environment.d.ts +1 -5
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +5 -8
- package/dest/avm/avm_gas.d.ts +1 -9
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +6 -13
- package/dest/avm/avm_machine_state.d.ts +1 -3
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +8 -9
- package/dest/avm/avm_simulator.js +2 -2
- package/dest/avm/fixtures/index.d.ts +2 -6
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +3 -12
- package/dest/avm/journal/journal.d.ts +2 -1
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +8 -17
- package/dest/avm/journal/trace.d.ts +3 -1
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace.js +11 -1
- package/dest/avm/journal/trace_types.d.ts +4 -0
- package/dest/avm/journal/trace_types.d.ts.map +1 -1
- package/dest/avm/journal/trace_types.js +1 -1
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +1 -1
- package/dest/avm/opcodes/context_getters.d.ts +0 -5
- package/dest/avm/opcodes/context_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/context_getters.js +1 -8
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +1 -3
- package/dest/avm/opcodes/environment_getters.d.ts +0 -15
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +1 -35
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +5 -6
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +3 -3
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +1 -1
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +3 -8
- package/dest/avm/serialization/instruction_serialization.d.ts +42 -47
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +43 -48
- package/dest/client/client_execution_context.d.ts +13 -16
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +36 -34
- package/dest/client/db_oracle.d.ts +5 -16
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/execution_note_cache.d.ts +6 -2
- package/dest/client/execution_note_cache.d.ts.map +1 -1
- package/dest/client/execution_note_cache.js +10 -7
- package/dest/client/execution_result.d.ts +10 -5
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +7 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +4 -10
- package/dest/client/simulator.d.ts +1 -3
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +5 -9
- package/dest/client/view_data_oracle.d.ts +7 -11
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +8 -14
- package/dest/mocks/fixtures.d.ts +1 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +9 -5
- package/dest/public/abstract_phase_manager.d.ts +4 -4
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +28 -43
- package/dest/public/app_logic_phase_manager.d.ts +1 -7
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/public/app_logic_phase_manager.js +1 -7
- package/dest/public/db.d.ts +6 -7
- package/dest/public/db.d.ts.map +1 -1
- package/dest/public/execution.d.ts +15 -6
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +7 -9
- package/dest/public/executor.d.ts +2 -2
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +19 -10
- package/dest/public/hints_builder.d.ts +10 -8
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +29 -35
- package/dest/public/public_execution_context.d.ts +8 -13
- package/dest/public/public_execution_context.d.ts.map +1 -1
- package/dest/public/public_execution_context.js +12 -29
- package/dest/public/public_executor.d.ts +2 -2
- package/dest/public/public_executor.d.ts.map +1 -1
- package/dest/public/public_executor.js +4 -5
- package/dest/public/public_processor.d.ts +1 -2
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +1 -1
- package/dest/public/setup_phase_manager.d.ts +0 -6
- package/dest/public/setup_phase_manager.d.ts.map +1 -1
- package/dest/public/setup_phase_manager.js +1 -7
- package/dest/public/state_actions.d.ts.map +1 -1
- package/dest/public/state_actions.js +3 -1
- package/dest/public/tail_phase_manager.d.ts +3 -6
- package/dest/public/tail_phase_manager.d.ts.map +1 -1
- package/dest/public/tail_phase_manager.js +47 -16
- package/dest/public/teardown_phase_manager.d.ts +3 -7
- package/dest/public/teardown_phase_manager.d.ts.map +1 -1
- package/dest/public/teardown_phase_manager.js +14 -7
- package/dest/public/transitional_adaptors.d.ts +2 -2
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +19 -21
- package/dest/public/utils.d.ts.map +1 -1
- package/dest/public/utils.js +4 -2
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +3 -5
- package/package.json +16 -8
- package/src/acvm/oracle/oracle.ts +39 -21
- package/src/acvm/oracle/typed_oracle.ts +18 -26
- package/src/avm/avm_execution_environment.ts +0 -13
- package/src/avm/avm_gas.ts +6 -14
- package/src/avm/avm_machine_state.ts +8 -11
- package/src/avm/avm_simulator.ts +1 -1
- package/src/avm/fixtures/index.ts +2 -24
- package/src/avm/journal/journal.ts +14 -25
- package/src/avm/journal/trace.ts +12 -0
- package/src/avm/journal/trace_types.ts +7 -0
- package/src/avm/opcodes/arithmetic.ts +2 -2
- package/src/avm/opcodes/context_getters.ts +0 -9
- package/src/avm/opcodes/contract.ts +0 -2
- package/src/avm/opcodes/environment_getters.ts +0 -45
- package/src/avm/opcodes/external_calls.ts +5 -6
- package/src/avm/opcodes/memory.ts +5 -5
- package/src/avm/opcodes/storage.ts +1 -1
- package/src/avm/serialization/bytecode_serialization.ts +2 -10
- package/src/avm/serialization/instruction_serialization.ts +1 -6
- package/src/client/client_execution_context.ts +79 -54
- package/src/client/db_oracle.ts +5 -17
- package/src/client/execution_note_cache.ts +16 -7
- package/src/client/execution_result.ts +17 -6
- package/src/client/private_execution.ts +4 -9
- package/src/client/simulator.ts +3 -15
- package/src/client/view_data_oracle.ts +25 -29
- package/src/mocks/fixtures.ts +7 -16
- package/src/public/abstract_phase_manager.ts +45 -56
- package/src/public/app_logic_phase_manager.ts +6 -6
- package/src/public/db.ts +7 -8
- package/src/public/execution.ts +22 -18
- package/src/public/executor.ts +31 -5
- package/src/public/hints_builder.ts +62 -62
- package/src/public/public_execution_context.ts +30 -36
- package/src/public/public_executor.ts +4 -6
- package/src/public/public_processor.ts +1 -1
- package/src/public/setup_phase_manager.ts +6 -6
- package/src/public/state_actions.ts +2 -0
- package/src/public/tail_phase_manager.ts +98 -23
- package/src/public/teardown_phase_manager.ts +24 -6
- package/src/public/transitional_adaptors.ts +25 -19
- package/src/public/utils.ts +3 -1
- package/src/test/utils.ts +2 -4
|
@@ -16,12 +16,13 @@ import {
|
|
|
16
16
|
FunctionSelector,
|
|
17
17
|
type Header,
|
|
18
18
|
NoteHashReadRequestMembershipWitness,
|
|
19
|
+
PrivateContextInputs,
|
|
19
20
|
PublicCallRequest,
|
|
20
21
|
type SideEffect,
|
|
21
|
-
TxContext,
|
|
22
|
+
type TxContext,
|
|
22
23
|
} from '@aztec/circuits.js';
|
|
23
|
-
import {
|
|
24
|
-
import { computePublicDataTreeLeafSlot,
|
|
24
|
+
import { Aes128 } from '@aztec/circuits.js/barretenberg';
|
|
25
|
+
import { computePublicDataTreeLeafSlot, computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
|
|
25
26
|
import { type FunctionAbi, type FunctionArtifact, countArgumentsSize } from '@aztec/foundation/abi';
|
|
26
27
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
27
28
|
import { Fr, type Point } from '@aztec/foundation/fields';
|
|
@@ -31,7 +32,7 @@ import { type NoteData, toACVMWitness } from '../acvm/index.js';
|
|
|
31
32
|
import { type PackedValuesCache } from '../common/packed_values_cache.js';
|
|
32
33
|
import { type DBOracle } from './db_oracle.js';
|
|
33
34
|
import { type ExecutionNoteCache } from './execution_note_cache.js';
|
|
34
|
-
import { type ExecutionResult, type NoteAndSlot } from './execution_result.js';
|
|
35
|
+
import { type ExecutionResult, type NoteAndSlot, type NullifiedNoteHashCounter } from './execution_result.js';
|
|
35
36
|
import { pickNotes } from './pick_notes.js';
|
|
36
37
|
import { executePrivateFunction } from './private_execution.js';
|
|
37
38
|
import { ViewDataOracle } from './view_data_oracle.js';
|
|
@@ -58,27 +59,27 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
58
59
|
* They should act as references for the read requests output by an app circuit via public inputs.
|
|
59
60
|
*/
|
|
60
61
|
private gotNotes: Map<bigint, bigint> = new Map();
|
|
62
|
+
private nullifiedNoteHashCounters: NullifiedNoteHashCounter[] = [];
|
|
61
63
|
private encryptedLogs: EncryptedL2Log[] = [];
|
|
62
64
|
private unencryptedLogs: UnencryptedL2Log[] = [];
|
|
63
65
|
private nestedExecutions: ExecutionResult[] = [];
|
|
64
66
|
private enqueuedPublicFunctionCalls: PublicCallRequest[] = [];
|
|
65
67
|
|
|
66
68
|
constructor(
|
|
67
|
-
|
|
69
|
+
contractAddress: AztecAddress,
|
|
68
70
|
private readonly argsHash: Fr,
|
|
69
71
|
private readonly txContext: TxContext,
|
|
70
72
|
private readonly callContext: CallContext,
|
|
71
73
|
/** Header of a block whose state is used during private execution (not the block the transaction is included in). */
|
|
72
74
|
protected readonly historicalHeader: Header,
|
|
73
75
|
/** List of transient auth witnesses to be used during this simulation */
|
|
74
|
-
|
|
76
|
+
authWitnesses: AuthWitness[],
|
|
75
77
|
private readonly packedValuesCache: PackedValuesCache,
|
|
76
78
|
private readonly noteCache: ExecutionNoteCache,
|
|
77
|
-
|
|
78
|
-
private readonly curve: Grumpkin,
|
|
79
|
+
db: DBOracle,
|
|
79
80
|
private node: AztecNode,
|
|
80
81
|
protected sideEffectCounter: number = 0,
|
|
81
|
-
|
|
82
|
+
log = createDebugLogger('aztec:simulator:client_execution_context'),
|
|
82
83
|
) {
|
|
83
84
|
super(contractAddress, authWitnesses, db, node, log);
|
|
84
85
|
}
|
|
@@ -99,18 +100,14 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
99
100
|
throw new Error('Invalid arguments size');
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
new Fr(this.sideEffectCounter),
|
|
110
|
-
|
|
111
|
-
...args,
|
|
112
|
-
];
|
|
103
|
+
const privateContextInputs = new PrivateContextInputs(
|
|
104
|
+
this.callContext,
|
|
105
|
+
this.historicalHeader,
|
|
106
|
+
this.txContext,
|
|
107
|
+
this.sideEffectCounter,
|
|
108
|
+
);
|
|
113
109
|
|
|
110
|
+
const fields = [...privateContextInputs.toFields(), ...args];
|
|
114
111
|
return toACVMWitness(0, fields);
|
|
115
112
|
}
|
|
116
113
|
|
|
@@ -142,6 +139,10 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
142
139
|
return this.newNotes;
|
|
143
140
|
}
|
|
144
141
|
|
|
142
|
+
public getNullifiedNoteHashCounters() {
|
|
143
|
+
return this.nullifiedNoteHashCounters;
|
|
144
|
+
}
|
|
145
|
+
|
|
145
146
|
/**
|
|
146
147
|
* Return the encrypted logs emitted during this execution.
|
|
147
148
|
*/
|
|
@@ -171,10 +172,10 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
171
172
|
}
|
|
172
173
|
|
|
173
174
|
/**
|
|
174
|
-
* Pack the given arguments.
|
|
175
|
+
* Pack the given array of arguments.
|
|
175
176
|
* @param args - Arguments to pack
|
|
176
177
|
*/
|
|
177
|
-
public
|
|
178
|
+
public override packArgumentsArray(args: Fr[]): Promise<Fr> {
|
|
178
179
|
return Promise.resolve(this.packedValuesCache.pack(args));
|
|
179
180
|
}
|
|
180
181
|
|
|
@@ -182,7 +183,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
182
183
|
* Pack the given returns.
|
|
183
184
|
* @param returns - Returns to pack
|
|
184
185
|
*/
|
|
185
|
-
public packReturns(returns: Fr[]): Promise<Fr> {
|
|
186
|
+
public override packReturns(returns: Fr[]): Promise<Fr> {
|
|
186
187
|
return Promise.resolve(this.packedValuesCache.pack(returns));
|
|
187
188
|
}
|
|
188
189
|
|
|
@@ -190,7 +191,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
190
191
|
* Unpack the given returns.
|
|
191
192
|
* @param returnsHash - Returns hash to unpack
|
|
192
193
|
*/
|
|
193
|
-
public unpackReturns(returnsHash: Fr): Promise<Fr[]> {
|
|
194
|
+
public override unpackReturns(returnsHash: Fr): Promise<Fr[]> {
|
|
194
195
|
return Promise.resolve(this.packedValuesCache.unpack(returnsHash));
|
|
195
196
|
}
|
|
196
197
|
|
|
@@ -214,7 +215,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
214
215
|
* @param status - The status of notes to fetch.
|
|
215
216
|
* @returns Array of note data.
|
|
216
217
|
*/
|
|
217
|
-
public async getNotes(
|
|
218
|
+
public override async getNotes(
|
|
218
219
|
storageSlot: Fr,
|
|
219
220
|
numSelects: number,
|
|
220
221
|
selectByIndexes: number[],
|
|
@@ -260,7 +261,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
260
261
|
notes.forEach(n => {
|
|
261
262
|
if (n.index !== undefined) {
|
|
262
263
|
const siloedNoteHash = siloNoteHash(n.contractAddress, n.innerNoteHash);
|
|
263
|
-
const uniqueSiloedNoteHash =
|
|
264
|
+
const uniqueSiloedNoteHash = computeUniqueNoteHash(n.nonce, siloedNoteHash);
|
|
264
265
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386)
|
|
265
266
|
// Should always be uniqueSiloedNoteHash when publicly created notes include nonces.
|
|
266
267
|
const noteHashForReadRequest = n.nonce.isZero() ? siloedNoteHash : uniqueSiloedNoteHash;
|
|
@@ -281,16 +282,25 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
281
282
|
* @param innerNoteHash - The inner note hash of the new note.
|
|
282
283
|
* @returns
|
|
283
284
|
*/
|
|
284
|
-
public notifyCreatedNote(
|
|
285
|
+
public override notifyCreatedNote(
|
|
286
|
+
storageSlot: Fr,
|
|
287
|
+
noteTypeId: Fr,
|
|
288
|
+
noteItems: Fr[],
|
|
289
|
+
innerNoteHash: Fr,
|
|
290
|
+
counter: number,
|
|
291
|
+
) {
|
|
285
292
|
const note = new Note(noteItems);
|
|
286
|
-
this.noteCache.addNewNote(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
293
|
+
this.noteCache.addNewNote(
|
|
294
|
+
{
|
|
295
|
+
contractAddress: this.callContext.storageContractAddress,
|
|
296
|
+
storageSlot,
|
|
297
|
+
nonce: Fr.ZERO, // Nonce cannot be known during private execution.
|
|
298
|
+
note,
|
|
299
|
+
siloedNullifier: undefined, // Siloed nullifier cannot be known for newly created note.
|
|
300
|
+
innerNoteHash,
|
|
301
|
+
},
|
|
302
|
+
counter,
|
|
303
|
+
);
|
|
294
304
|
this.newNotes.push({
|
|
295
305
|
storageSlot,
|
|
296
306
|
noteTypeId,
|
|
@@ -304,8 +314,15 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
304
314
|
* @param innerNullifier - The pending nullifier to add in the list (not yet siloed by contract address).
|
|
305
315
|
* @param innerNoteHash - The inner note hash of the new note.
|
|
306
316
|
*/
|
|
307
|
-
public notifyNullifiedNote(innerNullifier: Fr, innerNoteHash: Fr) {
|
|
308
|
-
this.noteCache.nullifyNote(
|
|
317
|
+
public override notifyNullifiedNote(innerNullifier: Fr, innerNoteHash: Fr, counter: number) {
|
|
318
|
+
const nullifiedNoteHashCounter = this.noteCache.nullifyNote(
|
|
319
|
+
this.callContext.storageContractAddress,
|
|
320
|
+
innerNullifier,
|
|
321
|
+
innerNoteHash,
|
|
322
|
+
);
|
|
323
|
+
if (nullifiedNoteHashCounter !== undefined) {
|
|
324
|
+
this.nullifiedNoteHashCounters.push({ noteHashCounter: nullifiedNoteHashCounter, nullifierCounter: counter });
|
|
325
|
+
}
|
|
309
326
|
return Promise.resolve();
|
|
310
327
|
}
|
|
311
328
|
|
|
@@ -317,22 +334,31 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
317
334
|
* @param publicKey - The public key of the account that can decrypt the log.
|
|
318
335
|
* @param log - The log contents.
|
|
319
336
|
*/
|
|
320
|
-
public emitEncryptedLog(
|
|
337
|
+
public override emitEncryptedLog(
|
|
338
|
+
contractAddress: AztecAddress,
|
|
339
|
+
storageSlot: Fr,
|
|
340
|
+
noteTypeId: Fr,
|
|
341
|
+
publicKey: Point,
|
|
342
|
+
log: Fr[],
|
|
343
|
+
) {
|
|
321
344
|
const note = new Note(log);
|
|
322
345
|
const l1NotePayload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId);
|
|
323
346
|
const taggedNote = new TaggedNote(l1NotePayload);
|
|
324
|
-
const encryptedNote = taggedNote.toEncryptedBuffer(publicKey
|
|
325
|
-
|
|
347
|
+
const encryptedNote = taggedNote.toEncryptedBuffer(publicKey);
|
|
348
|
+
const encryptedLog = new EncryptedL2Log(encryptedNote);
|
|
349
|
+
this.encryptedLogs.push(encryptedLog);
|
|
350
|
+
return Fr.fromBuffer(encryptedLog.hash());
|
|
326
351
|
}
|
|
327
352
|
|
|
328
353
|
/**
|
|
329
354
|
* Emit an unencrypted log.
|
|
330
355
|
* @param log - The unencrypted log to be emitted.
|
|
331
356
|
*/
|
|
332
|
-
public emitUnencryptedLog(log: UnencryptedL2Log) {
|
|
357
|
+
public override emitUnencryptedLog(log: UnencryptedL2Log) {
|
|
333
358
|
this.unencryptedLogs.push(log);
|
|
334
359
|
const text = log.toHumanReadable();
|
|
335
360
|
this.log.verbose(`Emitted unencrypted log: "${text.length > 100 ? text.slice(0, 100) + '...' : text}"`);
|
|
361
|
+
return Fr.fromBuffer(log.hash());
|
|
336
362
|
}
|
|
337
363
|
|
|
338
364
|
#checkValidStaticCall(childExecutionResult: ExecutionResult) {
|
|
@@ -357,7 +383,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
357
383
|
* @param isStaticCall - Whether the call is a delegate call.
|
|
358
384
|
* @returns The execution result.
|
|
359
385
|
*/
|
|
360
|
-
async callPrivateFunction(
|
|
386
|
+
override async callPrivateFunction(
|
|
361
387
|
targetContractAddress: AztecAddress,
|
|
362
388
|
functionSelector: FunctionSelector,
|
|
363
389
|
argsHash: Fr,
|
|
@@ -374,9 +400,9 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
374
400
|
const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
375
401
|
const targetFunctionData = FunctionData.fromAbi(targetArtifact);
|
|
376
402
|
|
|
377
|
-
const derivedTxContext =
|
|
403
|
+
const derivedTxContext = this.txContext.clone();
|
|
378
404
|
|
|
379
|
-
const derivedCallContext =
|
|
405
|
+
const derivedCallContext = this.deriveCallContext(
|
|
380
406
|
targetContractAddress,
|
|
381
407
|
targetArtifact,
|
|
382
408
|
sideEffectCounter,
|
|
@@ -394,7 +420,6 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
394
420
|
this.packedValuesCache,
|
|
395
421
|
this.noteCache,
|
|
396
422
|
this.db,
|
|
397
|
-
this.curve,
|
|
398
423
|
this.node,
|
|
399
424
|
sideEffectCounter,
|
|
400
425
|
);
|
|
@@ -426,7 +451,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
426
451
|
* @param isStaticCall - Whether the call is a static call.
|
|
427
452
|
* @returns The public call stack item with the request information.
|
|
428
453
|
*/
|
|
429
|
-
public async enqueuePublicFunctionCall(
|
|
454
|
+
public override async enqueuePublicFunctionCall(
|
|
430
455
|
targetContractAddress: AztecAddress,
|
|
431
456
|
functionSelector: FunctionSelector,
|
|
432
457
|
argsHash: Fr,
|
|
@@ -437,7 +462,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
437
462
|
isStaticCall = isStaticCall || this.callContext.isStaticCall;
|
|
438
463
|
|
|
439
464
|
const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
440
|
-
const derivedCallContext =
|
|
465
|
+
const derivedCallContext = this.deriveCallContext(
|
|
441
466
|
targetContractAddress,
|
|
442
467
|
targetArtifact,
|
|
443
468
|
sideEffectCounter,
|
|
@@ -475,25 +500,20 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
475
500
|
* @param isStaticCall - Whether the call is a static call.
|
|
476
501
|
* @returns The derived call context.
|
|
477
502
|
*/
|
|
478
|
-
private
|
|
503
|
+
private deriveCallContext(
|
|
479
504
|
targetContractAddress: AztecAddress,
|
|
480
505
|
targetArtifact: FunctionArtifact,
|
|
481
506
|
startSideEffectCounter: number,
|
|
482
507
|
isDelegateCall = false,
|
|
483
508
|
isStaticCall = false,
|
|
484
509
|
) {
|
|
485
|
-
const portalContractAddress = await this.db.getPortalContractAddress(targetContractAddress);
|
|
486
510
|
return new CallContext(
|
|
487
511
|
isDelegateCall ? this.callContext.msgSender : this.contractAddress,
|
|
488
512
|
isDelegateCall ? this.contractAddress : targetContractAddress,
|
|
489
|
-
portalContractAddress,
|
|
490
513
|
FunctionSelector.fromNameAndParameters(targetArtifact.name, targetArtifact.parameters),
|
|
491
|
-
this.callContext.gasLeft, // TODO(palla/gas): We should deduct DA and L1 gas used for the derived context
|
|
492
514
|
isDelegateCall,
|
|
493
515
|
isStaticCall,
|
|
494
516
|
startSideEffectCounter,
|
|
495
|
-
this.callContext.gasSettings,
|
|
496
|
-
this.callContext.transactionFee,
|
|
497
517
|
);
|
|
498
518
|
}
|
|
499
519
|
|
|
@@ -502,7 +522,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
502
522
|
* @param startStorageSlot - The starting storage slot.
|
|
503
523
|
* @param numberOfElements - Number of elements to read from the starting storage slot.
|
|
504
524
|
*/
|
|
505
|
-
public async storageRead(startStorageSlot: Fr, numberOfElements: number): Promise<Fr[]> {
|
|
525
|
+
public override async storageRead(startStorageSlot: Fr, numberOfElements: number): Promise<Fr[]> {
|
|
506
526
|
// TODO(#4320): This is a hack to work around not having directly access to the public data tree but
|
|
507
527
|
// still having access to the witnesses
|
|
508
528
|
const bn = await this.db.getBlockNumber();
|
|
@@ -521,4 +541,9 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
521
541
|
}
|
|
522
542
|
return values;
|
|
523
543
|
}
|
|
544
|
+
|
|
545
|
+
public override aes128Encrypt(input: Buffer, initializationVector: Buffer, key: Buffer): Buffer {
|
|
546
|
+
const aes128 = new Aes128();
|
|
547
|
+
return aes128.encryptBufferCBC(input, initializationVector, key);
|
|
548
|
+
}
|
|
524
549
|
}
|
package/src/client/db_oracle.ts
CHANGED
|
@@ -8,11 +8,10 @@ import {
|
|
|
8
8
|
import { type CompleteAddress, type Header } from '@aztec/circuits.js';
|
|
9
9
|
import { type FunctionArtifactWithDebugMetadata, type FunctionSelector } from '@aztec/foundation/abi';
|
|
10
10
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
11
|
-
import { type EthAddress } from '@aztec/foundation/eth-address';
|
|
12
11
|
import { type Fr } from '@aztec/foundation/fields';
|
|
13
12
|
import { type ContractInstance } from '@aztec/types/contracts';
|
|
14
13
|
|
|
15
|
-
import { type
|
|
14
|
+
import { type NoteData, type NullifierKeys } from '../acvm/index.js';
|
|
16
15
|
import { type CommitmentsDB } from '../public/db.js';
|
|
17
16
|
|
|
18
17
|
/**
|
|
@@ -66,16 +65,14 @@ export interface DBOracle extends CommitmentsDB {
|
|
|
66
65
|
popCapsule(): Promise<Fr[]>;
|
|
67
66
|
|
|
68
67
|
/**
|
|
69
|
-
* Retrieve
|
|
70
|
-
* The function only allows access to the secret keys of the transaction creator,
|
|
71
|
-
* and throws an error if the address does not match the account address of the key pair.
|
|
68
|
+
* Retrieve nullifier keys associated with a specific account and app/contract address.
|
|
72
69
|
*
|
|
73
70
|
* @param accountAddress - The account address.
|
|
74
71
|
* @param contractAddress - The contract address.
|
|
75
|
-
* @returns A Promise that resolves to
|
|
76
|
-
* @throws An
|
|
72
|
+
* @returns A Promise that resolves to nullifier keys of a requested account and contract.
|
|
73
|
+
* @throws An error if the account is not registered in the database.
|
|
77
74
|
*/
|
|
78
|
-
|
|
75
|
+
getNullifierKeys(accountAddress: AztecAddress, contractAddress: AztecAddress): Promise<NullifierKeys>;
|
|
79
76
|
|
|
80
77
|
/**
|
|
81
78
|
* Retrieves a set of notes stored in the database for a given contract address and storage slot.
|
|
@@ -115,15 +112,6 @@ export interface DBOracle extends CommitmentsDB {
|
|
|
115
112
|
functionName: string,
|
|
116
113
|
): Promise<FunctionArtifactWithDebugMetadata | undefined>;
|
|
117
114
|
|
|
118
|
-
/**
|
|
119
|
-
* Retrieves the portal contract address associated with the given contract address.
|
|
120
|
-
* Throws an error if the input contract address is not found or invalid.
|
|
121
|
-
*
|
|
122
|
-
* @param contractAddress - The address of the contract whose portal address is to be fetched.
|
|
123
|
-
* @returns A Promise that resolves to an EthAddress instance, representing the portal contract address.
|
|
124
|
-
*/
|
|
125
|
-
getPortalContractAddress(contractAddress: AztecAddress): Promise<EthAddress>;
|
|
126
|
-
|
|
127
115
|
/**
|
|
128
116
|
* Gets the index of a nullifier in the nullifier tree.
|
|
129
117
|
* @param nullifier - The nullifier.
|
|
@@ -4,6 +4,11 @@ import { Fr } from '@aztec/foundation/fields';
|
|
|
4
4
|
|
|
5
5
|
import { type NoteData } from '../acvm/index.js';
|
|
6
6
|
|
|
7
|
+
export interface PendingNote {
|
|
8
|
+
note: NoteData;
|
|
9
|
+
counter: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
/**
|
|
8
13
|
* Data that's accessible by all the function calls in an execution.
|
|
9
14
|
*/
|
|
@@ -12,7 +17,7 @@ export class ExecutionNoteCache {
|
|
|
12
17
|
* New notes created in this transaction.
|
|
13
18
|
* This mapping maps from a contract address to the notes in the contract.
|
|
14
19
|
*/
|
|
15
|
-
private newNotes: Map<bigint,
|
|
20
|
+
private newNotes: Map<bigint, PendingNote[]> = new Map();
|
|
16
21
|
|
|
17
22
|
/**
|
|
18
23
|
* The list of nullifiers created in this transaction.
|
|
@@ -26,9 +31,9 @@ export class ExecutionNoteCache {
|
|
|
26
31
|
* Add a new note to cache.
|
|
27
32
|
* @param note - New note created during execution.
|
|
28
33
|
*/
|
|
29
|
-
public addNewNote(note: NoteData) {
|
|
34
|
+
public addNewNote(note: NoteData, counter: number) {
|
|
30
35
|
const notes = this.newNotes.get(note.contractAddress.toBigInt()) ?? [];
|
|
31
|
-
notes.push(note);
|
|
36
|
+
notes.push({ note, counter });
|
|
32
37
|
this.newNotes.set(note.contractAddress.toBigInt(), notes);
|
|
33
38
|
}
|
|
34
39
|
|
|
@@ -46,16 +51,20 @@ export class ExecutionNoteCache {
|
|
|
46
51
|
nullifiers.add(siloedNullifier.value);
|
|
47
52
|
this.nullifiers.set(contractAddress.toBigInt(), nullifiers);
|
|
48
53
|
|
|
54
|
+
let nullifiedNoteHashCounter: number | undefined = undefined;
|
|
49
55
|
// Find and remove the matching new note if the emitted innerNoteHash is not empty.
|
|
50
56
|
if (!innerNoteHash.equals(Fr.ZERO)) {
|
|
51
57
|
const notes = this.newNotes.get(contractAddress.toBigInt()) ?? [];
|
|
52
|
-
const noteIndexToRemove = notes.findIndex(n => n.innerNoteHash.equals(innerNoteHash));
|
|
58
|
+
const noteIndexToRemove = notes.findIndex(n => n.note.innerNoteHash.equals(innerNoteHash));
|
|
53
59
|
if (noteIndexToRemove === -1) {
|
|
54
60
|
throw new Error('Attempt to remove a pending note that does not exist.');
|
|
55
61
|
}
|
|
56
|
-
notes.splice(noteIndexToRemove, 1);
|
|
62
|
+
const note = notes.splice(noteIndexToRemove, 1)[0];
|
|
63
|
+
nullifiedNoteHashCounter = note.counter;
|
|
57
64
|
this.newNotes.set(contractAddress.toBigInt(), notes);
|
|
58
65
|
}
|
|
66
|
+
|
|
67
|
+
return nullifiedNoteHashCounter;
|
|
59
68
|
}
|
|
60
69
|
|
|
61
70
|
/**
|
|
@@ -66,7 +75,7 @@ export class ExecutionNoteCache {
|
|
|
66
75
|
**/
|
|
67
76
|
public getNotes(contractAddress: AztecAddress, storageSlot: Fr) {
|
|
68
77
|
const notes = this.newNotes.get(contractAddress.toBigInt()) ?? [];
|
|
69
|
-
return notes.filter(n => n.storageSlot.equals(storageSlot));
|
|
78
|
+
return notes.filter(n => n.note.storageSlot.equals(storageSlot)).map(n => n.note);
|
|
70
79
|
}
|
|
71
80
|
|
|
72
81
|
/**
|
|
@@ -77,7 +86,7 @@ export class ExecutionNoteCache {
|
|
|
77
86
|
**/
|
|
78
87
|
public checkNoteExists(contractAddress: AztecAddress, innerNoteHash: Fr) {
|
|
79
88
|
const notes = this.newNotes.get(contractAddress.toBigInt()) ?? [];
|
|
80
|
-
return notes.some(n => n.innerNoteHash.equals(innerNoteHash));
|
|
89
|
+
return notes.some(n => n.note.innerNoteHash.equals(innerNoteHash));
|
|
81
90
|
}
|
|
82
91
|
|
|
83
92
|
/**
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
type PrivateCallStackItem,
|
|
5
5
|
type PublicCallRequest,
|
|
6
6
|
} from '@aztec/circuits.js';
|
|
7
|
-
import { type DecodedReturn } from '@aztec/foundation/abi';
|
|
8
7
|
import { type Fr } from '@aztec/foundation/fields';
|
|
9
8
|
|
|
10
9
|
import { type ACVMField } from '../acvm/index.js';
|
|
@@ -21,6 +20,11 @@ export interface NoteAndSlot {
|
|
|
21
20
|
noteTypeId: Fr;
|
|
22
21
|
}
|
|
23
22
|
|
|
23
|
+
export interface NullifiedNoteHashCounter {
|
|
24
|
+
noteHashCounter: number;
|
|
25
|
+
nullifierCounter: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
/**
|
|
25
29
|
* The result of executing a private function.
|
|
26
30
|
*/
|
|
@@ -37,27 +41,34 @@ export interface ExecutionResult {
|
|
|
37
41
|
callStackItem: PrivateCallStackItem;
|
|
38
42
|
/** The partially filled-in read request membership witnesses for commitments being read. */
|
|
39
43
|
noteHashReadRequestPartialWitnesses: NoteHashReadRequestMembershipWitness[];
|
|
40
|
-
// Needed when we enable chained txs. The new notes can be cached and used in a later transaction.
|
|
41
44
|
/** The notes created in the executed function. */
|
|
42
45
|
newNotes: NoteAndSlot[];
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
nullifiedNoteHashCounters: NullifiedNoteHashCounter[];
|
|
47
|
+
/** The raw return values of the executed function. */
|
|
48
|
+
returnValues: Fr[];
|
|
45
49
|
/** The nested executions. */
|
|
46
50
|
nestedExecutions: this[];
|
|
47
51
|
/** Enqueued public function execution requests to be picked up by the sequencer. */
|
|
48
52
|
enqueuedPublicFunctionCalls: PublicCallRequest[];
|
|
49
53
|
/**
|
|
50
54
|
* Encrypted logs emitted during execution of this function call.
|
|
51
|
-
* Note: These are preimages to `
|
|
55
|
+
* Note: These are preimages to `encryptedLogsHashes`.
|
|
52
56
|
*/
|
|
53
57
|
encryptedLogs: EncryptedFunctionL2Logs;
|
|
54
58
|
/**
|
|
55
59
|
* Unencrypted logs emitted during execution of this function call.
|
|
56
|
-
* Note: These are preimages to `
|
|
60
|
+
* Note: These are preimages to `unencryptedLogsHashes`.
|
|
57
61
|
*/
|
|
58
62
|
unencryptedLogs: UnencryptedFunctionL2Logs;
|
|
59
63
|
}
|
|
60
64
|
|
|
65
|
+
export function collectNullifiedNoteHashCounters(execResult: ExecutionResult): NullifiedNoteHashCounter[] {
|
|
66
|
+
return [
|
|
67
|
+
execResult.nullifiedNoteHashCounters,
|
|
68
|
+
...execResult.nestedExecutions.flatMap(collectNullifiedNoteHashCounters),
|
|
69
|
+
].flat();
|
|
70
|
+
}
|
|
71
|
+
|
|
61
72
|
/**
|
|
62
73
|
* Collect all encrypted logs across all nested executions.
|
|
63
74
|
* @param execResult - The topmost execution result.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FunctionData, PrivateCallStackItem, PrivateCircuitPublicInputs } from '@aztec/circuits.js';
|
|
2
|
-
import { type
|
|
2
|
+
import { type FunctionArtifactWithDebugMetadata } from '@aztec/foundation/abi';
|
|
3
3
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
@@ -46,24 +46,18 @@ export async function executePrivateFunction(
|
|
|
46
46
|
const encryptedLogs = context.getEncryptedLogs();
|
|
47
47
|
const unencryptedLogs = context.getUnencryptedLogs();
|
|
48
48
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) --> set this in Noir
|
|
49
|
-
publicInputs.encryptedLogsHash = Fr.fromBuffer(encryptedLogs.hash());
|
|
50
49
|
publicInputs.encryptedLogPreimagesLength = new Fr(encryptedLogs.getSerializedLength());
|
|
51
|
-
publicInputs.unencryptedLogsHash = Fr.fromBuffer(unencryptedLogs.hash());
|
|
52
50
|
publicInputs.unencryptedLogPreimagesLength = new Fr(unencryptedLogs.getSerializedLength());
|
|
53
51
|
|
|
54
52
|
const callStackItem = new PrivateCallStackItem(contractAddress, functionData, publicInputs);
|
|
55
53
|
|
|
56
|
-
// Mocking the return type to be an array of 4 fields
|
|
57
|
-
// TODO: @LHerskind must be updated as we are progressing with the macros to get the information
|
|
58
54
|
const rawReturnValues = await context.unpackReturns(publicInputs.returnsHash);
|
|
59
|
-
const returnTypes: AbiType[] = [{ kind: 'array', length: rawReturnValues.length, type: { kind: 'field' } }];
|
|
60
|
-
const mockArtifact = { ...artifact, returnTypes };
|
|
61
|
-
const returnValues = decodeReturnValues(mockArtifact, rawReturnValues);
|
|
62
55
|
|
|
63
56
|
const noteHashReadRequestPartialWitnesses = context.getNoteHashReadRequestPartialWitnesses(
|
|
64
57
|
publicInputs.noteHashReadRequests,
|
|
65
58
|
);
|
|
66
59
|
const newNotes = context.getNewNotes();
|
|
60
|
+
const nullifiedNoteHashCounters = context.getNullifiedNoteHashCounters();
|
|
67
61
|
const nestedExecutions = context.getNestedExecutions();
|
|
68
62
|
const enqueuedPublicFunctionCalls = context.getEnqueuedPublicFunctionCalls();
|
|
69
63
|
|
|
@@ -73,9 +67,10 @@ export async function executePrivateFunction(
|
|
|
73
67
|
acir,
|
|
74
68
|
partialWitness,
|
|
75
69
|
callStackItem,
|
|
76
|
-
returnValues,
|
|
70
|
+
returnValues: rawReturnValues,
|
|
77
71
|
noteHashReadRequestPartialWitnesses,
|
|
78
72
|
newNotes,
|
|
73
|
+
nullifiedNoteHashCounters,
|
|
79
74
|
vk: Buffer.from(artifact.verificationKey!, 'hex'),
|
|
80
75
|
nestedExecutions,
|
|
81
76
|
enqueuedPublicFunctionCalls,
|
package/src/client/simulator.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type AztecNode, type FunctionCall, type Note, type TxExecutionRequest } from '@aztec/circuit-types';
|
|
2
2
|
import { CallContext, FunctionData } from '@aztec/circuits.js';
|
|
3
|
-
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
4
3
|
import {
|
|
5
4
|
type ArrayType,
|
|
6
5
|
type FunctionArtifactWithDebugMetadata,
|
|
@@ -9,7 +8,6 @@ import {
|
|
|
9
8
|
encodeArguments,
|
|
10
9
|
} from '@aztec/foundation/abi';
|
|
11
10
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
12
|
-
import { type EthAddress } from '@aztec/foundation/eth-address';
|
|
13
11
|
import { Fr } from '@aztec/foundation/fields';
|
|
14
12
|
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
15
13
|
|
|
@@ -61,7 +59,6 @@ export class AcirSimulator {
|
|
|
61
59
|
* @param request - The transaction request.
|
|
62
60
|
* @param entryPointArtifact - The artifact of the entry point function.
|
|
63
61
|
* @param contractAddress - The address of the contract (should match request.origin)
|
|
64
|
-
* @param portalContractAddress - The address of the portal contract.
|
|
65
62
|
* @param msgSender - The address calling the function. This can be replaced to simulate a call from another contract or a specific account.
|
|
66
63
|
* @returns The result of the execution.
|
|
67
64
|
*/
|
|
@@ -69,7 +66,6 @@ export class AcirSimulator {
|
|
|
69
66
|
request: TxExecutionRequest,
|
|
70
67
|
entryPointArtifact: FunctionArtifactWithDebugMetadata,
|
|
71
68
|
contractAddress: AztecAddress,
|
|
72
|
-
portalContractAddress: EthAddress,
|
|
73
69
|
msgSender = AztecAddress.ZERO,
|
|
74
70
|
): Promise<ExecutionResult> {
|
|
75
71
|
if (entryPointArtifact.functionType !== FunctionType.SECRET) {
|
|
@@ -82,37 +78,29 @@ export class AcirSimulator {
|
|
|
82
78
|
);
|
|
83
79
|
}
|
|
84
80
|
|
|
85
|
-
const curve = new Grumpkin();
|
|
86
|
-
|
|
87
81
|
const header = await this.db.getHeader();
|
|
88
82
|
|
|
89
83
|
// reserve the first side effect for the tx hash (inserted by the private kernel)
|
|
90
84
|
const startSideEffectCounter = 1;
|
|
91
85
|
|
|
92
|
-
const transactionFee = Fr.ZERO;
|
|
93
86
|
const callContext = new CallContext(
|
|
94
87
|
msgSender,
|
|
95
88
|
contractAddress,
|
|
96
|
-
portalContractAddress,
|
|
97
89
|
FunctionSelector.fromNameAndParameters(entryPointArtifact.name, entryPointArtifact.parameters),
|
|
98
|
-
request.gasSettings.getInitialAvailable(),
|
|
99
90
|
false,
|
|
100
91
|
false,
|
|
101
92
|
startSideEffectCounter,
|
|
102
|
-
request.gasSettings,
|
|
103
|
-
transactionFee,
|
|
104
93
|
);
|
|
105
94
|
const context = new ClientExecutionContext(
|
|
106
95
|
contractAddress,
|
|
107
|
-
request.
|
|
96
|
+
request.firstCallArgsHash,
|
|
108
97
|
request.txContext,
|
|
109
98
|
callContext,
|
|
110
99
|
header,
|
|
111
100
|
request.authWitnesses,
|
|
112
|
-
PackedValuesCache.create(request.
|
|
101
|
+
PackedValuesCache.create(request.argsOfCalls),
|
|
113
102
|
new ExecutionNoteCache(),
|
|
114
103
|
this.db,
|
|
115
|
-
curve,
|
|
116
104
|
this.node,
|
|
117
105
|
startSideEffectCounter,
|
|
118
106
|
);
|
|
@@ -143,7 +131,7 @@ export class AcirSimulator {
|
|
|
143
131
|
contractAddress: AztecAddress,
|
|
144
132
|
) {
|
|
145
133
|
if (entryPointArtifact.functionType !== FunctionType.UNCONSTRAINED) {
|
|
146
|
-
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as
|
|
134
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as unconstrained`);
|
|
147
135
|
}
|
|
148
136
|
|
|
149
137
|
const context = new ViewDataOracle(contractAddress, [], this.db, this.node);
|