# Blockchain Technology for Secure Communication and Formation Control in Smart Drone Swarms
## 4 Materials and Methods  
### Proposed Scheme  
The scheme that is studied in this work follows the leader-follower strategy. The leader (only) can register (or delete) drones in the swarm based on their addresses (Listing 1). If drones have not been registered by the leader, they cannot use any of the smart contract's functionality. Drone registration is a method of authorization in order to enhance the security of the proposed system. ```
1 functionaddDrone(addressdrone)publiconlyLeader{
2 drones[drone]=true;
3 droneCount++;
4 emitDroneAdded(drone);
5}
```  
Listing 1: Drone registration function. This specific function can be called only by the swarm's leader; therefore, the onlyLeader modifier is used to prevent access from the other members. All drone addresses are stored in the drones[drone] mapping, along with a Boolean variable that is set to true if the drones have been successfully registered in the swarm. This function also has an opposite function called removeDrone, with the main difference being that the Boolean value is changed to false. The opposite function can be called by the leader, for instance, if a voting procedure is conducted and the majority of the swarm members decide that a specific drone has been compromised. In this way, the malicious drone can be stopped from using the smart contract's features. Therefore, the hacker will not be able to obstruct the task that the rest of the drones have to finish. The challenge of creating such a mechanism still needs to be addressed in future research. Subsequently, a new transaction can be started by the leader utilizing the submitData function to submit data along with its location (Listing 2). The swarm's followers can also utilize this specific function. For instance, location or other information that their sensors may have gathered can be submitted to the blockchain by the members of the swarm using this method. Figure 4: Advantages of using blockchain technology in UAV clusters. ```
1 functionsubmitData(stringmemory_location,stringmemory_data)public{
2 require(drones[msg.sender],\"Error:Adronemustbeinthe
3 warminordertosubmitdata.\");
4 droneData.push(DataCollectedByDrone(block.timestamp,_location,_data,msg.sender));
5}
```  
Once these tasks are finished, the leader can submit the mission information to the blockchain to generate a new transaction. The mission is identified by its name, a distinctive identifier (id) that sets it apart from other missions; its type (missionType); suitable formation (formationType); and a Boolean parameter that indicates whether the particular mission is operational (Listing 3). A specific type of mission (dive and attack, search and rescue, city surveillance) can be selected by the leader in the proposed smart contract. These missions are illustrative, though it would not be difficult to add to or modify the list. A mission can be created by the leader using the following method:  
```
1 functioncreateWission(stringmemoryname,MissionType missionType,FormationTypeformationType)publiconlyLeader{
2 uint16 missionId=missionCount;
3 missions[missionId]=Mission(missionId,name,missionType,formationType,false);
5 missionCount++;
6 emitMissionCreated(missionId);
7}
```  
A mapping missions[missionId] is used, which takes as a key the ID of each mission in order to identify it. One can see that initially, the mission is declared inactive (a false Boolean) during its definition. This is so it can be activated or deactivated whenever needed by the leader (Listing 4). In this way, there is better synchronization in cases where several missions have been declared. The formation that the swarm must follow depends on the type of mission assigned by the leader (Search, DiveAttack, CitySurveillance) and is determined automatically (Ring, V, and Line, respectively).