Skip to content

Commit

Permalink
Merge pull request #26 from yetanotherco/release-0.1.1-fixes
Browse files Browse the repository at this point in the history
fix: Release 0.1.1 fixes
  • Loading branch information
PatStiles authored Oct 2, 2024
2 parents 31aff20 + 569d89b commit f6cc2c7
Show file tree
Hide file tree
Showing 11 changed files with 397 additions and 380 deletions.
9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ tokio = "1.38.0"
zk_rust_io = { path = "./zk_rust_io" }

# Sp1
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.1.1" }
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.1" }

# Risc 0
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", tag = "v1.0.1" }

# Aligned SDK
aligned-sdk = { git = "https://github.com/yetanotherco/aligned_layer", tag = "v0.7.2" }
aligned-sdk = { git = "https://github.com/yetanotherco/aligned_layer", tag = "v0.7.3" }
ethers = { tag = "v2.0.15-fix-reconnections", features = [
"ws",
"rustls",
Expand All @@ -31,8 +31,3 @@ bincode = "1.3.3"
rpassword = "7.3.1"
env_logger = "0.11.3"
log = "0.4.22"

[patch.crates-io]
ark-ff = { git = "https://github.com/a16z/arkworks-algebra", branch = "optimize/field-from-u64" }
ark-ec = { git = "https://github.com/a16z/arkworks-algebra", branch = "optimize/field-from-u64" }
ark-serialize = { git = "https://github.com/a16z/arkworks-algebra", branch = "optimize/field-from-u64" }
16 changes: 0 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
install: install_sp1 install_risc0

install_risc0:
@curl -L https://risczero.com/install | bash
@rzup
@cargo risczero --version

install_sp1:
@curl -L https://sp1.succinct.xyz | bash
@sp1up
@cargo prove --version
@echo "Sp1 Toolchain Installed"

# Default target
all: install

__EXAMPLES__:

# RISC0
Expand Down
202 changes: 104 additions & 98 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ zkRust seeks to simplify the development experience of developing using zkVM's a

## Installation:

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

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

zkRust can then be installed directly by downloading the latest release binaries.
Expand All @@ -33,103 +35,11 @@ You can test zkRust for any of the examples in the `examples` folder. This inclu
- Computing and reading the results of computing Fibonacci numbers.
- Performing RSA key verification.
- Performing ECDSA program.
- a blockchain state diff program verification.
- Verification of a blockchain state diff.
- Computing the Sha256 hash of a value.
- Verifying a tendermint block.
- Interacting with a user to answer a quiz.

Run one of the following commands to test zkRust. You can choose either Risc0 or SP1:

**Fibonacci**:

```bash
make prove_risc0_fibonacci
```

```bash
make prove_sp1_fibonacci
```

**RSA**:

```bash
make prove_risc0_rsa
```

```bash
make prove_sp1_rsa
```

**ECDSA**:

```bash
make prove_risc0_ecdsa
```

```bash
make prove_sp1_ecdsa
```

**Blockchain state diff**:

```bash
make prove_risc0_json
```

```bash
make prove_sp1_json
```

**Blockchain state diff**:

```bash
make prove_risc0_json
```

```bash
make prove_sp1_json
```

**Regex**:

```bash
make prove_risc0_regex
```

```bash
make prove_sp1_regex
```

**Sha**:

```bash
make prove_risc0_sha
```

```bash
make prove_sp1_sha
```

**Tendermint**:

```bash
make prove_risc0_tendermint
```

```bash
make prove_sp1_tendermint
```

**Zk Quiz**:

```bash
make prove_risc0_zkquiz
```

```bash
make prove_sp1_zkquiz
```

## Usage:

To use zkRust, To use zkRust users specify a `fn main()` whose execution is proven within the zkVM. This function must be defined within a `main.rs` file in a directory with the following structure:
Expand Down Expand Up @@ -257,11 +167,13 @@ cargo run --release -- prove-sp1 --submit-to-aligned-with-keystore <PATH_TO_KEYS

- `--keystore_path`: Path to the keystore of the users wallet. Defaults to `~/keystore`.

- `--rpc-url`: Specify the rpc-url used for the user eth rpc-url. Defaults to `https://ethereum-holesky-rpc.publicnode.com`.
- `--rpc-url`: Specifies the rpc-url used for the user eth rpc-url. Defaults to `https://ethereum-holesky-rpc.publicnode.com`.

- `--max-fee`: Specifies the max fee the user is willing to pay for there proof to be included in a batch. Defaults to `0.01 Eth`.

- `--chain_id`: Chain ID number of the ethereum chain Aligned is deployed on. Defaults to `1700`.

- `--precompiles`: Enables in acceleration via precompiles for supported zkVM's. Specifying this flag allows for VM specific speedups for specific expensive operations such as SHA256, SHA3, bigint multiplication, and ed25519 signature verification. By specifying this flag proving operations for specific operations within the following rust crates are accelerated:
- `--precompiles`: Enables acceleration via precompiles for supported zkVM's. Specifying this flag allows for VM specific speedups for specific expensive operations such as SHA256, SHA3, bigint multiplication, and ed25519 signature verification. By specifying this flag proving operations for specific operations within the following rust crates are accelerated:
- SP1:
Expand All @@ -277,7 +189,101 @@ cargo run --release -- prove-sp1 --submit-to-aligned-with-keystore <PATH_TO_KEYS
- k256 v0.13.1
- crypto-bigint v0.5.5
NOTE: for the precompiles to be included within the compilation step the crate version you are using must match the crate version above.
Run one of the following commands to test zkRust. You can choose either Risc0 or SP1:
**Fibonacci**:
```bash
make prove_risc0_fibonacci
```
```bash
make prove_sp1_fibonacci
```
**RSA**:
```bash
make prove_risc0_rsa
```
```bash
make prove_sp1_rsa
```
**ECDSA**:
```bash
make prove_risc0_ecdsa
```
```bash
make prove_sp1_ecdsa
```
**Blockchain state diff**:
```bash
make prove_risc0_json
```
```bash
make prove_sp1_json
```
**Blockchain state diff**:
```bash
make prove_risc0_json
```
```bash
make prove_sp1_json
```
**Regex**:
```bash
make prove_risc0_regex
```
```bash
make prove_sp1_regex
```
**Sha**:
```bash
make prove_risc0_sha
```
```bash
make prove_sp1_sha
```
**Tendermint**:
```bash
make prove_risc0_tendermint
```
```bash
make prove_sp1_tendermint
```
**Zk Quiz**:
```bash
make prove_risc0_zkquiz
```
```bash
make prove_sp1_zkquiz
```
**NOTE**: for the precompiles to be included within the compilation step the crate version you are using must match the crate version above.
**NOTE**: Aligned currently supports Risc0 proofs from `risc0-zkvm` version `v1.0.1`. For generating proofs using `cargo risc-zero` please ensure you are using `v1.0.1` or your proof will not be verified. If you encounter issues installing an older version of `cargo-risc0` please reference this [thread](https://discord.com/channels/953703904086994974/1290498126049841232).
# Acknowledgments:
Expand Down
3 changes: 1 addition & 2 deletions examples/fibonacci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ fn input() {
}

fn output() {
let a: u32 = zk_rust_io::read();
let b: u32 = zk_rust_io::read();
let (a, b): (u32, u32) = zk_rust_io::out();

println!("a: {}", a);
println!("b: {}", b);
Expand Down
2 changes: 1 addition & 1 deletion examples/json/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn input() {
}

fn output() {
let account_state: Account = zk_rust_io::read();
let account_state: Account = zk_rust_io::out();
println!(
"Final account state: {}",
serde_json::to_string(&account_state).unwrap()
Expand Down
5 changes: 3 additions & 2 deletions install_zkrust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ echo "Installing zkVM toolchains"

# Install risc0 toolchain
curl -L https://risczero.com/install | bash
rzup
rzup install
cargo risczero install --version v1.0.1
cargo risczero --version
echo "Risc0 Toolchain Installed"

Expand All @@ -85,4 +86,4 @@ sp1up
cargo prove --version
echo "Sp1 Toolchain Installed"

echo "Run 'source $PROFILE' or start a new terminal session to use aligned."
echo "Run 'source $PROFILE' or start a new terminal session to use aligned."
47 changes: 31 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,38 @@ pub async fn submit_proof_to_aligned(
max_fee: &u128,
proof_system_id: ProvingSystemId,
) -> anyhow::Result<()> {
let keystore_password = rpassword::prompt_password("Enter keystore password: ")
.expect("Failed to read keystore password");
let Ok(keystore_password) = rpassword::prompt_password("Enter keystore password: ") else {
error!("Failed to read keystore password");
return Ok(());
};

let wallet = LocalWallet::decrypt_keystore(keystore_path, keystore_password)
.expect("Failed to decrypt keystore")
.with_chain_id(17000u64);
let Ok(local_wallet) = LocalWallet::decrypt_keystore(keystore_path, keystore_password) else {
error!("Failed to decrypt keystore");
return Ok(());
};
let wallet = local_wallet.with_chain_id(17000u64);

let proof = std::fs::read(proof_path).expect("failed to read proof");
let elf_data = std::fs::read(elf_path).expect("failed to read ELF");
let pub_input = pub_input_path
.map(|pub_input_path| std::fs::read(pub_input_path).expect("failed to read public input"));
let Ok(proof) = std::fs::read(proof_path) else {
error!("Failed to Read Proof");
return Ok(());
};
let Ok(elf_data) = std::fs::read(elf_path) else {
error!("Failed to Read ELF");
return Ok(());
};
let pub_input = match pub_input_path {
Some(path) => Some(std::fs::read(path).expect("Failed to Read Public Inputs")),
None => None,
};

let provider = Provider::<Http>::try_from(rpc_url).expect("Failed to connect to provider");
let Ok(provider) = Provider::<Http>::try_from(rpc_url) else {
error!("Failed to connect to provider");
return Ok(());
};

let signer = Arc::new(SignerMiddleware::new(provider.clone(), wallet.clone()));

pay_batcher(wallet.address(), signer.clone())
.await
.expect("Failed to pay for proof submission");
pay_batcher(wallet.address(), signer.clone()).await?;

let max_fee = U256::from(*max_fee);

Expand All @@ -100,9 +113,11 @@ pub async fn submit_proof_to_aligned(
pub_input,
};

let nonce = get_next_nonce(rpc_url, wallet.address(), BATCHER_PAYMENTS_ADDRESS)
.await
.expect("could not get nonce");
let Ok(nonce) = get_next_nonce(rpc_url, wallet.address(), BATCHER_PAYMENTS_ADDRESS).await
else {
error!("could not get nonce");
return Ok(());
};

let chain = match chain_id {
17000 => Chain::Holesky,
Expand Down
Loading

0 comments on commit f6cc2c7

Please sign in to comment.