1. Introduction
With the introduction of Bitcoin [
1] in 2008, blockchain came into the limelight as a distributed, asymmetric encrypted peer-to-peer network. Bitcoin transactions rely on Bitcoin scripts to take place on a decentralized peer-to-peer network. Bitcoin scripts are a stack-based, non-Turing-complete scripting language that defines the basic rules of Bitcoin transactions and is the prototype of a blockchain smart contract. Since then, a number of decentralized cryptocurrencies, typified by Bitcoin, have enabled the use of blockchain in finance. In 2015, Ethereum [
2] was launched, which is the first blockchain platform supporting Turing-complete language programming. Ethereum users can write smart contracts in languages such as Solidity to automate the transaction process. Subsequently, platforms such as Hyperledger [
3] and EOS [
4] were released, and their common feature is that they rely on smart contracts to automate interactions between nodes on a decentralized/weakly centralized peer-to-peer network. Thanks to Turing-complete language programming, such interactions are capable of handling computations of almost arbitrary complexity.
With the introduction of smart contracts, blockchain is no longer limited to the financial sector but is also used in the Internet of Industry [
5], logistics [
6], healthcare [
7], legal [
8], vulnerability detection [
9], privacy protection [
10], and other fields [
11], showing great application value. One emerging application area is the coordination of drone swarms. Drone swarms, consisting of multiple autonomous drones working together, require secure and reliable decentralized coordination to efficiently carry out tasks such as surveillance, search and rescue, or delivery services. Smart contracts can be leveraged in this context to automate and manage the interactions between individual drones, ensuring that certain conditions, such as task allocation, communication protocols, and resource sharing, are executed without central authority. By applying blockchain-based smart contracts, the operations of drone swarms become tamper-proof and can execute autonomously based on predefined rules, improving operational transparency, security, and fault tolerance in dynamic and potentially adversarial environments.
In order to better realize the application of blockchain technology in combination with traditional industries, more and more researchers [
12,
13,
14] have focused their work on smart contracts themselves in recent years.
A smart contract is defined as a computer program running in a distributed system whose rules are pre-set and whose states are conditionally correlated to facilitate the exchange of information, value, and asset ownership among distributed nodes, and that can encapsulate, verify, and execute complex behaviors [
15]. Zheng [
16] assumes that the smart contract life cycle is divided into four stages: creation, deployment, execution, and completion. A life-cycle approach to understanding smart contracts can assist in gaining a more thorough understanding of how they work. At present, the main research directions around smart contracts in academia are smart contract security issues [
17,
18,
19], smart contract applications [
20,
21], mechanism design [
22,
23], and formalization [
24].
Among these, formalization includes formal specification and formal verification, two important research elements. Formal research on smart contracts is a mathematical description of what a smart contract is and what it does, which can solve a series of problems such as functional verification, privacy, security, scalability, bug bounties, the Oracle problem, blockchain consensus, etc. [
25]. Existing research on the formalization of smart contracts has focused on formal verification, i.e., formal tools/frameworks to help troubleshoot vulnerabilities in smart contracts and reduce the risk of malicious attacks. However, few studies have analyzed the state migration of smart contracts from a microscopic perspective, resulting in a lack of detail on the internal execution logic of smart contracts, which makes it difficult to effectively supervise the process of contract execution as a black box.
At the same time, most of the existing formal models of smart contracts are based on specific application areas, with insufficient abstraction and a lack of generality to provide theoretical support for general research on smart contracts. Therefore, this paper analyzes the internal execution logic of smart contracts based on finite state automata and a conditional response mechanism and proposes a general formal model of smart contracts, the Variable-State-Trigger (VST) model, which is shown in
Figure 1. More importantly, this paper introduces the application of the VST model in the field of lightweight communication for drones, and will focus on introducing an intelligent contract for drone communication, created based on the VST model in the sixth part. This work is pioneering in the field of drone communication and formalization of smart contracts. The contributions of this paper are as follows.
Contributions:
This paper innovatively combines theorem proving and finite state automata to describe smart contracts. In general, finite state automata can clearly express the state migration process of smart contracts. Microscopically, the conditional trigger mechanism of smart contracts can be explained by means of theorem proof.
This paper represents the smart contract conditional response mechanism based on the graph structure, so as to modularize the smart contract so that it can be used for smart contract supervision, vulnerability detection, etc.
This paper expounds on the formal role of the proposed VST model in the practical application field of drone communication, which is innovative.
This paper is structured as follows:
Section 2 lists the existing research on the formalization of smart contracts;
Section 3 defines smart contracts formally and gives the basic definition of the VST model;
Section 4 analyzes the micro-conditional response mechanism;
Section 5 uses a rigorous mathematical proof method to verify the true property of the VST model; and
Section 6 takes a UAV mission contract written in natural language as an example and analyzes the VST model’s ability to interpret real contracts and verify its feasibility.
3. VST Model Overview
In this section, we introduce a conditional response mechanism based on finite state automata to describe the dynamic process of state migration of smart contracts from a microscopic perspective. The Variable-State-Trigger (VST) model is a formal specification of the smart contract and describes three core properties of the smart contract: Variable, State, and Trigger. The parameters involved in the VST model are shown in
Table 1.
The environment, V, in which the smart contract, C, is located can be quantified as a -dimensional vector, and each component, , is called an environment variable. The smart contract, C, is subjected to changes in the environment variables and undergoes state migration in a finite state space, S, which contains instantaneous states. are sets of indicators for the environment, V, and state set, S, respectively. The conditional response mechanism, T, consists of modules , is a directed acyclic graph consisting of vertices, t, and edges, e, and X is the set of indicators of T.
Definition 1. Smart Contract, C
A smart contract is a triple consisting of:
A vector ;
A set ;
A set , .
In Definition 1, the environment variable, , is a component of the multidimensional vector V. The state is a function on V, using to denote a particular environment that induces the state . The trigger, , is represented by the binary , in the sense that the variable environment is , and the instantaneous state of the smart contract, C, is represented as . The conditional response path, , is a directed edge from vertex to vertex in the directed acyclic graph , in the sense that the trigger condition occurs only if the trigger condition has already occurred.
Definition 2. The environment of a smart contract, C, can be quantified as a multidimensional vector , where each component, , is called an environmental variable.
To explain more concretely the environment of the smart contract,
C, the multidimensional vector
can be represented by a data table, as shown in
Table 2. For each component,
, in addition to symbols and key-value pairs, it also has meta-attributes: key variable/dummy variable.
Definition 3. States
The value range of the function is .
The state set, S, consists of |j| instantaneous states, ; “states” contain two forms: stable states and intermediate states. The stable states include the initial state, , the completion state, , and the failure state, ; The intermediate states include the success state, , and the default state, . The value of any instantaneous state, , is equal to some steady state or intermediate state, but the environment, , that induces different instantaneous states varies.
There are intra-state migration and inter-state migration in the VST model, as shown in
Figure 2.
Definition 4. Inter-state migration
If satisfies , this migration process → is called inter-state migration.
The reason for the above two different forms of state migration is that there are several key variables and key points in the multidimensional vector , there are several key variables and corresponding key points, and inter-state migration is caused when and only when the value of the key variables changes to the key point; otherwise, only intra-state migration is caused. In other words, the intra-state migration is related to all variables in the multidimensional vector V, while the inter-state migration is only related to the key variables in the multidimensional vector V.
Definition 5. Key variables
If a change in the value of one or more components of a vector causes inter-state migration, then these components are called key variables, i.e., if satisfies , then is called a key variable.
Definition 6. Dummy variables
If any change in the value of one or more components of a vector does not cause inter-state migration, then these components are called dummy variables, i.e., if satisfies , then is called a dummy variable.
It is worth noting that the range of key variables and dummy elements changes dynamically with the state migration of the smart contract. That is, at state , it is assumed that is the key variable that affects the migration of the current state to the next state, but when the state migrates to , no longer affects the future state migration, i.e., the dummy element.
Definition 7. key points and key set
If a change in the value of a key variable reaches a certain point and causes inter-state migration, then this point is called a key point, and the set of these key points is called a key set, i.e., when satisfies , is a key variable in V, if satisfies , then p is called a key point, and the set of values like p is called a key set.
Definition 8. Legal interval
An interval is called a legal interval if the value of a key variable varying arbitrarily within that interval does not cause the state to migrate from to .
Definition 9. Illegal interval
An interval is called an illegal interval if the value of a key variable changing within that interval causes the state to migrate to .
i.e., when satisfies , is a key variable in , , if an interval A satisfies , , then A is called a legal interval, and its complement set is called an illegal interval.
Stable state. When the execution of the smart contract is completed, the contract migrates to the stable state, i.e., inter-state migration such as occurs. At this point, the environment, V, no longer changes. When the environment, V, of the smart contract, C, no longer changes, C migrates from the intermediate state to the stable state: if the instantaneous state and the stable state , the contract, C, executes successfully; if the instantaneous state and the stable state , the execution of the contract, C, fails. The migration of a smart contract, C, from an intermediate state to a stable state still follows the conditions of inter-state migration. This process has a special key variable, , whose role is to listen to whether the environment, V, stops changing, and if the environment, V, stops changing then reaches the key point and causes the inter-state migration, which also marks the contract, C, reaching the stable state.
Definition 10. Conditional response mechanism
The conditional response mechanism, T, of the smart contract, C, consists of several conditional response modules, , and each module, , is a directed acyclic graph, including the vertex set, τ, and the edge set, E, where the vertex set contains the following vertex types.
;
;
;
;
.
In Definition 10, the vertices denote the trigger conditions for the stable states , respectively, and the vertices denote the trigger conditions for the intermediate states , respectively.
4. Microscopic Conditional Response
In order to describe the conditional response mechanism of a smart contract from a microscopic perspective, is introduced as a trigger into the VST model. Several triggers, t, and conditional response paths, e, form a directed acyclic graph, , and several directed acyclic graphs, , form the conditional response mechanism of a smart contract, C. Unlike the state migration graphs of finite state automata, there is no loop in the directed acyclic graphs, which can clearly show the start–end, and are more advantageous in describing complex logic structures than the state migration graphs with loops. Statically, T, as a collection of directed acyclic graphs, can clearly and intuitively show the conditional response structure of the contract, C, i.e., the encoding logic; dynamically, the trigger, t, can record the environment, V, when the smart contract, C, reaches the specified state, s, and the dynamic path returns to the user, t, during the contract execution, providing an idea for effective supervision of smart contracts. In this section, we introduce the micro-conditional response mechanism from a syntax-logical structure-modularity writing idea.
4.1. Grammar
Definition 10 introduces five types of triggers t: . Since the conditional response mechanism of a smart contract works mostly in the intermediate state, the contract can be executed properly when and only when , so the form (i denotes a letter or a non-zero number) is used below to refer to , without special specification, and is marked separately.
The meaning of the trigger
is to listen to the address of the smart contract,
C, to see if it receives a call request from the user, and if the user issues a call to
C, then
is triggered and the contract,
C, starts execution. The meaning of the trigger
is that the smart contract,
C, is executed normally and all key variables in the environment,
V, are in the legal interval. As shown in
Figure 3, when
is triggered
, if
is triggered then
cannot be triggered, and no arbitrary
is triggered, meaning that one or some key variables in the environment,
V, change into an illegal interval, and
is triggered, signifying that the smart contract,
C, is temporarily suspended. It is worth noting that each
can point to
,while the
which
points to is not consistent with the
which
points to. Although
is equivalent to
, the key variables of
are partly different from
,which means that the trigger of state migration
is distinct from
(according to Definition 5).
marks the successful execution of a smart contract, C. A smart contract may have multiple clauses, which may be relatively independent of each other or may affect each other. means that, after all the required clauses have been invoked, the environment, V, no longer changes, and the instantaneous state of the smart contract is , and then the contract will migrate to the stable state, .
The meaning of is that the execution of the smart contract, C, ends in failure. After is triggered, if the environment, V, does not change any more, then C will migrate from the hung state, , to the failed state, .
4.2. Logical Structure
Smart contracts are mainly presented in the form of program code, and there are three main logical structures in programming: sequential structure, selection structure, and cyclic structure. Naturally, directed acyclic graphs can describe sequential and selective structures, but not cyclic structures directly. However, the microscopic conditional response mechanism of the VST model can overcome this problem, and the directed acyclic graph, , can explain the loop structure in smart contracts well.
As shown in
Figure 4, when
form a loop structure, there are.
;
;
;
.
It is well known that dead loops are meaningless in computer programming, so any loop structure must have a counter, , to control the number of loops in order to prevent the contract program from falling into a dead loop. Suppose are the key variables of , respectively, then the loop progression between the trigger conditions can be replaced by a trigger condition instead, where are the key variables of the multidimensional vector . In other words, microscopically corresponding to , the migration process between the three instantaneous states can actually be interpreted as an intra-state migration of , which fuses the three instantaneous states.
4.3. Modularization
Definition 11. Dimension
The set of all event parameters of a trigger, t, is called the dimension of t.
Definition 12. Each DAG in a smart contract consisting of consecutive triggers is called a module.
There may be multiple clauses in a smart contract, and the modularity is designed to discuss the possible relationships between the clauses of a smart contract. In a smart contract, the following two relationships between different modules may exist.
Mutually independent:
Module completion does not cause module execution, and module completion does not cause module execution.
Strictly progressive:
Module completion causes module execution, and module completion does not cause module execution.
For convenience, the relationship between module and module can be formalized as if they meet the mutually independent clause. represents the relationship between modules. The relationship between module and module can be formalized as if they meet the strictly progressive clause.
Definition 13. Let the initial vertices of the modules and be and , respectively, and their termination vertices be and , respectively. If the module and the module satisfy: Then the module and the module are said to be mutually independent .
If the module and the module satisfy: Then the module and the module are said to be strictly progressive .
As shown in
Figure 5 and
Figure 6, let the module
start with a green sphere and end with a blue sphere, and the module
start with an orange sphere and end with a yellow sphere. Only the event parameters of each vertex are written in parentheses, and the parameters marked
in red are the key variables of that vertex. As shown in the
Figure 5,
, while
, so the module
and the module
are independent of each other; as shown in
Figure 6,
,
, while
, thus module
and module
are strictly recursive.
The strictly recursive relationship between modules provides feasibility for the implementation of the complementary terms. If satisfy , then is said to be a supplementary clause to , that is, if the relevant clause in is violated, the relevant clause in can be invoked to make the intelligent. The contract can be executed smoothly by calling to migrate its instantaneous state to .
In the module, there is a special existence called the supervision module. The responsibility of the supervision module is to monitor the environment, V, and the state, S, of the smart contract. Assuming there is a key variable time. Once the state of the smart contract is , the smart contract does not migrate to within time, the state of the smart contract migrates to , and the smart contract fails to run. The supervision module can effectively solve the problem that the loss causes by malicious contracts or the vulnerabilities in the contract itself cannot be terminated.
5. Theoretical Analysis
In the previous section, finite state automata are used to illustrate the state transition process of smart contracts from a macro perspective, and the conditional response mechanism is introduced to analyze the reasons for smart contract state transition from a micro perspective. Nevertheless, given the reality property of the VST model, the feasibility of the model needs to be demonstrated. Below we will introduce the theorem of the VST model and give the proof process. In this section, three theorems will be presented. The importance of Theorems 1 and 2 is to explain what is the condition for the state migration of the smart contract. The importance of Theorem 3 lies in proving the completeness of the conditional corresponding mechanism theory.
Theorem 1. A necessary and sufficient condition for the inter-state migration is that the value of at least one key variable changes to an illegal interval.
Proof. Sufficiency
Let the current state be:
Assuming there exists a previous state:
there exists an intra-state migration
. According to Definition 8, there exists a key variable
satisfies
, and
A is a legal interval. Let set
p be a key point and
. According to Definitions 7–9, the two ends of a key point are the legal interval and the illegal interval.
When
, there exists:
the current state
, and there exists a new state
. According to Definition 4, there exists an inter-state migration
.
There exists an inter-state migration , according to Definition 4, there exists key variables.
Assuming no key variables change to a value within an illegal interval, and, according to Definition 6, there exists an intra-state migration .
contradicts ,
, is the illegal interval of a key variable . □
Theorem 2. The inter-state migration happens if and only if the values of all key variables change to values within the legal interval.
Proof. Let us set the current state:
According to Definition 9,
,
is the illegal interval of a key variable
.
Let set
p be a key point and
, when
, there exists:
the current state
, and there exists a new state
. If the status is
, it means that the call to the compensation module failed. Smart contract execution failed.
is a key variable of controlling the inter-state migration
. The other key variables become dummy variables.
If the status is , is a key variable of controlling the inter-state migration . The key variable that controls the inter-state migration becomes a dummy variable.
According to Definition 4, there exists an inter-state migration .
There exists an inter-state migration , and, according to Definition 5, there exists key variables.
Assuming , is the illegal interval of a key variable , according to Definition 9, there exists an intra-state migration .
contradicts ,
And no key variables change to a value within an illegal interval, i.e., the values of all key variables change to within the legal interval.
To sum up, the original proposition holds. □
Theorem 3. There are only two relations between module and module that are mutually independent and strictly recursive.
Proof. Let the initial vertices of module and module be and , respectively, and their end vertices be and . We may wish to list all the combinations to prove them one by one.
Firstly, let the current combination of their relationships be:
The termination node of the current module has the same dimension as the initial vertex of module , and the termination node of module and the initial vertex of module describe the same trigger event. So, the two modules form a huge cyclic graph. For module , it is a one-way path from the initial vertex to the terminal vertex, but since the terminal vertex of module is the initial vertex of module , they will continue to loop, which does not match the actual meaning and does not exist.
Secondly, let the current combination of their relationships be:
Since the termination node of module and the initial node of module have the same dimension, they describe the same event. Therefore, module and module are actually the same module, and there is no relationship between modules.
Finally, let the current combination of their relationships be:
According to the Definition 13, module and module are strictly progressive.
To sum up, the original proposition holds. □
6. Application
In the context of the widespread application of distributed network technology, lightweight blockchain shows unique advantages in improving network security and credibility.
Figure 7 shows the operational framework of a lightweight blockchain-based distributed unmanned aerial vehicle (UAV) self-organizing network. This framework uses the consensus mechanism of blockchain and smart contracts to achieve the statistics and update of global credibility by real-time monitoring the behavior of UAV nodes. UAV nodes form a self-organizing network by connecting with each other. In this network, the credibility of nodes is dynamically evaluated by their data-forwarding behavior. After the evaluation result is verified by the consensus mechanism, it is automatically executed through the smart contract, and the global trust view is finally updated. This process fully reflects the ability of blockchain technology to improve transparency and trust in distributed systems. On this basis, the smart contract, as one of the core components of the system, further simplifies the complex processes in network operation. Smart contracts can automatically implement pre-set rules and protocols, such as the incentive mechanism for resource sharing between UAVs or the automatic isolation of faulty nodes. In this section, the VST model is used to describe the life cycle of a smart contract in four phases: creation, deployment, execution, and completion, and the following will illustrate how smart contracts play a practical role in UAV networks through specific application scenarios.
6.1. Creation
The creation phase of a smart contract is the process by which a software engineer transforms a traditional contract into a smart contract code that can be recognized and executed by a computer through a programming language. Generally, creating a smart contract involves defining variables, describing state, and setting conditional response rules. In the VST model, this process can be described as the instantiation of a multidimensional vector V, corresponding rules, and a directed acyclic graph set T. In conjunction with a common UAV mission contract, we need to perform natural language processing on the contract, extracting its entities, relations and logical structures, and recording and saving the attributes involved in the contract.
Declaration. The first step to create a smart contract is to extract the variables needed for the smart contract from the natural language contract, and declare the key-value pairs. In the UAV mission contract shown in
Figure 8, the variables to be declared are shown in
Table 3. After declaring the variables, it is necessary to define the state-variable mapping relationship, i.e., to define the instantaneous state that can cause the trigger condition, as shown in
Table 4. After the first two steps are completed, the trigger conditions of the smart contract can be declared and a directed acyclic graphical set representing the structure of the trigger conditions of a smart contract can be drawn. The trigger condition declaration of an example UAV mission contract is shown in
Table 5, and its directed acyclic graph set is shown in
Figure 9. Thus, the process of creating a smart contract from a traditional contract under the VST model is formally completed.
6.2. Deployment
After a smart contract is created, it is packaged and deployed on the chain by a consensus node (miner). The existing technology first stores the contract code directly to the contract address, then the contract address is asymmetrically encrypted, packaged into blocks, and deployed to the main chain. The deconstructed VST model can store the multidimensional vector set, V, state set, S, and graph set, T (split into module , point set , and edge set ) independently.
6.3. Execution
In the execution phase of a smart contract, the contract invoker initiates a transaction to the contract address, and the consensus node (miner) runs the smart contract to be executed in the local sandbox environment. The local sandbox accesses the state of the world through the prophecy machine, and returns the result to the contract invoker after execution, as shown in
Figure 10.
In the VST model, since the environment,
V, state set,
S, and graph set,
T, of the smart contract are stored independently in advance, the clause steps of the smart contract can be monitored during the execution process. When a clause is called, the module and vertex corresponding to the clause are returned to the caller in real time, and the instantaneous state of the contract and the corresponding variable key-value pairs are listened to. After the execution of the contract is completed, the result of the computation, the corresponding state and the variable key-value pairs to achieve the result are returned to the caller, as shown in
Figure 11. Thus, the execution phase of a smart contract under the VST model has been transformed from a black-box process to a white-box process.
This transformation means that the execution of smart contracts is no longer an opaque black box, but has become a transparent white box, where every step of the execution can be monitored and verified. This enhancement in transparency is crucial for the security and reliability of smart contracts, as it allows developers and users to monitor the execution status of the contract in real time, and to identify and correct potential issues promptly.
Compared with traditional deployment of smart contracts, the VST model offers greater transparency and monitorability, which is one of its main contributions and a key feature that distinguishes it from conventional smart contract deployment. In this way, the VST model enhances the auditability and verifiability of smart contracts, providing new safeguards for the secure execution of smart contracts.
In this example UAV mission contract, if Party B modifies Party A’s drone without Party A’s consent during the task period, Party B must compensate Party A for the damage to the equipment as required. As shown in
Figure 8, under the VST model, the above clauses correspond to
Module4 and
Module5, which are strictly recursive, and
Module5 is a supplement to
Module4. When Party B renovates Party A’s house without Party A’s consent, the trigger condition is
, followed by
. At this point, a supplement to the example UAV mission contract is executed.
6.4. Completion
A contract is completed when the smart contract no longer executes any of its terms. In the VST model, the “completion phase” of a contract refers to a stable state that reflects not only the success of the execution of the contract, but also the instantaneous state in which the contract has reached a stable state. In the VST model, there are two steady states,
and
, for smart contracts. Each contract has a separate listening module,
, which contains three vertices,
, as shown in
Figure 12.
When the smart contract is no longer executing any clause, is triggered, and the termination state of the last executed module is checked: if the state is , is triggered, i.e., the contract reaches a stable completion state, ; if the state is , is triggered, i.e., the contract reaches a stable default state, .
6.5. Conditional Response Path
In the VST model, after the execution of a smart contract, a conditional response path is returned to the user, which is the set of all triggers triggered during the execution of the contract. Unlike the pre-declared T-chart at the time of contract creation, the condition response path returned after contract execution records the environment and state under which the completion/failure condition was reached. Thus, for both developers and users, each contract call makes experimental sense: suppose that under contract version , user a completes the contract with , and user b completes the contract with ; under contract version , user a completes the contract with , while user b completes the contract with . Suppose some key variables in have better values than , and some key variables in have better values than . Then, for user a, it seems that the contract version better satisfies his interests, while, for user b, the opposite is true; for the developer, it becomes a mechanism design problem to adjust the predefined parameters at each step, balance the preferences of user a and user b, and improve the smart contract so that it can satisfy the interests of most users.
Specifically in the UAV mission contract example in this section, if the contract is executed and the conditional response path is , this means that b made alterations to the house while renting a’s property, but a did not agree to the alterations and ordered b to return the house to its original condition and pay 1000. If the owner, a, does not want to modify the drone in the next task period, he/she can improve the contract template, for example, setting the compensation to 10,000 in advance, which increases the user’s modification cost and reduces the possibility of users modifying the drone. Such a change in the contract is to some extent more favorable to the interests of the first party.