Skip to content

Commit 2978bbc

Browse files
committed
Merge branch 'staging' into 480-chore-implement-pausable-in-servicemanager
2 parents c52f567 + 014bd4d commit 2978bbc

File tree

29 files changed

+380
-254
lines changed

29 files changed

+380
-254
lines changed

Makefile

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ batcher/target/release/aligned:
252252

253253

254254
RPC_URL=http://localhost:8545
255-
BATCHER_PAYMENTS_CONTRACT_ADDRESS=0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650
255+
NETWORK=devnet # devnet | holesky-stage | holesky
256256

257257
batcher_send_sp1_task:
258258
@echo "Sending SP1 fibonacci task to Batcher..."
@@ -262,7 +262,7 @@ batcher_send_sp1_task:
262262
--vm_program ../../scripts/test_files/sp1/sp1_fibonacci.elf \
263263
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
264264
--rpc_url $(RPC_URL) \
265-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
265+
--network $(NETWORK)
266266

267267
batcher_send_sp1_burst:
268268
@echo "Sending SP1 fibonacci task to Batcher..."
@@ -273,7 +273,7 @@ batcher_send_sp1_burst:
273273
--repetitions $(BURST_SIZE) \
274274
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
275275
--rpc_url $(RPC_URL) \
276-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
276+
--network $(NETWORK)
277277

278278
batcher_send_infinite_sp1:
279279
@echo "Sending infinite SP1 fibonacci task to Batcher..."
@@ -288,7 +288,7 @@ batcher_send_risc0_task:
288288
--public_input ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci.pub \
289289
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
290290
--rpc_url $(RPC_URL) \
291-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
291+
--network $(NETWORK)
292292

293293
batcher_send_risc0_burst:
294294
@echo "Sending Risc0 fibonacci task to Batcher..."
@@ -300,7 +300,7 @@ batcher_send_risc0_burst:
300300
--repetitions $(BURST_SIZE) \
301301
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
302302
--rpc_url $(RPC_URL) \
303-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
303+
--network $(NETWORK)
304304

305305
batcher_send_plonk_bn254_task: batcher/target/release/aligned
306306
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
@@ -311,7 +311,7 @@ batcher_send_plonk_bn254_task: batcher/target/release/aligned
311311
--vk ../../scripts/test_files/gnark_plonk_bn254_script/plonk.vk \
312312
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
313313
--rpc_url $(RPC_URL) \
314-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
314+
--network $(NETWORK)
315315

316316
batcher_send_plonk_bn254_burst: batcher/target/release/aligned
317317
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
@@ -323,7 +323,7 @@ batcher_send_plonk_bn254_burst: batcher/target/release/aligned
323323
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
324324
--rpc_url $(RPC_URL) \
325325
--repetitions 4 \
326-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
326+
--network $(NETWORK)
327327

328328
batcher_send_plonk_bls12_381_task: batcher/target/release/aligned
329329
@echo "Sending Groth16 BLS12-381 1!=0 task to Batcher..."
@@ -334,7 +334,7 @@ batcher_send_plonk_bls12_381_task: batcher/target/release/aligned
334334
--vk ../../scripts/test_files/gnark_plonk_bls12_381_script/plonk.vk \
335335
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
336336
--rpc_url $(RPC_URL) \
337-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
337+
--network $(NETWORK)
338338

339339
batcher_send_plonk_bls12_381_burst: batcher/target/release/aligned
340340
@echo "Sending Groth16 BLS12-381 1!=0 task to Batcher..."
@@ -346,8 +346,7 @@ batcher_send_plonk_bls12_381_burst: batcher/target/release/aligned
346346
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
347347
--repetitions 15 \
348348
--rpc_url $(RPC_URL) \
349-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
350-
349+
--network $(NETWORK)
351350

352351
batcher_send_groth16_bn254_task: batcher/target/release/aligned
353352
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
@@ -358,7 +357,7 @@ batcher_send_groth16_bn254_task: batcher/target/release/aligned
358357
--vk ../../scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs/ineq_1_groth16.vk \
359358
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
360359
--rpc_url $(RPC_URL) \
361-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
360+
--network $(NETWORK)
362361

