Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(example): enhance example for public inputs validation #1195

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4948d71
feat: add sp1 to the example of validating public input
IAvecilla Oct 7, 2024
f8746d6
chore: add n as public input in risc0 example
IAvecilla Oct 7, 2024
a3ae2a3
feat: generate network from string
IAvecilla Oct 7, 2024
ae2f106
feat: update fibonacci validator to work with the new example
IAvecilla Oct 7, 2024
8674fdb
feat: update aligned integration to work with both verifiers
IAvecilla Oct 7, 2024
10ee5ce
chore: update lock files
IAvecilla Oct 7, 2024
48ea17a
chore: add docs to run example locally
IAvecilla Oct 7, 2024
7f5c784
feat: update docs for the new example
IAvecilla Oct 7, 2024
6d53937
feat: update makefile with new targets to make example easier to run
IAvecilla Oct 7, 2024
4c8e83c
feat: add bash script to test batch inclusion easily
IAvecilla Oct 7, 2024
334468f
chore: fix toml EOL
IAvecilla Oct 7, 2024
20b8aae
chore: address review comments
IAvecilla Oct 9, 2024
d46cc30
chore: add output examples for each command to be easier to follow
IAvecilla Oct 9, 2024
66977b5
docs: add disclaimer when sending proofs to actually seal the batch
IAvecilla Oct 9, 2024
4478256
Pull fixes from testnet (#1231)
MauroToscano Oct 13, 2024
ba04f04
Add observability batcher (#1226)
uri-99 Oct 13, 2024
73e0481
docs: update version to v0.9.1 (#1233)
JuArce Oct 13, 2024
e28d97e
Merge branch 'staging' into 1132-add-public-input-example
uri-99 Oct 14, 2024
f6b1dec
fix: remove duplicated import
uri-99 Oct 14, 2024
bc2fe08
fix: update cargo.lock
uri-99 Oct 14, 2024
8f73d97
fix: update cargo.lock
uri-99 Oct 14, 2024
55a931e
feat: better revert if invalid ELF, and updated risc0 elf
uri-99 Oct 14, 2024
6dfc1c6
chore: add error code
uri-99 Oct 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 135 additions & 49 deletions batcher/Cargo.lock

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions batcher/aligned-sdk/src/core/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use lambdaworks_crypto::merkle_tree::{
};
use serde::{Deserialize, Serialize};
use sha3::{Digest, Keccak256};
use std::str::FromStr;

use super::errors::VerifySignatureError;

Expand Down Expand Up @@ -344,6 +345,22 @@ pub enum Network {
HoleskyStage,
}

impl FromStr for Network {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"holesky" => Ok(Network::Holesky),
"holesky-stage" => Ok(Network::HoleskyStage),
"devnet" => Ok(Network::Devnet),
_ => Err(
"Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\""
.to_string(),
),
}
}
}

#[cfg(test)]
mod tests {
use ethers::signers::LocalWallet;
Expand Down
307 changes: 150 additions & 157 deletions docs/3_guides/3_validating_public_input.md

Large diffs are not rendered by default.

41 changes: 37 additions & 4 deletions examples/validating-public-input/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
generate_risc_zero_fibonacci_proof:
generate_risc0_fibonacci_proof:
@cd risc_zero/fibonacci_proof_generator && \
cargo run && \
cargo run --release && \
echo "Fibonacci proof, pub input and image ID generated in risc_zero folder"

submit_fibonacci_proof:
generate_sp1_fibonacci_proof:
@cd sp1/fibonacci/script && \
cargo run --release && \
echo "Fibonacci proof, pub input and image ID generated in sp1 folder"


submit_fibonacci_sp1_proof_devnet:
@cd aligned-integration && \
RUST_LOG=info cargo run --release -- --proving-system "SP1" --network "devnet" --batcher-url "ws://localhost:8080" --rpc-url "http://localhost:8545"

submit_fibonacci_sp1_proof:
@cd aligned-integration && \
RUST_LOG=info cargo run --release -- --keystore-path $(KEYSTORE_PATH)
RUST_LOG=info cargo run --release -- --keystore-path $(KEYSTORE_PATH) --proving-system "SP1"

submit_fibonacci_risc0_proof_devnet:
@cd aligned-integration && \
RUST_LOG=info cargo run --release -- --proving-system "Risc0" --network "devnet" --batcher-url "ws://localhost:8080" --rpc-url "http://localhost:8545"

submit_fibonacci_risc0_proof:
@cd aligned-integration && \
RUST_LOG=info cargo run --release -- --keystore-path $(KEYSTORE_PATH) --proving-system "Risc0"

verify_sp1_batch_inclusion:
@. ./contracts/.env && . ./contracts/validate_batch_inclusion.sh $(FIBONACCI_VALIDATOR_ADDRESS) $(DATA_FILE_NAME) SP1

verify_risc0_batch_inclusion:
@. ./contracts/.env && . ./contracts/validate_batch_inclusion.sh $(FIBONACCI_VALIDATOR_ADDRESS) $(DATA_FILE_NAME) Risc0

verify_risc0_batch_inclusion_devnet:
@. ./contracts/.env.devnet && . ./contracts/validate_batch_inclusion.sh $(FIBONACCI_VALIDATOR_ADDRESS) $(DATA_FILE_NAME) Risc0

verify_sp1_batch_inclusion_devnet:
@. ./contracts/.env.devnet && . ./contracts/validate_batch_inclusion.sh $(FIBONACCI_VALIDATOR_ADDRESS) $(DATA_FILE_NAME) SP1

deploy_fibonacci_validator:
@. ./contracts/.env && . ./contracts/deploy.sh

deploy_fibonacci_validator_devnet:
@. ./contracts/.env.devnet && . ./contracts/deploy.sh
91 changes: 91 additions & 0 deletions examples/validating-public-input/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Validating public input

## Testing locally

Set up all the components of aligned locally following the [aligned setup guide](../../docs/3_guides/6_setup_aligned.md).

This example is designed to do either with SP1 or risc0 proofs these are the commands to use depending on which verifier want to be used.

### Risc0

1. `make generate_risc0_fibonacci_proof`

2. `make submit_fibonacci_risc0_proof_devnet`

The command will log the file where all the aligned verification data was saved like so:

```
[2024-10-09T15:54:42Z INFO aligned_integration] Saved batch inclusion data to ".../aligned_test/examples/validating-public-input/aligned-integration/batch_inclusion_data/<DATA_FILE_NAME>"
```

Save the name since it will be necessary, you can see it in `aligned-layer/examples/validating-public-input/batch_inclusion_data` otherwise.

3. `make deploy_fibonacci_validator_devnet`

The command will log the address where the validator was deployed:

```
##### anvil-hardhat
✅ [Success]Hash: 0xe0c216a3a24d5bd0551924592e42c6d96a889e3082ba3d7fff413336fba66815
Contract Address: 0x5081a39b8A5f0E35a8D959395a630b68B74Dd30f
Block: 585
Paid: 0.000000000005889224 ETH (736153 gas * 0.000000008 gwei)
```

save the contract address for the next command.

4. `make verify_risc0_batch_inclusion_devnet FIBONACCI_VALIDATOR_ADDRESS=<FIBONACCI_VALIDATOR_ADDRESS> DATA_FILE_NAME=<DATA_FILE_NAME>`

Where `FIBONACCI_VALIDATOR_ADDRESS` is the address of the deployed validator contract and `DATA_FILE_NAME` the name of the file where the aligned verification data was saved (including the extension `.json`).

If everything goes well you should see a transaction receipt with a `success` label in the status:

```
...
root <ROOT_HASH>
status 1 (success)
transactionHash <TX_HASH>
...
```

uri-99 marked this conversation as resolved.
Show resolved Hide resolved
### SP1

1. `make generate_sp1_fibonacci_proof`

2. `make submit_fibonacci_sp1_proof_devnet`

The command will log the file where all the aligned verification data was saved like so:

```
[2024-10-09T15:54:42Z INFO aligned_integration] Saved batch inclusion data to ".../aligned_test/examples/validating-public-input/aligned-integration/batch_inclusion_data/<DATA_FILE_NAME>"
```

Save the name since it will be necessary, you can see it in `aligned-layer/examples/validating-public-input/batch_inclusion_data` otherwise.

3. `make deploy_fibonacci_validator_devnet`

The command will log the address where the validator was deployed:

```
##### anvil-hardhat
✅ [Success]Hash: 0xe0c216a3a24d5bd0551924592e42c6d96a889e3082ba3d7fff413336fba66815
Contract Address: 0x5081a39b8A5f0E35a8D959395a630b68B74Dd30f
Block: 585
Paid: 0.000000000005889224 ETH (736153 gas * 0.000000008 gwei)
```

save the contract address for the next command.

4. `make verify_sp1_batch_inclusion_devnet FIBONACCI_VALIDATOR_ADDRESS=<FIBONACCI_VALIDATOR_ADDRESS> DATA_FILE_NAME=<DATA_FILE_NAME>`

Where `FIBONACCI_VALIDATOR_ADDRESS` is the address of the deployed validator contract and `DATA_FILE_NAME` the name of the file where the aligned verification data was saved (including the extension `.json`).

If everything goes well you should see a transaction receipt with a `success` label in the status:

```
...
root <ROOT_HASH>
status 1 (success)
transactionHash <TX_HASH>
...
```
45 changes: 45 additions & 0 deletions examples/validating-public-input/aligned-integration/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading