Skip to content

Commit 3dbf05f

Browse files
authored
Merge pull request #4 from openSVM/openSVM_tornado-svm_issue_3_43e335ac
review cryptography (Run ID: openSVM_tornado-svm_issue_3_43e335ac)
2 parents 6f86e04 + 9d73672 commit 3dbf05f

21 files changed

+3368
-44
lines changed

.github/workflows/README.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Tornado-SVM GitHub Actions Workflows
2+
3+
## Build Workflow
4+
5+
### Workflow: `build.yml`
6+
7+
**Purpose:** Build, test, and validate the Tornado-SVM codebase using the Bun JavaScript runtime and Solana build tools.
8+
9+
### Trigger Methods:
10+
11+
1. **On Push:** Runs on all branch pushes and version tags
12+
2. **On Pull Request:** Runs on all pull requests
13+
14+
### What the Workflow Does:
15+
16+
1. Sets up Bun and Rust toolchains
17+
2. Installs Solana build tools
18+
3. Builds the Solana program using Cargo build-sbf
19+
4. Runs program tests
20+
5. Lints the code with Clippy
21+
6. Builds and tests the client
22+
23+
### Technologies Used:
24+
25+
- **Bun:** Fast JavaScript runtime and package manager
26+
- **Rust:** Primary language for the Solana program
27+
- **Solana CLI:** For building and testing Solana programs
28+
29+
### Solana CLI Installation
30+
31+
The workflow automatically installs the Solana CLI using the following process:
32+
33+
```bash
34+
# Install Solana CLI tools
35+
sh -c "$(curl -sSfL https://release.solana.com/v1.16.0/install)"
36+
37+
# Add to GitHub Actions PATH
38+
echo "$HOME/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
39+
40+
# Also add to current shell session
41+
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
42+
```
43+
44+
This ensures that the Solana binaries are available for all steps in the workflow that require them.
45+
46+
## Testnet Transaction Metrics Workflow
47+
48+
This workflow automates the process of running Tornado-SVM privacy solution transactions on Solana testnet and generating comprehensive metrics reports.
49+
50+
### Workflow: `tornado_testnet_transaction.yml`
51+
52+
**Purpose:** Execute the complete Tornado-SVM transaction flow on Solana testnet and collect detailed performance metrics.
53+
54+
### Trigger Methods:
55+
56+
1. **Manual Trigger:** Run the workflow on-demand via GitHub UI with configurable parameters
57+
2. **Scheduled Runs:** Automatically runs weekly on Sundays at midnight UTC
58+
3. **Pull Request Trigger:** Runs on PRs to the master branch that modify core files
59+
60+
### Configurable Parameters:
61+
62+
- **Denomination:** Amount of SOL to use in the transaction (default: 1 SOL)
63+
- **Merkle Tree Height:** Height of the Merkle tree for the Tornado instance (default: 20)
64+
- **RPC URL:** Custom Solana RPC URL (defaults to testnet)
65+
66+
### What the Workflow Does:
67+
68+
1. Sets up Bun runtime and the Solana toolchain
69+
2. Creates a new Solana wallet and requests an airdrop
70+
3. Deploys the Tornado-SVM program to the Solana testnet
71+
4. Initializes a new Tornado instance
72+
5. Performs a complete deposit and withdrawal flow with zkSNARK proofs
73+
6. Captures detailed metrics at each step including:
74+
- Execution times for each phase
75+
- Transaction signatures
76+
- Compute unit consumption
77+
- Gas fees
78+
- Transaction details
79+
7. Generates a comprehensive markdown report with visualizations
80+
8. Creates a GitHub job summary
81+
9. Uploads all reports and raw metrics as artifacts
82+
83+
### Artifacts Generated:
84+
85+
- **transaction_report.md:** Complete markdown report with all metrics and visualizations
86+
- **metrics/*.json:** Raw JSON data for transaction details
87+
- **metrics/execution_times.txt:** Detailed timing measurements for each phase
88+
89+
### Using the Report:
90+
91+
1. Download the artifact from the completed workflow run
92+
2. Open the markdown report to view all metrics and visualizations
93+
3. The report includes:
94+
- Executive summary
95+
- Configuration details
96+
- Transaction logs
97+
- Detailed metrics for each transaction
98+
- Explorer links for all on-chain activity
99+
- Visualizations of the transaction flow and zkSNARK process
100+
- Solana network stats during the test
101+
102+
### Example Usage
103+
104+
To manually trigger the workflow with custom parameters:
105+
106+
1. Go to the "Actions" tab in the GitHub repository
107+
2. Select "Tornado SVM Testnet Transaction Test" workflow
108+
3. Click "Run workflow"
109+
4. Enter your desired parameters (denomination, Merkle tree height, RPC URL)
110+
5. Click "Run workflow"
111+
6. Once completed, download the artifacts from the workflow run
112+
113+
### Troubleshooting
114+
115+
#### Solana CLI Not Found
116+
117+
If you encounter the error `solana: command not found`, check the following:
118+
119+
1. Verify that the Solana CLI installation step completed successfully
120+
2. The workflow now adds Solana binaries to GitHub's persistent PATH variable (`$GITHUB_PATH`), ensuring all subsequent steps can access the commands
121+
3. We also add `$HOME/.cargo/bin` to PATH to pick up cargo-build-sbf and cargo-test-sbf
122+
4. The workflow no longer needs explicit PATH exports in each step
123+
5. The transaction script has robust error handling to provide detailed diagnostic information when Solana is not found
124+
6. You can use the `SOLANA_PATH` environment variable to override the default Solana binary location
125+
126+
#### Cargo Lock File Version Compatibility
127+
128+
If you encounter Cargo lock file version compatibility issues:
129+
130+
1. The workflow now explicitly updates Cargo to the latest stable version
131+
2. We've added a specific step that runs `rustup update stable` and `rustup default stable`
132+
3. Cargo version is explicitly checked and logged for troubleshooting
133+
4. The workflow now intelligently checks if the installed Cargo version is compatible with Cargo.lock version 4:
134+
```bash
135+
CARGO_VERSION=$(cargo --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
136+
MAJOR=$(echo "$CARGO_VERSION" | cut -d'.' -f1)
137+
MINOR=$(echo "$CARGO_VERSION" | cut -d'.' -f2)
138+
if [ "$MAJOR" -lt 1 ] || ([ "$MAJOR" -eq 1 ] && [ "$MINOR" -lt 70 ]); then
139+
# If Cargo is too old, upgrade it again
140+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --profile minimal
141+
fi
142+
```
143+
5. The workflow automatically regenerates the Cargo.lock file to ensure it uses a format compatible with the current Cargo version
144+
6. After regeneration, it explicitly verifies the lock file format with `grep -q 'version = 4' Cargo.lock`
145+
7. Any existing Cargo.lock is deleted and freshly regenerated to avoid format conflicts
146+
8. Detailed debugging output is provided if the Cargo.lock generation fails
147+
148+
#### Build Command Not Found
149+
150+
If you encounter errors with `cargo build-sbf` or `cargo build-bpf`:
151+
152+
1. The workflow now checks if commands are available using `help` flags
153+
2. It tries both SBF (newer) and BPF (older) variants
154+
3. If needed, it runs `solana-install update` to get the latest build tools
155+
4. PATH is updated to include all possible locations for Cargo and Solana binaries
156+
157+
#### Notifications
158+
159+
The workflow previously used Telegram for notifications, which has been replaced with:
160+
161+
1. Console-based logging for better workflow compatibility
162+
2. No external dependencies or tokens required
163+
3. Clear notification messages in the workflow logs

.github/workflows/build.yml

Lines changed: 140 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,152 @@ name: build
33
on:
44
push:
55
branches: ['*']
6-
tags: ['v[0-9]+.[0-9]+.[0-9]+']
6+
tags: ['v[0-9]+.[0-9]+.[0-9]+']
77
pull_request:
88

99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v2
15-
- uses: actions/setup-node@v1
16-
with:
17-
node-version: 12
18-
- run: yarn install
19-
- run: yarn download
20-
- run: cp .env.example .env
21-
- run: npx ganache-cli > /dev/null &
22-
- run: npm run migrate:dev
23-
- run: yarn test
24-
- run: node src/cli.js test
25-
- run: yarn lint
26-
- run: yarn coverage
27-
- name: Coveralls
28-
uses: coverallsapp/github-action@master
14+
uses: actions/checkout@v3
15+
16+
- name: Setup Bun
17+
uses: oven-sh/setup-bun@v1
2918
with:
30-
github-token: ${{ secrets.GITHUB_TOKEN }}
31-
- name: Telegram Failure Notification
32-
uses: appleboy/[email protected]
33-
if: failure()
19+
bun-version: latest
20+
21+
- name: Install dependencies
22+
run: bun install
23+
24+
# Rust setup and build with explicit update to latest version
25+
- name: Install and Update Rust
26+
uses: dtolnay/rust-toolchain@stable
3427
with:
35-
message: ❗ Build failed for [${{ github.repository }}](https://github.com/${{ github.repository }}/actions) because of ${{ github.actor }}
36-
format: markdown
37-
to: ${{ secrets.TELEGRAM_CHAT_ID }}
38-
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
28+
components: rustfmt, clippy
29+
30+
- name: Update Cargo to latest stable
31+
run: |
32+
# Update to the latest stable Rust toolchain
33+
rustup update stable
34+
rustup default stable
35+
# Check Cargo version explicitly
36+
cargo --version
37+
echo "Using Cargo from: $(which cargo)"
38+
# Ensure we can handle Cargo.lock version 4
39+
CARGO_VERSION=$(cargo --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
40+
echo "Cargo version: $CARGO_VERSION"
41+
# Check if Cargo version is new enough for lock file version 4
42+
MAJOR=$(echo "$CARGO_VERSION" | cut -d'.' -f1)
43+
MINOR=$(echo "$CARGO_VERSION" | cut -d'.' -f2)
44+
if [ "$MAJOR" -lt 1 ] || ([ "$MAJOR" -eq 1 ] && [ "$MINOR" -lt 70 ]); then
45+
echo "Warning: Cargo version $CARGO_VERSION may not fully support Cargo.lock version 4 format"
46+
echo "Attempting to update Cargo again"
47+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --profile minimal
48+
source "$HOME/.cargo/env"
49+
cargo --version
50+
else
51+
echo "Cargo $CARGO_VERSION supports Cargo.lock version 4 format"
52+
fi
53+
54+
- name: Regenerate Cargo.lock
55+
run: |
56+
# Remove any existing Cargo.lock
57+
if [ -f Cargo.lock ]; then
58+
echo "Removing existing Cargo.lock"
59+
rm Cargo.lock
60+
fi
61+
# Regenerate Cargo.lock with the latest Cargo version
62+
echo "Regenerating Cargo.lock"
63+
cargo generate-lockfile
64+
echo "Cargo.lock regenerated successfully"
65+
66+
# Verify the Cargo.lock format
67+
if [ -f Cargo.lock ]; then
68+
echo "Checking Cargo.lock format..."
69+
# Quick check to see if it's a version 4 format (contains version = 4)
70+
if grep -q 'version = 4' Cargo.lock; then
71+
echo "Confirmed: Cargo.lock is using version 4 format"
72+
else
73+
echo "Warning: Cargo.lock may not be using version 4 format"
74+
# For debugging purposes, show the first few lines
75+
head -5 Cargo.lock
76+
fi
77+
else
78+
echo "Error: Cargo.lock was not generated!"
79+
exit 1
80+
fi
81+
82+
- name: Install Solana CLI
83+
run: |
84+
# Install Solana CLI tools
85+
sh -c "$(curl -sSfL https://release.solana.com/v1.16.0/install)"
86+
# Add Solana to PATH for this job
87+
echo "$HOME/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
88+
# Also add to PATH for current shell session
89+
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
90+
# Verify installation
91+
solana --version
92+
93+
- name: Build Solana program
94+
run: |
95+
# Ensure Solana binaries are in PATH
96+
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
97+
# Try the newer cargo build-sbf command first, fall back to cargo build-bpf if not available
98+
# First check if the commands are directly available
99+
if cargo build-sbf --help &> /dev/null; then
100+
echo "Using cargo build-sbf"
101+
cargo build-sbf
102+
elif cargo build-bpf --help &> /dev/null; then
103+
echo "Using cargo build-bpf"
104+
cargo build-bpf
105+
else
106+
echo "Installing Solana BPF/SBF tools..."
107+
solana-install update
108+
# Add Solana's .cargo/bin to PATH (where cargo-build-bpf is installed)
109+
export PATH="$HOME/.cargo/bin:$PATH"
110+
# Try again after update
111+
if cargo build-sbf --help &> /dev/null; then
112+
echo "Using cargo build-sbf after update"
113+
cargo build-sbf
114+
else
115+
echo "Using cargo build-bpf after update"
116+
cargo build-bpf
117+
fi
118+
fi
119+
120+
- name: Run Solana tests
121+
run: |
122+
# Ensure Solana binaries are in PATH
123+
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
124+
export PATH="$HOME/.cargo/bin:$PATH"
125+
# Try the newer cargo test-sbf command first, fall back to cargo test-bpf if not available
126+
if cargo test-sbf --help &> /dev/null; then
127+
echo "Using cargo test-sbf"
128+
cargo test-sbf
129+
elif cargo test-bpf --help &> /dev/null; then
130+
echo "Using cargo test-bpf"
131+
cargo test-bpf
132+
else
133+
echo "Installing Solana BPF/SBF tools..."
134+
solana-install update
135+
# Add Solana's .cargo/bin to PATH (where cargo-test-bpf is installed)
136+
export PATH="$HOME/.cargo/bin:$PATH"
137+
# Try again after update
138+
if cargo test-sbf --help &> /dev/null; then
139+
echo "Using cargo test-sbf after update"
140+
cargo test-sbf
141+
else
142+
echo "Using cargo test-bpf after update"
143+
cargo test-bpf
144+
fi
145+
fi
146+
147+
- name: Run Cargo Clippy
148+
run: cargo clippy -- -D warnings
149+
150+
- name: Build client
151+
run: cd client && bun install
152+
153+
- name: Run client tests
154+
run: cd client && bun test

0 commit comments

Comments
 (0)