NFGen: Automatic Non-linear Function Evaluation Code Generator for General-purpose MPC Platforms

Xiaoyu Fan, Kun Chen, Guosai Wang, Mingchun Zhuang, Yi Li, Wei Xu

This paper, presented at ACM CCS 2022, introduces NFGen, an automated framework designed to solve one of the most persistent "last mile" problems in Secure Multi-Party Computation (MPC): the efficient and accurate evaluation of non-linear functions.

TL;DR

NFGen is an automatic code generator that approximates complex non-linear functions (like Sigmoid, Tanh, or Log) using optimized piecewise polynomials tailored for specific MPC platforms. It achieves an average speedup of 6.5x (up to 86x) and significantly improves accuracy by avoiding the overflow and precision issues inherent in standard fixed-point MPC arithmetic.

What Problem Does This Paper Address?

Secure Multi-Party Computation (MPC) allows parties to compute a function over private data without revealing the data itself. While MPC is highly efficient for linear operations (addition and multiplication), it struggles with non-linear functions essential for machine learning and scientific computing.

The authors identify four major "pitfalls" in current MPC platforms:

  1. Correctness and Precision: Most MPC platforms use Fixed-Point (FXP) arithmetic for speed. However, standard mathematical formulas are designed for Floating-Point (FLP). Naively porting these leads to massive precision loss or silent overflows (e.g., the built-in tanh in the popular MP-SPDZ library fails if $|x| > 44$).
  2. Performance: Evaluating non-linear functions through iterative methods (like Newton-Raphson) is orders of magnitude slower in MPC than in plaintext.
  3. Generality: Many functions defined as integrals (like the Gamma function) are nearly impossible for non-experts to implement manually in MPC.
  4. Portability: Different MPC protocols (e.g., Shamir Secret Sharing vs. Replicated Secret Sharing) have different performance trade-offs. A method that is fast on one platform might be a bottleneck on another.

Methods

NFGen replaces complex iterative algorithms with discrete piecewise polynomials. The workflow consists of two main phases:

1. Offline Approximation (Plaintext)

  • Piecewise Fitting: NFGen recursively splits the function's domain into $m$ pieces and fits a degree-$k$ polynomial to each using Chebyshev or Lagrange interpolation.
  • FXP Optimization: To handle the limitations of fixed-point math, NFGen uses Scaling (to keep coefficients representable) and Residual Boosting (fitting secondary polynomials to the error of the first to "squeeze out" more precision).
  • Performance Profiling: NFGen runs a "profiler" on the target MPC platform to measure the cost of basic operations ($>$ vs. $\times$). It then uses a regression model to pick the optimal $(m, k)$ configuration—balancing the number of pieces against the polynomial degree to maximize speed.

2. Online Evaluation (MPC)

  • Oblivious Piecewise Polynomial Evaluation (OPPE): At runtime, NFGen uses a specialized algorithm to evaluate the polynomial. Crucially, this is "oblivious," meaning the execution path is identical regardless of the input, preventing side-channel leaks about the private data.

Datasets

The authors evaluated NFGen across a broad suite of mathematical benchmarks and real-world applications:

  • Functions: 23 non-linear functions, including 8 activation functions (Sigmoid, GELU, ELU, etc.), 7 probability distributions (Normal, Cauchy, Gamma, etc.), and 8 special functions defined as integrals.
  • MPC Protocols: Evaluated on 6 different protocols (including semi-honest and malicious models) across two major platforms: MP-SPDZ and PrivPy.
  • Real-world Data:
    • Logistic Regression: Tested on the Adult, Bank, and Branch datasets.
  • $\chi^2$ Statistical Test: Tested on medical datasets for Cervical Cancer and Sepsis.

Key Insights and Ideas

  • The "Aha" Moment on Trade-offs: The optimal way to compute a function in MPC isn't fixed. If a protocol has very slow comparisons ($>$) but fast multiplications ($\times$), NFGen will automatically choose a higher-degree polynomial with fewer pieces. If comparisons are fast, it chooses more pieces with lower-degree polynomials.
  • One-Shot vs. Composition: Standard methods often "compose" functions (e.g., Sigmoid = $1 / (1 + e^{-x})$). NFGen approximates the entire result in one shot, preventing the accumulation of errors that occurs when you chain multiple approximate operations together.
  • Handling the FXP Gap: The paper proves that you cannot ignore the difference between integer-based FXP and real-number FLP. Their "Residual Boosting" technique is a clever way to regain precision that is usually lost during the discretization of polynomial coefficients.

Key Results

  • Speed: NFGen outperformed baselines in 93% of cases, with an average speedup of 6.5x and a peak speedup of 86.1x.
  • Communication: It reduced network communication by an average of 39.3%.
  • Accuracy: 100% of tested samples met the target accuracy threshold ($10^{-3}$), whereas baseline methods frequently failed or produced "NaN" results due to overflows.
  • Application Impact: In Logistic Regression training, NFGen provided a 3.5x to 9.5x speedup while maintaining the same accuracy as plaintext models.

Limitations and Future Work

  • Lipschitz Continuity: The approximation logic assumes the target function is Lipschitz continuous. While this covers most common functions, it may struggle with functions that have extreme oscillations or discontinuities.
  • Dimensionality: Currently, NFGen is optimized for 1D functions ($f(x)$). The authors note that extending this to multi-dimensional functions (e.g., $f(x, y)$) is a goal for future work.
  • Theoretical Guarantees: While the fitting is empirically robust, the authors acknowledge there is no theoretical guarantee that a feasible approximation exists for every possible function under every accuracy requirement.

Summary updated

BibTeX
@inproceedings{fan2022nfgen,
  author = {Xiaoyu Fan and Kun Chen and Guosai Wang and Mingchun Zhuang and Yi Li and Wei Xu},
  title = {{NFGen: Automatic Non-linear Function Evaluation Code Generator for General-purpose MPC Platforms}},
  booktitle = {CCS},
  year = {2022},
  doi = {10.1145/3548606.3560565},
}

Loading related content...

Figure