@aztec/txe 0.62.0 → 0.63.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.
@@ -1,5 +1,5 @@
1
1
  import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
2
- import { L2Block, MerkleTreeId, PublicDataWrite, SimulationError } from '@aztec/circuit-types';
2
+ import { L2Block, MerkleTreeId, SimulationError } from '@aztec/circuit-types';
3
3
  import {
4
4
  Fr,
5
5
  FunctionSelector,
@@ -26,6 +26,7 @@ import { TXE } from '../oracle/txe_oracle.js';
26
26
  import {
27
27
  type ForeignCallArray,
28
28
  type ForeignCallSingle,
29
+ addressFromSingle,
29
30
  fromArray,
30
31
  fromSingle,
31
32
  toArray,
@@ -87,7 +88,7 @@ export class TXEService {
87
88
  }
88
89
 
89
90
  setContractAddress(address: ForeignCallSingle) {
90
- const typedAddress = AztecAddress.fromField(fromSingle(address));
91
+ const typedAddress = addressFromSingle(address);
91
92
  (this.typedOracle as TXE).setContractAddress(typedAddress);
92
93
  return toForeignCallResult([]);
93
94
  }
@@ -129,7 +130,7 @@ export class TXEService {
129
130
  return toForeignCallResult([
130
131
  toArray([
131
132
  instance.salt,
132
- instance.deployer,
133
+ instance.deployer.toField(),
133
134
  instance.contractClassId,
134
135
  instance.initializationHash,
135
136
  ...instance.publicKeys.toFields(),
@@ -145,20 +146,20 @@ export class TXEService {
145
146
  const trees = (this.typedOracle as TXE).getTrees();
146
147
  const startStorageSlotFr = fromSingle(startStorageSlot);
147
148
  const valuesFr = fromArray(values);
148
- const contractAddressFr = fromSingle(contractAddress);
149
+ const contractAddressFr = addressFromSingle(contractAddress);
149
150
  const db = await trees.getLatest();
150
151
 
151
152
  const publicDataWrites = valuesFr.map((value, i) => {
152
153
  const storageSlot = startStorageSlotFr.add(new Fr(i));
153
154
  this.logger.debug(`Oracle storage write: slot=${storageSlot.toString()} value=${value}`);
154
- return new PublicDataWrite(computePublicDataTreeLeafSlot(contractAddressFr, storageSlot), value);
155
+ return new PublicDataTreeLeaf(computePublicDataTreeLeafSlot(contractAddressFr, storageSlot), value);
155
156
  });
156
157
  await db.batchInsert(
157
158
  MerkleTreeId.PUBLIC_DATA_TREE,
158
- publicDataWrites.map(write => new PublicDataTreeLeaf(write.leafIndex, write.newValue).toBuffer()),
159
+ publicDataWrites.map(write => write.toBuffer()),
159
160
  PUBLIC_DATA_SUBTREE_HEIGHT,
160
161
  );
161
- return toForeignCallResult([toArray(publicDataWrites.map(write => write.newValue))]);
162
+ return toForeignCallResult([toArray(publicDataWrites.map(write => write.value))]);
162
163
  }
163
164
 
164
165
  async createAccount() {
@@ -207,7 +208,7 @@ export class TXEService {
207
208
  }
208
209
 
209
210
  async addAuthWitness(address: ForeignCallSingle, messageHash: ForeignCallSingle) {
210
- await (this.typedOracle as TXE).addAuthWitness(fromSingle(address), fromSingle(messageHash));
211
+ await (this.typedOracle as TXE).addAuthWitness(addressFromSingle(address), fromSingle(messageHash));
211
212
  return toForeignCallResult([]);
212
213
  }
213
214
 
@@ -217,7 +218,7 @@ export class TXEService {
217
218
  _length: ForeignCallSingle,
218
219
  args: ForeignCallArray,
219
220
  ) {
220
- const parsedAddress = fromSingle(address);
221
+ const parsedAddress = addressFromSingle(address);
221
222
  const parsedSelector = fromSingle(functionSelector);
222
223
  const extendedArgs = [parsedSelector, ...fromArray(args)];
223
224
  const result = await (this.typedOracle as TXE).avmOpcodeCall(parsedAddress, extendedArgs, false);
@@ -237,7 +238,7 @@ export class TXEService {
237
238
  ) {
238
239
  try {
239
240
  await this.typedOracle.callPrivateFunction(
240
- fromSingle(targetContractAddress),
241
+ addressFromSingle(targetContractAddress),
241
242
  FunctionSelector.fromField(fromSingle(functionSelector)),
242
243
  fromSingle(argsHash),
243
244
  fromSingle(sideEffectCounter).toNumber(),
@@ -306,7 +307,7 @@ export class TXEService {
306
307
  numberOfElements: ForeignCallSingle,
307
308
  ) {
308
309
  const values = await this.typedOracle.storageRead(
309
- fromSingle(contractAddress),
310
+ addressFromSingle(contractAddress),
310
311
  fromSingle(startStorageSlot),
311
312
  fromSingle(blockNumber).toNumber(),
312
313
  fromSingle(numberOfElements).toNumber(),
@@ -391,7 +392,7 @@ export class TXEService {
391
392
  ]);
392
393
 
393
394
  const returnFieldSize = fromSingle(returnSize).toNumber();
394
- const returnData = [noteDatas.length, contractAddress, ...flattenData].map(v => new Fr(v));
395
+ const returnData = [noteDatas.length, contractAddress.toField(), ...flattenData].map(v => new Fr(v));
395
396
  if (returnData.length > returnFieldSize) {
396
397
  throw new Error(`Return data size too big. Maximum ${returnFieldSize} fields. Got ${flattenData.length}.`);
397
398
  }
@@ -436,11 +437,11 @@ export class TXEService {
436
437
  }
437
438
 
438
439
  async getContractInstance(address: ForeignCallSingle) {
439
- const instance = await this.typedOracle.getContractInstance(fromSingle(address));
440
+ const instance = await this.typedOracle.getContractInstance(addressFromSingle(address));
440
441
  return toForeignCallResult([
441
442
  toArray([
442
443
  instance.salt,
443
- instance.deployer,
444
+ instance.deployer.toField(),
444
445
  instance.contractClassId,
445
446
  instance.initializationHash,
446
447
  ...instance.publicKeys.toFields(),
@@ -449,7 +450,7 @@ export class TXEService {
449
450
  }
450
451
 
451
452
  async getPublicKeysAndPartialAddress(address: ForeignCallSingle) {
452
- const parsedAddress = AztecAddress.fromField(fromSingle(address));
453
+ const parsedAddress = addressFromSingle(address);
453
454
  const { publicKeys, partialAddress } = await this.typedOracle.getCompleteAddress(parsedAddress);
454
455
  return toForeignCallResult([toArray([...publicKeys.toFields(), partialAddress])]);
455
456
  }
@@ -491,7 +492,7 @@ export class TXEService {
491
492
  isStaticCall: ForeignCallSingle,
492
493
  ) {
493
494
  const result = await this.typedOracle.callPrivateFunction(
494
- fromSingle(targetContractAddress),
495
+ addressFromSingle(targetContractAddress),
495
496
  FunctionSelector.fromField(fromSingle(functionSelector)),
496
497
  fromSingle(argsHash),
497
498
  fromSingle(sideEffectCounter).toNumber(),
@@ -526,7 +527,7 @@ export class TXEService {
526
527
  isStaticCall: ForeignCallSingle,
527
528
  ) {
528
529
  const newArgsHash = await this.typedOracle.enqueuePublicFunctionCall(
529
- fromSingle(targetContractAddress),
530
+ addressFromSingle(targetContractAddress),
530
531
  FunctionSelector.fromField(fromSingle(functionSelector)),
531
532
  fromSingle(argsHash),
532
533
  fromSingle(sideEffectCounter).toNumber(),
@@ -543,7 +544,7 @@ export class TXEService {
543
544
  isStaticCall: ForeignCallSingle,
544
545
  ) {
545
546
  const newArgsHash = await this.typedOracle.setPublicTeardownFunctionCall(
546
- fromSingle(targetContractAddress),
547
+ addressFromSingle(targetContractAddress),
547
548
  FunctionSelector.fromField(fromSingle(functionSelector)),
548
549
  fromSingle(argsHash),
549
550
  fromSingle(sideEffectCounter).toNumber(),
@@ -565,12 +566,12 @@ export class TXEService {
565
566
  }
566
567
 
567
568
  async addNullifiers(contractAddress: ForeignCallSingle, _length: ForeignCallSingle, nullifiers: ForeignCallArray) {
568
- await (this.typedOracle as TXE).addNullifiers(fromSingle(contractAddress), fromArray(nullifiers));
569
+ await (this.typedOracle as TXE).addNullifiers(addressFromSingle(contractAddress), fromArray(nullifiers));
569
570
  return toForeignCallResult([]);
570
571
  }
571
572
 
572
573
  async addNoteHashes(contractAddress: ForeignCallSingle, _length: ForeignCallSingle, noteHashes: ForeignCallArray) {
573
- await (this.typedOracle as TXE).addNoteHashes(fromSingle(contractAddress), fromArray(noteHashes));
574
+ await (this.typedOracle as TXE).addNoteHashes(addressFromSingle(contractAddress), fromArray(noteHashes));
574
575
  return toForeignCallResult([]);
575
576
  }
576
577
 
@@ -600,19 +601,17 @@ export class TXEService {
600
601
  return toForeignCallResult([]);
601
602
  }
602
603
 
603
- async getAppTaggingSecret(sender: ForeignCallSingle, recipient: ForeignCallSingle) {
604
- const secret = await this.typedOracle.getAppTaggingSecret(
604
+ async getAppTaggingSecretAsSender(sender: ForeignCallSingle, recipient: ForeignCallSingle) {
605
+ const secret = await this.typedOracle.getAppTaggingSecretAsSender(
605
606
  AztecAddress.fromField(fromSingle(sender)),
606
607
  AztecAddress.fromField(fromSingle(recipient)),
607
608
  );
608
609
  return toForeignCallResult([toArray(secret.toFields())]);
609
610
  }
610
611
 
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()))]);
612
+ async syncNotes() {
613
+ await this.typedOracle.syncNotes();
614
+ return toForeignCallResult([]);
616
615
  }
617
616
 
618
617
  // AVM opcodes
@@ -633,7 +632,7 @@ export class TXEService {
633
632
  }
634
633
 
635
634
  async avmOpcodeGetContractInstanceDeployer(address: ForeignCallSingle) {
636
- const instance = await this.typedOracle.getContractInstance(fromSingle(address));
635
+ const instance = await this.typedOracle.getContractInstance(addressFromSingle(address));
637
636
  return toForeignCallResult([
638
637
  toSingle(instance.deployer),
639
638
  // AVM requires an extra boolean indicating the instance was found
@@ -642,7 +641,7 @@ export class TXEService {
642
641
  }
643
642
 
644
643
  async avmOpcodeGetContractInstanceClassId(address: ForeignCallSingle) {
645
- const instance = await this.typedOracle.getContractInstance(fromSingle(address));
644
+ const instance = await this.typedOracle.getContractInstance(addressFromSingle(address));
646
645
  return toForeignCallResult([
647
646
  toSingle(instance.contractClassId),
648
647
  // AVM requires an extra boolean indicating the instance was found
@@ -651,7 +650,7 @@ export class TXEService {
651
650
  }
652
651
 
653
652
  async avmOpcodeGetContractInstanceInitializationHash(address: ForeignCallSingle) {
654
- const instance = await this.typedOracle.getContractInstance(fromSingle(address));
653
+ const instance = await this.typedOracle.getContractInstance(addressFromSingle(address));
655
654
  return toForeignCallResult([
656
655
  toSingle(instance.initializationHash),
657
656
  // AVM requires an extra boolean indicating the instance was found
@@ -733,7 +732,7 @@ export class TXEService {
733
732
  args: ForeignCallArray,
734
733
  ) {
735
734
  const result = await (this.typedOracle as TXE).avmOpcodeCall(
736
- fromSingle(address),
735
+ addressFromSingle(address),
737
736
  fromArray(args),
738
737
  /* isStaticCall */ false,
739
738
  );
@@ -763,7 +762,7 @@ export class TXEService {
763
762
  args: ForeignCallArray,
764
763
  ) {
765
764
  const result = await (this.typedOracle as TXE).avmOpcodeCall(
766
- fromSingle(address),
765
+ addressFromSingle(address),
767
766
  fromArray(args),
768
767
  /* isStaticCall */ true,
769
768
  );
@@ -1,9 +1,15 @@
1
+ import { AztecAddress } from '@aztec/circuits.js';
2
+ import { type ContractArtifact, ContractArtifactSchema } from '@aztec/foundation/abi';
1
3
  import { Fr } from '@aztec/foundation/fields';
2
4
 
5
+ import { z } from 'zod';
6
+
3
7
  export type ForeignCallSingle = string;
4
8
 
5
9
  export type ForeignCallArray = string[];
6
10
 
11
+ export type ForeignCallArgs = (ForeignCallSingle | ForeignCallArray | ContractArtifact)[];
12
+
7
13
  export type ForeignCallResult = {
8
14
  values: (ForeignCallSingle | ForeignCallArray)[];
9
15
  };
@@ -12,11 +18,15 @@ export function fromSingle(obj: ForeignCallSingle) {
12
18
  return Fr.fromBuffer(Buffer.from(obj, 'hex'));
13
19
  }
14
20
 
21
+ export function addressFromSingle(obj: ForeignCallSingle) {
22
+ return new AztecAddress(fromSingle(obj));
23
+ }
24
+
15
25
  export function fromArray(obj: ForeignCallArray) {
16
26
  return obj.map(str => Fr.fromBuffer(Buffer.from(str, 'hex')));
17
27
  }
18
28
 
19
- export function toSingle(obj: Fr) {
29
+ export function toSingle(obj: Fr | AztecAddress) {
20
30
  return obj.toString().slice(2);
21
31
  }
22
32
 
@@ -27,3 +37,15 @@ export function toArray(objs: Fr[]) {
27
37
  export function toForeignCallResult(obj: (ForeignCallSingle | ForeignCallArray)[]) {
28
38
  return { values: obj };
29
39
  }
40
+
41
+ export const ForeignCallSingleSchema = z.string();
42
+
43
+ export const ForeignCallArraySchema = z.array(z.string());
44
+
45
+ export const ForeignCallArgsSchema = z.array(
46
+ z.union([ForeignCallSingleSchema, ForeignCallArraySchema, ContractArtifactSchema]),
47
+ );
48
+
49
+ export const ForeignCallResultSchema = z.object({
50
+ values: z.array(z.union([ForeignCallSingleSchema, ForeignCallArraySchema])),
51
+ });