Skip to content

Commit

Permalink
Merge pull request #39 from yetanotherco/feat/release-nits
Browse files Browse the repository at this point in the history
Feat/release nits
  • Loading branch information
PatStiles authored Oct 10, 2024
2 parents 673f84a + 353b572 commit f64fd83
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 54 deletions.
22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,19 @@
`zkRust` simplifies the development experience of using zkVM's by abstracting the complexity of using zkVM's from the developer and providing them the choice of which zkVM they would like to develop with.

## Installation:
First make sure [Rust](https://www.rust-lang.org/tools/install) is installed on your machine.

First make sure [Rust](https://www.rust-lang.org/tools/install) is installed on your machine. Then install the zkVM toolchains from [sp1](https://github.com/succinctlabs/sp1) and [risc0](https://github.com/risc0/risc0) by running:

```sh
curl -L https://sp1.succinct.xyz | bash
sp1up
cargo prove --version
```

and
zkRust can also be installed directly by downloading the latest release binaries.

```sh
curl -L https://risczero.com/install | bash
rzup install
cargo risczero --version
curl -L https://raw.githubusercontent.com/yetanotherco/zkRust/main/install_zkrust.sh | bash
```

zkRust can also be installed directly by downloading the latest release binaries.
for local development install the repository dependencies.

```sh
curl -L https://raw.githubusercontent.com/yetanotherco/zkRust/main/install_zkrust.sh | bash
make install
```

## Quickstart
Expand Down Expand Up @@ -69,11 +61,11 @@ Projects can also store libraries in a separate `lib/` folder.
└── main.rs
```

The user may also define a `input()`, `output()` functions, in addition to `main()`. The `input()` and `output()` functions define code that runs outside of the zkVM before and after the zkVM generates a proof of the computation. The `input()` function executes before the zkVM code is executed and allows the user to define inputs passed to the VM such as a deserialized Tx or data fetched from an external source at runtime. Within the `main()` (guest) function the user may write information from the computation performed in the zkVM to an output buffer to be used after proof generation. The `output()` defines code that allows the user to read the information written to that buffer of the and perform post-processing of that data.
The user may also define a `input()`, `output()` functions, in addition to `main()`. The `input()` and `output()` functions define code that runs outside of the zkVM before and after the zkVM generates a proof of the users program. The `input()` function executes before the zkVM code is executed and allows the user to define inputs passed to the VM such as a deserialized Tx or data fetched from an external source at runtime. Within the `main()` (guest) function the user may write information from the computation performed in the zkVM to an output buffer to be used after proof generation. The `output()` defines code that allows the user to read the information written to that buffer of the and perform post-processing of that data.

![](./assets/zkRust_execution_flow.png)

The user may specify (public) inputs into the VM (guest) code using `zk_rust_io::write()` as long on the type of Rust object they want to input into the VM implements [Serialize](https://docs.rs/serde/latest/serde/trait.Serialize.html). Within there `main()` function the user may read in these inputs to there program by specifying `zk_rust_io::read()`. They can also output data computed during the execution phase of the code within the VM program by commiting it to the VM output via `zk_rust_io::commit()`. To read the output of the output of the VM program the user declares `zk_rust_io::out()`, which reads and deserializes the committed information from the VM output buffer.
The user may specify (public) inputs into the VM (guest) code using `zk_rust_io::write()` as long on the type of Rust object they want to input into the VM implements [Serialize](https://docs.rs/serde/latest/serde/trait.Serialize.html). Within there `main()` function the user may read in these inputs to there program via `zk_rust_io::read()`. They can also output data computed during the execution phase of the code within the VM program by commiting it to the VM output via `zk_rust_io::commit()`. To read the output of the output of the VM program the user declares `zk_rust_io::out()`, which reads and deserializes the committed information from the VM output buffer.

The `zk_rust_io` crate defines function headers that are not inlined and are purely used as compile time symbols to ensure a user can compile there Rust code before running it within one of the zkVM available in zkRust.

Expand Down
43 changes: 23 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ pub async fn submit_proof_to_aligned(
.map_err(|e| AlignedError::SubmitError(SubmitError::WalletSignerError(e.to_string())))?;

let network: Network = args.network.into();
//Required if submission enabled. Therefore we unwrap().
let keystore_path = args.keystore_path.clone().unwrap();
let Some(keystore_path) = args.keystore_path.clone() else {
return Err(SubmitError::GenericError(
"Keystore path no found. Please supply path to your local wallet keystore.".to_string(),
))?;
};
let local_wallet = LocalWallet::decrypt_keystore(&keystore_path, keystore_password)
.map_err(|e| AlignedError::SubmitError(SubmitError::WalletSignerError(e.to_string())))?;
let chain_id = get_chain_id(&args.rpc_url).await?;
Expand All @@ -118,13 +121,10 @@ pub async fn submit_proof_to_aligned(
.map_err(|e| AlignedError::SubmitError(SubmitError::GenericError(e.to_string())))?;

// Public inputs are optional.
let pub_input = match pub_input_path {
Some(path) => Some(
std::fs::read(path)
.map_err(|e| AlignedError::SubmitError(SubmitError::GenericError(e.to_string())))?,
),
None => None,
};
let pub_input = pub_input_path
.map(std::fs::read)
.transpose()
.map_err(|e| SubmitError::GenericError(e.to_string()))?;

let provider = Provider::<Http>::try_from(&args.rpc_url)
.map_err(|e| SubmitError::EthereumProviderError(e.to_string()))?;
Expand All @@ -139,24 +139,27 @@ pub async fn submit_proof_to_aligned(
let user_balance = get_balance_in_aligned(user_address, &args.rpc_url, network)
.await
.map_err(|_| {
SubmitError::GenericError("Failed to retrive user balance from Aligned".to_string())
SubmitError::GenericError("Failed to retrieve user balance from Aligned".to_string())
})?;

let format_estimated_fee = format_units(estimated_fee, "ether").map_err(|e| {
error!("Unable to convert estimate proof submision price");
error!("Unable to convert estimated proof submision price");
SubmitError::GenericError(e.to_string())
})?;

let format_user_balance = format_units(user_balance, "ether").map_err(|e| {
error!("Unable to convert estimate proof submision price");
error!("Unable to convert estimated proof submision price");
SubmitError::GenericError(e.to_string())
})?;

if user_balance < estimated_fee {
info!("Insufficient Balance balance for {:?}: User Balance {:?} eth < Proof Submission Fee {:?} eth", user_address, format_user_balance, format_estimated_fee);
info!(
"Insufficient balance for {:?}: User Balance {:?} eth < Proof Submission Fee {:?} eth",
user_address, format_user_balance, format_estimated_fee
);
if Confirm::with_theme(&dialoguer::theme::ColorfulTheme::default())
.with_prompt(format!(
"Would you like to deposit {:?} eth to Aligned to fund proof submission?",
"Would you like to deposit {:?} eth into Aligned to fund proof submission?",
args.batcher_payment
))
.interact()
Expand All @@ -165,7 +168,7 @@ pub async fn submit_proof_to_aligned(
SubmitError::GenericError(e.to_string())
})?
{
info!("Submitting Payment to Batcher");
info!("Submitting deposit to Batcher");
let Ok(tx_receipt) =
deposit_to_aligned(U256::from(args.batcher_payment), signer, network).await
else {
Expand All @@ -174,13 +177,13 @@ pub async fn submit_proof_to_aligned(
))?;
};
info!(
"Payment sent to the batcher successfully. Tx: 0x{:x}",
"Funds deposited successfully to Batcher payment contract. Tx: 0x{:x}",
tx_receipt.transaction_hash
);
} else {
info!("Batcher Payment Cancelled");
return Err(SubmitError::GenericError(
"Insufficient User Balance on Aligned".to_string(),
"Insufficient user balance on Aligned".to_string(),
))?;
}
}
Expand All @@ -196,9 +199,9 @@ pub async fn submit_proof_to_aligned(
SubmitError::GenericError(e.to_string())
})?
{
info!("User declined the submition cost");
info!("User declined to pay submission cost");
return Err(SubmitError::GenericError(
"User declined the submition cost".to_string(),
"User declined to pay submission cost".to_string(),
))?;
}

Expand Down Expand Up @@ -240,7 +243,7 @@ pub async fn submit_proof_to_aligned(
PathBuf::from(&args.batch_inclusion_data_directory_path),
&aligned_verification_data,
)?;
println!(
info!(
"Aligned Verification Data saved {:?}",
args.batch_inclusion_data_directory_path
);
Expand Down
32 changes: 16 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ async fn main() -> io::Result<()> {
let proof_data_dir = PathBuf::from(&args.proof_data_directory_path);
if !proof_data_dir.exists() {
std::fs::create_dir_all(proof_data_dir).unwrap_or(info!(
"saving generated proofs to: {:?}",
"Saving Proofs to: {:?}",
&args.proof_data_directory_path
));
}
if utils::validate_directory_structure(&args.guest_path) {
let Some(home_dir) = dirs::home_dir() else {
error!("Failed to locate Home Dir");
error!("Failed to locate home directory");
return Ok(());
};
let Ok(current_dir) = std::env::current_dir() else {
error!("Failed to get Current Directory");
error!("Failed to locate current directory");
return Ok(());
};
let home_dir = home_dir.join(".zkRust");
Expand All @@ -62,7 +62,7 @@ async fn main() -> io::Result<()> {
)?;

let Ok(imports) = utils::get_imports(&home_dir.join(sp1::SP1_GUEST_MAIN)) else {
error!("Failed to Extract Imports");
error!("Failed to extract imports");
return Ok(());
};

Expand All @@ -75,7 +75,7 @@ async fn main() -> io::Result<()> {
"fn output()".to_string(),
],
) else {
error!("Failed to Extract Function Bodies");
error!("Failed to extract function bodies");
return Ok(());
};
/*
Expand Down Expand Up @@ -130,7 +130,7 @@ async fn main() -> io::Result<()> {
)
.await
.map_err(|e| {
error!("Error Submitting Proof to Aligned: {:?}", e);
error!("Proof not submitted to Aligned");
io::Error::other(e.to_string())
})?;
info!("SP1 proof submitted and verified on Aligned");
Expand All @@ -141,7 +141,7 @@ async fn main() -> io::Result<()> {
home_dir.join(sp1::SP1_HOST_MAIN),
)
.map_err(|e| {
error!("Failed to clear SP1 Host File");
error!("Failed to clear SP1 host file");
e
})?;
return Ok(());
Expand All @@ -155,7 +155,7 @@ async fn main() -> io::Result<()> {
)?;
return Ok(());
} else {
error!("zkRust Directory structure incorrect please consult the README",);
error!("zkRust directory structure invalid please consult the README",);
return Ok(());
}
}
Expand All @@ -168,16 +168,16 @@ async fn main() -> io::Result<()> {
let proof_data_dir = PathBuf::from(&args.proof_data_directory_path);
if !proof_data_dir.exists() {
std::fs::create_dir_all(proof_data_dir).unwrap_or(info!(
"saving generated proofs to: {:?}",
"Saving generated proofs to: {:?}",
&args.proof_data_directory_path
));
}
let Some(home_dir) = dirs::home_dir() else {
error!("Failed to Locate Home Dir");
error!("Failed to locate home directory");
return Ok(());
};
let Ok(current_dir) = std::env::current_dir() else {
error!("Failed to get Current Directory");
error!("Failed to locate current directory");
return Ok(());
};
let home_dir = home_dir.join(".zkRust");
Expand All @@ -193,7 +193,7 @@ async fn main() -> io::Result<()> {

let Ok(imports) = utils::get_imports(&home_dir.join(risc0::RISC0_GUEST_MAIN))
else {
error!("Failed to Extract Imports");
error!("Failed to extract imports");
return Ok(());
};
let main_path = home_dir.join(risc0::RISC0_GUEST_MAIN);
Expand All @@ -205,7 +205,7 @@ async fn main() -> io::Result<()> {
"fn output()".to_string(),
],
) else {
error!("Failed to Extract Function Bodies");
error!("Failed to extract function bodies");
return Ok(());
};

Expand Down Expand Up @@ -261,7 +261,7 @@ async fn main() -> io::Result<()> {
)
.await
.map_err(|e| {
error!("Error Submitting Proof to Aligned: {:?}", e);
error!("Error submitting proofs to Aligned: {:?}", e);
io::Error::other(e.to_string())
})?;

Expand All @@ -274,7 +274,7 @@ async fn main() -> io::Result<()> {
home_dir.join(risc0::RISC0_HOST_MAIN),
)
.map_err(|e| {
error!("Failed to Clear Risc0 Host File");
error!("Failed to clear Risc0 host file");
e
})?;
return Ok(());
Expand All @@ -288,7 +288,7 @@ async fn main() -> io::Result<()> {
)?;
return Ok(());
} else {
error!("zkRust Directory structure incorrect please consult the README",);
error!("zkRust directory structure incorrect please consult the README",);
return Ok(());
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ fn copy_dependencies(toml_path: &Path, guest_toml_path: &Path) -> io::Result<()>
let mut guest_toml = OpenOptions::new()
.create(true)
.append(true)
.open(guest_toml_path)
.unwrap();
.open(guest_toml_path)?;

// Write the text after the search string to the output file
guest_toml.write_all(dependencies.as_bytes())
Expand Down Expand Up @@ -331,7 +330,7 @@ pub fn extract_regex(file_path: &PathBuf, regex: &str) -> io::Result<Vec<String>
let reader = io::BufReader::new(file);

let mut values = Vec::new();
let regex = Regex::new(regex).unwrap();
let regex = Regex::new(regex).map_err(io::Error::other)?;

for line in reader.lines() {
let line = line?;
Expand Down

0 comments on commit f64fd83

Please sign in to comment.