Skip to content

Commit 88f276c

Browse files
authored
fix: batcher sends proof even if eip712 signature contents are incompatible (#1005)
1 parent 39fe8a7 commit 88f276c

File tree

24 files changed

+342
-248
lines changed

24 files changed

+342
-248
lines changed

Makefile

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ batcher/target/release/aligned:
232232

233233

234234
RPC_URL=http://localhost:8545
235-
BATCHER_PAYMENTS_CONTRACT_ADDRESS=0x7969c5eD335650692Bc04293B07F5BF2e7A673C0
235+
NETWORK=devnet # devnet | holesky-stage | holesky
236236

237237
batcher_send_sp1_task:
238238
@echo "Sending SP1 fibonacci task to Batcher..."
@@ -242,7 +242,7 @@ batcher_send_sp1_task:
242242
--vm_program ../../scripts/test_files/sp1/sp1_fibonacci.elf \
243243
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
244244
--rpc_url $(RPC_URL) \
245-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
245+
--network $(NETWORK)
246246

247247
batcher_send_sp1_burst:
248248
@echo "Sending SP1 fibonacci task to Batcher..."
@@ -253,7 +253,7 @@ batcher_send_sp1_burst:
253253
--repetitions $(BURST_SIZE) \
254254
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
255255
--rpc_url $(RPC_URL) \
256-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
256+
--network $(NETWORK)
257257

258258
batcher_send_infinite_sp1:
259259
@echo "Sending infinite SP1 fibonacci task to Batcher..."
@@ -268,7 +268,7 @@ batcher_send_risc0_task:
268268
--public_input ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci.pub \
269269
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
270270
--rpc_url $(RPC_URL) \
271-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
271+
--network $(NETWORK)
272272

273273
batcher_send_risc0_burst:
274274
@echo "Sending Risc0 fibonacci task to Batcher..."
@@ -280,7 +280,7 @@ batcher_send_risc0_burst:
280280
--repetitions $(BURST_SIZE) \
281281
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
282282
--rpc_url $(RPC_URL) \
283-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
283+
--network $(NETWORK)
284284

285285
batcher_send_plonk_bn254_task: batcher/target/release/aligned
286286
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
@@ -291,7 +291,7 @@ batcher_send_plonk_bn254_task: batcher/target/release/aligned
291291
--vk ../../scripts/test_files/gnark_plonk_bn254_script/plonk.vk \
292292
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
293293
--rpc_url $(RPC_URL) \
294-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
294+
--network $(NETWORK)
295295

296296
batcher_send_plonk_bn254_burst: batcher/target/release/aligned
297297
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
@@ -303,7 +303,7 @@ batcher_send_plonk_bn254_burst: batcher/target/release/aligned
303303
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
304304
--rpc_url $(RPC_URL) \
305305
--repetitions 4 \
306-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
306+
--network $(NETWORK)
307307

308308
batcher_send_plonk_bls12_381_task: batcher/target/release/aligned
309309
@echo "Sending Groth16 BLS12-381 1!=0 task to Batcher..."
@@ -314,7 +314,7 @@ batcher_send_plonk_bls12_381_task: batcher/target/release/aligned
314314
--vk ../../scripts/test_files/gnark_plonk_bls12_381_script/plonk.vk \
315315
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
316316
--rpc_url $(RPC_URL) \
317-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
317+
--network $(NETWORK)
318318

319319
batcher_send_plonk_bls12_381_burst: batcher/target/release/aligned
320320
@echo "Sending Groth16 BLS12-381 1!=0 task to Batcher..."
@@ -326,8 +326,7 @@ batcher_send_plonk_bls12_381_burst: batcher/target/release/aligned
326326
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
327327
--repetitions 15 \
328328
--rpc_url $(RPC_URL) \
329-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
330-
329+
--network $(NETWORK)
331330

332331
batcher_send_groth16_bn254_task: batcher/target/release/aligned
333332
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
@@ -338,7 +337,7 @@ batcher_send_groth16_bn254_task: batcher/target/release/aligned
338337
--vk ../../scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs/ineq_1_groth16.vk \
339338
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
340339
--rpc_url $(RPC_URL) \
341-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
340+
--network $(NETWORK)
342341

343342
batcher_send_infinite_groth16: batcher/target/release/aligned ## Send a different Groth16 BN254 proof using the client every 3 seconds
344343
@mkdir -p scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs
@@ -358,7 +357,7 @@ batcher_send_halo2_ipa_task: batcher/target/release/aligned
358357
--public_input ../../scripts/test_files/halo2_ipa/pub_input.bin \
359358
--vk ../../scripts/test_files/halo2_ipa/params.bin \
360359
--rpc_url $(RPC_URL) \
361-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
360+
--network $(NETWORK)
362361

363362
batcher_send_halo2_ipa_task_burst_5: batcher/target/release/aligned
364363
@echo "Sending Halo2 IPA 1!=0 task to Batcher..."
@@ -369,7 +368,7 @@ batcher_send_halo2_ipa_task_burst_5: batcher/target/release/aligned
369368
--vk ../../scripts/test_files/halo2_ipa/params.bin \
370369
--repetitions 5 \
371370
--rpc_url $(RPC_URL) \
372-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
371+
--network $(NETWORK)
373372

374373
batcher_send_halo2_kzg_task: batcher/target/release/aligned
375374
@echo "Sending Halo2 KZG 1!=0 task to Batcher..."
@@ -380,7 +379,7 @@ batcher_send_halo2_kzg_task: batcher/target/release/aligned
380379
--vk ../../scripts/test_files/halo2_kzg/params.bin \
381380
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
382381
--rpc_url $(RPC_URL) \
383-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
382+
--network $(NETWORK)
384383

385384
batcher_send_halo2_kzg_task_burst_5: batcher/target/release/aligned
386385
@echo "Sending Halo2 KZG 1!=0 task to Batcher..."
@@ -392,7 +391,7 @@ batcher_send_halo2_kzg_task_burst_5: batcher/target/release/aligned
392391
--repetitions 5 \
393392
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
394393
--rpc_url $(RPC_URL) \
395-
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
394+
--network $(NETWORK)
396395

397396
__GENERATE_PROOFS__:
398397
# TODO add a default proving system

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)