Skip to content

Commit dbbadfa

Browse files
uri-99entropidelicMauroToscanotaturosatiJuArce
authored
feat: rust sdk (#459)
Co-authored-by: Mariano Nicolini <mariano.nicolini.91@gmail.com> Co-authored-by: MauroFab <maurotoscano2@gmail.com> Co-authored-by: Santos Rosati <rosatisantos@gmail.com> Co-authored-by: JuArce <52429267+JuArce@users.noreply.github.com> Co-authored-by: Nicolas Rampoldi <58613770+NicolasRampoldi@users.noreply.github.com>
1 parent 7bf111b commit dbbadfa

26 files changed

Lines changed: 978 additions & 407 deletions

File tree

batcher/Cargo.lock

Lines changed: 70 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

batcher/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[workspace]
22
members = [
33
"aligned-batcher",
4-
"aligned-batcher-lib",
4+
"aligned-sdk",
55
"aligned"
66
]
77
resolver = "2"

batcher/aligned-batcher-lib/src/lib.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

batcher/aligned-batcher/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ halo2_backend = { git = "https://github.com/yetanotherco/yet-another-halo2-fork.
2929
halo2_proofs = { git = "https://github.com/yetanotherco/yet-another-halo2-fork.git", branch = "feat/serde_constraint_system" }
3030
lazy_static = "1.4.0"
3131
bincode = "1.3.3"
32-
aligned-batcher-lib = { path = "../aligned-batcher-lib"}
32+
aligned-sdk = { path = "../aligned-sdk"}

batcher/aligned-batcher/src/gnark/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use aligned_batcher_lib::types::ProvingSystemId;
1+
use aligned_sdk::types::ProvingSystemId;
22

33
#[derive(Copy, Clone, Debug)]
44
#[repr(C)]

batcher/aligned-batcher/src/lib.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ use std::net::SocketAddr;
55
use std::sync::Arc;
66
use std::time::Duration;
77

8+
use crate::eth::BatchVerifiedEventStream;
9+
use aligned_sdk::types::{
10+
BatchInclusionData, ClientMessage, VerificationCommitmentBatch, VerificationData,
11+
VerificationDataCommitment,
12+
};
813
use aws_sdk_s3::client::Client as S3Client;
14+
use eth::{BatchVerifiedFilter, BatcherPaymentService};
915
use ethers::prelude::{Middleware, Provider};
1016
use ethers::providers::Ws;
1117
use ethers::types::{Address, U256};
@@ -20,18 +26,11 @@ use tokio_tungstenite::tungstenite::error::ProtocolError;
2026
use tokio_tungstenite::tungstenite::protocol::{frame::coding::CloseCode, CloseFrame};
2127
use tokio_tungstenite::tungstenite::{Error, Message};
2228
use tokio_tungstenite::WebSocketStream;
23-
24-
use aligned_batcher_lib::types::{
25-
BatchInclusionData, ClientMessage, VerificationCommitmentBatch, VerificationData,
26-
VerificationDataCommitment,
27-
};
28-
use eth::{BatchVerifiedFilter, BatcherPaymentService};
2929
use types::batch_queue::BatchQueue;
3030
use types::errors::BatcherError;
3131

3232
use crate::config::{ConfigFromYaml, ContractDeploymentOutput, NonPayingConfig};
3333
use crate::eth::AlignedLayerServiceManager;
34-
use crate::eth::BatchVerifiedEventStream;
3534

3635
mod config;
3736
mod eth;
@@ -45,8 +44,6 @@ mod zk_utils;
4544

4645
const S3_BUCKET_NAME: &str = "storage.alignedlayer.com";
4746

48-
const PROTOCOL_VERSION: u16 = 0;
49-
5047
pub struct Batcher {
5148
s3_client: S3Client,
5249
eth_ws_provider: Provider<Ws>,
@@ -59,7 +56,6 @@ pub struct Batcher {
5956
max_batch_size: usize,
6057
last_uploaded_batch_block: Mutex<u64>,
6158
pre_verification_is_enabled: bool,
62-
protocol_version: u16,
6359
non_paying_config: Option<NonPayingConfig>,
6460
}
6561

@@ -121,7 +117,6 @@ impl Batcher {
121117
max_batch_size: config.batcher.max_batch_size,
122118
last_uploaded_batch_block: Mutex::new(last_uploaded_batch_block),
123119
pre_verification_is_enabled: config.batcher.pre_verification_is_enabled,
124-
protocol_version: PROTOCOL_VERSION,
125120
non_paying_config: config.batcher.non_paying,
126121
}
127122
}
@@ -172,7 +167,11 @@ impl Batcher {
172167
let outgoing = Arc::new(RwLock::new(outgoing));
173168

174169
// Send the protocol version to the client
175-
let protocol_version_msg = Message::binary(self.protocol_version.to_be_bytes().to_vec());
170+
let protocol_version_msg = Message::binary(
171+
aligned_sdk::sdk::CURRENT_PROTOCOL_VERSION
172+
.to_be_bytes()
173+
.to_vec(),
174+
);
176175

177176
outgoing
178177
.write()

batcher/aligned-batcher/src/types/batch_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use futures_util::stream::SplitSink;
55
use tokio::{net::TcpStream, sync::RwLock};
66
use tokio_tungstenite::{tungstenite::Message, WebSocketStream};
77

8-
use aligned_batcher_lib::types::{VerificationData, VerificationDataCommitment};
8+
use aligned_sdk::types::{VerificationData, VerificationDataCommitment};
99

1010
pub(crate) type BatchQueueEntry = (
1111
VerificationData,

batcher/aligned-batcher/src/zk_utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::halo2::ipa::verify_halo2_ipa;
33
use crate::halo2::kzg::verify_halo2_kzg;
44
use crate::risc_zero::verify_risc_zero_proof;
55
use crate::sp1::verify_sp1_proof;
6-
use aligned_batcher_lib::types::{ProvingSystemId, VerificationData};
6+
use aligned_sdk::types::{ProvingSystemId, VerificationData};
77
use log::{debug, warn};
88

99
pub(crate) fn verify(verification_data: &VerificationData) -> bool {
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
[package]
2-
name = "aligned-batcher-lib"
2+
name = "aligned-sdk"
33
version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
77
ethers = { tag = "v2.0.15-fix-reconnections", features = ["ws", "rustls"], git = "https://github.com/yetanotherco/ethers-rs.git" }
8-
anyhow = "1.0.83"
98
log = { version = "0.4.21"}
9+
serde_json = "1.0.117"
10+
tokio-tungstenite = { version = "0.23.1", features = ["native-tls"] }
11+
futures-util = "0.3.30"
12+
tokio = { version = "1.37.0", features = ["io-std", "time", "macros", "rt", "rt-multi-thread", "sync"] }
13+
lambdaworks-crypto = { version = "0.7.0", features = ["serde"] }
1014
serde = { version = "1.0.201", features = ["derive"] }
1115
sha3 = { version = "0.10.8"}
12-
lambdaworks-crypto = { version = "0.7.0", features = ["serde"] }
16+
url = "2.5.0"
1317
hex = "0.4.3"
14-
serde_json = "1.0.117"

batcher/aligned-sdk/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Aligned Verification SDK
2+
3+
The Aligned Verification SDK facilitates the submission and verification of proofs through the Aligned batcher and checks the inclusion of these verified proofs on-chain. This README provides an overview of the SDK, its installation, usage, and API details.
4+
5+
## Table of Contents
6+
- [Aligned Verification SDK](#aligned-verification-sdk)
7+
- [Table of Contents](#table-of-contents)
8+
- [Installation](#installation)
9+
- [API Reference](#api-reference)
10+
11+
## Installation
12+
13+
To use this SDK in your Rust project, add the following to your `Cargo.toml`:
14+
15+
```toml
16+
[dependencies]
17+
aligned-sdk = { git = "https://github.com/yetanotherco/aligned_layer" }
18+
```
19+
20+
## API Reference
21+
22+
### submit
23+
24+
Submits a proof to the batcher to be verified and returns an aligned verification data struct.
25+
26+
#### Arguments
27+
28+
- `batcher_addr` - The address of the batcher to which the proof will be submitted.
29+
- `verification_data` - The verification data for the proof.
30+
- `wallet` - The wallet used to sign the proof.
31+
32+
#### Returns
33+
34+
- `Result<Option<AlignedVerificationData>>, SubmitError>` - An aligned verification data or an error.
35+
36+
#### Errors
37+
38+
- `MissingParameter` if the verification data vector is empty.
39+
- `SerdeError` if there is an error serializing the verification data.
40+
- `ConnectionError` if there is an error sending the message to the websocket.
41+
42+
### submit_multiple
43+
44+
Submits mulitple proofs to the batcher to be verified and returns an aligned verification data array.
45+
46+
#### Arguments
47+
48+
- `batcher_addr` - The address of the batcher to which the proof will be submitted.
49+
- `verification_data` - A verification data array.
50+
- `wallet` - The wallet used to sign the proof.
51+
52+
#### Returns
53+
54+
- `Result<Option<Vec<AlignedVerificationData>>>, SubmitError>` - An aligned verification data array or an error.
55+
56+
#### Errors
57+
58+
- `MissingParameter` if the verification data vector is empty.
59+
- `SerdeError` if there is an error serializing the verification data.
60+
- `ConnectionError` if there is an error sending the message to the websocket.
61+
62+
### verify_proof_onchain
63+
64+
Checks if the proof has been verified with Aligned and is included in the batch on-chain.
65+
66+
#### Arguments
67+
68+
- `aligned_verification_data` - The aligned verification data obtained when submitting the proofs.
69+
- `chain` - The chain on which the verification will be done.
70+
- `eth_rpc_url` - The URL of the Ethereum RPC node.
71+
72+
#### Returns
73+
74+
- `Result<bool, VerificationError>` - A boolean indicating whether the proof was verified on-chain and is included in the batch or an error.
75+
76+
#### Errors
77+
78+
- `EthError` if there is an error creating the rpc provider.
79+
- `ParsingError` if there is an error parsing the address of the contract.
80+
- `EthError` if there is an error verifying the proof on-chain.
81+
82+
### get_verification_key_commitment
83+
84+
Generates a keccak256 hash commitment of the verification key.
85+
86+
#### Arguments
87+
88+
- `content` - A byte slice of the verification key.
89+
90+
#### Returns
91+
92+
- `[u8; 32]` - A 32-byte array representing the keccak256 hash of the verification key.

0 commit comments

Comments
 (0)