Skip to content

Commit

Permalink
feat: migrate cpp private kernel tests to noir (#3165)
Browse files Browse the repository at this point in the history
Please provide a paragraph or two giving a summary of the change,
including relevant motivation and context.

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [ ] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [ ] Every change is related to the PR description.
- [ ] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).

---------

Co-authored-by: sirasistant <sirasistant@gmail.com>
  • Loading branch information
LeilaWang and sirasistant authored Nov 1, 2023
1 parent fb53f7a commit daee2f9
Show file tree
Hide file tree
Showing 6 changed files with 1,093 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use crate::utils;

// Aztec address
struct Address{
struct Address {
inner : Field
}

impl Address{
impl Address {
pub fn ZERO() -> Self {
Self {
inner: 0
}
}

pub fn default() -> Self {
Self {
Expand Down Expand Up @@ -44,6 +49,11 @@ struct EthAddress{
}

impl EthAddress{
pub fn ZERO() -> Self {
Self {
inner: 0
}
}

pub fn default() -> Self {
Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ pub fn contract_logic(private_call : PrivateCallData, public_inputs : &mut Kerne
public_inputs.end.new_nullifiers.push(new_contract_address_nullifier);
} else {
// non-contract deployments must specify contract address being interacted with
assert(storage_contract_address.to_field() != 0, "contract address can't be 0 for non-contract deployment related transactions");
// TODO - Allow special characters in error message.
// assert(storage_contract_address.to_field() != 0, "contract address can't be 0 for non-contract deployment related transactions");
assert(storage_contract_address.to_field() != 0, "contract address cannot be 0");

/* We need to compute the root of the contract tree, starting from the function's VK:
* - Compute the vk_hash (done above)
Expand All @@ -302,7 +304,9 @@ pub fn contract_logic(private_call : PrivateCallData, public_inputs : &mut Kerne
// Ensures that if the function is internal, only the contract itself can call it
if (private_call.call_stack_item.function_data().is_internal) {
let msg_sender = private_call.call_stack_item.public_inputs().call_context.msg_sender;
assert(storage_contract_address.eq(msg_sender), "call is internal, but msg_sender is not self");
// TODO - Allow special characters in error message.
// assert(storage_contract_address.eq(msg_sender), "call is internal, but msg_sender is not self");
assert(storage_contract_address.eq(msg_sender), "call is internal but msg_sender is not self");
}

// The logic below ensures that the contract exists in the contracts tree
Expand All @@ -321,7 +325,9 @@ pub fn contract_logic(private_call : PrivateCallData, public_inputs : &mut Kerne
private_call.contract_leaf_membership_witness.sibling_path);

let purported_contract_tree_root = private_call.call_stack_item.public_inputs().historical_block_data.contract_tree_root();
assert_eq(computed_contract_tree_root, purported_contract_tree_root, "computed_contract_tree_root doesn't match purported_contract_tree_root");
// TODO - Allow special characters in error message.
// assert_eq(computed_contract_tree_root, purported_contract_tree_root, "computed_contract_tree_root doesn't match purported_contract_tree_root");
assert_eq(computed_contract_tree_root, purported_contract_tree_root, "computed_contract_tree_root does not match purported_contract_tree_root");
}
}

Expand Down
Loading

0 comments on commit daee2f9

Please sign in to comment.