Dynamic Credible Spectrum Sharing Based on Smart Contract in Vehicular Networks

: With the rapid development of the Internet of Vehicles (IoV), the demand for wireless spectrum resources has significantly increased. Dynamic spectrum sharing technology is regarded as a key solution to alleviate the shortage of spectrum resources. However, during the spectrum sharing process, security issues and a low utilization of the shared spectrum may arise. This study designs a consortium blockchain for trustworthy dynamic spectrum sharing in IoV environments. An improved asynchronous byzantine fault-tolerant algorithm is also designed to address the instability of signals in this scenario, and the allocation and management of spectrum resources be-tween vehicles and base stations are further optimized using the Stackelberg game, ultimately deployed automatically through smart contracts. Simulation results show that our method not only significantly improves the system’s response time but also ensures communication quality and can maintain efficient operation under high network delay and complex scenarios.


Introduction
With the rapid development of technology, the widespread application of the IoV enables vehicles to communicate more intelligently and efficiently.On the other hand, due to the exponential growth in the number of connected vehicles, the demand for wireless spectrum resources has also increased rapidly.To address this demand, dynamic spectrum sharing technology has become a key solution.Devices can communicate in unused spectrum holes through dynamic spectrum sharing technology, thereby greatly improving the utilization of spectrum resources.In the process of spectrum resource sharing, it is often necessary to introduce a game theory framework to solve the problems of resource allocation and management.In the dynamic spectrum sharing scenario of the IoV, a leader-follower model is often adopted, where the leader makes decisions first, and then the followers respond based on the leader's decisions.Certain entities (such as large communication companies) can play the role of the leader, while vehicles or other communication devices act as followers.
However, the implementation of this spectrum resource sharing technology also brings a series of challenges, such as numerous security and trust issues in an environment where multiple parties are sharing the spectrum.At the same time, blockchain tech-nology, with its decentralized, highly transparent, and tamper-proof characteristics, provides a new solution to the trust issues in spectrum resource sharing in the IoV.Through blockchain, we can create a decentralized environment, making spectrum resource sharing safer and more transparent.Combined with smart contracts, we can also automate the process of spectrum resource allocation and management, thereby enhancing the reliability of the system.
In previous studies, the application of blockchain technology in spectrum allocation, management, and trading attracted widespread attention, as discussed in [1] and [2].In response to the issues of low spectrum utilization and high transaction latency in traditional consensus schemes, Reference [3] proposed a blockchain-based spectrum trading scheme (STBC).The authors of [4] proposed a consensus mechanism and spectrum trading validation mechanism based on interference to prevent potential harmful interference in spectrum sharing.Smart contracts implemented on the blockchain were used to replace traditional central management institutions to promote cooperation among them [5].Reference [6] proposed a bilateral auction framework based on smart contracts, in which auction activities were automatically implemented in a self-regulated and secure environment.
Reference [7] introduced a smart contract solution based on blockchain technology, aimed at facilitating secure and dynamic spectrum sharing among end-users.Specifically, a smart contract for multi-operator spectrum sharing had been developed to enable the dynamic nature of spectrum sharing among collaborative end-users, such as autonomous vehicles within smart cities, in a manner that was both trustworthy and ensured decentralization and security.
Reference [8] proposed a spectrum sharing scheme that allowed service providers to lease underutilized spectral bands, thereby enhancing operational efficiency and augmenting profit margins.The framework guaranteed service excellence, broadened the accessibility to a wider user base, and evidenced substantial potential for improvements in spectral efficiency and financial benefits for all stakeholders involved.Reference [9] had been cited for leveraging blockchain technology to establish a distributed and autonomous asset trading platform, aimed at facilitating a fully dynamic spectrum sharing system.This approach was designed to ensure transparency and trust among devices, eliminating the need for intermediaries.Additionally, the framework utilized smart contracts, a core feature of blockchain technology, to facilitate the transactions of spectrum tokens within the distributed ledger, thereby enhancing the efficiency and security of these exchanges.
References [9][10][11][12][13] explored dynamic spectrum management approaches based on Stackelberg game theory, covering device-to-device communication, drone-assisted communication, and cognitive radio networks.By introducing the Stackelberg game model, these studies proposed various strategies for optimizing spectrum allocation and usage.For instance, they improved direct communication between devices through mode selection and spectrum partitioning, enhanced the spectrum sharing efficiency of drone communication systems through a two-stage game, and managed spectrum resources in cognitive radio networks by combining combinatorial auctions with game theory.These methods not only enhanced the utilization efficiency of spectrum resources but also advanced the performance of communication networks.References [14][15][16][17][18][19][20] explored dynamic spectrum sharing and allocation strategies in various wireless communication networks, covering scenarios ranging from cognitive radio networks to multi-operator communication systems.For instance, Saha studied how to implement dynamic spectrum sharing technologies in buildings using small cell architecture, while Nair and others discussed the application of hybrid spectrum sharing in dynamic spectrum access networks.Ikami and his team focused on the fair distribution of spectrum resources among different wireless systems.On the other hand, Sumithra provided an overview of spectrum sharing and dynamic spectrum allocation schemes in cognitive radio networks.Umar and colleagues reviewed spectrum sharing strategies for multi-operator wireless communication networks in the next generation and provided a roadmap for future research.Sorayya and Suryanegara modeled spectrum sharing between a primary operator and two secondary operators.These studies demonstrated the significant role of dynamic spectrum management in enhancing spectral efficiency and promoting more flexible and efficient development of communication networks.
In previous research on spectrum resource sharing, transactions were typically negotiated between buyer base stations with limited resources and seller base stations with surplus resources.After determining the price and transaction volume, the buyer base station would directly utilize the idle frequency bands of the seller base station.However, this approach fails to accommodate real-time network demand changes, resulting in spectrum resource wastage.
In our research, we focus on enhancing the efficiency and security of spectrum resource sharing between base stations in the IoV using blockchain-based smart contracts.We developed a consortium blockchain with various types of nodes to ensure a secure and swift spectrum sharing process.Base stations of both buyers and sellers act as master nodes, while some vehicles using the buyer's operator services serve as light nodes to facilitate transactions.We implemented an improved asynchronous Byzantine fault tolerance consensus algorithm to handle network instability during spectrum sharing in the IoV.When the buyer's base station experiences spectrum resource shortages, vehicles using the buyer's operator services can directly connect to the seller's base station through an agreement, enabling inter-network roaming.Lastly, we integrated the Stackelberg game theory into the spectrum sharing process, allowing the seller's operator base station to engage in strategic interactions with connected vehicles.This approach maximizes the benefits for both buyers and sellers while ensuring an optimal utilization of spectrum resources.
The Byzantine fault tolerance algorithm is a fault tolerance mechanism used to handle malicious nodes in a system, ensuring that the system can correctly process messages and reach consensus even if some nodes fail or behave abnormally.The asynchronous Byzantine fault tolerance algorithm is a variant of this algorithm that does not require all participants to be online simultaneously or for information transfer between them to have strict timing.It is more suitable for network environments with delays and uncertainties.The improvements in this study include the efficiency optimization of the algorithm, stronger fault tolerance capabilities, and support for dynamic participant sets.Specifically, in the vehicular network environment, this algorithm can adapt to highly dynamic and changing network conditions, ensuring that consensus can be quickly reached even in unstable networks or with frequently changing nodes.
The Stackelberg game is a model in game theory where a leader makes a decision first, and then followers respond based on the leader's decision.This model is often used to analyze and optimize the interaction between leaders and followers, such as in price setting and resource allocation.In dynamic spectrum sharing, base stations that own spectrum resources are typically considered leaders, while vehicles or other base stations that need the spectrum are considered followers.By applying the Stackelberg game model, the leader base station can optimize spectrum pricing and allocation strategies to maximize its benefits while also meeting the needs of the followers, achieving a Nash equilibrium for both parties.

