Skip to content

Commit

Permalink
chore: fix oracle naming
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Sep 29, 2023
1 parent c08c36e commit c56ea1c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions yarn-project/acir-simulator/src/acvm/oracle/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export class Oracle {
return toAcvmL1ToL2MessageLoadOracleInputs(message, root);
}

async getDataTreePath([commitment]: ACVMField[]): Promise<ACVMField[]> {
return (await this.typedOracle.getDataTreePath(fromACVMField(commitment))).map(toACVMField);
async getMembershipWitness([leafValue]: ACVMField[]): Promise<ACVMField[]> {
return (await this.typedOracle.getMembershipWitness(fromACVMField(leafValue))).map(toACVMField);
}

async getPortalContractAddress([aztecAddress]: ACVMField[]): Promise<ACVMField> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export abstract class TypedOracle {
throw new Error('Not available.');
}

getDataTreePath(_commitment: Fr): Promise<Fr[]> {
getMembershipWitness(_commitment: Fr): Promise<Fr[]> {
throw new Error('Not available.');
}

Expand Down
9 changes: 5 additions & 4 deletions yarn-project/acir-simulator/src/client/view_data_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ export class ViewDataOracle extends TypedOracle {

/**
* Fetches the index and data tree path for a commitment
* @param commitment - The commitment
* @param leafValue - The commitment
* @returns The index and data tree path
*/
public async getDataTreePath(commitment: Fr): Promise<Fr[]> {
const index = await this.db.findCommitmentIndex(commitment.toBuffer());
public async getMembershipWitness(leafValue: Fr): Promise<Fr[]> {
// @todo @lherskind #2572
const index = await this.db.findCommitmentIndex(leafValue.toBuffer());
if (!index) {
throw new Error(`Commitment ${commitment} not found in private data tree`);
throw new Error(`Leaf value: ${leafValue} not found in private data tree`);
}
const path = await this.db.getDataTreePath(index);
return [new Fr(index), ...path.toFieldArray()];
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/aztec-nr/aztec/src/messaging.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ fn process_l1_to_l2_message(l1_to_l2_root: Field, storage_contract_address: Fiel
let returned_message = get_l1_to_l2_message_call(msg_key);
let l1_to_l2_message_data = make_l1_to_l2_message_getter_data(returned_message, 0, secret);

// Commitment should equal the msg_key if the message exsits and oracle is honest.
let commitment = l1_to_l2_message_data.message.message_hash();
assert(commitment == msg_key, "Data don't match the message key");
// leaf should equal the msg_key if the message exsits and oracle is honest.
let leaf = l1_to_l2_message_data.message.message_hash();
assert(leaf == msg_key, "Data don't match the message key");

// Validate that the commitment is indeed in the l1 to l2 message tree.
let root = compute_merkle_root(commitment, l1_to_l2_message_data.leaf_index, l1_to_l2_message_data.sibling_path);
let root = compute_merkle_root(leaf, l1_to_l2_message_data.leaf_index, l1_to_l2_message_data.sibling_path);
assert(root == l1_to_l2_root, "Invalid root");

// Validate this is the target contract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ describe('e2e_deploy_contract', () => {
expect(isIncludedReceipt.status).toEqual(TxStatus.MINED);

const badValueNote = { ...valueNote, owner: 100n };
const badCommitment = new Fr(await statefulContract.methods.get_commitment(badValueNote).view());
const badLeafValue = new Fr(await statefulContract.methods.get_commitment(badValueNote).view());
await expect(statefulContract.methods.is_included_in_history(badValueNote).simulate()).rejects.toThrowError(
`Commitment ${badCommitment} not found in private data tree`,
`Leaf value: ${badLeafValue} not found in private data tree`,
);
}, 30_000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ struct PrivateDataMembershipWitness {
path: [Field; PRIVATE_DATA_TREE_HEIGHT],
}

#[oracle(getDataTreePath)]
fn get_private_data_sibling_witness_oracle(_commitment: Field) -> [Field; PRIVATE_DATA_MEMBERSHIP_WITNESS_LEN] {}
#[oracle(getMembershipWitness)]
fn get_private_data_membership_witness_oracle(_commitment: Field) -> [Field; PRIVATE_DATA_MEMBERSHIP_WITNESS_LEN] {}

unconstrained fn get_private_data_sibling_witness(commitment: Field) -> PrivateDataMembershipWitness {
unconstrained fn get_private_data_membership_witness(commitment: Field) -> PrivateDataMembershipWitness {
assert(PRIVATE_DATA_MEMBERSHIP_WITNESS_LEN == PRIVATE_DATA_TREE_HEIGHT + 1);
let fields = get_private_data_sibling_witness_oracle(commitment);
let fields = get_private_data_membership_witness_oracle(commitment);
PrivateDataMembershipWitness {
index: fields[0],
path: arr_copy_slice(fields, [0; PRIVATE_DATA_TREE_HEIGHT], 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract StatefulTest {
},
};
use dep::aztec::constants_gen::PRIVATE_DATA_TREE_HEIGHT;
use crate::historic_commitment_oracle::{get_private_data_sibling_witness, PrivateDataMembershipWitness};
use crate::historic_commitment_oracle::{get_private_data_membership_witness, PrivateDataMembershipWitness};
use dep::aztec::note::utils::compute_note_hash_for_read_or_nullify;
use crate::almost_value_note::AlmostValueNote;

Expand Down Expand Up @@ -97,7 +97,7 @@ contract StatefulTest {
) {
let note = note.to_value_note();
let commitment = compute_note_hash_for_read_or_nullify(ValueNoteMethods, note);
let witness = get_private_data_sibling_witness(commitment);
let witness = get_private_data_membership_witness(commitment);
let root = compute_merkle_root(commitment, witness.index, witness.path);
assert(context.block_data.private_data_tree_root == root, "Note is not included in history");
}
Expand All @@ -107,7 +107,7 @@ contract StatefulTest {
) -> [Field; PRIVATE_DATA_TREE_HEIGHT] {
// compute the commitment
let commitment = compute_note_hash_for_read_or_nullify(ValueNoteMethods, note);
let witness = get_private_data_sibling_witness(commitment);
let witness = get_private_data_membership_witness(commitment);
witness.path
}

Expand All @@ -120,7 +120,7 @@ contract StatefulTest {
unconstrained fn get_root(note: ValueNote) -> Field {
// compute the commitment
let commitment = compute_note_hash_for_read_or_nullify(ValueNoteMethods, note);
let witness = get_private_data_sibling_witness(commitment);
let witness = get_private_data_membership_witness(commitment);
compute_merkle_root(commitment, witness.index, witness.path)
}

Expand Down

0 comments on commit c56ea1c

Please sign in to comment.