Formal Verification Systems and Methods
Through fine-grained concurrency layer calculation and authentication tools, combined with game theory strategies and combination semantic models, the concurrency abstraction layer verification problem is solved, and formal verification and security improvement of high-value applications such as blockchain are achieved.
Patent Information
- Application Number
- CN201880087842.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2017-11-28
- Filing Date
- 2018-11-28
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2038-11-28
AI Technical Summary
It is difficult to formally verify the concurrency abstraction layer with existing technology, which limits the applicability of layer-based technology and extended verification across multiple concurrency layers, especially in blockchain technology due to the concurrency between nodes and the diversity of hardware abstraction levels. nature, it is difficult to achieve formal verification of high-value applications.
Using fine-grained concurrency layer calculus, certified link tools and a C compiler with thread safety verification, by building a formal verification method covering the interface, using game theory strategies and combination semantic models to verify the correctness and security of the concurrency abstraction layer, Supports combinations of concurrency layers for multi-threaded and multi-core environments.
It implements formal verification of the concurrency abstraction layer, reduces complex dependencies between components at different abstraction levels, supports verification across multiple concurrency layers, and improves the security and credibility of high-value applications such as blockchain.
Smart Images

Figure CN112119423B_ABST
Abstract
Description
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application claims priority from French patent application No. 17 / 61318, filed on November 28, 2017, the entire contents of which are incorporated herein by reference.
[0003] Federally funded research
[0004] This invention was made with government support under Grant No. 1521523 from the National Science Foundation and Grant No. FA8750-12-2-0293 from the U.S. Air Force Office of Scientific Research. The government has certain rights in the invention. Background Art
[0005] Abstraction layers are a key technology used in building large-scale concurrent software and hardware. Due to the prevalence of multi-threaded programming and multi-core hardware, concurrency abstraction layers are ubiquitous in modern computer systems. Abstraction layers are used to hide implementation details (e.g., fine-grained synchronization) and reduce complex dependencies between components at different abstraction levels. Despite their obvious importance, concurrency abstraction layers have not been formally addressed. This severely limits the applicability of layer-based techniques and makes it difficult to scale verification across multiple concurrency layers.
[0006] Distributed ledgers provide another example of concurrent execution. Such systems (e.g., blockchain-based databases) enable decentralized management of records in a secure and transparent manner. For example, a blockchain can be used as an open ledger for recording transactions between parties and can be maintained by a network of nodes. These nodes can each maintain a local copy of the blockchain and can jointly execute a protocol to ensure that the local copies remain consistent with each other when new transactions are recorded. Blockchain technology can be suitable for a variety of applications that require high security, such as identity management, transaction processing, medical record keeping, traceability of logistics, etc. However, due to the concurrency of execution between nodes and the multiple levels of abstraction between the entire distributed ledger and the hardware of the nodes that implement the distributed ledger, the same characteristics that make blockchain technology suitable for such high-value applications also make it difficult to formally verify such applications. Summary of the Invention
[0007] Implementations can be used to build a certified concurrency abstraction layer. These implementations can include a program verifier for concurrent C and assembly that applies a fine-grained concurrency layer calculus, a certified linking tool, and a thread-safety-verified C compiler. Implementations can also include applying these tools to the verification of smart contracts.
[0008] Embodiments may include a method for formal verification of an overlay interface. The method may include modeling the overlay interface as a plurality of layer implementations built on an underlying interface, the underlying interface parameterized by a plurality of thread sets. The method may also include verifying the overlay interface by performing at least one of the following operations.
[0009] The first operation can verify that the mapping to the program built on the underlying interface implements the mapping to the policy. The semantics of running the shared primitive on the underlying interface can be simulated by the policy.
[0010] The second operation can verify that the first program module implements the overlay interface according to the first simulation relationship. The second program module built on the underlying interface can implement the first intermediate interface according to the second simulation relationship. The third program module built on the first intermediate interface can implement the overlay interface according to the third simulation relationship. The first program module can be a combination of the second program module and the third program module, and the first simulation relationship can be a combination of the second simulation relationship and the third simulation relationship.
[0011] The third operation can verify that the fourth program module implements the overlay interface according to the fourth simulation relationship. The fifth program module constructed on the underlying interface can implement the second intermediate interface according to the fourth simulation relationship. The sixth program module constructed on the underlying interface can implement the third intermediate interface according to the fourth simulation relationship. The fourth program module can be a combination of the fifth program module and the sixth program module, and the overlay interface can be a combination of the second intermediate interface and the third intermediate interface.
[0012] The fourth operation can verify that the seventh program module built on the fourth intermediate interface implements the fifth intermediate interface according to the fifth simulation relationship. The fourth intermediate interface can be simulated by the underlying interface according to the sixth simulation relationship. The seventh program module can implement the overlay interface according to the seventh simulation relationship. The overlay interface can be simulated by the fifth intermediate interface according to the eighth simulation relationship. The fifth simulation relationship can be a combination of the sixth simulation relationship, the seventh simulation relationship, and the eighth simulation relationship.
[0013] The fifth operation may verify that the eighth program module built on the underlying interface implements the overlay interface. The underlying interface may be parameterized by the union of the first thread set and the second thread set. The overlay interface may be parameterized by the union of the first thread set and the second thread set. The first underlying interface may be parameterized by the first thread set, and the second underlying interface may be parameterized by the second thread set. The first overlay interface may be parameterized by the first thread set, and the second overlay interface may be parameterized by the second thread set. The eighth program module built on the first underlying interface may implement the first overlay interface. The eighth program module built on the second underlying interface may implement the second overlay interface. The first underlying interface may be compatible with the second underlying interface. The first overlay interface may be compatible with the second overlay interface.
[0014] The sixth operation may verify that the interface parameterized by the third thread set is compatible with the interface parameterized by the fourth thread set. In some aspects, for all threads in the third thread set, the dependency conditions of the interface parameterized by the fourth thread set may imply the guaranteed conditions of the interface parameterized by the third thread set. In various aspects, for all threads in the fourth thread set, the dependency conditions of the interface parameterized by the third thread set may imply the guaranteed conditions of the interface parameterized by the fourth thread set. The dependency conditions of the interface parameterized by the intersection of the third and fourth thread sets may be equal to the union of the dependency conditions of the interface parameterized by the third thread set and the dependency conditions of the interface parameterized by the fourth thread set. The guaranteed conditions of the interface parameterized by the intersection of the third and fourth thread sets may be equal to the intersection of the guaranteed conditions of the interface parameterized by the third thread set and the guaranteed conditions of the interface parameterized by the fourth thread set. The set of primitives of the interface parameterized by the intersection of the third and fourth thread sets is equal to the combination of the set of primitives of the interface parameterized by the third thread set and the set of primitives of the interface parameterized by the fourth thread set.
[0015] Embodiments may include a method for formal verification of an overlay interface. The method may include determining that semantics of running a first shared primitive on an underlying interface are emulated by a first strategy. The first strategy may describe an action of the first primitive as a first function of a first log. The determination may include constructing a proof of the emulation relationship. The method may include generating an operation of an intermediate concurrency layer by combining the first strategy with a second strategy, the second strategy describing an action of a second shared primitive on the underlying interface as a second function of the first log. The method may include determining that the operation of the intermediate concurrency layer is emulated by the first overlay layer.
[0016] Embodiments may include a method for verifying smart contracts. The method may include modeling one or more smart contracts as a concurrency abstraction layer. The concurrency abstraction layer may include a layer implementation, a bottom layer interface, and an overlay interface. The layer implementation may include one or more smart contracts. The method may include verifying the correctness of the one or more smart contracts at least in part by constructing a formal proof that the layer implementation running on top of the bottom layer interface simulates the overlay interface.
[0017] The foregoing summary is provided by way of illustration and is not intended to be limiting. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 A diagram depicting exemplary concurrency layer objects in a modern multi-core runtime.
[0019] Figure 2 Describes a programming toolkit for building authenticated concurrency abstraction layers.
[0020] Figure 3 Depicted is exemplary code for using locks to protect critical sections of a program.
[0021] Figure 4 Depicted is the function call behavior of an exemplary system with two threads ( t1 and t2 ) and a scheduler.
[0022] Figure 5 Depicts the construction of an authenticated concurrency layer for the entire system from an authenticated assembly layer using published composition rules.
[0023] Figure 6 Describes the strategy σ pull ′, where r{i:v} means updating record v at field i with value r.
[0024] Figure 7 Describes the concurrency layer interface and the machine state of the concurrent machine model.
[0025] Figure 8 Depicts an exemplary specification of a push / pull primitive for L[c] that communicates the effects of a shared memory operation.
[0026] Figure 9 Lists layer calculi that can be used to build and compose concurrent layers.
[0027] Figure 10 Pseudo code for an exemplary ticket lock is depicted.
[0028] Figure 11Describes the specification of the middle layer of the queued lock, which can be used to verify the specification of the entire multi-threaded queued lock.
[0029] Figure 12 An extended memory model that satisfies the requirements for parallel combination of assembly layers is depicted.
[0030] Figures 13A to 13G Depicts exemplary strategies based on a game-theoretic concurrency framework.
[0031] 14A to 14D Describes the operation of scheduling primitives in various thread configurations.
[0032] Figure 14E Presented for Figure 2 The number of rows for each component in (in Coq).
[0033] Figure 14F Some of the statistics on the implemented components are presented.
[0034] Figure 15 An illustrative blockchain 1500 is depicted, according to some implementations.
[0035] Figure 16 An illustrative node 1600 is depicted that participates in a distributed computing platform for executing smart contracts, according to some embodiments.
[0036] Figure 17 An illustrative concurrency abstraction layer 1700 is depicted in accordance with some implementations.
[0037] Figure 18 Depicted are an illustrative physical blockchain 1800 and an illustrative logical blockchain 1805 in accordance with some implementations.
[0038] Figure 19 An illustrative computer 19000 is schematically depicted upon which any aspect of the present disclosure may be implemented. DETAILED DESCRIPTION
[0039] Concurrency abstraction layers can be used in modern computer systems with multi-threaded programming and multi-core hardware. Abstraction layers can be used to hide implementation details (e.g., fine-grained synchronization) and reduce complex dependencies between components at different levels of abstraction. However, systems and methods for formal verification of concurrency abstraction layers are inadequate, limiting the applicability of layer-based technologies and making it difficult to extend verification across multiple concurrency layers. The disclosed embodiments include a programming toolkit for specifying, combining, compiling, and linking certified concurrency abstraction layers. The disclosed embodiments provide technical improvements, including a new game-theoretic strategy-based compositional semantic model for concurrency (and its associated program verifier), a set of formalized linking theorems for combining multi-threaded and multi-core concurrency layers, and a compiler that supports certified thread-safe compilation and linking. The disclosed embodiments can be implemented in Coq and can support hierarchical concurrent programming in both C and assembly, but the disclosed embodiments are not limited to such implementations and languages. A fully certified concurrent OS kernel with fine-grained locking is also disclosed.
[0040] Abstraction layers (e.g., circuits, ISAs, device drivers, OS kernels, and hypervisors) can be used in modern computer systems to help reduce complex dependencies between components at different levels of abstraction. An abstraction layer can define an interface that hides the implementation details of its underlying software or hardware components. Client programs built on top of each layer can be understood based solely on the interface, regardless of the layer implementation. These abstraction layers can be concurrent in nature. Their interfaces (in addition to hiding specific data representation and algorithmic details) can create an illusion of atomicity for all their methods. For example, even if the implementation of such a method contains complex interweaving of operations performed with other threads, users of the interface will view such a method call as being completed in a single step. Large-scale concurrent software systems can be constructed using layers of these atomic objects.
[0041] As an example application, the formal verification framework described herein can be used to verify smart contracts. In some embodiments, one or more smart contracts can be verified as a concurrent abstraction layer. For example, the concurrent abstraction layer can include a layer implementation, an underlying interface, and an overlay interface, where the layer implementation can include one or more smart contracts. The correctness of one or more smart contracts can then be verified by constructing a formal proof of the overlay interface that simulates the layer implementation running on top of the underlying interface.
[0042] Figure 1A schematic diagram of exemplary concurrency layer objects in a modern multi-core runtime is presented. In this example, arrows indicate possible function calls from one component to another. Components include thread-local (or CPU-local) objects (e.g., 1a to 1f), objects shared between CPU cores (e.g., 2a to 2c), objects exported and shared between threads (e.g., 3a to 3e), and objects for the threads themselves (e.g., 4a to 4c). An efficient and starvation-free spinlock implementation 2b can be constructed on top of the hardware layer. Spinlocks can implement shared objects for the dormant thread queue 2a and the pending thread queue 2c, which can be used to implement a thread scheduler 3b and primitives such as yield, sleep, and wakeup. Advanced synchronization libraries such as queued locks 3e, condition variables (CVs) 3d, and message passing primitives 3c can be implemented on top of the thread scheduler and primitives such as yield, sleep, and wakeup.
[0043] Formal reasoning across multiple concurrent layers is challenging because different layers often exhibit different interleaving semantics and have different sets of observable events. For example, Figure 1 The spinlock module in
[15] assumes a multi-core model with overlapping execution of instruction streams from different CPUs. This model is different from the multi-threaded model used to build high-level synchronization libraries: if the queue lock or CV event is not available, each thread will block instead of spinning; and it must rely on other threads to wake it up to ensure activity. Reasoning across these different levels of abstraction requires a common, unified compositional semantic model that can cover all these concurrency layers. The model must also support common "parallel layer composition rules" that can handle explicit thread control primitives (e.g., sleep and wakeup). The model must also support vertical composition of these concurrency layer objects while preserving linearizability properties and progress properties (e.g., starvation-freedom).
[0044] The disclosed embodiments include a fully mechanized programming toolkit implemented for building a certified concurrency abstraction layer. The toolkit can be implemented in Coq. Figure 2As shown, the toolkit may include one or more of the following: a compositional semantic model 21 for concurrency, a collection of C program verifiers 23 and assembler verifiers 22, a library 24 for building hierarchical refinement proofs, a C compiler 25 for thread safety verification based on CompCertX, or a set of certified linking tools (e.g., 26a to 26c) for composing multi-threaded or multi-core layers. A certified concurrency abstraction layer can be described as a triple (L1[A], M, L2[A]) plus a mechanized proof object, which shows that the layer implementation M, running on behalf of a set of threads A on interface L1, implements a more abstract interface L2. The compositional semantic model 21 can use game semantics to enable local reasoning, enabling verification of the implementation on a single thread t by constructing (L1[{t}], M, L2[{t}]). Guarantees of the implementation on a single thread can be propagated to additional threads through parallel composition. The concurrency layer can enforce termination-sensitive contextual correctness properties. When applied to a concurrency abstraction layer, this termination-sensitive context correctness property may mean that every authenticated concurrent object satisfies not only safety properties (eg, linearizability) but also progress properties (eg, starvation-freedom).
[0045] Certain disclosed embodiments can implement a compositional semantic model for a shared-memory concurrent abstract machine and enable general parallel layer composition rules. Such embodiments can be used to specify, verify, and compose various concurrent objects at different levels of abstraction. Disclosed embodiments can be used to apply simulation techniques to verify the safety and liveness of concurrent objects in a unified setting. Disclosed embodiments can be used to impose temporal invariants, such as fairness requirements (for schedulers) or deterministic actions (for releasing locks), enable complete specification of lock primitives, and support vertical composition of starvation-free atomic objects, which are all technical improvements in the field of formal verification.
[0046] Certain disclosed embodiments can compile a certified concurrent C layer into an assembly layer. To achieve certified multi-threaded linking, such embodiments support an extended algebraic memory model whereby the stack frames allocated for each thread are combined to form a single coherent memory.
[0047] The embodiments disclosed herein relate to a shared memory concurrent program module that can be used to verify the Figure 1 The disclosed embodiments assume strong sequential consistency for shared primitives. However, as one skilled in the art will appreciate, the concept of a certified concurrency layer can potentially be applied to more general settings. Other embodiments disclosed herein apply the concept of a certified concurrency layer to smart contracts.
[0048] 1. Overview
[0049] The disclosed embodiments introduce a layer-based approach to formally specifying, certifying, and combining these (concurrent) layers. This approach provides a technical solution to the following problems: 1) untangling the complexity of module dependencies and interweaving, and 2) independently and locally verifying different parts at the layer to which they belong.
[0050] Figure 3 Depicted is exemplary code for using locks to protect critical sections of a program. In this example, a client program P has two threads running on two different CPUs; each thread makes a call to a primitive foo provided by the concurrency layer interface L2. Interface L2 is implemented by a concurrency module M2, which is in turn built on interface L1. Method foo calls two primitives f and g in the critical section protected by the lock. The lock is implemented on interface L0 using the ticket lock algorithm in module M1. The lock maintains two integer variables n (the "now serving" ticket number) and t (i.e., the next ticket number). The lock acquisition method acq fetches and increments the next ticket number (in FAI_t), then rotates until the fetched number is served. The lock release method rel increments the "now serving" ticket number by inc_n. These primitives are provided by L0 and are implemented using x86 atomic instructions. L0 also provides primitives f and g which are then passed to L1, as well as a no-op primitive hold called by acq to announce that the lock has been taken.
[0051] Authentication abstraction layer
[0052] The order abstraction layer of authentication can be used through predicate The description is made with the mechanized proof object of the predicate, showing that a layer implementation M built on top of an interface L' (called the underlying interface) does implement the above desired interface L (called the overlay interface) via a simulation relation R. Consistent with the disclosed embodiments, the implementation M can be a program module written in assembly (or C). The layer interface L can be composed of a set of abstract states and primitives. The abstract layer machine based on L can be a basic assembly (or C) machine extended with the abstract states and primitives defined in L. The realization relation represents a forward simulation with a (simulation) relation R. A certified layer can enforce the contextual correctness property: a correct layer can act like a "certified compiler" and transform any secure client program P running on top of L into a secure client program with the same behavior but running on top of L' (i.e., by "compiling" the abstract primitives in L to their implementations in M). The behavior of a layer machine based on L can be expressed as [[·]] L . The correctness property of can then be written as in, represents the link operator on programs P and M.
[0053] Authenticated concurrency layer
[0054] Consistent with the disclosed embodiment, each layer interface L may be implemented with a “focused” thread set A (where and D is the domain of all thread / CPU IDs). A layer machine based on the concurrent layer interface L[A] specifies the execution of threads in A. In some aspects, threads outside of A can be considered environments. As a non-limiting example, in Figure 3 In [1], the domain D is {1,2}. When {1} is the focused thread set, the environment contains thread 2. As used in this paper, for readability, L[{i}] can be abbreviated to L[i], where i∈D. The concurrency layer interface can be extended from its sequential counterpart with a set of abstract shared primitives and a global log l. Unlike calls to thread-local primitives that may not be observable by other threads, each shared primitive call (along with its arguments) can be recorded as an observable event appended to the end of the global log. For example, a FAI_t (see [1]) called from thread i Figure 3 ) brings the log "l" to the log "l·(i.FAI_t)", where the symbol "·" indicates that the event (i.FAI_t) is appended to the log.
[0055] The disclosed embodiments include a compositional (operational) model based on ideas from game semantics that defines the semantics of a concurrent program P in a general way. The compositional model frames each run of a program P on L[D] as a game involving members of D (plus a scheduler). According to this framework, each participant i∈D contributes its role by appending events to a global log l. Such a participant has a strategy Strategy It can be from the current log l to the participant whenever the last event in l transfers control back to i. For example, if thread i only calls FAI_t, then its strategy can be expressed as Figure 13A The automaton depicted in .
[0056] In this non-limiting depiction, when control is transferred to i, the global log is equal to l (denoted as "?l"). Thread i first generates event i.FAI_t (denoted as "!i.FAI_t") and returns ticket number t (counted from l). Then, thread i becomes idle (denoted as a reflexive edge marked with ?l',!∈) and will not generate any more events. Ticket number t is calculated by the following function: the function counts the extraction and incrementing events in l. As used in this article, such a function that reconstructs the current shared state from the log is called a replay function. The scheduler (denoted as ) is used as the judge of the game. In each round, the scheduler uses its policy to select a thread to take action (and generate events). Then, the behavior of the entire layer machine (represented as "[[·]] L[D] ”) is the set of logs generated by playing the game under all possible schedulers. When focusing on a subset of threads A, the semantics (or execution) of the (concurrency) layer machine based on interface L[A] can be defined on the set of its valid environment contexts. Each environment context (denoted as E) provides the strategy for its "environment", that is, the union of the strategies of the schedulers plus those of the participants not in A.
[0057] Figure 4 An example system with two threads (t1 and t2) and a scheduler is shown. Method foo can run on layer L[t1], which is implemented by L'[t1] under a specific environment context E'1. Here, E'1 is the policy for the scheduler. and the policy for thread t2 The method foo can also run on layer L[t2], which is implemented by L'[t2] under a specific environment context E'2. Here, E'2 is the policy used for the scheduler and the policy for thread t1 The union of . Figure 4 It also depicts the interleaved execution of two calls to foo on L'[{t1,t2}], where the environment context E' is the scheduler policy In this example, consistent with the disclosed embodiments, the execution of P on L[A] is deterministic when given an environment context E that also contains a specific scheduler policy. When control is passed to any member of A, the concurrent machine will run P, but when control is passed to the environment, the concurrent machine will query E for the next action. To enforce the safety of environment actions, each layer interface can specify a set of valid environment contexts. Consistent with the disclosed embodiments, this set of valid environment contexts corresponds to a generalized version of the "dependency" (or "assumption") conditions in rely-guarantee-based reasoning. Each layer interface can also provide one or more "guarantee" conditions that can be expressed as invariants on the global log.
[0058] Local layer interface
[0059] As a non-limiting example, the focused set of threads may be a singleton {i}. Since the execution of the environment (including interleaving) is fully encapsulated into the environment context, L[i] is effectively a sequential (or local) interface parameterized on E. Before each action of the client program P on this local interface, the layer machine first repeatedly requests environment events from E until control is transferred to i. The layer machine then acts based on the received events. Thus, the threads in L[i] (denoted as (|P|) L[i] ) runs a semantic analysis of P as a policy. The correctness property of asserting that a concurrent module above the local layer interface indeed satisfies its specification (i.e., the more abstract policy) can be defined by the policy simulation via the simulation relation R of the log.
[0060] As used herein, if and only if for any two related (by R) sequences of environmental events and any two related initial logs, for the sequence given by Any log l generated must exist through The log l' produced makes l and l' also satisfy R, then another strategy Using the simulation relation R (expressed as ) to simulate the strategy Consider the acq method of the ticket lock module M1 running on L0[i] (such as Figure 3 Its specification can be expressed as Figure 13B The strategy described in
[0061] like Figure 13B As depicted, a query on an environmental context E can be expressed as ? E. It can be shown that the relationship in, Denote the running acq on layer L0, i as the focused thread set. The simulation relation id is as follows: for any equal E and equal initial state, if If the transaction proceeds one step, then acq can proceed one (or more) steps to generate the same event and the resulting states will still be equal. This correctness property can also be used to define the concurrent layer of authentication:
[0062]
[0063] Here, we will build on the underlying interface L0, focus on the thread set i, and implement the strategy The acq of is defined as equivalent to the running acq on layer L0 (i as the focused thread set). Let as well as By showing that a lock release satisfies its specification (i.e., ) and by applying the horizontal combination rules described in this paper, we obtain predicate (1):
[0064]
[0065] Here, a layer implementation M1 that implements the authentication of the overlay interface L'1 (focused on thread set i) built on the underlying interface L0 (focused on thread set i) is defined as being equivalent to the running interface L'1 (i as the focused thread set) via the simulation relation id. This notation can be extended to a set of policies so that each policy of L'1[i] can simulate The corresponding one in .
[0066] More advanced strategies
[0067] In some embodiments, despite the above specifications (e.g., ) is abstract (i.e., language-independent), but low-level implementation details and interweaving within modules may still be exposed. For example, Figure 13B Depicted, A loop is revealed that repeatedly interacts with the environment to check the delivered ticket number. In accordance with the disclosed embodiment, the strategy of L'1[i] can be refined to an atomic higher-level interface L1[i], such as Figure 13C shown.
[0068] here, Only E is queried and a single event i.acq is generated. It then enters a so-called critical state (marked in gray) to prevent loss of control before the lock is released. Therefore, there is no need to query E in the critical state. Consistent with the disclosed embodiments, the policy simulation between L'1[i] and L1[i] can be illustrated by forming the following "dependency" (i.e., validity) condition R in the environmental context of L'1[i]:
[0069] L'1[i].R hs : Scheduler policy It must be fair.
[0070] L′1[i].R j (j≠i): by The generated lock-related events must follow and And the held lock will eventually be released.
[0071] These conditions ensure The loop in (waiting for the ticket to be delivered) terminates. Furthermore, these conditions can be used to prove that every run of L′1[i] is captured by L1[i]. As a non-limiting example, if the scheduler policy The schedule is "1, 2, 2, 1, 1, 2, 1, 1, 2, 2", then P is run on L′1[D] (see Figure 3 )Generate log:
[0072] l′ g :=(1.FAI_t)·(2.FAI_t)·(2.get_n)·(1.get_n)·(1.hold)·(2.get_n)·(1.f)·(2.get_n)·(1.g)·(1.inc_n)·(2.get_n)·(2.hold)
[0073] This interleaving can be done by a higher level scheduler that generates "1, 2" Capture (because thread 1 is critical while holding the lock), and the resulting log at L1[D] is:
[0074] l g :=(1.acq)·(1.f)·(1.g)·(1.rel)·(2.acq)
[0075] Although the logs (and events) at these two layers are different, the order of lock acquisition and the resulting shared state (computed from the logs by the replay function) are the same. By defining a relation R1 on the log as mapping event i.acq to i.hold, i.rel to i.inc_n, and other lock-related events to null events, we can prove that:
[0076] L′1[i]≤R1 L1[i]
[0077] Then, by predicate (1) and Figure 9 The parallel combination rules of , we can get:
[0078]
[0079] Similarly, for the foo method (i.e., Figure 3 M2 in , we can also introduce Figure 13D The low-level strategy shown as the first step Then, it was proved Figure 13E The advanced atomic interface shown in (Using some R2) simulation And simulate foo:
[0080]
[0081] Based on L′2[i], we can derive the “guaranteed” condition for thread i: That is, the held lock is always released within three steps, which is consistent but more complex than the dependency defined above. More specific.
[0082] Parallel layer combination
[0083] Consistent with the disclosed embodiments, if each interface guarantees Implies a dependency on another interface Then two layer interfaces L[t1] and L[t2] are compatible. The general parallel layer composition rule follows from the composition model described in this paper: if L′[t1] is compatible with L′[t2], L[t1] is compatible with L[t2], and Applicable to each t∈{t1,t2}, we get Figure 4 Depicts combining local layers of authentication (one for t1 and another for t2) to build an authenticated layer for the entire machine (where both t1 and t2 are focused).
[0084] Thread-safe CompCertX and layer linking
[0085] As described above, the native layer interface is sequential, so a compiler (e.g., a CompCertX compiler, etc.) can be modified to be thread-safe by merging the stack frames of threads on the same CPU into a single stack. In some embodiments, such a thread-safe compiler can be configured to compile a certified C layer into a certified assembly layer.
[0086] Figure 5 Depicts constructing a concurrent layer of authentication for the entire system from an assembly layer of authentication using the disclosed combination rules. The combination rules may include the horizontal, vertical, and parallel layer combination rules discussed herein. This implies the following soundness theorem, which enforces the context refinement property. The theorem proves that for any client program P, for behavior Any log l in the behavior [[P]] L[D] There must exist a log l′ in both cases such that l and l′ satisfy R.
[0087]
[0088] 2. Concurrency layer interface and calculation
[0089] The following section discusses the application of the disclosed composition model to x86 multi-core hardware.
[0090] 2.1 Multiprocessor Machine Model
[0091] Multiprocessor machine model Defined by machine states, transition relations, and a memory model.
[0092] Machine Model
[0093] Figure 7 Describes the concurrent machine model and the machine state of the concurrent layer interface. In some embodiments, The state can be represented as a tuple "s: = (c, f ρ ,m,a,l)", where the component can be the current CPU ID C , dedicated state f for all CPUs ρ (i.e., a partial mapping from CPU ID to dedicated state p), shared memory state m, abstract state a, and a global event log l. The dedicated state p may include CPU-specific memory pm (not visible to other CPUs) and register set rs. The shared memory state m may be shared between all CPUs. Each location b in local and shared memory may contain a memory value v. The abstract state a may be commonly used in a hierarchical approach to aggregate in-memory data structures from lower layers. Such abstract states are not ghost states because they affect program execution when primitive calls are made. The global log l may be a list of observable events, recording all shared operations that affect more than one CPU. Events generated by different CPUs are interleaved in the log in the actual chronological order of the events, following the actual chronological order of the events. This particular framework is not intended to be limiting. Other frameworks may also be used consistent with this disclosure.
[0094] Transforming relationships
[0095] In the non-limiting example provided, the machine There are two types of transitions that are arbitrarily and non-deterministically intertwined: program transitions and hardware dispatches. Consistent with the disclosed embodiments, program transitions can be one of three possible types: instruction execution, dedicated primitive call, and shared primitive call. The first two types can be "silent" in that they do not generate events. Shared primitives, on the other hand, can provide the only means of accessing events and appending them to a global log. Transitions to instructions only change ρ, pm, and m, and are defined according to standard operational semantics in C or x86 assembly (e.g., similar to the operational semantics used in CompCert). Primitive calls are specific to the style of verification: they specify the semantics of a function f directly from the bottom up as a relation σ f This relation can be defined using a theorem prover (e.g., Coq, etc.). Such a relation can specify how the state is updated after calling f with given arguments and what value f returns.
[0096] Hardware Scheduling
[0097] Consistent with the disclosed embodiment, a hardware scheduling transition may change the current CPU ID c to some ID c' (recorded as a scheduling event). Such transitions may be arbitrarily interleaved with program transitions. In this example, at any step, The client program P can either stay on the current CPU or switch to another CPU. The behavior of the client program P on the multi-core machine (represented as ) is a set of global logs generated by executing P through these two transitions.
[0098] Memory Model
[0099] In this non-limiting example, a "push / pull" memory model can be used for shared memory m (dedicated memory is handled separately in p), which encapsulates shared memory operations as push / pull events and can detect data races. However, this particular model is not intended to be limiting, and other memory models can also be used consistent with the disclosed embodiments.
[0100] In this non-limiting example, each shared memory location b can be associated with an ownership state under the abstract state a that can only be manipulated by two sharing primitives called push and pull. A pull operation can change ownership from "free" to "owned by c," after which shared memory access can be performed by CPU c. A push operation can release ownership and its memory update can be logged. Figure 6 The strategy σ is shown pull ′, where r{i:v} means updating record r at field i with value v.
[0101] If a program attempts to pull a non-free location, or attempts to access or push to a location that the current CPU does not own, a data race may occur and the machine is at risk of being stuck. One technical improvement in concurrent program verification enabled by the disclosed embodiments is the ability to prove that a program is free of data races. In this example, the program is proven to be free of data races by showing that the program will not be stuck.
[0102] 2.2 Concurrency Layer Interface
[0103] In this non-limiting example, the concurrency layer interface L[A] for a subset A of CPUs may be defined as represented as A machine based on this concurrent interface can be "open" in the sense that it can capture a subset of the CPUs and then combine with any acceptable execution of the remaining CPUs. The dedicated state map f ρ The domain of can also be a subset of the capture (or focus). Interface L[A] provides the open machine with The set of primitives defined in and callable at this level, specifying a set of acceptable environmental context dependencies And the guarantee conditions that log l should be kept Instruction transitions are defined as before, but all hardware dispatch is replaced by queries to the environment context.
[0104] Environmental Context
[0105] In some implementations, ε can be the number of columns from the CPU ID to its policy. As described herein, a policy can be an automaton that generates events in response to a given log. When focusing on CPU set A, all observable behaviors of hardware scheduling and program transitions of other CPUs can be specified as the union of policies (i.e., ε). In some embodiments, the machine can query ε for events from other CPUs (and schedulers) whenever there is potential interleaving.
[0106] Consistent with the disclosed embodiments, environment events cannot affect the behavior of instructions and specialized primitive calls. Since the push / pull memory model encapsulates the effects of other CPUs on shared memory into push / pull events, this lack of influence also applies to shared memory reads / writes. Therefore, during the execution of instructions and specialized primitives, it may not be necessary to query ε, and additional environment events will be received by the next so-called query point (i.e., the point just before executing a shared primitive).
[0107] To continue the example, at each query point, the machine can repeatedly query ε. Each query takes the current log l as a parameter and returns an event from CPU c′ that is not in A (i.e., ε(c′, l)). This event is then appended to l, and the query continues until there is a hardware transition event that returns A (assuming the hardware scheduler is fair). The entire process of expanding l with multiple events from other CPUs can be expressed as ε[A, l].
[0108] As described in this article, the layer interface and The validity of the environment context and the invariants of the log (including locally generated events) can be specified. After each step of the thread in A through the interface L[A], the resulting log l must satisfy the guarantee condition (For example, if c is the current CPU ID indicated by l, then ). In this example, the guarantee condition can depend on the validity of the locally generated event and the validity of the environment context. Dependent Condition A set of valid environment contexts can be specified that take a valid input log and return a valid list of events.
[0109] CPU Local Layer Interface
[0110] As used herein, L[c] represents a CPU-local layer interface focused on a single CPU c. The machine state of layer L focused on CPU c may be (ρ, m, a, l), where p may be the dedicated state of CPU c and m may be the local copy of shared memory.
[0111] Figure 8 Depicts an example specification of the push / pull primitives of L[c] that transmit the effects of a shared memory operation. In some embodiments, the local copy of shared memory m can only be accessed locally by c. The primitive push / pull of L[c] "transmits" the effects of a shared memory operation, which depends on the replay function To reconstruct a shared memory value v for some location b and check the well-formedness of the resulting log (ie, no data races occur). These example specifications are not intended to be limiting.
[0112] Since ε is used to replace σ pull parameterized, so it can also be considered as having Figure 13F The strategy for updating the dedicated state is depicted in Figure 2. As depicted in the figure, a layer machine can enter the critical state by calling pull while maintaining ownership of a shared location. A layer machine can exit the critical state by calling push to release ownership of a shared location.
[0113] 2.3 Concurrency Layer Calculus
[0114] The disclosed embodiments may use, include and / or implement Figure 9 The layer calculus shown in the to build and combine concurrent layers .exist Figure 9 middle, Represents an empty program module, Compute the union of two modules (or sets of primitives at two layers), and is a singleton map with a pointer or position i as its field.
[0115] Combination rules
[0116] In some embodiments, Figure 9 The vertical combination rule (Vcomp) depicted in FIG can enable the verification of modules M and N (where N may depend on M) to be performed in two separate steps, while Figure 9 The horizontal combination rule (Hcomp) depicted in
[0045] can enable local reasoning for independent modules M and N belonging to the same level. Consistent with the disclosed embodiments, these two combination rules can combine layers on the same CPU set. In some embodiments, these two combination rules can only combine layers on the same CPU set.
[0117] In some embodiments, as described herein, layers on different CPUs can be combined by the parallel composition rule (Pcomp) when the simulation relationships are the same and both the overlay interface and the underlying interface are compatible. This compatibility is expressed as We assert that every guarantee condition on L[A] implies the corresponding dependency condition on L[B], and conversely, every dependency condition on L[B] implies the corresponding guarantee condition on L[A]. The combined interface L[A∪B] merges the primitives of the two layers and provides stronger guarantees and weaker dependency conditions. Machines based on this combined layer interface only query ε for events that do not originate from A∪B.
[0118] Multi-core Link Theorem
[0119] By combining all CPUs in the machine (denoted as set D), the resulting layer interface does not depend on any context events except those from the hardware scheduler. The primitives provided construct such a layer interface L x86 [D]. Then, we can Each interleave (or log) of the selected L x86 [D] A suitable hardware scheduler to prove that to L x86[D] context refinement. According to the following multi-core link theorem, L x86 [D] Code verification on downlink to x86 multi-core hardware
[0120]
[0121] The theorem states that for all programs P, the behavior of a multicore machine on P is realized by simulating the relation R to focus on the layer interface L of the set D of CPUs. x86 The behavior of P on.
[0122] Function rules
[0123] Consistent with the disclosed embodiments, it is possible to use the simulation between the demonstration strategies Figure 9 The above is relative to the function rule (Fun) relationship described in the above. Figures 13C to X e describes the two most common patterns—function-lift and log-lift. As discussed with respect to these figures, the function-lift pattern abstracts the specific implementation into a low-level policy without changing the underlying interleaving. In this pattern, language-dependent details (e.g., silent actions that change time variables) are hidden, and data representation details (e.g., memory values carried by push events) are replaced with abstract state values. The log-lift pattern always involves event merging and interleaving shuffling to form an atomic interface.
[0124] 3. Build a certified multi-core layer
[0125] As shown in the following examples, the disclosed embodiments can be used to verify shared objects. In these examples, all layers are based on the CPU local layer interface L x86 [c] to build.
[0126] 3.1 Spin Lock
[0127] As will be appreciated by those skilled in the art, spin locks (e.g., the ticket lock algorithm described above) are a fundamental synchronization method for multi-core machines. Spin locks can be used as building blocks for shared objects and more complex synchronization.
[0128] A spinlock can enforce mutual exclusion by restricting CPU access to memory location b. Therefore, the lock operation can be considered a "safe" version of the push / pull primitive. For example, when the lock acquisition for b succeeds, the corresponding shared memory is guaranteed to be "free", which means that it is safe to pull the content to the local copy at that point ( Figure 10 In this non-limiting example, the disclosed embodiments may be used to Figure 10 The use of ticket lock algorithm (in Figure 10In the pseudocode depicted in , a query point is represented as )'s spin lock building layer.
[0129] Bottom interface Lx86[c]
[0130] In this example, the CPU local interface L can be extended using the shared primitives FAI_t, get_n, and inc_n x86 [c] These primitives can directly manipulate the lock state t (next ticket) and n (delivery ticket) via x86 atomic instructions. The lock state can be calculated by a replay function that counts c.FAI_t and c.inc_n events.
[0131] To L lock low Function promotion of [c]
[0132] As discussed herein, the low-level interface L lock_low [c] (which can be the same as L'1[c] above) proves the strategy simulation. Note that, with compared to, Contains additional silent actions (e.g., assign myt, Figure 10 In some embodiments, the simulated relationship R lock Not only does it show equality between logs, but it also maps the lock state in memory to the state defined by the replay function The state of the computation. The simulation relation must also handle potential integer overflows of t and n. Consistent with the disclosed embodiment, as long as the total number of CPUs in the machine (i.e., #CPUs) is less than 2^32 (this number depends on the definition of unsigned integers for the platform), the mutual exclusion property will not be violated even if there is overflow.
[0133] To L lock [c] log improvement
[0134] As discussed above, the acq and rel primitives can be refined into atomic interfaces so that each call generates exactly one event in the log. These atomic lock interfaces (or strategies) can be similar to the pull / push specifications, except that the atomic lock interfaces are safe (i.e., they will not get stuck). This safety property can be achieved using dependency conditions. To prove this, we can say that for any CPU c'≠c, its c'.acq event must be followed by a sequence of its own events (generated in a critical state) ending with c'.rel. The distance between c'.acq and c'.rel in the log is less than some number n.
[0135] Consistent with the disclosed embodiments, the liveness property (i.e., starvation-freedom) can be established by enforcing scheduler fairness as a requirement that any CPU in the dependency condition be scheduled within m steps. It can then be shown that the while-loop in acq terminates in "n×m×#CPU" steps.
[0136] 3.2 Shared Queue Objects
[0137] As those skilled in the art will appreciate, shared queues are widely used in concurrent programs (e.g., as lists of threads in schedulers, etc.). The disclosed embodiments improve upon the prior art by allowing verification of shared queue objects without requiring direct insertion of lock implementations and duplication of lock-related proofs. The following non-limiting example demonstrates the use of a concurrency abstraction layer to verify a shared queue module that uses fine-grained locks.
[0138] To L q Function promotion of [c]
[0139] In this non-limiting example, the shared queue is implemented as a doubly linked list and is protected by a spin lock. For example, a dequeue (deQ) operation first acquires the spin lock associated with queue i, then performs the actual dequeue operation in a critical state, and finally releases the lock. Consistent with the disclosed embodiment, deQ can be verified by verifying an intermediate function deQ_t that contains code to perform the dequeue operation on a local copy, under the assumption that the corresponding lock is maintained. Since no environment query is required in a critical state, building a concurrent layer for deQ_t is similar to building a sequential layer. The abstract states a.tcbp and a.tdqp can represent an array of thread control blocks (i.e., tcb) and an array of thread queues. The abstract tdqp can be a partial mapping from queue indices to abstract queues, which can be represented as a list of tcb indices. Consistent with the disclosed embodiment, deQ_t can be shown to satisfy its specification σ deQ_t ,like Figure 11 shown.
[0140] To L q_high [c] function improvement and log improvement
[0141] Consistent with the disclosed embodiments, the deQ function wrapping deQ_t with a lock primitive can be shown to satisfy the atomic interface. Using the analog relation R that merges two queue-related lock events (i.e., c.acq and c.rel) into a single event c.deQ at a higher layer lock , it can be shown that Figure 13G Simulation of the strategy depicted in .
[0142] Building a multi-threaded layer for authentication
[0143] Multithreaded programs must handle interleaving triggered not only by the hardware scheduler but also by explicit calls to thread scheduling primitives. The disclosed embodiments include a layer that handles authentication of scheduling primitives, an improved method for equipping thread-local layer interfaces with combining rules, and a thread-safe compiler.
[0144] 4.1 Layers for Authentication of Scheduling Primitives
[0145] Consistent with the disclosed embodiment, the shared thread queue can support a multi-threaded layer interface L btd [c] At this layer interface, transitions between threads can be made using scheduling primitives implemented in a mix of C and assembly.
[0146] In a multithreaded setup, each CPU c has a dedicated ready queue (rdq) and a shared pending queue (pendq) containing threads awakened by other CPUs. A thread yields to move the first pending thread from pendq to rdq, and then switches to the next ready thread. The setup can also include one or more shared sleep queues (slpq). When a sleeping thread is awakened, if the thread belongs to the currently running CPU, it is directly appended to the ready queue. Otherwise, the sleeping thread is appended to the pending queue of the CPU to which it belongs.
[0147] Thread switching can be implemented by the context switch function cswitch, which saves the kernel context of the current thread (e.g., ra, ebp, ebx, esi, edi, esp discussed above) and loads the context of the target thread. Since this cswitch (called by yield and sleep) does not meet the C calling convention, it can only be implemented at the assembly level. Scheduling primitives such as yield can first query E to update the log, append its own events, and then call cswitch to transfer control, such as Figure 14A shown.
[0148] In some embodiments, this layer interface can introduce three new events: c.yield, c.sleep(i,lk) (sleep on queue i while holding lock lk), and c.wakeup(i) (wake up queue i). These events record thread switches, which can be used to replay the thread through the replay function. To keep track of the currently running thread.
[0149] 4.2 Multithreading Layer Interface
[0150] CPU local interface L btd[c] can be configured to capture the execution of the entire set of threads of CPU c and does not support thread-local verification. The disclosed embodiments can improve upon existing approaches by permitting formal reasoning about each thread separately and subsequent combination of proofs to obtain global properties. Such improvements can be achieved by introducing a new layer interface that is combinatorial and focuses only on a subset of the threads running on CPU c.
[0151] Let T c Represents the entire set of threads running on CPU c. Based on L[c], a multi-threading layer interface can be constructed The multithreading layer interface can be used in the focused thread set is parameterized. Except for T A In addition, the policies of other threads running on c form the thread context ε t The dependency conditions of the multi-threaded layer interface are expressed as ε t Valid set extension And ensure that the condition is T A The invariants maintained by the threads in the Since the machine model does not allow preemption, ε is only queried during the execution of scheduling primitives. t ,This scheduling primitive has two behaviors depending on whether the target thread is focused.
[0152] In a non-limiting example, consider Figure 14B As shown in T A = {0, 1}. Whenever the execution switches (by yielding or sleeping) to T A External threads (i.e. Figure 14B When the yellow yield in the figure appears, execution takes the environment step (i.e., inside the red box), repeatedly passing the context ε and thread context ε to the environment. t Returned events are appended to the log until the c.yield event indicating that control has been switched back to the focused thread. Whenever execution switches to the focused thread (i.e., the blue yield above), it will execute without asking ε / ε t Context switching is performed in the absence of a context switch, and its behavior is the same as L btd [c] behaves the same way.
[0153] Combining multithreaded layers
[0154] Consistent with the disclosed embodiments, multi-threaded layer interfaces with disjoint focused thread sets can be combined in parallel (using the extended Pcomp rule) if the guarantee conditions imply dependency conditions for each thread. The resulting focused thread set is the union of the combined thread sets, and some environment steps are "replaced" by local steps of another thread set. For example, if Figure 14CUsing thread 2 and T A , then the yield of thread 0 will then cause a switch to the focused thread. In this example, the t The generated event list l1 can be divided into two parts: l 1a c.yield (generated by thread 2) and l 1b (Consists of events from threads other than {0, 1, 2}).
[0155] Multithreaded Linking
[0156] When the entire T c When L is focused, all scheduling primitives fall into the second case and never switch to those that are not focused. Consistent with the disclosed embodiment, the scheduling behavior is equal to L btd[c] By introducing L btd[c] Multithreading layer interface L for all primitives htd [c][T c ], we can prove the following multi-threaded link theorem:
[0157] L btd [c]≤id L htd [c][T c ]
[0158] This theorem guarantees that once the L htd [c][T c ]'s multithreaded machine captures the entire set of threads, and the properties of the threads running at the top can be propagated down to the layer with the specific scheduling implementation.
[0159] 4.3 Thread Local Interface
[0160] If the multithreaded interface L[c][t] focuses only on a single thread t∈T c , the yield primitive and the sleep primitive always switch to the unfocused thread, and then repeatedly query ε and ε t , until it returns to t, such as Figure 14D shown.
[0161] Program specifications consistent with the disclosed embodiments are termination sensitive. Thus, the disclosed embodiments enable proof that control returns to a focused set of threads, thereby improving upon existing analysis techniques. In some aspects, the proof may rely on assumed fairness of the software scheduler r and the requirement that each running thread relinquish the CPU within a finite number of steps. Since the scheduling primitives always end up switching back to the same thread, L[c][t] may be described as a "thread-local" layer interface. In this way, the scheduling primitives do not modify the kernel context (i.e., ra, ebp, ebx, esi, edi, esp) and effectively act as a "no-op" with respect to the thread unless the shared log is updated. In this way, the scheduling primitives may satisfy the C calling convention.
[0162] 4.4 Queue Lock
[0163] Consistent with the disclosed embodiments, a queued lock (as described above) can be built on top of the thread local interface. Figure 12 In some embodiments, the queue lock can be configured to put waiting threads to sleep to avoid busy spinning. In some embodiments, the C implementation of the queue lock can use spin locks and low-level scheduler primitives (i.e., sleep and wakeup). The verification task can be decomposed into L htd [c][t]The above multiple layers are used to complete the formal verification of the queue lock.
[0164] Consistent with the disclosed embodiments, the correctness properties of a queued lock can be composed of two parts: mutual exclusion and starvation freedom. Figure 12 (shown) can be mutually exclusive because the busy value of the lock (ql_busy) is always equal to the thread ID of the lock holder. In this non-limiting example, the busy value can be set by the lock requester when there is no lock ( Figure 12 6), or set by the previous lock holder when the lock is released (line 12). Through the atomic interface of the spinlock, the starvation-free proof of the queued lock can be partially established by proving the termination of the sleep primitive call (line 4). Since all lock holders will eventually release the lock, all sleeping threads will be added to the pending queue or ready queue within a finite number of steps. Therefore, due to the fair software scheduler, the sleep will terminate. Note that all of these properties proved at the C level can be propagated down to the assembly level using a thread-safe compiler (e.g., CompCertX, etc.).
[0165] 4.5 Thread-Safe Compilation and Linking
[0166] The disclosed embodiments include a compiler (e.g., a separate compiler verified by CompCertX) adapted to process programs that call dispatch primitives. As described above, the disclosed embodiments use a thread-native layer interface to assign C-style specifications to dispatch primitives (yield and sleep) that are partially implemented in assembly. This enables L htd [c][t] is a formal verification of the code of each thread at the C-style specification level. Then, the individual threads can be combined into L according to the multithreaded chaining theorem disclosed above. btd [c] on the program.
[0167] The disclosed embodiments also include a memory model that ensures that the compiler at the assembly level meets the assumptions of the parallel combination rules discussed herein. Whenever a function is called, an existing compiler (e.g., CompCert, etc.) can allocate a new block of memory for its stack frame. Thus, at the thread local level L htd [c][t] Above, a function called within a thread may have its stack frame allocated as thread-private memory state, and conversely, the thread is never aware of any newer memory blocks allocated by other threads. However, in L btd [c] All stack frames must be allocated in CPU local memory (i.e., thread shared memory), regardless of which thread they belong to. Therefore, all such stack frames must be accounted for in the thread composition proof.
[0168] The disclosed embodiment solves this problem by removing the memory extension of access permissions for some memory blocks. Consistent with the disclosed embodiment, the semantics of the thread-local yield primitive are modified so that it allocates enough empty memory blocks as placeholders for the stack frames of other threads. These empty blocks lack access permissions. Denote the total number of blocks in m when the memory is extended from m by allocating n new empty blocks as nb(m) and liftnb(m,n), for each thread i and its thread-local memory m i , maintenance liftnb(m i ,nb(m)-nb(m i ))Memory extension between thread shared memory state m.
[0169] The disclosed embodiment includes a ternary relationship between the private memory states m1 and m2 of two disjoint thread sets and the thread-shared memory state m after parallel combination. This relationship satisfies Figure 12The properties in
[15] ensure that the yield primitive is well-behaved. In particular, the condition nb(m1) ≤ nb(m2) ensures that only non-empty memory blocks are allocated in the memory state of the focused thread, thus guaranteeing that all new memory blocks created between when the thread calls yield and when it regains control are allocated by other threads. Lift-L enables disjoint unions to be preserved when a thread yields and regains control (i.e., the private memory states of different threads do not overlap), thereby allocating empty memory blocks in its private memory state m1 to account for blocks allocated by other threads in m.
[0170] Based on the disjoint union of two memory states, then if and only if there exists a memory state m' such that m' is m1, ..., m N-1 and When maintaining a disjoint union of , we use the rules Lift-R and Lift-L to define the private memory states m1, ..., m2 of N threads (on a single processor). N to generalize to N threads.
[0171] 5. Example Implementation
[0172] The disclosed embodiments have implemented the CCAL toolkit in the Coq proof assistant. Figure 14E Presented Figure 2 The number of lines per component in is (in Coq). The auxiliary library contains common strategies and lemmas for 64-bit integers, lists, maps, integer arithmetic, etc.
[0173] The disclosed embodiments have been used to implement, specify, and verify various concurrent programs. Figure 14F Some of the statistics of the components relative to the implementation are presented. For the lock implementations, their source code contains not only the code of the associated functions, but also the data structures and their initialization. In addition to the top-level interface, the specification also contains all specifications used in the intermediate layers. For ticket and MCS locks, the simulation proof column includes a proof of starvation freedom in addition to the correctness proof (about 1500 lines). The gap between the low-level C implementation and the high-level specifications of the locks also contributes to the large proof size of these components. For example, the intermediate specification of the ticket lock uses unbounded integers for the ticket field, while the implementation uses binary integers that wrap around zero. Similarly, the queue is represented as a logical list in the specification, while the queue is implemented as a doubly linked list.
[0174] The proof strategy for concurrent programs is combinatorial. Both ticket locks and MCS locks share the same high-level atomic specification (or strategy) described above. Therefore, lock implementations can be freely interchanged without affecting any proofs in higher-level modules that use the locks. When implementing a shared queue library, the proofs and implementations of the local (or sequential) queue library are also reused. To implement atomic queue objects, local queue operations are simply wrapped with lock acquisition and release statements. Figure 14F As shown, using the verified lock module to build atomic objects such as shared queues is relatively simple and does not require many lines of code. The performance of the ticket lock has been measured on an Intel 4-core i7-2600S (2.8GHz). Implementing the ticket lock resulted in a latency of 35 CPU cycles.
[0175] Consistent with the disclosed embodiments, whenever a new concrete concurrent object implementation is introduced, the concrete concurrent object implementation can be replaced by an abstract atomic object in its overriding interface. All shared abstract states can be represented using a single global log, so the semantics of each atomic method call may require replaying the entire global log to find the return value. Although this framework for handling shared atomic objects may appear inefficient, it enables the application of game semantics ideas and the definition of a common semantics that supports the composition of parallel layers.
[0176] The disclosed embodiments improve concurrent languages that use parallel composition commands to create and terminate new threads by providing thread spawning and joining primitives and assigning each new thread a unique ID (e.g., t, which must be a member of the complete thread ID universe D). Parallel layer composition consistent with the disclosed embodiments can be performed on the entire program P and all members of D. This enables reasoning about the behavior of the current thread over the full policy of the environment (i.e., both past and future events). Even if thread t is never created, the semantics for running P on L[t] can still be well defined, as it will only always query its environment context to construct a global log.
[0177] Smart Contract Application
[0178] Figure 15An illustrative blockchain 1500 according to some embodiments is shown. In this example, blockchain 1500 includes a plurality of blocks 1500-0, 1500-1, 1500-2, etc., where each block may include a hash, a timestamp, and transaction data. The timestamp may indicate the time when the corresponding block was created, and the transaction data may represent one or more transactions to be recorded on blockchain 1500. With the exception of block 1500-0 (which is sometimes referred to as the genesis block), the hash in each block may be a cryptographic hash of the previous block in blockchain 1500. In some embodiments, the cryptographic hash function used to hash a block can be deterministic (i.e., given the same input, the cryptographic hash function returns the same output) and can be selected such that: given a particular output, recovering the input used to generate the output or another input that hashes to the same output is computationally intensive (e.g., the amount of computation required to recover the input grows faster than any polynomial function in the size of the output); finding two different inputs that result in the same output is computationally intensive (e.g., the amount of computation required to find such a collision grows faster than any polynomial function in the size of the output); and / or a small change to the input (e.g., changing one bit) results in a significant change to the corresponding output (e.g., more than half of the output bits change). In this way, attempts to modify a block can be detected by comparing the result of hashing the block with the hash stored in a subsequent block. For example, to modify block 1500-0 without being detected, an attacker would also have to modify the hash stored in block 1500-1, which in turn would require modifying the hash stored in block 1500-2, and so on. Therefore, as more blocks are added to blockchain 1500, it may become increasingly difficult for an attacker to modify earlier blocks. In some embodiments, a distributed computing platform may be provided by a network of one or more nodes that collectively maintain the blockchain and / or execute one or more smart contracts stored on the blockchain. For example, software code and / or state information associated with a smart contract may be stored on the blockchain and accessed from the blockchain using a specific address. The execution of the software code may be triggered by an event and may result in a change in the state of the smart contract. This may be recorded as a transaction on the blockchain. In this way, the smart contract and / or its execution history may be tamper-proof.
[0179] Figure 16An illustrative node 1600 participating in a distributed computing platform for executing smart contracts, according to some embodiments, is shown. In this example, node 1600 includes a virtual machine 1620, an operating system 1625, and hardware 1630. Virtual machine 1620 can provide an execution environment for smart contracts and can isolate smart contracts from other processes executing on node 1600. Operating system 1625 can provide various services to virtual machine 1620, including, but not limited to, scheduling access to hardware 1630. Hardware 1630 can include one or more processors, memory, input devices, output devices, network interfaces, and the like. For example, node 1600 can use a network interface to communicate with one or more other nodes also participating in the distributed computing platform. In some embodiments, compiler 1610 can be configured to compile the source code 1605 of the smart contract into bytecode 1615, which can be loaded into virtual machine 1620 for execution. For example, virtual machine 1620 can include an interpreter programmed to interpret bytecode 1615. The inventors have recognized and appreciated that the correctness of smart contracts can be formally verified using one or more of the techniques described in detail above. For example, a set of one or more smart contracts can be verified as a concurrent abstraction layer, where the blockchain used to record transactions can be modeled as a global log.
[0180] Figure 17An illustrative concurrency abstraction layer 1700 according to some embodiments is shown. In this example, the concurrency abstraction layer 1700 includes a layer implementation M, an overlay interface L, and an underlying interface L'. The layer implementation may include multiple smart contracts 1705A, 1705B, 1705C, etc. These smart contracts can interact with each other and / or with one or more other smart contracts. For example, one or more lower-level smart contracts 1710 may provide one or more lower-level functions that the smart contracts 1705A, 1705B, 1705C, etc. can access via the underlying interface L'. Utilizing the one or more lower-level functions provided by the one or more lower-level smart contracts 1710, the smart contracts 1705A, 1705B, 1705C, etc. may provide one or more higher-level functions to one or more higher-level smart contracts 1715 via the overlay interface L. The inventors have recognized and appreciated that one or more of the techniques described in detail above can be used to verify that smart contracts 1705A, 1705B, 1705C, etc., running on top of the underlying interface L' simulate an overlay interface L. For example, in some embodiments, a first logical global log can be used to model the underlying blockchain used to record transactions executed by smart contracts (e.g., smart contracts 1705A, 1705B, 1705C, etc.), and one or more of the techniques described in detail in the attached manuscript can be used to verify that the first logical global log is consistent with a second logical global log that represents acceptable behavior.
[0181] Figure 18An illustrative physical blockchain 1800 and an illustrative logical blockchain 1805 are shown, according to some embodiments. Physical blockchain 1800 may represent a logical global log of the underlying blockchain used to record transactions executed by smart contracts (e.g., illustrative smart contracts 1705A, 1705B, 1705C, etc.), and may include a series of lower-level transactions LT0, LT1, LT2, etc. Logical blockchain 1800 may be another logical global log that includes a series of higher-level transactions HT0, HT1, HT2, etc. In some embodiments, verification of smart contracts 1705A, 1705B, 1705C, etc., running on underlying interface L', simulating overlay interface L, may include verifying that physical blockchain 1800 is consistent with logical blockchain 1805. As an example, lower-level transactions LT0 and LT1 may collectively correspond to higher-level transaction HT0. For example, a higher-level transaction HT0 may be a transfer from a first party to a second party and may be implemented by the first party initiating the transfer (lower-level transaction LT0) and the second party confirming the transfer (lower-level transaction LT1). As another example, a lower-level transaction LT2 may be a context transition, which may represent an action taken by a smart contract that is concurrently executing as a smart contract 1705A, 1705B, 1705C, etc. in a lower-level context. The lower-level transaction LT2 may correspond to the higher-level transaction HT2, which may represent an action taken by the smart contract in the corresponding higher-level context. As another example, a lower-level transaction LT3 may represent an action taken by one or more lower-level smart contracts 1710 that is unrelated to any lower-level functionality provided to smart contracts 1705A, 1705B, 1705C, etc. Thus, there is no corresponding higher-level transaction in the logical blockchain 1800. As another example, a higher-level transaction HT2 may represent a higher-level function provided by one of smart contracts 1705A, 1705B, 1705C, etc. to one or more higher-level smart contracts 1715 by calling a lower-level function provided by one or more lower-level smart contracts 1710. This lower-level function may be represented by a lower-level transaction LT4. In some embodiments, verification of a simulated overlay interface L of smart contracts 1705A, 1705B, 1705C, etc. running on top of underlying interface L' may include verifying that, given an environment in which smart contracts 1705A, 1705B, 1705C, etc. are executed, and given a physical blockchain and a corresponding logical blockchain, one or more lower-level transactions to be attached to the physical blockchain can be matched with one or more higher-level transactions to be attached to the logical blockchain. Such an environment may capture one or more assumptions about one or more smart contracts executing simultaneously as smart contracts 1705A, 1705B, 1705C, etc.The inventors have recognized and appreciated the various benefits of validating one or more smart contracts as a concurrent abstraction layer. For example, using one or more of the techniques described in detail above, a complex system executing smart contracts simultaneously can be decomposed into multiple layered components. These components can be formally specified and verified separately, and then linked together to form an end-to-end, fully verified system. Such a verified system is attack-resistant because it is likely to be free of vulnerabilities. For example, at any point during execution, the software implementation can be consistent with the formal specification. In some embodiments, a logical global log can be used to model a blockchain that records every transaction executed by any of multiple smart contracts. The formal semantics of the smart contract can be provided to the sequence of one or more transactions executed by the smart contract (before switching to another smart contract) based on functions from the logical global log. In some embodiments, multiple smart contracts can be combined into a system using horizontal and / or parallel composition. For example, the behavior of a smart contract can be verified based on one or more assumptions about the behavior of one or more other smart contracts executing concurrently with the smart contract being verified, and the one or more assumptions can be modeled using the environment. In some embodiments, multiple smart contracts can be combined into a system using vertical composition. For example, a new abstraction layer can be built on top of an existing smart contract (e.g., by hiding one or more lower-level transactions and / or introducing one or more higher-level transactions). Thus, a new type of logical global log can be provided for each new abstraction layer. In some embodiments, consistency between these global logs can be verified by establishing a simulated relationship between the logical global logs at different abstraction layers and the corresponding environments. For example, environments at different abstraction layers can be connected, and smart contracts at different abstraction layers can be combined based on the corresponding environments. In this way, vertical combination of smart contracts can be supported in addition to or in lieu of horizontal and / or parallel combination. In some embodiments, an environment can indicate the past and / or future behavior of one or more smart contracts that are executed concurrently with the smart contract to be verified. In this way, one or more fairness constraints can be imposed on the future behavior of one or more smart contracts in the environment, and one or more process properties can be verified in addition to or in lieu of functional correctness properties. In some embodiments, each layer module can be formally verified to correctly implement an overlay interface based on the underlying interface. The specification of the overlay interface can indicate how to construct the logical global log for the overlay interface and / or what environment to consider. Similarly, the specification of the underlying interface can indicate how to construct the logical global log for the underlying interface and / or what environment to consider.Formal simulation relationships can then be established to connect the environment, one or more abstract states, and / or logical global logs of the overlay interface with the environment, one or more abstract states, and / or logical global logs of the layer modules running on top of the underlying interface. In some embodiments, a formal proof can be constructed to show that the simulation relationship is valid at the beginning of each method call to the method in the layer module to be verified and is retained during the execution of each statement in the layer module. In some embodiments, after verifying each layer module, the layer module can be compiled into an assembly layer (e.g., using a verified compiler). The assembly layers can then be combined using horizontal, parallel, and / or vertical combination rules to form a system. In some embodiments, one or more formal specifications and / or proofs include one or more explicit artifacts stored on a hard disk or in a memory that can be independently checked by a third party.
[0182] Figure 19 An illustrative computer 1900 is schematically shown upon which any aspect of the present disclosure may be implemented. Figure 19 In the embodiment shown in , the computer 1900 includes a processing unit 1901 having one or more processors and a non-transitory computer-readable storage medium 1902, which may include, for example, volatile and / or non-volatile memory. The memory 1902 may store one or more instructions for programming the processing unit 1901 to perform any of the functions described herein. The computer 1900 may also include other types of non-transitory computer-readable media in addition to the system memory 1902, such as storage devices 1905 (e.g., one or more disk drives). The storage device 1905 may also store one or more application programs and / or external components used by the application programs (e.g., software libraries), which may be loaded into the memory 1902. The computer 1900 may have one or more input devices and / or output devices, such as Figure 19 1906 and 1907 shown in . These devices may be used, among other things, to present a user interface. Examples of output devices that may be used to provide a user interface include a printer or display screen for visual presentation of output and a speaker or other sound generating device for audible presentation of output. Examples of input devices that may be used for a user interface include a keyboard and pointing devices, such as a mouse, touchpad, and digitizer. As another example, the input device 1907 may include a microphone for capturing audio signals, and the output device 1906 may include a display screen for visually presenting recognized text and / or a speaker for audibly presenting recognized text. Figure 19As shown, computer 1900 may also include one or more network interfaces (e.g., network interface 1910) to enable communication via various networks (e.g., network 1920). Examples of networks include local area networks or wide area networks, such as enterprise networks or the Internet. Such networks can be based on any suitable technology and can operate according to any suitable protocol, and can include wireless networks, wired networks, or fiber optic networks. Although several aspects of at least one embodiment have been described in this manner, it should be appreciated that those skilled in the art will readily conceive of various changes, modifications, and improvements. Such changes, modifications, and improvements are intended to fall within the spirit and scope of the present disclosure. Therefore, the above description and accompanying drawings are intended to be examples only. The above-described embodiments of the present disclosure may be implemented in any of a variety of ways. For example, the embodiments may be implemented using hardware, software, or a combination thereof. When implemented in software, the software code may be executed on any suitable processor or set of processors, whether located in a single computer or distributed across multiple computers. In addition, the various methods or processes outlined herein may be encoded as software that can be executed on one or more processors using any of a variety of operating systems or platforms. In addition, such software can be written using any programming language and / or programming tool or scripting tool in many suitable programming languages and / or programming tools or scripting tools, and can also be compiled into executable machine language code or intermediate code executed on a framework or virtual machine. In this respect, the concept disclosed herein can be implemented as a non-transient computer-readable medium (or multiple computer-readable media) (for example, a computer memory, one or more floppy disks, compact disks, optical disks, tapes, flash memories, circuit configurations in field programmable gate arrays or other semiconductor devices or other non-transient tangible computer storage media) encoded with one or more programs, one or more programs when executed on one or more computers or other processors to implement the methods of the various embodiments of the present disclosure described above. One or more computer-readable media can be transportable so that one or more programs stored thereon can be loaded onto one or more different computers or other processors to implement various aspects of the present disclosure as discussed above. The term "program" or "software" is used herein to refer to any type of computer code or a set of computer-executable instructions, which can be used to program a computer or other processors to implement various aspects of the present disclosure as discussed above. In addition, it should be recognized that, according to one aspect of the present embodiment, one or more computer programs that perform the methods of the present disclosure when executed need not reside on a single computer or processor, but can be distributed in a modular manner among many different computers or processors to implement various aspects of the present disclosure.Computer-executable instructions can take many forms, such as program modules executed by one or more computers or other devices. Typically, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. Generally, the functions of program modules can be combined or dispersed as needed in various embodiments. In addition, data structures can be stored in computer-readable media in any suitable form. To simplify the description, data structures can be shown as having fields that are related by their position in the data structure. Such relationships can also be achieved by allocating storage for the fields, which has locations in the computer-readable medium that convey the relationship between the fields. However, any suitable mechanism (including by using pointers, tags, or other mechanisms that establish relationships between data elements) can be used to establish the relationship between the information in the fields of the data structure. The various features and aspects of the present disclosure can be used alone, in any combination of two or more, or in a variety of arrangements not specifically discussed in the aforementioned embodiments, and therefore their application is not limited to the details and arrangements of the components set forth in the preceding description or shown in the accompanying drawings. For example, aspects described in one embodiment can be combined in any way with aspects described in other embodiments. In addition, the concepts disclosed herein can be implemented as methods that provide examples thereof. The actions performed as part of the method can be sorted in any suitable manner. Therefore, an embodiment in which the actions are performed in an order different from the order shown can be constructed, which can include performing some actions that are shown as sequential actions in the illustrative embodiment simultaneously. The use of ordinal terms such as "first", "second", "third", etc., used to modify claim elements in the claims, does not itself mean that a claim element has any priority, precedence or sequence relative to another claim element or the time sequence of the action of the method of execution, but is only used as a mark for distinguishing a claim element with a certain name from another element with the same name (if no ordinal terms are used) to distinguish the claim elements. In addition, the wording and terms used in this article are for descriptive purposes and should not be considered as limiting. "Include", "comprise", "contain", "have", "contain", "involve" and variations thereof are used herein to mean the items listed thereafter and their equivalents, as well as other items.
Claims
1. A method for formal verification of coverage interfaces, include: Modeling the overlay interface as multiple layer implementations built on an underlying interface, the underlying interface parameterized by multiple thread sets; Verify the overlay interface by performing at least one of the following: Verify that the mapping to programs built on the underlying interface implements the mapping to the policy, where: The semantics of operating shared primitives on the underlying interface are emulated by the policy; Verifying that the first program module implements the coverage interface according to the first simulation relationship, wherein: A second program module constructed on the bottom layer interface implements the first intermediate interface according to a second simulation relationship; A third program module constructed on the first intermediate interface implements the overlay interface according to a third simulation relationship; and The first program module is a combination of the second program module and the third program module, and the first simulation relationship is a combination of the second simulation relationship and the third simulation relationship; Verify that the fourth program module implements the coverage interface according to the fourth simulation relationship, wherein: A fifth program module constructed on the bottom layer interface realizes a second intermediate interface according to the fourth simulation relationship; A sixth program module constructed on the bottom layer interface implements a third intermediate interface according to the fourth simulation relationship; and The fourth program module is a combination of the fifth program module and the sixth program module, and the overlay interface is a combination of the second intermediate interface and the third intermediate interface; Verify that the seventh program module built on the fourth intermediate interface implements the fifth intermediate interface according to the fifth simulation relationship, wherein: The fourth intermediate interface is simulated by the bottom layer interface according to a sixth simulation relationship; The seventh program module implements the coverage interface according to the seventh simulation relationship; The overlay interface is simulated by the fifth intermediate interface according to an eighth simulation relationship; and The fifth simulation relationship is a combination of the sixth simulation relationship, the seventh simulation relationship and the eighth simulation relationship; Verifying that an eighth program module built on the underlying interface implements the overlay interface, wherein: The underlying interface is parameterized by the union of the first thread set and the second thread set; The overlay interface is parameterized by the union of the first thread set and the second thread set; A first underlying interface is parameterized by the first set of threads, and a second underlying interface is parameterized by the second set of threads; A first overlay interface is parameterized by the first set of threads, and a second overlay interface is parameterized by the second set of threads; The eighth program module constructed on the first underlying interface implements the first overlay interface; The eighth program module constructed on the second underlying interface implements the second overlay interface; The first underlying interface is compatible with the second underlying interface; and The first overlay interface is compatible with the second overlay interface; and Verify that an interface parameterized by a third thread set is compatible with an interface parameterized by a fourth thread set, where: For all threads in the third thread set, the dependency condition of the interface parameterized by the fourth thread set means the guarantee condition of the interface parameterized by the third thread set; For all threads in a fourth thread set, the dependency condition of the interface parameterized by the third thread set implies the guarantee condition of the interface parameterized by the fourth thread set; The dependency condition of the interface parameterized by the intersection of the third thread set and the fourth thread set is equal to the union of the dependency condition of the interface parameterized by the third thread set and the dependency condition of the interface parameterized by the fourth thread set; The guaranteed conditions of the interface parameterized by the intersection of the third thread set and the fourth thread set are equal to the intersection of the guaranteed conditions of the interface parameterized by the third thread set and the guaranteed conditions of the interface parameterized by the fourth thread set; and The set of primitives of the interface parameterized by the intersection of the third thread set and the fourth thread set is equal to the combination of the set of primitives of the interface parameterized by the third thread set and the set of primitives of the interface parameterized by the fourth thread set.
2. The method according to claim 1, in, Verifying the overlay interface includes performing at least two of the following: verifying that a mapping to the program built on the underlying interface implements a mapping to the policy; verifying that the first program module implements the coverage interface according to the first simulation relationship; verifying that the fourth program module implements the coverage interface according to a fourth simulation relationship; verifying that the seventh program module constructed on the fourth intermediate interface implements the fifth intermediate interface according to the fifth simulation relationship; verifying that the eighth program module built on the underlying interface implements the overlay interface; and Verifying that an interface parameterized by the third thread set is compatible with an interface parameterized by the fourth thread set.
3. The method according to claim 1, in, Verifying the overlay interface includes performing at least three of the following: verifying that a mapping to the program built on the underlying interface implements a mapping to the policy; verifying that the first program module implements the coverage interface according to the first simulation relationship; verifying that the fourth program module implements the coverage interface according to a fourth simulation relationship; verifying that the seventh program module constructed on the fourth intermediate interface implements the fifth intermediate interface according to the fifth simulation relationship; verifying that the eighth program module built on the underlying interface implements the overlay interface; and Verifying that an interface parameterized by the third thread set is compatible with an interface parameterized by the fourth thread set.
4. The method according to claim 1, in, Verifying the coverage interface involves performing all of the following: verifying that a mapping to the program built on the underlying interface implements a mapping to the policy; verifying that the first program module implements the coverage interface according to the first simulation relationship; verifying that the fourth program module implements the coverage interface according to a fourth simulation relationship; verifying that the seventh program module constructed on the fourth intermediate interface implements the fifth intermediate interface according to the fifth simulation relationship; verifying that the eighth program module built on the underlying interface implements the overlay interface; and Verifying that an interface parameterized by the third thread set is compatible with an interface parameterized by the fourth thread set.
5. The method according to any one of claims 1 to 4, in, Verifying the overlay interface includes: after verifying that the first program module implements the overlay interface according to the first simulation relationship, performing thread-safe compilation.
6. The method according to any one of claims 1 to 4, in, Modeling the overlay interface includes modeling a scheduler using a fair scheduler policy.
7. The method according to any one of claims 1 to 4, in, Modeling the overlay interface includes requiring exact actions.
8. The method according to any one of claims 1 to 4, in, Modeling the overlay interface includes modeling an environmental context that specifies past events and future events.
Citation Information
Patent Citations
Multiplexing intelligent card formal modeling and validation method
CN103559238A
Coq-based MSVL program verification method
CN106708525A
Industrial automation visualization schemes employing overlays
US20100079488A1
Automated verification of a type-safe operating system
US20100192130A1