Multi-Operator Spectrum Sharing Architecture Based on Consortium Blockchain
As depicted in Figure 1, in the scenario under consideration, several distinct telecommunications operators coexist within the same geographical region.Each operator possesses a network of proprietary base stations, through which they establish their individual telecommunications networks.In situations where vehicles within this scenario require communication capabilities, they will connect to the base station of the operator they belong to.Additionally, this scenario incorporates numerous Road Side Units (RSUs), which have the capacity to access the network infrastructure established by each operator's base stations.
It can be seen that Operator A is in low load and Operator B is in high load, so Operator A can become a seller to sell spectrum resources to Operator B who becomes a buyer.
To facilitate the credible sharing of spectrum resources within this scenario, we have developed a specialized consortium blockchain architecture.This blockchain is comprised of a diverse array of nodes, categorized specifically into master nodes, light nodes, and auxiliary consensus nodes, each playing a distinct role in the scenario.

Consortium Blockchain-Enabled Spectrum Sharing among Base Stations
The master nodes are formed by the base stations operated by the telecom operators.These master nodes are pivotal in efficiently processing and validating transactions, thereby ensuring the integrity and security of spectrum transactions.The light nodes are constituted by a part of vehicles utilizing the services of these operators.Within the blockchain network, these vehicles serve as light nodes, storing only data and information directly relevant to them.They depend on master nodes for acquiring essential data and verification transactions.Owing to the fact that light nodes are not tasked with processing the entire blockchain, their resource demands (such as storage capacity and computational power) are significantly lower compared to master nodes.The auxiliary consensus nodes are composed of RSUs.These nodes engage in the blockchain's consensus mechanism and play a role in verifying transactions.

