A Ponzi Scheme Detection Method and System Based on Customized Semantic Grouping

By combining customized semantic grouping with a lightweight detection model, the problem of opcode classification separating business logic in existing technologies is solved, enabling efficient and accurate detection of Ponzi scheme contracts, improving detection accuracy and recall rate, and ensuring the security of the trading platform.

CN123118098APending Publication Date: 2026-11-17ZHONGYUAN ENGINEERING COLLEGE
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202611226405.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-13
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing technologies, when detecting Ponzi scheme smart contracts, suffer from insufficient feature discrimination power due to the fragmented business logic caused by the opcode classification method, making it difficult to effectively identify fraudulent contracts, especially with poor recall rates.

Method used

By constructing a customized semantic grouping method, opcode sequences are mapped to semantic group ID sequences that represent fraudulent business logic. A lightweight detection model is then used for feature extraction and recognition, including prior grouping of high-risk opcodes, FastText semantic embedding training, K-Means clustering, and TF-IDF weighted feature extraction. The LightGBM classifier is used for prediction.

Benefits of technology

While maintaining low computational overhead, it significantly improves the accuracy and recall rate of identifying Ponzi scheme contracts, achieving sub-second rapid detection and enhancing the risk defense capabilities of trading platforms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123118098A_ABST
    Figure CN123118098A_ABST
Patent Text Reader

Abstract

This application belongs to the field of blockchain security technology, specifically relating to a Ponzi scheme detection method and system based on customized semantic grouping, including the following steps: S1: opcode sequence acquisition and preprocessing; S2: opcode mapping of customized semantic grouping; S3: feature vector construction; S4: prediction performed by a lightweight detection model; This application maps the original opcode sequence to a semantic group ID sequence representing fraudulent business logic, and performs efficient feature extraction and model recognition based on this, thereby achieving accurate detection of Ponzi scheme contracts while maintaining low computational overhead.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of blockchain security technology, specifically relating to a Ponzi scheme detection method and system based on customized semantic grouping. Background Technology

[0002] In the field of Ethereum smart contract security detection, machine learning methods based on opcode sequence analysis are among the mainstream technologies. The closest existing technology is a Chinese invention patent with publication number CN115098861A, entitled "A Smart Contract Vulnerability Detection Method Based on Multi-Label Model".

[0003] When the aforementioned existing technical solutions are directly applied to the detection of Ponzi scheme smart contracts, their technical approach based on categorizing underlying functions has inherent limitations:

[0004] This scheme categorizes opcodes entirely based on their underlying execution functions (such as arithmetic, logic, storage, and invocation) within the Ethereum Virtual Machine (EVM). This categorization method severs the closely related opcode sequences within the business logic of a Ponzi scheme. For example, instructions like CALL, CALLVALUE, SSTORE, and SLOAD often work together in a Ponzi scheme to achieve a complete fraudulent chain of "fund collection—state recording—profit distribution," but current technology only categorizes them as isolated "invocation instructions" or "storage instructions." This results in N-gram features extracted based on these functional categories having a weak correlation with the core fraudulent behavior patterns of Ponzi schemes, and insufficient distinguishability. Therefore, the model struggles to effectively learn the essential patterns of fraud from these features, thus limiting the detection accuracy of the model, especially its poor performance in recall when identifying fraudulent contracts.

[0005] Therefore, the technical problem that this invention needs to solve is: how to overcome the limitation of feature discrimination caused by the fragmentation of business logic due to the opcode classification method in existing methods, and significantly improve the recognition accuracy of Ponzi scheme smart contracts while maintaining low computational overhead. Summary of the Invention

[0006] This solution can be widely applied to various scenarios for automating security risk screening of Ethereum smart contracts. The technical solution is as follows:

[0007] A Ponzi scheme detection method based on customized semantic grouping includes the following steps:

[0008] S1: Opcode sequence acquisition and preprocessing;

[0009] S2: Opcode mapping for customized semantic grouping;

[0010] Construct a mapping function M from atomic opcodes to customized semantic group IDs; iterate through the opcode sequence obtained in the previous step, mapping each opcode to its corresponding semantic group ID to generate a higher-order semantic group ID sequence S_group;

[0011] S3: Feature vector construction;

[0012] S4: Prediction is performed by a lightweight detection model.

[0013] Preferably, S1: opcode sequence acquisition and preprocessing, including:

[0014] S11: Bytecode Input and Decompilation:

[0015] Receive the Ethereum smart contract address or bytecode file to be tested; convert the hexadecimal bytecode into a readable opcode mnemonic sequence S_raw = {op_1, op_2, ...,op_n} by calling a built-in or external decompilation module, where n is the length of the sequence and op_i represents the i-th opcode in the sequence;

[0016] S12: Sequence Cleaning and Normalization:

[0017] The program performs automated cleaning of S_raw, including: removing invalid code fragments that are attached due to contract creation failure; performing hash calculations on the sequence to achieve deduplication and avoid multiple analyses of the same contract; and standardizing the opcodes to a standardized format.

[0018] Preferably, S2: Opcode mapping for customized semantic groups, including:

[0019] S21: Prior grouping of high-risk opcodes;

[0020] S22: Basic instruction semantic representation and adaptive clustering;

[0021] S23: Construct the global mapping function;

[0022] Merge the G prior semantic clusters obtained in S21 with the K_opt semantic clusters obtained in S22 to form a complete set containing K_total = G + K_opt groups;

[0023] Assign a unique integer ID to each group and generate a global key-value pair mapping function M: Opcode->Group_ID. Load this mapping table as a static function resource.

[0024] Preferably, step S21 includes:

[0025] S211: Define a high-risk opcode set: The program reads a predefined configuration file, which is based on the reverse analysis experience of security experts on historical Ponzi scheme contracts, and lists opcodes that are directly related to the core fraud logic and have high risk, forming a high-risk opcode set Ω_high;

[0026] S212: Manual business logic division: Based on the mapping rules in the configuration file, the program will forcibly assign the opcodes in Ω_high to 6 prior semantic clusters.

[0027] Preferably, step S22 includes:

[0028] S221: FastText semantic embedding training:

[0029] Collect a large-scale corpus of smart contract opcode sequences unrelated to contract types, and perform unsupervised training on this corpus using the FastText model:

[0030] The model treats each opcode as a "word" and learns its distributed representation (word vector) by using other opcodes that co-occur within its context window.

[0031] FastText effectively captures the morphological similarity between opcodes by introducing sub-word information, thereby mapping functionally similar opcodes to neighboring positions in the vector space and transforming discrete symbols, i.e. opcodes, into continuous, semantically rich, dense vectors.

[0032] S222: K-Means Clustering and Cluster Number Optimization:

[0033] For the basic instruction set Ω_base that is not part of Ω_high in the complete opcode set Ω, the program loads its FastText vector representation;

[0034] To determine the optimal number of clusters K_opt, the K-Means clustering algorithm is run. The program iterates through different K values ​​within a preset range and calculates the silhouette coefficient of the clustering result for each K value.

[0035] Finally, the K value with the highest silhouette coefficient is selected as K_opt; the silhouette coefficient measures the compactness of samples within the same cluster and the separation of samples between different clusters. Maximizing this coefficient can obtain clustering results that are cohesive and well separated.

[0036] Preferably, step S3, feature vector construction, includes:

[0037] S31: Opcode sequence conversion:

[0038] For the normalized opcode sequence S_raw of the contract under test, traverse each opcode op_i, obtain its group ID value id_i = M(op_i) through the mapping function M, and perform one-to-one transformation on each element in the opcode sequence. The i-th opcode op_i in the original sequence becomes the i-th element id_i in the new sequence after being mapped by M(op_i), resulting in the transformed sequence S_group = {id_1, id_2, ..., id_n}.

[0039] S32: n-gram feature extraction:

[0040] n-gram feature extraction is performed on the semantic group ID sequence S_group, where n is the sliding window size. All consecutive bigram units in the sequence are extracted, i.e. (id_i, id_{i+1}), which are called a bigram. The frequency of each different bigram in the sequence is counted to obtain its term frequency (TF).

[0041] S33: TF-IDF weighted:

[0042] The bigram term frequencies (TF) of each contract are organized into a TF vector; the offline computed inverse document frequency (IDF) dictionary is read, the IDF values ​​are calculated based on the training set, and reflect the prevalence of each semantic group ID in all contracts; the TF vector of this contract is multiplied by the global IDF vector to obtain the final TF-IDF feature vector F.

