@aztec/simulator 0.65.1 → 0.66.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 +0 -3
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +1 -17
- package/dest/acvm/oracle/typed_oracle.d.ts +0 -5
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +1 -10
- package/dest/avm/avm_memory_types.js +4 -4
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +5 -4
- package/dest/avm/avm_tree.d.ts +31 -14
- package/dest/avm/avm_tree.d.ts.map +1 -1
- package/dest/avm/avm_tree.js +34 -40
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +16 -10
- package/dest/avm/opcodes/environment_getters.d.ts +10 -11
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +12 -15
- package/dest/client/client_execution_context.d.ts +3 -30
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +5 -47
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +2 -4
- package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
- package/dest/public/enqueued_call_side_effect_trace.js +15 -15
- package/dest/public/fixtures/index.d.ts +1 -6
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +24 -11
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +27 -13
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +8 -5
- package/dest/public/public_processor_metrics.d.ts +1 -1
- package/dest/public/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_tx_context.d.ts +2 -6
- package/dest/public/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_context.js +23 -29
- package/dest/public/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator.js +18 -5
- package/dest/public/side_effect_trace.js +8 -8
- package/dest/public/transitional_adapters.d.ts +2 -6
- package/dest/public/transitional_adapters.d.ts.map +1 -1
- package/dest/public/transitional_adapters.js +4 -67
- package/package.json +9 -9
- package/src/acvm/oracle/oracle.ts +0 -30
- package/src/acvm/oracle/typed_oracle.ts +0 -17
- package/src/avm/avm_memory_types.ts +4 -4
- package/src/avm/avm_simulator.ts +4 -3
- package/src/avm/avm_tree.ts +67 -53
- package/src/avm/journal/journal.ts +21 -9
- package/src/avm/opcodes/environment_getters.ts +1 -4
- package/src/client/client_execution_context.ts +5 -59
- package/src/client/private_execution.ts +0 -4
- package/src/public/enqueued_call_side_effect_trace.ts +14 -16
- package/src/public/fixtures/index.ts +30 -10
- package/src/public/public_db_sources.ts +29 -16
- package/src/public/public_processor.ts +6 -8
- package/src/public/public_processor_metrics.ts +1 -1
- package/src/public/public_tx_context.ts +37 -44
- package/src/public/public_tx_simulator.ts +19 -13
- package/src/public/side_effect_trace.ts +7 -7
- package/src/public/transitional_adapters.ts +6 -193
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
type ContractClassPublic,
|
|
6
6
|
type ContractInstanceWithAddress,
|
|
7
7
|
DEFAULT_GAS_LIMIT,
|
|
8
|
-
|
|
8
|
+
FunctionSelector,
|
|
9
9
|
Gas,
|
|
10
10
|
GasFees,
|
|
11
11
|
GasSettings,
|
|
@@ -23,24 +23,21 @@ import {
|
|
|
23
23
|
computePublicBytecodeCommitment,
|
|
24
24
|
} from '@aztec/circuits.js';
|
|
25
25
|
import { makeContractClassPublic, makeContractInstanceFromClassId } from '@aztec/circuits.js/testing';
|
|
26
|
-
import { type ContractArtifact } from '@aztec/foundation/abi';
|
|
26
|
+
import { type ContractArtifact, type FunctionArtifact } from '@aztec/foundation/abi';
|
|
27
27
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
28
28
|
import { Fr, Point } from '@aztec/foundation/fields';
|
|
29
29
|
import { openTmpStore } from '@aztec/kv-store/utils';
|
|
30
|
+
import { AvmTestContractArtifact } from '@aztec/noir-contracts.js';
|
|
30
31
|
import { PublicTxSimulator, WorldStateDB } from '@aztec/simulator';
|
|
31
32
|
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
|
|
32
33
|
import { MerkleTrees } from '@aztec/world-state';
|
|
33
34
|
|
|
34
|
-
import {
|
|
35
|
+
import { strict as assert } from 'assert';
|
|
35
36
|
|
|
36
|
-
/**
|
|
37
|
-
* If assertionErrString is set, we expect a (non exceptional halting) revert due to a failing assertion and
|
|
38
|
-
* we check that the revert reason error contains this string. However, the circuit must correctly prove the
|
|
39
|
-
* execution.
|
|
40
|
-
*/
|
|
41
37
|
export async function simulateAvmTestContractGenerateCircuitInputs(
|
|
42
38
|
functionName: string,
|
|
43
39
|
calldata: Fr[] = [],
|
|
40
|
+
expectRevert: boolean = false,
|
|
44
41
|
assertionErrString?: string,
|
|
45
42
|
): Promise<AvmCircuitInputs> {
|
|
46
43
|
const sender = AztecAddress.random();
|
|
@@ -79,13 +76,15 @@ export async function simulateAvmTestContractGenerateCircuitInputs(
|
|
|
79
76
|
|
|
80
77
|
const avmResult = await simulator.simulate(tx);
|
|
81
78
|
|
|
82
|
-
if (
|
|
79
|
+
if (!expectRevert) {
|
|
83
80
|
expect(avmResult.revertCode.isOK()).toBe(true);
|
|
84
81
|
} else {
|
|
85
82
|
// Explicit revert when an assertion failed.
|
|
86
83
|
expect(avmResult.revertCode.isOK()).toBe(false);
|
|
87
84
|
expect(avmResult.revertReason).toBeDefined();
|
|
88
|
-
|
|
85
|
+
if (assertionErrString !== undefined) {
|
|
86
|
+
expect(avmResult.revertReason?.getMessage()).toContain(assertionErrString);
|
|
87
|
+
}
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
const avmCircuitInputs: AvmCircuitInputs = avmResult.avmProvingRequest.inputs;
|
|
@@ -210,3 +209,24 @@ class MockedAvmTestContractDataSource {
|
|
|
210
209
|
return Promise.resolve();
|
|
211
210
|
}
|
|
212
211
|
}
|
|
212
|
+
|
|
213
|
+
function getAvmTestContractFunctionSelector(functionName: string): FunctionSelector {
|
|
214
|
+
const artifact = AvmTestContractArtifact.functions.find(f => f.name === functionName)!;
|
|
215
|
+
assert(!!artifact, `Function ${functionName} not found in AvmTestContractArtifact`);
|
|
216
|
+
const params = artifact.parameters;
|
|
217
|
+
return FunctionSelector.fromNameAndParameters(artifact.name, params);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function getAvmTestContractArtifact(functionName: string): FunctionArtifact {
|
|
221
|
+
const artifact = AvmTestContractArtifact.functions.find(f => f.name === functionName)!;
|
|
222
|
+
assert(
|
|
223
|
+
!!artifact?.bytecode,
|
|
224
|
+
`No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`,
|
|
225
|
+
);
|
|
226
|
+
return artifact;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function getAvmTestContractBytecode(functionName: string): Buffer {
|
|
230
|
+
const artifact = getAvmTestContractArtifact(functionName);
|
|
231
|
+
return artifact.bytecode;
|
|
232
|
+
}
|
|
@@ -9,9 +9,7 @@ import { type PublicDBAccessStats } from '@aztec/circuit-types/stats';
|
|
|
9
9
|
import {
|
|
10
10
|
type AztecAddress,
|
|
11
11
|
type ContractClassPublic,
|
|
12
|
-
ContractClassRegisteredEvent,
|
|
13
12
|
type ContractDataSource,
|
|
14
|
-
ContractInstanceDeployedEvent,
|
|
15
13
|
type ContractInstanceWithAddress,
|
|
16
14
|
Fr,
|
|
17
15
|
type FunctionSelector,
|
|
@@ -24,7 +22,7 @@ import {
|
|
|
24
22
|
import { computeL1ToL2MessageNullifier, computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
|
|
25
23
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
26
24
|
import { Timer } from '@aztec/foundation/timer';
|
|
27
|
-
import {
|
|
25
|
+
import { ContractClassRegisteredEvent, ContractInstanceDeployedEvent } from '@aztec/protocol-contracts';
|
|
28
26
|
import {
|
|
29
27
|
type CommitmentsDB,
|
|
30
28
|
MessageLoadOracleInputs,
|
|
@@ -51,13 +49,20 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
|
51
49
|
public addNewContracts(tx: Tx): Promise<void> {
|
|
52
50
|
// Extract contract class and instance data from logs and add to cache for this block
|
|
53
51
|
const logs = tx.contractClassLogs.unrollLogs();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
logs
|
|
53
|
+
.filter(log => ContractClassRegisteredEvent.isContractClassRegisteredEvent(log.data))
|
|
54
|
+
.forEach(log => {
|
|
55
|
+
const event = ContractClassRegisteredEvent.fromLog(log.data);
|
|
56
|
+
this.log.debug(`Adding class ${event.contractClassId.toString()} to public execution contract cache`);
|
|
57
|
+
this.classCache.set(event.contractClassId.toString(), event.toContractClassPublic());
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// We store the contract instance deployed event log in private logs, contract_instance_deployer_contract/src/main.nr
|
|
61
|
+
const contractInstanceEvents = tx.data
|
|
62
|
+
.getNonEmptyPrivateLogs()
|
|
63
|
+
.filter(log => ContractInstanceDeployedEvent.isContractInstanceDeployedEvent(log))
|
|
64
|
+
.map(ContractInstanceDeployedEvent.fromLog);
|
|
65
|
+
contractInstanceEvents.forEach(e => {
|
|
61
66
|
this.log.debug(
|
|
62
67
|
`Adding instance ${e.address.toString()} with class ${e.contractClassId.toString()} to public execution contract cache`,
|
|
63
68
|
);
|
|
@@ -76,12 +81,20 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
|
76
81
|
// Let's say we have two txs adding the same contract on the same block. If the 2nd one reverts,
|
|
77
82
|
// wouldn't that accidentally remove the contract added on the first one?
|
|
78
83
|
const logs = tx.contractClassLogs.unrollLogs();
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
logs
|
|
85
|
+
.filter(log => ContractClassRegisteredEvent.isContractClassRegisteredEvent(log.data))
|
|
86
|
+
.forEach(log => {
|
|
87
|
+
const event = ContractClassRegisteredEvent.fromLog(log.data);
|
|
88
|
+
this.classCache.delete(event.contractClassId.toString());
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// We store the contract instance deployed event log in private logs, contract_instance_deployer_contract/src/main.nr
|
|
92
|
+
const contractInstanceEvents = tx.data
|
|
93
|
+
.getNonEmptyPrivateLogs()
|
|
94
|
+
.filter(log => ContractInstanceDeployedEvent.isContractInstanceDeployedEvent(log))
|
|
95
|
+
.map(ContractInstanceDeployedEvent.fromLog);
|
|
96
|
+
contractInstanceEvents.forEach(e => this.instanceCache.delete(e.address.toString()));
|
|
97
|
+
|
|
85
98
|
return Promise.resolve();
|
|
86
99
|
}
|
|
87
100
|
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
} from '@aztec/circuit-types';
|
|
14
14
|
import {
|
|
15
15
|
type AztecAddress,
|
|
16
|
-
ContractClassRegisteredEvent,
|
|
17
16
|
type ContractDataSource,
|
|
18
17
|
Fr,
|
|
19
18
|
type GlobalVariables,
|
|
@@ -26,7 +25,7 @@ import {
|
|
|
26
25
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
27
26
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
28
27
|
import { Timer } from '@aztec/foundation/timer';
|
|
29
|
-
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
28
|
+
import { ContractClassRegisteredEvent, ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
30
29
|
import { Attributes, type TelemetryClient, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
31
30
|
|
|
32
31
|
import { computeFeePayerBalanceLeafSlot, computeFeePayerBalanceStorageSlot } from './fee_payment.js';
|
|
@@ -167,10 +166,9 @@ export class PublicProcessor {
|
|
|
167
166
|
}
|
|
168
167
|
}
|
|
169
168
|
|
|
170
|
-
await this.db.
|
|
169
|
+
await this.db.sequentialInsert(
|
|
171
170
|
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
172
171
|
processedTx.txEffect.publicDataWrites.map(x => x.toBuffer()),
|
|
173
|
-
0,
|
|
174
172
|
);
|
|
175
173
|
result.push(processedTx);
|
|
176
174
|
returns = returns.concat(returnValues ?? []);
|
|
@@ -275,10 +273,10 @@ export class PublicProcessor {
|
|
|
275
273
|
});
|
|
276
274
|
|
|
277
275
|
this.metrics.recordClassRegistration(
|
|
278
|
-
...
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
276
|
+
...tx.contractClassLogs
|
|
277
|
+
.unrollLogs()
|
|
278
|
+
.filter(log => ContractClassRegisteredEvent.isContractClassRegisteredEvent(log.data))
|
|
279
|
+
.map(log => ContractClassRegisteredEvent.fromLog(log.data)),
|
|
282
280
|
);
|
|
283
281
|
|
|
284
282
|
const phaseCount = processedPhases.length;
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
type AvmProvingRequest,
|
|
3
3
|
MerkleTreeId,
|
|
4
4
|
type MerkleTreeReadOperations,
|
|
5
|
+
ProvingRequestType,
|
|
5
6
|
type PublicExecutionRequest,
|
|
6
7
|
type SimulationError,
|
|
7
8
|
type Tx,
|
|
@@ -9,16 +10,19 @@ import {
|
|
|
9
10
|
TxHash,
|
|
10
11
|
} from '@aztec/circuit-types';
|
|
11
12
|
import {
|
|
13
|
+
AppendOnlyTreeSnapshot,
|
|
14
|
+
AvmCircuitInputs,
|
|
12
15
|
type AvmCircuitPublicInputs,
|
|
13
16
|
Fr,
|
|
14
17
|
Gas,
|
|
15
18
|
type GasSettings,
|
|
16
19
|
type GlobalVariables,
|
|
17
|
-
type Header,
|
|
18
20
|
type PrivateToPublicAccumulatedData,
|
|
19
21
|
type PublicCallRequest,
|
|
22
|
+
PublicCircuitPublicInputs,
|
|
20
23
|
RevertCode,
|
|
21
24
|
type StateReference,
|
|
25
|
+
TreeSnapshots,
|
|
22
26
|
countAccumulatedItems,
|
|
23
27
|
} from '@aztec/circuits.js';
|
|
24
28
|
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
@@ -26,13 +30,12 @@ import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
|
26
30
|
import { strict as assert } from 'assert';
|
|
27
31
|
import { inspect } from 'util';
|
|
28
32
|
|
|
29
|
-
import { type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
|
|
30
33
|
import { AvmPersistableStateManager } from '../avm/index.js';
|
|
31
34
|
import { DualSideEffectTrace } from './dual_side_effect_trace.js';
|
|
32
35
|
import { PublicEnqueuedCallSideEffectTrace, SideEffectArrayLengths } from './enqueued_call_side_effect_trace.js';
|
|
33
36
|
import { type WorldStateDB } from './public_db_sources.js';
|
|
34
37
|
import { PublicSideEffectTrace } from './side_effect_trace.js';
|
|
35
|
-
import { generateAvmCircuitPublicInputs
|
|
38
|
+
import { generateAvmCircuitPublicInputs } from './transitional_adapters.js';
|
|
36
39
|
import { getCallRequestsByPhase, getExecutionRequestsByPhase } from './utils.js';
|
|
37
40
|
|
|
38
41
|
/**
|
|
@@ -58,7 +61,6 @@ export class PublicTxContext {
|
|
|
58
61
|
constructor(
|
|
59
62
|
public readonly state: PhaseStateManager,
|
|
60
63
|
private readonly globalVariables: GlobalVariables,
|
|
61
|
-
private readonly historicalHeader: Header, // FIXME(dbanks12): remove
|
|
62
64
|
private readonly startStateReference: StateReference,
|
|
63
65
|
private readonly startGasUsed: Gas,
|
|
64
66
|
private readonly gasSettings: GasSettings,
|
|
@@ -89,7 +91,7 @@ export class PublicTxContext {
|
|
|
89
91
|
const previousAccumulatedDataArrayLengths = new SideEffectArrayLengths(
|
|
90
92
|
/*publicDataWrites*/ 0,
|
|
91
93
|
countAccumulatedItems(nonRevertibleAccumulatedDataFromPrivate.noteHashes),
|
|
92
|
-
|
|
94
|
+
/*nullifiers=*/ 0,
|
|
93
95
|
countAccumulatedItems(nonRevertibleAccumulatedDataFromPrivate.l2ToL1Msgs),
|
|
94
96
|
/*unencryptedLogsHashes*/ 0,
|
|
95
97
|
);
|
|
@@ -105,7 +107,6 @@ export class PublicTxContext {
|
|
|
105
107
|
return new PublicTxContext(
|
|
106
108
|
new PhaseStateManager(txStateManager),
|
|
107
109
|
globalVariables,
|
|
108
|
-
tx.data.constants.historicalHeader,
|
|
109
110
|
await db.getStateReference(),
|
|
110
111
|
tx.data.gasUsed,
|
|
111
112
|
tx.data.constants.txContext.gasSettings,
|
|
@@ -301,11 +302,24 @@ export class PublicTxContext {
|
|
|
301
302
|
*/
|
|
302
303
|
private generateAvmCircuitPublicInputs(endStateReference: StateReference): AvmCircuitPublicInputs {
|
|
303
304
|
assert(this.halted, 'Can only get AvmCircuitPublicInputs after tx execution ends');
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
.
|
|
308
|
-
.getRoot();
|
|
305
|
+
const ephemeralTrees = this.state.getActiveStateManager().merkleTrees.treeMap;
|
|
306
|
+
|
|
307
|
+
const getAppendSnaphot = (id: MerkleTreeId) => {
|
|
308
|
+
const tree = ephemeralTrees.get(id)!;
|
|
309
|
+
return new AppendOnlyTreeSnapshot(tree.getRoot(), Number(tree.leafCount));
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
const noteHashTree = getAppendSnaphot(MerkleTreeId.NOTE_HASH_TREE);
|
|
313
|
+
const nullifierTree = getAppendSnaphot(MerkleTreeId.NULLIFIER_TREE);
|
|
314
|
+
const publicDataTree = getAppendSnaphot(MerkleTreeId.PUBLIC_DATA_TREE);
|
|
315
|
+
|
|
316
|
+
const endTreeSnapshots = new TreeSnapshots(
|
|
317
|
+
endStateReference.l1ToL2MessageTree,
|
|
318
|
+
noteHashTree,
|
|
319
|
+
nullifierTree,
|
|
320
|
+
publicDataTree,
|
|
321
|
+
);
|
|
322
|
+
|
|
309
323
|
return generateAvmCircuitPublicInputs(
|
|
310
324
|
this.trace,
|
|
311
325
|
this.globalVariables,
|
|
@@ -317,7 +331,7 @@ export class PublicTxContext {
|
|
|
317
331
|
this.teardownCallRequests,
|
|
318
332
|
this.nonRevertibleAccumulatedDataFromPrivate,
|
|
319
333
|
this.revertibleAccumulatedDataFromPrivate,
|
|
320
|
-
|
|
334
|
+
endTreeSnapshots,
|
|
321
335
|
/*endGasUsed=*/ this.gasUsed,
|
|
322
336
|
this.getTransactionFeeUnsafe(),
|
|
323
337
|
this.revertCode,
|
|
@@ -328,38 +342,17 @@ export class PublicTxContext {
|
|
|
328
342
|
* Generate the proving request for the AVM circuit.
|
|
329
343
|
*/
|
|
330
344
|
generateProvingRequest(endStateReference: StateReference): AvmProvingRequest {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
stateManager: AvmPersistableStateManager,
|
|
343
|
-
executionRequest: PublicExecutionRequest,
|
|
344
|
-
result: AvmFinalizedCallResult,
|
|
345
|
-
allocatedGas: Gas,
|
|
346
|
-
) {
|
|
347
|
-
if (this.avmProvingRequest === undefined) {
|
|
348
|
-
// Propagate the very first avmProvingRequest of the tx for now.
|
|
349
|
-
// Eventually this will be the proof for the entire public portion of the transaction.
|
|
350
|
-
this.avmProvingRequest = generateAvmProvingRequest(
|
|
351
|
-
real,
|
|
352
|
-
fnName,
|
|
353
|
-
stateManager,
|
|
354
|
-
this.historicalHeader,
|
|
355
|
-
this.globalVariables,
|
|
356
|
-
executionRequest,
|
|
357
|
-
// TODO(dbanks12): do we need this return type unless we are doing an isolated call?
|
|
358
|
-
stateManager.trace.toPublicEnqueuedCallExecutionResult(result),
|
|
359
|
-
allocatedGas,
|
|
360
|
-
this.getTransactionFee(phase),
|
|
361
|
-
);
|
|
362
|
-
}
|
|
345
|
+
const hints = this.trace.getAvmCircuitHints();
|
|
346
|
+
return {
|
|
347
|
+
type: ProvingRequestType.PUBLIC_VM,
|
|
348
|
+
inputs: new AvmCircuitInputs(
|
|
349
|
+
'public_dispatch',
|
|
350
|
+
[],
|
|
351
|
+
PublicCircuitPublicInputs.empty(),
|
|
352
|
+
hints,
|
|
353
|
+
this.generateAvmCircuitPublicInputs(endStateReference),
|
|
354
|
+
),
|
|
355
|
+
};
|
|
363
356
|
}
|
|
364
357
|
}
|
|
365
358
|
|
|
@@ -26,6 +26,7 @@ import { strict as assert } from 'assert';
|
|
|
26
26
|
|
|
27
27
|
import { type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
|
|
28
28
|
import { type AvmPersistableStateManager, AvmSimulator } from '../avm/index.js';
|
|
29
|
+
import { NullifierCollisionError } from '../avm/journal/nullifiers.js';
|
|
29
30
|
import { getPublicFunctionDebugName } from '../common/debug_fn_name.js';
|
|
30
31
|
import { ExecutorMetrics } from './executor_metrics.js';
|
|
31
32
|
import { type WorldStateDB } from './public_db_sources.js';
|
|
@@ -289,17 +290,6 @@ export class PublicTxSimulator {
|
|
|
289
290
|
`[AVM] Enqueued public call consumed ${gasUsed.l2Gas} L2 gas ending with ${result.gasLeft.l2Gas} L2 gas left.`,
|
|
290
291
|
);
|
|
291
292
|
|
|
292
|
-
// TODO(dbanks12): remove once AVM proves entire public tx
|
|
293
|
-
context.updateProvingRequest(
|
|
294
|
-
this.realAvmProvingRequests,
|
|
295
|
-
phase,
|
|
296
|
-
fnName,
|
|
297
|
-
stateManager,
|
|
298
|
-
executionRequest,
|
|
299
|
-
result,
|
|
300
|
-
allocatedGas,
|
|
301
|
-
);
|
|
302
|
-
|
|
303
293
|
stateManager.traceEnqueuedCall(callRequest, executionRequest.args, result.reverted);
|
|
304
294
|
|
|
305
295
|
if (result.reverted) {
|
|
@@ -385,7 +375,15 @@ export class PublicTxSimulator {
|
|
|
385
375
|
*/
|
|
386
376
|
public async insertNonRevertiblesFromPrivate(context: PublicTxContext) {
|
|
387
377
|
const stateManager = context.state.getActiveStateManager();
|
|
388
|
-
|
|
378
|
+
try {
|
|
379
|
+
await stateManager.writeSiloedNullifiersFromPrivate(context.nonRevertibleAccumulatedDataFromPrivate.nullifiers);
|
|
380
|
+
} catch (e) {
|
|
381
|
+
if (e instanceof NullifierCollisionError) {
|
|
382
|
+
throw new NullifierCollisionError(
|
|
383
|
+
`Nullifier collision encountered when inserting non-revertible nullifiers from private.\nDetails: ${e.message}\n.Stack:${e.stack}`,
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
389
387
|
}
|
|
390
388
|
|
|
391
389
|
/**
|
|
@@ -396,6 +394,14 @@ export class PublicTxSimulator {
|
|
|
396
394
|
// Fork the state manager so we can rollback to end of setup if app logic reverts.
|
|
397
395
|
context.state.fork();
|
|
398
396
|
const stateManager = context.state.getActiveStateManager();
|
|
399
|
-
|
|
397
|
+
try {
|
|
398
|
+
await stateManager.writeSiloedNullifiersFromPrivate(context.revertibleAccumulatedDataFromPrivate.nullifiers);
|
|
399
|
+
} catch (e) {
|
|
400
|
+
if (e instanceof NullifierCollisionError) {
|
|
401
|
+
throw new NullifierCollisionError(
|
|
402
|
+
`Nullifier collision encountered when inserting revertible nullifiers from private. Details:\n${e.message}\n.Stack:${e.stack}`,
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
400
406
|
}
|
|
401
407
|
}
|
|
@@ -138,7 +138,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
138
138
|
);
|
|
139
139
|
|
|
140
140
|
// New hinting
|
|
141
|
-
this.avmCircuitHints.
|
|
141
|
+
this.avmCircuitHints.publicDataReads.items.push(new AvmPublicDataReadTreeHint(leafPreimage, leafIndex, path));
|
|
142
142
|
|
|
143
143
|
this.log.debug(`SLOAD cnt: ${this.sideEffectCounter} val: ${value} slot: ${slot}`);
|
|
144
144
|
this.incrementSideEffectCounter();
|
|
@@ -168,7 +168,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
168
168
|
|
|
169
169
|
// New hinting
|
|
170
170
|
const readHint = new AvmPublicDataReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
|
|
171
|
-
this.avmCircuitHints.
|
|
171
|
+
this.avmCircuitHints.publicDataWrites.items.push(
|
|
172
172
|
new AvmPublicDataWriteTreeHint(readHint, newLeafPreimage, insertionPath),
|
|
173
173
|
);
|
|
174
174
|
this.log.debug(`SSTORE cnt: ${this.sideEffectCounter} val: ${value} slot: ${slot}`);
|
|
@@ -193,7 +193,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
193
193
|
new AvmKeyValueHint(/*key=*/ new Fr(leafIndex), /*value=*/ exists ? Fr.ONE : Fr.ZERO),
|
|
194
194
|
);
|
|
195
195
|
// New Hinting
|
|
196
|
-
this.avmCircuitHints.
|
|
196
|
+
this.avmCircuitHints.noteHashReads.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
|
|
197
197
|
// NOTE: counter does not increment for note hash checks (because it doesn't rely on pending note hashes)
|
|
198
198
|
}
|
|
199
199
|
|
|
@@ -210,7 +210,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
210
210
|
this.log.debug(`NEW_NOTE_HASH cnt: ${this.sideEffectCounter}`);
|
|
211
211
|
|
|
212
212
|
// New Hinting
|
|
213
|
-
this.avmCircuitHints.
|
|
213
|
+
this.avmCircuitHints.noteHashWrites.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
|
|
214
214
|
this.incrementSideEffectCounter();
|
|
215
215
|
}
|
|
216
216
|
|
|
@@ -237,7 +237,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
237
237
|
);
|
|
238
238
|
|
|
239
239
|
// New Hints
|
|
240
|
-
this.avmCircuitHints.
|
|
240
|
+
this.avmCircuitHints.nullifierReads.items.push(
|
|
241
241
|
new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath),
|
|
242
242
|
);
|
|
243
243
|
this.log.debug(`NULLIFIER_EXISTS cnt: ${this.sideEffectCounter}`);
|
|
@@ -259,7 +259,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
259
259
|
this.nullifiers.push(new Nullifier(siloedNullifier, this.sideEffectCounter, /*noteHash=*/ Fr.ZERO));
|
|
260
260
|
// New hinting
|
|
261
261
|
const lowLeafReadHint = new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
|
|
262
|
-
this.avmCircuitHints.
|
|
262
|
+
this.avmCircuitHints.nullifierWrites.items.push(new AvmNullifierWriteTreeHint(lowLeafReadHint, insertionPath));
|
|
263
263
|
this.log.debug(`NEW_NULLIFIER cnt: ${this.sideEffectCounter}`);
|
|
264
264
|
this.incrementSideEffectCounter();
|
|
265
265
|
}
|
|
@@ -282,7 +282,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
282
282
|
);
|
|
283
283
|
|
|
284
284
|
// New Hinting
|
|
285
|
-
this.avmCircuitHints.
|
|
285
|
+
this.avmCircuitHints.l1ToL2MessageReads.items.push(new AvmAppendTreeHint(msgLeafIndex, msgHash, path));
|
|
286
286
|
// NOTE: counter does not increment for l1tol2 message checks (because it doesn't rely on pending messages)
|
|
287
287
|
}
|
|
288
288
|
|