MicroSim: Contrastive Graph Neural Networks for Binary Code Similarity Detection
Authors: Moussa Moussaoui, Tarik Houichime, Abdelghani Souhar, Abdelalim Sadiq
Organizations: Computer Science Research Laboratory(LaRI), Faculty of Science, Ibn Tofail University, Kenitra, 14000, Morocco · Meridian Team, LyRICA Laboratory, School of Information Sciences, Rabat 10100, Morocco
We present MicroSim, a system for binary code similarity detection that represents each function as a graph built from IDA Pro Hex-Rays microcode and compares such graphs with a contrastive Siamese graph neural network (GNN). We evaluate on the TREX cross-optimization benchmark, a corpus of 849,072 function-level microcode graphs spanning optimization levels -O0 through -O3, under a strict class-disjoint split in which no function key is shared between train and test. Under this protocol, MicroSim reaches 0.9972 area under the receiver operating characteristic curve (ROC-AUC) and 0.9762 Matthews correlation coefficient (MCC), outperforming Gemini (0.9332 ROC-AUC), SAFE (0.9752), and jTrans (0.9740) retrained on the same split, as well as a structure-free Bag-of-Words (BoW) baseline (0.9484). We analyze the gap between pair classification and ranked retrieval in graph transformers, showing that Cross-domain Similarity Local Scaling (CSLS) under unified tie-resolved evaluation raises GraphGPS mean reciprocal rank (MRR) from 0.2542 to 0.2559 (R@1 = 0.1639, R@10 = 0.4561), strictly satisfying the theoretical MRR upper bound. Finally, over 5 seeds with equal compute, the pairwise cosine-embedding loss attains a slightly higher ROC-AUC (Δ = -0.0256, 95% confidence interval [-0.3282, +0.2770]), whereas the supervised-contrastive information noise-contrastive estimation (InfoNCE) loss is significantly better on thresholded classification and ranked retrieval.
Figures & tables
Fig. 1 : MicroSim: a control-/data-flow microcode graph distilled to a 128-dimensional embedding for binary similarity, with the (A) GraphGPS encoder upgrade and (B) GraphCL pre-training extensions.
Parameter
GCN
GraphGPS (Transformer)
Layers
2
3
Hidden size ⋅ heads
128 ⋅ —
128 ⋅ 4
Positional encoding
—
RWSE, length 8
Pooling ⋅ embedding size
mean ⋅ 128
mean ⋅ 128
Block features ⋅ block cap
64-d hashed ⋅ none
64-d hashed ⋅ 256
Batch ( B anchors, K neg/anchor)
B=64 , K=8
B=64 , K=8
TABLE I : Architecture and Implementation Details of MicroSim Encoders
Model
ROC-AUC
F1
MCC
MRR
R@1
R@10
Bag-of-Words (BoW)
0.9484
0.8744
0.7775
0.2114
0.1375
0.3657
Gemini [ 3 ]
0.9332
0.8486
0.7318
0.1553
0.0961
0.2749
SAFE [ 4 ]
0.9752
0.9237
0.8659
0.2134
0.1377
0.3716
jTrans [ 5 ]
0.9740
0.9262
0.8687
0.2124
0.1366
0.3711
MicroSim (GCN)
0.9905
0.9603
0.9288
0.2177
0.1380
0.3860
MicroSim (GraphGPS)
0.9972
0.9869
0.9762
0.2542
0.1618
0.4568
TABLE II : MicroSim and Baselines on the TREX Cross-Optimization Benchmark (Test Split, N=126,769 Functions)
Fig. 2 : Empirical CDF of positive match rank rq on the TREX test split ( N=126,769 functions) under unified tie-resolved evaluation. Post-hoc CSLS and score fusion shift the distribution toward top ranks.
Method / Variant
Type
MRR
R@1
R@10
GraphGPS (raw, τ=0.1 )
baseline
0.2542
0.1618
0.4568
+ Mean-centering & whitening
post-hoc
0.2543
0.1623
0.4565
+ CSLS re-ranking ( k=10 )
post-hoc
0.2559
0.1639
0.4561
+ Score fusion (GCN + GraphGPS)
post-hoc
0.2499
0.1594
0.4480
+ Two-stage (top-100 → GCN)
post-hoc
0.2348
0.1468
0.4241
GraphGPS ( τ=0.05 )
retrain
0.9457±0.0615
0.9321±0.0575
0.9774±0.0575
TABLE III : Retrieval Diagnostics and Re-Ranking Improvements on the TREX Test Split
Setting
Model
ROC-AUC
MRR
R@10
GCC ↔ Clang
Bag-of-Words
0.8912±0.0014
0.1842±0.0050
0.2895±0.0080
MicroSim (GCN)
0.9684±0.0011
0.2265±0.0050
0.3482±0.0099
MicroSim (GraphGPS)
0.9846±0.0007
0.2648±0.0058
0.4115±0.0075
Plain ↔ O-LLVM
Bag-of-Words
0.8426±0.0019
0.1418±0.0041
0.2264±0.0061
MicroSim (GCN)
0.9345±0.0014
0.1946±0.0047
0.3018±0.0073
MicroSim (GraphGPS)
0.9672±0.0009
0.2412±0.0061
0.3765±0.0097
TABLE IV : Zero-Shot Generalization to Clang and Obfuscated Builds
Metric
Pairwise
InfoNCE
Δ [95% CI]
p (Holm)
ROC-AUC
0.9929±0.0005
0.9834±0.0007
−0.0095[−0.0102,−0.0088]
<0.001
F1
0.9428±0.0014
0.9640±0.0011
+0.0212[+0.0198,+0.0227]
<0.001
MCC
0.8948±0.0026
0.9358±0.0020
+0.0410[+0.0383,+0.0438]
<0.001
MRR
0.2284±0.0020
0.2642±0.0018
+0.0358[+0.0336,+0.0380]
<0.001
R@1
0.1213±0.0015
0.1431±0.0014
+0.0218[+0.0201,+0.0235]
<0.001
R@5
0.2513±0.0022
0.2979±0.0021
+0.0466[+0.0441,+0.0491]
<0.001
TABLE V : Compute-Matched Objective Ablation on the TREX Test Split ( N=126,769 Graphs, Mean ± 95% CI over 5 Seeds; Δ = InfoNCE minus Pairwise)
Encoder
Variant
ROC-AUC
MCC
MRR
R@1
R@10
GCN
Full (CFG ∪ DFG)
0.9905±0.0005
0.9288±0.0035
0.2486±0.0059
0.1406±0.0044
0.3785±0.0074
Without DFG (CFG only)
0.9841±0.0008
0.8964±0.0045
0.2294±0.0061
0.1284±0.0037
0.3518±0.0070
Without CFG (DFG only)
0.9786±0.0009
0.8712±0.0057
0.2168±0.0064
0.1196±0.0036
0.3342±0.0069
Without block features
0.5413±0.0029
0.0842±0.0051
0.0215±0.0021
0.0084±0.0013
0.0364±0.0029
Features only (no edges)
0.9614±0.0010
0.8094±0.0074
0.2398±0.0059
0.1412±0.0032
0.3629±0.0082
GraphGPS
Full (CFG ∪ DFG)
0.9973±0.0004
0.9756±0.0023
0.2894±0.0070
0.1656±0.0045
0.4466±0.0097
TABLE VI : Ablation of Control Flow, Data Flow, and Block Features (Mean ± 95% CI over 3 Seeds)
Fig. 3 : Test MRR and empirical token hash collision rate across block feature hash dimension d∈{16,32,64,128,256} . d=64 achieves the best balance between token collision rate and parameter efficiency.
Size Bin (Blocks)
Test Share
GCN MRR
GraphGPS MRR
GCN R@10
GraphGPS R@10
1 – 16
73.84%
0.2584±0.0014
0.2942±0.0014
0.3912±0.0020
0.4538±0.0020
17 – 64
22.41%
0.2268±0.0024
0.2815±0.0024
0.3495±0.0033
0.4362±0.0033
65 – 256
3.54%
0.1892±0.0062
0.2468±0.0062
0.3042±0.0084
0.3945±0.0084
>256
0.21%
0.1425±0.0109
0.1984±0.0109
0.2368±0.0149
0.3270±0.0149
TABLE VII : Retrieval Performance by Function Size Bin on the TREX Test Split
Graph contrastive learning trains graph representations by aligning related nodes or graph views while separating structurally or semantically different examples.