[0043] Preferably, S4 is predicted by a lightweight detection model, specifically:

[0044] S41: Model Loading and Feature Input: Load the pre-trained LightGBM classifier model and input the feature vector F generated in step S3 into the model. The model uses cost-sensitive learning during the training phase. By adjusting the weight parameter scale_pos_weight of positive and negative samples in the loss function, a higher penalty for misclassification is imposed on the minority class, i.e. Ponzi scheme contracts.

[0045] S42: Classification Decision: The LightGBM model internally performs forward propagation and ensemble calculation on the feature vector F based on multiple decision trees, and finally outputs a probability value P between 0 and 1, representing the possibility that the contract is judged as a Ponzi scheme; P is compared with a preset decision threshold Y. If P is greater than the Y threshold, the smart contract is judged as a Ponzi scheme contract and a risk warning is generated; otherwise, it is judged as a normal contract.

[0046] A Ponzi scheme detection system based on customized semantic grouping includes a feature extraction module, a semantic grouping module, a feature engineering module, and a detection model module;

[0047] Feature extraction module: Obtains the complete bytecode of the target contract address through the Ethereum node RPC interface, calls the built-in decompilation module to convert the bytecode into a normalized raw opcode sequence S_raw, and cleans it;

[0048] Semantic grouping module: Loads the pre-defined global semantic grouping mapping function M, iterates through the opcode sequence obtained in the previous step, maps each opcode to its corresponding semantic group ID, and thus generates a high-order semantic group ID sequence S_group;

[0049] Feature Engineering Module: Receives a sequence of semantic group IDs, extracts all consecutive semantic group ID pairs bigrams in the sequence through a sliding window of size n, and counts the frequency of each different bigram to obtain a term frequency (TF) vector; performs a dot product calculation on this TF vector with a preloaded global inverse document frequency (IDF) dictionary to complete TF-IDF weighting, and finally outputs a feature vector F that represents the features of the continuous business logic segments of the contract.

[0050] Detection model module: Input the feature vector F into the pre-trained LightGBM classifier; the classifier performs inference based on the embedded cost-sensitive learning logic and outputs the probability value P that the contract is a Ponzi scheme;

[0051] The system automatically makes an audit decision based on a preset risk threshold Y. If P is greater than the Y threshold, the smart contract is determined to be a Ponzi scheme contract and a risk warning is generated; otherwise, it is determined to be a normal contract.

[0052] Compared with the prior art, the beneficial effects of this application are as follows:

[0053] This invention constructs a Ponzi scheme detection method based on customized semantic grouping, which maps the original opcode sequence into a semantic group ID sequence representing the fraudulent business logic, and performs efficient feature extraction and model recognition based on this, thereby achieving accurate detection of Ponzi scheme contracts while maintaining low computational overhead. Attached Figure Description

[0054] Figure 1 This is a flowchart of the application process. Detailed Implementation

[0055] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.

[0056] A Ponzi scheme detection method based on customized semantic grouping includes the following steps:

[0057] S1: Opcode sequence acquisition and preprocessing

[0058] S11: Bytecode Input and Decompilation: The system receives the Ethereum smart contract address or bytecode file to be tested. By calling the built-in or external decompilation module, the hexadecimal bytecode is converted into a human-readable opcode mnemonic sequence S_raw = {op_1, op_2, ..., op_n}, where n is the length of the sequence and op_i represents the i-th opcode in the sequence.

[0059] S12: Sequence Cleaning and Normalization: The program automatically cleans S_raw. This includes: removing invalid code fragments resulting from contract creation failures; hashing the sequence to remove duplicates and avoid multiple analyses of the same contract; and standardizing the opcodes to a standardized format. This step ensures the purity and consistency of the input data, providing a reliable foundation for subsequent semantic analysis.

[0060] S2: Opcode mapping for customized semantic grouping

[0061] This step aims to construct a mapping function M from atomic opcodes to customized semantic group IDs. This function is trained offline and loaded directly for use during online detection.

[0062] S21: Prior grouping of high-risk opcodes (offline construction)

