@aztec/simulator 0.66.0 → 0.67.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.js +3 -3
- package/dest/acvm/oracle/oracle.d.ts +1 -1
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +3 -3
- package/dest/acvm/oracle/typed_oracle.d.ts +2 -2
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +3 -3
- package/dest/acvm/serialize.js +2 -2
- package/dest/avm/avm_context.d.ts +2 -2
- package/dest/avm/avm_context.d.ts.map +1 -1
- package/dest/avm/avm_context.js +3 -4
- package/dest/avm/avm_execution_environment.d.ts +4 -6
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +8 -13
- package/dest/avm/avm_memory_types.d.ts +2 -2
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +3 -3
- package/dest/avm/avm_simulator.d.ts +3 -3
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +22 -13
- package/dest/avm/errors.d.ts +3 -3
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +8 -15
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +4 -4
- package/dest/avm/journal/journal.d.ts +15 -4
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +108 -29
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +4 -11
- package/dest/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/avm/opcodes/misc.js +3 -3
- 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 +14 -8
- package/dest/client/db_oracle.d.ts +2 -2
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/execution_note_cache.d.ts +9 -1
- package/dest/client/execution_note_cache.d.ts.map +1 -1
- package/dest/client/execution_note_cache.js +10 -3
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +4 -4
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +4 -4
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +3 -3
- package/dest/client/view_data_oracle.d.ts +2 -2
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +5 -6
- package/dest/common/debug_fn_name.d.ts +2 -2
- package/dest/common/debug_fn_name.d.ts.map +1 -1
- package/dest/common/debug_fn_name.js +8 -14
- package/dest/providers/acvm_native.js +4 -4
- package/dest/providers/factory.d.ts +2 -2
- package/dest/providers/factory.d.ts.map +1 -1
- package/dest/providers/factory.js +4 -4
- package/dest/public/enqueued_call_side_effect_trace.d.ts +11 -23
- package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
- package/dest/public/enqueued_call_side_effect_trace.js +37 -58
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +2 -5
- package/dest/public/fixtures/index.d.ts +24 -1
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +15 -9
- package/dest/public/index.d.ts +0 -1
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -2
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +4 -4
- package/dest/public/public_processor.d.ts +7 -8
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +30 -22
- package/dest/public/public_tx_context.d.ts +13 -10
- package/dest/public/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_context.js +46 -31
- package/dest/public/public_tx_simulator.d.ts +2 -2
- package/dest/public/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator.js +43 -23
- package/dest/public/side_effect_trace_interface.d.ts +4 -17
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/transitional_adapters.d.ts +2 -2
- package/dest/public/transitional_adapters.d.ts.map +1 -1
- package/dest/public/transitional_adapters.js +28 -24
- package/package.json +16 -9
- package/src/acvm/acvm.ts +2 -2
- package/src/acvm/oracle/oracle.ts +2 -2
- package/src/acvm/oracle/typed_oracle.ts +3 -3
- package/src/acvm/serialize.ts +1 -1
- package/src/avm/avm_context.ts +2 -3
- package/src/avm/avm_execution_environment.ts +6 -31
- package/src/avm/avm_memory_types.ts +2 -2
- package/src/avm/avm_simulator.ts +24 -20
- package/src/avm/errors.ts +12 -14
- package/src/avm/fixtures/index.ts +2 -3
- package/src/avm/journal/journal.ts +189 -63
- package/src/avm/opcodes/external_calls.ts +3 -19
- package/src/avm/opcodes/misc.ts +2 -2
- package/src/client/client_execution_context.ts +17 -9
- package/src/client/db_oracle.ts +2 -2
- package/src/client/execution_note_cache.ts +13 -3
- package/src/client/private_execution.ts +3 -3
- package/src/client/simulator.ts +4 -4
- package/src/client/unconstrained_execution.ts +2 -2
- package/src/client/view_data_oracle.ts +5 -6
- package/src/common/debug_fn_name.ts +7 -13
- package/src/providers/acvm_native.ts +3 -3
- package/src/providers/factory.ts +3 -3
- package/src/public/enqueued_call_side_effect_trace.ts +54 -74
- package/src/public/executor_metrics.ts +0 -4
- package/src/public/fixtures/index.ts +23 -10
- package/src/public/index.ts +0 -1
- package/src/public/public_db_sources.ts +3 -3
- package/src/public/public_processor.ts +46 -47
- package/src/public/public_tx_context.ts +52 -32
- package/src/public/public_tx_simulator.ts +58 -38
- package/src/public/side_effect_trace_interface.ts +8 -15
- package/src/public/transitional_adapters.ts +39 -24
- package/dest/public/dual_side_effect_trace.d.ts +0 -77
- package/dest/public/dual_side_effect_trace.d.ts.map +0 -1
- package/dest/public/dual_side_effect_trace.js +0 -119
- package/dest/public/side_effect_trace.d.ts +0 -96
- package/dest/public/side_effect_trace.d.ts.map +0 -1
- package/dest/public/side_effect_trace.js +0 -309
- package/src/public/dual_side_effect_trace.ts +0 -242
- package/src/public/side_effect_trace.ts +0 -536
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX,
|
|
1
|
+
import { Fr, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PrivateToAvmAccumulatedData, PrivateToAvmAccumulatedDataArrayLengths, PublicCallRequest, PublicDataWrite, TreeSnapshots, countAccumulatedItems, mergeAccumulatedData, } from '@aztec/circuits.js';
|
|
2
2
|
import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
|
|
3
3
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
4
4
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
5
|
-
export function generateAvmCircuitPublicInputs(trace, globalVariables, startStateReference, startGasUsed, gasSettings, setupCallRequests, appLogicCallRequests, teardownCallRequests, nonRevertibleAccumulatedDataFromPrivate, revertibleAccumulatedDataFromPrivate, endTreeSnapshots, endGasUsed, transactionFee, revertCode) {
|
|
5
|
+
export function generateAvmCircuitPublicInputs(trace, globalVariables, startStateReference, startGasUsed, gasSettings, feePayer, setupCallRequests, appLogicCallRequests, teardownCallRequests, nonRevertibleAccumulatedDataFromPrivate, revertibleAccumulatedDataFromPrivate, endTreeSnapshots, endGasUsed, transactionFee, revertCode) {
|
|
6
6
|
const startTreeSnapshots = new TreeSnapshots(startStateReference.l1ToL2MessageTree, startStateReference.partial.noteHashTree, startStateReference.partial.nullifierTree, startStateReference.partial.publicDataTree);
|
|
7
|
-
const avmCircuitPublicInputs = trace.toAvmCircuitPublicInputs(globalVariables, startTreeSnapshots, startGasUsed, gasSettings, setupCallRequests, appLogicCallRequests, teardownCallRequests.length ? teardownCallRequests[0] : PublicCallRequest.empty(), endTreeSnapshots, endGasUsed, transactionFee, !revertCode.isOK());
|
|
7
|
+
const avmCircuitPublicInputs = trace.toAvmCircuitPublicInputs(globalVariables, startTreeSnapshots, startGasUsed, gasSettings, feePayer, setupCallRequests, appLogicCallRequests, teardownCallRequests.length ? teardownCallRequests[0] : PublicCallRequest.empty(), endTreeSnapshots, endGasUsed, transactionFee, !revertCode.isOK());
|
|
8
8
|
const getArrayLengths = (from) => new PrivateToAvmAccumulatedDataArrayLengths(countAccumulatedItems(from.noteHashes), countAccumulatedItems(from.nullifiers), countAccumulatedItems(from.l2ToL1Msgs));
|
|
9
9
|
const convertAccumulatedData = (from) => new PrivateToAvmAccumulatedData(from.noteHashes, from.nullifiers, from.l2ToL1Msgs);
|
|
10
10
|
// Temporary overrides as these entries aren't yet populated in trace
|
|
@@ -12,12 +12,26 @@ export function generateAvmCircuitPublicInputs(trace, globalVariables, startStat
|
|
|
12
12
|
avmCircuitPublicInputs.previousRevertibleAccumulatedDataArrayLengths = getArrayLengths(revertibleAccumulatedDataFromPrivate);
|
|
13
13
|
avmCircuitPublicInputs.previousNonRevertibleAccumulatedData = convertAccumulatedData(nonRevertibleAccumulatedDataFromPrivate);
|
|
14
14
|
avmCircuitPublicInputs.previousRevertibleAccumulatedData = convertAccumulatedData(revertibleAccumulatedDataFromPrivate);
|
|
15
|
+
const txHash = avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.nullifiers[0];
|
|
16
|
+
// Add nonces to revertible note hashes from private. These don't have nonces since we don't know
|
|
17
|
+
// the final position in the tx until the AVM has executed.
|
|
18
|
+
// TODO: Use the final position in the tx
|
|
19
|
+
for (let revertibleIndex = 0; revertibleIndex < avmCircuitPublicInputs.previousRevertibleAccumulatedData.noteHashes.length; revertibleIndex++) {
|
|
20
|
+
const noteHash = avmCircuitPublicInputs.previousRevertibleAccumulatedData.noteHashes[revertibleIndex];
|
|
21
|
+
if (noteHash.isZero()) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const indexInTx = revertibleIndex + avmCircuitPublicInputs.previousNonRevertibleAccumulatedDataArrayLengths.noteHashes;
|
|
25
|
+
const nonce = computeNoteHashNonce(txHash, indexInTx);
|
|
26
|
+
const uniqueNoteHash = computeUniqueNoteHash(nonce, noteHash);
|
|
27
|
+
avmCircuitPublicInputs.previousRevertibleAccumulatedData.noteHashes[revertibleIndex] = uniqueNoteHash;
|
|
28
|
+
}
|
|
15
29
|
// merge all revertible & non-revertible side effects into output accumulated data
|
|
16
30
|
const noteHashesFromPrivate = revertCode.isOK()
|
|
17
31
|
? mergeAccumulatedData(avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.noteHashes, avmCircuitPublicInputs.previousRevertibleAccumulatedData.noteHashes)
|
|
18
32
|
: avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.noteHashes;
|
|
19
33
|
avmCircuitPublicInputs.accumulatedData.noteHashes = assertLength(mergeAccumulatedData(noteHashesFromPrivate, avmCircuitPublicInputs.accumulatedData.noteHashes), MAX_NOTE_HASHES_PER_TX);
|
|
20
|
-
|
|
34
|
+
// Silo and add nonces for note hashes emitted by the AVM
|
|
21
35
|
const scopedNoteHashesFromPublic = trace.getSideEffects().noteHashes;
|
|
22
36
|
for (let i = 0; i < scopedNoteHashesFromPublic.length; i++) {
|
|
23
37
|
const scopedNoteHash = scopedNoteHashesFromPublic[i];
|
|
@@ -25,34 +39,24 @@ export function generateAvmCircuitPublicInputs(trace, globalVariables, startStat
|
|
|
25
39
|
if (!noteHash.isZero()) {
|
|
26
40
|
const noteHashIndexInTx = i + countAccumulatedItems(noteHashesFromPrivate);
|
|
27
41
|
const nonce = computeNoteHashNonce(txHash, noteHashIndexInTx);
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
avmCircuitPublicInputs.accumulatedData.noteHashes[noteHashIndexInTx] =
|
|
42
|
+
const siloedNoteHash = siloNoteHash(scopedNoteHash.contractAddress, noteHash);
|
|
43
|
+
const uniqueNoteHash = computeUniqueNoteHash(nonce, siloedNoteHash);
|
|
44
|
+
avmCircuitPublicInputs.accumulatedData.noteHashes[noteHashIndexInTx] = uniqueNoteHash;
|
|
31
45
|
}
|
|
32
46
|
}
|
|
33
47
|
const msgsFromPrivate = revertCode.isOK()
|
|
34
48
|
? mergeAccumulatedData(avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.l2ToL1Msgs, avmCircuitPublicInputs.previousRevertibleAccumulatedData.l2ToL1Msgs)
|
|
35
49
|
: avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.l2ToL1Msgs;
|
|
36
50
|
avmCircuitPublicInputs.accumulatedData.l2ToL1Msgs = assertLength(mergeAccumulatedData(msgsFromPrivate, avmCircuitPublicInputs.accumulatedData.l2ToL1Msgs), MAX_L2_TO_L1_MSGS_PER_TX);
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
// Maps slot to value. Maps in TS are iterable in insertion order, which is exactly what we want for
|
|
52
|
+
// squashing "to the left", where the first occurrence of a slot uses the value of the last write to it,
|
|
53
|
+
// and the rest occurrences are omitted
|
|
54
|
+
const squashedPublicDataWrites = new Map();
|
|
39
55
|
for (const publicDataWrite of avmCircuitPublicInputs.accumulatedData.publicDataWrites) {
|
|
40
|
-
|
|
41
|
-
const prevOccurrences = leafSlotOccurences.get(slot) || 0;
|
|
42
|
-
leafSlotOccurences.set(slot, prevOccurrences + 1);
|
|
43
|
-
}
|
|
44
|
-
for (const publicDataWrite of avmCircuitPublicInputs.accumulatedData.publicDataWrites) {
|
|
45
|
-
const slot = publicDataWrite.leafSlot.toBigInt();
|
|
46
|
-
const prevOccurrences = leafSlotOccurences.get(slot) || 0;
|
|
47
|
-
if (prevOccurrences === 1) {
|
|
48
|
-
dedupedPublicDataWrites.push(publicDataWrite);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
leafSlotOccurences.set(slot, prevOccurrences - 1);
|
|
52
|
-
}
|
|
56
|
+
squashedPublicDataWrites.set(publicDataWrite.leafSlot.toBigInt(), publicDataWrite.value);
|
|
53
57
|
}
|
|
54
|
-
avmCircuitPublicInputs.accumulatedData.publicDataWrites = padArrayEnd(
|
|
58
|
+
avmCircuitPublicInputs.accumulatedData.publicDataWrites = padArrayEnd(Array.from(squashedPublicDataWrites.entries()).map(([slot, value]) => new PublicDataWrite(new Fr(slot), value)), PublicDataWrite.empty(), MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX);
|
|
55
59
|
//console.log(`AvmCircuitPublicInputs:\n${inspect(avmCircuitPublicInputs)}`);
|
|
56
60
|
return avmCircuitPublicInputs;
|
|
57
61
|
}
|
|
58
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
62
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNpdGlvbmFsX2FkYXB0ZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3B1YmxpYy90cmFuc2l0aW9uYWxfYWRhcHRlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUdMLEVBQUUsRUFJRix3QkFBd0IsRUFDeEIsc0JBQXNCLEVBQ3RCLDRDQUE0QyxFQUM1QywyQkFBMkIsRUFDM0IsdUNBQXVDLEVBRXZDLGlCQUFpQixFQUNqQixlQUFlLEVBR2YsYUFBYSxFQUNiLHFCQUFxQixFQUNyQixvQkFBb0IsR0FDckIsTUFBTSxvQkFBb0IsQ0FBQztBQUM1QixPQUFPLEVBQUUsb0JBQW9CLEVBQUUscUJBQXFCLEVBQUUsWUFBWSxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDcEcsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLDhCQUE4QixDQUFDO0FBQzNELE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUkzRCxNQUFNLFVBQVUsOEJBQThCLENBQzVDLEtBQXdDLEVBQ3hDLG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O0lBQ3ZDLE1BQU0sd0JBQXdCLEdBQW9CLElBQUksR0FBRyxFQUFFLENBQUM7SUFDNUQsS0FBSyxNQUFNLGVBQWUsSUFBSSxzQkFBc0IsQ0FBQyxlQUFlLENBQUMsZ0JBQWdCLEVBQUUsQ0FBQztRQUN0Rix3QkFBd0IsQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFDLFFBQVEsQ0FBQyxRQUFRLEVBQUUsRUFBRSxlQUFlLENBQUMsS0FBSyxDQUFDLENBQUM7SUFDM0YsQ0FBQztJQUVELHNCQUFzQixDQUFDLGVBQWUsQ0FBQyxnQkFBZ0IsR0FBRyxXQUFXLENBQ25FLEtBQUssQ0FBQyxJQUFJLENBQUMsd0JBQXdCLENBQUMsT0FBTyxFQUFFLENBQUMsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLElBQUksRUFBRSxLQUFLLENBQUMsRUFBRSxFQUFFLENBQUMsSUFBSSxlQUFlLENBQUMsSUFBSSxFQUFFLENBQUMsSUFBSSxDQUFDLEVBQUUsS0FBSyxDQUFDLENBQUMsRUFDL0csZUFBZSxDQUFDLEtBQUssRUFBRSxFQUN2Qiw0Q0FBNEMsQ0FDN0MsQ0FBQztJQUNGLDZFQUE2RTtJQUM3RSxPQUFPLHNCQUFzQixDQUFDO0FBQ2hDLENBQUMifQ==
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/simulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.67.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
7
|
+
"./client": "./dest/client/index.js",
|
|
8
|
+
"./acvm": "./dest/acvm/index.js",
|
|
9
|
+
"./errors": "./dest/common/errors.js",
|
|
7
10
|
"./public/fixtures": "./dest/public/fixtures/index.js"
|
|
8
11
|
},
|
|
9
12
|
"typedocOptions": {
|
|
@@ -56,17 +59,21 @@
|
|
|
56
59
|
"summaryThreshold": 9999
|
|
57
60
|
}
|
|
58
61
|
]
|
|
62
|
+
],
|
|
63
|
+
"testTimeout": 30000,
|
|
64
|
+
"setupFiles": [
|
|
65
|
+
"../../foundation/src/jest/setup.mjs"
|
|
59
66
|
]
|
|
60
67
|
},
|
|
61
68
|
"dependencies": {
|
|
62
|
-
"@aztec/circuit-types": "0.
|
|
63
|
-
"@aztec/circuits.js": "0.
|
|
64
|
-
"@aztec/foundation": "0.
|
|
65
|
-
"@aztec/noir-protocol-circuits-types": "0.
|
|
66
|
-
"@aztec/protocol-contracts": "0.
|
|
67
|
-
"@aztec/telemetry-client": "0.
|
|
68
|
-
"@aztec/types": "0.
|
|
69
|
-
"@aztec/world-state": "0.
|
|
69
|
+
"@aztec/circuit-types": "0.67.1",
|
|
70
|
+
"@aztec/circuits.js": "0.67.1",
|
|
71
|
+
"@aztec/foundation": "0.67.1",
|
|
72
|
+
"@aztec/noir-protocol-circuits-types": "0.67.1",
|
|
73
|
+
"@aztec/protocol-contracts": "0.67.1",
|
|
74
|
+
"@aztec/telemetry-client": "0.67.1",
|
|
75
|
+
"@aztec/types": "0.67.1",
|
|
76
|
+
"@aztec/world-state": "0.67.1",
|
|
70
77
|
"@noir-lang/acvm_js": "portal:../../noir/packages/acvm_js",
|
|
71
78
|
"@noir-lang/noirc_abi": "portal:../../noir/packages/noirc_abi",
|
|
72
79
|
"@noir-lang/types": "portal:../../noir/packages/types",
|
package/src/acvm/acvm.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type NoirCallStack } from '@aztec/circuit-types';
|
|
2
2
|
import type { FunctionDebugMetadata } from '@aztec/foundation/abi';
|
|
3
|
-
import {
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
type ExecutionError,
|
|
@@ -42,7 +42,7 @@ export async function acvm(
|
|
|
42
42
|
initialWitness: ACVMWitness,
|
|
43
43
|
callback: ACIRCallback,
|
|
44
44
|
): Promise<ACIRExecutionResult> {
|
|
45
|
-
const logger =
|
|
45
|
+
const logger = createLogger('simulator:acvm');
|
|
46
46
|
|
|
47
47
|
const solvedAndReturnWitness = await executeCircuitWithReturnWitness(
|
|
48
48
|
acir,
|
|
@@ -146,10 +146,10 @@ export class Oracle {
|
|
|
146
146
|
return witness.toFields().map(toACVMField);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
async
|
|
149
|
+
async getBlockHeader([blockNumber]: ACVMField[]): Promise<ACVMField[]> {
|
|
150
150
|
const parsedBlockNumber = frToNumber(fromACVMField(blockNumber));
|
|
151
151
|
|
|
152
|
-
const header = await this.typedOracle.
|
|
152
|
+
const header = await this.typedOracle.getBlockHeader(parsedBlockNumber);
|
|
153
153
|
if (!header) {
|
|
154
154
|
throw new Error(`Block header not found for block ${parsedBlockNumber}.`);
|
|
155
155
|
}
|
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
type UnencryptedL2Log,
|
|
10
10
|
} from '@aztec/circuit-types';
|
|
11
11
|
import {
|
|
12
|
+
type BlockHeader,
|
|
12
13
|
type ContractInstance,
|
|
13
|
-
type Header,
|
|
14
14
|
type IndexedTaggingSecret,
|
|
15
15
|
type KeyValidationRequest,
|
|
16
16
|
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
@@ -127,8 +127,8 @@ export abstract class TypedOracle {
|
|
|
127
127
|
throw new OracleMethodNotAvailableError('getLowNullifierMembershipWitness');
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
throw new OracleMethodNotAvailableError('
|
|
130
|
+
getBlockHeader(_blockNumber: number): Promise<BlockHeader | undefined> {
|
|
131
|
+
throw new OracleMethodNotAvailableError('getBlockHeader');
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
getCompleteAddress(_account: AztecAddress): Promise<CompleteAddress> {
|
package/src/acvm/serialize.ts
CHANGED
|
@@ -32,7 +32,7 @@ export function toACVMField(
|
|
|
32
32
|
} else if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'bigint') {
|
|
33
33
|
buffer = new Fr(value).toBuffer();
|
|
34
34
|
} else if (typeof value === 'string') {
|
|
35
|
-
buffer = Fr.
|
|
35
|
+
buffer = Fr.fromHexString(value).toBuffer();
|
|
36
36
|
} else {
|
|
37
37
|
buffer = value.toBuffer();
|
|
38
38
|
}
|
package/src/avm/avm_context.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AztecAddress
|
|
1
|
+
import { type AztecAddress } from '@aztec/circuits.js';
|
|
2
2
|
import { type Fr } from '@aztec/foundation/fields';
|
|
3
3
|
|
|
4
4
|
import { type AvmExecutionEnvironment } from './avm_execution_environment.js';
|
|
@@ -43,13 +43,12 @@ export class AvmContext {
|
|
|
43
43
|
calldata: Fr[],
|
|
44
44
|
allocatedGas: Gas,
|
|
45
45
|
callType: 'CALL' | 'STATICCALL',
|
|
46
|
-
functionSelector: FunctionSelector = FunctionSelector.empty(),
|
|
47
46
|
): AvmContext {
|
|
48
47
|
const deriveFn =
|
|
49
48
|
callType === 'CALL'
|
|
50
49
|
? this.environment.deriveEnvironmentForNestedCall
|
|
51
50
|
: this.environment.deriveEnvironmentForNestedStaticCall;
|
|
52
|
-
const newExecutionEnvironment = deriveFn.call(this.environment, address, calldata
|
|
51
|
+
const newExecutionEnvironment = deriveFn.call(this.environment, address, calldata);
|
|
53
52
|
const forkedWorldState = this.persistableState.fork();
|
|
54
53
|
const machineState = AvmMachineState.fromState(gasToGasLeft(allocatedGas));
|
|
55
54
|
return new AvmContext(forkedWorldState, newExecutionEnvironment, machineState);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type GlobalVariables } from '@aztec/circuits.js';
|
|
2
2
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
4
|
|
|
@@ -10,7 +10,6 @@ export class AvmExecutionEnvironment {
|
|
|
10
10
|
constructor(
|
|
11
11
|
public readonly address: AztecAddress,
|
|
12
12
|
public readonly sender: AztecAddress,
|
|
13
|
-
public readonly functionSelector: FunctionSelector, // may be temporary (#7224)
|
|
14
13
|
public readonly contractCallDepth: Fr,
|
|
15
14
|
public readonly transactionFee: Fr,
|
|
16
15
|
public readonly globals: GlobalVariables,
|
|
@@ -18,16 +17,10 @@ export class AvmExecutionEnvironment {
|
|
|
18
17
|
public readonly calldata: Fr[],
|
|
19
18
|
) {}
|
|
20
19
|
|
|
21
|
-
private deriveEnvironmentForNestedCallInternal(
|
|
22
|
-
targetAddress: AztecAddress,
|
|
23
|
-
calldata: Fr[],
|
|
24
|
-
functionSelector: FunctionSelector,
|
|
25
|
-
isStaticCall: boolean,
|
|
26
|
-
) {
|
|
20
|
+
private deriveEnvironmentForNestedCallInternal(targetAddress: AztecAddress, calldata: Fr[], isStaticCall: boolean) {
|
|
27
21
|
return new AvmExecutionEnvironment(
|
|
28
22
|
/*address=*/ targetAddress,
|
|
29
23
|
/*sender=*/ this.address,
|
|
30
|
-
functionSelector,
|
|
31
24
|
this.contractCallDepth.add(Fr.ONE),
|
|
32
25
|
this.transactionFee,
|
|
33
26
|
this.globals,
|
|
@@ -36,29 +29,11 @@ export class AvmExecutionEnvironment {
|
|
|
36
29
|
);
|
|
37
30
|
}
|
|
38
31
|
|
|
39
|
-
public deriveEnvironmentForNestedCall(
|
|
40
|
-
targetAddress
|
|
41
|
-
calldata: Fr[],
|
|
42
|
-
functionSelector: FunctionSelector = FunctionSelector.empty(),
|
|
43
|
-
): AvmExecutionEnvironment {
|
|
44
|
-
return this.deriveEnvironmentForNestedCallInternal(
|
|
45
|
-
targetAddress,
|
|
46
|
-
calldata,
|
|
47
|
-
functionSelector,
|
|
48
|
-
/*isStaticCall=*/ false,
|
|
49
|
-
);
|
|
32
|
+
public deriveEnvironmentForNestedCall(targetAddress: AztecAddress, calldata: Fr[]): AvmExecutionEnvironment {
|
|
33
|
+
return this.deriveEnvironmentForNestedCallInternal(targetAddress, calldata, /*isStaticCall=*/ false);
|
|
50
34
|
}
|
|
51
35
|
|
|
52
|
-
public deriveEnvironmentForNestedStaticCall(
|
|
53
|
-
targetAddress
|
|
54
|
-
calldata: Fr[],
|
|
55
|
-
functionSelector: FunctionSelector,
|
|
56
|
-
): AvmExecutionEnvironment {
|
|
57
|
-
return this.deriveEnvironmentForNestedCallInternal(
|
|
58
|
-
targetAddress,
|
|
59
|
-
calldata,
|
|
60
|
-
functionSelector,
|
|
61
|
-
/*isStaticCall=*/ true,
|
|
62
|
-
);
|
|
36
|
+
public deriveEnvironmentForNestedStaticCall(targetAddress: AztecAddress, calldata: Fr[]): AvmExecutionEnvironment {
|
|
37
|
+
return this.deriveEnvironmentForNestedCallInternal(targetAddress, calldata, /*isStaticCall=*/ true);
|
|
63
38
|
}
|
|
64
39
|
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
11
11
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
12
12
|
import { Fr } from '@aztec/foundation/fields';
|
|
13
|
-
import { type
|
|
13
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
14
14
|
import { type FunctionsOf } from '@aztec/foundation/types';
|
|
15
15
|
|
|
16
16
|
import { strict as assert } from 'assert';
|
|
@@ -227,7 +227,7 @@ export enum TypeTag {
|
|
|
227
227
|
export type TaggedMemoryInterface = FunctionsOf<TaggedMemory>;
|
|
228
228
|
|
|
229
229
|
export class TaggedMemory implements TaggedMemoryInterface {
|
|
230
|
-
static readonly log:
|
|
230
|
+
static readonly log: Logger = createLogger('simulator:avm:memory');
|
|
231
231
|
|
|
232
232
|
// Whether to track and validate memory accesses for each instruction.
|
|
233
233
|
static readonly TRACK_MEMORY_ACCESSES = process.env.NODE_ENV === 'test';
|
package/src/avm/avm_simulator.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
Fr,
|
|
4
|
-
type FunctionSelector,
|
|
5
|
-
type GlobalVariables,
|
|
6
|
-
MAX_L2_GAS_PER_ENQUEUED_CALL,
|
|
7
|
-
} from '@aztec/circuits.js';
|
|
8
|
-
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { type AztecAddress, Fr, type GlobalVariables, MAX_L2_GAS_PER_TX_PUBLIC_PORTION } from '@aztec/circuits.js';
|
|
2
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
9
3
|
|
|
10
4
|
import { strict as assert } from 'assert';
|
|
11
5
|
|
|
@@ -41,7 +35,7 @@ type PcTally = {
|
|
|
41
35
|
};
|
|
42
36
|
|
|
43
37
|
export class AvmSimulator {
|
|
44
|
-
private log:
|
|
38
|
+
private log: Logger;
|
|
45
39
|
private bytecode: Buffer | undefined;
|
|
46
40
|
private opcodeTallies: Map<string, OpcodeTally> = new Map();
|
|
47
41
|
private pcTallies: Map<number, PcTally> = new Map();
|
|
@@ -49,12 +43,14 @@ export class AvmSimulator {
|
|
|
49
43
|
private tallyPrintFunction = () => {};
|
|
50
44
|
private tallyInstructionFunction = (_a: number, _b: string, _c: Gas) => {};
|
|
51
45
|
|
|
46
|
+
// Test Purposes only: Logger will not have the proper function name. Use this constructor for testing purposes
|
|
47
|
+
// only. Otherwise, use build() below.
|
|
52
48
|
constructor(private context: AvmContext, private instructionSet: InstructionSet = INSTRUCTION_SET()) {
|
|
53
49
|
assert(
|
|
54
|
-
context.machineState.gasLeft.l2Gas <=
|
|
55
|
-
`Cannot allocate more than ${
|
|
50
|
+
context.machineState.gasLeft.l2Gas <= MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
|
|
51
|
+
`Cannot allocate more than ${MAX_L2_GAS_PER_TX_PUBLIC_PORTION} to the AVM for execution.`,
|
|
56
52
|
);
|
|
57
|
-
this.log =
|
|
53
|
+
this.log = createLogger(`simulator:avm(calldata[0]: ${context.environment.calldata[0]})`);
|
|
58
54
|
// TODO(palla/log): Should tallies be printed on debug, or only on trace?
|
|
59
55
|
if (this.log.isLevelEnabled('debug')) {
|
|
60
56
|
this.tallyPrintFunction = this.printOpcodeTallies;
|
|
@@ -62,11 +58,20 @@ export class AvmSimulator {
|
|
|
62
58
|
}
|
|
63
59
|
}
|
|
64
60
|
|
|
65
|
-
|
|
61
|
+
// Factory to have a proper function name in the logger. Retrieving the name is asynchronous and
|
|
62
|
+
// cannot be done as part of the constructor.
|
|
63
|
+
public static async build(context: AvmContext): Promise<AvmSimulator> {
|
|
64
|
+
const simulator = new AvmSimulator(context);
|
|
65
|
+
const fnName = await context.persistableState.getPublicFunctionDebugName(context.environment);
|
|
66
|
+
simulator.log = createLogger(`simulator:avm(f:${fnName})`);
|
|
67
|
+
|
|
68
|
+
return simulator;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public static async create(
|
|
66
72
|
stateManager: AvmPersistableStateManager,
|
|
67
73
|
address: AztecAddress,
|
|
68
74
|
sender: AztecAddress,
|
|
69
|
-
functionSelector: FunctionSelector, // may be temporary (#7224)
|
|
70
75
|
transactionFee: Fr,
|
|
71
76
|
globals: GlobalVariables,
|
|
72
77
|
isStaticCall: boolean,
|
|
@@ -76,7 +81,6 @@ export class AvmSimulator {
|
|
|
76
81
|
const avmExecutionEnv = new AvmExecutionEnvironment(
|
|
77
82
|
address,
|
|
78
83
|
sender,
|
|
79
|
-
functionSelector,
|
|
80
84
|
/*contractCallDepth=*/ Fr.zero(),
|
|
81
85
|
transactionFee,
|
|
82
86
|
globals,
|
|
@@ -86,8 +90,7 @@ export class AvmSimulator {
|
|
|
86
90
|
|
|
87
91
|
const avmMachineState = new AvmMachineState(allocatedGas);
|
|
88
92
|
const avmContext = new AvmContext(stateManager, avmExecutionEnv, avmMachineState);
|
|
89
|
-
|
|
90
|
-
return new AvmSimulator(avmContext, instructionSet);
|
|
93
|
+
return await AvmSimulator.build(avmContext);
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
/**
|
|
@@ -98,11 +101,12 @@ export class AvmSimulator {
|
|
|
98
101
|
if (!bytecode) {
|
|
99
102
|
// revert, consuming all gas
|
|
100
103
|
const message = `No bytecode found at: ${this.context.environment.address}. Reverting...`;
|
|
104
|
+
const fnName = await this.context.persistableState.getPublicFunctionDebugName(this.context.environment);
|
|
101
105
|
const revertReason = new AvmRevertReason(
|
|
102
106
|
message,
|
|
103
107
|
/*failingFunction=*/ {
|
|
104
108
|
contractAddress: this.context.environment.address,
|
|
105
|
-
|
|
109
|
+
functionName: fnName,
|
|
106
110
|
},
|
|
107
111
|
/*noirCallStack=*/ [],
|
|
108
112
|
);
|
|
@@ -176,7 +180,7 @@ export class AvmSimulator {
|
|
|
176
180
|
|
|
177
181
|
const output = machineState.getOutput();
|
|
178
182
|
const reverted = machineState.getReverted();
|
|
179
|
-
const revertReason = reverted ? revertReasonFromExplicitRevert(output, this.context) : undefined;
|
|
183
|
+
const revertReason = reverted ? await revertReasonFromExplicitRevert(output, this.context) : undefined;
|
|
180
184
|
const results = new AvmContractCallResult(reverted, output, machineState.gasLeft, revertReason);
|
|
181
185
|
this.log.debug(`Context execution results: ${results.toString()}`);
|
|
182
186
|
|
|
@@ -190,7 +194,7 @@ export class AvmSimulator {
|
|
|
190
194
|
throw err;
|
|
191
195
|
}
|
|
192
196
|
|
|
193
|
-
const revertReason = revertReasonFromExceptionalHalt(err, this.context);
|
|
197
|
+
const revertReason = await revertReasonFromExceptionalHalt(err, this.context);
|
|
194
198
|
// Note: "exceptional halts" cannot return data, hence [].
|
|
195
199
|
const results = new AvmContractCallResult(/*reverted=*/ true, /*output=*/ [], machineState.gasLeft, revertReason);
|
|
196
200
|
this.log.debug(`Context execution results: ${results.toString()}`);
|
package/src/avm/errors.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FailingFunction, type NoirCallStack } from '@aztec/circuit-types';
|
|
2
|
-
import { type AztecAddress, Fr
|
|
2
|
+
import { type AztecAddress, type Fr } from '@aztec/circuits.js';
|
|
3
3
|
|
|
4
4
|
import { ExecutionError } from '../common/errors.js';
|
|
5
5
|
import { type AvmContext } from './avm_context.js';
|
|
@@ -138,16 +138,9 @@ export class AvmRevertReason extends ExecutionError {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
function createRevertReason(message: string, revertData: Fr[], context: AvmContext): AvmRevertReason {
|
|
142
|
-
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Properly fix this.
|
|
143
|
-
// If the function selector is the public dispatch selector, we need to extract the actual function selector from the calldata.
|
|
144
|
-
// We should remove this because the AVM (or public protocol) shouldn't be aware of the public dispatch calling convention.
|
|
145
|
-
let functionSelector = context.environment.functionSelector;
|
|
141
|
+
async function createRevertReason(message: string, revertData: Fr[], context: AvmContext): Promise<AvmRevertReason> {
|
|
146
142
|
// We drop the returnPc information.
|
|
147
143
|
const internalCallStack = context.machineState.internalCallStack.map(entry => entry.callPc);
|
|
148
|
-
if (functionSelector.toField().equals(new Fr(PUBLIC_DISPATCH_SELECTOR)) && context.environment.calldata.length > 0) {
|
|
149
|
-
functionSelector = FunctionSelector.fromField(context.environment.calldata[0]);
|
|
150
|
-
}
|
|
151
144
|
|
|
152
145
|
// If we are reverting due to the same error that we have been tracking, we use the nested error as the cause.
|
|
153
146
|
let nestedError = undefined;
|
|
@@ -160,11 +153,13 @@ function createRevertReason(message: string, revertData: Fr[], context: AvmConte
|
|
|
160
153
|
message = context.machineState.collectedRevertInfo.recursiveRevertReason.message;
|
|
161
154
|
}
|
|
162
155
|
|
|
156
|
+
const fnName = await context.persistableState.getPublicFunctionDebugName(context.environment);
|
|
157
|
+
|
|
163
158
|
return new AvmRevertReason(
|
|
164
159
|
message,
|
|
165
160
|
/*failingFunction=*/ {
|
|
166
161
|
contractAddress: context.environment.address,
|
|
167
|
-
|
|
162
|
+
functionName: fnName,
|
|
168
163
|
},
|
|
169
164
|
/*noirCallStack=*/ [...internalCallStack, context.machineState.pc].map(pc => `0.${pc}`),
|
|
170
165
|
/*options=*/ { cause: nestedError },
|
|
@@ -177,8 +172,11 @@ function createRevertReason(message: string, revertData: Fr[], context: AvmConte
|
|
|
177
172
|
* @param haltingError - the lower-level error causing the exceptional halt
|
|
178
173
|
* @param context - the context of the AVM execution used to extract the failingFunction and noirCallStack
|
|
179
174
|
*/
|
|
180
|
-
export function revertReasonFromExceptionalHalt(
|
|
181
|
-
|
|
175
|
+
export async function revertReasonFromExceptionalHalt(
|
|
176
|
+
haltingError: AvmExecutionError,
|
|
177
|
+
context: AvmContext,
|
|
178
|
+
): Promise<AvmRevertReason> {
|
|
179
|
+
return await createRevertReason(haltingError.message, [], context);
|
|
182
180
|
}
|
|
183
181
|
|
|
184
182
|
/**
|
|
@@ -187,6 +185,6 @@ export function revertReasonFromExceptionalHalt(haltingError: AvmExecutionError,
|
|
|
187
185
|
* @param revertData - output data of the explicit REVERT instruction
|
|
188
186
|
* @param context - the context of the AVM execution used to extract the failingFunction and noirCallStack
|
|
189
187
|
*/
|
|
190
|
-
export function revertReasonFromExplicitRevert(revertData: Fr[], context: AvmContext): AvmRevertReason {
|
|
191
|
-
return createRevertReason('Assertion failed: ', revertData, context);
|
|
188
|
+
export async function revertReasonFromExplicitRevert(revertData: Fr[], context: AvmContext): Promise<AvmRevertReason> {
|
|
189
|
+
return await createRevertReason('Assertion failed: ', revertData, context);
|
|
192
190
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isNoirCallStackUnresolved } from '@aztec/circuit-types';
|
|
2
|
-
import { GasFees, GlobalVariables,
|
|
2
|
+
import { GasFees, GlobalVariables, MAX_L2_GAS_PER_TX_PUBLIC_PORTION } from '@aztec/circuits.js';
|
|
3
3
|
import { type FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
|
|
4
4
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
5
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
@@ -64,7 +64,6 @@ export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnviron
|
|
|
64
64
|
return new AvmExecutionEnvironment(
|
|
65
65
|
overrides?.address ?? AztecAddress.zero(),
|
|
66
66
|
overrides?.sender ?? AztecAddress.zero(),
|
|
67
|
-
overrides?.functionSelector ?? FunctionSelector.empty(),
|
|
68
67
|
overrides?.contractCallDepth ?? Fr.zero(),
|
|
69
68
|
overrides?.transactionFee ?? Fr.zero(),
|
|
70
69
|
overrides?.globals ?? GlobalVariables.empty(),
|
|
@@ -94,7 +93,7 @@ export function initGlobalVariables(overrides?: Partial<GlobalVariables>): Globa
|
|
|
94
93
|
*/
|
|
95
94
|
export function initMachineState(overrides?: Partial<AvmMachineState>): AvmMachineState {
|
|
96
95
|
return AvmMachineState.fromState({
|
|
97
|
-
l2GasLeft: overrides?.l2GasLeft ??
|
|
96
|
+
l2GasLeft: overrides?.l2GasLeft ?? MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
|
|
98
97
|
daGasLeft: overrides?.daGasLeft ?? 1e8,
|
|
99
98
|
});
|
|
100
99
|
}
|