-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from worldcoin/0xkitsune/utils
feat(utils): utilities to seed MPC and iris code database
- Loading branch information
Showing
10 changed files
with
899 additions
and
280 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# MPC Utils | ||
|
||
|
||
## Seed MPC Databases | ||
Seed the coordinator and participant databases with random shares and masks. When seeding multiple participant databases, specify a `--participant-db-url` for each participant db. | ||
|
||
```bash | ||
cargo run --bin utils seed-mpc-db --coordinator-db-url <COORDINATOR_DB_URL> --participant-db-url <PARTICIPANT_0_DB_URL> --participant-db-url <PARTICIPANT_1_DB_URL> --num-templates <NUM_TEMPLATES> | ||
``` | ||
|
||
## Seed Iris Database | ||
Seed the iris code database with random iris code entries. Each entry includes a `signup_id`, `serial_id`, `iris_code_left`, `mask_code_left`, `iris_code_right` and `mask_code_right`. | ||
|
||
```bash | ||
cargo run --bin utils seed-iris-db --iris-code-db <IRIS_CODE_DB> --num-templates <NUM_TEMPLATES> | ||
``` | ||
|
||
|
||
## Send a Random Query via SQS | ||
Send a random iris code template to the MPC setup via SQS. Ensure that you are logged into the proper AWS account for the queue url you are using. If running with Localstack, ensure to also pass `--endpoint-url <ENDPOINT_URL>` and `--region <AWS_REGION>`. | ||
|
||
```bash | ||
cargo run --bin utils sqs-query --queue-url <SQS_QUEUE_URL> | ||
``` | ||
|
||
|
||
## Receive SQS Results | ||
Receive messages from a queue. This is useful when inspecting the results queue after sending a query to the MPC setup. If the queue is empty, the program will continually check for new message every second. Once messages are in the queue, the program will receive all messages, print them to the terminal and then delete the message from the queue. Ensure that you are logged into the proper AWS account for the queue url you are using. If running with Localstack, ensure to also pass `--endpoint-url <ENDPOINT_URL>` and `--region <AWS_REGION>`. | ||
|
||
```bash | ||
cargo run --bin utils sqs-receive --queue-url <SQS_QUEUE_URL> | ||
``` | ||
|
||
## Generate Mock Templates | ||
|
||
Generate random templates and write the resulting items to an output file. | ||
|
||
```bash | ||
cargo run --bin utils generate-mock-templates --num-templates <NUM_TEMPLATES> --output <OUTPUT_FILE> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use clap::Args; | ||
use mpc::template::Template; | ||
use rand::{thread_rng, Rng}; | ||
|
||
#[derive(Debug, Clone, Args)] | ||
pub struct GenerateMockTemplates { | ||
#[clap(short, long)] | ||
pub output: String, | ||
|
||
#[clap(short, long)] | ||
pub num_templates: usize, | ||
} | ||
|
||
pub async fn generate_mock_templates( | ||
args: &GenerateMockTemplates, | ||
) -> eyre::Result<()> { | ||
let mut rng = thread_rng(); | ||
|
||
let templates: Vec<Template> = | ||
(0..args.num_templates).map(|_| rng.gen()).collect(); | ||
|
||
let json = serde_json::to_string(&templates)?; | ||
|
||
//write to file | ||
std::fs::write(&args.output, json)?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.