Skip to content

Commit e015abb

Browse files
authored
Merge branch 'main' into bwbush/doc-rust
2 parents 4a91678 + 3e09387 commit e015abb

37 files changed

+10764
-528
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: "Build Leios Design PDF"
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "docs/leios-design/**"
7+
- "nix/artifacts.nix"
8+
- ".github/workflows/leios-design.yaml"
9+
push:
10+
branches:
11+
- main
12+
paths:
13+
- "docs/leios-design/**"
14+
- "nix/artifacts.nix"
15+
workflow_dispatch: # Allow manual triggering
16+
17+
permissions:
18+
contents: read
19+
actions: read
20+
21+
# Prevent redundant workflow runs
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}
24+
cancel-in-progress: true
25+
26+
jobs:
27+
build-pdf:
28+
name: "Build Leios Design PDF"
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: 📥 Checkout repository
32+
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 1
35+
36+
- name: 🛠️ Install Nix
37+
uses: cachix/install-nix-action@v27
38+
with:
39+
nix_path: nixpkgs=channel:nixos-unstable
40+
extra_nix_config: |
41+
experimental-features = nix-command flakes
42+
accept-flake-config = true
43+
extra-substituters = https://cache.iog.io
44+
extra-trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
45+
46+
- name: 🗂️ Setup Cachix for IOG cache
47+
uses: cachix/cachix-action@v15
48+
with:
49+
name: iog
50+
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
51+
skipPush: true
52+
53+
- name: 🏗️ Build PDF using Nix
54+
run: |
55+
echo "Building Leios Design PDF..."
56+
nix build .#leiosDesignPdf -L
57+
58+
# Verify the PDF was created
59+
if [ ! -f result/leios-design.pdf ]; then
60+
echo "Error: PDF file was not created"
61+
exit 1
62+
fi
63+
64+
# Show file size and info
65+
ls -lh result/leios-design.pdf
66+
file result/leios-design.pdf
67+
68+
- name: 📊 Get PDF metadata
69+
run: |
70+
# Get basic file info
71+
echo "PDF file size: $(stat -c%s result/leios-design.pdf) bytes"
72+
echo "PDF creation date: $(stat -c%y result/leios-design.pdf)"
73+
74+
# If pdfinfo is available, show more details
75+
if command -v pdfinfo &> /dev/null; then
76+
echo "PDF metadata:"
77+
pdfinfo result/leios-design.pdf || true
78+
fi
79+
80+
- name: 🚀 Upload PDF artifact
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: leios-design-pdf-${{ github.sha }}
84+
path: result/leios-design.pdf
85+
if-no-files-found: error
86+
retention-days: 30
87+
88+
- name: 📄 Add PDF info to job summary
89+
run: |
90+
echo "## 📄 Leios Design PDF Generated" >> $GITHUB_STEP_SUMMARY
91+
echo "" >> $GITHUB_STEP_SUMMARY
92+
echo "✅ Successfully built PDF from markdown source" >> $GITHUB_STEP_SUMMARY
93+
echo "" >> $GITHUB_STEP_SUMMARY
94+
echo "**File details:**" >> $GITHUB_STEP_SUMMARY
95+
echo "- Size: $(stat -c%s result/leios-design.pdf) bytes" >> $GITHUB_STEP_SUMMARY
96+
echo "- Generated: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
97+
echo "- Commit: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
98+
echo "" >> $GITHUB_STEP_SUMMARY
99+
echo "The PDF is available as a workflow artifact named \`leios-design-pdf-${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY

crypto-benchmarks.rs/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
target/
22
*.cbor
33
*.txt
4+
5+
# Demo artifacts
6+
demo/**/*.pretty.json
7+
demo/**/*.json
8+
demo/**/*.png
9+
demo/**/*.csv
10+
demo/scripts/.env_cli
11+
12+
# Python cache
13+
__pycache__/
14+
*.pyc
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2+
3+
# Demo Scripts for Leios Crypto Benchmarks
4+
5+
This folder contains scripts that orchestrate end-to-end demonstrations of BLS-based vote aggregation and certificate generation/verification for the Leios project.
6+
7+
## Prerequisites
8+
9+
- Ensure the CLI built from the repository root is available; see `crypto-benchmarks.rs/ReadMe.md` for build instructions and usage details.
10+
- Ensure Python 3 is available with `cbor2` installed.
11+
For example:
12+
13+
```bash
14+
python3 -m venv .venv
15+
source .venv/bin/activate
16+
pip install cbor2
17+
```
18+
19+
## Workflow
20+
21+
The scripts are designed to be run from the `demo/` directory.
22+
23+
### Run Step by Step (Manual Mode)
24+
25+
You can run each script individually to understand and control each step of the process for a given number of voters (e.g., 100). Use the `-d` option to specify the output directory (e.g., `run100`).
26+
27+
#### 10_init_inputs.sh
28+
29+
Initialize inputs for N voters:
30+
31+
```bash
32+
scripts/10_init_inputs.sh -d run100 --pools 500 --stake 100000 --alpha 9 --beta 1
33+
```
34+
35+
#### 20_make_registry.sh
36+
37+
Build the registry from initialized inputs:
38+
39+
```bash
40+
./scripts/20_make_registry.sh -d run100 -n 100
41+
```
42+
43+
#### 30_cast_votes.sh
44+
45+
Cast votes with a specified fraction of voters voting (e.g., 1.0 means all vote):
46+
47+
```bash
48+
scripts/30_cast_votes.sh -d run100 -f 0.75
49+
```
50+
51+
#### 40_make_certificate.sh
52+
53+
Generate the aggregated certificate:
54+
55+
```bash
56+
scripts/40_make_certificate.sh -d run100
57+
```
58+
59+
#### 50_verify_certificate.sh
60+
61+
Verify the generated certificate:
62+
63+
```bash
64+
scripts/50_verify_certificate.sh -d run100
65+
```
66+
67+
### Run a Single End-to-End Demo
68+
69+
```bash
70+
scripts/70_run_one.sh -d run100 -p 500 -n 100 -f 0.75
71+
```
72+
73+
This will:
74+
75+
1. Initialize inputs (`10_init_inputs.sh`)
76+
2. Build a registry (`20_make_registry.sh`)
77+
3. Cast votes (`30_cast_votes.sh`)
78+
4. Make a certificate (`40_make_certificate.sh`)
79+
5. Verify the certificate (`50_verify_certificate.sh`)
80+
6. Export data for the UI (`60_export_demo_json.sh`)
81+
82+
All files are placed in `demo/run100/`.
83+
84+
### Launch the Demo UI
85+
86+
After generating a demo run (for example via `scripts/70_run_one.sh`), start the UI server from this directory:
87+
88+
```bash
89+
python3 ui/server.py
90+
```
91+
92+
Then open your browser at [http://127.0.0.1:5050/ui](http://127.0.0.1:5050/ui) to explore the results.
93+
94+
## Notes
95+
96+
- All scripts must be run from within the `demo/` directory.
97+
- Directories passed via `-d` will be created automatically under `demo/`.
98+
- Compression ratio is defined as:
99+
100+
```
101+
votes_bytes / certificate_bytes
102+
```
103+
104+
which illustrates the storage/bandwidth savings achieved by BLS aggregation.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
# Usage: demo/scripts/00_set_cli.sh [-p /abs/path/to/leios_crypto_benchmarks]
4+
# Writes demo/scripts/.env_cli with an absolute CLI path so other scripts can source it.
5+
6+
DIR_SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
ENV_FILE="$DIR_SCRIPT/.env_cli"
8+
CLI_PATH=""
9+
10+
while getopts ":p:" opt; do
11+
case "$opt" in
12+
p) CLI_PATH="$OPTARG" ;;
13+
*) echo "Usage: $0 [-p /abs/path/to/leios_crypto_benchmarks]"; exit 2 ;;
14+
esac
15+
done
16+
17+
if [[ -z "${CLI_PATH}" ]]; then
18+
read -r -p "Absolute path to leios_crypto_benchmarks binary: " CLI_PATH
19+
fi
20+
21+
if [[ ! -x "${CLI_PATH}" ]]; then
22+
echo "Error: '${CLI_PATH}' is not an executable file." >&2
23+
exit 1
24+
fi
25+
26+
mkdir -p "$DIR_SCRIPT"
27+
cat > "$ENV_FILE" <<EOF
28+
# Auto-generated by 00_set_cli.sh
29+
export CLI="${CLI_PATH}"
30+
EOF
31+
32+
echo "Saved CLI path to $ENV_FILE"
33+
echo "Example: source \"$ENV_FILE\" && \$CLI --help"
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
# Usage: demo/scripts/10_init_inputs.sh [-d DEMO_DIR] [--pools 5000] [--stake 100000] [--alpha 5] [--beta 1]
4+
DIR_SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
source "$DIR_SCRIPT/.env_cli"
6+
7+
DEMO_DIR="$(cd "$DIR_SCRIPT/.." && pwd)"
8+
POOLS=500
9+
TOTAL_STAKE=1000000
10+
ALPHA=9
11+
BETA=1
12+
13+
while [[ $# -gt 0 ]]; do
14+
case "$1" in
15+
-d) DEMO_DIR="$2"; shift 2;;
16+
--pools) POOLS="$2"; shift 2;;
17+
--stake) TOTAL_STAKE="$2"; shift 2;;
18+
--alpha) ALPHA="$2"; shift 2;;
19+
--beta) BETA="$2"; shift 2;;
20+
*) echo "Unknown arg: $1"; exit 2;;
21+
esac
22+
done
23+
24+
mkdir -p "$DEMO_DIR"
25+
26+
echo "== [10_init_inputs] DIR=${DEMO_DIR} POOLS=${POOLS} TOTAL_STAKE=${TOTAL_STAKE} =="
27+
28+
pushd "$DEMO_DIR" >/dev/null
29+
"$CLI" gen-eid > eid.txt
30+
"$CLI" gen-eb-hash > ebhash.txt
31+
32+
"$CLI" gen-stake \
33+
--pool-count "${POOLS}" \
34+
--total-stake "${TOTAL_STAKE}" \
35+
--shape-alpha "${ALPHA}" \
36+
--shape-beta "${BETA}" \
37+
--stake-file stake.cbor
38+
39+
"$CLI" gen-pools \
40+
--stake-file stake.cbor \
41+
--pools-file pools.cbor
42+
43+
# Pretty-print some of the generated values
44+
echo "EID: $(cat eid.txt)"
45+
echo "EB Hash: $(cat ebhash.txt)"
46+
47+
# Print first 3 pools and their stakes from pools.cbor using cbor2
48+
PYTHON_EXEC="${VIRTUAL_ENV:+$VIRTUAL_ENV/bin/python}"
49+
PYTHON_EXEC="${PYTHON_EXEC:-python3}"
50+
"$PYTHON_EXEC" - <<'PY'
51+
import sys, os
52+
try:
53+
import cbor2
54+
except ImportError:
55+
print('cbor2 not installed! (pip install cbor2)', file=sys.stderr)
56+
sys.exit(1)
57+
58+
if not os.path.exists('pools.cbor'):
59+
print('pools.cbor not found', file=sys.stderr)
60+
sys.exit(1)
61+
62+
with open('pools.cbor', 'rb') as f:
63+
pools = cbor2.load(f)
64+
65+
print('First 3 pools and their stakes:')
66+
for i, entry in enumerate(pools[:3]):
67+
# Expected structure: {"secret": <bytes>, "reg": {"pool": "<hex>", ...}, "stake": <int>}
68+
reg = entry.get('reg', {})
69+
pool_id = reg.get('pool', '<unknown>')
70+
stake = entry.get('stake', '<unknown>')
71+
print(f' {i:>2}: pool={pool_id} stake={stake}')
72+
PY
73+
popd >/dev/null
74+
75+
echo "Initialized inputs in ${DEMO_DIR}"

0 commit comments

Comments
 (0)