Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: batcher sends proof even if eip712 signature contents are incompatible #1005

Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9f50b7e
feat(wip)
uri-99 Sep 18, 2024
f39f5bc
fix: add InvalidPaymentServiceAddress to ValidityResponseMessage
uri-99 Sep 18, 2024
f4d7fbd
fix: understood issue, added comments
uri-99 Sep 18, 2024
d1aece2
refactor: remove --chain and --payment , replaced with --environment
uri-99 Sep 18, 2024
cff9c4b
feat: new error of NotAContract
uri-99 Sep 19, 2024
a0e8727
refactor: WIP task senders to use new param
uri-99 Sep 19, 2024
3909d61
refactor: change environment to network
uri-99 Sep 19, 2024
a76f39d
fix: task senders
uri-99 Sep 19, 2024
b35281b
fix: sp1 sender
uri-99 Sep 19, 2024
b4e98bb
chore: cargo clippy
uri-99 Sep 19, 2024
939e3cd
fix: wip docs
uri-99 Sep 19, 2024
5ac0862
docs: update 1.2_SDK_api_reference
uri-99 Sep 19, 2024
048c720
fix: setting max_fee
uri-99 Sep 19, 2024
f9d35d9
chore: remove prints
uri-99 Sep 19, 2024
a7b92e0
chore: removed more prints
uri-99 Sep 19, 2024
90ee57c
Merge branch 'staging' into 999-fix-batcher-sends-proof-even-if-eip71…
uri-99 Sep 24, 2024
44b3988
refactor: Copy trait on new enums to avoid usage of pointers
uri-99 Sep 24, 2024
25d8cff
fix: remove pointer on docs and extra impl in main.rs
uri-99 Sep 24, 2024
de09876
feat: InvalidPaymentServiceAddress has received and expected address …
uri-99 Sep 24, 2024
a41a854
chore: cargo fmt
uri-99 Sep 24, 2024
816798b
chore: example point sdk to latest commit
uri-99 Sep 24, 2024
a20bf76
Merge branch 'staging' into 999-fix-batcher-sends-proof-even-if-eip71…
uri-99 Sep 26, 2024
2edc257
fix: examples
uri-99 Sep 26, 2024
77e6ac6
chore: remove unused variable
uri-99 Sep 26, 2024
0e63597
fix: elf in ZKQuiz verifier contract
uri-99 Sep 26, 2024
1366aba
fix: error in comment
uri-99 Sep 30, 2024
5f896ae
remove: tests on sdk
uri-99 Sep 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ batcher/target/release/aligned:


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

batcher_send_sp1_task:
@echo "Sending SP1 fibonacci task to Batcher..."
Expand All @@ -236,7 +236,7 @@ batcher_send_sp1_task:
--vm_program ../../scripts/test_files/sp1/sp1_fibonacci.elf \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
--network $(NETWORK)

batcher_send_sp1_burst:
@echo "Sending SP1 fibonacci task to Batcher..."
Expand All @@ -247,7 +247,7 @@ batcher_send_sp1_burst:
--repetitions $(BURST_SIZE) \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
--network $(NETWORK)

batcher_send_infinite_sp1:
@echo "Sending infinite SP1 fibonacci task to Batcher..."
Expand All @@ -262,7 +262,7 @@ batcher_send_risc0_task:
--public_input ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci.pub \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
--network $(NETWORK)

batcher_send_risc0_burst:
@echo "Sending Risc0 fibonacci task to Batcher..."
Expand All @@ -274,7 +274,7 @@ batcher_send_risc0_burst:
--repetitions $(BURST_SIZE) \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
--network $(NETWORK)

batcher_send_plonk_bn254_task: batcher/target/release/aligned
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
Expand All @@ -285,7 +285,7 @@ batcher_send_plonk_bn254_task: batcher/target/release/aligned
--vk ../../scripts/test_files/gnark_plonk_bn254_script/plonk.vk \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
--network $(NETWORK)

batcher_send_plonk_bn254_burst: batcher/target/release/aligned
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
Expand All @@ -297,7 +297,7 @@ batcher_send_plonk_bn254_burst: batcher/target/release/aligned
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--rpc_url $(RPC_URL) \
--repetitions 4 \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
--network $(NETWORK)

batcher_send_plonk_bls12_381_task: batcher/target/release/aligned
@echo "Sending Groth16 BLS12-381 1!=0 task to Batcher..."
Expand All @@ -308,7 +308,7 @@ batcher_send_plonk_bls12_381_task: batcher/target/release/aligned
--vk ../../scripts/test_files/gnark_plonk_bls12_381_script/plonk.vk \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
--network $(NETWORK)

batcher_send_plonk_bls12_381_burst: batcher/target/release/aligned
@echo "Sending Groth16 BLS12-381 1!=0 task to Batcher..."
Expand All @@ -320,8 +320,7 @@ batcher_send_plonk_bls12_381_burst: batcher/target/release/aligned
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--repetitions 15 \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)

