@aztec/simulator 0.46.7 → 0.47.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/acvm/acvm.d.ts +1 -1
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.d.ts +4 -4
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +10 -12
- package/dest/acvm/oracle/typed_oracle.d.ts +9 -6
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +3 -3
- package/dest/acvm/serialize.d.ts +0 -11
- package/dest/acvm/serialize.d.ts.map +1 -1
- package/dest/acvm/serialize.js +1 -26
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +5 -1
- package/dest/avm/fixtures/index.d.ts +2 -1
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +5 -2
- package/dest/avm/opcodes/commitment.d.ts +16 -0
- package/dest/avm/opcodes/commitment.d.ts.map +1 -0
- package/dest/avm/opcodes/commitment.js +50 -0
- package/dest/avm/opcodes/hashing.d.ts +11 -0
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +42 -3
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +7 -2
- package/dest/avm/serialization/instruction_serialization.d.ts +4 -1
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +6 -2
- package/dest/client/client_execution_context.d.ts +17 -12
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +25 -31
- package/dest/client/execution_result.d.ts +12 -6
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +21 -8
- package/dest/mocks/fixtures.d.ts +5 -5
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +6 -9
- package/dest/providers/factory.d.ts +12 -0
- package/dest/providers/factory.d.ts.map +1 -0
- package/dest/providers/factory.js +27 -0
- package/dest/providers/index.d.ts +1 -0
- package/dest/providers/index.d.ts.map +1 -1
- package/dest/providers/index.js +2 -1
- package/dest/public/abstract_phase_manager.d.ts +4 -5
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +16 -83
- package/dest/public/execution.d.ts +8 -10
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +10 -1
- package/dest/public/executor.d.ts +2 -1
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +3 -3
- package/dest/public/index.d.ts +1 -1
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_processor.d.ts +1 -1
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +9 -3
- package/dest/public/side_effect_trace.d.ts +1 -0
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +9 -9
- package/package.json +9 -9
- package/src/acvm/acvm.ts +1 -1
- package/src/acvm/oracle/oracle.ts +9 -7
- package/src/acvm/oracle/typed_oracle.ts +6 -10
- package/src/acvm/serialize.ts +0 -29
- package/src/avm/avm_gas.ts +4 -0
- package/src/avm/fixtures/index.ts +5 -1
- package/src/avm/opcodes/commitment.ts +66 -0
- package/src/avm/opcodes/hashing.ts +53 -2
- package/src/avm/serialization/bytecode_serialization.ts +6 -1
- package/src/avm/serialization/instruction_serialization.ts +4 -0
- package/src/client/client_execution_context.ts +34 -38
- package/src/client/execution_result.ts +25 -10
- package/src/mocks/fixtures.ts +13 -11
- package/src/providers/factory.ts +38 -0
- package/src/providers/index.ts +1 -0
- package/src/public/abstract_phase_manager.ts +22 -102
- package/src/public/execution.ts +30 -14
- package/src/public/executor.ts +4 -3
- package/src/public/index.ts +1 -1
- package/src/public/public_processor.ts +8 -5
- package/src/public/side_effect_trace.ts +13 -7
package/src/public/execution.ts
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type PublicExecutionRequest,
|
|
3
|
+
type SimulationError,
|
|
4
|
+
type UnencryptedFunctionL2Logs,
|
|
5
|
+
} from '@aztec/circuit-types';
|
|
2
6
|
import {
|
|
3
7
|
type AvmExecutionHints,
|
|
4
8
|
type ContractStorageRead,
|
|
5
9
|
type ContractStorageUpdateRequest,
|
|
6
10
|
type Fr,
|
|
11
|
+
Gas,
|
|
7
12
|
type L2ToL1Message,
|
|
8
13
|
type LogHash,
|
|
9
14
|
type NoteHash,
|
|
10
15
|
type Nullifier,
|
|
11
|
-
|
|
16
|
+
PublicCallRequest,
|
|
17
|
+
PublicCallStackItemCompressed,
|
|
12
18
|
type ReadRequest,
|
|
19
|
+
RevertCode,
|
|
13
20
|
} from '@aztec/circuits.js';
|
|
21
|
+
import { computeVarArgsHash } from '@aztec/circuits.js/hash';
|
|
14
22
|
|
|
15
|
-
import { type Gas } from '../avm/avm_gas.js';
|
|
23
|
+
import { type Gas as AvmGas } from '../avm/avm_gas.js';
|
|
16
24
|
|
|
17
25
|
/**
|
|
18
26
|
* The public function execution result.
|
|
@@ -26,9 +34,9 @@ export interface PublicExecutionResult {
|
|
|
26
34
|
/** The side effect counter after executing this function call */
|
|
27
35
|
endSideEffectCounter: Fr;
|
|
28
36
|
/** How much gas was available for this public execution. */
|
|
29
|
-
startGasLeft:
|
|
37
|
+
startGasLeft: AvmGas;
|
|
30
38
|
/** How much gas was left after this public execution. */
|
|
31
|
-
endGasLeft:
|
|
39
|
+
endGasLeft: AvmGas;
|
|
32
40
|
/** Transaction fee set for this tx. */
|
|
33
41
|
transactionFee: Fr;
|
|
34
42
|
|
|
@@ -79,6 +87,8 @@ export interface PublicExecutionResult {
|
|
|
79
87
|
|
|
80
88
|
// TODO(dbanks12): add contract instance read requests
|
|
81
89
|
|
|
90
|
+
/** The requests to call public functions made by this call. */
|
|
91
|
+
publicCallRequests: PublicCallRequest[];
|
|
82
92
|
/** The results of nested calls. */
|
|
83
93
|
nestedExecutions: this[];
|
|
84
94
|
|
|
@@ -89,15 +99,6 @@ export interface PublicExecutionResult {
|
|
|
89
99
|
functionName: string;
|
|
90
100
|
}
|
|
91
101
|
|
|
92
|
-
/**
|
|
93
|
-
* The execution request of a public function.
|
|
94
|
-
* A subset of PublicCallRequest
|
|
95
|
-
*/
|
|
96
|
-
export type PublicExecutionRequest = Pick<
|
|
97
|
-
PublicCallRequest,
|
|
98
|
-
'contractAddress' | 'functionSelector' | 'callContext' | 'args'
|
|
99
|
-
>;
|
|
100
|
-
|
|
101
102
|
/**
|
|
102
103
|
* Returns if the input is a public execution result and not just a public execution.
|
|
103
104
|
* @param input - Public execution or public execution result.
|
|
@@ -131,3 +132,18 @@ export function checkValidStaticCall(
|
|
|
131
132
|
throw new Error('Static call cannot update the state, emit L2->L1 messages or generate logs');
|
|
132
133
|
}
|
|
133
134
|
}
|
|
135
|
+
|
|
136
|
+
export function resultToPublicCallRequest(result: PublicExecutionResult) {
|
|
137
|
+
const request = result.executionRequest;
|
|
138
|
+
const item = new PublicCallStackItemCompressed(
|
|
139
|
+
request.contractAddress,
|
|
140
|
+
request.callContext,
|
|
141
|
+
computeVarArgsHash(request.args),
|
|
142
|
+
computeVarArgsHash(result.returnValues),
|
|
143
|
+
// TODO(@just-mitch): need better mapping from simulator to revert code.
|
|
144
|
+
result.reverted ? RevertCode.APP_LOGIC_REVERTED : RevertCode.OK,
|
|
145
|
+
Gas.from(result.startGasLeft),
|
|
146
|
+
Gas.from(result.endGasLeft),
|
|
147
|
+
);
|
|
148
|
+
return new PublicCallRequest(item, result.startSideEffectCounter.toNumber());
|
|
149
|
+
}
|
package/src/public/executor.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PublicExecutionRequest } from '@aztec/circuit-types';
|
|
1
2
|
import { type AvmSimulationStats } from '@aztec/circuit-types/stats';
|
|
2
3
|
import { Fr, Gas, type GlobalVariables, type Header, type Nullifier, type TxContext } from '@aztec/circuits.js';
|
|
3
4
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
@@ -10,7 +11,7 @@ import { AvmSimulator } from '../avm/avm_simulator.js';
|
|
|
10
11
|
import { HostStorage } from '../avm/journal/host_storage.js';
|
|
11
12
|
import { AvmPersistableStateManager } from '../avm/journal/index.js';
|
|
12
13
|
import { type CommitmentsDB, type PublicContractsDB, type PublicStateDB } from './db_interfaces.js';
|
|
13
|
-
import { type
|
|
14
|
+
import { type PublicExecutionResult } from './execution.js';
|
|
14
15
|
import { PublicSideEffectTrace } from './side_effect_trace.js';
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -47,7 +48,7 @@ export class PublicExecutor {
|
|
|
47
48
|
startSideEffectCounter: number = 0,
|
|
48
49
|
): Promise<PublicExecutionResult> {
|
|
49
50
|
const address = executionRequest.contractAddress;
|
|
50
|
-
const selector = executionRequest.functionSelector;
|
|
51
|
+
const selector = executionRequest.callContext.functionSelector;
|
|
51
52
|
const fnName = (await this.contractsDb.getDebugFunctionName(address, selector)) ?? `${address}:${selector}`;
|
|
52
53
|
|
|
53
54
|
PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}.`);
|
|
@@ -122,7 +123,7 @@ function createAvmExecutionEnvironment(
|
|
|
122
123
|
executionRequest.contractAddress,
|
|
123
124
|
executionRequest.callContext.storageContractAddress,
|
|
124
125
|
executionRequest.callContext.msgSender,
|
|
125
|
-
executionRequest.functionSelector,
|
|
126
|
+
executionRequest.callContext.functionSelector,
|
|
126
127
|
/*contractCallDepth=*/ Fr.zero(),
|
|
127
128
|
transactionFee,
|
|
128
129
|
header,
|
package/src/public/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './abstract_phase_manager.js';
|
|
2
2
|
export * from './db_interfaces.js';
|
|
3
|
-
export { isPublicExecutionResult, type
|
|
3
|
+
export { isPublicExecutionResult, type PublicExecutionResult } from './execution.js';
|
|
4
4
|
export { PublicExecutor } from './executor.js';
|
|
5
5
|
export * from './fee_payment.js';
|
|
6
6
|
export { HintsBuilder } from './hints_builder.js';
|
|
@@ -59,11 +59,8 @@ export class PublicProcessorFactory {
|
|
|
59
59
|
* @param newContracts - Provides access to contract bytecode for public executions.
|
|
60
60
|
* @returns A new instance of a PublicProcessor.
|
|
61
61
|
*/
|
|
62
|
-
public
|
|
63
|
-
historicalHeader
|
|
64
|
-
globalVariables: GlobalVariables,
|
|
65
|
-
): Promise<PublicProcessor> {
|
|
66
|
-
historicalHeader = historicalHeader ?? (await this.merkleTree.buildInitialHeader());
|
|
62
|
+
public create(historicalHeader: Header | undefined, globalVariables: GlobalVariables): PublicProcessor {
|
|
63
|
+
historicalHeader = historicalHeader ?? this.merkleTree.getInitialHeader();
|
|
67
64
|
|
|
68
65
|
const publicContractsDB = new ContractsDataSourcePublicDB(this.contractDataSource);
|
|
69
66
|
const worldStatePublicDB = new WorldStatePublicDB(this.merkleTree);
|
|
@@ -128,6 +125,12 @@ export class PublicProcessor {
|
|
|
128
125
|
const [processedTx, returnValues] = !tx.hasPublicCalls()
|
|
129
126
|
? [makeProcessedTx(tx, tx.data.toKernelCircuitPublicInputs(), [])]
|
|
130
127
|
: await this.processTxWithPublicCalls(tx);
|
|
128
|
+
this.log.debug(`Processed tx`, {
|
|
129
|
+
txHash: processedTx.hash,
|
|
130
|
+
historicalHeaderHash: processedTx.data.constants.historicalHeader.hash(),
|
|
131
|
+
blockNumber: processedTx.data.constants.globalVariables.blockNumber,
|
|
132
|
+
lastArchiveRoot: processedTx.data.constants.historicalHeader.lastArchive.root,
|
|
133
|
+
});
|
|
131
134
|
|
|
132
135
|
// Set fee payment update request into the processed tx
|
|
133
136
|
processedTx.finalPublicDataUpdateRequests = await this.createFinalDataUpdateRequests(processedTx);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UnencryptedFunctionL2Logs, UnencryptedL2Log } from '@aztec/circuit-types';
|
|
1
|
+
import { PublicExecutionRequest, UnencryptedFunctionL2Logs, UnencryptedL2Log } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
3
|
AvmContractInstanceHint,
|
|
4
4
|
AvmExecutionHints,
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
LogHash,
|
|
15
15
|
NoteHash,
|
|
16
16
|
Nullifier,
|
|
17
|
+
type PublicCallRequest,
|
|
17
18
|
ReadRequest,
|
|
18
19
|
} from '@aztec/circuits.js';
|
|
19
20
|
import { Fr } from '@aztec/foundation/fields';
|
|
@@ -23,7 +24,7 @@ import { type ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
|
23
24
|
import { type AvmContractCallResult } from '../avm/avm_contract_call_result.js';
|
|
24
25
|
import { type AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
|
|
25
26
|
import { createSimulationError } from '../common/errors.js';
|
|
26
|
-
import { type
|
|
27
|
+
import { type PublicExecutionResult, resultToPublicCallRequest } from './execution.js';
|
|
27
28
|
import { type PublicSideEffectTraceInterface } from './side_effect_trace_interface.js';
|
|
28
29
|
|
|
29
30
|
export type TracedContractInstance = { exists: boolean } & ContractInstanceWithAddress;
|
|
@@ -51,6 +52,8 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
51
52
|
private allUnencryptedLogs: UnencryptedL2Log[] = [];
|
|
52
53
|
private unencryptedLogsHashes: LogHash[] = [];
|
|
53
54
|
|
|
55
|
+
private publicCallRequests: PublicCallRequest[] = [];
|
|
56
|
+
|
|
54
57
|
private gotContractInstances: ContractInstanceWithAddress[] = [];
|
|
55
58
|
|
|
56
59
|
private nestedExecutions: PublicExecutionResult[] = [];
|
|
@@ -247,6 +250,9 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
247
250
|
result.startGasLeft.daGas - result.endGasLeft.daGas,
|
|
248
251
|
result.startGasLeft.l2Gas - result.endGasLeft.l2Gas,
|
|
249
252
|
);
|
|
253
|
+
|
|
254
|
+
this.publicCallRequests.push(resultToPublicCallRequest(result));
|
|
255
|
+
|
|
250
256
|
this.avmCircuitHints.externalCalls.items.push(
|
|
251
257
|
new AvmExternalCallHint(
|
|
252
258
|
/*success=*/ new Fr(result.reverted ? 0 : 1),
|
|
@@ -305,6 +311,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
305
311
|
// TODO(dbanks12): process contract instance read requests in public kernel
|
|
306
312
|
//gotContractInstances: this.gotContractInstances,
|
|
307
313
|
|
|
314
|
+
publicCallRequests: this.publicCallRequests,
|
|
308
315
|
nestedExecutions: this.nestedExecutions,
|
|
309
316
|
|
|
310
317
|
avmCircuitHints: this.avmCircuitHints,
|
|
@@ -325,11 +332,10 @@ function createPublicExecutionRequest(avmEnvironment: AvmExecutionEnvironment):
|
|
|
325
332
|
isDelegateCall: avmEnvironment.isDelegateCall,
|
|
326
333
|
isStaticCall: avmEnvironment.isStaticCall,
|
|
327
334
|
});
|
|
328
|
-
return
|
|
329
|
-
|
|
330
|
-
functionSelector: avmEnvironment.functionSelector,
|
|
335
|
+
return new PublicExecutionRequest(
|
|
336
|
+
avmEnvironment.address,
|
|
331
337
|
callContext,
|
|
332
338
|
// execution request does not contain AvmContextInputs prefix
|
|
333
|
-
|
|
334
|
-
|
|
339
|
+
avmEnvironment.getCalldataWithoutPrefix(),
|
|
340
|
+
);
|
|
335
341
|
}
|