-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
275 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
227 changes: 0 additions & 227 deletions
227
yarn-project/pxe/src/note_processor/produce_note_dao.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rocessor/find_note_index_and_nullifier.ts → ..._processor/utils/brute_force_note_info.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { produceNoteDaos } from './produce_note_daos.js'; | ||
export { NoteInfo } from './brute_force_note_info.js'; |
114 changes: 114 additions & 0 deletions
114
yarn-project/pxe/src/note_processor/utils/produce_note_daos.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { type L1NotePayload, type PublicKey, type TxHash, type UnencryptedTxL2Logs } from '@aztec/circuit-types'; | ||
import { type Fr } from '@aztec/foundation/fields'; | ||
import { type Logger } from '@aztec/foundation/log'; | ||
import { type AcirSimulator } from '@aztec/simulator'; | ||
|
||
import { type DeferredNoteDao } from '../../database/deferred_note_dao.js'; | ||
import { IncomingNoteDao } from '../../database/incoming_note_dao.js'; | ||
import { OutgoingNoteDao } from '../../database/outgoing_note_dao.js'; | ||
import { type PxeDatabase } from '../../database/pxe_database.js'; | ||
import { produceNoteDaosForKey } from './produce_note_daos_for_key.js'; | ||
|
||
/** | ||
* Decodes a note from a transaction that we know was intended for us. | ||
* Throws if we do not yet have the contract corresponding to the note in our database. | ||
* Accepts a set of excluded indices, which are indices that have been assigned a note in the same tx. | ||
* Inserts the index of the note into the excludedIndices set if the note is successfully decoded. | ||
* | ||
* @param simulator - An instance of AcirSimulator. | ||
* @param db - An instance of PxeDatabase. | ||
* @param ivpkM - The public counterpart to the secret key to be used in the decryption of incoming note logs. | ||
* @param ovpkM - The public counterpart to the secret key to be used in the decryption of outgoing note logs. | ||
* @param payload - An instance of l1NotePayload. | ||
* @param txHash - The hash of the transaction that created the note. Equivalent to the first nullifier of the transaction. | ||
* @param noteHashes - New note hashes in this transaction, one of which belongs to this note. | ||
* @param dataStartIndexForTx - The next available leaf index for the note hash tree for this transaction. | ||
* @param excludedIndices - Indices that have been assigned a note in the same tx. Notes in a tx can have the same l1NotePayload, we need to find a different index for each replicate. | ||
* @param logger - An instance of Logger. | ||
* @param unencryptedLogs - Unencrypted logs for the transaction (used to complete partial notes). | ||
* @returns An object containing the incoming, outgoing, and deferred notes. | ||
*/ | ||
export async function produceNoteDaos( | ||
simulator: AcirSimulator, | ||
db: PxeDatabase, | ||
ivpkM: PublicKey | undefined, | ||
ovpkM: PublicKey | undefined, | ||
payload: L1NotePayload, | ||
txHash: TxHash, | ||
noteHashes: Fr[], | ||
dataStartIndexForTx: number, | ||
excludedIndices: Set<number>, | ||
logger: Logger, | ||
unencryptedLogs: UnencryptedTxL2Logs, | ||
): Promise<{ | ||
incomingNote: IncomingNoteDao | undefined; | ||
outgoingNote: OutgoingNoteDao | undefined; | ||
incomingDeferredNote: DeferredNoteDao | undefined; | ||
outgoingDeferredNote: DeferredNoteDao | undefined; | ||
}> { | ||
// WARNING: This code is full of tech debt and will be refactored once we have final design of partial notes | ||
// delivery. | ||
if (!ivpkM && !ovpkM) { | ||
throw new Error('Both ivpkM and ovpkM are undefined. Cannot create note.'); | ||
} | ||
|
||
let incomingNote: IncomingNoteDao | undefined; | ||
let outgoingNote: OutgoingNoteDao | undefined; | ||
let incomingDeferredNote: DeferredNoteDao | undefined; | ||
let outgoingDeferredNote: DeferredNoteDao | undefined; | ||
|
||
if (ivpkM) { | ||
[incomingNote, incomingDeferredNote] = await produceNoteDaosForKey( | ||
simulator, | ||
db, | ||
ivpkM, | ||
payload, | ||
txHash, | ||
noteHashes, | ||
dataStartIndexForTx, | ||
excludedIndices, | ||
logger, | ||
unencryptedLogs, | ||
IncomingNoteDao.fromPayloadAndNoteInfo, | ||
); | ||
} | ||
|
||
if (ovpkM) { | ||
if (incomingNote) { | ||
// Incoming note is defined meaning that this PXE has both the incoming and outgoing keys. We can skip computing | ||
// note hash and note index since we already have them in the incoming note. | ||
outgoingNote = new OutgoingNoteDao( | ||
payload.note, | ||
payload.contractAddress, | ||
payload.storageSlot, | ||
payload.noteTypeId, | ||
txHash, | ||
incomingNote.nonce, | ||
incomingNote.noteHash, | ||
incomingNote.index, | ||
ovpkM, | ||
); | ||
} else { | ||
[outgoingNote, outgoingDeferredNote] = await produceNoteDaosForKey( | ||
simulator, | ||
db, | ||
ovpkM, | ||
payload, | ||
txHash, | ||
noteHashes, | ||
dataStartIndexForTx, | ||
excludedIndices, | ||
logger, | ||
unencryptedLogs, | ||
OutgoingNoteDao.fromPayloadAndNoteInfo, | ||
); | ||
} | ||
} | ||
|
||
return { | ||
incomingNote, | ||
outgoingNote, | ||
incomingDeferredNote, | ||
outgoingDeferredNote, | ||
}; | ||
} |
Oops, something went wrong.