@aztec/simulator 0.35.1 → 0.37.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 +7 -5
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +50 -23
- package/dest/acvm/oracle/typed_oracle.d.ts +17 -22
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +13 -10
- package/dest/avm/avm_execution_environment.d.ts +1 -5
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +5 -8
- package/dest/avm/avm_gas.d.ts +1 -9
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +6 -13
- package/dest/avm/avm_machine_state.d.ts +1 -3
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +8 -9
- package/dest/avm/avm_simulator.js +2 -2
- package/dest/avm/fixtures/index.d.ts +2 -6
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +3 -12
- package/dest/avm/journal/journal.d.ts +2 -1
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +8 -17
- package/dest/avm/journal/trace.d.ts +3 -1
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace.js +11 -1
- package/dest/avm/journal/trace_types.d.ts +4 -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/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +1 -1
- package/dest/avm/opcodes/context_getters.d.ts +0 -5
- package/dest/avm/opcodes/context_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/context_getters.js +1 -8
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +1 -3
- package/dest/avm/opcodes/environment_getters.d.ts +0 -15
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +1 -35
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +5 -6
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +3 -3
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +1 -1
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +3 -8
- package/dest/avm/serialization/instruction_serialization.d.ts +42 -47
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +43 -48
- package/dest/client/client_execution_context.d.ts +13 -16
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +36 -34
- package/dest/client/db_oracle.d.ts +13 -17
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/execution_note_cache.d.ts +6 -2
- package/dest/client/execution_note_cache.d.ts.map +1 -1
- package/dest/client/execution_note_cache.js +10 -7
- package/dest/client/execution_result.d.ts +10 -5
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +7 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +4 -10
- package/dest/client/simulator.d.ts +1 -3
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +5 -9
- package/dest/client/view_data_oracle.d.ts +14 -11
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +17 -14
- package/dest/mocks/fixtures.d.ts +1 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +9 -5
- package/dest/public/abstract_phase_manager.d.ts +4 -4
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +28 -43
- package/dest/public/app_logic_phase_manager.d.ts +1 -7
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/public/app_logic_phase_manager.js +1 -7
- package/dest/public/db.d.ts +6 -7
- package/dest/public/db.d.ts.map +1 -1
- package/dest/public/execution.d.ts +15 -6
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +7 -9
- package/dest/public/executor.d.ts +2 -2
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +19 -10
- package/dest/public/hints_builder.d.ts +10 -8
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +29 -35
- package/dest/public/public_execution_context.d.ts +8 -13
- package/dest/public/public_execution_context.d.ts.map +1 -1
- package/dest/public/public_execution_context.js +12 -29
- package/dest/public/public_executor.d.ts +2 -2
- package/dest/public/public_executor.d.ts.map +1 -1
- package/dest/public/public_executor.js +4 -5
- package/dest/public/public_processor.d.ts +1 -2
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +1 -1
- package/dest/public/setup_phase_manager.d.ts +0 -6
- package/dest/public/setup_phase_manager.d.ts.map +1 -1
- package/dest/public/setup_phase_manager.js +1 -7
- package/dest/public/state_actions.d.ts.map +1 -1
- package/dest/public/state_actions.js +3 -1
- package/dest/public/tail_phase_manager.d.ts +3 -6
- package/dest/public/tail_phase_manager.d.ts.map +1 -1
- package/dest/public/tail_phase_manager.js +47 -16
- package/dest/public/teardown_phase_manager.d.ts +3 -7
- package/dest/public/teardown_phase_manager.d.ts.map +1 -1
- package/dest/public/teardown_phase_manager.js +14 -7
- package/dest/public/transitional_adaptors.d.ts +2 -2
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +19 -21
- package/dest/public/utils.d.ts.map +1 -1
- package/dest/public/utils.js +4 -2
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +3 -5
- package/package.json +16 -8
- package/src/acvm/oracle/oracle.ts +63 -22
- package/src/acvm/oracle/typed_oracle.ts +23 -27
- package/src/avm/avm_execution_environment.ts +0 -13
- package/src/avm/avm_gas.ts +6 -14
- package/src/avm/avm_machine_state.ts +8 -11
- package/src/avm/avm_simulator.ts +1 -1
- package/src/avm/fixtures/index.ts +2 -24
- package/src/avm/journal/journal.ts +14 -25
- package/src/avm/journal/trace.ts +12 -0
- package/src/avm/journal/trace_types.ts +7 -0
- package/src/avm/opcodes/arithmetic.ts +2 -2
- package/src/avm/opcodes/context_getters.ts +0 -9
- package/src/avm/opcodes/contract.ts +0 -2
- package/src/avm/opcodes/environment_getters.ts +0 -45
- package/src/avm/opcodes/external_calls.ts +5 -6
- package/src/avm/opcodes/memory.ts +5 -5
- package/src/avm/opcodes/storage.ts +1 -1
- package/src/avm/serialization/bytecode_serialization.ts +2 -10
- package/src/avm/serialization/instruction_serialization.ts +1 -6
- package/src/client/client_execution_context.ts +79 -54
- package/src/client/db_oracle.ts +14 -18
- package/src/client/execution_note_cache.ts +16 -7
- package/src/client/execution_result.ts +17 -6
- package/src/client/private_execution.ts +4 -9
- package/src/client/simulator.ts +3 -15
- package/src/client/view_data_oracle.ts +35 -29
- package/src/mocks/fixtures.ts +7 -16
- package/src/public/abstract_phase_manager.ts +45 -56
- package/src/public/app_logic_phase_manager.ts +6 -6
- package/src/public/db.ts +7 -8
- package/src/public/execution.ts +22 -18
- package/src/public/executor.ts +31 -5
- package/src/public/hints_builder.ts +62 -62
- package/src/public/public_execution_context.ts +30 -36
- package/src/public/public_executor.ts +4 -6
- package/src/public/public_processor.ts +1 -1
- package/src/public/setup_phase_manager.ts +6 -6
- package/src/public/state_actions.ts +2 -0
- package/src/public/tail_phase_manager.ts +98 -23
- package/src/public/teardown_phase_manager.ts +24 -6
- package/src/public/transitional_adaptors.ts +25 -19
- package/src/public/utils.ts +3 -1
- package/src/test/utils.ts +2 -4
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import { type PublicKernelRequest, PublicKernelType, type Tx } from '@aztec/circuit-types';
|
|
2
1
|
import {
|
|
3
|
-
type
|
|
2
|
+
type PublicKernelRequest,
|
|
3
|
+
PublicKernelType,
|
|
4
|
+
type Tx,
|
|
5
|
+
UnencryptedFunctionL2Logs,
|
|
6
|
+
type UnencryptedL2Log,
|
|
7
|
+
} from '@aztec/circuit-types';
|
|
8
|
+
import {
|
|
9
|
+
Fr,
|
|
4
10
|
type GlobalVariables,
|
|
5
11
|
type Header,
|
|
6
12
|
type KernelCircuitPublicInputs,
|
|
7
13
|
MAX_NEW_NOTE_HASHES_PER_TX,
|
|
14
|
+
MAX_NEW_NULLIFIERS_PER_TX,
|
|
15
|
+
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
16
|
+
type MAX_UNENCRYPTED_LOGS_PER_TX,
|
|
17
|
+
type NoteHash,
|
|
8
18
|
type Proof,
|
|
9
19
|
type PublicKernelCircuitPublicInputs,
|
|
10
20
|
PublicKernelTailCircuitPrivateInputs,
|
|
11
|
-
|
|
21
|
+
SideEffect,
|
|
12
22
|
makeEmptyProof,
|
|
13
23
|
mergeAccumulatedData,
|
|
14
24
|
sortByCounter,
|
|
@@ -23,14 +33,14 @@ import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simul
|
|
|
23
33
|
|
|
24
34
|
export class TailPhaseManager extends AbstractPhaseManager {
|
|
25
35
|
constructor(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
db: MerkleTreeOperations,
|
|
37
|
+
publicExecutor: PublicExecutor,
|
|
38
|
+
publicKernel: PublicKernelCircuitSimulator,
|
|
39
|
+
globalVariables: GlobalVariables,
|
|
40
|
+
historicalHeader: Header,
|
|
31
41
|
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
32
42
|
protected publicStateDB: PublicStateDB,
|
|
33
|
-
|
|
43
|
+
phase: PublicKernelPhase = PublicKernelPhase.TAIL,
|
|
34
44
|
) {
|
|
35
45
|
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
36
46
|
}
|
|
@@ -47,7 +57,8 @@ export class TailPhaseManager extends AbstractPhaseManager {
|
|
|
47
57
|
throw err;
|
|
48
58
|
},
|
|
49
59
|
);
|
|
50
|
-
|
|
60
|
+
// Temporary hack. Should sort them in the tail circuit.
|
|
61
|
+
this.patchLogsOrdering(tx, previousPublicKernelOutput);
|
|
51
62
|
// commit the state updates from this transaction
|
|
52
63
|
await this.publicStateDB.commit();
|
|
53
64
|
|
|
@@ -71,13 +82,17 @@ export class TailPhaseManager extends AbstractPhaseManager {
|
|
|
71
82
|
previousOutput: PublicKernelCircuitPublicInputs,
|
|
72
83
|
previousProof: Proof,
|
|
73
84
|
): Promise<[PublicKernelTailCircuitPrivateInputs, KernelCircuitPublicInputs]> {
|
|
85
|
+
// Temporary hack. Should sort them in the tail circuit.
|
|
86
|
+
previousOutput.end.unencryptedLogsHashes = this.sortLogsHashes<typeof MAX_UNENCRYPTED_LOGS_PER_TX>(
|
|
87
|
+
previousOutput.end.unencryptedLogsHashes,
|
|
88
|
+
);
|
|
74
89
|
const [inputs, output] = await this.simulate(previousOutput, previousProof);
|
|
75
90
|
|
|
76
91
|
// Temporary hack. Should sort them in the tail circuit.
|
|
77
92
|
const noteHashes = mergeAccumulatedData(
|
|
78
|
-
MAX_NEW_NOTE_HASHES_PER_TX,
|
|
79
93
|
previousOutput.endNonRevertibleData.newNoteHashes,
|
|
80
94
|
previousOutput.end.newNoteHashes,
|
|
95
|
+
MAX_NEW_NOTE_HASHES_PER_TX,
|
|
81
96
|
);
|
|
82
97
|
output.end.newNoteHashes = this.sortNoteHashes<typeof MAX_NEW_NOTE_HASHES_PER_TX>(noteHashes);
|
|
83
98
|
|
|
@@ -88,33 +103,93 @@ export class TailPhaseManager extends AbstractPhaseManager {
|
|
|
88
103
|
previousOutput: PublicKernelCircuitPublicInputs,
|
|
89
104
|
previousProof: Proof,
|
|
90
105
|
): Promise<[PublicKernelTailCircuitPrivateInputs, KernelCircuitPublicInputs]> {
|
|
106
|
+
const inputs = await this.buildPrivateInputs(previousOutput, previousProof);
|
|
107
|
+
// We take a deep copy (clone) of these to pass to the prover
|
|
108
|
+
return [inputs.clone(), await this.publicKernel.publicKernelCircuitTail(inputs)];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private async buildPrivateInputs(previousOutput: PublicKernelCircuitPublicInputs, previousProof: Proof) {
|
|
91
112
|
const previousKernel = this.getPreviousKernelData(previousOutput, previousProof);
|
|
92
113
|
|
|
93
114
|
const { validationRequests, endNonRevertibleData, end } = previousOutput;
|
|
94
|
-
|
|
95
|
-
|
|
115
|
+
|
|
116
|
+
const pendingNullifiers = mergeAccumulatedData(
|
|
96
117
|
endNonRevertibleData.newNullifiers,
|
|
97
118
|
end.newNullifiers,
|
|
119
|
+
MAX_NEW_NULLIFIERS_PER_TX,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const nullifierReadRequestHints = await this.hintsBuilder.getNullifierReadRequestHints(
|
|
123
|
+
validationRequests.nullifierReadRequests,
|
|
124
|
+
pendingNullifiers,
|
|
98
125
|
);
|
|
126
|
+
|
|
99
127
|
const nullifierNonExistentReadRequestHints = await this.hintsBuilder.getNullifierNonExistentReadRequestHints(
|
|
100
128
|
validationRequests.nullifierNonExistentReadRequests,
|
|
101
|
-
|
|
102
|
-
end.newNullifiers,
|
|
129
|
+
pendingNullifiers,
|
|
103
130
|
);
|
|
104
131
|
|
|
105
|
-
|
|
106
|
-
|
|
132
|
+
const pendingPublicDataWrites = mergeAccumulatedData(
|
|
133
|
+
endNonRevertibleData.publicDataUpdateRequests,
|
|
134
|
+
end.publicDataUpdateRequests,
|
|
135
|
+
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const publicDataHints = await this.hintsBuilder.getPublicDataHints(
|
|
139
|
+
validationRequests.publicDataReads,
|
|
140
|
+
pendingPublicDataWrites,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const publicDataReadRequestHints = this.hintsBuilder.getPublicDataReadRequestHints(
|
|
144
|
+
validationRequests.publicDataReads,
|
|
145
|
+
pendingPublicDataWrites,
|
|
146
|
+
publicDataHints,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const currentState = await this.db.getStateReference();
|
|
150
|
+
|
|
151
|
+
return new PublicKernelTailCircuitPrivateInputs(
|
|
107
152
|
previousKernel,
|
|
108
153
|
nullifierReadRequestHints,
|
|
109
154
|
nullifierNonExistentReadRequestHints,
|
|
155
|
+
publicDataHints,
|
|
156
|
+
publicDataReadRequestHints,
|
|
157
|
+
currentState.partial,
|
|
110
158
|
);
|
|
111
|
-
return [inputs.clone(), await this.publicKernel.publicKernelCircuitTail(inputs)];
|
|
112
159
|
}
|
|
113
160
|
|
|
114
|
-
private sortNoteHashes<N extends number>(noteHashes: Tuple<
|
|
115
|
-
return sortByCounter(noteHashes
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
161
|
+
private sortNoteHashes<N extends number>(noteHashes: Tuple<NoteHash, N>): Tuple<Fr, N> {
|
|
162
|
+
return sortByCounter(noteHashes).map(n => n.value) as Tuple<Fr, N>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private sortLogsHashes<N extends number>(unencryptedLogsHashes: Tuple<SideEffect, N>): Tuple<SideEffect, N> {
|
|
166
|
+
return sortByCounter(
|
|
167
|
+
unencryptedLogsHashes.map(n => ({ ...n, counter: n.counter.toNumber(), isEmpty: () => n.isEmpty() })),
|
|
168
|
+
).map(h => new SideEffect(h.value, new Fr(h.counter))) as Tuple<SideEffect, N>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// As above, this is a hack for unencrypted logs ordering, now they are sorted. Since the public kernel
|
|
172
|
+
// cannot keep track of side effects that happen after or before a nested call, we override the gathered logs.
|
|
173
|
+
// As a sanity check, we at least verify that the elements are the same, so we are only tweaking their ordering.
|
|
174
|
+
// See same fn in pxe_service.ts
|
|
175
|
+
// Added as part of resolving #5017
|
|
176
|
+
private patchLogsOrdering(tx: Tx, publicInputs: PublicKernelCircuitPublicInputs) {
|
|
177
|
+
const unencLogs = tx.unencryptedLogs.unrollLogs();
|
|
178
|
+
const sortedUnencLogs = publicInputs.end.unencryptedLogsHashes;
|
|
179
|
+
|
|
180
|
+
const finalUnencLogs: UnencryptedL2Log[] = [];
|
|
181
|
+
sortedUnencLogs.forEach((sideEffect: SideEffect) => {
|
|
182
|
+
if (!sideEffect.isEmpty()) {
|
|
183
|
+
const isLog = (log: UnencryptedL2Log) => Fr.fromBuffer(log.hash()).equals(sideEffect.value);
|
|
184
|
+
const thisLogIndex = unencLogs.findIndex(isLog);
|
|
185
|
+
finalUnencLogs.push(unencLogs[thisLogIndex]);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
const unencryptedLogs = new UnencryptedFunctionL2Logs(finalUnencLogs);
|
|
189
|
+
|
|
190
|
+
tx.unencryptedLogs.functionLogs[0] = unencryptedLogs;
|
|
191
|
+
for (let i = 1; i < tx.unencryptedLogs.functionLogs.length; i++) {
|
|
192
|
+
tx.unencryptedLogs.functionLogs[i] = UnencryptedFunctionL2Logs.empty();
|
|
193
|
+
}
|
|
119
194
|
}
|
|
120
195
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type PublicKernelRequest, PublicKernelType, type Tx } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
|
+
type Fr,
|
|
4
|
+
type Gas,
|
|
3
5
|
type GlobalVariables,
|
|
4
6
|
type Header,
|
|
5
7
|
type Proof,
|
|
@@ -8,6 +10,8 @@ import {
|
|
|
8
10
|
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
9
11
|
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
10
12
|
|
|
13
|
+
import { inspect } from 'util';
|
|
14
|
+
|
|
11
15
|
import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
12
16
|
import { type ContractsDataSourcePublicDB } from './public_executor.js';
|
|
13
17
|
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
@@ -17,14 +21,14 @@ import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simul
|
|
|
17
21
|
*/
|
|
18
22
|
export class TeardownPhaseManager extends AbstractPhaseManager {
|
|
19
23
|
constructor(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
db: MerkleTreeOperations,
|
|
25
|
+
publicExecutor: PublicExecutor,
|
|
26
|
+
publicKernel: PublicKernelCircuitSimulator,
|
|
27
|
+
globalVariables: GlobalVariables,
|
|
28
|
+
historicalHeader: Header,
|
|
25
29
|
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
26
30
|
protected publicStateDB: PublicStateDB,
|
|
27
|
-
|
|
31
|
+
phase: PublicKernelPhase = PublicKernelPhase.TEARDOWN,
|
|
28
32
|
) {
|
|
29
33
|
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
30
34
|
}
|
|
@@ -63,4 +67,18 @@ export class TeardownPhaseManager extends AbstractPhaseManager {
|
|
|
63
67
|
returnValues: undefined,
|
|
64
68
|
};
|
|
65
69
|
}
|
|
70
|
+
|
|
71
|
+
protected override getTransactionFee(tx: Tx, previousPublicKernelOutput: PublicKernelCircuitPublicInputs): Fr {
|
|
72
|
+
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
73
|
+
const gasFees = this.globalVariables.gasFees;
|
|
74
|
+
// No need to add teardown limits since they are already included in end.gasUsed
|
|
75
|
+
const gasUsed = previousPublicKernelOutput.end.gasUsed.add(previousPublicKernelOutput.endNonRevertibleData.gasUsed);
|
|
76
|
+
const txFee = gasSettings.inclusionFee.add(gasUsed.computeFee(gasFees));
|
|
77
|
+
this.log.debug(`Computed tx fee`, { txFee, gasUsed: inspect(gasUsed), gasFees: inspect(gasFees) });
|
|
78
|
+
return txFee;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
protected override getAvailableGas(tx: Tx, _previousPublicKernelOutput: PublicKernelCircuitPublicInputs): Gas {
|
|
82
|
+
return tx.data.constants.txContext.gasSettings.getTeardownLimits();
|
|
83
|
+
}
|
|
66
84
|
}
|
|
@@ -6,12 +6,14 @@ import {
|
|
|
6
6
|
ContractStorageUpdateRequest,
|
|
7
7
|
FunctionData,
|
|
8
8
|
Gas,
|
|
9
|
+
type GasSettings,
|
|
9
10
|
type GlobalVariables,
|
|
10
11
|
type Header,
|
|
11
12
|
L2ToL1Message,
|
|
13
|
+
NoteHash,
|
|
14
|
+
Nullifier,
|
|
12
15
|
ReadRequest,
|
|
13
16
|
SideEffect,
|
|
14
|
-
SideEffectLinkedToNoteHash,
|
|
15
17
|
} from '@aztec/circuits.js';
|
|
16
18
|
import { Fr } from '@aztec/foundation/fields';
|
|
17
19
|
|
|
@@ -37,14 +39,13 @@ export function createAvmExecutionEnvironment(
|
|
|
37
39
|
current: PublicExecution,
|
|
38
40
|
header: Header,
|
|
39
41
|
globalVariables: GlobalVariables,
|
|
42
|
+
gasSettings: GasSettings,
|
|
43
|
+
transactionFee: Fr,
|
|
40
44
|
): AvmExecutionEnvironment {
|
|
41
45
|
return new AvmExecutionEnvironment(
|
|
42
46
|
current.contractAddress,
|
|
43
47
|
current.callContext.storageContractAddress,
|
|
44
|
-
current.callContext.msgSender, // TODO: origin is not available
|
|
45
48
|
current.callContext.msgSender,
|
|
46
|
-
current.callContext.portalContractAddress,
|
|
47
|
-
globalVariables.gasFees.feePerL1Gas,
|
|
48
49
|
globalVariables.gasFees.feePerL2Gas,
|
|
49
50
|
globalVariables.gasFees.feePerDaGas,
|
|
50
51
|
/*contractCallDepth=*/ Fr.zero(),
|
|
@@ -53,8 +54,8 @@ export function createAvmExecutionEnvironment(
|
|
|
53
54
|
current.callContext.isStaticCall,
|
|
54
55
|
current.callContext.isDelegateCall,
|
|
55
56
|
current.args,
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
gasSettings,
|
|
58
|
+
transactionFee,
|
|
58
59
|
current.functionData.selector,
|
|
59
60
|
);
|
|
60
61
|
}
|
|
@@ -64,14 +65,10 @@ export function createPublicExecutionContext(avmContext: AvmContext, calldata: F
|
|
|
64
65
|
const callContext = CallContext.from({
|
|
65
66
|
msgSender: avmContext.environment.sender,
|
|
66
67
|
storageContractAddress: avmContext.environment.storageAddress,
|
|
67
|
-
portalContractAddress: avmContext.environment.portal,
|
|
68
68
|
functionSelector: avmContext.environment.temporaryFunctionSelector,
|
|
69
|
-
gasLeft: Gas.from(avmContext.machineState.gasLeft),
|
|
70
69
|
isDelegateCall: avmContext.environment.isDelegateCall,
|
|
71
70
|
isStaticCall: avmContext.environment.isStaticCall,
|
|
72
71
|
sideEffectCounter: sideEffectCounter,
|
|
73
|
-
gasSettings: avmContext.environment.gasSettings,
|
|
74
|
-
transactionFee: avmContext.environment.transactionFee,
|
|
75
72
|
});
|
|
76
73
|
const functionData = new FunctionData(avmContext.environment.temporaryFunctionSelector, /*isPrivate=*/ false);
|
|
77
74
|
const execution: PublicExecution = {
|
|
@@ -91,6 +88,9 @@ export function createPublicExecutionContext(avmContext: AvmContext, calldata: F
|
|
|
91
88
|
avmContext.persistableState.hostStorage.publicStateDb,
|
|
92
89
|
avmContext.persistableState.hostStorage.contractsDb,
|
|
93
90
|
avmContext.persistableState.hostStorage.commitmentsDb,
|
|
91
|
+
Gas.from(avmContext.machineState.gasLeft),
|
|
92
|
+
avmContext.environment.transactionFee,
|
|
93
|
+
avmContext.environment.gasSettings,
|
|
94
94
|
);
|
|
95
95
|
|
|
96
96
|
return context;
|
|
@@ -113,10 +113,10 @@ export async function convertAvmResults(
|
|
|
113
113
|
const execution = executionContext.execution;
|
|
114
114
|
|
|
115
115
|
const contractStorageReads: ContractStorageRead[] = newWorldState.storageReads.map(
|
|
116
|
-
read => new ContractStorageRead(read.slot, read.value, read.counter.toNumber()),
|
|
116
|
+
read => new ContractStorageRead(read.slot, read.value, read.counter.toNumber(), read.storageAddress),
|
|
117
117
|
);
|
|
118
118
|
const contractStorageUpdateRequests: ContractStorageUpdateRequest[] = newWorldState.storageWrites.map(
|
|
119
|
-
write => new ContractStorageUpdateRequest(write.slot, write.value, write.counter.toNumber()),
|
|
119
|
+
write => new ContractStorageUpdateRequest(write.slot, write.value, write.counter.toNumber(), write.storageAddress),
|
|
120
120
|
);
|
|
121
121
|
// We need to write the storage updates to the DB, because that's what the ACVM expects.
|
|
122
122
|
// Assumes the updates are in the right order.
|
|
@@ -125,7 +125,7 @@ export async function convertAvmResults(
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
const newNoteHashes = newWorldState.newNoteHashes.map(
|
|
128
|
-
noteHash => new
|
|
128
|
+
noteHash => new NoteHash(noteHash.noteHash, noteHash.counter.toNumber()),
|
|
129
129
|
);
|
|
130
130
|
const nullifierReadRequests: ReadRequest[] = newWorldState.nullifierChecks
|
|
131
131
|
.filter(nullifierCheck => nullifierCheck.exists)
|
|
@@ -133,17 +133,20 @@ export async function convertAvmResults(
|
|
|
133
133
|
const nullifierNonExistentReadRequests: ReadRequest[] = newWorldState.nullifierChecks
|
|
134
134
|
.filter(nullifierCheck => !nullifierCheck.exists)
|
|
135
135
|
.map(nullifierCheck => new ReadRequest(nullifierCheck.nullifier, nullifierCheck.counter.toNumber()));
|
|
136
|
-
const newNullifiers:
|
|
136
|
+
const newNullifiers: Nullifier[] = newWorldState.newNullifiers.map(
|
|
137
137
|
tracedNullifier =>
|
|
138
|
-
new
|
|
138
|
+
new Nullifier(
|
|
139
139
|
/*value=*/ tracedNullifier.nullifier,
|
|
140
|
+
tracedNullifier.counter.toNumber(),
|
|
140
141
|
/*noteHash=*/ Fr.ZERO, // NEEDED?
|
|
141
|
-
tracedNullifier.counter,
|
|
142
142
|
),
|
|
143
143
|
);
|
|
144
144
|
const unencryptedLogs: UnencryptedFunctionL2Logs = new UnencryptedFunctionL2Logs(
|
|
145
145
|
newWorldState.newLogs.map(log => new UnencryptedL2Log(log.contractAddress, log.selector, log.data)),
|
|
146
146
|
);
|
|
147
|
+
const unencryptedLogsHashes = newWorldState.newLogsHashes.map(
|
|
148
|
+
logHash => new SideEffect(logHash.logHash, logHash.counter),
|
|
149
|
+
);
|
|
147
150
|
const newL2ToL1Messages = newWorldState.newL1Messages.map(m => new L2ToL1Message(m.recipient, m.content));
|
|
148
151
|
|
|
149
152
|
const returnValues = result.output;
|
|
@@ -167,10 +170,13 @@ export async function convertAvmResults(
|
|
|
167
170
|
contractStorageUpdateRequests,
|
|
168
171
|
returnValues,
|
|
169
172
|
nestedExecutions,
|
|
173
|
+
unencryptedLogsHashes,
|
|
170
174
|
unencryptedLogs,
|
|
171
175
|
reverted: result.reverted,
|
|
172
176
|
revertReason: result.revertReason ? createSimulationError(result.revertReason) : undefined,
|
|
173
|
-
|
|
177
|
+
startGasLeft: executionContext.availableGas,
|
|
178
|
+
endGasLeft: endMachineState.gasLeft,
|
|
179
|
+
transactionFee: executionContext.transactionFee,
|
|
174
180
|
};
|
|
175
181
|
}
|
|
176
182
|
|
|
@@ -211,7 +217,7 @@ export function updateAvmContextFromPublicExecutionResult(ctx: AvmContext, resul
|
|
|
211
217
|
ctx.persistableState.trace.newNullifiers.push({
|
|
212
218
|
storageAddress: ctx.environment.storageAddress,
|
|
213
219
|
nullifier: nullifier.value,
|
|
214
|
-
counter: nullifier.counter,
|
|
220
|
+
counter: new Fr(nullifier.counter),
|
|
215
221
|
});
|
|
216
222
|
}
|
|
217
223
|
|
|
@@ -219,7 +225,7 @@ export function updateAvmContextFromPublicExecutionResult(ctx: AvmContext, resul
|
|
|
219
225
|
ctx.persistableState.trace.newNoteHashes.push({
|
|
220
226
|
storageAddress: ctx.environment.storageAddress,
|
|
221
227
|
noteHash: noteHash.value,
|
|
222
|
-
counter: noteHash.counter,
|
|
228
|
+
counter: new Fr(noteHash.counter),
|
|
223
229
|
});
|
|
224
230
|
}
|
|
225
231
|
|
package/src/public/utils.ts
CHANGED
|
@@ -14,6 +14,7 @@ export function lastSideEffectCounter(tx: Tx): number {
|
|
|
14
14
|
...data.endNonRevertibleData.publicCallStack,
|
|
15
15
|
...data.end.newNoteHashes,
|
|
16
16
|
...data.end.newNullifiers,
|
|
17
|
+
...data.end.unencryptedLogsHashes,
|
|
17
18
|
...data.end.publicCallStack,
|
|
18
19
|
];
|
|
19
20
|
|
|
@@ -23,7 +24,8 @@ export function lastSideEffectCounter(tx: Tx): number {
|
|
|
23
24
|
// look at both start and end counters because for enqueued public calls start > 0 while end === 0
|
|
24
25
|
max = Math.max(max, sideEffect.startSideEffectCounter.toNumber(), sideEffect.endSideEffectCounter.toNumber());
|
|
25
26
|
} else {
|
|
26
|
-
|
|
27
|
+
const counter = typeof sideEffect.counter === 'number' ? sideEffect.counter : sideEffect.counter.toNumber();
|
|
28
|
+
max = Math.max(max, counter);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
|
package/src/test/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { L1Actor, L1ToL2Message, L2Actor } from '@aztec/circuit-types';
|
|
2
2
|
import { type AztecAddress, EthAddress, type Fr } from '@aztec/circuits.js';
|
|
3
|
-
import {
|
|
3
|
+
import { computeSecretHash } from '@aztec/circuits.js/hash';
|
|
4
4
|
import { sha256ToField } from '@aztec/foundation/crypto';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -21,9 +21,7 @@ export const buildL1ToL2Message = (
|
|
|
21
21
|
const selectorBuf = Buffer.from(selector, 'hex');
|
|
22
22
|
|
|
23
23
|
const content = sha256ToField([selectorBuf, ...contentPreimage]);
|
|
24
|
-
const secretHash =
|
|
24
|
+
const secretHash = computeSecretHash(secret);
|
|
25
25
|
|
|
26
|
-
// Eventually the kernel will need to prove the kernel portal pair exists within the contract tree,
|
|
27
|
-
// EthAddress.random() will need to be replaced when this happens
|
|
28
26
|
return new L1ToL2Message(new L1Actor(EthAddress.random(), 1), new L2Actor(targetContract, 1), content, secretHash);
|
|
29
27
|
};
|