[0063] S211: Define a high-risk opcode set: The program reads a predefined configuration file, which, based on security experts' reverse engineering experience of historical Ponzi scheme contracts, lists opcodes directly related to the core fraud logic and possessing high risk, forming a high-risk opcode set Ω_high. Examples include: CALL, DELEGATECALL, SELFDESTRUCT, CALLVALUE, CALLER, SSTORE, SLOAD, JUMPI, LOG0, TIMESTAMP, etc.

[0064] S212: Manual Business Logic Division: Based on the mapping rules in the configuration file, the program forcibly assigns the opcodes in Ω_high to 6 prior semantic clusters. The mapping rules stipulate: CALL, DELEGATECALL, SELFDESTRUCT belong to cluster 0: Funds Flow and High-Risk Calls; CALLVALUE, CALLER, ADDRESS belong to cluster 1: Identity and Funds Environment Awareness; SSTORE, SLOAD belong to cluster 2: Persistent State Read / Write; JUMP, JUMPI, REVERT, RETURN belong to cluster 3: Core Control Flow and Interrupts; LOG0 ~ LOG4 belong to cluster 4: Event Log Recording; TIMESTAMP, NUMBER, BLOCKHASH belong to cluster 5: Block Environment and Timestamps. The business model of a Ponzi scheme (such as deposits, dividends, and bookkeeping) is deterministic. This step hard-codes domain knowledge into the feature space, ensuring that the characteristic signals of these key fraud patterns are not diluted or confused by the subsequent automatic clustering process, directly establishing strong semantic associations from the source. It significantly improves the interpretability of features and their relevance to core fraud patterns.

[0065] S22: Basic Instruction Semantic Representation and Adaptive Clustering (Offline Construction)

[0066] S221: FastText Semantic Embedding Training: The system collects a large-scale corpus of smart contract opcode sequences unrelated to contract types. The program uses the FastText model for unsupervised training on this corpus. The model treats each opcode as a "word" and learns its distributed representation (word vector) through other opcodes co-occurring within its context window. By introducing subword information, FastText effectively captures the morphological similarity between opcodes (e.g., PUSH1 and PUSH2 share the "PUSH" prefix and are semantically related), thus mapping functionally similar opcodes to neighboring positions in the vector space. This transforms discrete symbols (opcodes) into continuous, semantically rich, dense vectors, laying the foundation for distance-based clustering.

[0067] S222: K-Means Clustering and Cluster Number Optimization: For the basic instruction set Ω_base that does not belong to Ω_high in the full opcode set Ω, the program loads its FastText vector representation. Then, the K-Means clustering algorithm is run. To determine the optimal number of clusters K_opt, the program iterates through different K values ​​within a preset range [5, 30], calculating the silhouette score for each K value. Finally, the K value with the highest silhouette score is selected as K_opt. The silhouette score measures the density of samples within the same cluster and the separation between samples in different clusters; maximizing this coefficient yields cohesive and well-separated clustering results. This process adaptively groups a large number of scattered, low-information-density basic opcodes (such as various stack operations and arithmetic operations), achieving dimensionality reduction and semantic induction of non-core instructions.

[0068] S23: Constructing the global mapping function (offline construction): The program merges the G prior semantic clusters obtained in S21 with the K_opt semantic clusters obtained in S22, forming a complete set containing K_total = G + K_opt groups. A unique integer ID (from 1 to K_total) is assigned to each group, and a global key-value pair mapping table M: ​​Opcode -> Group_ID is generated. The online detection system loads this mapping table as a static resource.

[0069] S3: Feature vector construction (performed by the feature engineering module)

[0070] S31: Opcode Sequence Transformation: For the normalized opcode sequence S_raw of the contract under test, the program iterates through each opcode op_i and obtains its group ID value id_i = M(op_i) by querying the mapping table M (the mapping function M is a one-to-one transformation of each element in the opcode sequence. The i-th opcode op_i in the original sequence becomes the i-th element id_i in the new sequence after being mapped by M(op_i)). The transformed sequence S_group = {id_1, id_2, ..., id_n} is obtained.

[0071] S32: n-gram feature extraction: The program performs n-gram feature extraction on the semantic group ID sequence S_group. In this embodiment, n=2 (where n is the sliding window size). That is, through a sliding window of size 2, all consecutive bigram units in the sequence are extracted, i.e., (id_i, id_{i+1}), which are called a bigram. The frequency of each different bigram in the sequence is counted to obtain its term frequency (TF).

