├── .gitignore ├── Nargo.toml ├── README.md ├── add ├── Nargo.toml └── src │ └── main.sol ├── assets └── readme.png ├── for ├── Nargo.toml └── src │ └── main.sol └── if ├── Nargo.toml └── src └── main.sol /.gitignore: -------------------------------------------------------------------------------- 1 | proofs/ 2 | target/ 3 | Prover.toml 4 | Verifier.toml -------------------------------------------------------------------------------- /Nargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "add", 4 | "if", 5 | "for" 6 | ] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Solidity Circuits 4 | 5 | Write zero knowledge proofs in solidity. 6 | 7 | Creating an alternative frontend for noir / nargo, developers can write, prove and verify zk circuits that are written in solidity. 8 | 9 | That's it. 10 | 11 | ## What is in this repo? 12 | 13 | This repo contains a `nargo` workspace where the files are written in solidity. Each example demonstrates a different type of circuit, use the run instructions below to test each of them! 14 | 15 | ### How to run? 16 | 17 | 1. Make sure you have `noirup` installed - instructions below. 18 | 2. Go and clone this [branch of noir](https://github.com/noir-lang/noir/tree/md/solidity-circuits) 19 | 3. Run `noirup -p .` to replace your local nargo binary with the one with solidity support 20 | 4. Run `nargo check` to generate prover toml etc 21 | 5. Enter the values you want in your generate your proof with in `Prover.toml` 22 | 6. `nargo compile` 23 | 7. `nargo prove` 24 | 8. `nargo verify` 25 | 26 | 27 | ### First time with Noir? 28 | 29 | See the official Noir installation [instructions](https://noir-lang.org/getting_started/nargo_installation). 30 | 31 | Then, install the [Noir](https://github.com/noir-lang/noir) toolchain installer (`noirup`) with: 32 | 33 | ```bash 34 | curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash 35 | ``` 36 | 37 | Now you've installed the `noirup` binary, 38 | Follow the instructions above to install the solidity circuits branch. 39 | -------------------------------------------------------------------------------- /add/Nargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sol_test" 3 | type = "sol" 4 | authors = [""] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /add/src/main.sol: -------------------------------------------------------------------------------- 1 | 2 | contract AddTest { 3 | 4 | // Demo function, returns the sum of two numbers 5 | function main(uint256 x, uint256 y) public pure returns (uint256) { 6 | return x + y; 7 | } 8 | } -------------------------------------------------------------------------------- /assets/readme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maddiaa0/solidity-circuits/aa1eca9bd8369e741a824ecbbf0618c6e8d9c7f9/assets/readme.png -------------------------------------------------------------------------------- /for/Nargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "for_test" 3 | type = "sol" 4 | authors = [""] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /for/src/main.sol: -------------------------------------------------------------------------------- 1 | contract ForLoopTest { 2 | 3 | // Demonstrate a simple for loop 4 | function main(uint256 x) public pure returns (uint256) { 5 | uint256 ret_val = x; 6 | 7 | // Note, for loops MUST be in this form for support 8 | // Codegen must be able to solve for a static start and end to the loop 9 | // Using this i pattern is the simplest way 10 | for (uint256 i = 0; i < 10; i++){ 11 | ret_val += i; 12 | } 13 | return ret_val; 14 | } 15 | } -------------------------------------------------------------------------------- /if/Nargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "if_test" 3 | type = "sol" 4 | authors = [""] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /if/src/main.sol: -------------------------------------------------------------------------------- 1 | contract IfTest { 2 | // Demo function, returns the sum of two numbers 3 | function main(uint256 x, uint256 y) public pure returns (uint256) { 4 | uint256 ret_val; 5 | if (x == 10) { 6 | ret_val = x - y; 7 | } else { 8 | ret_val = y - x; 9 | } 10 | return ret_val; 11 | } 12 | } --------------------------------------------------------------------------------