@aztec/pxe 0.12.0 → 0.13.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.
- package/dest/bin/index.js +3 -3
- package/dest/contract_data_oracle/index.d.ts +9 -0
- package/dest/contract_data_oracle/index.d.ts.map +1 -1
- package/dest/contract_data_oracle/index.js +13 -1
- package/dest/contract_tree/index.js +2 -2
- package/dest/database/database.d.ts +17 -28
- package/dest/database/database.d.ts.map +1 -1
- package/dest/database/index.d.ts +0 -1
- package/dest/database/index.d.ts.map +1 -1
- package/dest/database/index.js +1 -2
- package/dest/database/memory_db.d.ts +8 -8
- package/dest/database/memory_db.d.ts.map +1 -1
- package/dest/database/memory_db.js +27 -19
- package/dest/database/note_dao.d.ts +61 -0
- package/dest/database/note_dao.d.ts.map +1 -0
- package/dest/database/note_dao.js +83 -0
- package/dest/kernel_oracle/index.js +2 -2
- package/dest/kernel_prover/kernel_prover.d.ts +4 -4
- package/dest/kernel_prover/kernel_prover.js +2 -2
- package/dest/note_processor/note_processor.d.ts +7 -6
- package/dest/note_processor/note_processor.d.ts.map +1 -1
- package/dest/note_processor/note_processor.js +31 -36
- package/dest/pxe_http/pxe_http_server.d.ts.map +1 -1
- package/dest/pxe_http/pxe_http_server.js +4 -3
- package/dest/pxe_service/pxe_service.d.ts +4 -4
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +32 -37
- package/dest/simulator_oracle/index.d.ts +2 -1
- package/dest/simulator_oracle/index.d.ts.map +1 -1
- package/dest/simulator_oracle/index.js +16 -5
- package/package.json +9 -9
- package/src/bin/index.ts +2 -2
- package/src/contract_data_oracle/index.ts +13 -0
- package/src/contract_tree/index.ts +1 -1
- package/src/database/database.ts +17 -28
- package/src/database/index.ts +0 -1
- package/src/database/memory_db.ts +33 -23
- package/src/database/note_dao.ts +90 -0
- package/src/kernel_oracle/index.ts +1 -1
- package/src/kernel_prover/kernel_prover.ts +4 -4
- package/src/note_processor/note_processor.ts +50 -48
- package/src/pxe_http/pxe_http_server.ts +4 -2
- package/src/pxe_service/pxe_service.ts +50 -50
- package/src/simulator_oracle/index.ts +28 -14
- package/dest/database/note_spending_info_dao.d.ts +0 -50
- package/dest/database/note_spending_info_dao.d.ts.map +0 -1
- package/dest/database/note_spending_info_dao.js +0 -24
- package/src/database/note_spending_info_dao.ts +0 -75
|
@@ -25,12 +25,12 @@ export class SimulatorOracle {
|
|
|
25
25
|
return witness;
|
|
26
26
|
}
|
|
27
27
|
async getNotes(contractAddress, storageSlot) {
|
|
28
|
-
const noteDaos = await this.db.
|
|
29
|
-
return noteDaos.map(({ contractAddress, storageSlot, nonce,
|
|
28
|
+
const noteDaos = await this.db.getNotes({ contractAddress, storageSlot });
|
|
29
|
+
return noteDaos.map(({ contractAddress, storageSlot, nonce, note, innerNoteHash, siloedNullifier, index }) => ({
|
|
30
30
|
contractAddress,
|
|
31
31
|
storageSlot,
|
|
32
32
|
nonce,
|
|
33
|
-
|
|
33
|
+
note,
|
|
34
34
|
innerNoteHash,
|
|
35
35
|
siloedNullifier,
|
|
36
36
|
// PXE can use this index to get full MembershipWitness
|
|
@@ -45,6 +45,17 @@ export class SimulatorOracle {
|
|
|
45
45
|
debug,
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
+
async getFunctionArtifactByName(contractAddress, functionName) {
|
|
49
|
+
const artifact = await this.contractDataOracle.getFunctionArtifactByName(contractAddress, functionName);
|
|
50
|
+
if (!artifact) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const debug = await this.contractDataOracle.getFunctionDebugMetadata(contractAddress, artifact.selector);
|
|
54
|
+
return {
|
|
55
|
+
...artifact,
|
|
56
|
+
debug,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
48
59
|
async getPortalContractAddress(contractAddress) {
|
|
49
60
|
return await this.contractDataOracle.getPortalContractAddress(contractAddress);
|
|
50
61
|
}
|
|
@@ -60,7 +71,7 @@ export class SimulatorOracle {
|
|
|
60
71
|
const messageAndIndex = await this.stateInfoProvider.getL1ToL2MessageAndIndex(msgKey);
|
|
61
72
|
const message = messageAndIndex.message.toFieldArray();
|
|
62
73
|
const index = messageAndIndex.index;
|
|
63
|
-
const siblingPath = await this.stateInfoProvider.
|
|
74
|
+
const siblingPath = await this.stateInfoProvider.getL1ToL2MessageSiblingPath(index);
|
|
64
75
|
return {
|
|
65
76
|
message,
|
|
66
77
|
siblingPath: siblingPath.toFieldArray(),
|
|
@@ -88,4 +99,4 @@ export class SimulatorOracle {
|
|
|
88
99
|
return Promise.resolve(this.db.getHistoricBlockData());
|
|
89
100
|
}
|
|
90
101
|
}
|
|
91
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
102
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2ltdWxhdG9yX29yYWNsZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFXQSxPQUFPLEVBQVksWUFBWSxFQUFxQixNQUFNLGNBQWMsQ0FBQztBQUt6RTs7R0FFRztBQUNILE1BQU0sT0FBTyxlQUFlO0lBQzFCLFlBQ1Usa0JBQXNDLEVBQ3RDLEVBQVksRUFDWixRQUFrQixFQUNsQixpQkFBb0M7UUFIcEMsdUJBQWtCLEdBQWxCLGtCQUFrQixDQUFvQjtRQUN0QyxPQUFFLEdBQUYsRUFBRSxDQUFVO1FBQ1osYUFBUSxHQUFSLFFBQVEsQ0FBVTtRQUNsQixzQkFBaUIsR0FBakIsaUJBQWlCLENBQW1CO0lBQzNDLENBQUM7SUFFSixZQUFZLENBQUMsZ0JBQThCLEVBQUUsTUFBaUI7UUFDNUQsT0FBTyxJQUFJLENBQUMsUUFBUSxDQUFDLG9CQUFvQixDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBQ3BELENBQUM7SUFFRCxLQUFLL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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/pxe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dest/index.js",
|
|
6
6
|
"bin": "./dest/bin/index.js",
|
|
@@ -26,19 +26,19 @@
|
|
|
26
26
|
"jest": {
|
|
27
27
|
"preset": "ts-jest/presets/default-esm",
|
|
28
28
|
"moduleNameMapper": {
|
|
29
|
-
"^(\\.{1,2}/.*)\\.
|
|
29
|
+
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
|
|
30
30
|
},
|
|
31
31
|
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
|
|
32
32
|
"rootDir": "./src"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@aztec/acir-simulator": "0.
|
|
36
|
-
"@aztec/circuits.js": "0.
|
|
37
|
-
"@aztec/ethereum": "0.
|
|
38
|
-
"@aztec/foundation": "0.
|
|
39
|
-
"@aztec/key-store": "0.
|
|
40
|
-
"@aztec/noir-compiler": "0.
|
|
41
|
-
"@aztec/types": "0.
|
|
35
|
+
"@aztec/acir-simulator": "0.13.1",
|
|
36
|
+
"@aztec/circuits.js": "0.13.1",
|
|
37
|
+
"@aztec/ethereum": "0.13.1",
|
|
38
|
+
"@aztec/foundation": "0.13.1",
|
|
39
|
+
"@aztec/key-store": "0.13.1",
|
|
40
|
+
"@aztec/noir-compiler": "0.13.1",
|
|
41
|
+
"@aztec/types": "0.13.1",
|
|
42
42
|
"koa": "^2.14.2",
|
|
43
43
|
"koa-router": "^12.0.0",
|
|
44
44
|
"lodash.omit": "^4.5.0",
|
package/src/bin/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --no-warnings
|
|
2
2
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
3
|
-
import {
|
|
3
|
+
import { createAztecNodeClient } from '@aztec/types';
|
|
4
4
|
|
|
5
5
|
import { getPXEServiceConfig } from '../config/index.js';
|
|
6
6
|
import { startPXEHttpServer } from '../pxe_http/index.js';
|
|
@@ -17,7 +17,7 @@ async function main() {
|
|
|
17
17
|
logger.info(`Setting up PXE...`);
|
|
18
18
|
|
|
19
19
|
const pxeConfig = getPXEServiceConfig();
|
|
20
|
-
const nodeRpcClient =
|
|
20
|
+
const nodeRpcClient = createAztecNodeClient(AZTEC_NODE_URL);
|
|
21
21
|
const pxeService = await createPXEService(nodeRpcClient, pxeConfig);
|
|
22
22
|
|
|
23
23
|
const shutdown = async () => {
|
|
@@ -44,6 +44,19 @@ export class ContractDataOracle {
|
|
|
44
44
|
return tree.getFunctionArtifact(selector);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves the artifact of a specified function within a given contract.
|
|
49
|
+
* The function is identified by its name, which is unique within a contract.
|
|
50
|
+
*
|
|
51
|
+
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
52
|
+
* @param functionName - The name of the function.
|
|
53
|
+
* @returns The corresponding function's artifact as an object.
|
|
54
|
+
*/
|
|
55
|
+
public async getFunctionArtifactByName(contractAddress: AztecAddress, functionName: string) {
|
|
56
|
+
const contract = await this.db.getContract(contractAddress);
|
|
57
|
+
return contract?.functions.find(f => f.name === functionName);
|
|
58
|
+
}
|
|
59
|
+
|
|
47
60
|
/**
|
|
48
61
|
* Retrieves the debug metadata of a specified function within a given contract.
|
|
49
62
|
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
@@ -154,7 +154,7 @@ export class ContractTree {
|
|
|
154
154
|
public async getContractMembershipWitness() {
|
|
155
155
|
const index = await this.getContractIndex();
|
|
156
156
|
|
|
157
|
-
const siblingPath = await this.stateInfoProvider.
|
|
157
|
+
const siblingPath = await this.stateInfoProvider.getContractSiblingPath(index);
|
|
158
158
|
return new MembershipWitness<typeof CONTRACT_TREE_HEIGHT>(
|
|
159
159
|
CONTRACT_TREE_HEIGHT,
|
|
160
160
|
index,
|
package/src/database/database.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CompleteAddress, HistoricBlockData } from '@aztec/circuits.js';
|
|
1
|
+
import { CompleteAddress, HistoricBlockData, PublicKey } from '@aztec/circuits.js';
|
|
2
2
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
-
import { ContractDatabase, MerkleTreeId,
|
|
4
|
+
import { ContractDatabase, MerkleTreeId, NoteFilter } from '@aztec/types';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { NoteDao } from './note_dao.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A database interface that provides methods for retrieving, adding, and removing transactional data related to Aztec
|
|
@@ -25,46 +25,35 @@ export interface Database extends ContractDatabase {
|
|
|
25
25
|
getAuthWitness(messageHash: Fr): Promise<Fr[]>;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* @param contract - The contract address.
|
|
33
|
-
* @param storageSlot - A Fr object representing the storage slot to search for in the auxiliary data.
|
|
34
|
-
* @returns An array of NoteSpendingInfoDao objects that fulfill the contract address and storage slot criteria.
|
|
28
|
+
* Gets notes based on the provided filter.
|
|
29
|
+
* @param filter - The filter to apply to the notes.
|
|
30
|
+
* @returns The requested notes.
|
|
35
31
|
*/
|
|
36
|
-
|
|
32
|
+
getNotes(filter: NoteFilter): Promise<NoteDao[]>;
|
|
37
33
|
|
|
38
34
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* such as contract address and storage slot, in the database.
|
|
42
|
-
*
|
|
43
|
-
* @param noteSpendingInfoDao - The NoteSpendingInfoDao instance containing the auxiliary data of a transaction.
|
|
44
|
-
* @returns A promise that resolves when the auxiliary data is added to the database.
|
|
35
|
+
* Adds a note to DB.
|
|
36
|
+
* @param note - The note to add.
|
|
45
37
|
*/
|
|
46
|
-
|
|
38
|
+
addNote(note: NoteDao): Promise<void>;
|
|
47
39
|
|
|
48
40
|
/**
|
|
49
|
-
* Adds an array of
|
|
50
|
-
* This function is used to insert multiple
|
|
41
|
+
* Adds an array of notes to DB.
|
|
42
|
+
* This function is used to insert multiple notes to the database at once,
|
|
51
43
|
* which can improve performance when dealing with large numbers of transactions.
|
|
52
44
|
*
|
|
53
|
-
* @param
|
|
54
|
-
* @returns A Promise that resolves when all NoteSpendingInfoDaos have been successfully added to the noteSpendingInfoTable.
|
|
45
|
+
* @param notes - An array of notes.
|
|
55
46
|
*/
|
|
56
|
-
|
|
47
|
+
addNotes(notes: NoteDao[]): Promise<void>;
|
|
57
48
|
|
|
58
49
|
/**
|
|
59
|
-
* Remove nullified
|
|
60
|
-
* The function filters the records based on matching account and nullifier values, and updates the
|
|
61
|
-
* noteSpendingInfoTable with the remaining records. It returns an array of removed NoteSpendingInfoDao instances.
|
|
50
|
+
* Remove nullified notes associated with the given account and nullifiers.
|
|
62
51
|
*
|
|
63
52
|
* @param nullifiers - An array of Fr instances representing nullifiers to be matched.
|
|
64
53
|
* @param account - A PublicKey instance representing the account for which the records are being removed.
|
|
65
|
-
* @returns
|
|
54
|
+
* @returns Removed notes.
|
|
66
55
|
*/
|
|
67
|
-
|
|
56
|
+
removeNullifiedNotes(nullifiers: Fr[], account: PublicKey): Promise<NoteDao[]>;
|
|
68
57
|
|
|
69
58
|
/**
|
|
70
59
|
* Retrieve the stored Merkle tree roots from the database.
|
package/src/database/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { CompleteAddress, HistoricBlockData } from '@aztec/circuits.js';
|
|
1
|
+
import { CompleteAddress, HistoricBlockData, PublicKey } from '@aztec/circuits.js';
|
|
2
2
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
4
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { MerkleTreeId,
|
|
5
|
+
import { MerkleTreeId, NoteFilter } from '@aztec/types';
|
|
6
6
|
|
|
7
7
|
import { MemoryContractDatabase } from '../contract_database/index.js';
|
|
8
8
|
import { Database } from './database.js';
|
|
9
|
-
import {
|
|
9
|
+
import { NoteDao } from './note_dao.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The MemoryDB class provides an in-memory implementation of a database to manage transactions and auxiliary data.
|
|
@@ -15,7 +15,7 @@ import { NoteSpendingInfoDao, getNoteSpendingInfoDaoSize } from './note_spending
|
|
|
15
15
|
* As an in-memory database, the stored data will not persist beyond the life of the application instance.
|
|
16
16
|
*/
|
|
17
17
|
export class MemoryDB extends MemoryContractDatabase implements Database {
|
|
18
|
-
private
|
|
18
|
+
private notesTable: NoteDao[] = [];
|
|
19
19
|
private treeRoots: Record<MerkleTreeId, Fr> | undefined;
|
|
20
20
|
private globalVariablesHash: Fr | undefined;
|
|
21
21
|
private addresses: CompleteAddress[] = [];
|
|
@@ -44,41 +44,51 @@ export class MemoryDB extends MemoryContractDatabase implements Database {
|
|
|
44
44
|
return Promise.resolve(this.authWitnesses[messageHash.toString()]);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
public
|
|
48
|
-
this.
|
|
47
|
+
public addNote(note: NoteDao) {
|
|
48
|
+
this.notesTable.push(note);
|
|
49
49
|
return Promise.resolve();
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
public
|
|
53
|
-
this.
|
|
52
|
+
public addNotes(notes: NoteDao[]) {
|
|
53
|
+
this.notesTable.push(...notes);
|
|
54
54
|
return Promise.resolve();
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
public
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
public async getNotes(filter: NoteFilter): Promise<NoteDao[]> {
|
|
58
|
+
let ownerPublicKey: PublicKey | undefined;
|
|
59
|
+
if (filter.owner !== undefined) {
|
|
60
|
+
const ownerCompleteAddress = await this.getCompleteAddress(filter.owner);
|
|
61
|
+
if (ownerCompleteAddress === undefined) {
|
|
62
|
+
throw new Error(`Owner ${filter.owner.toString()} not found in memory database`);
|
|
63
|
+
}
|
|
64
|
+
ownerPublicKey = ownerCompleteAddress.publicKey;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return this.notesTable.filter(
|
|
68
|
+
note =>
|
|
69
|
+
(filter.contractAddress == undefined || note.contractAddress.equals(filter.contractAddress)) &&
|
|
70
|
+
(filter.txHash == undefined || note.txHash.equals(filter.txHash)) &&
|
|
71
|
+
(filter.storageSlot == undefined || note.storageSlot.equals(filter.storageSlot!)) &&
|
|
72
|
+
(ownerPublicKey == undefined || note.publicKey.equals(ownerPublicKey!)),
|
|
62
73
|
);
|
|
63
|
-
return Promise.resolve(res);
|
|
64
74
|
}
|
|
65
75
|
|
|
66
|
-
public
|
|
76
|
+
public removeNullifiedNotes(nullifiers: Fr[], account: PublicKey) {
|
|
67
77
|
const nullifierSet = new Set(nullifiers.map(nullifier => nullifier.toString()));
|
|
68
|
-
const [remaining, removed] = this.
|
|
69
|
-
(acc: [
|
|
70
|
-
const nullifier =
|
|
71
|
-
if (
|
|
72
|
-
acc[1].push(
|
|
78
|
+
const [remaining, removed] = this.notesTable.reduce(
|
|
79
|
+
(acc: [NoteDao[], NoteDao[]], note) => {
|
|
80
|
+
const nullifier = note.siloedNullifier.toString();
|
|
81
|
+
if (note.publicKey.equals(account) && nullifierSet.has(nullifier)) {
|
|
82
|
+
acc[1].push(note);
|
|
73
83
|
} else {
|
|
74
|
-
acc[0].push(
|
|
84
|
+
acc[0].push(note);
|
|
75
85
|
}
|
|
76
86
|
return acc;
|
|
77
87
|
},
|
|
78
88
|
[[], []],
|
|
79
89
|
);
|
|
80
90
|
|
|
81
|
-
this.
|
|
91
|
+
this.notesTable = remaining;
|
|
82
92
|
|
|
83
93
|
return Promise.resolve(removed);
|
|
84
94
|
}
|
|
@@ -146,7 +156,7 @@ export class MemoryDB extends MemoryContractDatabase implements Database {
|
|
|
146
156
|
}
|
|
147
157
|
|
|
148
158
|
public estimateSize() {
|
|
149
|
-
const notesSize = this.
|
|
159
|
+
const notesSize = this.notesTable.reduce((sum, note) => sum + note.getSize(), 0);
|
|
150
160
|
const treeRootsSize = this.treeRoots ? Object.entries(this.treeRoots).length * Fr.SIZE_IN_BYTES : 0;
|
|
151
161
|
const authWits = Object.entries(this.authWitnesses);
|
|
152
162
|
const authWitsSize = authWits.reduce((sum, [key, value]) => sum + key.length + value.length * Fr.SIZE_IN_BYTES, 0);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { AztecAddress, Fr, Point, PublicKey } from '@aztec/circuits.js';
|
|
2
|
+
import { toBigIntBE, toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
3
|
+
import { BufferReader, Note, TxHash } from '@aztec/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A note with contextual data.
|
|
7
|
+
*/
|
|
8
|
+
export class NoteDao {
|
|
9
|
+
constructor(
|
|
10
|
+
/** The note as emitted from the Noir contract. */
|
|
11
|
+
public note: Note,
|
|
12
|
+
/** The contract address this note is created in. */
|
|
13
|
+
public contractAddress: AztecAddress,
|
|
14
|
+
/** The specific storage location of the note on the contract. */
|
|
15
|
+
public storageSlot: Fr,
|
|
16
|
+
/** The hash of the tx the note was created in. */
|
|
17
|
+
public txHash: TxHash,
|
|
18
|
+
/** The nonce of the note. */
|
|
19
|
+
public nonce: Fr,
|
|
20
|
+
/**
|
|
21
|
+
* Inner note hash of the note. This is customizable by the app circuit.
|
|
22
|
+
* We can use this value to compute siloedNoteHash and uniqueSiloedNoteHash.
|
|
23
|
+
*/
|
|
24
|
+
public innerNoteHash: Fr,
|
|
25
|
+
/** The nullifier of the note (siloed by contract address). */
|
|
26
|
+
public siloedNullifier: Fr,
|
|
27
|
+
/** The location of the relevant note in the note hash tree. */
|
|
28
|
+
public index: bigint,
|
|
29
|
+
/** The public key with which the note was encrypted. */
|
|
30
|
+
public publicKey: PublicKey,
|
|
31
|
+
) {}
|
|
32
|
+
|
|
33
|
+
toBuffer(): Buffer {
|
|
34
|
+
return Buffer.concat([
|
|
35
|
+
this.note.toBuffer(),
|
|
36
|
+
this.contractAddress.toBuffer(),
|
|
37
|
+
this.storageSlot.toBuffer(),
|
|
38
|
+
this.txHash.buffer,
|
|
39
|
+
this.nonce.toBuffer(),
|
|
40
|
+
this.innerNoteHash.toBuffer(),
|
|
41
|
+
this.siloedNullifier.toBuffer(),
|
|
42
|
+
toBufferBE(this.index, 32),
|
|
43
|
+
this.publicKey.toBuffer(),
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
47
|
+
const reader = BufferReader.asReader(buffer);
|
|
48
|
+
|
|
49
|
+
const note = Note.fromBuffer(reader);
|
|
50
|
+
const contractAddress = AztecAddress.fromBuffer(reader);
|
|
51
|
+
const storageSlot = Fr.fromBuffer(reader);
|
|
52
|
+
const txHash = new TxHash(reader.readBytes(TxHash.SIZE));
|
|
53
|
+
const nonce = Fr.fromBuffer(reader);
|
|
54
|
+
const innerNoteHash = Fr.fromBuffer(reader);
|
|
55
|
+
const siloedNullifier = Fr.fromBuffer(reader);
|
|
56
|
+
const index = toBigIntBE(reader.readBytes(32));
|
|
57
|
+
const publicKey = Point.fromBuffer(reader);
|
|
58
|
+
|
|
59
|
+
return new NoteDao(
|
|
60
|
+
note,
|
|
61
|
+
contractAddress,
|
|
62
|
+
storageSlot,
|
|
63
|
+
txHash,
|
|
64
|
+
nonce,
|
|
65
|
+
innerNoteHash,
|
|
66
|
+
siloedNullifier,
|
|
67
|
+
index,
|
|
68
|
+
publicKey,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
toString() {
|
|
73
|
+
return '0x' + this.toBuffer().toString('hex');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static fromString(str: string) {
|
|
77
|
+
const hex = str.replace(/^0x/, '');
|
|
78
|
+
return NoteDao.fromBuffer(Buffer.from(hex, 'hex'));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Returns the size in bytes of the Note Dao.
|
|
83
|
+
* @returns - Its size in bytes.
|
|
84
|
+
*/
|
|
85
|
+
public getSize() {
|
|
86
|
+
const indexSize = Math.ceil(Math.log2(Number(this.index)));
|
|
87
|
+
const noteSize = 4 + this.note.items.length * Fr.SIZE_IN_BYTES;
|
|
88
|
+
return noteSize + AztecAddress.SIZE_IN_BYTES + Fr.SIZE_IN_BYTES * 4 + TxHash.SIZE + Point.SIZE_IN_BYTES + indexSize;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -24,7 +24,7 @@ export class KernelOracle implements ProvingDataOracle {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
async getNoteMembershipWitness(leafIndex: bigint): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
27
|
-
const path = await this.node.
|
|
27
|
+
const path = await this.node.getNoteHashSiblingPath(leafIndex);
|
|
28
28
|
return new MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT>(
|
|
29
29
|
path.pathSize,
|
|
30
30
|
leafIndex,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExecutionResult,
|
|
1
|
+
import { ExecutionResult, NoteAndSlot } from '@aztec/acir-simulator';
|
|
2
2
|
import {
|
|
3
3
|
AztecAddress,
|
|
4
4
|
CONTRACT_TREE_HEIGHT,
|
|
@@ -42,7 +42,7 @@ export interface OutputNoteData {
|
|
|
42
42
|
/**
|
|
43
43
|
* The encrypted note data for an output note.
|
|
44
44
|
*/
|
|
45
|
-
data:
|
|
45
|
+
data: NoteAndSlot;
|
|
46
46
|
/**
|
|
47
47
|
* The unique value representing the note.
|
|
48
48
|
*/
|
|
@@ -231,11 +231,11 @@ export class KernelProver {
|
|
|
231
231
|
|
|
232
232
|
/**
|
|
233
233
|
* Retrieves the new output notes for a given execution result.
|
|
234
|
-
* The function maps over the new
|
|
234
|
+
* The function maps over the new notes and associates them with their corresponding
|
|
235
235
|
* commitments in the public inputs of the execution result. It also includes the contract address
|
|
236
236
|
* from the call context of the public inputs.
|
|
237
237
|
*
|
|
238
|
-
* @param executionResult - The execution result object containing
|
|
238
|
+
* @param executionResult - The execution result object containing notes and public inputs.
|
|
239
239
|
* @returns An array of OutputNoteData objects, each representing an output note with its associated data.
|
|
240
240
|
*/
|
|
241
241
|
private async getNewNotes(executionResult: ExecutionResult): Promise<OutputNoteData[]> {
|