TL;DR
CodeArt is a novel pre-training method for code models that uses program analysis to guide a Transformer's attention. By forcing the model to focus on data and control flow rather than missing or misleading variable names, it achieves state-of-the-art performance on binary analysis tasks like similarity detection, type inference, and malware classification.
What Problem Does This Paper Address?
Modern Large Language Models (LLMs) and Transformers are surprisingly good at understanding code, but they have a secret: they rely heavily on "natural language artifacts"—the comments, function names, and variable names (mean, index, buffer) that developers leave behind.
When these symbols are missing—as they are in "stripped" binary executables or obfuscated software—vanilla Transformer models struggle. Without symbolic hints, code looks like a "primitive language" of registers and memory addresses. Neighboring instructions might be completely unrelated, while a critical dependency might be dozens of lines away. Standard models often fail to learn these long-range correlations, leading to poor performance in security-critical tasks.
Methods
The authors propose CodeArt, which replaces symbolic "cheating" with rigorous program analysis. The core idea is Attention Regularization: instead of letting every token attend to every other token, CodeArt uses masks to restrict the model's focus to semantically meaningful contexts.
The pipeline works in several stages:
- Disassembly & Tokenization: Raw binaries are converted to assembly, then broken into tokens.
- Dependence Analysis: Using tools like IDA Pro, CodeArt builds a Program Dependence Graph (PDG) capturing how data and control flow through the function.
- Mask Building: It constructs three types of attention masks:
- Global Mask: Allows a special
[CLS]token to see everything to capture general co-occurrences. - Local Mask: Restricts attention within a single instruction.
- Dependence Mask: This is the "secret sauce." It uses the transitive closure of the PDG to allow tokens to attend only to instructions they actually depend on (or that depend on them), regardless of how far apart they are in the sequence.
- Regularized Multi-head Attention (RMA): A modified Transformer architecture that integrates these masks and uses Relative Positional Bias based on "dependence distance" (hops in the graph) rather than simple line numbers.
The model is pre-trained using two objectives: standard Masked Language Modeling (MLM) and a new Masked Dependence Modeling (MDM), where the model must predict whether a dependency edge exists between two instructions.
Datasets
- Pre-training: The authors used the BinaryCorp-26M dataset, consisting of 26 million stripped binary functions.
- Downstream Evaluation:
- Binary Similarity: Evaluated on BinaryCorp-3M and 7 real-world open-source projects (e.g., Curl, OpenSSL, SQLite).
- Malware Classification: A dataset of 5,484 samples across 100 malware families from VirusTotal and VirusShare.
- Type Inference: A dataset of x86-64 binaries with ground-truth type information.
Key Insights and Ideas
- Code as a Primitive Language: In the absence of symbols, the "meaning" of a statement is purely the aggregation of all statements that contribute to it. CodeArt treats code more like a mathematical expression than a natural language paragraph.
- Transitive Closure is Critical: Simply looking at direct neighbors in a graph isn't enough for deep Transformers. By using the transitive closure, CodeArt allows "information highways" between distant but related instructions in a single layer.
- Relative Distance > Absolute Position: In binary code, compilers often reorder instructions for optimization. Absolute positions are noisy; distance in the dependence graph is a much more stable signal for the model to learn from.
- Stability through Regularization: Unlike previous attempts (like GraphCodeBERT) that add auxiliary losses which can conflict with the main training goal, CodeArt's masking approach provides a more stable optimization path for binary code.
Key Results
CodeArt significantly outperformed existing state-of-the-art (SOTA) models across all tested tasks:
- Binary Similarity: Improved Recall@1 (with a pool size of 500) from 53% to 64%. In zero-shot settings, it outperformed the previous best model (JTrans) by over 30%.
- Type Inference: Boosted the F1 score from 74% to 94%, showing remarkable robustness against different compiler optimization levels (O0 to O3).
- Malware Classification: Improved the Label Ranking Average Precision (LRAP) from 49% to 60%.
Limitations and Future Work
- Architecture Focus: The current implementation is specifically tailored for x86-64 architectures. Extending this to ARM or MIPS would require additional engineering.
- Computational Overhead: Constructing the dependence masks takes about 2.5ms per sample. While this can be done in parallel with model training, further optimization is needed for real-time applications.
- Static Analysis Bounds: The model's accuracy is partially tied to the quality of the underlying static analysis (e.g., resolving indirect jumps or complex memory aliases).
For more details, you can find the full paper "CodeArt: Better Code Models by Attention Regularization When Symbols Are Lacking" on arXiv.
Summary updated