Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ZoKrates with curly brackets (wip) #211

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

StefanosChaliasos
Copy link

@StefanosChaliasos StefanosChaliasos commented Oct 30, 2024

This PR tries to address #208.
Some of the features that are not supported by the grammar are:

  • Integer
  • cond_store
  • Array Metadata
  • Witness

Furthermore, we don't currently support MPC.

Finally, the implementation of assembly has not been tested and shouldn't be complete.

All the tests pass. To run them, you can use the following commands:

cargo build --release --features=r1cs --features=smt --features=zok --features=lp --features=bellman --features=zokc --example=circ
cargo build --release --features=r1cs --features=smt --features=zokc --features=lp  --features=bellman --example=zcxi
./scripts/zokrates_curly_test.zsh

The changes to support ZoKrates with curly brackets are the following:

  • We added third_party/ZoKratesCurly.
  • We added a new frontend, src/front/zsharpcurly.
  • We added a new feature called zokc.
  • We updated circ executable to support zsharpcurly and implemented zcxi.
  • Finally, we copied and updated the tests and the scripts to run the tests for zsharpcurly.

TODOs:

  • Check that all tests have been converted correctly (which are not!)
  • Fix assembly
  • Apply the proper format
  • Do we want to support MPC?

Note that you can check the changes vs the original implementation in the first 4 commits of this PR.

Copy link
Contributor

@alex-ozdemir alex-ozdemir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very nice patch, Stefanos. I have a few questions about it, but I think they should be easy to address.

src/front/zsharpcurly/interp.rs Outdated Show resolved Hide resolved
src/front/zsharpcurly/mod.rs Show resolved Hide resolved
src/front/zsharpcurly/mod.rs Outdated Show resolved Hide resolved
src/front/zsharpcurly/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@alex-ozdemir alex-ozdemir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me now.
If you're happy with it, then I'll merge it.

}
}

fn assembly_assign_impl_<const IS_CNST: bool>(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alex-ozdemir, can you review this code?

}
}

fn assembly_constraint_<const IS_CNST: bool>(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I just add the assembly constraints like it was an assertion.

@StefanosChaliasos
Copy link
Author

I think that if we make sure that assembly is handled correctly, then we can proceed. ref: https://zokrates.github.io/language/assembly.html

@alex-ozdemir
Copy link
Contributor

Is the omission of field_to_bool_unsafe intentional?

}
}

pub fn field_to_bool_unsafe(f: T) -> Result<T, String> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alex-ozdemir, can you review this one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you actually want this operator using it will maintain the connection between the input and the output of the operator in the final constraint system, it will just assume that the value is 0 or 1. See this part of R1CS lowering.

What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes sense! Should we still wrap it in a new_witness Op? If we do so, in the test, should we also pass the new_witness value?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes sense! Should we still wrap it in a new_witness Op?

No, you should not.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it

@StefanosChaliasos
Copy link
Author

Sorry for the delay. It was not intentional; I tried to implement it (without changing the IR), but the test failed.

Copy link
Contributor

@alex-ozdemir alex-ozdemir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(A change may not be necessary---see my comment and let me know what you think.)

}
}

pub fn field_to_bool_unsafe(f: T) -> Result<T, String> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you actually want this operator using it will maintain the connection between the input and the output of the operator in the final constraint system, it will just assume that the value is 0 or 1. See this part of R1CS lowering.

What do you think?

@StefanosChaliasos
Copy link
Author

@alex-ozdemir fixed the issues, now the mpc tests fail. Seems like we miss libcrypto:

Server error: ./third_party/bin/ABY/aby_interpreter: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory

@alex-ozdemir
Copy link
Contributor

Hi @StefanosChaliasos ,

We've dodged the issue with ABY's testing infrastructure. (#221)
You should be able to merge/rebase and proceed with this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants