From eb7b08a3dfde81b13cf18c0b27336748ecea9314 Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Fri, 24 Nov 2023 09:33:38 +0300 Subject: [PATCH 1/2] fix: remove rsa tests --- .github/workflows/build-and-test.yml | 17 ++++++++++++----- ark-zkey/README.md | 4 ++-- ark-zkey/src/lib.rs | 3 +-- mopro-core/build.rs | 8 ++++---- mopro-core/src/middleware/circom/mod.rs | 2 ++ mopro-ffi/tests/test_generated_bindings.rs | 4 ++-- scripts/prepare_ci.sh | 21 +++++++++++++++++++-- 7 files changed, 42 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index b81b036f..084d830d 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -22,13 +22,20 @@ jobs: - name: Build run: ./scripts/build_ios.sh x86_64 debug - name: Run core tests - run: cd mopro-core/ && cargo test --verbose + run: cd mopro-core && cargo test -- --nocapture - name: Run ffi tests - run: cd mopro-ffi/ && cargo test --verbose - - name: Run bindings tests - run: cd mopro-ffi/ && cargo test --test test_generated_bindings + run: cd mopro-ffi/ && cargo test -- --nocapture - name: Run ios tests run: | cd mopro-ios/MoproKit/Example xcodebuild test -scheme MoproKit-Example -workspace MoproKit.xcworkspace -destination "platform=iOS Simulator,OS=16.2,name=iPhone 14 Pro" - + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Check mopro-core formatting + run: cd ark-zkey/ && cargo fmt --all -- --check + - name: Check mopro-core formatting + run: cd mopro-core/ && cargo fmt --all -- --check + - name: Check mopro-ffi formatting + run: cd mopro-ffi/ && cargo fmt --all -- --check diff --git a/ark-zkey/README.md b/ark-zkey/README.md index 067d8539..a5e2bf03 100644 --- a/ark-zkey/README.md +++ b/ark-zkey/README.md @@ -8,7 +8,7 @@ See https://github.com/oskarth/mopro/issues/25 for context. Hacky, but the way we generate `arkzkey` now is by running the corresponding test. -Note that we also neeed to change the const `ZKEY_BYTES` above. +Note that we also neeed to change the const `ZKEY_DATA` above. E.g.: @@ -18,7 +18,7 @@ cargo test keccak256 --release -- --nocapture cargo test rsa --release -- --nocapture ``` -Will take corresponding `zkey` and put `arkzkey`` in same folder. +Will take corresponding `zkey` and put `arkzkey` in same folder. ## Multiplier diff --git a/ark-zkey/src/lib.rs b/ark-zkey/src/lib.rs index cb554805..48dcc820 100644 --- a/ark-zkey/src/lib.rs +++ b/ark-zkey/src/lib.rs @@ -63,8 +63,7 @@ pub fn deserialize_proving_key(data: Vec) -> SerializableProvingKey { // TODO: Change this to multiplier2 or keccak as appropriate const ZKEY_DATA: &[u8] = include_bytes!( //"../../mopro-core/examples/circom/multiplier2/target/multiplier2_final.zkey" - //"../../mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.zkey" - "../../mopro-core/examples/circom/rsa/target/main_final.zkey" + "../../mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.zkey" // "../../mopro-core/examples/circom/rsa/target/main_final.zkey" ); pub fn read_proving_key_and_matrices( diff --git a/mopro-core/build.rs b/mopro-core/build.rs index 82c1bb5c..c1a9f090 100644 --- a/mopro-core/build.rs +++ b/mopro-core/build.rs @@ -79,12 +79,12 @@ fn build_dylib(wasm_path: String, dylib_name: String) -> Result<()> { fn main() -> Result<()> { // TODO: build_circuit function to builds all related artifacts, instead of doing this externally - // let dir = "examples/circom/keccak256"; - // let circuit = "keccak256_256_test"; + let dir = "examples/circom/keccak256"; + let circuit = "keccak256_256_test"; // XXX: Use RSA - let dir = "examples/circom/rsa"; - let circuit = "main"; + // let dir = "examples/circom/rsa"; + // let circuit = "main"; let zkey_path = format!("{}/target/{}_final.zkey", dir, circuit); let wasm_path = format!("{}/target/{}_js/{}.wasm", dir, circuit, circuit); diff --git a/mopro-core/src/middleware/circom/mod.rs b/mopro-core/src/middleware/circom/mod.rs index d66c4dda..443ca5c3 100644 --- a/mopro-core/src/middleware/circom/mod.rs +++ b/mopro-core/src/middleware/circom/mod.rs @@ -570,6 +570,7 @@ mod tests { assert!(verify_res.unwrap()); // Verifying that the proof was indeed verified } + #[ignore = "ignore for ci"] #[test] fn test_setup_prove_rsa() { let wasm_path = "./examples/circom/rsa/target/main_js/main.wasm"; @@ -720,6 +721,7 @@ mod tests { assert!(verify_res.unwrap()); // Verifying that the proof was indeed verified } + #[ignore = "ignore for ci"] #[test] fn test_setup_prove_rsa2() { // Prepare inputs diff --git a/mopro-ffi/tests/test_generated_bindings.rs b/mopro-ffi/tests/test_generated_bindings.rs index f94a85d9..1a770a7a 100644 --- a/mopro-ffi/tests/test_generated_bindings.rs +++ b/mopro-ffi/tests/test_generated_bindings.rs @@ -5,6 +5,6 @@ uniffi::build_foreign_language_testcases!( // "tests/bindings/test_mopro.py", "tests/bindings/test_mopro_keccak.swift", "tests/bindings/test_mopro_keccak2.swift", - "tests/bindings/test_mopro_rsa.swift", - "tests/bindings/test_mopro_rsa2.swift", + // "tests/bindings/test_mopro_rsa.swift", + // "tests/bindings/test_mopro_rsa2.swift", ); diff --git a/scripts/prepare_ci.sh b/scripts/prepare_ci.sh index 2b95b8d8..0cef4c81 100755 --- a/scripts/prepare_ci.sh +++ b/scripts/prepare_ci.sh @@ -79,9 +79,26 @@ download_files() { # Create directories if they don't exist mkdir -p "$target_dir" "$js_target_dir" + # Check if file exists # Download files to the specified directories - wget -P "$target_dir" "https://zkstuff.ams3.cdn.digitaloceanspaces.com/mopro/circom-examples-artifacts/${dir}/${circuit}_final.zkey" - wget -P "$js_target_dir" "https://zkstuff.ams3.cdn.digitaloceanspaces.com/mopro/circom-examples-artifacts/${dir}/${circuit}.wasm" + if ! [ -f "${target_dir}/${circuit}_final.arkzkey" ]; then + wget -P "$target_dir" "https://mopro.vivianjeng.xyz/${circuit}_final.arkzkey" + else + echo "File ${circuit}_final.arkzkey already exists, skipping download." + fi + + if ! [ -f "${target_dir}/${circuit}_final.zkey" ]; then + wget -P "$target_dir" "https://zkstuff.ams3.cdn.digitaloceanspaces.com/mopro/circom-examples-artifacts/${dir}/${circuit}_final.zkey" + else + echo "File ${circuit}_final.zkey already exists, skipping download." + fi + + if ! [ -f "${js_target_dir}/${circuit}.wasm" ]; then + wget -P "$js_target_dir" "https://zkstuff.ams3.cdn.digitaloceanspaces.com/mopro/circom-examples-artifacts/${dir}/${circuit}.wasm" + else + echo "File ${circuit}.wasm already exists, skipping download." + fi + } # TODO: Comment out compile_circuit stuff again once zkey is integrated and we don't need r1cs file anymore From 95ffedb7451beb9276b436a5884f4b347e45d251 Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Wed, 29 Nov 2023 18:01:48 +0300 Subject: [PATCH 2/2] chore: download rsa keys from server --- scripts/prepare_ci.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/prepare_ci.sh b/scripts/prepare_ci.sh index 0cef4c81..91ca5018 100755 --- a/scripts/prepare_ci.sh +++ b/scripts/prepare_ci.sh @@ -71,6 +71,7 @@ check_target_support() { } download_files() { + local url="https://mopro.vivianjeng.xyz" local dir=$1 local circuit=$2 local target_dir="${CIRCOM_DIR}/${dir}/target" @@ -82,19 +83,19 @@ download_files() { # Check if file exists # Download files to the specified directories if ! [ -f "${target_dir}/${circuit}_final.arkzkey" ]; then - wget -P "$target_dir" "https://mopro.vivianjeng.xyz/${circuit}_final.arkzkey" + wget -P "$target_dir" "${url}/${circuit}_final.arkzkey" else echo "File ${circuit}_final.arkzkey already exists, skipping download." fi if ! [ -f "${target_dir}/${circuit}_final.zkey" ]; then - wget -P "$target_dir" "https://zkstuff.ams3.cdn.digitaloceanspaces.com/mopro/circom-examples-artifacts/${dir}/${circuit}_final.zkey" + wget -P "$target_dir" "${url}/${circuit}_final.zkey" else echo "File ${circuit}_final.zkey already exists, skipping download." fi if ! [ -f "${js_target_dir}/${circuit}.wasm" ]; then - wget -P "$js_target_dir" "https://zkstuff.ams3.cdn.digitaloceanspaces.com/mopro/circom-examples-artifacts/${dir}/${circuit}.wasm" + wget -P "$js_target_dir" "${url}/${circuit}.wasm" else echo "File ${circuit}.wasm already exists, skipping download." fi @@ -119,6 +120,10 @@ compile_circuit multiplier2 multiplier2.circom npm_install keccak256 compile_circuit keccak256 keccak256_256_test.circom +# Setup and compile rsa +npm_install rsa +compile_circuit rsa main.circom + # # Run trusted setup for multiplier2 # print_action "[core/circom] Running trusted setup for multiplier2..." # ./scripts/trusted_setup.sh multiplier2 08 multiplier2 @@ -133,6 +138,9 @@ download_files "multiplier2" "multiplier2" print_action "[core/circom] Downloading artifacts for keccak256..." download_files "keccak256" "keccak256_256_test" +print_action "[core/circom] Downloading artifacts for rsa..." +download_files "rsa" "main" + # Add support for target architectures print_action "[ffi] Adding support for target architectures..." cd ${PROJECT_DIR}/mopro-ffi