@aztec/pxe 0.28.0 → 0.29.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/contract_data_oracle/index.d.ts +23 -9
- package/dest/contract_data_oracle/index.d.ts.map +1 -1
- package/dest/contract_data_oracle/index.js +55 -39
- package/dest/contract_data_oracle/private_functions_tree.d.ts +7 -15
- package/dest/contract_data_oracle/private_functions_tree.d.ts.map +1 -1
- package/dest/contract_data_oracle/private_functions_tree.js +10 -15
- package/dest/database/contracts/contract_instance_db.d.ts +2 -0
- package/dest/database/contracts/contract_instance_db.d.ts.map +1 -1
- package/dest/database/kv_pxe_database.d.ts +3 -4
- package/dest/database/kv_pxe_database.d.ts.map +1 -1
- package/dest/database/kv_pxe_database.js +16 -17
- package/dest/database/pxe_database.d.ts +5 -2
- package/dest/database/pxe_database.d.ts.map +1 -1
- package/dest/kernel_oracle/index.d.ts +1 -0
- package/dest/kernel_oracle/index.d.ts.map +1 -1
- package/dest/kernel_prover/kernel_prover.js +4 -4
- package/dest/pxe_http/pxe_http_server.d.ts.map +1 -1
- package/dest/pxe_http/pxe_http_server.js +2 -4
- package/dest/pxe_service/pxe_service.d.ts +2 -4
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +17 -32
- package/dest/pxe_service/test/pxe_test_suite.js +2 -2
- package/dest/simulator_oracle/index.d.ts.map +1 -1
- package/dest/simulator_oracle/index.js +6 -13
- package/package.json +12 -12
- package/src/contract_data_oracle/index.ts +63 -50
- package/src/contract_data_oracle/private_functions_tree.ts +12 -17
- package/src/database/contracts/contract_instance_db.ts +3 -0
- package/src/database/kv_pxe_database.ts +17 -17
- package/src/database/pxe_database.ts +6 -2
- package/src/kernel_prover/kernel_prover.ts +3 -3
- package/src/pxe_http/pxe_http_server.ts +0 -4
- package/src/pxe_service/pxe_service.ts +20 -36
- package/src/pxe_service/test/pxe_test_suite.ts +1 -1
- package/src/simulator_oracle/index.ts +5 -14
- package/dest/contract_database/index.d.ts +0 -2
- package/dest/contract_database/index.d.ts.map +0 -1
- package/dest/contract_database/index.js +0 -2
- package/dest/contract_database/memory_contract_database.d.ts +0 -43
- package/dest/contract_database/memory_contract_database.d.ts.map +0 -1
- package/dest/contract_database/memory_contract_database.js +0 -51
- package/src/contract_database/index.ts +0 -1
- package/src/contract_database/memory_contract_database.ts +0 -58
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AztecAddress, MembershipWitness, VK_TREE_HEIGHT } from '@aztec/circuits.js';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '@aztec/
|
|
9
|
-
import { FunctionDebugMetadata, FunctionSelector } from '@aztec/foundation/abi';
|
|
3
|
+
ContractArtifact,
|
|
4
|
+
FunctionArtifact,
|
|
5
|
+
FunctionDebugMetadata,
|
|
6
|
+
FunctionSelector,
|
|
7
|
+
getFunctionDebugMetadata,
|
|
8
|
+
} from '@aztec/foundation/abi';
|
|
10
9
|
import { Fr } from '@aztec/foundation/fields';
|
|
11
10
|
import { ContractClassNotFoundError, ContractNotFoundError } from '@aztec/simulator';
|
|
12
11
|
import { ContractClass, ContractInstance } from '@aztec/types/contracts';
|
|
@@ -23,27 +22,34 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
23
22
|
* the required information and facilitate cryptographic proof generation.
|
|
24
23
|
*/
|
|
25
24
|
export class ContractDataOracle {
|
|
26
|
-
private
|
|
25
|
+
/** Map from contract class id to private function tree. */
|
|
26
|
+
private contractClasses: Map<string, PrivateFunctionsTree> = new Map();
|
|
27
|
+
/** Map from address to contract instance. */
|
|
28
|
+
private contractInstances: Map<string, ContractInstance> = new Map();
|
|
27
29
|
|
|
28
|
-
constructor(private db:
|
|
30
|
+
constructor(private db: ContractArtifactDatabase & ContractInstanceDatabase) {}
|
|
29
31
|
|
|
30
32
|
/** Returns a contract instance for a given address. Throws if not found. */
|
|
31
33
|
public async getContractInstance(contractAddress: AztecAddress): Promise<ContractInstance> {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
if (!this.contractInstances.has(contractAddress.toString())) {
|
|
35
|
+
const instance = await this.db.getContractInstance(contractAddress);
|
|
36
|
+
if (!instance) {
|
|
37
|
+
throw new ContractNotFoundError(contractAddress.toString());
|
|
38
|
+
}
|
|
39
|
+
this.contractInstances.set(contractAddress.toString(), instance);
|
|
35
40
|
}
|
|
36
|
-
return
|
|
41
|
+
return this.contractInstances.get(contractAddress.toString())!;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
/** Returns a contract class for a given id. Throws if not found. */
|
|
44
|
+
/** Returns a contract class for a given class id. Throws if not found. */
|
|
40
45
|
public async getContractClass(contractClassId: Fr): Promise<ContractClass> {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
const tree = await this.getTreeForClassId(contractClassId);
|
|
47
|
+
return tree.getContractClass();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public async getContractArtifact(contractClassId: Fr): Promise<ContractArtifact> {
|
|
51
|
+
const tree = await this.getTreeForClassId(contractClassId);
|
|
52
|
+
return tree.getArtifact();
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
/**
|
|
@@ -56,8 +62,8 @@ export class ContractDataOracle {
|
|
|
56
62
|
* @returns A Promise that resolves to the portal contract address.
|
|
57
63
|
*/
|
|
58
64
|
public async getPortalContractAddress(contractAddress: AztecAddress) {
|
|
59
|
-
const
|
|
60
|
-
return
|
|
65
|
+
const instance = await this.getContractInstance(contractAddress);
|
|
66
|
+
return instance.portalContractAddress;
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
/**
|
|
@@ -70,7 +76,7 @@ export class ContractDataOracle {
|
|
|
70
76
|
* @returns The corresponding function's artifact as an object.
|
|
71
77
|
*/
|
|
72
78
|
public async getFunctionArtifact(contractAddress: AztecAddress, selector: FunctionSelector) {
|
|
73
|
-
const tree = await this.
|
|
79
|
+
const tree = await this.getTreeForAddress(contractAddress);
|
|
74
80
|
return tree.getFunctionArtifact(selector);
|
|
75
81
|
}
|
|
76
82
|
|
|
@@ -86,9 +92,9 @@ export class ContractDataOracle {
|
|
|
86
92
|
public async getFunctionArtifactByName(
|
|
87
93
|
contractAddress: AztecAddress,
|
|
88
94
|
functionName: string,
|
|
89
|
-
): Promise<
|
|
90
|
-
const tree = await this.
|
|
91
|
-
return tree.
|
|
95
|
+
): Promise<FunctionArtifact | undefined> {
|
|
96
|
+
const tree = await this.getTreeForAddress(contractAddress);
|
|
97
|
+
return tree.getArtifact().functions.find(f => f.name === functionName);
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
/**
|
|
@@ -105,14 +111,9 @@ export class ContractDataOracle {
|
|
|
105
111
|
contractAddress: AztecAddress,
|
|
106
112
|
selector: FunctionSelector,
|
|
107
113
|
): Promise<FunctionDebugMetadata | undefined> {
|
|
108
|
-
const tree = await this.
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
if (!functionArtifact) {
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return tree.contract.getFunctionDebugMetadataByName(functionArtifact.name);
|
|
114
|
+
const tree = await this.getTreeForAddress(contractAddress);
|
|
115
|
+
const artifact = tree.getFunctionArtifact(selector);
|
|
116
|
+
return getFunctionDebugMetadata(tree.getArtifact(), artifact);
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
/**
|
|
@@ -126,7 +127,7 @@ export class ContractDataOracle {
|
|
|
126
127
|
* @throws Error if the contract address is unknown or not found.
|
|
127
128
|
*/
|
|
128
129
|
public async getBytecode(contractAddress: AztecAddress, selector: FunctionSelector) {
|
|
129
|
-
const tree = await this.
|
|
130
|
+
const tree = await this.getTreeForAddress(contractAddress);
|
|
130
131
|
return tree.getBytecode(selector);
|
|
131
132
|
}
|
|
132
133
|
|
|
@@ -140,7 +141,7 @@ export class ContractDataOracle {
|
|
|
140
141
|
* @returns A promise that resolves with the MembershipWitness instance for the specified contract's function.
|
|
141
142
|
*/
|
|
142
143
|
public async getFunctionMembershipWitness(contractAddress: AztecAddress, selector: FunctionSelector) {
|
|
143
|
-
const tree = await this.
|
|
144
|
+
const tree = await this.getTreeForAddress(contractAddress);
|
|
144
145
|
return tree.getFunctionMembershipWitness(selector);
|
|
145
146
|
}
|
|
146
147
|
|
|
@@ -158,6 +159,28 @@ export class ContractDataOracle {
|
|
|
158
159
|
return await Promise.resolve(MembershipWitness.random(VK_TREE_HEIGHT));
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Retrieve or create a ContractTree instance based on the provided class id.
|
|
164
|
+
* If an existing tree with the same class id is found in the cache, it will be returned.
|
|
165
|
+
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
166
|
+
* and added to the cache before returning.
|
|
167
|
+
*
|
|
168
|
+
* @param classId - The class id of the contract for which the ContractTree is required.
|
|
169
|
+
* @returns A ContractTree instance associated with the specified contract address.
|
|
170
|
+
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
171
|
+
*/
|
|
172
|
+
private async getTreeForClassId(classId: Fr): Promise<PrivateFunctionsTree> {
|
|
173
|
+
if (!this.contractClasses.has(classId.toString())) {
|
|
174
|
+
const artifact = await this.db.getContractArtifact(classId);
|
|
175
|
+
if (!artifact) {
|
|
176
|
+
throw new ContractClassNotFoundError(classId.toString());
|
|
177
|
+
}
|
|
178
|
+
const tree = new PrivateFunctionsTree(artifact);
|
|
179
|
+
this.contractClasses.set(classId.toString(), tree);
|
|
180
|
+
}
|
|
181
|
+
return this.contractClasses.get(classId.toString())!;
|
|
182
|
+
}
|
|
183
|
+
|
|
161
184
|
/**
|
|
162
185
|
* Retrieve or create a ContractTree instance based on the provided AztecAddress.
|
|
163
186
|
* If an existing tree with the same contract address is found in the cache, it will be returned.
|
|
@@ -168,18 +191,8 @@ export class ContractDataOracle {
|
|
|
168
191
|
* @returns A ContractTree instance associated with the specified contract address.
|
|
169
192
|
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
170
193
|
*/
|
|
171
|
-
private async
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (!tree) {
|
|
175
|
-
const contract = await this.db.getContract(contractAddress);
|
|
176
|
-
if (!contract) {
|
|
177
|
-
throw new ContractNotFoundError(contractAddress.toString());
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
tree = new PrivateFunctionsTree(contract);
|
|
181
|
-
this.trees.push(tree);
|
|
182
|
-
}
|
|
183
|
-
return tree;
|
|
194
|
+
private async getTreeForAddress(contractAddress: AztecAddress): Promise<PrivateFunctionsTree> {
|
|
195
|
+
const instance = await this.getContractInstance(contractAddress);
|
|
196
|
+
return this.getTreeForClassId(instance.contractClassId);
|
|
184
197
|
}
|
|
185
198
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ContractDao } from '@aztec/circuit-types';
|
|
2
1
|
import {
|
|
3
2
|
FUNCTION_TREE_HEIGHT,
|
|
4
3
|
MembershipWitness,
|
|
@@ -7,7 +6,7 @@ import {
|
|
|
7
6
|
getContractClassFromArtifact,
|
|
8
7
|
} from '@aztec/circuits.js';
|
|
9
8
|
import { MerkleTree } from '@aztec/circuits.js/merkle';
|
|
10
|
-
import { FunctionSelector } from '@aztec/foundation/abi';
|
|
9
|
+
import { ContractArtifact, FunctionSelector } from '@aztec/foundation/abi';
|
|
11
10
|
import { Fr } from '@aztec/foundation/fields';
|
|
12
11
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
13
12
|
import { ContractClassWithId } from '@aztec/types/contracts';
|
|
@@ -20,15 +19,11 @@ import { ContractClassWithId } from '@aztec/types/contracts';
|
|
|
20
19
|
*/
|
|
21
20
|
export class PrivateFunctionsTree {
|
|
22
21
|
private tree?: MerkleTree;
|
|
23
|
-
private contractClass
|
|
22
|
+
private contractClass: ContractClassWithId;
|
|
24
23
|
|
|
25
|
-
constructor(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* TODO(@spalladino) Replace with contract class sourced from db.
|
|
29
|
-
*/
|
|
30
|
-
public readonly contract: ContractDao,
|
|
31
|
-
) {}
|
|
24
|
+
constructor(private readonly artifact: ContractArtifact) {
|
|
25
|
+
this.contractClass = getContractClassFromArtifact(artifact);
|
|
26
|
+
}
|
|
32
27
|
|
|
33
28
|
/**
|
|
34
29
|
* Retrieve the artifact of a given function.
|
|
@@ -39,12 +34,10 @@ export class PrivateFunctionsTree {
|
|
|
39
34
|
* @returns The artifact object containing relevant information about the targeted function.
|
|
40
35
|
*/
|
|
41
36
|
public getFunctionArtifact(selector: FunctionSelector) {
|
|
42
|
-
const artifact = this.
|
|
37
|
+
const artifact = this.artifact.functions.find(f => selector.equals(f.name, f.parameters));
|
|
43
38
|
if (!artifact) {
|
|
44
39
|
throw new Error(
|
|
45
|
-
`Unknown function. Selector ${selector.toString()} not found in the artifact
|
|
46
|
-
.map(f => `${f.name} (${f.selector.toString()})`)
|
|
47
|
-
.join(', ')}`,
|
|
40
|
+
`Unknown function. Selector ${selector.toString()} not found in the artifact with class ${this.getContractClassId().toString()}.`,
|
|
48
41
|
);
|
|
49
42
|
}
|
|
50
43
|
return artifact;
|
|
@@ -75,12 +68,14 @@ export class PrivateFunctionsTree {
|
|
|
75
68
|
|
|
76
69
|
/** Returns the contract class object. */
|
|
77
70
|
public getContractClass() {
|
|
78
|
-
if (!this.contractClass) {
|
|
79
|
-
this.contractClass = getContractClassFromArtifact(this.contract);
|
|
80
|
-
}
|
|
81
71
|
return this.contractClass;
|
|
82
72
|
}
|
|
83
73
|
|
|
74
|
+
/** Returns the contract artifact. */
|
|
75
|
+
public getArtifact() {
|
|
76
|
+
return this.artifact;
|
|
77
|
+
}
|
|
78
|
+
|
|
84
79
|
/**
|
|
85
80
|
* Returns the contract class identifier for the given artifact.
|
|
86
81
|
*/
|
|
@@ -15,4 +15,7 @@ export interface ContractInstanceDatabase {
|
|
|
15
15
|
* @param address - Address of the contract.
|
|
16
16
|
*/
|
|
17
17
|
getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined>;
|
|
18
|
+
|
|
19
|
+
/** Returns the addresses all contract instances registered in the DB. */
|
|
20
|
+
getContractsAddresses(): Promise<AztecAddress[]>;
|
|
18
21
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MerkleTreeId, NoteFilter, NoteStatus, PublicKey } from '@aztec/circuit-types';
|
|
2
2
|
import { AztecAddress, CompleteAddress, Header } from '@aztec/circuits.js';
|
|
3
3
|
import { ContractArtifact } from '@aztec/foundation/abi';
|
|
4
4
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
@@ -20,7 +20,6 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
20
20
|
#addressIndex: AztecMap<string, number>;
|
|
21
21
|
#authWitnesses: AztecMap<string, Buffer[]>;
|
|
22
22
|
#capsules: AztecArray<Buffer[]>;
|
|
23
|
-
#contracts: AztecMap<string, Buffer>;
|
|
24
23
|
#notes: AztecMap<string, Buffer>;
|
|
25
24
|
#nullifiedNotes: AztecMap<string, Buffer>;
|
|
26
25
|
#nullifierToNoteId: AztecMap<string, string>;
|
|
@@ -47,7 +46,6 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
47
46
|
|
|
48
47
|
this.#authWitnesses = db.openMap('auth_witnesses');
|
|
49
48
|
this.#capsules = db.openArray('capsules');
|
|
50
|
-
this.#contracts = db.openMap('contracts');
|
|
51
49
|
|
|
52
50
|
this.#contractArtifacts = db.openMap('contract_artifacts');
|
|
53
51
|
this.#contractInstances = db.openMap('contracts_instances');
|
|
@@ -73,11 +71,22 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
73
71
|
this.#deferredNotesByContract = db.openMultiMap('deferred_notes_by_contract');
|
|
74
72
|
}
|
|
75
73
|
|
|
74
|
+
public async getContract(
|
|
75
|
+
address: AztecAddress,
|
|
76
|
+
): Promise<(ContractInstanceWithAddress & ContractArtifact) | undefined> {
|
|
77
|
+
const instance = await this.getContractInstance(address);
|
|
78
|
+
const artifact = instance && (await this.getContractArtifact(instance?.contractClassId));
|
|
79
|
+
if (!instance || !artifact) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
return { ...instance, ...artifact };
|
|
83
|
+
}
|
|
84
|
+
|
|
76
85
|
public async addContractArtifact(id: Fr, contract: ContractArtifact): Promise<void> {
|
|
77
86
|
await this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract));
|
|
78
87
|
}
|
|
79
88
|
|
|
80
|
-
getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
|
|
89
|
+
public getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
|
|
81
90
|
const contract = this.#contractArtifacts.get(id.toString());
|
|
82
91
|
// TODO(@spalladino): AztecMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
|
|
83
92
|
return Promise.resolve(contract && contractArtifactFromBuffer(Buffer.from(contract)));
|
|
@@ -95,6 +104,10 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
95
104
|
return Promise.resolve(contract && SerializableContractInstance.fromBuffer(contract).withAddress(address));
|
|
96
105
|
}
|
|
97
106
|
|
|
107
|
+
getContractsAddresses(): Promise<AztecAddress[]> {
|
|
108
|
+
return Promise.resolve(Array.from(this.#contractInstances.keys()).map(AztecAddress.fromString));
|
|
109
|
+
}
|
|
110
|
+
|
|
98
111
|
async addAuthWitness(messageHash: Fr, witness: Fr[]): Promise<void> {
|
|
99
112
|
await this.#authWitnesses.set(
|
|
100
113
|
messageHash.toString(),
|
|
@@ -393,17 +406,4 @@ export class KVPxeDatabase implements PxeDatabase {
|
|
|
393
406
|
|
|
394
407
|
return notesSize + treeRootsSize + authWitsSize + addressesSize;
|
|
395
408
|
}
|
|
396
|
-
|
|
397
|
-
async addContract(contract: ContractDao): Promise<void> {
|
|
398
|
-
await this.#contracts.set(contract.instance.address.toString(), contract.toBuffer());
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
getContract(address: AztecAddress): Promise<ContractDao | undefined> {
|
|
402
|
-
const contract = this.#contracts.get(address.toString());
|
|
403
|
-
return Promise.resolve(contract ? ContractDao.fromBuffer(contract) : undefined);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
getContracts(): Promise<ContractDao[]> {
|
|
407
|
-
return Promise.resolve(Array.from(this.#contracts.values()).map(c => ContractDao.fromBuffer(c)));
|
|
408
|
-
}
|
|
409
409
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NoteFilter } from '@aztec/circuit-types';
|
|
2
2
|
import { CompleteAddress, Header, PublicKey } from '@aztec/circuits.js';
|
|
3
|
+
import { ContractArtifact } from '@aztec/foundation/abi';
|
|
3
4
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
6
|
+
import { ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
5
7
|
|
|
6
8
|
import { ContractArtifactDatabase } from './contracts/contract_artifact_db.js';
|
|
7
9
|
import { ContractInstanceDatabase } from './contracts/contract_instance_db.js';
|
|
@@ -12,7 +14,9 @@ import { NoteDao } from './note_dao.js';
|
|
|
12
14
|
* A database interface that provides methods for retrieving, adding, and removing transactional data related to Aztec
|
|
13
15
|
* addresses, storage slots, and nullifiers.
|
|
14
16
|
*/
|
|
15
|
-
export interface PxeDatabase extends
|
|
17
|
+
export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceDatabase {
|
|
18
|
+
getContract(address: AztecAddress): Promise<(ContractInstanceWithAddress & ContractArtifact) | undefined>;
|
|
19
|
+
|
|
16
20
|
/**
|
|
17
21
|
* Add a auth witness to the database.
|
|
18
22
|
* @param messageHash - The message hash.
|
|
@@ -185,12 +185,12 @@ export class KernelProver {
|
|
|
185
185
|
>(output.publicInputs.end.newNullifiers);
|
|
186
186
|
|
|
187
187
|
const readNoteHashHints = this.hintsBuilder.getNoteHashReadRequestHints(
|
|
188
|
-
output.publicInputs.
|
|
188
|
+
output.publicInputs.validationRequests.noteHashReadRequests,
|
|
189
189
|
sortedNoteHashes,
|
|
190
190
|
);
|
|
191
191
|
|
|
192
192
|
const nullifierReadRequestHints = await this.hintsBuilder.getNullifierReadRequestHints(
|
|
193
|
-
output.publicInputs.
|
|
193
|
+
output.publicInputs.validationRequests.nullifierReadRequests,
|
|
194
194
|
output.publicInputs.end.newNullifiers,
|
|
195
195
|
);
|
|
196
196
|
|
|
@@ -200,7 +200,7 @@ export class KernelProver {
|
|
|
200
200
|
);
|
|
201
201
|
|
|
202
202
|
const masterNullifierSecretKeys = await this.hintsBuilder.getMasterNullifierSecretKeys(
|
|
203
|
-
output.publicInputs.
|
|
203
|
+
output.publicInputs.validationRequests.nullifierKeyValidationRequests,
|
|
204
204
|
);
|
|
205
205
|
|
|
206
206
|
this.log.debug(
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthWitness,
|
|
3
3
|
CompleteAddress,
|
|
4
|
-
ContractData,
|
|
5
|
-
ExtendedContractData,
|
|
6
4
|
ExtendedNote,
|
|
7
5
|
ExtendedUnencryptedL2Log,
|
|
8
6
|
L2Block,
|
|
@@ -36,8 +34,6 @@ export function createPXERpcServer(pxeService: PXE): JsonRpcServer {
|
|
|
36
34
|
CompleteAddress,
|
|
37
35
|
AztecAddress,
|
|
38
36
|
TxExecutionRequest,
|
|
39
|
-
ContractData,
|
|
40
|
-
ExtendedContractData,
|
|
41
37
|
ExtendedUnencryptedL2Log,
|
|
42
38
|
FunctionSelector,
|
|
43
39
|
TxHash,
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthWitness,
|
|
3
3
|
AztecNode,
|
|
4
|
-
ContractDao,
|
|
5
|
-
ContractData,
|
|
6
4
|
DeployedContract,
|
|
7
|
-
ExtendedContractData,
|
|
8
5
|
ExtendedNote,
|
|
9
6
|
FunctionCall,
|
|
10
7
|
GetUnencryptedLogsResponse,
|
|
@@ -40,7 +37,7 @@ import {
|
|
|
40
37
|
getContractClassFromArtifact,
|
|
41
38
|
} from '@aztec/circuits.js';
|
|
42
39
|
import { computeCommitmentNonce, siloNullifier } from '@aztec/circuits.js/hash';
|
|
43
|
-
import { DecodedReturn, encodeArguments } from '@aztec/foundation/abi';
|
|
40
|
+
import { DecodedReturn, FunctionSelector, encodeArguments } from '@aztec/foundation/abi';
|
|
44
41
|
import { arrayNonEmptyLength, padArrayEnd } from '@aztec/foundation/collection';
|
|
45
42
|
import { Fr } from '@aztec/foundation/fields';
|
|
46
43
|
import { SerialQueue } from '@aztec/foundation/fifo';
|
|
@@ -219,35 +216,25 @@ export class PXEService implements PXE {
|
|
|
219
216
|
}
|
|
220
217
|
|
|
221
218
|
public async addContracts(contracts: DeployedContract[]) {
|
|
222
|
-
const contractDaos = contracts.map(c => new ContractDao(c.artifact, c.instance));
|
|
223
|
-
await Promise.all(contractDaos.map(c => this.db.addContract(c)));
|
|
224
|
-
await this.addArtifactsAndInstancesFromDeployedContracts(contracts);
|
|
225
|
-
for (const contract of contractDaos) {
|
|
226
|
-
const instance = contract.instance;
|
|
227
|
-
const contractAztecAddress = instance.address;
|
|
228
|
-
const hasPortal = instance.portalContractAddress && !instance.portalContractAddress.isZero();
|
|
229
|
-
const portalInfo = hasPortal ? ` with portal ${instance.portalContractAddress.toChecksumString()}` : '';
|
|
230
|
-
this.log.info(`Added contract ${contract.name} at ${contractAztecAddress}${portalInfo}`);
|
|
231
|
-
await this.synchronizer.reprocessDeferredNotesForContract(contractAztecAddress);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
private async addArtifactsAndInstancesFromDeployedContracts(contracts: DeployedContract[]) {
|
|
236
219
|
for (const contract of contracts) {
|
|
237
|
-
const artifact = contract
|
|
220
|
+
const { instance, artifact } = contract;
|
|
238
221
|
const artifactHash = computeArtifactHash(artifact);
|
|
239
222
|
const contractClassId = computeContractClassId(getContractClassFromArtifact({ ...artifact, artifactHash }));
|
|
240
223
|
await this.db.addContractArtifact(contractClassId, artifact);
|
|
241
|
-
await this.db.addContractInstance(
|
|
224
|
+
await this.db.addContractInstance(instance);
|
|
225
|
+
const hasPortal = instance.portalContractAddress && !instance.portalContractAddress.isZero();
|
|
226
|
+
const portalInfo = hasPortal ? ` with portal ${instance.portalContractAddress.toChecksumString()}` : '';
|
|
227
|
+
this.log.info(`Added contract ${artifact.name} at ${instance.address.toString()}${portalInfo}`);
|
|
228
|
+
await this.synchronizer.reprocessDeferredNotesForContract(instance.address);
|
|
242
229
|
}
|
|
243
230
|
}
|
|
244
231
|
|
|
245
|
-
public
|
|
246
|
-
return
|
|
232
|
+
public getContracts(): Promise<AztecAddress[]> {
|
|
233
|
+
return this.db.getContractsAddresses();
|
|
247
234
|
}
|
|
248
235
|
|
|
249
236
|
public async getPublicStorageAt(contract: AztecAddress, slot: Fr) {
|
|
250
|
-
if ((await this.
|
|
237
|
+
if (!(await this.getContractInstance(contract))) {
|
|
251
238
|
throw new Error(`Contract ${contract.toString()} is not deployed`);
|
|
252
239
|
}
|
|
253
240
|
return await this.node.getPublicStorageAt(contract, slot);
|
|
@@ -382,9 +369,6 @@ export class PXEService implements PXE {
|
|
|
382
369
|
if (!txRequest.functionData.isPrivate) {
|
|
383
370
|
throw new Error(`Public entrypoints are not allowed`);
|
|
384
371
|
}
|
|
385
|
-
if (txRequest.functionData.isInternal === undefined) {
|
|
386
|
-
throw new Error(`Unspecified internal are not allowed`);
|
|
387
|
-
}
|
|
388
372
|
|
|
389
373
|
// all simulations must be serialized w.r.t. the synchronizer
|
|
390
374
|
return await this.jobQueue.put(async () => {
|
|
@@ -443,14 +427,6 @@ export class PXEService implements PXE {
|
|
|
443
427
|
return await this.node.getBlockNumber();
|
|
444
428
|
}
|
|
445
429
|
|
|
446
|
-
public async getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
|
|
447
|
-
return await this.node.getExtendedContractData(contractAddress);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
public async getContractData(contractAddress: AztecAddress): Promise<ContractData | undefined> {
|
|
451
|
-
return await this.node.getContractData(contractAddress);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
430
|
/**
|
|
455
431
|
* Gets unencrypted logs based on the provided filter.
|
|
456
432
|
* @param filter - The filter to apply to the logs.
|
|
@@ -657,9 +633,13 @@ export class PXEService implements PXE {
|
|
|
657
633
|
if (contract) {
|
|
658
634
|
err.enrichWithContractName(parsedContractAddress, contract.name);
|
|
659
635
|
selectors.forEach(selector => {
|
|
660
|
-
const functionArtifact = contract.functions.find(f =>
|
|
636
|
+
const functionArtifact = contract.functions.find(f => FunctionSelector.fromString(selector).equals(f));
|
|
661
637
|
if (functionArtifact) {
|
|
662
|
-
err.enrichWithFunctionName(
|
|
638
|
+
err.enrichWithFunctionName(
|
|
639
|
+
parsedContractAddress,
|
|
640
|
+
FunctionSelector.fromNameAndParameters(functionArtifact),
|
|
641
|
+
functionArtifact.name,
|
|
642
|
+
);
|
|
663
643
|
}
|
|
664
644
|
});
|
|
665
645
|
}
|
|
@@ -749,4 +729,8 @@ export class PXEService implements PXE {
|
|
|
749
729
|
public async isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
|
|
750
730
|
return !!(await this.node.getContractClass(id));
|
|
751
731
|
}
|
|
732
|
+
|
|
733
|
+
public async isContractPubliclyDeployed(address: AztecAddress): Promise<boolean> {
|
|
734
|
+
return !!(await this.node.getContract(address));
|
|
735
|
+
}
|
|
752
736
|
}
|
|
@@ -119,7 +119,7 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
|
|
|
119
119
|
);
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
// Note: Not testing `
|
|
122
|
+
// Note: Not testing `getContractData` and `getUnencryptedLogs` here as these
|
|
123
123
|
// functions only call AztecNode and these methods are frequently used by the e2e tests.
|
|
124
124
|
|
|
125
125
|
it('successfully gets a block number', async () => {
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
Header,
|
|
17
17
|
L1_TO_L2_MSG_TREE_HEIGHT,
|
|
18
18
|
} from '@aztec/circuits.js';
|
|
19
|
-
import { FunctionArtifactWithDebugMetadata } from '@aztec/foundation/abi';
|
|
19
|
+
import { FunctionArtifactWithDebugMetadata, getFunctionArtifactWithDebugMetadata } from '@aztec/foundation/abi';
|
|
20
20
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
21
21
|
import { DBOracle, KeyPair, MessageLoadOracleInputs } from '@aztec/simulator';
|
|
22
22
|
import { ContractInstance } from '@aztec/types/contracts';
|
|
@@ -111,16 +111,9 @@ export class SimulatorOracle implements DBOracle {
|
|
|
111
111
|
contractAddress: AztecAddress,
|
|
112
112
|
functionName: string,
|
|
113
113
|
): Promise<FunctionArtifactWithDebugMetadata | undefined> {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const debug = await this.contractDataOracle.getFunctionDebugMetadata(contractAddress, artifact.selector);
|
|
120
|
-
return {
|
|
121
|
-
...artifact,
|
|
122
|
-
debug,
|
|
123
|
-
};
|
|
114
|
+
const instance = await this.contractDataOracle.getContractInstance(contractAddress);
|
|
115
|
+
const artifact = await this.contractDataOracle.getContractArtifact(instance.contractClassId);
|
|
116
|
+
return artifact && getFunctionArtifactWithDebugMetadata(artifact, functionName);
|
|
124
117
|
}
|
|
125
118
|
|
|
126
119
|
async getPortalContractAddress(contractAddress: AztecAddress): Promise<EthAddress> {
|
|
@@ -136,9 +129,7 @@ export class SimulatorOracle implements DBOracle {
|
|
|
136
129
|
* index of the message in the l1ToL2MessageTree
|
|
137
130
|
*/
|
|
138
131
|
async getL1ToL2MembershipWitness(entryKey: Fr): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>> {
|
|
139
|
-
const
|
|
140
|
-
const index = messageAndIndex.index;
|
|
141
|
-
const siblingPath = await this.aztecNode.getL1ToL2MessageSiblingPath('latest', index);
|
|
132
|
+
const [index, siblingPath] = await this.aztecNode.getL1ToL2MessageIndexAndSiblingPath('latest', entryKey);
|
|
142
133
|
return new MessageLoadOracleInputs(index, siblingPath);
|
|
143
134
|
}
|
|
144
135
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contract_database/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export * from './memory_contract_database.js';
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29udHJhY3RfZGF0YWJhc2UvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYywrQkFBK0IsQ0FBQyJ9
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { ContractDao, ContractDatabase } from '@aztec/circuit-types';
|
|
2
|
-
import { FunctionSelector } from '@aztec/circuits.js';
|
|
3
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
|
-
import { DebugLogger } from '@aztec/foundation/log';
|
|
5
|
-
/**
|
|
6
|
-
* The MemoryContractDatabase class serves as an in-memory implementation of the ContractDatabase interface.
|
|
7
|
-
* It allows for storing and retrieving contract data, such as ContractDao objects and associated function bytecodes,
|
|
8
|
-
* within a contracts array. This class is particularly useful for testing and development purposes where a
|
|
9
|
-
* persistent storage may not be required.
|
|
10
|
-
*/
|
|
11
|
-
export declare class MemoryContractDatabase implements ContractDatabase {
|
|
12
|
-
protected log: DebugLogger;
|
|
13
|
-
private contracts;
|
|
14
|
-
constructor(log: DebugLogger);
|
|
15
|
-
/**
|
|
16
|
-
* Adds a new ContractDao instance to the memory-based contract database.
|
|
17
|
-
* The function stores the contract in an array and returns a resolved promise indicating successful addition.
|
|
18
|
-
*
|
|
19
|
-
* @param contract - The ContractDao instance to be added to the memory database.
|
|
20
|
-
* @returns A Promise that resolves when the contract is successfully added.
|
|
21
|
-
*/
|
|
22
|
-
addContract(contract: ContractDao): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Retrieve a ContractDao instance with the specified AztecAddress from the in-memory contracts list.
|
|
25
|
-
* Returns the first match found or undefined if no contract with the given address is found.
|
|
26
|
-
*
|
|
27
|
-
* @param address - The AztecAddress to search for in the stored contracts.
|
|
28
|
-
* @returns A Promise resolving to the ContractDao instance matching the given address or undefined.
|
|
29
|
-
*/
|
|
30
|
-
getContract(address: AztecAddress): Promise<ContractDao | undefined>;
|
|
31
|
-
getContracts(): Promise<ContractDao[]>;
|
|
32
|
-
/**
|
|
33
|
-
* Retrieve the bytecode associated with a given contract address and function selector.
|
|
34
|
-
* This function searches through the stored contracts to find a matching contract and function,
|
|
35
|
-
* then returns the corresponding bytecode. If no match is found, it returns undefined.
|
|
36
|
-
*
|
|
37
|
-
* @param contractAddress - The AztecAddress representing the contract address to look for.
|
|
38
|
-
* @param selector - The function selector.
|
|
39
|
-
* @returns A Promise that resolves to the bytecode of the matching function or undefined if not found.
|
|
40
|
-
*/
|
|
41
|
-
getCode(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=memory_contract_database.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory_contract_database.d.ts","sourceRoot":"","sources":["../../src/contract_database/memory_contract_database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;;;;GAKG;AACH,qBAAa,sBAAuB,YAAW,gBAAgB;IAGjD,SAAS,CAAC,GAAG,EAAE,WAAW;IAFtC,OAAO,CAAC,SAAS,CAAqB;gBAEhB,GAAG,EAAE,WAAW;IAEtC;;;;;;OAMG;IACI,WAAW,CAAC,QAAQ,EAAE,WAAW;IAMxC;;;;;;OAMG;IACI,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAIpE,YAAY,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAI7C;;;;;;;;OAQG;IACU,OAAO,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB;CAI/E"}
|