Skip to content

Commit d2f1a26

Browse files
committed
refactor: update l2 example to use the new agg mode sdk
1 parent 747a730 commit d2f1a26

10 files changed

Lines changed: 265 additions & 1506 deletions

File tree

examples/l2/Cargo.lock

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

examples/l2/Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ __CONFIG__:
66
gen_devnet_owner_wallet:
77
rm -f ./contract-owner.keystore.json
88
cast wallet import -k . contract-owner.keystore.json --private-key 0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a --unsafe-password "<!w5Y%In94Vw"
9-
@echo "Funding on Aligned"
10-
cd ../../crates/cli/ && \
11-
cargo run --release -- deposit-to-batcher \
12-
--amount 0.01ether \
13-
--private_key 0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a \
9+
@echo "Funding on Aligned"
10+
cd ../../aggregation_mode/cli/ && \
11+
cargo run --release -- deposit \
12+
--private-key 0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a \
1413
--network devnet \
15-
--rpc_url http://localhost:8545
14+
--rpc-url http://localhost:8545
1615

1716
gen_env_l2_holesky:
1817
@cp .env.holesky .env

examples/l2/cmd/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ bincode = "1.3.3"
1212
tokio = "1.44"
1313
dotenv = "0.15"
1414
l2 = { path = "../crates/l2/" }
15-
aligned-sdk = { path = "../../../crates/sdk" }
15+
agg_mode_sdk = { path = "../../../aggregation_mode/sdk" }
1616

1717
[lib]
1818
name = "l2_cmd"

examples/l2/cmd/utils.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
use std::env;
22

3-
use aligned_sdk::common::types::Network;
3+
use agg_mode_sdk::types::Network;
44
use dotenv::dotenv;
55
use l2::config::Config;
66

