Blockchain enabled task offloading based on edge cooperation in the digital twin vehicular edge network

The rapid development of the Internet of Vehicles (IoV) along with the emergence of intelligent applications have put forward higher requirements for massive task offloading. Even though Mobile Edge Computing (MEC) can diminish network transmission delay and ease network congestion, the constrained heterogeneous resources of a single edge server and the highly dynamic topology of vehicular edge networks may compromise the efficiency of task offloading, including latency and energy consumption. Vehicular edge networks are also vulnerable to malicious outside attacks. In this paper, we propose a new blockchain-enabled digital twin vehicular edge network (DTVEN) where digital twin (DT) is exploited to monitor network communication, computation, and caching (3C) resources management in real time to provide rich data for offloading decision-making, and blockchain is utilized to secure fair and decentralized offloading transactions among DTs. To ensure 3C resources sharing across edge servers, we design a DT-assisted edge cooperation scheme, which makes full use of edge resources in vehicular networks. Furthermore, a DT-based smart contract is built to achieve a quick and effective consensus process. Then, we apply a task offloading algorithm based on an improved cuckoo algorithm (ICA) and a resource allocation scheme based on greedy strategy to minimize network cost by comprehensively taking into account latency and energy consumption. Numerical results demonstrate that our proposed scheme outperforms the existing schemes in terms of network cost.


Introduction
The Internet of Vehicles (IoV) is a crucial technology for implementing Intelligent Transportation System (ITS) based on in-vehicle network, inter-vehicle network, and mobile Internet [1,2].In recent years, with the continuous development of IoV and the commercialization of the fifth-generation (5G) networks, vehicles become more intelligent and efficient, offering users safe, comfortable, and intelligent travel experiences as well as traffic services [3].Generally, these computationally intensive and delaysensitive service applications require a large amount of communication, computation, and caching (3C) resources, but the computing capacity of vehicular terminal devices is difficult to meet the requirements of these applications, which will have an impact on the Quality of Service (QoS) and Quality of Experience (QoE) in IoV, as well as the safety of vehicle driving [4].
Mobile edge computing (MEC) can reduce task transmission time by deploying edge servers (ESs) with computation and caching resources at the edge of the network [5].With the explosive increase of tasks, a single ES cannot process multiple tasks simultaneously.Edge cooperation can effectively make up for the lack of 3C resources of a single ES.At the same time, edge cooperation processes tasks in a distributed and collaborative manner, which can take advantage of idle network resources and save system power consumption and time overhead [6,7].However, task offloading in IoV faces some critical challenges such as the randomness of wireless channels, the heterogeneity of collaborative nodes, and the high mobility of vehicles.These challenges seriously restrict the implementation of task offloading, resource allocation, and edge cooperation, and ultimately limit the long-term development of IoV.Digital Twin (DT) as an emerging technology, which can map the physical world to the digital world, enables communication, collaboration, and information sharing between the physical and digital worlds, thereby monitoring the state of the entire network in real time [8].DT can collect massive sensing data from IoV, then model and analyze it to obtain a global perspective, and publish control strategies for IoV.IoV can utilize powerful computation, communication, and control functions of DT to conduct unified scheduling management and obtain a vision related to the future of the system, making it possible to truly achieve the collaboration between the physical world and digital world throughout the life cycle of IoV [9][10][11].However, frequent wireless communication between IoV nodes makes the network vulnerable to attack.If the sensed data is maliciously falsified, the constructed DT will not reflect the actual status of the physical entity, which may lead to serious accidents.
As a distributed ledger, blockchain can achieve information fusion among all parties in IoV because of its non-deleting, non-tampering, and openness characteristics [12][13][14].The information collected from IoV will be uploaded to the blockchain platform that provides data security through encryption technology, forming a decentralized and distributed big data sharing network.Its decentralized and transparent data management approach has led to a significant reduction in transaction costs for vehicle management centers and data management centers [15,16].
However, there are some important challenges for edge cooperation in IoV.First, the dynamic characteristics in a time-varying IoV environment will have an impact on task offloading decision.Second, edge cooperation in IoV is prone to external attacks and information leakage.Third, how to make full use of the limited resources of heterogeneous edge servers is still worth research.
Therefore, in this paper, we propose a new vehicular edge network based on digital twin and blockchain, which optimizes edge cooperation and secures task offloading.Different from the previous studies, we introduce digital twin technology to map the status of physical entities in IoV into the virtual space and construct a digital twin model of task offloading based on blockchain, thereby improving resource sharing security.To satisfy the dynamic vehicular edge network, we design an edge cooperation-based task offloading scheme, which minimizes network cost under the constraints of latency and energy consumption.The key contributions of this paper can be listed as follows.
1 We propose a novel blockchain empowered digital twin vehicular edge network (DTVEN), in which DTs assist resource scheduling by capturing network dynamics while strengthening the security of resource sharing through blockchain. 2 We design an edge cooperation-based task offloading scheme to better reduce offloading latency and energy consumption, and construct a DT-driven blockchain consensus model to ensure the reliability of vehicles and edge servers.3 We propose a task offloading algorithm based on an improved cuckoo algorithm (ICA) and a resource allocation scheme based greedy strategy to jointly optimize the latency and energy consumption during the task offloading process.The simulation analysis is conducted to show the effectiveness of our proposed scheme.
The rest of this paper is organized as follows.In "Related works" section, we review the related work.In "System model" section, we propose the system model.In "Performance analysis" section, we describe the performance analysis of the system.In "Algorithms" section, we illustrate the algorithms in detail.In "Performance evaluation" section, we discuss the performance of the proposed scheme.In "Conclusion" section, we summary this paper.

