@aztec/simulator 0.40.1 → 0.42.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 +2 -2
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +3 -3
- package/dest/acvm/oracle/oracle.d.ts +6 -2
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +31 -19
- package/dest/acvm/oracle/typed_oracle.d.ts +8 -11
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +17 -5
- package/dest/acvm/serialize.js +2 -2
- package/dest/avm/avm_execution_environment.d.ts +4 -3
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +7 -5
- package/dest/avm/avm_gas.d.ts +1 -5
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +67 -73
- package/dest/avm/avm_simulator.d.ts +5 -0
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +12 -4
- package/dest/avm/errors.d.ts +6 -0
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +10 -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 +15 -3
- package/dest/avm/index.d.ts +2 -0
- package/dest/avm/index.d.ts.map +1 -0
- package/dest/avm/index.js +2 -0
- package/dest/avm/journal/host_storage.d.ts +1 -1
- package/dest/avm/journal/host_storage.d.ts.map +1 -1
- package/dest/avm/journal/journal.d.ts +4 -3
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +10 -11
- package/dest/avm/journal/nullifiers.d.ts +17 -5
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +27 -10
- package/dest/avm/journal/public_storage.d.ts +19 -6
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +30 -12
- package/dest/avm/journal/trace.d.ts +2 -0
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace.js +7 -1
- package/dest/avm/journal/trace_types.d.ts +1 -0
- package/dest/avm/journal/trace_types.d.ts.map +1 -1
- package/dest/avm/journal/trace_types.js +1 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +6 -7
- package/dest/avm/opcodes/arithmetic.d.ts +1 -7
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +1 -12
- package/dest/avm/opcodes/conversion.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 +25 -13
- package/dest/avm/opcodes/instruction.d.ts +1 -1
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +6 -4
- package/dest/avm/opcodes/memory.d.ts +0 -4
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +1 -7
- package/dest/avm/opcodes/storage.d.ts +0 -12
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +3 -18
- package/dest/avm/serialization/bytecode_serialization.js +2 -2
- package/dest/client/client_execution_context.d.ts +30 -20
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +59 -39
- package/dest/client/db_oracle.d.ts +17 -12
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/execution_note_cache.js +2 -2
- package/dest/client/execution_result.d.ts +17 -2
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +32 -4
- package/dest/client/private_execution.d.ts +2 -3
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +22 -8
- package/dest/client/simulator.d.ts +0 -16
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +13 -30
- package/dest/client/unconstrained_execution.d.ts +2 -3
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +5 -7
- package/dest/client/view_data_oracle.d.ts +12 -10
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +17 -11
- package/dest/common/index.d.ts +1 -0
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +2 -1
- package/dest/common/return_values.d.ts +11 -0
- package/dest/common/return_values.d.ts.map +1 -0
- package/dest/common/return_values.js +13 -0
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +4 -2
- package/dest/mocks/fixtures.d.ts +15 -10
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +22 -17
- package/dest/{simulator → providers}/acvm_native.d.ts.map +1 -1
- package/dest/{simulator → providers}/acvm_native.js +13 -14
- package/dest/providers/acvm_wasm.d.ts.map +1 -0
- package/dest/providers/acvm_wasm.js +15 -0
- package/dest/providers/index.d.ts.map +1 -0
- package/dest/{simulator → providers}/index.js +1 -1
- package/dest/{simulator → providers}/simulation_provider.d.ts.map +1 -1
- package/dest/{simulator → providers}/simulation_provider.js +1 -1
- package/dest/public/abstract_phase_manager.d.ts +43 -42
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +81 -103
- package/dest/public/app_logic_phase_manager.d.ts +7 -8
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/public/app_logic_phase_manager.js +14 -14
- package/dest/public/{db.d.ts → db_interfaces.d.ts} +3 -3
- package/dest/public/db_interfaces.d.ts.map +1 -0
- package/dest/public/db_interfaces.js +2 -0
- package/dest/public/execution.d.ts +17 -14
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -1
- package/dest/public/executor.d.ts +3 -30
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +32 -279
- package/dest/public/fee_payment.d.ts +11 -0
- package/dest/public/fee_payment.d.ts.map +1 -0
- package/dest/public/fee_payment.js +24 -0
- package/dest/public/hints_builder.d.ts +3 -2
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +8 -4
- package/dest/public/index.d.ts +4 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +5 -3
- package/dest/public/phase_manager_factory.d.ts +1 -1
- package/dest/public/phase_manager_factory.d.ts.map +1 -1
- package/dest/public/{public_executor.d.ts → public_db_sources.d.ts} +3 -2
- package/dest/public/public_db_sources.d.ts.map +1 -0
- package/dest/public/public_db_sources.js +198 -0
- package/dest/public/public_kernel.js +14 -14
- package/dest/public/public_processor.d.ts +8 -6
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +48 -29
- package/dest/public/setup_phase_manager.d.ts +7 -9
- package/dest/public/setup_phase_manager.d.ts.map +1 -1
- package/dest/public/setup_phase_manager.js +11 -20
- package/dest/public/tail_phase_manager.d.ts +5 -11
- package/dest/public/tail_phase_manager.d.ts.map +1 -1
- package/dest/public/tail_phase_manager.js +16 -36
- package/dest/public/teardown_phase_manager.d.ts +7 -9
- package/dest/public/teardown_phase_manager.d.ts.map +1 -1
- package/dest/public/teardown_phase_manager.js +15 -21
- package/dest/public/transitional_adaptors.d.ts +3 -2
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +24 -8
- package/dest/public/utils.d.ts +2 -2
- package/dest/public/utils.d.ts.map +1 -1
- package/dest/public/utils.js +21 -14
- package/package.json +12 -9
- package/src/acvm/acvm.ts +0 -3
- package/src/acvm/oracle/oracle.ts +53 -27
- package/src/acvm/oracle/typed_oracle.ts +25 -16
- package/src/acvm/serialize.ts +1 -1
- package/src/avm/avm_execution_environment.ts +9 -5
- package/src/avm/avm_gas.ts +66 -73
- package/src/avm/avm_simulator.ts +14 -3
- package/src/avm/errors.ts +10 -0
- package/src/avm/fixtures/index.ts +22 -2
- package/src/avm/index.ts +1 -0
- package/src/avm/journal/host_storage.ts +1 -1
- package/src/avm/journal/journal.ts +15 -14
- package/src/avm/journal/nullifiers.ts +27 -14
- package/src/avm/journal/public_storage.ts +30 -16
- package/src/avm/journal/trace.ts +12 -0
- package/src/avm/journal/trace_types.ts +1 -0
- package/src/avm/opcodes/accrued_substate.ts +5 -6
- package/src/avm/opcodes/arithmetic.ts +1 -14
- package/src/avm/opcodes/conversion.ts +1 -1
- package/src/avm/opcodes/external_calls.ts +26 -10
- package/src/avm/opcodes/instruction.ts +5 -3
- package/src/avm/opcodes/memory.ts +1 -8
- package/src/avm/opcodes/storage.ts +3 -20
- package/src/avm/serialization/bytecode_serialization.ts +1 -1
- package/src/client/client_execution_context.ts +70 -44
- package/src/client/db_oracle.ts +18 -12
- package/src/client/execution_note_cache.ts +1 -1
- package/src/client/execution_result.ts +41 -3
- package/src/client/private_execution.ts +38 -20
- package/src/client/simulator.ts +11 -32
- package/src/client/unconstrained_execution.ts +9 -12
- package/src/client/view_data_oracle.ts +20 -12
- package/src/common/index.ts +1 -0
- package/src/common/return_values.ts +18 -0
- package/src/index.ts +3 -1
- package/src/mocks/fixtures.ts +31 -33
- package/src/{simulator → providers}/acvm_native.ts +21 -19
- package/src/{simulator → providers}/acvm_wasm.ts +2 -16
- package/src/public/abstract_phase_manager.ts +146 -207
- package/src/public/app_logic_phase_manager.ts +23 -39
- package/src/public/{db.ts → db_interfaces.ts} +2 -2
- package/src/public/execution.ts +17 -14
- package/src/public/executor.ts +51 -391
- package/src/public/fee_payment.ts +26 -0
- package/src/public/hints_builder.ts +17 -3
- package/src/public/index.ts +4 -2
- package/src/public/phase_manager_factory.ts +1 -1
- package/src/public/{public_executor.ts → public_db_sources.ts} +3 -2
- package/src/public/public_kernel.ts +24 -24
- package/src/public/public_processor.ts +82 -38
- package/src/public/setup_phase_manager.ts +20 -45
- package/src/public/tail_phase_manager.ts +18 -68
- package/src/public/teardown_phase_manager.ts +22 -41
- package/src/public/transitional_adaptors.ts +24 -13
- package/src/public/utils.ts +20 -14
- package/dest/client/logs_cache.d.ts +0 -33
- package/dest/client/logs_cache.d.ts.map +0 -1
- package/dest/client/logs_cache.js +0 -59
- package/dest/public/db.d.ts.map +0 -1
- package/dest/public/db.js +0 -2
- package/dest/public/public_execution_context.d.ts +0 -121
- package/dest/public/public_execution_context.d.ts.map +0 -1
- package/dest/public/public_execution_context.js +0 -214
- package/dest/public/public_executor.d.ts.map +0 -1
- package/dest/public/public_executor.js +0 -197
- package/dest/public/state_actions.d.ts +0 -39
- package/dest/public/state_actions.d.ts.map +0 -1
- package/dest/public/state_actions.js +0 -80
- package/dest/simulator/acvm_wasm.d.ts.map +0 -1
- package/dest/simulator/acvm_wasm.js +0 -22
- package/dest/simulator/index.d.ts.map +0 -1
- package/src/client/logs_cache.ts +0 -65
- package/src/public/public_execution_context.ts +0 -289
- package/src/public/state_actions.ts +0 -102
- /package/dest/{simulator → providers}/acvm_native.d.ts +0 -0
- /package/dest/{simulator → providers}/acvm_wasm.d.ts +0 -0
- /package/dest/{simulator → providers}/index.d.ts +0 -0
- /package/dest/{simulator → providers}/simulation_provider.d.ts +0 -0
- /package/src/{simulator → providers}/index.ts +0 -0
- /package/src/{simulator → providers}/simulation_provider.ts +0 -0
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type DecodedReturn,
|
|
3
|
+
type FunctionArtifact,
|
|
4
|
+
type FunctionSelector,
|
|
5
|
+
decodeReturnValues,
|
|
6
|
+
} from '@aztec/foundation/abi';
|
|
3
7
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
8
|
import { type Fr } from '@aztec/foundation/fields';
|
|
5
9
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
@@ -7,7 +11,6 @@ import { createDebugLogger } from '@aztec/foundation/log';
|
|
|
7
11
|
import { witnessMapToFields } from '../acvm/deserialize.js';
|
|
8
12
|
import { Oracle, acvm, extractCallStack, toACVMWitness } from '../acvm/index.js';
|
|
9
13
|
import { ExecutionError } from '../common/errors.js';
|
|
10
|
-
import { AcirSimulator } from './simulator.js';
|
|
11
14
|
import { type ViewDataOracle } from './view_data_oracle.js';
|
|
12
15
|
|
|
13
16
|
// docs:start:execute_unconstrained_function
|
|
@@ -18,21 +21,15 @@ export async function executeUnconstrainedFunction(
|
|
|
18
21
|
oracle: ViewDataOracle,
|
|
19
22
|
artifact: FunctionArtifact,
|
|
20
23
|
contractAddress: AztecAddress,
|
|
21
|
-
|
|
24
|
+
functionSelector: FunctionSelector,
|
|
22
25
|
args: Fr[],
|
|
23
26
|
log = createDebugLogger('aztec:simulator:unconstrained_execution'),
|
|
24
27
|
): Promise<DecodedReturn> {
|
|
25
|
-
const functionSelector = functionData.selector;
|
|
26
28
|
log.verbose(`Executing unconstrained function ${contractAddress}:${functionSelector}(${artifact.name})`);
|
|
27
29
|
|
|
28
30
|
const acir = artifact.bytecode;
|
|
29
31
|
const initialWitness = toACVMWitness(0, args);
|
|
30
|
-
const acirExecutionResult = await acvm(
|
|
31
|
-
await AcirSimulator.getSolver(),
|
|
32
|
-
acir,
|
|
33
|
-
initialWitness,
|
|
34
|
-
new Oracle(oracle),
|
|
35
|
-
).catch((err: Error) => {
|
|
32
|
+
const acirExecutionResult = await acvm(acir, initialWitness, new Oracle(oracle)).catch((err: Error) => {
|
|
36
33
|
throw new ExecutionError(
|
|
37
34
|
err.message,
|
|
38
35
|
{
|
|
@@ -45,6 +42,6 @@ export async function executeUnconstrainedFunction(
|
|
|
45
42
|
});
|
|
46
43
|
|
|
47
44
|
const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness);
|
|
48
|
-
return decodeReturnValues(artifact, returnWitness);
|
|
45
|
+
return decodeReturnValues(artifact.returnTypes, returnWitness);
|
|
49
46
|
}
|
|
50
47
|
// docs:end:execute_unconstrained_function
|
|
@@ -7,14 +7,14 @@ import {
|
|
|
7
7
|
type NullifierMembershipWitness,
|
|
8
8
|
type PublicDataWitness,
|
|
9
9
|
} from '@aztec/circuit-types';
|
|
10
|
-
import { type Header } from '@aztec/circuits.js';
|
|
10
|
+
import { type Header, type KeyValidationRequest } from '@aztec/circuits.js';
|
|
11
11
|
import { siloNullifier } from '@aztec/circuits.js/hash';
|
|
12
12
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
13
13
|
import { Fr } from '@aztec/foundation/fields';
|
|
14
14
|
import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log';
|
|
15
15
|
import { type ContractInstance } from '@aztec/types/contracts';
|
|
16
16
|
|
|
17
|
-
import { type NoteData,
|
|
17
|
+
import { type NoteData, TypedOracle } from '../acvm/index.js';
|
|
18
18
|
import { type DBOracle } from './db_oracle.js';
|
|
19
19
|
import { pickNotes } from './pick_notes.js';
|
|
20
20
|
|
|
@@ -34,15 +34,22 @@ export class ViewDataOracle extends TypedOracle {
|
|
|
34
34
|
super();
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
public override getBlockNumber(): Promise<number> {
|
|
38
|
+
return this.aztecNode.getBlockNumber();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public override getContractAddress(): Promise<AztecAddress> {
|
|
42
|
+
return Promise.resolve(this.contractAddress);
|
|
43
|
+
}
|
|
44
|
+
|
|
37
45
|
/**
|
|
38
|
-
* Retrieve
|
|
39
|
-
*
|
|
40
|
-
* @
|
|
41
|
-
* @
|
|
42
|
-
* @throws An error if the account is not registered in the database.
|
|
46
|
+
* Retrieve keys associated with a specific master public key and app address.
|
|
47
|
+
* @param pkMHash - The master public key hash.
|
|
48
|
+
* @returns A Promise that resolves to nullifier keys.
|
|
49
|
+
* @throws If the keys are not registered in the key store.
|
|
43
50
|
*/
|
|
44
|
-
public override
|
|
45
|
-
return this.db.
|
|
51
|
+
public override getKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
|
|
52
|
+
return this.db.getKeyValidationRequest(pkMHash, this.contractAddress);
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
/**
|
|
@@ -129,11 +136,12 @@ export class ViewDataOracle extends TypedOracle {
|
|
|
129
136
|
|
|
130
137
|
/**
|
|
131
138
|
* Retrieve the complete address associated to a given address.
|
|
132
|
-
* @param
|
|
139
|
+
* @param account - The account address.
|
|
133
140
|
* @returns A complete address associated with the input address.
|
|
141
|
+
* @throws An error if the account is not registered in the database.
|
|
134
142
|
*/
|
|
135
|
-
public override getCompleteAddress(
|
|
136
|
-
return this.db.getCompleteAddress(
|
|
143
|
+
public override getCompleteAddress(account: AztecAddress): Promise<CompleteAddress> {
|
|
144
|
+
return this.db.getCompleteAddress(account);
|
|
137
145
|
}
|
|
138
146
|
|
|
139
147
|
/**
|
package/src/common/index.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NestedProcessReturnValues } from '@aztec/circuit-types';
|
|
2
|
+
|
|
3
|
+
import type { ExecutionResult } from '../client/execution_result.js';
|
|
4
|
+
import type { PublicExecutionResult } from '../public/execution.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Recursively accummulate the return values of a call result and its nested executions,
|
|
8
|
+
* so they can be retrieved in order.
|
|
9
|
+
* @param executionResult
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export function accumulateReturnValues(
|
|
13
|
+
executionResult: PublicExecutionResult | ExecutionResult,
|
|
14
|
+
): NestedProcessReturnValues {
|
|
15
|
+
const acc = new NestedProcessReturnValues(executionResult.returnValues);
|
|
16
|
+
acc.nested = executionResult.nestedExecutions.map(nestedExecution => accumulateReturnValues(nestedExecution));
|
|
17
|
+
return acc;
|
|
18
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from './acvm/index.js';
|
|
2
|
+
export * from './avm/index.js';
|
|
2
3
|
export * from './client/index.js';
|
|
3
4
|
export * from './common/index.js';
|
|
4
5
|
export * from './public/index.js';
|
|
5
|
-
export * from './
|
|
6
|
+
export * from './providers/index.js';
|
|
6
7
|
export * from './mocks/index.js';
|
|
7
8
|
export * from './stats/index.js';
|
|
9
|
+
export * from './utils.js';
|
package/src/mocks/fixtures.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { type FunctionCall, type SimulationError, UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
3
|
ARGS_LENGTH,
|
|
4
|
+
AvmExecutionHints,
|
|
4
5
|
type AztecAddress,
|
|
5
6
|
CallContext,
|
|
6
|
-
|
|
7
|
+
type ContractStorageRead,
|
|
7
8
|
type ContractStorageUpdateRequest,
|
|
8
9
|
Fr,
|
|
9
|
-
FunctionData,
|
|
10
10
|
Gas,
|
|
11
|
-
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
12
|
-
type PrivateKernelTailCircuitPublicInputs,
|
|
13
11
|
type PublicCallRequest,
|
|
14
12
|
} from '@aztec/circuits.js';
|
|
15
13
|
import { makeAztecAddress, makeSelector } from '@aztec/circuits.js/testing';
|
|
14
|
+
import { FunctionType } from '@aztec/foundation/abi';
|
|
16
15
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
17
16
|
|
|
18
17
|
import { type PublicExecution, type PublicExecutionResult } from '../public/execution.js';
|
|
@@ -21,6 +20,7 @@ export class PublicExecutionResultBuilder {
|
|
|
21
20
|
private _execution: PublicExecution;
|
|
22
21
|
private _nestedExecutions: PublicExecutionResult[] = [];
|
|
23
22
|
private _contractStorageUpdateRequests: ContractStorageUpdateRequest[] = [];
|
|
23
|
+
private _contractStorageReads: ContractStorageRead[] = [];
|
|
24
24
|
private _returnValues: Fr[] = [];
|
|
25
25
|
private _reverted = false;
|
|
26
26
|
private _revertReason: SimulationError | undefined = undefined;
|
|
@@ -34,17 +34,25 @@ export class PublicExecutionResultBuilder {
|
|
|
34
34
|
returnValues = [new Fr(1n)],
|
|
35
35
|
nestedExecutions = [],
|
|
36
36
|
contractStorageUpdateRequests = [],
|
|
37
|
+
contractStorageReads = [],
|
|
38
|
+
revertReason = undefined,
|
|
37
39
|
}: {
|
|
38
40
|
request: PublicCallRequest;
|
|
39
41
|
returnValues?: Fr[];
|
|
40
42
|
nestedExecutions?: PublicExecutionResult[];
|
|
41
43
|
contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
|
|
44
|
+
contractStorageReads?: ContractStorageRead[];
|
|
45
|
+
revertReason?: SimulationError;
|
|
42
46
|
}): PublicExecutionResultBuilder {
|
|
43
47
|
const builder = new PublicExecutionResultBuilder(request);
|
|
44
48
|
|
|
45
49
|
builder.withNestedExecutions(...nestedExecutions);
|
|
46
50
|
builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
|
|
51
|
+
builder.withContractStorageRead(...contractStorageReads);
|
|
47
52
|
builder.withReturnValues(...returnValues);
|
|
53
|
+
if (revertReason) {
|
|
54
|
+
builder.withReverted(revertReason);
|
|
55
|
+
}
|
|
48
56
|
|
|
49
57
|
return builder;
|
|
50
58
|
}
|
|
@@ -55,6 +63,7 @@ export class PublicExecutionResultBuilder {
|
|
|
55
63
|
returnValues = [new Fr(1n)],
|
|
56
64
|
nestedExecutions = [],
|
|
57
65
|
contractStorageUpdateRequests = [],
|
|
66
|
+
contractStorageReads = [],
|
|
58
67
|
revertReason,
|
|
59
68
|
}: {
|
|
60
69
|
from: AztecAddress;
|
|
@@ -62,17 +71,19 @@ export class PublicExecutionResultBuilder {
|
|
|
62
71
|
returnValues?: Fr[];
|
|
63
72
|
nestedExecutions?: PublicExecutionResult[];
|
|
64
73
|
contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
|
|
74
|
+
contractStorageReads?: ContractStorageRead[];
|
|
65
75
|
revertReason?: SimulationError;
|
|
66
76
|
}) {
|
|
67
77
|
const builder = new PublicExecutionResultBuilder({
|
|
68
|
-
callContext: new CallContext(from, tx.to, tx.
|
|
78
|
+
callContext: new CallContext(from, tx.to, tx.selector, false, false, 0),
|
|
69
79
|
contractAddress: tx.to,
|
|
70
|
-
|
|
80
|
+
functionSelector: tx.selector,
|
|
71
81
|
args: tx.args,
|
|
72
82
|
});
|
|
73
83
|
|
|
74
84
|
builder.withNestedExecutions(...nestedExecutions);
|
|
75
85
|
builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
|
|
86
|
+
builder.withContractStorageRead(...contractStorageReads);
|
|
76
87
|
builder.withReturnValues(...returnValues);
|
|
77
88
|
if (revertReason) {
|
|
78
89
|
builder.withReverted(revertReason);
|
|
@@ -91,6 +102,11 @@ export class PublicExecutionResultBuilder {
|
|
|
91
102
|
return this;
|
|
92
103
|
}
|
|
93
104
|
|
|
105
|
+
withContractStorageRead(...reads: ContractStorageRead[]): PublicExecutionResultBuilder {
|
|
106
|
+
this._contractStorageReads.push(...reads);
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
|
|
94
110
|
withReturnValues(...values: Fr[]): PublicExecutionResultBuilder {
|
|
95
111
|
this._returnValues.push(...values);
|
|
96
112
|
return this;
|
|
@@ -106,8 +122,10 @@ export class PublicExecutionResultBuilder {
|
|
|
106
122
|
return {
|
|
107
123
|
execution: this._execution,
|
|
108
124
|
nestedExecutions: this._nestedExecutions,
|
|
125
|
+
noteHashReadRequests: [],
|
|
109
126
|
nullifierReadRequests: [],
|
|
110
127
|
nullifierNonExistentReadRequests: [],
|
|
128
|
+
l1ToL2MsgReadRequests: [],
|
|
111
129
|
contractStorageUpdateRequests: this._contractStorageUpdateRequests,
|
|
112
130
|
returnValues: padArrayEnd(this._returnValues, Fr.ZERO, 4), // TODO(#5450) Need to use the proper return values here
|
|
113
131
|
newNoteHashes: [],
|
|
@@ -116,7 +134,6 @@ export class PublicExecutionResultBuilder {
|
|
|
116
134
|
contractStorageReads: [],
|
|
117
135
|
unencryptedLogsHashes: [],
|
|
118
136
|
unencryptedLogs: UnencryptedFunctionL2Logs.empty(),
|
|
119
|
-
unencryptedLogPreimagesLength: new Fr(4n), // empty logs have len 4
|
|
120
137
|
allUnencryptedLogs: UnencryptedFunctionL2Logs.empty(),
|
|
121
138
|
startSideEffectCounter: Fr.ZERO,
|
|
122
139
|
endSideEffectCounter: Fr.ZERO,
|
|
@@ -125,38 +142,19 @@ export class PublicExecutionResultBuilder {
|
|
|
125
142
|
startGasLeft: Gas.test(),
|
|
126
143
|
endGasLeft: Gas.test(),
|
|
127
144
|
transactionFee: Fr.ZERO,
|
|
145
|
+
calldata: [],
|
|
146
|
+
avmHints: AvmExecutionHints.empty(),
|
|
128
147
|
...overrides,
|
|
129
148
|
};
|
|
130
149
|
}
|
|
131
150
|
}
|
|
132
151
|
|
|
133
152
|
export const makeFunctionCall = (
|
|
153
|
+
name = 'function',
|
|
134
154
|
to = makeAztecAddress(30),
|
|
135
155
|
selector = makeSelector(5),
|
|
156
|
+
type = FunctionType.PUBLIC,
|
|
136
157
|
args = new Array(ARGS_LENGTH).fill(Fr.ZERO),
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
kernelOutput: PrivateKernelTailCircuitPublicInputs,
|
|
141
|
-
calls: {
|
|
142
|
-
setupCalls: PublicCallRequest[];
|
|
143
|
-
appLogicCalls: PublicCallRequest[];
|
|
144
|
-
teardownCall: PublicCallRequest;
|
|
145
|
-
},
|
|
146
|
-
) {
|
|
147
|
-
// the first two calls are non-revertible
|
|
148
|
-
// the first is for setup, the second is for teardown
|
|
149
|
-
kernelOutput.forPublic!.endNonRevertibleData.publicCallStack = padArrayEnd(
|
|
150
|
-
// this is a stack, so the first item is the last call
|
|
151
|
-
// and callRequests is in the order of the calls
|
|
152
|
-
[calls.teardownCall.toCallRequest(), ...calls.setupCalls.map(c => c.toCallRequest())],
|
|
153
|
-
CallRequest.empty(),
|
|
154
|
-
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
kernelOutput.forPublic!.end.publicCallStack = padArrayEnd(
|
|
158
|
-
calls.appLogicCalls.map(c => c.toCallRequest()),
|
|
159
|
-
CallRequest.empty(),
|
|
160
|
-
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
161
|
-
);
|
|
162
|
-
}
|
|
158
|
+
isStatic = false,
|
|
159
|
+
returnTypes = [],
|
|
160
|
+
) => ({ name, to, selector, type, args, isStatic, returnTypes });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { runInDirectory } from '@aztec/foundation/fs';
|
|
2
2
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
4
|
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
@@ -137,23 +137,25 @@ export class NativeACVMSimulator implements SimulationProvider {
|
|
|
137
137
|
async simulateCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
|
|
138
138
|
// Execute the circuit on those initial witness values
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
140
|
+
const operation = async (directory: string) => {
|
|
141
|
+
// Decode the bytecode from base64 since the acvm does not know about base64 encoding
|
|
142
|
+
const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
143
|
+
// Execute the circuit
|
|
144
|
+
const result = await executeNativeCircuit(
|
|
145
|
+
input,
|
|
146
|
+
decodedBytecode,
|
|
147
|
+
directory,
|
|
148
|
+
this.pathToAcvm,
|
|
149
|
+
this.witnessFilename,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
if (result.status == ACVM_RESULT.FAILURE) {
|
|
153
|
+
throw new Error(`Failed to generate witness: ${result.reason}`);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return result.witness;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return await runInDirectory(this.workingDirectory, operation);
|
|
158
160
|
}
|
|
159
161
|
}
|
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types';
|
|
2
2
|
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
type WasmBlackBoxFunctionSolver,
|
|
6
|
-
createBlackBoxSolver,
|
|
7
|
-
executeCircuitWithBlackBoxSolver,
|
|
8
|
-
} from '@noir-lang/acvm_js';
|
|
4
|
+
import { executeCircuit } from '@noir-lang/acvm_js';
|
|
9
5
|
import { type WitnessMap } from '@noir-lang/types';
|
|
10
6
|
|
|
11
7
|
import { type SimulationProvider } from './simulation_provider.js';
|
|
12
8
|
|
|
13
|
-
let solver: Promise<WasmBlackBoxFunctionSolver>;
|
|
14
|
-
|
|
15
|
-
const getSolver = (): Promise<WasmBlackBoxFunctionSolver> => {
|
|
16
|
-
if (!solver) {
|
|
17
|
-
solver = createBlackBoxSolver();
|
|
18
|
-
}
|
|
19
|
-
return solver;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
9
|
export class WASMSimulator implements SimulationProvider {
|
|
23
10
|
async simulateCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
|
|
24
11
|
// Execute the circuit on those initial witness values
|
|
@@ -27,8 +14,7 @@ export class WASMSimulator implements SimulationProvider {
|
|
|
27
14
|
const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
28
15
|
//
|
|
29
16
|
// Execute the circuit
|
|
30
|
-
const _witnessMap = await
|
|
31
|
-
await getSolver(),
|
|
17
|
+
const _witnessMap = await executeCircuit(
|
|
32
18
|
decodedBytecode,
|
|
33
19
|
input,
|
|
34
20
|
foreignCallHandler, // handle calls to debug_log
|