Block chain intelligent contract byte code level security detection method and system

By constructing a contract execution dependency graph and a dual-channel contract semantic encoding mechanism, combined with the self-supervised reconstruction learning of a variational autoencoder, the problem of insufficient accuracy and generalization ability of smart contract bytecode-level security detection in existing technologies is solved, and efficient identification and detection of unknown vulnerabilities is achieved.

CN121997328APending Publication Date: 2026-05-08ELECTRIC POWER RESEARCH INSTITUTE OF STATE GRID SHANDONG ELECTRIC POWER COMPANY
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
ELECTRIC POWER RESEARCH INSTITUTE OF STATE GRID SHANDONG ELECTRIC POWER COMPANY
Filing Date
2025-12-04
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

Existing technologies struggle to effectively characterize the dynamic control dependencies and data interaction patterns of smart contracts during execution without the contract source code, and their ability to detect unknown or evolving vulnerabilities is insufficient, resulting in inadequate accuracy and generalization of bytecode-level security testing for smart contracts.

Method used

By constructing a contract execution dependency graph, a dual-channel contract semantic encoding mechanism is used to mine mixed-granularity execution trajectory encoding, and a variational autoencoder is used for self-supervised reconstruction learning to generate potential semantic distribution features. Combined with a reconstruction error judgment mechanism, potential security vulnerabilities are identified.

Benefits of technology

It improves the accuracy and robustness of smart contract bytecode-level security detection, enhances the ability to detect unknown vulnerabilities, reduces the dependence on labeled vulnerability contract bytecode, and realizes potential behavior learning and anomaly detection under unlabeled conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121997328A_ABST
    Figure CN121997328A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of blockchain security, and discloses a blockchain smart contract byte code level security detection method and system, and the method comprises the steps: carrying out the execution of a semantic model through a contract byte code for the dependence of a control flow and a data flow in the execution process of a smart contract, and constructing a contract execution dependence graph; a two-channel contract semantic coding mechanism is used for mining contract mixed granularity execution track coding; performing trajectory coding based on contract mixed granularity, and performing self-supervised reconstruction learning on non-vulnerability execution samples by using a variational auto-encoder enhanced execution trajectory reconstruction model to obtain potential semantic distribution features; and according to the potential semantic distribution characteristics, performing reconstruction error evaluation on the byte code and the execution track of the intelligent contract input in the detection stage by utilizing a reconstruction error judgment mechanism, and judging whether the intelligent contract has potential security vulnerabilities or not. According to the invention, the accuracy, robustness and generalization performance of blockchain smart contract byte code level security detection are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of blockchain security technology, and in particular to a method and system for bytecode-level security detection of blockchain smart contracts. Background Technology

[0002] With the widespread application of blockchain technology in fields such as power grid trading and IoT collaborative computing, smart contracts, as the core execution carrier in blockchain systems, undertake the important functions of automating asset transfer and business logic processing. However, once deployed, smart contracts are immutable. If their bytecode contains security vulnerabilities, attackers may exploit them during the execution phase to launch reentrancy attacks, abuse of delegate calls, integer overflows, and other malicious operations, causing serious economic losses and systemic risks. However, traditional security vulnerability detection methods, such as symbolic execution, static rule matching, and fuzzing, are limited to contract source code-level analysis and are unable to effectively characterize the dynamic control dependencies and data interaction behavior patterns of smart contracts during execution when the contract source code is unavailable.

[0003] Existing bytecode-level contract security detection methods mainly rely on rule-based or supervised learning-based analysis paradigms. However, 1) existing methods are generally based on graph neural networks or text encoding models for supervised classification, requiring a large number of labeled vulnerability samples to train the detection model. In the actual blockchain environment, the number of vulnerability samples is limited and the type updates are lagging, resulting in insufficient generalization ability of the model when facing unknown or evolving vulnerabilities; 2) existing methods mostly focus on static control flow or data flow structures, making it difficult to capture dynamic temporal dependencies and state transition characteristics during contract execution, while real vulnerabilities often manifest as abnormal execution timing; 3) execution pattern mining is limited: current methods are mostly based on local control flow subgraphs or isolated instruction sequences for analysis, lacking the ability to jointly model long-range data dependencies and global execution semantics, resulting in insufficient multi-layered vulnerability semantic expression under complex contract execution trajectories, thus affecting the detection effect of variant attacks and potential vulnerabilities.

[0004] Therefore, how to provide a bytecode-level security detection solution for blockchain smart contracts, improve the accuracy of smart contract bytecode-level vulnerability detection and the ability to generalize to unknown vulnerabilities, reduce the dependence on labeled vulnerability contract bytecode, and enhance the model's adaptive expression of contract execution semantics and potential space learning ability are urgent problems to be solved. Summary of the Invention

[0005] This invention provides a bytecode-level security detection method and system for blockchain smart contracts to solve the aforementioned technical problems in the prior art.

[0006] According to a first aspect of the present invention, a bytecode-level security detection method for blockchain smart contracts is provided.

[0007] In one embodiment, the blockchain smart contract bytecode-level security detection method includes:

[0008] To address the control flow and data flow dependencies of smart contracts during execution, a contract execution dependency graph is constructed using a pre-configured contract bytecode execution semantic model.

[0009] Using the contract execution dependency graph as input, a dual-channel contract semantic encoding mechanism is used to mine the mixed-granularity execution trajectory encoding of the contract.

[0010] Based on contract hybrid granularity execution trajectory encoding, an execution trajectory reconstruction model enhanced by variational autoencoder is used to perform self-supervised reconstruction learning on non-vulnerability execution samples to obtain latent semantic distribution features;

[0011] Based on the latent semantic distribution characteristics, a reconstruction error judgment mechanism is used to evaluate the reconstruction error of the smart contract bytecode and execution trajectory input during the detection phase, and to determine whether the smart contract has potential security vulnerabilities.

[0012] In one embodiment, to address the control flow and data flow dependencies during the execution of a smart contract, a contract execution dependency graph is constructed using a pre-configured contract bytecode execution semantic model, including:

[0013] For each bytecode instruction sequence of a smart contract, a node is created to form a node set;

[0014] Extract runtime context attributes from the nodes in the node set to form feature vectors; based on the feature vectors, obtain the node attribute matrix:

[0015] The control flow and data flow during the execution of smart contracts are analyzed separately to obtain the control dependency edge set and the data dependency edge set;

[0016] The control dependency edge set and the data dependency edge set are weighted by dependency strength respectively to obtain the control dependency adjacency matrix and the data dependency adjacency matrix; the control dependency adjacency matrix and the data dependency adjacency matrix are merged to obtain the unified execution semantic adjacency matrix;

[0017] A contract execution dependency graph is constructed based on the node attribute matrix, the control dependency edge set, the data dependency edge set, and the unified execution semantic adjacency matrix.

[0018] In one embodiment, mining the mixed-granularity execution trajectory encoding of a contract using a dual-channel contract semantic encoding mechanism includes:

[0019] Based on the contract execution dependency graph, the global channel contract semantic analysis method is used to extract cross-functional dependency features of control flow;

[0020] Based on the contract execution dependency graph, the local channel contract semantic analysis method is used to extract data flow state transition features;

[0021] Based on the cross-functional dependency features of control flow and the state transition features of data flow, a hybrid granularity feature fusioner is used to extract multi-scale dependency features from coarse-grained semantics to fine-grained behavior; and based on the multi-scale dependency features, the hierarchical alignment and dynamic aggregation of smart contract execution semantics are performed to generate a hybrid granularity execution trajectory code for the contract.

[0022] In one embodiment, extracting cross-functional dependency features of control flow using a global channel contract semantic analysis method, based on the contract execution dependency graph, includes:

[0023] For the contract execution dependency graph, extract the control path set along the control flow dependency edge set:

[0024] For any path in the control path set, construct its global semantic input sequence, unify paths of different lengths to a fixed length, and introduce a masking mechanism to obtain the normalized global semantic input sequence.

[0025] Based on multi-head self-attention mechanism, layer normalization and feedforward network, path-level long-range dependency modeling is performed on the normalized global semantic input sequence to output global path dependency features; and average pooling is used to pool the global path dependency features to obtain the feature vector of a single path.

[0026] Based on the obtained compact feature vector of a single path, the feature vector of multiple paths is differentially weighted using path importance weights; and layer graph attention propagation is performed based on the control adjacency relationship to inject graph-level global context features. The weighted multi-path feature vector and global context features are deeply integrated through residual fusion to obtain the graph-level aggregated control features after residual fusion.

[0027] By transforming the aggregated features through nonlinear mapping, the control flow cross-functional dependency features of the global channel are obtained.

[0028] In one embodiment, extracting data flow state transition features based on the contract execution dependency graph and using a local channel contract semantic analysis method includes:

[0029] For the contract execution dependency graph, extract the data flow path set along the data flow dependency edge set;

[0030] For any path in the data flow path set, construct its local time-series input sequence, unify paths of different time scales to a fixed time scale, and introduce a masking mechanism to obtain the normalized local time-series input sequence.

[0031] Based on gated recurrent units, the Sigmoid activation function, and the Hadamard product, a temporal model of data flow state transitions is performed on the normalized local temporal input sequence, outputting local data flow state transition dependency features.

[0032] One-dimensional dilated convolutional layers are used to enhance the local data flow state transition dependency features. The feature distribution is stabilized by layer normalization to obtain convolutional enhanced features. The convolutional enhanced features are then integrated with the original temporal features by residual fusion to obtain path temporal state residual fusion features.