363362
batcher_send_infinite_groth16: batcher/target/release/aligned ## Send a different Groth16 BN254 proof using the client every 3 seconds
364363
@mkdir -p scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs
@@ -378,7 +377,7 @@ batcher_send_halo2_ipa_task: batcher/target/release/aligned
378377
--public_input ../../scripts/test_files/halo2_ipa/pub_input.bin \
379378
--vk ../../scripts/test_files/halo2_ipa/params.bin \
380379
--rpc_url $(RPC_URL) \
381-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
380+
--network $(NETWORK)
382381

383382
batcher_send_halo2_ipa_task_burst_5: batcher/target/release/aligned
384383
@echo "Sending Halo2 IPA 1!=0 task to Batcher..."
@@ -389,7 +388,7 @@ batcher_send_halo2_ipa_task_burst_5: batcher/target/release/aligned
389388
--vk ../../scripts/test_files/halo2_ipa/params.bin \
390389
--repetitions 5 \
391390
--rpc_url $(RPC_URL) \
392-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
391+
--network $(NETWORK)
393392

394393
batcher_send_halo2_kzg_task: batcher/target/release/aligned
395394
@echo "Sending Halo2 KZG 1!=0 task to Batcher..."
@@ -400,7 +399,7 @@ batcher_send_halo2_kzg_task: batcher/target/release/aligned
400399
--vk ../../scripts/test_files/halo2_kzg/params.bin \
401400
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
402401
--rpc_url $(RPC_URL) \
403-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
402+
--network $(NETWORK)
404403

405404
batcher_send_halo2_kzg_task_burst_5: batcher/target/release/aligned
406405
@echo "Sending Halo2 KZG 1!=0 task to Batcher..."
@@ -412,7 +411,7 @@ batcher_send_halo2_kzg_task_burst_5: batcher/target/release/aligned
412411
--repetitions 5 \
413412
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
414413
--rpc_url $(RPC_URL) \
415-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
414+
--network $(NETWORK)
416415

417416
__GENERATE_PROOFS__:
418417
# TODO add a default proving system
@@ -501,9 +500,9 @@ build_aligned_contracts:
501500

502501
show_aligned_error_codes:
503502
@echo "\nAlignedLayerServiceManager errors:"
504-
@cd contracts/src/core && forge inspect IAlignedLayerServiceManager.sol:IAlignedLayerServiceManager errors
503+
@cd contracts && forge inspect src/core/IAlignedLayerServiceManager.sol:IAlignedLayerServiceManager errors
505504
@echo "\nBatcherPaymentService errors:"
506-
@cd contracts/src/core && forge inspect BatcherPaymentService.sol:BatcherPaymentService errors
505+
@cd contracts && forge inspect src/core/BatcherPaymentService.sol:BatcherPaymentService errors
507506

508507
__BUILD__:
509508
build_binaries:

batcher/aligned-batcher/src/lib.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ impl Batcher {
441441

442442
if client_msg.verification_data.chain_id != self.chain_id {
443443
warn!(
444-
"Received message with incorrect chain id: {}",
444+
"Received message with incorrect chain id: {}", //This check does not save against "Holesky" and "HoleskyStage", since both are chain_id 17000
445445
client_msg.verification_data.chain_id
446446
);
447447

@@ -454,13 +454,32 @@ impl Batcher {
454454
return Ok(());
455455
}
456456

457+
if client_msg.verification_data.payment_service_addr != self.payment_service.address() {
458+
warn!(
459+
"Received message with incorrect payment service address: {}", //This checks saves against "Holesky" and "HoleskyStage", since each one has a different payment service address
460+
client_msg.verification_data.payment_service_addr
461+
);
462+
463+
send_message(
464+
ws_conn_sink.clone(),
465+
ValidityResponseMessage::InvalidPaymentServiceAddress(
466+
client_msg.verification_data.payment_service_addr,
467+
self.payment_service.address(),
468+
),
469+
)
470+
.await;
471+
472+
return Ok(());
473+
}
474+
457475
info!("Verifying message signature...");
458476
if let Ok(addr) = client_msg.verify_signature() {
459477
info!("Message signature verified");
460478
if self.is_nonpaying(&addr) {
461479
self.handle_nonpaying_msg(ws_conn_sink.clone(), client_msg)
462480
.await
463481
} else {
482+
info!("Handling paying message");
464483
if !self
465484
.check_user_balance_and_increment_proof_count(&addr)
466485
.await

batcher/aligned-sdk/src/communication/batch.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
core::{
55
errors,
66
types::{
7-
AlignedVerificationData, BatchInclusionData, Chain, VerificationCommitmentBatch,
7+
AlignedVerificationData, BatchInclusionData, Network, VerificationCommitmentBatch,
88
VerificationDataCommitment,
99
},
1010
},
@@ -43,18 +43,12 @@ pub fn handle_batch_inclusion_data(
4343
pub async fn await_batch_verification(
4444
aligned_verification_data: &AlignedVerificationData,
4545
rpc_url: &str,
46-
chain: Chain,
47-
payment_service_addr: &str,
46+
network: Network,
4847
) -> Result<(), errors::SubmitError> {
4948
for _ in 0..RETRIES {
50-
if is_proof_verified(
51-
aligned_verification_data,
52-
chain.clone(),
53-
rpc_url,
54-
payment_service_addr,
55-
)
56-
.await
57-
.is_ok_and(|r| r)
49+
if is_proof_verified(aligned_verification_data, network, rpc_url)
50+
.await
51+
.is_ok_and(|r| r)
5852
{
5953
return Ok(());
6054
}

batcher/aligned-sdk/src/communication/messaging.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ pub async fn send_messages(
114114
error!("Invalid replacement message!");
115115
return Err(SubmitError::InvalidReplacementMessage);
116116
}
117+
ValidityResponseMessage::InvalidPaymentServiceAddress(received_addr, expected_addr) => {
118+
error!(
119+
"Invalid payment service address, received: {}, expected: {}",
120+
received_addr, expected_addr
121+
);
122+
return Err(SubmitError::InvalidPaymentServiceAddress(
123+
received_addr,
124+
expected_addr,
125+
));
126+
}
117127
};
118128

119129
sent_verification_data.push(verification_data.clone());

batcher/aligned-sdk/src/core/errors.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::fmt;
22
use ethers::providers::ProviderError;
33
use ethers::signers::WalletError;
44
use ethers::types::transaction::eip712::Eip712Error;
5-
use ethers::types::SignatureError;
5+
use ethers::types::{SignatureError, H160};
66
use std::io;
77
use std::path::PathBuf;
88
use tokio_tungstenite::tungstenite::protocol::CloseFrame;
@@ -80,6 +80,7 @@ pub enum SubmitError {
8080
ProofTooLarge,
8181
InvalidReplacementMessage,
8282
InsufficientBalance,
83+
InvalidPaymentServiceAddress(H160, H160),
8384
BatchSubmissionFailed(String),
8485
GenericError(String),
8586
}
@@ -114,6 +115,9 @@ impl From<VerificationError> for SubmitError {
114115
VerificationError::HexDecodingError(e) => SubmitError::HexDecodingError(e.to_string()),
115116
VerificationError::EthereumProviderError(e) => SubmitError::EthereumProviderError(e),
116117
VerificationError::EthereumCallError(e) => SubmitError::EthereumProviderError(e),
118+
VerificationError::EthereumNotAContract(address) => {
119+
SubmitError::InvalidEthereumAddress(address.to_string())
120+
}
117121
}
118122
}
119123
}
@@ -178,6 +182,13 @@ impl fmt::Display for SubmitError {
178182
SubmitError::ProofTooLarge => write!(f, "Proof too Large"),
179183
SubmitError::InvalidReplacementMessage => write!(f, "Invalid replacement message"),
180184
SubmitError::InsufficientBalance => write!(f, "Insufficient balance"),
185+
SubmitError::InvalidPaymentServiceAddress(received_addr, expected_addr) => {
186+
write!(
187+
f,
188+
"Invalid payment service address, received: {}, expected: {}",
189+
received_addr, expected_addr
190+
)
191+
}
181192
SubmitError::ProofQueueFlushed => write!(f, "Batch reset"),
182193
}
183194
}
@@ -188,6 +199,7 @@ pub enum VerificationError {
188199
HexDecodingError(String),
189200
EthereumProviderError(String),
190201
EthereumCallError(String),
202+
EthereumNotAContract(H160),
191203
}
192204

193205
impl fmt::Display for VerificationError {
@@ -198,6 +210,9 @@ impl fmt::Display for VerificationError {
198210
write!(f, "Ethereum provider error: {}", e)
199211
}
200212
VerificationError::EthereumCallError(e) => write!(f, "Ethereum call error: {}", e),
213+
VerificationError::EthereumNotAContract(address) => {
214+
write!(f, "Address {} does not contain a contract", address)
215+
}
201216
}
202217
}
203218
}

batcher/aligned-sdk/src/core/types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ pub enum ValidityResponseMessage {
317317
InvalidReplacementMessage,
318318
ProofTooLarge,
319319
InsufficientBalance(Address),
320+
InvalidPaymentServiceAddress(Address, Address),
320321
}
321322

322323
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -328,8 +329,8 @@ pub enum ResponseMessage {
328329
Error(String),
329330
}
330331

331-
#[derive(Debug, Clone)]
332-
pub enum Chain {
332+
#[derive(Debug, Clone, Copy)]
333+
pub enum Network {
333334
Devnet,
334335
Holesky,
335336
HoleskyStage,

batcher/aligned-sdk/src/eth/aligned_service_manager.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::str::FromStr;
21
use std::sync::Arc;
32

43
use ethers::prelude::*;
@@ -18,11 +17,18 @@ type AlignedLayerServiceManager = AlignedLayerServiceManagerContract<Provider<Ht
1817

1918
pub async fn aligned_service_manager(
2019
provider: Provider<Http>,
21-
contract_address: &str,
20+
contract_address: H160,
2221
) -> Result<AlignedLayerServiceManager, VerificationError> {
2322
let client = Arc::new(provider);
24-
let contract_addr = H160::from_str(contract_address)
25-
.map_err(|e| VerificationError::HexDecodingError(e.to_string()))?;
2623

27-
Ok(AlignedLayerServiceManager::new(contract_addr, client))
24+
// Verify that the contract has code at the given address
25+
let code = client
26+
.get_code(contract_address, None)
27+
.await
28+
.map_err(|e| VerificationError::EthereumProviderError(e.to_string()))?;
29+
if code.is_empty() {
30+
return Err(VerificationError::EthereumNotAContract(contract_address));
31+
}
32+
33+
Ok(AlignedLayerServiceManager::new(contract_address, client))
2834
}

batcher/aligned-sdk/src/eth/batcher_payment_service.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::str::FromStr;
21
use std::sync::Arc;
32

43
use ethers::prelude::*;
@@ -14,13 +13,20 @@ pub type BatcherPaymentService = BatcherPaymentServiceContract<Provider<Http>>;
1413

1514
pub async fn batcher_payment_service(
1615
provider: Provider<Http>,
17-
contract_address: &str,
16+
contract_address: H160,
1817
) -> Result<BatcherPaymentService, VerificationError> {
1918
let client = Arc::new(provider);
20-
let contract_addr = H160::from_str(contract_address)
21-
.map_err(|e| VerificationError::HexDecodingError(e.to_string()))?;
2219

23-
Ok(BatcherPaymentService::new(contract_addr, client))
20+
// Verify that the contract has code at the given address
21+
let code = client
22+
.get_code(contract_address, None)
23+
.await
24+
.map_err(|e| VerificationError::EthereumProviderError(e.to_string()))?;
25+
if code.is_empty() {
26+
return Err(VerificationError::EthereumNotAContract(contract_address));
27+
}
28+
29+
Ok(BatcherPaymentService::new(contract_address, client))
2430
}
2531

2632
impl SignatureData {

0 commit comments

Comments
 (0)