Skip to content

Commit 050edea

Browse files
committed
fix: sdk merge
1 parent 68e3959 commit 050edea

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

examples/L2/crates/l2/src/aligned.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use aligned_sdk::{
2-
core::types::{AlignedVerificationData, Signer, VerificationData, Wallet},
3-
sdk::{estimate_fee, get_chain_id},
2+
common::types::{AlignedVerificationData, Signer, VerificationData, Wallet},
3+
verification_layer::{estimate_fee, get_chain_id},
44
};
55
use alloy::{
66
eips::BlockNumberOrTag,
@@ -19,7 +19,9 @@ pub async fn send_proof_to_be_verified_on_aligned(
1919
vm_program_code: Vec<u8>,
2020
) -> AlignedVerificationData {
2121
let proof = bincode::serialize(proof).expect("Serialize sp1 proof to binary");
22-
let chain_id = get_chain_id(&config.eth_rpc_url).await.expect("To query chain id from rpc");
22+
let chain_id = get_chain_id(&config.eth_rpc_url)
23+
.await
24+
.expect("To query chain id from rpc");
2325
let wallet = Wallet::decrypt_keystore(
2426
&config.private_key_store_path,
2527
&config.private_key_store_password,
@@ -29,25 +31,28 @@ pub async fn send_proof_to_be_verified_on_aligned(
2931

3032
let verification_data = VerificationData {
3133
proof_generator_addr: wallet.address(),
32-
proving_system: aligned_sdk::core::types::ProvingSystemId::SP1,
34+
proving_system: aligned_sdk::common::types::ProvingSystemId::SP1,
3335
proof,
3436
vm_program_code: Some(vm_program_code),
3537
pub_input: None,
3638
verification_key: None,
3739
};
3840

39-
let nonce = aligned_sdk::sdk::get_nonce_from_batcher(config.network.clone(), wallet.address())
40-
.await
41-
.expect("Retrieve nonce from aligned batcher");
41+
let nonce = aligned_sdk::verification_layer::get_nonce_from_batcher(
42+
config.network.clone(),
43+
wallet.address(),
44+
)
45+
.await
46+
.expect("Retrieve nonce from aligned batcher");
4247

4348
let max_fee = estimate_fee(
4449
&config.eth_rpc_url,
45-
aligned_sdk::core::types::FeeEstimationType::Instant,
50+
aligned_sdk::common::types::FeeEstimationType::Instant,
4651
)
4752
.await
4853
.expect("Max fee to be retrieved");
4954

50-
aligned_sdk::sdk::submit(
55+
aligned_sdk::verification_layer::submit(
5156
config.network.clone(),
5257
&verification_data,
5358
max_fee,
@@ -79,15 +84,15 @@ pub async fn wait_until_proof_is_aggregated(
7984
let sub = provider.subscribe_logs(&filter).await.unwrap();
8085
let mut stream = sub.into_stream();
8186

82-
let verification_data = aligned_sdk::sdk::aggregation::AggregationModeVerificationData::SP1 {
87+
let verification_data = aligned_sdk::aggregation_layer::AggregationModeVerificationData::SP1 {
8388
vk: vk.hash_bytes(),
8489
public_inputs: proof.public_values.to_vec(),
8590
};
8691

8792
let mut merkle_path = vec![];
8893

8994
while stream.next().await.is_some() {
90-
if let Some(merkle_proof) = aligned_sdk::sdk::aggregation::get_merkle_path_for_proof(
95+
if let Some(merkle_proof) = aligned_sdk::aggregation_layer::get_merkle_path_for_proof(
9196
config.network.clone(),
9297
config.eth_rpc_url.clone(),
9398
config.beacon_client_url.clone(),

examples/L2/crates/l2/src/lib.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ use aligned::{send_proof_to_be_verified_on_aligned, wait_until_proof_is_aggregat
22
use db::{generate_random_transfers, DB};
33
use eth::send_state_transition_to_chain;
44
use primitive_types::U256;
5+
use prover::{prove_state_transition, PROGRAM_ELF};
56
use sp1_state_transition_program::ProgramOutput;
67
use tracing::info;
7-
use prover::{prove_state_transition, PROGRAM_ELF};
88

99
mod aligned;
1010
mod db;
1111
mod eth;
1212
mod prover;
1313

1414
pub struct Config {
15-
pub network: aligned_sdk::core::types::Network,
15+
pub network: aligned_sdk::common::types::Network,
1616
pub eth_rpc_url: String,
1717
pub ws_eth_rpc_url: String,
1818
pub beacon_client_url: String,
@@ -28,7 +28,7 @@ pub async fn start_l2(config: Config) {
2828
loop {
2929
// 1. Create random transfers
3030
let transfers = generate_random_transfers(&db, 10);
31-
31+
3232
// 2. Call zkvm and transfer to perform and verify
3333
info!("Starting prover...");
3434
let (mut proof, vk) = prove_state_transition(&db, transfers.clone());
@@ -37,7 +37,7 @@ pub async fn start_l2(config: Config) {
3737
post_state_merkle_root,
3838
} = proof.public_values.read::<ProgramOutput>();
3939
info!("Prover finish");
40-
40+
4141
// 3. If the proving went alright, update the db and verify that the merkle root matches
4242
assert!(db.commitment() == initial_state_merkle_root);
4343
// Note: we don't have to verify that the user has enough balance, as the prover already validates it
@@ -47,47 +47,47 @@ pub async fn start_l2(config: Config) {
4747
.get(&transfer.from)
4848
.expect("User must exist in state")
4949
.clone();
50-
50+
5151
let mut user_to = db
5252
.user_states
5353
.get(&transfer.to)
5454
.expect("User must exist in state")
5555
.clone();
56-
56+
5757
user_from.balance -= transfer.amount;
5858
user_from.nonce += U256::one();
5959
user_to.balance += transfer.amount;
60-
60+
6161
db.user_states.insert(transfer.from, user_from);
6262
db.user_states.insert(transfer.to, user_to);
6363
}
6464
assert!(db.commitment() == post_state_merkle_root);
65-
65+
6666
// Fow now, in order for a proof to be aggregated, we first need to submit it via the fast mode or verification layer
6767
// Let's suppose that our L2 would run the prover once every 24hs and submit it on aligned
6868
// Once aligned aggregates the proof we will be notified and we'll send the new state commitment on chain
69-
69+
7070
// 4. Send the proof to aligned and wait for verification
7171
info!("Sending proof to aligned batcher...");
7272
let _ = send_proof_to_be_verified_on_aligned(&config, &proof, PROGRAM_ELF.to_vec()).await;
7373
info!("Proof submitted");
74-
74+
7575
// 5. Wait until proof is aggregated
7676
info!("Waiting until is proof is aggregated...");
7777
let merkle_path = wait_until_proof_is_aggregated(&config, &proof, &vk).await;
7878
info!("Proof has been aggregated on aligned, about to send update to chain...");
79-
79+
8080
// 6. Send updateState transaction to Ethereum
8181
let receipt =
82-
send_state_transition_to_chain(&config, proof.public_values.to_vec(), merkle_path).await;
83-
82+
send_state_transition_to_chain(&config, proof.public_values.to_vec(), merkle_path)
83+
.await;
84+
8485
info!(
8586
"State update in contracts tx hash: {:?}",
8687
receipt.transaction_hash
8788
);
88-
89+
8990
// 7. Finally save the db to a file to be retrieved later
9091
db.save().unwrap();
9192
}
92-
9393
}

examples/L2/crates/l2/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::env;
22

3-
use aligned_sdk::core::types::Network;
3+
use aligned_sdk::common::types::Network;
44
use dotenv::dotenv;
55
use l2_example::{start_l2, Config};
66
use tracing_subscriber::FmtSubscriber;

0 commit comments

Comments
 (0)