@aztec/txe 0.56.0 → 0.58.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/bin/index.js +5 -1
- package/dest/oracle/txe_oracle.d.ts +4 -8
- package/dest/oracle/txe_oracle.d.ts.map +1 -1
- package/dest/oracle/txe_oracle.js +26 -45
- package/dest/txe_service/txe_service.d.ts +6 -3
- package/dest/txe_service/txe_service.d.ts.map +1 -1
- package/dest/txe_service/txe_service.js +31 -24
- package/dest/util/txe_public_contract_data_source.d.ts +1 -2
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +10 -3
- package/dest/util/txe_world_state_db.d.ts +3 -4
- package/dest/util/txe_world_state_db.d.ts.map +1 -1
- package/dest/util/txe_world_state_db.js +1 -1
- package/package.json +18 -14
- package/src/bin/index.ts +5 -0
- package/src/oracle/txe_oracle.ts +31 -77
- package/src/txe_service/txe_service.ts +32 -47
- package/src/util/txe_public_contract_data_source.ts +16 -5
- package/src/util/txe_world_state_db.ts +3 -3
package/src/oracle/txe_oracle.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthWitness,
|
|
3
|
-
Event,
|
|
4
|
-
L1EventPayload,
|
|
5
|
-
L1NotePayload,
|
|
6
3
|
MerkleTreeId,
|
|
7
4
|
Note,
|
|
8
5
|
type NoteStatus,
|
|
@@ -10,14 +7,15 @@ import {
|
|
|
10
7
|
PublicDataWitness,
|
|
11
8
|
PublicDataWrite,
|
|
12
9
|
PublicExecutionRequest,
|
|
13
|
-
TaggedLog,
|
|
14
10
|
type UnencryptedL2Log,
|
|
15
11
|
} from '@aztec/circuit-types';
|
|
16
12
|
import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats';
|
|
17
13
|
import {
|
|
18
14
|
CallContext,
|
|
15
|
+
CombinedConstantData,
|
|
16
|
+
type ContractInstance,
|
|
17
|
+
type ContractInstanceWithAddress,
|
|
19
18
|
Gas,
|
|
20
|
-
GlobalVariables,
|
|
21
19
|
Header,
|
|
22
20
|
type KeyValidationRequest,
|
|
23
21
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
@@ -25,7 +23,7 @@ import {
|
|
|
25
23
|
type NullifierLeafPreimage,
|
|
26
24
|
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
27
25
|
type PUBLIC_DATA_TREE_HEIGHT,
|
|
28
|
-
|
|
26
|
+
PUBLIC_DISPATCH_SELECTOR,
|
|
29
27
|
PrivateContextInputs,
|
|
30
28
|
PublicDataTreeLeaf,
|
|
31
29
|
type PublicDataTreeLeafPreimage,
|
|
@@ -34,18 +32,17 @@ import {
|
|
|
34
32
|
deriveKeys,
|
|
35
33
|
getContractClassFromArtifact,
|
|
36
34
|
} from '@aztec/circuits.js';
|
|
37
|
-
import {
|
|
35
|
+
import { Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
38
36
|
import { computePublicDataTreeLeafSlot, siloNoteHash, siloNullifier } from '@aztec/circuits.js/hash';
|
|
39
37
|
import {
|
|
40
38
|
type ContractArtifact,
|
|
41
|
-
EventSelector,
|
|
42
39
|
type FunctionAbi,
|
|
43
40
|
FunctionSelector,
|
|
44
41
|
type NoteSelector,
|
|
45
42
|
countArgumentsSize,
|
|
46
43
|
} from '@aztec/foundation/abi';
|
|
47
44
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
48
|
-
import { Fr
|
|
45
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
49
46
|
import { type Logger, applyStringFormatting } from '@aztec/foundation/log';
|
|
50
47
|
import { Timer } from '@aztec/foundation/timer';
|
|
51
48
|
import { type KeyStore } from '@aztec/key-store';
|
|
@@ -62,12 +59,12 @@ import {
|
|
|
62
59
|
acvm,
|
|
63
60
|
createSimulationError,
|
|
64
61
|
extractCallStack,
|
|
62
|
+
extractPrivateCircuitPublicInputs,
|
|
65
63
|
pickNotes,
|
|
66
64
|
toACVMWitness,
|
|
67
65
|
witnessMapToFields,
|
|
68
66
|
} from '@aztec/simulator';
|
|
69
67
|
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
|
|
70
|
-
import { type ContractInstance, type ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
71
68
|
import { MerkleTreeSnapshotOperationsFacade, type MerkleTrees } from '@aztec/world-state';
|
|
72
69
|
|
|
73
70
|
import { type TXEDatabase } from '../util/txe_database.js';
|
|
@@ -109,7 +106,7 @@ export class TXE implements TypedOracle {
|
|
|
109
106
|
async #getTreesAt(blockNumber: number) {
|
|
110
107
|
const db =
|
|
111
108
|
blockNumber === (await this.getBlockNumber())
|
|
112
|
-
? this.trees.
|
|
109
|
+
? await this.trees.getLatest()
|
|
113
110
|
: new MerkleTreeSnapshotOperationsFacade(this.trees, blockNumber);
|
|
114
111
|
return db;
|
|
115
112
|
}
|
|
@@ -214,20 +211,20 @@ export class TXE implements TypedOracle {
|
|
|
214
211
|
|
|
215
212
|
async avmOpcodeNullifierExists(innerNullifier: Fr, targetAddress: AztecAddress): Promise<boolean> {
|
|
216
213
|
const nullifier = siloNullifier(targetAddress, innerNullifier!);
|
|
217
|
-
const db = this.trees.
|
|
214
|
+
const db = await this.trees.getLatest();
|
|
218
215
|
const index = await db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer());
|
|
219
216
|
return index !== undefined;
|
|
220
217
|
}
|
|
221
218
|
|
|
222
219
|
async avmOpcodeEmitNullifier(nullifier: Fr) {
|
|
223
|
-
const db = this.trees.
|
|
220
|
+
const db = await this.trees.getLatest();
|
|
224
221
|
const siloedNullifier = siloNullifier(this.contractAddress, nullifier);
|
|
225
222
|
await db.batchInsert(MerkleTreeId.NULLIFIER_TREE, [siloedNullifier.toBuffer()], NULLIFIER_SUBTREE_HEIGHT);
|
|
226
223
|
return Promise.resolve();
|
|
227
224
|
}
|
|
228
225
|
|
|
229
226
|
async avmOpcodeEmitNoteHash(noteHash: Fr) {
|
|
230
|
-
const db = this.trees.
|
|
227
|
+
const db = await this.trees.getLatest();
|
|
231
228
|
const siloedNoteHash = siloNoteHash(this.contractAddress, noteHash);
|
|
232
229
|
await db.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, [siloedNoteHash]);
|
|
233
230
|
return Promise.resolve();
|
|
@@ -247,14 +244,14 @@ export class TXE implements TypedOracle {
|
|
|
247
244
|
}
|
|
248
245
|
|
|
249
246
|
async addNullifiers(contractAddress: AztecAddress, nullifiers: Fr[]) {
|
|
250
|
-
const db = this.trees.
|
|
247
|
+
const db = await this.trees.getLatest();
|
|
251
248
|
const siloedNullifiers = nullifiers.map(nullifier => siloNullifier(contractAddress, nullifier).toBuffer());
|
|
252
249
|
|
|
253
250
|
await db.batchInsert(MerkleTreeId.NULLIFIER_TREE, siloedNullifiers, NULLIFIER_SUBTREE_HEIGHT);
|
|
254
251
|
}
|
|
255
252
|
|
|
256
253
|
async addNoteHashes(contractAddress: AztecAddress, noteHashes: Fr[]) {
|
|
257
|
-
const db = this.trees.
|
|
254
|
+
const db = await this.trees.getLatest();
|
|
258
255
|
const siloedNoteHashes = noteHashes.map(noteHash => siloNoteHash(contractAddress, noteHash));
|
|
259
256
|
await db.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, siloedNoteHashes);
|
|
260
257
|
}
|
|
@@ -458,7 +455,7 @@ export class TXE implements TypedOracle {
|
|
|
458
455
|
|
|
459
456
|
async checkNullifierExists(innerNullifier: Fr): Promise<boolean> {
|
|
460
457
|
const nullifier = siloNullifier(this.contractAddress, innerNullifier!);
|
|
461
|
-
const db = this.trees.
|
|
458
|
+
const db = await this.trees.getLatest();
|
|
462
459
|
const index = await db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer());
|
|
463
460
|
return index !== undefined;
|
|
464
461
|
}
|
|
@@ -472,7 +469,7 @@ export class TXE implements TypedOracle {
|
|
|
472
469
|
}
|
|
473
470
|
|
|
474
471
|
async avmOpcodeStorageRead(slot: Fr) {
|
|
475
|
-
const db = this.trees.
|
|
472
|
+
const db = await this.trees.getLatest();
|
|
476
473
|
|
|
477
474
|
const leafSlot = computePublicDataTreeLeafSlot(this.contractAddress, slot);
|
|
478
475
|
|
|
@@ -518,7 +515,7 @@ export class TXE implements TypedOracle {
|
|
|
518
515
|
}
|
|
519
516
|
|
|
520
517
|
async storageWrite(startStorageSlot: Fr, values: Fr[]): Promise<Fr[]> {
|
|
521
|
-
const db = this.trees.
|
|
518
|
+
const db = await this.trees.getLatest();
|
|
522
519
|
|
|
523
520
|
const publicDataWrites = values.map((value, i) => {
|
|
524
521
|
const storageSlot = startStorageSlot.add(new Fr(i));
|
|
@@ -543,24 +540,6 @@ export class TXE implements TypedOracle {
|
|
|
543
540
|
return;
|
|
544
541
|
}
|
|
545
542
|
|
|
546
|
-
computeEncryptedNoteLog(
|
|
547
|
-
contractAddress: AztecAddress,
|
|
548
|
-
storageSlot: Fr,
|
|
549
|
-
noteTypeId: NoteSelector,
|
|
550
|
-
ovKeys: KeyValidationRequest,
|
|
551
|
-
ivpkM: Point,
|
|
552
|
-
recipient: AztecAddress,
|
|
553
|
-
preimage: Fr[],
|
|
554
|
-
): Buffer {
|
|
555
|
-
const note = new Note(preimage);
|
|
556
|
-
const l1NotePayload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId);
|
|
557
|
-
const taggedNote = new TaggedLog(l1NotePayload);
|
|
558
|
-
|
|
559
|
-
const ephSk = GrumpkinScalar.random();
|
|
560
|
-
|
|
561
|
-
return taggedNote.encrypt(ephSk, recipient, ivpkM, ovKeys);
|
|
562
|
-
}
|
|
563
|
-
|
|
564
543
|
emitUnencryptedLog(_log: UnencryptedL2Log, counter: number): void {
|
|
565
544
|
this.sideEffectsCounter = counter + 1;
|
|
566
545
|
return;
|
|
@@ -579,10 +558,10 @@ export class TXE implements TypedOracle {
|
|
|
579
558
|
isDelegateCall: boolean,
|
|
580
559
|
) {
|
|
581
560
|
this.logger.verbose(
|
|
582
|
-
`Executing external function ${
|
|
561
|
+
`Executing external function ${await this.getDebugFunctionName(
|
|
583
562
|
targetContractAddress,
|
|
584
563
|
functionSelector,
|
|
585
|
-
)}
|
|
564
|
+
)}@${targetContractAddress} isStaticCall=${isStaticCall} isDelegateCall=${isDelegateCall}`,
|
|
586
565
|
);
|
|
587
566
|
|
|
588
567
|
// Store and modify env
|
|
@@ -620,8 +599,7 @@ export class TXE implements TypedOracle {
|
|
|
620
599
|
throw createSimulationError(execError);
|
|
621
600
|
});
|
|
622
601
|
const duration = timer.ms();
|
|
623
|
-
const
|
|
624
|
-
const publicInputs = PrivateCircuitPublicInputs.fromFields(returnWitness);
|
|
602
|
+
const publicInputs = extractPrivateCircuitPublicInputs(artifact, acirExecutionResult.partialWitness);
|
|
625
603
|
|
|
626
604
|
const initialWitnessSize = witnessMapToFields(initialWitness).length * Fr.SIZE_IN_BYTES;
|
|
627
605
|
this.logger.debug(`Ran external function ${targetContractAddress.toString()}:${functionSelector}`, {
|
|
@@ -708,26 +686,22 @@ export class TXE implements TypedOracle {
|
|
|
708
686
|
callContext: CallContext,
|
|
709
687
|
counter: number,
|
|
710
688
|
) {
|
|
711
|
-
const header = Header.empty();
|
|
712
|
-
header.state = await this.trees.getStateReference(true);
|
|
713
|
-
header.globalVariables.blockNumber = new Fr(await this.getBlockNumber());
|
|
714
|
-
|
|
715
689
|
const executor = new PublicExecutor(
|
|
716
|
-
new TXEWorldStateDB(this.trees.
|
|
717
|
-
header,
|
|
690
|
+
new TXEWorldStateDB(await this.trees.getLatest(), new TXEPublicContractDataSource(this)),
|
|
718
691
|
new NoopTelemetryClient(),
|
|
719
692
|
);
|
|
720
693
|
const execution = new PublicExecutionRequest(targetContractAddress, callContext, args);
|
|
721
694
|
|
|
722
|
-
|
|
695
|
+
const executionResult = executor.simulate(
|
|
723
696
|
execution,
|
|
724
|
-
|
|
697
|
+
CombinedConstantData.empty(),
|
|
725
698
|
Gas.test(),
|
|
726
699
|
TxContext.empty(),
|
|
727
700
|
/* pendingNullifiers */ [],
|
|
728
701
|
/* transactionFee */ Fr.ONE,
|
|
729
702
|
counter,
|
|
730
703
|
);
|
|
704
|
+
return Promise.resolve(executionResult);
|
|
731
705
|
}
|
|
732
706
|
|
|
733
707
|
async avmOpcodeCall(
|
|
@@ -778,7 +752,7 @@ export class TXE implements TypedOracle {
|
|
|
778
752
|
sideEffectCounter: number,
|
|
779
753
|
isStaticCall: boolean,
|
|
780
754
|
isDelegateCall: boolean,
|
|
781
|
-
) {
|
|
755
|
+
): Promise<Fr> {
|
|
782
756
|
// Store and modify env
|
|
783
757
|
const currentContractAddress = AztecAddress.fromField(this.contractAddress);
|
|
784
758
|
const currentMessageSender = AztecAddress.fromField(this.msgSender);
|
|
@@ -789,12 +763,13 @@ export class TXE implements TypedOracle {
|
|
|
789
763
|
|
|
790
764
|
const callContext = CallContext.empty();
|
|
791
765
|
callContext.msgSender = this.msgSender;
|
|
792
|
-
callContext.functionSelector =
|
|
766
|
+
callContext.functionSelector = FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR));
|
|
793
767
|
callContext.storageContractAddress = targetContractAddress;
|
|
794
768
|
callContext.isStaticCall = isStaticCall;
|
|
795
769
|
callContext.isDelegateCall = isDelegateCall;
|
|
796
770
|
|
|
797
|
-
const args = this.packedValuesCache.unpack(argsHash);
|
|
771
|
+
const args = [this.functionSelector.toField(), ...this.packedValuesCache.unpack(argsHash)];
|
|
772
|
+
const newArgsHash = this.packedValuesCache.pack(args);
|
|
798
773
|
|
|
799
774
|
const executionResult = await this.executePublicFunction(
|
|
800
775
|
targetContractAddress,
|
|
@@ -812,6 +787,8 @@ export class TXE implements TypedOracle {
|
|
|
812
787
|
this.setContractAddress(currentContractAddress);
|
|
813
788
|
this.setMsgSender(currentMessageSender);
|
|
814
789
|
this.setFunctionSelector(currentFunctionSelector);
|
|
790
|
+
|
|
791
|
+
return newArgsHash;
|
|
815
792
|
}
|
|
816
793
|
|
|
817
794
|
async setPublicTeardownFunctionCall(
|
|
@@ -821,10 +798,10 @@ export class TXE implements TypedOracle {
|
|
|
821
798
|
sideEffectCounter: number,
|
|
822
799
|
isStaticCall: boolean,
|
|
823
800
|
isDelegateCall: boolean,
|
|
824
|
-
) {
|
|
801
|
+
): Promise<Fr> {
|
|
825
802
|
// Definitely not right, in that the teardown should always be last.
|
|
826
803
|
// But useful for executing flows.
|
|
827
|
-
await this.enqueuePublicFunctionCall(
|
|
804
|
+
return await this.enqueuePublicFunctionCall(
|
|
828
805
|
targetContractAddress,
|
|
829
806
|
functionSelector,
|
|
830
807
|
argsHash,
|
|
@@ -838,11 +815,6 @@ export class TXE implements TypedOracle {
|
|
|
838
815
|
this.noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
|
|
839
816
|
}
|
|
840
817
|
|
|
841
|
-
aes128Encrypt(input: Buffer, initializationVector: Buffer, key: Buffer): Buffer {
|
|
842
|
-
const aes128 = new Aes128();
|
|
843
|
-
return aes128.encryptBufferCBC(input, initializationVector, key);
|
|
844
|
-
}
|
|
845
|
-
|
|
846
818
|
debugLog(message: string, fields: Fr[]): void {
|
|
847
819
|
this.logger.verbose(`debug_log ${applyStringFormatting(message, fields)}`);
|
|
848
820
|
}
|
|
@@ -856,22 +828,4 @@ export class TXE implements TypedOracle {
|
|
|
856
828
|
this.sideEffectsCounter = counter + 1;
|
|
857
829
|
return;
|
|
858
830
|
}
|
|
859
|
-
|
|
860
|
-
computeEncryptedEventLog(
|
|
861
|
-
contractAddress: AztecAddress,
|
|
862
|
-
randomness: Fr,
|
|
863
|
-
eventTypeId: Fr,
|
|
864
|
-
ovKeys: KeyValidationRequest,
|
|
865
|
-
ivpkM: Point,
|
|
866
|
-
recipient: AztecAddress,
|
|
867
|
-
preimage: Fr[],
|
|
868
|
-
): Buffer {
|
|
869
|
-
const event = new Event(preimage);
|
|
870
|
-
const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, EventSelector.fromField(eventTypeId));
|
|
871
|
-
const taggedEvent = new TaggedLog(l1EventPayload);
|
|
872
|
-
|
|
873
|
-
const ephSk = GrumpkinScalar.random();
|
|
874
|
-
|
|
875
|
-
return taggedEvent.encrypt(ephSk, recipient, ivpkM, ovKeys);
|
|
876
|
-
}
|
|
877
831
|
}
|
|
@@ -4,10 +4,9 @@ import {
|
|
|
4
4
|
Fr,
|
|
5
5
|
FunctionSelector,
|
|
6
6
|
Header,
|
|
7
|
-
KeyValidationRequest,
|
|
8
7
|
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
9
|
-
Point,
|
|
10
8
|
PublicDataTreeLeaf,
|
|
9
|
+
PublicKeys,
|
|
11
10
|
computePartialAddress,
|
|
12
11
|
getContractInstanceFromDeployParams,
|
|
13
12
|
} from '@aztec/circuits.js';
|
|
@@ -17,6 +16,7 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
|
17
16
|
import { type Logger } from '@aztec/foundation/log';
|
|
18
17
|
import { KeyStore } from '@aztec/key-store';
|
|
19
18
|
import { openTmpStore } from '@aztec/kv-store/utils';
|
|
19
|
+
import { getCanonicalProtocolContract, protocolContractNames } from '@aztec/protocol-contracts';
|
|
20
20
|
import { ExecutionNoteCache, PackedValuesCache, type TypedOracle } from '@aztec/simulator';
|
|
21
21
|
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
|
|
22
22
|
import { MerkleTrees } from '@aztec/world-state';
|
|
@@ -45,6 +45,12 @@ export class TXEService {
|
|
|
45
45
|
const noteCache = new ExecutionNoteCache(txHash);
|
|
46
46
|
const keyStore = new KeyStore(store);
|
|
47
47
|
const txeDatabase = new TXEDatabase(store);
|
|
48
|
+
// Register protocol contracts.
|
|
49
|
+
for (const name of protocolContractNames) {
|
|
50
|
+
const { contractClass, instance, artifact } = getCanonicalProtocolContract(name);
|
|
51
|
+
await txeDatabase.addContractArtifact(contractClass.id, artifact);
|
|
52
|
+
await txeDatabase.addContractInstance(instance);
|
|
53
|
+
}
|
|
48
54
|
logger.debug(`TXE service initialized`);
|
|
49
55
|
const txe = new TXE(logger, trees, packedValuesCache, noteCache, keyStore, txeDatabase);
|
|
50
56
|
const service = new TXEService(logger, txe);
|
|
@@ -110,7 +116,8 @@ export class TXEService {
|
|
|
110
116
|
constructorArgs: decodedArgs,
|
|
111
117
|
skipArgsDecoding: true,
|
|
112
118
|
salt: Fr.ONE,
|
|
113
|
-
|
|
119
|
+
// TODO: Modify this to allow for passing public keys.
|
|
120
|
+
publicKeys: PublicKeys.empty(),
|
|
114
121
|
constructorArtifact: initializerStr ? initializerStr : undefined,
|
|
115
122
|
deployer: AztecAddress.ZERO,
|
|
116
123
|
});
|
|
@@ -124,7 +131,7 @@ export class TXEService {
|
|
|
124
131
|
instance.deployer,
|
|
125
132
|
instance.contractClassId,
|
|
126
133
|
instance.initializationHash,
|
|
127
|
-
instance.
|
|
134
|
+
...instance.publicKeys.toFields(),
|
|
128
135
|
]),
|
|
129
136
|
]);
|
|
130
137
|
}
|
|
@@ -138,7 +145,7 @@ export class TXEService {
|
|
|
138
145
|
const startStorageSlotFr = fromSingle(startStorageSlot);
|
|
139
146
|
const valuesFr = fromArray(values);
|
|
140
147
|
const contractAddressFr = fromSingle(contractAddress);
|
|
141
|
-
const db = trees.
|
|
148
|
+
const db = await trees.getLatest();
|
|
142
149
|
|
|
143
150
|
const publicDataWrites = valuesFr.map((value, i) => {
|
|
144
151
|
const storageSlot = startStorageSlotFr.add(new Fr(i));
|
|
@@ -168,13 +175,12 @@ export class TXEService {
|
|
|
168
175
|
async addAccount(secret: ForeignCallSingle) {
|
|
169
176
|
const keys = (this.typedOracle as TXE).deriveKeys(fromSingle(secret));
|
|
170
177
|
const args = [keys.publicKeys.masterIncomingViewingPublicKey.x, keys.publicKeys.masterIncomingViewingPublicKey.y];
|
|
171
|
-
const hash = keys.publicKeys.hash();
|
|
172
178
|
const artifact = SchnorrAccountContractArtifact;
|
|
173
179
|
const instance = getContractInstanceFromDeployParams(artifact, {
|
|
174
180
|
constructorArgs: args,
|
|
175
181
|
skipArgsDecoding: true,
|
|
176
182
|
salt: Fr.ONE,
|
|
177
|
-
|
|
183
|
+
publicKeys: keys.publicKeys,
|
|
178
184
|
constructorArtifact: 'constructor',
|
|
179
185
|
deployer: AztecAddress.ZERO,
|
|
180
186
|
});
|
|
@@ -503,7 +509,7 @@ export class TXEService {
|
|
|
503
509
|
instance.deployer,
|
|
504
510
|
instance.contractClassId,
|
|
505
511
|
instance.initializationHash,
|
|
506
|
-
instance.
|
|
512
|
+
...instance.publicKeys.toFields(),
|
|
507
513
|
]),
|
|
508
514
|
]);
|
|
509
515
|
}
|
|
@@ -518,7 +524,7 @@ export class TXEService {
|
|
|
518
524
|
instance.deployer,
|
|
519
525
|
instance.contractClassId,
|
|
520
526
|
instance.initializationHash,
|
|
521
|
-
instance.
|
|
527
|
+
...instance.publicKeys.toFields(),
|
|
522
528
|
]),
|
|
523
529
|
]);
|
|
524
530
|
}
|
|
@@ -614,46 +620,13 @@ export class TXEService {
|
|
|
614
620
|
return toForeignCallResult([toArray(keyValidationRequest.toFields())]);
|
|
615
621
|
}
|
|
616
622
|
|
|
617
|
-
computeEncryptedNoteLog(
|
|
618
|
-
contractAddress: ForeignCallSingle,
|
|
619
|
-
storageSlot: ForeignCallSingle,
|
|
620
|
-
noteTypeId: ForeignCallSingle,
|
|
621
|
-
ovskApp: ForeignCallSingle,
|
|
622
|
-
ovpkMX: ForeignCallSingle,
|
|
623
|
-
ovpkMY: ForeignCallSingle,
|
|
624
|
-
ovpkMIsInfinite: ForeignCallSingle,
|
|
625
|
-
ivpkMX: ForeignCallSingle,
|
|
626
|
-
ivpkMY: ForeignCallSingle,
|
|
627
|
-
ivpkMIsInfinite: ForeignCallSingle,
|
|
628
|
-
recipient: ForeignCallSingle,
|
|
629
|
-
preimage: ForeignCallArray,
|
|
630
|
-
) {
|
|
631
|
-
const ovpkM = new Point(fromSingle(ovpkMX), fromSingle(ovpkMY), !fromSingle(ovpkMIsInfinite).isZero());
|
|
632
|
-
const ovKeys = new KeyValidationRequest(ovpkM, Fr.fromString(fromSingle(ovskApp).toString()));
|
|
633
|
-
const ivpkM = new Point(fromSingle(ivpkMX), fromSingle(ivpkMY), !fromSingle(ivpkMIsInfinite).isZero());
|
|
634
|
-
const encLog = this.typedOracle.computeEncryptedNoteLog(
|
|
635
|
-
AztecAddress.fromString(fromSingle(contractAddress).toString()),
|
|
636
|
-
Fr.fromString(fromSingle(storageSlot).toString()),
|
|
637
|
-
NoteSelector.fromField(Fr.fromString(fromSingle(noteTypeId).toString())),
|
|
638
|
-
ovKeys,
|
|
639
|
-
ivpkM,
|
|
640
|
-
AztecAddress.fromString(fromSingle(recipient).toString()),
|
|
641
|
-
fromArray(preimage),
|
|
642
|
-
);
|
|
643
|
-
const bytes: Fr[] = [];
|
|
644
|
-
|
|
645
|
-
encLog.forEach(v => {
|
|
646
|
-
bytes.push(new Fr(v));
|
|
647
|
-
});
|
|
648
|
-
return toForeignCallResult([toArray(bytes)]);
|
|
649
|
-
}
|
|
650
|
-
|
|
651
623
|
emitEncryptedLog(
|
|
652
624
|
_contractAddress: ForeignCallSingle,
|
|
653
625
|
_randomness: ForeignCallSingle,
|
|
654
626
|
_encryptedLog: ForeignCallSingle,
|
|
655
627
|
_counter: ForeignCallSingle,
|
|
656
628
|
) {
|
|
629
|
+
// TODO(#8811): Implement
|
|
657
630
|
return toForeignCallResult([]);
|
|
658
631
|
}
|
|
659
632
|
|
|
@@ -662,10 +635,12 @@ export class TXEService {
|
|
|
662
635
|
_encryptedNote: ForeignCallArray,
|
|
663
636
|
_counter: ForeignCallSingle,
|
|
664
637
|
) {
|
|
638
|
+
// TODO(#8811): Implement
|
|
665
639
|
return toForeignCallResult([]);
|
|
666
640
|
}
|
|
667
641
|
|
|
668
642
|
emitEncryptedEventLog(_contractAddress: AztecAddress, _randomness: Fr, _encryptedEvent: Buffer, _counter: number) {
|
|
643
|
+
// TODO(#8811): Implement
|
|
669
644
|
return toForeignCallResult([]);
|
|
670
645
|
}
|
|
671
646
|
|
|
@@ -714,7 +689,7 @@ export class TXEService {
|
|
|
714
689
|
isStaticCall: ForeignCallSingle,
|
|
715
690
|
isDelegateCall: ForeignCallSingle,
|
|
716
691
|
) {
|
|
717
|
-
await this.typedOracle.enqueuePublicFunctionCall(
|
|
692
|
+
const newArgsHash = await this.typedOracle.enqueuePublicFunctionCall(
|
|
718
693
|
fromSingle(targetContractAddress),
|
|
719
694
|
FunctionSelector.fromField(fromSingle(functionSelector)),
|
|
720
695
|
fromSingle(argsHash),
|
|
@@ -722,7 +697,7 @@ export class TXEService {
|
|
|
722
697
|
fromSingle(isStaticCall).toBool(),
|
|
723
698
|
fromSingle(isDelegateCall).toBool(),
|
|
724
699
|
);
|
|
725
|
-
return toForeignCallResult([]);
|
|
700
|
+
return toForeignCallResult([toSingle(newArgsHash)]);
|
|
726
701
|
}
|
|
727
702
|
|
|
728
703
|
public async setPublicTeardownFunctionCall(
|
|
@@ -733,7 +708,7 @@ export class TXEService {
|
|
|
733
708
|
isStaticCall: ForeignCallSingle,
|
|
734
709
|
isDelegateCall: ForeignCallSingle,
|
|
735
710
|
) {
|
|
736
|
-
await this.typedOracle.setPublicTeardownFunctionCall(
|
|
711
|
+
const newArgsHash = await this.typedOracle.setPublicTeardownFunctionCall(
|
|
737
712
|
fromSingle(targetContractAddress),
|
|
738
713
|
FunctionSelector.fromField(fromSingle(functionSelector)),
|
|
739
714
|
fromSingle(argsHash),
|
|
@@ -741,7 +716,7 @@ export class TXEService {
|
|
|
741
716
|
fromSingle(isStaticCall).toBool(),
|
|
742
717
|
fromSingle(isDelegateCall).toBool(),
|
|
743
718
|
);
|
|
744
|
-
return toForeignCallResult([]);
|
|
719
|
+
return toForeignCallResult([toSingle(newArgsHash)]);
|
|
745
720
|
}
|
|
746
721
|
|
|
747
722
|
public notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: ForeignCallSingle) {
|
|
@@ -786,4 +761,14 @@ export class TXEService {
|
|
|
786
761
|
}
|
|
787
762
|
return toForeignCallResult([toArray(witness)]);
|
|
788
763
|
}
|
|
764
|
+
|
|
765
|
+
emitUnencryptedLog(_contractAddress: ForeignCallSingle, _message: ForeignCallArray, _counter: ForeignCallSingle) {
|
|
766
|
+
// TODO(#8811): Implement
|
|
767
|
+
return toForeignCallResult([]);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
avmOpcodeEmitUnencryptedLog(_message: ForeignCallArray) {
|
|
771
|
+
// TODO(#8811): Implement
|
|
772
|
+
return toForeignCallResult([]);
|
|
773
|
+
}
|
|
789
774
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { type AztecAddress, Fr, type FunctionSelector, unpackBytecode } from '@aztec/circuits.js';
|
|
2
|
-
import { type ContractArtifact } from '@aztec/foundation/abi';
|
|
3
|
-
import { PrivateFunctionsTree } from '@aztec/pxe';
|
|
4
1
|
import {
|
|
2
|
+
type AztecAddress,
|
|
5
3
|
type ContractClassPublic,
|
|
6
4
|
type ContractDataSource,
|
|
7
5
|
type ContractInstanceWithAddress,
|
|
6
|
+
Fr,
|
|
7
|
+
FunctionSelector,
|
|
8
|
+
PUBLIC_DISPATCH_SELECTOR,
|
|
8
9
|
type PublicFunction,
|
|
9
|
-
} from '@aztec/
|
|
10
|
+
} from '@aztec/circuits.js';
|
|
11
|
+
import { type ContractArtifact } from '@aztec/foundation/abi';
|
|
12
|
+
import { PrivateFunctionsTree } from '@aztec/pxe';
|
|
10
13
|
|
|
11
14
|
import { type TXE } from '../oracle/txe_oracle.js';
|
|
12
15
|
|
|
@@ -31,11 +34,19 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
31
34
|
const tree = new PrivateFunctionsTree(artifact);
|
|
32
35
|
const privateFunctionsRoot = tree.getFunctionTreeRoot();
|
|
33
36
|
|
|
37
|
+
const publicFunctions: PublicFunction[] = [];
|
|
38
|
+
if (contractClass!.packedBytecode.length > 0) {
|
|
39
|
+
publicFunctions.push({
|
|
40
|
+
selector: FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)),
|
|
41
|
+
bytecode: contractClass!.packedBytecode,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
34
45
|
return {
|
|
35
46
|
id,
|
|
36
47
|
artifactHash: contractClass!.artifactHash,
|
|
37
48
|
packedBytecode: contractClass!.packedBytecode,
|
|
38
|
-
publicFunctions:
|
|
49
|
+
publicFunctions: publicFunctions,
|
|
39
50
|
privateFunctionsRoot: new Fr(privateFunctionsRoot!.root),
|
|
40
51
|
version: contractClass!.version,
|
|
41
52
|
privateFunctions: [],
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { MerkleTreeId, type
|
|
1
|
+
import { MerkleTreeId, type MerkleTreeWriteOperations } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
3
|
type AztecAddress,
|
|
4
|
+
type ContractDataSource,
|
|
4
5
|
Fr,
|
|
5
6
|
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
6
7
|
PublicDataTreeLeaf,
|
|
@@ -8,10 +9,9 @@ import {
|
|
|
8
9
|
} from '@aztec/circuits.js';
|
|
9
10
|
import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
|
|
10
11
|
import { WorldStateDB } from '@aztec/simulator';
|
|
11
|
-
import { type ContractDataSource } from '@aztec/types/contracts';
|
|
12
12
|
|
|
13
13
|
export class TXEWorldStateDB extends WorldStateDB {
|
|
14
|
-
constructor(private merkleDb:
|
|
14
|
+
constructor(private merkleDb: MerkleTreeWriteOperations, dataSource: ContractDataSource) {
|
|
15
15
|
super(merkleDb, dataSource);
|
|
16
16
|
}
|
|
17
17
|
|