Analysis of Spectrum Resources and Decision-Making in Trading
Within the designated scenario, each operator undertakes an analysis of spectrum demand across their network of base stations during a predefined phase interval, denoted as time t.This analysis is aimed at assessing the adequacy of their spectrum resources.Based on this assessment, operators determine whether to procure additional spectrum resources from other operators in the subsequent phase or to allocate some of their spectrum for use by other operators, thereby generating profit.
Operators can make the following trading decisions, contingent upon their remaining spectrum capacity:

•
Opt-out of the trading process for the current phase.

•
Seller's decision: Upon identifying an excess of spectrum resources, an operator may elect to become a seller, offering these surplus resources to other operators in need and thereby deriving revenue.

•
Buyer's decision: In the event of a spectrum shortfall, an operator may decide to act as a buyer, engaging in transactions with other operators possessing excess spectrum resources, to fulfill the communication requirements of their clientele.

Profit Model
In our model, the benefits for both the buyer and seller operators are quantifiable.The seller operator's profit arises from base stations with excess spectrum resources providing communication services to vehicles using the buyer operator's services, thereby earning remuneration from the buyer vehicles' operator.On the buyer's side, the advantage manifests as enhanced communication quality and accelerated data transmission rates for user vehicles.Previously, we proposed a related profit model, which was published in the 2023 IEEE 23rd International Conference on Communication Technology (ICCT) [12].
We assume each base station involved in spectrum sharing can offer a total spectrum quantity of Q, and the number of buyer vehicles requiring spectrum sharing with this base station is M, with each vehicle demanding a bandwidth of i B , where i = 1, 2, 3, ..., M.
Additionally, each base station must reserve a portion of the spectrum a Q , because of the possibility of new users accessing and thus occupying the spectrum, necessitating the satisfaction as in Suppose the cost per unit of spectrum resource is , and the cost of the seller's base station for each buyer's vehicle as well as the total cost overhead can be expressed as in Then, we consider the spectrum resource cost for each buyer's vehicle; namely, the buyer vehicle's operator must pay the seller base station's operator.Assuming the base station's per unit bandwidth selling pricing is i p , the payment required by a vehicle's operator to the base station correlates with the needed bandwidth quantity and per unit bandwidth pricing, as in Having accounted for the expenditures of both vehicles and base stations, we now turn to their revenues.The vehicles' profit is linked to the communication link's bitrate

