[Paper Review] On using distributed representations of source code for the detection of C security vulnerabilities
This paper evaluates Code2vec, a model that learns distributed representations of C source code using path-contexts extracted from abstract syntax trees, for detecting security vulnerabilities. Trained on the CodeXGLUE benchmark, it achieves 61.43% accuracy—comparable to RoBERTa but with significantly lower computational costs, making it suitable for resource-constrained CI pipelines.
This paper presents an evaluation of the code representation model Code2vec when trained on the task of detecting security vulnerabilities in C source code. We leverage the open-source library astminer to extract path-contexts from the abstract syntax trees of a corpus of labeled C functions. Code2vec is trained on the resulting path-contexts with the task of classifying a function as vulnerable or non-vulnerable. Using the CodeXGLUE benchmark, we show that the accuracy of Code2vec for this task is comparable to simple transformer-based methods such as pre-trained RoBERTa, and outperforms more naive NLP-based methods. We achieved an accuracy of 61.43% while maintaining low computational requirements relative to larger models.
Motivation & Objective
- To assess the effectiveness of Code2vec in detecting security vulnerabilities in C source code.
- To compare Code2vec’s performance and computational efficiency against transformer-based models like RoBERTa and CodeBERT.
- To evaluate whether path-context-based code representations can achieve competitive accuracy with minimal computational overhead.
- To provide a reproducible implementation and training pipeline for vulnerability detection using Code2vec.
- To demonstrate that smaller models like Code2vec can be practical alternatives in CI environments where large models are infeasible.
Proposed method
- Extracted path-contexts from abstract syntax trees (ASTs) of C functions using the astminer library.
- Constructed code representations by learning distributed embeddings from AST path-contexts using Code2vec’s attention-based feed-forward network.
- Fine-tuned Code2vec on a labeled corpus of C functions from the CodeXGLUE defect detection benchmark.
- Trained the model using binary cross-entropy loss to classify functions as vulnerable or non-vulnerable.
- Configured hyperparameters including batch size (1024), learning rate, and maximum path-context length and width for optimal performance.
- Evaluated model performance using standard metrics such as accuracy, and compared results with RoBERTa and other NLP baselines.
Experimental results
Research questions
- RQ1Can Code2vec, a non-transformer model based on AST path-contexts, achieve competitive accuracy in detecting C security vulnerabilities?
- RQ2How does Code2vec’s performance compare to pre-trained transformer models like RoBERTa and CodeBERT in vulnerability detection?
- RQ3What is the computational cost of training Code2vec relative to larger models, and is it viable for integration into CI pipelines?
- RQ4Does the use of AST-based path-contexts capture sufficient semantic and syntactic information for vulnerability detection?
- RQ5Can Code2vec be effectively fine-tuned on a labeled dataset of C functions to achieve state-of-the-art performance with minimal resources?
Key findings
- Code2vec achieved an accuracy of 61.43% on the CodeXGLUE defect detection benchmark for C code, outperforming naive NLP-based methods.
- The performance of Code2vec was comparable to RoBERTa, a simple fine-tuned transformer model, despite not being pre-trained on source code.
- Code2vec required only about 5 minutes of training time on a consumer-grade GPU and did not exhaust memory with 1024-sample batches.
- The model demonstrated low computational resource usage, making it suitable for deployment in resource-constrained environments like CI pipelines.
- Code2vec was outperformed by more expressive models such as CodeBERT and Devign, which leverage deeper syntactic and semantic features.
- The results suggest that Code2vec offers a strong trade-off between performance and efficiency, especially where model size and inference cost are critical.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.