Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/aws_tfhe_wasm_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,20 @@ jobs:
run: |
make test_nodejs_wasm_api_ci

- name: Run wasm_par_mq tests
run: |
make test_wasm_par_mq_chrome_ci
make test_wasm_par_mq_firefox_ci

- name: Run parallel wasm tests
run: |
make test_web_js_api_parallel_chrome_ci
make test_web_js_api_parallel_firefox_ci

- name: Run wasm_par_mq tests
- name: Run cross origin wasm tests
run: |
make test_wasm_par_mq_chrome_ci
make test_wasm_par_mq_firefox_ci
make test_web_js_api_cross_origin_chrome_ci
make test_web_js_api_cross_origin_firefox_ci

- name: Run x86_64/wasm zk compatibility tests
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/benchmark_wasm_client_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ jobs:
env:
BROWSER: ${{ matrix.browser }}

- name: Run benchmarks (unsafe coop)
- name: Run benchmarks (cross origin)
run: |
make bench_web_js_api_unsafe_coop_"${BROWSER}"_ci
make bench_web_js_api_cross_origin_"${BROWSER}"_ci
env:
BROWSER: ${{ matrix.browser }}

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ rand = "0.8"
rayon = "1.11"
serde = { version = "1.0", default-features = false }
wasm-bindgen = { version = "0.2.114" }
wasm-bindgen-futures = { version = "0.4.56" }
# js-sys (at this point in time) automatically enables the unsafe-eval feature which we do not want
# this does not prevent other deps from enabling it, but it at least conveys our need to not have it
# we still enable std, which was part of default before
Expand Down
108 changes: 85 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ install_build_wasm32_target:
( echo "Unable to install wasm32-unknown-unknown target toolchain, check your rustup installation. \
Rustup can be downloaded at https://rustup.rs/" && exit 1 )

.PHONY: install_check_wasm32_target # Install the wasm32 toolchain used for checks
install_check_wasm32_target:
rustup target add wasm32-unknown-unknown --toolchain "$(RS_CHECK_TOOLCHAIN)" || \
( echo "Unable to install wasm32-unknown-unknown target toolchain, check your rustup installation. \
Rustup can be downloaded at https://rustup.rs/" && exit 1 )

.PHONY: install_cargo_nextest # Install cargo nextest used for shortint tests
install_cargo_nextest:
@cargo nextest --version > /dev/null 2>&1 || \
Expand Down Expand Up @@ -530,6 +536,12 @@ clippy_zk_pok: install_rs_check_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
-p tfhe-zk-pok --features=experimental -- --no-deps -D warnings

.PHONY: clippy_zk_pok_wasm # Run clippy lints on tfhe-zk-pok for wasm32 target
clippy_zk_pok_wasm: install_rs_check_toolchain install_check_wasm32_target
RUSTFLAGS="$(WASM_RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
--target wasm32-unknown-unknown \
-p tfhe-zk-pok -- --no-deps -D warnings

.PHONY: clippy_versionable # Run clippy lints on tfhe-versionable
clippy_versionable: install_rs_check_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
Expand Down Expand Up @@ -573,9 +585,11 @@ clippy_test_vectors: install_rs_check_toolchain
cd apps/test-vectors; RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
-p tfhe-test-vectors -- --no-deps -D warnings

# WARNING: This target is not directly run in CI. When adding a subtarget here,
# MAKE SURE TO ALSO ADD IT TO A PCC BATCH BELOW
.PHONY: clippy_all # Run all clippy targets
clippy_all: clippy_rustdoc clippy clippy_boolean clippy_shortint clippy_integer clippy_all_targets \
clippy_c_api clippy_js_wasm_api clippy_tasks clippy_core clippy_tfhe_csprng clippy_zk_pok clippy_trivium \
clippy_c_api clippy_js_wasm_api clippy_tasks clippy_core clippy_tfhe_csprng clippy_zk_pok clippy_zk_pok_wasm clippy_trivium \
clippy_versionable clippy_tfhe_lints clippy_ws_tests clippy_bench clippy_param_dedup \
clippy_test_vectors clippy_backward_compat_data clippy_wasm_par_mq

Expand Down Expand Up @@ -691,11 +705,14 @@ build_c_api_experimental_deterministic_fft: install_rs_check_toolchain
--features=boolean-c-api,shortint-c-api,high-level-c-api,zk-pok,experimental-force_fft_algo_dif4 \
-p tfhe