B
; an increased bitrate signifies improved communication performance and faster data transfer rates.A threshold th C is established as a benchmark to evaluate if the commu- nication performance meets the expected standard.Utilizing the square root here gives a smoother picture of the trend of change, so the revenue for vehicles is thus articulated as in The seller's base stations earn revenue by the vending spectrum.If M vehicles require spectrum purchases from a base station, the total revenue is depicted as in Utilizing Equations ( 1) and ( 3)-( 6), we can formulate the profit function for the buyer and seller, as in In this equation, We put the proof of the existence of Nash equilibrium in Appendix A.

The Stackelberg Game in Spectrum Trading
In our study, since we consider that each participant in spectrum trading tries to maximize profit, we model this mechanism by introducing the Stackelberg game.In this strategy, the seller's base station assumes the role of the leader, owing to its control over the residual available spectrum.As the leader, the seller's base station not only wields the power to allocate spectrum resources but also exercises predominant influence over pricing.Consequently, it initially sets the price per unit of spectrum resource, incorporating considerations of dynamic demand-supply fluctuations, operational costs, and profit objectives.Conversely, the buyers act as followers in this game.They determine the quantity of the spectrum to purchase, guided by the price stipulated by the leader and aligned with their specific communication requirements.Their decisions are influenced by factors including the price, communication quality, and data transfer rates.
As illustrated in Figure 2, within the iterative dynamics of the Stackelberg game, the strategic adjustments and interactions of both parties persist until a point of equilibrium is achieved-the Nash equilibrium.At this juncture, neither participant can enhance their profit by unilaterally altering their strategy.This state signifies that both buyers and sellers have attained their maximum possible profits.

Consensus Mechanism Implementation
Upon establishing optimal pricing and resource allocation strategies, we confirm the volume of spectrum resources shared by sellers and their unit spectrum price.The participants are pre-approved and their identities are verified and there is mutual trust between the buyer and the seller.Consensus will be reached between the buyer and seller through a federated blockchain system.
Consequently, we improve the asynchronous Byzantine fault-tolerant consensus algorithm as our consensus mechanism to better fit our proposed scenario.Its most significant characteristic is that it can achieve consensus without the need for synchronous communication between nodes, which is very suitable for communication networks with high network delays and complex environments.Unlike traditional consensus algorithms that require the synchronization of all nodes, this system, through its unique operating method, can maintain operation and successfully achieve consensus even in situations of high network latency or partial node failure.
The flow of our proposed algorithm is as follows: 1. Transaction Preparation and Distribution: The buyer's master node, after analyzing the spectrum resources needed for the transaction, selects an appropriate number of vehicles under its service as light nodes for this consensus round.It prepares a transaction request encompassing the buyer's identity, intended spectrum usage, and transaction timestamp.Similarly, the seller's master node prepares its transaction request with the seller's identity, spectrum to be shared, and timestamp.Both nodes encrypt and distribute this transaction information to all nodes in the network, which then respond upon receipt.2. Transaction Collection: Post-distribution, master nodes gather and decrypt transaction data sent by other master nodes.Vehicles designated as light nodes gear up to switch connections to the seller's base station and utilize the traded resources.3. Achieving Consensus: Through multiple communication rounds, master nodes reconstruct and authenticate each other's transaction information, eventually reaching a consensus on the transactions' validity and order.4. Block Formation: All authenticated transactions and data regarding participating light nodes are compiled into a new block, subsequently being added to the blockchain. 5. Block Broadcasting and Verification: This new block is broadcast across the network to all master, auxiliary, and consensus-participating light nodes.Each node independently verifies the block's transactions upon receipt, ensuring their legitimacy.6. Feedback on Results: Light nodes corresponding to vehicles, after consensus, will connect to the seller operator's base station according to the transaction information and occupy the relevant spectrum resources included in the transaction.
Auxiliary consensus nodes, while not directly involved in transaction creation, participate in the verification process.Following the consensus and creation of a new block by the master nodes, these auxiliary consensus nodes independently verify the accuracy of these blocks and document the transaction data, thereby enhancing the system's redundancy and reliability.

