@aztec/txe 0.46.7 → 0.47.1

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,7 @@
1
1
  import {
2
2
  AuthWitness,
3
+ Event,
4
+ L1EventPayload,
3
5
  L1NotePayload,
4
6
  MerkleTreeId,
5
7
  Note,
@@ -7,13 +9,13 @@ import {
7
9
  NullifierMembershipWitness,
8
10
  PublicDataWitness,
9
11
  PublicDataWrite,
12
+ PublicExecutionRequest,
10
13
  TaggedLog,
11
14
  type UnencryptedL2Log,
12
15
  } from '@aztec/circuit-types';
13
16
  import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats';
14
17
  import {
15
18
  CallContext,
16
- FunctionData,
17
19
  Gas,
18
20
  GlobalVariables,
19
21
  Header,
@@ -23,10 +25,8 @@ import {
23
25
  type NullifierLeafPreimage,
24
26
  PUBLIC_DATA_SUBTREE_HEIGHT,
25
27
  type PUBLIC_DATA_TREE_HEIGHT,
26
- PrivateCallStackItem,
27
28
  PrivateCircuitPublicInputs,
28
29
  PrivateContextInputs,
29
- PublicCallRequest,
30
30
  PublicDataTreeLeaf,
31
31
  type PublicDataTreeLeafPreimage,
32
32
  TxContext,
@@ -38,6 +38,7 @@ import { Aes128, Schnorr } from '@aztec/circuits.js/barretenberg';
38
38
  import { computePublicDataTreeLeafSlot, siloNoteHash, siloNullifier } from '@aztec/circuits.js/hash';
39
39
  import {
40
40
  type ContractArtifact,
41
+ EventSelector,
41
42
  type FunctionAbi,
42
43
  FunctionSelector,
43
44
  type NoteSelector,
@@ -523,6 +524,7 @@ export class TXE implements TypedOracle {
523
524
  noteTypeId: NoteSelector,
524
525
  ovKeys: KeyValidationRequest,
525
526
  ivpkM: Point,
527
+ recipient: AztecAddress,
526
528
  preimage: Fr[],
527
529
  ): Buffer {
528
530
  const note = new Note(preimage);
@@ -531,8 +533,6 @@ export class TXE implements TypedOracle {
531
533
 
532
534
  const ephSk = GrumpkinScalar.random();
533
535
 
534
- const recipient = AztecAddress.random();
535
-
536
536
  return taggedNote.encrypt(ephSk, recipient, ivpkM, ovKeys);
537
537
  }
538
538
 
@@ -551,7 +551,7 @@ export class TXE implements TypedOracle {
551
551
  sideEffectCounter: number,
552
552
  isStaticCall: boolean,
553
553
  isDelegateCall: boolean,
554
- ): Promise<PrivateCallStackItem> {
554
+ ) {
555
555
  this.logger.verbose(
556
556
  `Executing external function ${targetContractAddress}:${functionSelector}(${await this.getDebugFunctionName(
557
557
  targetContractAddress,
@@ -607,13 +607,9 @@ export class TXE implements TypedOracle {
607
607
  appCircuitName: 'noname',
608
608
  } satisfies CircuitWitnessGenerationStats);
609
609
 
610
- const callStackItem = new PrivateCallStackItem(
611
- targetContractAddress,
612
- new FunctionData(functionSelector, true),
613
- publicInputs,
614
- );
615
610
  // Apply side effects
616
- this.sideEffectsCounter = publicInputs.endSideEffectCounter.toNumber();
611
+ const endSideEffectCounter = publicInputs.endSideEffectCounter;
612
+ this.sideEffectsCounter = endSideEffectCounter.toNumber();
617
613
 
618
614
  await this.addNullifiers(
619
615
  targetContractAddress,
@@ -625,7 +621,7 @@ export class TXE implements TypedOracle {
625
621
  publicInputs.noteHashes.filter(noteHash => !noteHash.isEmpty()).map(noteHash => noteHash.value),
626
622
  );
627
623
 
628
- return callStackItem;
624
+ return { endSideEffectCounter, returnsHash: publicInputs.returnsHash };
629
625
  } finally {
630
626
  this.setContractAddress(currentContractAddress);
631
627
  this.setMsgSender(currentMessageSender);
@@ -680,12 +676,7 @@ export class TXE implements TypedOracle {
680
676
  return `${artifact.name}:${f.name}`;
681
677
  }
682
678
 
683
- async executePublicFunction(
684
- targetContractAddress: AztecAddress,
685
- functionSelector: FunctionSelector,
686
- args: Fr[],
687
- callContext: CallContext,
688
- ) {
679
+ async executePublicFunction(targetContractAddress: AztecAddress, args: Fr[], callContext: CallContext) {
689
680
  const header = Header.empty();
690
681
  header.state = await this.trees.getStateReference(true);
691
682
  header.globalVariables.blockNumber = new Fr(await this.getBlockNumber());
@@ -707,12 +698,7 @@ export class TXE implements TypedOracle {
707
698
  new WorldStateDB(this.trees.asLatest()),
708
699
  header,
709
700
  );
710
- const execution = {
711
- contractAddress: targetContractAddress,
712
- functionSelector,
713
- args,
714
- callContext,
715
- };
701
+ const execution = new PublicExecutionRequest(targetContractAddress, callContext, args);
716
702
 
717
703
  return executor.simulate(
718
704
  execution,
@@ -746,12 +732,7 @@ export class TXE implements TypedOracle {
746
732
  callContext.isStaticCall = isStaticCall;
747
733
  callContext.isDelegateCall = isDelegateCall;
748
734
 
749
- const executionResult = await this.executePublicFunction(
750
- targetContractAddress,
751
- functionSelector,
752
- args,
753
- callContext,
754
- );
735
+ const executionResult = await this.executePublicFunction(targetContractAddress, args, callContext);
755
736
 
756
737
  // Apply side effects
757
738
  if (!executionResult.reverted) {
@@ -768,7 +749,7 @@ export class TXE implements TypedOracle {
768
749
  targetContractAddress: AztecAddress,
769
750
  functionSelector: FunctionSelector,
770
751
  argsHash: Fr,
771
- sideEffectCounter: number,
752
+ _sideEffectCounter: number,
772
753
  isStaticCall: boolean,
773
754
  isDelegateCall: boolean,
774
755
  ): Promise<Fr[]> {
@@ -789,12 +770,7 @@ export class TXE implements TypedOracle {
789
770
 
790
771
  const args = this.packedValuesCache.unpack(argsHash);
791
772
 
792
- const executionResult = await this.executePublicFunction(
793
- targetContractAddress,
794
- functionSelector,
795
- args,
796
- callContext,
797
- );
773
+ const executionResult = await this.executePublicFunction(targetContractAddress, args, callContext);
798
774
 
799
775
  // Apply side effects
800
776
  this.sideEffectsCounter = executionResult.endSideEffectCounter.toNumber();
@@ -809,10 +785,10 @@ export class TXE implements TypedOracle {
809
785
  targetContractAddress: AztecAddress,
810
786
  functionSelector: FunctionSelector,
811
787
  argsHash: Fr,
812
- sideEffectCounter: number,
788
+ _sideEffectCounter: number,
813
789
  isStaticCall: boolean,
814
790
  isDelegateCall: boolean,
815
- ): Promise<PublicCallRequest> {
791
+ ) {
816
792
  // Store and modify env
817
793
  const currentContractAddress = AztecAddress.fromField(this.contractAddress);
818
794
  const currentMessageSender = AztecAddress.fromField(this.msgSender);
@@ -830,47 +806,26 @@ export class TXE implements TypedOracle {
830
806
 
831
807
  const args = this.packedValuesCache.unpack(argsHash);
832
808
 
833
- const executionResult = await this.executePublicFunction(
834
- targetContractAddress,
835
- functionSelector,
836
- args,
837
- callContext,
838
- );
809
+ const executionResult = await this.executePublicFunction(targetContractAddress, args, callContext);
839
810
 
840
811
  // Apply side effects
841
812
  this.sideEffectsCounter += executionResult.endSideEffectCounter.toNumber();
842
813
  this.setContractAddress(currentContractAddress);
843
814
  this.setMsgSender(currentMessageSender);
844
815
  this.setFunctionSelector(currentFunctionSelector);
845
-
846
- const parentCallContext = CallContext.empty();
847
- parentCallContext.msgSender = currentMessageSender;
848
- parentCallContext.functionSelector = currentFunctionSelector;
849
- parentCallContext.storageContractAddress = currentContractAddress;
850
- parentCallContext.isStaticCall = isStaticCall;
851
- parentCallContext.isDelegateCall = isDelegateCall;
852
-
853
- return PublicCallRequest.from({
854
- parentCallContext,
855
- contractAddress: targetContractAddress,
856
- functionSelector,
857
- callContext,
858
- sideEffectCounter,
859
- args,
860
- });
861
816
  }
862
817
 
863
- setPublicTeardownFunctionCall(
818
+ async setPublicTeardownFunctionCall(
864
819
  targetContractAddress: AztecAddress,
865
820
  functionSelector: FunctionSelector,
866
821
  argsHash: Fr,
867
822
  sideEffectCounter: number,
868
823
  isStaticCall: boolean,
869
824
  isDelegateCall: boolean,
870
- ): Promise<PublicCallRequest> {
825
+ ) {
871
826
  // Definitely not right, in that the teardown should always be last.
872
827
  // But useful for executing flows.
873
- return this.enqueuePublicFunctionCall(
828
+ await this.enqueuePublicFunctionCall(
874
829
  targetContractAddress,
875
830
  functionSelector,
876
831
  argsHash,
@@ -899,13 +854,20 @@ export class TXE implements TypedOracle {
899
854
  }
900
855
 
901
856
  computeEncryptedEventLog(
902
- _contractAddress: AztecAddress,
903
- _randomness: Fr,
904
- _eventTypeId: Fr,
905
- _ovKeys: KeyValidationRequest,
906
- _ivpkM: Point,
907
- _preimage: Fr[],
857
+ contractAddress: AztecAddress,
858
+ randomness: Fr,
859
+ eventTypeId: Fr,
860
+ ovKeys: KeyValidationRequest,
861
+ ivpkM: Point,
862
+ recipient: AztecAddress,
863
+ preimage: Fr[],
908
864
  ): Buffer {
909
- throw new Error('Method not implemented.');
865
+ const event = new Event(preimage);
866
+ const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, EventSelector.fromField(eventTypeId));
867
+ const taggedEvent = new TaggedLog(l1EventPayload);
868
+
869
+ const ephSk = GrumpkinScalar.random();
870
+
871
+ return taggedEvent.encrypt(ephSk, recipient, ivpkM, ovKeys);
910
872
  }
911
873
  }
@@ -1,3 +1,4 @@
1
+ import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
1
2
  import { L2Block, MerkleTreeId, PublicDataWrite } from '@aztec/circuit-types';
2
3
  import {
3
4
  Fr,
@@ -7,10 +8,11 @@ import {
7
8
  PUBLIC_DATA_SUBTREE_HEIGHT,
8
9
  Point,
9
10
  PublicDataTreeLeaf,
11
+ computePartialAddress,
10
12
  getContractInstanceFromDeployParams,
11
13
  } from '@aztec/circuits.js';
12
14
  import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
13
- import { NoteSelector } from '@aztec/foundation/abi';
15
+ import { type ContractArtifact, NoteSelector } from '@aztec/foundation/abi';
14
16
  import { AztecAddress } from '@aztec/foundation/aztec-address';
15
17
  import { type Logger } from '@aztec/foundation/log';
16
18
  import { KeyStore } from '@aztec/key-store';
@@ -92,27 +94,22 @@ export class TXEService {
92
94
  }
93
95
 
94
96
  async deploy(
95
- path: ForeignCallArray,
97
+ artifact: ContractArtifact,
96
98
  initializer: ForeignCallArray,
97
99
  _length: ForeignCallSingle,
98
100
  args: ForeignCallArray,
99
101
  publicKeysHash: ForeignCallSingle,
100
102
  ) {
101
- const pathStr = fromArray(path)
102
- .map(char => String.fromCharCode(char.toNumber()))
103
- .join('');
104
103
  const initializerStr = fromArray(initializer)
105
104
  .map(char => String.fromCharCode(char.toNumber()))
106
105
  .join('');
107
106
  const decodedArgs = fromArray(args);
108
107
  const publicKeysHashFr = fromSingle(publicKeysHash);
109
108
  this.logger.debug(
110
- `Deploy ${pathStr} with initializer ${initializerStr}(${decodedArgs}) and public keys hash ${publicKeysHashFr}`,
109
+ `Deploy ${artifact.name} with initializer ${initializerStr}(${decodedArgs}) and public keys hash ${publicKeysHashFr}`,
111
110
  );
112
- const contractModule = await import(pathStr);
113
- // Hacky way of getting the class, the name of the Artifact is always longer
114
- const contractClass = contractModule[Object.keys(contractModule).sort((a, b) => a.length - b.length)[0]];
115
- const instance = getContractInstanceFromDeployParams(contractClass.artifact, {
111
+
112
+ const instance = getContractInstanceFromDeployParams(artifact, {
116
113
  constructorArgs: decodedArgs,
117
114
  skipArgsDecoding: true,
118
115
  salt: Fr.ONE,
@@ -121,9 +118,9 @@ export class TXEService {
121
118
  deployer: AztecAddress.ZERO,
122
119
  });
123
120
 
124
- this.logger.debug(`Deployed ${contractClass.artifact.name} at ${instance.address}`);
121
+ this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
125
122
  await (this.typedOracle as TXE).addContractInstance(instance);
126
- await (this.typedOracle as TXE).addContractArtifact(contractClass.artifact);
123
+ await (this.typedOracle as TXE).addContractArtifact(artifact);
127
124
  return toForeignCallResult([
128
125
  toArray([
129
126
  instance.salt,
@@ -171,9 +168,26 @@ export class TXEService {
171
168
  ]);
172
169
  }
173
170
 
174
- async addAccount(secret: ForeignCallSingle, partialAddress: ForeignCallSingle) {
171
+ async addAccount(secret: ForeignCallSingle) {
172
+ const keys = (this.typedOracle as TXE).deriveKeys(fromSingle(secret));
173
+ const args = [keys.publicKeys.masterIncomingViewingPublicKey.x, keys.publicKeys.masterIncomingViewingPublicKey.y];
174
+ const hash = keys.publicKeys.hash();
175
+ const artifact = SchnorrAccountContractArtifact;
176
+ const instance = getContractInstanceFromDeployParams(artifact, {
177
+ constructorArgs: args,
178
+ skipArgsDecoding: true,
179
+ salt: Fr.ONE,
180
+ publicKeysHash: hash,
181
+ constructorArtifact: 'constructor',
182
+ deployer: AztecAddress.ZERO,
183
+ });
184
+
185
+ this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
186
+ await (this.typedOracle as TXE).addContractInstance(instance);
187
+ await (this.typedOracle as TXE).addContractArtifact(artifact);
188
+
175
189
  const keyStore = (this.typedOracle as TXE).getKeyStore();
176
- const completeAddress = await keyStore.addAccount(fromSingle(secret), fromSingle(partialAddress));
190
+ const completeAddress = await keyStore.addAccount(fromSingle(secret), computePartialAddress(instance));
177
191
  const accountStore = (this.typedOracle as TXE).getTXEDatabase();
178
192
  await accountStore.setAccount(completeAddress.address, completeAddress);
179
193
  this.logger.debug(`Created account ${completeAddress.address}`);
@@ -578,6 +592,7 @@ export class TXEService {
578
592
  ivpkMX: ForeignCallSingle,
579
593
  ivpkMY: ForeignCallSingle,
580
594
  ivpkMIsInfinite: ForeignCallSingle,
595
+ recipient: ForeignCallSingle,
581
596
  preimage: ForeignCallArray,
582
597
  ) {
583
598
  const ovpkM = new Point(fromSingle(ovpkMX), fromSingle(ovpkMY), !fromSingle(ovpkMIsInfinite).isZero());
@@ -589,6 +604,7 @@ export class TXEService {
589
604
  NoteSelector.fromField(Fr.fromString(fromSingle(noteTypeId).toString())),
590
605
  ovKeys,
591
606
  ivpkM,
607
+ AztecAddress.fromString(fromSingle(recipient).toString()),
592
608
  fromArray(preimage),
593
609
  );
594
610
  const bytes: Fr[] = [];
@@ -636,7 +652,7 @@ export class TXEService {
636
652
  fromSingle(isStaticCall).toBool(),
637
653
  fromSingle(isDelegateCall).toBool(),
638
654
  );
639
- return toForeignCallResult([toArray(result.toFields())]);
655
+ return toForeignCallResult([toArray([result.endSideEffectCounter, result.returnsHash])]);
640
656
  }
641
657
 
642
658
  async getNullifierMembershipWitness(blockNumber: ForeignCallSingle, nullifier: ForeignCallSingle) {
@@ -665,7 +681,7 @@ export class TXEService {
665
681
  isStaticCall: ForeignCallSingle,
666
682
  isDelegateCall: ForeignCallSingle,
667
683
  ) {
668
- const publicCallRequest = await this.typedOracle.enqueuePublicFunctionCall(
684
+ await this.typedOracle.enqueuePublicFunctionCall(
669
685
  fromSingle(targetContractAddress),
670
686
  FunctionSelector.fromField(fromSingle(functionSelector)),
671
687
  fromSingle(argsHash),
@@ -673,14 +689,7 @@ export class TXEService {
673
689
  fromSingle(isStaticCall).toBool(),
674
690
  fromSingle(isDelegateCall).toBool(),
675
691
  );
676
- const fields = [
677
- publicCallRequest.contractAddress.toField(),
678
- publicCallRequest.functionSelector.toField(),
679
- ...publicCallRequest.callContext.toFields(),
680
- fromSingle(sideEffectCounter),
681
- publicCallRequest.getArgsHash(),
682
- ];
683
- return toForeignCallResult([toArray(fields)]);
692
+ return toForeignCallResult([]);
684
693
  }
685
694
 
686
695
  public async setPublicTeardownFunctionCall(
@@ -691,7 +700,7 @@ export class TXEService {
691
700
  isStaticCall: ForeignCallSingle,
692
701
  isDelegateCall: ForeignCallSingle,
693
702
  ) {
694
- const publicTeardownCallRequest = await this.typedOracle.setPublicTeardownFunctionCall(
703
+ await this.typedOracle.setPublicTeardownFunctionCall(
695
704
  fromSingle(targetContractAddress),
696
705
  FunctionSelector.fromField(fromSingle(functionSelector)),
697
706
  fromSingle(argsHash),
@@ -699,16 +708,7 @@ export class TXEService {
699
708
  fromSingle(isStaticCall).toBool(),
700
709
  fromSingle(isDelegateCall).toBool(),
701
710
  );
702
-
703
- const fields = [
704
- publicTeardownCallRequest.contractAddress.toField(),
705
- publicTeardownCallRequest.functionSelector.toField(),
706
- ...publicTeardownCallRequest.callContext.toFields(),
707
- fromSingle(sideEffectCounter),
708
- publicTeardownCallRequest.getArgsHash(),
709
- ];
710
-
711
- return toForeignCallResult([toArray(fields)]);
711
+ return toForeignCallResult([]);
712
712
  }
713
713
 
714
714
  async getChainId() {