@aztec/simulator 0.43.0 → 0.44.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 -0
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +10 -4
- package/dest/acvm/oracle/typed_oracle.d.ts +5 -3
- 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 +2 -0
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +9 -4
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +2 -3
- package/dest/avm/fixtures/index.d.ts +10 -6
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +8 -15
- package/dest/avm/journal/journal.d.ts +56 -65
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +76 -115
- package/dest/avm/journal/nullifiers.d.ts +21 -8
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +26 -8
- package/dest/avm/journal/public_storage.d.ts +4 -0
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +10 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +4 -4
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +12 -27
- package/dest/avm/test_utils.d.ts +14 -0
- package/dest/avm/test_utils.d.ts.map +1 -0
- package/dest/avm/test_utils.js +36 -0
- package/dest/client/client_execution_context.d.ts +3 -3
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +3 -3
- package/dest/client/execution_note_cache.d.ts.map +1 -1
- package/dest/client/execution_note_cache.js +1 -1
- package/dest/client/execution_result.d.ts +2 -1
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +1 -1
- package/dest/client/index.d.ts +2 -0
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +3 -1
- package/dest/client/simulator.d.ts +3 -3
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +1 -1
- package/dest/client/view_data_oracle.d.ts +2 -0
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +7 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +3 -2
- package/dest/public/abstract_phase_manager.d.ts +1 -0
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +11 -8
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/public/app_logic_phase_manager.js +2 -1
- package/dest/public/execution.d.ts +27 -25
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -1
- package/dest/public/executor.d.ts +9 -4
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +29 -25
- package/dest/public/public_processor.d.ts +5 -2
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +142 -123
- package/dest/public/side_effect_trace.d.ts +86 -0
- package/dest/public/side_effect_trace.d.ts.map +1 -0
- package/dest/public/side_effect_trace.js +222 -0
- package/dest/public/side_effect_trace_interface.d.ts +36 -0
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -0
- package/dest/public/side_effect_trace_interface.js +2 -0
- package/dest/public/teardown_phase_manager.d.ts.map +1 -1
- package/dest/public/teardown_phase_manager.js +2 -1
- package/dest/public/transitional_adaptors.d.ts +2 -6
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +1 -49
- package/package.json +18 -9
- package/src/acvm/oracle/oracle.ts +11 -3
- package/src/acvm/oracle/typed_oracle.ts +17 -3
- package/src/avm/avm_execution_environment.ts +10 -3
- package/src/avm/avm_simulator.ts +2 -3
- package/src/avm/fixtures/index.ts +18 -17
- package/src/avm/journal/journal.ts +114 -223
- package/src/avm/journal/nullifiers.ts +30 -13
- package/src/avm/journal/public_storage.ts +10 -0
- package/src/avm/opcodes/accrued_substate.ts +7 -3
- package/src/avm/opcodes/external_calls.ts +12 -34
- package/src/avm/test_utils.ts +53 -0
- package/src/client/client_execution_context.ts +10 -4
- package/src/client/execution_note_cache.ts +0 -1
- package/src/client/execution_result.ts +2 -1
- package/src/client/index.ts +2 -0
- package/src/client/simulator.ts +8 -2
- package/src/client/view_data_oracle.ts +8 -0
- package/src/mocks/fixtures.ts +2 -1
- package/src/public/abstract_phase_manager.ts +22 -11
- package/src/public/app_logic_phase_manager.ts +1 -0
- package/src/public/execution.ts +35 -25
- package/src/public/executor.ts +44 -37
- package/src/public/public_processor.ts +11 -2
- package/src/public/side_effect_trace.ts +323 -0
- package/src/public/side_effect_trace_interface.ts +41 -0
- package/src/public/teardown_phase_manager.ts +1 -0
- package/src/public/transitional_adaptors.ts +2 -100
- package/dest/avm/journal/trace.d.ts +0 -33
- package/dest/avm/journal/trace.d.ts.map +0 -1
- package/dest/avm/journal/trace.js +0 -152
- package/dest/avm/journal/trace_types.d.ts +0 -55
- package/dest/avm/journal/trace_types.d.ts.map +0 -1
- package/dest/avm/journal/trace_types.js +0 -2
- package/src/avm/journal/trace.ts +0 -181
- package/src/avm/journal/trace_types.ts +0 -91
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FunctionSelector, Gas } from '@aztec/circuits.js';
|
|
2
2
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
3
|
|
|
4
|
-
import { convertAvmResultsToPxResult, createPublicExecution } from '../../public/transitional_adaptors.js';
|
|
5
4
|
import type { AvmContext } from '../avm_context.js';
|
|
6
5
|
import { gasLeftToGas } from '../avm_gas.js';
|
|
7
6
|
import { Field, TypeTag, Uint8 } from '../avm_memory_types.js';
|
|
@@ -24,7 +23,6 @@ abstract class ExternalCall extends Instruction {
|
|
|
24
23
|
OperandType.UINT32,
|
|
25
24
|
OperandType.UINT32,
|
|
26
25
|
OperandType.UINT32,
|
|
27
|
-
/* temporary function selector */
|
|
28
26
|
OperandType.UINT32,
|
|
29
27
|
];
|
|
30
28
|
|
|
@@ -37,8 +35,8 @@ abstract class ExternalCall extends Instruction {
|
|
|
37
35
|
private retOffset: number,
|
|
38
36
|
private retSize: number,
|
|
39
37
|
private successOffset: number,
|
|
40
|
-
// Function selector is temporary since eventually public contract bytecode will be one
|
|
41
|
-
// containing all functions, and function selector will become an application-level mechanism
|
|
38
|
+
// NOTE: Function selector is likely temporary since eventually public contract bytecode will be one
|
|
39
|
+
// blob containing all functions, and function selector will become an application-level mechanism
|
|
42
40
|
// (e.g. first few bytes of calldata + compiler-generated jump table)
|
|
43
41
|
private functionSelectorOffset: number,
|
|
44
42
|
) {
|
|
@@ -81,7 +79,6 @@ abstract class ExternalCall extends Instruction {
|
|
|
81
79
|
const allocatedGas = { l2Gas: allocatedL2Gas, daGas: allocatedDaGas };
|
|
82
80
|
context.machineState.consumeGas(allocatedGas);
|
|
83
81
|
|
|
84
|
-
// TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
|
|
85
82
|
const nestedContext = context.createNestedContractCallContext(
|
|
86
83
|
callAddress.toFr(),
|
|
87
84
|
calldata,
|
|
@@ -89,32 +86,9 @@ abstract class ExternalCall extends Instruction {
|
|
|
89
86
|
callType,
|
|
90
87
|
FunctionSelector.fromField(functionSelector),
|
|
91
88
|
);
|
|
92
|
-
const startSideEffectCounter = nestedContext.persistableState.trace.accessCounter;
|
|
93
89
|
|
|
94
|
-
const oldStyleExecution = createPublicExecution(startSideEffectCounter, nestedContext.environment, calldata);
|
|
95
90
|
const simulator = new AvmSimulator(nestedContext);
|
|
96
91
|
const nestedCallResults: AvmContractCallResults = await simulator.execute();
|
|
97
|
-
const pxResults = convertAvmResultsToPxResult(
|
|
98
|
-
nestedCallResults,
|
|
99
|
-
startSideEffectCounter,
|
|
100
|
-
oldStyleExecution,
|
|
101
|
-
Gas.from(allocatedGas),
|
|
102
|
-
nestedContext,
|
|
103
|
-
simulator.getBytecode(),
|
|
104
|
-
);
|
|
105
|
-
// store the old PublicExecutionResult object to maintain a recursive data structure for the old kernel
|
|
106
|
-
context.persistableState.transitionalExecutionResult.nestedExecutions.push(pxResults);
|
|
107
|
-
// END TRANSITIONAL
|
|
108
|
-
|
|
109
|
-
// const nestedContext = context.createNestedContractCallContext(
|
|
110
|
-
// callAddress.toFr(),
|
|
111
|
-
// calldata,
|
|
112
|
-
// allocatedGas,
|
|
113
|
-
// this.type,
|
|
114
|
-
// FunctionSelector.fromField(functionSelector),
|
|
115
|
-
// );
|
|
116
|
-
// const nestedCallResults: AvmContractCallResults = await new AvmSimulator(nestedContext).execute();
|
|
117
|
-
|
|
118
92
|
const success = !nestedCallResults.reverted;
|
|
119
93
|
|
|
120
94
|
// TRANSITIONAL: We rethrow here so that the MESSAGE gets propagated.
|
|
@@ -143,12 +117,16 @@ abstract class ExternalCall extends Instruction {
|
|
|
143
117
|
// Refund unused gas
|
|
144
118
|
context.machineState.refundGas(gasLeftToGas(nestedContext.machineState));
|
|
145
119
|
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
120
|
+
// Accept the nested call's state and trace the nested call
|
|
121
|
+
await context.persistableState.processNestedCall(
|
|
122
|
+
/*nestedState=*/ nestedContext.persistableState,
|
|
123
|
+
/*success=*/ success,
|
|
124
|
+
/*nestedEnvironment=*/ nestedContext.environment,
|
|
125
|
+
/*startGasLeft=*/ Gas.from(allocatedGas),
|
|
126
|
+
/*endGasLeft=*/ Gas.from(nestedContext.machineState.gasLeft),
|
|
127
|
+
/*bytecode=*/ simulator.getBytecode()!,
|
|
128
|
+
/*avmCallResults=*/ nestedCallResults,
|
|
129
|
+
);
|
|
152
130
|
|
|
153
131
|
memory.assert(memoryOperations);
|
|
154
132
|
context.machineState.incrementPc();
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Fr } from '@aztec/circuits.js';
|
|
2
|
+
import { type ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
3
|
+
|
|
4
|
+
import { type jest } from '@jest/globals';
|
|
5
|
+
import { mock } from 'jest-mock-extended';
|
|
6
|
+
|
|
7
|
+
import { type CommitmentsDB, type PublicContractsDB, type PublicStateDB } from '../public/db_interfaces.js';
|
|
8
|
+
import { type PublicSideEffectTraceInterface } from '../public/side_effect_trace_interface.js';
|
|
9
|
+
import { type HostStorage } from './journal/host_storage.js';
|
|
10
|
+
|
|
11
|
+
export function mockGetBytecode(hs: HostStorage, bytecode: Buffer) {
|
|
12
|
+
(hs as jest.Mocked<HostStorage>).contractsDb.getBytecode.mockResolvedValue(bytecode);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function mockTraceFork(trace: PublicSideEffectTraceInterface, nestedTrace?: PublicSideEffectTraceInterface) {
|
|
16
|
+
(trace as jest.Mocked<PublicSideEffectTraceInterface>).fork.mockReturnValue(
|
|
17
|
+
nestedTrace ?? mock<PublicSideEffectTraceInterface>(),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function mockStorageRead(hs: HostStorage, value: Fr) {
|
|
22
|
+
(hs.publicStateDb as jest.Mocked<PublicStateDB>).storageRead.mockResolvedValue(value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function mockStorageReadWithMap(hs: HostStorage, mockedStorage: Map<bigint, Fr>) {
|
|
26
|
+
(hs.publicStateDb as jest.Mocked<PublicStateDB>).storageRead.mockImplementation((_address, slot) =>
|
|
27
|
+
Promise.resolve(mockedStorage.get(slot.toBigInt()) ?? Fr.ZERO),
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function mockNoteHashExists(hs: HostStorage, leafIndex: Fr, _value?: Fr) {
|
|
32
|
+
(hs.commitmentsDb as jest.Mocked<CommitmentsDB>).getCommitmentIndex.mockResolvedValue(leafIndex.toBigInt());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function mockNullifierExists(hs: HostStorage, leafIndex: Fr, _value?: Fr) {
|
|
36
|
+
(hs.commitmentsDb as jest.Mocked<CommitmentsDB>).getNullifierIndex.mockResolvedValue(leafIndex.toBigInt());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function mockL1ToL2MessageExists(hs: HostStorage, leafIndex: Fr, value: Fr, valueAtOtherIndices?: Fr) {
|
|
40
|
+
(hs.commitmentsDb as jest.Mocked<CommitmentsDB>).getL1ToL2LeafValue.mockImplementation((index: bigint) => {
|
|
41
|
+
if (index == leafIndex.toBigInt()) {
|
|
42
|
+
return Promise.resolve(value);
|
|
43
|
+
} else {
|
|
44
|
+
// any indices other than mockAtLeafIndex will return a different value
|
|
45
|
+
// (or undefined if no value is specified for other indices)
|
|
46
|
+
return Promise.resolve(valueAtOtherIndices!);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function mockGetContractInstance(hs: HostStorage, contractInstance: ContractInstanceWithAddress) {
|
|
52
|
+
(hs.contractsDb as jest.Mocked<PublicContractsDB>).getContractInstance.mockResolvedValue(contractInstance);
|
|
53
|
+
}
|
|
@@ -22,7 +22,13 @@ import {
|
|
|
22
22
|
} from '@aztec/circuits.js';
|
|
23
23
|
import { Aes128 } from '@aztec/circuits.js/barretenberg';
|
|
24
24
|
import { computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
EventSelector,
|
|
27
|
+
type FunctionAbi,
|
|
28
|
+
type FunctionArtifact,
|
|
29
|
+
type NoteSelector,
|
|
30
|
+
countArgumentsSize,
|
|
31
|
+
} from '@aztec/foundation/abi';
|
|
26
32
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
27
33
|
import { pedersenHash } from '@aztec/foundation/crypto';
|
|
28
34
|
import { Fr, GrumpkinScalar, type Point } from '@aztec/foundation/fields';
|
|
@@ -288,7 +294,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
288
294
|
*/
|
|
289
295
|
public override notifyCreatedNote(
|
|
290
296
|
storageSlot: Fr,
|
|
291
|
-
noteTypeId:
|
|
297
|
+
noteTypeId: NoteSelector,
|
|
292
298
|
noteItems: Fr[],
|
|
293
299
|
innerNoteHash: Fr,
|
|
294
300
|
counter: number,
|
|
@@ -382,7 +388,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
382
388
|
preimage: Fr[],
|
|
383
389
|
) {
|
|
384
390
|
const event = new Event(preimage);
|
|
385
|
-
const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, eventTypeId);
|
|
391
|
+
const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, EventSelector.fromField(eventTypeId));
|
|
386
392
|
const taggedEvent = new TaggedLog(l1EventPayload);
|
|
387
393
|
|
|
388
394
|
const ephSk = GrumpkinScalar.random();
|
|
@@ -404,7 +410,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
404
410
|
public override computeEncryptedNoteLog(
|
|
405
411
|
contractAddress: AztecAddress,
|
|
406
412
|
storageSlot: Fr,
|
|
407
|
-
noteTypeId:
|
|
413
|
+
noteTypeId: NoteSelector,
|
|
408
414
|
ovKeys: KeyValidationRequest,
|
|
409
415
|
ivpkM: Point,
|
|
410
416
|
preimage: Fr[],
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type UnencryptedL2Log,
|
|
9
9
|
} from '@aztec/circuit-types';
|
|
10
10
|
import { type IsEmpty, type PrivateCallStackItem, PublicCallRequest, sortByCounter } from '@aztec/circuits.js';
|
|
11
|
+
import { type NoteSelector } from '@aztec/foundation/abi';
|
|
11
12
|
import { type Fr } from '@aztec/foundation/fields';
|
|
12
13
|
|
|
13
14
|
import { type ACVMField } from '../acvm/index.js';
|
|
@@ -21,7 +22,7 @@ export interface NoteAndSlot {
|
|
|
21
22
|
/** The storage slot of the note. */
|
|
22
23
|
storageSlot: Fr;
|
|
23
24
|
/** The note type identifier. */
|
|
24
|
-
noteTypeId:
|
|
25
|
+
noteTypeId: NoteSelector;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export class CountedLog<TLog extends UnencryptedL2Log | EncryptedL2NoteLog | EncryptedL2Log> implements IsEmpty {
|
package/src/client/index.ts
CHANGED
package/src/client/simulator.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type FunctionArtifact,
|
|
6
6
|
FunctionSelector,
|
|
7
7
|
FunctionType,
|
|
8
|
+
type NoteSelector,
|
|
8
9
|
encodeArguments,
|
|
9
10
|
} from '@aztec/foundation/abi';
|
|
10
11
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
@@ -140,7 +141,7 @@ export class AcirSimulator {
|
|
|
140
141
|
contractAddress: AztecAddress,
|
|
141
142
|
nonce: Fr,
|
|
142
143
|
storageSlot: Fr,
|
|
143
|
-
noteTypeId:
|
|
144
|
+
noteTypeId: NoteSelector,
|
|
144
145
|
computeNullifier: boolean,
|
|
145
146
|
note: Note,
|
|
146
147
|
) {
|
|
@@ -210,7 +211,12 @@ export class AcirSimulator {
|
|
|
210
211
|
* @param note - The note.
|
|
211
212
|
* @returns The note hash.
|
|
212
213
|
*/
|
|
213
|
-
public async computeInnerNoteHash(
|
|
214
|
+
public async computeInnerNoteHash(
|
|
215
|
+
contractAddress: AztecAddress,
|
|
216
|
+
storageSlot: Fr,
|
|
217
|
+
noteTypeId: NoteSelector,
|
|
218
|
+
note: Note,
|
|
219
|
+
) {
|
|
214
220
|
const { innerNoteHash } = await this.computeNoteHashAndOptionallyANullifier(
|
|
215
221
|
contractAddress,
|
|
216
222
|
Fr.ZERO,
|
|
@@ -42,6 +42,14 @@ export class ViewDataOracle extends TypedOracle {
|
|
|
42
42
|
return Promise.resolve(this.contractAddress);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
public override getChainId(): Promise<Fr> {
|
|
46
|
+
return Promise.resolve(this.aztecNode.getChainId().then(id => new Fr(id)));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public override getVersion(): Promise<Fr> {
|
|
50
|
+
return Promise.resolve(this.aztecNode.getVersion().then(v => new Fr(v)));
|
|
51
|
+
}
|
|
52
|
+
|
|
45
53
|
/**
|
|
46
54
|
* Retrieve keys associated with a specific master public key and app address.
|
|
47
55
|
* @param pkMHash - The master public key hash.
|
package/src/mocks/fixtures.ts
CHANGED
|
@@ -143,7 +143,8 @@ export class PublicExecutionResultBuilder {
|
|
|
143
143
|
endGasLeft: Gas.test(),
|
|
144
144
|
transactionFee: Fr.ZERO,
|
|
145
145
|
calldata: [],
|
|
146
|
-
|
|
146
|
+
avmCircuitHints: AvmExecutionHints.empty(),
|
|
147
|
+
functionName: 'unknown',
|
|
147
148
|
...overrides,
|
|
148
149
|
};
|
|
149
150
|
}
|
|
@@ -77,6 +77,7 @@ export const PhaseIsRevertible: Record<PublicKernelType, boolean> = {
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
export type PublicProvingInformation = {
|
|
80
|
+
functionName: string; // informational only
|
|
80
81
|
calldata: Fr[];
|
|
81
82
|
bytecode: Buffer;
|
|
82
83
|
inputs: PublicKernelCircuitPrivateInputs;
|
|
@@ -89,6 +90,7 @@ export function makeAvmProvingRequest(
|
|
|
89
90
|
): AvmProvingRequest {
|
|
90
91
|
return {
|
|
91
92
|
type: AVM_REQUEST,
|
|
93
|
+
functionName: info.functionName,
|
|
92
94
|
bytecode: info.bytecode,
|
|
93
95
|
calldata: info.calldata,
|
|
94
96
|
avmHints: info.avmHints,
|
|
@@ -264,13 +266,15 @@ export abstract class AbstractPhaseManager {
|
|
|
264
266
|
const isExecutionRequest = !isPublicExecutionResult(current);
|
|
265
267
|
const result = isExecutionRequest
|
|
266
268
|
? await this.publicExecutor.simulate(
|
|
267
|
-
current,
|
|
269
|
+
/*executionRequest=*/ current,
|
|
268
270
|
this.globalVariables,
|
|
269
271
|
/*availableGas=*/ this.getAvailableGas(tx, kernelPublicOutput),
|
|
270
272
|
tx.data.constants.txContext,
|
|
271
273
|
/*pendingNullifiers=*/ this.getSiloedPendingNullifiers(kernelPublicOutput),
|
|
272
274
|
transactionFee,
|
|
273
275
|
/*startSideEffectCounter=*/ AbstractPhaseManager.getMaxSideEffectCounter(kernelPublicOutput) + 1,
|
|
276
|
+
// NOTE: startSideEffectCounter is not the same as the executionRequest's sideEffectCounter
|
|
277
|
+
// (which counts the request itself)
|
|
274
278
|
)
|
|
275
279
|
: current;
|
|
276
280
|
|
|
@@ -282,15 +286,17 @@ export abstract class AbstractPhaseManager {
|
|
|
282
286
|
const functionSelector = result.execution.functionSelector.toString();
|
|
283
287
|
if (result.reverted && !result.revertReason) {
|
|
284
288
|
throw new Error(
|
|
285
|
-
`Simulation of ${result.execution.contractAddress.toString()}:${functionSelector}
|
|
289
|
+
`Simulation of ${result.execution.contractAddress.toString()}:${functionSelector}(${
|
|
290
|
+
result.functionName
|
|
291
|
+
}) reverted with no reason.`,
|
|
286
292
|
);
|
|
287
293
|
}
|
|
288
294
|
|
|
289
295
|
if (result.reverted && !PhaseIsRevertible[this.phase]) {
|
|
290
296
|
this.log.debug(
|
|
291
|
-
`Simulation error on ${result.execution.contractAddress.toString()}:${functionSelector}
|
|
292
|
-
result.
|
|
293
|
-
}`,
|
|
297
|
+
`Simulation error on ${result.execution.contractAddress.toString()}:${functionSelector}(${
|
|
298
|
+
result.functionName
|
|
299
|
+
}) with reason: ${result.revertReason}`,
|
|
294
300
|
);
|
|
295
301
|
throw result.revertReason;
|
|
296
302
|
}
|
|
@@ -302,7 +308,9 @@ export abstract class AbstractPhaseManager {
|
|
|
302
308
|
|
|
303
309
|
// Simulate the public kernel circuit.
|
|
304
310
|
this.log.debug(
|
|
305
|
-
`Running public kernel circuit for ${result.execution.contractAddress.toString()}:${functionSelector}
|
|
311
|
+
`Running public kernel circuit for ${result.execution.contractAddress.toString()}:${functionSelector}(${
|
|
312
|
+
result.functionName
|
|
313
|
+
})`,
|
|
306
314
|
);
|
|
307
315
|
const callData = await this.getPublicCallData(result, isExecutionRequest);
|
|
308
316
|
const [privateInputs, publicInputs] = await this.runKernelCircuit(kernelPublicOutput, callData);
|
|
@@ -310,10 +318,11 @@ export abstract class AbstractPhaseManager {
|
|
|
310
318
|
|
|
311
319
|
// Capture the inputs for later proving in the AVM and kernel.
|
|
312
320
|
const publicProvingInformation: PublicProvingInformation = {
|
|
321
|
+
functionName: result.functionName,
|
|
313
322
|
calldata: result.calldata,
|
|
314
323
|
bytecode: result.bytecode!,
|
|
315
324
|
inputs: privateInputs,
|
|
316
|
-
avmHints: result.
|
|
325
|
+
avmHints: result.avmCircuitHints,
|
|
317
326
|
};
|
|
318
327
|
provingInformationList.push(publicProvingInformation);
|
|
319
328
|
|
|
@@ -322,7 +331,9 @@ export abstract class AbstractPhaseManager {
|
|
|
322
331
|
// but the kernel carries the reverted flag forward. But if the simulator reverts, so should the kernel.
|
|
323
332
|
if (result.reverted && kernelPublicOutput.revertCode.isOK()) {
|
|
324
333
|
throw new Error(
|
|
325
|
-
`Public kernel circuit did not revert on ${result.execution.contractAddress.toString()}:${functionSelector}
|
|
334
|
+
`Public kernel circuit did not revert on ${result.execution.contractAddress.toString()}:${functionSelector}(${
|
|
335
|
+
result.functionName
|
|
336
|
+
}), but simulator did.`,
|
|
326
337
|
);
|
|
327
338
|
}
|
|
328
339
|
|
|
@@ -330,9 +341,9 @@ export abstract class AbstractPhaseManager {
|
|
|
330
341
|
// So safely return the revert reason and the kernel output (which has had its revertible side effects dropped)
|
|
331
342
|
if (result.reverted) {
|
|
332
343
|
this.log.debug(
|
|
333
|
-
`Reverting on ${result.execution.contractAddress.toString()}:${functionSelector}
|
|
334
|
-
result.
|
|
335
|
-
}`,
|
|
344
|
+
`Reverting on ${result.execution.contractAddress.toString()}:${functionSelector}(${
|
|
345
|
+
result.functionName
|
|
346
|
+
}) with reason: ${result.revertReason}`,
|
|
336
347
|
);
|
|
337
348
|
// TODO(@spalladino): Check gasUsed is correct. The AVM should take care of setting gasLeft to zero upon a revert.
|
|
338
349
|
return {
|
|
@@ -47,6 +47,7 @@ export class AppLogicPhaseManager extends AbstractPhaseManager {
|
|
|
47
47
|
// if so, this is removing contracts deployed in private setup
|
|
48
48
|
await this.publicContractsDB.removeNewContracts(tx);
|
|
49
49
|
await this.publicStateDB.rollbackToCheckpoint();
|
|
50
|
+
tx.filterRevertedLogs(kernelOutput);
|
|
50
51
|
} else {
|
|
51
52
|
tx.unencryptedLogs.addFunctionLogs(newUnencryptedLogs);
|
|
52
53
|
// TODO(#6470): we should be adding contracts deployed in those logs to the publicContractsDB
|
package/src/public/execution.ts
CHANGED
|
@@ -20,16 +20,37 @@ import { type Gas } from '../avm/avm_gas.js';
|
|
|
20
20
|
export interface PublicExecutionResult {
|
|
21
21
|
/** The execution that triggered this result. */
|
|
22
22
|
execution: PublicExecution;
|
|
23
|
+
|
|
24
|
+
/** The side effect counter at the start of the function call. */
|
|
25
|
+
startSideEffectCounter: Fr;
|
|
26
|
+
/** The side effect counter after executing this function call */
|
|
27
|
+
endSideEffectCounter: Fr;
|
|
28
|
+
/** How much gas was available for this public execution. */
|
|
29
|
+
startGasLeft: Gas;
|
|
30
|
+
/** How much gas was left after this public execution. */
|
|
31
|
+
endGasLeft: Gas;
|
|
32
|
+
/** Transaction fee set for this tx. */
|
|
33
|
+
transactionFee: Fr;
|
|
34
|
+
|
|
35
|
+
/** Bytecode used for this execution. */
|
|
36
|
+
bytecode?: Buffer;
|
|
37
|
+
/** Calldata used for this execution. */
|
|
38
|
+
calldata: Fr[];
|
|
23
39
|
/** The return values of the function. */
|
|
24
40
|
returnValues: Fr[];
|
|
41
|
+
/** Whether the execution reverted. */
|
|
42
|
+
reverted: boolean;
|
|
43
|
+
/** The revert reason if the execution reverted. */
|
|
44
|
+
revertReason?: SimulationError;
|
|
45
|
+
|
|
46
|
+
/** The contract storage reads performed by the function. */
|
|
47
|
+
contractStorageReads: ContractStorageRead[];
|
|
48
|
+
/** The contract storage update requests performed by the function. */
|
|
49
|
+
contractStorageUpdateRequests: ContractStorageUpdateRequest[];
|
|
25
50
|
/** The new note hashes to be inserted into the note hashes tree. */
|
|
26
51
|
newNoteHashes: NoteHash[];
|
|
27
52
|
/** The new l2 to l1 messages generated in this call. */
|
|
28
53
|
newL2ToL1Messages: L2ToL1Message[];
|
|
29
|
-
/** The side effect counter at the start of the function call. */
|
|
30
|
-
startSideEffectCounter: Fr;
|
|
31
|
-
/** The side effect counter after executing this function call */
|
|
32
|
-
endSideEffectCounter: Fr;
|
|
33
54
|
/** The new nullifiers to be inserted into the nullifier tree. */
|
|
34
55
|
newNullifiers: Nullifier[];
|
|
35
56
|
/** The note hash read requests emitted in this call. */
|
|
@@ -40,12 +61,6 @@ export interface PublicExecutionResult {
|
|
|
40
61
|
nullifierNonExistentReadRequests: ReadRequest[];
|
|
41
62
|
/** L1 to L2 message read requests emitted in this call. */
|
|
42
63
|
l1ToL2MsgReadRequests: ReadRequest[];
|
|
43
|
-
/** The contract storage reads performed by the function. */
|
|
44
|
-
contractStorageReads: ContractStorageRead[];
|
|
45
|
-
/** The contract storage update requests performed by the function. */
|
|
46
|
-
contractStorageUpdateRequests: ContractStorageUpdateRequest[];
|
|
47
|
-
/** The results of nested calls. */
|
|
48
|
-
nestedExecutions: this[];
|
|
49
64
|
/**
|
|
50
65
|
* The hashed logs with side effect counter.
|
|
51
66
|
* Note: required as we don't track the counter anywhere else.
|
|
@@ -61,22 +76,17 @@ export interface PublicExecutionResult {
|
|
|
61
76
|
* Useful for maintaining correct ordering in ts.
|
|
62
77
|
*/
|
|
63
78
|
allUnencryptedLogs: UnencryptedFunctionL2Logs;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/** How much gas was left after this public execution. */
|
|
71
|
-
endGasLeft: Gas;
|
|
72
|
-
/** Transaction fee set for this tx. */
|
|
73
|
-
transactionFee: Fr;
|
|
74
|
-
/** Bytecode used for this execution. */
|
|
75
|
-
bytecode?: Buffer;
|
|
76
|
-
/** Calldata used for this execution. */
|
|
77
|
-
calldata: Fr[];
|
|
79
|
+
|
|
80
|
+
// TODO(dbanks12): add contract instance read requests
|
|
81
|
+
|
|
82
|
+
/** The results of nested calls. */
|
|
83
|
+
nestedExecutions: this[];
|
|
84
|
+
|
|
78
85
|
/** Hints for proving AVM execution. */
|
|
79
|
-
|
|
86
|
+
avmCircuitHints: AvmExecutionHints;
|
|
87
|
+
|
|
88
|
+
/** The name of the function that was executed. Only used for logging. */
|
|
89
|
+
functionName: string;
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
/**
|
package/src/public/executor.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AvmSimulationStats } from '@aztec/circuit-types/stats';
|
|
2
|
-
import { Fr,
|
|
2
|
+
import { Fr, Gas, type GlobalVariables, type Header, type Nullifier, type TxContext } from '@aztec/circuits.js';
|
|
3
3
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { Timer } from '@aztec/foundation/timer';
|
|
5
5
|
|
|
@@ -10,7 +10,8 @@ import { HostStorage } from '../avm/journal/host_storage.js';
|
|
|
10
10
|
import { AvmPersistableStateManager } from '../avm/journal/index.js';
|
|
11
11
|
import { type CommitmentsDB, type PublicContractsDB, type PublicStateDB } from './db_interfaces.js';
|
|
12
12
|
import { type PublicExecution, type PublicExecutionResult, checkValidStaticCall } from './execution.js';
|
|
13
|
-
import {
|
|
13
|
+
import { PublicSideEffectTrace } from './side_effect_trace.js';
|
|
14
|
+
import { createAvmExecutionEnvironment } from './transitional_adaptors.js';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Handles execution of public functions.
|
|
@@ -27,54 +28,57 @@ export class PublicExecutor {
|
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Executes a public execution request.
|
|
30
|
-
* @param
|
|
31
|
+
* @param executionRequest - The execution to run.
|
|
31
32
|
* @param globalVariables - The global variables to use.
|
|
32
|
-
* @
|
|
33
|
+
* @param availableGas - The gas available at the start of this enqueued call.
|
|
34
|
+
* @param txContext - Transaction context.
|
|
35
|
+
* @param pendingSiloedNullifiers - The pending nullifier set from earlier parts of this TX.
|
|
36
|
+
* @param transactionFee - Fee offered for this TX.
|
|
37
|
+
* @param startSideEffectCounter - The counter of the first side-effect generated by this simulation.
|
|
38
|
+
* @returns The result of execution, including the results of all nested calls.
|
|
33
39
|
*/
|
|
34
40
|
public async simulate(
|
|
35
|
-
|
|
41
|
+
executionRequest: PublicExecution,
|
|
36
42
|
globalVariables: GlobalVariables,
|
|
37
43
|
availableGas: Gas,
|
|
38
44
|
txContext: TxContext,
|
|
39
|
-
|
|
45
|
+
pendingSiloedNullifiers: Nullifier[],
|
|
40
46
|
transactionFee: Fr = Fr.ZERO,
|
|
41
47
|
startSideEffectCounter: number = 0,
|
|
42
48
|
): Promise<PublicExecutionResult> {
|
|
43
|
-
const address =
|
|
44
|
-
const selector =
|
|
45
|
-
const
|
|
46
|
-
const fnName = await this.contractsDb.getDebugFunctionName(address, selector);
|
|
49
|
+
const address = executionRequest.contractAddress;
|
|
50
|
+
const selector = executionRequest.functionSelector;
|
|
51
|
+
const fnName = (await this.contractsDb.getDebugFunctionName(address, selector)) ?? `${address}:${selector}`;
|
|
47
52
|
|
|
48
53
|
PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}.`);
|
|
49
54
|
const timer = new Timer();
|
|
50
55
|
|
|
51
|
-
// Temporary code to construct the AVM context
|
|
52
|
-
// These data structures will permeate across the simulator when the public executor is phased out
|
|
53
56
|
const hostStorage = new HostStorage(this.stateDb, this.contractsDb, this.commitmentsDb);
|
|
57
|
+
const trace = new PublicSideEffectTrace(startSideEffectCounter);
|
|
58
|
+
const avmPersistableState = AvmPersistableStateManager.newWithPendingSiloedNullifiers(
|
|
59
|
+
hostStorage,
|
|
60
|
+
trace,
|
|
61
|
+
pendingSiloedNullifiers.map(n => n.value),
|
|
62
|
+
);
|
|
54
63
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
worldStateJournal.nullifiers.cache.appendSiloed(nullifier.value);
|
|
58
|
-
}
|
|
59
|
-
worldStateJournal.trace.accessCounter = startSideEffectCounter;
|
|
60
|
-
|
|
61
|
-
const executionEnv = createAvmExecutionEnvironment(
|
|
62
|
-
execution,
|
|
64
|
+
const avmExecutionEnv = createAvmExecutionEnvironment(
|
|
65
|
+
executionRequest,
|
|
63
66
|
this.header,
|
|
64
67
|
globalVariables,
|
|
65
68
|
txContext.gasSettings,
|
|
66
69
|
transactionFee,
|
|
67
70
|
);
|
|
68
71
|
|
|
69
|
-
const
|
|
70
|
-
const avmContext = new AvmContext(
|
|
72
|
+
const avmMachineState = new AvmMachineState(availableGas);
|
|
73
|
+
const avmContext = new AvmContext(avmPersistableState, avmExecutionEnv, avmMachineState);
|
|
71
74
|
const simulator = new AvmSimulator(avmContext);
|
|
72
75
|
const avmResult = await simulator.execute();
|
|
73
|
-
const bytecode = simulator.getBytecode()
|
|
76
|
+
const bytecode = simulator.getBytecode()!;
|
|
74
77
|
|
|
75
78
|
// Commit the journals state to the DBs since this is a top-level execution.
|
|
76
79
|
// Observe that this will write all the state changes to the DBs, not only the latest for each slot.
|
|
77
80
|
// However, the underlying DB keep a cache and will only write the latest state to disk.
|
|
81
|
+
// TODO(dbanks12): this should be unnecessary here or should be exposed by state manager
|
|
78
82
|
await avmContext.persistableState.publicStorage.commitToDB();
|
|
79
83
|
|
|
80
84
|
PublicExecutor.log.verbose(
|
|
@@ -83,33 +87,36 @@ export class PublicExecutor {
|
|
|
83
87
|
}.`,
|
|
84
88
|
{
|
|
85
89
|
eventName: 'avm-simulation',
|
|
86
|
-
appCircuitName: fnName
|
|
90
|
+
appCircuitName: fnName,
|
|
87
91
|
duration: timer.ms(),
|
|
88
92
|
bytecodeSize: bytecode!.length,
|
|
89
93
|
} satisfies AvmSimulationStats,
|
|
90
94
|
);
|
|
91
95
|
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
startGas,
|
|
97
|
-
avmContext,
|
|
96
|
+
const publicExecutionResult = trace.toPublicExecutionResult(
|
|
97
|
+
avmExecutionEnv,
|
|
98
|
+
/*startGasLeft=*/ availableGas,
|
|
99
|
+
/*endGasLeft=*/ Gas.from(avmContext.machineState.gasLeft),
|
|
98
100
|
bytecode,
|
|
101
|
+
avmResult,
|
|
102
|
+
fnName,
|
|
103
|
+
/*requestSideEffectCounter=*/ executionRequest.callContext.sideEffectCounter,
|
|
104
|
+
// NOTE: startSideEffectCounter is not the same as the executionRequest's sideEffectCounter
|
|
105
|
+
// (which counts the request itself)
|
|
99
106
|
);
|
|
100
107
|
|
|
101
108
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/5818): is this really needed?
|
|
102
109
|
// should already be handled in simulation.
|
|
103
|
-
if (
|
|
110
|
+
if (executionRequest.callContext.isStaticCall) {
|
|
104
111
|
checkValidStaticCall(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
publicExecutionResult.newNoteHashes,
|
|
113
|
+
publicExecutionResult.newNullifiers,
|
|
114
|
+
publicExecutionResult.contractStorageUpdateRequests,
|
|
115
|
+
publicExecutionResult.newL2ToL1Messages,
|
|
116
|
+
publicExecutionResult.unencryptedLogs,
|
|
110
117
|
);
|
|
111
118
|
}
|
|
112
119
|
|
|
113
|
-
return
|
|
120
|
+
return publicExecutionResult;
|
|
114
121
|
}
|
|
115
122
|
}
|