## 4 Secure, and Private Data Filtering, and Aggregation
### Data Filtering and Aggregation
Therefore, the sink node gathers the results of all OM issued to resolve a request and uses the collected data to reconstruct the environment representation as shown in Figure 7 to detect where and when the social distancing was violated. ``` Input:\(D\) sensor node data \(w\) binary string \(S_{1},S_{2}\) symmetric encryption keys Output:\(w^{\prime}\) modified binary string FunctionMain (args) \(t_{start}\),\(t_{end}\) ;// Time interval \(t_{contact}\) ;// Time in milliseconds // Filter the interval of data between \(time_{start}\) and \(time_{end}\) \(D=\) FilterTimeInterval (\(D\),\(t_{start}\),\(t_{end}\)); // Exclude objects from the data \(D=\) FilterObjects (\(D\)); // Remove all activities that are not stationary for \(t_{contact}\) milliseconds \(D=\) FilterStationary (\(D\),\(t_{contact}\)); // Discretrize the data into an value array of underlying sensors, each value describing the number of observed events \(tile_{status}=\) DiscretizeData (\(D\)); // Use encryption keys to find the position in \(w\) where insert the data \(pos=(S_{1}+S_{2})^{\circ}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\! was Bitcoin, which uses Proof of Work to secure the blockchain coupled with the unspent transaction output (UTXO) transaction model. Even with the limited expressing power of Bitcoin's UTXO model, researchers have demonstrated that an access control can be built [40]. Microsoft implemented a decentralized identity solution running on the Bitcoin network [49], and Factom protocol, which uses the Bitcoin network as a decentralized notary service [50]. Smart contract platforms such as Ethereum use a state-based model in which state transitions are recorded in blocks. This paved the way for the development of smart contracts, Turing complete programs that are recorded on-chain. With smart contracts, more complex applications can be built. Our framework uses the OpenEthereum [51] private network as a smart contract platform that facilitates two main modules, namely Role-based access control (RBAC) and decentralized sink node for the underlying WSNs. In a permissioned setting, Ethereum is configured to run a proof of authority (PoA), in which only a selected group of nodes are configured as validators. In our use case, each building with an indoor location system operates at least one OpenEthereum node. However, preferably, most compute units that serve as sinks should run a light client. ### WSN Sink

In order to perform queries and computation, WSNs are usually deployed with a sink node. Sensors in the network collect information from the environment and ultimately transfer the data to the sink node. In practical implementations, sink nodes usually reside in the cloud and seldom on-site. Whatever the case, sink nodes arguably present a single point of failure (SPOF) of the entire system [52]. Moreover, sink nodes are easier to identify as a target due to their fixed network identity and recognizable traffic patterns. In our solution, we achieve complete decentralization by replacing sink nodes with smart contracts. The sink contract keeps a record of public keys of all nodes in the network. The publicly exposed function _sendQuery()_ enables users to initiate a query on a set of tiles and retrieve the result once submitted on-chain. The contract keeps a registry of all the computing nodes, their public keys, and references to which building/area they belong to. A query consists of a set of compute units and a function. To obtain the set of compute units, the sender can call the function _getComputingNodes()_, which checks the senders public key against RBAC and filters the set accordingly. The result is a subset of units, the sender has access to. Upon calling _sendQuery()_ the contract creates an onion. The subset of computing nodes should be randomized to avoid using on-chain randomness when creating the onion. Computing nodes in the WSN run a light client of OpenEthereum and are able to synchronize blocks with reasonable storage and resource requirements.