[0033] Based on the obtained path temporal state residual fusion features, a multi-head temporal attention mechanism is used to aggregate key data migration segments to obtain key migration segment aggregation vectors; and the aggregation vectors of multiple data flow paths are differentially weighted by path importance weights to obtain multi-path robust aggregation features.

[0034] By transforming the multi-path robust aggregation features through nonlinear mapping, the data flow state transition features of local channels are obtained.

[0035] In one embodiment, based on control flow cross-functional dependency features and data flow state transition features, a hybrid granularity feature fusion processor is used to extract multi-scale dependency features from coarse-grained semantics to fine-grained behavior; and based on the hierarchical alignment and dynamic aggregation processing of smart contract execution semantics using multi-scale dependency features, a hybrid granularity execution trajectory encoding of the contract is generated, including:

[0036] For control flow cross-functional dependency features and data flow state, channel alignment and projection onto a common semantic space are performed using linear mapping matrix and bias matrix to obtain aligned control flow cross-functional dependency features and data flow state transition features.

[0037] The aligned control flow cross-functional dependency features and data flow state transition features are subjected to nonlinear transformation based on k scale transformers to obtain a multi-scale feature set from coarse-grained semantics to fine-grained behavior.

[0038] For a multi-scale feature set, the importance weight of each scale is calculated through the attention parameter, and based on the importance weight, the semantic association between features at different scales is modeled based on the self-attention mechanism to obtain multi-scale attention aggregated features;

[0039] For multi-scale attention aggregation features, the gating weight parameters and the Sigmoid activation function are used to generate dimension-wise gating coefficients. The Hadamard product is then used for element-wise filtering to enhance the complementarity between control flow features and data flow features, thus obtaining channel-gated fusion results.

[0040] The gated fusion result is superimposed with the aligned original features by residual superposition, and combined with the layer normalization to stabilize the feature distribution, a nonlinear expression is introduced through the GELU activation function to generate a contract hybrid granularity execution trajectory code.

[0041] In one embodiment, based on contract hybrid granularity execution trajectory encoding, an execution trajectory reconstruction model enhanced by variational autoencoder is used to perform self-supervised reconstruction learning on non-vulnerability execution samples, resulting in latent semantic distribution features including:

[0042] Trajectory encoding is performed on the mixed granularity of the contract, and parameterized modeling is performed using the encoder of the variational autoencoder to output the mean vector and variance vector of the posterior distribution.

[0043] Based on the mean vector and variance vector, differentiable sampling is performed using reparameterization to obtain latent variables of the implicit semantics of the contract execution trajectory;

[0044] Using latent variables as input, the distribution is modeled and reconstructed through the decoder of a variational autoencoder, generating a trajectory reconstruction vector with the same dimension as the original input.

[0045] Trajectory encoding is performed at a mixed granularity based on trajectory reconstruction vector and original contract. Self-supervised optimization is performed by maximizing the lower bound of evidence, and the encoder and decoder parameters are iteratively updated to obtain the optimized variational autoencoder.

[0046] The non-vulnerability execution sample set is input into the optimized variational autoencoder for continuous iterative training. The parameters are fine-tuned through the latent space distribution constraint and reconstruction error minimization process, and the latent semantic distribution features of the normal execution trajectory of the smart contract are learned in the latent space.

[0047] In one embodiment, based on latent semantic distribution characteristics, a reconstruction error assessment mechanism is used to evaluate the reconstruction error of the smart contract bytecode and execution trajectory input during the detection phase, determining whether the smart contract has potential security vulnerabilities, including:

[0048] For the smart contract bytecode input during the detection phase, a hybrid granularity execution trajectory code for the contract is generated through the contract bytecode execution semantic model and the dual-channel contract semantic encoding mechanism.

[0049] The mixed-granularity execution trajectory encoding is input into the variational autoencoder-enhanced execution trajectory reconstruction model to generate a trajectory reconstruction vector that conforms to the latent semantic distribution characteristics of normal execution trajectories.

[0050] The reconstruction error is obtained by calculating the reconstruction error by combining the original mixed-granularity execution trajectory encoding of the smart contract bytecode with the generated trajectory reconstruction vector;

[0051] The reconstruction error is compared with a predetermined threshold. If the reconstruction error is greater than the predetermined threshold, the smart contract is determined to have a potential security vulnerability.

[0052] The predetermined threshold is set based on the mean and standard deviation of the reconstruction error distribution data of non-vulnerable samples during the training phase, combined with preset hyperparameters.

[0053] According to a second aspect of the present invention, a bytecode-level security detection system for blockchain smart contracts is provided.

[0054] In one embodiment, the blockchain smart contract bytecode-level security detection system includes:

[0055] The Contract Bytecode Execution Semantics module is used to address the control flow and data flow dependencies of smart contracts during execution. It utilizes a pre-configured contract bytecode execution semantic model to construct a contract execution dependency graph.

[0056] The dual-channel contract semantic encoding module is used to take the contract execution dependency graph as input and use the dual-channel contract semantic encoding mechanism to mine the mixed-granularity execution trajectory encoding of the contract.

[0057] Variational autoencoders enhance remodeling for contract-based hybrid granularity execution trajectory encoding. The execution trajectory reconstruction model enhanced by variational autoencoders performs self-supervised reconstruction learning on non-vulnerability execution samples to obtain latent semantic distribution features.

[0058] The reconstruction error vulnerability determination module is used to evaluate the reconstruction error of the smart contract bytecode and execution trajectory input during the detection phase based on the potential semantic distribution characteristics and the reconstruction error determination mechanism, so as to determine whether the smart contract has potential security vulnerabilities.

[0059] In one embodiment, when the contract bytecode execution semantic module constructs a contract execution dependency graph based on a pre-configured contract bytecode execution semantic model, it considers the control flow and data flow dependencies of a smart contract during execution.

[0060] For each bytecode instruction sequence of a smart contract, a node is created to form a node set;

[0061] Extract runtime context attributes from the nodes in the node set to form feature vectors; based on the feature vectors, obtain the node attribute matrix:

[0062] The control flow and data flow during the execution of smart contracts are analyzed separately to obtain the control dependency edge set and the data dependency edge set;

[0063] The control dependency edge set and the data dependency edge set are weighted by dependency strength respectively to obtain the control dependency adjacency matrix and the data dependency adjacency matrix; the control dependency adjacency matrix and the data dependency adjacency matrix are merged to obtain the unified execution semantic adjacency matrix;

[0064] A contract execution dependency graph is constructed based on the node attribute matrix, the control dependency edge set, the data dependency edge set, and the unified execution semantic adjacency matrix.

[0065] In one embodiment, when the dual-channel contract semantic encoding module utilizes the dual-channel contract semantic encoding mechanism to mine the mixed-granularity execution trajectory encoding of the contract...

[0066] Based on the contract execution dependency graph, the global channel contract semantic analysis method is used to extract cross-functional dependency features of control flow;

[0067] Based on the contract execution dependency graph, the local channel contract semantic analysis method is used to extract data flow state transition features;

[0068] Based on the cross-functional dependency features of control flow and the state transition features of data flow, a hybrid granularity feature fusioner is used to extract multi-scale dependency features from coarse-grained semantics to fine-grained behavior; and based on the multi-scale dependency features, the hierarchical alignment and dynamic aggregation of smart contract execution semantics are performed to generate a hybrid granularity execution trajectory code for the contract.

[0069] In one embodiment, when the dual-channel contract semantic encoding module extracts control flow cross-functional dependency features based on the contract execution dependency graph and using a global channel contract semantic analysis method,

[0070] For the contract execution dependency graph, extract the control path set along the control flow dependency edge set:

[0071] For any path in the control path set, construct its global semantic input sequence, unify paths of different lengths to a fixed length, and introduce a masking mechanism to obtain the normalized global semantic input sequence.

[0072] Based on multi-head self-attention mechanism, layer normalization and feedforward network, path-level long-range dependency modeling is performed on the normalized global semantic input sequence to output global path dependency features; and average pooling is used to pool the global path dependency features to obtain the feature vector of a single path.

[0073] Based on the obtained compact feature vector of a single path, the feature vector of multiple paths is differentially weighted using path importance weights; and layer graph attention propagation is performed based on the control adjacency relationship to inject graph-level global context features. The weighted multi-path feature vector and global context features are deeply integrated through residual fusion to obtain the graph-level aggregated control features after residual fusion.

[0074] By transforming the aggregated features through nonlinear mapping, the control flow cross-functional dependency features of the global channel are obtained.

[0075] In one embodiment, when the dual-channel contract semantic encoding module extracts data flow state transition features based on the contract execution dependency graph and using a local channel contract semantic analysis method,

[0076] For the contract execution dependency graph, extract the data flow path set along the data flow dependency edge set;

[0077] For any path in the data flow path set, construct its local time-series input sequence, unify paths of different time scales to a fixed time scale, and introduce a masking mechanism to obtain the normalized local time-series input sequence.

[0078] Based on gated recurrent units, the Sigmoid activation function, and the Hadamard product, a temporal model of data flow state transitions is performed on the normalized local temporal input sequence, outputting local data flow state transition dependency features.

[0079] One-dimensional dilated convolutional layers are used to enhance the local data flow state transition dependency features. The feature distribution is stabilized by layer normalization to obtain convolutional enhanced features. The convolutional enhanced features are then integrated with the original temporal features by residual fusion to obtain path temporal state residual fusion features.

[0080] Based on the obtained path temporal state residual fusion features, a multi-head temporal attention mechanism is used to aggregate key data migration segments to obtain key migration segment aggregation vectors; and the aggregation vectors of multiple data flow paths are differentially weighted by path importance weights to obtain multi-path robust aggregation features.