[0072] S33: TF-IDF Weighting: The bigram term frequency (TF) of each contract is organized into a TF vector. The program reads an offline-computed Inverse Document Frequency (IDF) dictionary. This IDF value is calculated based on the training set and reflects the prevalence of each semantic group ID across all contracts. The program performs a dot product between the TF vector of this contract and the global IDF vector to obtain the final TF-IDF feature vector F. TF-IDF can amplify the weights of bigram features that frequently appear in this contract but are rare (high IDF) in all normal contracts, such as anomalous sequential operation patterns like "identity perception -> fund transfer," while suppressing the weights of common instruction pairs. This further enhances the discriminative power of the feature vector, making it more focused on the contract-specific, continuous business logic.

[0073] S4: Model Prediction

[0074] S41: Model Loading and Feature Input: The system loads the pre-trained LightGBM classifier model. This model uses cost-sensitive learning during training, adjusting the scale_pos_weight parameter of the loss function to impose a higher penalty for misclassification of the minority class (Ponzi scheme contracts). The program inputs the feature vector F generated in step S3 into the model.

[0075] S42: Classification Decision: Internally, the LightGBM model performs forward propagation and ensemble calculations on the feature vector F based on multiple decision trees, ultimately outputting a probability value P between 0 and 1, representing the likelihood that the contract is classified as a Ponzi scheme. The program compares P with a preset decision threshold Y. If P is greater than the Y threshold, the smart contract is classified as a Ponzi scheme contract, and a risk warning is generated; otherwise, it is classified as a legitimate contract. LightGBM employs gradient-based one-sided sampling (GOSS) and histogram algorithms, which are inherently highly efficient. Combined with cost-sensitive learning, it is specifically optimized for classification performance in scenarios with extremely imbalanced positive and negative samples, aiming to maximize the recall of high-risk contracts.

[0076] A Ponzi scheme detection system based on customized semantic grouping includes a feature extraction module, a semantic grouping module, a feature engineering module, and a detection model module;

[0077] Feature extraction module:

[0078] For opcode acquisition and preprocessing, the feature extraction module of the auditing system obtains the complete bytecode of the target contract address through the Ethereum node RPC interface. Subsequently, the feature extraction module calls the built-in decompilation module to convert the bytecode into a normalized raw opcode sequence (S_raw) and clean it.

[0079] Semantic grouping module:

[0080] Customized semantic grouping mapping: The system's semantic grouping engine loads the pre-set global semantic grouping mapping function M, traverses the opcode sequence obtained in the previous step, and maps each opcode to its corresponding semantic group ID (for example, mapping CALL to group ID 1 "fund transfer and high-risk call"), thereby generating a high-order semantic group ID sequence (S_group).

[0081] Feature Engineering Module: Receives a sequence of semantic group IDs. This module first extracts all consecutive semantic group ID pairs (bigamies) from the sequence using a sliding window of size n=2, and counts the frequency of each different bigamy to obtain a term frequency (TF) vector. Subsequently, this TF vector is multiplied by a preloaded global inverse document frequency (IDF) dictionary to complete the TF-IDF weighted calculation, and finally outputs a feature vector F representing the features of the continuous business logic segments of the contract.

[0082] The detection model module inputs the feature vector F into a pre-trained LightGBM classifier. This classifier performs inference based on embedded cost-sensitive learning logic and outputs a probability value P indicating that the contract is a Ponzi scheme. The review system automatically makes a review decision based on a preset risk threshold Y. If P is greater than the Y threshold, the smart contract is determined to be a Ponzi scheme contract, and a risk warning is generated; otherwise, it is determined to be a normal contract.

[0083] Results: In this scenario, each step of this solution is automatically executed by specific system components, achieving full automation from contract address to risk assessment. Through the core step of "customized semantic grouping," the system can understand the business intent and execution mode of the underlying code, thus achieving sub-second-level ultra-fast analysis while ensuring high detection accuracy. This enables exchanges to quickly and automatically intercept fraudulent contracts with Ponzi scheme characteristics under the pressure of high-concurrency listing applications, improving operational efficiency while fundamentally strengthening the platform's risk defense capabilities and protecting investor assets.

[0084] This solution can be widely applied to various scenarios for automating security risk screening of Ethereum smart contracts, such as:

