# A Secure Median Implementation for the Federated Secure Computing Architecture
## 3 Materials and Methods
### Implementation  
The original protocol, as detailed in Section 2, has been converted into the staging logic within SIMON, which is described previously (see Listing 2). Specifically, we implemented the Python class _MicroprotocolKthElement_ (Available under [[https://github.com/federated](https://github.com/federated)]([https://github.com/federated](https://github.com/federated)) secure/service-simon/blob/main/src/federatedsecure/services/simon/microprotocols /microprotocol_kth_element.py, last accessed: 20 August 2024). After first initialization of the search range and required caches, the main part encapsulates a stage that can be iteratively initialized and called. Similar to the staged approach shown in Figure 2, the stages are iteratively executed, narrowing the search range until the exact \(k\)th-ranked value is found (see pseudocode in Listing 2). ```
1 defstage_n():
3
4#defineacandidatevalueunintherangeofthedata[a,b]
5 mu=ceil((a+b)/2)
6
7#computethenumberofsamplesbigger(g)andsaller(l)than
8#candidatevalueinmydataset
9l,g=compute_lg()
10
11#participeinsecursummationtothesumoflandgoverall
12
13 parties

Figure 2: Example of (not secure) computation of the sum in SImple Multiparty ComputatiON (SIMON) for two parties with inputs 3 and 5. Each party sends its input to the input cache. In stage 0, these inputs are broadcast to the result cache, where they are summed (\(3+5\)). When both inputs are received, the protocol proceeds to stage 1, where the final result (8) is retrieved and returned. L, Q = secure_sum()
* check conditions
* if L <= k-1 and G <= n-k
* initialize final stage for termination of protocol
* register_stage(final, caches, stage_final)
* if L >= k
* redefine upperbound of search space

* if G >= k
* e redefine lowerbound of search space
* a = mu + 1
* gstart next stage, i.e., next iteration of stage_n
* register_stage(n+1, caches, stage_n)

### Experimental Setup

The experimental setup is visualized in Figure 3. In this setup, each party runs its own federated secure compute server instance and provides input data. #### 3.2.1 Server Setup

To evaluate the implementation, we deployed FSC servers either locally or on AWS EC2 instances across various regions. Local deployment ensures precise execution time measurement, free from network latency interference. Conversely, AWS deployment allows assessing the influence of network overhead on performance. Moreover, leveraging AWS EC2 instances across various regions effectively replicates real-world scenarios, which is particularly beneficial when parties are globally dispersed. There are a few minimum hardware requirements; we were using an office laptop with an Intel Core i5-1235U processor and 8 GB RAM for local deployment. AWS EC2 instances were configured using t2.micro or t3.micro tiers, i.e., Intel Xeon processors and 1 GB RAM, depending on regional availability. FSC facilitates easy server setup. For example, Listing 3 lists the commands to start two local servers:

Figure 3: Experimental setup for testing the implementation. Federated Secure servers were deployed either on localhost or in the cloud. Datasets \(D_{i}\) included both synthetic data (random numbers with various sizes and open real-world datasets (breast cancer and heart disease). Various numbers of parties \(m\) were tested. ```
1 pipinstallfederatedsecure-server
2 pipinstallfederatedsecure-simon
3 pipinstallconnexion[flask,uvicorn,swagger-ui]
4 gitclone[[https://github.com/federatedsecure/webserver-connexion](https://github.com/federatedsecure/webserver-connexion)]([https://github.com/federatedsecure/webserver-connexion](https://github.com/federatedsecure/webserver-connexion))
5 cdwobserver-connexion/src
6 python_main_.pyport=55500&
7 python_main_.pyport=55501&
```
Listing 3: Exemplary commands to initiate two local servers.