[0081] By transforming the multi-path robust aggregation features through nonlinear mapping, the data flow state transition features of local channels are obtained.

[0082] In one embodiment, the dual-channel contract semantic encoding module, based on control flow cross-functional dependency features and data flow state transition features, utilizes a hybrid granularity feature fusion processor to extract multi-scale dependency features from coarse-grained semantics to fine-grained behavior; and generates a hybrid granularity execution trajectory code for the contract by performing hierarchical alignment and dynamic aggregation processing of smart contract execution semantics based on these multi-scale dependency features.

[0083] For control flow cross-functional dependency features and data flow state, channel alignment and projection onto a common semantic space are performed using linear mapping matrix and bias matrix to obtain aligned control flow cross-functional dependency features and data flow state transition features.

[0084] The aligned control flow cross-functional dependency features and data flow state transition features are subjected to nonlinear transformation based on k scale transformers to obtain a multi-scale feature set from coarse-grained semantics to fine-grained behavior.

[0085] For a multi-scale feature set, the importance weight of each scale is calculated through the attention parameter, and based on the importance weight, the semantic association between features at different scales is modeled based on the self-attention mechanism to obtain multi-scale attention aggregated features;

[0086] For multi-scale attention aggregation features, the gating weight parameters and the Sigmoid activation function are used to generate dimension-wise gating coefficients. The Hadamard product is then used for element-wise filtering to enhance the complementarity between control flow features and data flow features, thus obtaining channel-gated fusion results.

[0087] The gated fusion result is superimposed with the aligned original features by residual superposition, and combined with the layer normalization to stabilize the feature distribution, a nonlinear expression is introduced through the GELU activation function to generate a contract hybrid granularity execution trajectory code.

[0088] In one embodiment, the variational autoencoder-enhanced remodeling, based on contract-mixed granularity execution trajectory encoding, utilizes a variational autoencoder-enhanced execution trajectory reconstruction model to perform self-supervised reconstruction learning on non-vulnerability execution samples to obtain latent semantic distribution features.

[0089] Trajectory encoding is performed on the mixed granularity of the contract, and parameterized modeling is performed using the encoder of the variational autoencoder to output the mean vector and variance vector of the posterior distribution.

[0090] Based on the mean vector and variance vector, differentiable sampling is performed using reparameterization to obtain latent variables of the implicit semantics of the contract execution trajectory;

[0091] Using latent variables as input, the distribution is modeled and reconstructed through the decoder of a variational autoencoder, generating a trajectory reconstruction vector with the same dimension as the original input.

[0092] Trajectory encoding is performed at a mixed granularity based on trajectory reconstruction vector and original contract. Self-supervised optimization is performed by maximizing the lower bound of evidence, and the encoder and decoder parameters are iteratively updated to obtain the optimized variational autoencoder.

[0093] The non-vulnerability execution sample set is input into the optimized variational autoencoder for continuous iterative training. The parameters are fine-tuned through the latent space distribution constraint and reconstruction error minimization process, and the latent semantic distribution features of the normal execution trajectory of the smart contract are learned in the latent space.

[0094] In one embodiment, the reconstruction error vulnerability determination module, based on latent semantic distribution characteristics and utilizing a reconstruction error determination mechanism, evaluates the reconstruction error of the smart contract bytecode and execution trajectory input during the detection phase to determine whether the smart contract has potential security vulnerabilities.

[0095] For the smart contract bytecode input during the detection phase, a hybrid granularity execution trajectory code for the contract is generated through the contract bytecode execution semantic model and the dual-channel contract semantic encoding mechanism.

[0096] The mixed-granularity execution trajectory encoding is input into the variational autoencoder-enhanced execution trajectory reconstruction model to generate a trajectory reconstruction vector that conforms to the latent semantic distribution characteristics of normal execution trajectories.

[0097] The reconstruction error is obtained by calculating the reconstruction error by combining the original mixed-granularity execution trajectory encoding of the smart contract bytecode with the generated trajectory reconstruction vector;

[0098] The reconstruction error is compared with a predetermined threshold. If the reconstruction error is greater than the predetermined threshold, the smart contract is determined to have a potential security vulnerability.

[0099] The predetermined threshold is set based on the mean and standard deviation of the reconstruction error distribution data of non-vulnerable samples during the training phase, combined with preset hyperparameters.

[0100] The technical solutions provided by the embodiments of the present invention may include the following beneficial effects:

[0101] This invention proposes a contract bytecode execution semantic model to jointly model the control flow and data flow dependencies of smart contracts during execution, improving the structured expression capability and execution dependency modeling accuracy of smart contract execution semantics. Furthermore, it utilizes a proposed dual-channel contract semantic encoding mechanism to mine the hybrid-granularity execution trajectory encoding of smart contracts across both global control dependencies and local data migration dimensions, enhancing the completeness and multi-granularity expression capability of semantic feature extraction under complex execution paths. In addition, through a proposed variational autoencoder-enhanced execution trajectory reconstruction model, self-supervised reconstruction learning is performed on non-vulnerable execution samples. During the optimization process of potential spatial distribution constraints and minimizing reconstruction errors, the potential semantic distribution of normal smart contract execution trajectories is learned, achieving bytecode-level potential behavior learning and anomaly detection under unlabeled conditions. Finally, a designed reconstruction error judgment mechanism is used to evaluate the reconstruction error of the smart contract bytecode execution trajectory input during the detection phase, achieving accurate identification of potential security vulnerabilities. Therefore, this invention solves the problems of strong dependence on labeled vulnerability contract bytecode, single execution semantic modeling, and insufficient detection capability for unknown vulnerabilities in existing technologies, improving the accuracy, robustness, and generalization performance of blockchain smart contract bytecode-level security detection.

[0102] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit the invention. Attached Figure Description

[0103] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0104] Figure 1 This is a flowchart illustrating a bytecode-level security detection method for blockchain smart contracts according to an exemplary embodiment;

[0105] Figure 2 This is a structural block diagram illustrating a blockchain smart contract bytecode-level security detection system according to an exemplary embodiment;

[0106] Figure 3 This is a schematic diagram illustrating the principle of a blockchain smart contract bytecode-level security detection process based on variational autoencoder-enhanced dual-channel analysis, according to an exemplary embodiment.

[0107] Figure 4 This is a design diagram of a contract bytecode execution semantic model according to an exemplary embodiment;

[0108] Figure 5 This is a design diagram of a dual-channel contract semantic encoding mechanism according to an exemplary embodiment;

[0109] Figure 6 This is a design diagram of an execution trajectory reconstruction model enhanced by a variational autoencoder, illustrated according to an exemplary embodiment.

[0110] Figure 7 This is a schematic diagram of the structure of a computer device according to an exemplary embodiment. Detailed Implementation

[0111] Figure 1 An embodiment of a bytecode-level security detection method for blockchain smart contracts according to the present invention is shown.

[0112] In this optional embodiment, the blockchain smart contract bytecode-level security detection method includes:

[0113] Step S101: Based on the control flow and data flow dependencies of smart contracts during execution, construct a contract execution dependency graph using a pre-configured contract bytecode execution semantic model;

[0114] Step S102: Using the contract execution dependency graph as input, the dual-channel contract semantic encoding mechanism is used to mine the mixed-granularity execution trajectory encoding of the contract.

[0115] Step S103: Based on the contract hybrid granularity execution trajectory encoding, the execution trajectory reconstruction model enhanced by variational autoencoder is used to perform self-supervised reconstruction learning on non-vulnerability execution samples to obtain latent semantic distribution features;

[0116] Step S104: Based on the latent semantic distribution characteristics, the reconstruction error judgment mechanism is used to evaluate the reconstruction error of the smart contract bytecode and execution trajectory input in the detection stage, and to determine whether the smart contract has potential security vulnerabilities.

[0117] Figure 2 An embodiment of a blockchain smart contract bytecode-level security detection system according to the present invention is shown.

[0118] In this optional embodiment, the blockchain smart contract bytecode-level security detection method includes:

[0119] The Contract Bytecode Execution Semantics Module 201 is used to construct a contract execution dependency graph by utilizing a pre-configured contract bytecode execution semantic model to address the control flow and data flow dependencies of smart contracts during execution.

[0120] The dual-channel contract semantic encoding module 202 is used to take the contract execution dependency graph as input and use the dual-channel contract semantic encoding mechanism to mine the mixed-granularity execution trajectory encoding of the contract.

[0121] Variational autoencoder-enhanced remodeling 203 is used for contract-based hybrid granularity execution trajectory encoding. The execution trajectory reconstruction model enhanced by variational autoencoder is used to perform self-supervised reconstruction learning on non-vulnerability execution samples to obtain latent semantic distribution features.

[0122] The reconstruction error vulnerability determination module 204 is used to evaluate the reconstruction error of the smart contract bytecode and execution trajectory input in the detection stage based on the potential semantic distribution characteristics and the reconstruction error determination mechanism, and to determine whether the smart contract has potential security vulnerabilities.

[0123] In the above optional embodiments, such as Figure 4As shown, when constructing a contract execution dependency graph based on a pre-configured contract bytecode execution semantic model to address the control flow and data flow dependencies during smart contract execution, a node is created for each instruction in the smart contract bytecode instruction sequence, forming a node set. Runtime context attributes are extracted for each node in the node set to form a feature vector. Based on the feature vector, a node attribute matrix is ​​obtained. The control flow and data flow during smart contract execution are analyzed separately to obtain a control dependency edge set and a data dependency edge set. The control dependency edge set and the data dependency edge set are weighted by dependency strength to obtain a control dependency adjacency matrix and a data dependency adjacency matrix. The control dependency adjacency matrix and the data dependency adjacency matrix are then merged to obtain a unified execution semantic adjacency matrix. Based on the node attribute matrix, the control dependency edge set, the data dependency edge set, and the unified execution semantic adjacency matrix, a contract execution dependency graph is constructed.

