Skip to content

Commit 5ac308d

Browse files
MarcosNicolauIAvecillaentropidelicuri-99
authored
feat: disable verifiers (#1090)
Co-authored-by: IAvecilla <[email protected]> Co-authored-by: Mariano Nicolini <[email protected]> Co-authored-by: Uriel Mihura <[email protected]>
1 parent 84fc022 commit 5ac308d

38 files changed

+1429
-1604
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ jobs:
3535
run: go build operator/cmd/main.go
3636
- name: Build aggregator
3737
run: go build aggregator/cmd/main.go
38+

.github/workflows/build-and-test-rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
cargo build --all
4848
4949
test:
50-
runs-on: ubuntu-latest
50+
runs-on: aligned-runner
5151
needs: build
5252
steps:
5353
- name: Checkout code

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ anvil_upgrade_add_aggregator:
9393
@echo "Adding Aggregator to Aligned Contracts..."
9494
. contracts/scripts/anvil/upgrade_add_aggregator_to_service_manager.sh
9595

96+
anvil_upgrade_initialize_disable_verifiers:
97+
@echo "Initializing disabled verifiers..."
98+
. contracts/scripts/anvil/upgrade_disabled_verifiers_in_service_manager.sh
99+
96100
lint_contracts:
97101
@cd contracts && npm run lint:sol
98102

@@ -230,6 +234,23 @@ operator_register_with_aligned_layer:
230234
operator_deposit_and_register: operator_deposit_into_strategy operator_register_with_aligned_layer
231235

232236

237+
# The verifier ID to enable or disable corresponds to the index of the verifier in the `ProvingSystemID` enum.
238+
verifier_enable_devnet:
239+
@echo "Enabling verifier with id: $(VERIFIER_ID)"
240+
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 RPC_URL=http://localhost:8545 OUTPUT_PATH=./script/output/devnet/alignedlayer_deployment_output.json ./contracts/scripts/enable_verifier.sh $(VERIFIER_ID)
241+
242+
verifier_disable_devnet:
243+
@echo "Disabling verifier with id: $(VERIFIER_ID)"
244+
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 RPC_URL=http://localhost:8545 OUTPUT_PATH=./script/output/devnet/alignedlayer_deployment_output.json ./contracts/scripts/disable_verifier.sh $(VERIFIER_ID)
245+
246+
verifier_enable:
247+
@echo "Enabling verifier with ID: $(VERIFIER_ID)"
248+
@. contracts/scripts/.env && . contracts/scripts/enable_verifier.sh $(VERIFIER_ID)
249+
250+
verifier_disable:
251+
@echo "Disabling verifier with ID: $(VERIFIER_ID)"
252+
@. contracts/scripts/.env && . contracts/scripts/disable_verifier.sh $(VERIFIER_ID)
253+
233254
__BATCHER__:
234255

235256
BURST_SIZE=5
@@ -455,6 +476,10 @@ upgrade_add_aggregator: ## Add Aggregator to Aligned Contracts
455476
@echo "Adding Aggregator to Aligned Contracts..."
456477
@. contracts/scripts/.env && . contracts/scripts/upgrade_add_aggregator_to_service_manager.sh
457478

479+
upgrade_initialize_disabled_verifiers:
480+
@echo "Adding disabled verifiers to Aligned Service Manager..."
481+
@. contracts/scripts/.env && . contracts/scripts/upgrade_disabled_verifiers_in_service_manager.sh
482+
458483
deploy_verify_batch_inclusion_caller:
459484
@echo "Deploying VerifyBatchInclusionCaller contract..."
460485
@. examples/verify/.env && . examples/verify/scripts/deploy_verify_batch_inclusion_caller.sh

batcher/aligned-batcher/src/config/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ impl ConfigFromYaml {
6868
pub struct Addresses {
6969
#[serde(rename = "batcherPaymentService")]
7070
pub batcher_payment_service: String,
71+
#[serde(rename = "alignedLayerServiceManager")]
72+
pub service_manager: String,
7173
}
7274

7375
#[derive(Debug, Deserialize)]
Lines changed: 4 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,5 @@
1-
use std::str::FromStr;
2-
use std::sync::Arc;
1+
pub(crate) mod payment_service;
2+
pub(crate) mod service_manager;
3+
pub mod utils;
34

4-
use aligned_sdk::eth::batcher_payment_service::BatcherPaymentServiceContract;
5-
use ethers::prelude::k256::ecdsa::SigningKey;
6-
use ethers::prelude::*;
7-
use gas_escalator::{Frequency, GeometricGasPrice};
8-
use log::info;
9-
10-
use crate::{config::ECDSAConfig, types::errors::BatcherSendError};
11-
12-
#[derive(Debug, Clone, EthEvent)]
13-
pub struct BatchVerified {
14-
pub batch_merkle_root: [u8; 32],
15-
}
16-
17-
pub type SignerMiddlewareT =
18-
SignerMiddleware<GasEscalatorMiddleware<Provider<RetryClient<Http>>>, Wallet<SigningKey>>;
19-
20-
pub type BatcherPaymentService = BatcherPaymentServiceContract<SignerMiddlewareT>;
21-
22-
const MAX_RETRIES: u32 = 15; // Max retries for the retry client. Will only retry on network errors
23-
const INITIAL_BACKOFF: u64 = 1000; // Initial backoff for the retry client in milliseconds, will increase every retry
24-
const GAS_MULTIPLIER: f64 = 1.125; // Multiplier for the gas price for gas escalator
25-
const GAS_ESCALATOR_INTERVAL: u64 = 12; // Time in seconds between gas escalations
26-
27-
#[derive(Debug, Clone)]
28-
pub struct CreateNewTaskFeeParams {
29-
pub fee_for_aggregator: U256,
30-
pub fee_per_proof: U256,
31-
pub gas_price: U256,
32-
pub respond_to_task_fee_limit: U256,
33-
}
34-
35-
impl CreateNewTaskFeeParams {
36-
pub fn new(
37-
fee_for_aggregator: U256,
38-
fee_per_proof: U256,
39-
gas_price: U256,
40-
respond_to_task_fee_limit: U256,
41-
) -> Self {
42-
CreateNewTaskFeeParams {
43-
fee_for_aggregator,
44-
fee_per_proof,
45-
gas_price,
46-
respond_to_task_fee_limit,
47-
}
48-
}
49-
}
50-
51-
pub fn get_provider(eth_rpc_url: String) -> Result<Provider<RetryClient<Http>>, anyhow::Error> {
52-
let provider = Http::from_str(eth_rpc_url.as_str())
53-
.map_err(|e| anyhow::Error::msg(format!("Failed to create provider: {}", e)))?;
54-
55-
let client = RetryClient::new(
56-
provider,
57-
Box::<ethers::providers::HttpRateLimitRetryPolicy>::default(),
58-
MAX_RETRIES,
59-
INITIAL_BACKOFF,
60-
);
61-
62-
Ok(Provider::<RetryClient<Http>>::new(client))
63-
}
64-
65-
pub async fn get_batcher_payment_service(
66-
provider: Provider<RetryClient<Http>>,
67-
ecdsa_config: ECDSAConfig,
68-
contract_address: String,
69-
) -> Result<BatcherPaymentService, anyhow::Error> {
70-
let chain_id = provider.get_chainid().await?;
71-
72-
let escalator = GeometricGasPrice::new(GAS_MULTIPLIER, GAS_ESCALATOR_INTERVAL, None::<u64>);
73-
74-
let provider = GasEscalatorMiddleware::new(provider, escalator, Frequency::PerBlock);
75-
76-
// get private key from keystore
77-
let wallet = Wallet::decrypt_keystore(
78-
&ecdsa_config.private_key_store_path,
79-
&ecdsa_config.private_key_store_password,
80-
)?
81-
.with_chain_id(chain_id.as_u64());
82-
83-
let signer = Arc::new(SignerMiddleware::new(provider, wallet));
84-
85-
let service_manager =
86-
BatcherPaymentService::new(H160::from_str(contract_address.as_str())?, signer);
87-
88-
Ok(service_manager)
89-
}
90-
91-
pub async fn try_create_new_task(
92-
batch_merkle_root: [u8; 32],
93-
batch_data_pointer: String,
94-
proofs_submitters: Vec<Address>,
95-
fee_params: CreateNewTaskFeeParams,
96-
payment_service: &BatcherPaymentService,
97-
) -> Result<TransactionReceipt, BatcherSendError> {
98-
let call = payment_service
99-
.create_new_task(
100-
batch_merkle_root,
101-
batch_data_pointer,
102-
proofs_submitters,
103-
fee_params.fee_for_aggregator,
104-
fee_params.fee_per_proof,
105-
fee_params.respond_to_task_fee_limit,
106-
)
107-
.gas_price(fee_params.gas_price);
108-
109-
info!("Creating task for: {}", hex::encode(batch_merkle_root));
110-
111-
let pending_tx = call.send().await.map_err(|err| match err {
112-
ContractError::Revert(err) => BatcherSendError::TransactionReverted(err.to_string()),
113-
_ => BatcherSendError::UnknownError(err.to_string()),
114-
})?;
115-
116-
pending_tx
117-
.await
118-
.map_err(|err| BatcherSendError::UnknownError(err.to_string()))?
119-
.ok_or(BatcherSendError::ReceiptNotFound)
120-
}
5+
pub use utils::get_provider;
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
use std::str::FromStr;
2+
use std::sync::Arc;
3+
4+
use aligned_sdk::eth::batcher_payment_service::BatcherPaymentServiceContract;
5+
use ethers::prelude::k256::ecdsa::SigningKey;
6+
use ethers::prelude::*;
7+
use gas_escalator::{Frequency, GeometricGasPrice};
8+
use log::info;
9+
10+
use crate::{config::ECDSAConfig, types::errors::BatcherSendError};
11+
12+
use super::utils::{GAS_ESCALATOR_INTERVAL, GAS_MULTIPLIER};
13+
14+
#[derive(Debug, Clone, EthEvent)]
15+
pub struct BatchVerified {
16+
pub batch_merkle_root: [u8; 32],
17+
}
18+
19+
pub type SignerMiddlewareT =
20+
SignerMiddleware<GasEscalatorMiddleware<Provider<RetryClient<Http>>>, Wallet<SigningKey>>;
21+
22+
pub type BatcherPaymentService = BatcherPaymentServiceContract<SignerMiddlewareT>;
23+
24+
#[derive(Debug, Clone)]
25+
pub struct CreateNewTaskFeeParams {
26+
pub fee_for_aggregator: U256,
27+
pub fee_per_proof: U256,
28+
pub gas_price: U256,
29+
pub respond_to_task_fee_limit: U256,
30+
}
31+
32+
impl CreateNewTaskFeeParams {
33+
pub fn new(
34+
fee_for_aggregator: U256,
35+
fee_per_proof: U256,
36+
gas_price: U256,
37+
respond_to_task_fee_limit: U256,
38+
) -> Self {
39+
CreateNewTaskFeeParams {
40+
fee_for_aggregator,
41+
fee_per_proof,
42+
gas_price,
43+
respond_to_task_fee_limit,
44+
}
45+
}
46+
}
47+
48+
pub async fn get_batcher_payment_service(
49+
provider: Provider<RetryClient<Http>>,
50+
ecdsa_config: ECDSAConfig,
51+
contract_address: String,
52+
) -> Result<BatcherPaymentService, anyhow::Error> {
53+
let chain_id = provider.get_chainid().await?;
54+
55+
let escalator = GeometricGasPrice::new(GAS_MULTIPLIER, GAS_ESCALATOR_INTERVAL, None::<u64>);
56+
57+
let provider = GasEscalatorMiddleware::new(provider, escalator, Frequency::PerBlock);
58+
59+
// get private key from keystore
60+
let wallet = Wallet::decrypt_keystore(
61+
&ecdsa_config.private_key_store_path,
62+
&ecdsa_config.private_key_store_password,
63+
)?
64+
.with_chain_id(chain_id.as_u64());
65+
66+
let signer = Arc::new(SignerMiddleware::new(provider, wallet));
67+
68+
let payment_service =
69+
BatcherPaymentService::new(H160::from_str(contract_address.as_str())?, signer);
70+
71+
Ok(payment_service)
72+
}
73+
74+
pub async fn try_create_new_task(
75+
batch_merkle_root: [u8; 32],
76+
batch_data_pointer: String,
77+
proofs_submitters: Vec<Address>,
78+
fee_params: CreateNewTaskFeeParams,
79+
payment_service: &BatcherPaymentService,
80+
) -> Result<TransactionReceipt, BatcherSendError> {
81+
let call = payment_service
82+
.create_new_task(
83+
batch_merkle_root,
84+
batch_data_pointer,
85+
proofs_submitters,
86+
fee_params.fee_for_aggregator,
87+
fee_params.fee_per_proof,
88+
fee_params.respond_to_task_fee_limit,
89+
)
90+
.gas_price(fee_params.gas_price);
91+
92+
info!("Creating task for: {}", hex::encode(batch_merkle_root));
93+
94+
let pending_tx = call.send().await.map_err(|err| match err {
95+
ContractError::Revert(err) => BatcherSendError::TransactionReverted(err.to_string()),
96+
_ => BatcherSendError::UnknownError(err.to_string()),
97+
})?;
98+
99+
pending_tx
100+
.await
101+
.map_err(|err| BatcherSendError::UnknownError(err.to_string()))?
102+
.ok_or(BatcherSendError::ReceiptNotFound)
103+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use std::{str::FromStr, sync::Arc};
2+
3+
use aligned_sdk::eth::aligned_service_manager::AlignedLayerServiceManagerContract;
4+
use ethers::{
5+
core::k256::ecdsa::SigningKey,
6+
middleware::{
7+
gas_escalator::{Frequency, GeometricGasPrice},
8+
GasEscalatorMiddleware, SignerMiddleware,
9+
},
10+
providers::{Http, Middleware, Provider, RetryClient},
11+
signers::{Signer, Wallet},
12+
types::H160,
13+
};
14+
15+
use crate::config::ECDSAConfig;
16+
17+
use super::utils::{GAS_ESCALATOR_INTERVAL, GAS_MULTIPLIER};
18+
19+
pub type SignerMiddlewareT =
20+
SignerMiddleware<GasEscalatorMiddleware<Provider<RetryClient<Http>>>, Wallet<SigningKey>>;
21+
22+
pub type ServiceManager = AlignedLayerServiceManagerContract<SignerMiddlewareT>;
23+
24+
pub async fn get_service_manager(
25+
provider: Provider<RetryClient<Http>>,
26+
ecdsa_config: ECDSAConfig,
27+
contract_address: String,
28+
) -> Result<ServiceManager, anyhow::Error> {
29+
let chain_id = provider.get_chainid().await?;
30+
31+
let escalator = GeometricGasPrice::new(GAS_MULTIPLIER, GAS_ESCALATOR_INTERVAL, None::<u64>);
32+
33+
let provider = GasEscalatorMiddleware::new(provider, escalator, Frequency::PerBlock);
34+
35+
// get private key from keystore
36+
let wallet = Wallet::decrypt_keystore(
37+
&ecdsa_config.private_key_store_path,
38+
&ecdsa_config.private_key_store_password,
39+
)?
40+
.with_chain_id(chain_id.as_u64());
41+
42+
let signer = Arc::new(SignerMiddleware::new(provider, wallet));
43+
44+
let service_manager = ServiceManager::new(H160::from_str(contract_address.as_str())?, signer);
45+
46+
Ok(service_manager)
47+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use std::str::FromStr;
2+
3+
use ethers::providers::{Http, Provider, RetryClient};
4+
5+
const MAX_RETRIES: u32 = 15; // Max retries for the retry client. Will only retry on network errors
6+
const INITIAL_BACKOFF: u64 = 1000; // Initial backoff for the retry client in milliseconds, will increase every retry
7+
pub(crate) const GAS_MULTIPLIER: f64 = 1.125; // Multiplier for the gas price for gas escalator
8+
pub(crate) const GAS_ESCALATOR_INTERVAL: u64 = 12; // Time in seconds between gas escalations
9+
10+
pub fn get_provider(eth_rpc_url: String) -> Result<Provider<RetryClient<Http>>, anyhow::Error> {
11+
let provider = Http::from_str(eth_rpc_url.as_str())
12+
.map_err(|e| anyhow::Error::msg(format!("Failed to create provider: {}", e)))?;
13+
14+
let client = RetryClient::new(
15+
provider,
16+
Box::<ethers::providers::HttpRateLimitRetryPolicy>::default(),
17+
MAX_RETRIES,
18+
INITIAL_BACKOFF,
19+
);
20+
21+
Ok(Provider::<RetryClient<Http>>::new(client))
22+
}

0 commit comments

Comments
 (0)