Abstract
Spectrum sensing is the key technology of cognitive radio. In this article, we apply blockchain technology in spectrum sensing process and propose a related algorithm based on reputation. The algorithm builds a system model based on smart contract in blockchain and applies blockchain asymmetric encryption algorithm and digital signature technology in the process of secondary users’ transmitting local judgments to the secondary user base station. The algorithm can resist spectrum sensing data falsification (SSDF) attack launched by malicious users. This article comprehensively considers the channel error rate, detection probability, secondary user base station budget and remaining energy of the secondary users (SUs) and then establishes the SU’s utility function as well as the game model. By solving the Nash equilibrium, the SU determines whether it uploads sensing data. Finally, the SU base station selects registered SUs by calculating and updating their reputation, obtaining the final judgment by voting rule. With simulations, we prove that the algorithm proposed in this article increases the accuracy and security of spectrum sensing and can effectively resist SSDF attack.
Introduction
With the vigorous advances in the mobile Internet and the Internet of Things, people’s demand for spectrum resources is even more urgent. 1 Traditional radio spectrum allocation is a fixed allocation strategy, which prevents the spectrum resources from being fully utilized. Cognitive radio technology is a spectrum sharing technology which has a significant role in improving spectrum utilization. 2 Spectrum sensing is the key technology of cognitive radio systems. When spectrum sensing is performed by a single SU, it is easily affected by shadow effects, multipath fading and other factors, so it is difficult for a single SU to make correct local judgments. Multi-user cooperative spectrum sensing can overcome these difficulties, but it will bring some conditions such as malicious SU collusion attacks and tampering of sensing data, 3 which will seriously affect the performance and efficiency of spectrum sensing. Blockchain technology can effectively solve these problems. 4
People have conducted in-depth research on spectrum sensing technology. Khasawneh et al. 5 proposed a routing algorithm to perform spectrum sensing and realize spectrum management. They defined a parameter to measure SUs’ sensing behaviors and encoded sensing data. To optimize spectrum sensing performance and power allocation, Karimi et al. 6 proposed a probabilistic spectrum access scheme. Hu and Zhu 7 applied incentive mechanism of crowdsensing in cooperative spectrum sensing and proposed a relative algorithm based on game to maximize the utility of SU. Kotobi et al. 8 proposed a puzzle-based spectrum sharing auction mechanism. For SUs who want to buy available spectrum, a puzzle is set as a threshold, and only the first SU who solves the puzzle correctly can obtain the right to use it. Zhu et al. 9 presented a reverse Vickery auction incentive mechanism(RVA-IM) and conducted research and analysis on provider selection, payment determination and QC process. From the perspective of behavioral economics, Liu and Gao 10 studied the influence of user loss aversion on the results of spectrum sensing and proposed an incentive mechanism based on user loss aversion. However, the above researches do not consider the security issues of spectrum sensing. Since incentive mechanism is actually a transaction between SU base station and SUs, the above articles lack a reliable mechanism to ensure the security of transactions and to defend the attack of malicious users.
Blockchain technology can guarantee the security of transactions. Blockchain is a chain-type data structure connected in chronological and is order based on blocks. 11 It does not require a third party to interference and monitor. Blockchain uses cryptography technology, consensus mechanism and some other technologies to maintain a set of tamper-resistant ledger records among mutual distrust or weak trust SUs so as to ensure the consistency, authenticity, security and reliability of data shared by nodes in the distributed network, 12 and blockchain can effectively resist malicious attacks. He et al. 13 proposed an incentive mechanism in the application of crowdsensing based on blockchain, which quantifies the contribution of SUs to distribute payments and uses digital watermarking technology to process the sensing data uploaded by SUs. Sun and Xiong 14 established a consortium blockchain on multiple authorized local base stations, regarded the use of spectrum resources as a transaction and proposed a loan-based payment scheme, giving an optimal pricing strategy. The importance role of consensus mechanism in blockchain technology and the comparison of the two main consensus mechanisms Proof of Work(PoW) and Proof of Stake(PoS) are shown in literature. 15 PoW is that the node with the largest computing power will eventually win the mining, while PoS means that the node with more coins will mine blocks more easily. Bayhan et al. 16 proposed the Spectrum Sensing as a Service(Spass) system model and two-threshold based voting(TTBV) algorithm via smart contracts. The algorithm can ensure that malicious users will be excluded. Chen et al. 17 established a data transaction framework based on consortium blockchain and proposed an iterative double auction mechanism. The mechanism aims to prompt buyers and sellers to submit their bids as well as determine how many and how much of the spectrum resources they want to transact. Kotobi and Bilen 18 proposed a blockchain verification protocol that uses the First Come First Service(FCFS) auction mechanism for transactions. They also introduced a virtual currency called Specoins to pay fees in spectrum transactions. However, the above literatures rarely consider the existence of malicious users at the stage of selecting users by the SU base station and lack a practical selection mechanism. In addition, these researches do not consider the reputation of SUs or apply smart contract to spectrum sensing.
Smart contract is a computer transaction agreement that executes the contract digitally on the blockchain. These transactions are transparent, traceable and irreversible. Based on blockchain technology, this article proposes a secure cooperative spectrum sensing algorithm to improve the accuracy and efficiency of spectrum sensing while resisting MU attacks. We regards the SU base station and each SU as a node on the blockchain and transform the entire spectrum sensing process into the automatic execution of smart contracts on the blockchain. The algorithm first defines the utility function of the SU, establishes the optimization problem of maximizing the utility of the SU and obtains the optimal sensing time of the SU in the way of game. The SU base station adopts a reputation mechanism proposed in this article to select SUs and exclude malicious SUs. Finally, the SU base station adopts voting rule to make the final judgment according to the weight of each user’s reputation value. The main contributions of this article are summarized as follows:
We construct a cooperative spectrum sensing system model based on smart contract of blockchain to execute the entire spectrum sensing process automatically. Once trigger conditions are met, the smart contract will execute automatically on the blockchain, which realizes the autonomy of transactions and improves overall efficiency. During the stage of SUs upload local judgments, we use asymmetric encryption technology to encrypt and digitally sign the uploaded data, so as to prevent malicious users from impersonating as normal SUs to upload low-quality sensing data and reducing the probability of normal SUs being selected.
We propose a SU utility optimization algorithm using game theory. Since SUs report sensing data to the SU base station wirelessly, there must be errors during the transmission. Therefore, channel error rate is considered in this article, which is closer to the actual situation. We define the SU utility function based on the detection probability, reward, channel error rate and the remaining energy of the SU, and then calculate the unique Nash Equilibrium. Once all SUs achieve the Nash Equilibrium, the utilities of SUs are maximized and cannot be improved by deviating from current strategies. We prove the existence of Nash equilibrium and obtains the closed expression of the optimal sensing time.
We design a reputation mechanism for the SU base station to distinguish malicious users from normal ones by comprehensively considering their historical sensing behaviors and detection probability. The SU base station checks the historical sensing behaviors of each SU from the blockchain and updates their reputation values. In the fusion stage, the fusion center assigns different weights to each SU according to their reputation values and obtains the final judgment by voting rule.
The rest of this article is arranged as follows. We describe the system model and smart contract model in Section II. We formulate the optimization problem and prove the existence of the Nash Equilibrium in the game in Section III. We propose a reputation mechanism in Section IV. The results of simulations and analyses are shown in Section V. Finally, the conclusion is summarized in Section VI.
System model and smart contract model
System model
As shown in Figure 1, a cognitive radio network consists of a SU base station, a primary user, N SUs and some malicious users, which are all nodes on the blockchain. The SU base station publishes spectrum sensing tasks via smart contract. Each SU calculates their own utility according to utility function, and they will accept sensing task once the utility is larger than the average utility. SUs perform local spectrum sensing tasks through energy detection and send the encrypted sensing data to the SU base station. Then the SU base station selects SUs by their reputation and uses voting fusion algorithm to make the final judgment.