Simulation Results
In order to validate the effectiveness of our proposed architecture, we simulated the time taken for multiple systems to reach consensus.We deploy the system using the Ethereum smart contract platform.Prior to deployment, the identities and permissions of all participating nodes are authenticated and registered on the blockchain.To adapt different network latency conditions, we adjust the synchronization intervals and transaction confirmation times accordingly.Node configurations are then completed, where the master node manages transaction requests, initiates verification, and oversees the consensus process.Light nodes dynamically join or leave the network based on their assigned tasks, with reconnection mechanisms and data synchronization features designed to address potential disconnections.Auxiliary consensus nodes assist in data verification and consensus decision-making, ensuring data consistency and integrity.Taking into account different network scales, we set the number of light nodes to 10, 20, and 30, respectively.Considering that communication distance or vehicle speed and other factors may cause different delays, we set the network delay to 100 ms, 300 ms, and 1000 ms, respectively.The specific parameters are in Table 1.We varied the number of light nodes under different network delay conditions and compared our proposed algorithm with the HBBFT algorithm.After several simulation tests, we obtained the average value in Figure 3; the systems utilizing the algorithm we proposed are represented by a column bar with a diagonal line, while those using the HBBFT algorithm are shown as a column bar without a diagonal line.The results show that, in this scenario, irrespective of network latency and the number of light nodes, the algorithm we proposed always outperforms the HBBFT algorithm in terms of consensus speed.Furthermore, as the network latency and/or the number of light nodes increase, it is observed that reaching a consensus requires more time.Considering that communication distance may cause disconnection issues, we also simulated the system's fault tolerance.In Figure 4, we set different rates of light node failure (10%, 20%, 30%) under varying network latencies and quantities of light nodes.The simulation results suggest that despite a slowdown in the speed of consensus, it is still successfully achieved in all scenarios.It can be seen that the algorithm we proposed has a superior speed in this scenario compared to HBBFT.To investigate the efficacy of Stackelberg game-based spectrum resource allocation, we establish a scenario where a seller base station allocates bandwidth to five buyer vehicles' impending connection.The respective channels are designated as Channel 1~5, with the simulation capturing both sides' profit in real-time.We conform to the standard parameters mentioned in Table 2, with an initial bandwidth of 1.2Mhz, and a bitrate threshold set at 5 Mbps.According to Figure 5, after 12 iterative adjustments, bandwidth distribution starts to stabilize.Coupled with Figure 6, it is apparent that the highest profit for both parties is achieved at the 12th iteration, indicating a Nash equilibrium situation.After calculating the bitrate using data from the 12th iteration, the results are shown in Table 3; we obtain bitrates for Channel 1~5 as 8.58, 8.31, 8.37, 8.55, and 8.76 Mbps, respectively, all of which surpass the pre-established bitrate threshold, thus validating the communication speed.We also tested bandwidth allocation under different noise power and different disturbance.As shown in Figure 7 and Figure 8, bandwidth can be effectively allocated under different circumstances.

Discussion
Simulation results indicate that our architecture and algorithm exhibit strong performance under various network delays and node configurations, significantly reducing the time required to achieve consensus and demonstrating robust fault tolerance.The system can operate with node numbers of 10-30 and node failure rates of 10-30%.Compared to other algorithms, our solution shows varying degrees of improvement in consensus speed.The Stackelberg game can effectively allocate bandwidth in this scenario, achieving efficient bandwidth utilization and maximizing the benefits for both parties, ultimately enhancing data transmission rates and communication quality in vehicular networks.Before spectrum sharing, users might be unable to access the network due to insufficient bandwidth resources, but after spectrum sharing, the users' bitrate exceeded our set threshold, allowing normal network service usage.In future research, we will consider larger network scales and the impact of different communication ranges.

Conclusions
This research successfully demonstrates the effective promotion of dynamic spectrum sharing in the IoV context via blockchain-based smart contracts.By developing a consortium blockchain architecture and implementing an improved asynchronous Byzantine fault tolerance algorithm, we have enhanced both the spectrum resource utilization efficiency and the system's security and reliability.Moreover, this study utilizes the Stackelberg game approach to optimize spectrum resource allocation, ensuring that all parties reach Nash equilibrium in transactions, thereby maximizing benefits.
Our envisioned future development directions: Continue to improve and optimize the algorithm to adapt to a wider range of network conditions and higher performance requirements, such as reducing the communication overhead of the algorithm and enhancing its scalability.Strengthen the security of blockchain and smart contracts, and develop new encryption technologies and verification mechanisms to prevent fraud and attacks, especially in open vehicular network environments.Explore interoperability with other types of blockchains (such as public chains and private chains) to support a broader range of application scenarios and more complex service needs.Deploy and test the proposed system in real vehicular network environments to verify its actual performance and applicability.
Our envisioned specific application areas: In smart cities and intelligent transportation systems, use blockchain technology, smart contracts, and game theory to manage and optimize communication resources among vehicles.In commercial wireless network ser-vices, apply dynamic spectrum management technology to provide more flexible communication services.In emergency situations (such as natural disasters and major public safety events), ensure the rapid allocation and reliable use of communication resources.
This research affirms the efficacy of blockchain-based smart contracts in managing a dynamic spectrum, offering valuable insights and references for future research and practical applications in wireless networks.

Data Availability Statement:
The original contributions presented in the study are included in the article.The pseudo-code is uploaded to https://github.com/qinchilee/Dynamic-Credible-Spectrum-Sharing-Based-on-Smart-Contract/tree/main(accessed on 6 June 2024).

Conflicts of Interest:
The authors declare no conflicts of interest.

Appendix A
In accordance with Stackelberg game theory, it is understood that the attainment of Nash equilibrium coincides with the maximization of returns.Subsequently, we aim to demonstrate the existence of a maximum in the profit function.
First, we need to derive the profit function c U with respect to bandwidth i B to find the point of the maximum extremum.According to Shannon's formula, it can be known that there is the following relationship between  .
In order to judge the concavity or convexity of a function to determine whether the extreme point is a maximum extreme point, we also need to calculate the second-order derivative of c U with respect to

Figure 1 .
Figure 1.System model diagram in vehicle networking scenario.

iD.
When a seller's base station shares a quantity i B of spectrum resources to a buyer's vehicle, the base station's cost is i C .Therefore, for M vehicles, the total cost of the seller's base station is

cU
represents the buyer's profit, and b U represents the seller's profit; we need to maximize the profits of both parties, where bandwidth i B is subject to Q and a Q .

Figure 3 .
Figure 3. Consensus time comparison with different delay and node count.

Figure 4 .
Figure 4. Node failure consensus time comparison with different node count and failure rate.

Figure 5 .
Figure 5. Bandwidth allocation for different channels with iteration times in Stackelberg game.

Figure 6 .
Figure 6.Profit for seller/buyer with iteration times in Stackelberg game.

Figure 7 .
Figure 7. Bandwidth allocation under different noise power in Stackelberg game.

Figure 8 .
Figure 8. Bandwidth allocation under different disturbance in Stackelberg game.

Author Contributions:
Conceptualization, Q.W. and Q.L.; methodology, Q.W.; software, Q.L.; validation, T.C., Y.Y., and S.X.; investigation, Q.L.; resources, H.Z.; writing-original draft preparation, Q.L.; writing-review and editing, H.Z.; supervision, Q.W.All authors have read and agreed to the published version of the manuscript.Funding: This work was supported in part by the Postgraduate Research & Practice Innovation Program of Jiangsu Province under KYCX23_1020, the National Natural Science Foundation of China under Grant 92367302 and Grant 62371250, the Natural Science Foundation on Frontier Leading Technology Basic Research Project of Jiangsu under Grant BK20212001, and the Jiangsu Natural Science Foundation for Distinguished Young Scholars under Grant BK20220054.

iB.
According to the known conditions, we can conclude that maximum value point.