.PHONY: build_web_js_api # Build the js API targeting the web browser
.PHONY: build_web_js_api # Build the js API targeting the web browser, in sequential or cross origin parallelism modes.
build_web_js_api: install_wasm_pack
cd tfhe && \
RUSTFLAGS="$(WASM_RUSTFLAGS)" wasm-pack build --release --target=web \
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok,extended-types
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok,extended-types && \
find pkg/snippets -type f -iname worker_helpers.js -exec sed -i 's|import("../../..")|import("../../../tfhe.js")|g' {} \;
cp utils/wasm-par-mq/js/coordinator.js tfhe/pkg/
jq '.files += ["snippets"]' tfhe/pkg/package.json > tmp_pkg.json && mv -f tmp_pkg.json tfhe/pkg/package.json

.PHONY: build_web_js_api_parallel # Build the js API targeting the web browser with parallelism support
# parallel wasm requires specific build options, see https://github.com/rust-lang/rust/pull/147225
Expand Down Expand Up @@ -1383,6 +1400,18 @@ run_web_js_api_parallel: build_web_js_api_parallel setup_venv
--server-workdir "$(WEB_SERVER_DIR)" \
--id-pattern $(filter)

# This is an internal target, not meant to be called on its own.
run_web_js_api_cross_origin: build_web_js_api setup_venv
cd $(WEB_SERVER_DIR) && npm install && npm run build
source venv/bin/activate && \
python ci/webdriver.py \
--browser-path $(browser_path) \
--driver-path $(driver_path) \
--browser-kind $(browser_kind) \
--server-cmd $(server_cmd) \
--server-workdir "$(WEB_SERVER_DIR)" \
--id-pattern $(filter)

test_web_js_api_parallel_chrome: browser_path = "$(WEB_RUNNER_DIR)/chrome/chrome-linux64/chrome"
test_web_js_api_parallel_chrome: driver_path = "$(WEB_RUNNER_DIR)/chrome/chromedriver-linux64/chromedriver"
test_web_js_api_parallel_chrome: browser_kind = chrome
Expand Down Expand Up @@ -1415,6 +1444,38 @@ test_web_js_api_parallel_firefox_ci: setup_venv
nvm use $(NODE_VERSION) && \
$(MAKE) test_web_js_api_parallel_firefox

test_web_js_api_cross_origin_chrome: browser_path = "$(WEB_RUNNER_DIR)/chrome/chrome-linux64/chrome"
test_web_js_api_cross_origin_chrome: driver_path = "$(WEB_RUNNER_DIR)/chrome/chromedriver-linux64/chromedriver"
test_web_js_api_cross_origin_chrome: browser_kind = chrome
test_web_js_api_cross_origin_chrome: server_cmd = "npm run server:cross-origin"
test_web_js_api_cross_origin_chrome: filter = ZeroKnowledgeTest # Only run zk proof tests in cross-origin mode

.PHONY: test_web_js_api_cross_origin_chrome # Run tests for the web wasm api in cross-origin mode on Chrome
test_web_js_api_cross_origin_chrome: run_web_js_api_cross_origin

.PHONY: test_web_js_api_cross_origin_chrome_ci # Run tests for the web wasm api in cross-origin mode on Chrome
test_web_js_api_cross_origin_chrome_ci: setup_venv
source ~/.nvm/nvm.sh && \
nvm install $(NODE_VERSION) && \
nvm use $(NODE_VERSION) && \
$(MAKE) test_web_js_api_cross_origin_chrome

test_web_js_api_cross_origin_firefox: browser_path = "$(WEB_RUNNER_DIR)/firefox/firefox/firefox"
test_web_js_api_cross_origin_firefox: driver_path = "$(WEB_RUNNER_DIR)/firefox/geckodriver"
test_web_js_api_cross_origin_firefox: browser_kind = firefox
test_web_js_api_cross_origin_firefox: server_cmd = "npm run server:cross-origin"
test_web_js_api_cross_origin_firefox: filter = ZeroKnowledgeTest # Only run zk proof tests in cross-origin mode

.PHONY: test_web_js_api_cross_origin_firefox # Run tests for the web wasm api in cross-origin mode on Firefox
test_web_js_api_cross_origin_firefox: run_web_js_api_cross_origin

.PHONY: test_web_js_api_cross_origin_firefox_ci # Run tests for the web wasm api in cross-origin mode on Firefox
test_web_js_api_cross_origin_firefox_ci: setup_venv
source ~/.nvm/nvm.sh && \
nvm install $(NODE_VERSION) && \
nvm use $(NODE_VERSION) && \
$(MAKE) test_web_js_api_cross_origin_firefox

WASM_PAR_MQ_TEST_DIR=utils/wasm-par-mq/web_tests

.PHONY: build_wasm_par_mq_tests # Build the wasm-par-mq test WASM package
Expand Down Expand Up @@ -1755,37 +1816,37 @@ bench_web_js_api_parallel_firefox_ci: setup_venv
nvm use $(NODE_VERSION) && \
$(MAKE) bench_web_js_api_parallel_firefox

bench_web_js_api_unsafe_coop_chrome: browser_path = "$(WEB_RUNNER_DIR)/chrome/chrome-linux64/chrome"
bench_web_js_api_unsafe_coop_chrome: driver_path = "$(WEB_RUNNER_DIR)/chrome/chromedriver-linux64/chromedriver"
bench_web_js_api_unsafe_coop_chrome: browser_kind = chrome
bench_web_js_api_unsafe_coop_chrome: server_cmd = "npm run server:unsafe-coop"
bench_web_js_api_unsafe_coop_chrome: filter = ZeroKnowledgeBench # Only bench zk with unsafe coop
bench_web_js_api_cross_origin_chrome: browser_path = "$(WEB_RUNNER_DIR)/chrome/chrome-linux64/chrome"
bench_web_js_api_cross_origin_chrome: driver_path = "$(WEB_RUNNER_DIR)/chrome/chromedriver-linux64/chromedriver"
bench_web_js_api_cross_origin_chrome: browser_kind = chrome
bench_web_js_api_cross_origin_chrome: server_cmd = "npm run server:cross-origin"
bench_web_js_api_cross_origin_chrome: filter = ZeroKnowledgeBench # Only bench zk with cross-origin workers

.PHONY: bench_web_js_api_unsafe_coop_chrome # Run benchmarks for the web wasm api without cross-origin isolation
bench_web_js_api_unsafe_coop_chrome: run_web_js_api_parallel
.PHONY: bench_web_js_api_cross_origin_chrome # Run benchmarks for the web wasm api without cross-origin isolation
bench_web_js_api_cross_origin_chrome: run_web_js_api_cross_origin

.PHONY: bench_web_js_api_unsafe_coop_chrome_ci # Run benchmarks for the web wasm api without cross-origin isolation
bench_web_js_api_unsafe_coop_chrome_ci: setup_venv
.PHONY: bench_web_js_api_cross_origin_chrome_ci # Run benchmarks for the web wasm api without cross-origin isolation
bench_web_js_api_cross_origin_chrome_ci: setup_venv
source ~/.nvm/nvm.sh && \
nvm install $(NODE_VERSION) && \
nvm use $(NODE_VERSION) && \
$(MAKE) bench_web_js_api_unsafe_coop_chrome
$(MAKE) bench_web_js_api_cross_origin_chrome

bench_web_js_api_unsafe_coop_firefox: browser_path = "$(WEB_RUNNER_DIR)/firefox/firefox/firefox"
bench_web_js_api_unsafe_coop_firefox: driver_path = "$(WEB_RUNNER_DIR)/firefox/geckodriver"
bench_web_js_api_unsafe_coop_firefox: browser_kind = firefox
bench_web_js_api_unsafe_coop_firefox: server_cmd = "npm run server:unsafe-coop"
bench_web_js_api_unsafe_coop_firefox: filter = ZeroKnowledgeBench # Only bench zk with unsafe coop
bench_web_js_api_cross_origin_firefox: browser_path = "$(WEB_RUNNER_DIR)/firefox/firefox/firefox"
bench_web_js_api_cross_origin_firefox: driver_path = "$(WEB_RUNNER_DIR)/firefox/geckodriver"
bench_web_js_api_cross_origin_firefox: browser_kind = firefox
bench_web_js_api_cross_origin_firefox: server_cmd = "npm run server:cross-origin"
bench_web_js_api_cross_origin_firefox: filter = ZeroKnowledgeBench # Only bench zk with cross-origin workers

.PHONY: bench_web_js_api_unsafe_coop_firefox # Run benchmarks for the web wasm api without cross-origin isolation
bench_web_js_api_unsafe_coop_firefox: run_web_js_api_parallel
.PHONY: bench_web_js_api_cross_origin_firefox # Run benchmarks for the web wasm api without cross-origin isolation
bench_web_js_api_cross_origin_firefox: run_web_js_api_cross_origin

.PHONY: bench_web_js_api_unsafe_coop_firefox_ci # Run benchmarks for the web wasm api without cross-origin isolation
bench_web_js_api_unsafe_coop_firefox_ci: setup_venv
.PHONY: bench_web_js_api_cross_origin_firefox_ci # Run benchmarks for the web wasm api without cross-origin isolation
bench_web_js_api_cross_origin_firefox_ci: setup_venv
source ~/.nvm/nvm.sh && \
nvm install $(NODE_VERSION) && \
nvm use $(NODE_VERSION) && \
$(MAKE) bench_web_js_api_unsafe_coop_firefox
$(MAKE) bench_web_js_api_cross_origin_firefox