[0124] Specifically, regarding the bytecode instruction sequence of smart contracts T represents the smart contract bytecode instruction sequence. The length of the node is used to create a node v for each instruction. i , forming a set of nodes And extract runtime context attributes for nodes to form feature vectors:

[0125]

[0126] In the formula, Represents node v i The contextual attributes constitute the feature vector; e(op(b) i )) indicates one-hot or embedded opcode; These represent stack, memory, and storage depth, respectively. Indicates the calling hierarchy, t i Indicates time or execution order marker;

[0127] This yields the node attribute matrix X:

[0128]

[0129] In the formula, The context attributes of node v1 constitute the feature vector. Represents node v T The contextual attributes constitute the feature vector;

[0130] The set of control-dependent edges is obtained through control flow analysis:

[0131]

[0132] In the formula, Represents the set of control dependency edges, whose elements (v i ,v j ) indicates from node v i to node v j There is a control dependency edge; C(v) i ,v j ) is a dependency decision function that determines dependency if and only if the dependency is determined from node v. i to node v j The value is 1 if a control dependency exists, and 0 otherwise; i and j represent the source node and target node in the node set, respectively. Index in; This indicates an indicator function, which evaluates to 1 if the condition within the brackets is true, and 0 otherwise. This represents a set of instructions with control transfer semantics (such as JUMP, JUMPI, CALL, DELEGATECALL, STATICCALL, etc.); op(b i ) represents the i-th bytecode b i The instruction; π(v i ) indicates that the node v i The index position of the target instruction in the sequence obtained from the parsing of the corresponding control transfer statement.

[0133] The set of data dependency edges is obtained through data flow analysis:

[0134]

[0135] In the formula, For a set of data-dependent edges, its elements (v i ,v j ) indicates from node v i to node v j There are data-dependent edges; D(v) i ,v j ) is a data dependency determination function, if and only if from node v i to node v j The value is 1 if there is a data dependency, and 0 otherwise. This indicates an indicator function; the function value is 1 if the condition within the brackets is true, and 0 otherwise. Def(v i ) represents node v i A set of definitions for variables / stacks / storage slots; Use(v j ) represents node v j The set of uses for variables / stack / slots;

[0136] To characterize dependency strength, the control dependency edge set and the data dependency edge set are weighted by dependency strength respectively, resulting in the control dependency adjacency matrix and the data dependency adjacency matrix:

[0137]

[0138] In the formula, A c To control the dependency adjacency matrix, A d For the data-dependent adjacency matrix, [·] ij w represents the element in the i-th row and j-th column of the matrix; c (v i ,v j ) represents node v i to v j The control depends on the weights, where (v i ,v j (belongs to the control dependency edge set) w d (v i ,v j ) represents node v i to v j Data dependency weights, where (v i ,v j (belongs to the data dependency edge set) λ c To control the adjustable coefficient of the dependency weights, λ d p is an adjustable coefficient for data dependency weights; ctrl (v i ,v j ) represents node v i to v j Control transfer confidence; Def(v i ) represents node v i A set of definitions for variables / stacks / storage slots; Use(v j ) represents node v j The set of uses for variables / stacks / storage slots; ε > 0 indicates a numerically stable term for data dependency weights;

[0139] By fusing the control dependency adjacency matrix and the data dependency adjacency matrix, a unified execution semantic adjacency matrix is ​​obtained:

[0140] A=αA c +(1-α)A d ,α∈[0,1],

[0141] In the formula, A is the unified execution semantic adjacency matrix; A c To control the dependency adjacency matrix, A d The data dependency adjacency matrix is ​​denoted by α, which is the fusion coefficient.

[0142] This leads to the construction of a contract execution dependency graph:

[0143]

[0144] In the formula, For contract execution dependency graph; For a set of nodes To control the set of dependent edges; X is the set of data-dependent edges; A is the node attribute matrix; A is the unified execution semantic adjacency matrix.

[0145] Contract execution dependency graph The initial embedding definition for the middle node is:

[0146]

[0147] In the formula, Represents node v i The initial embedding vector; Represents node v i The original feature vector; W emb ,b emb H represents the learnable parameters of the learning node embedding in a multilayer perceptron; (0) Representation diagram The initial node represents the matrix; superscript This indicates the matrix transpose.

[0148] In the above optional embodiments, such as Figure 5 As shown, when mining the hybrid granularity execution trajectory encoding of contracts using the dual-channel contract semantic encoding mechanism, based on the contract execution dependency graph, the global channel contract semantic analysis method is used to extract the cross-functional dependency features of the control flow; based on the contract execution dependency graph, the local channel contract semantic analysis method is used to extract the state transition features of the data flow; based on the cross-functional dependency features of the control flow and the state transition features of the data flow, a hybrid granularity feature fusion device is used to extract multi-scale dependency features from coarse-grained semantics to fine-grained behavior; and based on the multi-scale dependency features, the hierarchical alignment and dynamic aggregation processing of the smart contract execution semantics are performed to generate the hybrid granularity execution trajectory encoding of the contract.

[0149] Specifically, when extracting control flow cross-functional dependency features based on the contract execution dependency graph using the global channel contract semantic analysis method, for the contract execution dependency graph, a set of control paths is extracted along the set of control flow dependency edges: for any path in the set of control paths, its global semantic input sequence is constructed, paths of different lengths are unified to a fixed length, and a masking mechanism is introduced to obtain a normalized global semantic input sequence; based on a multi-head self-attention mechanism, layer normalization, and a feedforward network, path-level long-range dependency modeling is performed on the normalized global semantic input sequence to output global path dependency features; and average pooling is used to pool the global path dependency features to obtain the feature vector of a single path; based on the obtained compact feature vector of a single path, the feature vectors of multiple paths are differentially weighted using path importance weights; and layer graph attention propagation is performed based on control adjacency relationships to inject graph-level global context features; the weighted multi-path feature vectors are deeply integrated with the global context features through residual fusion to obtain graph-level aggregated control features after residual fusion; and the aggregated features are transformed through nonlinear mapping to obtain the control flow cross-functional dependency features of the global channel.

[0150] Specifically, regarding the contract execution dependency graph Along the control flow dependent edge set Extract the control path set:

[0151]

[0152] In the formula, Represents a set of control paths; Indicates that by node arrive Then proceed in order to The control path is composed of node indices i1, i2, ..., i l i l+1 ,...,i L This represents the node's dependency graph in contract execution. The index position in the path, where l represents the l-th path node; Represents a node With nodes There are control dependency edges between them. Let represent the set of control dependency edges, 1≤l<L represent the path length range constraint, and L represent the path length of the control path p;

[0153] For any control path Construct its global semantic input sequence:

[0154]

[0155] In the formula, This represents the global semantic input sequence of control path p at the l-th path node; Represents a node Attribute feature vectors; Indicates from node To the node The control edge embedding vector; This represents the context distance from the beginning of the path to the l-th path node; This represents the relative position code of the l-th path node in the path; L represents the path length controlling path p;

[0156] A path masking mechanism is introduced to normalize control paths of different lengths:

[0157]

[0158] In the formula, This represents the global semantic input sequence of control path p at the l-th path node; Indicates the path padding mask; This represents the global semantic input sequence of the control path p at the l-th path node before normalization; 0 represents a zero vector with dimension equal to 1. Same; T max This indicates the maximum unified control path length.

[0159] Furthermore, path-level long-range control dependency modeling is performed based on multi-head self-attention:

[0160]

[0161] In the formula, and These represent the global semantic input sequences of control path p at the l-th and τ-th path nodes, respectively; Let h be the query vector of the h-th attention head in the self-attention mechanism at the l-th path node of the control path p. These are the key and value vectors of the h-th attention head at the τ-th path node of control path p in the self-attention mechanism; Let represent the key vector of the h-th attention head at the ξ-th path node in the control path p in the self-attention mechanism. From 1 to T max The traversal variable, T max W represents the maximum unified control path length. q,h W k,h W v,h These are the learnable linear mapping matrices corresponding to the h-th attention head in the self-attention mechanism; d represents the attention weight of the l-th path node of control path p in the h-th attention head to the τ-th path node;h Let h be the feature dimension of the h-th attention head; Let be the long-range dependency aggregation vector of the l-th path node of the control path p in the h-th attention head; W represents the global path dependency feature of control path p at the l-th path node; o b o Let represent the linear mapping matrix and bias vector of the feedforward network, respectively; This indicates that all attention heads are concatenated into vectors, and H represents the number of attention heads in the multi-head self-attention; LN(·) represents the path-level long-range dependent intermediate features after residual connections; LN(·) represents a layer-normalized neural network; FFN(·) represents a feedforward neural network. This represents the path-level long-range dependency feature of control path p at the l-th path node.

[0162] Furthermore, the path features are obtained by performing average pooling on the global path:

[0163]

[0164] In the formula, Pool(·) represents an average pooling neural network; The control path p represents the set of all path nodes {l|l∈[1,T]}. max The path-level long-range dependency feature set obtained from ]}; f p This represents the path characteristics of the control path p.

[0165] Furthermore, path importance weights are introduced for robust multi-control path aggregation:

[0166]

[0167] In the formula, ω p This represents the importance weight of the control path p; Represents the contract execution dependency graph The set of all control paths in the middle; f p This represents the path characteristics of the control path p; W g F represents the learnable parameter matrix in global attention; glob Represents the contract execution dependency graph Robust aggregation vector of all control paths in the process.

