From db76b066ec5b5f2c4ba89cf4842f427ec30b2c6a Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 1 Feb 2024 08:55:42 -0300 Subject: [PATCH] chore: Reenable private kernel function tree checks --- .../src/private_kernel_init.nr | 43 +++++++++---------- .../src/private_kernel_inner.nr | 43 +++++++++---------- 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr index 04d5d60c0e7..3fe0658498d 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr @@ -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(); } diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr index 47e378306c3..1901a82fc44 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -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(); }