From b096457963c6785393b128beac4b9526768240a2 Mon Sep 17 00:00:00 2001 From: Nicolas Sarlin Date: Tue, 5 Nov 2024 18:05:58 +0100 Subject: [PATCH] fix(zk): fix zk wasm x86_64 tests --- tfhe/js_on_wasm_tests/package.json | 2 +- tfhe/src/high_level_api/compact_list.rs | 2 +- tfhe/tests/zk_wasm_x86_test.rs | 15 +++++++++++++-- tfhe/tests/zk_wasm_x86_test/index.js | 6 ++++-- tfhe/tests/zk_wasm_x86_test/package.json | 2 +- tfhe/web_wasm_parallel_tests/package.json | 2 +- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tfhe/js_on_wasm_tests/package.json b/tfhe/js_on_wasm_tests/package.json index 0532bcd56f..350cb87754 100644 --- a/tfhe/js_on_wasm_tests/package.json +++ b/tfhe/js_on_wasm_tests/package.json @@ -7,5 +7,5 @@ "test": "node --test --test-reporter=tap" }, "author": "", - "license": "BSD-3-Clause" + "license": "BSD-3-Clause-Clear" } diff --git a/tfhe/src/high_level_api/compact_list.rs b/tfhe/src/high_level_api/compact_list.rs index 708dc554da..5aded5d62f 100644 --- a/tfhe/src/high_level_api/compact_list.rs +++ b/tfhe/src/high_level_api/compact_list.rs @@ -742,7 +742,7 @@ mod tests { set_server_key(sks); - // Intentionally low to that we test when multiple lists and proofs are needed + // Intentionally low so that we test when multiple lists and proofs are needed let crs = CompactPkeCrs::from_config(config, 32).unwrap(); let metadata = [b'h', b'l', b'a', b'p', b'i']; diff --git a/tfhe/tests/zk_wasm_x86_test.rs b/tfhe/tests/zk_wasm_x86_test.rs index d82f3f218a..9b1a601192 100644 --- a/tfhe/tests/zk_wasm_x86_test.rs +++ b/tfhe/tests/zk_wasm_x86_test.rs @@ -11,14 +11,25 @@ use std::fs::File; use std::path::{Path, PathBuf}; use std::process::Command; use tfhe::safe_serialization::{safe_deserialize, safe_serialize}; +use tfhe::shortint::parameters::compact_public_key_only::p_fail_2_minus_64::ks_pbs::PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64; +use tfhe::shortint::parameters::key_switching::p_fail_2_minus_64::ks_pbs::PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64; +use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64; use tfhe::zk::{CompactPkeCrs, CompactPkePublicParams}; use tfhe::{ClientKey, CompactPublicKey, ConfigBuilder, ProvenCompactCiphertextList}; const SIZE_LIMIT: u64 = 1024 * 1024 * 1024; +const METADATA: [u8; 6] = [b'w', b'a', b's', b'm', b'6', b'4']; fn gen_key_and_crs() -> (CompactPublicKey, CompactPkeCrs) { println!("Generating keys"); - let config = ConfigBuilder::default().build(); + let config = + crate::ConfigBuilder::with_custom_parameters(PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64) + .use_dedicated_compact_public_key_parameters(( + PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64, + PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64, + )) + .build(); + let client_key = ClientKey::generate(config); let pub_key = CompactPublicKey::new(&client_key); @@ -52,7 +63,7 @@ fn verify_proof( proven_ct: &ProvenCompactCiphertextList, ) { println!("Verifying proof"); - match proven_ct.verify(crs, public_key, &[]) { + match proven_ct.verify(crs, public_key, &METADATA) { tfhe::zk::ZkVerificationOutCome::Valid => { println!("proof verification succeeded"); } diff --git a/tfhe/tests/zk_wasm_x86_test/index.js b/tfhe/tests/zk_wasm_x86_test/index.js index ec9cb72af4..3f708002a4 100644 --- a/tfhe/tests/zk_wasm_x86_test/index.js +++ b/tfhe/tests/zk_wasm_x86_test/index.js @@ -8,6 +8,7 @@ const { const fs = require('fs'); const SIZE_LIMIT = BigInt(1024) * BigInt(1024) * BigInt(1024); +const METADATA = "wasm64"; const tfhe_proof = async () => { const publicKeyBuf = fs.readFileSync(`${__dirname}/public_key.bin`); @@ -17,12 +18,13 @@ const tfhe_proof = async () => { const builder = CompactCiphertextList.builder(publicKey); builder.push_u4(1); + builder.push_u8(0xff); - builder.push_u8(0xff); + const metadata = Uint8Array.from(METADATA.split('').map(letter => letter.charCodeAt(0))); const encrypted = builder.build_with_proof_packed( publicParams, - new Uint8Array(), + metadata, ZkComputeLoad.Proof, ); diff --git a/tfhe/tests/zk_wasm_x86_test/package.json b/tfhe/tests/zk_wasm_x86_test/package.json index 20923c18f5..b9f657a4f2 100644 --- a/tfhe/tests/zk_wasm_x86_test/package.json +++ b/tfhe/tests/zk_wasm_x86_test/package.json @@ -8,7 +8,7 @@ }, "type": "commonjs", "author": "", - "license": "BSD-3-Clause", + "license": "BSD-3-Clause-Clear", "dependencies": { "node-tfhe": "file:../../pkg" } diff --git a/tfhe/web_wasm_parallel_tests/package.json b/tfhe/web_wasm_parallel_tests/package.json index eaec66906b..37efbe931e 100644 --- a/tfhe/web_wasm_parallel_tests/package.json +++ b/tfhe/web_wasm_parallel_tests/package.json @@ -10,7 +10,7 @@ "check-format": "prettier . --check" }, "author": "", - "license": "BSD-3-Clause", + "license": "BSD-3-Clause-Clear", "devDependencies": { "@babel/preset-env": "^7.25.4", "prettier": "^3.3.3",