[0168] Furthermore, graph-level global context features are injected, based on the contract execution dependency graph. Controlling adjacency relationships for graph attention propagation and residual fusion:

[0169]

[0170] In the formula, Represents the contract execution dependency graph The output feature vector of node v in the control path during the attention propagation in the (l+1)th layer graph; σ(·) represents the Sigmoid activation function; W represents the set of neighboring nodes that have control flow dependencies on node v; (l) The learnable weight parameters for attention propagation in the l-th layer graph; Represents the contract execution dependency graph The output feature vectors of nodes u, k, and v in the control path during the attention propagation in the l-th layer graph; This represents the attention weight of node v to node u in the attention propagation of the l-th layer graph; The temperature parameter represents the graph attention propagation; Readout(·) represents the graph-level convergence operator; L represents the depth of the graph attention neural network; Representation diagram The set of nodes; g represents the contract execution dependency graph. Graph-level aggregation control features.

[0171] The final control flow state analysis results for the global channel are as follows:

[0172] F g =φ(W m [F glob ||g]+b m ),

[0173] In the formula, φ(·) represents the GELU activation function; F glob Dependency graph for contract execution Robust aggregation vector of all control paths in the graph; [·‖·] denotes vector concatenation operation; g represents the contract execution dependency graph. Graph-level aggregation control features; W m b is the weight matrix of a fully connected neural network. m F is the bias vector of the fully connected neural network; g This indicates the cross-functional dependency characteristics of control flow.

[0174] Specifically, when extracting data flow state transition features based on the contract execution dependency graph and using local channel contract semantic analysis, a set of data paths is extracted along the data flow dependency edges of the contract execution dependency graph. For any path in the data path set, its local temporal input sequence is constructed, unifying paths at different time scales to a fixed time scale, and introducing a masking mechanism to obtain a normalized local temporal input sequence. Based on gated recurrent units, the Sigmoid activation function, and the Hadamard product, data flow state transition temporal modeling is performed on the normalized local temporal input sequence, outputting local data flow state transition dependency features, and utilizing one-dimensional dilated convolutions. The convolutional layer enhances the local data flow state transition dependency features by stabilizing the feature distribution through layer normalization to obtain convolutional enhanced features. Then, the convolutional enhanced features are integrated with the original temporal features using residual fusion to obtain path temporal state residual fusion features. Based on these residual fusion features, a multi-head temporal attention mechanism is used to aggregate key data transition segments, resulting in key transition segment aggregation vectors. Furthermore, the aggregation vectors of multiple data flow paths are differentially weighted using path importance weights to obtain multi-path robust aggregation features. Finally, a nonlinear mapping is used to transform the multi-path robust aggregation features to obtain the local channel data flow state transition features.

[0175] Specifically, regarding the contract execution dependency graph Set of data flow dependent edges Data path set to be extracted:

[0176]

[0177] In the formula, Represents a set of data paths; Indicates that by node arrive Then proceed in order to The data path consists of nodes i1, i2, ..., i l i l+1 ,...,i L This represents the node's dependency graph in contract execution. The index position in the path, where l represents the l-th path node; Represents a node With nodes There are data dependency edges between them. Represents the set of data-dependent edges. This indicates a range constraint for path length. Indicates the path length of data path p;

[0178] For any data path p, construct its local time-series input sequence:

[0179]

[0180] In the formula, This represents the local time-series input sequence of the path node corresponding to data path p at time l; Represents a node Attribute feature vectors; Indicates from node To the node Data edge embedding vector; This represents the relative position code of the l-th path node in the path; Indicates the time scale of data path p;

[0181] A path masking mechanism is introduced to normalize data paths at different time scales:

[0182]

[0183] In the formula, This represents the local time-series input sequence of the path node corresponding to data path p at time l; Indicates the path padding mask; This represents the local temporal input sequence of the path node corresponding to the data path p at time l before normalization; 0 represents a vector of all zeros, with dimension equal to 1 / l. same; This represents the largest uniform time scale.

[0184] Timing modeling of local data stream state transitions based on gated loop units:

[0185]

[0186] In the formula, The output of the update gate at time l for data path p; σ(·) represents the Sigmoid activation function; W z U z ,b z These are the input transformation matrix of the update gate, the hidden state transformation matrix, and the bias vector, respectively. W is the output of the reset gate at time l of data path p; r U r ,b r These are the input transformation matrix of the reset gate, the hidden state transformation matrix, and the bias vector, respectively. Output the candidate hidden gate results for data path p at time l; W h U h ,b h These are the input transformation matrix, hidden state transformation matrix, and bias vector of the candidate hidden gate, respectively. Let be the local data flow state transition dependency of data path p at time l; ⊙ represents the Hadamard product.

[0187] To enhance the local receptive field, a one-dimensional dilated convolution is introduced and residual fusion is performed with the output of the gated recurrent unit:

[0188]

[0189] In the formula, This represents the convolutional enhancement feature at time l of data path p; This represents the local temporal input sequence of the path node corresponding to data path p at time l-δ; Denotes the set of shift indices of the convolution kernel, where δ belongs to The traversal variable of a set; W δ LN(·) represents the learnable weight matrix of the convolution kernel at shift δ; LN(·) is a layer-normalized neural network. For the local data flow state transition dependency of data path p at time l; The path temporal state residual fusion feature of data path p at time l;

[0190] Furthermore, multi-head temporal attention is applied to the path-sequence hidden states to aggregate key transition fragments:

[0191]

[0192] In the formula, Let p be the time attention query vector at time l of data path p. These are the time attention key and value vectors at time τ of data path p, respectively; This represents the time attention key vector at time ξ of data path p. From 1 to The traversal variable, W represents the largest unified time scale; q W k W v These are the linear projection matrices of the query, key, and value vectors, respectively, in the time attention process; These are the path temporal state residual fusion features of data path p at time l and time τ, respectively; Let d be the temporal attention weight for data path p from time l to time τ; a For time-based attention head feature dimensions; This represents the temporal attention aggregation representation of data path p at time l; Pool(·) is the average attention pooling neural network; This indicates that vectors are concatenated over all time steps; This represents the aggregate vector of key migration segments.

[0193] Furthermore, to robustly aggregate the features of multiple local data flow paths, a data path importance weight is introduced:

[0194]

[0195] In the formula, This indicates the importance weight of data path p; Represents the contract execution dependency graph The set of all data paths in the middle; Represents the aggregate vector of key migration segments; W a These represent the weights of the attention learnable parameters.

[0196] The final data flow state analysis result F of the local channel is obtained. loc :

[0197]

[0198] In the formula, This indicates the importance weight of data path p; Represents the aggregate vector of key migration segments; Represents the contract execution dependency graph The set of all data paths in F; loc Represents the global analysis characteristics of the data flow state of a local channel; φ(·) represents the GELU activation function; W o b o For the weight parameters of the feedforward neural network; F d This refers to the state transition characteristics of the data stream.

[0199] Specifically, based on control flow cross-functional dependency features and data flow state transition features, a hybrid granularity feature fusion machine is used to extract multi-scale dependency features from coarse-grained semantics to fine-grained behavior. When generating hybrid-granularity execution trajectory encoding for smart contract execution semantics based on hierarchical alignment and dynamic aggregation of these multi-scale dependency features, the control flow cross-functional dependency features and data flow state are channel-aligned and projected onto a common semantic space using linear mapping matrices and bias matrices to obtain aligned control flow cross-functional dependency features and data flow state transition features. Finally, the aligned control flow cross-functional dependency features and data flow state transition features are nonlinearly transformed based on k scale transformers to obtain the transition from coarse-grained semantics to fine-grained behavior. The system is a multi-scale feature set. For the multi-scale feature set, the importance weight of each scale is calculated through the attention parameter. Based on the importance weight, the semantic relationship between features at different scales is modeled based on the self-attention mechanism to obtain multi-scale attention aggregated features. For the multi-scale attention aggregated features, the system generates dimension-wise gating coefficients through the gating weight parameter and the Sigmoid activation function. The system uses the Hadamard product to perform element-wise filtering to enhance the complementarity between control flow features and data flow features, and obtains the channel-gated fusion result. The gated fusion result is superimposed with the aligned original features by residual superposition. Combined with the layer normalization to stabilize the feature distribution, the system introduces a nonlinear expression through the GELU activation function to generate a contract hybrid granularity execution trajectory code.

[0200] Specifically, for the control flow across the functional dependency feature F of the global channel output... g The state transition feature F of the data stream output from the local channel d First, channel alignment and projection to a common semantic space are performed:

[0201]

[0202] In the formula, W g W d Let b be the linear mapping matrix of the fully connected neural network. g ,b d Let be the bias matrix of the fully connected neural network. The aligned control flow features across functional dependencies and data flow state transition features.

[0203] To characterize multi-scale dependencies ranging from coarse-grained semantics to fine-grained behavior, K scale transformers are introduced:

[0204]

[0205] In the formula, W represents the nonlinear transformation characteristic at the k-th scale. k Let φ be the nonlinear mapping matrix of the multilayer perceptron at the k-th scale. k(·) represents the GELU activation function at the k-th scale, b k Let K be the bias matrix of the multilayer perceptron at the k-th scale; [·‖·] denotes the vector concatenation operation; K represents the number of multi-scale branches; This indicates that a multi-scale feature set has been obtained.

[0206] Furthermore, attention selection is applied to multi-scale features to achieve scale-adaptive weighting:

[0207]

[0208] In the formula, s k This represents the attention score at the k-th scale; s r This represents the attention score at the r-th scale. The traversal variables are from 1 to K, where K represents the number of multi-scale branches; Represents the learnable attention query vector; U represents the learnable attention mechanism linear transformation matrix; This represents the nonlinear transformation characteristics at the k-th scale; Represents the attention weights at multiple scales, α k Let represent the attention weight at the k-th scale.

[0209] Furthermore, a multi-scale representation of attention aggregation is obtained based on the self-attention mechanism:

[0210]

[0211] In the formula, f ms Represents multi-scale attention aggregation features; K represents the number of multi-scale branches; α k This represents the attention weight at the k-th scale; This represents the nonlinear transformation characteristics at the k-th scale.

[0212] Furthermore, to enhance the complementarity between channels, gating fusion from global to local is introduced:

[0213]

[0214] In the formula, σ(·) is the Sigmoid activation function; W r b represents the weight matrix parameters of the gated recurrent unit. r These are the bias matrix parameters for the gated loop unit; The aligned control flow features across functional dependencies and data flow state transition features; r is the gating coefficient vector of the dual-channel fusion; [·‖·] represents the vector concatenation operation; ⊙ is the Hadamard multiplication; f gl This is the result of channel gating fusion.

[0215] Furthermore, residual normalization is performed:

[0216]

[0217] In the formula, The intermediate features are the residuals after stacking and layer normalization; f gl For channel-gated fusion results; f ms Multi-scale attention aggregation features; LN(·) is a layer normalized neural network; φ(·) is the GELU activation function; W o Let b be the linear mapping matrix of the fully connected neural network. o is the bias matrix of the fully connected neural network; [·‖·‖·] represents the sequential concatenation operation of multiple vectors; Z is the mixed-granularity execution trajectory encoding.

[0218] In the above optional embodiments, such as Figure 6 As shown, in the process of encoding execution trajectories at a mixed granularity based on contracts and using a variational autoencoder-enhanced execution trajectory reconstruction model to perform self-supervised reconstruction learning on non-vulnerable execution samples to obtain latent semantic distribution features, the encoding of execution trajectories at a mixed granularity based on contracts utilizes the encoder of the variational autoencoder for parameterized modeling, outputting the mean vector and variance vector of the posterior distribution. Based on the mean vector and variance vector, differentiable sampling is performed using reparameterization to obtain latent variables of the latent semantics of the contract execution trajectory. Using the latent variables as input, the distribution is reconstructed through the decoder of the variational autoencoder, generating a trajectory reconstruction vector with the same dimension as the original input. Based on the trajectory reconstruction vector and the original mixed granularity execution trajectory encoding of contracts, self-supervised optimization is performed by maximizing the lower bound of evidence, iteratively updating the encoder and decoder parameters to obtain the optimized variational autoencoder. The non-vulnerable execution sample set is input into the optimized variational autoencoder for continuous iterative training, and the parameters are fine-tuned through the latent space distribution constraint and reconstruction error minimization process to learn the latent semantic distribution features of the normal execution trajectory of the smart contract in the latent space.

[0219] Specifically, for the mixed-granularity execution trajectory encoding Z, the latent semantic distribution of non-vulnerable execution samples is learned through a variational autoencoder structure. The encoder models the posterior distribution q with the encoding parameters φ. φ (z∣Z):

[0220]

[0221] In the formula, the encoding parameter φ represents the complete set of learnable parameters of the encoder neural network; Z represents the mixed-granularity execution trajectory encoding; μ φ (Z) represents the latent mean vector obtained by the encoder from performing trajectory encoding Z according to the mixed granularity; This represents the latent variance vector obtained by the encoder from trajectory encoding Z based on mixed granularity; diag(·) represents taking the diagonal covariance matrix of the vector; q represents a multidimensional Gaussian distribution; φ (z|Z) represents the approximate posterior distribution of the latent variable z after a given mixed granularity execution trajectory encoding Z;

[0222] Differentiable sampling is achieved through reparameterization:

[0223]

[0224] In the formula, z is a reparameterizable latent variable, representing the implicit semantic representation of the contract execution trajectory; μ φ (Z) represents the latent mean vector obtained by the encoder performing trajectory encoding Z according to the mixed granularity; σ φ (Z) represents the latent standard deviation vector obtained by the encoder from trajectory encoding Z based on mixed granularity; ⊙ is the Hadamard multiplication; ∈ is a random noise vector. Indicates a standard Gaussian distribution;

[0225] Furthermore, the decoder models and reconstructs the distribution p using the decoding parameters θ. θ (Z∣z):

[0226]

[0227] In the formula, the decoding parameter θ represents the complete set of learnable parameters of the decoder neural network; μ θ (z) represents the reconstructed mean vector obtained by the decoder based on the latent variable z; The variance constant of the Gaussian distribution reconstructed by the decoder is represented by I; p represents the identity matrix. θ (Z|z) represents the conditional generation probability distribution of the mixed-granularity execution trajectory encoding Z given the latent variable z;

[0228] Furthermore, the decoder generates a trajectory reconstruction vector:

[0229] Z = μ θ (z).

[0230] In the formula, Z represents the trajectory reconstruction vector generated by the decoder.

[0231] The model performs self-supervised optimization by maximizing the lower bound of evidence:

[0232]

[0233] In the formula, This represents the self-supervised optimization objective of the variational autoencoder; Represents the probability distribution q φ (z|Z) is expected; qφ (z|Z) represents the approximate posterior distribution of the latent variable z after performing trajectory encoding Z given the original mixed granularity; The reconstruction error is measured by Z, where Z is the original mixed-granularity trajectory encoding and Z is the trajectory reconstruction vector generated by the decoder. Let represent the squared L2 norm of the vector; β represent the regularization balance coefficient of the variational autoencoder; and p(z) represent the prior distribution of the latent variable z. In the implementation of this invention... represents the standard Gaussian distribution; KL(·‖·) represents the standard KL divergence between two probability distributions.

[0234] Through non-vulnerability sample sets To minimize the aforementioned loss, the model models the semantic distribution of normal execution trajectories in the latent space. After training, the encoder q... φ Decoder p is used to extract latent semantic features z. θ This is used to generate the reconstructed trajectory Z, thereby enabling the latent semantic learning and reconstruction of the normal execution trajectory of the smart contract, and providing a distribution constraint basis for the subsequent reconstruction error determination mechanism.

[0235] In the above optional embodiments, based on the latent semantic distribution characteristics, a reconstruction error judgment mechanism is used to evaluate the reconstruction error of the execution trajectory of the smart contract bytecode input during the detection phase. When determining whether the smart contract has potential security vulnerabilities, the smart contract bytecode input during the detection phase is used to generate a hybrid granularity execution trajectory code of the contract through a contract bytecode execution semantic model and a dual-channel contract semantic encoding mechanism. This hybrid granularity execution trajectory code is input into an execution trajectory reconstruction model enhanced by a variational autoencoder to generate a trajectory reconstruction vector that conforms to the latent semantic distribution characteristics of normal execution trajectories. The original hybrid granularity execution trajectory code of the smart contract bytecode and the generated trajectory reconstruction vector are used to calculate the reconstruction error to obtain the reconstruction error. The reconstruction error is compared with a predetermined threshold. If the reconstruction error is greater than the predetermined threshold, the smart contract is determined to have potential security vulnerabilities. The predetermined threshold is set based on the mean and standard deviation of the reconstruction error distribution data of non-vulnerability samples during the training phase, combined with preset hyperparameters.

[0236] Specifically, after the variational autoencoder-enhanced execution trajectory reconstruction model is trained, the encoder and decoder are used to encode the mixed-granularity execution trajectory Z of the input contract. test The reconstruction was performed, and the reconstruction result Z was obtained. test :

[0237] Z test =μ θ (μ φ (Z test )),

[0238] In the formula, μ φ (·) indicates that the encoder obtains the latent mean vector of the input with encoding parameters φ; μ θ (·) indicates that the decoder obtains the reconstructed mean vector of the input using the decoding parameters θ; Z test This indicates the result of the execution trajectory reconstruction.

[0239] Furthermore, the reconstruction error of the execution trajectory is calculated:

[0240]

[0241] In the formula, S(Z) represents the squared L2 norm of a vector; test ) represents the reconstruction error of the execution trajectory.

[0242] To measure the deviation between the input trajectory and the normal trajectory semantic distribution learned by the variational autoencoder-enhanced execution trajectory reconstruction model, a multidimensional normalized distance is further introduced to enhance detection robustness.

[0243]

[0244] In the formula, S′(Z test Z represents the mixed-granularity execution trajectory encoding of the input contract. test Multidimensional normalized reconstruction error; d z Z is the mixed-granularity execution trajectory encoding for the input contract. test The vector dimension of Z; test,i Z is the mixed-granularity execution trajectory encoding for the input contract. test The value of Z in the i-th dimension vector; test,i For the trajectory reconstruction result Z test The value of σ in the i-th dimension vector; S,i σ represents the standard deviation of the reconstruction error distribution of non-vulnerable samples during the training phase. S The value taken on the i-th dimension vector; ∈ is a small constant to prevent the denominator from being zero.

[0245] Furthermore, based on the reconstruction error distribution of non-vulnerable samples during the training phase, its mean μ is calculated. S With standard deviation σ S Set the vulnerability detection threshold τ:

[0246] τ=μ S +κσ S ,

[0247] In the formula, κ>0 is a hyperparameter used to control the detection sensitivity; μ S , σ S These are the mean and standard deviation of the reconstruction error distribution of non-vulnerable samples during the training phase, respectively.

[0248] When the reconstruction error of the test sample satisfies:

[0249]

[0250] In the formula, Vuln(Z) test S′(Z) = 1 indicates that a potential contract vulnerability has been detected; τ is the vulnerability detection threshold; ... test Z represents the mixed-granularity execution trajectory encoding of the input contract. test Multidimensional normalized reconstruction error.

[0251] Figure 7 An embodiment of a computer device according to the present invention is shown. The computer device may be a server, and includes a processor, memory, and a network interface connected via a system bus. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database of the computer device stores static and dynamic information data. The network interface of the computer device is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it implements the steps in the above-described method embodiment.

[0252] Those skilled in the art will understand that Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present invention and does not constitute a limitation on the computer device to which the present invention is applied. A specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0253] In addition, the present invention also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.

