Skip to content

Commit

Permalink
prl: add script to compute probabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
gianlucascopelliti committed Sep 29, 2023
1 parent bd6aeb1 commit f508395
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ jobs:
steps:
-
uses: actions/checkout@master
-
name: Probabilities
run: |
cd prl
make probabilities
-
name: Transition graph
run: |
Expand Down
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ cd ..

| Artifact | Paper references | Description |
|-----------------------|---------------------|----------------------------------------|
| `probabilities` | Sect. VII-B, Appendix D | Probabilities used for each scenario, and expected number of revocations |
| `p-plot` | Sect. VII-B, Fig. 6 | Plots percentiles for maximum PRL sizes under different scenarios and shares of attackers, with fixed `T_prl` and number of pseudonyms |
| `tv-distribution` | Sect. VII-B, Fig. 7 | Evaluates `T_eff`, heartbeat frequency, heartbeat size, and required bandwidth under different values for `T_v` |
| `tikz-graph` | Appendix D, Fig. 15 | Simple transition graph |
Expand All @@ -333,43 +334,49 @@ depending on your hardware.
# go to the `prl` folder
cd prl

# Step 1: transition graph (~1-5 seconds)
# Step 1: compute probabilities (~1-5 seconds)
# Expected output:
# - probabilities and expected number of revocations printed to standard output
# - "All done!" message
make probabilities

# Step 2: transition graph (~1-5 seconds)
# Expected output:
# - markov matrix and the "Done" message printed to standard output
# - `tikz-graph.tex` plot under `./plots`
make tikz

# Step 2: Plot series over the different probabilities (~15-20 minutes)
# Step 3: Plot series over the different probabilities (~15-20 minutes)
# Expected output:
# - no errors printed to standard output
# - several distributions cached in `./cached` and plotted in `./plots/distributions`
# - plots `p-plot_n800_e30.{tex,png}` under `./plots`
make p-plot

# Step 3: Plot series over the number of pseudonyms (~25-35 minutes)
# Step 4: Plot series over the number of pseudonyms (~25-35 minutes)
# Expected output:
# - no errors printed to standard output
# - several distributions cached in `./cached` and plotted in `./plots/distributions`
# - plots `n-plot_e30.{tex,png}` under `./plots`
make n-plot

# Step 4: Plot series over the time each pseudonym stays in the list (~90-140 minutes)
# Step 5: Plot series over the time each pseudonym stays in the list (~90-140 minutes)
# Expected output:
# - no errors printed to standard output
# - several distributions cached in `./cached` and plotted in `./plots/distributions`
# - plots `t-plot_n800.{tex,png}` under `./plots`
make t-plot

# Step 5: Generate distribution for Tv (~15-20 minutes)
# Step 6: Generate distribution for Tv (~15-20 minutes)
# Expected output:
# - no errors printed to standard output
# - several distributions cached in `./cached` and plotted in `./plots/distributions`
# - plots `tv-distribution.{tex,png}` under `./plots`
make tv-distribution

# Step 6 (optional): Copy results somewhere safe (`plots` folder will be deleted in the next step!)
# Step 7 (optional): Copy results somewhere safe (`plots` folder will be deleted in the next step!)

# Step 7: clean up
# Step 8: clean up
make clean

# go back to the root folder
Expand Down
5 changes: 4 additions & 1 deletion prl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ build-docker:
test: init_dirs
$(DOCKER_CMD) python3 main.py -n 3 -p 0.01 -e 2 --cache-dir=$(CACHE_DIR) --allow-cached

probabilities:
$(DOCKER_CMD) python3 probabilities.py

single: init_dirs
$(DOCKER_CMD) python3 main.py -n 800 -p 0.000000116323325 -e 30 --cache-dir=$(CACHE_DIR) --allow-cached

Expand Down Expand Up @@ -52,7 +55,7 @@ check:
fi ; \
fi

all: init_dirs check p-plot t-plot n-plot tv-distribution tikz
all: init_dirs check probabilities p-plot t-plot n-plot tv-distribution tikz
@echo Successfully created all graphs!

init_dirs:
Expand Down
11 changes: 8 additions & 3 deletions prl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ you have already generated, the faster the scripts will complete.
| Target | Time |
| :--------------- | :-- |
| test | 1 second |
| probabilities | 1 second |
| tikz | 1 second |
| single | 3 minutes |
| tv-distribution | 18 minutes |
Expand Down Expand Up @@ -161,8 +162,12 @@ below for how to do this manually.

