@aztec/txe 0.44.0 → 0.45.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/txe",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
4
4
  "type": "module",
5
5
  "exports": "./dest/index.js",
6
6
  "bin": "./dest/bin/index.js",
@@ -18,7 +18,7 @@
18
18
  "formatting": "run -T prettier --check ./src && run -T eslint ./src",
19
19
  "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
20
20
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests",
21
- "dev": "DEBUG='aztec:*' && node ./dest/bin/index.js",
21
+ "dev": "DEBUG='aztec:*' LOG_LEVEL=debug && node ./dest/bin/index.js",
22
22
  "start": "node ./dest/bin/index.js"
23
23
  },
24
24
  "inherits": [
@@ -57,18 +57,18 @@
57
57
  ]
58
58
  },
59
59
  "dependencies": {
60
- "@aztec/archiver": "0.44.0",
61
- "@aztec/aztec.js": "0.44.0",
62
- "@aztec/circuit-types": "0.44.0",
63
- "@aztec/circuits.js": "0.44.0",
64
- "@aztec/foundation": "0.44.0",
65
- "@aztec/key-store": "0.44.0",
66
- "@aztec/kv-store": "0.44.0",
67
- "@aztec/noir-contracts.js": "0.44.0",
68
- "@aztec/pxe": "0.44.0",
69
- "@aztec/simulator": "0.44.0",
70
- "@aztec/types": "0.44.0",
71
- "@aztec/world-state": "0.44.0"
60
+ "@aztec/archiver": "0.45.0",
61
+ "@aztec/aztec.js": "0.45.0",
62
+ "@aztec/circuit-types": "0.45.0",
63
+ "@aztec/circuits.js": "0.45.0",
64
+ "@aztec/foundation": "0.45.0",
65
+ "@aztec/key-store": "0.45.0",
66
+ "@aztec/kv-store": "0.45.0",
67
+ "@aztec/noir-contracts.js": "0.45.0",
68
+ "@aztec/pxe": "0.45.0",
69
+ "@aztec/simulator": "0.45.0",
70
+ "@aztec/types": "0.45.0",
71
+ "@aztec/world-state": "0.45.0"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@jest/globals": "^29.5.0",
@@ -113,6 +113,10 @@ export class TXE implements TypedOracle {
113
113
  return this.msgSender;
114
114
  }
115
115
 
116
+ getFunctionSelector() {
117
+ return this.functionSelector;
118
+ }
119
+
116
120
  setMsgSender(msgSender: Fr) {
117
121
  this.msgSender = msgSender;
118
122
  }
@@ -185,11 +189,10 @@ export class TXE implements TypedOracle {
185
189
 
186
190
  getPublicContextInputs() {
187
191
  const inputs = {
188
- functionSelector: FunctionSelector.fromField(new Fr(0)),
189
192
  argsHash: new Fr(0),
190
193
  isStaticCall: false,
191
194
  toFields: function () {
192
- return [this.functionSelector.toField(), this.argsHash, new Fr(this.isStaticCall)];
195
+ return [this.argsHash, new Fr(this.isStaticCall)];
193
196
  },
194
197
  };
195
198
  return inputs;
@@ -434,13 +437,45 @@ export class TXE implements TypedOracle {
434
437
  throw new Error('Method not implemented.');
435
438
  }
436
439
 
437
- async storageRead(startStorageSlot: Fr, numberOfElements: number): Promise<Fr[]> {
440
+ async avmOpcodeStorageRead(slot: Fr, length: Fr) {
438
441
  const db = this.trees.asLatest();
439
442
 
443
+ const result = [];
444
+
445
+ for (let i = 0; i < length.toNumber(); i++) {
446
+ const leafSlot = computePublicDataTreeLeafSlot(this.contractAddress, slot.add(new Fr(i))).toBigInt();
447
+
448
+ const lowLeafResult = await db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
449
+ if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
450
+ result.push(Fr.ZERO);
451
+ continue;
452
+ }
453
+
454
+ const preimage = (await db.getLeafPreimage(
455
+ MerkleTreeId.PUBLIC_DATA_TREE,
456
+ lowLeafResult.index,
457
+ )) as PublicDataTreeLeafPreimage;
458
+
459
+ result.push(preimage.value);
460
+ }
461
+ return result;
462
+ }
463
+
464
+ async storageRead(
465
+ contractAddress: Fr,
466
+ startStorageSlot: Fr,
467
+ blockNumber: number,
468
+ numberOfElements: number,
469
+ ): Promise<Fr[]> {
470
+ const db =
471
+ blockNumber === (await this.getBlockNumber())
472
+ ? this.trees.asLatest()
473
+ : new MerkleTreeSnapshotOperationsFacade(this.trees, blockNumber);
474
+
440
475
  const values = [];
441
476
  for (let i = 0n; i < numberOfElements; i++) {
442
477
  const storageSlot = startStorageSlot.add(new Fr(i));
443
- const leafSlot = computePublicDataTreeLeafSlot(this.contractAddress, storageSlot).toBigInt();
478
+ const leafSlot = computePublicDataTreeLeafSlot(contractAddress, storageSlot).toBigInt();
444
479
 
445
480
  const lowLeafResult = await db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
446
481
 
@@ -685,7 +720,7 @@ export class TXE implements TypedOracle {
685
720
  Gas.test(),
686
721
  TxContext.empty(),
687
722
  /* pendingNullifiers */ [],
688
- /* transactionFee */ Fr.ZERO,
723
+ /* transactionFee */ Fr.ONE,
689
724
  callContext.sideEffectCounter,
690
725
  );
691
726
  }
@@ -830,14 +865,23 @@ export class TXE implements TypedOracle {
830
865
  }
831
866
 
832
867
  setPublicTeardownFunctionCall(
833
- _targetContractAddress: AztecAddress,
834
- _functionSelector: FunctionSelector,
835
- _argsHash: Fr,
836
- _sideEffectCounter: number,
837
- _isStaticCall: boolean,
838
- _isDelegateCall: boolean,
868
+ targetContractAddress: AztecAddress,
869
+ functionSelector: FunctionSelector,
870
+ argsHash: Fr,
871
+ sideEffectCounter: number,
872
+ isStaticCall: boolean,
873
+ isDelegateCall: boolean,
839
874
  ): Promise<PublicCallRequest> {
840
- throw new Error('Method not implemented.');
875
+ // Definitely not right, in that the teardown should always be last.
876
+ // But useful for executing flows.
877
+ return this.enqueuePublicFunctionCall(
878
+ targetContractAddress,
879
+ functionSelector,
880
+ argsHash,
881
+ sideEffectCounter,
882
+ isStaticCall,
883
+ isDelegateCall,
884
+ );
841
885
  }
842
886
 
843
887
  aes128Encrypt(input: Buffer, initializationVector: Buffer, key: Buffer): Buffer {
@@ -251,6 +251,16 @@ export class TXEService {
251
251
  return toForeignCallResult([]);
252
252
  }
253
253
 
254
+ setFunctionSelector(functionSelector: ForeignCallSingle) {
255
+ (this.typedOracle as TXE).setFunctionSelector(FunctionSelector.fromField(fromSingle(functionSelector)));
256
+ return toForeignCallResult([]);
257
+ }
258
+
259
+ getFunctionSelector() {
260
+ const functionSelector = (this.typedOracle as TXE).getFunctionSelector();
261
+ return toForeignCallResult([toSingle(functionSelector.toField())]);
262
+ }
263
+
254
264
  // PXE oracles
255
265
 
256
266
  getRandomField() {
@@ -277,6 +287,11 @@ export class TXEService {
277
287
  return toForeignCallResult([toSingle(new Fr(blockNumber))]);
278
288
  }
279
289
 
290
+ avmOpcodeFunctionSelector() {
291
+ const functionSelector = (this.typedOracle as TXE).getFunctionSelector();
292
+ return toForeignCallResult([toSingle(functionSelector.toField())]);
293
+ }
294
+
280
295
  async packArgumentsArray(args: ForeignCallArray) {
281
296
  const packed = await this.typedOracle.packArgumentsArray(fromArray(args));
282
297
  return toForeignCallResult([toSingle(packed)]);
@@ -308,9 +323,16 @@ export class TXEService {
308
323
  return toForeignCallResult([]);
309
324
  }
310
325
 
311
- async storageRead(startStorageSlot: ForeignCallSingle, numberOfElements: ForeignCallSingle) {
326
+ async storageRead(
327
+ contractAddress: ForeignCallSingle,
328
+ startStorageSlot: ForeignCallSingle,
329
+ blockNumber: ForeignCallSingle,
330
+ numberOfElements: ForeignCallSingle,
331
+ ) {
312
332
  const values = await this.typedOracle.storageRead(
333
+ fromSingle(contractAddress),
313
334
  fromSingle(startStorageSlot),
335
+ fromSingle(blockNumber).toNumber(),
314
336
  fromSingle(numberOfElements).toNumber(),
315
337
  );
316
338
  return toForeignCallResult([toArray(values)]);
@@ -499,13 +521,41 @@ export class TXEService {
499
521
  fromSingle(address),
500
522
  FunctionSelector.fromField(fromSingle(functionSelector)),
501
523
  fromArray(args),
502
- false,
503
- false,
524
+ /* isStaticCall */ false,
525
+ /* isDelegateCall */ false,
504
526
  );
505
527
 
506
528
  return toForeignCallResult([toArray(result.returnValues), toSingle(new Fr(1))]);
507
529
  }
508
530
 
531
+ async avmOpcodeStaticCall(
532
+ _gas: ForeignCallArray,
533
+ address: ForeignCallSingle,
534
+ _length: ForeignCallSingle,
535
+ args: ForeignCallArray,
536
+ functionSelector: ForeignCallSingle,
537
+ ) {
538
+ const result = await (this.typedOracle as TXE).avmOpcodeCall(
539
+ fromSingle(address),
540
+ FunctionSelector.fromField(fromSingle(functionSelector)),
541
+ fromArray(args),
542
+ /* isStaticCall */ true,
543
+ /* isDelegateCall */ false,
544
+ );
545
+
546
+ return toForeignCallResult([toArray(result.returnValues), toSingle(new Fr(1))]);
547
+ }
548
+
549
+ async avmOpcodeStorageRead(slot: ForeignCallSingle, length: ForeignCallSingle) {
550
+ const values = await (this.typedOracle as TXE).avmOpcodeStorageRead(fromSingle(slot), fromSingle(length));
551
+ return toForeignCallResult([toArray(values)]);
552
+ }
553
+
554
+ async avmOpcodeStorageWrite(startStorageSlot: ForeignCallSingle, values: ForeignCallArray) {
555
+ await this.typedOracle.storageWrite(fromSingle(startStorageSlot), fromArray(values));
556
+ return toForeignCallResult([]);
557
+ }
558
+
509
559
  async getPublicKeysAndPartialAddress(address: ForeignCallSingle) {
510
560
  const parsedAddress = AztecAddress.fromField(fromSingle(address));
511
561
  const { publicKeys, partialAddress } = await this.typedOracle.getCompleteAddress(parsedAddress);
@@ -564,6 +614,10 @@ export class TXEService {
564
614
  return toForeignCallResult([]);
565
615
  }
566
616
 
617
+ emitEncryptedEventLog(_contractAddress: AztecAddress, _randomness: Fr, _encryptedEvent: Buffer, _counter: number) {
618
+ return toForeignCallResult([]);
619
+ }
620
+
567
621
  async callPrivateFunction(
568
622
  targetContractAddress: ForeignCallSingle,
569
623
  functionSelector: ForeignCallSingle,
@@ -626,6 +680,33 @@ export class TXEService {
626
680
  return toForeignCallResult([toArray(fields)]);
627
681
  }
628
682
 
683
+ public async setPublicTeardownFunctionCall(
684
+ targetContractAddress: ForeignCallSingle,
685
+ functionSelector: ForeignCallSingle,
686
+ argsHash: ForeignCallSingle,
687
+ sideEffectCounter: ForeignCallSingle,
688
+ isStaticCall: ForeignCallSingle,
689
+ isDelegateCall: ForeignCallSingle,
690
+ ) {
691
+ const publicTeardownCallRequest = await this.typedOracle.setPublicTeardownFunctionCall(
692
+ fromSingle(targetContractAddress),
693
+ FunctionSelector.fromField(fromSingle(functionSelector)),
694
+ fromSingle(argsHash),
695
+ fromSingle(sideEffectCounter).toNumber(),
696
+ fromSingle(isStaticCall).toBool(),
697
+ fromSingle(isDelegateCall).toBool(),
698
+ );
699
+
700
+ const fields = [
701
+ publicTeardownCallRequest.contractAddress.toField(),
702
+ publicTeardownCallRequest.functionSelector.toField(),
703
+ ...publicTeardownCallRequest.callContext.toFields(),
704
+ publicTeardownCallRequest.getArgsHash(),
705
+ ];
706
+
707
+ return toForeignCallResult([toArray(fields)]);
708
+ }
709
+
629
710
  async getChainId() {
630
711
  return toForeignCallResult([toSingle(await this.typedOracle.getChainId())]);
631
712
  }