@aztec/txe 0.59.0 → 0.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/oracle/txe_oracle.d.ts +18 -15
- package/dest/oracle/txe_oracle.d.ts.map +1 -1
- package/dest/oracle/txe_oracle.js +127 -91
- package/dest/txe_service/txe_service.d.ts +66 -68
- package/dest/txe_service/txe_service.d.ts.map +1 -1
- package/dest/txe_service/txe_service.js +135 -119
- package/package.json +15 -15
- package/src/oracle/txe_oracle.ts +175 -139
- package/src/txe_service/txe_service.ts +187 -173
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
|
|
2
|
-
import { L2Block, MerkleTreeId, PublicDataWrite } from '@aztec/circuit-types';
|
|
2
|
+
import { L2Block, MerkleTreeId, PublicDataWrite, SimulationError } from '@aztec/circuit-types';
|
|
3
3
|
import {
|
|
4
4
|
Fr,
|
|
5
5
|
FunctionSelector,
|
|
@@ -17,6 +17,7 @@ import { type Logger } from '@aztec/foundation/log';
|
|
|
17
17
|
import { KeyStore } from '@aztec/key-store';
|
|
18
18
|
import { openTmpStore } from '@aztec/kv-store/utils';
|
|
19
19
|
import { getCanonicalProtocolContract, protocolContractNames } from '@aztec/protocol-contracts';
|
|
20
|
+
import { enrichPublicSimulationError } from '@aztec/pxe';
|
|
20
21
|
import { ExecutionNoteCache, PackedValuesCache, type TypedOracle } from '@aztec/simulator';
|
|
21
22
|
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
|
|
22
23
|
import { MerkleTrees } from '@aztec/world-state';
|
|
@@ -117,7 +118,7 @@ export class TXEService {
|
|
|
117
118
|
skipArgsDecoding: true,
|
|
118
119
|
salt: Fr.ONE,
|
|
119
120
|
// TODO: Modify this to allow for passing public keys.
|
|
120
|
-
publicKeys: PublicKeys.
|
|
121
|
+
publicKeys: PublicKeys.default(),
|
|
121
122
|
constructorArtifact: initializerStr ? initializerStr : undefined,
|
|
122
123
|
deployer: AztecAddress.ZERO,
|
|
123
124
|
});
|
|
@@ -200,16 +201,6 @@ export class TXEService {
|
|
|
200
201
|
]);
|
|
201
202
|
}
|
|
202
203
|
|
|
203
|
-
setMsgSender(msgSender: ForeignCallSingle) {
|
|
204
|
-
(this.typedOracle as TXE).setMsgSender(fromSingle(msgSender));
|
|
205
|
-
return toForeignCallResult([]);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
getMsgSender() {
|
|
209
|
-
const msgSender = (this.typedOracle as TXE).getMsgSender();
|
|
210
|
-
return toForeignCallResult([toSingle(msgSender)]);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
204
|
getSideEffectsCounter() {
|
|
214
205
|
const counter = (this.typedOracle as TXE).getSideEffectsCounter();
|
|
215
206
|
return toForeignCallResult([toSingle(new Fr(counter))]);
|
|
@@ -227,14 +218,9 @@ export class TXEService {
|
|
|
227
218
|
args: ForeignCallArray,
|
|
228
219
|
) {
|
|
229
220
|
const parsedAddress = fromSingle(address);
|
|
230
|
-
const parsedSelector =
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
parsedSelector,
|
|
234
|
-
fromArray(args),
|
|
235
|
-
false,
|
|
236
|
-
false,
|
|
237
|
-
);
|
|
221
|
+
const parsedSelector = fromSingle(functionSelector);
|
|
222
|
+
const extendedArgs = [parsedSelector, ...fromArray(args)];
|
|
223
|
+
const result = await (this.typedOracle as TXE).avmOpcodeCall(parsedAddress, extendedArgs, false);
|
|
238
224
|
if (!result.reverted) {
|
|
239
225
|
throw new ExpectedFailureError('Public call did not revert');
|
|
240
226
|
}
|
|
@@ -248,7 +234,6 @@ export class TXEService {
|
|
|
248
234
|
argsHash: ForeignCallSingle,
|
|
249
235
|
sideEffectCounter: ForeignCallSingle,
|
|
250
236
|
isStaticCall: ForeignCallSingle,
|
|
251
|
-
isDelegateCall: ForeignCallSingle,
|
|
252
237
|
) {
|
|
253
238
|
try {
|
|
254
239
|
await this.typedOracle.callPrivateFunction(
|
|
@@ -257,7 +242,6 @@ export class TXEService {
|
|
|
257
242
|
fromSingle(argsHash),
|
|
258
243
|
fromSingle(sideEffectCounter).toNumber(),
|
|
259
244
|
fromSingle(isStaticCall).toBool(),
|
|
260
|
-
fromSingle(isDelegateCall).toBool(),
|
|
261
245
|
);
|
|
262
246
|
throw new ExpectedFailureError('Private call did not fail');
|
|
263
247
|
} catch (e) {
|
|
@@ -268,21 +252,6 @@ export class TXEService {
|
|
|
268
252
|
return toForeignCallResult([]);
|
|
269
253
|
}
|
|
270
254
|
|
|
271
|
-
setFunctionSelector(functionSelector: ForeignCallSingle) {
|
|
272
|
-
(this.typedOracle as TXE).setFunctionSelector(FunctionSelector.fromField(fromSingle(functionSelector)));
|
|
273
|
-
return toForeignCallResult([]);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
setCalldata(_length: ForeignCallSingle, calldata: ForeignCallArray) {
|
|
277
|
-
(this.typedOracle as TXE).setCalldata(fromArray(calldata));
|
|
278
|
-
return toForeignCallResult([]);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
getFunctionSelector() {
|
|
282
|
-
const functionSelector = (this.typedOracle as TXE).getFunctionSelector();
|
|
283
|
-
return toForeignCallResult([toSingle(functionSelector.toField())]);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
255
|
// PXE oracles
|
|
287
256
|
|
|
288
257
|
getRandomField() {
|
|
@@ -299,41 +268,6 @@ export class TXEService {
|
|
|
299
268
|
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
300
269
|
}
|
|
301
270
|
|
|
302
|
-
async avmOpcodeAddress() {
|
|
303
|
-
const contractAddress = await this.typedOracle.getContractAddress();
|
|
304
|
-
return toForeignCallResult([toSingle(contractAddress.toField())]);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
async avmOpcodeBlockNumber() {
|
|
308
|
-
const blockNumber = await this.typedOracle.getBlockNumber();
|
|
309
|
-
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
avmOpcodeFunctionSelector() {
|
|
313
|
-
const functionSelector = (this.typedOracle as TXE).getFunctionSelector();
|
|
314
|
-
return toForeignCallResult([toSingle(functionSelector.toField())]);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
setIsStaticCall(isStaticCall: ForeignCallSingle) {
|
|
318
|
-
(this.typedOracle as TXE).setIsStaticCall(fromSingle(isStaticCall).toBool());
|
|
319
|
-
return toForeignCallResult([]);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
avmOpcodeIsStaticCall() {
|
|
323
|
-
const isStaticCall = (this.typedOracle as TXE).getIsStaticCall();
|
|
324
|
-
return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
async avmOpcodeChainId() {
|
|
328
|
-
const chainId = await (this.typedOracle as TXE).getChainId();
|
|
329
|
-
return toForeignCallResult([toSingle(chainId)]);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
async avmOpcodeVersion() {
|
|
333
|
-
const version = await (this.typedOracle as TXE).getVersion();
|
|
334
|
-
return toForeignCallResult([toSingle(version)]);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
271
|
async packArgumentsArray(args: ForeignCallArray) {
|
|
338
272
|
const packed = await this.typedOracle.packArgumentsArray(fromArray(args));
|
|
339
273
|
return toForeignCallResult([toSingle(packed)]);
|
|
@@ -514,101 +448,6 @@ export class TXEService {
|
|
|
514
448
|
]);
|
|
515
449
|
}
|
|
516
450
|
|
|
517
|
-
async avmOpcodeGetContractInstance(address: ForeignCallSingle) {
|
|
518
|
-
const instance = await this.typedOracle.getContractInstance(fromSingle(address));
|
|
519
|
-
return toForeignCallResult([
|
|
520
|
-
toArray([
|
|
521
|
-
// AVM requires an extra boolean indicating the instance was found
|
|
522
|
-
new Fr(1),
|
|
523
|
-
instance.salt,
|
|
524
|
-
instance.deployer,
|
|
525
|
-
instance.contractClassId,
|
|
526
|
-
instance.initializationHash,
|
|
527
|
-
...instance.publicKeys.toFields(),
|
|
528
|
-
]),
|
|
529
|
-
]);
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
avmOpcodeSender() {
|
|
533
|
-
const sender = (this.typedOracle as TXE).getMsgSender();
|
|
534
|
-
return toForeignCallResult([toSingle(sender)]);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
async avmOpcodeEmitNullifier(nullifier: ForeignCallSingle) {
|
|
538
|
-
await (this.typedOracle as TXE).avmOpcodeEmitNullifier(fromSingle(nullifier));
|
|
539
|
-
return toForeignCallResult([]);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
async avmOpcodeEmitNoteHash(noteHash: ForeignCallSingle) {
|
|
543
|
-
await (this.typedOracle as TXE).avmOpcodeEmitNoteHash(fromSingle(noteHash));
|
|
544
|
-
return toForeignCallResult([]);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
async avmOpcodeNullifierExists(innerNullifier: ForeignCallSingle, targetAddress: ForeignCallSingle) {
|
|
548
|
-
const exists = await (this.typedOracle as TXE).avmOpcodeNullifierExists(
|
|
549
|
-
fromSingle(innerNullifier),
|
|
550
|
-
AztecAddress.fromField(fromSingle(targetAddress)),
|
|
551
|
-
);
|
|
552
|
-
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
async avmOpcodeCall(
|
|
556
|
-
_gas: ForeignCallArray,
|
|
557
|
-
address: ForeignCallSingle,
|
|
558
|
-
_length: ForeignCallSingle,
|
|
559
|
-
args: ForeignCallArray,
|
|
560
|
-
functionSelector: ForeignCallSingle,
|
|
561
|
-
) {
|
|
562
|
-
const result = await (this.typedOracle as TXE).avmOpcodeCall(
|
|
563
|
-
fromSingle(address),
|
|
564
|
-
FunctionSelector.fromField(fromSingle(functionSelector)),
|
|
565
|
-
fromArray(args),
|
|
566
|
-
/* isStaticCall */ false,
|
|
567
|
-
/* isDelegateCall */ false,
|
|
568
|
-
);
|
|
569
|
-
|
|
570
|
-
return toForeignCallResult([toArray(result.returnValues), toSingle(new Fr(1))]);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
async avmOpcodeStaticCall(
|
|
574
|
-
_gas: ForeignCallArray,
|
|
575
|
-
address: ForeignCallSingle,
|
|
576
|
-
_length: ForeignCallSingle,
|
|
577
|
-
args: ForeignCallArray,
|
|
578
|
-
functionSelector: ForeignCallSingle,
|
|
579
|
-
) {
|
|
580
|
-
const result = await (this.typedOracle as TXE).avmOpcodeCall(
|
|
581
|
-
fromSingle(address),
|
|
582
|
-
FunctionSelector.fromField(fromSingle(functionSelector)),
|
|
583
|
-
fromArray(args),
|
|
584
|
-
/* isStaticCall */ true,
|
|
585
|
-
/* isDelegateCall */ false,
|
|
586
|
-
);
|
|
587
|
-
|
|
588
|
-
return toForeignCallResult([toArray(result.returnValues), toSingle(new Fr(1))]);
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
async avmOpcodeStorageRead(slot: ForeignCallSingle) {
|
|
592
|
-
const value = await (this.typedOracle as TXE).avmOpcodeStorageRead(fromSingle(slot));
|
|
593
|
-
return toForeignCallResult([toSingle(value)]);
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
async avmOpcodeStorageWrite(slot: ForeignCallSingle, value: ForeignCallSingle) {
|
|
597
|
-
await this.typedOracle.storageWrite(fromSingle(slot), [fromSingle(value)]);
|
|
598
|
-
return toForeignCallResult([]);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
//unconstrained fn calldata_copy_opcode<let N: u32>(cdoffset: u32, copy_size: u32) -> [Field; N] {}
|
|
602
|
-
avmOpcodeCalldataCopy(cdOffsetInput: ForeignCallSingle, copySizeInput: ForeignCallSingle) {
|
|
603
|
-
const cdOffset = fromSingle(cdOffsetInput).toNumber();
|
|
604
|
-
const copySize = fromSingle(copySizeInput).toNumber();
|
|
605
|
-
|
|
606
|
-
const calldata = (this.typedOracle as TXE).getCalldata();
|
|
607
|
-
const calldataSlice = calldata.slice(cdOffset, cdOffset + copySize);
|
|
608
|
-
|
|
609
|
-
return toForeignCallResult([toArray(calldataSlice)]);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
451
|
async getPublicKeysAndPartialAddress(address: ForeignCallSingle) {
|
|
613
452
|
const parsedAddress = AztecAddress.fromField(fromSingle(address));
|
|
614
453
|
const { publicKeys, partialAddress } = await this.typedOracle.getCompleteAddress(parsedAddress);
|
|
@@ -650,7 +489,6 @@ export class TXEService {
|
|
|
650
489
|
argsHash: ForeignCallSingle,
|
|
651
490
|
sideEffectCounter: ForeignCallSingle,
|
|
652
491
|
isStaticCall: ForeignCallSingle,
|
|
653
|
-
isDelegateCall: ForeignCallSingle,
|
|
654
492
|
) {
|
|
655
493
|
const result = await this.typedOracle.callPrivateFunction(
|
|
656
494
|
fromSingle(targetContractAddress),
|
|
@@ -658,7 +496,6 @@ export class TXEService {
|
|
|
658
496
|
fromSingle(argsHash),
|
|
659
497
|
fromSingle(sideEffectCounter).toNumber(),
|
|
660
498
|
fromSingle(isStaticCall).toBool(),
|
|
661
|
-
fromSingle(isDelegateCall).toBool(),
|
|
662
499
|
);
|
|
663
500
|
return toForeignCallResult([toArray([result.endSideEffectCounter, result.returnsHash])]);
|
|
664
501
|
}
|
|
@@ -687,7 +524,6 @@ export class TXEService {
|
|
|
687
524
|
argsHash: ForeignCallSingle,
|
|
688
525
|
sideEffectCounter: ForeignCallSingle,
|
|
689
526
|
isStaticCall: ForeignCallSingle,
|
|
690
|
-
isDelegateCall: ForeignCallSingle,
|
|
691
527
|
) {
|
|
692
528
|
const newArgsHash = await this.typedOracle.enqueuePublicFunctionCall(
|
|
693
529
|
fromSingle(targetContractAddress),
|
|
@@ -695,7 +531,6 @@ export class TXEService {
|
|
|
695
531
|
fromSingle(argsHash),
|
|
696
532
|
fromSingle(sideEffectCounter).toNumber(),
|
|
697
533
|
fromSingle(isStaticCall).toBool(),
|
|
698
|
-
fromSingle(isDelegateCall).toBool(),
|
|
699
534
|
);
|
|
700
535
|
return toForeignCallResult([toSingle(newArgsHash)]);
|
|
701
536
|
}
|
|
@@ -706,7 +541,6 @@ export class TXEService {
|
|
|
706
541
|
argsHash: ForeignCallSingle,
|
|
707
542
|
sideEffectCounter: ForeignCallSingle,
|
|
708
543
|
isStaticCall: ForeignCallSingle,
|
|
709
|
-
isDelegateCall: ForeignCallSingle,
|
|
710
544
|
) {
|
|
711
545
|
const newArgsHash = await this.typedOracle.setPublicTeardownFunctionCall(
|
|
712
546
|
fromSingle(targetContractAddress),
|
|
@@ -714,7 +548,6 @@ export class TXEService {
|
|
|
714
548
|
fromSingle(argsHash),
|
|
715
549
|
fromSingle(sideEffectCounter).toNumber(),
|
|
716
550
|
fromSingle(isStaticCall).toBool(),
|
|
717
|
-
fromSingle(isDelegateCall).toBool(),
|
|
718
551
|
);
|
|
719
552
|
return toForeignCallResult([toSingle(newArgsHash)]);
|
|
720
553
|
}
|
|
@@ -767,8 +600,189 @@ export class TXEService {
|
|
|
767
600
|
return toForeignCallResult([]);
|
|
768
601
|
}
|
|
769
602
|
|
|
603
|
+
async getAppTaggingSecret(sender: ForeignCallSingle, recipient: ForeignCallSingle) {
|
|
604
|
+
const secret = await this.typedOracle.getAppTaggingSecret(
|
|
605
|
+
AztecAddress.fromField(fromSingle(sender)),
|
|
606
|
+
AztecAddress.fromField(fromSingle(recipient)),
|
|
607
|
+
);
|
|
608
|
+
return toForeignCallResult([toArray(secret.toFields())]);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
async getAppTaggingSecretsForSenders(recipient: ForeignCallSingle) {
|
|
612
|
+
const secrets = await this.typedOracle.getAppTaggingSecretsForSenders(
|
|
613
|
+
AztecAddress.fromField(fromSingle(recipient)),
|
|
614
|
+
);
|
|
615
|
+
return toForeignCallResult([toArray(secrets.flatMap(secret => secret.toFields()))]);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// AVM opcodes
|
|
619
|
+
|
|
770
620
|
avmOpcodeEmitUnencryptedLog(_message: ForeignCallArray) {
|
|
771
621
|
// TODO(#8811): Implement
|
|
772
622
|
return toForeignCallResult([]);
|
|
773
623
|
}
|
|
624
|
+
|
|
625
|
+
async avmOpcodeStorageRead(slot: ForeignCallSingle) {
|
|
626
|
+
const value = await (this.typedOracle as TXE).avmOpcodeStorageRead(fromSingle(slot));
|
|
627
|
+
return toForeignCallResult([toSingle(value)]);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
async avmOpcodeStorageWrite(slot: ForeignCallSingle, value: ForeignCallSingle) {
|
|
631
|
+
await this.typedOracle.storageWrite(fromSingle(slot), [fromSingle(value)]);
|
|
632
|
+
return toForeignCallResult([]);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
async avmOpcodeGetContractInstanceDeployer(address: ForeignCallSingle) {
|
|
636
|
+
const instance = await this.typedOracle.getContractInstance(fromSingle(address));
|
|
637
|
+
return toForeignCallResult([
|
|
638
|
+
toSingle(instance.deployer),
|
|
639
|
+
// AVM requires an extra boolean indicating the instance was found
|
|
640
|
+
toSingle(new Fr(1)),
|
|
641
|
+
]);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
async avmOpcodeGetContractInstanceClassId(address: ForeignCallSingle) {
|
|
645
|
+
const instance = await this.typedOracle.getContractInstance(fromSingle(address));
|
|
646
|
+
return toForeignCallResult([
|
|
647
|
+
toSingle(instance.contractClassId),
|
|
648
|
+
// AVM requires an extra boolean indicating the instance was found
|
|
649
|
+
toSingle(new Fr(1)),
|
|
650
|
+
]);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
async avmOpcodeGetContractInstanceInitializationHash(address: ForeignCallSingle) {
|
|
654
|
+
const instance = await this.typedOracle.getContractInstance(fromSingle(address));
|
|
655
|
+
return toForeignCallResult([
|
|
656
|
+
toSingle(instance.initializationHash),
|
|
657
|
+
// AVM requires an extra boolean indicating the instance was found
|
|
658
|
+
toSingle(new Fr(1)),
|
|
659
|
+
]);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
avmOpcodeSender() {
|
|
663
|
+
const sender = (this.typedOracle as TXE).getMsgSender();
|
|
664
|
+
return toForeignCallResult([toSingle(sender)]);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
async avmOpcodeEmitNullifier(nullifier: ForeignCallSingle) {
|
|
668
|
+
await (this.typedOracle as TXE).avmOpcodeEmitNullifier(fromSingle(nullifier));
|
|
669
|
+
return toForeignCallResult([]);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
async avmOpcodeEmitNoteHash(noteHash: ForeignCallSingle) {
|
|
673
|
+
await (this.typedOracle as TXE).avmOpcodeEmitNoteHash(fromSingle(noteHash));
|
|
674
|
+
return toForeignCallResult([]);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
async avmOpcodeNullifierExists(innerNullifier: ForeignCallSingle, targetAddress: ForeignCallSingle) {
|
|
678
|
+
const exists = await (this.typedOracle as TXE).avmOpcodeNullifierExists(
|
|
679
|
+
fromSingle(innerNullifier),
|
|
680
|
+
AztecAddress.fromField(fromSingle(targetAddress)),
|
|
681
|
+
);
|
|
682
|
+
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
async avmOpcodeAddress() {
|
|
686
|
+
const contractAddress = await this.typedOracle.getContractAddress();
|
|
687
|
+
return toForeignCallResult([toSingle(contractAddress.toField())]);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
async avmOpcodeBlockNumber() {
|
|
691
|
+
const blockNumber = await this.typedOracle.getBlockNumber();
|
|
692
|
+
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
avmOpcodeFunctionSelector() {
|
|
696
|
+
const functionSelector = (this.typedOracle as TXE).getFunctionSelector();
|
|
697
|
+
return toForeignCallResult([toSingle(functionSelector.toField())]);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
avmOpcodeIsStaticCall() {
|
|
701
|
+
const isStaticCall = (this.typedOracle as TXE).getIsStaticCall();
|
|
702
|
+
return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
async avmOpcodeChainId() {
|
|
706
|
+
const chainId = await (this.typedOracle as TXE).getChainId();
|
|
707
|
+
return toForeignCallResult([toSingle(chainId)]);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
async avmOpcodeVersion() {
|
|
711
|
+
const version = await (this.typedOracle as TXE).getVersion();
|
|
712
|
+
return toForeignCallResult([toSingle(version)]);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
avmOpcodeReturndataSize() {
|
|
716
|
+
const size = (this.typedOracle as TXE).avmOpcodeReturndataSize();
|
|
717
|
+
return toForeignCallResult([toSingle(new Fr(size))]);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
avmOpcodeReturndataCopy(rdOffset: ForeignCallSingle, copySize: ForeignCallSingle) {
|
|
721
|
+
const returndata = (this.typedOracle as TXE).avmOpcodeReturndataCopy(
|
|
722
|
+
fromSingle(rdOffset).toNumber(),
|
|
723
|
+
fromSingle(copySize).toNumber(),
|
|
724
|
+
);
|
|
725
|
+
// This is a slice, so we need to return the length as well.
|
|
726
|
+
return toForeignCallResult([toSingle(new Fr(returndata.length)), toArray(returndata)]);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
async avmOpcodeCall(
|
|
730
|
+
_gas: ForeignCallArray,
|
|
731
|
+
address: ForeignCallSingle,
|
|
732
|
+
_length: ForeignCallSingle,
|
|
733
|
+
args: ForeignCallArray,
|
|
734
|
+
) {
|
|
735
|
+
const result = await (this.typedOracle as TXE).avmOpcodeCall(
|
|
736
|
+
fromSingle(address),
|
|
737
|
+
fromArray(args),
|
|
738
|
+
/* isStaticCall */ false,
|
|
739
|
+
);
|
|
740
|
+
|
|
741
|
+
// Poor man's revert handling
|
|
742
|
+
if (result.reverted) {
|
|
743
|
+
if (result.revertReason && result.revertReason instanceof SimulationError) {
|
|
744
|
+
await enrichPublicSimulationError(
|
|
745
|
+
result.revertReason,
|
|
746
|
+
(this.typedOracle as TXE).getContractDataOracle(),
|
|
747
|
+
(this.typedOracle as TXE).getTXEDatabase(),
|
|
748
|
+
this.logger,
|
|
749
|
+
);
|
|
750
|
+
throw new Error(result.revertReason.message);
|
|
751
|
+
} else {
|
|
752
|
+
throw new Error(`Public function call reverted: ${result.revertReason}`);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
return toForeignCallResult([toSingle(new Fr(!result.reverted))]);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
async avmOpcodeStaticCall(
|
|
760
|
+
_gas: ForeignCallArray,
|
|
761
|
+
address: ForeignCallSingle,
|
|
762
|
+
_length: ForeignCallSingle,
|
|
763
|
+
args: ForeignCallArray,
|
|
764
|
+
) {
|
|
765
|
+
const result = await (this.typedOracle as TXE).avmOpcodeCall(
|
|
766
|
+
fromSingle(address),
|
|
767
|
+
fromArray(args),
|
|
768
|
+
/* isStaticCall */ true,
|
|
769
|
+
);
|
|
770
|
+
|
|
771
|
+
// Poor man's revert handling
|
|
772
|
+
if (result.reverted) {
|
|
773
|
+
if (result.revertReason && result.revertReason instanceof SimulationError) {
|
|
774
|
+
await enrichPublicSimulationError(
|
|
775
|
+
result.revertReason,
|
|
776
|
+
(this.typedOracle as TXE).getContractDataOracle(),
|
|
777
|
+
(this.typedOracle as TXE).getTXEDatabase(),
|
|
778
|
+
this.logger,
|
|
779
|
+
);
|
|
780
|
+
throw new Error(result.revertReason.message);
|
|
781
|
+
} else {
|
|
782
|
+
throw new Error(`Public function call reverted: ${result.revertReason}`);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
return toForeignCallResult([toSingle(new Fr(!result.reverted))]);
|
|
787
|
+
}
|
|
774
788
|
}
|