Related works
In order to improve the QoE performance of vehicles, some researchers have studied the advantages of edge cooperation in improving the performance of the IoV system.Literature [17] develops a blockchain-based collective learning framework, in which distributed vehicles can train the machine learning models locally and upload to blockchain network to utilize the collective intelligence while avoiding large amounts of data transmission.Considering there is a large number of parking vehicles with abundant and undeveloped resources in the city, Ma et al. [18] use parking vehicles as virtual edge servers to assist ESs in performing tasks.A task scheduling algorithm combined with ESs selection and resource allocation is designed to provide a more efficient and stable offloading service in the case of a large number of task requests.
To solve the load imbalance among the ESs caused by the uneven geographical distribution of the vehicles, the authors in [19] present a joint task offloading and resource allocation method for vehicular edge computing (VEC) via edge cooperation, in which the tasks offloaded to a high-load ES can be further offloaded to the other low-load ESs.Duan et al. [20] construct a hierarchical model with QoS-aware and energy-aware resource management for the cooperative edge computing-based intelligent vehicular network (CEC-IoV).They propose a Minimum Latency with Migration Loads (MLML) scheme for load balance among multiple MECs to obtain lower system delay and higher energy efficiency.Literature [21] studies a new framework of hierarchical multi access edge computing based on blockchain, which can reach effective consensus among blockchain nodes while ensuring the performance of MEC system and blockchain.A trust model is proposed to greatly ensure the security of communication links between vehicles.Since the integration of DT into IoV is beneficial to the system, some scholars have exploited DT to promote the network performance of IoV.To prevent edge computing device (ECD) overload in DT-empowered IoV, Xu et al. [22] study a multiuser offloading system and propose a service offloading (SOL) method with deep reinforcement learning for optimal offloading decisions.In [23], a vehicular edge computing network combined with DT and artificial intelligence (AI) is presented to match potential edge services, in which a coordination graph-driven task offloading scheme based on Multi-agent Deep Deterministic Policy Gradient is designed to decrease offloading costs.Dai et al. [24] integrate DT into VEC networks to adaptively conduct network management and strategy schedule, thereby minimizing the overall offloading latency of the system.The authors in [25] present a holistic network virtualization model that integrates DT and network slicing, in which an environment-aware offloading method is designed to reduce the total time of the system.Liu et al. [26] propose a DT-assisted edge intelligent collaboration scheme in IoV to realize optimal 3C resources allocation and edge collaboration.Considering the deviations between the physical world and the digital world, they utilize a DRL algorithm to obtain the optimal offloading strategy and diminish the response delay.
The above studies have proved that digital twin and blockchain are both promising technologies.Different from these studies, we integrate digital twin and blockchain into edge cooperation in IoV, which is conducive to efficient and secure edge computing.In addition, this paper minimizes network cost by jointly optimizing offloading cost and consensus cost.

System model
In this section, We first propose the system model of blockchain-enabled vehicular edge network architecture.Then, we describe the detailed process of blockchain-based vehicular edge computing.The main notations used in this paper are summarized in Table 1.

Network model
As shown in Fig. 1, the proposed system model consists of three layers, namely, an end layer, an edge layer, and a digital twin layer.
On the end layer, vehicles equipped with multiple sensors and onboard units can collect various valuable information about other vehicles, roads, and the surrounding environment, including video music, entertainment games, and traffic situation.Vehicles can locally process their own generated tasks by consuming their computation resources.Each task is represented as Ta v = {D D , Z C , Y max } .D D is the data size of the task, Z C is the CPU cycles required to perform the task, and Y max means the maximum deadline for executing tasks.However, due to the limited computing capacity, vehicles divide a task into several subtasks and offload them to different edge servers on the edge layer through vehicleto-infrastructure (V2I) communication.
On the edge layer, multiple edge servers with 3C resources are uniformly distributed.We use the set represent edge serv- ers in the model.Owing to the constrained and heterogeneous resources, each edge server has different capabilities for performing tasks.By utilizing 3C resources, edge servers can provide high-quality V2I transmission, efficient task execution, and reliable block consensus for vehicles.In the meantime, each edge server is equipped with a blockchain to ensure that untrusted vehicles are able to offload tasks in a secure manner.All edge servers collaborate to maintain the blockchain, store relevant data, and manage the participating nodes of the network architecture.
On the digital twin layer, digital twins that are highly similar to vehicles and edge servers are constructed The cost for blockchain consensus

U Net
The network cost based on the state information of the physical entities on the end layer and edge layer.To maintain consistency with physical entities, the digital twin maps the physical devices to virtual space and updates them in real time.As shown in Fig. 2, DT can simulate the basic functions of the end layer and edge layer, which realizes more effective offloading decisions during the entire task execution process.The twins on the digital twin layer are modeled and maintained by edge servers on the edge layer.In this paper, we consider two types of digital twins, namely, the digital twins for vehicles and the digital twins for edge servers.
The digital twin of the vehicle is constructed on the digital twin layer with the help of the edge servers.By collecting and processing the operation status of the vehicle, including available computation resources and locations, the historical and current behavior of the vehicle is dynamically presented in digital form.
where f v is the estimated computing capability of the vehicle, l v = x v , y v is the location of the vehicle.
The digital twin of the edge server is a digital replica of the edge server that can reflect the current state of the edge layer.It constantly interacts with edge servers and updates itself based on actual network topology, task requests from vehicles, and so on.At the same time, the digital twin model of the edge server is stored in the digital twin layer through the edge server.For the vehicle ES j , its DT can be represented as where C 1 j , C 2 j , and C 3 j are the estimated communication, computing, and caching resources of the vehicle respectively, l E j = x E j , y E j is the location of the edge server.
(1) In terms of data sensing, accurate global sensing is still difficult, because electromagnetic information transmission is subject to losses due to absorption and scattering in wireless channels, which cannot fully reflect the status of physical entities.The loss of state data further leads to deviations between the estimated value of the twins and the true value of the physical entity state.To calibrate the deviation of the digital twin, the resource deviation is represented by a matrix C of size 3 × M where the first, second, and third rows of the matrix C represent the deviation values of communication, computation and caching resources for each edge server, respectively.

Blockchain-based vehicular edge computing
Blockchain technology can prevent data leakage from vehicles and edge servers while ensuring safe and reliable task offloading.Since the digital twin network is built on the edge layer, we can use blockchain to trace the resource allocation between the digital twins.
To achieve task offloading and resource allocation by blockchain technology, vehicles and edge servers must first register their unique accounts and create corresponding keys.The identities of vehicles and edge servers are established through elliptic curve digital signature technology and asymmetric encryption algorithms.Specifically, vehicles and edge servers need to register their legal identities after passing the authentication of the blockchain registration authority.A legal identity consists of a public key, a private key, and a certificate.The public key is used as the source address of the offloading transaction to verify the authenticity of the transaction.
The key is regarded as transaction signing, and the certificate is used to identify the unique vehicle and edge server by binding their registration information.
As shown in Fig. 3, we use smart contracts to complete each transaction and store it on the blockchain to ensure the traceability of transaction information.Based on digital twin and blockchain, safe and efficient task offloading in vehicular edge networks can be achieved through the following stages.
When a new task is generated, the vehicle sends an encrypted task offloading request to its corresponding digital twin DT v .The request message for task offloading of the vehicle can be described as where En PK DT v indicates that the message Req v→DT v is encrypted with a public key indicates that the digital signature of the task information Ta v and vehicle location l v is encrypted with a private key SK v .ICert v is the unique v identifier between the vehicle v and its twin DT v , and ts is the timestamp of the current message.
In the digital twin network, as a task publisher, DT v broadcasts task details to the digital twin DT E j (j ∈ [1, M]) of the edge server ES j where En PK DT E j indicates that the message Boc DT v is encrypted with a public key PK DT E j .Sign DT v = SiSK DT v (DD, ZC , Ymax, l v ) represents that the digital signature of the detailed status information of the edge server is encrypted with a private (3) Cert DT v is the identification of the vehicular twin DT v , i.e., digital certificate, and ts is the timestamp of the current message.As a task executor, the twin DT E j (j ∈ [1, M]) of edge server responds to broadcast information of DT v and sends its detailed information such as its own resources and location, to DT v for edge resource allocation where En PK DT v indicates that the message Rep indicates that the digi- tal signature of detailed status information about the edge server is encrypted with a private key SK DT E j .Dep j is the deposit submitted by the edge server.Cert DT E j is the identification of the edge server twin DT E j , i.e., digital certificate, and ts is the timestamp of the current message.
After receiving the response message, DT v verifies the identity of the twin DT E j (j ∈ [1, M]) .To accelerate the verification process, a batch verification process is used to verify the validity of multiple identities simultaneously [27].Next, DT v performs subtask offloading and task-resource matching where En PK DT E j indicates that the message Sol DT v →DT E j is encrypted with a public key PK DT E j .OR j represents the proportion of tasks offloaded to the twin DT E j .The digital signatures of OR j and Ta v are encrypted with a private key SK DT v through Si SK DT v (OR j , Ta v ).
DT E j (j ∈ [1, M]) verifies the validity of its identity based on the digital certificate of DT v , and then executes the task according to the offloading scheme message sent by DT v and feedbacks the task result message where En PK DT v indicates that the message Res DT E j →DT v is encrypted with a public key PK DT v .The digital signature of the subtask result RES j is encrypted with a private key After receiving the feedback results of all subtasks, DT v integrates them into the total task result RES all and feedbacks them to the vehicle v (5) where En PK v indicates that the message Feb DT v →v is encrypted with a public key PK v .The digital signature of total task results RES all is encrypted with a private key SK DT v through Si SK DT v (RES all ) .ICert DT v is the unique DT v identifier between the vehicle v and its twin DT v , and ts is the timestamp of the current message.
The smart contract verifies the validity of the task results.If the result is verified successfully, the rewards in the smart contract will be sent to the digital twins of the edge servers and the deposits submitted by them will be returned.If the task is not completed or its execution deadline is exceeded, the deposit of DT v will be refunded.Furthermore, the deposit of DT E j will be confiscated as a penalty to prevent DT E j from inaction or passive action after receiving the offloading scheme.
At the same time, DT v generates a transaction to record the task offloading event, and sends the transaction to DT E j .DT E j validates the received transaction and cryptographically broadcasts it to the blockchain network where En PK DT E j indicates that the message Tra Newly generated transactions are broadcast across the blockchain network for review and verification.Validated transactions are sorted and batch processed into encrypted and tamper-proof blocks.Blocks are connected in linear chronological order via hash pointers to form a blockchain.During the consensus process, the digital twin DT E j creates the corresponding blocks.Then, DT E j broadcasts the block with a timestamp for block auditing while verifying the correctness of the newly created block.

Performance analysis
In this section, The partial offloading technology based on blockchain is used to perform tasks.We will describe the local computing model, edge computing model, and blockchain consensus model in detail.

Local computing model
Since partial offloading can collaboratively utilize the computation resources of the vehicle and edge servers, it also benefits from both parallel computing [28].Therefore, when vehicles with constrained resources cannot ( 9) perform tasks with large amounts of data, a partial offloading model is used to divide the task into several subtasks.It is assumed that tasks are data partition oriented and can be divided arbitrarily on their input bits [29].Similar to the literature [30], we ignore the task partitioning cost and divide vehicular tasks.Some subtasks are processed locally on the vehicle, while the remaining subtasks are offloaded to the edge servers for execution.Considering the mapping of the digital twin of the vehicle, the generated estimated value has a deviation from the vehicular real value.When the proportion of tasks to be processed by the vehicle is θ v , the local computing time is The energy consumption generated by executing the task locally on the vehicle is where f v is the computation resources deviation value of the vehicle.κ v is the energy coefficient depending on the vehicle chip structure [31].

Edge computing model
When the vehicle offloads the subtask to the edge server for processing, the time required includes (1) the upload time for transmitting the subtask to the edge server, (2) the processing task time of the edge server, and (3) the downlink time for the edge server to feed the task result back to the vehicle.The results of the task will be compressed and are much smaller than when they are input, so the downlink time can be ignored in the calculation [32].
Due to the heterogeneity of resources, the edge servers have different communication resources, resulting in different transmission times for vehicles offloading subtasks to different edge servers.When the vehicle offloads a subtask with a ratio of θ j to the edge server ES j , the transmission time is R j represents the data transmission rate of vehicle v to edge server ES j , which can be calculated according to the Shannon's formula where p v is the transmitting power of the vehicle, h v is the current channel gain, σ 0 power of the Gaussian (10) indicates the distance between the vehicle v and the edge server ES j .
When the task ratio processed by the edge server ES j is θ j , the processing time is Therefore, when the vehicle offloads a subtask with a ratio of θ j to the edge server ES j , the time includes transmission time and processing time, which can be calculated The energy consumption generated by this process includes vehicle transmission subtask energy consumption and edge server ES j processing energy consumption, which can be calculated where κ E is the energy coefficient depending on the edge server chip structure.
With the help of advanced wireless communication technology, the vehicle cooperates with multiple edge servers to process tasks in parallel through full-duplex mode, so the completion time of a task is the maximum of the vehicular local computing time or the computing time of multiple edge servers.Therefore, the total time for the vehicle v offloading task is expressed as The total energy consumption of offloading task includes local computing and edge computing energy consumption, which can be calculated By introducing a delay factor ϑ 1 and energy consump- tion factor ϑ 2 , the optimization of the offloading delay and the energy consumption is transformed into the optimization of the offloading cost

Blockchain consensus model
By dividing and offloading vehicular tasks to edge servers, the service quality and service experience of ( 14) vehicles are improved, but there exist some malicious edge servers that may privately steal vehicle user data and even disclose the privacy of vehicle users.Therefore, to ensure the security of the vehicular edge network, we use blockchain technology to verify task transactions.Edge servers are regarded as blockchain network nodes to perform consensus because of their 3C resources.They will form a verification set, where one edge server acts as the leader and is responsible for block production and the other edge servers act as verifiers to audit and verify the blocks.The blockchain consensus phase can be divided into four processes: block production process, block broadcast process, block verification process, and block confirmation process.
During the block production process, the edge server collects transactions after the task is offloaded and broadcasts them to the entire network.The edge server, as a leader, packages its collection and computes a correct hash to create an unverified block.According to Delegated Proof of Stake (DPoS), the time T bp for collecting transactions and computing hashes can be predefined, for example the time is 0.5s in a commercial distributed design blockchain operating system.In the meantime, the energy consumption during the block production process can be expressed as During the block broadcast process, the leader sends a broadcast message to the other verifier edge servers.The format of the broadcast message is Brm = (block, PK sou , PK des , ts Brm ) , where block repre- sents the block it created, PK sou is the source address of the message, PK des is the destination address of the mes- sage, and ts Brm is the timestamp of the broadcast mes- sage.The leader simultaneously broadcasts the generated blocks to the other verifiers.Since the location of each edge server is different, the block broadcast time is determined by the block transmission time with the longest distance.The time and energy consumption of the block broadcast process are respectively where D bb is the size of the block before validation.d jm is the distance between the edge server j and m.P E is the transmit power of the edge server.R E is the wired trans- mission rate between edge servers.( 20) The block verification process consists of three stages.First, each verifier that receives a block performs a local verification, i.e., it audits the accuracy of the block by comparing the hash value calculated by using a hashing algorithm with the digital signature of the received broadcast message.Then, the verifier broadcasts its local audit result with the digital signature to other verifiers in a distributed manner.Finally, the verifier performs a secondary audit of the received local results.The time and energy consumption during the block verification process can be expressed as where T lv is the block local verification time, T rb is the broadcast time of the block local verification results, and T sa is the secondary audit time of the block local verifica- tion results.Z 0 represents the size of caching resources per bit used to verify blocks, represent the caching resources provided by the verifier edge servers m and m ′ for block verification respectively.d mm ′ is the distance between the verifier m and m ′ .D lr is the data size of the local verification result.
During the block confirmation process, each verifier compares its audit results with those received from other verifiers and sends a confirmation message to the leader.The format of the validation message is Com = (Res com , Aut own , Aut oth , PK sou , PK des , ts Com ) , where Res com is the audit comparison result between the verifiers, Aut own is the verifier's audit result, Aut oth is the audit result received from other verifiers, and ts Com is the timestamp of the feedback message.The block confirmation time depends on the distance between edge servers, so the block confirmation time and energy consumption are expressed as where D sr is the data size of the secondary audit result.( 23) Similarly, the optimization of consensus delay and the energy consumption is transformed into the optimization of consensus cost by introducing a delay factor ϑ 1 and energy consumption factor ϑ 2 .The expression is In summary, network cost consists of task offloading cost and blockchain consensus cost, which can be calculated

Problem formulation
The purpose of task offloading and blockchain consensus is to minimize network cost, including offloading cost and consensus cost.Therefore, the optimization model can be formulated as C1 is a requirement for task offloading ratios to ensure that tasks can be fully executed.C2 represents a linear combination of delay and energy consumption.C3 ensures that the computing power of each edge server is greater than the computing power of the vehicle.C4 indicates that the task offloading time cannot exceed the maximum deadline for the task.

Algorithms
In this section, we divide the optimization model into two problems to solve, namely, using an improved cuckoo algorithm to minimize task offloading cost, and using a greedy strategy to minimize blockchain consensus cost, thereby jointly optimizing to minimize network cost.

ICA based task offloading algorithm
The offloading ratio of a task determines its offloading time and energy consumption, i.e., task offloading cost.Since the advantages of Cuckoo algorithm (CA) include fewer parameters and fast convergence speed [33], we design a task offloading algorithm based on improved Cuckoo algorithm (ICA).The probability of cuckoo eggs being discovered P a and control step ε 0 are adap- tively changed to balance the relationship between global ( 27) search ability and local search ability.At the same time, the preferred random walking mode with global optimal guidance can better improve the development ability of ICA algorithm and jump out of a local optimal solution, thereby obtaining the optimal task offloading ratio and minimizing task offloading cost.The task offloading algorithm based on ICA is shown in Algorithm 1.

Algorithm 1 ICA based task offloading algorithm
To prevent uneven distribution of individuals within a randomly generated population, we adopt the Latin hypercube sampling method to generate the initial population [34].Based on the space-filling technique, Latin hypercube sampling ensures that the projection of sample points in the variable space is uniformly distributed in each dimension.The population locations after Latin hypercube sampling not only realize non-overlap throughout the entire space-filling and sampling to make the initial population uniformly distributed but also allow more full searching of the entire variable space with a small number of sample points.The specific steps for population initialization in the ICA are as follows (1) Determine the population size and dimension number of the ICA, (2) Determine the interval of variables X ∈ [0, 1] , (3) Divide the interval of variables X ∈ [0, 1] into equal subintervals with the same number of population sizes, (4) Select a point within each sub-interval of each dimension randomly, (5) Combine the extracted points of each dimension to generate the initial population position of the ICA.
Based on the above three rules, the CA uses both the Levy flight mode and the random walking mode to jointly update the location of the nest.
Levy flight mode (global search).The update formula for the location and path of the cuckoo bird searching for its host nest is where X t+1 i and X t i represent the nest location in the t + 1 and t generation respectively.ε = ε 0 (X t i − X best ) is the control step length, X best represents the optimal nest location in the current population.
stands for point-to-point multiplication; N is the number of bird nests; L( ) represents the random search path for Levy flight, which follows the Levy probability distribution L( ) ∼ s − , 1 < ≤ 3 , and its random step s can be cal- culated by where u ∼ N (0, δ 2 u ) , µ ∼ N (0, 1) , β = 1.5 , δ u can be cal- culated by The control step ε 0 in the early stage of iterative opti- mization should be larger to search more regions to improve the global optimum performance, which is more favorable to jump out of the local optimum.In the later stage of iterative convergence, the control step ε 0 should be gradually reduced to a smaller value, which is more conducive to the careful search in the local region and to improve the solution accuracy while accelerating the convergence speed.As a result, the relationship between the control step ε 0 and the number of iterations t is where the maximum and minimum values of control step ε 0 represent ε max 0 and ε min 0 respectively, T I represents the maximum number of iterations, and ω is a non-linear factor with a value greater than 0 to control the rate of decline of control step ε 0 .
Preferred random walking mode (local search).The host bird will discover and discard cuckoo eggs with a certain probability P a , P a ∈ [0, 1] .The new nest location is updated by where i = i ′ = i ′′ , and i, i ′ , i ′′ ∈ [1, N ] .ρ 1 and ρ 2 are ran- dom numbers subject to uniform distribution [0, 1]; H is the Heaviside step function; X t i ′ and X t i ′′ represent two randomly selected nest locations in the T generation respectively.
The discovery probability P a of cuckoo eggs is used to generate new individuals.If ρ 2 < P a , the original indi- viduals are saved to the next generation.If ρ 2 > P a , the (30) original individuals are eliminated and new individuals are generated.However, in the early iterative stage, the discovery probability P a should be kept at a large value to increase the diversity of the population and avoid falling into a local optimum, and a smaller value in the later stage to ensure better convergence of the algorithm.The appropriate discovery probability P a should be gradually reduced as the iteration progresses to ensure that new individuals can be generated more easily in the late iterations, so we adopt a cosine decreasing strategy to achieve dynamic changes in the discovery probability: To greatly improve the population diversity and the efficiency of ICA algorithm, we combine the particle swarm algorithm (PSO) and the golden sine optimization algorithm [35] for the preferred random walking mode with global optimal guidance, which can be calculated by where i = i ′ = i ′′ , and i, i are random numbers that determine the distance and direction of the location update during the iteration respectively.φ 1 = −π + 2π(1 − γ ) and φ 1 = −π + 2πγ are compression factors that can be used to compress the space to find the best nest location more quickly.γ = ( √ 5 − 1)/2 is the golden section ratio coef- ficient, which can be obtained where the offset coefficient η is a random number uni- formly distributed on the interval (−η, η) , and the value is (π/6) [36].According to (36), the preferred random walking mode with global optimal guidance generates new solutions based on the golden ratio coefficient close to the global optimal solution, because the new solutions obtained by the golden ratio coefficient are superior to those generated only within the interval [0, 1].Compared to generating new solutions linearly between [0, 1], the offset coefficient allows the ICA to search for more location information with a certain offset angle.

Greedy strategy based resource allocation scheme
DPoS is a fast and efficient blockchain consensus mechanism that utilizes voting and selection to protect blockchains from the impact of centralization and malicious use [37].Compared with traditional consensus algorithms, the number of entities involved in DPoS consensus is few, which can effectively reduce the time and ( 35) = ηγ energy consumption to reach consensus.Therefore, the DPoS consensus is combined with a greedy strategy to reasonably allocate resources, thereby minimizing the consensus cost.
The first is the leader selection.Task offloading is mainly performed between edge servers, so they store relevant transaction information and can be considered as leader candidates.In each selection, the edge servers vote based on their respective caching resources.The caching resources can be used for block consensus, including block production and verification.As a measure of the quality of the edge servers, more caching resources means that the edge servers have more processing power to produce and verify blocks.At the end of the voting, the edge servers with the highest number of votes will form a verification set.

Algorithm 2 Greedy strategy based resource allocation scheme
There are two roles in the verification set, the leader and the verifier.The leader is responsible for transaction collection and block production, and the verifier is responsible for block verification.In each block production process, one edge server in the verification set acts as a leader and other edge servers act as verifiers.Leaders are generated in a round-robin manner in the verification set, indicating that each edge server can become a leader to produce blocks.In the specific block consensus process, the leader first collects a certain amount of taskoffloading transactions and then computes a correct hash value to produce an unverified block.The verifier audits the block broadcasted by the leader and sends a confirmation message to the leader.The leader analyzes the received confirmation message and audits the block for accuracy.If more than two-thirds of the verifiers agree on the block, the leader sends the block to all edge servers in the verification set for storage.Edge servers that are not in the verification set will periodically synchronize the latest blockchain information in their vicinity.
When a newly generated block is successfully added to the blockchain, the edge servers involved in the block consensus process are rewarded to compensate for their resource consumption.If all edge servers in the verification set become leaders, the order of leaders is changed, and they then produce new blocks again in a roundrobin manner.If a leader fails to create a block, the block is skipped and the transactions in the skipped block are transferred to the next block.The blockchain resource allocation scheme based on greedy strategy is shown in Algorithm 2.

Security analysis
The DT-based blockchain provides secure and reliable edge cooperation for vehicular edge networks.
1) Efficient operation: Physical entities transmit information through physical-to-physical (P2P) communications, including vehicles and edge servers.The DTs in the proposed DTVEN achieve information interaction and resource sharing through twinto-twin (T2T) communications, to reflect the state behavior in the actual physical network.T2T communications depend on the computation resources of the edge server to model and simulate, without consuming any communication resources.Compared with time-consuming P2P communications, T2T communications only need to simulate and predict the operational state of the network in a relatively short time, and send the results to the physical entities through twin-to-physical (T2P) communications to realize task offloading and resource allocation.
2) Transaction traceability: In the proposed scheme, the verifier selection process is based on a greedy strategy, where all blocks and transactions are publicly audited and mutually verified by all verifiers in a round-robin manner.Broadcasted transactions recorded with timestamps cannot be maliciously modified by a single entity, since timestamps in the blockchain can be used to keep transactions intact.At the same time, any vehicle and edge server can quickly verify and trace previous records by accessing the digital twin layer.
3) Privacy Protection: Vehicles, edge servers, and their corresponding DTs transfer messages about task offloading and blockchain in an anonymous manner.For example, the twin DT v of a vehicle v uses its public key as a pseudonym to ensure the anonymity of its true identity.DT v sends the messages (i.e., Boc DT v , Sol DT v →DT E j , Feb DT v →v ), and transac- tions (i.e., Tra DT v →DT E j ), which are signed and can only be accessible by vehicle v and the digital twin DT E j of the edge server ES j with the correct private key.If the malicious DT v ′ and DT E want to forge the signature of DT v to pass the authentication process, the attackers must forge a signature.However, attackers cannot obtain the private key from the public key of DT v , so they cannot access the private key to forge the signature information of the legitimate DT v .In edge collaboration, anonymity and digital signatures can protect the privacy of physical entities and twins in DTVEN.

Simulation and results analysis
As can be seen from Fig. 4, the ICA proposed in this paper can achieve convergence compared to the traditional CA.The solution space can be explored more fully by generating uniformly distributed initial populations through Latin hypercube sampling.In the global search process using Levy flight, the number of control step ε 0 changes dynamically with the number of itera- tions to improve the accuracy of the search.In the process of local search, the cosine decreasing strategy is used to realize the dynamic change of discovery probability P a , which can increase the strength of population evo- lution and thus avoid falling into local optimum.At the same time, the global optimization guidance is added to strengthen the development ability of the algorithm, and the search process generates new solutions toward the global optimum to improve the convergence speed.
Figure 5 illustrates the comparison of offloading time with increasing data size for different schemes.It can be seen that offloading time increases with increasing data size for most of the schemes.The time fluctuation of the AVER scheme is the smallest because offloading time depends on the maximum of both local computing time and edge computing time when the task is partially offloaded.Since the computing power of the edge server is stronger than that of the vehicle, vehicular local  computing time is often higher than the time offloaded to the edge server for task execution, so the offloading time of the AVER scheme is vehicular local computing time.
The DM scheme represents offloading a single task to the edge server with the maximum computing power without any task segmentation operation.Even if the task is offloaded to the edge server with the maximum computing power, the transmission time of the task grows due to the increase in the data size, so the offloading time of the DM scheme also increases linearly.The RAN scheme randomly offloads tasks to the edge server, and the offloading ratio of the tasks is random, resulting in a large offloading time.The comparison results show that the ICA scheme proposed in this paper consistently outperforms the other schemes in terms of offloading time.
Compared with other schemes, the ICA scheme can more reasonably allocate communication and computation resources between the vehicles and the edge servers to efficiently execute the tasks.Figure 6 compares the offloading time for task execution under six schemes.As the number of CPU cycles required for computing tasks increases, the offloading time also grows.The time spent in the LOCA scheme is the largest since the task is executed directly on the vehicle without any offloading operation.Due to the limited computation resources of the vehicle, the LOCA scheme is prone to the risk of vehicular overload.The task is only offloaded to the edge server with the highest computation resources in the DM scheme.Although the task offloading time also increases, it is less than the LOCA scheme because the edge server has higher computing power than that of the vehicle.Compared with the average task offloading in the AVER scheme and the random task offloading in the RAN scheme, the ICA-based task offloading scheme maintains good performance.Considering the resource constraints of the edge server, the appropriate subtasks are offloaded based on the distance from the edge server, thereby reducing the offloading time.
Figure 7 shows how the offloading cost varies with the CPU cycles.It can be seen that when the number of CPU cycles required to process the task increases, the corresponding offload cost grows as well.The offloading cost of the LOCA scheme is the largest since the offloading time required by the LOCA scheme is the largest and computing tasks locally consume vehicular computation resources.The RAN scheme randomly divides and offloads tasks to different edge servers, resulting in relatively high offloading cost.In Fig. 6, although the offloading time of the DM Fig. 5 Offloading time with respect to data size under different schemes Fig. 6 Offloading time with respect to CPU cycles under different schemes Fig. 7 Offloading cost with respect to CPU cycles under different schemes scheme is larger than that of the AVER scheme, its offloading cost is lower than that of the AVER scheme.This is because the DM scheme offloads a single task to the edge server with the strongest computing power, and the offloading time increases with the number of CPU cycles, but it only consumes the computation resources of one edge server.In contrast, the AVER scheme requires dividing and offloading tasks equally to the vehicle and the edge server, which consumes not only the computation resources of the vehicle, but also the communication and computation resources of the edge server.Our proposed ICA scheme can measure the energy consumption of offloading tasks based on the communication and computation resources between the vehicle and the edge servers, and reasonably divide the offloading tasks to minimize the offloading cost.
Figure 8 presents the network cost over the varying CPU cycles under six schemes.The network cost of all schemes grows correspondingly with the increase in the number of CPU cycles.During the task offloading process, the task computing time and energy consumption increase accordingly as the number of CPU cycles for processing the task grows.Furthermore, as the CPU cycle of a task increases, more transactions are generated, resulting in a larger number of generated blocks.This increases the time and energy consumption of the blockchain consensus process, and the network cost also grows.We adopt a resource allocation scheme based on greedy strategy, which reduces the blockchain consensus cost by selecting the edge server with the highest caching resources as the leader and reducing the distance of block broadcast.From Fig. 7, it can be seen that our proposed ICA scheme can obtain the minimum offloading cost.Therefore, the proposed scheme in this paper can achieve the minimum network cost during the entire task offloading process.

Conclusion
In this paper, an edge cooperation scheme based on task offloading and resource allocation is proposed to minimize the network cost.We propose a novel blockchain-empowered digital twin vehicular edge network architecture, which utilizes the DT-based smart contract to realize efficient and secure edge computing.To jointly optimize the latency and energy consumption, we first design an ICAbased task offloading algorithm to reduce offloading cost by reasonably offloading subtasks to edge servers.Then, while introducing blockchain for safe data sharing, a greedy strategy-based resource allocation scheme is present to select appropriate edge server verifiers, thereby diminishing consensus cost.Simulation results show that the proposed edge cooperation scheme has a lower network cost significantly than other schemes during the entire task offloading process.

Fig. 3 .
Fig. 3 Smart contract for secure vehicular edge computing DT v →DT E j is encrypted with a public key PK DT E j .HA is its hash value.The digital signatures of all offload schemes sent by DT v are encrypted with the private key SK DT E j through Si SK DT E j (Sol DT v )

The communication resources of edge server C 1 jFig. 4
Fig. 4 Comparison of convergence performance

Fig. 8
Fig. 8 Comparison of network cost with respect to CPU cycles under different schemes

Table 1
Main notations

Table 2
Simulation parameters