### Reproducing the data used in the first plot

The appendix explains more in-depth how the probabilities were calculated.
For the plots, the following probabilities were used:
The appendix explains more in-depth how the probabilities were calculated. The
probabilities that we used can be re-computed by running the `probabilities.py`
script (via `make probabilities`). This will also print the number of expected
revocations for each scenario, as discussed in Section VII-B. The script should
give as output the following probabilities:

```text
Scenario 1: vehicles get revoked at least once a day with 1% probability
0.000000116323325
Expand All @@ -181,7 +186,7 @@ Scenario 2: vehicles get revoked at least once a day with 99% probability
0.000196612735153
```

Then multiple plots can be generated at the same time with the
Then, multiple plots can be generated at the same time with the
`generate_plots.py` script (careful, only with python up to 3.8), which is
wrapped in the [p-plot.sh](./scripts/p-plot.sh) script.

Expand Down
84 changes: 84 additions & 0 deletions prl/probabilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import numpy as np

### Parameters used to compute the average number of revocations ###
AVG_PRL_SIZE = 5 # average PRL size for Scenario 2 - 20% attackers -- computed from Markov analysis
T_PRL = 30 # time in PRL considered
PSEUDONYMS = 800 # number of pseudonyms considered

def print_scenario(scenario, attackers):
assert len(scenario) == len(attackers)

for i in range(len(scenario)):
print(f"{int(attackers[i] * 100)}% attackers: {scenario[i]:.15f} ")

# Vehicle classes: used to compute probabilities for Scenario 1 and 2
vehicle_classes = {
"honest_1": {
"p": 0.01, # 1% probability to get revoked within the specified duration
"duration": 86400 # a week
},
"honest_2": {
"p": 0.99, # 99% probability to get revoked within the specified duration
"duration": 86400 # a week
},
"malicious": {
"p": 0.75, # 75% probability to get revoked within the specified duration
"duration": 1800 # 30 min
},
}

# Shares of attackers in the network: from 0% to 20%
attackers = np.array([0.0, 0.01, 0.02, 0.05, 0.1, 0.2])

print(f"Vehicle classes considered: {vehicle_classes}")
print(f"Shares of attackers considered: {attackers}")

print("Computing per-second revocation probabilities for each vehicle class and share of attackers..")
probabilities = {}
for vc in vehicle_classes:
# computing the per-second probability via geometric series (See Appendix D-D)
p = 1 - (1 - vehicle_classes[vc]["p"]) ** (1 / vehicle_classes[vc]["duration"])

probabilities[vc] = {
"per-second p": p,
"attackers": []
}
for attacker in attackers:
if "honest" in vc:
attacker_p = (1 - attacker) * p
else:
attacker_p = attacker * p

probabilities[vc]["attackers"].append(attacker_p)


print("Computing total (honest + malicious) probabilities for each scenario..")

# h1 <-> Scenario 1:
# honest vehicles get revoked at least once a day with 1% probability
# malicious vehicles get revoked every 30 minutes with 75% probabiity
h1 = np.add(probabilities["honest_1"]["attackers"], probabilities["malicious"]["attackers"])
print(f"Probabilities Scenario 1")
print_scenario(h1, attackers)

# h2 <-> Scenario 2:
# honest vehicles get revoked at least once a day with 99% probability
# malicious vehicles get revoked every 30 minutes with 75% probabiity
h2 = np.add(probabilities["honest_2"]["attackers"], probabilities["malicious"]["attackers"])
print(f"Probabilities Scenario 2")
print_scenario(h2, attackers)

print(f"Computing expected number of revocations over a day for n={PSEUDONYMS} and T_prl={T_PRL}..")

# From the paper: E_rev = n * s * p * (1 - p_prl)
p_prl = AVG_PRL_SIZE / PSEUDONYMS
rev_h1 = PSEUDONYMS * 86400 * h1 * (1 - p_prl)
rev_h2 = PSEUDONYMS * 86400 * h2 * (1 - p_prl)

print(f"Expected revocations over a day Scenario 1")
print_scenario(rev_h1, attackers)

print(f"Expected revocations over a day Scenario 2")
print_scenario(rev_h2, attackers)

print("All done!")

0 comments on commit f508395

Please sign in to comment.