@aztec/txe 0.0.1-fake-ceab37513c → 0.0.6-commit.a2d1860fe9
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/bin/index.d.ts +1 -1
- package/dest/bin/index.js +1 -1
- package/dest/constants.d.ts +3 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -0
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +90 -54
- package/dest/oracle/interfaces.d.ts +57 -0
- package/dest/oracle/interfaces.d.ts.map +1 -0
- package/dest/oracle/interfaces.js +3 -0
- package/dest/oracle/txe_oracle_public_context.d.ts +14 -14
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +36 -40
- package/dest/oracle/txe_oracle_top_level_context.d.ts +65 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_top_level_context.js +530 -0
- package/dest/rpc_translator.d.ts +252 -0
- package/dest/rpc_translator.d.ts.map +1 -0
- package/dest/{txe_service/txe_service.js → rpc_translator.js} +258 -156
- package/dest/state_machine/archiver.d.ts +21 -51
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +63 -94
- package/dest/state_machine/dummy_p2p_client.d.ts +20 -13
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +41 -21
- package/dest/state_machine/global_variable_builder.d.ts +6 -17
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +16 -23
- package/dest/state_machine/index.d.ts +7 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +42 -24
- package/dest/state_machine/mock_epoch_cache.d.ts +14 -10
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +21 -13
- package/dest/state_machine/synchronizer.d.ts +3 -2
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +5 -4
- package/dest/txe_session.d.ts +44 -48
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +314 -98
- package/dest/util/encoding.d.ts +616 -17
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/expected_failure_error.d.ts +1 -1
- package/dest/util/expected_failure_error.d.ts.map +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +9 -8
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +15 -30
- package/dest/utils/block_creation.d.ts +28 -0
- package/dest/utils/block_creation.d.ts.map +1 -0
- package/dest/utils/block_creation.js +58 -0
- package/dest/utils/tx_effect_creation.d.ts +5 -0
- package/dest/utils/tx_effect_creation.d.ts.map +1 -0
- package/dest/utils/tx_effect_creation.js +13 -0
- package/package.json +18 -17
- package/src/bin/index.ts +1 -1
- package/src/constants.ts +3 -0
- package/src/index.ts +102 -68
- package/src/oracle/interfaces.ts +86 -0
- package/src/oracle/txe_oracle_public_context.ts +40 -80
- package/src/oracle/txe_oracle_top_level_context.ts +756 -0
- package/src/{txe_service/txe_service.ts → rpc_translator.ts} +323 -161
- package/src/state_machine/archiver.ts +63 -117
- package/src/state_machine/dummy_p2p_client.ts +58 -28
- package/src/state_machine/global_variable_builder.ts +25 -42
- package/src/state_machine/index.ts +65 -24
- package/src/state_machine/mock_epoch_cache.ts +25 -20
- package/src/state_machine/synchronizer.ts +6 -5
- package/src/txe_session.ts +441 -121
- package/src/util/encoding.ts +1 -1
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/txe_public_contract_data_source.ts +23 -46
- package/src/utils/block_creation.ts +97 -0
- package/src/utils/tx_effect_creation.ts +30 -0
- package/dest/oracle/txe_oracle.d.ts +0 -124
- package/dest/oracle/txe_oracle.d.ts.map +0 -1
- package/dest/oracle/txe_oracle.js +0 -770
- package/dest/oracle/txe_typed_oracle.d.ts +0 -42
- package/dest/oracle/txe_typed_oracle.d.ts.map +0 -1
- package/dest/oracle/txe_typed_oracle.js +0 -83
- package/dest/txe_constants.d.ts +0 -2
- package/dest/txe_constants.d.ts.map +0 -1
- package/dest/txe_constants.js +0 -7
- package/dest/txe_service/txe_service.d.ts +0 -231
- package/dest/txe_service/txe_service.d.ts.map +0 -1
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -11
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.js +0 -22
- package/src/oracle/txe_oracle.ts +0 -1287
- package/src/oracle/txe_typed_oracle.ts +0 -142
- package/src/txe_constants.ts +0 -9
- package/src/util/txe_contract_data_provider.ts +0 -35
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import { Fr, Point } from '@aztec/aztec.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Fr, Point } from '@aztec/aztec.js/fields';
|
|
2
|
+
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX } from '@aztec/constants';
|
|
3
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { packAsHintedNote } from '@aztec/pxe/simulator';
|
|
5
|
+
import { EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
4
6
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import {
|
|
6
|
-
import { addressFromSingle, arrayOfArraysToBoundedVecOfArrays, arrayToBoundedVec, bufferToU8Array, fromArray, fromSingle, fromUintArray, fromUintBoundedVec, toArray, toForeignCallResult, toSingle } from '
|
|
7
|
-
|
|
7
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
8
|
+
import { addressFromSingle, arrayOfArraysToBoundedVecOfArrays, arrayToBoundedVec, bufferToU8Array, fromArray, fromSingle, fromUintArray, fromUintBoundedVec, toArray, toForeignCallResult, toSingle } from './util/encoding.js';
|
|
9
|
+
const MAX_EVENT_LEN = 12; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_RESERVED_FIELDS
|
|
10
|
+
const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
|
|
11
|
+
export class UnavailableOracleError extends Error {
|
|
12
|
+
constructor(oracleName){
|
|
13
|
+
super(`${oracleName} oracles not available with the current handler`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class RPCTranslator {
|
|
8
17
|
stateHandler;
|
|
9
18
|
oracleHandler;
|
|
10
19
|
/**
|
|
11
|
-
* Create a new instance of `
|
|
20
|
+
* Create a new instance of `RPCTranslator` that will translate all TXE RPC calls to and from the foreign
|
|
12
21
|
* (`ForeignCallSingle`, `ForeignCallResult`, etc.) and native TS types, delegating actual execution of the oracles
|
|
13
22
|
* to the different handlers.
|
|
14
23
|
* @param stateHandler The handler that will process TXE session state transitions, such as entering a private or
|
|
@@ -19,42 +28,92 @@ export class TXEService {
|
|
|
19
28
|
this.stateHandler = stateHandler;
|
|
20
29
|
this.oracleHandler = oracleHandler;
|
|
21
30
|
}
|
|
31
|
+
// Note: If you rename the following functions to not start with "handlerAs", you must also update the validation
|
|
32
|
+
// check in `TXESession.processFunction`.
|
|
33
|
+
handlerAsMisc() {
|
|
34
|
+
if (!('isMisc' in this.oracleHandler)) {
|
|
35
|
+
throw new UnavailableOracleError('Misc');
|
|
36
|
+
}
|
|
37
|
+
return this.oracleHandler;
|
|
38
|
+
}
|
|
39
|
+
handlerAsUtility() {
|
|
40
|
+
if (!('isUtility' in this.oracleHandler)) {
|
|
41
|
+
throw new UnavailableOracleError('Utility');
|
|
42
|
+
}
|
|
43
|
+
return this.oracleHandler;
|
|
44
|
+
}
|
|
45
|
+
handlerAsPrivate() {
|
|
46
|
+
if (!('isPrivate' in this.oracleHandler)) {
|
|
47
|
+
throw new UnavailableOracleError('Private');
|
|
48
|
+
}
|
|
49
|
+
return this.oracleHandler;
|
|
50
|
+
}
|
|
51
|
+
handlerAsAvm() {
|
|
52
|
+
if (!('isAvm' in this.oracleHandler)) {
|
|
53
|
+
throw new UnavailableOracleError('Avm');
|
|
54
|
+
}
|
|
55
|
+
return this.oracleHandler;
|
|
56
|
+
}
|
|
57
|
+
handlerAsTxe() {
|
|
58
|
+
if (!('isTxe' in this.oracleHandler)) {
|
|
59
|
+
throw new UnavailableOracleError('Txe');
|
|
60
|
+
}
|
|
61
|
+
return this.oracleHandler;
|
|
62
|
+
}
|
|
22
63
|
// TXE session state transition functions - these get handled by the state handler
|
|
23
64
|
async txeSetTopLevelTXEContext() {
|
|
24
|
-
await this.stateHandler.
|
|
65
|
+
await this.stateHandler.enterTopLevelState();
|
|
25
66
|
return toForeignCallResult([]);
|
|
26
67
|
}
|
|
27
|
-
async txeSetPrivateTXEContext(foreignContractAddressIsSome, foreignContractAddressValue,
|
|
68
|
+
async txeSetPrivateTXEContext(foreignContractAddressIsSome, foreignContractAddressValue, foreignAnchorBlockNumberIsSome, foreignAnchorBlockNumberValue) {
|
|
28
69
|
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignContractAddressValue)) : undefined;
|
|
29
|
-
const
|
|
30
|
-
const privateContextInputs = await this.stateHandler.
|
|
70
|
+
const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool() ? BlockNumber(fromSingle(foreignAnchorBlockNumberValue).toNumber()) : undefined;
|
|
71
|
+
const privateContextInputs = await this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber);
|
|
31
72
|
return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
|
|
32
73
|
}
|
|
33
74
|
async txeSetPublicTXEContext(foreignContractAddressIsSome, foreignContractAddressValue) {
|
|
34
75
|
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignContractAddressValue)) : undefined;
|
|
35
|
-
await this.stateHandler.
|
|
76
|
+
await this.stateHandler.enterPublicState(contractAddress);
|
|
36
77
|
return toForeignCallResult([]);
|
|
37
78
|
}
|
|
38
79
|
async txeSetUtilityTXEContext(foreignContractAddressIsSome, foreignContractAddressValue) {
|
|
39
80
|
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignContractAddressValue)) : undefined;
|
|
40
|
-
await this.stateHandler.
|
|
81
|
+
await this.stateHandler.enterUtilityState(contractAddress);
|
|
41
82
|
return toForeignCallResult([]);
|
|
42
83
|
}
|
|
43
84
|
// Other oracles - these get handled by the oracle handler
|
|
44
85
|
// TXE-specific oracles
|
|
86
|
+
txeGetDefaultAddress() {
|
|
87
|
+
const defaultAddress = this.handlerAsTxe().txeGetDefaultAddress();
|
|
88
|
+
return toForeignCallResult([
|
|
89
|
+
toSingle(defaultAddress)
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
async txeGetNextBlockNumber() {
|
|
93
|
+
const nextBlockNumber = await this.handlerAsTxe().txeGetNextBlockNumber();
|
|
94
|
+
return toForeignCallResult([
|
|
95
|
+
toSingle(nextBlockNumber)
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
async txeGetNextBlockTimestamp() {
|
|
99
|
+
const nextBlockTimestamp = await this.handlerAsTxe().txeGetNextBlockTimestamp();
|
|
100
|
+
return toForeignCallResult([
|
|
101
|
+
toSingle(nextBlockTimestamp)
|
|
102
|
+
]);
|
|
103
|
+
}
|
|
45
104
|
async txeAdvanceBlocksBy(foreignBlocks) {
|
|
46
105
|
const blocks = fromSingle(foreignBlocks).toNumber();
|
|
47
|
-
await this.
|
|
106
|
+
await this.handlerAsTxe().txeAdvanceBlocksBy(blocks);
|
|
48
107
|
return toForeignCallResult([]);
|
|
49
108
|
}
|
|
50
109
|
txeAdvanceTimestampBy(foreignDuration) {
|
|
51
110
|
const duration = fromSingle(foreignDuration).toBigInt();
|
|
52
|
-
this.
|
|
111
|
+
this.handlerAsTxe().txeAdvanceTimestampBy(duration);
|
|
53
112
|
return toForeignCallResult([]);
|
|
54
113
|
}
|
|
55
114
|
async txeDeploy(artifact, instance, foreignSecret) {
|
|
56
115
|
const secret = fromSingle(foreignSecret);
|
|
57
|
-
await this.
|
|
116
|
+
await this.handlerAsTxe().txeDeploy(artifact, instance, secret);
|
|
58
117
|
return toForeignCallResult([
|
|
59
118
|
toArray([
|
|
60
119
|
instance.salt,
|
|
@@ -67,7 +126,7 @@ export class TXEService {
|
|
|
67
126
|
}
|
|
68
127
|
async txeCreateAccount(foreignSecret) {
|
|
69
128
|
const secret = fromSingle(foreignSecret);
|
|
70
|
-
const completeAddress = await this.
|
|
129
|
+
const completeAddress = await this.handlerAsTxe().txeCreateAccount(secret);
|
|
71
130
|
return toForeignCallResult([
|
|
72
131
|
toSingle(completeAddress.address),
|
|
73
132
|
...completeAddress.publicKeys.toFields().map(toSingle)
|
|
@@ -75,7 +134,7 @@ export class TXEService {
|
|
|
75
134
|
}
|
|
76
135
|
async txeAddAccount(artifact, instance, foreignSecret) {
|
|
77
136
|
const secret = fromSingle(foreignSecret);
|
|
78
|
-
const completeAddress = await this.
|
|
137
|
+
const completeAddress = await this.handlerAsTxe().txeAddAccount(artifact, instance, secret);
|
|
79
138
|
return toForeignCallResult([
|
|
80
139
|
toSingle(completeAddress.address),
|
|
81
140
|
...completeAddress.publicKeys.toFields().map(toSingle)
|
|
@@ -84,87 +143,101 @@ export class TXEService {
|
|
|
84
143
|
async txeAddAuthWitness(foreignAddress, foreignMessageHash) {
|
|
85
144
|
const address = addressFromSingle(foreignAddress);
|
|
86
145
|
const messageHash = fromSingle(foreignMessageHash);
|
|
87
|
-
await this.
|
|
146
|
+
await this.handlerAsTxe().txeAddAuthWitness(address, messageHash);
|
|
88
147
|
return toForeignCallResult([]);
|
|
89
148
|
}
|
|
90
149
|
// PXE oracles
|
|
91
150
|
utilityAssertCompatibleOracleVersion(foreignVersion) {
|
|
92
151
|
const version = fromSingle(foreignVersion).toNumber();
|
|
93
|
-
this.
|
|
152
|
+
this.handlerAsMisc().utilityAssertCompatibleOracleVersion(version);
|
|
94
153
|
return toForeignCallResult([]);
|
|
95
154
|
}
|
|
96
155
|
utilityGetRandomField() {
|
|
97
|
-
const randomField = this.
|
|
156
|
+
const randomField = this.handlerAsMisc().utilityGetRandomField();
|
|
98
157
|
return toForeignCallResult([
|
|
99
158
|
toSingle(randomField)
|
|
100
159
|
]);
|
|
101
160
|
}
|
|
102
|
-
async
|
|
103
|
-
const
|
|
104
|
-
return toForeignCallResult([
|
|
105
|
-
toSingle(contractAddress.toField())
|
|
106
|
-
]);
|
|
107
|
-
}
|
|
108
|
-
async utilityGetBlockNumber() {
|
|
109
|
-
const blockNumber = await this.oracleHandler.utilityGetBlockNumber();
|
|
161
|
+
async txeGetLastBlockTimestamp() {
|
|
162
|
+
const timestamp = await this.handlerAsTxe().txeGetLastBlockTimestamp();
|
|
110
163
|
return toForeignCallResult([
|
|
111
|
-
toSingle(new Fr(
|
|
164
|
+
toSingle(new Fr(timestamp))
|
|
112
165
|
]);
|
|
113
166
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const timestamp = await this.oracleHandler.utilityGetTimestamp();
|
|
167
|
+
async txeGetLastTxEffects() {
|
|
168
|
+
const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().txeGetLastTxEffects();
|
|
117
169
|
return toForeignCallResult([
|
|
118
|
-
toSingle(
|
|
170
|
+
toSingle(txHash.hash),
|
|
171
|
+
...arrayToBoundedVec(toArray(noteHashes), MAX_NOTE_HASHES_PER_TX),
|
|
172
|
+
...arrayToBoundedVec(toArray(nullifiers), MAX_NULLIFIERS_PER_TX)
|
|
119
173
|
]);
|
|
120
174
|
}
|
|
121
|
-
async
|
|
122
|
-
const
|
|
175
|
+
async txeGetPrivateEvents(foreignSelector, foreignContractAddress, foreignScope) {
|
|
176
|
+
const selector = EventSelector.fromField(fromSingle(foreignSelector));
|
|
177
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
178
|
+
const scope = addressFromSingle(foreignScope);
|
|
179
|
+
const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
|
|
180
|
+
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
181
|
+
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
182
|
+
}
|
|
183
|
+
if (events.some((e)=>e.length > MAX_EVENT_LEN)) {
|
|
184
|
+
throw new Error(`Some private event has length larger than maxLen ${MAX_EVENT_LEN}`);
|
|
185
|
+
}
|
|
186
|
+
// This is a workaround as Noir does not currently let us return nested structs with arrays. We instead return a raw
|
|
187
|
+
// multidimensional array in get_private_events_oracle and create the BoundedVecs here.
|
|
188
|
+
const rawArrayStorage = events.map((e)=>e.concat(Array(MAX_EVENT_LEN - e.length).fill(new Fr(0)))).concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(Array(MAX_EVENT_LEN).fill(new Fr(0)))).flat();
|
|
189
|
+
const eventLengths = events.map((e)=>new Fr(e.length)).concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(new Fr(0)));
|
|
190
|
+
const queryLength = new Fr(events.length);
|
|
123
191
|
return toForeignCallResult([
|
|
124
|
-
|
|
192
|
+
toArray(rawArrayStorage),
|
|
193
|
+
toArray(eventLengths),
|
|
194
|
+
toSingle(queryLength)
|
|
125
195
|
]);
|
|
126
196
|
}
|
|
127
|
-
|
|
128
|
-
privateStoreInExecutionCache(_foreignLength, foreignValues, foreignHash) {
|
|
197
|
+
privateStoreInExecutionCache(foreignValues, foreignHash) {
|
|
129
198
|
const values = fromArray(foreignValues);
|
|
130
199
|
const hash = fromSingle(foreignHash);
|
|
131
|
-
this.
|
|
200
|
+
this.handlerAsPrivate().privateStoreInExecutionCache(values, hash);
|
|
132
201
|
return toForeignCallResult([]);
|
|
133
202
|
}
|
|
134
203
|
async privateLoadFromExecutionCache(foreignHash) {
|
|
135
204
|
const hash = fromSingle(foreignHash);
|
|
136
|
-
const returns = await this.
|
|
205
|
+
const returns = await this.handlerAsPrivate().privateLoadFromExecutionCache(hash);
|
|
137
206
|
return toForeignCallResult([
|
|
138
207
|
toArray(returns)
|
|
139
208
|
]);
|
|
140
209
|
}
|
|
141
|
-
//
|
|
142
|
-
|
|
210
|
+
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
211
|
+
// When the argument is an array, we add the field length manually to the signature.
|
|
212
|
+
async utilityLog(foreignLevel, foreignMessage, _foreignLength, foreignFields) {
|
|
213
|
+
const level = fromSingle(foreignLevel).toNumber();
|
|
143
214
|
const message = fromArray(foreignMessage).map((field)=>String.fromCharCode(field.toNumber())).join('');
|
|
144
215
|
const fields = fromArray(foreignFields);
|
|
145
|
-
this.
|
|
216
|
+
await this.handlerAsMisc().utilityLog(level, message, fields);
|
|
146
217
|
return toForeignCallResult([]);
|
|
147
218
|
}
|
|
148
|
-
async utilityStorageRead(foreignContractAddress, foreignStartStorageSlot,
|
|
219
|
+
async utilityStorageRead(foreignBlockHash, foreignContractAddress, foreignStartStorageSlot, foreignNumberOfElements) {
|
|
220
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
149
221
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
150
222
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
151
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
152
223
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
153
|
-
const values = await this.
|
|
224
|
+
const values = await this.handlerAsUtility().utilityStorageRead(blockHash, contractAddress, startStorageSlot, numberOfElements);
|
|
154
225
|
return toForeignCallResult([
|
|
155
226
|
toArray(values)
|
|
156
227
|
]);
|
|
157
228
|
}
|
|
158
|
-
async utilityGetPublicDataWitness(
|
|
159
|
-
const
|
|
229
|
+
async utilityGetPublicDataWitness(foreignBlockHash, foreignLeafSlot) {
|
|
230
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
160
231
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
161
|
-
const witness = await this.
|
|
232
|
+
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
|
|
162
233
|
if (!witness) {
|
|
163
|
-
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${
|
|
234
|
+
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
|
|
164
235
|
}
|
|
165
236
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
166
237
|
}
|
|
167
|
-
async utilityGetNotes(foreignStorageSlot, foreignNumSelects, foreignSelectByIndexes, foreignSelectByOffsets, foreignSelectByLengths, foreignSelectValues, foreignSelectComparators, foreignSortByIndexes, foreignSortByOffsets, foreignSortByLengths, foreignSortOrder, foreignLimit, foreignOffset, foreignStatus, foreignMaxNotes,
|
|
238
|
+
async utilityGetNotes(foreignOwnerIsSome, foreignOwnerValue, foreignStorageSlot, foreignNumSelects, foreignSelectByIndexes, foreignSelectByOffsets, foreignSelectByLengths, foreignSelectValues, foreignSelectComparators, foreignSortByIndexes, foreignSortByOffsets, foreignSortByLengths, foreignSortOrder, foreignLimit, foreignOffset, foreignStatus, foreignMaxNotes, foreignPackedHintedNoteLength) {
|
|
239
|
+
// Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
|
|
240
|
+
const owner = fromSingle(foreignOwnerIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignOwnerValue)) : undefined;
|
|
168
241
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
169
242
|
const numSelects = fromSingle(foreignNumSelects).toNumber();
|
|
170
243
|
const selectByIndexes = fromArray(foreignSelectByIndexes).map((fr)=>fr.toNumber());
|
|
@@ -180,45 +253,63 @@ export class TXEService {
|
|
|
180
253
|
const offset = fromSingle(foreignOffset).toNumber();
|
|
181
254
|
const status = fromSingle(foreignStatus).toNumber();
|
|
182
255
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
183
|
-
const
|
|
184
|
-
const noteDatas = await this.
|
|
185
|
-
const returnDataAsArrayOfArrays = noteDatas.map(
|
|
256
|
+
const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
|
|
257
|
+
const noteDatas = await this.handlerAsUtility().utilityGetNotes(owner, storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status);
|
|
258
|
+
const returnDataAsArrayOfArrays = noteDatas.map((noteData)=>packAsHintedNote({
|
|
259
|
+
contractAddress: noteData.contractAddress,
|
|
260
|
+
owner: noteData.owner,
|
|
261
|
+
randomness: noteData.randomness,
|
|
262
|
+
storageSlot: noteData.storageSlot,
|
|
263
|
+
noteNonce: noteData.noteNonce,
|
|
264
|
+
isPending: noteData.isPending,
|
|
265
|
+
note: noteData.note
|
|
266
|
+
}));
|
|
186
267
|
// Now we convert each sub-array to an array of ForeignCallSingles
|
|
187
268
|
const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map((subArray)=>subArray.map(toSingle));
|
|
188
269
|
// At last we convert the array of arrays to a bounded vec of arrays
|
|
189
|
-
return toForeignCallResult(arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes,
|
|
270
|
+
return toForeignCallResult(arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength));
|
|
190
271
|
}
|
|
191
|
-
privateNotifyCreatedNote(foreignStorageSlot, foreignNoteTypeId, foreignNote, foreignNoteHash, foreignCounter) {
|
|
272
|
+
privateNotifyCreatedNote(foreignOwner, foreignStorageSlot, foreignRandomness, foreignNoteTypeId, foreignNote, foreignNoteHash, foreignCounter) {
|
|
273
|
+
const owner = addressFromSingle(foreignOwner);
|
|
192
274
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
275
|
+
const randomness = fromSingle(foreignRandomness);
|
|
193
276
|
const noteTypeId = NoteSelector.fromField(fromSingle(foreignNoteTypeId));
|
|
194
277
|
const note = fromArray(foreignNote);
|
|
195
278
|
const noteHash = fromSingle(foreignNoteHash);
|
|
196
279
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
197
|
-
this.
|
|
280
|
+
this.handlerAsPrivate().privateNotifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
|
|
198
281
|
return toForeignCallResult([]);
|
|
199
282
|
}
|
|
200
283
|
async privateNotifyNullifiedNote(foreignInnerNullifier, foreignNoteHash, foreignCounter) {
|
|
201
284
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
202
285
|
const noteHash = fromSingle(foreignNoteHash);
|
|
203
286
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
204
|
-
await this.
|
|
287
|
+
await this.handlerAsPrivate().privateNotifyNullifiedNote(innerNullifier, noteHash, counter);
|
|
205
288
|
return toForeignCallResult([]);
|
|
206
289
|
}
|
|
207
290
|
async privateNotifyCreatedNullifier(foreignInnerNullifier) {
|
|
208
291
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
209
|
-
await this.
|
|
292
|
+
await this.handlerAsPrivate().privateNotifyCreatedNullifier(innerNullifier);
|
|
210
293
|
return toForeignCallResult([]);
|
|
211
294
|
}
|
|
295
|
+
async privateIsNullifierPending(foreignInnerNullifier, foreignContractAddress) {
|
|
296
|
+
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
297
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
298
|
+
const isPending = await this.handlerAsPrivate().privateIsNullifierPending(innerNullifier, contractAddress);
|
|
299
|
+
return toForeignCallResult([
|
|
300
|
+
toSingle(new Fr(isPending))
|
|
301
|
+
]);
|
|
302
|
+
}
|
|
212
303
|
async utilityCheckNullifierExists(foreignInnerNullifier) {
|
|
213
304
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
214
|
-
const exists = await this.
|
|
305
|
+
const exists = await this.handlerAsUtility().utilityCheckNullifierExists(innerNullifier);
|
|
215
306
|
return toForeignCallResult([
|
|
216
307
|
toSingle(new Fr(exists))
|
|
217
308
|
]);
|
|
218
309
|
}
|
|
219
310
|
async utilityGetContractInstance(foreignAddress) {
|
|
220
311
|
const address = addressFromSingle(foreignAddress);
|
|
221
|
-
const instance = await this.
|
|
312
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
222
313
|
return toForeignCallResult([
|
|
223
314
|
instance.salt,
|
|
224
315
|
instance.deployer.toField(),
|
|
@@ -227,36 +318,48 @@ export class TXEService {
|
|
|
227
318
|
...instance.publicKeys.toFields()
|
|
228
319
|
].map(toSingle));
|
|
229
320
|
}
|
|
230
|
-
async
|
|
321
|
+
async utilityTryGetPublicKeysAndPartialAddress(foreignAddress) {
|
|
231
322
|
const address = addressFromSingle(foreignAddress);
|
|
232
|
-
const
|
|
233
|
-
return
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
323
|
+
const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(address);
|
|
324
|
+
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
325
|
+
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
326
|
+
if (result === undefined) {
|
|
327
|
+
// No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
|
|
328
|
+
return toForeignCallResult([
|
|
329
|
+
toSingle(new Fr(0)),
|
|
330
|
+
toArray(Array(13).fill(new Fr(0)))
|
|
331
|
+
]);
|
|
332
|
+
} else {
|
|
333
|
+
// Data was found so we set `some` to 1 and return it along with `value`.
|
|
334
|
+
return toForeignCallResult([
|
|
335
|
+
toSingle(new Fr(1)),
|
|
336
|
+
toArray([
|
|
337
|
+
...result.publicKeys.toFields(),
|
|
338
|
+
result.partialAddress
|
|
339
|
+
])
|
|
340
|
+
]);
|
|
341
|
+
}
|
|
239
342
|
}
|
|
240
343
|
async utilityGetKeyValidationRequest(foreignPkMHash) {
|
|
241
344
|
const pkMHash = fromSingle(foreignPkMHash);
|
|
242
|
-
const keyValidationRequest = await this.
|
|
345
|
+
const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
|
|
243
346
|
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
244
347
|
}
|
|
245
348
|
privateCallPrivateFunction(_foreignTargetContractAddress, _foreignFunctionSelector, _foreignArgsHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
|
|
246
349
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::private_context`, use `private_call` instead');
|
|
247
350
|
}
|
|
248
|
-
async utilityGetNullifierMembershipWitness(
|
|
249
|
-
const
|
|
351
|
+
async utilityGetNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
|
|
352
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
250
353
|
const nullifier = fromSingle(foreignNullifier);
|
|
251
|
-
const witness = await this.
|
|
354
|
+
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
|
|
252
355
|
if (!witness) {
|
|
253
|
-
throw new Error(`Nullifier membership witness not found at block ${
|
|
356
|
+
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
254
357
|
}
|
|
255
358
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
256
359
|
}
|
|
257
360
|
async utilityGetAuthWitness(foreignMessageHash) {
|
|
258
361
|
const messageHash = fromSingle(foreignMessageHash);
|
|
259
|
-
const authWitness = await this.
|
|
362
|
+
const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
|
|
260
363
|
if (!authWitness) {
|
|
261
364
|
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
262
365
|
}
|
|
@@ -273,85 +376,83 @@ export class TXEService {
|
|
|
273
376
|
privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter) {
|
|
274
377
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
275
378
|
}
|
|
276
|
-
async
|
|
277
|
-
const
|
|
379
|
+
async privateIsSideEffectCounterRevertible(foreignSideEffectCounter) {
|
|
380
|
+
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
381
|
+
const isRevertible = await this.handlerAsPrivate().privateIsSideEffectCounterRevertible(sideEffectCounter);
|
|
278
382
|
return toForeignCallResult([
|
|
279
|
-
toSingle(
|
|
383
|
+
toSingle(new Fr(isRevertible))
|
|
280
384
|
]);
|
|
281
385
|
}
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
return toForeignCallResult(
|
|
285
|
-
toSingle(version)
|
|
286
|
-
]);
|
|
386
|
+
utilityGetUtilityContext() {
|
|
387
|
+
const context = this.handlerAsUtility().utilityGetUtilityContext();
|
|
388
|
+
return toForeignCallResult(context.toNoirRepresentation());
|
|
287
389
|
}
|
|
288
390
|
async utilityGetBlockHeader(foreignBlockNumber) {
|
|
289
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
290
|
-
const header = await this.
|
|
391
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
392
|
+
const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
|
|
291
393
|
if (!header) {
|
|
292
394
|
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
293
395
|
}
|
|
294
396
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
295
397
|
}
|
|
296
|
-
async
|
|
297
|
-
const
|
|
298
|
-
const
|
|
299
|
-
const
|
|
300
|
-
const witness = await this.oracleHandler.utilityGetMembershipWitness(blockNumber, treeId, leafValue);
|
|
398
|
+
async utilityGetNoteHashMembershipWitness(foreignAnchorBlockHash, foreignNoteHash) {
|
|
399
|
+
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
400
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
401
|
+
const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, noteHash);
|
|
301
402
|
if (!witness) {
|
|
302
|
-
throw new Error(`
|
|
403
|
+
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
303
404
|
}
|
|
304
|
-
return toForeignCallResult(
|
|
305
|
-
toSingle(witness[0]),
|
|
306
|
-
toArray(witness.slice(1))
|
|
307
|
-
]);
|
|
405
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
308
406
|
}
|
|
309
|
-
async
|
|
310
|
-
const
|
|
311
|
-
const
|
|
312
|
-
const witness = await this.
|
|
407
|
+
async utilityGetBlockHashMembershipWitness(foreignAnchorBlockHash, foreignBlockHash) {
|
|
408
|
+
const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
409
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
410
|
+
const witness = await this.handlerAsUtility().utilityGetBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
313
411
|
if (!witness) {
|
|
314
|
-
throw new Error(`
|
|
412
|
+
throw new Error(`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`);
|
|
315
413
|
}
|
|
316
414
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
317
415
|
}
|
|
318
|
-
async
|
|
319
|
-
const
|
|
320
|
-
const
|
|
321
|
-
const
|
|
322
|
-
|
|
416
|
+
async utilityGetLowNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
|
|
417
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
418
|
+
const nullifier = fromSingle(foreignNullifier);
|
|
419
|
+
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
|
|
420
|
+
if (!witness) {
|
|
421
|
+
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
422
|
+
}
|
|
423
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
323
424
|
}
|
|
324
425
|
async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot) {
|
|
325
426
|
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
326
|
-
await this.
|
|
427
|
+
await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
|
|
327
428
|
return toForeignCallResult([]);
|
|
328
429
|
}
|
|
329
|
-
async
|
|
430
|
+
async utilityValidateAndStoreEnqueuedNotesAndEvents(foreignContractAddress, foreignNoteValidationRequestsArrayBaseSlot, foreignEventValidationRequestsArrayBaseSlot) {
|
|
330
431
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
331
432
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
332
433
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
333
|
-
await this.
|
|
434
|
+
await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot);
|
|
334
435
|
return toForeignCallResult([]);
|
|
335
436
|
}
|
|
336
437
|
async utilityBulkRetrieveLogs(foreignContractAddress, foreignLogRetrievalRequestsArrayBaseSlot, foreignLogRetrievalResponsesArrayBaseSlot) {
|
|
337
438
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
338
439
|
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
339
440
|
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
340
|
-
await this.
|
|
441
|
+
await this.handlerAsUtility().utilityBulkRetrieveLogs(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot);
|
|
341
442
|
return toForeignCallResult([]);
|
|
342
443
|
}
|
|
343
444
|
async utilityStoreCapsule(foreignContractAddress, foreignSlot, foreignCapsule) {
|
|
344
445
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
345
446
|
const slot = fromSingle(foreignSlot);
|
|
346
447
|
const capsule = fromArray(foreignCapsule);
|
|
347
|
-
await this.
|
|
448
|
+
await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
|
|
348
449
|
return toForeignCallResult([]);
|
|
349
450
|
}
|
|
350
451
|
async utilityLoadCapsule(foreignContractAddress, foreignSlot, foreignTSize) {
|
|
351
452
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
352
453
|
const slot = fromSingle(foreignSlot);
|
|
353
454
|
const tSize = fromSingle(foreignTSize).toNumber();
|
|
354
|
-
const values = await this.
|
|
455
|
+
const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
|
|
355
456
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
356
457
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
357
458
|
if (values === null) {
|
|
@@ -371,7 +472,7 @@ export class TXEService {
|
|
|
371
472
|
async utilityDeleteCapsule(foreignContractAddress, foreignSlot) {
|
|
372
473
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
373
474
|
const slot = fromSingle(foreignSlot);
|
|
374
|
-
await this.
|
|
475
|
+
await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
|
|
375
476
|
return toForeignCallResult([]);
|
|
376
477
|
}
|
|
377
478
|
async utilityCopyCapsule(foreignContractAddress, foreignSrcSlot, foreignDstSlot, foreignNumEntries) {
|
|
@@ -379,7 +480,7 @@ export class TXEService {
|
|
|
379
480
|
const srcSlot = fromSingle(foreignSrcSlot);
|
|
380
481
|
const dstSlot = fromSingle(foreignDstSlot);
|
|
381
482
|
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
382
|
-
await this.
|
|
483
|
+
await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
|
|
383
484
|
return toForeignCallResult([]);
|
|
384
485
|
}
|
|
385
486
|
// TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
|
|
@@ -390,7 +491,7 @@ export class TXEService {
|
|
|
390
491
|
const ciphertext = fromUintBoundedVec(foreignCiphertextBVecStorage, foreignCiphertextLength, 8);
|
|
391
492
|
const iv = fromUintArray(foreignIv, 8);
|
|
392
493
|
const symKey = fromUintArray(foreignSymKey, 8);
|
|
393
|
-
const plaintextBuffer = await this.
|
|
494
|
+
const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
|
|
394
495
|
return toForeignCallResult(arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length));
|
|
395
496
|
}
|
|
396
497
|
async utilityGetSharedSecret(foreignAddress, foreignEphPKField0, foreignEphPKField1, foreignEphPKField2) {
|
|
@@ -400,20 +501,21 @@ export class TXEService {
|
|
|
400
501
|
fromSingle(foreignEphPKField1),
|
|
401
502
|
fromSingle(foreignEphPKField2)
|
|
402
503
|
]);
|
|
403
|
-
const secret = await this.
|
|
504
|
+
const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
|
|
404
505
|
return toForeignCallResult(secret.toFields().map(toSingle));
|
|
405
506
|
}
|
|
406
507
|
emitOffchainEffect(_foreignData) {
|
|
407
508
|
throw new Error('Offchain effects are not yet supported in the TestEnvironment');
|
|
408
509
|
}
|
|
409
510
|
// AVM opcodes
|
|
410
|
-
|
|
511
|
+
avmOpcodeEmitPublicLog(_foreignMessage) {
|
|
411
512
|
// TODO(#8811): Implement
|
|
412
513
|
return toForeignCallResult([]);
|
|
413
514
|
}
|
|
414
|
-
async avmOpcodeStorageRead(foreignSlot) {
|
|
515
|
+
async avmOpcodeStorageRead(foreignSlot, foreignContractAddress) {
|
|
415
516
|
const slot = fromSingle(foreignSlot);
|
|
416
|
-
const
|
|
517
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
518
|
+
const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
|
|
417
519
|
return toForeignCallResult([
|
|
418
520
|
toSingle(new Fr(value))
|
|
419
521
|
]);
|
|
@@ -421,12 +523,12 @@ export class TXEService {
|
|
|
421
523
|
async avmOpcodeStorageWrite(foreignSlot, foreignValue) {
|
|
422
524
|
const slot = fromSingle(foreignSlot);
|
|
423
525
|
const value = fromSingle(foreignValue);
|
|
424
|
-
await this.
|
|
526
|
+
await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
|
|
425
527
|
return toForeignCallResult([]);
|
|
426
528
|
}
|
|
427
529
|
async avmOpcodeGetContractInstanceDeployer(foreignAddress) {
|
|
428
530
|
const address = addressFromSingle(foreignAddress);
|
|
429
|
-
const instance = await this.
|
|
531
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
430
532
|
return toForeignCallResult([
|
|
431
533
|
toSingle(instance.deployer),
|
|
432
534
|
// AVM requires an extra boolean indicating the instance was found
|
|
@@ -435,7 +537,7 @@ export class TXEService {
|
|
|
435
537
|
}
|
|
436
538
|
async avmOpcodeGetContractInstanceClassId(foreignAddress) {
|
|
437
539
|
const address = addressFromSingle(foreignAddress);
|
|
438
|
-
const instance = await this.
|
|
540
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
439
541
|
return toForeignCallResult([
|
|
440
542
|
toSingle(instance.currentContractClassId),
|
|
441
543
|
// AVM requires an extra boolean indicating the instance was found
|
|
@@ -444,69 +546,68 @@ export class TXEService {
|
|
|
444
546
|
}
|
|
445
547
|
async avmOpcodeGetContractInstanceInitializationHash(foreignAddress) {
|
|
446
548
|
const address = addressFromSingle(foreignAddress);
|
|
447
|
-
const instance = await this.
|
|
549
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
448
550
|
return toForeignCallResult([
|
|
449
551
|
toSingle(instance.initializationHash),
|
|
450
552
|
// AVM requires an extra boolean indicating the instance was found
|
|
451
553
|
toSingle(new Fr(1))
|
|
452
554
|
]);
|
|
453
555
|
}
|
|
454
|
-
avmOpcodeSender() {
|
|
455
|
-
const sender = this.
|
|
556
|
+
async avmOpcodeSender() {
|
|
557
|
+
const sender = await this.handlerAsAvm().avmOpcodeSender();
|
|
456
558
|
return toForeignCallResult([
|
|
457
559
|
toSingle(sender)
|
|
458
560
|
]);
|
|
459
561
|
}
|
|
460
562
|
async avmOpcodeEmitNullifier(foreignNullifier) {
|
|
461
563
|
const nullifier = fromSingle(foreignNullifier);
|
|
462
|
-
await this.
|
|
564
|
+
await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
|
|
463
565
|
return toForeignCallResult([]);
|
|
464
566
|
}
|
|
465
567
|
async avmOpcodeEmitNoteHash(foreignNoteHash) {
|
|
466
568
|
const noteHash = fromSingle(foreignNoteHash);
|
|
467
|
-
await this.
|
|
569
|
+
await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
|
|
468
570
|
return toForeignCallResult([]);
|
|
469
571
|
}
|
|
470
|
-
async avmOpcodeNullifierExists(
|
|
471
|
-
const
|
|
472
|
-
const
|
|
473
|
-
const exists = await this.oracleHandler.avmOpcodeNullifierExists(innerNullifier, targetAddress);
|
|
572
|
+
async avmOpcodeNullifierExists(foreignSiloedNullifier) {
|
|
573
|
+
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
574
|
+
const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(siloedNullifier);
|
|
474
575
|
return toForeignCallResult([
|
|
475
576
|
toSingle(new Fr(exists))
|
|
476
577
|
]);
|
|
477
578
|
}
|
|
478
579
|
async avmOpcodeAddress() {
|
|
479
|
-
const contractAddress = await this.
|
|
580
|
+
const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
|
|
480
581
|
return toForeignCallResult([
|
|
481
582
|
toSingle(contractAddress.toField())
|
|
482
583
|
]);
|
|
483
584
|
}
|
|
484
585
|
async avmOpcodeBlockNumber() {
|
|
485
|
-
const blockNumber = await this.
|
|
586
|
+
const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
|
|
486
587
|
return toForeignCallResult([
|
|
487
588
|
toSingle(new Fr(blockNumber))
|
|
488
589
|
]);
|
|
489
590
|
}
|
|
490
591
|
async avmOpcodeTimestamp() {
|
|
491
|
-
const timestamp = await this.
|
|
592
|
+
const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
|
|
492
593
|
return toForeignCallResult([
|
|
493
594
|
toSingle(new Fr(timestamp))
|
|
494
595
|
]);
|
|
495
596
|
}
|
|
496
597
|
async avmOpcodeIsStaticCall() {
|
|
497
|
-
const isStaticCall = await this.
|
|
598
|
+
const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
|
|
498
599
|
return toForeignCallResult([
|
|
499
600
|
toSingle(new Fr(isStaticCall ? 1 : 0))
|
|
500
601
|
]);
|
|
501
602
|
}
|
|
502
603
|
async avmOpcodeChainId() {
|
|
503
|
-
const chainId = await this.
|
|
604
|
+
const chainId = await this.handlerAsAvm().avmOpcodeChainId();
|
|
504
605
|
return toForeignCallResult([
|
|
505
606
|
toSingle(chainId)
|
|
506
607
|
]);
|
|
507
608
|
}
|
|
508
609
|
async avmOpcodeVersion() {
|
|
509
|
-
const version = await this.
|
|
610
|
+
const version = await this.handlerAsAvm().avmOpcodeVersion();
|
|
510
611
|
return toForeignCallResult([
|
|
511
612
|
toSingle(version)
|
|
512
613
|
]);
|
|
@@ -526,46 +627,39 @@ export class TXEService {
|
|
|
526
627
|
avmOpcodeSuccessCopy() {
|
|
527
628
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
528
629
|
}
|
|
529
|
-
async txePrivateCallNewFlow(foreignFrom, foreignTargetContractAddress, foreignFunctionSelector,
|
|
630
|
+
async txePrivateCallNewFlow(foreignFrom, foreignTargetContractAddress, foreignFunctionSelector, foreignArgs, foreignArgsHash, foreignIsStaticCall) {
|
|
530
631
|
const from = addressFromSingle(foreignFrom);
|
|
531
632
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
532
633
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
533
634
|
const args = fromArray(foreignArgs);
|
|
534
635
|
const argsHash = fromSingle(foreignArgsHash);
|
|
535
636
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
536
|
-
const
|
|
637
|
+
const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall);
|
|
537
638
|
return toForeignCallResult([
|
|
538
|
-
toArray(
|
|
539
|
-
result.endSideEffectCounter,
|
|
540
|
-
result.returnsHash,
|
|
541
|
-
result.txHash.hash
|
|
542
|
-
])
|
|
639
|
+
toArray(returnValues)
|
|
543
640
|
]);
|
|
544
641
|
}
|
|
545
|
-
async
|
|
642
|
+
async txeExecuteUtilityFunction(foreignTargetContractAddress, foreignFunctionSelector, foreignArgs) {
|
|
546
643
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
547
644
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
548
|
-
const
|
|
549
|
-
const
|
|
645
|
+
const args = fromArray(foreignArgs);
|
|
646
|
+
const returnValues = await this.handlerAsTxe().txeExecuteUtilityFunction(targetContractAddress, functionSelector, args);
|
|
550
647
|
return toForeignCallResult([
|
|
551
|
-
|
|
648
|
+
toArray(returnValues)
|
|
552
649
|
]);
|
|
553
650
|
}
|
|
554
|
-
async txePublicCallNewFlow(foreignFrom, foreignAddress,
|
|
651
|
+
async txePublicCallNewFlow(foreignFrom, foreignAddress, foreignCalldata, foreignIsStaticCall) {
|
|
555
652
|
const from = addressFromSingle(foreignFrom);
|
|
556
653
|
const address = addressFromSingle(foreignAddress);
|
|
557
654
|
const calldata = fromArray(foreignCalldata);
|
|
558
655
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
559
|
-
const
|
|
656
|
+
const returnValues = await this.handlerAsTxe().txePublicCallNewFlow(from, address, calldata, isStaticCall);
|
|
560
657
|
return toForeignCallResult([
|
|
561
|
-
toArray(
|
|
562
|
-
result.returnsHash,
|
|
563
|
-
result.txHash.hash
|
|
564
|
-
])
|
|
658
|
+
toArray(returnValues)
|
|
565
659
|
]);
|
|
566
660
|
}
|
|
567
661
|
async privateGetSenderForTags() {
|
|
568
|
-
const sender = await this.
|
|
662
|
+
const sender = await this.handlerAsPrivate().privateGetSenderForTags();
|
|
569
663
|
// Return a Noir Option struct with `some` and `value` fields
|
|
570
664
|
if (sender === undefined) {
|
|
571
665
|
// No sender found, return Option with some=0 and value=0
|
|
@@ -583,7 +677,15 @@ export class TXEService {
|
|
|
583
677
|
}
|
|
584
678
|
async privateSetSenderForTags(foreignSenderForTags) {
|
|
585
679
|
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
586
|
-
await this.
|
|
680
|
+
await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
|
|
587
681
|
return toForeignCallResult([]);
|
|
588
682
|
}
|
|
683
|
+
async privateGetNextAppTagAsSender(foreignSender, foreignRecipient) {
|
|
684
|
+
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
685
|
+
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
686
|
+
const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
|
|
687
|
+
return toForeignCallResult([
|
|
688
|
+
toSingle(nextAppTag.value)
|
|
689
|
+
]);
|
|
690
|
+
}
|
|
589
691
|
}
|