@aztec/simulator 0.61.0 → 0.63.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/acvm.d.ts +2 -16
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +2 -70
- package/dest/acvm/oracle/oracle.d.ts +4 -3
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +11 -9
- package/dest/acvm/oracle/typed_oracle.d.ts +5 -4
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +9 -6
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +4 -3
- package/dest/avm/avm_machine_state.d.ts +27 -8
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +6 -10
- package/dest/avm/avm_memory_types.d.ts +8 -0
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +5 -1
- package/dest/avm/avm_simulator.d.ts +2 -19
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +12 -14
- package/dest/avm/avm_tree.d.ts +249 -0
- package/dest/avm/avm_tree.d.ts.map +1 -0
- package/dest/avm/avm_tree.js +637 -0
- package/dest/avm/errors.d.ts +4 -17
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +21 -50
- package/dest/avm/fixtures/index.d.ts +7 -2
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +12 -12
- package/dest/avm/index.d.ts +1 -0
- package/dest/avm/index.d.ts.map +1 -1
- package/dest/avm/index.js +2 -1
- package/dest/avm/journal/journal.d.ts +43 -24
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +172 -39
- package/dest/avm/journal/nullifiers.d.ts +5 -4
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +2 -3
- package/dest/avm/journal/public_storage.d.ts +6 -5
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +1 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +4 -10
- package/dest/avm/opcodes/arithmetic.d.ts +4 -1
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +18 -4
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +1 -3
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +1 -2
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +2 -3
- package/dest/avm/opcodes/control_flow.d.ts +4 -0
- package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/avm/opcodes/control_flow.js +26 -11
- package/dest/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/avm/opcodes/conversion.js +1 -2
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/avm/opcodes/ec_add.js +5 -11
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +1 -2
- package/dest/avm/opcodes/external_calls.d.ts +4 -2
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +38 -22
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +1 -4
- package/dest/avm/opcodes/instruction.d.ts +4 -0
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +7 -1
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +1 -7
- package/dest/avm/opcodes/misc.js +3 -3
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
- package/dest/avm/opcodes/multi_scalar_mul.js +6 -5
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +2 -4
- package/dest/avm/serialization/bytecode_serialization.d.ts +1 -6
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +24 -20
- package/dest/avm/serialization/instruction_serialization.d.ts +2 -2
- package/dest/avm/serialization/instruction_serialization.js +2 -2
- package/dest/client/client_execution_context.d.ts +7 -10
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +19 -18
- package/dest/client/db_oracle.d.ts +22 -8
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +5 -4
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +3 -2
- package/dest/client/view_data_oracle.d.ts +6 -12
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +10 -12
- package/dest/common/errors.d.ts +15 -2
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/errors.js +85 -4
- package/dest/mocks/fixtures.d.ts +9 -28
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +12 -57
- package/dest/public/dual_side_effect_trace.d.ts +34 -26
- package/dest/public/dual_side_effect_trace.d.ts.map +1 -1
- package/dest/public/dual_side_effect_trace.js +48 -36
- package/dest/public/enqueued_call_side_effect_trace.d.ts +96 -33
- package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
- package/dest/public/enqueued_call_side_effect_trace.js +212 -138
- package/dest/public/execution.d.ts +50 -17
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -29
- package/dest/public/executor.d.ts +28 -11
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +33 -33
- package/dest/public/index.d.ts +4 -5
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +4 -5
- package/dest/public/public_db_sources.d.ts +1 -0
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +21 -19
- package/dest/public/public_processor.d.ts +7 -11
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +60 -42
- package/dest/public/public_processor_metrics.d.ts +3 -3
- package/dest/public/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor_metrics.js +1 -1
- package/dest/public/public_tx_context.d.ts +130 -0
- package/dest/public/public_tx_context.d.ts.map +1 -0
- package/dest/public/public_tx_context.js +293 -0
- package/dest/public/public_tx_simulator.d.ts +36 -0
- package/dest/public/public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator.js +148 -0
- package/dest/public/side_effect_trace.d.ts +30 -15
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +70 -16
- package/dest/public/side_effect_trace_interface.d.ts +43 -12
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/transitional_adapters.d.ts +9 -0
- package/dest/public/transitional_adapters.d.ts.map +1 -0
- package/dest/public/transitional_adapters.js +127 -0
- package/dest/public/utils.d.ts +5 -0
- package/dest/public/utils.d.ts.map +1 -0
- package/dest/public/utils.js +30 -0
- package/dest/test/utils.d.ts +2 -2
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +4 -4
- package/package.json +12 -9
- package/src/acvm/acvm.ts +3 -94
- package/src/acvm/oracle/oracle.ts +14 -12
- package/src/acvm/oracle/typed_oracle.ts +10 -6
- package/src/avm/avm_gas.ts +3 -2
- package/src/avm/avm_machine_state.ts +28 -12
- package/src/avm/avm_memory_types.ts +5 -0
- package/src/avm/avm_simulator.ts +13 -16
- package/src/avm/avm_tree.ts +785 -0
- package/src/avm/errors.ts +25 -48
- package/src/avm/fixtures/index.ts +16 -12
- package/src/avm/index.ts +1 -0
- package/src/avm/journal/journal.ts +291 -52
- package/src/avm/journal/nullifiers.ts +7 -7
- package/src/avm/journal/public_storage.ts +5 -5
- package/src/avm/opcodes/accrued_substate.ts +3 -9
- package/src/avm/opcodes/arithmetic.ts +26 -4
- package/src/avm/opcodes/bitwise.ts +0 -2
- package/src/avm/opcodes/comparators.ts +0 -1
- package/src/avm/opcodes/contract.ts +1 -2
- package/src/avm/opcodes/control_flow.ts +29 -10
- package/src/avm/opcodes/conversion.ts +0 -1
- package/src/avm/opcodes/ec_add.ts +6 -9
- package/src/avm/opcodes/environment_getters.ts +0 -1
- package/src/avm/opcodes/external_calls.ts +39 -21
- package/src/avm/opcodes/hashing.ts +0 -3
- package/src/avm/opcodes/instruction.ts +7 -0
- package/src/avm/opcodes/memory.ts +0 -6
- package/src/avm/opcodes/misc.ts +2 -2
- package/src/avm/opcodes/multi_scalar_mul.ts +5 -4
- package/src/avm/opcodes/storage.ts +1 -3
- package/src/avm/serialization/bytecode_serialization.ts +31 -22
- package/src/avm/serialization/instruction_serialization.ts +2 -2
- package/src/client/client_execution_context.ts +24 -21
- package/src/client/db_oracle.ts +31 -8
- package/src/client/private_execution.ts +5 -4
- package/src/client/unconstrained_execution.ts +2 -1
- package/src/client/view_data_oracle.ts +14 -13
- package/src/common/errors.ts +119 -3
- package/src/mocks/fixtures.ts +15 -106
- package/src/public/dual_side_effect_trace.ts +138 -50
- package/src/public/enqueued_call_side_effect_trace.ts +352 -212
- package/src/public/execution.ts +58 -42
- package/src/public/executor.ts +52 -67
- package/src/public/index.ts +7 -5
- package/src/public/public_db_sources.ts +22 -19
- package/src/public/public_processor.ts +111 -73
- package/src/public/public_processor_metrics.ts +3 -3
- package/src/public/public_tx_context.ts +411 -0
- package/src/public/public_tx_simulator.ts +232 -0
- package/src/public/side_effect_trace.ts +154 -28
- package/src/public/side_effect_trace_interface.ts +92 -14
- package/src/public/transitional_adapters.ts +347 -0
- package/src/public/utils.ts +32 -0
- package/src/test/utils.ts +9 -2
- package/dest/public/enqueued_call_simulator.d.ts +0 -43
- package/dest/public/enqueued_call_simulator.d.ts.map +0 -1
- package/dest/public/enqueued_call_simulator.js +0 -156
- package/dest/public/enqueued_calls_processor.d.ts +0 -43
- package/dest/public/enqueued_calls_processor.d.ts.map +0 -1
- package/dest/public/enqueued_calls_processor.js +0 -209
- package/dest/public/hints_builder.d.ts +0 -29
- package/dest/public/hints_builder.d.ts.map +0 -1
- package/dest/public/hints_builder.js +0 -75
- package/dest/public/public_kernel.d.ts +0 -30
- package/dest/public/public_kernel.d.ts.map +0 -1
- package/dest/public/public_kernel.js +0 -67
- package/dest/public/public_kernel_circuit_simulator.d.ts +0 -25
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +0 -1
- package/dest/public/public_kernel_circuit_simulator.js +0 -2
- package/dest/public/public_kernel_tail_simulator.d.ts +0 -15
- package/dest/public/public_kernel_tail_simulator.d.ts.map +0 -1
- package/dest/public/public_kernel_tail_simulator.js +0 -39
- package/src/public/enqueued_call_simulator.ts +0 -360
- package/src/public/enqueued_calls_processor.ts +0 -372
- package/src/public/hints_builder.ts +0 -168
- package/src/public/public_kernel.ts +0 -100
- package/src/public/public_kernel_circuit_simulator.ts +0 -32
- package/src/public/public_kernel_tail_simulator.ts +0 -97
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
} from '@aztec/circuits.js';
|
|
25
25
|
import { computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
|
|
26
26
|
import { type FunctionAbi, type FunctionArtifact, type NoteSelector, countArgumentsSize } from '@aztec/foundation/abi';
|
|
27
|
-
import {
|
|
27
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
28
28
|
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
|
|
29
29
|
import { Fr } from '@aztec/foundation/fields';
|
|
30
30
|
import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log';
|
|
@@ -62,7 +62,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
62
62
|
private noteHashNullifierCounterMap: Map<number, number> = new Map();
|
|
63
63
|
private noteEncryptedLogs: CountedNoteLog[] = [];
|
|
64
64
|
private encryptedLogs: CountedLog<EncryptedL2Log>[] = [];
|
|
65
|
-
private
|
|
65
|
+
private contractClassLogs: CountedLog<UnencryptedL2Log>[] = [];
|
|
66
66
|
private nestedExecutions: PrivateExecutionResult[] = [];
|
|
67
67
|
private enqueuedPublicFunctionCalls: CountedPublicExecutionRequest[] = [];
|
|
68
68
|
private publicTeardownFunctionCall: PublicExecutionRequest = PublicExecutionRequest.empty();
|
|
@@ -151,10 +151,10 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
|
-
* Return the
|
|
154
|
+
* Return the contract class logs emitted during this execution.
|
|
155
155
|
*/
|
|
156
|
-
public
|
|
157
|
-
return this.
|
|
156
|
+
public getContractClassLogs() {
|
|
157
|
+
return this.contractClassLogs;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
/**
|
|
@@ -360,16 +360,6 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
360
360
|
this.noteEncryptedLogs.push(encryptedLog);
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
-
/**
|
|
364
|
-
* Emit an unencrypted log.
|
|
365
|
-
* @param log - The unencrypted log to be emitted.
|
|
366
|
-
*/
|
|
367
|
-
public override emitUnencryptedLog(log: UnencryptedL2Log, counter: number) {
|
|
368
|
-
this.unencryptedLogs.push(new CountedLog(log, counter));
|
|
369
|
-
const text = log.toHumanReadable();
|
|
370
|
-
this.log.verbose(`Emitted unencrypted log: "${text.length > 100 ? text.slice(0, 100) + '...' : text}"`);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
363
|
/**
|
|
374
364
|
* Emit a contract class unencrypted log.
|
|
375
365
|
* This fn exists separately from emitUnencryptedLog because sha hashing the preimage
|
|
@@ -377,13 +367,11 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
377
367
|
* See private_context.nr
|
|
378
368
|
* @param log - The unencrypted log to be emitted.
|
|
379
369
|
*/
|
|
380
|
-
public override
|
|
381
|
-
this.
|
|
370
|
+
public override emitContractClassLog(log: UnencryptedL2Log, counter: number) {
|
|
371
|
+
this.contractClassLogs.push(new CountedLog(log, counter));
|
|
382
372
|
const text = log.toHumanReadable();
|
|
383
373
|
this.log.verbose(
|
|
384
|
-
`Emitted
|
|
385
|
-
text.length > 100 ? text.slice(0, 100) + '...' : text
|
|
386
|
-
}"`,
|
|
374
|
+
`Emitted log from ContractClassRegisterer: "${text.length > 100 ? text.slice(0, 100) + '...' : text}"`,
|
|
387
375
|
);
|
|
388
376
|
return Fr.fromBuffer(log.hash());
|
|
389
377
|
}
|
|
@@ -394,7 +382,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
394
382
|
childExecutionResult.publicInputs.nullifiers.some(item => !item.isEmpty()) ||
|
|
395
383
|
childExecutionResult.publicInputs.l2ToL1Msgs.some(item => !item.isEmpty()) ||
|
|
396
384
|
childExecutionResult.publicInputs.encryptedLogsHashes.some(item => !item.isEmpty()) ||
|
|
397
|
-
childExecutionResult.publicInputs.
|
|
385
|
+
childExecutionResult.publicInputs.contractClassLogsHashes.some(item => !item.isEmpty())
|
|
398
386
|
) {
|
|
399
387
|
throw new Error(`Static call cannot update the state, emit L2->L1 messages or generate logs`);
|
|
400
388
|
}
|
|
@@ -609,4 +597,19 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
609
597
|
public getDebugFunctionName() {
|
|
610
598
|
return this.db.getDebugFunctionName(this.contractAddress, this.callContext.functionSelector);
|
|
611
599
|
}
|
|
600
|
+
|
|
601
|
+
public override async incrementAppTaggingSecretIndexAsSender(sender: AztecAddress, recipient: AztecAddress) {
|
|
602
|
+
await this.db.incrementAppTaggingSecretIndexAsSender(this.contractAddress, sender, recipient);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
public override async syncNotes() {
|
|
606
|
+
const taggedLogsByRecipient = await this.db.syncTaggedLogs(
|
|
607
|
+
this.contractAddress,
|
|
608
|
+
this.historicalHeader.globalVariables.blockNumber.toNumber(),
|
|
609
|
+
this.scopes,
|
|
610
|
+
);
|
|
611
|
+
for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) {
|
|
612
|
+
await this.db.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient));
|
|
613
|
+
}
|
|
614
|
+
}
|
|
612
615
|
}
|
package/src/client/db_oracle.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type L2Block,
|
|
3
|
+
type L2BlockNumber,
|
|
3
4
|
type MerkleTreeId,
|
|
4
5
|
type NoteStatus,
|
|
5
6
|
type NullifierMembershipWitness,
|
|
6
7
|
type PublicDataWitness,
|
|
8
|
+
type TxScopedL2Log,
|
|
7
9
|
} from '@aztec/circuit-types';
|
|
8
10
|
import {
|
|
9
11
|
type CompleteAddress,
|
|
@@ -145,7 +147,7 @@ export interface DBOracle extends CommitmentsDB {
|
|
|
145
147
|
* @param leafValue - The leaf value buffer.
|
|
146
148
|
* @returns - The index of the leaf. Undefined if it does not exist in the tree.
|
|
147
149
|
*/
|
|
148
|
-
findLeafIndex(blockNumber:
|
|
150
|
+
findLeafIndex(blockNumber: L2BlockNumber, treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined>;
|
|
149
151
|
|
|
150
152
|
/**
|
|
151
153
|
* Fetch the sibling path of the leaf in the respective tree
|
|
@@ -197,26 +199,47 @@ export interface DBOracle extends CommitmentsDB {
|
|
|
197
199
|
|
|
198
200
|
/**
|
|
199
201
|
* Returns the tagging secret for a given sender and recipient pair. For this to work, the ivpsk_m of the sender must be known.
|
|
200
|
-
* Includes the
|
|
202
|
+
* Includes the next index to be used used for tagging with this secret.
|
|
201
203
|
* @param contractAddress - The contract address to silo the secret for
|
|
202
204
|
* @param sender - The address sending the note
|
|
203
205
|
* @param recipient - The address receiving the note
|
|
204
206
|
* @returns A tagging secret that can be used to tag notes.
|
|
205
207
|
*/
|
|
206
|
-
|
|
208
|
+
getAppTaggingSecretAsSender(
|
|
207
209
|
contractAddress: AztecAddress,
|
|
208
210
|
sender: AztecAddress,
|
|
209
211
|
recipient: AztecAddress,
|
|
210
212
|
): Promise<IndexedTaggingSecret>;
|
|
211
213
|
|
|
212
214
|
/**
|
|
213
|
-
*
|
|
215
|
+
* Increments the tagging secret for a given sender and recipient pair. For this to work, the ivpsk_m of the sender must be known.
|
|
214
216
|
* @param contractAddress - The contract address to silo the secret for
|
|
215
|
-
* @param
|
|
216
|
-
* @
|
|
217
|
+
* @param sender - The address sending the note
|
|
218
|
+
* @param recipient - The address receiving the note
|
|
217
219
|
*/
|
|
218
|
-
|
|
220
|
+
incrementAppTaggingSecretIndexAsSender(
|
|
219
221
|
contractAddress: AztecAddress,
|
|
222
|
+
sender: AztecAddress,
|
|
220
223
|
recipient: AztecAddress,
|
|
221
|
-
): Promise<
|
|
224
|
+
): Promise<void>;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Synchronizes the logs tagged with the recipient's address and all the senders in the addressbook.
|
|
228
|
+
* Returns the unsynched logs and updates the indexes of the secrets used to tag them until there are no more logs to sync.
|
|
229
|
+
* @param contractAddress - The address of the contract that the logs are tagged for
|
|
230
|
+
* @param recipient - The address of the recipient
|
|
231
|
+
* @returns A list of encrypted logs tagged with the recipient's address
|
|
232
|
+
*/
|
|
233
|
+
syncTaggedLogs(
|
|
234
|
+
contractAddress: AztecAddress,
|
|
235
|
+
maxBlockNumber: number,
|
|
236
|
+
scopes?: AztecAddress[],
|
|
237
|
+
): Promise<Map<string, TxScopedL2Log[]>>;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Processes the tagged logs returned by syncTaggedLogs by decrypting them and storing them in the database.
|
|
241
|
+
* @param logs - The logs to process.
|
|
242
|
+
* @param recipient - The recipient of the logs.
|
|
243
|
+
*/
|
|
244
|
+
processTaggedLogs(logs: TxScopedL2Log[], recipient: AztecAddress): Promise<void>;
|
|
222
245
|
}
|
|
@@ -13,7 +13,7 @@ import { Timer } from '@aztec/foundation/timer';
|
|
|
13
13
|
|
|
14
14
|
import { fromACVMField, witnessMapToFields } from '../acvm/deserialize.js';
|
|
15
15
|
import { type ACVMWitness, Oracle, acvm, extractCallStack } from '../acvm/index.js';
|
|
16
|
-
import { ExecutionError } from '../common/errors.js';
|
|
16
|
+
import { ExecutionError, resolveAssertionMessageFromError } from '../common/errors.js';
|
|
17
17
|
import { type ClientExecutionContext } from './client_execution_context.js';
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -33,6 +33,7 @@ export async function executePrivateFunction(
|
|
|
33
33
|
const acvmCallback = new Oracle(context);
|
|
34
34
|
const timer = new Timer();
|
|
35
35
|
const acirExecutionResult = await acvm(acir, initialWitness, acvmCallback).catch((err: Error) => {
|
|
36
|
+
err.message = resolveAssertionMessageFromError(err, artifact);
|
|
36
37
|
throw new ExecutionError(
|
|
37
38
|
err.message,
|
|
38
39
|
{
|
|
@@ -60,7 +61,7 @@ export async function executePrivateFunction(
|
|
|
60
61
|
|
|
61
62
|
const noteEncryptedLogs = context.getNoteEncryptedLogs();
|
|
62
63
|
const encryptedLogs = context.getEncryptedLogs();
|
|
63
|
-
const
|
|
64
|
+
const contractClassLogs = context.getContractClassLogs();
|
|
64
65
|
|
|
65
66
|
const rawReturnValues = await context.unpackReturns(publicInputs.returnsHash);
|
|
66
67
|
|
|
@@ -75,7 +76,7 @@ export async function executePrivateFunction(
|
|
|
75
76
|
|
|
76
77
|
return new PrivateExecutionResult(
|
|
77
78
|
acir,
|
|
78
|
-
Buffer.from(artifact.verificationKey!, '
|
|
79
|
+
Buffer.from(artifact.verificationKey!, 'base64'),
|
|
79
80
|
partialWitness,
|
|
80
81
|
publicInputs,
|
|
81
82
|
noteHashLeafIndexMap,
|
|
@@ -87,7 +88,7 @@ export async function executePrivateFunction(
|
|
|
87
88
|
publicTeardownFunctionCall,
|
|
88
89
|
noteEncryptedLogs,
|
|
89
90
|
encryptedLogs,
|
|
90
|
-
|
|
91
|
+
contractClassLogs,
|
|
91
92
|
);
|
|
92
93
|
}
|
|
93
94
|
|
|
@@ -5,7 +5,7 @@ import { createDebugLogger } from '@aztec/foundation/log';
|
|
|
5
5
|
|
|
6
6
|
import { witnessMapToFields } from '../acvm/deserialize.js';
|
|
7
7
|
import { Oracle, acvm, extractCallStack, toACVMWitness } from '../acvm/index.js';
|
|
8
|
-
import { ExecutionError } from '../common/errors.js';
|
|
8
|
+
import { ExecutionError, resolveAssertionMessageFromError } from '../common/errors.js';
|
|
9
9
|
import { type ViewDataOracle } from './view_data_oracle.js';
|
|
10
10
|
|
|
11
11
|
// docs:start:execute_unconstrained_function
|
|
@@ -25,6 +25,7 @@ export async function executeUnconstrainedFunction(
|
|
|
25
25
|
const acir = artifact.bytecode;
|
|
26
26
|
const initialWitness = toACVMWitness(0, args);
|
|
27
27
|
const acirExecutionResult = await acvm(acir, initialWitness, new Oracle(oracle)).catch((err: Error) => {
|
|
28
|
+
err.message = resolveAssertionMessageFromError(err, artifact);
|
|
28
29
|
throw new ExecutionError(
|
|
29
30
|
err.message,
|
|
30
31
|
{
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
type KeyValidationRequest,
|
|
15
15
|
} from '@aztec/circuits.js';
|
|
16
16
|
import { siloNullifier } from '@aztec/circuits.js/hash';
|
|
17
|
-
import {
|
|
17
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
18
18
|
import { Fr } from '@aztec/foundation/fields';
|
|
19
19
|
import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log';
|
|
20
20
|
|
|
@@ -271,7 +271,7 @@ export class ViewDataOracle extends TypedOracle {
|
|
|
271
271
|
* @param numberOfElements - Number of elements to read from the starting storage slot.
|
|
272
272
|
*/
|
|
273
273
|
public override async storageRead(
|
|
274
|
-
contractAddress:
|
|
274
|
+
contractAddress: AztecAddress,
|
|
275
275
|
startStorageSlot: Fr,
|
|
276
276
|
blockNumber: number,
|
|
277
277
|
numberOfElements: number,
|
|
@@ -296,26 +296,27 @@ export class ViewDataOracle extends TypedOracle {
|
|
|
296
296
|
|
|
297
297
|
/**
|
|
298
298
|
* Returns the tagging secret for a given sender and recipient pair, siloed to the current contract address.
|
|
299
|
-
* Includes the
|
|
299
|
+
* Includes the next index to be used used for tagging with this secret.
|
|
300
300
|
* For this to work, the ivpsk_m of the sender must be known.
|
|
301
301
|
* @param sender - The address sending the note
|
|
302
302
|
* @param recipient - The address receiving the note
|
|
303
303
|
* @returns A tagging secret that can be used to tag notes.
|
|
304
304
|
*/
|
|
305
|
-
public override async
|
|
305
|
+
public override async getAppTaggingSecretAsSender(
|
|
306
306
|
sender: AztecAddress,
|
|
307
307
|
recipient: AztecAddress,
|
|
308
308
|
): Promise<IndexedTaggingSecret> {
|
|
309
|
-
return await this.db.
|
|
309
|
+
return await this.db.getAppTaggingSecretAsSender(this.contractAddress, sender, recipient);
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
312
|
+
public override async syncNotes() {
|
|
313
|
+
const taggedLogsByRecipient = await this.db.syncTaggedLogs(
|
|
314
|
+
this.contractAddress,
|
|
315
|
+
await this.aztecNode.getBlockNumber(),
|
|
316
|
+
this.scopes,
|
|
317
|
+
);
|
|
318
|
+
for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) {
|
|
319
|
+
await this.db.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient));
|
|
320
|
+
}
|
|
320
321
|
}
|
|
321
322
|
}
|
package/src/common/errors.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type FailingFunction,
|
|
3
|
+
type NoirCallStack,
|
|
4
|
+
SimulationError,
|
|
5
|
+
type SourceCodeLocation,
|
|
6
|
+
} from '@aztec/circuit-types';
|
|
7
|
+
import { type Fr } from '@aztec/circuits.js';
|
|
8
|
+
import type { BrilligFunctionId, FunctionAbi, FunctionDebugMetadata, OpcodeLocation } from '@aztec/foundation/abi';
|
|
9
|
+
|
|
10
|
+
import { type RawAssertionPayload } from '@noir-lang/acvm_js';
|
|
11
|
+
import { abiDecodeError } from '@noir-lang/noirc_abi';
|
|
2
12
|
|
|
3
13
|
/**
|
|
4
14
|
* An error that occurred during the execution of a function.
|
|
@@ -47,7 +57,7 @@ export function traverseCauseChain(error: Error, callback: (error: Error) => voi
|
|
|
47
57
|
* @param error - The error thrown during execution.
|
|
48
58
|
* @returns - A simulation error.
|
|
49
59
|
*/
|
|
50
|
-
export function createSimulationError(error: Error): SimulationError {
|
|
60
|
+
export function createSimulationError(error: Error, revertData?: Fr[]): SimulationError {
|
|
51
61
|
let rootCause = error;
|
|
52
62
|
let noirCallStack: NoirCallStack | undefined = undefined;
|
|
53
63
|
const aztecCallStack: FailingFunction[] = [];
|
|
@@ -62,5 +72,111 @@ export function createSimulationError(error: Error): SimulationError {
|
|
|
62
72
|
}
|
|
63
73
|
});
|
|
64
74
|
|
|
65
|
-
return new SimulationError(rootCause.message, aztecCallStack, noirCallStack, { cause: rootCause });
|
|
75
|
+
return new SimulationError(rootCause.message, aztecCallStack, revertData, noirCallStack, { cause: rootCause });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Extracts a brillig location from an opcode location.
|
|
80
|
+
* @param opcodeLocation - The opcode location to extract from. It should be in the format `acirLocation.brilligLocation` or `acirLocation`.
|
|
81
|
+
* @returns The brillig location if the opcode location contains one.
|
|
82
|
+
*/
|
|
83
|
+
function extractBrilligLocation(opcodeLocation: string): string | undefined {
|
|
84
|
+
const splitted = opcodeLocation.split('.');
|
|
85
|
+
if (splitted.length === 2) {
|
|
86
|
+
return splitted[1];
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Extracts the call stack from the location of a failing opcode and the debug metadata.
|
|
93
|
+
* One opcode can point to multiple calls due to inlining.
|
|
94
|
+
*/
|
|
95
|
+
function getSourceCodeLocationsFromOpcodeLocation(
|
|
96
|
+
opcodeLocation: string,
|
|
97
|
+
debug: FunctionDebugMetadata,
|
|
98
|
+
brilligFunctionId?: BrilligFunctionId,
|
|
99
|
+
): SourceCodeLocation[] {
|
|
100
|
+
const { debugSymbols, files } = debug;
|
|
101
|
+
|
|
102
|
+
let callStack = debugSymbols.locations[opcodeLocation] || [];
|
|
103
|
+
if (callStack.length === 0) {
|
|
104
|
+
const brilligLocation = extractBrilligLocation(opcodeLocation);
|
|
105
|
+
if (brilligFunctionId !== undefined && brilligLocation !== undefined) {
|
|
106
|
+
callStack = debugSymbols.brillig_locations[brilligFunctionId][brilligLocation] || [];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return callStack.map(call => {
|
|
110
|
+
const { file: fileId, span } = call;
|
|
111
|
+
|
|
112
|
+
const { path, source } = files[fileId];
|
|
113
|
+
|
|
114
|
+
const locationText = source.substring(span.start, span.end);
|
|
115
|
+
const precedingText = source.substring(0, span.start);
|
|
116
|
+
const previousLines = precedingText.split('\n');
|
|
117
|
+
// Lines and columns in stacks are one indexed.
|
|
118
|
+
const line = previousLines.length;
|
|
119
|
+
const column = previousLines[previousLines.length - 1].length + 1;
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
filePath: path,
|
|
123
|
+
line,
|
|
124
|
+
column,
|
|
125
|
+
fileSource: source,
|
|
126
|
+
locationText,
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Extracts the source code locations for an array of opcode locations
|
|
133
|
+
* @param opcodeLocations - The opcode locations that caused the error.
|
|
134
|
+
* @param debug - The debug metadata of the function.
|
|
135
|
+
* @returns The source code locations.
|
|
136
|
+
*/
|
|
137
|
+
export function resolveOpcodeLocations(
|
|
138
|
+
opcodeLocations: OpcodeLocation[],
|
|
139
|
+
debug: FunctionDebugMetadata,
|
|
140
|
+
brilligFunctionId?: BrilligFunctionId,
|
|
141
|
+
): SourceCodeLocation[] {
|
|
142
|
+
return opcodeLocations.flatMap(opcodeLocation =>
|
|
143
|
+
getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, brilligFunctionId),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function resolveAssertionMessage(errorPayload: RawAssertionPayload, abi: FunctionAbi): string | undefined {
|
|
148
|
+
const decoded = abiDecodeError(
|
|
149
|
+
{ parameters: [], error_types: abi.errorTypes, return_type: null }, // eslint-disable-line camelcase
|
|
150
|
+
errorPayload,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
if (typeof decoded === 'string') {
|
|
154
|
+
return decoded;
|
|
155
|
+
} else {
|
|
156
|
+
return JSON.stringify(decoded);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function resolveAssertionMessageFromRevertData(revertData: Fr[], abi: FunctionAbi): string | undefined {
|
|
161
|
+
if (revertData.length == 0) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const [errorSelector, ...errorData] = revertData;
|
|
166
|
+
|
|
167
|
+
return resolveAssertionMessage(
|
|
168
|
+
{
|
|
169
|
+
selector: errorSelector.toBigInt().toString(),
|
|
170
|
+
data: errorData.map(f => f.toString()),
|
|
171
|
+
},
|
|
172
|
+
abi,
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function resolveAssertionMessageFromError(err: Error, abi: FunctionAbi): string {
|
|
177
|
+
if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err && err.rawAssertionPayload) {
|
|
178
|
+
return `Assertion failed: ${resolveAssertionMessage(err.rawAssertionPayload as RawAssertionPayload, abi)}`;
|
|
179
|
+
} else {
|
|
180
|
+
return err.message;
|
|
181
|
+
}
|
|
66
182
|
}
|
package/src/mocks/fixtures.ts
CHANGED
|
@@ -1,90 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
PublicExecutionRequest,
|
|
4
|
-
type SimulationError,
|
|
5
|
-
UnencryptedFunctionL2Logs,
|
|
6
|
-
} from '@aztec/circuit-types';
|
|
7
|
-
import {
|
|
8
|
-
ARGS_LENGTH,
|
|
9
|
-
AvmExecutionHints,
|
|
10
|
-
type AztecAddress,
|
|
11
|
-
CallContext,
|
|
12
|
-
type ContractStorageRead,
|
|
13
|
-
type ContractStorageUpdateRequest,
|
|
14
|
-
Fr,
|
|
15
|
-
Gas,
|
|
16
|
-
} from '@aztec/circuits.js';
|
|
1
|
+
import { SimulationError } from '@aztec/circuit-types';
|
|
2
|
+
import { ARGS_LENGTH, Fr, Gas } from '@aztec/circuits.js';
|
|
17
3
|
import { makeAztecAddress, makeSelector } from '@aztec/circuits.js/testing';
|
|
18
4
|
import { FunctionType } from '@aztec/foundation/abi';
|
|
19
5
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
20
6
|
|
|
21
|
-
import { type
|
|
7
|
+
import { type EnqueuedPublicCallExecutionResult } from '../public/execution.js';
|
|
22
8
|
|
|
23
9
|
export class PublicExecutionResultBuilder {
|
|
24
|
-
private _executionRequest: PublicExecutionRequest;
|
|
25
|
-
private _nestedExecutions: PublicExecutionResult[] = [];
|
|
26
|
-
private _contractStorageUpdateRequests: ContractStorageUpdateRequest[] = [];
|
|
27
|
-
private _contractStorageReads: ContractStorageRead[] = [];
|
|
28
10
|
private _returnValues: Fr[] = [];
|
|
29
11
|
private _reverted = false;
|
|
30
12
|
private _revertReason: SimulationError | undefined = undefined;
|
|
31
13
|
|
|
32
|
-
constructor(
|
|
33
|
-
this._executionRequest = executionRequest;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
static fromPublicExecutionRequest({
|
|
37
|
-
request,
|
|
38
|
-
returnValues = [new Fr(1n)],
|
|
39
|
-
nestedExecutions = [],
|
|
40
|
-
contractStorageUpdateRequests = [],
|
|
41
|
-
contractStorageReads = [],
|
|
42
|
-
revertReason = undefined,
|
|
43
|
-
}: {
|
|
44
|
-
request: PublicExecutionRequest;
|
|
45
|
-
returnValues?: Fr[];
|
|
46
|
-
nestedExecutions?: PublicExecutionResult[];
|
|
47
|
-
contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
|
|
48
|
-
contractStorageReads?: ContractStorageRead[];
|
|
49
|
-
revertReason?: SimulationError;
|
|
50
|
-
}): PublicExecutionResultBuilder {
|
|
51
|
-
const builder = new PublicExecutionResultBuilder(request);
|
|
14
|
+
constructor() {}
|
|
52
15
|
|
|
53
|
-
|
|
54
|
-
builder
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (revertReason) {
|
|
58
|
-
builder.withReverted(revertReason);
|
|
16
|
+
static empty(basicRevert = false) {
|
|
17
|
+
const builder = new PublicExecutionResultBuilder();
|
|
18
|
+
if (basicRevert) {
|
|
19
|
+
builder.withReverted(new SimulationError('Simulation failed', []));
|
|
59
20
|
}
|
|
60
|
-
|
|
61
21
|
return builder;
|
|
62
22
|
}
|
|
63
23
|
|
|
64
|
-
static
|
|
65
|
-
from,
|
|
66
|
-
tx,
|
|
24
|
+
static fromPublicExecutionRequest({
|
|
67
25
|
returnValues = [new Fr(1n)],
|
|
68
|
-
|
|
69
|
-
contractStorageUpdateRequests = [],
|
|
70
|
-
contractStorageReads = [],
|
|
71
|
-
revertReason,
|
|
26
|
+
revertReason = undefined,
|
|
72
27
|
}: {
|
|
73
|
-
from: AztecAddress;
|
|
74
|
-
tx: FunctionCall;
|
|
75
28
|
returnValues?: Fr[];
|
|
76
|
-
nestedExecutions?: PublicExecutionResult[];
|
|
77
|
-
contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
|
|
78
|
-
contractStorageReads?: ContractStorageRead[];
|
|
79
29
|
revertReason?: SimulationError;
|
|
80
|
-
}) {
|
|
81
|
-
const builder = new PublicExecutionResultBuilder(
|
|
82
|
-
new PublicExecutionRequest(new CallContext(from, tx.to, tx.selector, false), tx.args),
|
|
83
|
-
);
|
|
30
|
+
}): PublicExecutionResultBuilder {
|
|
31
|
+
const builder = new PublicExecutionResultBuilder();
|
|
84
32
|
|
|
85
|
-
builder.withNestedExecutions(...nestedExecutions);
|
|
86
|
-
builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
|
|
87
|
-
builder.withContractStorageRead(...contractStorageReads);
|
|
88
33
|
builder.withReturnValues(...returnValues);
|
|
89
34
|
if (revertReason) {
|
|
90
35
|
builder.withReverted(revertReason);
|
|
@@ -93,21 +38,6 @@ export class PublicExecutionResultBuilder {
|
|
|
93
38
|
return builder;
|
|
94
39
|
}
|
|
95
40
|
|
|
96
|
-
withNestedExecutions(...nested: PublicExecutionResult[]): PublicExecutionResultBuilder {
|
|
97
|
-
this._nestedExecutions.push(...nested);
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
withContractStorageUpdateRequest(...request: ContractStorageUpdateRequest[]): PublicExecutionResultBuilder {
|
|
102
|
-
this._contractStorageUpdateRequests.push(...request);
|
|
103
|
-
return this;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
withContractStorageRead(...reads: ContractStorageRead[]): PublicExecutionResultBuilder {
|
|
107
|
-
this._contractStorageReads.push(...reads);
|
|
108
|
-
return this;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
41
|
withReturnValues(...values: Fr[]): PublicExecutionResultBuilder {
|
|
112
42
|
this._returnValues.push(...values);
|
|
113
43
|
return this;
|
|
@@ -119,34 +49,13 @@ export class PublicExecutionResultBuilder {
|
|
|
119
49
|
return this;
|
|
120
50
|
}
|
|
121
51
|
|
|
122
|
-
build(overrides: Partial<
|
|
52
|
+
build(overrides: Partial<EnqueuedPublicCallExecutionResult> = {}): EnqueuedPublicCallExecutionResult {
|
|
123
53
|
return {
|
|
124
|
-
|
|
125
|
-
nestedExecutions: this._nestedExecutions,
|
|
126
|
-
publicCallRequests: this._nestedExecutions.map(resultToPublicCallRequest),
|
|
127
|
-
noteHashReadRequests: [],
|
|
128
|
-
nullifierReadRequests: [],
|
|
129
|
-
nullifierNonExistentReadRequests: [],
|
|
130
|
-
l1ToL2MsgReadRequests: [],
|
|
131
|
-
contractStorageUpdateRequests: this._contractStorageUpdateRequests,
|
|
132
|
-
returnValues: padArrayEnd(this._returnValues, Fr.ZERO, 4), // TODO(#5450) Need to use the proper return values here
|
|
133
|
-
noteHashes: [],
|
|
134
|
-
nullifiers: [],
|
|
135
|
-
l2ToL1Messages: [],
|
|
136
|
-
contractStorageReads: [],
|
|
137
|
-
unencryptedLogsHashes: [],
|
|
138
|
-
unencryptedLogs: UnencryptedFunctionL2Logs.empty(),
|
|
139
|
-
allUnencryptedLogs: UnencryptedFunctionL2Logs.empty(),
|
|
140
|
-
startSideEffectCounter: Fr.ZERO,
|
|
54
|
+
endGasLeft: Gas.empty(),
|
|
141
55
|
endSideEffectCounter: Fr.ZERO,
|
|
56
|
+
returnValues: padArrayEnd(this._returnValues, Fr.ZERO, 4), // TODO(#5450) Need to use the proper return values here
|
|
142
57
|
reverted: this._reverted,
|
|
143
58
|
revertReason: this._revertReason,
|
|
144
|
-
startGasLeft: Gas.test(),
|
|
145
|
-
endGasLeft: Gas.test(),
|
|
146
|
-
transactionFee: Fr.ZERO,
|
|
147
|
-
calldata: [],
|
|
148
|
-
avmCircuitHints: AvmExecutionHints.empty(),
|
|
149
|
-
functionName: 'unknown',
|
|
150
59
|
...overrides,
|
|
151
60
|
};
|
|
152
61
|
}
|