Skip to content

Commit

Permalink
nullifying the note
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Nov 7, 2023
1 parent d23cc43 commit 4eae602
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_liquidity_mining.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('e2e_liquidity_mining', () => {
// Claim
const receipt = await contract.methods.claim(accounts[0].address).send().wait({ debug: true });
const { newNullifiers } = receipt.debugInfo!;
expect(newNullifiers.length).toBe(1);
expect(newNullifiers.length).toBe(2); // tx hash and note nullifier
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ contract LiquidityMining {
types::address::AztecAddress,
context::Context,
note::{
note_getter_options::NoteGetterOptions,
note_header::NoteHeader,
utils as note_utils,
},
Expand Down Expand Up @@ -72,17 +73,21 @@ contract LiquidityMining {
#[aztec(private)]
fn claim(
owner: AztecAddress,
) -> Field {
// TODO
) {
let balances = storage.balances.at(owner.address);

let options = NoteGetterOptions::new().select(1, owner.address).set_limit(1);
let notes = balances.get_notes(options);
let note = notes[0].unwrap();

1
// Remove/nullify the note
balances.remove(note);
}

// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, serialized_note: [Field; LP_NOTE_LEN]) -> [Field; 4] {
assert(storage_slot == 1, "Invalid storage slot");
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(LPNoteMethods, note_header, serialized_note)
}
Expand Down

0 comments on commit 4eae602

Please sign in to comment.