Skip to content

Commit 58d5b99

Browse files
authored
Sp1 task sender (#2039)
1 parent ecb6ca2 commit 58d5b99

File tree

3 files changed

+134
-32
lines changed

3 files changed

+134
-32
lines changed

crates/task-sender/README.md

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Task Sender
2+
23
This CLI is made to stress-test the network.
34

45
It has the following commands:
@@ -8,21 +9,25 @@ It has the following commands:
89
This command is to generate N Groth16 proofs.
910

1011
To run it, you can:
12+
1113
```bash
1214
cargo run --release -- generate-proofs \
1315
--number-of-proofs <NUMBER_OF_PROOFS> --proof-type groth16 \
1416
--dir-to-save-proofs $(PWD)/scripts/test_files/task_sender/proofs
1517
```
1618

1719
We also have a make target:
20+
1821
```bash
1922
NUMBER_OF_PROOFS=15 make task_sender_generate_groth16_proofs
2023
```
24+
2125
## GenerateAndFundWallets
2226

2327
This command is to generate N wallets, and fund them in the BatcherPaymentService.
2428

2529
To run it, you can:
30+
2631
```bash
2732
cargo run --release -- generate-and-fund-wallets \
2833
--eth-rpc-url <RPC_URL> \
@@ -35,17 +40,20 @@ cargo run --release -- generate-and-fund-wallets \
3540
```
3641

3742
### In Testnet
43+
3844
```bash
3945
NUM_WALLETS=<N> make task_sender_generate_and_fund_wallets_holesky_stage
4046
```
4147

4248
### In Devnet:
4349
Run anvil with more prefunded accounts, using the following make target:
50+
4451
```bash
4552
make anvil_start_with_more_prefunded_accounts
4653
```
4754

4855
Then run the following make target, with `NUM_WALLETS` being the amount of wallets you want to deposit funds to aligned payment service, up to 1000.
56+
4957
```bash
5058
NUM_WALLETS=<N> make task_sender_generate_and_fund_wallets_devnet
5159
```
@@ -56,20 +64,55 @@ This command sends `BURST_SIZE` proofs from each private key in `PATH_TO_PRIVATE
5664

5765
To vary the amount of senders, it is recommended to have a backup with all private keys, and add/remove keys from the file being used.
5866

59-
To run it, you can:
67+
Note: The `--random-address` flag is optional and will use the address a salt to avoid the repetitions of batches.
68+
69+
### RISC Zero Proofs
70+
6071
```bash
6172
cargo run --release -- send-infinite-proofs \
62-
--burst-size <BURST_SIZE> --burst-time-secs <BURST_TIME_SECS> \
63-
--eth-rpc-url <RPC_URL> \
64-
--network <network> \
65-
--proofs-dirpath $(PWD)/scripts/test_files/task_sender/proofs \
66-
--private-keys-filepath <PATH_TO_PRIVATE_KEYS_FILE>
73+
--private-keys-filepath <PATH_TO_PRIVATE_KEYS_FILE> \
74+
--random-address \
75+
--burst-size <BURST_SIZE> \
76+
--burst-time-secs <BURST_TIME_SECS> \
77+
--network <NETWORK> \
78+
risc0 \
79+
--proof-path ./scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci_2_2_0.proof \
80+
--bin-path ./scripts/test_files/risc_zero/fibonacci_proof_generator/fibonacci_id_2_2_0.bin \
81+
--pub-path ./scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci_2_2_0.pub
82+
```
83+
84+
### Gnark Groth16 Proofs
85+
86+
```bash
87+
cargo run --release -- send-infinite-proofs \
88+
--private-keys-filepath <PATH_TO_PRIVATE_KEYS_FILE> \
89+
--random-address \
90+
--burst-size <BURST_SIZE> \
91+
--burst-time-secs <BURST_TIME_SECS> \
92+
--network <NETWORK> \
93+
gnark-groth16 --proofs-dir ./scripts/test_files/gnark_groth16_bn254_script
94+
```
95+
96+
### SP1 Proofs
97+
98+
```bash
99+
cargo run --release --manifest-path ./crates/task-sender/Cargo.toml -- send-infinite-proofs \
100+
--private-keys-filepath <PATH_TO_PRIVATE_KEYS_FILE> \
101+
--burst-size <BURST_SIZE> \
102+
--burst-time-secs <BURST_TIME_SECS> \
103+
--random-address \
104+
sp1 \
105+
--proof-path ./scripts/test_files/sp1/sp1_fibonacci_5_0_0.proof \
106+
--elf-path ./scripts/test_files/sp1/sp1_fibonacci_5_0_0.elf \
107+
--pub-path ./scripts/test_files/sp1/sp1_fibonacci_5_0_0.pub
67108
```
68109

69-
We also have the following related make targets
110+
We also have the following related make targets:
111+
70112
```bash
71113
BURST_SIZE=<N> BURST_TIME_SECS=<N> make task_sender_send_infinite_proofs_devnet
72114
```
115+
73116
```bash
74117
BURST_SIZE=<N> BURST_TIME_SECS=<N> make task_sender_send_infinite_proofs_holesky_stage
75118
```
@@ -79,15 +122,18 @@ BURST_SIZE=<N> BURST_TIME_SECS=<N> make task_sender_send_infinite_proofs_holesky
79122
This command enables and hangs N connections with the Batcher.
80123

81124
To run it, you can:
82-
```
83-
cargo run --release -- test-connections \
125+
126+
```bash
127+
cargo run --release --manifest-path ./crates/task-sender/Cargo.toml -- test-connections \
84128
--num-senders <NUM_SENDERS>
85129
```
86130

87131
We also have the following related make targets:
132+
88133
```bash
89134
NUM_SENDERS=<N> make task_sender_test_connections_devnet
90135
```
136+
91137
```bash
92138
NUM_SENDERS=<N> make task_sender_test_connections_holesky_stage
93139
```

crates/task-sender/src/commands.rs

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -412,29 +412,27 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) {
412412
pub_path,
413413
} => {
414414
info!("Loading RISC Zero proof files");
415-
let Ok(proof) = std::fs::read(proof_path) else {
416-
error!("Could not read proof file: {}", proof_path);
417-
return;
418-
};
419-
let Ok(vm_program) = std::fs::read(bin_path) else {
420-
error!("Could not read bin file: {}", bin_path);
421-
return;
422-
};
423-
let pub_input = if let Some(pub_path) = pub_path {
424-
std::fs::read(pub_path).ok()
425-
} else {
426-
None
427-
};
428-
429-
// Create template verification data (without proof_generator_addr)
430-
vec![VerificationData {
431-
proving_system: ProvingSystemId::Risc0,
432-
proof,
433-
pub_input,
434-
verification_key: None,
435-
vm_program_code: Some(vm_program),
436-
proof_generator_addr: Address::zero(), // Will be set randomly in the loop
437-
}]
415+
match load_risc0_verification_data(proof_path, bin_path, pub_path) {
416+
Ok(data) => data,
417+
Err(err) => {
418+
error!("Failed to load RISC Zero files: {}", err);
419+
return;
420+
}
421+
}
422+
}
423+
InfiniteProofType::SP1 {
424+
proof_path,
425+
elf_path,
426+
pub_path,
427+
} => {
428+
info!("Loading SP1 proof files");
429+
match load_sp1_verification_data(proof_path, elf_path, pub_path) {
430+
Ok(data) => data,
431+
Err(err) => {
432+
error!("Failed to load SP1 files: {}", err);
433+
return;
434+
}
435+
}
438436
}
439437
};
440438

