@aztec/pxe 0.87.4 → 0.87.6
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/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +37 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -0
- package/dest/contract_function_simulator/contract_function_simulator.js +117 -0
- package/dest/contract_function_simulator/execution_data_provider.d.ts +301 -0
- package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -0
- package/dest/contract_function_simulator/execution_data_provider.js +14 -0
- package/dest/contract_function_simulator/execution_note_cache.d.ts +93 -0
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/execution_note_cache.js +180 -0
- package/dest/contract_function_simulator/hashed_values_cache.d.ts +28 -0
- package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/hashed_values_cache.js +36 -0
- package/dest/contract_function_simulator/index.d.ts +10 -0
- package/dest/contract_function_simulator/index.d.ts.map +1 -0
- package/dest/contract_function_simulator/index.js +8 -0
- package/dest/contract_function_simulator/oracle/index.d.ts +14 -0
- package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/index.js +2 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +19 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +24 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +53 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/oracle.js +317 -0
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +24 -0
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/private_execution.js +100 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +187 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +325 -0
- package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +83 -0
- package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/typed_oracle.js +138 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +163 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +257 -0
- package/dest/contract_function_simulator/pick_notes.d.ts +85 -0
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -0
- package/dest/contract_function_simulator/pick_notes.js +51 -0
- package/dest/contract_function_simulator/proxied_node.d.ts +9 -0
- package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -0
- package/dest/contract_function_simulator/proxied_node.js +27 -0
- package/dest/{pxe_oracle_interface → contract_function_simulator}/pxe_oracle_interface.d.ts +5 -4
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -0
- package/dest/{pxe_oracle_interface → contract_function_simulator}/pxe_oracle_interface.js +16 -15
- package/dest/contract_function_simulator/tagging_utils.d.ts.map +1 -0
- package/dest/entrypoints/client/bundle/index.d.ts +1 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +1 -1
- package/dest/entrypoints/client/bundle/utils.js +3 -3
- package/dest/entrypoints/client/lazy/index.d.ts +1 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +1 -1
- package/dest/entrypoints/client/lazy/utils.js +3 -3
- package/dest/entrypoints/server/index.d.ts +1 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -1
- package/dest/entrypoints/server/utils.d.ts +4 -4
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +12 -12
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +4 -4
- package/dest/pxe_service/pxe_service.d.ts +2 -2
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +46 -21
- package/dest/storage/note_data_provider/note_dao.d.ts +1 -1
- package/dest/storage/note_data_provider/note_dao.d.ts.map +1 -1
- package/package.json +17 -15
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +193 -0
- package/src/contract_function_simulator/execution_data_provider.ts +391 -0
- package/src/contract_function_simulator/execution_note_cache.ts +217 -0
- package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
- package/src/contract_function_simulator/index.ts +9 -0
- package/src/contract_function_simulator/oracle/index.ts +16 -0
- package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +23 -0
- package/src/contract_function_simulator/oracle/oracle.ts +541 -0
- package/src/contract_function_simulator/oracle/private_execution.ts +171 -0
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +518 -0
- package/src/contract_function_simulator/oracle/typed_oracle.ts +273 -0
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +384 -0
- package/src/contract_function_simulator/pick_notes.ts +141 -0
- package/src/contract_function_simulator/proxied_node.ts +33 -0
- package/src/{pxe_oracle_interface → contract_function_simulator}/pxe_oracle_interface.ts +18 -21
- package/src/entrypoints/client/bundle/index.ts +1 -1
- package/src/entrypoints/client/bundle/utils.ts +3 -3
- package/src/entrypoints/client/lazy/index.ts +1 -1
- package/src/entrypoints/client/lazy/utils.ts +3 -3
- package/src/entrypoints/server/index.ts +1 -1
- package/src/entrypoints/server/utils.ts +14 -14
- package/src/private_kernel/private_kernel_execution_prover.ts +5 -4
- package/src/pxe_service/pxe_service.ts +75 -39
- package/src/storage/note_data_provider/note_dao.ts +2 -1
- package/dest/pxe_oracle_interface/pxe_oracle_interface.d.ts.map +0 -1
- package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +0 -1
- /package/dest/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.d.ts +0 -0
- /package/dest/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.js +0 -0
- /package/src/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.ts +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { SiblingPath } from '@aztec/foundation/trees';
|
|
3
|
+
|
|
4
|
+
export class MessageLoadOracleInputs<N extends number> {
|
|
5
|
+
constructor(
|
|
6
|
+
/** The index of the message commitment in the merkle tree. */
|
|
7
|
+
public index: bigint,
|
|
8
|
+
/** The path in the merkle tree to the message. */
|
|
9
|
+
public siblingPath: SiblingPath<N>,
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
toFields(): Fr[] {
|
|
13
|
+
return [new Fr(this.index), ...this.siblingPath.toFields()];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns a representation of the public data witness as expected by intrinsic Noir deserialization.
|
|
18
|
+
*/
|
|
19
|
+
public toNoirRepresentation(): (string | string[])[] {
|
|
20
|
+
// TODO(#12874): remove the stupid as string conversion by modifying ForeignCallOutput type in acvm.js
|
|
21
|
+
return [new Fr(this.index).toString() as string, this.siblingPath.toFields().map(fr => fr.toString()) as string[]];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
import { Fr, Point } from '@aztec/foundation/fields';
|
|
2
|
+
import {
|
|
3
|
+
type ACIRCallback,
|
|
4
|
+
type ACVMField,
|
|
5
|
+
arrayOfArraysToBoundedVecOfArrays,
|
|
6
|
+
bufferToBoundedVec,
|
|
7
|
+
fromBoundedVec,
|
|
8
|
+
fromUintArray,
|
|
9
|
+
fromUintBoundedVec,
|
|
10
|
+
toACVMField,
|
|
11
|
+
toACVMFieldSingleOrArray,
|
|
12
|
+
} from '@aztec/simulator/client';
|
|
13
|
+
import { EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
14
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
+
import { ContractClassLog, ContractClassLogFields, LogWithTxData } from '@aztec/stdlib/logs';
|
|
16
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
17
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
18
|
+
|
|
19
|
+
import type { TypedOracle } from './typed_oracle.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A data source that has all the apis required by Aztec.nr.
|
|
23
|
+
*/
|
|
24
|
+
export class Oracle {
|
|
25
|
+
private typedOracle: TypedOracle;
|
|
26
|
+
|
|
27
|
+
constructor(typedOracle: TypedOracle) {
|
|
28
|
+
this.typedOracle = typedOracle;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
toACIRCallback(): ACIRCallback {
|
|
32
|
+
return Object.getOwnPropertyNames(Oracle.prototype)
|
|
33
|
+
.filter(
|
|
34
|
+
name => name !== 'constructor' && name != 'toACIRCallback' && typeof this[name as keyof Oracle] === 'function',
|
|
35
|
+
)
|
|
36
|
+
.reduce((acc, name) => {
|
|
37
|
+
acc[name] = this[name as keyof Omit<Oracle, 'toACIRCallback' | 'typedOracle' | 'constructor'>].bind(this);
|
|
38
|
+
return acc;
|
|
39
|
+
}, {} as ACIRCallback);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getRandomField(): Promise<ACVMField[]> {
|
|
43
|
+
const val = this.typedOracle.getRandomField();
|
|
44
|
+
return Promise.resolve([toACVMField(val)]);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Since the argument is a slice, noir automatically adds a length field to oracle call.
|
|
48
|
+
storeInExecutionCache(_length: ACVMField[], values: ACVMField[], [hash]: ACVMField[]): Promise<ACVMField[]> {
|
|
49
|
+
this.typedOracle.storeInExecutionCache(values.map(Fr.fromString), Fr.fromString(hash));
|
|
50
|
+
return Promise.resolve([]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async loadFromExecutionCache([returnsHash]: ACVMField[]): Promise<ACVMField[][]> {
|
|
54
|
+
const values = await this.typedOracle.loadFromExecutionCache(Fr.fromString(returnsHash));
|
|
55
|
+
return [values.map(toACVMField)];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async getBlockNumber(): Promise<ACVMField[]> {
|
|
59
|
+
return [toACVMField(await this.typedOracle.getBlockNumber())];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async getContractAddress(): Promise<ACVMField[]> {
|
|
63
|
+
return [toACVMField(await this.typedOracle.getContractAddress())];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async getVersion(): Promise<ACVMField[]> {
|
|
67
|
+
return [toACVMField(await this.typedOracle.getVersion())];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async getChainId(): Promise<ACVMField[]> {
|
|
71
|
+
return [toACVMField(await this.typedOracle.getChainId())];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async getKeyValidationRequest([pkMHash]: ACVMField[]): Promise<ACVMField[]> {
|
|
75
|
+
const keyValidationRequest = await this.typedOracle.getKeyValidationRequest(Fr.fromString(pkMHash));
|
|
76
|
+
|
|
77
|
+
return keyValidationRequest.toFields().map(toACVMField);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async getContractInstance([address]: ACVMField[]): Promise<ACVMField[]> {
|
|
81
|
+
const instance = await this.typedOracle.getContractInstance(AztecAddress.fromField(Fr.fromString(address)));
|
|
82
|
+
|
|
83
|
+
return [
|
|
84
|
+
instance.salt,
|
|
85
|
+
instance.deployer,
|
|
86
|
+
instance.currentContractClassId,
|
|
87
|
+
instance.initializationHash,
|
|
88
|
+
...instance.publicKeys.toFields(),
|
|
89
|
+
].map(toACVMField);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async getMembershipWitness(
|
|
93
|
+
[blockNumber]: ACVMField[],
|
|
94
|
+
[treeId]: ACVMField[],
|
|
95
|
+
[leafValue]: ACVMField[],
|
|
96
|
+
): Promise<(ACVMField | ACVMField[])[]> {
|
|
97
|
+
const parsedBlockNumber = Fr.fromString(blockNumber).toNumber();
|
|
98
|
+
const parsedTreeId = Fr.fromString(treeId).toNumber();
|
|
99
|
+
const parsedLeafValue = Fr.fromString(leafValue);
|
|
100
|
+
|
|
101
|
+
const witness = await this.typedOracle.getMembershipWitness(parsedBlockNumber, parsedTreeId, parsedLeafValue);
|
|
102
|
+
if (!witness) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Leaf ${leafValue} not found in the tree ${MerkleTreeId[parsedTreeId]} at block ${parsedBlockNumber}.`,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return [toACVMField(witness[0]), witness.slice(1).map(toACVMField)];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async getNullifierMembershipWitness(
|
|
111
|
+
[blockNumber]: ACVMField[],
|
|
112
|
+
[nullifier]: ACVMField[], // nullifier, we try to find the witness for (to prove inclusion)
|
|
113
|
+
): Promise<(ACVMField | ACVMField[])[]> {
|
|
114
|
+
const parsedBlockNumber = Fr.fromString(blockNumber).toNumber();
|
|
115
|
+
const parsedNullifier = Fr.fromString(nullifier);
|
|
116
|
+
|
|
117
|
+
const witness = await this.typedOracle.getNullifierMembershipWitness(parsedBlockNumber, parsedNullifier);
|
|
118
|
+
if (!witness) {
|
|
119
|
+
throw new Error(`Nullifier witness not found for nullifier ${parsedNullifier} at block ${parsedBlockNumber}.`);
|
|
120
|
+
}
|
|
121
|
+
return witness.toNoirRepresentation();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async getLowNullifierMembershipWitness(
|
|
125
|
+
[blockNumber]: ACVMField[],
|
|
126
|
+
[nullifier]: ACVMField[], // nullifier, we try to find the low nullifier witness for (to prove non-inclusion)
|
|
127
|
+
): Promise<(ACVMField | ACVMField[])[]> {
|
|
128
|
+
const parsedBlockNumber = Fr.fromString(blockNumber).toNumber();
|
|
129
|
+
const parsedNullifier = Fr.fromString(nullifier);
|
|
130
|
+
|
|
131
|
+
const witness = await this.typedOracle.getLowNullifierMembershipWitness(parsedBlockNumber, parsedNullifier);
|
|
132
|
+
if (!witness) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`Low nullifier witness not found for nullifier ${parsedNullifier} at block ${parsedBlockNumber}.`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
return witness.toNoirRepresentation();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async getPublicDataWitness(
|
|
141
|
+
[blockNumber]: ACVMField[],
|
|
142
|
+
[leafSlot]: ACVMField[],
|
|
143
|
+
): Promise<(ACVMField | ACVMField[])[]> {
|
|
144
|
+
const parsedBlockNumber = Fr.fromString(blockNumber).toNumber();
|
|
145
|
+
const parsedLeafSlot = Fr.fromString(leafSlot);
|
|
146
|
+
|
|
147
|
+
const witness = await this.typedOracle.getPublicDataWitness(parsedBlockNumber, parsedLeafSlot);
|
|
148
|
+
if (!witness) {
|
|
149
|
+
throw new Error(`Public data witness not found for slot ${parsedLeafSlot} at block ${parsedBlockNumber}.`);
|
|
150
|
+
}
|
|
151
|
+
return witness.toNoirRepresentation();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async getBlockHeader([blockNumber]: ACVMField[]): Promise<ACVMField[]> {
|
|
155
|
+
const parsedBlockNumber = Fr.fromString(blockNumber).toNumber();
|
|
156
|
+
|
|
157
|
+
const header = await this.typedOracle.getBlockHeader(parsedBlockNumber);
|
|
158
|
+
if (!header) {
|
|
159
|
+
throw new Error(`Block header not found for block ${parsedBlockNumber}.`);
|
|
160
|
+
}
|
|
161
|
+
return header.toFields().map(toACVMField);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async getAuthWitness([messageHash]: ACVMField[]): Promise<ACVMField[][]> {
|
|
165
|
+
const messageHashField = Fr.fromString(messageHash);
|
|
166
|
+
const witness = await this.typedOracle.getAuthWitness(messageHashField);
|
|
167
|
+
if (!witness) {
|
|
168
|
+
throw new Error(`Unknown auth witness for message hash ${messageHashField}`);
|
|
169
|
+
}
|
|
170
|
+
return [witness.map(toACVMField)];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async getPublicKeysAndPartialAddress([address]: ACVMField[]): Promise<ACVMField[][]> {
|
|
174
|
+
const parsedAddress = AztecAddress.fromField(Fr.fromString(address));
|
|
175
|
+
const { publicKeys, partialAddress } = await this.typedOracle.getCompleteAddress(parsedAddress);
|
|
176
|
+
|
|
177
|
+
return [[...publicKeys.toFields(), partialAddress].map(toACVMField)];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async getNotes(
|
|
181
|
+
[storageSlot]: ACVMField[],
|
|
182
|
+
[numSelects]: ACVMField[],
|
|
183
|
+
selectByIndexes: ACVMField[],
|
|
184
|
+
selectByOffsets: ACVMField[],
|
|
185
|
+
selectByLengths: ACVMField[],
|
|
186
|
+
selectValues: ACVMField[],
|
|
187
|
+
selectComparators: ACVMField[],
|
|
188
|
+
sortByIndexes: ACVMField[],
|
|
189
|
+
sortByOffsets: ACVMField[],
|
|
190
|
+
sortByLengths: ACVMField[],
|
|
191
|
+
sortOrder: ACVMField[],
|
|
192
|
+
[limit]: ACVMField[],
|
|
193
|
+
[offset]: ACVMField[],
|
|
194
|
+
[status]: ACVMField[],
|
|
195
|
+
[maxNotes]: ACVMField[],
|
|
196
|
+
[packedRetrievedNoteLength]: ACVMField[],
|
|
197
|
+
): Promise<(ACVMField | ACVMField[])[]> {
|
|
198
|
+
const noteDatas = await this.typedOracle.getNotes(
|
|
199
|
+
Fr.fromString(storageSlot),
|
|
200
|
+
+numSelects,
|
|
201
|
+
selectByIndexes.map(s => +s),
|
|
202
|
+
selectByOffsets.map(s => +s),
|
|
203
|
+
selectByLengths.map(s => +s),
|
|
204
|
+
selectValues.map(Fr.fromString),
|
|
205
|
+
selectComparators.map(s => +s),
|
|
206
|
+
sortByIndexes.map(s => +s),
|
|
207
|
+
sortByOffsets.map(s => +s),
|
|
208
|
+
sortByLengths.map(s => +s),
|
|
209
|
+
sortOrder.map(s => +s),
|
|
210
|
+
+limit,
|
|
211
|
+
+offset,
|
|
212
|
+
+status,
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
if (noteDatas.length > 0) {
|
|
216
|
+
const noteLength = noteDatas[0].note.items.length;
|
|
217
|
+
if (!noteDatas.every(({ note }) => noteLength === note.items.length)) {
|
|
218
|
+
throw new Error('Notes should all be the same length.');
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// The expected return type is a BoundedVec<[Field; packedRetrievedNoteLength], maxNotes> where each
|
|
223
|
+
// array is structured as [contract_address, nonce, nonzero_note_hash_counter, ...packed_note].
|
|
224
|
+
|
|
225
|
+
const returnDataAsArrayOfArrays = noteDatas.map(({ contractAddress, nonce, index, note }) => {
|
|
226
|
+
// If index is undefined, the note is transient which implies that the nonzero_note_hash_counter has to be true
|
|
227
|
+
const noteIsTransient = index === undefined;
|
|
228
|
+
const nonzeroNoteHashCounter = noteIsTransient ? true : false;
|
|
229
|
+
// If you change the array on the next line you have to change the `unpack_retrieved_note` function in
|
|
230
|
+
// `aztec/src/note/retrieved_note.nr`
|
|
231
|
+
return [contractAddress, nonce, nonzeroNoteHashCounter, ...note.items];
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Now we convert each sub-array to an array of ACVMField
|
|
235
|
+
const returnDataAsArrayOfACVMFieldArrays = returnDataAsArrayOfArrays.map(subArray => subArray.map(toACVMField));
|
|
236
|
+
|
|
237
|
+
// At last we convert the array of arrays to a bounded vec of arrays
|
|
238
|
+
return arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfACVMFieldArrays, +maxNotes, +packedRetrievedNoteLength);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
notifyCreatedNote(
|
|
242
|
+
[storageSlot]: ACVMField[],
|
|
243
|
+
[noteTypeId]: ACVMField[],
|
|
244
|
+
note: ACVMField[],
|
|
245
|
+
[noteHash]: ACVMField[],
|
|
246
|
+
[counter]: ACVMField[],
|
|
247
|
+
): Promise<ACVMField[]> {
|
|
248
|
+
this.typedOracle.notifyCreatedNote(
|
|
249
|
+
Fr.fromString(storageSlot),
|
|
250
|
+
NoteSelector.fromField(Fr.fromString(noteTypeId)),
|
|
251
|
+
note.map(Fr.fromString),
|
|
252
|
+
Fr.fromString(noteHash),
|
|
253
|
+
+counter,
|
|
254
|
+
);
|
|
255
|
+
return Promise.resolve([]);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async notifyNullifiedNote(
|
|
259
|
+
[innerNullifier]: ACVMField[],
|
|
260
|
+
[noteHash]: ACVMField[],
|
|
261
|
+
[counter]: ACVMField[],
|
|
262
|
+
): Promise<ACVMField[]> {
|
|
263
|
+
await this.typedOracle.notifyNullifiedNote(Fr.fromString(innerNullifier), Fr.fromString(noteHash), +counter);
|
|
264
|
+
return [];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async notifyCreatedNullifier([innerNullifier]: ACVMField[]): Promise<ACVMField[]> {
|
|
268
|
+
await this.typedOracle.notifyCreatedNullifier(Fr.fromString(innerNullifier));
|
|
269
|
+
return [];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async checkNullifierExists([innerNullifier]: ACVMField[]): Promise<ACVMField[]> {
|
|
273
|
+
const exists = await this.typedOracle.checkNullifierExists(Fr.fromString(innerNullifier));
|
|
274
|
+
return [toACVMField(exists)];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async getL1ToL2MembershipWitness(
|
|
278
|
+
[contractAddress]: ACVMField[],
|
|
279
|
+
[messageHash]: ACVMField[],
|
|
280
|
+
[secret]: ACVMField[],
|
|
281
|
+
): Promise<(ACVMField | ACVMField[])[]> {
|
|
282
|
+
const message = await this.typedOracle.getL1ToL2MembershipWitness(
|
|
283
|
+
AztecAddress.fromString(contractAddress),
|
|
284
|
+
Fr.fromString(messageHash),
|
|
285
|
+
Fr.fromString(secret),
|
|
286
|
+
);
|
|
287
|
+
return message.toNoirRepresentation();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async storageRead(
|
|
291
|
+
[contractAddress]: ACVMField[],
|
|
292
|
+
[startStorageSlot]: ACVMField[],
|
|
293
|
+
[blockNumber]: ACVMField[],
|
|
294
|
+
[numberOfElements]: ACVMField[],
|
|
295
|
+
): Promise<ACVMField[][]> {
|
|
296
|
+
const values = await this.typedOracle.storageRead(
|
|
297
|
+
new AztecAddress(Fr.fromString(contractAddress)),
|
|
298
|
+
Fr.fromString(startStorageSlot),
|
|
299
|
+
+blockNumber,
|
|
300
|
+
+numberOfElements,
|
|
301
|
+
);
|
|
302
|
+
return [values.map(toACVMField)];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async storageWrite([startStorageSlot]: ACVMField[], values: ACVMField[]): Promise<ACVMField[]> {
|
|
306
|
+
const newValues = await this.typedOracle.storageWrite(Fr.fromString(startStorageSlot), values.map(Fr.fromString));
|
|
307
|
+
return newValues.map(toACVMField);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
notifyCreatedContractClassLog(
|
|
311
|
+
[contractAddress]: ACVMField[],
|
|
312
|
+
message: ACVMField[],
|
|
313
|
+
[length]: ACVMField[],
|
|
314
|
+
[counter]: ACVMField[],
|
|
315
|
+
): Promise<ACVMField[]> {
|
|
316
|
+
const logFields = new ContractClassLogFields(message.map(Fr.fromString));
|
|
317
|
+
const log = new ContractClassLog(new AztecAddress(Fr.fromString(contractAddress)), logFields, +length);
|
|
318
|
+
|
|
319
|
+
this.typedOracle.notifyCreatedContractClassLog(log, +counter);
|
|
320
|
+
return Promise.resolve([]);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
debugLog(message: ACVMField[], _ignoredFieldsSize: ACVMField[], fields: ACVMField[]): Promise<ACVMField[]> {
|
|
324
|
+
const messageStr = message.map(acvmField => String.fromCharCode(Fr.fromString(acvmField).toNumber())).join('');
|
|
325
|
+
const fieldsFr = fields.map(Fr.fromString);
|
|
326
|
+
this.typedOracle.debugLog(messageStr, fieldsFr);
|
|
327
|
+
return Promise.resolve([]);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
async callPrivateFunction(
|
|
331
|
+
[contractAddress]: ACVMField[],
|
|
332
|
+
[functionSelector]: ACVMField[],
|
|
333
|
+
[argsHash]: ACVMField[],
|
|
334
|
+
[sideEffectCounter]: ACVMField[],
|
|
335
|
+
[isStaticCall]: ACVMField[],
|
|
336
|
+
): Promise<ACVMField[][]> {
|
|
337
|
+
const { endSideEffectCounter, returnsHash } = await this.typedOracle.callPrivateFunction(
|
|
338
|
+
AztecAddress.fromField(Fr.fromString(contractAddress)),
|
|
339
|
+
FunctionSelector.fromField(Fr.fromString(functionSelector)),
|
|
340
|
+
Fr.fromString(argsHash),
|
|
341
|
+
Fr.fromString(sideEffectCounter).toNumber(),
|
|
342
|
+
Fr.fromString(isStaticCall).toBool(),
|
|
343
|
+
);
|
|
344
|
+
return [[endSideEffectCounter, returnsHash].map(toACVMField)];
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async notifyEnqueuedPublicFunctionCall(
|
|
348
|
+
[contractAddress]: ACVMField[],
|
|
349
|
+
[calldataHash]: ACVMField[],
|
|
350
|
+
[sideEffectCounter]: ACVMField[],
|
|
351
|
+
[isStaticCall]: ACVMField[],
|
|
352
|
+
): Promise<ACVMField[]> {
|
|
353
|
+
await this.typedOracle.notifyEnqueuedPublicFunctionCall(
|
|
354
|
+
AztecAddress.fromString(contractAddress),
|
|
355
|
+
Fr.fromString(calldataHash),
|
|
356
|
+
Fr.fromString(sideEffectCounter).toNumber(),
|
|
357
|
+
Fr.fromString(isStaticCall).toBool(),
|
|
358
|
+
);
|
|
359
|
+
return [];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
async notifySetPublicTeardownFunctionCall(
|
|
363
|
+
[contractAddress]: ACVMField[],
|
|
364
|
+
[calldataHash]: ACVMField[],
|
|
365
|
+
[sideEffectCounter]: ACVMField[],
|
|
366
|
+
[isStaticCall]: ACVMField[],
|
|
367
|
+
): Promise<ACVMField[]> {
|
|
368
|
+
await this.typedOracle.notifySetPublicTeardownFunctionCall(
|
|
369
|
+
AztecAddress.fromString(contractAddress),
|
|
370
|
+
Fr.fromString(calldataHash),
|
|
371
|
+
Fr.fromString(sideEffectCounter).toNumber(),
|
|
372
|
+
Fr.fromString(isStaticCall).toBool(),
|
|
373
|
+
);
|
|
374
|
+
return [];
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
async notifySetMinRevertibleSideEffectCounter([minRevertibleSideEffectCounter]: ACVMField[]): Promise<ACVMField[]> {
|
|
378
|
+
await this.typedOracle.notifySetMinRevertibleSideEffectCounter(
|
|
379
|
+
Fr.fromString(minRevertibleSideEffectCounter).toNumber(),
|
|
380
|
+
);
|
|
381
|
+
return Promise.resolve([]);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
async getIndexedTaggingSecretAsSender([sender]: ACVMField[], [recipient]: ACVMField[]): Promise<ACVMField[]> {
|
|
385
|
+
const taggingSecret = await this.typedOracle.getIndexedTaggingSecretAsSender(
|
|
386
|
+
AztecAddress.fromString(sender),
|
|
387
|
+
AztecAddress.fromString(recipient),
|
|
388
|
+
);
|
|
389
|
+
return taggingSecret.toFields().map(toACVMField);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async incrementAppTaggingSecretIndexAsSender([sender]: ACVMField[], [recipient]: ACVMField[]): Promise<ACVMField[]> {
|
|
393
|
+
await this.typedOracle.incrementAppTaggingSecretIndexAsSender(
|
|
394
|
+
AztecAddress.fromString(sender),
|
|
395
|
+
AztecAddress.fromString(recipient),
|
|
396
|
+
);
|
|
397
|
+
return [];
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
async fetchTaggedLogs([pendingTaggedLogArrayBaseSlot]: ACVMField[]): Promise<ACVMField[]> {
|
|
401
|
+
await this.typedOracle.fetchTaggedLogs(Fr.fromString(pendingTaggedLogArrayBaseSlot));
|
|
402
|
+
return [];
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
async deliverNote(
|
|
406
|
+
[contractAddress]: ACVMField[],
|
|
407
|
+
[storageSlot]: ACVMField[],
|
|
408
|
+
[nonce]: ACVMField[],
|
|
409
|
+
content: ACVMField[],
|
|
410
|
+
[contentLength]: ACVMField[],
|
|
411
|
+
[noteHash]: ACVMField[],
|
|
412
|
+
[nullifier]: ACVMField[],
|
|
413
|
+
[txHash]: ACVMField[],
|
|
414
|
+
[recipient]: ACVMField[],
|
|
415
|
+
): Promise<ACVMField[]> {
|
|
416
|
+
// TODO(#10728): try-catch this block and return false if we get an exception so that the contract can decide what
|
|
417
|
+
// to do if a note fails delivery (e.g. not increment the tagging index, or add it to some pending work list).
|
|
418
|
+
// Delivery might fail due to temporary issues, such as poor node connectivity.
|
|
419
|
+
await this.typedOracle.deliverNote(
|
|
420
|
+
AztecAddress.fromString(contractAddress),
|
|
421
|
+
Fr.fromString(storageSlot),
|
|
422
|
+
Fr.fromString(nonce),
|
|
423
|
+
fromBoundedVec(content, contentLength),
|
|
424
|
+
Fr.fromString(noteHash),
|
|
425
|
+
Fr.fromString(nullifier),
|
|
426
|
+
TxHash.fromString(txHash),
|
|
427
|
+
AztecAddress.fromString(recipient),
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
return [toACVMField(true)];
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
async getLogByTag([tag]: ACVMField[]): Promise<(ACVMField | ACVMField[])[]> {
|
|
434
|
+
const log = await this.typedOracle.getLogByTag(Fr.fromString(tag));
|
|
435
|
+
|
|
436
|
+
if (log == null) {
|
|
437
|
+
return [toACVMField(0), ...LogWithTxData.noirSerializationOfEmpty().map(toACVMFieldSingleOrArray)];
|
|
438
|
+
} else {
|
|
439
|
+
return [toACVMField(1), ...log.toNoirSerialization().map(toACVMFieldSingleOrArray)];
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
async storeCapsule([contractAddress]: ACVMField[], [slot]: ACVMField[], capsule: ACVMField[]): Promise<ACVMField[]> {
|
|
444
|
+
await this.typedOracle.storeCapsule(
|
|
445
|
+
AztecAddress.fromField(Fr.fromString(contractAddress)),
|
|
446
|
+
Fr.fromString(slot),
|
|
447
|
+
capsule.map(Fr.fromString),
|
|
448
|
+
);
|
|
449
|
+
return [];
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
async loadCapsule(
|
|
453
|
+
[contractAddress]: ACVMField[],
|
|
454
|
+
[slot]: ACVMField[],
|
|
455
|
+
[tSize]: ACVMField[],
|
|
456
|
+
): Promise<(ACVMField | ACVMField[])[]> {
|
|
457
|
+
const values = await this.typedOracle.loadCapsule(
|
|
458
|
+
AztecAddress.fromField(Fr.fromString(contractAddress)),
|
|
459
|
+
Fr.fromString(slot),
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
463
|
+
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
464
|
+
if (values === null) {
|
|
465
|
+
// No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
|
|
466
|
+
return [toACVMField(0), Array(Fr.fromString(tSize).toNumber()).fill(toACVMField(0))];
|
|
467
|
+
} else {
|
|
468
|
+
// Data was found so we set `some` to 1 and return it along with `value`.
|
|
469
|
+
return [toACVMField(1), values.map(toACVMField)];
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
async deleteCapsule([contractAddress]: ACVMField[], [slot]: ACVMField[]): Promise<ACVMField[]> {
|
|
474
|
+
await this.typedOracle.deleteCapsule(AztecAddress.fromField(Fr.fromString(contractAddress)), Fr.fromString(slot));
|
|
475
|
+
return [];
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
async copyCapsule(
|
|
479
|
+
[contractAddress]: ACVMField[],
|
|
480
|
+
[srcSlot]: ACVMField[],
|
|
481
|
+
[dstSlot]: ACVMField[],
|
|
482
|
+
[numEntries]: ACVMField[],
|
|
483
|
+
): Promise<ACVMField[]> {
|
|
484
|
+
await this.typedOracle.copyCapsule(
|
|
485
|
+
AztecAddress.fromField(Fr.fromString(contractAddress)),
|
|
486
|
+
Fr.fromString(srcSlot),
|
|
487
|
+
Fr.fromString(dstSlot),
|
|
488
|
+
Fr.fromString(numEntries).toNumber(),
|
|
489
|
+
);
|
|
490
|
+
return [];
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
async aes128Decrypt(
|
|
494
|
+
ciphertextBVecStorage: ACVMField[],
|
|
495
|
+
[ciphertextLength]: ACVMField[],
|
|
496
|
+
iv: ACVMField[],
|
|
497
|
+
symKey: ACVMField[],
|
|
498
|
+
): Promise<(ACVMField | ACVMField[])[]> {
|
|
499
|
+
const ciphertext = fromUintBoundedVec(ciphertextBVecStorage, ciphertextLength, 8);
|
|
500
|
+
const ivBuffer = fromUintArray(iv, 8);
|
|
501
|
+
const symKeyBuffer = fromUintArray(symKey, 8);
|
|
502
|
+
|
|
503
|
+
const plaintext = await this.typedOracle.aes128Decrypt(ciphertext, ivBuffer, symKeyBuffer);
|
|
504
|
+
return bufferToBoundedVec(plaintext, ciphertextBVecStorage.length);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
async getSharedSecret(
|
|
508
|
+
[address]: ACVMField[],
|
|
509
|
+
[ephPKField0]: ACVMField[],
|
|
510
|
+
[ephPKField1]: ACVMField[],
|
|
511
|
+
[ephPKField2]: ACVMField[],
|
|
512
|
+
): Promise<ACVMField[]> {
|
|
513
|
+
const secret = await this.typedOracle.getSharedSecret(
|
|
514
|
+
AztecAddress.fromField(Fr.fromString(address)),
|
|
515
|
+
Point.fromFields([ephPKField0, ephPKField1, ephPKField2].map(Fr.fromString)),
|
|
516
|
+
);
|
|
517
|
+
return secret.toFields().map(toACVMField);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
async storePrivateEventLog(
|
|
521
|
+
[contractAddress]: ACVMField[],
|
|
522
|
+
[recipient]: ACVMField[],
|
|
523
|
+
[eventSelector]: ACVMField[],
|
|
524
|
+
msgContentBVecStorage: ACVMField[],
|
|
525
|
+
[msgContentLength]: ACVMField[],
|
|
526
|
+
[txHash]: ACVMField[],
|
|
527
|
+
[logIndexInTx]: ACVMField[],
|
|
528
|
+
[txIndexInBlock]: ACVMField[],
|
|
529
|
+
) {
|
|
530
|
+
await this.typedOracle.storePrivateEventLog(
|
|
531
|
+
AztecAddress.fromField(Fr.fromString(contractAddress)),
|
|
532
|
+
AztecAddress.fromField(Fr.fromString(recipient)),
|
|
533
|
+
EventSelector.fromField(Fr.fromString(eventSelector)),
|
|
534
|
+
fromBoundedVec(msgContentBVecStorage, msgContentLength),
|
|
535
|
+
new TxHash(Fr.fromString(txHash)),
|
|
536
|
+
Fr.fromString(logIndexInTx).toNumber(),
|
|
537
|
+
Fr.fromString(txIndexInBlock).toNumber(),
|
|
538
|
+
);
|
|
539
|
+
return [];
|
|
540
|
+
}
|
|
541
|
+
}
|