@aztec/simulator 0.59.0 → 0.60.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/acvm.d.ts +1 -0
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.d.ts +3 -3
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +7 -7
- package/dest/acvm/oracle/typed_oracle.d.ts +4 -3
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +4 -4
- package/dest/acvm/serialize.d.ts +1 -0
- package/dest/acvm/serialize.d.ts.map +1 -1
- package/dest/avm/avm_context.d.ts +1 -1
- package/dest/avm/avm_context.js +1 -1
- package/dest/avm/avm_execution_environment.d.ts +2 -5
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +7 -15
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +1 -8
- package/dest/avm/avm_memory_types.d.ts +1 -0
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_simulator.d.ts +1 -0
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/bytecode_utils.d.ts +1 -0
- package/dest/avm/bytecode_utils.d.ts.map +1 -1
- package/dest/avm/fixtures/index.d.ts +3 -0
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +8 -2
- package/dest/avm/journal/journal.d.ts +14 -13
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +33 -33
- package/dest/avm/journal/nullifiers.d.ts +9 -9
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +24 -24
- package/dest/avm/journal/public_storage.d.ts +10 -10
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +21 -21
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +5 -5
- package/dest/avm/opcodes/environment_getters.d.ts +12 -13
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +13 -16
- package/dest/avm/opcodes/hashing.d.ts +2 -26
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +11 -95
- package/dest/avm/opcodes/index.d.ts +0 -1
- package/dest/avm/opcodes/index.d.ts.map +1 -1
- package/dest/avm/opcodes/index.js +1 -2
- package/dest/avm/opcodes/instruction.d.ts +1 -0
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +3 -3
- package/dest/avm/serialization/buffer_cursor.d.ts +1 -0
- package/dest/avm/serialization/buffer_cursor.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.d.ts +1 -0
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +2 -6
- package/dest/avm/serialization/instruction_serialization.d.ts +11 -14
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +11 -15
- package/dest/avm/test_utils.d.ts +1 -0
- package/dest/avm/test_utils.d.ts.map +1 -1
- package/dest/client/client_execution_context.d.ts +9 -10
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +30 -33
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +3 -4
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +3 -3
- package/dest/mocks/fixtures.js +2 -2
- package/dest/providers/acvm_native.d.ts +1 -0
- package/dest/providers/acvm_native.d.ts.map +1 -1
- package/dest/public/db_interfaces.d.ts +1 -0
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/dual_side_effect_trace.d.ts +7 -6
- package/dest/public/dual_side_effect_trace.d.ts.map +1 -1
- package/dest/public/dual_side_effect_trace.js +19 -19
- package/dest/public/enqueued_call_side_effect_trace.d.ts +7 -6
- package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
- package/dest/public/enqueued_call_side_effect_trace.js +15 -17
- package/dest/public/enqueued_call_simulator.d.ts +1 -1
- package/dest/public/enqueued_call_simulator.d.ts.map +1 -1
- package/dest/public/enqueued_call_simulator.js +11 -12
- package/dest/public/enqueued_calls_processor.d.ts.map +1 -1
- package/dest/public/enqueued_calls_processor.js +2 -2
- package/dest/public/execution.d.ts +1 -0
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +2 -2
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +6 -5
- package/dest/public/public_db_sources.d.ts +1 -0
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/side_effect_trace.d.ts +7 -6
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +14 -15
- package/dest/public/side_effect_trace_interface.d.ts +7 -6
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/acvm/oracle/oracle.ts +0 -6
- package/src/acvm/oracle/typed_oracle.ts +0 -3
- package/src/avm/avm_context.ts +1 -1
- package/src/avm/avm_execution_environment.ts +0 -15
- package/src/avm/avm_gas.ts +0 -7
- package/src/avm/fixtures/index.ts +7 -2
- package/src/avm/journal/journal.ts +32 -32
- package/src/avm/journal/nullifiers.ts +23 -23
- package/src/avm/journal/public_storage.ts +20 -20
- package/src/avm/opcodes/accrued_substate.ts +4 -8
- package/src/avm/opcodes/environment_getters.ts +0 -3
- package/src/avm/opcodes/hashing.ts +9 -122
- package/src/avm/opcodes/index.ts +0 -1
- package/src/avm/opcodes/storage.ts +2 -2
- package/src/avm/serialization/bytecode_serialization.ts +0 -7
- package/src/avm/serialization/instruction_serialization.ts +0 -4
- package/src/client/client_execution_context.ts +21 -44
- package/src/client/private_execution.ts +1 -9
- package/src/client/simulator.ts +0 -2
- package/src/mocks/fixtures.ts +1 -1
- package/src/public/dual_side_effect_trace.ts +18 -18
- package/src/public/enqueued_call_side_effect_trace.ts +14 -20
- package/src/public/enqueued_call_simulator.ts +10 -23
- package/src/public/enqueued_calls_processor.ts +1 -3
- package/src/public/execution.ts +1 -1
- package/src/public/executor.ts +11 -5
- package/src/public/side_effect_trace.ts +19 -14
- package/src/public/side_effect_trace_interface.ts +6 -6
- package/dest/avm/opcodes/commitment.d.ts +0 -16
- package/dest/avm/opcodes/commitment.d.ts.map +0 -1
- package/dest/avm/opcodes/commitment.js +0 -51
- package/src/avm/opcodes/commitment.ts +0 -65
|
@@ -68,7 +68,6 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
68
68
|
private publicTeardownFunctionCall: PublicExecutionRequest = PublicExecutionRequest.empty();
|
|
69
69
|
|
|
70
70
|
constructor(
|
|
71
|
-
contractAddress: AztecAddress,
|
|
72
71
|
private readonly argsHash: Fr,
|
|
73
72
|
private readonly txContext: TxContext,
|
|
74
73
|
private readonly callContext: CallContext,
|
|
@@ -84,7 +83,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
84
83
|
log = createDebugLogger('aztec:simulator:client_execution_context'),
|
|
85
84
|
scopes?: AztecAddress[],
|
|
86
85
|
) {
|
|
87
|
-
super(contractAddress, authWitnesses, db, node, log, scopes);
|
|
86
|
+
super(callContext.contractAddress, authWitnesses, db, node, log, scopes);
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
// We still need this function until we can get user-defined ordering of structs for fn arguments
|
|
@@ -240,10 +239,10 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
240
239
|
status: NoteStatus,
|
|
241
240
|
): Promise<NoteData[]> {
|
|
242
241
|
// Nullified pending notes are already removed from the list.
|
|
243
|
-
const pendingNotes = this.noteCache.getNotes(this.callContext.
|
|
242
|
+
const pendingNotes = this.noteCache.getNotes(this.callContext.contractAddress, storageSlot);
|
|
244
243
|
|
|
245
|
-
const pendingNullifiers = this.noteCache.getNullifiers(this.callContext.
|
|
246
|
-
const dbNotes = await this.db.getNotes(this.callContext.
|
|
244
|
+
const pendingNullifiers = this.noteCache.getNullifiers(this.callContext.contractAddress);
|
|
245
|
+
const dbNotes = await this.db.getNotes(this.callContext.contractAddress, storageSlot, status, this.scopes);
|
|
247
246
|
const dbNotesFiltered = dbNotes.filter(n => !pendingNullifiers.has((n.siloedNullifier as Fr).value));
|
|
248
247
|
|
|
249
248
|
const notes = pickNotes<NoteData>([...dbNotesFiltered, ...pendingNotes], {
|
|
@@ -261,7 +260,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
261
260
|
});
|
|
262
261
|
|
|
263
262
|
this.log.debug(
|
|
264
|
-
`Returning ${notes.length} notes for ${this.callContext.
|
|
263
|
+
`Returning ${notes.length} notes for ${this.callContext.contractAddress} at ${storageSlot}: ${notes
|
|
265
264
|
.map(n => `${n.nonce.toString()}:[${n.note.items.map(i => i.toString()).join(',')}]`)
|
|
266
265
|
.join(', ')}`,
|
|
267
266
|
);
|
|
@@ -297,7 +296,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
297
296
|
const note = new Note(noteItems);
|
|
298
297
|
this.noteCache.addNewNote(
|
|
299
298
|
{
|
|
300
|
-
contractAddress: this.callContext.
|
|
299
|
+
contractAddress: this.callContext.contractAddress,
|
|
301
300
|
storageSlot,
|
|
302
301
|
nonce: Fr.ZERO, // Nonce cannot be known during private execution.
|
|
303
302
|
note,
|
|
@@ -317,7 +316,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
317
316
|
*/
|
|
318
317
|
public override notifyNullifiedNote(innerNullifier: Fr, noteHash: Fr, counter: number) {
|
|
319
318
|
const nullifiedNoteHashCounter = this.noteCache.nullifyNote(
|
|
320
|
-
this.callContext.
|
|
319
|
+
this.callContext.contractAddress,
|
|
321
320
|
innerNullifier,
|
|
322
321
|
noteHash,
|
|
323
322
|
);
|
|
@@ -391,11 +390,11 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
391
390
|
|
|
392
391
|
#checkValidStaticCall(childExecutionResult: PrivateExecutionResult) {
|
|
393
392
|
if (
|
|
394
|
-
childExecutionResult.
|
|
395
|
-
childExecutionResult.
|
|
396
|
-
childExecutionResult.
|
|
397
|
-
childExecutionResult.
|
|
398
|
-
childExecutionResult.
|
|
393
|
+
childExecutionResult.publicInputs.noteHashes.some(item => !item.isEmpty()) ||
|
|
394
|
+
childExecutionResult.publicInputs.nullifiers.some(item => !item.isEmpty()) ||
|
|
395
|
+
childExecutionResult.publicInputs.l2ToL1Msgs.some(item => !item.isEmpty()) ||
|
|
396
|
+
childExecutionResult.publicInputs.encryptedLogsHashes.some(item => !item.isEmpty()) ||
|
|
397
|
+
childExecutionResult.publicInputs.unencryptedLogsHashes.some(item => !item.isEmpty())
|
|
399
398
|
) {
|
|
400
399
|
throw new Error(`Static call cannot update the state, emit L2->L1 messages or generate logs`);
|
|
401
400
|
}
|
|
@@ -408,7 +407,6 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
408
407
|
* @param argsHash - The packed arguments to pass to the function.
|
|
409
408
|
* @param sideEffectCounter - The side effect counter at the start of the call.
|
|
410
409
|
* @param isStaticCall - Whether the call is a static call.
|
|
411
|
-
* @param isDelegateCall - Whether the call is a delegate call.
|
|
412
410
|
* @returns The execution result.
|
|
413
411
|
*/
|
|
414
412
|
override async callPrivateFunction(
|
|
@@ -417,10 +415,9 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
417
415
|
argsHash: Fr,
|
|
418
416
|
sideEffectCounter: number,
|
|
419
417
|
isStaticCall: boolean,
|
|
420
|
-
isDelegateCall: boolean,
|
|
421
418
|
) {
|
|
422
419
|
this.log.debug(
|
|
423
|
-
`Calling private function ${this.contractAddress}:${functionSelector} from ${this.callContext.
|
|
420
|
+
`Calling private function ${this.contractAddress}:${functionSelector} from ${this.callContext.contractAddress}`,
|
|
424
421
|
);
|
|
425
422
|
|
|
426
423
|
isStaticCall = isStaticCall || this.callContext.isStaticCall;
|
|
@@ -429,15 +426,9 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
429
426
|
|
|
430
427
|
const derivedTxContext = this.txContext.clone();
|
|
431
428
|
|
|
432
|
-
const derivedCallContext = this.deriveCallContext(
|
|
433
|
-
targetContractAddress,
|
|
434
|
-
targetArtifact,
|
|
435
|
-
isDelegateCall,
|
|
436
|
-
isStaticCall,
|
|
437
|
-
);
|
|
429
|
+
const derivedCallContext = this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
|
|
438
430
|
|
|
439
431
|
const context = new ClientExecutionContext(
|
|
440
|
-
targetContractAddress,
|
|
441
432
|
argsHash,
|
|
442
433
|
derivedTxContext,
|
|
443
434
|
derivedCallContext,
|
|
@@ -465,7 +456,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
465
456
|
|
|
466
457
|
this.nestedExecutions.push(childExecutionResult);
|
|
467
458
|
|
|
468
|
-
const publicInputs = childExecutionResult.
|
|
459
|
+
const publicInputs = childExecutionResult.publicInputs;
|
|
469
460
|
return {
|
|
470
461
|
endSideEffectCounter: publicInputs.endSideEffectCounter,
|
|
471
462
|
returnsHash: publicInputs.returnsHash,
|
|
@@ -473,7 +464,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
473
464
|
}
|
|
474
465
|
|
|
475
466
|
/**
|
|
476
|
-
* Creates a
|
|
467
|
+
* Creates a PublicExecutionRequest object representing the request to call a public function.
|
|
477
468
|
* @param targetContractAddress - The address of the contract to call.
|
|
478
469
|
* @param functionSelector - The function selector of the function to call.
|
|
479
470
|
* @param argsHash - The packed arguments to pass to the function.
|
|
@@ -488,15 +479,9 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
488
479
|
argsHash: Fr,
|
|
489
480
|
sideEffectCounter: number,
|
|
490
481
|
isStaticCall: boolean,
|
|
491
|
-
isDelegateCall: boolean,
|
|
492
482
|
) {
|
|
493
483
|
const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
494
|
-
const derivedCallContext = this.deriveCallContext(
|
|
495
|
-
targetContractAddress,
|
|
496
|
-
targetArtifact,
|
|
497
|
-
isDelegateCall,
|
|
498
|
-
isStaticCall,
|
|
499
|
-
);
|
|
484
|
+
const derivedCallContext = this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
|
|
500
485
|
const args = this.packedValuesCache.unpack(argsHash);
|
|
501
486
|
|
|
502
487
|
this.log.verbose(
|
|
@@ -506,7 +491,6 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
506
491
|
const request = PublicExecutionRequest.from({
|
|
507
492
|
args,
|
|
508
493
|
callContext: derivedCallContext,
|
|
509
|
-
contractAddress: targetContractAddress,
|
|
510
494
|
});
|
|
511
495
|
|
|
512
496
|
if (callType === 'enqueued') {
|
|
@@ -517,7 +501,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
517
501
|
}
|
|
518
502
|
|
|
519
503
|
/**
|
|
520
|
-
* Creates and enqueues a
|
|
504
|
+
* Creates and enqueues a PublicExecutionRequest object representing the request to call a public function. No function
|
|
521
505
|
* is actually called, since that must happen on the sequencer side. All the fields related to the result
|
|
522
506
|
* of the execution are empty.
|
|
523
507
|
* @param targetContractAddress - The address of the contract to call.
|
|
@@ -533,7 +517,6 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
533
517
|
argsHash: Fr,
|
|
534
518
|
sideEffectCounter: number,
|
|
535
519
|
isStaticCall: boolean,
|
|
536
|
-
isDelegateCall: boolean,
|
|
537
520
|
): Promise<Fr> {
|
|
538
521
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Fix this.
|
|
539
522
|
// WARNING: This is insecure and should be temporary!
|
|
@@ -552,13 +535,12 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
552
535
|
newArgsHash,
|
|
553
536
|
sideEffectCounter,
|
|
554
537
|
isStaticCall,
|
|
555
|
-
isDelegateCall,
|
|
556
538
|
);
|
|
557
539
|
return newArgsHash;
|
|
558
540
|
}
|
|
559
541
|
|
|
560
542
|
/**
|
|
561
|
-
* Creates a
|
|
543
|
+
* Creates a PublicExecutionRequest and sets it as the public teardown function. No function
|
|
562
544
|
* is actually called, since that must happen on the sequencer side. All the fields related to the result
|
|
563
545
|
* of the execution are empty.
|
|
564
546
|
* @param targetContractAddress - The address of the contract to call.
|
|
@@ -574,7 +556,6 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
574
556
|
argsHash: Fr,
|
|
575
557
|
sideEffectCounter: number,
|
|
576
558
|
isStaticCall: boolean,
|
|
577
|
-
isDelegateCall: boolean,
|
|
578
559
|
): Promise<Fr> {
|
|
579
560
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Fix this.
|
|
580
561
|
// WARNING: This is insecure and should be temporary!
|
|
@@ -593,7 +574,6 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
593
574
|
newArgsHash,
|
|
594
575
|
sideEffectCounter,
|
|
595
576
|
isStaticCall,
|
|
596
|
-
isDelegateCall,
|
|
597
577
|
);
|
|
598
578
|
return newArgsHash;
|
|
599
579
|
}
|
|
@@ -606,21 +586,18 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
606
586
|
* Derives the call context for a nested execution.
|
|
607
587
|
* @param targetContractAddress - The address of the contract being called.
|
|
608
588
|
* @param targetArtifact - The artifact of the function being called.
|
|
609
|
-
* @param isDelegateCall - Whether the call is a delegate call.
|
|
610
589
|
* @param isStaticCall - Whether the call is a static call.
|
|
611
590
|
* @returns The derived call context.
|
|
612
591
|
*/
|
|
613
592
|
private deriveCallContext(
|
|
614
593
|
targetContractAddress: AztecAddress,
|
|
615
594
|
targetArtifact: FunctionArtifact,
|
|
616
|
-
isDelegateCall = false,
|
|
617
595
|
isStaticCall = false,
|
|
618
596
|
) {
|
|
619
597
|
return new CallContext(
|
|
620
|
-
|
|
621
|
-
|
|
598
|
+
this.contractAddress,
|
|
599
|
+
targetContractAddress,
|
|
622
600
|
FunctionSelector.fromNameAndParameters(targetArtifact.name, targetArtifact.parameters),
|
|
623
|
-
isDelegateCall,
|
|
624
601
|
isStaticCall,
|
|
625
602
|
);
|
|
626
603
|
}
|
|
@@ -2,10 +2,8 @@ import { PrivateExecutionResult } from '@aztec/circuit-types';
|
|
|
2
2
|
import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats';
|
|
3
3
|
import {
|
|
4
4
|
Fr,
|
|
5
|
-
FunctionData,
|
|
6
5
|
PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH,
|
|
7
6
|
PRIVATE_CONTEXT_INPUTS_LENGTH,
|
|
8
|
-
PrivateCallStackItem,
|
|
9
7
|
PrivateCircuitPublicInputs,
|
|
10
8
|
} from '@aztec/circuits.js';
|
|
11
9
|
import { type FunctionArtifact, type FunctionSelector, countArgumentsSize } from '@aztec/foundation/abi';
|
|
@@ -64,12 +62,6 @@ export async function executePrivateFunction(
|
|
|
64
62
|
const encryptedLogs = context.getEncryptedLogs();
|
|
65
63
|
const unencryptedLogs = context.getUnencryptedLogs();
|
|
66
64
|
|
|
67
|
-
const callStackItem = new PrivateCallStackItem(
|
|
68
|
-
contractAddress,
|
|
69
|
-
new FunctionData(functionSelector, true),
|
|
70
|
-
publicInputs,
|
|
71
|
-
);
|
|
72
|
-
|
|
73
65
|
const rawReturnValues = await context.unpackReturns(publicInputs.returnsHash);
|
|
74
66
|
|
|
75
67
|
const noteHashLeafIndexMap = context.getNoteHashLeafIndexMap();
|
|
@@ -85,7 +77,7 @@ export async function executePrivateFunction(
|
|
|
85
77
|
acir,
|
|
86
78
|
Buffer.from(artifact.verificationKey!, 'hex'),
|
|
87
79
|
partialWitness,
|
|
88
|
-
|
|
80
|
+
publicInputs,
|
|
89
81
|
noteHashLeafIndexMap,
|
|
90
82
|
newNotes,
|
|
91
83
|
noteHashNullifierCounterMap,
|
package/src/client/simulator.ts
CHANGED
|
@@ -66,14 +66,12 @@ export class AcirSimulator {
|
|
|
66
66
|
msgSender,
|
|
67
67
|
contractAddress,
|
|
68
68
|
FunctionSelector.fromNameAndParameters(entryPointArtifact.name, entryPointArtifact.parameters),
|
|
69
|
-
false,
|
|
70
69
|
entryPointArtifact.isStatic,
|
|
71
70
|
);
|
|
72
71
|
|
|
73
72
|
const txHash = request.toTxRequest().hash();
|
|
74
73
|
|
|
75
74
|
const context = new ClientExecutionContext(
|
|
76
|
-
contractAddress,
|
|
77
75
|
request.firstCallArgsHash,
|
|
78
76
|
request.txContext,
|
|
79
77
|
callContext,
|
package/src/mocks/fixtures.ts
CHANGED
|
@@ -79,7 +79,7 @@ export class PublicExecutionResultBuilder {
|
|
|
79
79
|
revertReason?: SimulationError;
|
|
80
80
|
}) {
|
|
81
81
|
const builder = new PublicExecutionResultBuilder(
|
|
82
|
-
new PublicExecutionRequest(
|
|
82
|
+
new PublicExecutionRequest(new CallContext(from, tx.to, tx.selector, false), tx.args),
|
|
83
83
|
);
|
|
84
84
|
|
|
85
85
|
builder.withNestedExecutions(...nestedExecutions);
|
|
@@ -32,35 +32,35 @@ export class DualSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
32
32
|
return this.innerCallTrace.getCounter();
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
public tracePublicStorageRead(
|
|
36
|
-
this.innerCallTrace.tracePublicStorageRead(
|
|
37
|
-
this.enqueuedCallTrace.tracePublicStorageRead(
|
|
35
|
+
public tracePublicStorageRead(contractAddress: Fr, slot: Fr, value: Fr, exists: boolean, cached: boolean) {
|
|
36
|
+
this.innerCallTrace.tracePublicStorageRead(contractAddress, slot, value, exists, cached);
|
|
37
|
+
this.enqueuedCallTrace.tracePublicStorageRead(contractAddress, slot, value, exists, cached);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
public tracePublicStorageWrite(
|
|
41
|
-
this.innerCallTrace.tracePublicStorageWrite(
|
|
42
|
-
this.enqueuedCallTrace.tracePublicStorageWrite(
|
|
40
|
+
public tracePublicStorageWrite(contractAddress: Fr, slot: Fr, value: Fr) {
|
|
41
|
+
this.innerCallTrace.tracePublicStorageWrite(contractAddress, slot, value);
|
|
42
|
+
this.enqueuedCallTrace.tracePublicStorageWrite(contractAddress, slot, value);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// TODO(8287): _exists can be removed once we have the vm properly handling the equality check
|
|
46
|
-
public traceNoteHashCheck(
|
|
47
|
-
this.innerCallTrace.traceNoteHashCheck(
|
|
48
|
-
this.enqueuedCallTrace.traceNoteHashCheck(
|
|
46
|
+
public traceNoteHashCheck(_contractAddress: Fr, noteHash: Fr, leafIndex: Fr, exists: boolean) {
|
|
47
|
+
this.innerCallTrace.traceNoteHashCheck(_contractAddress, noteHash, leafIndex, exists);
|
|
48
|
+
this.enqueuedCallTrace.traceNoteHashCheck(_contractAddress, noteHash, leafIndex, exists);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
public traceNewNoteHash(
|
|
52
|
-
this.innerCallTrace.traceNewNoteHash(
|
|
53
|
-
this.enqueuedCallTrace.traceNewNoteHash(
|
|
51
|
+
public traceNewNoteHash(_contractAddress: Fr, noteHash: Fr) {
|
|
52
|
+
this.innerCallTrace.traceNewNoteHash(_contractAddress, noteHash);
|
|
53
|
+
this.enqueuedCallTrace.traceNewNoteHash(_contractAddress, noteHash);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
public traceNullifierCheck(
|
|
57
|
-
this.innerCallTrace.traceNullifierCheck(
|
|
58
|
-
this.enqueuedCallTrace.traceNullifierCheck(
|
|
56
|
+
public traceNullifierCheck(contractAddress: Fr, nullifier: Fr, leafIndex: Fr, exists: boolean, isPending: boolean) {
|
|
57
|
+
this.innerCallTrace.traceNullifierCheck(contractAddress, nullifier, leafIndex, exists, isPending);
|
|
58
|
+
this.enqueuedCallTrace.traceNullifierCheck(contractAddress, nullifier, leafIndex, exists, isPending);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
public traceNewNullifier(
|
|
62
|
-
this.innerCallTrace.traceNewNullifier(
|
|
63
|
-
this.enqueuedCallTrace.traceNewNullifier(
|
|
61
|
+
public traceNewNullifier(contractAddress: Fr, nullifier: Fr) {
|
|
62
|
+
this.innerCallTrace.traceNewNullifier(contractAddress, nullifier);
|
|
63
|
+
this.enqueuedCallTrace.traceNewNullifier(contractAddress, nullifier);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
public traceL1ToL2MessageCheck(contractAddress: Fr, msgHash: Fr, msgLeafIndex: Fr, exists: boolean) {
|
|
@@ -157,7 +157,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
157
157
|
this.sideEffectCounter++;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
public tracePublicStorageRead(
|
|
160
|
+
public tracePublicStorageRead(contractAddress: Fr, slot: Fr, value: Fr, _exists: boolean, _cached: boolean) {
|
|
161
161
|
// NOTE: exists and cached are unused for now but may be used for optimizations or kernel hints later
|
|
162
162
|
if (
|
|
163
163
|
this.contractStorageReads.length + this.previousValidationRequestArrayLengths.publicDataReads >=
|
|
@@ -167,7 +167,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
this.contractStorageReads.push(
|
|
170
|
-
new ContractStorageRead(slot, value, this.sideEffectCounter, AztecAddress.fromField(
|
|
170
|
+
new ContractStorageRead(slot, value, this.sideEffectCounter, AztecAddress.fromField(contractAddress)),
|
|
171
171
|
);
|
|
172
172
|
this.avmCircuitHints.storageValues.items.push(
|
|
173
173
|
new AvmKeyValueHint(/*key=*/ new Fr(this.sideEffectCounter), /*value=*/ value),
|
|
@@ -176,7 +176,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
176
176
|
this.incrementSideEffectCounter();
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
public tracePublicStorageWrite(
|
|
179
|
+
public tracePublicStorageWrite(contractAddress: Fr, slot: Fr, value: Fr) {
|
|
180
180
|
if (
|
|
181
181
|
this.contractStorageUpdateRequests.length + this.previousAccumulatedDataArrayLengths.publicDataUpdateRequests >=
|
|
182
182
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
|
|
@@ -185,15 +185,15 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
this.contractStorageUpdateRequests.push(
|
|
188
|
-
new ContractStorageUpdateRequest(slot, value, this.sideEffectCounter,
|
|
188
|
+
new ContractStorageUpdateRequest(slot, value, this.sideEffectCounter, contractAddress),
|
|
189
189
|
);
|
|
190
190
|
this.log.debug(`SSTORE cnt: ${this.sideEffectCounter} val: ${value} slot: ${slot}`);
|
|
191
191
|
this.incrementSideEffectCounter();
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
// TODO(8287): _exists can be removed once we have the vm properly handling the equality check
|
|
195
|
-
public traceNoteHashCheck(
|
|
196
|
-
// NOTE:
|
|
195
|
+
public traceNoteHashCheck(_contractAddress: Fr, noteHash: Fr, leafIndex: Fr, exists: boolean) {
|
|
196
|
+
// NOTE: contractAddress is unused because noteHash is an already-siloed leaf
|
|
197
197
|
if (
|
|
198
198
|
this.noteHashReadRequests.length + this.previousValidationRequestArrayLengths.noteHashReadRequests >=
|
|
199
199
|
MAX_NOTE_HASH_READ_REQUESTS_PER_TX
|
|
@@ -208,22 +208,22 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
208
208
|
// NOTE: counter does not increment for note hash checks (because it doesn't rely on pending note hashes)
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
public traceNewNoteHash(
|
|
211
|
+
public traceNewNoteHash(contractAddress: Fr, noteHash: Fr) {
|
|
212
212
|
if (this.noteHashes.length + this.previousAccumulatedDataArrayLengths.noteHashes >= MAX_NOTE_HASHES_PER_TX) {
|
|
213
213
|
throw new SideEffectLimitReachedError('note hash', MAX_NOTE_HASHES_PER_TX);
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
this.noteHashes.push(new NoteHash(noteHash, this.sideEffectCounter).scope(AztecAddress.fromField(
|
|
216
|
+
this.noteHashes.push(new NoteHash(noteHash, this.sideEffectCounter).scope(AztecAddress.fromField(contractAddress)));
|
|
217
217
|
this.log.debug(`NEW_NOTE_HASH cnt: ${this.sideEffectCounter}`);
|
|
218
218
|
this.incrementSideEffectCounter();
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
public traceNullifierCheck(
|
|
221
|
+
public traceNullifierCheck(contractAddress: Fr, nullifier: Fr, _leafIndex: Fr, exists: boolean, _isPending: boolean) {
|
|
222
222
|
// NOTE: isPending and leafIndex are unused for now but may be used for optimizations or kernel hints later
|
|
223
223
|
this.enforceLimitOnNullifierChecks();
|
|
224
224
|
|
|
225
225
|
const readRequest = new ReadRequest(nullifier, this.sideEffectCounter).scope(
|
|
226
|
-
AztecAddress.fromField(
|
|
226
|
+
AztecAddress.fromField(contractAddress),
|
|
227
227
|
);
|
|
228
228
|
if (exists) {
|
|
229
229
|
this.nullifierReadRequests.push(readRequest);
|
|
@@ -237,14 +237,14 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
237
237
|
this.incrementSideEffectCounter();
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
public traceNewNullifier(
|
|
240
|
+
public traceNewNullifier(contractAddress: Fr, nullifier: Fr) {
|
|
241
241
|
if (this.nullifiers.length + this.previousAccumulatedDataArrayLengths.nullifiers >= MAX_NULLIFIERS_PER_TX) {
|
|
242
242
|
throw new SideEffectLimitReachedError('nullifier', MAX_NULLIFIERS_PER_TX);
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
this.nullifiers.push(
|
|
246
246
|
new Nullifier(nullifier, this.sideEffectCounter, /*noteHash=*/ Fr.ZERO).scope(
|
|
247
|
-
AztecAddress.fromField(
|
|
247
|
+
AztecAddress.fromField(contractAddress),
|
|
248
248
|
),
|
|
249
249
|
);
|
|
250
250
|
this.log.debug(`NEW_NULLIFIER cnt: ${this.sideEffectCounter}`);
|
|
@@ -538,15 +538,9 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
538
538
|
function createPublicCallRequest(avmEnvironment: AvmExecutionEnvironment): PublicCallRequest {
|
|
539
539
|
const callContext = CallContext.from({
|
|
540
540
|
msgSender: avmEnvironment.sender,
|
|
541
|
-
|
|
541
|
+
contractAddress: avmEnvironment.address,
|
|
542
542
|
functionSelector: avmEnvironment.functionSelector,
|
|
543
|
-
isDelegateCall: avmEnvironment.isDelegateCall,
|
|
544
543
|
isStaticCall: avmEnvironment.isStaticCall,
|
|
545
544
|
});
|
|
546
|
-
return new PublicCallRequest(
|
|
547
|
-
avmEnvironment.address,
|
|
548
|
-
callContext,
|
|
549
|
-
computeVarArgsHash(avmEnvironment.calldata),
|
|
550
|
-
/*counter=*/ 0,
|
|
551
|
-
);
|
|
545
|
+
return new PublicCallRequest(callContext, computeVarArgsHash(avmEnvironment.calldata), /*counter=*/ 0);
|
|
552
546
|
}
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
ContractStorageRead,
|
|
17
17
|
ContractStorageUpdateRequest,
|
|
18
18
|
Fr,
|
|
19
|
-
FunctionData,
|
|
20
19
|
Gas,
|
|
21
20
|
type GlobalVariables,
|
|
22
21
|
type Header,
|
|
@@ -42,7 +41,6 @@ import {
|
|
|
42
41
|
PublicAccumulatedDataArrayLengths,
|
|
43
42
|
PublicCallData,
|
|
44
43
|
type PublicCallRequest,
|
|
45
|
-
PublicCallStackItem,
|
|
46
44
|
PublicCircuitPublicInputs,
|
|
47
45
|
PublicInnerCallRequest,
|
|
48
46
|
type PublicKernelCircuitPublicInputs,
|
|
@@ -157,7 +155,7 @@ export class EnqueuedCallSimulator {
|
|
|
157
155
|
);
|
|
158
156
|
|
|
159
157
|
const callStack = makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, PublicInnerCallRequest.empty);
|
|
160
|
-
callStack[0].item.contractAddress = callRequest.contractAddress;
|
|
158
|
+
callStack[0].item.contractAddress = callRequest.callContext.contractAddress;
|
|
161
159
|
callStack[0].item.callContext = callRequest.callContext;
|
|
162
160
|
callStack[0].item.argsHash = callRequest.argsHash;
|
|
163
161
|
|
|
@@ -197,22 +195,19 @@ export class EnqueuedCallSimulator {
|
|
|
197
195
|
// Accumulate gas used in this enqueued call.
|
|
198
196
|
gasUsed = gasUsed.add(Gas.from(result.startGasLeft).sub(Gas.from(result.endGasLeft)));
|
|
199
197
|
|
|
198
|
+
const { contractAddress, functionSelector } = result.executionRequest.callContext;
|
|
199
|
+
|
|
200
200
|
// Sanity check for a current upstream assumption.
|
|
201
201
|
// Consumers of the result seem to expect "reverted <=> revertReason !== undefined".
|
|
202
|
-
const functionSelector = result.executionRequest.callContext.functionSelector.toString();
|
|
203
202
|
if (result.reverted && !result.revertReason) {
|
|
204
203
|
throw new Error(
|
|
205
|
-
`Simulation of ${
|
|
206
|
-
result.functionName
|
|
207
|
-
}) reverted with no reason.`,
|
|
204
|
+
`Simulation of ${contractAddress}:${functionSelector}(${result.functionName}) reverted with no reason.`,
|
|
208
205
|
);
|
|
209
206
|
}
|
|
210
207
|
|
|
211
208
|
// Simulate the public kernel circuit.
|
|
212
209
|
this.log.debug(
|
|
213
|
-
`Running public kernel inner circuit for ${
|
|
214
|
-
result.functionName
|
|
215
|
-
})`,
|
|
210
|
+
`Running public kernel inner circuit for ${contractAddress}:${functionSelector}(${result.functionName})`,
|
|
216
211
|
);
|
|
217
212
|
|
|
218
213
|
const callData = await this.getPublicCallData(result);
|
|
@@ -226,9 +221,7 @@ export class EnqueuedCallSimulator {
|
|
|
226
221
|
// TODO(@leila) we shouldn't drop everything when it reverts. The tail kernel needs the data to prove that it's reverted for the correct reason.
|
|
227
222
|
if (result.reverted) {
|
|
228
223
|
this.log.debug(
|
|
229
|
-
`Reverting on ${
|
|
230
|
-
result.functionName
|
|
231
|
-
}) with reason: ${result.revertReason}`,
|
|
224
|
+
`Reverting on ${contractAddress}:${functionSelector}(${result.functionName}) with reason: ${result.revertReason}`,
|
|
232
225
|
);
|
|
233
226
|
// TODO(@spalladino): Check gasUsed is correct. The AVM should take care of setting gasLeft to zero upon a revert.
|
|
234
227
|
|
|
@@ -278,15 +271,15 @@ export class EnqueuedCallSimulator {
|
|
|
278
271
|
*/
|
|
279
272
|
private async getPublicCallData(result: PublicExecutionResult) {
|
|
280
273
|
const bytecodeHash = await this.getBytecodeHash(result);
|
|
281
|
-
const
|
|
282
|
-
return new PublicCallData(
|
|
274
|
+
const publicInputs = await this.getPublicCircuitPublicInputs(result);
|
|
275
|
+
return new PublicCallData(publicInputs, makeEmptyProof(), bytecodeHash);
|
|
283
276
|
}
|
|
284
277
|
|
|
285
|
-
private async
|
|
278
|
+
private async getPublicCircuitPublicInputs(result: PublicExecutionResult) {
|
|
286
279
|
const publicDataTreeInfo = await this.db.getTreeInfo(MerkleTreeId.PUBLIC_DATA_TREE);
|
|
287
280
|
this.historicalHeader.state.partial.publicDataTree.root = Fr.fromBuffer(publicDataTreeInfo.root);
|
|
288
281
|
|
|
289
|
-
|
|
282
|
+
return PublicCircuitPublicInputs.from({
|
|
290
283
|
callContext: result.executionRequest.callContext,
|
|
291
284
|
proverAddress: AztecAddress.ZERO,
|
|
292
285
|
argsHash: computeVarArgsHash(result.executionRequest.args),
|
|
@@ -340,12 +333,6 @@ export class EnqueuedCallSimulator {
|
|
|
340
333
|
// TODO(@just-mitch): need better mapping from simulator to revert code.
|
|
341
334
|
revertCode: result.reverted ? RevertCode.APP_LOGIC_REVERTED : RevertCode.OK,
|
|
342
335
|
});
|
|
343
|
-
|
|
344
|
-
return new PublicCallStackItem(
|
|
345
|
-
result.executionRequest.contractAddress,
|
|
346
|
-
new FunctionData(result.executionRequest.callContext.functionSelector, false),
|
|
347
|
-
publicCircuitPublicInputs,
|
|
348
|
-
);
|
|
349
336
|
}
|
|
350
337
|
|
|
351
338
|
private getBytecodeHash(_result: PublicExecutionResult) {
|
|
@@ -265,9 +265,7 @@ export class EnqueuedCallsProcessor {
|
|
|
265
265
|
|
|
266
266
|
if (enqueuedCallResult.revertReason && !PhaseIsRevertible[phase]) {
|
|
267
267
|
this.log.debug(
|
|
268
|
-
`Simulation error on ${executionRequest.contractAddress
|
|
269
|
-
executionRequest.callContext.functionSelector
|
|
270
|
-
} with reason: ${enqueuedCallResult.revertReason}`,
|
|
268
|
+
`Simulation error on ${executionRequest.callContext.contractAddress}:${executionRequest.callContext.functionSelector} with reason: ${enqueuedCallResult.revertReason}`,
|
|
271
269
|
);
|
|
272
270
|
throw enqueuedCallResult.revertReason;
|
|
273
271
|
}
|
package/src/public/execution.ts
CHANGED
|
@@ -139,7 +139,7 @@ export function checkValidStaticCall(
|
|
|
139
139
|
export function resultToPublicCallRequest(result: PublicExecutionResult) {
|
|
140
140
|
const request = result.executionRequest;
|
|
141
141
|
const item = new PublicCallStackItemCompressed(
|
|
142
|
-
request.contractAddress,
|
|
142
|
+
request.callContext.contractAddress,
|
|
143
143
|
request.callContext,
|
|
144
144
|
computeVarArgsHash(request.args),
|
|
145
145
|
computeVarArgsHash(result.returnValues),
|
package/src/public/executor.ts
CHANGED
|
@@ -63,11 +63,13 @@ export class PublicExecutor {
|
|
|
63
63
|
previousValidationRequestArrayLengths: PublicValidationRequestArrayLengths = PublicValidationRequestArrayLengths.empty(),
|
|
64
64
|
previousAccumulatedDataArrayLengths: PublicAccumulatedDataArrayLengths = PublicAccumulatedDataArrayLengths.empty(),
|
|
65
65
|
): Promise<PublicExecutionResult> {
|
|
66
|
-
const address = executionRequest.contractAddress;
|
|
66
|
+
const address = executionRequest.callContext.contractAddress;
|
|
67
67
|
const selector = executionRequest.callContext.functionSelector;
|
|
68
68
|
const fnName = await getPublicFunctionDebugName(this.worldStateDB, address, selector, executionRequest.args);
|
|
69
69
|
|
|
70
|
-
PublicExecutor.log.verbose(
|
|
70
|
+
PublicExecutor.log.verbose(
|
|
71
|
+
`[AVM] Executing public external function ${fnName}@${address} with ${allocatedGas.l2Gas} allocated L2 gas.`,
|
|
72
|
+
);
|
|
71
73
|
const timer = new Timer();
|
|
72
74
|
|
|
73
75
|
const innerCallTrace = new PublicSideEffectTrace(startSideEffectCounter);
|
|
@@ -132,6 +134,12 @@ export class PublicExecutor {
|
|
|
132
134
|
avmResult,
|
|
133
135
|
);
|
|
134
136
|
|
|
137
|
+
PublicExecutor.log.verbose(
|
|
138
|
+
`[AVM] ${fnName} simulation complete. Reverted=${avmResult.reverted}. Consumed ${
|
|
139
|
+
allocatedGas.l2Gas - avmContext.machineState.gasLeft.l2Gas
|
|
140
|
+
} L2 gas, ending with ${avmContext.machineState.gasLeft.l2Gas} L2 gas left.`,
|
|
141
|
+
);
|
|
142
|
+
|
|
135
143
|
return publicExecutionResult;
|
|
136
144
|
}
|
|
137
145
|
}
|
|
@@ -149,15 +157,13 @@ function createAvmExecutionEnvironment(
|
|
|
149
157
|
transactionFee: Fr,
|
|
150
158
|
): AvmExecutionEnvironment {
|
|
151
159
|
return new AvmExecutionEnvironment(
|
|
152
|
-
executionRequest.contractAddress,
|
|
153
|
-
executionRequest.callContext.storageContractAddress,
|
|
160
|
+
executionRequest.callContext.contractAddress,
|
|
154
161
|
executionRequest.callContext.msgSender,
|
|
155
162
|
executionRequest.callContext.functionSelector,
|
|
156
163
|
/*contractCallDepth=*/ Fr.zero(),
|
|
157
164
|
transactionFee,
|
|
158
165
|
globalVariables,
|
|
159
166
|
executionRequest.callContext.isStaticCall,
|
|
160
|
-
executionRequest.callContext.isDelegateCall,
|
|
161
167
|
executionRequest.args,
|
|
162
168
|
);
|
|
163
169
|
}
|