77
pub fn load_config() -> Config {
88
dotenv().ok();
99

1010
let network = match env::var("NETWORK").expect("NETWORK not set").as_str() {
11-
"holesky" => Network::Holesky,
12-
"holesky-stage" => Network::HoleskyStage,
1311
"devnet" => Network::Devnet,
1412
"hoodi" => Network::Hoodi,
15-
_ => panic!("Invalid network, possible values are: holesky, holesky-stage, hoodi, devnet"),
13+
_ => panic!("Invalid network, possible values are: hoodi, devnet"),
1614
};
1715

1816
let config = Config {

examples/l2/crates/l2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
1414
rand = "0.8"
1515
sp1-sdk = "5.0.0"
1616
sp1_state_transition_program = { path = "./zkvm_programs/sp1" }
17-
aligned-sdk = { path = "../../../../crates/sdk" }
17+
agg_mode_sdk = { path = "../../../../aggregation_mode/sdk" }
1818
bincode = "1.3.3"
1919
futures-util = "0.3"
2020
tokio = "1.44"

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

Lines changed: 0 additions & 83 deletions
This file was deleted.

examples/l2/crates/l2/src/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use agg_mode_sdk::types::Network;
2+
13
pub struct Config {
2-
pub network: aligned_sdk::common::types::Network,
4+
pub network: Network,
35
pub eth_rpc_url: String,
46
pub ws_eth_rpc_url: String,
57
pub beacon_client_url: String,

examples/l2/crates/l2/src/eth.rs

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

3-
use aligned_sdk::aggregation_layer::AggregationModeProvingSystem;
3+
use agg_mode_sdk::blockchain::AggregationModeProvingSystem;
44
use alloy::{
55
network::EthereumWallet, primitives::Address, providers::ProviderBuilder,
66
rpc::types::TransactionReceipt, signers::local::LocalSigner, sol,

examples/l2/crates/l2/src/l2.rs

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,48 @@
1-
use crate::aligned::{check_proof_proof_aggregation_status, send_proof_to_be_verified_on_aligned};
21
use crate::config::Config;
32
use crate::db::{generate_random_transfers, DB};
43
use crate::eth::send_state_transition_to_chain;
54
use crate::prover::{self, prove_state_transition, PROGRAM_ELF};
5+
use agg_mode_sdk::blockchain::provider::ProofAggregationServiceProvider;
6+
use agg_mode_sdk::blockchain::{AggregationModeVerificationData, ProofStatus};
7+
use agg_mode_sdk::gateway::provider::AggregationModeGatewayProvider;
68
use alloy::hex;
9+
use alloy::signers::k256::ecdsa::SigningKey;
10+
use alloy::signers::local::LocalSigner;
711
use primitive_types::U256;
8-
use sp1_sdk::SP1ProofWithPublicValues;
12+
use sp1_sdk::{HashableKey, SP1ProofWithPublicValues};
913
use sp1_state_transition_program::ProgramOutput;
1014
use tracing::info;
1115

1216
pub struct L2 {
17+
aligned_agg_mode_gateway_provider: AggregationModeGatewayProvider<LocalSigner<SigningKey>>,
18+
aligned_proof_agg_service: ProofAggregationServiceProvider,
1319
config: Config,
1420
db: DB,
1521
}
1622

1723
impl L2 {
1824
pub fn new(config: Config) -> Self {
1925
let db_path = config.db_path.clone().unwrap_or("./db".to_string());
26+
let signer = LocalSigner::decrypt_keystore(
27+
config.private_key_store_path.clone(),
28+
config.private_key_store_password.clone(),
29+
)
30+
.expect("failed to parse private key: {e}");
31+
32+
let gatewat_provider =
33+
AggregationModeGatewayProvider::new_with_signer(config.network.clone(), signer)
34+
.expect("to build gateway provider");
35+
36+
let proof_agg_service = ProofAggregationServiceProvider::new(
37+
config.network.clone(),
38+
config.eth_rpc_url.clone(),
39+
config.beacon_client_url.clone(),
40+
);
2041

2142
Self {
2243
config,
44+
aligned_agg_mode_gateway_provider: gatewat_provider,
45+
aligned_proof_agg_service: proof_agg_service,
2346
db: DB::new(db_path),
2447
}
2548
}
@@ -32,7 +55,7 @@ impl L2 {
3255

3356
// 2. Call zkvm and transfer to perform and verify
3457
info!("Starting prover...");
35-
let (mut proof, _vk) = prove_state_transition(&self.db, transfers.clone());
58+
let (mut proof, vk) = prove_state_transition(&self.db, transfers.clone());
3659
let ProgramOutput {
3760
initial_state_merkle_root,
3861
post_state_merkle_root,
@@ -71,10 +94,13 @@ impl L2 {
7194
// Once aligned aggregates the proof we will be notified and we'll send the new state commitment on chain
7295

7396
// 4. Send the proof to aligned and wait for verification
74-
info!("Sending proof to aligned batcher...");
75-
let _ =
76-
send_proof_to_be_verified_on_aligned(&self.config, &proof, PROGRAM_ELF.to_vec()).await;
77-
info!("Proof submitted");
97+
info!("Sending proof to aligned gateway...");
98+
let res = self
99+
.aligned_agg_mode_gateway_provider
100+
.submit_sp1_proof(&proof, &vk)
101+
.await
102+
.expect("Failed to send proof to aggregation mode gateway: {e}");
103+
info!("Response from gateway: {:?}", res);
78104

79105
self.db.save().unwrap();
80106

@@ -85,9 +111,20 @@ impl L2 {
85111
let vk = prover::vk_from_elf(PROGRAM_ELF);
86112
// 5. Check if proof has been aggregated
87113
info!("Checking if proof has been aggregated in the last 24 hours...");
88-
let proof_status = check_proof_proof_aggregation_status(&self.config, &proof, &vk).await;
114+
let proof_status = self
115+
.aligned_proof_agg_service
116+
.check_proof_verification(
117+
None,
118+
AggregationModeVerificationData::SP1 {
119+
vk: vk.hash_bytes(),
120+
public_inputs: proof.public_values.to_vec(),
121+
},
122+
)
123+
.await
124+
.expect("To be able to check proof status {e}");
125+
89126
let merkle_path = match proof_status {
90-
aligned_sdk::aggregation_layer::ProofStatus::Verified {
127+
ProofStatus::Verified {
91128
merkle_root,
92129
merkle_path,
93130
} => {
@@ -97,10 +134,10 @@ impl L2 {
97134
);
98135
merkle_path
99136
}
100-
aligned_sdk::aggregation_layer::ProofStatus::Invalid => {
137+
ProofStatus::Invalid => {
101138
panic!("Proof did pass merkle root verification");
102139
}
103-
aligned_sdk::aggregation_layer::ProofStatus::NotFound => {
140+
ProofStatus::NotFound => {
104141
panic!("Proof not found in the last 24 hours logs");
105142
}
106143
};

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
mod aligned;
21
pub mod config;
32
mod db;
43
mod eth;

0 commit comments

Comments
 (0)