A method and system for monitoring temporal properties of smart contracts based on dynamic instrumentation
By designing a dynamic instrumentation method for monitoring Temporal Properties of smart contracts at the Ethereum Virtual Machine level, the problem of detecting uninitialized resource reading vulnerabilities in smart contracts is solved, achieving efficient and accurate security detection and monitoring, and improving the reliability and security of contracts.
Patent Information
- Application Number
- CN202411302020.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-18
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2044-09-18
AI Technical Summary
Existing technologies are insufficient to effectively detect and monitor vulnerabilities in reading uninitialized global resources in smart contracts, especially in complex cross-contract call scenarios, resulting in false positives and false negatives, and lacking flexible and efficient runtime monitoring tools.
Design a smart contract temporal property monitoring method based on dynamic instrumentation. By implementing the Vector Clock mechanism and resource status tracking at the Ethereum Virtual Machine level, and combining SHA3 instruction caching and Slot reverse analysis system, it supports multi-layer mapping tracing and dynamic variable monitoring, providing efficient and accurate security detection.
It enables efficient and accurate monitoring of complex smart contracts, significantly reduces false positives and false negatives, supports real-time monitoring of complex data structures, and improves the reliability and security of contracts.
Smart Images

Figure CN119293793B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular to a smart contract TemporalProperty monitoring method and system based on dynamic instrumentation. Background Art
[0002] Smart contracts are a core component of blockchain technology. Uninitialized global resource access is a common and serious security vulnerability that can lead to erratic contract behavior, asset loss, and other serious consequences. This vulnerability typically occurs in the following situations: 1. Contract developers forget to initialize certain global variables. 2. Initialization of certain resources is omitted during complex contract interactions. 3. When making cross-contract calls, incorrect assumptions about the state of other contracts are made.
[0003] Conventional solutions to the above problems include: 1. Using static analysis methods to detect potential vulnerabilities in smart contracts. However, this approach struggles with complex runtime scenarios, especially those involving cross-contract calls. It can produce numerous false positives and false negatives, requiring manual verification. 2. Proving the correctness of smart contracts through the use of more general-purpose formal tools supplemented by manual verification requires significant manual effort to construct formal models. The verification process is complex and requires specialized knowledge. It is difficult to scale to large and complex contracts. 3. This approach relies on variable modification instrumentation, a common approach in general-purpose programming languages. The monitoring logic in this approach is often hard-coded and lacks flexibility. There are currently no runtime monitoring tools for smart contracts. 4. Using the Specification language, however, this approach has limited expressiveness and cannot describe temporal properties. Furthermore, its integration with the actual execution environment is limited. Summary of the Invention
[0004] In response to the shortcomings of the existing technology, the purpose of the present invention is to provide a smart contract Temporal Property monitoring method and system based on dynamic instrumentation to solve the problems raised in the above background technology. By implementing the Vector Clock mechanism and resource status tracking at the Ethereum Virtual Machine (EVM) level, the present invention realizes an efficient, accurate and non-invasive security detection method for existing contract code.
[0005] To achieve the above objectives, the present invention is implemented through the following technical solutions: a smart contract Temporal Property monitoring method based on dynamic instrumentation, which includes the following contents: designing a temporal property specification language for smart contracts, optimizing the LTL conversion algorithm, and realizing dynamic monitoring of variables appearing in the specification. The method implements the Vector Clock mechanism and resource status tracking at the Ethereum Virtual Machine (EVM) level, and provides a multi-layer Mapping tracing SHA3 instruction cache and Slot reverse analysis system.
[0006] Furthermore, the temporal property specification language supports the expression of complex temporal logic and state constraints, and has built-in support for special data structures such as mapping; the LTL conversion algorithm converts the specification into linear temporal logic (LTL) and generates efficient and executable monitoring logic.
[0007] Furthermore, the SHA3 instruction cache and Slot reverse analysis system is used to implement intelligent caching of EVM SHA3 instructions, support recursive tracing and analysis of multi-layer mappings, and provide real-time monitoring capabilities for complex data structures.
[0008] Furthermore, it also includes developing a lightweight EVM modification solution to achieve efficient tracking of key state variables; and designing a state reconstruction algorithm to support the verification of complex temporal properties.
[0009] A monitoring system as used in the above-mentioned monitoring method includes the following components: a TPSL parser, an LTL converter, a multi-layer Mapping analysis system, and a dynamic variable monitoring framework, wherein the TPSL parser is the entry point of the system and is responsible for processing user-defined temporal property specifications; the LTL converter receives the internal representation generated by the TPSL parser and converts it into executable monitoring logic; the multi-layer Mapping analysis system is used to process the complex multi-layer nested mapping structure in the smart contract; and the dynamic variable monitoring framework is used to monitor the changes of key state variables in real time during the execution of the smart contract.
[0010] Furthermore, the workflow of the TPSL parser is as follows:
[0011] S1-1, Lexical analysis: decompose the TPSL specification text into a series of tokens;
[0012] S1-2, Syntax analysis: According to the predefined TPSL grammar rules, the token sequence is constructed into an abstract syntax tree (AST);
[0013] S1-3, Semantic Analysis: Perform semantic checks on AST to ensure type consistency and reference integrity;
[0014] S1-4, internal representation generation: Convert the verified AST into an intermediate representation used internally by the system.
[0015] Furthermore, the conversion step of the LTL converter includes:
[0016] S2-1, LTL formula conversion: convert the TPSL internal representation into a standard linear temporal logic (LTL) formula;
[0017] S2-2. Büchi automaton generation: Convert LTL formulas into Büchi automata using an optimized algorithm;
[0018] S2-3, monitoring automaton optimization: optimize and simplify the generated Büchi automaton;
[0019] S2-4. Executable monitoring logic generation: Convert the optimized automaton into efficient monitoring code that can be executed in the smart contract environment.
[0020] Furthermore, the core functions of the multi-layer mapping analysis system include:
[0021] S3-1. EVM modification: Modify the EVM to capture and record the input and output of the SHA3 instruction;
[0022] S3-2, SHA3 instruction cache: implements a multi-layer cache mechanism to store the input and output relationships of SHA3 instructions;
[0023] S3-3, Slot analysis: Analyze the read and write operations of the storage slot and track the updates of the mapping;
[0024] S3-4, recursive tracing: implement recursive tracing algorithm for multi-layer nested mapping;
[0025] S3-5, State view construction: Based on the collected information, build and maintain the global structural view of the mapping.
[0026] Furthermore, the main components of the dynamic variable monitoring framework include:
[0027] S4-1. Code instrumentation: Analyze the smart contract source code or bytecode and insert monitoring logic at key points;
[0028] S4-2, Runtime Monitor: collects information about changes in state variables during contract execution;
[0029] S4-3, State Reconstruction: Dynamically reconstruct the complete state of the contract based on the collected information;
[0030] S4-4. Property Verification: Verify predefined temporal properties using the reconstructed state information.
[0031] Furthermore, it also includes an integrated verification environment, which integrates all components into a unified system to provide an end-to-end verification solution. The workflow is as follows:
[0032] S5-1. User input: Through the graphical interface or command line interface, the user inputs the TPSL specification and the smart contract to be verified;
[0033] S5-2, Preprocessing: TPSL parser processes the specification, and LTL converter generates monitoring logic;
[0034] S5-3. Contract analysis: The multi-layer Mapping analysis system performs static analysis on the contract;
[0035] S5-4, Dynamic Monitoring: Deploy the smart contract containing the monitoring logic, and the dynamic variable monitoring framework begins real-time monitoring;
[0036] S5-5. Result analysis: Collect and analyze verification results and generate detailed reports;
[0037] S5-6, Feedback: Display the verification results to the user, including whether the specified temporal properties are violated, and related detailed information.
[0038] Beneficial effects of the present invention:
[0039] 1. This monitoring method and system can improve expressiveness and accuracy: TPSL allows developers to accurately express complex timing properties and state constraints, significantly reducing ambiguity in specification descriptions and improving verification accuracy.
[0040] 2. This monitoring method and system enhances the ability to handle complex data structures: A multi-layer mapping analysis system enables monitoring of deeply nested data structures. This overcomes the limitations of existing technologies that struggle to handle complex mappings. It also improves execution efficiency. The optimized LTL conversion algorithm generates more efficient monitoring logic. The SHA3 instruction cache reduces recalculation and improves runtime performance.
[0041] 3. This monitoring method and system enhance dynamic analysis capabilities: The dynamic variable monitoring framework provides deep insight into the runtime behavior of contracts and supports real-time verification of complex temporal properties. It also reduces false positives and false negatives: Combining static analysis and dynamic monitoring significantly improves verification accuracy; multi-layer mapping analysis reduces false positives caused by complex data structures. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 This is the overall architecture diagram of the present invention;
[0043] Figure 2 This is the architecture diagram of the mapping analysis system of the present invention. DETAILED DESCRIPTION
[0044] In order to make the technical means, creative features, objectives and effects achieved by the present invention easier to understand, the present invention is further described below in conjunction with specific implementation methods.
[0045] See also Figures 1 to 2 The present invention provides the following technical solution: a method for monitoring Temporal Property of smart contracts based on dynamic instrumentation. The basic scheme and ideas of the method are as follows:
[0046] 1. Temporal Property Specification Language (TPSL) for smart contracts:
[0047] Design a high-level specification language for smart contract features; support the expression of complex timing logic and state constraints; built-in support for special data structures such as mapping
[0048] 2. Optimized LTL conversion algorithm:
[0049] Develop a conversion algorithm from LTL to monitoring automata specifically for smart contracts; consider EVM characteristics and generate efficient and executable monitoring logic
[0050] 3. Multi-layer Mapping tracing SHA3 instruction cache and Slot reverse analysis system:
[0051] Implement intelligent caching of EVM SHA3 instructions; support recursive tracing and analysis of multi-layer mapping; provide real-time monitoring capabilities for complex data structures
[0052] 4. Dynamic variable monitoring and state reconstruction framework:
[0053] Develop a lightweight EVM modification solution to achieve efficient tracking of key state variables; design a state reconstruction algorithm to support the verification of complex temporal properties.
[0054] This embodiment also provides a monitoring system used in the above-mentioned monitoring method, which aims to address the challenges faced by existing technologies when processing complex smart contracts. The system includes the following core components and workflows:
[0055] 1. TPSL (Temporal Property Specification Language) parser
[0056] The TPSL parser is the entry point of the system and is responsible for processing user-defined temporal property specifications. Its workflow is as follows:
[0057] a) Lexical analysis: decompose the TPSL specification text into a series of tokens.
[0058] b) Syntax analysis: According to the predefined TPSL grammar rules, the token sequence is constructed into an abstract syntax tree (AST).
[0059] c) Semantic analysis: Perform semantic checks on the AST to ensure type consistency and reference integrity.
[0060] d) Internal representation generation: Convert the verified AST into an intermediate representation used internally by the system.
[0061] 2. LTL Converter
[0062] The LTL converter receives the internal representation generated by the TPSL parser and converts it into executable monitoring logic. The main steps include:
[0063] a) LTL formula conversion: Convert the TPSL internal representation into a standard linear temporal logic (LTL) formula.
[0064] b) Büchi automaton generation: LTL formulas are converted into Büchi automata using an optimized algorithm.
[0065] c) Monitoring automaton optimization: Considering the characteristics of EVM (Ethereum Virtual Machine), the generated Büchi automaton is optimized and simplified.
[0066] d) Executable monitoring logic generation: Convert the optimized automaton into efficient monitoring code that can be executed in the smart contract environment.
[0067] 3. Multi-layer Mapping Analysis System
[0068] This system is specifically designed to handle complex multi-layer nested mapping structures in smart contracts. Its core features include:
[0069] a) EVM modification: Modify the EVM to capture and record the input and output of the SHA3 instruction.
[0070] b) SHA3 instruction cache: Implements a multi-layer cache mechanism to store the input and output relationships of SHA3 instructions.
[0071] c) Slot analysis: Analyze the read and write operations of the storage slots and track the updates of the mapping.
[0072] d) Recursive tracing: Implement a recursive tracing algorithm for multi-layer nested mappings.
[0073] e) State view construction: Based on the collected information, build and maintain the global structural view of the mapping.
[0074] 4. Dynamic Variable Monitoring Framework
[0075] The framework is responsible for real-time monitoring of changes in key state variables during smart contract execution. The main components include:
[0076] a) Code instrumentation: Analyze the smart contract source code or bytecode and insert monitoring logic at key points.
[0077] b) Runtime monitor: collects information about changes in state variables during contract execution.
[0078] c) State reconstruction: Dynamically reconstruct the complete state of the contract based on the collected information.
[0079] d) Property Verification: Verify predefined temporal properties using the reconstructed state information.
[0080] 5. Integrated Verification Environment
[0081] The integrated verification environment integrates all the above components into a unified system, providing an end-to-end verification solution. Its workflow is as follows:
[0082] a) User input: Through a graphical interface or command line interface, the user enters the TPSL specification and the smart contract to be verified.
[0083] b) Preprocessing: The TPSL parser processes the specification and the LTL converter generates the monitoring logic.
[0084] c) Contract analysis: A multi-layer mapping analysis system performs static analysis on the contract.
[0085] d) Dynamic monitoring: Deploy a smart contract containing monitoring logic, and the dynamic variable monitoring framework begins real-time monitoring.
[0086] e) Result analysis: Collect and analyze verification results and generate detailed reports.
[0087] f) Feedback: Display the validation results to the user, including whether the specified temporal properties are violated, and related detailed information.
[0088] Through this comprehensive approach, the present invention can effectively monitor and verify the temporal properties of complex smart contracts, significantly improving the reliability and security of the contracts. The system can not only handle the complex data structures and logic in current smart contracts, but also has good scalability and can adapt to the development of future smart contract technology.
[0089] In this embodiment, a TPSL language alternative is also provided, including:
[0090] 1. Based on the extension of existing specification languages: Instead of developing a completely new TPSL, the existing LTL or CTL languages are extended. This leverages existing tools and theoretical foundations to reduce learning costs.
[0091] 2. Graphical specification definition tool: Develop a visual interface that allows users to define temporal properties by dragging and connecting graphical elements. This solution is more intuitive and suitable for non-professional users.
[0092] In this embodiment, alternative multi-layer Mapping analysis solutions are also provided, including:
[0093] 1. Analysis based on symbolic execution: Use symbolic execution technology to analyze the mapping structure. This solution may reveal deeper problems.
[0094] 2. Combining static and dynamic analysis: Static analysis is performed before contract deployment, and dynamic analysis is performed during runtime. This combines the advantages of both methods to improve analysis efficiency and accuracy.
[0095] The basic principles, main features and advantages of the present invention are shown and described above. For those skilled in the art, it is obvious that the present invention is not limited to the details of the above exemplary embodiments, and the present invention can be implemented in other specific forms without departing from the spirit or basic features of the present invention.
[0096] In addition, it should be understood that although this specification is described in terms of implementation methods, not every implementation method contains only one independent technical solution. This narrative method of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment can also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.
Claims
1. A method for monitoring Temporal Property of smart contracts based on dynamic instrumentation, characterized in that: The monitoring method comprises the following steps: S1. User input: Through a graphical interface or command line interface, the user inputs the TPSL specification and the smart contract to be verified. TPSL is a Temporal Property Specification language designed for smart contracts, and the TPSL specification is preprocessed. S2, the pre-processed TPSL specification converts the specification into linear temporal logic and generates efficient and executable monitoring logic; S3-1. Ethereum Virtual Machine Modification: Modify the Ethereum Virtual Machine to capture and record the input and output of SHA3 instructions; S3-2, SHA3 instruction cache: implements a multi-layer cache mechanism to store the input and output relationships of SHA3 instructions; S3-3, Slot analysis: Analyze the read and write operations of the storage slot and track the updates of the mapping; S3-4, recursive tracing: implement recursive tracing of multi-layer nested mappings; S3-5, State view construction: Based on the collected information, build and maintain the global structure view of the mapping; S4-1. Code instrumentation: Analyze the smart contract source code or bytecode and insert monitoring logic at key points; S4-2, Runtime Monitor: collects information about changes in state variables during contract execution; S4-3, State Reconstruction: Dynamically reconstruct the complete state of the contract based on the collected information; S4-4, Property Verification: Verify predefined temporal properties using the reconstructed state information; S5. Result analysis: Collect and analyze verification results and generate detailed reports; S6. Feedback: Display the verification results to the user, including whether the specified temporal properties are violated.
2. A method for monitoring Temporal Property of smart contracts based on dynamic instrumentation according to claim 1, characterized in that: The workflow for preprocessing the TPSL specification in S1 is as follows: S1-1, Lexical analysis: decompose the TPSL specification text into a series of tokens; S1-2, Syntax analysis: Construct the token sequence into an abstract syntax tree according to the predefined TPSL grammar rules; S1-3, semantic analysis: semantically check the abstract syntax tree to ensure type consistency and reference integrity; S1-4, internal representation generation: Convert the verified abstract syntax tree into an intermediate representation used internally by the system.
3. A method for monitoring Temporal Property of smart contracts based on dynamic instrumentation according to claim 2, characterized in that: Step S2 includes: S2-1, LTL formula conversion: convert the TPSL internal representation into a standard linear temporal logic formula; S2-2. Büchi automaton generation: Convert LTL formulas into Büchi automata using an optimized algorithm; S2-3, monitoring automaton optimization: optimize and simplify the generated Büchi automaton; S2-4. Executable monitoring logic generation: Convert the optimized automaton into monitoring code that is executed in the smart contract environment.
4. A monitoring system used in the monitoring method according to claim 1, characterized in that: The monitoring system includes the following components: TPSL parser, LTL converter, multi-layer Mapping analysis system, and dynamic variable monitoring framework. The TPSL parser is the entry point of the system and is responsible for processing user-defined temporal property specifications; the LTL converter receives the internal representation generated by the TPSL parser and converts it into executable monitoring logic; the multi-layer Mapping analysis system is used to process the complex multi-layer nested mapping structure in the smart contract; and the dynamic variable monitoring framework is used to monitor the changes of key state variables in real time during the execution of the smart contract.
Citation Information
Patent Citations
method for verifying a monitor during simplified operation based on a Buchi automaton
CN109522713A
Extensible intelligent contract vulnerability detection method
CN110659494A
Efficient runtime monitoring method oriented to complete regular sequential logic property
CN116107862A
Smart contract input mapping
US20200034453A1