@aztec/simulator 0.33.0 → 0.35.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 +4 -1
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +5 -5
- package/dest/acvm/deserialize.d.ts +3 -5
- package/dest/acvm/deserialize.d.ts.map +1 -1
- package/dest/acvm/deserialize.js +6 -9
- package/dest/acvm/oracle/oracle.d.ts +3 -1
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +14 -6
- package/dest/acvm/oracle/typed_oracle.d.ts +2 -0
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +7 -1
- package/dest/avm/avm_execution_environment.d.ts +6 -3
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +12 -9
- package/dest/avm/avm_gas.js +2 -2
- package/dest/avm/avm_machine_state.d.ts +2 -0
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +24 -6
- package/dest/avm/avm_memory_types.js +6 -6
- package/dest/avm/avm_simulator.js +7 -7
- 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 +11 -4
- package/dest/avm/journal/journal.d.ts +15 -13
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +16 -5
- package/dest/avm/journal/trace.d.ts +8 -19
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace.js +48 -116
- package/dest/avm/journal/trace_types.d.ts +23 -4
- package/dest/avm/journal/trace_types.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.d.ts +2 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +14 -6
- package/dest/avm/opcodes/context_getters.js +2 -2
- package/dest/avm/opcodes/external_calls.d.ts +2 -2
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +26 -10
- package/dest/avm/opcodes/hashing.d.ts +8 -8
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +35 -43
- package/dest/avm/serialization/instruction_serialization.d.ts +1 -1
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +2 -2
- package/dest/client/client_execution_context.d.ts +14 -4
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +28 -13
- package/dest/client/private_execution.d.ts +1 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +10 -8
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +6 -5
- package/dest/client/unconstrained_execution.d.ts +1 -1
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +6 -5
- package/dest/client/view_data_oracle.d.ts +2 -2
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +2 -2
- package/dest/common/index.d.ts +1 -1
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +2 -2
- package/dest/common/packed_values_cache.d.ts +28 -0
- package/dest/common/packed_values_cache.d.ts.map +1 -0
- package/dest/common/packed_values_cache.js +50 -0
- package/dest/index.d.ts +1 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/mocks/fixtures.d.ts +42 -0
- package/dest/mocks/fixtures.d.ts.map +1 -0
- package/dest/mocks/fixtures.js +84 -0
- package/dest/mocks/index.d.ts +2 -0
- package/dest/mocks/index.d.ts.map +1 -0
- package/dest/mocks/index.js +2 -0
- package/dest/public/abstract_phase_manager.d.ts +82 -0
- package/dest/public/abstract_phase_manager.d.ts.map +1 -0
- package/dest/public/abstract_phase_manager.js +320 -0
- package/dest/public/app_logic_phase_manager.d.ts +29 -0
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -0
- package/dest/public/app_logic_phase_manager.js +50 -0
- package/dest/public/execution.d.ts +3 -0
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -1
- package/dest/public/executor.d.ts +1 -15
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +80 -83
- package/dest/public/hints_builder.d.ts +23 -0
- package/dest/public/hints_builder.d.ts.map +1 -0
- package/dest/public/hints_builder.js +62 -0
- package/dest/public/index.d.ts +5 -0
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +6 -1
- package/dest/public/phase_manager_factory.d.ts +18 -0
- package/dest/public/phase_manager_factory.d.ts.map +1 -0
- package/dest/public/phase_manager_factory.js +56 -0
- package/dest/public/public_execution_context.d.ts +20 -10
- package/dest/public/public_execution_context.d.ts.map +1 -1
- package/dest/public/public_execution_context.js +35 -23
- package/dest/public/public_executor.d.ts +79 -0
- package/dest/public/public_executor.d.ts.map +1 -0
- package/dest/public/public_executor.js +198 -0
- package/dest/public/public_kernel.d.ts +37 -0
- package/dest/public/public_kernel.d.ts.map +1 -0
- package/dest/public/public_kernel.js +97 -0
- package/dest/public/public_kernel_circuit_simulator.d.ts +31 -0
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +1 -0
- package/dest/public/public_kernel_circuit_simulator.js +2 -0
- package/dest/public/public_processor.d.ts +53 -0
- package/dest/public/public_processor.d.ts.map +1 -0
- package/dest/public/public_processor.js +144 -0
- package/dest/public/setup_phase_manager.d.ts +30 -0
- package/dest/public/setup_phase_manager.d.ts.map +1 -0
- package/dest/public/setup_phase_manager.js +46 -0
- package/dest/public/tail_phase_manager.d.ts +30 -0
- package/dest/public/tail_phase_manager.d.ts.map +1 -0
- package/dest/public/tail_phase_manager.js +60 -0
- package/dest/public/teardown_phase_manager.d.ts +30 -0
- package/dest/public/teardown_phase_manager.d.ts.map +1 -0
- package/dest/public/teardown_phase_manager.js +46 -0
- package/dest/public/transitional_adaptors.d.ts +33 -0
- package/dest/public/transitional_adaptors.d.ts.map +1 -0
- package/dest/public/transitional_adaptors.js +162 -0
- package/dest/public/utils.d.ts +8 -0
- package/dest/public/utils.d.ts.map +1 -0
- package/dest/public/utils.js +29 -0
- package/dest/simulator/acvm_native.d.ts +19 -3
- package/dest/simulator/acvm_native.d.ts.map +1 -1
- package/dest/simulator/acvm_native.js +75 -48
- package/dest/simulator/acvm_wasm.d.ts.map +1 -1
- package/dest/simulator/acvm_wasm.js +3 -4
- package/package.json +8 -5
- package/src/acvm/acvm.ts +8 -5
- package/src/acvm/deserialize.ts +5 -9
- package/src/acvm/oracle/oracle.ts +15 -5
- package/src/acvm/oracle/typed_oracle.ts +8 -0
- package/src/avm/avm_execution_environment.ts +17 -17
- package/src/avm/avm_gas.ts +1 -1
- package/src/avm/avm_machine_state.ts +26 -5
- package/src/avm/avm_memory_types.ts +5 -5
- package/src/avm/avm_simulator.ts +6 -6
- package/src/avm/fixtures/index.ts +14 -1
- package/src/avm/journal/journal.ts +37 -17
- package/src/avm/journal/trace.ts +59 -121
- package/src/avm/journal/trace_types.ts +39 -39
- package/src/avm/opcodes/accrued_substate.ts +17 -5
- package/src/avm/opcodes/context_getters.ts +1 -1
- package/src/avm/opcodes/external_calls.ts +32 -9
- package/src/avm/opcodes/hashing.ts +38 -54
- package/src/avm/serialization/instruction_serialization.ts +1 -1
- package/src/client/client_execution_context.ts +30 -11
- package/src/client/private_execution.ts +9 -8
- package/src/client/simulator.ts +7 -3
- package/src/client/unconstrained_execution.ts +5 -4
- package/src/client/view_data_oracle.ts +1 -1
- package/src/common/index.ts +1 -1
- package/src/common/packed_values_cache.ts +55 -0
- package/src/index.ts +1 -0
- package/src/mocks/fixtures.ts +169 -0
- package/src/mocks/index.ts +1 -0
- package/src/public/abstract_phase_manager.ts +571 -0
- package/src/public/app_logic_phase_manager.ts +76 -0
- package/src/public/execution.ts +4 -0
- package/src/public/executor.ts +93 -93
- package/src/public/hints_builder.ts +119 -0
- package/src/public/index.ts +5 -0
- package/src/public/phase_manager_factory.ts +126 -0
- package/src/public/public_execution_context.ts +43 -37
- package/src/public/public_executor.ts +267 -0
- package/src/public/public_kernel.ts +139 -0
- package/src/public/public_kernel_circuit_simulator.ts +36 -0
- package/src/public/public_processor.ts +212 -0
- package/src/public/setup_phase_manager.ts +66 -0
- package/src/public/tail_phase_manager.ts +120 -0
- package/src/public/teardown_phase_manager.ts +66 -0
- package/src/public/transitional_adaptors.ts +249 -0
- package/src/public/utils.ts +31 -0
- package/src/simulator/acvm_native.ts +94 -47
- package/src/simulator/acvm_wasm.ts +7 -3
- package/dest/avm/temporary_executor_migration.d.ts +0 -27
- package/dest/avm/temporary_executor_migration.d.ts.map +0 -1
- package/dest/avm/temporary_executor_migration.js +0 -94
- package/dest/common/packed_args_cache.d.ts +0 -28
- package/dest/common/packed_args_cache.d.ts.map +0 -1
- package/dest/common/packed_args_cache.js +0 -50
- package/src/avm/temporary_executor_migration.ts +0 -136
- package/src/common/packed_args_cache.ts +0 -55
|
@@ -28,7 +28,7 @@ import { Fr, type Point } from '@aztec/foundation/fields';
|
|
|
28
28
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
29
29
|
|
|
30
30
|
import { type NoteData, toACVMWitness } from '../acvm/index.js';
|
|
31
|
-
import { type
|
|
31
|
+
import { type PackedValuesCache } from '../common/packed_values_cache.js';
|
|
32
32
|
import { type DBOracle } from './db_oracle.js';
|
|
33
33
|
import { type ExecutionNoteCache } from './execution_note_cache.js';
|
|
34
34
|
import { type ExecutionResult, type NoteAndSlot } from './execution_result.js';
|
|
@@ -72,7 +72,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
72
72
|
protected readonly historicalHeader: Header,
|
|
73
73
|
/** List of transient auth witnesses to be used during this simulation */
|
|
74
74
|
protected readonly authWitnesses: AuthWitness[],
|
|
75
|
-
private readonly
|
|
75
|
+
private readonly packedValuesCache: PackedValuesCache,
|
|
76
76
|
private readonly noteCache: ExecutionNoteCache,
|
|
77
77
|
protected readonly db: DBOracle,
|
|
78
78
|
private readonly curve: Grumpkin,
|
|
@@ -93,7 +93,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
93
93
|
public getInitialWitness(abi: FunctionAbi) {
|
|
94
94
|
const argumentsSize = countArgumentsSize(abi);
|
|
95
95
|
|
|
96
|
-
const args = this.
|
|
96
|
+
const args = this.packedValuesCache.unpack(this.argsHash);
|
|
97
97
|
|
|
98
98
|
if (args.length !== argumentsSize) {
|
|
99
99
|
throw new Error('Invalid arguments size');
|
|
@@ -175,7 +175,23 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
175
175
|
* @param args - Arguments to pack
|
|
176
176
|
*/
|
|
177
177
|
public packArguments(args: Fr[]): Promise<Fr> {
|
|
178
|
-
return Promise.resolve(this.
|
|
178
|
+
return Promise.resolve(this.packedValuesCache.pack(args));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Pack the given returns.
|
|
183
|
+
* @param returns - Returns to pack
|
|
184
|
+
*/
|
|
185
|
+
public packReturns(returns: Fr[]): Promise<Fr> {
|
|
186
|
+
return Promise.resolve(this.packedValuesCache.pack(returns));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Unpack the given returns.
|
|
191
|
+
* @param returnsHash - Returns hash to unpack
|
|
192
|
+
*/
|
|
193
|
+
public unpackReturns(returnsHash: Fr): Promise<Fr[]> {
|
|
194
|
+
return Promise.resolve(this.packedValuesCache.unpack(returnsHash));
|
|
179
195
|
}
|
|
180
196
|
|
|
181
197
|
/**
|
|
@@ -235,7 +251,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
235
251
|
offset,
|
|
236
252
|
});
|
|
237
253
|
|
|
238
|
-
this.log(
|
|
254
|
+
this.log.debug(
|
|
239
255
|
`Returning ${notes.length} notes for ${this.callContext.storageContractAddress} at ${storageSlot}: ${notes
|
|
240
256
|
.map(n => `${n.nonce.toString()}:[${n.note.items.map(i => i.toString()).join(',')}]`)
|
|
241
257
|
.join(', ')}`,
|
|
@@ -316,7 +332,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
316
332
|
public emitUnencryptedLog(log: UnencryptedL2Log) {
|
|
317
333
|
this.unencryptedLogs.push(log);
|
|
318
334
|
const text = log.toHumanReadable();
|
|
319
|
-
this.log(`Emitted unencrypted log: "${text.length > 100 ? text.slice(0, 100) + '...' : text}"`);
|
|
335
|
+
this.log.verbose(`Emitted unencrypted log: "${text.length > 100 ? text.slice(0, 100) + '...' : text}"`);
|
|
320
336
|
}
|
|
321
337
|
|
|
322
338
|
#checkValidStaticCall(childExecutionResult: ExecutionResult) {
|
|
@@ -349,7 +365,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
349
365
|
isStaticCall: boolean,
|
|
350
366
|
isDelegateCall: boolean,
|
|
351
367
|
) {
|
|
352
|
-
this.log(
|
|
368
|
+
this.log.debug(
|
|
353
369
|
`Calling private function ${this.contractAddress}:${functionSelector} from ${this.callContext.storageContractAddress}`,
|
|
354
370
|
);
|
|
355
371
|
|
|
@@ -375,7 +391,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
375
391
|
derivedCallContext,
|
|
376
392
|
this.historicalHeader,
|
|
377
393
|
this.authWitnesses,
|
|
378
|
-
this.
|
|
394
|
+
this.packedValuesCache,
|
|
379
395
|
this.noteCache,
|
|
380
396
|
this.db,
|
|
381
397
|
this.curve,
|
|
@@ -428,7 +444,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
428
444
|
isDelegateCall,
|
|
429
445
|
isStaticCall,
|
|
430
446
|
);
|
|
431
|
-
const args = this.
|
|
447
|
+
const args = this.packedValuesCache.unpack(argsHash);
|
|
432
448
|
const enqueuedRequest = PublicCallRequest.from({
|
|
433
449
|
args,
|
|
434
450
|
callContext: derivedCallContext,
|
|
@@ -441,7 +457,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
441
457
|
// side-effect counter, that will leak info about how many other private
|
|
442
458
|
// side-effects occurred in the TX. Ultimately the private kernel should
|
|
443
459
|
// just output everything in the proper order without any counters.
|
|
444
|
-
this.log(
|
|
460
|
+
this.log.verbose(
|
|
445
461
|
`Enqueued call to public function (with side-effect counter #${sideEffectCounter}) ${targetContractAddress}:${functionSelector}(${targetArtifact.name})`,
|
|
446
462
|
);
|
|
447
463
|
|
|
@@ -472,9 +488,12 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
472
488
|
isDelegateCall ? this.contractAddress : targetContractAddress,
|
|
473
489
|
portalContractAddress,
|
|
474
490
|
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
|
|
475
492
|
isDelegateCall,
|
|
476
493
|
isStaticCall,
|
|
477
494
|
startSideEffectCounter,
|
|
495
|
+
this.callContext.gasSettings,
|
|
496
|
+
this.callContext.transactionFee,
|
|
478
497
|
);
|
|
479
498
|
}
|
|
480
499
|
|
|
@@ -497,7 +516,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
497
516
|
throw new Error(`No witness for slot ${storageSlot.toString()}`);
|
|
498
517
|
}
|
|
499
518
|
const value = witness.leafPreimage.value;
|
|
500
|
-
this.log(`Oracle storage read: slot=${storageSlot.toString()} value=${value}`);
|
|
519
|
+
this.log.debug(`Oracle storage read: slot=${storageSlot.toString()} value=${value}`);
|
|
501
520
|
values.push(value);
|
|
502
521
|
}
|
|
503
522
|
return values;
|
|
@@ -4,7 +4,7 @@ import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
|
4
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { witnessMapToFields } from '../acvm/deserialize.js';
|
|
8
8
|
import { Oracle, acvm, extractCallStack } from '../acvm/index.js';
|
|
9
9
|
import { ExecutionError } from '../common/errors.js';
|
|
10
10
|
import { type ClientExecutionContext } from './client_execution_context.js';
|
|
@@ -22,11 +22,11 @@ export async function executePrivateFunction(
|
|
|
22
22
|
log = createDebugLogger('aztec:simulator:secret_execution'),
|
|
23
23
|
): Promise<ExecutionResult> {
|
|
24
24
|
const functionSelector = functionData.selector;
|
|
25
|
-
log(`Executing external function ${contractAddress}:${functionSelector}(${artifact.name})`);
|
|
25
|
+
log.verbose(`Executing external function ${contractAddress}:${functionSelector}(${artifact.name})`);
|
|
26
26
|
const acir = artifact.bytecode;
|
|
27
27
|
const initialWitness = context.getInitialWitness(artifact);
|
|
28
28
|
const acvmCallback = new Oracle(context);
|
|
29
|
-
const
|
|
29
|
+
const acirExecutionResult = await acvm(await AcirSimulator.getSolver(), acir, initialWitness, acvmCallback).catch(
|
|
30
30
|
(err: Error) => {
|
|
31
31
|
throw new ExecutionError(
|
|
32
32
|
err.message,
|
|
@@ -39,8 +39,8 @@ export async function executePrivateFunction(
|
|
|
39
39
|
);
|
|
40
40
|
},
|
|
41
41
|
);
|
|
42
|
-
|
|
43
|
-
const returnWitness =
|
|
42
|
+
const partialWitness = acirExecutionResult.partialWitness;
|
|
43
|
+
const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness);
|
|
44
44
|
const publicInputs = PrivateCircuitPublicInputs.fromFields(returnWitness);
|
|
45
45
|
|
|
46
46
|
const encryptedLogs = context.getEncryptedLogs();
|
|
@@ -55,9 +55,10 @@ export async function executePrivateFunction(
|
|
|
55
55
|
|
|
56
56
|
// Mocking the return type to be an array of 4 fields
|
|
57
57
|
// TODO: @LHerskind must be updated as we are progressing with the macros to get the information
|
|
58
|
-
const
|
|
58
|
+
const rawReturnValues = await context.unpackReturns(publicInputs.returnsHash);
|
|
59
|
+
const returnTypes: AbiType[] = [{ kind: 'array', length: rawReturnValues.length, type: { kind: 'field' } }];
|
|
59
60
|
const mockArtifact = { ...artifact, returnTypes };
|
|
60
|
-
const returnValues = decodeReturnValues(mockArtifact,
|
|
61
|
+
const returnValues = decodeReturnValues(mockArtifact, rawReturnValues);
|
|
61
62
|
|
|
62
63
|
const noteHashReadRequestPartialWitnesses = context.getNoteHashReadRequestPartialWitnesses(
|
|
63
64
|
publicInputs.noteHashReadRequests,
|
|
@@ -66,7 +67,7 @@ export async function executePrivateFunction(
|
|
|
66
67
|
const nestedExecutions = context.getNestedExecutions();
|
|
67
68
|
const enqueuedPublicFunctionCalls = context.getEnqueuedPublicFunctionCalls();
|
|
68
69
|
|
|
69
|
-
log(`Returning from call to ${contractAddress.toString()}:${functionSelector}`);
|
|
70
|
+
log.debug(`Returning from call to ${contractAddress.toString()}:${functionSelector}`);
|
|
70
71
|
|
|
71
72
|
return {
|
|
72
73
|
acir,
|
package/src/client/simulator.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
|
16
16
|
import { type WasmBlackBoxFunctionSolver, createBlackBoxSolver } from '@noir-lang/acvm_js';
|
|
17
17
|
|
|
18
18
|
import { createSimulationError } from '../common/errors.js';
|
|
19
|
-
import {
|
|
19
|
+
import { PackedValuesCache } from '../common/packed_values_cache.js';
|
|
20
20
|
import { ClientExecutionContext } from './client_execution_context.js';
|
|
21
21
|
import { type DBOracle } from './db_oracle.js';
|
|
22
22
|
import { ExecutionNoteCache } from './execution_note_cache.js';
|
|
@@ -89,14 +89,18 @@ export class AcirSimulator {
|
|
|
89
89
|
// reserve the first side effect for the tx hash (inserted by the private kernel)
|
|
90
90
|
const startSideEffectCounter = 1;
|
|
91
91
|
|
|
92
|
+
const transactionFee = Fr.ZERO;
|
|
92
93
|
const callContext = new CallContext(
|
|
93
94
|
msgSender,
|
|
94
95
|
contractAddress,
|
|
95
96
|
portalContractAddress,
|
|
96
97
|
FunctionSelector.fromNameAndParameters(entryPointArtifact.name, entryPointArtifact.parameters),
|
|
98
|
+
request.gasSettings.getInitialAvailable(),
|
|
97
99
|
false,
|
|
98
100
|
false,
|
|
99
101
|
startSideEffectCounter,
|
|
102
|
+
request.gasSettings,
|
|
103
|
+
transactionFee,
|
|
100
104
|
);
|
|
101
105
|
const context = new ClientExecutionContext(
|
|
102
106
|
contractAddress,
|
|
@@ -105,7 +109,7 @@ export class AcirSimulator {
|
|
|
105
109
|
callContext,
|
|
106
110
|
header,
|
|
107
111
|
request.authWitnesses,
|
|
108
|
-
|
|
112
|
+
PackedValuesCache.create(request.packedArguments),
|
|
109
113
|
new ExecutionNoteCache(),
|
|
110
114
|
this.db,
|
|
111
115
|
curve,
|
|
@@ -194,7 +198,7 @@ export class AcirSimulator {
|
|
|
194
198
|
const maxNoteFields = (artifact.parameters[artifact.parameters.length - 1].type as ArrayType).length;
|
|
195
199
|
if (maxNoteFields < note.items.length) {
|
|
196
200
|
throw new Error(
|
|
197
|
-
`The note being processed has ${note.items.length} fields, while "compute_note_hash_and_nullifier" can only handle a maximum of ${maxNoteFields} fields. Please
|
|
201
|
+
`The note being processed has ${note.items.length} fields, while "compute_note_hash_and_nullifier" can only handle a maximum of ${maxNoteFields} fields. Please reduce the number of fields in your note.`,
|
|
198
202
|
);
|
|
199
203
|
}
|
|
200
204
|
|
|
@@ -4,7 +4,7 @@ import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
|
4
4
|
import { type Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { witnessMapToFields } from '../acvm/deserialize.js';
|
|
8
8
|
import { Oracle, acvm, extractCallStack, toACVMWitness } from '../acvm/index.js';
|
|
9
9
|
import { ExecutionError } from '../common/errors.js';
|
|
10
10
|
import { AcirSimulator } from './simulator.js';
|
|
@@ -23,11 +23,11 @@ export async function executeUnconstrainedFunction(
|
|
|
23
23
|
log = createDebugLogger('aztec:simulator:unconstrained_execution'),
|
|
24
24
|
): Promise<DecodedReturn> {
|
|
25
25
|
const functionSelector = functionData.selector;
|
|
26
|
-
log(`Executing unconstrained function ${contractAddress}:${functionSelector}`);
|
|
26
|
+
log.verbose(`Executing unconstrained function ${contractAddress}:${functionSelector}(${artifact.name})`);
|
|
27
27
|
|
|
28
28
|
const acir = artifact.bytecode;
|
|
29
29
|
const initialWitness = toACVMWitness(0, args);
|
|
30
|
-
const
|
|
30
|
+
const acirExecutionResult = await acvm(
|
|
31
31
|
await AcirSimulator.getSolver(),
|
|
32
32
|
acir,
|
|
33
33
|
initialWitness,
|
|
@@ -44,6 +44,7 @@ export async function executeUnconstrainedFunction(
|
|
|
44
44
|
);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness);
|
|
48
|
+
return decodeReturnValues(artifact, returnWitness);
|
|
48
49
|
}
|
|
49
50
|
// docs:end:execute_unconstrained_function
|
|
@@ -257,7 +257,7 @@ export class ViewDataOracle extends TypedOracle {
|
|
|
257
257
|
const storageSlot = new Fr(startStorageSlot.value + i);
|
|
258
258
|
const value = await this.aztecNode.getPublicStorageAt(this.contractAddress, storageSlot);
|
|
259
259
|
|
|
260
|
-
this.log(`Oracle storage read: slot=${storageSlot.toString()} value=${value}`);
|
|
260
|
+
this.log.debug(`Oracle storage read: slot=${storageSlot.toString()} value=${value}`);
|
|
261
261
|
values.push(value);
|
|
262
262
|
}
|
|
263
263
|
return values;
|
package/src/common/index.ts
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { PackedValues } from '@aztec/circuit-types';
|
|
2
|
+
import { Fr } from '@aztec/circuits.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A cache for packed values (arguments, returns) during transaction execution.
|
|
6
|
+
*/
|
|
7
|
+
export class PackedValuesCache {
|
|
8
|
+
private cache: Map<bigint, Fr[]>;
|
|
9
|
+
|
|
10
|
+
constructor(initialArguments: PackedValues[] = []) {
|
|
11
|
+
this.cache = new Map();
|
|
12
|
+
for (const initialArg of initialArguments) {
|
|
13
|
+
this.cache.set(initialArg.hash.toBigInt(), initialArg.values);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new packed values cache.
|
|
19
|
+
* @param initialArguments - The initial arguments to add to the cache.
|
|
20
|
+
* @returns The new packed values cache.
|
|
21
|
+
*/
|
|
22
|
+
public static create(initialArguments: PackedValues[] = []) {
|
|
23
|
+
return new PackedValuesCache(initialArguments);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Unpacks packed values.
|
|
28
|
+
* @param hash - The hash of the packed values.
|
|
29
|
+
* @returns The unpacked values.
|
|
30
|
+
*/
|
|
31
|
+
public unpack(hash: Fr): Fr[] {
|
|
32
|
+
if (hash.equals(Fr.ZERO)) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
const packedValues = this.cache.get(hash.value);
|
|
36
|
+
if (!packedValues) {
|
|
37
|
+
throw new Error(`Packed values for hash ${hash.toString()} not found in cache`);
|
|
38
|
+
}
|
|
39
|
+
return packedValues;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Packs values.
|
|
44
|
+
* @param values - The values to pack.
|
|
45
|
+
* @returns The hash of the packed values.
|
|
46
|
+
*/
|
|
47
|
+
public pack(values: Fr[]) {
|
|
48
|
+
if (values.length === 0) {
|
|
49
|
+
return Fr.ZERO;
|
|
50
|
+
}
|
|
51
|
+
const packedValues = PackedValues.fromValues(values);
|
|
52
|
+
this.cache.set(packedValues.hash.value, packedValues.values);
|
|
53
|
+
return packedValues.hash;
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { type FunctionCall, type SimulationError, UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
|
|
2
|
+
import {
|
|
3
|
+
ARGS_LENGTH,
|
|
4
|
+
type AztecAddress,
|
|
5
|
+
CallContext,
|
|
6
|
+
CallRequest,
|
|
7
|
+
type ContractStorageUpdateRequest,
|
|
8
|
+
EthAddress,
|
|
9
|
+
Fr,
|
|
10
|
+
FunctionData,
|
|
11
|
+
Gas,
|
|
12
|
+
GasSettings,
|
|
13
|
+
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
14
|
+
type PrivateKernelTailCircuitPublicInputs,
|
|
15
|
+
type PublicCallRequest,
|
|
16
|
+
} from '@aztec/circuits.js';
|
|
17
|
+
import { makeAztecAddress, makeSelector } from '@aztec/circuits.js/testing';
|
|
18
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
19
|
+
|
|
20
|
+
import { type PublicExecution, type PublicExecutionResult } from '../public/execution.js';
|
|
21
|
+
|
|
22
|
+
export class PublicExecutionResultBuilder {
|
|
23
|
+
private _execution: PublicExecution;
|
|
24
|
+
private _nestedExecutions: PublicExecutionResult[] = [];
|
|
25
|
+
private _contractStorageUpdateRequests: ContractStorageUpdateRequest[] = [];
|
|
26
|
+
private _returnValues: Fr[] = [];
|
|
27
|
+
private _reverted = false;
|
|
28
|
+
private _revertReason: SimulationError | undefined = undefined;
|
|
29
|
+
|
|
30
|
+
constructor(execution: PublicExecution) {
|
|
31
|
+
this._execution = execution;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static fromPublicCallRequest({
|
|
35
|
+
request,
|
|
36
|
+
returnValues = [new Fr(1n)],
|
|
37
|
+
nestedExecutions = [],
|
|
38
|
+
contractStorageUpdateRequests = [],
|
|
39
|
+
}: {
|
|
40
|
+
request: PublicCallRequest;
|
|
41
|
+
returnValues?: Fr[];
|
|
42
|
+
nestedExecutions?: PublicExecutionResult[];
|
|
43
|
+
contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
|
|
44
|
+
}): PublicExecutionResultBuilder {
|
|
45
|
+
const builder = new PublicExecutionResultBuilder(request);
|
|
46
|
+
|
|
47
|
+
builder.withNestedExecutions(...nestedExecutions);
|
|
48
|
+
builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
|
|
49
|
+
builder.withReturnValues(...returnValues);
|
|
50
|
+
|
|
51
|
+
return builder;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static fromFunctionCall({
|
|
55
|
+
from,
|
|
56
|
+
tx,
|
|
57
|
+
returnValues = [new Fr(1n)],
|
|
58
|
+
nestedExecutions = [],
|
|
59
|
+
contractStorageUpdateRequests = [],
|
|
60
|
+
revertReason,
|
|
61
|
+
}: {
|
|
62
|
+
from: AztecAddress;
|
|
63
|
+
tx: FunctionCall;
|
|
64
|
+
returnValues?: Fr[];
|
|
65
|
+
nestedExecutions?: PublicExecutionResult[];
|
|
66
|
+
contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
|
|
67
|
+
revertReason?: SimulationError;
|
|
68
|
+
}) {
|
|
69
|
+
const builder = new PublicExecutionResultBuilder({
|
|
70
|
+
callContext: new CallContext(
|
|
71
|
+
from,
|
|
72
|
+
tx.to,
|
|
73
|
+
EthAddress.ZERO,
|
|
74
|
+
tx.functionData.selector,
|
|
75
|
+
Gas.test(),
|
|
76
|
+
false,
|
|
77
|
+
false,
|
|
78
|
+
0,
|
|
79
|
+
GasSettings.default(),
|
|
80
|
+
Fr.ZERO,
|
|
81
|
+
),
|
|
82
|
+
contractAddress: tx.to,
|
|
83
|
+
functionData: tx.functionData,
|
|
84
|
+
args: tx.args,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
builder.withNestedExecutions(...nestedExecutions);
|
|
88
|
+
builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
|
|
89
|
+
builder.withReturnValues(...returnValues);
|
|
90
|
+
if (revertReason) {
|
|
91
|
+
builder.withReverted(revertReason);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return builder;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
withNestedExecutions(...nested: PublicExecutionResult[]): PublicExecutionResultBuilder {
|
|
98
|
+
this._nestedExecutions.push(...nested);
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
withContractStorageUpdateRequest(...request: ContractStorageUpdateRequest[]): PublicExecutionResultBuilder {
|
|
103
|
+
this._contractStorageUpdateRequests.push(...request);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
withReturnValues(...values: Fr[]): PublicExecutionResultBuilder {
|
|
108
|
+
this._returnValues.push(...values);
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
withReverted(reason: SimulationError): PublicExecutionResultBuilder {
|
|
113
|
+
this._reverted = true;
|
|
114
|
+
this._revertReason = reason;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
build(): PublicExecutionResult {
|
|
119
|
+
return {
|
|
120
|
+
execution: this._execution,
|
|
121
|
+
nestedExecutions: this._nestedExecutions,
|
|
122
|
+
nullifierReadRequests: [],
|
|
123
|
+
nullifierNonExistentReadRequests: [],
|
|
124
|
+
contractStorageUpdateRequests: this._contractStorageUpdateRequests,
|
|
125
|
+
returnValues: padArrayEnd(this._returnValues, Fr.ZERO, 4), // TODO(#5450) Need to use the proper return values here
|
|
126
|
+
newNoteHashes: [],
|
|
127
|
+
newNullifiers: [],
|
|
128
|
+
newL2ToL1Messages: [],
|
|
129
|
+
contractStorageReads: [],
|
|
130
|
+
unencryptedLogs: UnencryptedFunctionL2Logs.empty(),
|
|
131
|
+
startSideEffectCounter: Fr.ZERO,
|
|
132
|
+
endSideEffectCounter: Fr.ZERO,
|
|
133
|
+
reverted: this._reverted,
|
|
134
|
+
revertReason: this._revertReason,
|
|
135
|
+
gasLeft: this._execution.callContext.gasLeft.mul(0.9),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const makeFunctionCall = (
|
|
141
|
+
to = makeAztecAddress(30),
|
|
142
|
+
selector = makeSelector(5),
|
|
143
|
+
args = new Array(ARGS_LENGTH).fill(Fr.ZERO),
|
|
144
|
+
) => ({ to, functionData: new FunctionData(selector, false), args });
|
|
145
|
+
|
|
146
|
+
export function addKernelPublicCallStack(
|
|
147
|
+
kernelOutput: PrivateKernelTailCircuitPublicInputs,
|
|
148
|
+
calls: {
|
|
149
|
+
setupCalls: PublicCallRequest[];
|
|
150
|
+
appLogicCalls: PublicCallRequest[];
|
|
151
|
+
teardownCall: PublicCallRequest;
|
|
152
|
+
},
|
|
153
|
+
) {
|
|
154
|
+
// the first two calls are non-revertible
|
|
155
|
+
// the first is for setup, the second is for teardown
|
|
156
|
+
kernelOutput.forPublic!.endNonRevertibleData.publicCallStack = padArrayEnd(
|
|
157
|
+
// this is a stack, so the first item is the last call
|
|
158
|
+
// and callRequests is in the order of the calls
|
|
159
|
+
[calls.teardownCall.toCallRequest(), ...calls.setupCalls.map(c => c.toCallRequest())],
|
|
160
|
+
CallRequest.empty(),
|
|
161
|
+
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
kernelOutput.forPublic!.end.publicCallStack = padArrayEnd(
|
|
165
|
+
calls.appLogicCalls.map(c => c.toCallRequest()),
|
|
166
|
+
CallRequest.empty(),
|
|
167
|
+
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fixtures.js';
|