diff --git a/Cargo.lock b/Cargo.lock index 00a6d07..39468b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -222,7 +222,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -624,7 +624,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -750,7 +750,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -1156,7 +1156,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -1551,7 +1551,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -1578,7 +1578,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -1595,7 +1595,7 @@ checksum = "8908e380a8efd42150c017b0cfa31509fc49b6d47f7cb6b33e93ffb8f4e3661e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -1820,7 +1820,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -1866,7 +1866,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.57", + "syn 2.0.87", "termcolor", "toml 0.8.10", "walkdir", @@ -2090,7 +2090,7 @@ dependencies = [ "fs-err", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -2438,7 +2438,7 @@ dependencies = [ "proc-macro2", "quote", "sp-crypto-hashing", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -2450,7 +2450,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -2460,7 +2460,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0 dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -2653,7 +2653,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -3462,7 +3462,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -4218,7 +4218,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -4232,7 +4232,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -4243,7 +4243,7 @@ checksum = "9ea73aa640dc01d62a590d48c0c3521ed739d53b27f919b25c3551e233481654" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -4254,7 +4254,7 @@ checksum = "ef9d79ae96aaba821963320eb2b6e34d17df1e5a83d8a1985c29cc5be59577b3" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -5603,7 +5603,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -5644,7 +5644,7 @@ checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -5736,7 +5736,7 @@ dependencies = [ "polkavm-common", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -5746,7 +5746,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -5905,7 +5905,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -5972,14 +5972,14 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] @@ -6064,7 +6064,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -6132,7 +6132,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -6391,7 +6391,7 @@ checksum = "5fddb4f8d99b0a2ebafc65a87a69a7b9875e4b1ae1f00db265d300ef7f28bccc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -6894,7 +6894,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -7708,7 +7708,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -7980,7 +7980,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -8233,7 +8233,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -8478,7 +8478,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0 dependencies = [ "quote", "sp-crypto-hashing", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -8497,7 +8497,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0 dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -8507,7 +8507,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk#d3d1542c1d387408c141f9a dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -8737,7 +8737,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -8750,7 +8750,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -8972,7 +8972,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -9163,7 +9163,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -9176,7 +9176,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -9284,9 +9284,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.57" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a6ae1e52eb25aab8f3fb9fca13be982a373b8f1157ca14b897a825ba4a2d35" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -9392,7 +9392,7 @@ checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -9512,7 +9512,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -9693,7 +9693,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -10175,7 +10175,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -10209,7 +10209,7 @@ checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -10918,7 +10918,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] @@ -10938,7 +10938,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.87", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f02e10b..5bf5a06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,6 +77,7 @@ pallet-anonymous-account = { path = "custom-pallets/anonymous-account", default- pallet-simple-approval-voting = { path = "custom-pallets/simple-approval-voting", default-features = false } pallet-first-past-the-post = { path = "custom-pallets/first-past-the-post" } + ## Traits trait-sortition-sum-game = { path = "traits/trait-sortition-sum-game", default-features = false } trait-shared-storage = { path = "traits/trait-shared-storage", default-features = false } diff --git a/custom-pallets/zkp-anonymous_account/.gitignore b/custom-pallets/zkp-anonymous_account/.gitignore new file mode 100644 index 0000000..f4247e1 --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +Cargo.lock +methods/guest/Cargo.lock +target/ diff --git a/custom-pallets/zkp-anonymous_account/Cargo.toml b/custom-pallets/zkp-anonymous_account/Cargo.toml new file mode 100644 index 0000000..63b3854 --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] +resolver = "2" +members = ["host", "methods"] + +# Always optimize; building and running the guest takes much longer without optimization. +[profile.dev] +opt-level = 3 + +[profile.release] +debug = 1 +lto = true diff --git a/custom-pallets/zkp-anonymous_account/LICENSE b/custom-pallets/zkp-anonymous_account/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/custom-pallets/zkp-anonymous_account/README.md b/custom-pallets/zkp-anonymous_account/README.md new file mode 100644 index 0000000..df70292 --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/README.md @@ -0,0 +1,111 @@ +# RISC Zero Rust Starter Template + +Welcome to the RISC Zero Rust Starter Template! This template is intended to +give you a starting point for building a project using the RISC Zero zkVM. +Throughout the template (including in this README), you'll find comments +labelled `TODO` in places where you'll need to make changes. To better +understand the concepts behind this template, check out the [zkVM +Overview][zkvm-overview]. + +## Quick Start + +First, make sure [rustup] is installed. The +[`rust-toolchain.toml`][rust-toolchain] file will be used by `cargo` to +automatically install the correct version. + +To build all methods and execute the method within the zkVM, run the following +command: + +```bash +cargo run +``` + +This is an empty template, and so there is no expected output (until you modify +the code). + +### Executing the Project Locally in Development Mode + +During development, faster iteration upon code changes can be achieved by leveraging [dev-mode], we strongly suggest activating it during your early development phase. Furthermore, you might want to get insights into the execution statistics of your project, and this can be achieved by specifying the environment variable `RUST_LOG="[executor]=info"` before running your project. + +Put together, the command to run your project in development mode while getting execution statistics is: + +```bash +RUST_LOG="[executor]=info" RISC0_DEV_MODE=1 cargo run +``` + +### Running Proofs Remotely on Bonsai + +_Note: The Bonsai proving service is still in early Alpha; an API key is +required for access. [Click here to request access][bonsai access]._ + +If you have access to the URL and API key to Bonsai you can run your proofs +remotely. To prove in Bonsai mode, invoke `cargo run` with two additional +environment variables: + +```bash +BONSAI_API_KEY="YOUR_API_KEY" BONSAI_API_URL="BONSAI_URL" cargo run +``` + +## How to Create a Project Based on This Template + +Search this template for the string `TODO`, and make the necessary changes to +implement the required feature described by the `TODO` comment. Some of these +changes will be complex, and so we have a number of instructional resources to +assist you in learning how to write your own code for the RISC Zero zkVM: + +- The [RISC Zero Developer Docs][dev-docs] is a great place to get started. +- Example projects are available in the [examples folder][examples] of + [`risc0`][risc0-repo] repository. +- Reference documentation is available at [https://docs.rs][docs.rs], including + [`risc0-zkvm`][risc0-zkvm], [`cargo-risczero`][cargo-risczero], + [`risc0-build`][risc0-build], and [others][crates]. + +## Directory Structure + +It is possible to organize the files for these components in various ways. +However, in this starter template we use a standard directory structure for zkVM +applications, which we think is a good starting point for your applications. + +```text +project_name +├── Cargo.toml +├── host +│ ├── Cargo.toml +│ └── src +│ └── main.rs <-- [Host code goes here] +└── methods + ├── Cargo.toml + ├── build.rs + ├── guest + │ ├── Cargo.toml + │ └── src + │ └── method_name.rs <-- [Guest code goes here] + └── src + └── lib.rs +``` + +## Video Tutorial + +For a walk-through of how to build with this template, check out this [excerpt +from our workshop at ZK HACK III][zkhack-iii]. + +## Questions, Feedback, and Collaborations + +We'd love to hear from you on [Discord][discord] or [Twitter][twitter]. + +[bonsai access]: https://bonsai.xyz/apply +[cargo-risczero]: https://docs.rs/cargo-risczero +[crates]: https://github.com/risc0/risc0/blob/main/README.md#rust-binaries +[dev-docs]: https://dev.risczero.com +[dev-mode]: https://dev.risczero.com/api/generating-proofs/dev-mode +[discord]: https://discord.gg/risczero +[docs.rs]: https://docs.rs/releases/search?query=risc0 +[examples]: https://github.com/risc0/risc0/tree/main/examples +[risc0-build]: https://docs.rs/risc0-build +[risc0-repo]: https://www.github.com/risc0/risc0 +[risc0-zkvm]: https://docs.rs/risc0-zkvm +[rust-toolchain]: rust-toolchain.toml +[rustup]: https://rustup.rs +[twitter]: https://twitter.com/risczero +[zkhack-iii]: https://www.youtube.com/watch?v=Yg_BGqj_6lg&list=PLcPzhUaCxlCgig7ofeARMPwQ8vbuD6hC5&index=5 +[zkvm-overview]: https://dev.risczero.com/zkvm diff --git a/custom-pallets/zkp-anonymous_account/host/Cargo.toml b/custom-pallets/zkp-anonymous_account/host/Cargo.toml new file mode 100644 index 0000000..981b82d --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/host/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "host" +version = "0.1.0" +edition = "2021" + +[dependencies] +methods = { path = "../methods" } +risc0-zkvm = { version = "1.1.2" } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } +serde = "1.0" +subxt = "0.37.0" +subxt-signer = "0.37.0" +sp-io = "38.0.0" +sp-core = "34.0.0" +subxt-core = "0.37.0" diff --git a/custom-pallets/zkp-anonymous_account/host/src/accounts_hash.rs b/custom-pallets/zkp-anonymous_account/host/src/accounts_hash.rs new file mode 100644 index 0000000..127e627 --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/host/src/accounts_hash.rs @@ -0,0 +1,74 @@ +use serde::{Deserialize, Serialize}; +use sp_io::hashing::blake2_256; +use subxt_core::utils::AccountId32; +use subxt_signer::{bip39::Mnemonic, sr25519::Keypair}; + +#[derive(Serialize, Deserialize)] +pub struct AccountData { + pub account_addresses: Vec, + pub current_hash: [u8; 32], + pub index: usize, + pub public_key_of_account: [u8; 32], + pub signature: Vec, // Use Vec instead of [u8; 64] + pub password: String, +} + +fn update_hash_incrementally(current_hash: [u8; 32], account_id: &AccountId32) -> [u8; 32] { + let mut input_data = Vec::new(); + + // Extend input data with the current hash and the new account ID + input_data.extend_from_slice(¤t_hash); + input_data.extend_from_slice(account_id.as_ref()); + + // Recalculate the hash with the new account ID + blake2_256(&input_data) +} + +pub fn keypair_func() -> AccountData { + let mut phrases = Vec::new(); + phrases.push("bottom drive obey lake curtain smoke basket hold race lonely fit walk"); + phrases.push("demand toy recycle symptom this arrow pear ribbon orchard large cabin tower"); + phrases.push("repair resist urban upgrade delay security blush vote bean moment current drill"); + phrases + .push("disagree romance reform wink essence speak sense fence cause reflect sound alarm"); + phrases.push("figure husband please idea captain bulk despair over letter code art mimic"); + phrases.push("regret family similar face thumb magic head team duty web side strike"); + phrases.push("resemble timber picnic stage must video amount price sport help good stable"); + let phrases_clone = phrases.clone(); + let mut account_addresses = Vec::new(); + let mut current_hash: [u8; 32] = [0; 32]; + for phrase in phrases { + let mnemonic = Mnemonic::parse(phrase).unwrap(); + let keypair = Keypair::from_phrase(&mnemonic, None).unwrap(); + let account_address = keypair.public_key().to_account_id(); + println!("{:?}", account_address); + account_addresses.push(account_address.clone()); + current_hash = update_hash_incrementally(current_hash, &account_address); + } + + println!("current_hash:{:?}", current_hash); + + let index = 2; + + let phrase_of_index = phrases_clone[index]; + let mnemonic = Mnemonic::parse(phrase_of_index).unwrap(); + let keypair = Keypair::from_phrase(&mnemonic, None).unwrap(); + + let public_key_of_account = keypair.public_key().0; + + let password = "password-signature".to_owned(); + + let signature = keypair.sign(password.as_bytes()); + + // Make the signature public in blockchain, so that person can't enter another password + let signature_array = signature.0.to_vec(); + + AccountData { + account_addresses: account_addresses, + current_hash: current_hash, + index: index, + public_key_of_account: public_key_of_account, + signature: signature_array, + password: password, + } +} diff --git a/custom-pallets/zkp-anonymous_account/host/src/lib.rs b/custom-pallets/zkp-anonymous_account/host/src/lib.rs new file mode 100644 index 0000000..877aaa0 --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/host/src/lib.rs @@ -0,0 +1 @@ +pub mod accounts_hash; diff --git a/custom-pallets/zkp-anonymous_account/host/src/main.rs b/custom-pallets/zkp-anonymous_account/host/src/main.rs new file mode 100644 index 0000000..228282a --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/host/src/main.rs @@ -0,0 +1,56 @@ +// These constants represent the RISC-V ELF and the image ID generated by risc0-build. +// The ELF is used for proving and the ID is used for verification. +use host::accounts_hash::keypair_func; +use methods::{GUEST_ANONYMOUS_ACCOUNT_ELF, GUEST_ANONYMOUS_ACCOUNT_ID}; +use risc0_zkvm::{default_prover, ExecutorEnv}; + +fn main() { + // Initialize tracing. In order to view logs, run `RUST_LOG=info cargo run` + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::filter::EnvFilter::from_default_env()) + .init(); + + // An executor environment describes the configurations for the zkVM + // including program inputs. + // An default ExecutorEnv can be created like so: + // `let env = ExecutorEnv::builder().build().unwrap();` + // However, this `env` does not have any inputs. + // + // To add guest input to the executor environment, use + // ExecutorEnvBuilder::write(). + // To access this method, you'll need to use ExecutorEnv::builder(), which + // creates an ExecutorEnvBuilder. When you're done adding input, call + // ExecutorEnvBuilder::build(). + + // For example: + let account_data = keypair_func(); + + let env = ExecutorEnv::builder() + .write(&account_data) + .unwrap() + .build() + .unwrap(); + + // Obtain the default prover. + let prover = default_prover(); + + // Proof information by proving the specified ELF binary. + // This struct contains the receipt along with statistics about execution of the guest + let prove_info = prover.prove(env, GUEST_ANONYMOUS_ACCOUNT_ELF).unwrap(); + + // extract the receipt. + let receipt = prove_info.receipt; + + // TODO: Implement code for retrieving receipt journal here. + + // For example: + let (output, password_hash): ([u8; 32], [u8; 32]) = receipt.journal.decode().unwrap(); + + println!("output: {:?}", output); + + println!("password hash: {:?}", password_hash); + + // The receipt was verified at the end of proving, but the below code is an + // example of how someone else could verify this receipt. + receipt.verify(GUEST_ANONYMOUS_ACCOUNT_ID).unwrap(); +} diff --git a/custom-pallets/zkp-anonymous_account/methods/Cargo.toml b/custom-pallets/zkp-anonymous_account/methods/Cargo.toml new file mode 100644 index 0000000..0e06e71 --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/methods/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "methods" +version = "0.1.0" +edition = "2021" + +[build-dependencies] +risc0-build = { version = "1.1.2" } + +[package.metadata.risc0] +methods = ["guest"] diff --git a/custom-pallets/zkp-anonymous_account/methods/build.rs b/custom-pallets/zkp-anonymous_account/methods/build.rs new file mode 100644 index 0000000..08a8a4e --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/methods/build.rs @@ -0,0 +1,3 @@ +fn main() { + risc0_build::embed_methods(); +} diff --git a/custom-pallets/zkp-anonymous_account/methods/guest/Cargo.toml b/custom-pallets/zkp-anonymous_account/methods/guest/Cargo.toml new file mode 100644 index 0000000..63f8cbf --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/methods/guest/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "guest_anonymous_account" +version = "0.1.0" +edition = "2021" + +[workspace] + +[dependencies] +risc0-zkvm = { version = "1.1.2", default-features = false, features = ['std'] } +subxt-signer = "0.37.0" +sp-io = "38.0.0" +sp-core = "34.0.0" +subxt-core = "0.37.0" +serde = "1.0" diff --git a/custom-pallets/zkp-anonymous_account/methods/guest/src/accounts_hash.rs b/custom-pallets/zkp-anonymous_account/methods/guest/src/accounts_hash.rs new file mode 100644 index 0000000..39c735f --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/methods/guest/src/accounts_hash.rs @@ -0,0 +1,34 @@ +use serde::{Deserialize, Serialize}; +use sp_io::hashing::blake2_256; +use subxt_core::utils::AccountId32; + +#[derive(Serialize, Deserialize)] +pub struct AccountData { + pub account_addresses: Vec, + pub current_hash: [u8; 32], + pub index: usize, + pub public_key_of_account: [u8; 32], + pub signature: Vec, // Use Vec instead of [u8; 64] + pub password: String, +} + +pub fn update_hash_incrementally(current_hash: [u8; 32], account_id: &AccountId32) -> [u8; 32] { + let mut input_data = Vec::new(); + + // Extend input data with the current hash and the new account ID + input_data.extend_from_slice(¤t_hash); + input_data.extend_from_slice(account_id.as_ref()); + + // Recalculate the hash with the new account ID + blake2_256(&input_data) +} + +pub fn password_hash_fn(index: usize, password: String) -> [u8; 32] { + // Convert the index to bytes (using 8 bytes to represent usize) + let mut index_bytes = index.to_le_bytes().to_vec(); + + // Convert the password string to bytes and append to index bytes + index_bytes.extend(password.as_bytes()); + // Hash the combined data using blake2_256 + blake2_256(&index_bytes) +} diff --git a/custom-pallets/zkp-anonymous_account/methods/guest/src/lib.rs b/custom-pallets/zkp-anonymous_account/methods/guest/src/lib.rs new file mode 100644 index 0000000..877aaa0 --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/methods/guest/src/lib.rs @@ -0,0 +1 @@ +pub mod accounts_hash; diff --git a/custom-pallets/zkp-anonymous_account/methods/guest/src/main.rs b/custom-pallets/zkp-anonymous_account/methods/guest/src/main.rs new file mode 100644 index 0000000..4de52e1 --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/methods/guest/src/main.rs @@ -0,0 +1,53 @@ +use guest_anonymous_account::accounts_hash::{ + password_hash_fn, update_hash_incrementally, AccountData, +}; +use risc0_zkvm::guest::env; +use subxt_signer::sr25519; +use subxt_signer::sr25519::{PublicKey, Signature}; + +fn main() { + let account_data: AccountData = env::read(); + + let account_addresses = account_data.account_addresses.clone(); + + let mut current_hash: [u8; 32] = [0; 32]; + for account_address in &account_addresses { + current_hash = update_hash_incrementally(current_hash, &account_address); + } + + assert_eq!(current_hash, account_data.current_hash); + // assert_ne!(current_hash, hash); + + let public_key_of_account = PublicKey(account_data.public_key_of_account); + + let public_key_of_account2 = PublicKey(account_data.public_key_of_account); + + // Ensure the Vec has exactly 64 bytes and convert it to [u8; 64] + let signature_array: [u8; 64] = account_data + .signature + .try_into() + .expect("Invalid length: Vec must be 64 bytes to convert to Signature"); + + // Create a Signature from the [u8; 64] array + let signature_of_account = Signature(signature_array); + + let your_account_id = public_key_of_account.to_account_id(); + + // // let mnemonic = Mnemonic::parse(&phrase_of_index).unwrap(); + // // let keypair = Keypair::from_phrase(&mnemonic, None).unwrap(); + // // let account_address_of_your_account = keypair.public_key().to_account_id(); + + assert_eq!(account_addresses[account_data.index], your_account_id); + let password = account_data.password.as_bytes(); + let password_string = account_data.password.clone(); + assert!(sr25519::verify( + &signature_of_account, + password, + &public_key_of_account2 + )); + + let password_hash = password_hash_fn(account_data.index, password_string); + + // write public output to the journal + env::commit(&(current_hash, password_hash)); +} diff --git a/custom-pallets/zkp-anonymous_account/methods/src/lib.rs b/custom-pallets/zkp-anonymous_account/methods/src/lib.rs new file mode 100644 index 0000000..1bdb308 --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/methods/src/lib.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/methods.rs")); diff --git a/custom-pallets/zkp-anonymous_account/rust-toolchain.toml b/custom-pallets/zkp-anonymous_account/rust-toolchain.toml new file mode 100644 index 0000000..36614c3 --- /dev/null +++ b/custom-pallets/zkp-anonymous_account/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "stable" +components = ["rustfmt", "rust-src"] +profile = "minimal"