@@ -560,3 +558,49 @@ fn get_verification_data_from_proofs_folder(
560558

561559
verifications_data
562560
}
561+
562+
fn load_risc0_verification_data(
563+
proof_path: &str,
564+
bin_path: &str,
565+
pub_path: &Option<String>,
566+
) -> Result<Vec<VerificationData>, std::io::Error> {
567+
let proof = std::fs::read(proof_path)?;
568+
let vm_program = std::fs::read(bin_path)?;
569+
let pub_input = if let Some(pub_path) = pub_path {
570+
std::fs::read(pub_path).ok()
571+
} else {
572+
None
573+
};
574+
575+
Ok(vec![VerificationData {
576+
proving_system: ProvingSystemId::Risc0,
577+
proof,
578+
pub_input,
579+
verification_key: None,
580+
vm_program_code: Some(vm_program),
581+
proof_generator_addr: Address::zero(),
582+
}])
583+
}
584+
585+
fn load_sp1_verification_data(
586+
proof_path: &str,
587+
elf_path: &str,
588+
pub_path: &Option<String>,
589+
) -> Result<Vec<VerificationData>, std::io::Error> {
590+
let proof = std::fs::read(proof_path)?;
591+
let vm_program = std::fs::read(elf_path)?;
592+
let pub_input = if let Some(pub_path) = pub_path {
593+
std::fs::read(pub_path).ok()
594+
} else {
595+
None
596+
};
597+
598+
Ok(vec![VerificationData {
599+
proving_system: ProvingSystemId::SP1,
600+
proof,
601+
pub_input,
602+
verification_key: None,
603+
vm_program_code: Some(vm_program),
604+
proof_generator_addr: Address::zero(),
605+
}])
606+
}

crates/task-sender/src/structs.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ pub enum InfiniteProofType {
158158
)]
159159
pub_path: Option<String>,
160160
},
161+
#[clap(about = "Send infinite SP1 proofs from file paths")]
162+
SP1 {
163+
#[arg(name = "Path to SP1 proof file (.proof)", long = "proof-path")]
164+
proof_path: String,
165+
#[arg(name = "Path to SP1 ELF file (.elf)", long = "elf-path")]
166+
elf_path: String,
167+
#[arg(
168+
name = "Path to SP1 public input file (.pub) - optional",
169+
long = "pub-path"
170+
)]
171+
pub_path: Option<String>,
172+
},
161173
}
162174

163175
#[derive(Debug, Clone, Copy)]

0 commit comments

Comments
 (0)