From 7f206992980b1547f5afcc5a3c640fcbc866c9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=80a?= <76558220+rkdud007@users.noreply.github.com> Date: Wed, 3 Sep 2025 13:20:54 -0700 Subject: [PATCH 1/6] wip --- .github/workflows/benchmark-self-hosted.yml | 63 +++++++++------------ e2e/dummy.param.toml | 12 ++++ 2 files changed, 39 insertions(+), 36 deletions(-) create mode 100644 e2e/dummy.param.toml diff --git a/.github/workflows/benchmark-self-hosted.yml b/.github/workflows/benchmark-self-hosted.yml index 5197d3ea..7116c6cb 100644 --- a/.github/workflows/benchmark-self-hosted.yml +++ b/.github/workflows/benchmark-self-hosted.yml @@ -4,33 +4,33 @@ on: workflow_dispatch: inputs: param_id: - description: 'Configuration ID (e.g. 36)' + description: "Configuration ID (e.g. 36)" required: true - default: '36' + default: "36" data_id: - description: 'Data ID (e.g. 53)' + description: "Data ID (e.g. 53)" required: true - default: '53' + default: "53" bench_type: - description: 'Benchmark type' + description: "Benchmark type" required: true type: choice options: - add-mul - plt - default: 'add-mul' + default: "add-mul" add_num: - description: 'Number of additions (add-mul only)' + description: "Number of additions (add-mul only)" required: false - default: '0' + default: "0" mul_num: - description: 'Number of multiplications (add-mul only)' + description: "Number of multiplications (add-mul only)" required: false - default: '0' + default: "0" t_num: - description: 't parameter (plt only)' + description: "t parameter (plt only)" required: false - default: '0' + default: "0" env: CARGO_TERM_COLOR: always @@ -38,6 +38,7 @@ env: permissions: id-token: write contents: read + concurrency: group: ${{ github.workflow }}-${{ github.head_ref }} cancel-in-progress: true @@ -127,11 +128,18 @@ jobs: - name: Verify OpenFHE install run: ls -lah /usr/local/lib | grep OpenFHE - - name: Install dio - run: cargo install --path dio + # === changed: install abe instead of dio === + - name: Checkout arithmetic-abe + uses: actions/checkout@v4 + with: + repository: MachinaIO/arithmetic-abe + path: arithmetic-abe - - name: Verify dio - run: which dio + - name: Install abe + run: cargo install --path arithmetic-abe/abe + + - name: Verify abe + run: which abe - name: Run benchmarks (stream + log) env: @@ -140,27 +148,10 @@ jobs: run: | mkdir -p logs - case "${{ github.event.inputs.bench_type }}" in - "add-mul") - BENCH_FLAGS="--bench-type add-mul \ - --add-num ${{ github.event.inputs.add_num }} \ - --mul-num ${{ github.event.inputs.mul_num }}" - ;; - "plt") - BENCH_FLAGS="--bench-type plt \ - --t-num ${{ github.event.inputs.t_num }}" - ;; - *) - echo "Unknown bench_type"; exit 1 - ;; - esac - echo "Using flags: $BENCH_FLAGS" - + # Run abe with hardcoded config path as requested ( - dio run-bench \ - -c e2e/dio-config.${{ github.event.inputs.param_id }}.toml \ - -o /tmp/data_${{ github.event.inputs.data_id }}_param_${{ github.event.inputs.param_id }} \ - $BENCH_FLAGS \ + abe run \ + --config e2e/dummy.param.toml \ 2>&1 | tee logs/data_${{ github.event.inputs.data_id }}_param_${{ github.event.inputs.param_id }}.log ) & pid=$! diff --git a/e2e/dummy.param.toml b/e2e/dummy.param.toml new file mode 100644 index 00000000..13642357 --- /dev/null +++ b/e2e/dummy.param.toml @@ -0,0 +1,12 @@ +num_inputs = 3 +num_packed_limbs = 1 +limb_bit_size = 5 +crt_depth = 3 +crt_bits = 17 +d = 1 +e_b_sigma = 0.0 +message = 1 +ring_dimension = 4 +base_bits = 17 +switched_modulus = "1" +input = ["10", "3", "5"] From 8241dcde0811263fd2df63b4539b61dfcbd6f923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=80a?= <76558220+rkdud007@users.noreply.github.com> Date: Wed, 3 Sep 2025 15:35:34 -0700 Subject: [PATCH 2/6] ref --- .github/workflows/benchmark-self-hosted.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark-self-hosted.yml b/.github/workflows/benchmark-self-hosted.yml index 7116c6cb..4ce449e4 100644 --- a/.github/workflows/benchmark-self-hosted.yml +++ b/.github/workflows/benchmark-self-hosted.yml @@ -128,11 +128,11 @@ jobs: - name: Verify OpenFHE install run: ls -lah /usr/local/lib | grep OpenFHE - # === changed: install abe instead of dio === - name: Checkout arithmetic-abe uses: actions/checkout@v4 with: repository: MachinaIO/arithmetic-abe + ref: fix/dir path: arithmetic-abe - name: Install abe From 48559ab465f3b332a778de0e0e1863818dc72eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=80a?= <76558220+rkdud007@users.noreply.github.com> Date: Mon, 8 Sep 2025 14:56:20 +0900 Subject: [PATCH 3/6] sim abe --- dio/src/config.rs | 15 +++++++++++++++ dio/src/main.rs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/dio/src/config.rs b/dio/src/config.rs index 424e9831..dc320fd1 100644 --- a/dio/src/config.rs +++ b/dio/src/config.rs @@ -56,3 +56,18 @@ pub struct SimBenchNormConfig { pub base_bits: u32, pub d: usize, } + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SimABEConfig { + /// Log2 of the ring dimension + pub log_ring_dim: u32, + /// maximum size of the tower + pub max_crt_depth: usize, + /// number of bits of each tower's modulus + pub crt_bits: usize, + /// bit size of the base for the gadget vector and decomposition + pub base_bits: u32, + pub d: usize, + pub limb_bit_size: usize, + pub input_len: usize, +} diff --git a/dio/src/main.rs b/dio/src/main.rs index fd3560fc..d32e9236 100644 --- a/dio/src/main.rs +++ b/dio/src/main.rs @@ -12,6 +12,7 @@ use diamond_io::{ utils::{calculate_directory_size, init_tracing}, }; use mxx::{ + arithmetic::circuit::{ArithGateId, ArithmeticCircuit}, bgg::public_key::BggPublicKey, element::{PolyElem, finite_ring::FinRingElem}, lookup::poly::PolyPltEvaluator, @@ -38,6 +39,8 @@ use std::{ }; use tracing::info; +use crate::config::SimABEConfig; + pub mod circuit; pub mod config; @@ -100,6 +103,13 @@ enum Commands { #[arg(long, requires_if("plt", "bench_type"))] t_num: Option, }, + SimABENorm { + #[arg(short, long)] + config: PathBuf, + + #[arg(short, long)] + out_path: PathBuf, + }, BuildCircuit { #[arg(short, long)] config: PathBuf, @@ -287,6 +297,35 @@ async fn main() { let norm_json = serde_json::to_string(&norms).unwrap(); fs::write(out_path, norm_json.as_bytes()).unwrap() } + Commands::SimABENorm { config, out_path } => { + let dio_config: SimABEConfig = + serde_json::from_reader(fs::File::open(&config).unwrap()).unwrap(); + let log_n = dio_config.log_ring_dim; + let n = 2u32.pow(log_n); + let max_crt_depth = dio_config.max_crt_depth; + let crt_bits = dio_config.crt_bits; + let base_bits = dio_config.base_bits; + let params = DCRTPolyParams::new(n, max_crt_depth, crt_bits, base_bits); + let mut arith = ArithmeticCircuit::::setup( + ¶ms, + dio_config.limb_bit_size, + dio_config.input_len, + false, + true, + ); + let add_idx = arith.add(ArithGateId::new(0), ArithGateId::new(1)); // a + b + let mul_idx = arith.mul(add_idx, ArithGateId::new(2)); // (a + b) * c + let final_idx = arith.sub(mul_idx, ArithGateId::new(0)); // (a + b) * c - a + arith.output(final_idx); + let packed_input_norms = vec![BigUint::one(), params.modulus().as_ref().clone()]; + let norms = arith.poly_circuit.simulate_bgg_norm( + params.ring_dimension(), + params.base_bits(), + packed_input_norms, + ); + let norm_json = serde_json::to_string(&norms).unwrap(); + fs::write(out_path, norm_json.as_bytes()).unwrap() + } Commands::BuildCircuit { config, add_num, mul_num } => { let contents = fs::read_to_string(&config).unwrap(); let dio_config: RunBenchConfig = toml::from_str(&contents).unwrap(); From 4fa180555eb7e47bee9bc262e13a6ec13af4f62c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=80a?= <76558220+rkdud007@users.noreply.github.com> Date: Mon, 8 Sep 2025 15:36:16 +0900 Subject: [PATCH 4/6] ci --- .github/workflows/benchmark-self-hosted.yml | 24 +++++---------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/.github/workflows/benchmark-self-hosted.yml b/.github/workflows/benchmark-self-hosted.yml index 4ce449e4..0beaf202 100644 --- a/.github/workflows/benchmark-self-hosted.yml +++ b/.github/workflows/benchmark-self-hosted.yml @@ -11,26 +11,10 @@ on: description: "Data ID (e.g. 53)" required: true default: "53" - bench_type: - description: "Benchmark type" + height: + description: "Height of binary tree" required: true - type: choice - options: - - add-mul - - plt - default: "add-mul" - add_num: - description: "Number of additions (add-mul only)" - required: false - default: "0" - mul_num: - description: "Number of multiplications (add-mul only)" - required: false - default: "0" - t_num: - description: "t parameter (plt only)" - required: false - default: "0" + default: "1" env: CARGO_TERM_COLOR: always @@ -152,6 +136,8 @@ jobs: ( abe run \ --config e2e/dummy.param.toml \ + -h ${{ github.event.inputs.height }} \ + -d /tmp/data_${{ github.event.inputs.data_id }}_param_${{ github.event.inputs.param_id }} \ 2>&1 | tee logs/data_${{ github.event.inputs.data_id }}_param_${{ github.event.inputs.param_id }}.log ) & pid=$! From f9a223512e45b78fd71e8286d59881eabfe6eb8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=80a?= <76558220+rkdud007@users.noreply.github.com> Date: Mon, 8 Sep 2025 15:57:29 +0900 Subject: [PATCH 5/6] param --- e2e/dummy.param.toml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/e2e/dummy.param.toml b/e2e/dummy.param.toml index 13642357..70e50bea 100644 --- a/e2e/dummy.param.toml +++ b/e2e/dummy.param.toml @@ -1,12 +1,11 @@ num_inputs = 3 num_packed_limbs = 1 -limb_bit_size = 5 -crt_depth = 3 +limb_bit_size = 3 +crt_depth = 2 crt_bits = 17 d = 1 -e_b_sigma = 0.0 -message = 1 +e_b_sigma = 1.2 +message = true ring_dimension = 4 base_bits = 17 -switched_modulus = "1" input = ["10", "3", "5"] From 564d7251a03260ceff6105c4cb7370736d50f475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=80a?= <76558220+rkdud007@users.noreply.github.com> Date: Fri, 19 Sep 2025 14:39:51 +0900 Subject: [PATCH 6/6] dummy --- e2e/dummy.param.toml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/e2e/dummy.param.toml b/e2e/dummy.param.toml index 70e50bea..60bf636b 100644 --- a/e2e/dummy.param.toml +++ b/e2e/dummy.param.toml @@ -1,11 +1,8 @@ -num_inputs = 3 -num_packed_limbs = 1 -limb_bit_size = 3 -crt_depth = 2 +limb_bit_size = 5 +crt_depth = 3 crt_bits = 17 -d = 1 -e_b_sigma = 1.2 -message = true +e_b_sigma = 0.0 +message = [true, false, true, false] ring_dimension = 4 base_bits = 17 -input = ["10", "3", "5"] +input = [["10", "3", "5", "7"], ["2", "4", "6", "8"], ["1", "1", "1", "1"]]