@aztec/simulator 0.55.1 → 0.57.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 +2 -5
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +6 -37
- package/dest/acvm/oracle/typed_oracle.d.ts +3 -6
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +1 -10
- package/dest/avm/avm_execution_environment.d.ts +2 -11
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +3 -22
- package/dest/avm/avm_gas.d.ts +2 -2
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +31 -116
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +6 -6
- package/dest/avm/avm_memory_types.d.ts +38 -9
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +27 -13
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +5 -6
- package/dest/avm/bytecode_utils.d.ts +1 -2
- package/dest/avm/bytecode_utils.d.ts.map +1 -1
- package/dest/avm/bytecode_utils.js +3 -17
- package/dest/avm/errors.d.ts +1 -1
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +12 -3
- package/dest/avm/fixtures/index.d.ts +4 -16
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +11 -27
- package/dest/avm/journal/index.d.ts +0 -1
- package/dest/avm/journal/index.d.ts.map +1 -1
- package/dest/avm/journal/index.js +1 -2
- package/dest/avm/journal/journal.d.ts +6 -5
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +18 -16
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +37 -30
- package/dest/avm/opcodes/addressing_mode.d.ts +3 -2
- package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/avm/opcodes/addressing_mode.js +25 -21
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +6 -5
- package/dest/avm/opcodes/bitwise.d.ts +10 -4
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +26 -18
- package/dest/avm/opcodes/commitment.d.ts.map +1 -1
- package/dest/avm/opcodes/commitment.js +6 -5
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +8 -7
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +6 -5
- package/dest/avm/opcodes/control_flow.js +6 -6
- package/dest/avm/opcodes/conversion.d.ts +3 -2
- package/dest/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/avm/opcodes/conversion.js +21 -13
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/avm/opcodes/ec_add.js +8 -7
- package/dest/avm/opcodes/environment_getters.d.ts +27 -63
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +76 -80
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +27 -16
- package/dest/avm/opcodes/hashing.d.ts +5 -5
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +47 -40
- package/dest/avm/opcodes/index.d.ts +3 -0
- package/dest/avm/opcodes/index.d.ts.map +1 -1
- package/dest/avm/opcodes/index.js +4 -1
- package/dest/avm/opcodes/instruction.d.ts +2 -6
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +3 -9
- package/dest/avm/opcodes/instruction_impl.d.ts +0 -26
- package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction_impl.js +1 -51
- package/dest/avm/opcodes/memory.d.ts +5 -12
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +40 -53
- package/dest/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/avm/opcodes/misc.js +6 -5
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
- package/dest/avm/opcodes/multi_scalar_mul.js +17 -16
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +11 -9
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +5 -25
- package/dest/avm/serialization/instruction_serialization.d.ts +40 -54
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +41 -57
- package/dest/avm/test_utils.d.ts +8 -8
- package/dest/avm/test_utils.d.ts.map +1 -1
- package/dest/avm/test_utils.js +15 -15
- package/dest/client/client_execution_context.d.ts +6 -30
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +31 -53
- package/dest/client/index.d.ts +0 -1
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -2
- package/dest/client/private_execution.d.ts +2 -2
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +5 -19
- package/dest/client/simulator.d.ts +3 -4
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +1 -1
- package/dest/client/test_utils.d.ts.map +1 -1
- package/dest/client/test_utils.js +12 -6
- package/dest/client/unconstrained_execution.d.ts +2 -2
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +3 -3
- package/dest/common/debug_fn_name.d.ts +4 -0
- package/dest/common/debug_fn_name.d.ts.map +1 -0
- package/dest/common/debug_fn_name.js +15 -0
- package/dest/common/index.d.ts +0 -1
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +1 -2
- package/dest/public/enqueued_call_simulator.d.ts +43 -0
- package/dest/public/enqueued_call_simulator.d.ts.map +1 -0
- package/dest/public/enqueued_call_simulator.js +154 -0
- package/dest/public/enqueued_calls_processor.d.ts +44 -0
- package/dest/public/enqueued_calls_processor.d.ts.map +1 -0
- package/dest/public/enqueued_calls_processor.js +218 -0
- package/dest/public/execution.d.ts +10 -8
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +15 -8
- package/dest/public/executor.d.ts +4 -7
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +10 -14
- package/dest/public/hints_builder.d.ts +4 -3
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +5 -5
- package/dest/public/index.d.ts +3 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +3 -3
- package/dest/public/public_db_sources.d.ts +17 -24
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +58 -65
- package/dest/public/public_kernel.d.ts +3 -9
- package/dest/public/public_kernel.d.ts.map +1 -1
- package/dest/public/public_kernel.js +13 -40
- package/dest/public/public_kernel_circuit_simulator.d.ts +5 -11
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +1 -1
- package/dest/public/public_kernel_tail_simulator.d.ts +19 -0
- package/dest/public/public_kernel_tail_simulator.d.ts.map +1 -0
- package/dest/public/public_kernel_tail_simulator.js +45 -0
- package/dest/public/public_processor.d.ts +9 -5
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +34 -48
- package/dest/public/public_processor_metrics.d.ts +3 -3
- package/dest/public/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor_metrics.js +1 -1
- package/dest/public/side_effect_errors.d.ts +4 -0
- package/dest/public/side_effect_errors.d.ts.map +1 -0
- package/dest/public/side_effect_errors.js +7 -0
- package/dest/public/side_effect_trace.d.ts +2 -2
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +56 -35
- package/dest/public/side_effect_trace_interface.d.ts +1 -1
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/package.json +12 -9
- package/src/acvm/oracle/oracle.ts +7 -85
- package/src/acvm/oracle/typed_oracle.ts +2 -31
- package/src/avm/avm_execution_environment.ts +2 -24
- package/src/avm/avm_gas.ts +30 -115
- package/src/avm/avm_machine_state.ts +5 -5
- package/src/avm/avm_memory_types.ts +41 -14
- package/src/avm/avm_simulator.ts +4 -5
- package/src/avm/bytecode_utils.ts +2 -17
- package/src/avm/errors.ts +11 -3
- package/src/avm/fixtures/index.ts +13 -46
- package/src/avm/journal/index.ts +0 -1
- package/src/avm/journal/journal.ts +22 -22
- package/src/avm/opcodes/accrued_substate.ts +36 -44
- package/src/avm/opcodes/addressing_mode.ts +27 -24
- package/src/avm/opcodes/arithmetic.ts +5 -7
- package/src/avm/opcodes/bitwise.ts +23 -20
- package/src/avm/opcodes/commitment.ts +6 -7
- package/src/avm/opcodes/comparators.ts +7 -9
- package/src/avm/opcodes/contract.ts +5 -7
- package/src/avm/opcodes/control_flow.ts +5 -5
- package/src/avm/opcodes/conversion.ts +19 -12
- package/src/avm/opcodes/ec_add.ts +14 -16
- package/src/avm/opcodes/environment_getters.ts +73 -99
- package/src/avm/opcodes/external_calls.ts +27 -20
- package/src/avm/opcodes/hashing.ts +52 -52
- package/src/avm/opcodes/index.ts +3 -0
- package/src/avm/opcodes/instruction.ts +3 -10
- package/src/avm/opcodes/instruction_impl.ts +0 -62
- package/src/avm/opcodes/memory.ts +37 -67
- package/src/avm/opcodes/misc.ts +5 -7
- package/src/avm/opcodes/multi_scalar_mul.ts +16 -19
- package/src/avm/opcodes/storage.ts +10 -8
- package/src/avm/serialization/bytecode_serialization.ts +11 -35
- package/src/avm/serialization/instruction_serialization.ts +3 -19
- package/src/avm/test_utils.ts +20 -16
- package/src/client/client_execution_context.ts +40 -96
- package/src/client/index.ts +0 -1
- package/src/client/private_execution.ts +9 -9
- package/src/client/simulator.ts +2 -3
- package/src/client/test_utils.ts +36 -9
- package/src/client/unconstrained_execution.ts +3 -8
- package/src/common/debug_fn_name.ts +22 -0
- package/src/common/index.ts +0 -1
- package/src/public/enqueued_call_simulator.ts +335 -0
- package/src/public/enqueued_calls_processor.ts +388 -0
- package/src/public/execution.ts +16 -12
- package/src/public/executor.ts +8 -22
- package/src/public/hints_builder.ts +21 -21
- package/src/public/index.ts +3 -2
- package/src/public/public_db_sources.ts +62 -67
- package/src/public/public_kernel.ts +15 -49
- package/src/public/public_kernel_circuit_simulator.ts +6 -10
- package/src/public/public_kernel_tail_simulator.ts +106 -0
- package/src/public/public_processor.ts +65 -86
- package/src/public/public_processor_metrics.ts +3 -3
- package/src/public/side_effect_errors.ts +6 -0
- package/src/public/side_effect_trace.ts +77 -39
- package/src/public/side_effect_trace_interface.ts +2 -2
- package/dest/avm/journal/host_storage.d.ts +0 -13
- package/dest/avm/journal/host_storage.d.ts.map +0 -1
- package/dest/avm/journal/host_storage.js +0 -13
- package/dest/avm/opcodes/context_getters.d.ts +0 -15
- package/dest/avm/opcodes/context_getters.d.ts.map +0 -1
- package/dest/avm/opcodes/context_getters.js +0 -19
- package/dest/client/execution_result.d.ts +0 -104
- package/dest/client/execution_result.d.ts.map +0 -1
- package/dest/client/execution_result.js +0 -136
- package/dest/common/return_values.d.ts +0 -11
- package/dest/common/return_values.d.ts.map +0 -1
- package/dest/common/return_values.js +0 -13
- package/dest/public/abstract_phase_manager.d.ts +0 -93
- package/dest/public/abstract_phase_manager.d.ts.map +0 -1
- package/dest/public/abstract_phase_manager.js +0 -285
- package/dest/public/app_logic_phase_manager.d.ts +0 -25
- package/dest/public/app_logic_phase_manager.d.ts.map +0 -1
- package/dest/public/app_logic_phase_manager.js +0 -52
- package/dest/public/phase_manager_factory.d.ts +0 -18
- package/dest/public/phase_manager_factory.d.ts.map +0 -1
- package/dest/public/phase_manager_factory.js +0 -56
- package/dest/public/setup_phase_manager.d.ts +0 -25
- package/dest/public/setup_phase_manager.d.ts.map +0 -1
- package/dest/public/setup_phase_manager.js +0 -39
- package/dest/public/tail_phase_manager.d.ts +0 -23
- package/dest/public/tail_phase_manager.d.ts.map +0 -1
- package/dest/public/tail_phase_manager.js +0 -50
- package/dest/public/teardown_phase_manager.d.ts +0 -27
- package/dest/public/teardown_phase_manager.d.ts.map +0 -1
- package/dest/public/teardown_phase_manager.js +0 -56
- package/src/avm/journal/host_storage.ts +0 -14
- package/src/avm/opcodes/context_getters.ts +0 -23
- package/src/client/execution_result.ts +0 -228
- package/src/common/return_values.ts +0 -18
- package/src/public/abstract_phase_manager.ts +0 -522
- package/src/public/app_logic_phase_manager.ts +0 -81
- package/src/public/phase_manager_factory.ts +0 -126
- package/src/public/setup_phase_manager.ts +0 -61
- package/src/public/tail_phase_manager.ts +0 -127
- package/src/public/teardown_phase_manager.ts +0 -86
|
@@ -1,50 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type AuthWitness,
|
|
3
3
|
type AztecNode,
|
|
4
|
+
CountedLog,
|
|
5
|
+
CountedNoteLog,
|
|
6
|
+
CountedPublicExecutionRequest,
|
|
4
7
|
EncryptedL2Log,
|
|
5
8
|
EncryptedL2NoteLog,
|
|
6
|
-
Event,
|
|
7
|
-
L1EventPayload,
|
|
8
|
-
L1NotePayload,
|
|
9
9
|
Note,
|
|
10
|
+
NoteAndSlot,
|
|
10
11
|
type NoteStatus,
|
|
12
|
+
type PrivateExecutionResult,
|
|
11
13
|
PublicExecutionRequest,
|
|
12
|
-
TaggedLog,
|
|
13
14
|
type UnencryptedL2Log,
|
|
14
15
|
} from '@aztec/circuit-types';
|
|
15
16
|
import {
|
|
16
17
|
CallContext,
|
|
17
18
|
FunctionSelector,
|
|
18
19
|
type Header,
|
|
19
|
-
|
|
20
|
+
PUBLIC_DISPATCH_SELECTOR,
|
|
20
21
|
PrivateContextInputs,
|
|
21
22
|
type TxContext,
|
|
22
23
|
} from '@aztec/circuits.js';
|
|
23
|
-
import { Aes128 } from '@aztec/circuits.js/barretenberg';
|
|
24
24
|
import { computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
|
|
25
|
-
import {
|
|
26
|
-
EventSelector,
|
|
27
|
-
type FunctionAbi,
|
|
28
|
-
type FunctionArtifact,
|
|
29
|
-
type NoteSelector,
|
|
30
|
-
countArgumentsSize,
|
|
31
|
-
} from '@aztec/foundation/abi';
|
|
25
|
+
import { type FunctionAbi, type FunctionArtifact, type NoteSelector, countArgumentsSize } from '@aztec/foundation/abi';
|
|
32
26
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
33
27
|
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
|
|
34
|
-
import { Fr
|
|
28
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
35
29
|
import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log';
|
|
36
30
|
|
|
37
31
|
import { type NoteData, toACVMWitness } from '../acvm/index.js';
|
|
38
32
|
import { type PackedValuesCache } from '../common/packed_values_cache.js';
|
|
39
33
|
import { type DBOracle } from './db_oracle.js';
|
|
40
34
|
import { type ExecutionNoteCache } from './execution_note_cache.js';
|
|
41
|
-
import {
|
|
42
|
-
CountedLog,
|
|
43
|
-
CountedNoteLog,
|
|
44
|
-
CountedPublicExecutionRequest,
|
|
45
|
-
type ExecutionResult,
|
|
46
|
-
type NoteAndSlot,
|
|
47
|
-
} from './execution_result.js';
|
|
48
35
|
import { pickNotes } from './pick_notes.js';
|
|
49
36
|
import { executePrivateFunction } from './private_execution.js';
|
|
50
37
|
import { ViewDataOracle } from './view_data_oracle.js';
|
|
@@ -75,7 +62,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
75
62
|
private noteEncryptedLogs: CountedNoteLog[] = [];
|
|
76
63
|
private encryptedLogs: CountedLog<EncryptedL2Log>[] = [];
|
|
77
64
|
private unencryptedLogs: CountedLog<UnencryptedL2Log>[] = [];
|
|
78
|
-
private nestedExecutions:
|
|
65
|
+
private nestedExecutions: PrivateExecutionResult[] = [];
|
|
79
66
|
private enqueuedPublicFunctionCalls: CountedPublicExecutionRequest[] = [];
|
|
80
67
|
private publicTeardownFunctionCall: PublicExecutionRequest = PublicExecutionRequest.empty();
|
|
81
68
|
|
|
@@ -314,11 +301,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
314
301
|
},
|
|
315
302
|
counter,
|
|
316
303
|
);
|
|
317
|
-
this.newNotes.push(
|
|
318
|
-
storageSlot,
|
|
319
|
-
noteTypeId,
|
|
320
|
-
note,
|
|
321
|
-
});
|
|
304
|
+
this.newNotes.push(new NoteAndSlot(note, storageSlot, noteTypeId));
|
|
322
305
|
}
|
|
323
306
|
|
|
324
307
|
/**
|
|
@@ -373,62 +356,6 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
373
356
|
this.noteEncryptedLogs.push(encryptedLog);
|
|
374
357
|
}
|
|
375
358
|
|
|
376
|
-
/**
|
|
377
|
-
* Encrypt an event
|
|
378
|
-
* @param contractAddress - The contract emitting the encrypted event.
|
|
379
|
-
* @param randomness - A value used to mask the contract address we are siloing with.
|
|
380
|
-
* @param eventTypeId - The type ID of the event (function selector).
|
|
381
|
-
* @param ovKeys - The outgoing viewing keys to use to encrypt.
|
|
382
|
-
* @param ivpkM - The master incoming viewing public key.
|
|
383
|
-
* @param recipient - The recipient of the encrypted event log.
|
|
384
|
-
* @param preimage - The event preimage.
|
|
385
|
-
*/
|
|
386
|
-
public override computeEncryptedEventLog(
|
|
387
|
-
contractAddress: AztecAddress,
|
|
388
|
-
randomness: Fr,
|
|
389
|
-
eventTypeId: Fr,
|
|
390
|
-
ovKeys: KeyValidationRequest,
|
|
391
|
-
ivpkM: Point,
|
|
392
|
-
recipient: AztecAddress,
|
|
393
|
-
preimage: Fr[],
|
|
394
|
-
) {
|
|
395
|
-
const event = new Event(preimage);
|
|
396
|
-
const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, EventSelector.fromField(eventTypeId));
|
|
397
|
-
const taggedEvent = new TaggedLog(l1EventPayload);
|
|
398
|
-
|
|
399
|
-
const ephSk = GrumpkinScalar.random();
|
|
400
|
-
|
|
401
|
-
return taggedEvent.encrypt(ephSk, recipient, ivpkM, ovKeys);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Encrypt a note
|
|
406
|
-
* @param contractAddress - The contract address of the note.
|
|
407
|
-
* @param storageSlot - The storage slot the note is at.
|
|
408
|
-
* @param noteTypeId - The type ID of the note.
|
|
409
|
-
* @param ovKeys - The outgoing viewing keys to use to encrypt.
|
|
410
|
-
* @param ivpkM - The master incoming viewing public key.
|
|
411
|
-
* @param recipient - The recipient of the encrypted note log.
|
|
412
|
-
* @param preimage - The note preimage.
|
|
413
|
-
*/
|
|
414
|
-
public override computeEncryptedNoteLog(
|
|
415
|
-
contractAddress: AztecAddress,
|
|
416
|
-
storageSlot: Fr,
|
|
417
|
-
noteTypeId: NoteSelector,
|
|
418
|
-
ovKeys: KeyValidationRequest,
|
|
419
|
-
ivpkM: Point,
|
|
420
|
-
recipient: AztecAddress,
|
|
421
|
-
preimage: Fr[],
|
|
422
|
-
) {
|
|
423
|
-
const note = new Note(preimage);
|
|
424
|
-
const l1NotePayload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId);
|
|
425
|
-
const taggedNote = new TaggedLog(l1NotePayload);
|
|
426
|
-
|
|
427
|
-
const ephSk = GrumpkinScalar.random();
|
|
428
|
-
|
|
429
|
-
return taggedNote.encrypt(ephSk, recipient, ivpkM, ovKeys);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
359
|
/**
|
|
433
360
|
* Emit an unencrypted log.
|
|
434
361
|
* @param log - The unencrypted log to be emitted.
|
|
@@ -457,7 +384,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
457
384
|
return Fr.fromBuffer(log.hash());
|
|
458
385
|
}
|
|
459
386
|
|
|
460
|
-
#checkValidStaticCall(childExecutionResult:
|
|
387
|
+
#checkValidStaticCall(childExecutionResult: PrivateExecutionResult) {
|
|
461
388
|
if (
|
|
462
389
|
childExecutionResult.callStackItem.publicInputs.noteHashes.some(item => !item.isEmpty()) ||
|
|
463
390
|
childExecutionResult.callStackItem.publicInputs.nullifiers.some(item => !item.isEmpty()) ||
|
|
@@ -568,7 +495,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
568
495
|
const args = this.packedValuesCache.unpack(argsHash);
|
|
569
496
|
|
|
570
497
|
this.log.verbose(
|
|
571
|
-
`Created PublicExecutionRequest of type [${callType}], side-effect counter [${sideEffectCounter}]
|
|
498
|
+
`Created PublicExecutionRequest to ${targetArtifact.name}@${targetContractAddress}, of type [${callType}], side-effect counter [${sideEffectCounter}]`,
|
|
572
499
|
);
|
|
573
500
|
|
|
574
501
|
const request = PublicExecutionRequest.from({
|
|
@@ -602,16 +529,27 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
602
529
|
sideEffectCounter: number,
|
|
603
530
|
isStaticCall: boolean,
|
|
604
531
|
isDelegateCall: boolean,
|
|
605
|
-
) {
|
|
532
|
+
): Promise<Fr> {
|
|
533
|
+
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Fix this.
|
|
534
|
+
// WARNING: This is insecure and should be temporary!
|
|
535
|
+
// The oracle repacks the arguments and returns a new args_hash.
|
|
536
|
+
// new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function.
|
|
537
|
+
// We don't validate or compute it in the circuit because a) it's harder to do with slices, and
|
|
538
|
+
// b) this is only temporary.
|
|
539
|
+
const newArgsHash = this.packedValuesCache.pack([
|
|
540
|
+
functionSelector.toField(),
|
|
541
|
+
...this.packedValuesCache.unpack(argsHash),
|
|
542
|
+
]);
|
|
606
543
|
await this.createPublicExecutionRequest(
|
|
607
544
|
'enqueued',
|
|
608
545
|
targetContractAddress,
|
|
609
|
-
|
|
610
|
-
|
|
546
|
+
FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)),
|
|
547
|
+
newArgsHash,
|
|
611
548
|
sideEffectCounter,
|
|
612
549
|
isStaticCall,
|
|
613
550
|
isDelegateCall,
|
|
614
551
|
);
|
|
552
|
+
return newArgsHash;
|
|
615
553
|
}
|
|
616
554
|
|
|
617
555
|
/**
|
|
@@ -632,16 +570,27 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
632
570
|
sideEffectCounter: number,
|
|
633
571
|
isStaticCall: boolean,
|
|
634
572
|
isDelegateCall: boolean,
|
|
635
|
-
) {
|
|
573
|
+
): Promise<Fr> {
|
|
574
|
+
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Fix this.
|
|
575
|
+
// WARNING: This is insecure and should be temporary!
|
|
576
|
+
// The oracle repacks the arguments and returns a new args_hash.
|
|
577
|
+
// new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function.
|
|
578
|
+
// We don't validate or compute it in the circuit because a) it's harder to do with slices, and
|
|
579
|
+
// b) this is only temporary.
|
|
580
|
+
const newArgsHash = this.packedValuesCache.pack([
|
|
581
|
+
functionSelector.toField(),
|
|
582
|
+
...this.packedValuesCache.unpack(argsHash),
|
|
583
|
+
]);
|
|
636
584
|
await this.createPublicExecutionRequest(
|
|
637
585
|
'teardown',
|
|
638
586
|
targetContractAddress,
|
|
639
|
-
|
|
640
|
-
|
|
587
|
+
FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)),
|
|
588
|
+
newArgsHash,
|
|
641
589
|
sideEffectCounter,
|
|
642
590
|
isStaticCall,
|
|
643
591
|
isDelegateCall,
|
|
644
592
|
);
|
|
593
|
+
return newArgsHash;
|
|
645
594
|
}
|
|
646
595
|
|
|
647
596
|
public override notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): void {
|
|
@@ -698,11 +647,6 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
698
647
|
return values;
|
|
699
648
|
}
|
|
700
649
|
|
|
701
|
-
public override aes128Encrypt(input: Buffer, initializationVector: Buffer, key: Buffer): Buffer {
|
|
702
|
-
const aes128 = new Aes128();
|
|
703
|
-
return aes128.encryptBufferCBC(input, initializationVector, key);
|
|
704
|
-
}
|
|
705
|
-
|
|
706
650
|
public override debugLog(message: string, fields: Fr[]) {
|
|
707
651
|
this.log.verbose(`debug_log ${applyStringFormatting(message, fields)}`);
|
|
708
652
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PrivateExecutionResult } from '@aztec/circuit-types';
|
|
1
2
|
import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats';
|
|
2
3
|
import { Fr, FunctionData, PrivateCallStackItem, PrivateCircuitPublicInputs } from '@aztec/circuits.js';
|
|
3
4
|
import type { FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
|
|
@@ -9,7 +10,6 @@ import { witnessMapToFields } from '../acvm/deserialize.js';
|
|
|
9
10
|
import { Oracle, acvm, extractCallStack } from '../acvm/index.js';
|
|
10
11
|
import { ExecutionError } from '../common/errors.js';
|
|
11
12
|
import { type ClientExecutionContext } from './client_execution_context.js';
|
|
12
|
-
import { type ExecutionResult } from './execution_result.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Execute a private function and return the execution result.
|
|
@@ -19,10 +19,10 @@ export async function executePrivateFunction(
|
|
|
19
19
|
artifact: FunctionArtifact,
|
|
20
20
|
contractAddress: AztecAddress,
|
|
21
21
|
functionSelector: FunctionSelector,
|
|
22
|
-
log = createDebugLogger('aztec:simulator:
|
|
23
|
-
): Promise<
|
|
22
|
+
log = createDebugLogger('aztec:simulator:private_execution'),
|
|
23
|
+
): Promise<PrivateExecutionResult> {
|
|
24
24
|
const functionName = await context.getDebugFunctionName();
|
|
25
|
-
log.verbose(`Executing external function ${
|
|
25
|
+
log.verbose(`Executing external function ${functionName}@${contractAddress}`);
|
|
26
26
|
const acir = artifact.bytecode;
|
|
27
27
|
const initialWitness = context.getInitialWitness(artifact);
|
|
28
28
|
const acvmCallback = new Oracle(context);
|
|
@@ -75,20 +75,20 @@ export async function executePrivateFunction(
|
|
|
75
75
|
|
|
76
76
|
log.debug(`Returning from call to ${contractAddress.toString()}:${functionSelector}`);
|
|
77
77
|
|
|
78
|
-
return
|
|
78
|
+
return new PrivateExecutionResult(
|
|
79
79
|
acir,
|
|
80
|
+
Buffer.from(artifact.verificationKey!, 'hex'),
|
|
80
81
|
partialWitness,
|
|
81
82
|
callStackItem,
|
|
82
|
-
returnValues: rawReturnValues,
|
|
83
83
|
noteHashLeafIndexMap,
|
|
84
84
|
newNotes,
|
|
85
85
|
noteHashNullifierCounterMap,
|
|
86
|
-
|
|
86
|
+
rawReturnValues,
|
|
87
87
|
nestedExecutions,
|
|
88
88
|
enqueuedPublicFunctionCalls,
|
|
89
|
-
noteEncryptedLogs,
|
|
90
89
|
publicTeardownFunctionCall,
|
|
90
|
+
noteEncryptedLogs,
|
|
91
91
|
encryptedLogs,
|
|
92
92
|
unencryptedLogs,
|
|
93
|
-
|
|
93
|
+
);
|
|
94
94
|
}
|
package/src/client/simulator.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AztecNode, FunctionCall, Note, PrivateExecutionResult, TxExecutionRequest } from '@aztec/circuit-types';
|
|
2
2
|
import { CallContext } from '@aztec/circuits.js';
|
|
3
3
|
import {
|
|
4
4
|
type ArrayType,
|
|
@@ -17,7 +17,6 @@ import { PackedValuesCache } from '../common/packed_values_cache.js';
|
|
|
17
17
|
import { ClientExecutionContext } from './client_execution_context.js';
|
|
18
18
|
import { type DBOracle } from './db_oracle.js';
|
|
19
19
|
import { ExecutionNoteCache } from './execution_note_cache.js';
|
|
20
|
-
import { type ExecutionResult } from './execution_result.js';
|
|
21
20
|
import { executePrivateFunction } from './private_execution.js';
|
|
22
21
|
import { executeUnconstrainedFunction } from './unconstrained_execution.js';
|
|
23
22
|
import { ViewDataOracle } from './view_data_oracle.js';
|
|
@@ -47,7 +46,7 @@ export class AcirSimulator {
|
|
|
47
46
|
contractAddress: AztecAddress,
|
|
48
47
|
msgSender = AztecAddress.fromField(Fr.MAX_FIELD_VALUE),
|
|
49
48
|
scopes?: AztecAddress[],
|
|
50
|
-
): Promise<
|
|
49
|
+
): Promise<PrivateExecutionResult> {
|
|
51
50
|
if (entryPointArtifact.functionType !== FunctionType.PRIVATE) {
|
|
52
51
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as private`);
|
|
53
52
|
}
|
package/src/client/test_utils.ts
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
|
-
import { Fq, Fr,
|
|
1
|
+
import { Fq, Fr, Point } from '@aztec/circuits.js';
|
|
2
2
|
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
3
|
-
import { pedersenCommit } from '@aztec/foundation/crypto';
|
|
4
3
|
|
|
5
4
|
// Copied over from `noir-projects/aztec-nr/aztec/src/generators.nr`
|
|
5
|
+
const GENERATORS = [
|
|
6
|
+
new Point(
|
|
7
|
+
new Fr(0x30426e64aee30e998c13c8ceecda3a77807dbead52bc2f3bf0eae851b4b710c1n),
|
|
8
|
+
new Fr(0x113156a068f603023240c96b4da5474667db3b8711c521c748212a15bc034ea6n),
|
|
9
|
+
false,
|
|
10
|
+
),
|
|
11
|
+
new Point(
|
|
12
|
+
new Fr(0x2825c79cc6a5cbbeef7d6a8f1b6a12b312aa338440aefeb4396148c89147c049n),
|
|
13
|
+
new Fr(0x129bfd1da54b7062d6b544e7e36b90736350f6fba01228c41c72099509f5701en),
|
|
14
|
+
false,
|
|
15
|
+
),
|
|
16
|
+
new Point(
|
|
17
|
+
new Fr(0x0edb1e293c3ce91bfc04e3ceaa50d2c541fa9d091c72eb403efb1cfa2cb3357fn),
|
|
18
|
+
new Fr(0x1341d675fa030ece3113ad53ca34fd13b19b6e9762046734f414824c4d6ade35n),
|
|
19
|
+
false,
|
|
20
|
+
),
|
|
21
|
+
new Point(
|
|
22
|
+
new Fr(0x0e0dad2250583f2a9f0acb04ededf1701b85b0393cae753fe7e14b88af81cb52n),
|
|
23
|
+
new Fr(0x0973b02c5caac339ee4ad5dab51329920f7bf1b6a07e1dabe5df67040b300962n),
|
|
24
|
+
false,
|
|
25
|
+
),
|
|
26
|
+
new Point(
|
|
27
|
+
new Fr(0x2f3342e900e8c488a28931aae68970738fdc68afde2910de7b320c00c902087dn),
|
|
28
|
+
new Fr(0x1bf958dc63cb09d59230603a0269ae86d6f92494da244910351f1132df20fc08n),
|
|
29
|
+
false,
|
|
30
|
+
),
|
|
31
|
+
];
|
|
32
|
+
|
|
6
33
|
const G_SLOT = new Point(
|
|
7
34
|
new Fr(0x041223147b680850dc82e8a55a952d4df20256fe0593d949a9541ca00f0abf15n),
|
|
8
35
|
new Fr(0x0a8c72e60d0e60f5d804549d48f3044d06140b98ed717a9b532af630c1530791n),
|
|
@@ -16,14 +43,14 @@ const G_SLOT = new Point(
|
|
|
16
43
|
* @returns A note hash.
|
|
17
44
|
*/
|
|
18
45
|
export function computeNoteHash(storageSlot: Fr, noteContent: Fr[]): Fr {
|
|
19
|
-
// TODO(#7771): update this to do only 1 MSM call
|
|
20
|
-
const c = pedersenCommit(
|
|
21
|
-
noteContent.map(f => f.toBuffer()),
|
|
22
|
-
GeneratorIndex.NOTE_HIDING_POINT,
|
|
23
|
-
);
|
|
24
|
-
const noteHidingPointBeforeSlotting = new Point(new Fr(c[0]), new Fr(c[1]), false);
|
|
25
|
-
|
|
26
46
|
const grumpkin = new Grumpkin();
|
|
47
|
+
const noteHidingPointBeforeSlotting = noteContent
|
|
48
|
+
.slice(1)
|
|
49
|
+
.reduce(
|
|
50
|
+
(acc, item, i) => grumpkin.add(acc, grumpkin.mul(GENERATORS[i + 1], new Fq(item.toBigInt()))),
|
|
51
|
+
grumpkin.mul(GENERATORS[0], new Fq(noteContent[0].toBigInt())),
|
|
52
|
+
);
|
|
53
|
+
|
|
27
54
|
const slotPoint = grumpkin.mul(G_SLOT, new Fq(storageSlot.toBigInt()));
|
|
28
55
|
const noteHidingPoint = grumpkin.add(noteHidingPointBeforeSlotting, slotPoint);
|
|
29
56
|
return noteHidingPoint.x;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type DecodedReturn,
|
|
3
|
-
type FunctionArtifact,
|
|
4
|
-
type FunctionSelector,
|
|
5
|
-
decodeReturnValues,
|
|
6
|
-
} from '@aztec/foundation/abi';
|
|
1
|
+
import { type AbiDecoded, type FunctionArtifact, type FunctionSelector, decodeFromAbi } from '@aztec/foundation/abi';
|
|
7
2
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
8
3
|
import { type Fr } from '@aztec/foundation/fields';
|
|
9
4
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
@@ -24,7 +19,7 @@ export async function executeUnconstrainedFunction(
|
|
|
24
19
|
functionSelector: FunctionSelector,
|
|
25
20
|
args: Fr[],
|
|
26
21
|
log = createDebugLogger('aztec:simulator:unconstrained_execution'),
|
|
27
|
-
): Promise<
|
|
22
|
+
): Promise<AbiDecoded> {
|
|
28
23
|
log.verbose(`Executing unconstrained function ${contractAddress}:${functionSelector}(${artifact.name})`);
|
|
29
24
|
|
|
30
25
|
const acir = artifact.bytecode;
|
|
@@ -42,6 +37,6 @@ export async function executeUnconstrainedFunction(
|
|
|
42
37
|
});
|
|
43
38
|
|
|
44
39
|
const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness);
|
|
45
|
-
return
|
|
40
|
+
return decodeFromAbi(artifact.returnTypes, returnWitness);
|
|
46
41
|
}
|
|
47
42
|
// docs:end:execute_unconstrained_function
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type AztecAddress, Fr, FunctionSelector, PUBLIC_DISPATCH_SELECTOR } from '@aztec/circuits.js';
|
|
2
|
+
|
|
3
|
+
import { type WorldStateDB } from '../public/public_db_sources.js';
|
|
4
|
+
|
|
5
|
+
export async function getPublicFunctionDebugName(
|
|
6
|
+
db: WorldStateDB,
|
|
7
|
+
contractAddress: AztecAddress,
|
|
8
|
+
fn: FunctionSelector,
|
|
9
|
+
calldata: Fr[],
|
|
10
|
+
): Promise<string> {
|
|
11
|
+
if (fn.equals(FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)))) {
|
|
12
|
+
// If the function is a dispatch, we need to look up the target function which
|
|
13
|
+
// is expected to be the first argument.
|
|
14
|
+
const targetFunction =
|
|
15
|
+
calldata[0] !== undefined
|
|
16
|
+
? await db.getDebugFunctionName(contractAddress, FunctionSelector.fromField(calldata[0]))
|
|
17
|
+
: `<calldata[0] undefined>`;
|
|
18
|
+
return `${targetFunction} (via dispatch)`;
|
|
19
|
+
} else {
|
|
20
|
+
return (await db.getDebugFunctionName(contractAddress, fn)) ?? `${contractAddress}:${fn}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/common/index.ts
CHANGED