[0254] In addition, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in the above method embodiments.

Claims

1. A bytecode-level security detection method for blockchain smart contracts, characterized in that, include: To address the control flow and data flow dependencies of smart contracts during execution, a contract execution dependency graph is constructed using a pre-configured contract bytecode execution semantic model. Using the contract execution dependency graph as input, a dual-channel contract semantic encoding mechanism is used to mine the mixed-granularity execution trajectory encoding of the contract. Based on contract hybrid granularity execution trajectory encoding, an execution trajectory reconstruction model enhanced by variational autoencoder is used to perform self-supervised reconstruction learning on non-vulnerability execution samples to obtain latent semantic distribution features; Based on the latent semantic distribution characteristics, a reconstruction error judgment mechanism is used to evaluate the reconstruction error of the smart contract bytecode and execution trajectory input during the detection phase, and to determine whether the smart contract has potential security vulnerabilities.

2. The blockchain smart contract bytecode-level security detection method according to claim 1, characterized in that, To address the control flow and data flow dependencies during smart contract execution, a contract execution dependency graph is constructed using a pre-configured contract bytecode execution semantic model, including: For each bytecode instruction sequence of a smart contract, a node is created to form a node set; Extract runtime context attributes from the nodes in the node set to form feature vectors; based on the feature vectors, obtain the node attribute matrix: The control flow and data flow during the execution of smart contracts are analyzed separately to obtain the control dependency edge set and the data dependency edge set; The control dependency edge set and the data dependency edge set are weighted by dependency strength respectively to obtain the control dependency adjacency matrix and the data dependency adjacency matrix; the control dependency adjacency matrix and the data dependency adjacency matrix are merged to obtain the unified execution semantic adjacency matrix; A contract execution dependency graph is constructed based on the node attribute matrix, the control dependency edge set, the data dependency edge set, and the unified execution semantic adjacency matrix.

3. The blockchain smart contract bytecode-level security detection method according to claim 1, characterized in that, Mining mixed-granularity execution trajectory encoding of contracts using a dual-channel contract semantic encoding mechanism includes: Based on the contract execution dependency graph, the global channel contract semantic analysis method is used to extract cross-functional dependency features of control flow; Based on the contract execution dependency graph, the data flow state transition features are extracted using the local channel contract semantic analysis method. Based on the cross-functional dependency features of control flow and the state transition features of data flow, a hybrid granularity feature fusioner is used to extract multi-scale dependency features from coarse-grained semantics to fine-grained behavior; and based on the multi-scale dependency features, the hierarchical alignment and dynamic aggregation of smart contract execution semantics are performed to generate a hybrid granularity execution trajectory code for the contract.

4. The blockchain smart contract bytecode-level security detection method according to claim 3, characterized in that, Based on the contract execution dependency graph, the global channel contract semantic analysis method is used to extract control flow cross-functional dependency features, including: For the contract execution dependency graph, extract the control path set along the control flow dependency edge set: For any path in the control path set, construct its global semantic input sequence, unify paths of different lengths to a fixed length, and introduce a masking mechanism to obtain the normalized global semantic input sequence. Based on multi-head self-attention mechanism, layer normalization and feedforward network, path-level long-range dependency modeling is performed on the normalized global semantic input sequence to output global path dependency features; and average pooling is used to pool the global path dependency features to obtain the feature vector of a single path. Based on the obtained compact feature vector of a single path, the feature vector of multiple paths is differentially weighted using path importance weights; and layer graph attention propagation is performed based on the control adjacency relationship to inject graph-level global context features. The weighted multi-path feature vector and global context features are deeply integrated through residual fusion to obtain the graph-level aggregated control features after residual fusion. By transforming the aggregated features through nonlinear mapping, the control flow cross-functional dependency features of the global channel are obtained.

5. The blockchain smart contract bytecode-level security detection method according to claim 3, characterized in that, Based on the contract execution dependency graph, the data flow state transition features extracted using the local channel contract semantic analysis method include: For the contract execution dependency graph, extract the data flow path set along the data flow dependency edge set; For any path in the data flow path set, construct its local time-series input sequence, unify paths of different time scales to a fixed time scale, and introduce a masking mechanism to obtain the normalized local time-series input sequence. Based on gated recurrent units, the Sigmoid activation function, and the Hadamard product, a temporal model of data flow state transitions is performed on the normalized local temporal input sequence, outputting local data flow state transition dependency features. One-dimensional dilated convolutional layers are used to enhance the local data flow state transition dependency features. The feature distribution is stabilized by layer normalization to obtain convolutional enhanced features. The convolutional enhanced features are then integrated with the original temporal features by residual fusion to obtain path temporal state residual fusion features. Based on the obtained path temporal state residual fusion features, a multi-head temporal attention mechanism is used to aggregate key data migration segments to obtain key migration segment aggregation vectors; and the aggregation vectors of multiple data flow paths are differentially weighted by path importance weights to obtain multi-path robust aggregation features. By transforming the multi-path robust aggregation features through nonlinear mapping, the data flow state transition features of local channels are obtained.

6. The blockchain smart contract bytecode-level security detection method according to claim 3, characterized in that, Based on control flow cross-functional dependency features and data flow state transition features, a hybrid granularity feature fusioner is used to extract multi-scale dependency features from coarse-grained semantics to fine-grained behavior. Furthermore, based on multi-scale dependency features, hierarchical alignment and dynamic aggregation processing of smart contract execution semantics are performed to generate hybrid-granularity execution trajectory encodings for contracts, including: For control flow cross-functional dependency features and data flow state, channel alignment and projection onto a common semantic space are performed using linear mapping matrix and bias matrix to obtain aligned control flow cross-functional dependency features and data flow state transition features. The aligned control flow cross-functional dependency features and data flow state transition features are subjected to nonlinear transformation based on k scale transformers to obtain a multi-scale feature set from coarse-grained semantics to fine-grained behavior. For a multi-scale feature set, the importance weight of each scale is calculated through the attention parameter, and based on the importance weight, the semantic association between features at different scales is modeled based on the self-attention mechanism to obtain multi-scale attention aggregated features; For multi-scale attention aggregation features, the gating weight parameters and the Sigmoid activation function are used to generate dimension-wise gating coefficients. The Hadamard product is then used for element-wise filtering to enhance the complementarity between control flow features and data flow features, thus obtaining channel-gated fusion results. The gated fusion result is superimposed with the aligned original features by residual superposition, and combined with the layer normalization to stabilize the feature distribution, a nonlinear expression is introduced through the GELU activation function to generate a contract hybrid granularity execution trajectory code.

7. The blockchain smart contract bytecode-level security detection method according to claim 1, characterized in that, Based on contract hybrid granularity execution trajectory encoding, and utilizing a variational autoencoder-enhanced execution trajectory reconstruction model, self-supervised reconstruction learning is performed on non-vulnerability execution samples to obtain latent semantic distribution features, including: Trajectory encoding is performed on the mixed granularity of the contract, and parameterized modeling is performed using the encoder of the variational autoencoder to output the mean vector and variance vector of the posterior distribution. Based on the mean vector and variance vector, differentiable sampling is performed using reparameterization to obtain latent variables of the implicit semantics of the contract execution trajectory; Using latent variables as input, the distribution is modeled and reconstructed through the decoder of a variational autoencoder, generating a trajectory reconstruction vector with the same dimension as the original input. Trajectory encoding is performed at a mixed granularity based on trajectory reconstruction vector and original contract. Self-supervised optimization is performed by maximizing the lower bound of evidence, and the encoder and decoder parameters are iteratively updated to obtain the optimized variational autoencoder. The non-vulnerability execution sample set is input into the optimized variational autoencoder for continuous iterative training. The parameters are fine-tuned through the latent space distribution constraint and reconstruction error minimization process, and the latent semantic distribution features of the normal execution trajectory of the smart contract are learned in the latent space.

8. The blockchain smart contract bytecode-level security detection method according to claim 1, characterized in that, Based on the latent semantic distribution characteristics, and utilizing a reconstruction error judgment mechanism, the reconstruction error of the smart contract bytecode and execution trajectory input during the detection phase is evaluated to determine whether the smart contract has potential security vulnerabilities, including: For the smart contract bytecode input during the detection phase, a hybrid granularity execution trajectory code for the contract is generated through the contract bytecode execution semantic model and the dual-channel contract semantic encoding mechanism. The mixed-granularity execution trajectory encoding is input into the variational autoencoder-enhanced execution trajectory reconstruction model to generate a trajectory reconstruction vector that conforms to the latent semantic distribution characteristics of normal execution trajectories. The reconstruction error is obtained by calculating the reconstruction error by combining the original mixed-granularity execution trajectory encoding of the smart contract bytecode with the generated trajectory reconstruction vector; The reconstruction error is compared with a predetermined threshold. If the reconstruction error is greater than the predetermined threshold, the smart contract is determined to have a potential security vulnerability. The predetermined threshold is set based on the mean and standard deviation of the reconstruction error distribution data of non-vulnerable samples during the training phase, combined with preset hyperparameters.

