@aztec/simulator 0.23.0 → 0.26.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/deserialize.d.ts +5 -0
- package/dest/acvm/deserialize.d.ts.map +1 -1
- package/dest/acvm/deserialize.js +8 -1
- package/dest/acvm/oracle/oracle.d.ts +7 -6
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +28 -15
- package/dest/acvm/oracle/typed_oracle.d.ts +9 -11
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +11 -11
- package/dest/avm/avm_context.d.ts +4 -4
- package/dest/avm/avm_context.d.ts.map +1 -1
- package/dest/avm/avm_context.js +6 -6
- package/dest/avm/avm_execution_environment.d.ts +3 -2
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +6 -5
- package/dest/avm/avm_memory_types.d.ts +127 -37
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +98 -106
- package/dest/avm/avm_simulator.d.ts +6 -4
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +17 -19
- package/dest/avm/errors.d.ts +3 -1
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +9 -3
- package/dest/avm/fixtures/index.d.ts +21 -5
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +28 -9
- package/dest/avm/journal/host_storage.d.ts +1 -1
- package/dest/avm/journal/host_storage.d.ts.map +1 -1
- package/dest/avm/journal/host_storage.js +1 -1
- package/dest/avm/journal/journal.d.ts +78 -50
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +125 -169
- package/dest/avm/journal/nullifiers.d.ts +85 -0
- package/dest/avm/journal/nullifiers.d.ts.map +1 -0
- package/dest/avm/journal/nullifiers.js +147 -0
- package/dest/avm/journal/public_storage.d.ts +88 -0
- package/dest/avm/journal/public_storage.d.ts.map +1 -0
- package/dest/avm/journal/public_storage.js +135 -0
- package/dest/avm/journal/trace.d.ts +43 -0
- package/dest/avm/journal/trace.d.ts.map +1 -0
- package/dest/avm/journal/trace.js +204 -0
- package/dest/avm/journal/trace_types.d.ts +26 -0
- package/dest/avm/journal/trace_types.d.ts.map +1 -0
- package/dest/avm/journal/trace_types.js +6 -0
- package/dest/avm/opcodes/accrued_substate.d.ts +37 -4
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +109 -12
- package/dest/avm/opcodes/addressing_mode.d.ts +24 -0
- package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -0
- package/dest/avm/opcodes/addressing_mode.js +62 -0
- package/dest/avm/opcodes/environment_getters.d.ts +14 -13
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +1 -1
- package/dest/avm/opcodes/external_calls.js +5 -5
- package/dest/avm/opcodes/hashing.d.ts +48 -0
- package/dest/avm/opcodes/hashing.d.ts.map +1 -0
- package/dest/avm/opcodes/hashing.js +127 -0
- package/dest/avm/opcodes/instruction.d.ts +4 -4
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +1 -1
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +5 -3
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +3 -3
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +28 -22
- package/dest/avm/serialization/instruction_serialization.d.ts +21 -16
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +23 -18
- package/dest/avm/temporary_executor_migration.d.ts +25 -0
- package/dest/avm/temporary_executor_migration.d.ts.map +1 -0
- package/dest/avm/temporary_executor_migration.js +71 -0
- package/dest/client/client_execution_context.d.ts +13 -7
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +52 -27
- package/dest/client/db_oracle.d.ts +7 -0
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/execution_note_cache.js +1 -1
- package/dest/client/execution_result.d.ts +4 -2
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +1 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +4 -4
- package/dest/client/simulator.d.ts +11 -6
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +21 -12
- package/dest/client/unconstrained_execution.js +2 -2
- package/dest/client/view_data_oracle.d.ts +9 -2
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +13 -5
- package/dest/public/db.d.ts +17 -4
- package/dest/public/db.d.ts.map +1 -1
- package/dest/public/execution.d.ts +9 -4
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +18 -5
- package/dest/public/executor.d.ts +7 -0
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +40 -6
- package/dest/public/public_execution_context.d.ts +5 -4
- package/dest/public/public_execution_context.d.ts.map +1 -1
- package/dest/public/public_execution_context.js +24 -13
- package/dest/public/state_actions.d.ts +1 -1
- package/dest/public/state_actions.d.ts.map +1 -1
- package/dest/public/state_actions.js +6 -7
- package/dest/test/utils.js +4 -4
- package/dest/utils.d.ts +5 -20
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +4 -21
- package/package.json +9 -6
- package/src/acvm/acvm.ts +156 -0
- package/src/acvm/acvm_types.ts +11 -0
- package/src/acvm/deserialize.ts +44 -0
- package/src/acvm/index.ts +5 -0
- package/src/acvm/oracle/debug.ts +109 -0
- package/src/acvm/oracle/index.ts +17 -0
- package/src/acvm/oracle/oracle.ts +356 -0
- package/src/acvm/oracle/typed_oracle.ts +225 -0
- package/src/acvm/serialize.ts +75 -0
- package/src/avm/avm_context.ts +63 -0
- package/src/avm/avm_execution_environment.ts +98 -0
- package/src/avm/avm_machine_state.ts +93 -0
- package/src/avm/avm_memory_types.ts +324 -0
- package/src/avm/avm_message_call_result.ts +29 -0
- package/src/avm/avm_simulator.ts +87 -0
- package/src/avm/errors.ts +57 -0
- package/src/avm/fixtures/index.ts +115 -0
- package/src/avm/journal/host_storage.ts +14 -0
- package/src/avm/journal/index.ts +2 -0
- package/src/avm/journal/journal.ts +231 -0
- package/src/avm/journal/nullifiers.ts +170 -0
- package/src/avm/journal/public_storage.ts +149 -0
- package/src/avm/journal/trace.ts +223 -0
- package/src/avm/journal/trace_types.ts +79 -0
- package/src/avm/opcodes/.eslintrc.cjs +8 -0
- package/src/avm/opcodes/accrued_substate.ts +214 -0
- package/src/avm/opcodes/addressing_mode.ts +66 -0
- package/src/avm/opcodes/arithmetic.ts +79 -0
- package/src/avm/opcodes/bitwise.ts +129 -0
- package/src/avm/opcodes/comparators.ts +69 -0
- package/src/avm/opcodes/control_flow.ts +129 -0
- package/src/avm/opcodes/environment_getters.ts +201 -0
- package/src/avm/opcodes/external_calls.ts +122 -0
- package/src/avm/opcodes/hashing.ts +170 -0
- package/src/avm/opcodes/index.ts +10 -0
- package/src/avm/opcodes/instruction.ts +64 -0
- package/src/avm/opcodes/instruction_impl.ts +52 -0
- package/src/avm/opcodes/memory.ts +194 -0
- package/src/avm/opcodes/storage.ts +79 -0
- package/src/avm/serialization/buffer_cursor.ts +109 -0
- package/src/avm/serialization/bytecode_serialization.ts +179 -0
- package/src/avm/serialization/instruction_serialization.ts +170 -0
- package/src/avm/temporary_executor_migration.ts +109 -0
- package/src/client/client_execution_context.ts +502 -0
- package/src/client/db_oracle.ts +192 -0
- package/src/client/execution_note_cache.ts +90 -0
- package/src/client/execution_result.ts +89 -0
- package/src/client/index.ts +3 -0
- package/src/client/pick_notes.ts +125 -0
- package/src/client/private_execution.ts +79 -0
- package/src/client/simulator.ts +317 -0
- package/src/client/unconstrained_execution.ts +49 -0
- package/src/client/view_data_oracle.ts +253 -0
- package/src/common/errors.ts +61 -0
- package/src/common/index.ts +3 -0
- package/src/common/packed_args_cache.ts +55 -0
- package/src/common/side_effect_counter.ts +12 -0
- package/src/index.ts +3 -0
- package/src/public/db.ts +100 -0
- package/src/public/execution.ts +161 -0
- package/src/public/executor.ts +178 -0
- package/src/public/index.ts +9 -0
- package/src/public/public_execution_context.ts +241 -0
- package/src/public/state_actions.ts +100 -0
- package/src/test/utils.ts +38 -0
- package/src/utils.ts +18 -0
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthWitness,
|
|
3
|
+
AztecNode,
|
|
4
|
+
FunctionL2Logs,
|
|
5
|
+
L1NotePayload,
|
|
6
|
+
Note,
|
|
7
|
+
NoteStatus,
|
|
8
|
+
TaggedNote,
|
|
9
|
+
UnencryptedL2Log,
|
|
10
|
+
} from '@aztec/circuit-types';
|
|
11
|
+
import {
|
|
12
|
+
CallContext,
|
|
13
|
+
ContractDeploymentData,
|
|
14
|
+
FunctionData,
|
|
15
|
+
FunctionSelector,
|
|
16
|
+
Header,
|
|
17
|
+
NoteHashReadRequestMembershipWitness,
|
|
18
|
+
PublicCallRequest,
|
|
19
|
+
SideEffect,
|
|
20
|
+
TxContext,
|
|
21
|
+
} from '@aztec/circuits.js';
|
|
22
|
+
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
23
|
+
import { computePublicDataTreeLeafSlot, computeUniqueCommitment, siloNoteHash } from '@aztec/circuits.js/hash';
|
|
24
|
+
import { FunctionAbi, FunctionArtifact, countArgumentsSize } from '@aztec/foundation/abi';
|
|
25
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
26
|
+
import { Fr, Point } from '@aztec/foundation/fields';
|
|
27
|
+
import { createDebugLogger } from '@aztec/foundation/log';
|
|
28
|
+
|
|
29
|
+
import { NoteData, toACVMWitness } from '../acvm/index.js';
|
|
30
|
+
import { PackedArgsCache } from '../common/packed_args_cache.js';
|
|
31
|
+
import { DBOracle } from './db_oracle.js';
|
|
32
|
+
import { ExecutionNoteCache } from './execution_note_cache.js';
|
|
33
|
+
import { ExecutionResult, NoteAndSlot } from './execution_result.js';
|
|
34
|
+
import { pickNotes } from './pick_notes.js';
|
|
35
|
+
import { executePrivateFunction } from './private_execution.js';
|
|
36
|
+
import { ViewDataOracle } from './view_data_oracle.js';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The execution context for a client tx simulation.
|
|
40
|
+
*/
|
|
41
|
+
export class ClientExecutionContext extends ViewDataOracle {
|
|
42
|
+
/**
|
|
43
|
+
* New notes created during this execution.
|
|
44
|
+
* It's possible that a note in this list has been nullified (in the same or other executions) and doesn't exist in the ExecutionNoteCache and the final proof data.
|
|
45
|
+
* But we still include those notes in the execution result because their commitments are still in the public inputs of this execution.
|
|
46
|
+
* This information is only for references (currently used for tests), and is not used for any sort of constrains.
|
|
47
|
+
* Users can also use this to get a clearer idea of what's happened during a simulation.
|
|
48
|
+
*/
|
|
49
|
+
private newNotes: NoteAndSlot[] = [];
|
|
50
|
+
/**
|
|
51
|
+
* Notes from previous transactions that are returned to the oracle call `getNotes` during this execution.
|
|
52
|
+
* The mapping maps from the unique siloed note hash to the index for notes created in private executions.
|
|
53
|
+
* It maps from siloed note hash to the index for notes created by public functions.
|
|
54
|
+
*
|
|
55
|
+
* They are not part of the ExecutionNoteCache and being forwarded to nested contexts via `extend()`
|
|
56
|
+
* because these notes are meant to be maintained on a per-call basis
|
|
57
|
+
* They should act as references for the read requests output by an app circuit via public inputs.
|
|
58
|
+
*/
|
|
59
|
+
private gotNotes: Map<bigint, bigint> = new Map();
|
|
60
|
+
private encryptedLogs: Buffer[] = [];
|
|
61
|
+
private unencryptedLogs: UnencryptedL2Log[] = [];
|
|
62
|
+
private nestedExecutions: ExecutionResult[] = [];
|
|
63
|
+
private enqueuedPublicFunctionCalls: PublicCallRequest[] = [];
|
|
64
|
+
|
|
65
|
+
constructor(
|
|
66
|
+
protected readonly contractAddress: AztecAddress,
|
|
67
|
+
private readonly argsHash: Fr,
|
|
68
|
+
private readonly txContext: TxContext,
|
|
69
|
+
private readonly callContext: CallContext,
|
|
70
|
+
/** Header of a block whose state is used during private execution (not the block the transaction is included in). */
|
|
71
|
+
protected readonly historicalHeader: Header,
|
|
72
|
+
/** List of transient auth witnesses to be used during this simulation */
|
|
73
|
+
protected readonly authWitnesses: AuthWitness[],
|
|
74
|
+
private readonly packedArgsCache: PackedArgsCache,
|
|
75
|
+
private readonly noteCache: ExecutionNoteCache,
|
|
76
|
+
protected readonly db: DBOracle,
|
|
77
|
+
private readonly curve: Grumpkin,
|
|
78
|
+
private node: AztecNode,
|
|
79
|
+
protected log = createDebugLogger('aztec:simulator:client_execution_context'),
|
|
80
|
+
) {
|
|
81
|
+
super(contractAddress, authWitnesses, db, node, log);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// We still need this function until we can get user-defined ordering of structs for fn arguments
|
|
85
|
+
// TODO When that is sorted out on noir side, we can use instead the utilities in serialize.ts
|
|
86
|
+
/**
|
|
87
|
+
* Writes the function inputs to the initial witness.
|
|
88
|
+
* @param abi - The function ABI.
|
|
89
|
+
* @returns The initial witness.
|
|
90
|
+
*/
|
|
91
|
+
public getInitialWitness(abi: FunctionAbi) {
|
|
92
|
+
const contractDeploymentData = this.txContext.contractDeploymentData;
|
|
93
|
+
|
|
94
|
+
const argumentsSize = countArgumentsSize(abi);
|
|
95
|
+
|
|
96
|
+
const args = this.packedArgsCache.unpack(this.argsHash);
|
|
97
|
+
|
|
98
|
+
if (args.length !== argumentsSize) {
|
|
99
|
+
throw new Error('Invalid arguments size');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const fields = [
|
|
103
|
+
...this.callContext.toFields(),
|
|
104
|
+
...this.historicalHeader.toFields(),
|
|
105
|
+
...contractDeploymentData.toFields(),
|
|
106
|
+
|
|
107
|
+
this.txContext.chainId,
|
|
108
|
+
this.txContext.version,
|
|
109
|
+
|
|
110
|
+
...args,
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
return toACVMWitness(0, fields);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* This function will populate readRequestPartialWitnesses which
|
|
118
|
+
* here is just used to flag reads as "transient" for new notes created during this execution
|
|
119
|
+
* or to flag non-transient reads with their leafIndex.
|
|
120
|
+
* The KernelProver will use this to fully populate witnesses and provide hints to
|
|
121
|
+
* the kernel regarding which commitments each transient read request corresponds to.
|
|
122
|
+
* @param noteHashReadRequests - SideEffect containing Note hashed of the notes being read and counter.
|
|
123
|
+
* @returns An array of partially filled in read request membership witnesses.
|
|
124
|
+
*/
|
|
125
|
+
public getNoteHashReadRequestPartialWitnesses(noteHashReadRequests: SideEffect[]) {
|
|
126
|
+
return noteHashReadRequests
|
|
127
|
+
.filter(r => !r.isEmpty())
|
|
128
|
+
.map(r => {
|
|
129
|
+
const index = this.gotNotes.get(r.value.toBigInt());
|
|
130
|
+
return index !== undefined
|
|
131
|
+
? NoteHashReadRequestMembershipWitness.empty(index)
|
|
132
|
+
: NoteHashReadRequestMembershipWitness.emptyTransient();
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get the data for the newly created notes.
|
|
138
|
+
* @param innerNoteHashes - Inner note hashes for the notes.
|
|
139
|
+
*/
|
|
140
|
+
public getNewNotes(): NoteAndSlot[] {
|
|
141
|
+
return this.newNotes;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Return the encrypted logs emitted during this execution.
|
|
146
|
+
*/
|
|
147
|
+
public getEncryptedLogs() {
|
|
148
|
+
return new FunctionL2Logs(this.encryptedLogs);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Return the encrypted logs emitted during this execution.
|
|
153
|
+
*/
|
|
154
|
+
public getUnencryptedLogs() {
|
|
155
|
+
return new FunctionL2Logs(this.unencryptedLogs.map(log => log.toBuffer()));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Return the nested execution results during this execution.
|
|
160
|
+
*/
|
|
161
|
+
public getNestedExecutions() {
|
|
162
|
+
return this.nestedExecutions;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Return the enqueued public function calls during this execution.
|
|
167
|
+
*/
|
|
168
|
+
public getEnqueuedPublicFunctionCalls() {
|
|
169
|
+
return this.enqueuedPublicFunctionCalls;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Pack the given arguments.
|
|
174
|
+
* @param args - Arguments to pack
|
|
175
|
+
*/
|
|
176
|
+
public packArguments(args: Fr[]): Promise<Fr> {
|
|
177
|
+
return Promise.resolve(this.packedArgsCache.pack(args));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Gets some notes for a storage slot.
|
|
182
|
+
*
|
|
183
|
+
* @remarks
|
|
184
|
+
* Check for pending notes with matching slot.
|
|
185
|
+
* Real notes coming from DB will have a leafIndex which
|
|
186
|
+
* represents their index in the note hash tree.
|
|
187
|
+
*
|
|
188
|
+
* @param storageSlot - The storage slot.
|
|
189
|
+
* @param numSelects - The number of valid selects in selectBy and selectValues.
|
|
190
|
+
* @param selectBy - An array of indices of the fields to selects.
|
|
191
|
+
* @param selectValues - The values to match.
|
|
192
|
+
* @param selectComparators - The comparators to match by.
|
|
193
|
+
* @param sortBy - An array of indices of the fields to sort.
|
|
194
|
+
* @param sortOrder - The order of the corresponding index in sortBy. (1: DESC, 2: ASC, 0: Do nothing)
|
|
195
|
+
* @param limit - The number of notes to retrieve per query.
|
|
196
|
+
* @param offset - The starting index for pagination.
|
|
197
|
+
* @param status - The status of notes to fetch.
|
|
198
|
+
* @returns Array of note data.
|
|
199
|
+
*/
|
|
200
|
+
public async getNotes(
|
|
201
|
+
storageSlot: Fr,
|
|
202
|
+
numSelects: number,
|
|
203
|
+
selectBy: number[],
|
|
204
|
+
selectValues: Fr[],
|
|
205
|
+
selectComparators: number[],
|
|
206
|
+
sortBy: number[],
|
|
207
|
+
sortOrder: number[],
|
|
208
|
+
limit: number,
|
|
209
|
+
offset: number,
|
|
210
|
+
status: NoteStatus,
|
|
211
|
+
): Promise<NoteData[]> {
|
|
212
|
+
// Nullified pending notes are already removed from the list.
|
|
213
|
+
const pendingNotes = this.noteCache.getNotes(this.callContext.storageContractAddress, storageSlot);
|
|
214
|
+
|
|
215
|
+
const pendingNullifiers = this.noteCache.getNullifiers(this.callContext.storageContractAddress);
|
|
216
|
+
const dbNotes = await this.db.getNotes(this.callContext.storageContractAddress, storageSlot, status);
|
|
217
|
+
const dbNotesFiltered = dbNotes.filter(n => !pendingNullifiers.has((n.siloedNullifier as Fr).value));
|
|
218
|
+
|
|
219
|
+
const notes = pickNotes<NoteData>([...dbNotesFiltered, ...pendingNotes], {
|
|
220
|
+
selects: selectBy
|
|
221
|
+
.slice(0, numSelects)
|
|
222
|
+
.map((index, i) => ({ index, value: selectValues[i], comparator: selectComparators[i] })),
|
|
223
|
+
sorts: sortBy.map((index, i) => ({ index, order: sortOrder[i] })),
|
|
224
|
+
limit,
|
|
225
|
+
offset,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
this.log(
|
|
229
|
+
`Returning ${notes.length} notes for ${this.callContext.storageContractAddress} at ${storageSlot}: ${notes
|
|
230
|
+
.map(n => `${n.nonce.toString()}:[${n.note.items.map(i => i.toString()).join(',')}]`)
|
|
231
|
+
.join(', ')}`,
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
notes.forEach(n => {
|
|
235
|
+
if (n.index !== undefined) {
|
|
236
|
+
const siloedNoteHash = siloNoteHash(n.contractAddress, n.innerNoteHash);
|
|
237
|
+
const uniqueSiloedNoteHash = computeUniqueCommitment(n.nonce, siloedNoteHash);
|
|
238
|
+
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386)
|
|
239
|
+
// Should always be uniqueSiloedNoteHash when publicly created notes include nonces.
|
|
240
|
+
const noteHashForReadRequest = n.nonce.isZero() ? siloedNoteHash : uniqueSiloedNoteHash;
|
|
241
|
+
this.gotNotes.set(noteHashForReadRequest.value, n.index);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
return notes;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Keep track of the new note created during execution.
|
|
250
|
+
* It can be used in subsequent calls (or transactions when chaining txs is possible).
|
|
251
|
+
* @param contractAddress - The contract address.
|
|
252
|
+
* @param storageSlot - The storage slot.
|
|
253
|
+
* @param noteTypeId - The type ID of the note.
|
|
254
|
+
* @param noteItems - The items to be included in a Note.
|
|
255
|
+
* @param innerNoteHash - The inner note hash of the new note.
|
|
256
|
+
* @returns
|
|
257
|
+
*/
|
|
258
|
+
public notifyCreatedNote(storageSlot: Fr, noteTypeId: Fr, noteItems: Fr[], innerNoteHash: Fr) {
|
|
259
|
+
const note = new Note(noteItems);
|
|
260
|
+
this.noteCache.addNewNote({
|
|
261
|
+
contractAddress: this.callContext.storageContractAddress,
|
|
262
|
+
storageSlot,
|
|
263
|
+
nonce: Fr.ZERO, // Nonce cannot be known during private execution.
|
|
264
|
+
note,
|
|
265
|
+
siloedNullifier: undefined, // Siloed nullifier cannot be known for newly created note.
|
|
266
|
+
innerNoteHash,
|
|
267
|
+
});
|
|
268
|
+
this.newNotes.push({
|
|
269
|
+
storageSlot,
|
|
270
|
+
noteTypeId,
|
|
271
|
+
note,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Adding a siloed nullifier into the current set of all pending nullifiers created
|
|
277
|
+
* within the current transaction/execution.
|
|
278
|
+
* @param innerNullifier - The pending nullifier to add in the list (not yet siloed by contract address).
|
|
279
|
+
* @param innerNoteHash - The inner note hash of the new note.
|
|
280
|
+
*/
|
|
281
|
+
public notifyNullifiedNote(innerNullifier: Fr, innerNoteHash: Fr) {
|
|
282
|
+
this.noteCache.nullifyNote(this.callContext.storageContractAddress, innerNullifier, innerNoteHash);
|
|
283
|
+
return Promise.resolve();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Encrypt a note and emit it as a log.
|
|
288
|
+
* @param contractAddress - The contract address of the note.
|
|
289
|
+
* @param storageSlot - The storage slot the note is at.
|
|
290
|
+
* @param noteTypeId - The type ID of the note.
|
|
291
|
+
* @param publicKey - The public key of the account that can decrypt the log.
|
|
292
|
+
* @param log - The log contents.
|
|
293
|
+
*/
|
|
294
|
+
public emitEncryptedLog(contractAddress: AztecAddress, storageSlot: Fr, noteTypeId: Fr, publicKey: Point, log: Fr[]) {
|
|
295
|
+
const note = new Note(log);
|
|
296
|
+
const l1NotePayload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId);
|
|
297
|
+
const taggedNote = new TaggedNote(l1NotePayload);
|
|
298
|
+
const encryptedNote = taggedNote.toEncryptedBuffer(publicKey, this.curve);
|
|
299
|
+
this.encryptedLogs.push(encryptedNote);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Emit an unencrypted log.
|
|
304
|
+
* @param log - The unencrypted log to be emitted.
|
|
305
|
+
*/
|
|
306
|
+
public emitUnencryptedLog(log: UnencryptedL2Log) {
|
|
307
|
+
this.unencryptedLogs.push(log);
|
|
308
|
+
const text = log.toHumanReadable();
|
|
309
|
+
this.log(`Emitted unencrypted log: "${text.length > 100 ? text.slice(0, 100) + '...' : text}"`);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
#checkValidStaticCall(childExecutionResult: ExecutionResult) {
|
|
313
|
+
if (
|
|
314
|
+
childExecutionResult.callStackItem.publicInputs.newNoteHashes.some(item => !item.isEmpty()) ||
|
|
315
|
+
childExecutionResult.callStackItem.publicInputs.newNullifiers.some(item => !item.isEmpty()) ||
|
|
316
|
+
childExecutionResult.callStackItem.publicInputs.newL2ToL1Msgs.some(item => !item.isEmpty()) ||
|
|
317
|
+
!childExecutionResult.callStackItem.publicInputs.encryptedLogPreimagesLength.equals(new Fr(4)) ||
|
|
318
|
+
!childExecutionResult.callStackItem.publicInputs.unencryptedLogPreimagesLength.equals(new Fr(4))
|
|
319
|
+
) {
|
|
320
|
+
throw new Error(`Static call cannot create new notes, emit L2->L1 messages or generate logs`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Calls a private function as a nested execution.
|
|
326
|
+
* @param targetContractAddress - The address of the contract to call.
|
|
327
|
+
* @param functionSelector - The function selector of the function to call.
|
|
328
|
+
* @param argsHash - The packed arguments to pass to the function.
|
|
329
|
+
* @param sideEffectCounter - The side effect counter at the start of the call.
|
|
330
|
+
* @param isStaticCall - Whether the call is a static call.
|
|
331
|
+
* @param isStaticCall - Whether the call is a delegate call.
|
|
332
|
+
* @returns The execution result.
|
|
333
|
+
*/
|
|
334
|
+
async callPrivateFunction(
|
|
335
|
+
targetContractAddress: AztecAddress,
|
|
336
|
+
functionSelector: FunctionSelector,
|
|
337
|
+
argsHash: Fr,
|
|
338
|
+
sideEffectCounter: number,
|
|
339
|
+
isStaticCall: boolean,
|
|
340
|
+
isDelegateCall: boolean,
|
|
341
|
+
) {
|
|
342
|
+
this.log(
|
|
343
|
+
`Calling private function ${this.contractAddress}:${functionSelector} from ${this.callContext.storageContractAddress}`,
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
isStaticCall = isStaticCall || this.callContext.isStaticCall;
|
|
347
|
+
|
|
348
|
+
const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
349
|
+
const targetFunctionData = FunctionData.fromAbi(targetArtifact);
|
|
350
|
+
|
|
351
|
+
const derivedTxContext = new TxContext(
|
|
352
|
+
false,
|
|
353
|
+
false,
|
|
354
|
+
false,
|
|
355
|
+
ContractDeploymentData.empty(),
|
|
356
|
+
this.txContext.chainId,
|
|
357
|
+
this.txContext.version,
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
const derivedCallContext = await this.deriveCallContext(
|
|
361
|
+
targetContractAddress,
|
|
362
|
+
targetArtifact,
|
|
363
|
+
sideEffectCounter,
|
|
364
|
+
isDelegateCall,
|
|
365
|
+
isStaticCall,
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
const context = new ClientExecutionContext(
|
|
369
|
+
targetContractAddress,
|
|
370
|
+
argsHash,
|
|
371
|
+
derivedTxContext,
|
|
372
|
+
derivedCallContext,
|
|
373
|
+
this.historicalHeader,
|
|
374
|
+
this.authWitnesses,
|
|
375
|
+
this.packedArgsCache,
|
|
376
|
+
this.noteCache,
|
|
377
|
+
this.db,
|
|
378
|
+
this.curve,
|
|
379
|
+
this.node,
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
const childExecutionResult = await executePrivateFunction(
|
|
383
|
+
context,
|
|
384
|
+
targetArtifact,
|
|
385
|
+
targetContractAddress,
|
|
386
|
+
targetFunctionData,
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
if (isStaticCall) {
|
|
390
|
+
this.#checkValidStaticCall(childExecutionResult);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
this.nestedExecutions.push(childExecutionResult);
|
|
394
|
+
|
|
395
|
+
return childExecutionResult.callStackItem;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Creates a PublicCallStackItem object representing the request to call a public function. No function
|
|
400
|
+
* is actually called, since that must happen on the sequencer side. All the fields related to the result
|
|
401
|
+
* of the execution are empty.
|
|
402
|
+
* @param targetContractAddress - The address of the contract to call.
|
|
403
|
+
* @param functionSelector - The function selector of the function to call.
|
|
404
|
+
* @param argsHash - The packed arguments to pass to the function.
|
|
405
|
+
* @param sideEffectCounter - The side effect counter at the start of the call.
|
|
406
|
+
* @param isStaticCall - Whether the call is a static call.
|
|
407
|
+
* @returns The public call stack item with the request information.
|
|
408
|
+
*/
|
|
409
|
+
public async enqueuePublicFunctionCall(
|
|
410
|
+
targetContractAddress: AztecAddress,
|
|
411
|
+
functionSelector: FunctionSelector,
|
|
412
|
+
argsHash: Fr,
|
|
413
|
+
sideEffectCounter: number,
|
|
414
|
+
isStaticCall: boolean,
|
|
415
|
+
isDelegateCall: boolean,
|
|
416
|
+
): Promise<PublicCallRequest> {
|
|
417
|
+
isStaticCall = isStaticCall || this.callContext.isStaticCall;
|
|
418
|
+
|
|
419
|
+
const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
420
|
+
const derivedCallContext = await this.deriveCallContext(
|
|
421
|
+
targetContractAddress,
|
|
422
|
+
targetArtifact,
|
|
423
|
+
sideEffectCounter,
|
|
424
|
+
isDelegateCall,
|
|
425
|
+
isStaticCall,
|
|
426
|
+
);
|
|
427
|
+
const args = this.packedArgsCache.unpack(argsHash);
|
|
428
|
+
const enqueuedRequest = PublicCallRequest.from({
|
|
429
|
+
args,
|
|
430
|
+
callContext: derivedCallContext,
|
|
431
|
+
parentCallContext: this.callContext,
|
|
432
|
+
functionData: FunctionData.fromAbi(targetArtifact),
|
|
433
|
+
contractAddress: targetContractAddress,
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// TODO($846): if enqueued public calls are associated with global
|
|
437
|
+
// side-effect counter, that will leak info about how many other private
|
|
438
|
+
// side-effects occurred in the TX. Ultimately the private kernel should
|
|
439
|
+
// just output everything in the proper order without any counters.
|
|
440
|
+
this.log(
|
|
441
|
+
`Enqueued call to public function (with side-effect counter #${sideEffectCounter}) ${targetContractAddress}:${functionSelector}(${targetArtifact.name})`,
|
|
442
|
+
);
|
|
443
|
+
|
|
444
|
+
this.enqueuedPublicFunctionCalls.push(enqueuedRequest);
|
|
445
|
+
|
|
446
|
+
return enqueuedRequest;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Derives the call context for a nested execution.
|
|
451
|
+
* @param targetContractAddress - The address of the contract being called.
|
|
452
|
+
* @param targetArtifact - The artifact of the function being called.
|
|
453
|
+
* @param startSideEffectCounter - The side effect counter at the start of the call.
|
|
454
|
+
* @param isDelegateCall - Whether the call is a delegate call.
|
|
455
|
+
* @param isStaticCall - Whether the call is a static call.
|
|
456
|
+
* @returns The derived call context.
|
|
457
|
+
*/
|
|
458
|
+
private async deriveCallContext(
|
|
459
|
+
targetContractAddress: AztecAddress,
|
|
460
|
+
targetArtifact: FunctionArtifact,
|
|
461
|
+
startSideEffectCounter: number,
|
|
462
|
+
isDelegateCall = false,
|
|
463
|
+
isStaticCall = false,
|
|
464
|
+
) {
|
|
465
|
+
const portalContractAddress = await this.db.getPortalContractAddress(targetContractAddress);
|
|
466
|
+
return new CallContext(
|
|
467
|
+
isDelegateCall ? this.callContext.msgSender : this.contractAddress,
|
|
468
|
+
isDelegateCall ? this.contractAddress : targetContractAddress,
|
|
469
|
+
portalContractAddress,
|
|
470
|
+
FunctionSelector.fromNameAndParameters(targetArtifact.name, targetArtifact.parameters),
|
|
471
|
+
isDelegateCall,
|
|
472
|
+
isStaticCall,
|
|
473
|
+
false,
|
|
474
|
+
startSideEffectCounter,
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Read the public storage data.
|
|
480
|
+
* @param startStorageSlot - The starting storage slot.
|
|
481
|
+
* @param numberOfElements - Number of elements to read from the starting storage slot.
|
|
482
|
+
*/
|
|
483
|
+
public async storageRead(startStorageSlot: Fr, numberOfElements: number): Promise<Fr[]> {
|
|
484
|
+
// TODO(#4320): This is a hack to work around not having directly access to the public data tree but
|
|
485
|
+
// still having access to the witnesses
|
|
486
|
+
const bn = await this.db.getBlockNumber();
|
|
487
|
+
|
|
488
|
+
const values = [];
|
|
489
|
+
for (let i = 0n; i < numberOfElements; i++) {
|
|
490
|
+
const storageSlot = new Fr(startStorageSlot.value + i);
|
|
491
|
+
const leafSlot = computePublicDataTreeLeafSlot(this.callContext.storageContractAddress, storageSlot);
|
|
492
|
+
const witness = await this.db.getPublicDataTreeWitness(bn, leafSlot);
|
|
493
|
+
if (!witness) {
|
|
494
|
+
throw new Error(`No witness for slot ${storageSlot.toString()}`);
|
|
495
|
+
}
|
|
496
|
+
const value = witness.leafPreimage.value;
|
|
497
|
+
this.log(`Oracle storage read: slot=${storageSlot.toString()} value=${value}`);
|
|
498
|
+
values.push(value);
|
|
499
|
+
}
|
|
500
|
+
return values;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { L2Block, MerkleTreeId, NoteStatus, NullifierMembershipWitness, PublicDataWitness } from '@aztec/circuit-types';
|
|
2
|
+
import { CompleteAddress, Header } from '@aztec/circuits.js';
|
|
3
|
+
import { FunctionArtifactWithDebugMetadata, FunctionSelector } from '@aztec/foundation/abi';
|
|
4
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
5
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
7
|
+
import { ContractInstance } from '@aztec/types/contracts';
|
|
8
|
+
|
|
9
|
+
import { KeyPair, NoteData } from '../acvm/index.js';
|
|
10
|
+
import { CommitmentsDB } from '../public/db.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Error thrown when a contract is not found in the database.
|
|
14
|
+
*/
|
|
15
|
+
export class ContractNotFoundError extends Error {
|
|
16
|
+
constructor(contractAddress: string) {
|
|
17
|
+
super(`DB has no contract with address ${contractAddress}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Error thrown when a contract class is not found in the database.
|
|
23
|
+
*/
|
|
24
|
+
export class ContractClassNotFoundError extends Error {
|
|
25
|
+
constructor(contractClassId: string) {
|
|
26
|
+
super(`DB has no contract class with id ${contractClassId}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The database oracle interface.
|
|
32
|
+
*/
|
|
33
|
+
export interface DBOracle extends CommitmentsDB {
|
|
34
|
+
/**
|
|
35
|
+
* Returns a contract instance associated with an address, if available.
|
|
36
|
+
* @param address - Address.
|
|
37
|
+
* @returns A contract instance.
|
|
38
|
+
*/
|
|
39
|
+
getContractInstance(address: AztecAddress): Promise<ContractInstance>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Retrieve the complete address associated to a given address.
|
|
43
|
+
* @param address - Address to fetch the pubkey for.
|
|
44
|
+
* @returns A complete address associated with the input address.
|
|
45
|
+
*/
|
|
46
|
+
getCompleteAddress(address: AztecAddress): Promise<CompleteAddress>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Retrieve the auth witness for a given message hash.
|
|
50
|
+
* @param messageHash - The message hash.
|
|
51
|
+
* @returns A Promise that resolves to an array of field elements representing the auth witness.
|
|
52
|
+
*/
|
|
53
|
+
getAuthWitness(messageHash: Fr): Promise<Fr[]>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Retrieve a capsule from the capsule dispenser.
|
|
57
|
+
* @returns A promise that resolves to an array of field elements representing the capsule.
|
|
58
|
+
* @remarks A capsule is a "blob" of data that is passed to the contract through an oracle.
|
|
59
|
+
*/
|
|
60
|
+
popCapsule(): Promise<Fr[]>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Retrieve the nullifier key pair associated with a specific account.
|
|
64
|
+
* The function only allows access to the secret keys of the transaction creator,
|
|
65
|
+
* and throws an error if the address does not match the account address of the key pair.
|
|
66
|
+
*
|
|
67
|
+
* @param accountAddress - The account address.
|
|
68
|
+
* @param contractAddress - The contract address.
|
|
69
|
+
* @returns A Promise that resolves to the nullifier key pair.
|
|
70
|
+
* @throws An Error if the input address does not match the account address of the key pair.
|
|
71
|
+
*/
|
|
72
|
+
getNullifierKeyPair(accountAddress: AztecAddress, contractAddress: AztecAddress): Promise<KeyPair>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Retrieves a set of notes stored in the database for a given contract address and storage slot.
|
|
76
|
+
* The query result is paginated using 'limit' and 'offset' values.
|
|
77
|
+
* Returns an object containing an array of note data.
|
|
78
|
+
*
|
|
79
|
+
* @param contractAddress - The AztecAddress instance representing the contract address.
|
|
80
|
+
* @param storageSlot - The Fr instance representing the storage slot of the notes.
|
|
81
|
+
* @param status - The status of notes to fetch.
|
|
82
|
+
* @returns A Promise that resolves to an array of note data.
|
|
83
|
+
*/
|
|
84
|
+
getNotes(contractAddress: AztecAddress, storageSlot: Fr, status: NoteStatus): Promise<NoteData[]>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Retrieve the artifact information of a specific function within a contract.
|
|
88
|
+
* The function is identified by its selector, which is a unique identifier generated from the function signature.
|
|
89
|
+
*
|
|
90
|
+
* @param contractAddress - The contract address.
|
|
91
|
+
* @param selector - The corresponding function selector.
|
|
92
|
+
* @returns A Promise that resolves to a FunctionArtifact object.
|
|
93
|
+
*/
|
|
94
|
+
getFunctionArtifact(
|
|
95
|
+
contractAddress: AztecAddress,
|
|
96
|
+
selector: FunctionSelector,
|
|
97
|
+
): Promise<FunctionArtifactWithDebugMetadata>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Retrieves the artifact of a specified function within a given contract.
|
|
101
|
+
* The function is identified by its name, which is unique within a contract.
|
|
102
|
+
*
|
|
103
|
+
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
104
|
+
* @param functionName - The name of the function.
|
|
105
|
+
* @returns The corresponding function's artifact as an object.
|
|
106
|
+
*/
|
|
107
|
+
getFunctionArtifactByName(
|
|
108
|
+
contractAddress: AztecAddress,
|
|
109
|
+
functionName: string,
|
|
110
|
+
): Promise<FunctionArtifactWithDebugMetadata | undefined>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves the portal contract address associated with the given contract address.
|
|
114
|
+
* Throws an error if the input contract address is not found or invalid.
|
|
115
|
+
*
|
|
116
|
+
* @param contractAddress - The address of the contract whose portal address is to be fetched.
|
|
117
|
+
* @returns A Promise that resolves to an EthAddress instance, representing the portal contract address.
|
|
118
|
+
*/
|
|
119
|
+
getPortalContractAddress(contractAddress: AztecAddress): Promise<EthAddress>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Gets the index of a nullifier in the nullifier tree.
|
|
123
|
+
* @param nullifier - The nullifier.
|
|
124
|
+
* @returns - The index of the nullifier. Undefined if it does not exist in the tree.
|
|
125
|
+
*/
|
|
126
|
+
getNullifierIndex(nullifier: Fr): Promise<bigint | undefined>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Retrieve the databases view of the Block Header object.
|
|
130
|
+
* This structure is fed into the circuits simulator and is used to prove against certain historical roots.
|
|
131
|
+
*
|
|
132
|
+
* @returns A Promise that resolves to a Header object.
|
|
133
|
+
*/
|
|
134
|
+
getHeader(): Promise<Header>;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Fetch the index of the leaf in the respective tree
|
|
138
|
+
* @param blockNumber - The block number at which to get the leaf index.
|
|
139
|
+
* @param treeId - The id of the tree to search.
|
|
140
|
+
* @param leafValue - The leaf value buffer.
|
|
141
|
+
* @returns - The index of the leaf. Undefined if it does not exist in the tree.
|
|
142
|
+
*/
|
|
143
|
+
findLeafIndex(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined>;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Fetch the sibling path of the leaf in the respective tree
|
|
147
|
+
* @param blockNumber - The block number at which to get the sibling path.
|
|
148
|
+
* @param treeId - The id of the tree to search.
|
|
149
|
+
* @param leafIndex - The index of the leaf.
|
|
150
|
+
* @returns - The sibling path of the leaf.
|
|
151
|
+
*/
|
|
152
|
+
getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: bigint): Promise<Fr[]>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
156
|
+
* @param blockNumber - The block number at which to get the index.
|
|
157
|
+
* @param nullifier - Nullifier we try to find witness for.
|
|
158
|
+
* @returns The nullifier membership witness (if found).
|
|
159
|
+
*/
|
|
160
|
+
getNullifierMembershipWitness(blockNumber: number, nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
164
|
+
* @param blockNumber - The block number at which to get the index.
|
|
165
|
+
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
166
|
+
* @returns The low nullifier membership witness (if found).
|
|
167
|
+
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
168
|
+
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
169
|
+
* we are trying to prove non-inclusion for.
|
|
170
|
+
*/
|
|
171
|
+
getLowNullifierMembershipWitness(blockNumber: number, nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Returns a witness for a given slot of the public data tree at a given block.
|
|
175
|
+
* @param blockNumber - The block number at which to get the witness.
|
|
176
|
+
* @param leafSlot - The slot of the public data in the public data tree.
|
|
177
|
+
*/
|
|
178
|
+
getPublicDataTreeWitness(blockNumber: number, leafSlot: Fr): Promise<PublicDataWitness | undefined>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Fetch a block corresponding to the given block number.
|
|
182
|
+
* @param blockNumber - The block number of a block to fetch.
|
|
183
|
+
* @returns - The block corresponding to the given block number. Undefined if it does not exist.
|
|
184
|
+
*/
|
|
185
|
+
getBlock(blockNumber: number): Promise<L2Block | undefined>;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Fetches the current block number.
|
|
189
|
+
* @returns The block number.
|
|
190
|
+
*/
|
|
191
|
+
getBlockNumber(): Promise<number>;
|
|
192
|
+
}
|