From 9cf7c05c24d5d131f4b75820031701771f02e7cf Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 9 Sep 2024 13:10:17 -0500 Subject: [PATCH 1/2] Replace uses of fixed-macro --- Cargo.lock | 61 -------------------------- Cargo.toml | 1 - benches/speed_tests.rs | 39 ++++++++-------- binaries/Cargo.toml | 1 - binaries/src/bin/vdaf_message_sizes.rs | 10 +++-- src/flp/types/fixedpoint_l2.rs | 30 ++++++------- src/vdaf/prio3.rs | 44 ++++++++++--------- 7 files changed, 64 insertions(+), 122 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a79c070a6..ab59b7933 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -345,41 +345,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "fixed-macro" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0c48af8cb14e02868f449f8a2187bd78af7a08da201fdc78d518ecb1675bc" -dependencies = [ - "fixed", - "fixed-macro-impl", - "fixed-macro-types", -] - -[[package]] -name = "fixed-macro-impl" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c93086f471c0a1b9c5e300ea92f5cd990ac6d3f8edf27616ef624b8fa6402d4b" -dependencies = [ - "fixed", - "paste", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.104", -] - -[[package]] -name = "fixed-macro-types" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "044a61b034a2264a7f65aa0c3cd112a01b4d4ee58baace51fead3f21b993c7e4" -dependencies = [ - "fixed", - "fixed-macro-impl", -] - [[package]] name = "funty" version = "2.0.0" @@ -744,7 +709,6 @@ dependencies = [ "ctr", "fiat-crypto", "fixed", - "fixed-macro", "getrandom", "hex", "hex-literal", @@ -777,35 +741,10 @@ version = "0.5.0" dependencies = [ "base64", "fixed", - "fixed-macro", "prio", "rand", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.104", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.74" diff --git a/Cargo.toml b/Cargo.toml index 02f47baa0..c0d119ebb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,6 @@ assert_matches = "1.5.0" base64 = "0.22.1" cfg-if = "1.0.0" criterion = "0.5" -fixed-macro = "1.2.0" hex-literal = "0.4.1" iai = "0.1" modinverse = "0.1.0" diff --git a/benches/speed_tests.rs b/benches/speed_tests.rs index bf7a66e9a..4718b182a 100644 --- a/benches/speed_tests.rs +++ b/benches/speed_tests.rs @@ -6,8 +6,6 @@ use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criteri #[cfg(feature = "experimental")] use fixed::types::{I1F15, I1F31}; #[cfg(feature = "experimental")] -use fixed_macro::fixed; -#[cfg(feature = "experimental")] use num_bigint::BigUint; #[cfg(feature = "experimental")] use num_rational::Ratio; @@ -434,6 +432,11 @@ fn prio3(c: &mut Criterion) { #[cfg(feature = "experimental")] { + const FP16_ZERO: I1F15 = I1F15::lit("0"); + const FP32_ZERO: I1F31 = I1F31::lit("0"); + const FP16_HALF: I1F15 = I1F15::lit("0.5"); + const FP32_HALF: I1F31 = I1F31::lit("0.5"); + let mut group = c.benchmark_group("prio3fixedpointboundedl2vecsum_i1f15_shard"); for dimension in [10, 100, 1_000] { group.bench_with_input( @@ -442,8 +445,8 @@ fn prio3(c: &mut Criterion) { |b, dimension| { let vdaf: Prio3, _, 16> = Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, *dimension).unwrap(); - let mut measurement = vec![fixed!(0: I1F15); *dimension]; - measurement[0] = fixed!(0.5: I1F15); + let mut measurement = vec![FP16_ZERO; *dimension]; + measurement[0] = FP16_HALF; let nonce = black_box([0u8; 16]); b.iter(|| vdaf.shard(&measurement, &nonce).unwrap()); }, @@ -462,8 +465,8 @@ fn prio3(c: &mut Criterion) { num_shares, *dimension, ) .unwrap(); - let mut measurement = vec![fixed!(0: I1F15); *dimension]; - measurement[0] = fixed!(0.5: I1F15); + let mut measurement = vec![FP16_ZERO; *dimension]; + measurement[0] = FP16_HALF; let nonce = black_box([0u8; 16]); b.iter(|| vdaf.shard(&measurement, &nonce).unwrap()); }, @@ -480,8 +483,8 @@ fn prio3(c: &mut Criterion) { |b, dimension| { let vdaf: Prio3, _, 16> = Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, *dimension).unwrap(); - let mut measurement = vec![fixed!(0: I1F15); *dimension]; - measurement[0] = fixed!(0.5: I1F15); + let mut measurement = vec![FP16_ZERO; *dimension]; + measurement[0] = FP16_HALF; let nonce = black_box([0u8; 16]); let verify_key = black_box([0u8; 16]); let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap(); @@ -512,8 +515,8 @@ fn prio3(c: &mut Criterion) { num_shares, *dimension, ) .unwrap(); - let mut measurement = vec![fixed!(0: I1F15); *dimension]; - measurement[0] = fixed!(0.5: I1F15); + let mut measurement = vec![FP16_ZERO; *dimension]; + measurement[0] = FP16_HALF; let nonce = black_box([0u8; 16]); let verify_key = black_box([0u8; 16]); let (public_share, input_shares) = @@ -543,8 +546,8 @@ fn prio3(c: &mut Criterion) { |b, dimension| { let vdaf: Prio3, _, 16> = Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, *dimension).unwrap(); - let mut measurement = vec![fixed!(0: I1F31); *dimension]; - measurement[0] = fixed!(0.5: I1F31); + let mut measurement = vec![FP32_ZERO; *dimension]; + measurement[0] = FP32_HALF; let nonce = black_box([0u8; 16]); b.iter(|| vdaf.shard(&measurement, &nonce).unwrap()); }, @@ -563,8 +566,8 @@ fn prio3(c: &mut Criterion) { num_shares, *dimension, ) .unwrap(); - let mut measurement = vec![fixed!(0: I1F31); *dimension]; - measurement[0] = fixed!(0.5: I1F31); + let mut measurement = vec![FP32_ZERO; *dimension]; + measurement[0] = FP32_HALF; let nonce = black_box([0u8; 16]); b.iter(|| vdaf.shard(&measurement, &nonce).unwrap()); }, @@ -581,8 +584,8 @@ fn prio3(c: &mut Criterion) { |b, dimension| { let vdaf: Prio3, _, 16> = Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, *dimension).unwrap(); - let mut measurement = vec![fixed!(0: I1F31); *dimension]; - measurement[0] = fixed!(0.5: I1F31); + let mut measurement = vec![FP32_ZERO; *dimension]; + measurement[0] = FP32_HALF; let nonce = black_box([0u8; 16]); let verify_key = black_box([0u8; 16]); let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap(); @@ -613,8 +616,8 @@ fn prio3(c: &mut Criterion) { num_shares, *dimension, ) .unwrap(); - let mut measurement = vec![fixed!(0: I1F31); *dimension]; - measurement[0] = fixed!(0.5: I1F31); + let mut measurement = vec![FP32_ZERO; *dimension]; + measurement[0] = FP32_HALF; let nonce = black_box([0u8; 16]); let verify_key = black_box([0u8; 16]); let (public_share, input_shares) = diff --git a/binaries/Cargo.toml b/binaries/Cargo.toml index 81fd8d3a4..cb57338c9 100644 --- a/binaries/Cargo.toml +++ b/binaries/Cargo.toml @@ -9,6 +9,5 @@ repository = "https://github.com/divviup/libprio-rs" [dependencies] base64 = "0.22.1" fixed = "1.27" -fixed-macro = "1.2.0" rand = "0.8" prio = { path = "..", features = ["experimental", "test-util"] } diff --git a/binaries/src/bin/vdaf_message_sizes.rs b/binaries/src/bin/vdaf_message_sizes.rs index a5c0035b5..dae75685a 100644 --- a/binaries/src/bin/vdaf_message_sizes.rs +++ b/binaries/src/bin/vdaf_message_sizes.rs @@ -1,5 +1,7 @@ -use fixed::{types::extra::U15, FixedI16}; -use fixed_macro::fixed; +use fixed::{ + types::{extra::U15, I1F15}, + FixedI16, +}; use prio::{ codec::Encode, @@ -53,8 +55,8 @@ fn main() { let len = 1000; let prio3 = Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, len).unwrap(); - let fp_num = fixed!(0.0001: I1F15); - let measurement = vec![fp_num; len]; + const FP_NUM: I1F15 = I1F15::lit("0.0001"); + let measurement = vec![FP_NUM; len]; println!( "prio3 fixedpoint16 boundedl2 vec ({} entries) size = {}", len, diff --git a/src/flp/types/fixedpoint_l2.rs b/src/flp/types/fixedpoint_l2.rs index 8f3a6321f..fbedb9321 100644 --- a/src/flp/types/fixedpoint_l2.rs +++ b/src/flp/types/fixedpoint_l2.rs @@ -672,17 +672,23 @@ mod tests { use crate::flp::test_utils::FlpTest; use crate::vdaf::xof::SeedStreamTurboShake128; use fixed::types::extra::{U127, U14, U63}; + use fixed::types::{I1F15, I1F31, I1F63}; use fixed::{FixedI128, FixedI16, FixedI64}; - use fixed_macro::fixed; use rand::SeedableRng; + const FP16_4_INV: I1F15 = I1F15::lit("0.25"); + const FP16_8_INV: I1F15 = I1F15::lit("0.125"); + const FP16_16_INV: I1F15 = I1F15::lit("0.0625"); + const FP32_4_INV: I1F31 = I1F31::lit("0.25"); + const FP32_8_INV: I1F31 = I1F31::lit("0.125"); + const FP32_16_INV: I1F31 = I1F31::lit("0.0625"); + const FP64_4_INV: I1F63 = I1F63::lit("0.25"); + const FP64_8_INV: I1F63 = I1F63::lit("0.125"); + const FP64_16_INV: I1F63 = I1F63::lit("0.0625"); + #[test] fn test_bounded_fpvec_sum_parallel_fp16() { - let fp16_4_inv = fixed!(0.25: I1F15); - let fp16_8_inv = fixed!(0.125: I1F15); - let fp16_16_inv = fixed!(0.0625: I1F15); - - let fp16_vec = vec![fp16_4_inv, fp16_8_inv, fp16_16_inv]; + let fp16_vec = vec![FP16_4_INV, FP16_8_INV, FP16_16_INV]; // the encoded vector has the following entries: // enc(0.25) = 2^(n-1) * 0.25 + 2^(n-1) = 40960 @@ -693,22 +699,14 @@ mod tests { #[test] fn test_bounded_fpvec_sum_parallel_fp32() { - let fp32_4_inv = fixed!(0.25: I1F31); - let fp32_8_inv = fixed!(0.125: I1F31); - let fp32_16_inv = fixed!(0.0625: I1F31); - - let fp32_vec = vec![fp32_4_inv, fp32_8_inv, fp32_16_inv]; + let fp32_vec = vec![FP32_4_INV, FP32_8_INV, FP32_16_INV]; // computed as above but with n=32 test_fixed(fp32_vec, vec![2684354560, 2415919104, 2281701376]); } #[test] fn test_bounded_fpvec_sum_parallel_fp64() { - let fp64_4_inv = fixed!(0.25: I1F63); - let fp64_8_inv = fixed!(0.125: I1F63); - let fp64_16_inv = fixed!(0.0625: I1F63); - - let fp64_vec = vec![fp64_4_inv, fp64_8_inv, fp64_16_inv]; + let fp64_vec = vec![FP64_4_INV, FP64_8_INV, FP64_16_INV]; // computed as above but with n=64 test_fixed( fp64_vec, diff --git a/src/vdaf/prio3.rs b/src/vdaf/prio3.rs index 635af4805..d3241603d 100644 --- a/src/vdaf/prio3.rs +++ b/src/vdaf/prio3.rs @@ -1575,11 +1575,12 @@ mod tests { use assert_matches::assert_matches; #[cfg(feature = "experimental")] use fixed::{ - types::extra::{U15, U31, U63}, + types::{ + extra::{U15, U31, U63}, + I1F15, I1F31, I1F63, + }, FixedI16, FixedI32, FixedI64, }; - #[cfg(feature = "experimental")] - use fixed_macro::fixed; use rand::prelude::*; #[test] @@ -1719,19 +1720,19 @@ mod tests { { const SIZE: usize = 5; - let fp32_0 = fixed!(0: I1F31); + const FP32_0: I1F31 = I1F31::lit("0"); // 32 bit fixedpoint, non-power-of-2 vector, single-threaded { let prio3_32 = ctor_32(2, SIZE).unwrap(); - test_fixed_vec::<_, _, _, SIZE>(fp32_0, prio3_32); + test_fixed_vec::<_, _, _, SIZE>(FP32_0, prio3_32); } // 32 bit fixedpoint, non-power-of-2 vector, multi-threaded #[cfg(feature = "multithreaded")] { let prio3_mt_32 = ctor_mt_32(2, SIZE).unwrap(); - test_fixed_vec::<_, _, _, SIZE>(fp32_0, prio3_mt_32); + test_fixed_vec::<_, _, _, SIZE>(FP32_0, prio3_mt_32); } } @@ -1756,6 +1757,16 @@ mod tests { #[test] #[cfg(feature = "experimental")] fn test_prio3_bounded_fpvec_sum() { + const FP16_4_INV: I1F15 = I1F15::lit("0.25"); + const FP16_8_INV: I1F15 = I1F15::lit("0.125"); + const FP16_16_INV: I1F15 = I1F15::lit("0.0625"); + const FP32_4_INV: I1F31 = I1F31::lit("0.25"); + const FP32_8_INV: I1F31 = I1F31::lit("0.125"); + const FP32_16_INV: I1F31 = I1F31::lit("0.0625"); + const FP64_4_INV: I1F63 = I1F63::lit("0.25"); + const FP64_8_INV: I1F63 = I1F63::lit("0.125"); + const FP64_16_INV: I1F63 = I1F63::lit("0.0625"); + type P = Prio3FixedPointBoundedL2VecSum; let ctor_16 = P::>::new_fixedpoint_boundedl2_vec_sum; let ctor_32 = P::>::new_fixedpoint_boundedl2_vec_sum; @@ -1772,56 +1783,47 @@ mod tests { { // 16 bit fixedpoint - let fp16_4_inv = fixed!(0.25: I1F15); - let fp16_8_inv = fixed!(0.125: I1F15); - let fp16_16_inv = fixed!(0.0625: I1F15); // two aggregators, three entries per vector. { let prio3_16 = ctor_16(2, 3).unwrap(); - test_fixed(fp16_4_inv, fp16_8_inv, fp16_16_inv, prio3_16); + test_fixed(FP16_4_INV, FP16_8_INV, FP16_16_INV, prio3_16); } #[cfg(feature = "multithreaded")] { let prio3_16_mt = ctor_mt_16(2, 3).unwrap(); - test_fixed(fp16_4_inv, fp16_8_inv, fp16_16_inv, prio3_16_mt); + test_fixed(FP16_4_INV, FP16_8_INV, FP16_16_INV, prio3_16_mt); } } { // 32 bit fixedpoint - let fp32_4_inv = fixed!(0.25: I1F31); - let fp32_8_inv = fixed!(0.125: I1F31); - let fp32_16_inv = fixed!(0.0625: I1F31); { let prio3_32 = ctor_32(2, 3).unwrap(); - test_fixed(fp32_4_inv, fp32_8_inv, fp32_16_inv, prio3_32); + test_fixed(FP32_4_INV, FP32_8_INV, FP32_16_INV, prio3_32); } #[cfg(feature = "multithreaded")] { let prio3_32_mt = ctor_mt_32(2, 3).unwrap(); - test_fixed(fp32_4_inv, fp32_8_inv, fp32_16_inv, prio3_32_mt); + test_fixed(FP32_4_INV, FP32_8_INV, FP32_16_INV, prio3_32_mt); } } { // 64 bit fixedpoint - let fp64_4_inv = fixed!(0.25: I1F63); - let fp64_8_inv = fixed!(0.125: I1F63); - let fp64_16_inv = fixed!(0.0625: I1F63); { let prio3_64 = ctor_64(2, 3).unwrap(); - test_fixed(fp64_4_inv, fp64_8_inv, fp64_16_inv, prio3_64); + test_fixed(FP64_4_INV, FP64_8_INV, FP64_16_INV, prio3_64); } #[cfg(feature = "multithreaded")] { let prio3_64_mt = ctor_mt_64(2, 3).unwrap(); - test_fixed(fp64_4_inv, fp64_8_inv, fp64_16_inv, prio3_64_mt); + test_fixed(FP64_4_INV, FP64_8_INV, FP64_16_INV, prio3_64_mt); } } From e81096ff548967e4dceb895bbc91424f5f73396c Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 9 Sep 2024 13:29:29 -0500 Subject: [PATCH 2/2] Prune exemptions --- supply-chain/config.toml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/supply-chain/config.toml b/supply-chain/config.toml index f03642d9a..1c12a8a12 100644 --- a/supply-chain/config.toml +++ b/supply-chain/config.toml @@ -100,10 +100,6 @@ notes = "This is only used when the \"crypto-dependencies\" feature is enabled." version = "1.20.0" criteria = "safe-to-deploy" -[[exemptions.fixed-macro-types]] -version = "1.2.0" -criteria = "safe-to-run" - [[exemptions.funty]] version = "2.0.0" criteria = "safe-to-deploy" @@ -162,10 +158,6 @@ criteria = "safe-to-run" version = "0.2.16" criteria = "safe-to-deploy" -[[exemptions.proc-macro-error]] -version = "1.0.4" -criteria = "safe-to-run" - [[exemptions.radium]] version = "0.7.0" criteria = "safe-to-deploy"