Skip to content

Commit

Permalink
chore: Reenable private kernel function tree checks (AztecProtocol#4358)
Browse files Browse the repository at this point in the history
Reenables private kernel tests disabled in AztecProtocol#4337 to test the correct
derivation of contract address, as a means to verifying that the
function being executed belongs to the contract.
  • Loading branch information
spalladino committed Feb 1, 2024
1 parent 75e30b9 commit e7db0da
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,47 +429,46 @@ mod tests {
builder.failed();
}

// #[test(should_fail_with="computed_contract_tree_root does not match purported_contract_tree_root")]
fn private_function_incorrect_contract_leaf_index_fails() {
#[test(should_fail_with="computed contract address does not match expected one")]
fn private_function_incorrect_function_leaf_index_fails() {
let mut builder = PrivateKernelInitInputsBuilder::new();

// Set the leaf index of the contract leaf to a wrong value (the correct value + 1).
// let leaf_index = builder.private_call.contract_leaf_membership_witness.leaf_index;
// builder.private_call.contract_leaf_membership_witness.leaf_index = leaf_index + 1;
// Set the leaf index of the function leaf to a wrong value (the correct value + 1).
let leaf_index = builder.private_call.function_leaf_membership_witness.leaf_index;
builder.private_call.function_leaf_membership_witness.leaf_index = leaf_index + 1;

builder.failed();
}

// #[test(should_fail_with="computed_contract_tree_root does not match purported_contract_tree_root")]
fn private_function_incorrect_contract_leaf_sibling_path_fails() {
#[test(should_fail_with="computed contract address does not match expected one")]
fn private_function_incorrect_function_leaf_sibling_path_fails() {
let mut builder = PrivateKernelInitInputsBuilder::new();

// Set the first value of the sibling path to a wrong value (the correct value + 1).
// let sibling_path_0 = builder.private_call.contract_leaf_membership_witness.sibling_path[0];
// builder.private_call.contract_leaf_membership_witness.sibling_path[0] = sibling_path_0 + 1;
let sibling_path_0 = builder.private_call.function_leaf_membership_witness.sibling_path[0];
builder.private_call.function_leaf_membership_witness.sibling_path[0] = sibling_path_0 + 1;

builder.failed();
}

// #[test(should_fail_with="computed_contract_tree_root does not match purported_contract_tree_root")]
fn private_function_incorrect_function_leaf_index_fails() {
#[test(should_fail_with="computed contract address does not match expected one")]
fn private_function_incorrect_contract_class_preimage_fails() {
let mut builder = PrivateKernelInitInputsBuilder::new();

// Set the leaf index of the function leaf to a wrong value (the correct value + 1).
let leaf_index = builder.private_call.function_leaf_membership_witness.leaf_index;
builder.private_call.function_leaf_membership_witness.leaf_index = leaf_index + 1;

builder.private_call.contract_class_artifact_hash = builder.private_call.contract_class_artifact_hash + 1;
builder.failed();
}

// #[test(should_fail_with="computed_contract_tree_root does not match purported_contract_tree_root")]
fn private_function_incorrect_function_leaf_sibling_path_fails() {
#[test(should_fail_with="computed contract address does not match expected one")]
fn private_function_incorrect_partial_address_preimage_fails() {
let mut builder = PrivateKernelInitInputsBuilder::new();
builder.private_call.salted_initialization_hash.inner = builder.private_call.salted_initialization_hash.inner + 1;
builder.failed();
}

// Set the first value of the sibling path to a wrong value (the correct value + 1).
let sibling_path_0 = builder.private_call.function_leaf_membership_witness.sibling_path[0];
builder.private_call.function_leaf_membership_witness.sibling_path[0] = sibling_path_0 + 1;

#[test(should_fail_with="computed contract address does not match expected one")]
fn private_function_incorrect_address_preimage_fails() {
let mut builder = PrivateKernelInitInputsBuilder::new();
builder.private_call.public_keys_hash.inner = builder.private_call.public_keys_hash.inner + 1;
builder.failed();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,47 +176,46 @@ mod tests {
builder.failed();
}

// #[test(should_fail_with = "computed_contract_tree_root does not match purported_contract_tree_root")]
fn private_function_incorrect_contract_leaf_index_fails() {
#[test(should_fail_with="computed contract address does not match expected one")]
fn private_function_incorrect_function_leaf_index_fails() {
let mut builder = PrivateKernelInnerInputsBuilder::new();

// Set the leaf index of the contract leaf to a wrong value (the correct value + 1).
// let leaf_index = builder.private_call.contract_leaf_membership_witness.leaf_index;
// builder.private_call.contract_leaf_membership_witness.leaf_index = leaf_index + 1;
// Set the leaf index of the function leaf to a wrong value (the correct value + 1).
let leaf_index = builder.private_call.function_leaf_membership_witness.leaf_index;
builder.private_call.function_leaf_membership_witness.leaf_index = leaf_index + 1;

builder.failed();
}

// #[test(should_fail_with = "computed_contract_tree_root does not match purported_contract_tree_root")]
fn private_function_incorrect_contract_leaf_sibling_path_fails() {
#[test(should_fail_with="computed contract address does not match expected one")]
fn private_function_incorrect_function_leaf_sibling_path_fails() {
let mut builder = PrivateKernelInnerInputsBuilder::new();

// Set the first value of the sibling path to a wrong value (the correct value + 1).
// let sibling_path_0 = builder.private_call.contract_leaf_membership_witness.sibling_path[0];
// builder.private_call.contract_leaf_membership_witness.sibling_path[0] = sibling_path_0 + 1;
let sibling_path_0 = builder.private_call.function_leaf_membership_witness.sibling_path[0];
builder.private_call.function_leaf_membership_witness.sibling_path[0] = sibling_path_0 + 1;

builder.failed();
}

// #[test(should_fail_with = "computed_contract_tree_root does not match purported_contract_tree_root")]
fn private_function_incorrect_function_leaf_index_fails() {
#[test(should_fail_with="computed contract address does not match expected one")]
fn private_function_incorrect_contract_class_preimage_fails() {
let mut builder = PrivateKernelInnerInputsBuilder::new();

// Set the leaf index of the function leaf to a wrong value (the correct value + 1).
let leaf_index = builder.private_call.function_leaf_membership_witness.leaf_index;
builder.private_call.function_leaf_membership_witness.leaf_index = leaf_index + 1;

builder.private_call.contract_class_artifact_hash = builder.private_call.contract_class_artifact_hash + 1;
builder.failed();
}

// #[test(should_fail_with = "computed_contract_tree_root does not match purported_contract_tree_root")]
fn private_function_incorrect_function_leaf_sibling_path_fails() {
#[test(should_fail_with="computed contract address does not match expected one")]
fn private_function_incorrect_partial_address_preimage_fails() {
let mut builder = PrivateKernelInnerInputsBuilder::new();
builder.private_call.salted_initialization_hash.inner = builder.private_call.salted_initialization_hash.inner + 1;
builder.failed();
}

// Set the first value of the sibling path to a wrong value (the correct value + 1).
let sibling_path_0 = builder.private_call.function_leaf_membership_witness.sibling_path[0];
builder.private_call.function_leaf_membership_witness.sibling_path[0] = sibling_path_0 + 1;

#[test(should_fail_with="computed contract address does not match expected one")]
fn private_function_incorrect_address_preimage_fails() {
let mut builder = PrivateKernelInnerInputsBuilder::new();
builder.private_call.public_keys_hash.inner = builder.private_call.public_keys_hash.inner + 1;
builder.failed();
}

Expand Down

0 comments on commit e7db0da

Please sign in to comment.