MicroSim: Binary Code Similarity Detection with Contrastive Graph Neural Networks

MicroSim uses microcode graphs and a contrastive Siamese GNN to achieve high-accuracy binary code similarity detection.
MicroSim is a binary code similarity detection system based on a contrastive Siamese graph neural network. It constructs each function as a graph from microcode extracted via IDA Pro Hex-Rays, with microcode instructions as nodes and data-flow or control-flow dependencies as edges, preserving rich semantic information while avoiding the complexity of raw assembly. A weight-sharing Siamese network processes pairs of function graphs and optimizes the embedding space through a contrastive loss. Under a strict class-disjoint split on the TREX benchmark, MicroSim achieves 0.9972 ROC-AUC and 0.9762 MCC, significantly outperforming Gemini, SAFE, jTrans, and a Bag-of-Words baseline. The paper also analyzes the performance gap in ranking retrieval, introduces CSLS and unified tie handling to improve GraphGPS's MRR from 0.2542 to 0.2559, and compares two loss functions: InfoNCE is significantly better on threshold classification and ranking retrieval.
Introduction
Binary Code Similarity Detection (BCSD) plays a critical role in security scenarios such as vulnerability search, malware analysis, and patch comparison. Traditional methods rely on handcrafted features or simple statistical models, making it difficult to capture the structural semantics of code. Recently, researchers proposed MicroSim, a system based on a contrastive Siamese graph neural network (Siamese GNN) that represents each function as a graph built from IDA Pro Hex-Rays microcode and performs similarity judgment through contrastive learning. This article provides an in-depth interpretation of MicroSim's design, experiments, and findings.

Core Method: Microcode Graphs and Contrastive Learning
The core innovation of MicroSim lies in converting binary functions into microcode graphs and using graph neural networks to learn their embedding representations. Specifically, each function's microcode is extracted via the IDA Pro Hex-Rays decompiler and constructed into a graph structure, where nodes represent microcode instructions and edges represent data-flow or control-flow dependencies. This representation preserves rich semantic information while avoiding the complexity of directly processing raw assembly.
To effectively compare similarity between graphs, MicroSim adopts a contrastive Siamese GNN architecture. The two branches of the Siamese network share weights, each processing one function graph from a pair and outputting embedding vectors, which are optimized through a contrastive loss function: embeddings of similar functions are pulled closer, while embeddings of dissimilar functions are pushed apart. The paper explores two losses: pairwise cosine-embedding loss and supervised-contrastive InfoNCE loss.
IDA Pro Hex-Rays microcode is an intermediate representation (IR) generated by the IDA Pro decompiler before it lifts assembly instructions into high-level C-like code. Compared with raw assembly, microcode decomposes each instruction into finer-grained operations (such as assignments, arithmetic operations, conditional jumps, function calls, etc.) and explicitly exposes data dependencies between operands. This representation both preserves low-level semantics (such as register and memory access) and eliminates instruction-selection differences introduced by different compilers and optimization levels, making it highly suitable as a foundation for function representation in cross-optimization scenarios. MicroSim leverages exactly this property of microcode to transform each function into a graph structure with microcode instructions as nodes and data-flow or control-flow dependencies as edges.
Siamese GNN is a dual-branch network architecture with shared weights, where the two branches each receive an input graph and output its embedding vector. Because of weight sharing, the network applies exactly the same mapping function to both inputs, thereby ensuring that distances in the embedding space are comparable. During training, it is typically combined with a contrastive loss: pulling the embeddings of similar sample pairs closer and pushing those of dissimilar sample pairs apart. This architecture is naturally suited to pairwise similarity judgment tasks because it directly optimizes the objective of "pairwise comparison" rather than independent classification or regression. MicroSim combines this architecture with microcode graphs, enabling the model to learn structural semantic similarity between functions end to end.
Experimental Setup and Results
The researchers evaluated MicroSim on the TREX cross-optimization benchmark, which contains 849,072 function-level microcode graphs covering optimization levels from -O0 to -O3. To ensure rigor, the experiments adopted a strict class-disjoint split: the training and test sets share no function keys. Under this protocol, MicroSim achieved 0.9972 ROC-AUC and 0.9762 MCC, significantly outperforming several baseline models: Gemini (0.9332 ROC-AUC), SAFE (0.9752), jTrans (0.9740), and a structure-free Bag-of-Words baseline (0.9484). These results highlight the effectiveness of combining graph structural information with contrastive learning.