System model.
The SU uses energy detection to sense the spectrum.
Where
After the SU base station receives the sensing data reported by SU, it uses the voting rule to process the data. The voting rule is that the system sets a voting threshold
Where
Spectrum sensing based on smart contract
The essence of blockchain is a distributed network. It combines multiple technologies, such as asymmetric encryption technology, consensus mechanism, smart contract and peer-to-peer transmission. Asymmetric encryption technology can ensure the security of the transaction while smart contract can realize its programmability and autonomy. Applying blockchain technology to the spectrum sensing process can enhance the convenience and security of sensing execution. Smart contract runs on the blockchain. It’s a piece of code that writes the contract into the blockchain in a digital form. When the content of the contract is satisfied, the code will be automatically executed, which not only avoids the complicated manual operation, but also ensures both parties cannot violate the contract. Due to the characteristics of the blockchain, data cannot be deleted or modified. The entire process is open and transparent and the source can be traced, which greatly avoids malicious attacks that interfere with the normal execution of the contract. The decentralized characteristic of the blockchain can also improve the efficiency and cost advantages of smart contract.
Blockchain is actually a database system which can be distributed in various places and can operate in coordination. The traditional database system presents the characteristics of centralization, while the blockchain, on the contrary, is decentralized. Distributed users, as long as they are connected to the blockchain network, can be a node on the blockchain. All nodes have the rights to read and write data in the database system. The operation is updated synchronously for all nodes. Blockchain is composed of many blocks. A block is composed of block header and block body. Block header records the initial information of the block, such as the hash value of the previous block, the timestamp, the blockchain protocol version, the root hash value of the Merkle tree of the block body, etc. The block body stores the detailed transaction data. The “chain” of the blockchain means the hash pointer and each block is connected in series through the hash value of the previous block stored in its own block header, thus forming a blockchain.
As shown in Figure 2, the SU base station publishes spectrum sensing tasks and proposes task requirements including collection time, budget, geographic location restrictions and frequency band range. Then it uses blockchain-supported programming languages such as Solidity to write tasks into smart contract codes and publishes the written smart contract. Miners package it and write it into the blockchain. Although the smart contract is published on the blockchain, it will not execute automatically in that corresponding trigger conditions must be satisfied. In this article, the trigger condition is that the SU chooses to accept the task after viewing the content of the task and register on the smart contract. After the smart contract is released on the blockchain, the SU base station broadcasts the address of the smart contract on the blockchain. Interested local sensing nodes can retrieve the content of the contract through the address and view the requirements of the sensing task. It calculates its own utility according to its preferences, remaining energy, geographic location, estimated reward and other factors. If the utility is greater than the average of all SUs’ utility, the SU accepts the spectrum sensing task and registers on the smart contract. The smart contract then selects registered nodes with the consideration of its budget, the asked price of SUs and their reputations. Selected nodes start to carry out the sensing task, then they upload sensing results to the SU base station with their digital signatures. The SU base station decrypts and fuses the sensing data as well as pays rewards.

Spectrum sensing based on smart contract.
Digital signature is another characteristic of blockchain. Through the verification of the digital signature, the information can be guaranteed not to be tampered during the transmission. Digital signature can also ensure the security of the information and resist malicious attacks. Digital signature is composed of digital digest and asymmetric encryption technology. First, the information is shortened into a fixed-length string through digital digest technology. Then the digest is encrypted using asymmetric encryption technology to form a digital signature. In order to prevent malicious users from impersonating normal SUs or tampering with the sensing data of normal ones, in which case normal SU’s reputation and probability of being selected will be reduced, we apply blockchain digital signature technology to the process of SU base station verifying spectrum data. Each spectrum sensing device register on the blockchain network, that is, generate a pair of public key and private key

Digital signature.
SU sensing time game
If the channel between the SU and SU base station is ideal, the sensing results of local SUs can be accurately reported to the SU base station through the control channel. However, actually the wireless channel is often influenced by fading and interferences, which cause bit errors in the transmission and deteriorates the performance of spectrum sensing. Assume that the channels between all SUs and SU base station are independent and identically distributed. The channel error rate is
Denote
The probability that the SU base station receiving the local judgment of the SU
Where
The final expression of the voting rule used by the SU base station is
For a SU, the benefit of participating in spectrum sensing is to get a reward from the SU base station, which is related to the sensing accuracy. The sensing accuracy is related to the sensing time. The longer the time, the higher the accuracy. However, the SU also needs to pay a certain cost to sense the spectrum. When performing tasks, the SU will consume energy. The longer the sensing time, the greater the energy consumption paid. So the utility is a comprehensive consideration of rewards, sensing time, and energy consumption. For a SU, when the remaining energy is small, it is unwilling to participate in sensing tasks, so the remaining energy factor is considered in the utility function. Therefore, the utility function is the difference between the sensing reward and the cost
Where
In formula (11), only the sensing time can be determined by the SU. In order to optimize its own utility, the SU needs to determine its own optimal sensing time, so the optimization problem can be expressed as
There is a game among N SUs and the game strategy of each SU is the sensing time. Since every SU is rational and selfish, they will aim to maximize their own utilities. Nash equilibrium is the best result that each SU can get in the game. When other SUs keep their strategies unchanged, every SU’s strategy is the best strategy and any SU can’t get higher reward by only changing its own strategy.
Game theory is a mathematical method to study competitive phenomena among players. In a game, players are interrelated with each other. Each player will not only affect other players, but also be affected by other players’ strategies. These strategies will affect the final overall decision. Formula (11) shows that the utility of each SU has relations with its sensing time, detection probability and remaining energy as well as other SUs’ detection probabilities. Therefore, the SU can take part in a game to maximize its utility.
Equilibrium refers to the optimal strategy combination of all players in the game. Nash equilibrium refers to the strategy of the players in the game reaching a stable state, that is, when the strategies of other players remain unchanged, any player’s strategy is optimal. In the game
When the above condition is satisfied,
In the game
The game is a finite and non-empty set;
Strategy set
The utility function is strictly concave.
The following is the proof of the existence of Nash equilibrium in the SU sensing time game:
The strategy set of the SUs is
The first-order derivative of
Where
For simplicity, let
So the derivative of
Let
So the second-order derivative of
Where
Where
It’s obvious from the formula of
Since the second-order derivative of
if the maximum value of the first-order derivative of
When the detection probabilities of other
User selection method based on reputation mechanism
Reputation mechanism
The SUs receiving the task sense the signal transmitted by the primary user and make a local judgment. Then they send the local judgment to the fusion center which merges the local judgments to make the final judgment. In order to find and eliminate malicious users, this article proposes a reputation mechanism. The SU base station checks the historical sensing behaviors of each SU from released blocks and updates reputation continuously according to the number of times the SU sensed tasks successfully in the past as well as the detection probability of this sensing task. In the fusion stage, the fusion center assigns different weights to each SU according to different reputations. The higher the reputation is, the more weight SU will get. On the contrary, the malicious SUs will be given lower weights or even be excluded in the final judgment. In this way, the accuracy of the final judgment is improved. In order to avoid malicious SUs, the SU base station publishes the updated reputation on the blockchain, which not only prevents tampering, but also is publicly visible to all SUs.
In the user selection stage, the SU base station sorts SUs according to the selection function
Where
The local sensing result of the SU
Where
Then the SU base station compares
Assuming that the maximum storage length of the SU base station for the sensing behaviors of the SU is
Algorithm
This article proposes a cooperative spectrum sensing algorithm based on reputation mechanism. First, the optimal sensing time and optimal utility of each SU are solved. If the optimal utility of the SU is greater than the average utility, then it participates in the spectrum sensing task. Then the SU base station updates the reputation of each SU and sorts the selection function in descending order to select SUs from large to small with the constraint that the budget is positive. The specific processes are shown in Algorithm 1.
Performance evaluation
To evaluate the performance of the algorithm proposed in this article, we set the coordinate of the SU base station as (0,0) and 100 SUs are distributed in a circular area with a radius of 100 meters randomly. The center of the circle is SU base station. The remaining energy of SUs is random from 20% to 100%. We set sampling frequency
Figure 4 simulates the convergence evolution of the utility of four random SUs. It is clearly that the SU utility can realize stability after about four iterations. From the convergence it is obvious that Nash equilibrium exists. The Nash equilibrium is not necessarily the optimal utility of each SU, but a globally stable state of all SUs. Meanwhile, the corresponding sensing time is the optimal sensing time for each SU. When the strategies of other players remain unchanged, any player in the game cannot obtain higher utility by changing its own strategy.