--network $(NETWORK)

batcher_send_groth16_bn254_task: batcher/target/release/aligned
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
Expand All @@ -332,7 +331,7 @@ batcher_send_groth16_bn254_task: batcher/target/release/aligned
--vk ../../scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs/ineq_1_groth16.vk \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
--network $(NETWORK)

batcher_send_infinite_groth16: batcher/target/release/aligned ## Send a different Groth16 BN254 proof using the client every 3 seconds
@mkdir -p scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs
Expand All @@ -352,7 +351,7 @@ batcher_send_halo2_ipa_task: batcher/target/release/aligned
--public_input ../../scripts/test_files/halo2_ipa/pub_input.bin \
--vk ../../scripts/test_files/halo2_ipa/params.bin \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
--network $(NETWORK)

batcher_send_halo2_ipa_task_burst_5: batcher/target/release/aligned
@echo "Sending Halo2 IPA 1!=0 task to Batcher..."
Expand All @@ -363,7 +362,7 @@ batcher_send_halo2_ipa_task_burst_5: batcher/target/release/aligned
--vk ../../scripts/test_files/halo2_ipa/params.bin \
--repetitions 5 \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
--network $(NETWORK)

batcher_send_halo2_kzg_task: batcher/target/release/aligned
@echo "Sending Halo2 KZG 1!=0 task to Batcher..."
Expand All @@ -374,7 +373,7 @@ batcher_send_halo2_kzg_task: batcher/target/release/aligned
--vk ../../scripts/test_files/halo2_kzg/params.bin \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
--network $(NETWORK)

batcher_send_halo2_kzg_task_burst_5: batcher/target/release/aligned
@echo "Sending Halo2 KZG 1!=0 task to Batcher..."
Expand All @@ -386,7 +385,7 @@ batcher_send_halo2_kzg_task_burst_5: batcher/target/release/aligned
--repetitions 5 \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
--network $(NETWORK)