The TREX benchmark is a widely used evaluation dataset in the field of binary code similarity detection. Its function-level microcode graphs cover multiple optimization levels from -O0 to -O3 and are used to test model robustness under different compiler optimizations. The key challenge of this benchmark is that the same source-code function produces significantly different binary forms under different optimization levels, and the model must learn to ignore the noise introduced by these compiler optimizations. The class-disjoint split is a stricter evaluation protocol: the training and test sets share no function keys (that is, different compiled versions of the same function do not appear in both training and test sets), thereby preventing the model from "cheating" by memorizing function identities rather than learning semantic similarity. Performance under this protocol better reflects the model's generalization ability on truly unseen functions.
In-depth Analysis of Ranking Retrieval
In addition to pairwise classification, the paper also analyzes the performance of graph transformers on ranking retrieval tasks. The study finds a performance gap between pairwise classification and ranking retrieval. By introducing Cross-Domain Similarity Local Scaling (CSLS) and unified tie-handling evaluation, GraphGPS's mean reciprocal rank (MRR) improved from 0.2542 to 0.2559, with R@1 reaching 0.1639 and R@10 reaching 0.4561. This improvement strictly satisfies the theoretical MRR upper bound.
Cross-Domain Similarity Local Scaling (CSLS) is a similarity correction method used to alleviate the "hubness" problem in embedding spaces. In high-dimensional embedding spaces, some vectors may accidentally become the nearest neighbors of many queries, causing retrieval results to be biased toward these "hub" vectors. CSLS performs local scaling by subtracting each candidate vector's average neighborhood similarity from the raw similarity, thereby penalizing hub points and improving retrieval discrimination. Mean Reciprocal Rank (MRR) is a commonly used metric for ranking retrieval, defined as the average of the reciprocal ranks of the first correct result across all queries. The closer MRR is to 1, the higher the correct results are ranked; R@k denotes the proportion of queries whose top-k results contain the correct item. Together, these metrics characterize the model's practical usability on ranking retrieval tasks.
Comparison of Loss Functions
Under 5 random seeds and the same computational budget, pairwise cosine-embedding loss achieved a slightly higher ROC-AUC (Δ = -0.0256, 95% confidence interval [-0.3282, +0.2770]), but the difference was not significant. In contrast, supervised-contrastive InfoNCE loss was significantly better on threshold classification and ranking retrieval tasks. This suggests that InfoNCE loss is more suitable for scenarios requiring discrimination of decision boundaries, while cosine loss may have a slight advantage in overall ranking, though further experimental validation is needed.
Conclusion and Outlook
Through microcode graph representation and a contrastive Siamese GNN, MicroSim achieves leading performance on the binary code similarity detection task. Its strict class-disjoint evaluation protocol sets a benchmark for future research. Future work can explore more efficient graph neural network architectures, cross-architecture generalization ability, and applications in practical vulnerability search.
In summary, MicroSim demonstrates the potential of graph neural networks in binary analysis and provides new tools and insights for the security field.
Related articles

Gemini 4 Hydrogen Released: A 2.5x Faster Everyday AI Model
Google releases Gemini 4 Hydrogen, claiming 2.5x the speed of Gemini 3.8 Flash, with four-tier thinking control, a million-token context, and Orchestrator multi-model collaboration. API pricing is $1.50 per million input tokens.

Gemini 4 Hydrogen Hands-On: Google's Fastest and Cheapest AI Model
Hands-on with Gemini 4 Hydrogen: the fastest, cheapest model in the Gemini 4 family. We break down the Carbon/Argon/Hydrogen split, API pricing traps, free-tier limits, and the cost trade-offs of four thinking levels—with a real bug-debugging demo.

Gemini 4 Hydrogen vs Sonnet Comparison Test: Uses Only 1% of Weekly Quota, Performance on Par
Hands-on test: Gemini 4 Hydrogen vs Sonnet on the same CRUD task—Hydrogen used only 1% weekly quota with comparable performance and better UI details, while Anthropic's model used 7%. Developer says daily tasks don't require expensive models.