## 1 Introduction
widely-used training objective function, aiming to minimize the distance between embeddings of similar binary code while maximizing the distance for dissimilar ones. As shown in Figure 2a, an anchor represents an input basic block \(B\), a positive sample \(B_{+}\) denotes a similar block to the anchor, and a negative sample \(B_{-}\) represents a dissimilar one. During the training, the triplet loss objective brings the embeddings of block \(B\) and block \(B_{+}\) closer in the hyper-sphere, while ensuring a distinct separation between \(B\) and \(B_{-}\). Nevertheless, in real-world BCSD tasks, given an anchor basic block, there are numerous similar basic blocks and dissimilar basic blocks. As shown in Figure 2b, the triplet loss function focuses primarily on the local positive/negative samples and lacks a more comprehensive optimization, resulting in slow convergence and even difficulty in converging to the desired parameters. Furthermore, selecting representative positive/negative samples from a large number of basic blocks is challenging, and the quality of the positive/negative samples seriously affects the effectiveness of model training. In BCSD tasks, easy samples represent basic blocks with distinguishable features that facilitate accurate predictions or classifications, while hard samples present challenges and complexities for the model predictions. In Figure 2b, with \(B\) as the anchor sample, \(B_{+}\) and \(B_{-}\) are an easy positive sample and an easy negative one, while \(B^{\prime}_{+}\) and \(B^{\prime}_{-}\) are a hard positive sample and a hard negative one, respectively. As depicted in Figure 2b, with \(B\) as the anchor sample, \(B_{+}\) and \(B_{-}\) represent easy positive and easy negative samples, respectively, while \(B^{\prime}_{+}\) and \(B^{\prime}_{-}\) represent hard positive and hard negative samples. Easy samples are typically associated with low prediction errors and contribute less to the overall loss calculations, while hard samples tend to result in higher prediction errors and have a greater impact on the overall loss calculations. In this paper, we introduce a novel approach called BlockMatchfor fine-grained Binary Code Similarity Detection (BCSD) that utilizes Natural Language Processing (NLP) and contrastive learning techniques to match similar basic blocks between complex functions for the last-mile problem of BCSD tasks. Basic blocks in binary files consist of various instructions. We first treat binary code as a language and use a DeBERTa model to capture position relations and contextual semantics for instruction sequence encoding. We then use a mean pooling layer to generate basic block embeddings for binary code similarity detection. To solve the aforementioned challenges, we propose a training framework based on contrastive learning [30; 31]. We adopt NT-Xent loss [31] as our objective functions for model training to address the aforementioned challenges. The NT-Xent loss function supports larger sample sizes for model training, which mitigates slow convergence optimization-less problems caused by local limited positive/negative samples. We also propose a block augmentation model to generate high-quality samples for training effectiveness improvements. In summary, we have made the following contributions:  
* We propose a novel fine-grained BCSD approach based on NLP technique for basic block matching, namely BlockMatch. It first uses an NLP model to capture position relations and contextual semantics for instruction sequence encoding. Then, we use  
Figure 2: An example of BCSD model training. (**a**) An example of triplet loss, and (**b**) the actual situation. a mean pooling layer to generate basic block embeddings for binary code similarity detection. BlockMatch can be used to solve the last-mile problem of BCSD tasks regarding matching among basic blocks.