@aztec/pxe 1.2.1 → 2.0.0-nightly.20250813
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 +5 -2
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +48 -29
- package/dest/contract_function_simulator/index.d.ts +1 -0
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +22 -0
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +49 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +44 -43
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +127 -106
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +7 -2
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +16 -11
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +41 -17
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +51 -23
- package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +48 -47
- package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/typed_oracle.js +89 -87
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +31 -30
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +33 -30
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -1
- package/dest/contract_function_simulator/pxe_oracle_interface.js +6 -7
- package/dest/entrypoints/server/utils.d.ts +4 -2
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +4 -2
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +4 -4
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +58 -59
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +41 -0
- package/dest/private_kernel/hints/index.d.ts +1 -0
- package/dest/private_kernel/hints/index.d.ts.map +1 -1
- package/dest/private_kernel/hints/index.js +1 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +13 -4
- package/dest/private_kernel/private_kernel_oracle.d.ts +1 -1
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle_impl.js +6 -6
- package/dest/pxe_service/error_enriching.d.ts.map +1 -1
- package/dest/pxe_service/error_enriching.js +1 -0
- package/dest/pxe_service/pxe_service.d.ts +3 -2
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +28 -19
- package/dest/storage/capsule_data_provider/capsule_data_provider.js +1 -1
- package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
- package/dest/storage/note_data_provider/note_data_provider.js +16 -4
- package/package.json +16 -16
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +67 -37
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +52 -0
- package/src/contract_function_simulator/oracle/oracle.ts +149 -111
- package/src/contract_function_simulator/oracle/private_execution.ts +17 -12
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +60 -24
- package/src/contract_function_simulator/oracle/typed_oracle.ts +108 -92
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +34 -30
- package/src/contract_function_simulator/pxe_oracle_interface.ts +6 -8
- package/src/entrypoints/server/utils.ts +17 -6
- package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +106 -104
- package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +58 -0
- package/src/private_kernel/hints/index.ts +1 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +21 -4
- package/src/private_kernel/private_kernel_oracle.ts +1 -1
- package/src/private_kernel/private_kernel_oracle_impl.ts +12 -9
- package/src/pxe_service/error_enriching.ts +1 -0
- package/src/pxe_service/pxe_service.ts +30 -32
- package/src/storage/capsule_data_provider/capsule_data_provider.ts +1 -1
- package/src/storage/note_data_provider/note_data_provider.ts +27 -16
|
@@ -4,6 +4,7 @@ import { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
|
4
4
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
import { ContractClassLog, ContractClassLogFields } from '@aztec/stdlib/logs';
|
|
6
6
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
7
|
+
import { packAsRetrievedNote } from './note_packing_utils.js';
|
|
7
8
|
/**
|
|
8
9
|
* A data source that has all the apis required by Aztec.nr.
|
|
9
10
|
*/ export class Oracle {
|
|
@@ -12,59 +13,79 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
|
12
13
|
this.typedOracle = typedOracle;
|
|
13
14
|
}
|
|
14
15
|
toACIRCallback() {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const excludedProps = [
|
|
17
|
+
'typedOracle',
|
|
18
|
+
'constructor',
|
|
19
|
+
'toACIRCallback'
|
|
20
|
+
];
|
|
21
|
+
// Get all the oracle function names
|
|
22
|
+
const oracleNames = Object.getOwnPropertyNames(Oracle.prototype).filter((name)=>!excludedProps.includes(name));
|
|
23
|
+
// Validate oracle names - these must be prefixed with either "private" or "utility" to indicate their scope
|
|
24
|
+
// and must correspond to a function on the Oracle class.
|
|
25
|
+
oracleNames.forEach((name)=>{
|
|
26
|
+
if (!name.startsWith('private') && !name.startsWith('utility')) {
|
|
27
|
+
throw new Error(`Oracle function "${name}" must be prefixed with either "private" or "utility" to indicate its scope`);
|
|
28
|
+
}
|
|
29
|
+
const method = this[name];
|
|
30
|
+
if (typeof method !== 'function') {
|
|
31
|
+
throw new Error(`Oracle property "${name}" must be a function`);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
// Build callback object and return it
|
|
35
|
+
return oracleNames.reduce((acc, name)=>{
|
|
36
|
+
const method = this[name];
|
|
37
|
+
acc[name] = method.bind(this);
|
|
17
38
|
return acc;
|
|
18
39
|
}, {});
|
|
19
40
|
}
|
|
20
|
-
|
|
21
|
-
const val = this.typedOracle.
|
|
41
|
+
utilityGetRandomField() {
|
|
42
|
+
const val = this.typedOracle.utilityGetRandomField();
|
|
22
43
|
return Promise.resolve([
|
|
23
44
|
toACVMField(val)
|
|
24
45
|
]);
|
|
25
46
|
}
|
|
26
47
|
// Since the argument is a slice, noir automatically adds a length field to oracle call.
|
|
27
|
-
|
|
28
|
-
this.typedOracle.
|
|
48
|
+
privateStoreInExecutionCache(_length, values, [hash]) {
|
|
49
|
+
this.typedOracle.privateStoreInExecutionCache(values.map(Fr.fromString), Fr.fromString(hash));
|
|
29
50
|
return Promise.resolve([]);
|
|
30
51
|
}
|
|
31
|
-
async
|
|
32
|
-
const values = await this.typedOracle.
|
|
52
|
+
async privateLoadFromExecutionCache([returnsHash]) {
|
|
53
|
+
const values = await this.typedOracle.privateLoadFromExecutionCache(Fr.fromString(returnsHash));
|
|
33
54
|
return [
|
|
34
55
|
values.map(toACVMField)
|
|
35
56
|
];
|
|
36
57
|
}
|
|
37
|
-
async
|
|
58
|
+
async utilityGetBlockNumber() {
|
|
38
59
|
return [
|
|
39
|
-
toACVMField(await this.typedOracle.
|
|
60
|
+
toACVMField(await this.typedOracle.utilityGetBlockNumber())
|
|
40
61
|
];
|
|
41
62
|
}
|
|
42
|
-
async
|
|
63
|
+
async utilityGetTimestamp() {
|
|
43
64
|
return [
|
|
44
|
-
toACVMField(await this.typedOracle.
|
|
65
|
+
toACVMField(await this.typedOracle.utilityGetTimestamp())
|
|
45
66
|
];
|
|
46
67
|
}
|
|
47
|
-
async
|
|
68
|
+
async utilityGetContractAddress() {
|
|
48
69
|
return [
|
|
49
|
-
toACVMField(await this.typedOracle.
|
|
70
|
+
toACVMField(await this.typedOracle.utilityGetContractAddress())
|
|
50
71
|
];
|
|
51
72
|
}
|
|
52
|
-
async
|
|
73
|
+
async utilityGetVersion() {
|
|
53
74
|
return [
|
|
54
|
-
toACVMField(await this.typedOracle.
|
|
75
|
+
toACVMField(await this.typedOracle.utilityGetVersion())
|
|
55
76
|
];
|
|
56
77
|
}
|
|
57
|
-
async
|
|
78
|
+
async utilityGetChainId() {
|
|
58
79
|
return [
|
|
59
|
-
toACVMField(await this.typedOracle.
|
|
80
|
+
toACVMField(await this.typedOracle.utilityGetChainId())
|
|
60
81
|
];
|
|
61
82
|
}
|
|
62
|
-
async
|
|
63
|
-
const keyValidationRequest = await this.typedOracle.
|
|
83
|
+
async utilityGetKeyValidationRequest([pkMHash]) {
|
|
84
|
+
const keyValidationRequest = await this.typedOracle.utilityGetKeyValidationRequest(Fr.fromString(pkMHash));
|
|
64
85
|
return keyValidationRequest.toFields().map(toACVMField);
|
|
65
86
|
}
|
|
66
|
-
async
|
|
67
|
-
const instance = await this.typedOracle.
|
|
87
|
+
async utilityGetContractInstance([address]) {
|
|
88
|
+
const instance = await this.typedOracle.utilityGetContractInstance(AztecAddress.fromField(Fr.fromString(address)));
|
|
68
89
|
return [
|
|
69
90
|
instance.salt,
|
|
70
91
|
instance.deployer,
|
|
@@ -73,11 +94,11 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
|
73
94
|
...instance.publicKeys.toFields()
|
|
74
95
|
].map(toACVMField);
|
|
75
96
|
}
|
|
76
|
-
async
|
|
97
|
+
async utilityGetMembershipWitness([blockNumber], [treeId], [leafValue]) {
|
|
77
98
|
const parsedBlockNumber = Fr.fromString(blockNumber).toNumber();
|
|
78
99
|
const parsedTreeId = Fr.fromString(treeId).toNumber();
|
|
79
100
|
const parsedLeafValue = Fr.fromString(leafValue);
|
|
80
|
-
const witness = await this.typedOracle.
|
|
101
|
+
const witness = await this.typedOracle.utilityGetMembershipWitness(parsedBlockNumber, parsedTreeId, parsedLeafValue);
|
|
81
102
|
if (!witness) {
|
|
82
103
|
throw new Error(`Leaf ${leafValue} not found in the tree ${MerkleTreeId[parsedTreeId]} at block ${parsedBlockNumber}.`);
|
|
83
104
|
}
|
|
@@ -86,44 +107,44 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
|
86
107
|
witness.slice(1).map(toACVMField)
|
|
87
108
|
];
|
|
88
109
|
}
|
|
89
|
-
async
|
|
110
|
+
async utilityGetNullifierMembershipWitness([blockNumber], [nullifier]) {
|
|
90
111
|
const parsedBlockNumber = Fr.fromString(blockNumber).toNumber();
|
|
91
112
|
const parsedNullifier = Fr.fromString(nullifier);
|
|
92
|
-
const witness = await this.typedOracle.
|
|
113
|
+
const witness = await this.typedOracle.utilityGetNullifierMembershipWitness(parsedBlockNumber, parsedNullifier);
|
|
93
114
|
if (!witness) {
|
|
94
115
|
throw new Error(`Nullifier witness not found for nullifier ${parsedNullifier} at block ${parsedBlockNumber}.`);
|
|
95
116
|
}
|
|
96
117
|
return witness.toNoirRepresentation();
|
|
97
118
|
}
|
|
98
|
-
async
|
|
119
|
+
async utilityGetLowNullifierMembershipWitness([blockNumber], [nullifier]) {
|
|
99
120
|
const parsedBlockNumber = Fr.fromString(blockNumber).toNumber();
|
|
100
121
|
const parsedNullifier = Fr.fromString(nullifier);
|
|
101
|
-
const witness = await this.typedOracle.
|
|
122
|
+
const witness = await this.typedOracle.utilityGetLowNullifierMembershipWitness(parsedBlockNumber, parsedNullifier);
|
|
102
123
|
if (!witness) {
|
|
103
124
|
throw new Error(`Low nullifier witness not found for nullifier ${parsedNullifier} at block ${parsedBlockNumber}.`);
|
|
104
125
|
}
|
|
105
126
|
return witness.toNoirRepresentation();
|
|
106
127
|
}
|
|
107
|
-
async
|
|
128
|
+
async utilityGetPublicDataWitness([blockNumber], [leafSlot]) {
|
|
108
129
|
const parsedBlockNumber = Fr.fromString(blockNumber).toNumber();
|
|
109
130
|
const parsedLeafSlot = Fr.fromString(leafSlot);
|
|
110
|
-
const witness = await this.typedOracle.
|
|
131
|
+
const witness = await this.typedOracle.utilityGetPublicDataWitness(parsedBlockNumber, parsedLeafSlot);
|
|
111
132
|
if (!witness) {
|
|
112
133
|
throw new Error(`Public data witness not found for slot ${parsedLeafSlot} at block ${parsedBlockNumber}.`);
|
|
113
134
|
}
|
|
114
135
|
return witness.toNoirRepresentation();
|
|
115
136
|
}
|
|
116
|
-
async
|
|
137
|
+
async utilityGetBlockHeader([blockNumber]) {
|
|
117
138
|
const parsedBlockNumber = Fr.fromString(blockNumber).toNumber();
|
|
118
|
-
const header = await this.typedOracle.
|
|
139
|
+
const header = await this.typedOracle.utilityGetBlockHeader(parsedBlockNumber);
|
|
119
140
|
if (!header) {
|
|
120
141
|
throw new Error(`Block header not found for block ${parsedBlockNumber}.`);
|
|
121
142
|
}
|
|
122
143
|
return header.toFields().map(toACVMField);
|
|
123
144
|
}
|
|
124
|
-
async
|
|
145
|
+
async utilityGetAuthWitness([messageHash]) {
|
|
125
146
|
const messageHashField = Fr.fromString(messageHash);
|
|
126
|
-
const witness = await this.typedOracle.
|
|
147
|
+
const witness = await this.typedOracle.utilityGetAuthWitness(messageHashField);
|
|
127
148
|
if (!witness) {
|
|
128
149
|
throw new Error(`Unknown auth witness for message hash ${messageHashField}`);
|
|
129
150
|
}
|
|
@@ -131,9 +152,10 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
|
131
152
|
witness.map(toACVMField)
|
|
132
153
|
];
|
|
133
154
|
}
|
|
134
|
-
|
|
155
|
+
// TODO(benesjan): This doesn't map to the underlying oracle name which is just ugly.
|
|
156
|
+
async utilityGetPublicKeysAndPartialAddress([address]) {
|
|
135
157
|
const parsedAddress = AztecAddress.fromField(Fr.fromString(address));
|
|
136
|
-
const { publicKeys, partialAddress } = await this.typedOracle.
|
|
158
|
+
const { publicKeys, partialAddress } = await this.typedOracle.utilityGetCompleteAddress(parsedAddress);
|
|
137
159
|
return [
|
|
138
160
|
[
|
|
139
161
|
...publicKeys.toFields(),
|
|
@@ -141,80 +163,64 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
|
141
163
|
].map(toACVMField)
|
|
142
164
|
];
|
|
143
165
|
}
|
|
144
|
-
async
|
|
145
|
-
const noteDatas = await this.typedOracle.
|
|
166
|
+
async utilityGetNotes([storageSlot], [numSelects], selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, [limit], [offset], [status], [maxNotes], [packedRetrievedNoteLength]) {
|
|
167
|
+
const noteDatas = await this.typedOracle.utilityGetNotes(Fr.fromString(storageSlot), +numSelects, selectByIndexes.map((s)=>+s), selectByOffsets.map((s)=>+s), selectByLengths.map((s)=>+s), selectValues.map(Fr.fromString), selectComparators.map((s)=>+s), sortByIndexes.map((s)=>+s), sortByOffsets.map((s)=>+s), sortByLengths.map((s)=>+s), sortOrder.map((s)=>+s), +limit, +offset, +status);
|
|
146
168
|
if (noteDatas.length > 0) {
|
|
147
169
|
const noteLength = noteDatas[0].note.items.length;
|
|
148
170
|
if (!noteDatas.every(({ note })=>noteLength === note.items.length)) {
|
|
149
171
|
throw new Error('Notes should all be the same length.');
|
|
150
172
|
}
|
|
151
173
|
}
|
|
152
|
-
|
|
153
|
-
// array is structured as [contract_address, note_nonce, nonzero_note_hash_counter, ...packed_note].
|
|
154
|
-
const returnDataAsArrayOfArrays = noteDatas.map(({ contractAddress, noteNonce, index, note })=>{
|
|
155
|
-
// If index is undefined, the note is transient which implies that the nonzero_note_hash_counter has to be true
|
|
156
|
-
const noteIsTransient = index === undefined;
|
|
157
|
-
const nonzeroNoteHashCounter = noteIsTransient ? true : false;
|
|
158
|
-
// If you change the array on the next line you have to change the `unpack_retrieved_note` function in
|
|
159
|
-
// `aztec/src/note/retrieved_note.nr`
|
|
160
|
-
return [
|
|
161
|
-
contractAddress,
|
|
162
|
-
noteNonce,
|
|
163
|
-
nonzeroNoteHashCounter,
|
|
164
|
-
...note.items
|
|
165
|
-
];
|
|
166
|
-
});
|
|
174
|
+
const returnDataAsArrayOfPackedRetrievedNotes = noteDatas.map(packAsRetrievedNote);
|
|
167
175
|
// Now we convert each sub-array to an array of ACVMField
|
|
168
|
-
const returnDataAsArrayOfACVMFieldArrays =
|
|
176
|
+
const returnDataAsArrayOfACVMFieldArrays = returnDataAsArrayOfPackedRetrievedNotes.map((subArray)=>subArray.map(toACVMField));
|
|
169
177
|
// At last we convert the array of arrays to a bounded vec of arrays
|
|
170
178
|
return arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfACVMFieldArrays, +maxNotes, +packedRetrievedNoteLength);
|
|
171
179
|
}
|
|
172
|
-
|
|
173
|
-
this.typedOracle.
|
|
180
|
+
privateNotifyCreatedNote([storageSlot], [noteTypeId], note, [noteHash], [counter]) {
|
|
181
|
+
this.typedOracle.privateNotifyCreatedNote(Fr.fromString(storageSlot), NoteSelector.fromField(Fr.fromString(noteTypeId)), note.map(Fr.fromString), Fr.fromString(noteHash), +counter);
|
|
174
182
|
return Promise.resolve([]);
|
|
175
183
|
}
|
|
176
|
-
async
|
|
177
|
-
await this.typedOracle.
|
|
184
|
+
async privateNotifyNullifiedNote([innerNullifier], [noteHash], [counter]) {
|
|
185
|
+
await this.typedOracle.privateNotifyNullifiedNote(Fr.fromString(innerNullifier), Fr.fromString(noteHash), +counter);
|
|
178
186
|
return [];
|
|
179
187
|
}
|
|
180
|
-
async
|
|
181
|
-
await this.typedOracle.
|
|
188
|
+
async privateNotifyCreatedNullifier([innerNullifier]) {
|
|
189
|
+
await this.typedOracle.privateNotifyCreatedNullifier(Fr.fromString(innerNullifier));
|
|
182
190
|
return [];
|
|
183
191
|
}
|
|
184
|
-
async
|
|
185
|
-
const exists = await this.typedOracle.
|
|
192
|
+
async utilityCheckNullifierExists([innerNullifier]) {
|
|
193
|
+
const exists = await this.typedOracle.utilityCheckNullifierExists(Fr.fromString(innerNullifier));
|
|
186
194
|
return [
|
|
187
195
|
toACVMField(exists)
|
|
188
196
|
];
|
|
189
197
|
}
|
|
190
|
-
async
|
|
191
|
-
const message = await this.typedOracle.
|
|
198
|
+
async utilityGetL1ToL2MembershipWitness([contractAddress], [messageHash], [secret]) {
|
|
199
|
+
const message = await this.typedOracle.utilityGetL1ToL2MembershipWitness(AztecAddress.fromString(contractAddress), Fr.fromString(messageHash), Fr.fromString(secret));
|
|
192
200
|
return message.toNoirRepresentation();
|
|
193
201
|
}
|
|
194
|
-
async
|
|
195
|
-
const values = await this.typedOracle.
|
|
202
|
+
async utilityStorageRead([contractAddress], [startStorageSlot], [blockNumber], [numberOfElements]) {
|
|
203
|
+
const values = await this.typedOracle.utilityStorageRead(new AztecAddress(Fr.fromString(contractAddress)), Fr.fromString(startStorageSlot), +blockNumber, +numberOfElements);
|
|
196
204
|
return [
|
|
197
205
|
values.map(toACVMField)
|
|
198
206
|
];
|
|
199
207
|
}
|
|
200
|
-
|
|
201
|
-
const newValues = await this.typedOracle.storageWrite(Fr.fromString(startStorageSlot), values.map(Fr.fromString));
|
|
202
|
-
return newValues.map(toACVMField);
|
|
203
|
-
}
|
|
204
|
-
notifyCreatedContractClassLog([contractAddress], message, [length], [counter]) {
|
|
208
|
+
privateNotifyCreatedContractClassLog([contractAddress], message, [length], [counter]) {
|
|
205
209
|
const logFields = new ContractClassLogFields(message.map(Fr.fromString));
|
|
206
210
|
const log = new ContractClassLog(new AztecAddress(Fr.fromString(contractAddress)), logFields, +length);
|
|
207
|
-
this.typedOracle.
|
|
211
|
+
this.typedOracle.privateNotifyCreatedContractClassLog(log, +counter);
|
|
208
212
|
return Promise.resolve([]);
|
|
209
213
|
}
|
|
210
|
-
|
|
214
|
+
utilityDebugLog(message, _ignoredFieldsSize, fields) {
|
|
211
215
|
const messageStr = message.map((acvmField)=>String.fromCharCode(Fr.fromString(acvmField).toNumber())).join('');
|
|
212
216
|
const fieldsFr = fields.map(Fr.fromString);
|
|
213
|
-
this.typedOracle.
|
|
217
|
+
this.typedOracle.utilityDebugLog(messageStr, fieldsFr);
|
|
214
218
|
return Promise.resolve([]);
|
|
215
219
|
}
|
|
216
|
-
|
|
217
|
-
|
|
220
|
+
// This function's name is directly hardcoded in `circuit_recorder.ts`. Don't forget to update it there if you
|
|
221
|
+
// change the name here.
|
|
222
|
+
async privateCallPrivateFunction([contractAddress], [functionSelector], [argsHash], [sideEffectCounter], [isStaticCall]) {
|
|
223
|
+
const { endSideEffectCounter, returnsHash } = await this.typedOracle.privateCallPrivateFunction(AztecAddress.fromField(Fr.fromString(contractAddress)), FunctionSelector.fromField(Fr.fromString(functionSelector)), Fr.fromString(argsHash), Fr.fromString(sideEffectCounter).toNumber(), Fr.fromString(isStaticCall).toBool());
|
|
218
224
|
return [
|
|
219
225
|
[
|
|
220
226
|
endSideEffectCounter,
|
|
@@ -222,44 +228,44 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
|
222
228
|
].map(toACVMField)
|
|
223
229
|
];
|
|
224
230
|
}
|
|
225
|
-
async
|
|
226
|
-
await this.typedOracle.
|
|
231
|
+
async privateNotifyEnqueuedPublicFunctionCall([contractAddress], [calldataHash], [sideEffectCounter], [isStaticCall]) {
|
|
232
|
+
await this.typedOracle.privateNotifyEnqueuedPublicFunctionCall(AztecAddress.fromString(contractAddress), Fr.fromString(calldataHash), Fr.fromString(sideEffectCounter).toNumber(), Fr.fromString(isStaticCall).toBool());
|
|
227
233
|
return [];
|
|
228
234
|
}
|
|
229
|
-
async
|
|
230
|
-
await this.typedOracle.
|
|
235
|
+
async privateNotifySetPublicTeardownFunctionCall([contractAddress], [calldataHash], [sideEffectCounter], [isStaticCall]) {
|
|
236
|
+
await this.typedOracle.privateNotifySetPublicTeardownFunctionCall(AztecAddress.fromString(contractAddress), Fr.fromString(calldataHash), Fr.fromString(sideEffectCounter).toNumber(), Fr.fromString(isStaticCall).toBool());
|
|
231
237
|
return [];
|
|
232
238
|
}
|
|
233
|
-
async
|
|
234
|
-
await this.typedOracle.
|
|
239
|
+
async privateNotifySetMinRevertibleSideEffectCounter([minRevertibleSideEffectCounter]) {
|
|
240
|
+
await this.typedOracle.privateNotifySetMinRevertibleSideEffectCounter(Fr.fromString(minRevertibleSideEffectCounter).toNumber());
|
|
235
241
|
return Promise.resolve([]);
|
|
236
242
|
}
|
|
237
|
-
async
|
|
238
|
-
const taggingSecret = await this.typedOracle.
|
|
243
|
+
async utilityGetIndexedTaggingSecretAsSender([sender], [recipient]) {
|
|
244
|
+
const taggingSecret = await this.typedOracle.utilityGetIndexedTaggingSecretAsSender(AztecAddress.fromString(sender), AztecAddress.fromString(recipient));
|
|
239
245
|
return taggingSecret.toFields().map(toACVMField);
|
|
240
246
|
}
|
|
241
|
-
async
|
|
242
|
-
await this.typedOracle.
|
|
247
|
+
async privateIncrementAppTaggingSecretIndexAsSender([sender], [recipient]) {
|
|
248
|
+
await this.typedOracle.privateIncrementAppTaggingSecretIndexAsSender(AztecAddress.fromString(sender), AztecAddress.fromString(recipient));
|
|
243
249
|
return [];
|
|
244
250
|
}
|
|
245
|
-
async
|
|
246
|
-
await this.typedOracle.
|
|
251
|
+
async utilityFetchTaggedLogs([pendingTaggedLogArrayBaseSlot]) {
|
|
252
|
+
await this.typedOracle.utilityFetchTaggedLogs(Fr.fromString(pendingTaggedLogArrayBaseSlot));
|
|
247
253
|
return [];
|
|
248
254
|
}
|
|
249
|
-
async
|
|
250
|
-
await this.typedOracle.
|
|
255
|
+
async utilityValidateEnqueuedNotesAndEvents([contractAddress], [noteValidationRequestsArrayBaseSlot], [eventValidationRequestsArrayBaseSlot]) {
|
|
256
|
+
await this.typedOracle.utilityValidateEnqueuedNotesAndEvents(AztecAddress.fromString(contractAddress), Fr.fromString(noteValidationRequestsArrayBaseSlot), Fr.fromString(eventValidationRequestsArrayBaseSlot));
|
|
251
257
|
return [];
|
|
252
258
|
}
|
|
253
|
-
async
|
|
254
|
-
await this.typedOracle.
|
|
259
|
+
async utilityBulkRetrieveLogs([contractAddress], [logRetrievalRequestsArrayBaseSlot], [logRetrievalResponsesArrayBaseSlot]) {
|
|
260
|
+
await this.typedOracle.utilityBulkRetrieveLogs(AztecAddress.fromString(contractAddress), Fr.fromString(logRetrievalRequestsArrayBaseSlot), Fr.fromString(logRetrievalResponsesArrayBaseSlot));
|
|
255
261
|
return [];
|
|
256
262
|
}
|
|
257
|
-
async
|
|
258
|
-
await this.typedOracle.
|
|
263
|
+
async utilityStoreCapsule([contractAddress], [slot], capsule) {
|
|
264
|
+
await this.typedOracle.utilityStoreCapsule(AztecAddress.fromField(Fr.fromString(contractAddress)), Fr.fromString(slot), capsule.map(Fr.fromString));
|
|
259
265
|
return [];
|
|
260
266
|
}
|
|
261
|
-
async
|
|
262
|
-
const values = await this.typedOracle.
|
|
267
|
+
async utilityLoadCapsule([contractAddress], [slot], [tSize]) {
|
|
268
|
+
const values = await this.typedOracle.utilityLoadCapsule(AztecAddress.fromField(Fr.fromString(contractAddress)), Fr.fromString(slot));
|
|
263
269
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
264
270
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
265
271
|
if (values === null) {
|
|
@@ -276,31 +282,46 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
|
276
282
|
];
|
|
277
283
|
}
|
|
278
284
|
}
|
|
279
|
-
async
|
|
280
|
-
await this.typedOracle.
|
|
285
|
+
async utilityDeleteCapsule([contractAddress], [slot]) {
|
|
286
|
+
await this.typedOracle.utilityDeleteCapsule(AztecAddress.fromField(Fr.fromString(contractAddress)), Fr.fromString(slot));
|
|
281
287
|
return [];
|
|
282
288
|
}
|
|
283
|
-
async
|
|
284
|
-
await this.typedOracle.
|
|
289
|
+
async utilityCopyCapsule([contractAddress], [srcSlot], [dstSlot], [numEntries]) {
|
|
290
|
+
await this.typedOracle.utilityCopyCapsule(AztecAddress.fromField(Fr.fromString(contractAddress)), Fr.fromString(srcSlot), Fr.fromString(dstSlot), Fr.fromString(numEntries).toNumber());
|
|
285
291
|
return [];
|
|
286
292
|
}
|
|
287
|
-
async
|
|
293
|
+
async utilityAes128Decrypt(ciphertextBVecStorage, [ciphertextLength], iv, symKey) {
|
|
288
294
|
const ciphertext = fromUintBoundedVec(ciphertextBVecStorage, ciphertextLength, 8);
|
|
289
295
|
const ivBuffer = fromUintArray(iv, 8);
|
|
290
296
|
const symKeyBuffer = fromUintArray(symKey, 8);
|
|
291
|
-
const plaintext = await this.typedOracle.
|
|
297
|
+
const plaintext = await this.typedOracle.utilityAes128Decrypt(ciphertext, ivBuffer, symKeyBuffer);
|
|
292
298
|
return bufferToBoundedVec(plaintext, ciphertextBVecStorage.length);
|
|
293
299
|
}
|
|
294
|
-
async
|
|
295
|
-
const secret = await this.typedOracle.
|
|
300
|
+
async utilityGetSharedSecret([address], [ephPKField0], [ephPKField1], [ephPKField2]) {
|
|
301
|
+
const secret = await this.typedOracle.utilityGetSharedSecret(AztecAddress.fromField(Fr.fromString(address)), Point.fromFields([
|
|
296
302
|
ephPKField0,
|
|
297
303
|
ephPKField1,
|
|
298
304
|
ephPKField2
|
|
299
305
|
].map(Fr.fromString)));
|
|
300
306
|
return secret.toFields().map(toACVMField);
|
|
301
307
|
}
|
|
302
|
-
async
|
|
303
|
-
await this.typedOracle.
|
|
308
|
+
async utilityEmitOffchainEffect(data) {
|
|
309
|
+
await this.typedOracle.utilityEmitOffchainEffect(data.map(Fr.fromString));
|
|
310
|
+
return [];
|
|
311
|
+
}
|
|
312
|
+
async privateGetSenderForTags() {
|
|
313
|
+
const sender = await this.typedOracle.privateGetSenderForTags();
|
|
314
|
+
// Return [1, address] for Some(address), [0, 0] for None
|
|
315
|
+
return sender ? [
|
|
316
|
+
toACVMField(1n),
|
|
317
|
+
toACVMField(sender)
|
|
318
|
+
] : [
|
|
319
|
+
toACVMField(0n),
|
|
320
|
+
toACVMField(0n)
|
|
321
|
+
];
|
|
322
|
+
}
|
|
323
|
+
async privateSetSenderForTags([senderForTags]) {
|
|
324
|
+
await this.typedOracle.privateSetSenderForTags(AztecAddress.fromField(Fr.fromString(senderForTags)));
|
|
304
325
|
return [];
|
|
305
326
|
}
|
|
306
327
|
}
|
|
@@ -11,6 +11,11 @@ import type { ExecutionDataProvider } from '../execution_data_provider.js';
|
|
|
11
11
|
import type { PrivateExecutionOracle } from './private_execution_oracle.js';
|
|
12
12
|
/**
|
|
13
13
|
* Execute a private function and return the execution result.
|
|
14
|
+
* This does not execute any kernel circuits; only the user functions.
|
|
15
|
+
*
|
|
16
|
+
* If this private function execution results in any nested private function calls,
|
|
17
|
+
* those nested calls are made via oracle calls to the `privateCallPrivateFunction` oracle,
|
|
18
|
+
* which in turn makes corresponding further calls to this function.
|
|
14
19
|
*/
|
|
15
20
|
export declare function executePrivateFunction(simulator: CircuitSimulator, privateExecutionOracle: PrivateExecutionOracle, artifact: FunctionArtifactWithContractName, contractAddress: AztecAddress, functionSelector: FunctionSelector, log?: import("@aztec/foundation/log").Logger): Promise<PrivateCallExecutionResult>;
|
|
16
21
|
/**
|
|
@@ -26,8 +31,8 @@ export declare function extractPrivateCircuitPublicInputs(artifact: FunctionArti
|
|
|
26
31
|
* @param contractAddress - The address of the contract to read the class id for.
|
|
27
32
|
* @param instance - The instance of the contract.
|
|
28
33
|
* @param executionDataProvider - The execution data provider.
|
|
29
|
-
* @param blockNumber - The block number at which to load the
|
|
30
|
-
* @param timestamp - The timestamp at which to obtain the class id from the
|
|
34
|
+
* @param blockNumber - The block number at which to load the DelayedPublicMutable storing the class id.
|
|
35
|
+
* @param timestamp - The timestamp at which to obtain the class id from the DelayedPublicMutable.
|
|
31
36
|
* @returns The current class id.
|
|
32
37
|
*/
|
|
33
38
|
export declare function readCurrentClassId(contractAddress: AztecAddress, instance: ContractInstance, executionDataProvider: ExecutionDataProvider | AztecNode, blockNumber: number, timestamp: UInt64): Promise<Fr>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private_execution.d.ts","sourceRoot":"","sources":["../../../src/contract_function_simulator/oracle/private_execution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAI9C,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAKtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gCAAgC,EACrC,KAAK,gBAAgB,EAEtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"private_execution.d.ts","sourceRoot":"","sources":["../../../src/contract_function_simulator/oracle/private_execution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAI9C,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAKtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gCAAgC,EACrC,KAAK,gBAAgB,EAEtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,SAAS,EAAE,gBAAgB,EAC3B,sBAAsB,EAAE,sBAAsB,EAC9C,QAAQ,EAAE,gCAAgC,EAC1C,eAAe,EAAE,YAAY,EAC7B,gBAAgB,EAAE,gBAAgB,EAClC,GAAG,yCAA8C,GAChD,OAAO,CAAC,0BAA0B,CAAC,CA2ErC;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,gBAAgB,EAC1B,cAAc,EAAE,WAAW,GAC1B,0BAA0B,CAa5B;AAED;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CACtC,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,gBAAgB,EAC1B,qBAAqB,EAAE,qBAAqB,GAAG,SAAS,EACxD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,eAWlB;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,eAAe,EAAE,YAAY,EAC7B,qBAAqB,EAAE,qBAAqB,EAC5C,MAAM,CAAC,EAAE,WAAW,iBA2BrB"}
|
|
@@ -5,12 +5,17 @@ import { Timer } from '@aztec/foundation/timer';
|
|
|
5
5
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
6
6
|
import { ExecutionError, extractCallStack, resolveAssertionMessageFromError, witnessMapToFields } from '@aztec/simulator/client';
|
|
7
7
|
import { countArgumentsSize } from '@aztec/stdlib/abi';
|
|
8
|
+
import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
|
|
8
9
|
import { PrivateCircuitPublicInputs } from '@aztec/stdlib/kernel';
|
|
9
|
-
import { SharedMutableValues, SharedMutableValuesWithHash } from '@aztec/stdlib/shared-mutable';
|
|
10
10
|
import { PrivateCallExecutionResult } from '@aztec/stdlib/tx';
|
|
11
11
|
import { Oracle } from './oracle.js';
|
|
12
12
|
/**
|
|
13
13
|
* Execute a private function and return the execution result.
|
|
14
|
+
* This does not execute any kernel circuits; only the user functions.
|
|
15
|
+
*
|
|
16
|
+
* If this private function execution results in any nested private function calls,
|
|
17
|
+
* those nested calls are made via oracle calls to the `privateCallPrivateFunction` oracle,
|
|
18
|
+
* which in turn makes corresponding further calls to this function.
|
|
14
19
|
*/ export async function executePrivateFunction(simulator, privateExecutionOracle, artifact, contractAddress, functionSelector, log = createLogger('simulator:private_execution')) {
|
|
15
20
|
const functionName = await privateExecutionOracle.getDebugFunctionName();
|
|
16
21
|
log.verbose(`Executing private function ${functionName}`, {
|
|
@@ -42,21 +47,21 @@ import { Oracle } from './oracle.js';
|
|
|
42
47
|
appCircuitName: functionName
|
|
43
48
|
});
|
|
44
49
|
const contractClassLogs = privateExecutionOracle.getContractClassLogs();
|
|
45
|
-
const rawReturnValues = await privateExecutionOracle.
|
|
50
|
+
const rawReturnValues = await privateExecutionOracle.privateLoadFromExecutionCache(publicInputs.returnsHash);
|
|
46
51
|
const noteHashLeafIndexMap = privateExecutionOracle.getNoteHashLeafIndexMap();
|
|
47
52
|
const newNotes = privateExecutionOracle.getNewNotes();
|
|
48
53
|
const noteHashNullifierCounterMap = privateExecutionOracle.getNoteHashNullifierCounterMap();
|
|
49
54
|
const offchainEffects = privateExecutionOracle.getOffchainEffects();
|
|
50
|
-
const
|
|
51
|
-
let timerSubtractionList =
|
|
55
|
+
const nestedExecutionResults = privateExecutionOracle.getNestedExecutionResults();
|
|
56
|
+
let timerSubtractionList = nestedExecutionResults;
|
|
52
57
|
let witgenTime = duration;
|
|
53
58
|
// Due to the recursive nature of execution, we have to subtract the time taken by nested calls
|
|
54
59
|
while(timerSubtractionList.length > 0){
|
|
55
60
|
witgenTime -= timerSubtractionList.reduce((acc, nested)=>acc + (nested.profileResult?.timings.witgen ?? 0), 0);
|
|
56
|
-
timerSubtractionList = timerSubtractionList.flatMap((nested)=>nested.
|
|
61
|
+
timerSubtractionList = timerSubtractionList.flatMap((nested)=>nested.nestedExecutionResults ?? []);
|
|
57
62
|
}
|
|
58
63
|
log.debug(`Returning from call to ${contractAddress.toString()}:${functionSelector}`);
|
|
59
|
-
return new PrivateCallExecutionResult(artifact.bytecode, Buffer.from(artifact.verificationKey, 'base64'), partialWitness, publicInputs, noteHashLeafIndexMap, newNotes, noteHashNullifierCounterMap, rawReturnValues, offchainEffects,
|
|
64
|
+
return new PrivateCallExecutionResult(artifact.bytecode, Buffer.from(artifact.verificationKey, 'base64'), partialWitness, publicInputs, noteHashLeafIndexMap, newNotes, noteHashNullifierCounterMap, rawReturnValues, offchainEffects, nestedExecutionResults, contractClassLogs, {
|
|
60
65
|
timings: {
|
|
61
66
|
witgen: witgenTime,
|
|
62
67
|
oracles: acirExecutionResult.oracles
|
|
@@ -88,13 +93,13 @@ import { Oracle } from './oracle.js';
|
|
|
88
93
|
* @param contractAddress - The address of the contract to read the class id for.
|
|
89
94
|
* @param instance - The instance of the contract.
|
|
90
95
|
* @param executionDataProvider - The execution data provider.
|
|
91
|
-
* @param blockNumber - The block number at which to load the
|
|
92
|
-
* @param timestamp - The timestamp at which to obtain the class id from the
|
|
96
|
+
* @param blockNumber - The block number at which to load the DelayedPublicMutable storing the class id.
|
|
97
|
+
* @param timestamp - The timestamp at which to obtain the class id from the DelayedPublicMutable.
|
|
93
98
|
* @returns The current class id.
|
|
94
99
|
*/ export async function readCurrentClassId(contractAddress, instance, executionDataProvider, blockNumber, timestamp) {
|
|
95
|
-
const {
|
|
96
|
-
const
|
|
97
|
-
let currentClassId =
|
|
100
|
+
const { delayedPublicMutableSlot } = await DelayedPublicMutableValuesWithHash.getContractUpdateSlots(contractAddress);
|
|
101
|
+
const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(delayedPublicMutableSlot, (slot)=>executionDataProvider.getPublicStorageAt(blockNumber, ProtocolContractAddress.ContractInstanceRegistry, slot));
|
|
102
|
+
let currentClassId = delayedPublicMutableValues.svc.getCurrentAt(timestamp)[0];
|
|
98
103
|
if (currentClassId.isZero()) {
|
|
99
104
|
currentClassId = instance.originalContractClassId;
|
|
100
105
|
}
|