Convergence evolution of SU utility.
Figure 5 shows the performance comparison of the number of SUs and their utilities when the budget varies from 200 to 500. It is observed that when the number of SUs is constant, a higher budget makes the higher utility. The reason is that when the budget is higher, the reward of each SU also increases. Since the cost of SU has not changed, the utility increases. When the budget remains unchanged, more SUs results in the decrease of the average utility. The reason is that when the budget is assigned to more SUs, the reward available to each SU is reduced. As a result, the utility decreases. Compared with literature, 21 the SUs in this article can obtain higher utility. The sensing cost of SUs in literature 21 may be higher, so the utility is lower.

Performance comparison about the average utility of the number of SUs.
Figure 6 simulates the performance impacts of the budget on detection probability of SU. It is clearly that the detection probability of the SU increases with the growth of the budget which is better than literature. 21 The reason is that when the budget grows, the SU can get higher reward. As a result, the utility will increase and more SUs will be willing to take part in spectrum sensing. SUs will increase their sensing time so as to increase the probability of being selected in the process of gaming. Because of this reason, the detection probability will also increase. Literature 21 is failed to consider SU’s remaining energy, so the difference in sensing time among SUs is slightly and the detection probability of literature 21 is lower.

Performance impacts of budget on detection probability.
Figure 7 simulates the utility of a SU when the remaining energy changes from 20% to 100%. From the figure it can be seen that the greater the remaining energy of the SU, the larger the utility. The reason is that when the remaining energy of the SU is greater, the lower its spectrum sensing cost. Yet the reward of the SU is only related to the budget of the SU base station and the detection probability of the SU and has nothing to do with its remaining energy, so its utility is also greater. When the remaining energy is larger than 70%, the utility tends to be stable. This is because the remaining energy in the utility function of this article is a logarithmic function. It can be seen from the property of the logarithmic function that when the independent variable is relatively large, the function value becomes stable. In that literature 21 doesn’t take the impact of the remaining energy of the SU on utility into consideration, the utility of the algorithm in literature 21 is lower than that in this article.