.PHONY: bench_hlapi_unsigned # Run benchmarks for integer operations
bench_hlapi_unsigned: install_rs_check_toolchain
Expand Down Expand Up @@ -2146,6 +2207,7 @@ pcc_batch_6:
$(call run_recipe_with_details,clippy_tasks)
$(call run_recipe_with_details,clippy_tfhe_csprng)
$(call run_recipe_with_details,clippy_zk_pok)
$(call run_recipe_with_details,clippy_zk_pok_wasm)
$(call run_recipe_with_details,clippy_trivium)
$(call run_recipe_with_details,clippy_versionable)
$(call run_recipe_with_details,clippy_param_dedup)
Expand Down
5 changes: 4 additions & 1 deletion ci/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,14 @@ def __init__(self, browser_path, driver_path, browser_kind, threaded_logs=False)
"Script is running as root, running browser with --no-sandbox for compatibility"
)
self.options.add_argument("--no-sandbox")
self.options.add_argument("--headless=new")
# Needed for wasm-par-mq sync executor mode
self.options.add_argument("--enable-features=ServiceWorker")
case BrowserKind.firefox:
self.options = FirefoxOptions()
self.options.add_argument("-headless")

self.options.binary_location = self.browser_path
self.options.add_argument("--headless")

self._driver = None

Expand Down
3 changes: 3 additions & 0 deletions tfhe-zk-pok/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ serde = { workspace = true, features = ["default", "derive"] }
zeroize = "1.7.0"
num-bigint = "0.4.5"
tfhe-versionable = { version = "0.7.0", path = "../utils/tfhe-versionable" }
[target.'cfg(target_family = "wasm")'.dependencies]
getrandom = { workspace = true, features = ["js"] }
wasm-par-mq = { version = "0.1.0", path = "../utils/wasm-par-mq", features = ["sync-api"] }

[features]
experimental = []
Expand Down
12 changes: 11 additions & 1 deletion tfhe-zk-pok/src/backward_compatibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tfhe_versionable::{Upgrade, Version, VersionsDispatch};

use crate::curve_api::Curve;
use crate::proofs::pke_v2::Bound;
use crate::proofs::GroupElements;
use crate::proofs::{ComputeLoad, GroupElements};
use crate::serialization::*;

#[derive(VersionsDispatch)]
Expand Down Expand Up @@ -302,3 +302,13 @@ pub enum SerializablePKEv1DomainSeparatorsVersions {
pub enum BoundVersions {
V0(Bound),
}

#[derive(VersionsDispatch)]
pub enum SerializableProjectiveVersions<F> {
V0(SerializableProjective<F>),
}

#[derive(VersionsDispatch)]
pub enum ComputeLoadVersions {
V0(ComputeLoad),
}
20 changes: 16 additions & 4 deletions tfhe-zk-pok/src/curve_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,16 @@ impl CurveGroupOps<bls12_446::Zp> for bls12_446::G1 {

#[track_caller]
fn multi_mul_scalar(bases: &[Self::Affine], scalars: &[bls12_446::Zp]) -> Self {
// overhead seems to not be worth it outside of wasm
if cfg!(target_family = "wasm") {
// wnaf overhead seems to not be worth it outside of wasm
#[cfg(target_family = "wasm")]
{
if wasm_par_mq::is_pool_initialized() {
return msm::cross_origin::msm_wnaf_g1_446_cross_origin(bases, scalars);
}
msm::msm_wnaf_g1_446(bases, scalars)
} else {
Self::Affine::multi_mul_scalar(bases, scalars)
}
#[cfg(not(target_family = "wasm"))]
Self::Affine::multi_mul_scalar(bases, scalars)
}

fn to_le_bytes(self) -> impl AsRef<[u8]> {
Expand Down Expand Up @@ -409,6 +413,14 @@ impl CurveGroupOps<bls12_446::Zp> for bls12_446::G2 {

#[track_caller]
fn multi_mul_scalar(bases: &[Self::Affine], scalars: &[bls12_446::Zp]) -> Self {
#[cfg(target_family = "wasm")]
{
if wasm_par_mq::is_pool_initialized() {
return msm::cross_origin::msm_wnaf_g2_446_cross_origin(bases, scalars);
}
msm::msm_wnaf_g2_446(bases, scalars)
}
#[cfg(not(target_family = "wasm"))]
Self::Affine::multi_mul_scalar(bases, scalars)
}

Expand Down
Loading
Loading