[0085] Decentralized exchange listing review: Before deciding whether to list a new asset contract, exchanges use this solution to automatically detect whether the contract has Ponzi scheme characteristics.

[0086] Blockchain security audit service: Security companies integrate this solution into their automated auditing platforms to provide project owners or investors with contract risk scanning reports.

[0087] User-side risk warning: Cryptocurrency wallets or plugins silently perform checks in the background before users interact with unfamiliar contracts and issue immediate warnings to users about high-risk contracts.

[0088] Example application scenario: Decentralized exchange listing review

[0089] In a high-performance decentralized exchange (DEX), the smart contracts corresponding to all trading pairs applying for listing must pass a security audit.

[0090] Initialization: When deploying the auditing system, the exchange has already completed the offline training of the core components of this solution, including the customized semantic grouping mapping function M, feature weighting parameters (IDF dictionary), and the LightGBM classifier model that integrates cost-sensitive learning. These components have all been pre-loaded into the auditing server.

[0091] Table 1. Effectiveness of the detection method

[0092] Precision Recall F1-Score Runtime / s 0.942±0.011 0.966±0.013 0.954±0.014 8.026

[0093] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A Ponzi scheme detection method based on customized semantic grouping, characterized in that, Includes the following steps: S1: Opcode sequence acquisition and preprocessing; S2: Opcode mapping for customized semantic grouping; Construct a mapping function M from atomic opcodes to customized semantic group IDs; iterate through the opcode sequence obtained in the previous step, mapping each opcode to its corresponding semantic group ID to generate a higher-order semantic group ID sequence S_group; S3: Feature vector construction; S4: Prediction is performed by a lightweight detection model.

2. The Ponzi scheme detection method based on customized semantic grouping according to claim 1, characterized in that, S1: Opcode sequence acquisition and preprocessing, including: S11: Bytecode Input and Decompilation: Receive the Ethereum smart contract address or bytecode file to be tested; convert the hexadecimal bytecode into a readable opcode mnemonic sequence S_raw = {op_1, op_2, ..., op_n} by calling a built-in or external decompilation module, where n is the length of the sequence and op_i represents the i-th opcode in the sequence; S12: Sequence Cleaning and Normalization: The program performs automated cleaning of S_raw, including: removing invalid code fragments that are attached due to contract creation failure; performing hash calculations on the sequence to achieve deduplication and avoid multiple analyses of the same contract; and standardizing the opcodes to a standardized format.

3. The Ponzi scheme detection method based on customized semantic grouping according to claim 1, characterized in that, S2: Opcode mapping for customized semantic groups, including: S21: Prior grouping of high-risk opcodes; S22: Basic instruction semantic representation and adaptive clustering; S23: Construct the global mapping function; Merge the G prior semantic clusters obtained in S21 with the K_opt semantic clusters obtained in S22 to form a complete set containing K_total=G + K_opt groups; Assign a unique integer ID to each group and generate a global key-value pair mapping function M: Opcode -> Group_ID. Load this mapping table as a static function resource.

4. The Ponzi scheme detection method based on customized semantic grouping according to claim 3, characterized in that, Step S21 includes: S211: Define a high-risk opcode set: The program reads a predefined configuration file, which is based on the reverse analysis experience of security experts on historical Ponzi scheme contracts, and lists opcodes that are directly related to the core fraud logic and have high risk, forming a high-risk opcode set Ω_high; S212: Manual business logic division: Based on the mapping rules in the configuration file, the program will forcibly assign the opcodes in Ω_high to 6 prior semantic clusters.

5. The Ponzi scheme detection method based on customized semantic grouping according to claim 3, characterized in that, Step S22 includes: S221: FastText semantic embedding training: Collect a large-scale corpus of smart contract opcode sequences unrelated to contract types, and perform unsupervised training on this corpus using the FastText model: The model treats each opcode as a "word" and learns its distributed representation (word vector) by using other opcodes that co-occur within its context window. FastText effectively captures the morphological similarity between opcodes by introducing sub-word information, thereby mapping functionally similar opcodes to neighboring positions in the vector space and transforming discrete symbols, i.e. opcodes, into continuous, semantically rich, dense vectors. S222: K-Means Clustering and Cluster Number Optimization: For the basic instruction set Ω_base that is not part of Ω_high in the complete opcode set Ω, the program loads its FastText vector representation; To determine the optimal number of clusters K_opt, the K-Means clustering algorithm is run. The program iterates through different K values ​​within a preset range and calculates the silhouette coefficient of the clustering result for each K value. Finally, the K value with the highest silhouette coefficient is selected as K_opt; the silhouette coefficient measures the compactness of samples within the same cluster and the separation of samples between different clusters. Maximizing this coefficient can obtain clustering results that are cohesive and well separated.