Relationship of remaining energy and utility of SU.
Figure 8 simulates the influence of reputation on detection probability. It is clearly that when the number of SU is certain, less the number of malicious users brings higher detection probability. In the process of increasing the number of malicious users from 0 to 15, the detection probability has decreased, but it can still be maintained at a high level. When the number of SUs is 100, the detection probability with no malicious user is about 0.92, and that of 15 malicious users is about 0.86. When the number of malicious users is 5, the detection probability of literature 21 is significantly lower than that of this article. This is because literature 21 does not consider the existence of malicious user attacks and there is no reasonable and feasible SU selection mechanism. Proposed algorithm in this article can effectively identify malicious users and reduce the probability of malicious users being selected to participate in spectrum sensing, so as to increase the accuracy and security of spectrum sensing and resist SSDF attacks.

Relationship of the number of MUs and detection probability.
Figures 9 and 10 simulate the influence of different values of coefficients

Relationship of

Relationship of
Conclusion
We have introduced a secure cooperative spectrum sensing algorithm based on reputation mechanism with blockchain technology of smart contract and digital signature. With comprehensive consideration of channel bit error, detection probability, the budget of SU base station and SU remaining energy, we establish the utility function of SU, proving that a Nash equilibrium is existed in the game between SUs and solving the optimal spectrum sensing time of each SU. Then the SU base station selects registered SUs by calculating and updating the reputation of each SU. Finally, performance analyses show that our algorithm increases accuracy and security of spectrum sensing which effectively helps resist SSDF attacks.
Footnotes
Handling Editor: Yanjiao Chen
Declaration of conflicting interests
The author(s) declared no potential conflicts of interest with respect to the research, authorship, and/or publication of this article.
Funding
The author(s) disclosed receipt of the following financial support for the research, authorship, and/or publication of this article: this work was supported by National Natural Science Foundation of China (Grant No. 61971239, 61631020).