__GENERATE_PROOFS__:
# TODO add a default proving system
Expand Down
18 changes: 17 additions & 1 deletion batcher/aligned-batcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl Batcher {

if client_msg.verification_data.chain_id != self.chain_id {
warn!(
"Received message with incorrect chain id: {}",
"Received message with incorrect chain id: {}", //This check does not save against "Holesky" and "HoleskyStage", since both are chain_id 17000
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any other check that can cover the difference?

Copy link
Contributor Author

@uri-99 uri-99 Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, on line 459: This checks saves against "Holesky" and "HoleskyStage", since each one has a different payment service address.
So with those 2 checks, the batcher is certain the user signed and sent the message with the expected chainId and Network

client_msg.verification_data.chain_id
);

Expand All @@ -452,13 +452,29 @@ impl Batcher {
return Ok(());
}

if client_msg.verification_data.payment_service_addr != self.payment_service.address() {
warn!(
"Received message with incorrect payment service address: {}", //This checks saves against "Holesky" and "HoleskyStage", since each one has a different payment service address
client_msg.verification_data.payment_service_addr
);

send_message(
ws_conn_sink.clone(),
ValidityResponseMessage::InvalidPaymentServiceAddress,
)
.await;

return Ok(());
}

info!("Verifying message signature...");
if let Ok(addr) = client_msg.verify_signature() {
info!("Message signature verified");
if self.is_nonpaying(&addr) {
self.handle_nonpaying_msg(ws_conn_sink.clone(), client_msg)
.await
} else {
info!("Handling paying message");
if !self
.check_user_balance_and_increment_proof_count(&addr)
.await
Expand Down
16 changes: 5 additions & 11 deletions batcher/aligned-sdk/src/communication/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
core::{
errors,
types::{
AlignedVerificationData, BatchInclusionData, Chain, VerificationCommitmentBatch,
AlignedVerificationData, BatchInclusionData, Network, VerificationCommitmentBatch,
VerificationDataCommitment,
},
},
Expand Down Expand Up @@ -43,18 +43,12 @@ pub fn handle_batch_inclusion_data(
pub async fn await_batch_verification(
aligned_verification_data: &AlignedVerificationData,
rpc_url: &str,
chain: Chain,
payment_service_addr: &str,
network: &Network,
) -> Result<(), errors::SubmitError> {
for _ in 0..RETRIES {
if is_proof_verified(
aligned_verification_data,
chain.clone(),
rpc_url,
payment_service_addr,
)
.await
.is_ok_and(|r| r)
if is_proof_verified(aligned_verification_data, network, rpc_url)
.await
.is_ok_and(|r| r)
{
return Ok(());
}
Expand Down
4 changes: 4 additions & 0 deletions batcher/aligned-sdk/src/communication/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ pub async fn send_messages(
error!("Invalid replacement message!");
return Err(SubmitError::InvalidReplacementMessage);
}
ValidityResponseMessage::InvalidPaymentServiceAddress => {
error!("Invalid payment service address!");
return Err(SubmitError::InvalidPaymentServiceAddress);
}
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
};

sent_verification_data.push(verification_data.clone());
Expand Down
13 changes: 12 additions & 1 deletion batcher/aligned-sdk/src/core/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::fmt;
use ethers::providers::ProviderError;
use ethers::signers::WalletError;
use ethers::types::transaction::eip712::Eip712Error;
use ethers::types::SignatureError;
use ethers::types::{SignatureError, H160};
use std::io;
use std::path::PathBuf;
use tokio_tungstenite::tungstenite::protocol::CloseFrame;
Expand Down Expand Up @@ -80,6 +80,7 @@ pub enum SubmitError {
ProofTooLarge,
InvalidReplacementMessage,
InsufficientBalance,
InvalidPaymentServiceAddress,
BatchSubmissionFailed(String),
GenericError(String),
}
Expand Down Expand Up @@ -114,6 +115,9 @@ impl From<VerificationError> for SubmitError {
VerificationError::HexDecodingError(e) => SubmitError::HexDecodingError(e.to_string()),
VerificationError::EthereumProviderError(e) => SubmitError::EthereumProviderError(e),
VerificationError::EthereumCallError(e) => SubmitError::EthereumProviderError(e),
VerificationError::EthereumNotAContract(address) => {
SubmitError::InvalidEthereumAddress(address.to_string())
}
}
}
}
Expand Down Expand Up @@ -178,6 +182,9 @@ impl fmt::Display for SubmitError {
SubmitError::ProofTooLarge => write!(f, "Proof too Large"),
SubmitError::InvalidReplacementMessage => write!(f, "Invalid replacement message"),
SubmitError::InsufficientBalance => write!(f, "Insufficient balance"),
SubmitError::InvalidPaymentServiceAddress => {
write!(f, "Invalid payment service address")
}
SubmitError::ProofQueueFlushed => write!(f, "Batch reset"),
}
}
Expand All @@ -188,6 +195,7 @@ pub enum VerificationError {
HexDecodingError(String),
EthereumProviderError(String),
EthereumCallError(String),
EthereumNotAContract(H160),
}

impl fmt::Display for VerificationError {
Expand All @@ -198,6 +206,9 @@ impl fmt::Display for VerificationError {
write!(f, "Ethereum provider error: {}", e)
}
VerificationError::EthereumCallError(e) => write!(f, "Ethereum call error: {}", e),
VerificationError::EthereumNotAContract(address) => {
write!(f, "Address {} does not contain a contract", address)
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion batcher/aligned-sdk/src/core/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ pub enum ValidityResponseMessage {
InvalidReplacementMessage,
ProofTooLarge,
InsufficientBalance(Address),
InvalidPaymentServiceAddress,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -324,7 +325,7 @@ pub enum ResponseMessage {
}

#[derive(Debug, Clone)]
pub enum Chain {
pub enum Network {
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
Devnet,
Holesky,
HoleskyStage,
Expand Down
16 changes: 11 additions & 5 deletions batcher/aligned-sdk/src/eth/aligned_service_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::str::FromStr;
use std::sync::Arc;

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

pub async fn aligned_service_manager(
provider: Provider<Http>,
contract_address: &str,
contract_address: H160,
) -> Result<AlignedLayerServiceManager, VerificationError> {
let client = Arc::new(provider);
let contract_addr = H160::from_str(contract_address)
.map_err(|e| VerificationError::HexDecodingError(e.to_string()))?;

Ok(AlignedLayerServiceManager::new(contract_addr, client))
// Verify that the contract has code at the given address
let code = client
.get_code(contract_address, None)
.await
.map_err(|e| VerificationError::EthereumProviderError(e.to_string()))?;
if code.is_empty() {
return Err(VerificationError::EthereumNotAContract(contract_address));
}

Ok(AlignedLayerServiceManager::new(contract_address, client))
}
16 changes: 11 additions & 5 deletions batcher/aligned-sdk/src/eth/batcher_payment_service.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::str::FromStr;
use std::sync::Arc;

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

pub async fn batcher_payment_service(
provider: Provider<Http>,
contract_address: &str,
contract_address: H160,
) -> Result<BatcherPaymentService, VerificationError> {
let client = Arc::new(provider);
let contract_addr = H160::from_str(contract_address)
.map_err(|e| VerificationError::HexDecodingError(e.to_string()))?;

Ok(BatcherPaymentService::new(contract_addr, client))
// Verify that the contract has code at the given address
let code = client
.get_code(contract_address, None)
.await
.map_err(|e| VerificationError::EthereumProviderError(e.to_string()))?;
if code.is_empty() {
return Err(VerificationError::EthereumNotAContract(contract_address));
}

Ok(BatcherPaymentService::new(contract_address, client))
}

impl SignatureData {
Expand Down
Loading
Loading