6. The Ponzi scheme detection method based on customized semantic grouping according to claim 1, characterized in that, Step S3, feature vector construction, includes: S31: Opcode sequence conversion: For the normalized opcode sequence S_raw of the contract under test, traverse each opcode op_i, obtain its group ID value id_i = M(op_i) through the mapping function M, and perform one-to-one transformation on each element in the opcode sequence. The i-th opcode op_i in the original sequence becomes the i-th element id_i in the new sequence after being mapped by M(op_i), resulting in the transformed sequence S_group = {id_1, id_2, ..., id_n}. S32: n-gram feature extraction: n-gram feature extraction is performed on the semantic group ID sequence S_group, where n is the sliding window size. All consecutive bigram units in the sequence are extracted, i.e. (id_i, id_{i+1}), which are called a bigram. The frequency of each different bigram in the sequence is counted to obtain its term frequency (TF). S33: TF-IDF weighted: The bigram term frequencies (TF) of each contract are organized into a TF vector; the offline computed inverse document frequency (IDF) dictionary is read, the IDF values ​​are calculated based on the training set, and reflect the prevalence of each semantic group ID in all contracts; the TF vector of this contract is multiplied by the global IDF vector to obtain the final TF-IDF feature vector F.

7. The Ponzi scheme detection method based on customized semantic grouping according to claim 1, characterized in that, S4 is predicted using a lightweight detection model, specifically: S41: Model Loading and Feature Input: Load the pre-trained LightGBM classifier model and input the feature vector F generated in step S3 into the model. The model uses cost-sensitive learning during the training phase. By adjusting the weight parameter scale_pos_weight of positive and negative samples in the loss function, a higher penalty for misclassification is imposed on the minority class, i.e. Ponzi scheme contracts. S42: Classification Decision: The LightGBM model internally performs forward propagation and ensemble calculation on the feature vector F based on multiple decision trees, and finally outputs a probability value P between 0 and 1, which represents the possibility that the contract is judged as a Ponzi scheme; P is compared with a preset decision threshold Y. If P is greater than the Y threshold, the smart contract is judged as a Ponzi scheme contract and a risk warning is generated. Otherwise, it is considered a normal contract.

8. A Ponzi scheme detection system based on customized semantic grouping, applicable to the method described in any one of claims 1-7, characterized in that, It includes a feature extraction module, a semantic grouping module, a feature engineering module, and a detection model module; Feature extraction module: Obtains the complete bytecode of the target contract address through the Ethereum node RPC interface, calls the built-in decompilation module to convert the bytecode into a normalized raw opcode sequence S_raw, and cleans it; Semantic grouping module: Loads the pre-defined global semantic grouping mapping function M, iterates through the opcode sequence obtained in the previous step, maps each opcode to its corresponding semantic group ID, and thus generates a high-order semantic group ID sequence S_group; Feature Engineering Module: Receives a sequence of semantic group IDs, extracts all consecutive semantic group ID pairs bigrams in the sequence through a sliding window of size n, and counts the frequency of each different bigram to obtain a term frequency (TF) vector; performs a dot product calculation on this TF vector with a preloaded global inverse document frequency (IDF) dictionary to complete TF-IDF weighting, and finally outputs a feature vector F that represents the features of the continuous business logic segments of the contract. Detection model module: Input the feature vector F into the pre-trained LightGBM classifier; the classifier performs inference based on the embedded cost-sensitive learning logic and outputs the probability value P that the contract is a Ponzi scheme; The system automatically makes an audit decision based on a preset risk threshold Y. If P is greater than the Y threshold, the smart contract is determined to be a Ponzi scheme contract and a risk warning is generated; otherwise, it is determined to be a normal contract.

Citation Information

Patent Citations

  • Intelligent contract vulnerability detection method based on multi-label model

    CN115098861A