mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-04-28 03:01:21 -04:00
Compare commits
1 Commits
tm/update-
...
am/chore/z
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62a05d7bf7 |
213
.github/workflows/aws_tfhe_param_prod_tests.yml
vendored
213
.github/workflows/aws_tfhe_param_prod_tests.yml
vendored
@@ -1,213 +0,0 @@
|
||||
# Run a small subset of tests to ensure quick feedback.
|
||||
name: aws_tfhe_param_prod_tests
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
RUSTFLAGS: "-C target-cpu=native"
|
||||
RUST_BACKTRACE: "full"
|
||||
RUST_MIN_STACK: "8388608"
|
||||
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
|
||||
SLACK_ICON: https://pbs.twimg.com/profile_images/1274014582265298945/OjBKP9kn_400x400.png
|
||||
SLACK_USERNAME: ${{ secrets.BOT_USERNAME }}
|
||||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
||||
SLACKIFY_MARKDOWN: true
|
||||
IS_PULL_REQUEST: ${{ github.event_name == 'pull_request' }}
|
||||
PULL_REQUEST_MD_LINK: ""
|
||||
CHECKOUT_TOKEN: ${{ secrets.REPO_CHECKOUT_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
# Secrets will be available only to zama-ai organization members
|
||||
SECRETS_AVAILABLE: ${{ secrets.JOB_SECRET != '' }}
|
||||
EXTERNAL_CONTRIBUTION_RUNNER: "large_ubuntu_64-22.04"
|
||||
|
||||
on:
|
||||
# Allows you to run this workflow manually from the Actions tab as an alternative.
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
types: [ labeled ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# zizmor: ignore[concurrency-limits] concurrency is managed after instance setup to ensure safe provisioning
|
||||
|
||||
jobs:
|
||||
should-run:
|
||||
name: aws_tfhe_param_prod_tests/should-run
|
||||
if: (github.event_name == 'pull_request' && contains(github.event.label.name, 'approved')) || github.event_name == 'workflow_dispatch'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: read # Needed to check for file change
|
||||
outputs:
|
||||
csprng_test: ${{ env.IS_PULL_REQUEST == 'false' || steps.changed-files.outputs.csprng_any_changed }}
|
||||
zk_pok_test: ${{ env.IS_PULL_REQUEST == 'false' || steps.changed-files.outputs.zk_pok_any_changed }}
|
||||
versionable_test: ${{ env.IS_PULL_REQUEST == 'false' || steps.changed-files.outputs.versionable_any_changed }}
|
||||
shortint_test: ${{ env.IS_PULL_REQUEST == 'false' ||
|
||||
steps.changed-files.outputs.shortint_any_changed ||
|
||||
steps.changed-files.outputs.dependencies_any_changed }}
|
||||
integer_test: ${{ env.IS_PULL_REQUEST == 'false' ||
|
||||
steps.changed-files.outputs.integer_any_changed ||
|
||||
steps.changed-files.outputs.dependencies_any_changed }}
|
||||
high_level_api_test: ${{ env.IS_PULL_REQUEST == 'false' ||
|
||||
steps.changed-files.outputs.high_level_api_any_changed ||
|
||||
steps.changed-files.outputs.dependencies_any_changed }}
|
||||
any_file_changed: ${{ env.IS_PULL_REQUEST == 'false' || steps.aggregated-changes.outputs.any_changed }}
|
||||
steps:
|
||||
- name: Checkout tfhe-rs
|
||||
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: 'false'
|
||||
token: ${{ env.CHECKOUT_TOKEN }}
|
||||
|
||||
- name: Check for file changes
|
||||
id: changed-files
|
||||
uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47.0.0
|
||||
with:
|
||||
files_yaml: |
|
||||
dependencies:
|
||||
- tfhe/Cargo.toml
|
||||
- tfhe-csprng/**
|
||||
- tfhe-fft/**
|
||||
- tfhe-zk-pok/**
|
||||
- utils/tfhe-versionable/**
|
||||
- utils/tfhe-versionable-derive/**
|
||||
versionable:
|
||||
- utils/tfhe-versionable/**
|
||||
- utils/tfhe-versionable-derive/**
|
||||
shortint:
|
||||
- tfhe/src/core_crypto/**
|
||||
- tfhe/src/shortint/**
|
||||
integer:
|
||||
- tfhe/src/core_crypto/**
|
||||
- tfhe/src/shortint/**
|
||||
- tfhe/src/integer/**
|
||||
high_level_api:
|
||||
- tfhe/src/**
|
||||
- '!tfhe/src/c_api/**'
|
||||
- '!tfhe/src/boolean/**'
|
||||
- '!tfhe/src/c_api/**'
|
||||
- '!tfhe/src/js_on_wasm_api/**'
|
||||
|
||||
- name: Aggregate file changes
|
||||
id: aggregated-changes
|
||||
if: ( steps.changed-files.outputs.dependencies_any_changed == 'true' ||
|
||||
steps.changed-files.outputs.csprng_any_changed == 'true' ||
|
||||
steps.changed-files.outputs.zk_pok_any_changed == 'true' ||
|
||||
steps.changed-files.outputs.versionable_any_changed == 'true' ||
|
||||
steps.changed-files.outputs.core_crypto_any_changed == 'true' ||
|
||||
steps.changed-files.outputs.boolean_any_changed == 'true' ||
|
||||
steps.changed-files.outputs.shortint_any_changed == 'true' ||
|
||||
steps.changed-files.outputs.integer_any_changed == 'true' ||
|
||||
steps.changed-files.outputs.wasm_any_changed == 'true' ||
|
||||
steps.changed-files.outputs.high_level_api_any_changed == 'true' ||
|
||||
steps.changed-files.outputs.user_docs_any_changed == 'true')
|
||||
run: |
|
||||
echo "any_changed=true" >> "$GITHUB_OUTPUT"
|
||||
|
||||
setup-instance:
|
||||
name: aws_tfhe_param_prod_tests/setup-instance
|
||||
if: github.event_name == 'workflow_dispatch' ||
|
||||
(github.event_name != 'workflow_dispatch' && needs.should-run.outputs.any_file_changed == 'true')
|
||||
needs: should-run
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
runner-name: ${{ steps.start-remote-instance.outputs.label || steps.start-github-instance.outputs.runner_group }}
|
||||
steps:
|
||||
- name: Start remote instance
|
||||
id: start-remote-instance
|
||||
if: env.SECRETS_AVAILABLE == 'true'
|
||||
uses: zama-ai/slab-github-runner@973c1d22702de8d0acd2b34e83404c96ed92c264 # v1.4.2
|
||||
with:
|
||||
mode: start
|
||||
github-token: ${{ secrets.SLAB_ACTION_TOKEN }}
|
||||
slab-url: ${{ secrets.SLAB_BASE_URL }}
|
||||
job-secret: ${{ secrets.JOB_SECRET }}
|
||||
backend: aws
|
||||
profile: cpu-big
|
||||
|
||||
# This instance will be spawned especially for pull-request from forked repository
|
||||
- name: Start GitHub instance
|
||||
id: start-github-instance
|
||||
if: env.SECRETS_AVAILABLE == 'false'
|
||||
run: |
|
||||
echo "runner_group=${EXTERNAL_CONTRIBUTION_RUNNER}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
param-prod-tests:
|
||||
name: aws_tfhe_param_prod_tests/param-prod-tests
|
||||
needs: [ should-run, setup-instance ]
|
||||
concurrency:
|
||||
group: ${{ github.workflow_ref }}
|
||||
cancel-in-progress: true
|
||||
runs-on: ${{ needs.setup-instance.outputs.runner-name }}
|
||||
steps:
|
||||
- name: Checkout tfhe-rs
|
||||
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3
|
||||
with:
|
||||
persist-credentials: 'false'
|
||||
token: ${{ env.CHECKOUT_TOKEN }}
|
||||
|
||||
- name: Install latest stable
|
||||
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # zizmor: ignore[stale-action-refs] this action doesn't create releases
|
||||
with:
|
||||
toolchain: stable
|
||||
|
||||
- name: Gen Keys if required
|
||||
if: needs.should-run.outputs.shortint_test == 'true' ||
|
||||
needs.should-run.outputs.integer_test == 'true'
|
||||
run: |
|
||||
make gen_key_cache
|
||||
|
||||
- name: Run shortint tests
|
||||
if: needs.should-run.outputs.shortint_test == 'true'
|
||||
run: |
|
||||
BIG_TESTS_INSTANCE=TRUE FAST_TESTS=FALSE make test_param_prod_shortint_ci
|
||||
|
||||
- name: Run integer tests
|
||||
if: needs.should-run.outputs.integer_test == 'true'
|
||||
run: |
|
||||
BIG_TESTS_INSTANCE=TRUE FAST_TESTS=FALSE make test_param_prod_integer_ci
|
||||
|
||||
- name: Run high-level API tests
|
||||
if: needs.should-run.outputs.high_level_api_test == 'true'
|
||||
run: |
|
||||
make test_param_prod_high_level_api
|
||||
|
||||
- name: Set pull-request URL
|
||||
if: ${{ failure() && github.event_name == 'pull_request' }}
|
||||
run: |
|
||||
echo "PULL_REQUEST_MD_LINK=[pull-request](${PR_BASE_URL}${PR_NUMBER}), " >> "${GITHUB_ENV}"
|
||||
env:
|
||||
PR_BASE_URL: ${{ vars.PR_BASE_URL }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
|
||||
- name: Slack Notification
|
||||
if: ${{ failure() && env.SECRETS_AVAILABLE == 'true' }}
|
||||
continue-on-error: true
|
||||
uses: rtCamp/action-slack-notify@e31e87e03dd19038e411e38ae27cbad084a90661
|
||||
env:
|
||||
SLACK_COLOR: ${{ job.status }}
|
||||
SLACK_MESSAGE: "Fast AWS tests finished with status: ${{ job.status }}. (${{ env.PULL_REQUEST_MD_LINK }}[action run](${{ env.ACTION_RUN_URL }}))"
|
||||
|
||||
teardown-instance:
|
||||
name: aws_tfhe_param_prod_tests/teardown-instance
|
||||
if: ${{ always() && needs.setup-instance.result == 'success' }}
|
||||
needs: [ setup-instance, param-prod-tests ]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Stop remote instance
|
||||
id: stop-instance
|
||||
if: env.SECRETS_AVAILABLE == 'true'
|
||||
uses: zama-ai/slab-github-runner@973c1d22702de8d0acd2b34e83404c96ed92c264 # v1.4.2
|
||||
with:
|
||||
mode: stop
|
||||
github-token: ${{ secrets.SLAB_ACTION_TOKEN }}
|
||||
slab-url: ${{ secrets.SLAB_BASE_URL }}
|
||||
job-secret: ${{ secrets.JOB_SECRET }}
|
||||
label: ${{ needs.setup-instance.outputs.runner-name }}
|
||||
|
||||
- name: Slack Notification
|
||||
if: ${{ failure() || (cancelled() && github.event_name != 'pull_request') }}
|
||||
uses: rtCamp/action-slack-notify@e31e87e03dd19038e411e38ae27cbad084a90661
|
||||
env:
|
||||
SLACK_COLOR: ${{ job.status }}
|
||||
SLACK_MESSAGE: "Instance teardown (param-prod-tests) finished with status: ${{ job.status }}. (${{ env.ACTION_RUN_URL }})"
|
||||
28
Makefile
28
Makefile
@@ -905,14 +905,6 @@ test_shortint_ci: install_cargo_nextest
|
||||
./scripts/shortint-tests.sh \
|
||||
--cargo-profile "$(CARGO_PROFILE)" --tfhe-package "tfhe"
|
||||
|
||||
.PHONY: test_param_prod_shortint_ci # Run the tests for shortint ci
|
||||
test_param_prod_shortint_ci: install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/shortint-tests.sh \
|
||||
--cargo-profile "$(CARGO_PROFILE)" --run-prod-only --tfhe-package "tfhe"
|
||||
|
||||
|
||||
.PHONY: test_shortint_multi_bit_ci # Run the tests for shortint ci running only multibit tests
|
||||
test_shortint_multi_bit_ci: install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
@@ -942,15 +934,6 @@ test_integer_ci: install_cargo_nextest
|
||||
--cargo-profile "$(CARGO_PROFILE)" --avx512-support "$(AVX512_SUPPORT)" \
|
||||
--tfhe-package "tfhe"
|
||||
|
||||
.PHONY: test_param_prod_integer_ci # Run the tests for integer ci
|
||||
test_param_prod_integer_ci: install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
NIGHTLY_TESTS="$(NIGHTLY_TESTS)" \
|
||||
./scripts/integer-tests.sh \
|
||||
--cargo-profile "$(CARGO_PROFILE)" --avx512-support "$(AVX512_SUPPORT)" \
|
||||
--run-prod-only --tfhe-package "tfhe"
|
||||
|
||||
.PHONY: test_unsigned_integer_ci # Run the tests for unsigned integer ci
|
||||
test_unsigned_integer_ci: install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
@@ -1048,16 +1031,9 @@ test_integer_cov: install_tarpaulin
|
||||
|
||||
.PHONY: test_high_level_api # Run all the tests for high_level_api
|
||||
test_high_level_api:
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo nextest run --cargo-profile $(CARGO_PROFILE) \
|
||||
--profile=ci \
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo test --profile $(CARGO_PROFILE) \
|
||||
--features=boolean,shortint,integer,internal-keycache,zk-pok,strings -p tfhe \
|
||||
-E "test(/high_level_api::.*/) and not test(/.*param_prod.*/)"
|
||||
|
||||
test_param_prod_high_level_api:
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo nextest run --cargo-profile $(CARGO_PROFILE) \
|
||||
--profile=ci \
|
||||
--features=boolean,shortint,integer,internal-keycache,zk-pok,strings -p tfhe \
|
||||
-E "test(/high_level_api::.*/) and test(/.*param_prod.*/)"
|
||||
-- high_level_api::
|
||||
|
||||
test_high_level_api_gpu: install_cargo_nextest
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo nextest run --cargo-profile $(CARGO_PROFILE) \
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
// Construct an empty set. Invalid use of an empty set should raise an error
|
||||
// right away through asserts or because of a nullptr dereference
|
||||
CudaStreams()
|
||||
: _streams(nullptr), _gpu_indexes(nullptr), _gpu_count(0),
|
||||
: _streams(nullptr), _gpu_indexes(nullptr), _gpu_count((uint32_t)-1),
|
||||
_owns_streams(false) {}
|
||||
|
||||
// Returns a subset of this set as an active subset. An active subset is one
|
||||
@@ -114,13 +114,11 @@ public:
|
||||
// streams on the same GPU
|
||||
void create_on_same_gpus(const CudaStreams &other) {
|
||||
PANIC_IF_FALSE(_streams == nullptr,
|
||||
"Cuda error: Assign clone to non-empty CudaStreams");
|
||||
PANIC_IF_FALSE(_gpu_count <= 8,
|
||||
"Cuda error: GPU count should be in the interval [0, 8]");
|
||||
"Assign clone to non-empty cudastreams");
|
||||
|
||||
cudaStream_t *new_streams = new cudaStream_t[other._gpu_count];
|
||||
|
||||
uint32_t *gpu_indexes_clone = new uint32_t[other._gpu_count];
|
||||
uint32_t *gpu_indexes_clone = new uint32_t[_gpu_count];
|
||||
for (uint32_t i = 0; i < other._gpu_count; ++i) {
|
||||
new_streams[i] = cuda_create_stream(other._gpu_indexes[i]);
|
||||
gpu_indexes_clone[i] = other._gpu_indexes[i];
|
||||
@@ -172,7 +170,6 @@ public:
|
||||
_streams = nullptr;
|
||||
delete[] _gpu_indexes;
|
||||
_gpu_indexes = nullptr;
|
||||
_gpu_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -136,9 +136,9 @@ host_integer_compress(CudaStreams streams,
|
||||
}
|
||||
|
||||
// Modulus switch
|
||||
uint32_t size = num_glwes * compression_params.glwe_dimension *
|
||||
compression_params.polynomial_size +
|
||||
glwe_array_out->total_lwe_bodies_count;
|
||||
int size = num_glwes * compression_params.glwe_dimension *
|
||||
compression_params.polynomial_size +
|
||||
glwe_array_out->total_lwe_bodies_count;
|
||||
|
||||
host_modulus_switch_inplace<Torus>(streams.stream(0), streams.gpu_index(0),
|
||||
tmp_glwe_array_out, size,
|
||||
|
||||
@@ -3,23 +3,21 @@
|
||||
set -e
|
||||
|
||||
function usage() {
|
||||
echo "$0: integer test runner"
|
||||
echo
|
||||
echo "--help Print this message"
|
||||
echo "--no-run Does not run the tests, but prints which tests would be ran (except doctests)"
|
||||
echo "--rust-toolchain The toolchain to run the tests with default: stable"
|
||||
echo "--multi-bit Run multi-bit tests only: default off"
|
||||
echo "--unsigned-only Run only unsigned integer tests, by default both signed and unsigned tests are run"
|
||||
echo "--signed-only Run only signed integer tests, by default both signed and unsigned tests are run"
|
||||
echo "--run-prod-only Run only the tests using the prod parameters"
|
||||
echo "--nightly-tests Run integer tests configured for nightly runs (3_3 params)"
|
||||
echo "--fast-tests Run integer set but skip a subset of longer tests"
|
||||
echo "--long-tests Run only long run integer tests"
|
||||
echo "--cargo-profile The cargo profile used to build tests"
|
||||
echo "--backend Backend to use with tfhe-rs"
|
||||
echo "--avx512-support Set to ON to enable avx512"
|
||||
echo "--tfhe-package The package spec like tfhe@0.4.2, default=tfhe"
|
||||
echo
|
||||
echo "$0: integer test runner"
|
||||
echo
|
||||
echo "--help Print this message"
|
||||
echo "--rust-toolchain The toolchain to run the tests with default: stable"
|
||||
echo "--multi-bit Run multi-bit tests only: default off"
|
||||
echo "--unsigned-only Run only unsigned integer tests, by default both signed and unsigned tests are run"
|
||||
echo "--signed-only Run only signed integer tests, by default both signed and unsigned tests are run"
|
||||
echo "--nightly-tests Run integer tests configured for nightly runs (3_3 params)"
|
||||
echo "--fast-tests Run integer set but skip a subset of longer tests"
|
||||
echo "--long-tests Run only long run integer tests"
|
||||
echo "--cargo-profile The cargo profile used to build tests"
|
||||
echo "--backend Backend to use with tfhe-rs"
|
||||
echo "--avx512-support Set to ON to enable avx512"
|
||||
echo "--tfhe-package The package spec like tfhe@0.4.2, default=tfhe"
|
||||
echo
|
||||
}
|
||||
|
||||
RUST_TOOLCHAIN=""
|
||||
@@ -35,96 +33,87 @@ backend="cpu"
|
||||
gpu_feature=""
|
||||
avx512_feature=""
|
||||
tfhe_package="tfhe"
|
||||
prod_param_argument=
|
||||
no_run=false
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
case "$1" in
|
||||
"--help" | "-h")
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
while [ -n "$1" ]
|
||||
do
|
||||
case "$1" in
|
||||
"--help" | "-h" )
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
|
||||
"--no-run")
|
||||
no_run=true
|
||||
;;
|
||||
"--rust-toolchain" )
|
||||
shift
|
||||
RUST_TOOLCHAIN="$1"
|
||||
;;
|
||||
|
||||
"--run-prod-only")
|
||||
prod_param_argument="--run-prod-only"
|
||||
;;
|
||||
"--multi-bit" )
|
||||
multi_bit_argument=--multi-bit
|
||||
;;
|
||||
|
||||
"--rust-toolchain")
|
||||
shift
|
||||
RUST_TOOLCHAIN="$1"
|
||||
;;
|
||||
"--unsigned-only" )
|
||||
sign_argument=--unsigned-only
|
||||
;;
|
||||
|
||||
"--multi-bit")
|
||||
multi_bit_argument=--multi-bit
|
||||
;;
|
||||
"--signed-only" )
|
||||
sign_argument=--signed-only
|
||||
;;
|
||||
|
||||
"--unsigned-only")
|
||||
sign_argument=--unsigned-only
|
||||
;;
|
||||
"--cargo-profile" )
|
||||
shift
|
||||
cargo_profile="$1"
|
||||
;;
|
||||
|
||||
"--signed-only")
|
||||
sign_argument=--signed-only
|
||||
;;
|
||||
"--backend" )
|
||||
shift
|
||||
backend="$1"
|
||||
;;
|
||||
"--avx512-support" )
|
||||
shift
|
||||
if [[ "$1" == "ON" ]]; then
|
||||
avx512_feature=avx512
|
||||
fi
|
||||
;;
|
||||
|
||||
"--cargo-profile")
|
||||
shift
|
||||
cargo_profile="$1"
|
||||
;;
|
||||
"--tfhe-package" )
|
||||
shift
|
||||
tfhe_package="$1"
|
||||
;;
|
||||
|
||||
"--backend")
|
||||
shift
|
||||
backend="$1"
|
||||
;;
|
||||
"--avx512-support")
|
||||
shift
|
||||
if [[ "$1" == "ON" ]]; then
|
||||
avx512_feature=avx512
|
||||
fi
|
||||
;;
|
||||
|
||||
"--tfhe-package")
|
||||
shift
|
||||
tfhe_package="$1"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown param : $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
*)
|
||||
echo "Unknown param : $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ "${RUST_TOOLCHAIN::1}" != "+" ]]; then
|
||||
RUST_TOOLCHAIN=${RUST_TOOLCHAIN:+"+${RUST_TOOLCHAIN}"}
|
||||
RUST_TOOLCHAIN=${RUST_TOOLCHAIN:+"+${RUST_TOOLCHAIN}"}
|
||||
fi
|
||||
|
||||
if [[ "${FAST_TESTS}" == TRUE ]]; then
|
||||
fast_tests_argument=--fast-tests
|
||||
fast_tests_argument=--fast-tests
|
||||
fi
|
||||
|
||||
if [[ "${LONG_TESTS}" == TRUE ]]; then
|
||||
long_tests_argument=--long-tests
|
||||
long_tests_argument=--long-tests
|
||||
fi
|
||||
|
||||
if [[ "${NIGHTLY_TESTS}" == TRUE ]]; then
|
||||
nightly_tests_argument=--nightly-tests
|
||||
nightly_tests_argument=--nightly-tests
|
||||
fi
|
||||
|
||||
if [[ "${NO_BIG_PARAMS}" == TRUE ]]; then
|
||||
no_big_params_argument=--no-big-params
|
||||
no_big_params_argument=--no-big-params
|
||||
fi
|
||||
|
||||
if [[ "${NO_BIG_PARAMS_GPU}" == TRUE ]]; then
|
||||
no_big_params_argument_gpu=--no-big-params-gpu
|
||||
no_big_params_argument_gpu=--no-big-params-gpu
|
||||
fi
|
||||
|
||||
if [[ "${backend}" == "gpu" ]]; then
|
||||
gpu_feature="gpu"
|
||||
gpu_feature="gpu"
|
||||
fi
|
||||
|
||||
CURR_DIR="$(dirname "$0")"
|
||||
@@ -133,80 +122,70 @@ CURR_DIR="$(dirname "$0")"
|
||||
num_cpu_threads="$("${CURR_DIR}"/cpu_count.sh)"
|
||||
|
||||
if uname -a | grep "arm64"; then
|
||||
if [[ $(uname) == "Darwin" ]]; then
|
||||
# Keys are 4.7 gigs at max, CI M1 macs only has 8 gigs of RAM
|
||||
small_instance_n_threads=1
|
||||
fi
|
||||
if [[ $(uname) == "Darwin" ]]; then
|
||||
# Keys are 4.7 gigs at max, CI M1 macs only has 8 gigs of RAM
|
||||
small_instance_n_threads=1
|
||||
fi
|
||||
else
|
||||
# Keys are 4.7 gigs at max, test machine has 32 gigs of RAM
|
||||
small_instance_n_threads=6
|
||||
# Keys are 4.7 gigs at max, test machine has 32 gigs of RAM
|
||||
small_instance_n_threads=6
|
||||
fi
|
||||
|
||||
if [[ "${BIG_TESTS_INSTANCE}" == TRUE ]]; then
|
||||
test_threads="$((num_cpu_threads * 1 / 4))"
|
||||
doctest_threads="${num_cpu_threads}"
|
||||
test_threads="$((num_cpu_threads * 1 / 4))"
|
||||
doctest_threads="${num_cpu_threads}"
|
||||
else
|
||||
test_threads="${small_instance_n_threads}"
|
||||
doctest_threads="${num_cpu_threads}"
|
||||
test_threads="${small_instance_n_threads}"
|
||||
doctest_threads="${num_cpu_threads}"
|
||||
fi
|
||||
|
||||
# Override test-threads number to avoid Out-of-memory issues on GPU instances
|
||||
if [[ "${backend}" == "gpu" ]]; then
|
||||
if [[ "${BIG_TESTS_INSTANCE}" == TRUE ]]; then
|
||||
test_threads=8
|
||||
doctest_threads=8
|
||||
else
|
||||
test_threads=4
|
||||
doctest_threads=4
|
||||
fi
|
||||
if [[ "${BIG_TESTS_INSTANCE}" == TRUE ]]; then
|
||||
test_threads=8
|
||||
doctest_threads=8
|
||||
else
|
||||
test_threads=4
|
||||
doctest_threads=4
|
||||
fi
|
||||
fi
|
||||
|
||||
filter_expression=$(/usr/bin/python3 scripts/test_filtering.py --layer integer --backend "${backend}" ${fast_tests_argument:+$fast_tests_argument} ${long_tests_argument:+$long_tests_argument} ${nightly_tests_argument:+$nightly_tests_argument} ${no_big_params_argument_gpu:+$no_big_params_argument_gpu} ${multi_bit_argument:+$multi_bit_argument} ${sign_argument:+$sign_argument} ${no_big_params_argument:+$no_big_params_argument} ${prod_param_argument:+$prod_param_argument})
|
||||
filter_expression=$(/usr/bin/python3 scripts/test_filtering.py --layer integer --backend "${backend}" ${fast_tests_argument:+$fast_tests_argument} ${long_tests_argument:+$long_tests_argument} ${nightly_tests_argument:+$nightly_tests_argument} ${no_big_params_argument_gpu:+$no_big_params_argument_gpu} ${multi_bit_argument:+$multi_bit_argument} ${sign_argument:+$sign_argument} ${no_big_params_argument:+$no_big_params_argument})
|
||||
|
||||
if [[ "${FAST_TESTS}" == "TRUE" ]]; then
|
||||
echo "Running 'fast' test set"
|
||||
echo "Running 'fast' test set"
|
||||
elif [[ "${LONG_TESTS}" == "FALSE" ]]; then
|
||||
echo "Running 'slow' test set"
|
||||
echo "Running 'slow' test set"
|
||||
fi
|
||||
|
||||
if [[ "${LONG_TESTS}" == "TRUE" ]]; then
|
||||
echo "Running 'long run' test set"
|
||||
echo "Running 'long run' test set"
|
||||
fi
|
||||
|
||||
if [[ "${NIGHTLY_TESTS}" == "TRUE" ]]; then
|
||||
echo "Running 'nightly' test set"
|
||||
echo "Running 'nightly' test set"
|
||||
fi
|
||||
|
||||
echo "${filter_expression}"
|
||||
|
||||
if $no_run; then
|
||||
nextest_command="list"
|
||||
nextest_extra_flags=""
|
||||
else
|
||||
nextest_command="run"
|
||||
nextest_extra_flags="--profile ci --test-threads ${test_threads}"
|
||||
fi
|
||||
cargo ${RUST_TOOLCHAIN:+"$RUST_TOOLCHAIN"} nextest run \
|
||||
--tests \
|
||||
--cargo-profile "${cargo_profile}" \
|
||||
--package "${tfhe_package}" \
|
||||
--profile ci \
|
||||
--no-default-features \
|
||||
--features=integer,internal-keycache,zk-pok,experimental,"${avx512_feature}","${gpu_feature}" \
|
||||
--test-threads "${test_threads}" \
|
||||
-E "$filter_expression"
|
||||
|
||||
cargo ${RUST_TOOLCHAIN:+"$RUST_TOOLCHAIN"} nextest ${nextest_command} \
|
||||
--tests \
|
||||
--cargo-profile "${cargo_profile}" \
|
||||
--package "${tfhe_package}" \
|
||||
--no-default-features \
|
||||
--features=integer,internal-keycache,zk-pok,experimental,"${avx512_feature}","${gpu_feature}" \
|
||||
${nexttest_extra_flags} \
|
||||
-E "$filter_expression"
|
||||
|
||||
if ! $no_run; then
|
||||
# Unfortunately, we cannot skip running doctest with `--no-run`
|
||||
if [[ -z ${multi_bit_argument} && -z ${long_tests_argument} ]]; then
|
||||
cargo ${RUST_TOOLCHAIN:+"$RUST_TOOLCHAIN"} test \
|
||||
--profile "${cargo_profile}" \
|
||||
--package "${tfhe_package}" \
|
||||
--no-default-features \
|
||||
--features=integer,internal-keycache,experimental,"${avx512_feature}","${gpu_feature}" \
|
||||
--doc \
|
||||
-- --test-threads="${doctest_threads}" integer::"${gpu_feature}"
|
||||
fi
|
||||
if [[ -z ${multi_bit_argument} && -z ${long_tests_argument} ]]; then
|
||||
cargo ${RUST_TOOLCHAIN:+"$RUST_TOOLCHAIN"} test \
|
||||
--profile "${cargo_profile}" \
|
||||
--package "${tfhe_package}" \
|
||||
--no-default-features \
|
||||
--features=integer,internal-keycache,experimental,"${avx512_feature}","${gpu_feature}" \
|
||||
--doc \
|
||||
-- --test-threads="${doctest_threads}" integer::"${gpu_feature}"
|
||||
fi
|
||||
|
||||
echo "Test ran in $SECONDS seconds"
|
||||
|
||||
@@ -8,7 +8,6 @@ function usage() {
|
||||
echo "--help Print this message"
|
||||
echo "--rust-toolchain The toolchain to run the tests with default: stable"
|
||||
echo "--multi-bit Run multi-bit tests only: default off"
|
||||
echo "--run-prod-only Run only the tests using the prod parameters"
|
||||
echo "--cargo-profile The cargo profile used to build tests"
|
||||
echo "--tfhe-package The package spec like tfhe@0.4.2, default=tfhe"
|
||||
echo
|
||||
@@ -20,7 +19,6 @@ multi_bit_argument=
|
||||
fast_tests_argument=
|
||||
cargo_profile="release"
|
||||
tfhe_package="tfhe"
|
||||
prod_param_argument=
|
||||
|
||||
while [ -n "$1" ]
|
||||
do
|
||||
@@ -40,9 +38,6 @@ do
|
||||
multi_bit_argument=--multi-bit
|
||||
;;
|
||||
|
||||
"--run-prod-only")
|
||||
prod_param_argument="--run-prod-only"
|
||||
;;
|
||||
"--cargo-profile" )
|
||||
shift
|
||||
cargo_profile="$1"
|
||||
@@ -90,7 +85,7 @@ else
|
||||
fi
|
||||
|
||||
if [[ "${BIG_TESTS_INSTANCE}" != TRUE ]]; then
|
||||
filter_expression_small_params=$(/usr/bin/python3 scripts/test_filtering.py --layer shortint ${fast_tests_argument} ${multi_bit_argument} ${prod_param_argument})
|
||||
filter_expression_small_params=$(/usr/bin/python3 scripts/test_filtering.py --layer shortint ${fast_tests_argument} ${multi_bit_argument})
|
||||
|
||||
# Run tests only no examples or benches with small params and more threads
|
||||
cargo ${RUST_TOOLCHAIN:+"$RUST_TOOLCHAIN"} nextest run \
|
||||
@@ -130,7 +125,7 @@ and not test(~smart_add_and_mul)"""
|
||||
fi
|
||||
fi
|
||||
else
|
||||
filter_expression=$(/usr/bin/python3 scripts/test_filtering.py --layer shortint --big-instance ${fast_tests_argument} ${multi_bit_argument} ${prod_param_argument})
|
||||
filter_expression=$(/usr/bin/python3 scripts/test_filtering.py --layer shortint --big-instance ${fast_tests_argument} ${multi_bit_argument})
|
||||
|
||||
# Run tests only no examples or benches with small params and more threads
|
||||
cargo ${RUST_TOOLCHAIN:+"$RUST_TOOLCHAIN"} nextest run \
|
||||
|
||||
@@ -74,17 +74,12 @@ parser.add_argument(
|
||||
action="store_true",
|
||||
help="Do not run tests with big parameters set (e.g. 3bits message with 3 bits carry) for GPU",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--run-prod-only",
|
||||
action="store_true",
|
||||
help="Specify to run the CPU tests with the prod KS_PBS 2_2 parameters, \
|
||||
only the 'layer' parameter will be taken into account if this flag is specified",
|
||||
)
|
||||
|
||||
# block PBS are too slow for high params
|
||||
# mul_crt_4_4 is extremely flaky (~80% failure)
|
||||
# test_wopbs_bivariate_crt_wopbs_param_message generate tables that are too big at the moment
|
||||
# test_integer_smart_mul_param_message_4_carry_4_ks_pbs_gaussian_2m64 is too slow
|
||||
# so is test_integer_default_add_sequence_multi_thread_param_message_4_carry_4_ks_pbs_gaussian_2m64
|
||||
# skip smart_div, smart_rem which are already covered by the smar_div_rem test
|
||||
# skip default_div, default_rem which are covered by default_div_rem
|
||||
EXCLUDED_INTEGER_TESTS = [
|
||||
@@ -96,6 +91,7 @@ EXCLUDED_INTEGER_TESTS = [
|
||||
"~mul_crt_param_message_4_carry_4_ks_pbs_gaussian_2m64",
|
||||
"/.*test_wopbs_bivariate_crt_wopbs_param_message_[34]_carry_[34]_ks_pbs_gaussian_2m64$/",
|
||||
"/.*test_integer_smart_mul_param_message_4_carry_4_ks_pbs_gaussian_2m64$/",
|
||||
"/.*test_integer_default_add_sequence_multi_thread_param_message_4_carry_4_ks_pbs_gaussian_2m64$/",
|
||||
"/.*::tests_long_run::.*/",
|
||||
]
|
||||
|
||||
@@ -104,6 +100,7 @@ EXCLUDED_INTEGER_FAST_TESTS = [
|
||||
"/.*integer_default_div_param/",
|
||||
"/.*integer_default_rem_param/",
|
||||
"/.*_param_message_[14]_carry_[14]_ks_pbs_gaussian_2m64$/",
|
||||
"/.*default_add_sequence_multi_thread_param_message_3_carry_3_ks_pbs_gaussian_2m64$/",
|
||||
]
|
||||
|
||||
EXCLUDED_BIG_PARAMETERS = [
|
||||
@@ -128,13 +125,7 @@ def filter_integer_tests(input_args):
|
||||
# For now, GPU only has specific parameters set for multi-bit
|
||||
multi_bit_filter = "_gpu_multi_bit"
|
||||
|
||||
if input_args.run_prod_only:
|
||||
filter_expression = [f"test(/^integer::{backend_filter}.*_param_prod.*/)"]
|
||||
else:
|
||||
filter_expression = [
|
||||
f"test(/^integer::{backend_filter}.*/)",
|
||||
"not test(~_param_prod)",
|
||||
]
|
||||
filter_expression = [f"test(/^integer::{backend_filter}.*/)"]
|
||||
|
||||
if input_args.multi_bit:
|
||||
filter_expression.append("test(~_multi_bit)")
|
||||
@@ -170,32 +161,29 @@ def filter_integer_tests(input_args):
|
||||
f"test(/.*_default_.*?_param{multi_bit_filter}{group_filter}_message_3_carry_3_.*/)"
|
||||
)
|
||||
excluded_tests = (
|
||||
EXCLUDED_INTEGER_FAST_TESTS
|
||||
if input_args.fast_tests
|
||||
else EXCLUDED_INTEGER_TESTS
|
||||
EXCLUDED_INTEGER_FAST_TESTS if input_args.fast_tests else EXCLUDED_INTEGER_TESTS
|
||||
)
|
||||
for pattern in excluded_tests:
|
||||
filter_expression.append(f"not test({pattern})")
|
||||
|
||||
else:
|
||||
if input_args.backend == "gpu":
|
||||
filter_expression = [
|
||||
"test(/^integer::gpu::server_key::radix::tests_long_run.*/)"
|
||||
]
|
||||
filter_expression = ["test(/^integer::gpu::server_key::radix::tests_long_run.*/)"]
|
||||
elif input_args.backend == "cpu":
|
||||
filter_expression = [
|
||||
"test(/^integer::server_key::radix_parallel::tests_long_run.*/)"
|
||||
]
|
||||
filter_expression = ["test(/^integer::server_key::radix_parallel::tests_long_run.*/)"]
|
||||
|
||||
|
||||
# Do not run noise check tests by default as they can be very slow
|
||||
# they will be run e.g. nightly or on demand
|
||||
filter_expression.append(
|
||||
"not test(/^integer::gpu::server_key::radix::tests_noise_distribution::.*::test_gpu_noise_check.*/)"
|
||||
)
|
||||
filter = filter_expression.append(f"not test(/^integer::gpu::server_key::radix::tests_noise_distribution::.*::test_gpu_noise_check.*/)")
|
||||
|
||||
return " and ".join(filter_expression)
|
||||
|
||||
|
||||
def shortint_normal_filter(input_args):
|
||||
multi_bit_filter = "_multi_bit_group_[0-9]" if input_args.multi_bit else ""
|
||||
def filter_shortint_tests(input_args):
|
||||
multi_bit_filter, group_filter = (
|
||||
("_multi_bit", "_group_[0-9]") if input_args.multi_bit else ("", "")
|
||||
)
|
||||
|
||||
if input_args.fast_tests:
|
||||
msg_carry_pairs = [(2, 1), (2, 2), (2, 3)]
|
||||
@@ -218,31 +206,19 @@ def shortint_normal_filter(input_args):
|
||||
msg_carry_pairs.append((4, 4))
|
||||
|
||||
filter_expression = [
|
||||
f"test(/^shortint::.*_param{multi_bit_filter}_message_{msg}_carry_{carry}\
|
||||
(_compact_pk)?_ks(32)?_pbs.*/)"
|
||||
f"test(/^shortint::.*_param{multi_bit_filter}{group_filter}_message_{msg}_carry_{carry}(_compact_pk)?_ks(32)?_pbs.*/)"
|
||||
for msg, carry in msg_carry_pairs
|
||||
]
|
||||
filter_expression.append("test(/^shortint::.*meta_param_cpu_2_2/)")
|
||||
|
||||
filter_expression.append("test(/^shortint::.*meta_param_cpu_2_2_ks32_pbs/)")
|
||||
filter_expression.append("test(/^shortint::.*_ci_run_filter/)")
|
||||
|
||||
return filter_expression
|
||||
|
||||
|
||||
def filter_shortint_tests(input_args):
|
||||
# We special case the CPU KS_PBS 2_2 parameters to be able to run them alone
|
||||
filter_expression = shortint_normal_filter(input_args)
|
||||
opt_in_tests = " or ".join(filter_expression)
|
||||
|
||||
# Do not run noise check tests by default as they can be very slow
|
||||
# they will be run e.g. nightly or on demand
|
||||
filter = f"({opt_in_tests}) and not test(/^shortint::.*test_noise_check/)"
|
||||
|
||||
if input_args.run_prod_only:
|
||||
filter = f"({filter}) and test(/^shortint::.*_param_prod.*/)"
|
||||
else:
|
||||
filter = f"({filter}) and not test(/^shortint::.*_param_prod.*/)"
|
||||
|
||||
return filter
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
use benchmark::params_aliases::BENCH_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
#[cfg(feature = "gpu")]
|
||||
use benchmark::params_aliases::BENCH_PARAM_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
use criterion::{black_box, criterion_group, Criterion};
|
||||
use std::num::NonZeroU64;
|
||||
use tfhe::{set_server_key, ClientKey, ConfigBuilder, FheUint64, RangeForRandom, Seed, ServerKey};
|
||||
|
||||
fn oprf_any_range_bench(c: &mut Criterion, bench_name: &str) {
|
||||
pub fn oprf_any_range(c: &mut Criterion) {
|
||||
let bench_name = "hlapi::oprf_any_range";
|
||||
|
||||
let mut bench_group = c.benchmark_group(bench_name);
|
||||
bench_group
|
||||
.sample_size(15)
|
||||
.measurement_time(std::time::Duration::from_secs(30));
|
||||
|
||||
let param = BENCH_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let config = ConfigBuilder::with_custom_parameters(param).build();
|
||||
let cks = ClientKey::generate(config);
|
||||
let sks = ServerKey::new(&cks);
|
||||
|
||||
rayon::broadcast(|_| set_server_key(sks.clone()));
|
||||
set_server_key(sks);
|
||||
|
||||
for excluded_upper_bound in [3, 52] {
|
||||
let range = RangeForRandom::new_from_excluded_upper_bound(
|
||||
NonZeroU64::new(excluded_upper_bound).unwrap(),
|
||||
@@ -33,34 +41,4 @@ fn oprf_any_range_bench(c: &mut Criterion, bench_name: &str) {
|
||||
bench_group.finish()
|
||||
}
|
||||
|
||||
pub fn oprf_any_range_cpu(c: &mut Criterion) {
|
||||
let param = BENCH_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let config = ConfigBuilder::with_custom_parameters(param).build();
|
||||
let cks = ClientKey::generate(config);
|
||||
let sks = ServerKey::new(&cks);
|
||||
|
||||
rayon::broadcast(|_| set_server_key(sks.clone()));
|
||||
set_server_key(sks);
|
||||
|
||||
oprf_any_range_bench(c, "hlapi::oprf_any_range_cpu");
|
||||
}
|
||||
|
||||
#[cfg(feature = "gpu")]
|
||||
pub fn oprf_any_range_gpu(c: &mut Criterion) {
|
||||
let param = BENCH_PARAM_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let config = ConfigBuilder::with_custom_parameters(param).build();
|
||||
let cks = ClientKey::generate(config);
|
||||
let sks = tfhe::CompressedServerKey::new(&cks).decompress_to_gpu();
|
||||
|
||||
set_server_key(sks);
|
||||
|
||||
oprf_any_range_bench(c, "hlapi::oprf_any_range_gpu");
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
criterion_group!(oprf_any_range2, oprf_any_range_cpu);
|
||||
|
||||
#[cfg(feature = "gpu")]
|
||||
criterion_group!(oprf_any_range2, oprf_any_range_cpu, oprf_any_range_gpu);
|
||||
criterion_group!(oprf_any_range2, oprf_any_range);
|
||||
|
||||
@@ -41,3 +41,7 @@ harness = false
|
||||
[[bench]]
|
||||
name = "pke_v2"
|
||||
harness = false
|
||||
|
||||
[[example]]
|
||||
name = "example"
|
||||
path = "example.rs"
|
||||
|
||||
260
tfhe-zk-pok/example.rs
Normal file
260
tfhe-zk-pok/example.rs
Normal file
@@ -0,0 +1,260 @@
|
||||
use rand::rngs::StdRng;
|
||||
use rand::{thread_rng, Rng, SeedableRng};
|
||||
use tfhe_zk_pok::proofs::pke_v2::*;
|
||||
use tfhe_zk_pok::proofs::*;
|
||||
|
||||
pub fn polymul_rev(a: &[i64], b: &[i64]) -> Vec<i64> {
|
||||
assert_eq!(a.len(), b.len());
|
||||
let d = a.len();
|
||||
let mut c = vec![0i64; d];
|
||||
|
||||
for i in 0..d {
|
||||
for j in 0..d {
|
||||
if i + j < d {
|
||||
c[i + j] = c[i + j].wrapping_add(a[i].wrapping_mul(b[d - j - 1]));
|
||||
} else {
|
||||
c[i + j - d] = c[i + j - d].wrapping_sub(a[i].wrapping_mul(b[d - j - 1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c
|
||||
}
|
||||
|
||||
type CurveMy = tfhe_zk_pok::curve_api::Bls12_446;
|
||||
|
||||
/// q (modulus) is encoded on 64b, with 0 meaning 2^64. This converts the encoded q to its effective
|
||||
/// value for modular operations.
|
||||
fn decode_q(q: u64) -> u128 {
|
||||
if q == 0 {
|
||||
1u128 << 64
|
||||
} else {
|
||||
q as u128
|
||||
}
|
||||
}
|
||||
|
||||
// One of our usecases uses 320 bits of additional metadata
|
||||
pub const METADATA_LEN: usize = (64 / u8::BITS) as usize;
|
||||
|
||||
pub struct PkeTestCiphertext {
|
||||
pub c1: Vec<i64>,
|
||||
pub c2: Vec<i64>,
|
||||
}
|
||||
|
||||
pub struct PkeTestParameters {
|
||||
pub d: usize,
|
||||
pub k: usize,
|
||||
pub B: u64,
|
||||
pub q: u64,
|
||||
pub t: u64,
|
||||
pub msbs_zero_padding_bit_count: u64,
|
||||
}
|
||||
|
||||
pub const PKEV2_TEST_PARAMS: PkeTestParameters = PkeTestParameters {
|
||||
d: 2048,
|
||||
k: 32,
|
||||
B: 131072, // 2**17
|
||||
q: 0,
|
||||
t: 32, // 2b msg, 2b carry, 1b padding
|
||||
msbs_zero_padding_bit_count: 1,
|
||||
};
|
||||
|
||||
/// A randomly generated testcase of pke encryption
|
||||
#[derive(Clone)]
|
||||
pub struct PkeTestcase {
|
||||
pub a: Vec<i64>,
|
||||
pub e1: Vec<i64>,
|
||||
pub e2: Vec<i64>,
|
||||
pub r: Vec<i64>,
|
||||
pub m: Vec<i64>,
|
||||
pub b: Vec<i64>,
|
||||
pub metadata: [u8; METADATA_LEN],
|
||||
pub s: Vec<i64>,
|
||||
}
|
||||
|
||||
impl PkeTestcase {
|
||||
pub fn gen(rng: &mut StdRng, params: PkeTestParameters) -> Self {
|
||||
let PkeTestParameters {
|
||||
d,
|
||||
k,
|
||||
B,
|
||||
q: _q,
|
||||
t,
|
||||
msbs_zero_padding_bit_count,
|
||||
} = params;
|
||||
|
||||
let effective_cleartext_t = t >> msbs_zero_padding_bit_count;
|
||||
|
||||
let a = (0..d).map(|_| rng.gen::<i64>()).collect::<Vec<_>>();
|
||||
|
||||
let s = (0..d)
|
||||
.map(|_| (rng.gen::<u64>() % 2) as i64)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let e = (0..d)
|
||||
.map(|_| (rng.gen::<u64>() % (2 * B)) as i64 - B as i64)
|
||||
.collect::<Vec<_>>();
|
||||
let e1 = (0..d)
|
||||
.map(|_| (rng.gen::<u64>() % (2 * B)) as i64 - B as i64)
|
||||
.collect::<Vec<_>>();
|
||||
let e2 = (0..k)
|
||||
.map(|_| (rng.gen::<u64>() % (2 * B)) as i64 - B as i64)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let r = (0..d)
|
||||
.map(|_| (rng.gen::<u64>() % 2) as i64)
|
||||
.collect::<Vec<_>>();
|
||||
let m = (0..k)
|
||||
.map(|_| (rng.gen::<u64>() % effective_cleartext_t) as i64)
|
||||
.collect::<Vec<_>>();
|
||||
let b = polymul_rev(&a, &s)
|
||||
.into_iter()
|
||||
.zip(e.iter())
|
||||
.map(|(x, e)| x.wrapping_add(*e))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut metadata = [0u8; METADATA_LEN];
|
||||
metadata.fill_with(|| rng.gen::<u8>());
|
||||
|
||||
Self {
|
||||
a,
|
||||
e1,
|
||||
e2,
|
||||
r,
|
||||
m,
|
||||
b,
|
||||
metadata,
|
||||
s,
|
||||
}
|
||||
}
|
||||
|
||||
/// Encrypt using compact pke, the encryption is validated by doing a decryption
|
||||
pub fn encrypt(&self, params: PkeTestParameters) -> PkeTestCiphertext {
|
||||
let ct = self.encrypt_unchecked(params);
|
||||
|
||||
ct
|
||||
}
|
||||
|
||||
pub fn encrypt_unchecked(&self, params: PkeTestParameters) -> PkeTestCiphertext {
|
||||
let PkeTestParameters {
|
||||
d,
|
||||
k,
|
||||
B: _B,
|
||||
q,
|
||||
t,
|
||||
msbs_zero_padding_bit_count: _msbs_zero_padding_bit_count,
|
||||
} = params;
|
||||
|
||||
let delta = {
|
||||
let q = decode_q(q) as i128;
|
||||
// delta takes the encoding with the padding bit
|
||||
(q / t as i128) as u64
|
||||
};
|
||||
|
||||
let c1 = polymul_rev(&self.a, &self.r)
|
||||
.into_iter()
|
||||
.zip(self.e1.iter())
|
||||
.map(|(x, e1)| x.wrapping_add(*e1))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut c2 = vec![0i64; k];
|
||||
|
||||
for (i, c2) in c2.iter_mut().enumerate() {
|
||||
let mut dot = 0i64;
|
||||
for j in 0..d {
|
||||
let b = if i + j < d {
|
||||
self.b[d - j - i - 1]
|
||||
} else {
|
||||
self.b[2 * d - j - i - 1].wrapping_neg()
|
||||
};
|
||||
|
||||
dot = dot.wrapping_add(self.r[d - j - 1].wrapping_mul(b));
|
||||
}
|
||||
|
||||
*c2 = dot
|
||||
.wrapping_add(self.e2[i])
|
||||
.wrapping_add((delta * self.m[i] as u64) as i64);
|
||||
}
|
||||
|
||||
PkeTestCiphertext { c1, c2 }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let PkeTestParameters {
|
||||
d,
|
||||
k,
|
||||
B,
|
||||
q,
|
||||
t,
|
||||
msbs_zero_padding_bit_count,
|
||||
} = PKEV2_TEST_PARAMS;
|
||||
|
||||
// let d = 2048;
|
||||
// let k = 32;
|
||||
// let B = 131072; // 2**17
|
||||
// let q = 0; // 2^64
|
||||
// let t = 32; // 2b msg, 2b carry, 1b padding
|
||||
// let msbs_zero_padding_bit_count = 1;
|
||||
|
||||
let effective_cleartext_t = t >> msbs_zero_padding_bit_count;
|
||||
|
||||
let seed = thread_rng().gen();
|
||||
println!("pkev2 seed: {seed:x}");
|
||||
let rng = &mut StdRng::seed_from_u64(seed);
|
||||
|
||||
let testcase = PkeTestcase::gen(rng, PKEV2_TEST_PARAMS);
|
||||
let ct = testcase.encrypt(PKEV2_TEST_PARAMS);
|
||||
|
||||
let crs_k = d / (t >> msbs_zero_padding_bit_count) as usize;
|
||||
|
||||
let public_param = crs_gen::<CurveMy>(d, crs_k, B, q, t, msbs_zero_padding_bit_count, rng);
|
||||
|
||||
let (public_commit, private_commit) = commit(
|
||||
testcase.a.clone(),
|
||||
testcase.b.clone(),
|
||||
ct.c1.clone(),
|
||||
ct.c2.clone(),
|
||||
testcase.r.clone(),
|
||||
testcase.e1.clone(),
|
||||
testcase.m.clone(),
|
||||
testcase.e2.clone(),
|
||||
&public_param,
|
||||
);
|
||||
|
||||
for load in [ComputeLoad::Verify] {
|
||||
proof_loop(
|
||||
(&public_param, &public_commit),
|
||||
&private_commit,
|
||||
&testcase.metadata,
|
||||
load,
|
||||
seed,
|
||||
&testcase,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
fn proof_loop(
|
||||
(public_param, public_commit): (&PublicParams<CurveMy>, &PublicCommit<CurveMy>),
|
||||
private_commit: &PrivateCommit<CurveMy>,
|
||||
metadata: &[u8],
|
||||
load: ComputeLoad,
|
||||
seed: u64,
|
||||
testcase: &PkeTestcase,
|
||||
) {
|
||||
let test_runs = 10;
|
||||
let start = std::time::Instant::now();
|
||||
for _ in 0..test_runs {
|
||||
let proof = prove(
|
||||
(public_param, public_commit),
|
||||
private_commit,
|
||||
&testcase.metadata,
|
||||
load,
|
||||
&seed.to_le_bytes(),
|
||||
);
|
||||
}
|
||||
let elapsed = start.elapsed();
|
||||
println!("total: {elapsed:#?}");
|
||||
println!("per run avg: {:#?}", elapsed / test_runs);
|
||||
}
|
||||
@@ -17,8 +17,7 @@ use tfhe::shortint::parameters::key_switching::ShortintKeySwitchingParameters;
|
||||
|
||||
use tfhe::shortint::parameters::current_params::*;
|
||||
use tfhe::shortint::parameters::{
|
||||
AtomicPatternParameters, ClassicPBSParameters, PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
ClassicPBSParameters, PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
};
|
||||
#[cfg(feature = "experimental")]
|
||||
use tfhe::shortint::parameters::{
|
||||
@@ -130,8 +129,6 @@ fn client_server_keys() {
|
||||
];
|
||||
generate_pbs_keys(&PBS_KEYS);
|
||||
|
||||
generate_pbs_keys(&[PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128]);
|
||||
|
||||
#[cfg(feature = "experimental")]
|
||||
{
|
||||
const WOPBS_PARAMS: [(ClassicPBSParameters, WopbsParameters); 4] = [
|
||||
@@ -158,11 +155,10 @@ fn client_server_keys() {
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_pbs_keys<P: Into<AtomicPatternParameters> + Copy>(params: &[P]) {
|
||||
fn generate_pbs_keys(params: &[ClassicPBSParameters]) {
|
||||
println!("Generating shortint (ClientKey, ServerKey)");
|
||||
|
||||
for (i, param) in params.iter().copied().enumerate() {
|
||||
let param: AtomicPatternParameters = param.into();
|
||||
println!(
|
||||
"Generating [{} / {}] : {}",
|
||||
i + 1,
|
||||
|
||||
@@ -30,7 +30,7 @@ pub fn ggsw_encryption_multiplicative_factor<Scalar: UnsignedInteger>(
|
||||
cleartext.0.wrapping_neg(),
|
||||
ciphertext_modulus,
|
||||
)
|
||||
.to_recomposition_summand(),
|
||||
.to_approximate_recomposition_summand(),
|
||||
CiphertextModulusKind::Native | CiphertextModulusKind::NonNativePowerOfTwo => {
|
||||
let native_decomp_term =
|
||||
DecompositionTerm::new(decomp_level, decomp_base_log, cleartext.0.wrapping_neg())
|
||||
@@ -906,7 +906,7 @@ where
|
||||
Scalar::ONE,
|
||||
ciphertext_modulus,
|
||||
)
|
||||
.to_recomposition_summand();
|
||||
.to_approximate_recomposition_summand();
|
||||
|
||||
let decoded = divide_round(*cleartext_ref.0, delta)
|
||||
.wrapping_rem(Scalar::ONE << (decomp_level.0 * decomp_base_log.0));
|
||||
|
||||
@@ -290,7 +290,7 @@ pub fn generate_glwe_keyswitch_key_other_mod<
|
||||
input_key_polynomial.as_ref(),
|
||||
ciphertext_modulus,
|
||||
);
|
||||
term.to_recomposition_summand(message_polynomial.as_mut());
|
||||
term.to_approximate_recomposition_summand(message_polynomial.as_mut());
|
||||
}
|
||||
|
||||
let decomposition_plaintexts_buffer =
|
||||
|
||||
@@ -274,7 +274,7 @@ pub fn generate_lwe_keyswitch_key_other_mod<
|
||||
CastInto::<OutputScalar>::cast_into(*input_key_element),
|
||||
ciphertext_modulus,
|
||||
)
|
||||
.to_recomposition_summand();
|
||||
.to_approximate_recomposition_summand();
|
||||
}
|
||||
|
||||
encrypt_lwe_ciphertext_list(
|
||||
@@ -1026,7 +1026,7 @@ pub fn generate_chunked_lwe_keyswitch_key_other_mod<
|
||||
CastInto::<OutputScalar>::cast_into(*input_key_element),
|
||||
ciphertext_modulus,
|
||||
)
|
||||
.to_recomposition_summand();
|
||||
.to_approximate_recomposition_summand();
|
||||
}
|
||||
|
||||
encrypt_lwe_ciphertext_list(
|
||||
|
||||
@@ -637,7 +637,7 @@ where
|
||||
if decomp.is_fresh() {
|
||||
Some(decomp.fold(Scalar::ZERO, |acc, term| {
|
||||
acc.wrapping_add_custom_mod(
|
||||
term.to_recomposition_summand(),
|
||||
term.to_approximate_recomposition_summand(),
|
||||
ciphertext_modulus_as_scalar,
|
||||
)
|
||||
}))
|
||||
|
||||
@@ -129,7 +129,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Turn this term into a summand. The returned value is under the provided modulus.
|
||||
/// Turn this term into a summand.
|
||||
///
|
||||
/// If our member represents one $\tilde{\theta}\_i$ of the decomposition, this method returns
|
||||
/// $\tilde{\theta}\_i\frac{v}{B^i}$ where $\lambda = \lceil{\log_2{q}}\rceil$ and
|
||||
@@ -148,9 +148,9 @@ where
|
||||
/// CiphertextModulus::try_new((1 << 64) - (1 << 32) + 1).unwrap(),
|
||||
/// );
|
||||
/// let output = decomposer.decompose(2u64.pow(52)).next().unwrap();
|
||||
/// assert_eq!(output.to_recomposition_summand(), 2u64.pow(52));
|
||||
/// assert_eq!(output.to_approximate_recomposition_summand(), 2u64.pow(52));
|
||||
/// ```
|
||||
pub fn to_recomposition_summand(&self) -> T {
|
||||
pub fn to_approximate_recomposition_summand(&self) -> T {
|
||||
let modulus_as_t = T::cast_from(self.ciphertext_modulus.get_custom_modulus());
|
||||
let ciphertext_modulus_bit_count: usize = modulus_as_t.ceil_ilog2().try_into().unwrap();
|
||||
let shift: usize = ciphertext_modulus_bit_count - self.base_log * self.level;
|
||||
@@ -359,8 +359,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Fills the output tensor with the terms turned to summands. The values are under the provided
|
||||
/// modulus.
|
||||
/// Fills the output tensor with the terms turned to summands.
|
||||
///
|
||||
/// If our term tensor represents a set of $(\tilde{\theta}^{(a)}\_i)\_{a\in\mathbb{N}}$ of the
|
||||
/// decomposition, this method fills the output tensor with a set of
|
||||
@@ -382,10 +381,10 @@ where
|
||||
/// let mut decomp = decomposer.decompose_slice(&input);
|
||||
/// let term = decomp.next_term().unwrap();
|
||||
/// let mut output = vec![0; 2];
|
||||
/// term.to_recomposition_summand(&mut output);
|
||||
/// term.to_approximate_recomposition_summand(&mut output);
|
||||
/// assert!(output.iter().all(|&x| x == 1048576));
|
||||
/// ```
|
||||
pub fn to_recomposition_summand(&self, output: &mut [T]) {
|
||||
pub fn to_approximate_recomposition_summand(&self, output: &mut [T]) {
|
||||
assert_eq!(self.slice.len(), output.len());
|
||||
let modulus_as_t = T::cast_from(self.ciphertext_modulus.get_custom_modulus());
|
||||
let ciphertext_modulus_bit_count: usize = modulus_as_t.ceil_ilog2().try_into().unwrap();
|
||||
|
||||
@@ -320,7 +320,7 @@ mod cpu {
|
||||
use super::*;
|
||||
use crate::high_level_api::booleans::compressed::CompressedFheBoolConformanceParams;
|
||||
use crate::safe_serialization::{DeserializationConfig, SerializationConfig};
|
||||
use crate::shortint::parameters::test_params::TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
use crate::FheBoolConformanceParams;
|
||||
use rand::random;
|
||||
|
||||
@@ -675,7 +675,7 @@ mod cpu {
|
||||
|
||||
#[test]
|
||||
fn test_safe_deserialize_conformant_fhe_bool() {
|
||||
let block_params = TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
let (keys, server_key) = generate_keys(ConfigBuilder::with_custom_parameters(block_params));
|
||||
set_server_key(server_key.clone());
|
||||
|
||||
@@ -698,7 +698,7 @@ mod cpu {
|
||||
|
||||
#[test]
|
||||
fn test_safe_deserialize_conformant_compressed_fhe_bool() {
|
||||
let block_params = TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
let (keys, server_key) = generate_keys(ConfigBuilder::with_custom_parameters(block_params));
|
||||
set_server_key(server_key.clone());
|
||||
let clear_a = random::<bool>();
|
||||
|
||||
@@ -850,7 +850,7 @@ mod zk {
|
||||
fn conformance_zk_compact_ciphertext_list() {
|
||||
let mut rng = thread_rng();
|
||||
|
||||
let params = PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
let params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let cpk_params = PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
|
||||
@@ -957,13 +957,12 @@ pub mod gpu {
|
||||
mod tests {
|
||||
use crate::prelude::*;
|
||||
use crate::safe_serialization::{safe_deserialize, safe_serialize};
|
||||
#[cfg(any(not(feature = "gpu"), feature = "strings"))]
|
||||
use crate::shortint::parameters::test_params::TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
#[cfg(feature = "gpu")]
|
||||
use crate::shortint::parameters::COMP_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
#[cfg(feature = "gpu")]
|
||||
use crate::shortint::parameters::PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
use crate::shortint::parameters::{
|
||||
COMP_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
};
|
||||
@@ -984,10 +983,9 @@ mod tests {
|
||||
),
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
(
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128.into(),
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128.into(),
|
||||
COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
),
|
||||
#[cfg(feature = "gpu")]
|
||||
(
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128.into(),
|
||||
COMP_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
@@ -1149,7 +1147,7 @@ mod tests {
|
||||
#[cfg(feature = "strings")]
|
||||
#[test]
|
||||
fn test_compressed_strings_cpu() {
|
||||
let params = TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
let params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let config = crate::ConfigBuilder::with_custom_parameters(params)
|
||||
.enable_compression(COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128)
|
||||
.build();
|
||||
|
||||
@@ -628,25 +628,24 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::prelude::*;
|
||||
use crate::safe_serialization::{safe_deserialize, safe_serialize};
|
||||
use crate::shortint::parameters::test_params::TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
#[cfg(feature = "gpu")]
|
||||
use crate::shortint::parameters::v1_6::{
|
||||
V1_6_NOISE_SQUASHING_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
V1_6_NOISE_SQUASHING_PARAM_GPU_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
V1_6_NOISE_SQUASHING_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
V1_6_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
V1_6_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
};
|
||||
#[cfg(feature = "gpu")]
|
||||
use crate::ConfigBuilder;
|
||||
use crate::{generate_keys, set_server_key, FheBool, FheInt32, FheUint32};
|
||||
use crate::shortint::parameters::current_params::*;
|
||||
use crate::{generate_keys, set_server_key, ConfigBuilder, FheBool, FheInt32, FheUint32};
|
||||
use rand::Rng;
|
||||
|
||||
#[test]
|
||||
fn test_compressed_squashed_noise_ciphertext_list() {
|
||||
let meta_params = TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let params = V1_6_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let noise_squashing_params =
|
||||
V1_6_NOISE_SQUASHING_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let noise_squashing_compression_params =
|
||||
V1_6_NOISE_SQUASHING_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let (cks, sks) = generate_keys(meta_params);
|
||||
let config = ConfigBuilder::with_custom_parameters(params)
|
||||
.enable_noise_squashing(noise_squashing_params)
|
||||
.enable_noise_squashing_compression(noise_squashing_compression_params)
|
||||
.build();
|
||||
|
||||
let (cks, sks) = generate_keys(config);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
|
||||
@@ -238,28 +238,8 @@ impl<Id: FheUintId> FheUint<Id> {
|
||||
Self::new(ct, key.tag.clone(), ReRandomizationMetadata::default())
|
||||
}
|
||||
#[cfg(feature = "gpu")]
|
||||
InternalServerKey::Cuda(cuda_key) => {
|
||||
let message_modulus = cuda_key.message_modulus();
|
||||
|
||||
let num_input_random_bits = num_input_random_bits_for_max_distance(
|
||||
excluded_upper_bound,
|
||||
max_distance,
|
||||
message_modulus,
|
||||
);
|
||||
|
||||
let num_blocks_output = Id::num_blocks(cuda_key.message_modulus()) as u64;
|
||||
|
||||
let ct = cuda_key
|
||||
.pbs_key()
|
||||
.par_generate_oblivious_pseudo_random_unsigned_custom_range(
|
||||
seed,
|
||||
num_input_random_bits,
|
||||
excluded_upper_bound.get(),
|
||||
num_blocks_output,
|
||||
&cuda_key.streams,
|
||||
);
|
||||
|
||||
Self::new(ct, cuda_key.tag.clone(), ReRandomizationMetadata::default())
|
||||
InternalServerKey::Cuda(_cuda_key) => {
|
||||
panic!("Gpu does not support this operation yet.")
|
||||
}
|
||||
#[cfg(feature = "hpu")]
|
||||
InternalServerKey::Hpu(_device) => {
|
||||
@@ -571,8 +551,6 @@ mod test {
|
||||
};
|
||||
use crate::prelude::FheDecrypt;
|
||||
use crate::shortint::oprf::test::test_uniformity;
|
||||
#[cfg(feature = "gpu")]
|
||||
use crate::shortint::parameters::PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
use crate::{generate_keys, set_server_key, ClientKey, ConfigBuilder, FheUint8, Seed};
|
||||
use num_bigint::BigUint;
|
||||
@@ -700,12 +678,19 @@ mod test {
|
||||
(random_input * excluded_upper_bound) >> num_input_random_bits
|
||||
}
|
||||
|
||||
fn test_case_uniformity_generate_oblivious_pseudo_random_custom_range(cks: &ClientKey) {
|
||||
#[test]
|
||||
fn test_uniformity_generate_oblivious_pseudo_random_custom_range() {
|
||||
let base_sample_count: usize = 10_000;
|
||||
|
||||
let p_value_limit: f64 = 0.001;
|
||||
|
||||
let message_modulus = cks.message_modulus();
|
||||
let params = PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
let config = ConfigBuilder::with_custom_parameters(params).build();
|
||||
|
||||
let (cks, sks) = generate_keys(config);
|
||||
rayon::broadcast(|_| set_server_key(sks.clone()));
|
||||
|
||||
let message_modulus = params.message_modulus;
|
||||
|
||||
// [0.7, 0.1] for `max_distance` chosen to have `num_input_random_bits` be [2, 4]
|
||||
// for any of the listed `excluded_upper_bound`
|
||||
@@ -729,7 +714,7 @@ mod test {
|
||||
sample_count,
|
||||
p_value_limit,
|
||||
message_modulus,
|
||||
cks,
|
||||
&cks,
|
||||
excluded_upper_bound,
|
||||
max_distance,
|
||||
);
|
||||
@@ -737,26 +722,6 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uniformity_generate_oblivious_pseudo_random_custom_range_cpu() {
|
||||
let params = PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
let config = ConfigBuilder::with_custom_parameters(params).build();
|
||||
let (cks, sks) = generate_keys(config);
|
||||
rayon::broadcast(|_| set_server_key(sks.clone()));
|
||||
test_case_uniformity_generate_oblivious_pseudo_random_custom_range(&cks);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "gpu")]
|
||||
fn test_uniformity_generate_oblivious_pseudo_random_custom_range_gpu() {
|
||||
let params = PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let config = ConfigBuilder::with_custom_parameters(params).build();
|
||||
let cks = ClientKey::generate(config);
|
||||
let sks = crate::CompressedServerKey::new(&cks).decompress_to_gpu();
|
||||
rayon::broadcast(|_| set_server_key(sks.clone()));
|
||||
test_case_uniformity_generate_oblivious_pseudo_random_custom_range(&cks);
|
||||
}
|
||||
|
||||
fn test_uniformity_generate_oblivious_pseudo_random_custom_range2(
|
||||
sample_count: usize,
|
||||
p_value_limit: f64,
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
use super::{
|
||||
test_case_abs, test_case_flip, test_case_if_then_else, test_case_ilog2,
|
||||
test_case_int32_bitwise, test_case_int32_compare, test_case_int32_div_rem,
|
||||
test_case_int64_rotate, test_case_integer_casting, test_case_integer_compress_decompress,
|
||||
test_case_leading_trailing_zeros_ones, test_case_min_max, test_case_scalar_flip,
|
||||
};
|
||||
use crate::high_level_api::tests::create_parameterized_test;
|
||||
use crate::high_level_api::tests::{setup_cpu, setup_default_cpu};
|
||||
use crate::integer::I256;
|
||||
use crate::prelude::{
|
||||
CiphertextList, FheDecrypt, FheEncrypt, FheTryEncrypt, FheTryTrivialEncrypt,
|
||||
@@ -14,30 +8,16 @@ use crate::shortint::parameters::test_params::{
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS_GAUSSIAN_2M128,
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS_GAUSSIAN_2M128,
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_PBS_KS_GAUSSIAN_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128,
|
||||
};
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
use crate::{
|
||||
generate_keys, set_server_key, ClientKey, CompactCiphertextList, CompactPublicKey,
|
||||
CompressedFheInt16, CompressedFheInt32, CompressedFheInt32ConformanceParams, ConfigBuilder,
|
||||
DeserializationConfig, FheInt256, FheInt32, FheInt32ConformanceParams, FheInt8,
|
||||
SerializationConfig, ServerKey,
|
||||
generate_keys, set_server_key, CompactCiphertextList, CompactPublicKey, CompressedFheInt16,
|
||||
CompressedFheInt32, CompressedFheInt32ConformanceParams, ConfigBuilder, DeserializationConfig,
|
||||
FheInt256, FheInt32, FheInt32ConformanceParams, FheInt8, SerializationConfig,
|
||||
};
|
||||
use rand::{random, thread_rng, Rng};
|
||||
|
||||
create_parameterized_test!(test_case_int32_compare);
|
||||
create_parameterized_test!(test_case_int32_bitwise);
|
||||
create_parameterized_test!(test_case_int64_rotate);
|
||||
create_parameterized_test!(test_case_int32_div_rem);
|
||||
create_parameterized_test!(test_case_integer_casting);
|
||||
create_parameterized_test!(test_case_if_then_else);
|
||||
create_parameterized_test!(test_case_flip);
|
||||
create_parameterized_test!(test_case_scalar_flip);
|
||||
create_parameterized_test!(test_case_abs);
|
||||
create_parameterized_test!(test_case_min_max);
|
||||
create_parameterized_test!(test_case_ilog2);
|
||||
create_parameterized_test!(test_case_leading_trailing_zeros_ones);
|
||||
create_parameterized_test!(test_case_integer_compress_decompress);
|
||||
|
||||
#[test]
|
||||
fn test_signed_integer_compressed() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
@@ -66,6 +46,88 @@ fn test_integer_compressed_small() {
|
||||
assert_eq!(clear_decompressed, clear);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_int32_compare() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_int32_compare(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_int32_bitwise() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_int32_bitwise(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_int64_rotate() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_int64_rotate(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multi_bit_rotate() {
|
||||
let client_key = setup_cpu(Some(
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128,
|
||||
));
|
||||
super::test_case_int64_rotate(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_int32_div_rem() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_int32_div_rem(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multi_div_rem() {
|
||||
let client_key = setup_cpu(Some(
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128,
|
||||
));
|
||||
super::test_case_int32_div_rem(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_integer_casting() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_integer_casting(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_if_then_else() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_if_then_else(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_flip() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_flip(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scalar_flip() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_scalar_flip(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_abs() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_abs(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_integer_compress_decompress() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_integer_compress_decompress(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_min_max() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_min_max(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trivial_fhe_int8() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
@@ -93,7 +155,6 @@ fn test_trivial_fhe_int256_small() {
|
||||
let clear: I256 = a.decrypt(&client_key);
|
||||
assert_eq!(clear, clear_a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_compact_public_key_big() {
|
||||
let config = ConfigBuilder::default()
|
||||
@@ -130,73 +191,65 @@ fn test_compact_public_key_small() {
|
||||
assert_eq!(clear, -123i8);
|
||||
}
|
||||
|
||||
fn test_case_safe_deserialize_conformant_fhe_int32(client_key: &ClientKey, server_key: &ServerKey) {
|
||||
#[test]
|
||||
fn test_ilog2() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_ilog2(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_leading_trailing_zeros_ones() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_leading_trailing_zeros_ones(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_safe_deserialize_conformant_fhe_int32() {
|
||||
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let (client_key, server_key) =
|
||||
generate_keys(ConfigBuilder::with_custom_parameters(block_params));
|
||||
set_server_key(server_key.clone());
|
||||
|
||||
let clear_a = random::<i32>();
|
||||
let a = FheInt32::encrypt(clear_a, client_key);
|
||||
let a = FheInt32::encrypt(clear_a, &client_key);
|
||||
let mut serialized = vec![];
|
||||
SerializationConfig::new(1 << 20)
|
||||
.serialize_into(&a, &mut serialized)
|
||||
.unwrap();
|
||||
|
||||
let params = FheInt32ConformanceParams::from(server_key);
|
||||
let params = FheInt32ConformanceParams::from(&server_key);
|
||||
let deserialized_a = DeserializationConfig::new(1 << 20)
|
||||
.deserialize_from::<FheInt32>(serialized.as_slice(), ¶ms)
|
||||
.unwrap();
|
||||
let decrypted: i32 = deserialized_a.decrypt(client_key);
|
||||
let decrypted: i32 = deserialized_a.decrypt(&client_key);
|
||||
assert_eq!(decrypted, clear_a);
|
||||
|
||||
let params = FheInt32ConformanceParams::from(block_params);
|
||||
assert!(deserialized_a.is_conformant(¶ms));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_safe_deserialize_conformant_fhe_int32_default() {
|
||||
let (client_key, server_key) = generate_keys(ConfigBuilder::default());
|
||||
fn test_safe_deserialize_conformant_compressed_fhe_int32() {
|
||||
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let (client_key, server_key) =
|
||||
generate_keys(ConfigBuilder::with_custom_parameters(block_params));
|
||||
set_server_key(server_key.clone());
|
||||
test_case_safe_deserialize_conformant_fhe_int32(&client_key, &server_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_safe_deserialize_conformant_fhe_int32_prod_param() {
|
||||
let (client_key, server_key) = generate_keys(ConfigBuilder::with_custom_parameters(
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
));
|
||||
set_server_key(server_key.clone());
|
||||
test_case_safe_deserialize_conformant_fhe_int32(&client_key, &server_key);
|
||||
}
|
||||
|
||||
fn test_case_safe_deserialize_conformant_compressed_fhe_int32(
|
||||
client_key: &ClientKey,
|
||||
server_key: &ServerKey,
|
||||
) {
|
||||
let clear_a = random::<i32>();
|
||||
let a = CompressedFheInt32::encrypt(clear_a, client_key);
|
||||
let a = CompressedFheInt32::encrypt(clear_a, &client_key);
|
||||
let mut serialized = vec![];
|
||||
SerializationConfig::new(1 << 20)
|
||||
.serialize_into(&a, &mut serialized)
|
||||
.unwrap();
|
||||
|
||||
let params = CompressedFheInt32ConformanceParams::from(server_key);
|
||||
let params = CompressedFheInt32ConformanceParams::from(&server_key);
|
||||
let deserialized_a = DeserializationConfig::new(1 << 20)
|
||||
.deserialize_from::<CompressedFheInt32>(serialized.as_slice(), ¶ms)
|
||||
.unwrap();
|
||||
|
||||
let params = CompressedFheInt32ConformanceParams::from(block_params);
|
||||
assert!(deserialized_a.is_conformant(¶ms));
|
||||
|
||||
let decrypted: i32 = deserialized_a.decompress().decrypt(client_key);
|
||||
let decrypted: i32 = deserialized_a.decompress().decrypt(&client_key);
|
||||
assert_eq!(decrypted, clear_a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_safe_deserialize_conformant_compressed_fhe_int32_default() {
|
||||
let (client_key, server_key) = generate_keys(ConfigBuilder::default());
|
||||
set_server_key(server_key.clone());
|
||||
test_case_safe_deserialize_conformant_compressed_fhe_int32(&client_key, &server_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_safe_deserialize_conformant_compressed_fhe_int32_prod_param() {
|
||||
let (client_key, server_key) = generate_keys(ConfigBuilder::with_custom_parameters(
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
));
|
||||
set_server_key(server_key.clone());
|
||||
test_case_safe_deserialize_conformant_compressed_fhe_int32(&client_key, &server_key);
|
||||
}
|
||||
|
||||
@@ -443,14 +443,11 @@ fn test_case_abs(cks: &ClientKey) {
|
||||
}
|
||||
|
||||
fn test_case_integer_compress_decompress(cks: &ClientKey) {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let clear_a: i8 = rng.gen();
|
||||
let a = FheInt8::try_encrypt(clear_a, cks).unwrap();
|
||||
let a = FheInt8::try_encrypt(-83i8, cks).unwrap();
|
||||
|
||||
let clear: i8 = a.compress().decompress().decrypt(cks);
|
||||
|
||||
assert_eq!(clear, clear_a);
|
||||
assert_eq!(clear, -83i8);
|
||||
}
|
||||
|
||||
fn test_case_leading_trailing_zeros_ones(cks: &ClientKey) {
|
||||
|
||||
@@ -1850,10 +1850,7 @@ mod test {
|
||||
use super::*;
|
||||
use crate::core_crypto::prelude::UnsignedInteger;
|
||||
use crate::prelude::*;
|
||||
use crate::shortint::parameters::{
|
||||
AtomicPatternKind, PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||
};
|
||||
use crate::shortint::parameters::{AtomicPatternKind, PARAM_MESSAGE_2_CARRY_2_KS_PBS};
|
||||
use crate::shortint::{CiphertextModulus, PBSOrder};
|
||||
use crate::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
|
||||
use rand::{thread_rng, Rng};
|
||||
@@ -1883,7 +1880,7 @@ mod test {
|
||||
let ct = FheUint8::try_encrypt(0_u64, &client_key).unwrap();
|
||||
|
||||
assert!(ct.is_conformant(&FheUintConformanceParams::from(
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||
)));
|
||||
|
||||
let breaker_lists = [
|
||||
@@ -1943,7 +1940,7 @@ mod test {
|
||||
breaker(i, &mut ct_clone);
|
||||
|
||||
assert!(!ct_clone.is_conformant(&FheUintConformanceParams::from(
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||
)));
|
||||
}
|
||||
}
|
||||
@@ -1960,7 +1957,7 @@ mod test {
|
||||
let ct = FheUint8::try_encrypt(0_u64, &client_key).unwrap();
|
||||
|
||||
assert!(ct.is_conformant(&FheUintConformanceParams::from(
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||
)));
|
||||
|
||||
let mut rng = thread_rng();
|
||||
@@ -1978,7 +1975,7 @@ mod test {
|
||||
}
|
||||
|
||||
assert!(ct.is_conformant(&FheUintConformanceParams::from(
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||
)));
|
||||
|
||||
ct_clone += &ct_clone.clone();
|
||||
|
||||
@@ -263,7 +263,7 @@ where
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::core_crypto::prelude::UnsignedInteger;
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
use crate::shortint::{CiphertextModulus, CompressedCiphertext};
|
||||
use crate::{generate_keys, set_server_key, CompressedFheUint8, ConfigBuilder};
|
||||
use rand::{thread_rng, Rng};
|
||||
@@ -315,7 +315,7 @@ mod test {
|
||||
let ct = CompressedFheUint8::try_encrypt(0_u64, &client_key).unwrap();
|
||||
|
||||
assert!(ct.is_conformant(&CompressedFheUintConformanceParams::from(
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
)));
|
||||
|
||||
let breaker_lists = [
|
||||
@@ -340,7 +340,7 @@ mod test {
|
||||
|
||||
assert!(
|
||||
!ct_clone.is_conformant(&CompressedFheUintConformanceParams::from(
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
))
|
||||
);
|
||||
}
|
||||
@@ -373,7 +373,7 @@ mod test {
|
||||
|
||||
assert!(
|
||||
!ct_clone.is_conformant(&CompressedFheUintConformanceParams::from(
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
))
|
||||
);
|
||||
}
|
||||
@@ -391,7 +391,7 @@ mod test {
|
||||
let ct = CompressedFheUint8::try_encrypt(0_u64, &client_key).unwrap();
|
||||
|
||||
assert!(ct.is_conformant(&CompressedFheUintConformanceParams::from(
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
)));
|
||||
|
||||
let mut rng = thread_rng();
|
||||
@@ -410,10 +410,9 @@ mod test {
|
||||
.seed
|
||||
.0 = rng.gen::<u128>();
|
||||
}
|
||||
|
||||
assert!(
|
||||
ct_clone.is_conformant(&CompressedFheUintConformanceParams::from(
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
))
|
||||
);
|
||||
|
||||
|
||||
@@ -1,112 +1,18 @@
|
||||
use crate::conformance::ListSizeConstraint;
|
||||
use crate::high_level_api::prelude::*;
|
||||
use crate::high_level_api::tests::create_parameterized_test;
|
||||
use crate::high_level_api::tests::{setup_cpu, setup_default_cpu};
|
||||
use crate::high_level_api::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
|
||||
use crate::integer::U256;
|
||||
use crate::safe_serialization::{DeserializationConfig, SerializationConfig};
|
||||
use crate::shortint::parameters::test_params::*;
|
||||
use crate::{CompressedFheUint256, CompressedPublicKey, FheUint256};
|
||||
|
||||
use super::{
|
||||
test_case_bitslice, test_case_clone, test_case_flip, test_case_if_then_else,
|
||||
test_case_if_then_zero, test_case_ilog2, test_case_integer_casting, test_case_is_even_is_odd,
|
||||
test_case_leading_trailing_zeros_ones, test_case_match_value, test_case_match_value_or,
|
||||
test_case_min_max, test_case_scalar_flip, test_case_sum, test_case_uint256_trivial,
|
||||
test_case_uint32_arith, test_case_uint32_arith_assign, test_case_uint32_bitwise,
|
||||
test_case_uint32_bitwise_assign, test_case_uint32_div_rem, test_case_uint32_quickstart,
|
||||
test_case_uint32_rotate, test_case_uint32_scalar_arith, test_case_uint32_scalar_arith_assign,
|
||||
test_case_uint32_scalar_bitwise, test_case_uint32_shift, test_case_uint64_quickstart,
|
||||
test_case_uint8_compare, test_case_uint8_compare_scalar, test_case_uint8_quickstart,
|
||||
test_case_uint8_trivial, test_dedicated_compact_public_key,
|
||||
test_dedicated_compressed_compact_public_key, test_integer_compress_decompress,
|
||||
test_integer_compressed, test_safe_deserialize_conformant_compact_fhe_uint32,
|
||||
test_safe_deserialize_conformant_compressed_fhe_uint32,
|
||||
test_safe_deserialize_conformant_fhe_uint32, test_scalar_shift_when_clear_type_is_small,
|
||||
use crate::shortint::parameters::*;
|
||||
use crate::{
|
||||
ClientKey, CompactCiphertextList, CompactCiphertextListConformanceParams, CompactPublicKey,
|
||||
CompressedCompactPublicKey, CompressedFheUint16, CompressedFheUint256, CompressedFheUint32,
|
||||
CompressedFheUint32ConformanceParams, CompressedPublicKey, CompressedServerKey, FheInt16,
|
||||
FheInt32, FheInt8, FheUint128, FheUint16, FheUint256, FheUint32, FheUint32ConformanceParams,
|
||||
};
|
||||
|
||||
create_parameterized_test!(test_case_match_value_or);
|
||||
create_parameterized_test!(test_case_uint8_quickstart);
|
||||
create_parameterized_test!(test_case_uint32_quickstart);
|
||||
create_parameterized_test!(test_case_uint64_quickstart);
|
||||
create_parameterized_test!(test_case_uint32_arith);
|
||||
create_parameterized_test!(test_case_uint32_arith_assign);
|
||||
create_parameterized_test!(test_case_uint32_scalar_arith);
|
||||
create_parameterized_test!(test_case_uint32_scalar_arith_assign);
|
||||
create_parameterized_test!(test_case_clone);
|
||||
create_parameterized_test!(test_case_uint8_compare);
|
||||
create_parameterized_test!(test_case_uint8_compare_scalar);
|
||||
create_parameterized_test!(test_case_uint32_shift);
|
||||
create_parameterized_test!(test_case_uint32_bitwise);
|
||||
create_parameterized_test!(test_case_uint32_bitwise_assign);
|
||||
create_parameterized_test!(test_case_uint32_scalar_bitwise);
|
||||
create_parameterized_test!(test_case_uint32_rotate);
|
||||
create_parameterized_test!(test_case_uint32_div_rem);
|
||||
create_parameterized_test!(test_case_if_then_else);
|
||||
create_parameterized_test!(test_case_flip);
|
||||
create_parameterized_test!(test_case_scalar_flip);
|
||||
create_parameterized_test!(test_case_ilog2);
|
||||
create_parameterized_test!(test_case_is_even_is_odd);
|
||||
create_parameterized_test!(test_case_bitslice);
|
||||
create_parameterized_test!(test_case_leading_trailing_zeros_ones);
|
||||
create_parameterized_test!(test_case_sum);
|
||||
create_parameterized_test!(test_case_min_max);
|
||||
create_parameterized_test!(test_case_match_value);
|
||||
create_parameterized_test!(test_case_uint8_trivial);
|
||||
create_parameterized_test!(test_case_uint256_trivial);
|
||||
create_parameterized_test!(test_case_integer_casting);
|
||||
create_parameterized_test!(test_scalar_shift_when_clear_type_is_small);
|
||||
create_parameterized_test!(test_integer_compress_decompress);
|
||||
create_parameterized_test!(test_safe_deserialize_conformant_compact_fhe_uint32);
|
||||
create_parameterized_test!(test_integer_compressed);
|
||||
create_parameterized_test!(test_case_if_then_zero);
|
||||
|
||||
#[test]
|
||||
fn test_safe_deserialize_conformant_fhe_uint32_default() {
|
||||
let (client_key, server_key) = generate_keys(ConfigBuilder::default());
|
||||
test_safe_deserialize_conformant_fhe_uint32(&client_key, &server_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_safe_deserialize_conformant_compressed_fhe_uint32_default() {
|
||||
let (client_key, server_key) = generate_keys(ConfigBuilder::default());
|
||||
test_safe_deserialize_conformant_compressed_fhe_uint32(&client_key, &server_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_integer_compressed_small() {
|
||||
let config =
|
||||
ConfigBuilder::with_custom_parameters(TEST_PARAM_MESSAGE_2_CARRY_2_PBS_KS_GAUSSIAN_2M128)
|
||||
.build();
|
||||
let (client_key, _) = generate_keys(config);
|
||||
test_integer_compressed(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dedicated_compact_public_default() {
|
||||
let param_fhe = TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
let param_pke_only = TEST_PARAM_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128_ZKV2;
|
||||
let param_ksk = TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let config = ConfigBuilder::with_custom_parameters(param_fhe)
|
||||
.use_dedicated_compact_public_key_parameters((param_pke_only, param_ksk))
|
||||
.build();
|
||||
let (client_key, sks) = generate_keys(config);
|
||||
set_server_key(sks);
|
||||
test_dedicated_compact_public_key(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dedicated_compressed_compact_public_default() {
|
||||
let param_fhe = TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
let param_pke_only = TEST_PARAM_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128_ZKV2;
|
||||
let param_ksk = TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let config = ConfigBuilder::with_custom_parameters(param_fhe)
|
||||
.use_dedicated_compact_public_key_parameters((param_pke_only, param_ksk))
|
||||
.build();
|
||||
let (client_key, sks) = generate_keys(config);
|
||||
|
||||
set_server_key(sks);
|
||||
test_dedicated_compressed_compact_public_key(&client_key);
|
||||
}
|
||||
use rand::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn test_integer_compressed_can_be_serialized() {
|
||||
@@ -125,15 +31,176 @@ fn test_integer_compressed_can_be_serialized() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_case_uint64_quickstart_small() {
|
||||
fn test_integer_compressed() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let (client_key, _) = generate_keys(config);
|
||||
|
||||
let clear = 12_837u16;
|
||||
let compressed = CompressedFheUint16::try_encrypt(clear, &client_key).unwrap();
|
||||
let decompressed = FheUint16::from(compressed.decompress());
|
||||
let clear_decompressed: u16 = decompressed.decrypt(&client_key);
|
||||
assert_eq!(clear_decompressed, clear);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_integer_compressed_small() {
|
||||
let config =
|
||||
ConfigBuilder::with_custom_parameters(TEST_PARAM_MESSAGE_2_CARRY_2_PBS_KS_GAUSSIAN_2M128)
|
||||
.build();
|
||||
let (client_key, _) = generate_keys(config);
|
||||
|
||||
let clear = 12_837u16;
|
||||
let compressed = CompressedFheUint16::try_encrypt(clear, &client_key).unwrap();
|
||||
let decompressed = FheUint16::from(compressed.decompress());
|
||||
let clear_decompressed: u16 = decompressed.decrypt(&client_key);
|
||||
assert_eq!(clear_decompressed, clear);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint8_quickstart() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint8_quickstart(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_quickstart() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint32_quickstart(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint64_quickstart() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint64_quickstart(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_arith() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint32_arith(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_arith_assign() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint32_arith_assign(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_scalar_arith() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint32_scalar_arith(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_scalar_arith_assign() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint32_scalar_arith_assign(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_clone() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_clone(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint8_compare() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint8_compare(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint8_compare_scalar() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint8_compare_scalar(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_shift() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint32_shift(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_shift_multibit() {
|
||||
let config = ConfigBuilder::default()
|
||||
.use_custom_parameters(TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M64)
|
||||
.build();
|
||||
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
set_server_key(server_key);
|
||||
super::test_case_uint32_shift(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_bitwise() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint32_bitwise(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_bitwise_assign() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint32_bitwise_assign(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_scalar_bitwise() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint32_scalar_bitwise(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_rotate() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint32_rotate(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multi_bit_rotate() {
|
||||
let client_key = setup_cpu(Some(
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M64,
|
||||
));
|
||||
super::test_case_uint32_rotate(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint32_div_rem() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint32_div_rem(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multi_div_rem() {
|
||||
let client_key = setup_cpu(Some(
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M64,
|
||||
));
|
||||
super::test_case_uint32_div_rem(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_small_uint128() {
|
||||
let config =
|
||||
ConfigBuilder::with_custom_parameters(TEST_PARAM_MESSAGE_2_CARRY_2_PBS_KS_GAUSSIAN_2M128)
|
||||
.build();
|
||||
|
||||
let (cks, sks) = generate_keys(config);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let clear_a = rng.gen::<u128>();
|
||||
let clear_b = rng.gen::<u128>();
|
||||
|
||||
let a = FheUint128::try_encrypt(clear_a, &cks).unwrap();
|
||||
let b = FheUint128::try_encrypt(clear_b, &cks).unwrap();
|
||||
|
||||
set_server_key(sks);
|
||||
|
||||
test_case_uint64_quickstart(&cks);
|
||||
let c = a + b;
|
||||
|
||||
let decrypted: u128 = c.decrypt(&cks);
|
||||
assert_eq!(decrypted, clear_a.wrapping_add(clear_b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -160,3 +227,442 @@ fn test_decompressed_public_key_encrypt() {
|
||||
let clear: u8 = a.decrypt(&client_key);
|
||||
assert_eq!(clear, 255u8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_compact_public_key_big() {
|
||||
let config = ConfigBuilder::default()
|
||||
.use_custom_parameters(TEST_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS_GAUSSIAN_2M128)
|
||||
.build();
|
||||
let (client_key, _) = generate_keys(config);
|
||||
|
||||
let public_key = CompactPublicKey::new(&client_key);
|
||||
let compact_list = CompactCiphertextList::builder(&public_key)
|
||||
.push(255u8)
|
||||
.build();
|
||||
let expanded = compact_list.expand().unwrap();
|
||||
let a: FheUint8 = expanded.get(0).unwrap().unwrap();
|
||||
|
||||
let clear: u8 = a.decrypt(&client_key);
|
||||
assert_eq!(clear, 255u8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_compact_public_key_small() {
|
||||
let config = ConfigBuilder::default()
|
||||
.use_custom_parameters(TEST_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS_GAUSSIAN_2M128)
|
||||
.build();
|
||||
let (client_key, _) = generate_keys(config);
|
||||
|
||||
let public_key = CompactPublicKey::new(&client_key);
|
||||
let compact_list = CompactCiphertextList::builder(&public_key)
|
||||
.push(255u8)
|
||||
.build();
|
||||
let expanded = compact_list.expand().unwrap();
|
||||
let a: FheUint8 = expanded.get(0).unwrap().unwrap();
|
||||
|
||||
let clear: u8 = a.decrypt(&client_key);
|
||||
assert_eq!(clear, 255u8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_integer_compress_decompress() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
set_server_key(server_key);
|
||||
|
||||
let a = FheUint8::try_encrypt(213u8, &client_key).unwrap();
|
||||
|
||||
let clear: u8 = a.compress().decompress().decrypt(&client_key);
|
||||
|
||||
assert_eq!(clear, 213u8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trivial_uint8() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint8_trivial(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trivial_uint256_small() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_uint256_trivial(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_integer_casting() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
set_server_key(server_key);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let clear = rng.gen::<u16>();
|
||||
|
||||
// Downcasting then Upcasting
|
||||
{
|
||||
let a = FheUint16::encrypt(clear, &client_key);
|
||||
|
||||
// Downcasting
|
||||
let a: FheUint8 = a.cast_into();
|
||||
let da: u8 = a.decrypt(&client_key);
|
||||
assert_eq!(da, clear as u8);
|
||||
|
||||
// Upcasting
|
||||
let a: FheUint32 = a.cast_into();
|
||||
let da: u32 = a.decrypt(&client_key);
|
||||
assert_eq!(da, (clear as u8) as u32);
|
||||
}
|
||||
|
||||
// Upcasting then Downcasting
|
||||
{
|
||||
let a = FheUint16::encrypt(clear, &client_key);
|
||||
|
||||
// Upcasting
|
||||
let a = FheUint32::cast_from(a);
|
||||
let da: u32 = a.decrypt(&client_key);
|
||||
assert_eq!(da, clear as u32);
|
||||
|
||||
// Downcasting
|
||||
let a = FheUint8::cast_from(a);
|
||||
let da: u8 = a.decrypt(&client_key);
|
||||
assert_eq!(da, (clear as u32) as u8);
|
||||
}
|
||||
|
||||
// Casting to self, it not useful but is supported
|
||||
{
|
||||
let a = FheUint16::encrypt(clear, &client_key);
|
||||
let a = FheUint16::cast_from(a);
|
||||
let da: u16 = a.decrypt(&client_key);
|
||||
assert_eq!(da, clear);
|
||||
}
|
||||
|
||||
// Downcasting to smaller signed integer then Upcasting back to unsigned
|
||||
{
|
||||
let clear = rng.gen_range((i16::MAX) as u16 + 1..u16::MAX);
|
||||
let a = FheUint16::encrypt(clear, &client_key);
|
||||
|
||||
// Downcasting
|
||||
let a: FheInt8 = a.cast_into();
|
||||
let da: i8 = a.decrypt(&client_key);
|
||||
assert_eq!(da, clear as i8);
|
||||
|
||||
// Upcasting
|
||||
let a: FheUint32 = a.cast_into();
|
||||
let da: u32 = a.decrypt(&client_key);
|
||||
assert_eq!(da, (clear as i8) as u32);
|
||||
}
|
||||
|
||||
{
|
||||
let clear = rng.gen_range(i16::MIN..0);
|
||||
let a = FheInt16::encrypt(clear, &client_key);
|
||||
|
||||
// Upcasting
|
||||
let a: FheUint32 = a.cast_into();
|
||||
let da: u32 = a.decrypt(&client_key);
|
||||
assert_eq!(da, clear as u32);
|
||||
}
|
||||
|
||||
// Upcasting to bigger signed integer then downcasting back to unsigned
|
||||
{
|
||||
let clear = rng.gen_range((i16::MAX) as u16 + 1..u16::MAX);
|
||||
let a = FheUint16::encrypt(clear, &client_key);
|
||||
|
||||
// Upcasting
|
||||
let a: FheInt32 = a.cast_into();
|
||||
let da: i32 = a.decrypt(&client_key);
|
||||
assert_eq!(da, clear as i32);
|
||||
|
||||
// Downcasting
|
||||
let a: FheUint16 = a.cast_into();
|
||||
let da: u16 = a.decrypt(&client_key);
|
||||
assert_eq!(da, (clear as i32) as u16);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_if_then_else() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_if_then_else(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_if_then_zero() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_if_then_zero(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_flip() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_flip(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scalar_flip() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_scalar_flip(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scalar_shift_when_clear_type_is_small() {
|
||||
// This is a regression tests
|
||||
// The goal is to make sure that doing a scalar shift / rotate
|
||||
// with a clear type that does not have enough bits to represent
|
||||
// the number of bits of the fhe type correctly works.
|
||||
|
||||
let config = ConfigBuilder::default().build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
set_server_key(server_key);
|
||||
|
||||
let mut a = FheUint256::encrypt(U256::ONE, &client_key);
|
||||
// The fhe type has 256 bits, the clear type is u8,
|
||||
// a u8 cannot represent the value '256'.
|
||||
// This used to result in the shift/rotate panicking
|
||||
let clear = 1u8;
|
||||
|
||||
let _ = &a << clear;
|
||||
let _ = &a >> clear;
|
||||
let _ = (&a).rotate_left(clear);
|
||||
let _ = (&a).rotate_right(clear);
|
||||
|
||||
a <<= clear;
|
||||
a >>= clear;
|
||||
a.rotate_left_assign(clear);
|
||||
a.rotate_right_assign(clear);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ilog2() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_ilog2(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_even_is_odd() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_is_even_is_odd(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bitslice() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_bitslice(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_leading_trailing_zeros_ones() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_leading_trailing_zeros_ones(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sum() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_sum(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_min_max() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_min_max(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_match_value() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_match_value(&client_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_safe_deserialize_conformant_fhe_uint32() {
|
||||
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let (client_key, server_key) =
|
||||
generate_keys(ConfigBuilder::with_custom_parameters(block_params));
|
||||
set_server_key(server_key.clone());
|
||||
|
||||
let clear_a = random::<u32>();
|
||||
let a = FheUint32::encrypt(clear_a, &client_key);
|
||||
let mut serialized = vec![];
|
||||
SerializationConfig::new(1 << 20)
|
||||
.serialize_into(&a, &mut serialized)
|
||||
.unwrap();
|
||||
|
||||
let params = FheUint32ConformanceParams::from(&server_key);
|
||||
let deserialized_a = DeserializationConfig::new(1 << 20)
|
||||
.deserialize_from::<FheUint32>(serialized.as_slice(), ¶ms)
|
||||
.unwrap();
|
||||
let decrypted: u32 = deserialized_a.decrypt(&client_key);
|
||||
assert_eq!(decrypted, clear_a);
|
||||
|
||||
assert!(deserialized_a.is_conformant(&FheUint32ConformanceParams::from(block_params)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_safe_deserialize_conformant_compressed_fhe_uint32() {
|
||||
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
let (client_key, server_key) =
|
||||
generate_keys(ConfigBuilder::with_custom_parameters(block_params));
|
||||
set_server_key(server_key.clone());
|
||||
|
||||
let clear_a = random::<u32>();
|
||||
let a = CompressedFheUint32::encrypt(clear_a, &client_key);
|
||||
let mut serialized = vec![];
|
||||
SerializationConfig::new(1 << 20)
|
||||
.serialize_into(&a, &mut serialized)
|
||||
.unwrap();
|
||||
|
||||
let params = CompressedFheUint32ConformanceParams::from(&server_key);
|
||||
let deserialized_a = DeserializationConfig::new(1 << 20)
|
||||
.deserialize_from::<CompressedFheUint32>(serialized.as_slice(), ¶ms)
|
||||
.unwrap();
|
||||
|
||||
assert!(deserialized_a.is_conformant(&CompressedFheUint32ConformanceParams::from(block_params)));
|
||||
|
||||
let decrypted: u32 = deserialized_a.decompress().decrypt(&client_key);
|
||||
assert_eq!(decrypted, clear_a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_safe_deserialize_conformant_compact_fhe_uint32() {
|
||||
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
let (client_key, server_key) =
|
||||
generate_keys(ConfigBuilder::with_custom_parameters(block_params));
|
||||
set_server_key(server_key);
|
||||
let pk = CompactPublicKey::new(&client_key);
|
||||
|
||||
let clears = [random::<u32>(), random::<u32>(), random::<u32>()];
|
||||
let a = CompactCiphertextList::builder(&pk)
|
||||
.extend(clears.iter().copied())
|
||||
.build();
|
||||
let mut serialized = vec![];
|
||||
SerializationConfig::new(1 << 20)
|
||||
.serialize_into(&a, &mut serialized)
|
||||
.unwrap();
|
||||
|
||||
let params = CompactCiphertextListConformanceParams::from_parameters_and_size_constraint(
|
||||
pk.parameters(),
|
||||
ListSizeConstraint::exact_size(clears.len()),
|
||||
)
|
||||
.allow_unpacked();
|
||||
let deserialized_a = DeserializationConfig::new(1 << 20)
|
||||
.deserialize_from::<CompactCiphertextList>(serialized.as_slice(), ¶ms)
|
||||
.unwrap();
|
||||
|
||||
let expander = deserialized_a.expand().unwrap();
|
||||
for (i, clear) in clears.into_iter().enumerate() {
|
||||
let encrypted: FheUint32 = expander.get(i).unwrap().unwrap();
|
||||
let decrypted: u32 = encrypted.decrypt(&client_key);
|
||||
assert_eq!(decrypted, clear);
|
||||
}
|
||||
|
||||
assert!(deserialized_a.is_conformant(¶ms));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cpk_encrypt_cast_compute_hl() {
|
||||
let param_pke_only = PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let param_fhe = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let param_ksk = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let num_block = 4usize;
|
||||
|
||||
assert_eq!(param_pke_only.message_modulus, param_fhe.message_modulus);
|
||||
assert_eq!(param_pke_only.carry_modulus, param_fhe.carry_modulus);
|
||||
|
||||
let modulus = param_fhe.message_modulus.0.pow(num_block as u32);
|
||||
|
||||
let (client_key, server_key) = generate_keys(
|
||||
ConfigBuilder::with_custom_parameters(param_fhe)
|
||||
.use_dedicated_compact_public_key_parameters((param_pke_only, param_ksk)),
|
||||
);
|
||||
set_server_key(server_key);
|
||||
|
||||
use rand::Rng;
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let input_msg: u64 = rng.gen_range(0..modulus);
|
||||
|
||||
let pk = CompactPublicKey::new(&client_key);
|
||||
|
||||
// Encrypt a value and cast
|
||||
let mut builder = CompactCiphertextList::builder(&pk);
|
||||
let list = builder
|
||||
.push_with_num_bits(input_msg, 8)
|
||||
.unwrap()
|
||||
.build_packed();
|
||||
|
||||
let expander = list.expand().unwrap();
|
||||
let ct1_extracted_and_cast = expander.get::<FheUint8>(0).unwrap().unwrap();
|
||||
|
||||
let sanity_cast: u64 = ct1_extracted_and_cast.decrypt(&client_key);
|
||||
assert_eq!(sanity_cast, input_msg);
|
||||
|
||||
let multiplier = rng.gen_range(0..modulus);
|
||||
|
||||
// Classical AP: DP, KS, PBS
|
||||
let mul = &ct1_extracted_and_cast * multiplier as u8;
|
||||
|
||||
// High level decryption and test
|
||||
let clear: u64 = mul.decrypt(&client_key);
|
||||
assert_eq!(clear, (input_msg * multiplier) % modulus);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_compressed_cpk_encrypt_cast_compute_hl() {
|
||||
let param_pke_only = PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let param_fhe = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let param_ksk = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let num_block = 4usize;
|
||||
|
||||
assert_eq!(param_pke_only.message_modulus, param_fhe.message_modulus);
|
||||
assert_eq!(param_pke_only.carry_modulus, param_fhe.carry_modulus);
|
||||
|
||||
let modulus = param_fhe.message_modulus.0.pow(num_block as u32);
|
||||
|
||||
let config = ConfigBuilder::with_custom_parameters(param_fhe)
|
||||
.use_dedicated_compact_public_key_parameters((param_pke_only, param_ksk))
|
||||
.build();
|
||||
let client_key = ClientKey::generate(config);
|
||||
let compressed_server_key = CompressedServerKey::new(&client_key);
|
||||
let server_key = compressed_server_key.decompress();
|
||||
|
||||
set_server_key(server_key);
|
||||
|
||||
use rand::Rng;
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let input_msg: u64 = rng.gen_range(0..modulus);
|
||||
|
||||
let compressed_pk = CompressedCompactPublicKey::new(&client_key);
|
||||
let pk = compressed_pk.decompress();
|
||||
|
||||
// Encrypt a value and cast
|
||||
let mut builder = CompactCiphertextList::builder(&pk);
|
||||
let list = builder
|
||||
.push_with_num_bits(input_msg, 8)
|
||||
.unwrap()
|
||||
.build_packed();
|
||||
|
||||
let expander = list.expand().unwrap();
|
||||
let ct1_extracted_and_cast = expander.get::<FheUint8>(0).unwrap().unwrap();
|
||||
|
||||
let sanity_cast: u64 = ct1_extracted_and_cast.decrypt(&client_key);
|
||||
assert_eq!(sanity_cast, input_msg);
|
||||
|
||||
let multiplier = rng.gen_range(0..modulus);
|
||||
|
||||
// Classical AP: DP, KS, PBS
|
||||
let mul = &ct1_extracted_and_cast * multiplier as u8;
|
||||
|
||||
// High level decryption and test
|
||||
let clear: u64 = mul.decrypt(&client_key);
|
||||
assert_eq!(clear, (input_msg * multiplier) % modulus);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_match_value_or() {
|
||||
let client_key = setup_default_cpu();
|
||||
super::test_case_match_value_or(&client_key);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
use crate::conformance::ListSizeConstraint;
|
||||
use crate::high_level_api::traits::BitSlice;
|
||||
use crate::integer::U256;
|
||||
use crate::prelude::*;
|
||||
use crate::{
|
||||
ClientKey, CompactCiphertextList, CompactCiphertextListConformanceParams, CompactPublicKey,
|
||||
CompressedCompactPublicKey, CompressedFheUint16, CompressedFheUint32,
|
||||
CompressedFheUint32ConformanceParams, DeserializationConfig, FheBool, FheInt16, FheInt32,
|
||||
FheInt8, FheUint16, FheUint256, FheUint32, FheUint32ConformanceParams, FheUint64, FheUint8,
|
||||
MatchValues, SerializationConfig, ServerKey,
|
||||
};
|
||||
use rand::{random, thread_rng, Rng};
|
||||
use crate::{ClientKey, FheBool, FheUint256, FheUint32, FheUint64, FheUint8, MatchValues};
|
||||
use rand::{thread_rng, Rng};
|
||||
use std::collections::HashMap;
|
||||
|
||||
mod cpu;
|
||||
@@ -306,193 +299,6 @@ fn test_case_uint8_compare_scalar(client_key: &ClientKey) {
|
||||
assert_eq!(decrypted_result, clear_result);
|
||||
}
|
||||
|
||||
fn test_safe_deserialize_conformant_fhe_uint32(client_key: &ClientKey, server_key: &ServerKey) {
|
||||
let clear_a = random::<u32>();
|
||||
let a = FheUint32::encrypt(clear_a, client_key);
|
||||
let mut serialized = vec![];
|
||||
SerializationConfig::new(1 << 20)
|
||||
.serialize_into(&a, &mut serialized)
|
||||
.unwrap();
|
||||
|
||||
let params = FheUint32ConformanceParams::from(server_key);
|
||||
let deserialized_a = DeserializationConfig::new(1 << 20)
|
||||
.deserialize_from::<FheUint32>(serialized.as_slice(), ¶ms)
|
||||
.unwrap();
|
||||
let decrypted: u32 = deserialized_a.decrypt(client_key);
|
||||
assert_eq!(decrypted, clear_a);
|
||||
|
||||
assert!(deserialized_a.is_conformant(¶ms));
|
||||
}
|
||||
|
||||
fn test_safe_deserialize_conformant_compressed_fhe_uint32(
|
||||
client_key: &ClientKey,
|
||||
server_key: &ServerKey,
|
||||
) {
|
||||
let clear_a = random::<u32>();
|
||||
let a = CompressedFheUint32::encrypt(clear_a, client_key);
|
||||
let mut serialized = vec![];
|
||||
SerializationConfig::new(1 << 20)
|
||||
.serialize_into(&a, &mut serialized)
|
||||
.unwrap();
|
||||
|
||||
let params = CompressedFheUint32ConformanceParams::from(server_key);
|
||||
let deserialized_a = DeserializationConfig::new(1 << 20)
|
||||
.deserialize_from::<CompressedFheUint32>(serialized.as_slice(), ¶ms)
|
||||
.unwrap();
|
||||
|
||||
let decrypted: u32 = deserialized_a.decompress().decrypt(client_key);
|
||||
assert_eq!(decrypted, clear_a);
|
||||
}
|
||||
|
||||
fn test_safe_deserialize_conformant_compact_fhe_uint32(client_key: &ClientKey) {
|
||||
let pk = CompactPublicKey::new(client_key);
|
||||
|
||||
let clears = [random::<u32>(), random::<u32>(), random::<u32>()];
|
||||
let a = CompactCiphertextList::builder(&pk)
|
||||
.extend(clears.iter().copied())
|
||||
.build();
|
||||
let mut serialized = vec![];
|
||||
SerializationConfig::new(1 << 20)
|
||||
.serialize_into(&a, &mut serialized)
|
||||
.unwrap();
|
||||
|
||||
let params = CompactCiphertextListConformanceParams::from_parameters_and_size_constraint(
|
||||
pk.parameters(),
|
||||
ListSizeConstraint::exact_size(clears.len()),
|
||||
)
|
||||
.allow_unpacked();
|
||||
let deserialized_a = DeserializationConfig::new(1 << 20)
|
||||
.deserialize_from::<CompactCiphertextList>(serialized.as_slice(), ¶ms)
|
||||
.unwrap();
|
||||
|
||||
let expander = deserialized_a.expand().unwrap();
|
||||
for (i, clear) in clears.into_iter().enumerate() {
|
||||
let encrypted: FheUint32 = expander.get(i).unwrap().unwrap();
|
||||
let decrypted: u32 = encrypted.decrypt(client_key);
|
||||
assert_eq!(decrypted, clear);
|
||||
}
|
||||
|
||||
assert!(deserialized_a.is_conformant(¶ms));
|
||||
}
|
||||
|
||||
fn test_case_integer_casting(client_key: &ClientKey) {
|
||||
let mut rng = rand::thread_rng();
|
||||
let clear = rng.gen::<u16>();
|
||||
|
||||
// Downcasting then Upcasting
|
||||
{
|
||||
let a = FheUint16::encrypt(clear, client_key);
|
||||
|
||||
// Downcasting
|
||||
let a: FheUint8 = a.cast_into();
|
||||
let da: u8 = a.decrypt(client_key);
|
||||
assert_eq!(da, clear as u8);
|
||||
|
||||
// Upcasting
|
||||
let a: FheUint32 = a.cast_into();
|
||||
let da: u32 = a.decrypt(client_key);
|
||||
assert_eq!(da, (clear as u8) as u32);
|
||||
}
|
||||
|
||||
// Upcasting then Downcasting
|
||||
{
|
||||
let a = FheUint16::encrypt(clear, client_key);
|
||||
|
||||
// Upcasting
|
||||
let a = FheUint32::cast_from(a);
|
||||
let da: u32 = a.decrypt(client_key);
|
||||
assert_eq!(da, clear as u32);
|
||||
|
||||
// Downcasting
|
||||
let a = FheUint8::cast_from(a);
|
||||
let da: u8 = a.decrypt(client_key);
|
||||
assert_eq!(da, (clear as u32) as u8);
|
||||
}
|
||||
|
||||
// Casting to self, it not useful but is supported
|
||||
{
|
||||
let a = FheUint16::encrypt(clear, client_key);
|
||||
let a = FheUint16::cast_from(a);
|
||||
let da: u16 = a.decrypt(client_key);
|
||||
assert_eq!(da, clear);
|
||||
}
|
||||
|
||||
// Downcasting to smaller signed integer then Upcasting back to unsigned
|
||||
{
|
||||
let clear = rng.gen_range((i16::MAX) as u16 + 1..u16::MAX);
|
||||
let a = FheUint16::encrypt(clear, client_key);
|
||||
|
||||
// Downcasting
|
||||
let a: FheInt8 = a.cast_into();
|
||||
let da: i8 = a.decrypt(client_key);
|
||||
assert_eq!(da, clear as i8);
|
||||
|
||||
// Upcasting
|
||||
let a: FheUint32 = a.cast_into();
|
||||
let da: u32 = a.decrypt(client_key);
|
||||
assert_eq!(da, (clear as i8) as u32);
|
||||
}
|
||||
|
||||
{
|
||||
let clear = rng.gen_range(i16::MIN..0);
|
||||
let a = FheInt16::encrypt(clear, client_key);
|
||||
|
||||
// Upcasting
|
||||
let a: FheUint32 = a.cast_into();
|
||||
let da: u32 = a.decrypt(client_key);
|
||||
assert_eq!(da, clear as u32);
|
||||
}
|
||||
|
||||
// Upcasting to bigger signed integer then downcasting back to unsigned
|
||||
{
|
||||
let clear = rng.gen_range((i16::MAX) as u16 + 1..u16::MAX);
|
||||
let a = FheUint16::encrypt(clear, client_key);
|
||||
|
||||
// Upcasting
|
||||
let a: FheInt32 = a.cast_into();
|
||||
let da: i32 = a.decrypt(client_key);
|
||||
assert_eq!(da, clear as i32);
|
||||
|
||||
// Downcasting
|
||||
let a: FheUint16 = a.cast_into();
|
||||
let da: u16 = a.decrypt(client_key);
|
||||
assert_eq!(da, (clear as i32) as u16);
|
||||
}
|
||||
}
|
||||
|
||||
fn test_scalar_shift_when_clear_type_is_small(client_key: &ClientKey) {
|
||||
// This is a regression tests
|
||||
// The goal is to make sure that doing a scalar shift / rotate
|
||||
// with a clear type that does not have enough bits to represent
|
||||
// the number of bits of the fhe type correctly works.
|
||||
|
||||
let mut a = FheUint256::encrypt(U256::ONE, client_key);
|
||||
// The fhe type has 256 bits, the clear type is u8,
|
||||
// a u8 cannot represent the value '256'.
|
||||
// This used to result in the shift/rotate panicking
|
||||
let clear = 1u8;
|
||||
|
||||
let _ = &a << clear;
|
||||
let _ = &a >> clear;
|
||||
let _ = (&a).rotate_left(clear);
|
||||
let _ = (&a).rotate_right(clear);
|
||||
|
||||
a <<= clear;
|
||||
a >>= clear;
|
||||
a.rotate_left_assign(clear);
|
||||
a.rotate_right_assign(clear);
|
||||
}
|
||||
|
||||
fn test_integer_compressed(client_key: &ClientKey) {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let clear: u16 = rng.gen();
|
||||
let compressed = CompressedFheUint16::try_encrypt(clear, client_key).unwrap();
|
||||
let decompressed = FheUint16::from(compressed.decompress());
|
||||
let clear_decompressed: u16 = decompressed.decrypt(client_key);
|
||||
assert_eq!(clear_decompressed, clear);
|
||||
}
|
||||
|
||||
fn test_case_uint32_shift(cks: &ClientKey) {
|
||||
let mut rng = rand::thread_rng();
|
||||
let clear_a = rng.gen::<u32>();
|
||||
@@ -547,16 +353,6 @@ fn test_case_uint32_shift(cks: &ClientKey) {
|
||||
}
|
||||
}
|
||||
|
||||
fn test_integer_compress_decompress(client_key: &ClientKey) {
|
||||
let mut rng = rand::thread_rng();
|
||||
let clear_a: u8 = rng.gen();
|
||||
let a = FheUint8::try_encrypt(clear_a, client_key).unwrap();
|
||||
|
||||
let clear: u8 = a.compress().decompress().decrypt(client_key);
|
||||
|
||||
assert_eq!(clear, clear_a);
|
||||
}
|
||||
|
||||
fn test_case_uint32_bitwise(cks: &ClientKey) {
|
||||
let mut rng = rand::thread_rng();
|
||||
let clear_a = rng.gen::<u32>();
|
||||
@@ -1114,66 +910,3 @@ fn test_case_match_value_or(cks: &ClientKey) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn test_dedicated_compact_public_key(client_key: &ClientKey) {
|
||||
use rand::Rng;
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let input_msg: u8 = rng.gen();
|
||||
|
||||
let pk = CompactPublicKey::new(client_key);
|
||||
|
||||
// Encrypt a value and cast
|
||||
let mut builder = CompactCiphertextList::builder(&pk);
|
||||
let list = builder
|
||||
.push_with_num_bits(input_msg, 8)
|
||||
.unwrap()
|
||||
.build_packed();
|
||||
|
||||
let expander = list.expand().unwrap();
|
||||
let ct1_extracted_and_cast = expander.get::<FheUint8>(0).unwrap().unwrap();
|
||||
|
||||
let sanity_cast: u8 = ct1_extracted_and_cast.decrypt(client_key);
|
||||
assert_eq!(sanity_cast, input_msg);
|
||||
|
||||
let multiplier: u8 = rng.gen();
|
||||
|
||||
// Classical AP: DP, KS, PBS
|
||||
let mul = &ct1_extracted_and_cast * multiplier as u8;
|
||||
|
||||
// High level decryption and test
|
||||
let clear: u8 = mul.decrypt(client_key);
|
||||
assert_eq!(clear, input_msg * multiplier);
|
||||
}
|
||||
|
||||
fn test_dedicated_compressed_compact_public_key(client_key: &ClientKey) {
|
||||
use rand::Rng;
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let input_msg: u8 = rng.gen();
|
||||
|
||||
let compressed_pk = CompressedCompactPublicKey::new(client_key);
|
||||
let pk = compressed_pk.decompress();
|
||||
|
||||
// Encrypt a value and cast
|
||||
let mut builder = CompactCiphertextList::builder(&pk);
|
||||
let list = builder
|
||||
.push_with_num_bits(input_msg, 8)
|
||||
.unwrap()
|
||||
.build_packed();
|
||||
|
||||
let expander = list.expand().unwrap();
|
||||
let ct1_extracted_and_cast = expander.get::<FheUint8>(0).unwrap().unwrap();
|
||||
|
||||
let sanity_cast: u8 = ct1_extracted_and_cast.decrypt(client_key);
|
||||
assert_eq!(sanity_cast, input_msg);
|
||||
|
||||
let multiplier: u8 = rng.gen();
|
||||
|
||||
// Classical AP: DP, KS, PBS
|
||||
let mul = &ct1_extracted_and_cast * multiplier as u8;
|
||||
|
||||
// High level decryption and test
|
||||
let clear: u8 = mul.decrypt(client_key);
|
||||
assert_eq!(clear, (input_msg * multiplier));
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ impl Default for IntegerConfig {
|
||||
fn default() -> Self {
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
let params =
|
||||
crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128.into();
|
||||
crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128.into();
|
||||
#[cfg(feature = "gpu")]
|
||||
let params =
|
||||
crate::shortint::parameters::PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
|
||||
@@ -57,7 +57,7 @@ impl PublicKey {
|
||||
}
|
||||
|
||||
pub(crate) fn message_modulus(&self) -> MessageModulus {
|
||||
self.key.key.parameters.message_modulus()
|
||||
self.key.parameters().message_modulus()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::high_level_api::{
|
||||
CompactPublicKey, CompressedCiphertextListBuilder, ConfigBuilder, FheBool, FheInt8, FheUint64,
|
||||
ReRandomizationContext,
|
||||
};
|
||||
use crate::shortint::parameters::test_params::TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
use crate::shortint::parameters::v1_6::meta::cpu::V1_6_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_BIG_ZKV2_TUNIFORM_2M128;
|
||||
#[cfg(feature = "gpu")]
|
||||
use crate::shortint::parameters::v1_6::meta::gpu::V1_6_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_BIG_ZKV2_TUNIFORM_2M128;
|
||||
use crate::shortint::parameters::{MetaParameters, ShortintKeySwitchingParameters};
|
||||
@@ -211,7 +211,7 @@ fn setup_re_rand_test(
|
||||
|
||||
#[test]
|
||||
fn test_re_rand() {
|
||||
let params = TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let params = V1_6_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_BIG_ZKV2_TUNIFORM_2M128;
|
||||
let (cks, sks, cpk) = setup_re_rand_test(params);
|
||||
|
||||
set_server_key(sks.decompress());
|
||||
|
||||
@@ -10,10 +10,6 @@ use crate::high_level_api::{
|
||||
generate_keys, ClientKey, ConfigBuilder, FheBool, FheUint256, FheUint8, PublicKey, ServerKey,
|
||||
};
|
||||
use crate::integer::U256;
|
||||
use crate::shortint::parameters::test_params::{
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
};
|
||||
use crate::shortint::parameters::TestParameters;
|
||||
use crate::shortint::ClassicPBSParameters;
|
||||
use crate::{
|
||||
@@ -41,48 +37,6 @@ pub(crate) fn setup_default_cpu() -> ClientKey {
|
||||
setup_cpu(Option::<ClassicPBSParameters>::None)
|
||||
}
|
||||
|
||||
pub(crate) fn setup_param_prod_cpu() -> ClientKey {
|
||||
setup_cpu(Some(
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
))
|
||||
}
|
||||
|
||||
macro_rules! create_parameterized_test {
|
||||
(
|
||||
$test_case_func:ident
|
||||
) => {
|
||||
create_parameterized_test!(
|
||||
$test_case_func,
|
||||
{
|
||||
{default, $crate::high_level_api::tests::setup_default_cpu},
|
||||
{param_prod, $crate::high_level_api::tests::setup_param_prod_cpu},
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
(
|
||||
$test_case_func:ident,
|
||||
{
|
||||
$({
|
||||
$suffix:ident,
|
||||
$setup_func:path
|
||||
}),*
|
||||
$(,)?
|
||||
}
|
||||
) => {
|
||||
::paste::paste! {
|
||||
$(
|
||||
#[test]
|
||||
fn [<$test_case_func _ $suffix>]() {
|
||||
let client_key = $setup_func();
|
||||
$test_case_func(&client_key);
|
||||
}
|
||||
)*
|
||||
}
|
||||
};
|
||||
}
|
||||
pub(in crate::high_level_api) use create_parameterized_test;
|
||||
|
||||
fn assert_that_public_key_encryption_is_decrypted_by_client_key<FheType, ClearType>(
|
||||
clear: ClearType,
|
||||
pks: &PublicKey,
|
||||
@@ -232,7 +186,7 @@ fn test_serialize_deserialize_are_implemented() {
|
||||
|
||||
#[test]
|
||||
fn test_try_from_single_lwe_encryption_key() {
|
||||
let parameters = TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
let parameters = crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let lwe_sk = crate::shortint::engine::ShortintEngine::with_thread_local_mut(|engine| {
|
||||
crate::core_crypto::algorithms::allocate_and_generate_new_binary_lwe_secret_key(
|
||||
parameters
|
||||
|
||||
@@ -15,7 +15,6 @@ use crate::shortint::parameters::{
|
||||
AtomicPatternParameters, ClassicPBSParameters, CompactPublicKeyEncryptionParameters,
|
||||
ShortintKeySwitchingParameters,
|
||||
};
|
||||
use crate::shortint::AtomicPatternKind;
|
||||
use crate::{ClientKey, CompactCiphertextList, CompactPublicKey, ConfigBuilder, FheUint2};
|
||||
|
||||
use rayon::prelude::*;
|
||||
@@ -121,9 +120,8 @@ fn noise_check_compact_public_key_encryption_noise_tuniform(
|
||||
block_params: ClassicPBSParameters,
|
||||
) {
|
||||
// Hack to avoid server key needs and get the ciphertext directly
|
||||
cpke_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting(
|
||||
AtomicPatternKind::Standard(block_params.encryption_key_choice.into_pbs_order()),
|
||||
);
|
||||
cpke_params.expansion_kind =
|
||||
CompactCiphertextListExpansionKind::NoCasting(block_params.encryption_key_choice.into());
|
||||
|
||||
let modulus_as_f64 = cpke_params.ciphertext_modulus.raw_modulus_float();
|
||||
|
||||
|
||||
@@ -549,7 +549,7 @@ mod tests {
|
||||
use crate::shortint::parameters::test_params::{
|
||||
TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
};
|
||||
use crate::upgrade::{DecompressionUpgradeKey, UpgradeKeyChain};
|
||||
use crate::*;
|
||||
@@ -621,7 +621,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_keychain_upgrade() {
|
||||
let compute_params = TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
let compute_params = TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let compression_parameters = TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let config = ConfigBuilder::with_custom_parameters(compute_params)
|
||||
|
||||
@@ -1306,7 +1306,6 @@ mod zk_pok_tests {
|
||||
};
|
||||
use crate::shortint::ciphertext::Degree;
|
||||
use crate::shortint::parameters::test_params::{
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128_ZKV1,
|
||||
TEST_PARAM_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128_ZKV1,
|
||||
};
|
||||
@@ -1320,16 +1319,9 @@ mod zk_pok_tests {
|
||||
use rand::random;
|
||||
|
||||
fn test_zk_list(is_packed: bool) {
|
||||
let params = TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let pke_params = params
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.pke_params;
|
||||
let ksk_params = params
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.ksk_params;
|
||||
let fhe_params = params.compute_parameters;
|
||||
let pke_params = PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let ksk_params = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
|
||||
|
||||
@@ -1419,16 +1411,9 @@ mod zk_pok_tests {
|
||||
|
||||
#[test]
|
||||
fn test_zk_empty_list() {
|
||||
let params = TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let pke_params = params
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.pke_params;
|
||||
let ksk_params = params
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.ksk_params;
|
||||
let fhe_params = params.compute_parameters;
|
||||
let pke_params = PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let ksk_params = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
|
||||
|
||||
@@ -1578,16 +1563,9 @@ mod zk_pok_tests {
|
||||
/// is modified
|
||||
#[test]
|
||||
fn test_attack_list_info() {
|
||||
let params = TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let pke_params = params
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.pke_params;
|
||||
let ksk_params = params
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.ksk_params;
|
||||
let fhe_params = params.compute_parameters;
|
||||
let pke_params = PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let ksk_params = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
|
||||
|
||||
@@ -1705,16 +1683,9 @@ mod zk_pok_tests {
|
||||
|
||||
#[test]
|
||||
fn test_attack_proven_list_metadata() {
|
||||
let params = TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let pke_params = params
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.pke_params;
|
||||
let ksk_params = params
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.ksk_params;
|
||||
let fhe_params = params.compute_parameters;
|
||||
let pke_params = PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let ksk_params = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
|
||||
|
||||
@@ -1824,16 +1795,9 @@ mod zk_pok_tests {
|
||||
|
||||
#[test]
|
||||
fn test_several_proven_lists() {
|
||||
let params = TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let pke_params = params
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.pke_params;
|
||||
let ksk_params = params
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.ksk_params;
|
||||
let fhe_params = params.compute_parameters;
|
||||
let pke_params = PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let ksk_params = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
|
||||
|
||||
@@ -1894,16 +1858,9 @@ mod zk_pok_tests {
|
||||
fn test_malicious_boolean_proven_lists() {
|
||||
use super::DataKind;
|
||||
|
||||
let params = TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let pke_params = params
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.pke_params;
|
||||
let ksk_params = params
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.ksk_params;
|
||||
let fhe_params = params.compute_parameters;
|
||||
let pke_params = PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let ksk_params = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
|
||||
|
||||
|
||||
@@ -224,8 +224,6 @@ mod tests {
|
||||
use crate::shortint::parameters::test_params::{
|
||||
TEST_COMP_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
@@ -280,22 +278,6 @@ mod tests {
|
||||
TEST_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128.into(),
|
||||
TEST_COMP_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
),
|
||||
(
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128
|
||||
.compute_parameters
|
||||
.into(),
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128
|
||||
.compression_parameters
|
||||
.unwrap(),
|
||||
),
|
||||
(
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128
|
||||
.compute_parameters
|
||||
.into(),
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128
|
||||
.compression_parameters
|
||||
.unwrap(),
|
||||
),
|
||||
] {
|
||||
let (cks, sks) = gen_keys::<ShortintParameterSet>(params, IntegerKeyKind::Radix);
|
||||
|
||||
|
||||
@@ -420,14 +420,18 @@ impl CompressedSquashedNoiseCiphertextListBuilder {
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::integer::noise_squashing::NoiseSquashingKey;
|
||||
use crate::shortint::parameters::test_params::TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
use crate::shortint::parameters::test_params::{
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_NOISE_SQUASHING_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_NOISE_SQUASHING_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
};
|
||||
use rand::Rng;
|
||||
|
||||
#[test]
|
||||
fn test_compressed_noise_squashed_ciphertext_list() {
|
||||
let meta_param = TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let param = meta_param.compute_parameters;
|
||||
let noise_squashing_parameters = meta_param.noise_squashing_parameters.unwrap().parameters;
|
||||
let param = TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let noise_squashing_parameters =
|
||||
TEST_PARAM_NOISE_SQUASHING_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
// The goal is to test that encrypting a value stored in a type
|
||||
// for which the bit count does not match the target block count of the encrypted
|
||||
@@ -438,11 +442,7 @@ mod test {
|
||||
let noise_squashing_key = NoiseSquashingKey::new(&cks, &noise_squashing_private_key);
|
||||
|
||||
let noise_squashing_compression_private_key = NoiseSquashingCompressionPrivateKey::new(
|
||||
meta_param
|
||||
.noise_squashing_parameters
|
||||
.unwrap()
|
||||
.compression_parameters
|
||||
.unwrap(),
|
||||
TEST_PARAM_NOISE_SQUASHING_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
);
|
||||
let compression_key = noise_squashing_private_key
|
||||
.new_noise_squashing_compression_key(&noise_squashing_compression_private_key);
|
||||
|
||||
@@ -5,7 +5,12 @@ use crate::integer::{
|
||||
gen_keys, BooleanBlock, CompactPrivateKey, CompactPublicKey, IntegerKeyKind, RadixCiphertext,
|
||||
SignedRadixCiphertext,
|
||||
};
|
||||
use crate::shortint::parameters::test_params::TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
use crate::shortint::parameters::test_params::{
|
||||
TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128_ZKV2,
|
||||
};
|
||||
use crate::shortint::ShortintParameterSet;
|
||||
use itertools::Itertools;
|
||||
use rand::Rng;
|
||||
@@ -15,20 +20,12 @@ const NUM_BLOCKS: usize = 32;
|
||||
|
||||
#[test]
|
||||
fn test_ciphertext_re_randomization_after_compression() {
|
||||
let meta_param = TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let params = meta_param.compute_parameters;
|
||||
let comp_params = meta_param.compression_parameters.unwrap();
|
||||
let cpk_params = meta_param
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.pke_params;
|
||||
let ks_params = meta_param
|
||||
.dedicated_compact_public_key_parameters
|
||||
.unwrap()
|
||||
.re_randomization_parameters
|
||||
.unwrap();
|
||||
let params = TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128.into();
|
||||
let comp_params = TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let cpk_params = TEST_PARAM_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128_ZKV2;
|
||||
let ks_params = TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let (cks, sks) = gen_keys::<ShortintParameterSet>(params.into(), IntegerKeyKind::Radix);
|
||||
let (cks, sks) = gen_keys::<ShortintParameterSet>(params, IntegerKeyKind::Radix);
|
||||
|
||||
let private_compression_key = cks.new_compression_private_key(comp_params);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ impl CudaCompactCiphertextListExpander {
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.blocks_info.len()
|
||||
self.expanded_blocks.lwe_ciphertext_count().0
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
|
||||
@@ -805,9 +805,6 @@ where
|
||||
let oprf_bounded_executor = OpSequenceGpuMultiDeviceFunctionExecutor::new(
|
||||
&CudaServerKey::par_generate_oblivious_pseudo_random_unsigned_integer_bounded,
|
||||
);
|
||||
let oprf_custom_range_executor = OpSequenceGpuMultiDeviceFunctionExecutor::new(
|
||||
&CudaServerKey::par_generate_oblivious_pseudo_random_unsigned_custom_range,
|
||||
);
|
||||
|
||||
let mut oprf_ops: Vec<(OprfExecutor, String)> = vec![(
|
||||
Box::new(oprf_executor),
|
||||
@@ -819,10 +816,8 @@ where
|
||||
"par_generate_oblivious_pseudo_random_unsigned_integer_bounded".to_string(),
|
||||
)];
|
||||
|
||||
let mut oprf_custom_range_ops: Vec<(OprfCustomRangeExecutor, String)> = vec![(
|
||||
Box::new(oprf_custom_range_executor),
|
||||
"par_generate_oblivious_pseudo_random_unsigned_custom_range".to_string(),
|
||||
)];
|
||||
// The custom_range variant is not yet implemented on GPU
|
||||
let mut oprf_custom_range_ops: Vec<(OprfCustomRangeExecutor, String)> = vec![];
|
||||
|
||||
let (cks, sks, mut datagen) = random_op_sequence_test_init_gpu(
|
||||
param,
|
||||
|
||||
@@ -128,7 +128,7 @@ impl<'de> serde::Deserialize<'de> for CudaProvenCompactCiphertextList {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "zk-pok", feature = "gpu"))]
|
||||
#[cfg(feature = "zk-pok")]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// Test utils for tests here
|
||||
@@ -493,100 +493,4 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expander_length_matches_data_items() {
|
||||
// This test ensures len() returns the number of data items, not the total number of blocks.
|
||||
use crate::high_level_api::prelude::*;
|
||||
use crate::high_level_api::set_server_key;
|
||||
use crate::zk::ZkComputeLoad;
|
||||
|
||||
let params = crate::shortint::parameters::PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let cpk_params =
|
||||
crate::shortint::parameters::PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let casting_params =
|
||||
crate::shortint::parameters::PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
let config = crate::ConfigBuilder::with_custom_parameters(params)
|
||||
.use_dedicated_compact_public_key_parameters((cpk_params, casting_params))
|
||||
.build();
|
||||
|
||||
let client_key = crate::ClientKey::generate(config);
|
||||
let compressed_server_key = crate::CompressedServerKey::new(&client_key);
|
||||
let gpu_server_key = compressed_server_key.decompress_to_gpu();
|
||||
|
||||
let crs = CompactPkeCrs::from_config(config, 64).unwrap();
|
||||
let public_key = crate::CompactPublicKey::try_new(&client_key).unwrap();
|
||||
let metadata = [b'T', b'F', b'H', b'E', b'-', b'r', b's'];
|
||||
|
||||
// Create a proven compact list with 6 items (matching user's scenario)
|
||||
let proven_compact_list = crate::ProvenCompactCiphertextList::builder(&public_key)
|
||||
.push(true)
|
||||
.push(42u8)
|
||||
.push(42u8)
|
||||
.push(12345u16)
|
||||
.push(67890u32)
|
||||
.push(1234567890u64)
|
||||
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Verify)
|
||||
.unwrap();
|
||||
|
||||
// Set GPU server key
|
||||
set_server_key(gpu_server_key);
|
||||
|
||||
// Verify and expand on GPU
|
||||
let expander = proven_compact_list
|
||||
.verify_and_expand(&crs, &public_key, &metadata)
|
||||
.unwrap();
|
||||
|
||||
// The expander should have length 6 (number of data items), not 66 (total blocks)
|
||||
assert_eq!(
|
||||
expander.len(),
|
||||
6,
|
||||
"Expander length should be 6 (number of data items), not the total number of blocks"
|
||||
);
|
||||
|
||||
// Verify we can get the kind for all 6 items
|
||||
assert!(
|
||||
expander.get_kind_of(0).is_some(),
|
||||
"Should be able to get kind at index 0"
|
||||
);
|
||||
assert!(
|
||||
expander.get_kind_of(1).is_some(),
|
||||
"Should be able to get kind at index 1"
|
||||
);
|
||||
assert!(
|
||||
expander.get_kind_of(2).is_some(),
|
||||
"Should be able to get kind at index 2"
|
||||
);
|
||||
assert!(
|
||||
expander.get_kind_of(3).is_some(),
|
||||
"Should be able to get kind at index 3"
|
||||
);
|
||||
assert!(
|
||||
expander.get_kind_of(4).is_some(),
|
||||
"Should be able to get kind at index 4"
|
||||
);
|
||||
assert!(
|
||||
expander.get_kind_of(5).is_some(),
|
||||
"Should be able to get kind at index 5"
|
||||
);
|
||||
|
||||
// Verify indices beyond the data item count return None
|
||||
assert!(
|
||||
expander.get_kind_of(6).is_none(),
|
||||
"Index 6 should return None (beyond data item count)"
|
||||
);
|
||||
assert!(
|
||||
expander.get_kind_of(65).is_none(),
|
||||
"Index 65 should return None (beyond data item count)"
|
||||
);
|
||||
|
||||
// Verify we can actually retrieve the values
|
||||
let _bool_val: crate::FheBool = expander.get(0).unwrap().unwrap();
|
||||
let _u8_val_1: crate::FheUint8 = expander.get(1).unwrap().unwrap();
|
||||
let _u8_val_2: crate::FheUint8 = expander.get(2).unwrap().unwrap();
|
||||
let _u16_val: crate::FheUint16 = expander.get(3).unwrap().unwrap();
|
||||
let _u32_val: crate::FheUint32 = expander.get(4).unwrap().unwrap();
|
||||
let _u64_val: crate::FheUint64 = expander.get(5).unwrap().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
use crate::integer::keycache::KEY_CACHE;
|
||||
use crate::integer::noise_squashing::{NoiseSquashingKey, NoiseSquashingPrivateKey};
|
||||
use crate::integer::IntegerKeyKind;
|
||||
use crate::shortint::parameters::test_params::TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
use crate::shortint::parameters::{
|
||||
NOISE_SQUASHING_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
};
|
||||
use rand::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn test_integer_noise_squashing_decrypt_auto_cast_and_bool() {
|
||||
let meta_param = TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let param = meta_param.compute_parameters;
|
||||
let noise_squashing_parameters = meta_param.noise_squashing_parameters.unwrap().parameters;
|
||||
let param = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
let noise_squashing_parameters = NOISE_SQUASHING_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
// The goal is to test that encrypting a value stored in a type
|
||||
// for which the bit count does not match the target block count of the encrypted
|
||||
@@ -19,7 +21,7 @@ fn test_integer_noise_squashing_decrypt_auto_cast_and_bool() {
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let num_blocks = 32u32.div_ceil(param.message_modulus().0.ilog2()) as usize;
|
||||
let num_blocks = 32u32.div_ceil(param.message_modulus.0.ilog2()) as usize;
|
||||
|
||||
// Positive signed value
|
||||
let value = rng.gen_range(0..=i32::MAX);
|
||||
|
||||
@@ -70,8 +70,8 @@ impl CompressedPublicKey {
|
||||
encrypt_many_crt(&self.key, message, base_vec, encrypt_block)
|
||||
}
|
||||
|
||||
pub fn parameters(&self) -> crate::shortint::ShortintParameterSet {
|
||||
self.key.parameters
|
||||
pub fn parameters(&self) -> crate::shortint::PBSParameters {
|
||||
self.key.parameters.pbs_parameters().unwrap()
|
||||
}
|
||||
|
||||
pub fn encrypt_radix<T: DecomposableInto<u64>>(
|
||||
|
||||
@@ -67,8 +67,8 @@ impl PublicKey {
|
||||
encrypt_crt(&self.key, message, base_vec, encrypt_block)
|
||||
}
|
||||
|
||||
pub fn parameters(&self) -> crate::shortint::ShortintParameterSet {
|
||||
self.key.parameters
|
||||
pub fn parameters(&self) -> crate::shortint::PBSParameters {
|
||||
self.key.parameters.pbs_parameters().unwrap()
|
||||
}
|
||||
|
||||
pub fn encrypt_radix<T>(&self, message: T, num_blocks: usize) -> RadixCiphertext
|
||||
@@ -118,16 +118,14 @@ mod tests {
|
||||
use crate::integer::keycache::KEY_CACHE;
|
||||
use crate::integer::tests::create_parameterized_test;
|
||||
use crate::integer::IntegerKeyKind;
|
||||
use crate::shortint::parameters::test_params::{
|
||||
TestParameters, TEST_PARAM_MESSAGE_2_CARRY_2_PBS_KS_GAUSSIAN_2M128,
|
||||
};
|
||||
use crate::shortint::parameters::test_params::TEST_PARAM_MESSAGE_2_CARRY_2_PBS_KS_GAUSSIAN_2M128;
|
||||
use crate::shortint::parameters::ClassicPBSParameters;
|
||||
|
||||
create_parameterized_test!(integer_public_key_decompression_small {
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_PBS_KS_GAUSSIAN_2M128,
|
||||
});
|
||||
|
||||
fn integer_public_key_decompression_small<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_public_key_decompression_small(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let compressed_pk = crate::integer::CompressedPublicKey::new(&cks);
|
||||
|
||||
@@ -15,8 +15,7 @@ create_parameterized_test!(big_radix_encrypt_decrypt_128_bits {
|
||||
},
|
||||
no_coverage => {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
/* PARAM_MESSAGE_3_CARRY_3_KS_PBS, Skipped as the key requires 32GB
|
||||
* PARAM_MESSAGE_4_CARRY_4_KS_PBS, Skipped as the key requires 550GB */
|
||||
}
|
||||
@@ -30,8 +29,7 @@ create_parameterized_test!(
|
||||
},
|
||||
no_coverage => {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
/* PARAM_MESSAGE_3_CARRY_3_KS_PBS, Skipped as its slow
|
||||
* PARAM_MESSAGE_4_CARRY_4_KS_PBS, Skipped as its slow */
|
||||
}
|
||||
@@ -39,27 +37,35 @@ create_parameterized_test!(
|
||||
);
|
||||
|
||||
create_parameterized_test!(
|
||||
radix_encrypt_decrypt_compact_128_bits_list {
|
||||
big_radix_encrypt_decrypt_compact_128_bits_list {
|
||||
coverage => {
|
||||
COVERAGE_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS_GAUSSIAN_2M64,
|
||||
},
|
||||
no_coverage => {
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS_GAUSSIAN_2M128,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
create_parameterized_test!(
|
||||
small_radix_encrypt_decrypt_compact_128_bits_list {
|
||||
coverage => {
|
||||
COVERAGE_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS_GAUSSIAN_2M64,
|
||||
},
|
||||
no_coverage => {
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS_GAUSSIAN_2M128,
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS_GAUSSIAN_2M128,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/// Test that the public key can encrypt a 128 bit number
|
||||
/// in radix decomposition, and that the client key can decrypt it
|
||||
fn big_radix_encrypt_decrypt_128_bits<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn big_radix_encrypt_decrypt_128_bits(param: ClassicPBSParameters) {
|
||||
let (cks, _) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let public_key = PublicKey::new(&cks);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let num_block = (128f64 / (param.message_modulus().0 as f64).log(2.0)).ceil() as usize;
|
||||
let num_block = (128f64 / (param.message_modulus.0 as f64).log(2.0)).ceil() as usize;
|
||||
|
||||
let clear = rng.gen::<u128>();
|
||||
|
||||
@@ -70,13 +76,12 @@ fn big_radix_encrypt_decrypt_128_bits<P: Into<TestParameters>>(param: P) {
|
||||
assert_eq!(clear, dec);
|
||||
}
|
||||
|
||||
fn radix_encrypt_decrypt_compressed_128_bits<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn radix_encrypt_decrypt_compressed_128_bits(param: ClassicPBSParameters) {
|
||||
let (cks, _) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let public_key = CompressedPublicKey::new(&cks);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let num_block = (128f64 / (param.message_modulus().0 as f64).log(2.0)).ceil() as usize;
|
||||
let num_block = (128f64 / (param.message_modulus.0 as f64).log(2.0)).ceil() as usize;
|
||||
|
||||
let clear = rng.gen::<u128>();
|
||||
|
||||
@@ -87,6 +92,14 @@ fn radix_encrypt_decrypt_compressed_128_bits<P: Into<TestParameters>>(param: P)
|
||||
assert_eq!(clear, dec);
|
||||
}
|
||||
|
||||
fn big_radix_encrypt_decrypt_compact_128_bits_list(params: ClassicPBSParameters) {
|
||||
radix_encrypt_decrypt_compact_128_bits_list(params);
|
||||
}
|
||||
|
||||
fn small_radix_encrypt_decrypt_compact_128_bits_list(params: ClassicPBSParameters) {
|
||||
radix_encrypt_decrypt_compact_128_bits_list(params);
|
||||
}
|
||||
|
||||
fn radix_encrypt_decrypt_compact_128_bits_list(params: ClassicPBSParameters) {
|
||||
let (cks, sks) = gen_keys(params, IntegerKeyKind::Radix);
|
||||
let pk = crate::integer::public_key::CompactPublicKey::new(&cks);
|
||||
|
||||
@@ -227,15 +227,14 @@ fn integer_unchecked_crt_scalar_sub_32_bits() {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_unchecked_crt_mul<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_unchecked_crt_mul(param: ClassicPBSParameters) {
|
||||
// generate the server-client key set
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// Define CRT basis, and global modulus
|
||||
let basis = make_basis(param.message_modulus().0);
|
||||
let basis = make_basis(param.message_modulus.0);
|
||||
let modulus = basis.iter().product::<u64>();
|
||||
|
||||
for _ in 0..NB_TESTS {
|
||||
@@ -254,10 +253,9 @@ fn integer_unchecked_crt_mul<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_smart_crt_add<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_crt_add(param: ClassicPBSParameters) {
|
||||
// Define CRT basis, and global modulus
|
||||
let basis = make_basis(param.message_modulus().0);
|
||||
let basis = make_basis(param.message_modulus.0);
|
||||
let modulus = basis.iter().product::<u64>();
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
@@ -281,13 +279,12 @@ fn integer_smart_crt_add<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_smart_crt_mul<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_crt_mul(param: ClassicPBSParameters) {
|
||||
// generate the server-client key set
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
|
||||
// Define CRT basis, and global modulus
|
||||
let basis = make_basis(param.message_modulus().0);
|
||||
let basis = make_basis(param.message_modulus.0);
|
||||
let modulus = basis.iter().product::<u64>();
|
||||
|
||||
println!("BASIS = {basis:?}");
|
||||
@@ -311,10 +308,9 @@ fn integer_smart_crt_mul<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_smart_crt_neg<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_crt_neg(param: ClassicPBSParameters) {
|
||||
// Define CRT basis, and global modulus
|
||||
let basis = make_basis(param.message_modulus().0);
|
||||
let basis = make_basis(param.message_modulus.0);
|
||||
let modulus = basis.iter().product::<u64>();
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
@@ -338,10 +334,9 @@ fn integer_smart_crt_neg<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_smart_crt_scalar_add<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_crt_scalar_add(param: ClassicPBSParameters) {
|
||||
// Define CRT basis, and global modulus
|
||||
let basis = make_basis(param.message_modulus().0);
|
||||
let basis = make_basis(param.message_modulus.0);
|
||||
let modulus = basis.iter().product::<u64>();
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
@@ -363,10 +358,9 @@ fn integer_smart_crt_scalar_add<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_smart_crt_scalar_mul<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_crt_scalar_mul(param: ClassicPBSParameters) {
|
||||
// Define CRT basis, and global modulus
|
||||
let basis = make_basis(param.message_modulus().0);
|
||||
let basis = make_basis(param.message_modulus.0);
|
||||
let modulus = basis.iter().product::<u64>();
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
@@ -388,10 +382,9 @@ fn integer_smart_crt_scalar_mul<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_smart_crt_scalar_sub<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_crt_scalar_sub(param: ClassicPBSParameters) {
|
||||
// Define CRT basis, and global modulus
|
||||
let basis = make_basis(param.message_modulus().0);
|
||||
let basis = make_basis(param.message_modulus.0);
|
||||
let modulus = basis.iter().product::<u64>();
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
@@ -416,10 +409,9 @@ fn integer_smart_crt_scalar_sub<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_smart_crt_sub<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_crt_sub(param: ClassicPBSParameters) {
|
||||
// Define CRT basis, and global modulus
|
||||
let basis = make_basis(param.message_modulus().0);
|
||||
let basis = make_basis(param.message_modulus.0);
|
||||
let modulus = basis.iter().product::<u64>();
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::CRT);
|
||||
|
||||
@@ -129,21 +129,19 @@ create_parameterized_test!(integer_unchecked_min {
|
||||
COVERAGE_PARAM_MESSAGE_2_CARRY_2_KS_PBS
|
||||
},
|
||||
no_coverage => {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
}
|
||||
});
|
||||
|
||||
fn integer_encrypt_decrypt<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_encrypt_decrypt(param: ClassicPBSParameters) {
|
||||
let (cks, _) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let modulus = param.message_modulus().0.pow(NB_CTXT as u32);
|
||||
let modulus = param.message_modulus.0.pow(NB_CTXT as u32);
|
||||
|
||||
for _ in 0..NB_TESTS {
|
||||
let clear = rng.gen::<u64>() % modulus;
|
||||
@@ -156,12 +154,11 @@ fn integer_encrypt_decrypt<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_encrypt_decrypt_128_bits<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_encrypt_decrypt_128_bits(param: ClassicPBSParameters) {
|
||||
let (cks, _) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let num_block = 128u32.div_ceil(param.message_modulus().0.ilog2()) as usize;
|
||||
let num_block = 128u32.div_ceil(param.message_modulus.0.ilog2()) as usize;
|
||||
for _ in 0..10 {
|
||||
let clear = rng.gen::<u128>();
|
||||
|
||||
@@ -173,11 +170,10 @@ fn integer_encrypt_decrypt_128_bits<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_encrypt_decrypt_128_bits_specific_values<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_encrypt_decrypt_128_bits_specific_values(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let num_block = 128u32.div_ceil(param.message_modulus().0.ilog2()) as usize;
|
||||
let num_block = 128u32.div_ceil(param.message_modulus.0.ilog2()) as usize;
|
||||
{
|
||||
let a = u64::MAX as u128;
|
||||
let ct = cks.encrypt_radix(a, num_block);
|
||||
@@ -222,11 +218,10 @@ fn integer_encrypt_decrypt_128_bits_specific_values<P: Into<TestParameters>>(par
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_encrypt_decrypt_256_bits_specific_values<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_encrypt_decrypt_256_bits_specific_values(param: ClassicPBSParameters) {
|
||||
let (cks, _) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let num_block = 256u32.div_ceil(param.message_modulus().0.ilog2()) as usize;
|
||||
let num_block = 256u32.div_ceil(param.message_modulus.0.ilog2()) as usize;
|
||||
{
|
||||
let a = (u64::MAX as u128) << 64;
|
||||
let b = 0;
|
||||
@@ -247,12 +242,11 @@ fn integer_encrypt_decrypt_256_bits_specific_values<P: Into<TestParameters>>(par
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_encrypt_decrypt_256_bits<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_encrypt_decrypt_256_bits(param: ClassicPBSParameters) {
|
||||
let (cks, _) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let num_block = 256u32.div_ceil(param.message_modulus().0.ilog2()) as usize;
|
||||
let num_block = 256u32.div_ceil(param.message_modulus.0.ilog2()) as usize;
|
||||
|
||||
for _ in 0..10 {
|
||||
let clear0 = rng.gen::<u128>();
|
||||
@@ -268,8 +262,7 @@ fn integer_encrypt_decrypt_256_bits<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_encrypt_auto_cast<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_encrypt_auto_cast(param: ClassicPBSParameters) {
|
||||
// The goal is to test that encrypting a value stored in a type
|
||||
// for which the bit count does not match the target block count of the encrypted
|
||||
// radix properly applies upcasting/downcasting
|
||||
@@ -277,7 +270,7 @@ fn integer_encrypt_auto_cast<P: Into<TestParameters>>(param: P) {
|
||||
let (cks, _) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let num_blocks = 32u32.div_ceil(param.message_modulus().0.ilog2()) as usize;
|
||||
let num_blocks = 32u32.div_ceil(param.message_modulus.0.ilog2()) as usize;
|
||||
|
||||
// Positive signed value
|
||||
let value = rng.gen_range(0..=i32::MAX);
|
||||
@@ -318,12 +311,11 @@ fn integer_encrypt_auto_cast<P: Into<TestParameters>>(param: P) {
|
||||
assert_eq!(value as u16, d);
|
||||
}
|
||||
|
||||
fn integer_smart_add_128_bits<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_add_128_bits(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let num_block = 128u32.div_ceil(param.message_modulus().0.ilog2()) as usize;
|
||||
let num_block = 128u32.div_ceil(param.message_modulus.0.ilog2()) as usize;
|
||||
|
||||
for _ in 0..100 {
|
||||
let clear_0 = rng.gen::<u128>();
|
||||
@@ -354,14 +346,12 @@ fn integer_smart_add_128_bits<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_unchecked_add<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_unchecked_add(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::unchecked_add);
|
||||
unchecked_add_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_smart_add<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_add(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::smart_add);
|
||||
smart_add_test(param, executor);
|
||||
}
|
||||
@@ -414,16 +404,15 @@ where
|
||||
smart_bitxor_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_unchecked_small_scalar_mul<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_unchecked_small_scalar_mul(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
let modulus = param.message_modulus().0.pow(NB_CTXT as u32);
|
||||
let modulus = param.message_modulus.0.pow(NB_CTXT as u32);
|
||||
|
||||
let scalar_modulus = param.message_modulus().0;
|
||||
let scalar_modulus = param.message_modulus.0;
|
||||
|
||||
for _ in 0..NB_TESTS {
|
||||
let clear = rng.gen::<u64>() % modulus;
|
||||
@@ -441,16 +430,15 @@ fn integer_unchecked_small_scalar_mul<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_smart_small_scalar_mul<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_small_scalar_mul(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
let modulus = param.message_modulus().0.pow(NB_CTXT as u32);
|
||||
let modulus = param.message_modulus.0.pow(NB_CTXT as u32);
|
||||
|
||||
let scalar_modulus = param.message_modulus().0;
|
||||
let scalar_modulus = param.message_modulus.0;
|
||||
|
||||
let mut clear_res;
|
||||
for _ in 0..NB_TESTS_SMALLER {
|
||||
@@ -475,14 +463,13 @@ fn integer_smart_small_scalar_mul<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_blockshift<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_blockshift(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
let modulus = param.message_modulus().0.pow(NB_CTXT as u32);
|
||||
let modulus = param.message_modulus.0.pow(NB_CTXT as u32);
|
||||
|
||||
for _ in 0..NB_TESTS {
|
||||
let clear = rng.gen::<u64>() % modulus;
|
||||
@@ -497,20 +484,19 @@ fn integer_blockshift<P: Into<TestParameters>>(param: P) {
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
assert_eq!(
|
||||
(clear * param.message_modulus().0.pow(power as u32) as u64) % modulus,
|
||||
(clear * param.message_modulus.0.pow(power as u32) as u64) % modulus,
|
||||
dec_res
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_blockshift_right<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_blockshift_right(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
let modulus = param.message_modulus().0.pow(NB_CTXT as u32);
|
||||
let modulus = param.message_modulus.0.pow(NB_CTXT as u32);
|
||||
|
||||
for _ in 0..NB_TESTS {
|
||||
let clear = rng.gen::<u64>() % modulus;
|
||||
@@ -525,20 +511,19 @@ fn integer_blockshift_right<P: Into<TestParameters>>(param: P) {
|
||||
let dec_res: u64 = cks.decrypt_radix(&ct_res);
|
||||
|
||||
assert_eq!(
|
||||
(clear / param.message_modulus().0.pow(power as u32) as u64) % modulus,
|
||||
(clear / param.message_modulus.0.pow(power as u32) as u64) % modulus,
|
||||
dec_res
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_smart_scalar_mul<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_scalar_mul(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
let modulus = param.message_modulus().0.pow(NB_CTXT as u32);
|
||||
let modulus = param.message_modulus.0.pow(NB_CTXT as u32);
|
||||
|
||||
for _ in 0..NB_TESTS {
|
||||
let clear = rng.gen::<u64>() % modulus;
|
||||
@@ -580,8 +565,7 @@ where
|
||||
unchecked_neg_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_smart_neg<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_neg(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::smart_neg);
|
||||
smart_neg_test(param, executor);
|
||||
}
|
||||
@@ -594,8 +578,7 @@ where
|
||||
unchecked_sub_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_smart_sub<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_sub(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::smart_sub);
|
||||
smart_sub_test(param, executor);
|
||||
}
|
||||
@@ -608,16 +591,15 @@ where
|
||||
unchecked_block_mul_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_smart_block_mul<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_block_mul(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
// message_modulus^vec_length
|
||||
let modulus = param.message_modulus().0.pow(NB_CTXT as u32);
|
||||
let modulus = param.message_modulus.0.pow(NB_CTXT as u32);
|
||||
|
||||
let block_modulus = param.message_modulus().0;
|
||||
let block_modulus = param.message_modulus.0;
|
||||
|
||||
for _ in 0..5 {
|
||||
// Define the cleartexts
|
||||
@@ -693,8 +675,7 @@ where
|
||||
smart_scalar_sub_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_unchecked_scalar_decomposition_overflow<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_unchecked_scalar_decomposition_overflow(param: ClassicPBSParameters) {
|
||||
// This is a regression test.
|
||||
//
|
||||
// The purpose here is to check the behaviour when the scalar value has less bits
|
||||
@@ -702,7 +683,7 @@ fn integer_unchecked_scalar_decomposition_overflow<P: Into<TestParameters>>(para
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let num_block = (128_f64 / (param.message_modulus().0 as f64).log(2.0)).ceil() as usize;
|
||||
let num_block = (128_f64 / (param.message_modulus.0 as f64).log(2.0)).ceil() as usize;
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
@@ -847,56 +828,47 @@ fn integer_signed_decryption_correctly_sign_extend(param: impl Into<TestParamete
|
||||
assert_eq!(trivial.decrypt_trivial::<i128>().unwrap(), value as i128);
|
||||
}
|
||||
|
||||
fn integer_scalar_blockslice<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_scalar_blockslice(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::scalar_blockslice);
|
||||
scalar_blockslice_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_scalar_blockslice_assign<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_scalar_blockslice_assign(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::scalar_blockslice_assign);
|
||||
scalar_blockslice_assign_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_unchecked_scalar_slice<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_unchecked_scalar_slice(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::unchecked_scalar_bitslice);
|
||||
unchecked_scalar_bitslice_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_unchecked_scalar_slice_assign<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_unchecked_scalar_slice_assign(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::unchecked_scalar_bitslice_assign);
|
||||
unchecked_scalar_bitslice_assign_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_default_scalar_slice<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_default_scalar_slice(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::scalar_bitslice);
|
||||
default_scalar_bitslice_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_default_scalar_slice_assign<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_default_scalar_slice_assign(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::scalar_bitslice_assign);
|
||||
default_scalar_bitslice_assign_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_smart_scalar_slice<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_scalar_slice(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::smart_scalar_bitslice);
|
||||
smart_scalar_bitslice_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_smart_scalar_slice_assign<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_smart_scalar_slice_assign(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::smart_scalar_bitslice_assign);
|
||||
smart_scalar_bitslice_assign_test(param, executor);
|
||||
}
|
||||
|
||||
fn integer_unchecked_min<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_unchecked_min(param: ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::unchecked_min);
|
||||
test_unchecked_minmax(param, 2, executor, std::cmp::min::<u64>);
|
||||
}
|
||||
|
||||
@@ -439,7 +439,10 @@ mod tests {
|
||||
use crate::integer::{
|
||||
gen_keys, ClientKey, IntegerKeyKind, RadixCiphertext, SignedRadixCiphertext,
|
||||
};
|
||||
use crate::shortint::parameters::test_params::TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
use crate::shortint::parameters::test_params::{
|
||||
TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
};
|
||||
use crate::shortint::ShortintParameterSet;
|
||||
|
||||
fn assert_store_unsigned_matches(
|
||||
@@ -468,13 +471,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_compression_serialization_unsigned() {
|
||||
let meta_params = TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let params = meta_params.compute_parameters.into();
|
||||
let params = TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128.into();
|
||||
|
||||
let (cks, _) = gen_keys::<ShortintParameterSet>(params, IntegerKeyKind::Radix);
|
||||
|
||||
let private_compression_key =
|
||||
cks.new_compression_private_key(meta_params.compression_parameters.unwrap());
|
||||
let private_compression_key = cks
|
||||
.new_compression_private_key(TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128);
|
||||
|
||||
let (compression_key, decompression_key) =
|
||||
cks.new_compression_decompression_keys(&private_compression_key);
|
||||
@@ -536,13 +538,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_compression_serialization_signed() {
|
||||
let meta_params = TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
let params = meta_params.compute_parameters.into();
|
||||
let params = TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128.into();
|
||||
|
||||
let (cks, _) = gen_keys::<ShortintParameterSet>(params, IntegerKeyKind::Radix);
|
||||
|
||||
let private_compression_key =
|
||||
cks.new_compression_private_key(meta_params.compression_parameters.unwrap());
|
||||
let private_compression_key = cks
|
||||
.new_compression_private_key(TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128);
|
||||
|
||||
let (compression_key, decompression_key) =
|
||||
cks.new_compression_decompression_keys(&private_compression_key);
|
||||
|
||||
@@ -8,26 +8,21 @@ use crate::integer::tests::create_parameterized_test;
|
||||
use crate::integer::{
|
||||
BooleanBlock, IntegerCiphertext, IntegerKeyKind, RadixCiphertext, RadixClientKey, ServerKey,
|
||||
};
|
||||
use crate::shortint::parameters::test_params::*;
|
||||
use crate::shortint::parameters::*;
|
||||
use rand::Rng;
|
||||
use std::sync::Arc;
|
||||
|
||||
create_parameterized_test!(safe_erc20 {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
});
|
||||
create_parameterized_test!(whitepaper_erc20 {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
});
|
||||
create_parameterized_test!(no_cmux_erc20 {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
});
|
||||
create_parameterized_test!(overflow_erc20 {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
});
|
||||
|
||||
fn safe_erc20<P>(param: P)
|
||||
|
||||
@@ -7,7 +7,6 @@ use crate::integer::server_key::radix_parallel::tests_long_run::{
|
||||
use crate::integer::server_key::radix_parallel::tests_unsigned::OpSequenceCpuFunctionExecutor;
|
||||
use crate::integer::tests::create_parameterized_test;
|
||||
use crate::integer::{BooleanBlock, IntegerKeyKind, RadixCiphertext, RadixClientKey, ServerKey};
|
||||
use crate::shortint::parameters::test_params::*;
|
||||
use crate::shortint::parameters::*;
|
||||
use crate::{ClientKey, CompressedServerKey, MatchValues, Seed, Tag};
|
||||
use std::cmp::{max, min};
|
||||
@@ -15,13 +14,11 @@ use std::num::NonZeroU64;
|
||||
use std::sync::Arc;
|
||||
|
||||
create_parameterized_test!(random_op_sequence {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
});
|
||||
|
||||
create_parameterized_test!(random_op_sequence_data_generator {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
});
|
||||
|
||||
pub(crate) type BinaryOpExecutor = Box<
|
||||
|
||||
@@ -9,18 +9,15 @@ use crate::integer::{
|
||||
BooleanBlock, IntegerCiphertext, IntegerKeyKind, RadixClientKey, ServerKey,
|
||||
SignedRadixCiphertext,
|
||||
};
|
||||
use crate::shortint::parameters::test_params::*;
|
||||
use crate::shortint::parameters::*;
|
||||
use rand::Rng;
|
||||
use std::sync::Arc;
|
||||
|
||||
create_parameterized_test!(whitepaper_erc20 {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
});
|
||||
create_parameterized_test!(no_cmux_erc20 {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
});
|
||||
|
||||
fn whitepaper_erc20<P>(param: P)
|
||||
|
||||
@@ -9,15 +9,13 @@ use crate::integer::tests::create_parameterized_test;
|
||||
use crate::integer::{
|
||||
BooleanBlock, IntegerKeyKind, RadixCiphertext, RadixClientKey, ServerKey, SignedRadixCiphertext,
|
||||
};
|
||||
use crate::shortint::parameters::test_params::*;
|
||||
use crate::shortint::parameters::*;
|
||||
use crate::{ClientKey, CompressedServerKey, Seed, Tag};
|
||||
use std::cmp::{max, min};
|
||||
use std::sync::Arc;
|
||||
|
||||
create_parameterized_test!(random_op_sequence {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
});
|
||||
|
||||
pub(crate) type SignedBinaryOpExecutor = Box<
|
||||
|
||||
@@ -31,8 +31,7 @@ create_parameterized_test!(
|
||||
no_coverage => {
|
||||
// Requires 4 bits, so 1_1 parameters are not supported
|
||||
// until they get their own version of the algorithm
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
@@ -60,8 +59,7 @@ create_parameterized_test!(
|
||||
no_coverage => {
|
||||
// Requires 4 bits, so 1_1 parameters are not supported
|
||||
// until they get their own version of the algorithm
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
|
||||
@@ -350,8 +350,7 @@ macro_rules! define_signed_comparison_test_functions {
|
||||
{
|
||||
// Non parallelized does not support 1_1
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
@@ -365,8 +364,7 @@ macro_rules! define_signed_comparison_test_functions {
|
||||
{
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
@@ -380,8 +378,7 @@ macro_rules! define_signed_comparison_test_functions {
|
||||
{
|
||||
// Non parallelized does not support PARAM_MESSAGE_1_CARRY_1_KS_PBS,
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as smart test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -397,8 +394,7 @@ macro_rules! define_signed_comparison_test_functions {
|
||||
{
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as smart test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -414,8 +410,7 @@ macro_rules! define_signed_comparison_test_functions {
|
||||
{
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as default test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -725,8 +720,7 @@ mod no_coverage {
|
||||
create_parameterized_test!(integer_signed_unchecked_min_parallelized_128_bits);
|
||||
create_parameterized_test!(integer_signed_smart_max_parallelized_128_bits {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as default test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -736,8 +730,7 @@ mod no_coverage {
|
||||
});
|
||||
create_parameterized_test!(integer_signed_smart_min_parallelized_128_bits {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as default test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -747,8 +740,7 @@ mod no_coverage {
|
||||
});
|
||||
create_parameterized_test!(integer_signed_max_parallelized_128_bits {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as default test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -758,8 +750,7 @@ mod no_coverage {
|
||||
});
|
||||
create_parameterized_test!(integer_signed_min_parallelized_128_bits {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as default test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
|
||||
@@ -23,8 +23,7 @@ create_parameterized_test!(
|
||||
},
|
||||
no_coverage => {
|
||||
// Does not support 1_1
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
@@ -43,8 +42,7 @@ create_parameterized_test!(
|
||||
},
|
||||
no_coverage => {
|
||||
// Does not support 1_1
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
|
||||
@@ -26,8 +26,7 @@ create_parameterized_test!(integer_signed_default_leading_ones);
|
||||
create_parameterized_test!(integer_signed_default_ilog2);
|
||||
create_parameterized_test!(integer_signed_default_checked_ilog2 {
|
||||
// uses comparison so 1_1 parameters are not supported
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
|
||||
@@ -26,8 +26,7 @@ create_parameterized_test!(
|
||||
},
|
||||
no_coverage => {
|
||||
// Uses comparisons internally, so no 1_1
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
|
||||
@@ -3,7 +3,6 @@ use crate::integer::server_key::radix_parallel::tests_cases_unsigned::FunctionEx
|
||||
use crate::integer::server_key::radix_parallel::tests_unsigned::CpuFunctionExecutor;
|
||||
use crate::integer::tests::create_parameterized_test;
|
||||
use crate::integer::{IntegerKeyKind, RadixClientKey, ServerKey, SignedRadixCiphertext};
|
||||
use crate::shortint::parameters::test_params::*;
|
||||
use crate::shortint::parameters::*;
|
||||
use statrs::distribution::ContinuousCDF;
|
||||
use std::collections::HashMap;
|
||||
@@ -11,13 +10,11 @@ use std::sync::Arc;
|
||||
use tfhe_csprng::seeders::Seed;
|
||||
|
||||
create_parameterized_test!(oprf_signed_uniformity_bounded {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
});
|
||||
|
||||
create_parameterized_test!(oprf_signed_uniformity_unbounded {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
});
|
||||
|
||||
fn oprf_signed_uniformity_bounded<P>(param: P)
|
||||
|
||||
@@ -269,8 +269,7 @@ macro_rules! define_signed_scalar_comparison_test_functions {
|
||||
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
@@ -285,8 +284,7 @@ macro_rules! define_signed_scalar_comparison_test_functions {
|
||||
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as smart test might overflow values
|
||||
// and when using 3_3 to represent 128 we actually have more than 128 bits
|
||||
@@ -303,8 +301,7 @@ macro_rules! define_signed_scalar_comparison_test_functions {
|
||||
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as default test might overflow values
|
||||
// and when using 3_3 to represent 128 we actually have more than 128 bits
|
||||
@@ -319,10 +316,9 @@ macro_rules! define_signed_scalar_comparison_test_functions {
|
||||
};
|
||||
}
|
||||
|
||||
fn integer_signed_is_scalar_out_of_bounds<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_signed_is_scalar_out_of_bounds(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let num_block = (128f64 / (param.message_modulus().0 as f64).log(2.0)).ceil() as usize;
|
||||
let num_block = (128f64 / (param.message_modulus.0 as f64).log(2.0)).ceil() as usize;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
@@ -578,56 +574,61 @@ pub(crate) fn test_signed_default_scalar_minmax<P, T, ClearF, Scalar>(
|
||||
mod no_coverage {
|
||||
use super::*;
|
||||
|
||||
fn integer_signed_unchecked_scalar_min_parallelized_i128(params: impl Into<TestParameters>) {
|
||||
fn integer_signed_unchecked_scalar_min_parallelized_i128(
|
||||
params: crate::shortint::ClassicPBSParameters,
|
||||
) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::unchecked_scalar_min_parallelized);
|
||||
test_signed_unchecked_scalar_minmax(params, 2, executor, std::cmp::min::<i128>);
|
||||
}
|
||||
|
||||
fn integer_signed_unchecked_scalar_max_parallelized_i128(params: impl Into<TestParameters>) {
|
||||
fn integer_signed_unchecked_scalar_max_parallelized_i128(
|
||||
params: crate::shortint::ClassicPBSParameters,
|
||||
) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::unchecked_scalar_max_parallelized);
|
||||
test_signed_unchecked_scalar_minmax(params, 2, executor, std::cmp::max::<i128>);
|
||||
}
|
||||
|
||||
fn integer_signed_smart_scalar_min_parallelized_i128(params: impl Into<TestParameters>) {
|
||||
fn integer_signed_smart_scalar_min_parallelized_i128(
|
||||
params: crate::shortint::ClassicPBSParameters,
|
||||
) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::smart_scalar_min_parallelized);
|
||||
test_signed_smart_scalar_minmax(params, 2, executor, std::cmp::min::<i128>);
|
||||
}
|
||||
|
||||
fn integer_signed_smart_scalar_max_parallelized_i128(params: impl Into<TestParameters>) {
|
||||
fn integer_signed_smart_scalar_max_parallelized_i128(
|
||||
params: crate::shortint::ClassicPBSParameters,
|
||||
) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::smart_scalar_max_parallelized);
|
||||
test_signed_smart_scalar_minmax(params, 2, executor, std::cmp::max::<i128>);
|
||||
}
|
||||
|
||||
fn integer_signed_scalar_min_parallelized_i128(params: impl Into<TestParameters>) {
|
||||
fn integer_signed_scalar_min_parallelized_i128(params: crate::shortint::ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::scalar_min_parallelized);
|
||||
test_signed_default_scalar_minmax(params, 2, executor, std::cmp::min::<i128>);
|
||||
}
|
||||
|
||||
fn integer_signed_scalar_max_parallelized_i128(params: impl Into<TestParameters>) {
|
||||
fn integer_signed_scalar_max_parallelized_i128(params: crate::shortint::ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::scalar_max_parallelized);
|
||||
test_signed_default_scalar_minmax(params, 2, executor, std::cmp::max::<i128>);
|
||||
}
|
||||
|
||||
create_parameterized_test!(integer_signed_unchecked_scalar_max_parallelized_i128 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
});
|
||||
create_parameterized_test!(integer_signed_unchecked_scalar_min_parallelized_i128 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
});
|
||||
create_parameterized_test!(integer_signed_smart_scalar_max_parallelized_i128 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as default test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -637,8 +638,7 @@ mod no_coverage {
|
||||
});
|
||||
create_parameterized_test!(integer_signed_smart_scalar_min_parallelized_i128 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as default test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -648,8 +648,7 @@ mod no_coverage {
|
||||
});
|
||||
create_parameterized_test!(integer_signed_scalar_max_parallelized_i128 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as default test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -659,8 +658,7 @@ mod no_coverage {
|
||||
});
|
||||
create_parameterized_test!(integer_signed_scalar_min_parallelized_i128 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as default test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -678,8 +676,7 @@ mod no_coverage {
|
||||
|
||||
create_parameterized_test!(integer_signed_is_scalar_out_of_bounds {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as the test relies on the ciphertext to encrypt 128bits
|
||||
// but with param 3_3 we actually encrypt more that 128bits
|
||||
@@ -694,31 +691,39 @@ mod coverage {
|
||||
use super::*;
|
||||
use crate::integer::tests::create_parameterized_test_classical_params;
|
||||
|
||||
fn integer_signed_unchecked_scalar_min_parallelized_i8(params: impl Into<TestParameters>) {
|
||||
fn integer_signed_unchecked_scalar_min_parallelized_i8(
|
||||
params: crate::shortint::ClassicPBSParameters,
|
||||
) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::unchecked_scalar_min_parallelized);
|
||||
test_signed_unchecked_scalar_minmax(params, 1, executor, std::cmp::min::<i8>);
|
||||
}
|
||||
|
||||
fn integer_signed_unchecked_scalar_max_parallelized_i8(params: impl Into<TestParameters>) {
|
||||
fn integer_signed_unchecked_scalar_max_parallelized_i8(
|
||||
params: crate::shortint::ClassicPBSParameters,
|
||||
) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::unchecked_scalar_max_parallelized);
|
||||
test_signed_unchecked_scalar_minmax(params, 1, executor, std::cmp::max::<i8>);
|
||||
}
|
||||
fn integer_signed_smart_scalar_min_parallelized_i8(params: impl Into<TestParameters>) {
|
||||
fn integer_signed_smart_scalar_min_parallelized_i8(
|
||||
params: crate::shortint::ClassicPBSParameters,
|
||||
) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::smart_scalar_min_parallelized);
|
||||
test_signed_smart_scalar_minmax(params, 1, executor, std::cmp::min::<i8>);
|
||||
}
|
||||
|
||||
fn integer_signed_smart_scalar_max_parallelized_i8(params: impl Into<TestParameters>) {
|
||||
fn integer_signed_smart_scalar_max_parallelized_i8(
|
||||
params: crate::shortint::ClassicPBSParameters,
|
||||
) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::smart_scalar_max_parallelized);
|
||||
test_signed_smart_scalar_minmax(params, 1, executor, std::cmp::max::<i8>);
|
||||
}
|
||||
|
||||
fn integer_signed_scalar_min_parallelized_i8(params: impl Into<TestParameters>) {
|
||||
fn integer_signed_scalar_min_parallelized_i8(params: crate::shortint::ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::scalar_min_parallelized);
|
||||
test_signed_default_scalar_minmax(params, 1, executor, std::cmp::min::<i8>);
|
||||
}
|
||||
|
||||
fn integer_signed_scalar_max_parallelized_i8(params: impl Into<TestParameters>) {
|
||||
fn integer_signed_scalar_max_parallelized_i8(params: crate::shortint::ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::scalar_max_parallelized);
|
||||
test_signed_default_scalar_minmax(params, 1, executor, std::cmp::max::<i8>);
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ create_parameterized_test!(integer_signed_default_overflowing_sub_parallel {
|
||||
COVERAGE_PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_2_KS_PBS
|
||||
},
|
||||
no_coverage => {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
|
||||
@@ -522,8 +522,7 @@ create_parameterized_test!(
|
||||
},
|
||||
no_coverage => {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_2_CARRY_3_KS_PBS_GAUSSIAN_2M128, // Test case where carry_modulus > message_modulus
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
|
||||
@@ -30,8 +30,7 @@ create_parameterized_test!(integer_advanced_overflowing_add_assign_with_carry_at
|
||||
COVERAGE_PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_2_KS_PBS
|
||||
},
|
||||
no_coverage => {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
@@ -48,8 +47,7 @@ create_parameterized_test!(integer_extensive_trivial_overflowing_advanced_add_as
|
||||
COVERAGE_PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_2_KS_PBS
|
||||
},
|
||||
no_coverage => {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
|
||||
@@ -321,8 +321,7 @@ macro_rules! define_comparison_test_functions {
|
||||
{
|
||||
// Non parallelized does not support 1_1
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
@@ -335,8 +334,7 @@ macro_rules! define_comparison_test_functions {
|
||||
{
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
@@ -350,8 +348,7 @@ macro_rules! define_comparison_test_functions {
|
||||
{
|
||||
// Non parallelized does not support 1_1
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as smart test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -367,8 +364,7 @@ macro_rules! define_comparison_test_functions {
|
||||
{
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as smart test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -384,8 +380,7 @@ macro_rules! define_comparison_test_functions {
|
||||
{
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as default test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -675,32 +670,28 @@ mod no_coverage {
|
||||
create_parameterized_test!(integer_unchecked_max_parallelized_u256);
|
||||
create_parameterized_test!(integer_smart_min_parallelized_u256 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// No test for 3_3, see define_comparison_test_functions macro
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
});
|
||||
create_parameterized_test!(integer_smart_max_parallelized_u256 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// No test for 3_3, see define_comparison_test_functions macro
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
});
|
||||
create_parameterized_test!(integer_min_parallelized_u256 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// No test for 3_3, see define_comparison_test_functions macro
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
});
|
||||
create_parameterized_test!(integer_max_parallelized_u256 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// No test for 3_3, see define_comparison_test_functions macro
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
|
||||
@@ -21,8 +21,7 @@ create_parameterized_test!(
|
||||
no_coverage => {
|
||||
// Due to the use of comparison,
|
||||
// this algorithm requires 3 bits
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
@@ -42,8 +41,7 @@ create_parameterized_test!(
|
||||
no_coverage => {
|
||||
// Due to the use of comparison,
|
||||
// this algorithm requires 3 bits
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
@@ -63,8 +61,7 @@ create_parameterized_test!(
|
||||
no_coverage => {
|
||||
// Due to the use of comparison,
|
||||
// this algorithm requires 3 bits
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
@@ -84,8 +81,7 @@ create_parameterized_test!(
|
||||
no_coverage => {
|
||||
// Due to the use of comparison,
|
||||
// this algorithm requires 3 bits
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
@@ -105,8 +101,7 @@ create_parameterized_test!(
|
||||
no_coverage => {
|
||||
// Due to the use of comparison,
|
||||
// this algorithm requires 3 bits
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
@@ -126,8 +121,7 @@ create_parameterized_test!(
|
||||
no_coverage => {
|
||||
// Due to the use of comparison,
|
||||
// this algorithm requires 3 bits
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
@@ -148,8 +142,7 @@ create_parameterized_test!(
|
||||
// Due to the use of comparison,
|
||||
// this algorithm requires 3 bits
|
||||
// The algorithm is agnostic to multibit so we don't test those params
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ create_parameterized_test!(integer_default_leading_ones);
|
||||
create_parameterized_test!(integer_default_ilog2);
|
||||
create_parameterized_test!(integer_default_checked_ilog2 {
|
||||
// This uses comparisons, so require more than 1 bit
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
|
||||
@@ -18,8 +18,7 @@ create_parameterized_test!(
|
||||
},
|
||||
no_coverage => {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
@@ -38,8 +37,7 @@ create_parameterized_test!(
|
||||
},
|
||||
no_coverage => {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
|
||||
@@ -248,8 +248,7 @@ macro_rules! define_scalar_comparison_test_functions {
|
||||
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
|
||||
@@ -263,8 +262,7 @@ macro_rules! define_scalar_comparison_test_functions {
|
||||
{
|
||||
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as smart test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -280,8 +278,7 @@ macro_rules! define_scalar_comparison_test_functions {
|
||||
{
|
||||
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as default test might overflow values
|
||||
// and when using 3_3 to represent 256 we actually have more than 256 bits
|
||||
@@ -299,11 +296,10 @@ macro_rules! define_scalar_comparison_test_functions {
|
||||
/// The goal of this function is to ensure that scalar comparisons
|
||||
/// work when the scalar type used is either bigger or smaller (in bit size)
|
||||
/// compared to the ciphertext
|
||||
fn integer_unchecked_scalar_comparisons_edge<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_unchecked_scalar_comparisons_edge(param: ClassicPBSParameters) {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let num_block = (128f64 / (param.message_modulus().0 as f64).log(2.0)).ceil() as usize;
|
||||
let num_block = (128f64 / (param.message_modulus.0 as f64).log(2.0)).ceil() as usize;
|
||||
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
@@ -406,8 +402,7 @@ fn integer_unchecked_scalar_comparisons_edge<P: Into<TestParameters>>(param: P)
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_unchecked_scalar_comparisons_edge_one_block<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_unchecked_scalar_comparisons_edge_one_block(param: ClassicPBSParameters) {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let num_block = 1;
|
||||
@@ -491,8 +486,7 @@ fn integer_unchecked_scalar_comparisons_edge_one_block<P: Into<TestParameters>>(
|
||||
|
||||
// Given a ciphertext that consists of empty blocks,
|
||||
// the function tests whether comparisons still hold.
|
||||
fn integer_comparisons_for_empty_blocks<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_comparisons_for_empty_blocks(param: ClassicPBSParameters) {
|
||||
let mut rng = rand::thread_rng();
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
|
||||
@@ -525,10 +519,9 @@ fn integer_comparisons_for_empty_blocks<P: Into<TestParameters>>(param: P) {
|
||||
}
|
||||
}
|
||||
|
||||
fn integer_is_scalar_out_of_bounds<P: Into<TestParameters>>(param: P) {
|
||||
let param: TestParameters = param.into();
|
||||
fn integer_is_scalar_out_of_bounds(param: ClassicPBSParameters) {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let num_block = 128usize.div_ceil(param.message_modulus().0.ilog2() as usize);
|
||||
let num_block = 128usize.div_ceil(param.message_modulus.0.ilog2() as usize);
|
||||
|
||||
let mut rng = thread_rng();
|
||||
|
||||
@@ -771,64 +764,64 @@ pub(crate) fn test_default_scalar_minmax<P, T, ClearF, Scalar>(
|
||||
mod no_coverage {
|
||||
use super::*;
|
||||
|
||||
fn integer_unchecked_scalar_min_parallelized_u256(params: impl Into<TestParameters>) {
|
||||
fn integer_unchecked_scalar_min_parallelized_u256(
|
||||
params: crate::shortint::ClassicPBSParameters,
|
||||
) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::unchecked_scalar_min_parallelized);
|
||||
test_unchecked_scalar_minmax(params, 2, executor, std::cmp::min::<U256>);
|
||||
}
|
||||
|
||||
fn integer_unchecked_scalar_max_parallelized_u256(params: impl Into<TestParameters>) {
|
||||
fn integer_unchecked_scalar_max_parallelized_u256(
|
||||
params: crate::shortint::ClassicPBSParameters,
|
||||
) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::unchecked_scalar_max_parallelized);
|
||||
test_unchecked_scalar_minmax(params, 2, executor, std::cmp::max::<U256>);
|
||||
}
|
||||
|
||||
fn integer_smart_scalar_min_parallelized_u256(params: impl Into<TestParameters>) {
|
||||
fn integer_smart_scalar_min_parallelized_u256(params: crate::shortint::ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::smart_scalar_min_parallelized);
|
||||
test_smart_scalar_minmax(params, 2, executor, std::cmp::min::<U256>);
|
||||
}
|
||||
|
||||
fn integer_smart_scalar_max_parallelized_u256(params: impl Into<TestParameters>) {
|
||||
fn integer_smart_scalar_max_parallelized_u256(params: crate::shortint::ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::smart_scalar_max_parallelized);
|
||||
test_smart_scalar_minmax(params, 2, executor, std::cmp::max::<U256>);
|
||||
}
|
||||
|
||||
fn integer_scalar_min_parallelized_u256(params: impl Into<TestParameters>) {
|
||||
fn integer_scalar_min_parallelized_u256(params: crate::shortint::ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::scalar_min_parallelized);
|
||||
test_default_scalar_minmax(params, 2, executor, std::cmp::min::<U256>);
|
||||
}
|
||||
|
||||
fn integer_scalar_max_parallelized_u256(params: impl Into<TestParameters>) {
|
||||
fn integer_scalar_max_parallelized_u256(params: crate::shortint::ClassicPBSParameters) {
|
||||
let executor = CpuFunctionExecutor::new(&ServerKey::scalar_max_parallelized);
|
||||
test_default_scalar_minmax(params, 2, executor, std::cmp::max::<U256>);
|
||||
}
|
||||
|
||||
create_parameterized_test!(integer_unchecked_scalar_min_parallelized_u256 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
});
|
||||
create_parameterized_test!(integer_unchecked_scalar_max_parallelized_u256 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
});
|
||||
create_parameterized_test!(integer_smart_scalar_min_parallelized_u256 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// No test for 3_3, see define_scalar_comparison_test_functions macro
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
});
|
||||
create_parameterized_test!(integer_smart_scalar_max_parallelized_u256 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// No test for 3_3, see define_scalar_comparison_test_functions macro
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
@@ -836,16 +829,14 @@ mod no_coverage {
|
||||
|
||||
create_parameterized_test!(integer_scalar_min_parallelized_u256 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// No test for 3_3, see define_scalar_comparison_test_functions macro
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
});
|
||||
create_parameterized_test!(integer_scalar_max_parallelized_u256 {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// No test for 3_3, see define_scalar_comparison_test_functions macro
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
@@ -860,8 +851,7 @@ mod no_coverage {
|
||||
|
||||
create_parameterized_test!(integer_unchecked_scalar_comparisons_edge {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
@@ -869,16 +859,14 @@ mod no_coverage {
|
||||
|
||||
create_parameterized_test!(integer_unchecked_scalar_comparisons_edge_one_block {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
});
|
||||
|
||||
create_parameterized_test!(integer_is_scalar_out_of_bounds {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
// We don't use PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
// as the test relies on the ciphertext to encrypt 128bits
|
||||
// but with param 3_3 we actually encrypt more that 128bits
|
||||
@@ -888,8 +876,7 @@ mod no_coverage {
|
||||
|
||||
create_parameterized_test!(integer_comparisons_for_empty_blocks {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
|
||||
@@ -17,8 +17,7 @@ create_parameterized_test!(
|
||||
},
|
||||
no_coverage => {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -29,8 +28,7 @@ create_parameterized_test!(
|
||||
COVERAGE_PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||
},
|
||||
no_coverage => {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -30,8 +30,7 @@ create_parameterized_test!(integer_advanced_sub_assign_with_borrow_at_least_4_bi
|
||||
COVERAGE_PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_2_KS_PBS
|
||||
},
|
||||
no_coverage => {
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
|
||||
@@ -24,7 +24,7 @@ macro_rules! create_parameterized_test {
|
||||
},
|
||||
no_coverage => {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
@@ -33,9 +33,7 @@ macro_rules! create_parameterized_test {
|
||||
TEST_PARAM_MULTI_BIT_GROUP_2_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M64,
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M64,
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M64,
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M64,
|
||||
// Test prod params
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M64
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -69,12 +67,10 @@ macro_rules! create_parameterized_test_classical_params {
|
||||
},
|
||||
no_coverage => {
|
||||
TEST_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
|
||||
TEST_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128,
|
||||
// 2M128 is too slow for 4_4, it is estimated to be 2x slower
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64,
|
||||
// Test prod params
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
TEST_PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -82,9 +82,7 @@ impl Upgrade<CompactCiphertextListV1> for CompactCiphertextListV0 {
|
||||
degree: self.degree,
|
||||
message_modulus: self.message_modulus,
|
||||
carry_modulus: self.carry_modulus,
|
||||
expansion_kind: CompactCiphertextListExpansionKind::NoCasting(
|
||||
AtomicPatternKind::Standard(self.pbs_order),
|
||||
),
|
||||
expansion_kind: CompactCiphertextListExpansionKind::NoCasting(self.pbs_order),
|
||||
noise_level: self.noise_level,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7,31 +7,10 @@ use super::parameters::{
|
||||
CompactCiphertextListExpansionKind, DynamicDistribution, SupportedCompactPkeZkScheme,
|
||||
};
|
||||
use super::prelude::*;
|
||||
use crate::shortint::AtomicPatternKind;
|
||||
|
||||
#[derive(Version)]
|
||||
pub enum CompactCiphertextListExpansionKindV0 {
|
||||
RequiresCasting,
|
||||
NoCasting(PBSOrder),
|
||||
}
|
||||
|
||||
impl Upgrade<CompactCiphertextListExpansionKind> for CompactCiphertextListExpansionKindV0 {
|
||||
type Error = Infallible;
|
||||
|
||||
fn upgrade(self) -> Result<CompactCiphertextListExpansionKind, Self::Error> {
|
||||
Ok(match self {
|
||||
Self::RequiresCasting => CompactCiphertextListExpansionKind::RequiresCasting,
|
||||
Self::NoCasting(pbsorder) => {
|
||||
CompactCiphertextListExpansionKind::NoCasting(AtomicPatternKind::Standard(pbsorder))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(VersionsDispatch)]
|
||||
pub enum CompactCiphertextListExpansionKindVersions {
|
||||
V0(CompactCiphertextListExpansionKindV0),
|
||||
V1(CompactCiphertextListExpansionKind),
|
||||
V0(CompactCiphertextListExpansionKind),
|
||||
}
|
||||
|
||||
#[derive(Version)]
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::shortint::atomic_pattern::AtomicPattern;
|
||||
use crate::shortint::backward_compatibility::ciphertext::CompactCiphertextListVersions;
|
||||
pub use crate::shortint::parameters::ShortintCompactCiphertextListCastingMode;
|
||||
use crate::shortint::parameters::{
|
||||
CarryModulus, CompactCiphertextListExpansionKind, MessageModulus,
|
||||
AtomicPatternKind, CarryModulus, CompactCiphertextListExpansionKind, MessageModulus,
|
||||
};
|
||||
use rayon::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -144,7 +144,7 @@ impl CompactCiphertextList {
|
||||
.collect::<Vec<_>>();
|
||||
Ok(res)
|
||||
}
|
||||
(CompactCiphertextListExpansionKind::NoCasting(atomic_pattern), _) => {
|
||||
(CompactCiphertextListExpansionKind::NoCasting(pbs_order), _) => {
|
||||
let res = output_lwe_ciphertext_list
|
||||
.iter()
|
||||
.map(|lwe_view| {
|
||||
@@ -152,6 +152,7 @@ impl CompactCiphertextList {
|
||||
lwe_view.as_ref().to_vec(),
|
||||
self.ct_list.ciphertext_modulus(),
|
||||
);
|
||||
let atomic_pattern = AtomicPatternKind::Standard(pbs_order);
|
||||
|
||||
Ciphertext::new(
|
||||
ct,
|
||||
|
||||
@@ -4,7 +4,6 @@ use crate::core_crypto::algorithms::*;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
use crate::core_crypto::entities::*;
|
||||
use crate::shortint::ciphertext::{Degree, NoiseLevel};
|
||||
use crate::shortint::client_key::atomic_pattern::EncryptionAtomicPattern;
|
||||
use crate::shortint::parameters::{AtomicPatternKind, CarryModulus, MessageModulus};
|
||||
use crate::shortint::{
|
||||
Ciphertext, ClientKey, CompressedPublicKey, PaddingBit, PublicKey, ShortintEncoding,
|
||||
@@ -48,11 +47,12 @@ impl ShortintEngine {
|
||||
client_key.parameters().ciphertext_modulus(),
|
||||
&mut self.encryption_generator,
|
||||
);
|
||||
|
||||
PublicKey {
|
||||
lwe_public_key,
|
||||
parameters: client_key.parameters(),
|
||||
atomic_pattern: client_key.atomic_pattern.kind(),
|
||||
atomic_pattern: AtomicPatternKind::Standard(
|
||||
client_key.parameters().encryption_key_choice().into(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::shortint::parameters::v1_6::meta::cpu::V1_6_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
use crate::shortint::parameters::{
|
||||
current_params, ClassicPBSParameters, CompactPublicKeyEncryptionParameters,
|
||||
CompressionParameters, KeySwitch32PBSParameters, MetaParameters, MultiBitPBSParameters,
|
||||
CompressionParameters, KeySwitch32PBSParameters, MultiBitPBSParameters,
|
||||
NoiseSquashingCompressionParameters, NoiseSquashingParameters, ShortintKeySwitchingParameters,
|
||||
};
|
||||
|
||||
@@ -75,6 +74,11 @@ pub const PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M64: ClassicPBSParameters =
|
||||
pub const PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128: ClassicPBSParameters =
|
||||
V1_6_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
pub const PARAM_MESSAGE_2_CARRY_2_KS_PBS: ClassicPBSParameters =
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
pub const PARAM_MESSAGE_2_CARRY_2: ClassicPBSParameters = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
|
||||
// 2M64
|
||||
pub const PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: ClassicPBSParameters =
|
||||
V1_6_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64;
|
||||
@@ -84,21 +88,6 @@ pub const PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: ClassicPBSParameters =
|
||||
pub const PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128: KeySwitch32PBSParameters =
|
||||
V1_6_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
|
||||
// "Naked" aliases
|
||||
pub const PARAM_MESSAGE_2_CARRY_2_KS_PBS: ClassicPBSParameters =
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
pub const PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128: ClassicPBSParameters =
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
pub const PARAM_MESSAGE_2_CARRY_2_KS32_PBS: KeySwitch32PBSParameters =
|
||||
PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
|
||||
|
||||
pub const META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128: MetaParameters =
|
||||
V1_6_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
|
||||
pub const PARAM_MESSAGE_2_CARRY_2: KeySwitch32PBSParameters = PARAM_MESSAGE_2_CARRY_2_KS32_PBS;
|
||||
|
||||
// Compression Gaussian
|
||||
// 2M128
|
||||
pub const COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128: CompressionParameters =
|
||||
|
||||
@@ -4,8 +4,8 @@ use crate::shortint::backward_compatibility::parameters::compact_public_key_only
|
||||
};
|
||||
use crate::shortint::parameters::{
|
||||
AtomicPatternKind, CarryModulus, CiphertextModulus, ClassicPBSParameters, DynamicDistribution,
|
||||
LweDimension, MessageModulus, MultiBitPBSParameters, PBSParameters, ShortintParameterSet,
|
||||
SupportedCompactPkeZkScheme,
|
||||
LweDimension, MessageModulus, MultiBitPBSParameters, PBSOrder, PBSParameters,
|
||||
ShortintParameterSet, SupportedCompactPkeZkScheme,
|
||||
};
|
||||
use crate::shortint::{KeySwitchingKeyView, PaddingBit, ShortintEncoding};
|
||||
use crate::Error;
|
||||
@@ -16,7 +16,7 @@ use tfhe_versionable::Versionize;
|
||||
#[versionize(CompactCiphertextListExpansionKindVersions)]
|
||||
pub enum CompactCiphertextListExpansionKind {
|
||||
RequiresCasting,
|
||||
NoCasting(AtomicPatternKind),
|
||||
NoCasting(PBSOrder),
|
||||
}
|
||||
|
||||
pub type CastingFunctionsOwned<'functions> =
|
||||
@@ -35,7 +35,10 @@ pub enum ShortintCompactCiphertextListCastingMode<'a> {
|
||||
|
||||
impl From<AtomicPatternKind> for CompactCiphertextListExpansionKind {
|
||||
fn from(value: AtomicPatternKind) -> Self {
|
||||
Self::NoCasting(value)
|
||||
match value {
|
||||
AtomicPatternKind::Standard(pbsorder) => Self::NoCasting(pbsorder),
|
||||
AtomicPatternKind::KeySwitch32 => Self::NoCasting(PBSOrder::KeyswitchBootstrap),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +129,9 @@ impl TryFrom<ShortintParameterSet> for CompactPublicKeyEncryptionParameters {
|
||||
let message_modulus = parameters.message_modulus();
|
||||
let carry_modulus = parameters.carry_modulus();
|
||||
let ciphertext_modulus = parameters.ciphertext_modulus();
|
||||
let output_ciphertext_kind = parameters.atomic_pattern().into();
|
||||
let output_ciphertext_kind = CompactCiphertextListExpansionKind::NoCasting(
|
||||
parameters.encryption_key_choice().into(),
|
||||
);
|
||||
|
||||
Self::try_new(
|
||||
encryption_lwe_dimension,
|
||||
|
||||
@@ -240,12 +240,6 @@ pub const TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128: Met
|
||||
pub const TEST_META_PARAM_CPU_2_2_KS_PBS_GAUSSIAN_2M128: MetaParameters =
|
||||
V1_6_META_PARAM_CPU_2_2_KS_PBS_GAUSSIAN_2M128;
|
||||
|
||||
pub const TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128: ClassicPBSParameters =
|
||||
V1_6_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
|
||||
|
||||
pub const TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128: MetaParameters =
|
||||
V1_6_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
|
||||
|
||||
// GPU params we want to check for full scenario
|
||||
pub const TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128:
|
||||
MetaParameters =
|
||||
|
||||
@@ -20,7 +20,6 @@ use crate::shortint::parameters::test_params::{
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_GAUSSIAN_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
};
|
||||
use crate::shortint::parameters::{AtomicPatternParameters, CarryModulus, MetaParameters};
|
||||
use crate::shortint::server_key::tests::noise_distribution::utils::noise_simulation::NoiseSimulationModulus;
|
||||
@@ -172,9 +171,9 @@ fn sanity_check_encrypt_br_dp_ks_pbs(meta_params: MetaParameters) {
|
||||
|
||||
create_parameterized_test!(sanity_check_encrypt_br_dp_ks_pbs {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_GAUSSIAN_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
fn encrypt_br_dp_ks_any_ms_inner_helper(
|
||||
@@ -416,9 +415,9 @@ fn noise_check_encrypt_br_dp_ks_ms_noise(meta_params: MetaParameters) {
|
||||
|
||||
create_parameterized_test!(noise_check_encrypt_br_dp_ks_ms_noise {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_GAUSSIAN_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
fn noise_check_encrypt_br_dp_ks_ms_pfail(meta_params: MetaParameters) {
|
||||
@@ -485,8 +484,7 @@ fn noise_check_encrypt_br_dp_ks_ms_pfail(meta_params: MetaParameters) {
|
||||
|
||||
create_parameterized_test!(noise_check_encrypt_br_dp_ks_ms_pfail {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_GAUSSIAN_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
@@ -15,7 +15,6 @@ use crate::shortint::parameters::test_params::{
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
};
|
||||
use crate::shortint::parameters::{
|
||||
AtomicPatternParameters, CarryModulus, CiphertextModulusLog, CompressionParameters,
|
||||
@@ -161,9 +160,9 @@ fn sanity_check_encrypt_br_dp_packing_ks_ms(meta_params: MetaParameters) {
|
||||
}
|
||||
|
||||
create_parameterized_test!(sanity_check_encrypt_br_dp_packing_ks_ms {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
@@ -507,9 +506,9 @@ fn noise_check_encrypt_br_dp_packing_ks_ms_noise(meta_params: MetaParameters) {
|
||||
assert!(before_ms_normality.null_hypothesis_is_valid && after_ms_is_ok);
|
||||
}
|
||||
create_parameterized_test!(noise_check_encrypt_br_dp_packing_ks_ms_noise {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
fn noise_check_encrypt_br_dp_packing_ks_ms_pfail(meta_params: MetaParameters) {
|
||||
@@ -675,8 +674,7 @@ fn noise_check_encrypt_br_dp_packing_ks_ms_pfail(meta_params: MetaParameters) {
|
||||
}
|
||||
|
||||
create_parameterized_test!(noise_check_encrypt_br_dp_packing_ks_ms_pfail {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
@@ -31,7 +31,6 @@ use crate::shortint::parameters::test_params::{
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
};
|
||||
use crate::shortint::parameters::{
|
||||
AtomicPatternParameters, CarryModulus, CompactCiphertextListExpansionKind,
|
||||
@@ -490,7 +489,9 @@ fn noise_check_encrypt_br_rerand_dp_ks_ms_noise(meta_params: MetaParameters) {
|
||||
// expand
|
||||
let cpk_params = {
|
||||
let mut cpk_params = dedicated_cpk_params.pke_params;
|
||||
cpk_params.expansion_kind = compute_params.atomic_pattern().into();
|
||||
cpk_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting(
|
||||
compute_params.encryption_key_choice().into_pbs_order(),
|
||||
);
|
||||
cpk_params
|
||||
};
|
||||
|
||||
@@ -682,9 +683,9 @@ fn noise_check_encrypt_br_rerand_dp_ks_ms_noise(meta_params: MetaParameters) {
|
||||
}
|
||||
|
||||
create_parameterized_test!(noise_check_encrypt_br_rerand_dp_ks_ms_noise {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
fn noise_check_encrypt_br_rerand_dp_ks_ms_pfail(meta_params: MetaParameters) {
|
||||
@@ -697,8 +698,9 @@ fn noise_check_encrypt_br_rerand_dp_ks_ms_pfail(meta_params: MetaParameters) {
|
||||
// expand
|
||||
let cpk_params = {
|
||||
let mut cpk_params = dedicated_cpk_params.pke_params;
|
||||
cpk_params.expansion_kind =
|
||||
CompactCiphertextListExpansionKind::NoCasting(compute_params.atomic_pattern());
|
||||
cpk_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting(
|
||||
compute_params.encryption_key_choice().into_pbs_order(),
|
||||
);
|
||||
cpk_params
|
||||
};
|
||||
|
||||
@@ -791,9 +793,9 @@ fn noise_check_encrypt_br_rerand_dp_ks_ms_pfail(meta_params: MetaParameters) {
|
||||
}
|
||||
|
||||
create_parameterized_test!(noise_check_encrypt_br_rerand_dp_ks_ms_pfail {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
fn sanity_check_encrypt_br_rerand_dp_ks_ms_pbs(meta_params: MetaParameters) {
|
||||
@@ -806,8 +808,9 @@ fn sanity_check_encrypt_br_rerand_dp_ks_ms_pbs(meta_params: MetaParameters) {
|
||||
// expand
|
||||
let cpk_params = {
|
||||
let mut cpk_params = dedicated_cpk_params.pke_params;
|
||||
cpk_params.expansion_kind =
|
||||
CompactCiphertextListExpansionKind::NoCasting(compute_params.atomic_pattern());
|
||||
cpk_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting(
|
||||
compute_params.encryption_key_choice().into_pbs_order(),
|
||||
);
|
||||
cpk_params
|
||||
};
|
||||
|
||||
@@ -954,8 +957,7 @@ fn sanity_check_encrypt_br_rerand_dp_ks_ms_pbs(meta_params: MetaParameters) {
|
||||
}
|
||||
|
||||
create_parameterized_test!(sanity_check_encrypt_br_rerand_dp_ks_ms_pbs {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
@@ -16,7 +16,6 @@ use crate::shortint::parameters::test_params::{
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
};
|
||||
use crate::shortint::parameters::{
|
||||
AtomicPatternParameters, CarryModulus, CompactCiphertextListExpansionKind,
|
||||
@@ -258,7 +257,9 @@ fn noise_check_encrypt_cpk_ks_ms_noise(meta_params: MetaParameters) {
|
||||
// expand
|
||||
let cpk_params = {
|
||||
let mut cpk_params = dedicated_cpk_params.pke_params;
|
||||
cpk_params.expansion_kind = compute_params.atomic_pattern().into();
|
||||
cpk_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting(
|
||||
compute_params.encryption_key_choice().into_pbs_order(),
|
||||
);
|
||||
cpk_params
|
||||
};
|
||||
|
||||
@@ -375,9 +376,9 @@ fn noise_check_encrypt_cpk_ks_ms_noise(meta_params: MetaParameters) {
|
||||
}
|
||||
|
||||
create_parameterized_test!(noise_check_encrypt_cpk_ks_ms_noise {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
fn noise_check_encrypt_cpk_ks_ms_pfail(meta_params: MetaParameters) {
|
||||
@@ -390,7 +391,9 @@ fn noise_check_encrypt_cpk_ks_ms_pfail(meta_params: MetaParameters) {
|
||||
// expand
|
||||
let cpk_params = {
|
||||
let mut cpk_params = dedicated_cpk_params.pke_params;
|
||||
cpk_params.expansion_kind = compute_params.atomic_pattern().into();
|
||||
cpk_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting(
|
||||
compute_params.encryption_key_choice().into_pbs_order(),
|
||||
);
|
||||
cpk_params
|
||||
};
|
||||
|
||||
@@ -470,9 +473,9 @@ fn noise_check_encrypt_cpk_ks_ms_pfail(meta_params: MetaParameters) {
|
||||
}
|
||||
|
||||
create_parameterized_test!(noise_check_encrypt_cpk_ks_ms_pfail {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
fn sanity_check_encrypt_cpk_ks_ms_pbs(meta_params: MetaParameters) {
|
||||
@@ -486,7 +489,9 @@ fn sanity_check_encrypt_cpk_ks_ms_pbs(meta_params: MetaParameters) {
|
||||
let (cpk_params, orig_cast_mode) = {
|
||||
let mut cpk_params = dedicated_cpk_params.pke_params;
|
||||
let orig_cast_mode = cpk_params.expansion_kind;
|
||||
cpk_params.expansion_kind = compute_params.atomic_pattern().into();
|
||||
cpk_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting(
|
||||
compute_params.encryption_key_choice().into_pbs_order(),
|
||||
);
|
||||
(cpk_params, orig_cast_mode)
|
||||
};
|
||||
|
||||
@@ -567,8 +572,7 @@ fn sanity_check_encrypt_cpk_ks_ms_pbs(meta_params: MetaParameters) {
|
||||
}
|
||||
|
||||
create_parameterized_test!(sanity_check_encrypt_cpk_ks_ms_pbs {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
@@ -13,7 +13,6 @@ use crate::shortint::parameters::test_params::{
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_GAUSSIAN_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
};
|
||||
use crate::shortint::parameters::{AtomicPatternParameters, CarryModulus, MetaParameters};
|
||||
use crate::shortint::server_key::tests::parameterized_test::create_parameterized_test;
|
||||
@@ -207,9 +206,9 @@ fn sanity_check_encrypt_dp_ks_pbs(meta_params: MetaParameters) {
|
||||
|
||||
create_parameterized_test!(sanity_check_encrypt_dp_ks_pbs {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_GAUSSIAN_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
fn encrypt_dp_ks_any_ms_inner_helper(
|
||||
@@ -420,9 +419,9 @@ fn noise_check_encrypt_dp_ks_ms_noise(meta_params: MetaParameters) {
|
||||
|
||||
create_parameterized_test!(noise_check_encrypt_dp_ks_ms_noise {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_GAUSSIAN_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
fn noise_check_encrypt_dp_ks_ms_pfail(meta_params: MetaParameters) {
|
||||
@@ -489,8 +488,7 @@ fn noise_check_encrypt_dp_ks_ms_pfail(meta_params: MetaParameters) {
|
||||
|
||||
create_parameterized_test!(noise_check_encrypt_dp_ks_ms_pfail {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_GAUSSIAN_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
@@ -18,7 +18,6 @@ use crate::shortint::parameters::test_params::{
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
};
|
||||
use crate::shortint::parameters::{
|
||||
AtomicPatternParameters, MetaParameters, NoiseSquashingCompressionParameters,
|
||||
@@ -336,9 +335,9 @@ fn sanity_check_encrypt_dp_ks_standard_pbs128_packing_ks(meta_params: MetaParame
|
||||
}
|
||||
|
||||
create_parameterized_test!(sanity_check_encrypt_dp_ks_standard_pbs128_packing_ks {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -746,8 +745,7 @@ fn noise_check_encrypt_dp_ks_standard_pbs128_packing_ks_noise(meta_params: MetaP
|
||||
}
|
||||
|
||||
create_parameterized_test!(noise_check_encrypt_dp_ks_standard_pbs128_packing_ks_noise {
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_GPU_2_2_MULTI_BIT_GROUP_4_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_PROD_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
|
||||
});
|
||||
|
||||
@@ -56,9 +56,7 @@ macro_rules! create_parameterized_test{
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M64,
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M64,
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M64,
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
// To still be able to test prod
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -63,10 +63,7 @@ macro_rules! create_parameterized_test_bivariate_pbs_compliant{
|
||||
TEST_PARAM_MULTI_BIT_GROUP_2_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M64,
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M64,
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M64,
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M64,
|
||||
TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
|
||||
// To still be able to test prod
|
||||
TEST_PARAM_PROD_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128
|
||||
TEST_PARAM_MULTI_BIT_GROUP_3_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M64
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user