9. A bytecode-level security detection system for blockchain smart contracts, characterized in that, include: The Contract Bytecode Execution Semantics module is used to address the control flow and data flow dependencies of smart contracts during execution. It utilizes a pre-configured contract bytecode execution semantic model to construct a contract execution dependency graph. The dual-channel contract semantic encoding module is used to take the contract execution dependency graph as input and use the dual-channel contract semantic encoding mechanism to mine the mixed-granularity execution trajectory encoding of the contract. Variational autoencoders enhance remodeling for contract-based hybrid granularity execution trajectory encoding. The execution trajectory reconstruction model enhanced by variational autoencoders performs self-supervised reconstruction learning on non-vulnerability execution samples to obtain latent semantic distribution features. The reconstruction error vulnerability determination module is used to evaluate the reconstruction error of the smart contract bytecode and execution trajectory input during the detection phase based on the potential semantic distribution characteristics and the reconstruction error determination mechanism, so as to determine whether the smart contract has potential security vulnerabilities.

10. The blockchain smart contract bytecode-level security detection system according to claim 9, characterized in that, When the contract bytecode execution semantic module addresses the control flow and data flow dependencies during the execution of a smart contract, it constructs a contract execution dependency graph using a pre-configured contract bytecode execution semantic model. For each bytecode instruction sequence of a smart contract, a node is created to form a node set; Extract runtime context attributes from the nodes in the node set to form feature vectors; Based on the feature vectors, the node attribute matrix is ​​obtained: The control flow and data flow during the execution of smart contracts are analyzed separately to obtain the control dependency edge set and the data dependency edge set; The control dependency edge set and the data dependency edge set are weighted by dependency strength respectively to obtain the control dependency adjacency matrix and the data dependency adjacency matrix; the control dependency adjacency matrix and the data dependency adjacency matrix are merged to obtain the unified execution semantic adjacency matrix; A contract execution dependency graph is constructed based on the node attribute matrix, the control dependency edge set, the data dependency edge set, and the unified execution semantic adjacency matrix.

11. The blockchain smart contract bytecode-level security detection system according to claim 9, characterized in that, When the dual-channel contract semantic encoding module uses the dual-channel contract semantic encoding mechanism to mine the mixed-granularity execution trajectory encoding of the contract, Based on the contract execution dependency graph, the global channel contract semantic analysis method is used to extract cross-functional dependency features of control flow; Based on the contract execution dependency graph, the data flow state transition features are extracted using the local channel contract semantic analysis method. Based on control flow cross-functional dependency features and data flow state transition features, a hybrid granularity feature fusioner is used to extract multi-scale dependency features from coarse-grained semantics to fine-grained behavior. Furthermore, based on multi-scale dependency features, hierarchical alignment and dynamic aggregation processing of smart contract execution semantics are performed to generate mixed-granularity execution trajectory codes for contracts.

12. The blockchain smart contract bytecode-level security detection system according to claim 11, characterized in that, When the dual-channel contract semantic encoding module extracts cross-functional dependency features of control flow based on the contract execution dependency graph and using the global channel contract semantic analysis method, For the contract execution dependency graph, extract the control path set along the control flow dependency edge set: For any path in the control path set, construct its global semantic input sequence, unify paths of different lengths to a fixed length, and introduce a masking mechanism to obtain the normalized global semantic input sequence. Based on multi-head self-attention mechanism, layer normalization and feedforward network, path-level long-range dependency modeling is performed on the normalized global semantic input sequence to output global path dependency features. The average pooling method is used to pool and represent the global path dependency features to obtain the feature vector of a single path. Based on the obtained compact feature vector of a single path, the feature vector of multiple paths is differentially weighted using path importance weights; and layer graph attention propagation is performed based on the control adjacency relationship to inject graph-level global context features. The weighted multi-path feature vector and global context features are deeply integrated through residual fusion to obtain the graph-level aggregated control features after residual fusion. By transforming the aggregated features through nonlinear mapping, the control flow cross-functional dependency features of the global channel are obtained.

13. The blockchain smart contract bytecode-level security detection system according to claim 11, characterized in that, When the dual-channel contract semantic encoding module extracts data flow state transition features based on the contract execution dependency graph and using the local channel contract semantic analysis method, For the contract execution dependency graph, extract the data flow path set along the data flow dependency edge set; For any path in the data flow path set, construct its local time-series input sequence, unify paths of different time scales to a fixed time scale, and introduce a masking mechanism to obtain the normalized local time-series input sequence. Based on gated recurrent units, the Sigmoid activation function, and the Hadamard product, a temporal model of data flow state transitions is performed on the normalized local temporal input sequence, outputting local data flow state transition dependency features. One-dimensional dilated convolutional layers are used to enhance the local data flow state transition dependency features. The feature distribution is stabilized by layer normalization to obtain the convolutional enhanced features. Furthermore, the convolutional enhanced features are integrated with the original temporal features using the residual fusion method to obtain the path temporal state residual fusion features; Based on the obtained path temporal state residual fusion features, a multi-head temporal attention mechanism is used to aggregate key data migration segments to obtain key migration segment aggregation vectors; and the aggregation vectors of multiple data flow paths are differentially weighted by path importance weights to obtain multi-path robust aggregation features. By transforming the multi-path robust aggregation features through nonlinear mapping, the data flow state transition features of local channels are obtained.

14. The blockchain smart contract bytecode-level security detection system according to claim 11, characterized in that, The dual-channel contract semantic encoding module extracts multi-scale dependency features from coarse-grained semantics to fine-grained behavior based on control flow cross-functional dependency features and data flow state transition features using a hybrid granularity feature fusion device. Furthermore, based on multi-scale dependency features, hierarchical alignment and dynamic aggregation processing of smart contract execution semantics are performed to generate mixed-granularity execution trajectory encodings for contracts. For control flow cross-functional dependency features and data flow state, channel alignment and projection onto a common semantic space are performed using linear mapping matrix and bias matrix to obtain aligned control flow cross-functional dependency features and data flow state transition features. The aligned control flow cross-functional dependency features and data flow state transition features are subjected to nonlinear transformation based on k scale transformers to obtain a multi-scale feature set from coarse-grained semantics to fine-grained behavior. For a multi-scale feature set, the importance weight of each scale is calculated through the attention parameter, and based on the importance weight, the semantic association between features at different scales is modeled based on the self-attention mechanism to obtain multi-scale attention aggregated features; For multi-scale attention aggregation features, the gating weight parameters and the Sigmoid activation function are used to generate dimension-wise gating coefficients. The Hadamard product is then used for element-wise filtering to enhance the complementarity between control flow features and data flow features, thus obtaining channel-gated fusion results. The gated fusion result is superimposed with the aligned original features by residual superposition, and combined with the layer normalization to stabilize the feature distribution, a nonlinear expression is introduced through the GELU activation function to generate a contract hybrid granularity execution trajectory code.

15. The blockchain smart contract bytecode-level security detection system according to claim 9, characterized in that, The variational autoencoder-enhanced remodeling, based on contract hybrid granularity execution trajectory encoding, utilizes a variational autoencoder-enhanced execution trajectory reconstruction model to perform self-supervised reconstruction learning on non-vulnerability execution samples to obtain latent semantic distribution features. Trajectory encoding is performed on the mixed granularity of the contract, and parameterized modeling is performed using the encoder of the variational autoencoder to output the mean vector and variance vector of the posterior distribution. Based on the mean vector and variance vector, differentiable sampling is performed using reparameterization to obtain latent variables of the implicit semantics of the contract execution trajectory; Using latent variables as input, the distribution is modeled and reconstructed through the decoder of a variational autoencoder, generating a trajectory reconstruction vector with the same dimension as the original input. Trajectory encoding is performed at a mixed granularity based on trajectory reconstruction vector and original contract. Self-supervised optimization is performed by maximizing the lower bound of evidence, and the encoder and decoder parameters are iteratively updated to obtain the optimized variational autoencoder. The non-vulnerability execution sample set is input into the optimized variational autoencoder for continuous iterative training. The parameters are fine-tuned through the latent space distribution constraint and reconstruction error minimization process, and the latent semantic distribution features of the normal execution trajectory of the smart contract are learned in the latent space.

16. The blockchain smart contract bytecode-level security detection system according to claim 9, characterized in that, The reconstruction error vulnerability determination module, based on latent semantic distribution characteristics and utilizing a reconstruction error determination mechanism, evaluates the reconstruction error of the smart contract bytecode and execution trajectory input during the detection phase to determine whether the smart contract contains potential security vulnerabilities. For the smart contract bytecode input during the detection phase, a hybrid granularity execution trajectory code for the contract is generated through the contract bytecode execution semantic model and the dual-channel contract semantic encoding mechanism. The mixed-granularity execution trajectory encoding is input into the variational autoencoder-enhanced execution trajectory reconstruction model to generate a trajectory reconstruction vector that conforms to the latent semantic distribution characteristics of normal execution trajectories. The reconstruction error is obtained by calculating the reconstruction error by combining the original mixed-granularity execution trajectory encoding of the smart contract bytecode with the generated trajectory reconstruction vector; The reconstruction error is compared with a predetermined threshold. If the reconstruction error is greater than the predetermined threshold, the smart contract is determined to have a potential security vulnerability. The predetermined threshold is set based on the mean and standard deviation of the reconstruction error distribution data of non-vulnerable samples during the training phase, combined with preset hyperparameters.