forked from visoftsolutions/noir_rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: reprocess notes in pxe when a new contract is added (AztecProtoc…
…ol#3867) Add notion of a Deferred Note: a note that we can *decrypt*, but not decode because we don't have the contract artifact in our PXE database. We hang on to these deferred notes in a new store in our PXE database, and reprocess them when their contract is made available. When we reprocess and successfully decode, we also need to search if we have already nullified the newly decoded note.
- Loading branch information
1 parent
ab07e7e
commit ccbff99
Showing
17 changed files
with
725 additions
and
159 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
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,34 @@ | ||
import { AztecAddress, Fr, Point } from '@aztec/circuits.js'; | ||
import { Note, randomTxHash } from '@aztec/types'; | ||
|
||
import { DeferredNoteDao } from './deferred_note_dao.js'; | ||
|
||
export const randomDeferredNoteDao = ({ | ||
publicKey = Point.random(), | ||
note = Note.random(), | ||
contractAddress = AztecAddress.random(), | ||
txHash = randomTxHash(), | ||
storageSlot = Fr.random(), | ||
txNullifier = Fr.random(), | ||
newCommitments = [Fr.random(), Fr.random()], | ||
dataStartIndexForTx = Math.floor(Math.random() * 100), | ||
}: Partial<DeferredNoteDao> = {}) => { | ||
return new DeferredNoteDao( | ||
publicKey, | ||
note, | ||
contractAddress, | ||
storageSlot, | ||
txHash, | ||
txNullifier, | ||
newCommitments, | ||
dataStartIndexForTx, | ||
); | ||
}; | ||
|
||
describe('Deferred Note DAO', () => { | ||
it('convert to and from buffer', () => { | ||
const deferredNote = randomDeferredNoteDao(); | ||
const buf = deferredNote.toBuffer(); | ||
expect(DeferredNoteDao.fromBuffer(buf)).toEqual(deferredNote); | ||
}); | ||
}); |
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,55 @@ | ||
import { AztecAddress, Fr, Point, PublicKey, Vector } from '@aztec/circuits.js'; | ||
import { serializeToBuffer } from '@aztec/circuits.js/utils'; | ||
import { BufferReader, Note, TxHash } from '@aztec/types'; | ||
|
||
/** | ||
* A note that is intended for us, but we cannot decode it yet because the contract is not yet in our database. | ||
* | ||
* So keep the state that we need to decode it later. | ||
*/ | ||
export class DeferredNoteDao { | ||
constructor( | ||
/** The public key associated with this note */ | ||
public publicKey: PublicKey, | ||
/** The note as emitted from the Noir contract. */ | ||
public note: Note, | ||
/** The contract address this note is created in. */ | ||
public contractAddress: AztecAddress, | ||
/** The specific storage location of the note on the contract. */ | ||
public storageSlot: Fr, | ||
/** The hash of the tx the note was created in. */ | ||
public txHash: TxHash, | ||
/** The first nullifier emitted by the transaction */ | ||
public txNullifier: Fr, | ||
/** New commitments in this transaction, one of which belongs to this note */ | ||
public newCommitments: Fr[], | ||
/** The next available leaf index for the note hash tree for this transaction */ | ||
public dataStartIndexForTx: number, | ||
) {} | ||
|
||
toBuffer(): Buffer { | ||
return serializeToBuffer( | ||
this.publicKey.toBuffer(), | ||
this.note.toBuffer(), | ||
this.contractAddress.toBuffer(), | ||
this.storageSlot.toBuffer(), | ||
this.txHash.toBuffer(), | ||
this.txNullifier.toBuffer(), | ||
new Vector(this.newCommitments), | ||
this.dataStartIndexForTx, | ||
); | ||
} | ||
static fromBuffer(buffer: Buffer | BufferReader) { | ||
const reader = BufferReader.asReader(buffer); | ||
return new DeferredNoteDao( | ||
reader.readObject(Point), | ||
reader.readObject(Note), | ||
reader.readObject(AztecAddress), | ||
reader.readObject(Fr), | ||
reader.readObject(TxHash), | ||
reader.readObject(Fr), | ||
reader.readVector(Fr), | ||
reader.readNumber(), | ||
); | ||
} | ||
} |
Oops, something went wrong.