Skip to content

Commit

Permalink
noir nullified commitments fix, simplify use of get_commitments to pr…
Browse files Browse the repository at this point in the history
…ep for pending commitments updates
  • Loading branch information
dbanks12 committed Jul 21, 2023
1 parent b1ede85 commit d7b2cab
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 28 deletions.
5 changes: 4 additions & 1 deletion yarn-project/aztec-rpc/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ export class SimulatorOracle implements DBOracle {
async getCommitmentOracle(contractAddress: AztecAddress, commitment: Fr): Promise<CommitmentDataOracleInputs> {
const siloedCommitment = siloCommitment(await CircuitsWasm.get(), contractAddress, commitment);
const index = await this.dataTreeProvider.findCommitmentIndex(siloedCommitment.toBuffer());
if (!index) throw new Error('Commitment not found');
if (!index)
throw new Error(
`Commitment not found in private data tree\n\traw: ${commitment.toString()}\n\tsiloed: ${siloedCommitment}`,
);

const siblingPath = await this.dataTreeProvider.getDataTreePath(index);
return await Promise.resolve({
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ contract NonNativeToken {

// Assert that the note exists within the tree
let public_note = TransparentNote::new_from_secret(amount, secret);
context = public_note.consume_in_secret(context, inputs.roots.private_data_tree_root, secret);
context = public_note.consume_in_secret(context, secret);

// Mint the tokens
let balance = storage.balances.at(owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,26 @@ impl TransparentNote {
pedersen([self.amount, self.secretHash])[0]
}

fn consume_in_secret(self: Self, mut context: Context, root: Field, secret: Field) -> Context {
fn consume_in_secret(self: Self, mut context: Context, secret: Field) -> Context {
// Get the commitment value (before silo)
let commitment = self.get_commitment();

// Let the kernel perform the read.
context = context.push_read_request(commitment);

// Get the commitment data, (where it is in the db)
let commitment_oracle_call = get_commitment(commitment);
let commitment_data = make_commitment_getter_data(commitment_oracle_call, 0);
// Do we still need to do this with read requests?
assert(root == commitment_data.root);
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1142): can probably replace
// get_commitment here with a simple "check_commitment_exists" oracle that just throws an
// error in simulator if commitment isn't found

// Get the commitment data (leaf index and root in private data tree)
// if it returns the commitment, then it does in fact exist in DB
let serialized_commitment_data = get_commitment(commitment);
let commitment_data = make_commitment_getter_data(serialized_commitment_data, 0);
// membership check happens in kernel, so just make sure the oracle call
// was successful to confirm that the commitment exists
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1142): just assert
// that oracle was successful (result == 0) if we switch to "check_commitment_exists"
assert(commitment_data.message == commitment);

// Calculate the nullifier
self.emit_nullifier(context, secret, commitment, commitment_data.leaf_index)
Expand All @@ -63,7 +71,7 @@ impl TransparentNote {

fn emit_nullifier(_self: Self, mut context: Context, secret: Field, siloed_commitment: Field, index: Field) -> Context {
// Create a nullifier for the message based on its index in the tree

let nullifier = pedersen([secret, siloed_commitment, index])[0];
context.push_new_nullifier(nullifier, siloed_commitment)
}
Expand Down
7 changes: 3 additions & 4 deletions yarn-project/noir-libs/noir-aztec/src/note/lifecycle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ fn create_note<Note, N>(

let serialise = note_interface.serialise;
let preimage = serialise(note);
let mut myfield = 0;
notify_result = notify_created_note(storage_slot, preimage);
assert(notify_result == 0); // TODO(https://github.com/noir-lang/noir/pull/1729): combine with above line (more below)
}
Expand All @@ -43,7 +42,7 @@ fn destroy_note<Note, N>(
note_interface: NoteInterface<Note, N>,
) -> Context {
let mut nullifier = 0;
let mut nullified_commitment = EMPTY_NULLIFIED_COMMITMENT;
let mut nullified_commitment: Field = EMPTY_NULLIFIED_COMMITMENT;
let is_dummy = note_interface.is_dummy;
if is_dummy(note) == false {
let compute_nullifier = note_interface.compute_nullifier;
Expand All @@ -52,10 +51,10 @@ fn destroy_note<Note, N>(
let serialise = note_interface.serialise;
let preimage = serialise(note);
assert(notify_nullified_note(storage_slot, nullifier, preimage) == 0);

// We also need the note commitment corresponding to the "nullifier"
// TODO(suyash): We're re-computing the note commitment, ideally we can reuse the one already computed.
let nullified_commitment = compute_inner_note_hash(note_interface, note);
nullified_commitment = compute_inner_note_hash(note_interface, note);
}


Expand Down

0 comments on commit d7b2cab

Please sign in to comment.