Skip to main content
QUICK REVIEW

[Paper Review] CoCoFuzzing: Testing Neural Code Models with Coverage-Guided Fuzzing

Moshi Wei, Yuchao Huang|arXiv (Cornell University)|Jun 17, 2021
Adversarial Robustness in Machine LearningComputer Science41 references7 citations
TL;DR

CoCoFuzzing is a novel coverage-guided fuzzing framework that generates semantically preserving code mutations to test the robustness of neural code models. By employing ten custom mutation operators and neuron coverage-driven test generation, it improves model robustness and achieves up to 84.81% performance drop on NeuralCodeSum, while adversarial retraining with its outputs boosts model accuracy by up to 35.15%.

ABSTRACT

Deep learning-based code processing models have shown good performance for tasks such as predicting method names, summarizing programs, and comment generation. However, despite the tremendous progress, deep learning models are often prone to adversarial attacks, which can significantly threaten the robustness and generalizability of these models by leading them to misclassification with unexpected inputs. To address the above issue, many deep learning testing approaches have been proposed, however, these approaches mainly focus on testing deep learning applications in the domains of image, audio, and text analysis, etc., which cannot be directly applied to neural models for code due to the unique properties of programs. In this paper, we propose a coverage-based fuzzing framework, CoCoFuzzing, for testing deep learning-based code processing models. In particular, we first propose ten mutation operators to automatically generate valid and semantically preserving source code examples as tests; then we propose a neuron coverage-based approach to guide the generation of tests. We investigate the performance of CoCoFuzzing on three state-of-the-art neural code models, i.e., NeuralCodeSum, CODE2SEQ, and CODE2VEC. Our experiment results demonstrate that CoCoFuzzing can generate valid and semantically preserving source code examples for testing the robustness and generalizability of these models and improve the neuron coverage. Moreover, these tests can be used to improve the performance of the target neural code models through adversarial retraining.

Motivation & Objective

  • To address the lack of effective testing frameworks for deep learning-based neural code models, which are vulnerable to adversarial inputs.
  • To develop a systematic approach that generates valid, semantically preserving code mutations to thoroughly test model robustness.
  • To guide test generation using neuron coverage as a metric, enabling systematic exploration of diverse program transformations.
  • To evaluate the effectiveness of generated tests in both exposing model weaknesses and improving model performance through adversarial retraining.

Proposed method

  • Design and implement ten mutation operators that represent real-world, semantics-preserving code transformations, such as variable renaming, dead code insertion, and argument addition.
  • Use neuron coverage (NC) as a guidance metric to drive the mutation process, ensuring diverse and comprehensive exploration of the model's internal behavior.
  • Integrate a coverage-guided fuzzer that selects and applies mutation operators based on how effectively they increase neuron coverage.
  • Apply the generated test cases to evaluate model robustness and retrain models adversarially to improve generalization.
  • Measure the impact of test cases on model performance degradation and improvement through retraining.

Experimental results

Research questions

  • RQ1Can a coverage-guided fuzzing framework effectively generate valid and semantically preserving code tests for neural code models?
  • RQ2How effective is neuron coverage in guiding the generation of diverse and robust test cases for code models?
  • RQ3To what extent do the generated test cases reduce the performance of state-of-the-art neural code models?
  • RQ4Can adversarial retraining using the generated test cases improve the robustness and accuracy of these models?

Key findings

  • CoCoFuzzing successfully generated valid and semantically preserving code examples that significantly reduced the performance of NeuralCodeSum, CODE2SEQ, and CODE2VEC by 84.81%, 22.06%, and 27.58%, respectively.
  • The generated test cases improved model robustness, with adversarial retraining boosting performance by 35.15% on NeuralCodeSum, 8.83% on CODE2SEQ, and 34.14% on CODE2VEC.
  • The neuron coverage metric effectively guided the fuzzer to explore diverse program transformations and achieve higher coverage of the model's internal neurons.
  • CoCoFuzzing is the first coverage-based fuzzing framework specifically designed for neural code models, addressing limitations of existing approaches in image, audio, and NLP domains.
  • The ten custom mutation operators enabled broader exploration of semantic-preserving code variations than prior methods relying on only two operators (e.g., renaming and dead code insertion).

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.