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

feat: disable verifiers #1090

Merged
merged 70 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
446f04e
feat: blacklist verifier functions in ServiceManager contract
MarcosNicolau Sep 25, 2024
ec2321e
test(contracts): ServiceManager
MarcosNicolau Sep 25, 2024
ed05957
chore: update bindings
MarcosNicolau Sep 25, 2024
786f4e0
Add function to get the blacklisted verifiers from service manager
IAvecilla Sep 26, 2024
0186666
Update avs reader with function to get disabled verifiers
IAvecilla Sep 26, 2024
413b7ed
Check for disabled verifiers in the operator task
IAvecilla Sep 26, 2024
8326ed3
Update mod and sum files
IAvecilla Sep 26, 2024
3cf96d5
chore(batcher): add service manager to the batcher
IAvecilla Sep 27, 2024
0eb1dba
feat(batcher): check for blacklisted verifiers in pre verification
IAvecilla Sep 27, 2024
0bc8fd1
chore: improve errors from validity response
IAvecilla Sep 27, 2024
6d71349
chore: add function to service manager abigen to get blacklist bitmap
IAvecilla Sep 27, 2024
b086ef0
chore: use uint256 for blacklist bitmap
IAvecilla Sep 27, 2024
ec34a6d
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
IAvecilla Sep 27, 2024
0d89b80
chore(contracts): update anvil state json file
IAvecilla Sep 27, 2024
3893e0f
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
IAvecilla Sep 30, 2024
11e7767
chore: add extra comments for the blacklisted verifiers bitmap
IAvecilla Sep 30, 2024
bf3d2b7
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
IAvecilla Oct 1, 2024
7ceb8eb
chore: use public variable deleting unnecessary function
IAvecilla Oct 1, 2024
88fc2e0
chore: use uint8 for verifier id
IAvecilla Oct 1, 2024
ee0d97d
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
IAvecilla Oct 1, 2024
2dbaecf
chore: make verifier id an uint8 for the events
IAvecilla Oct 2, 2024
958aa18
feature: add makefile and scripts to blacklist and whitelist verifiers
IAvecilla Oct 2, 2024
6e0f689
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
IAvecilla Oct 2, 2024
cc09567
chore: fix comments on new bash scripts
IAvecilla Oct 2, 2024
e387c6f
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
IAvecilla Oct 2, 2024
04ca5cf
ci: update runner for rust tests
IAvecilla Oct 2, 2024
35c82da
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
IAvecilla Oct 7, 2024
f92cdb7
chore: correctly display validity response on error case
IAvecilla Oct 7, 2024
d44ae01
fix: avoid bitmap casting to uint8
IAvecilla Oct 7, 2024
00f5967
fix: format rust code
IAvecilla Oct 7, 2024
469cffd
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
entropidelic Oct 8, 2024
aa9bf66
Small refactors on verify function of zk utils
entropidelic Oct 8, 2024
9b149b8
Change log
entropidelic Oct 8, 2024
4de307d
Change log
entropidelic Oct 8, 2024
de1857f
Apply clippy suggestions
entropidelic Oct 8, 2024
260152c
chore: rename blacklist and whitelist to enable and disable
IAvecilla Oct 8, 2024
efa739f
fix: update storage GAP with new bitmap
IAvecilla Oct 8, 2024
15c53a7
chore: add new line between function declarations in contract
IAvecilla Oct 8, 2024
aa382a3
chore: fix typo
IAvecilla Oct 8, 2024
e3066eb
feat: add tests for enabling and disabling verifiers
IAvecilla Oct 9, 2024
cc6b01f
ci: run build and test steps in the same job
IAvecilla Oct 9, 2024
895f5fc
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
IAvecilla Oct 9, 2024
f5bd5a6
ci: use make test instead of go
IAvecilla Oct 9, 2024
c4c7960
ci: rollback ci changes
IAvecilla Oct 9, 2024
e4ff7c4
feat: add fallback for service manager on the batcher init
IAvecilla Oct 9, 2024
6d96950
refactor: move verifier disable check to new function and add tests
IAvecilla Oct 9, 2024
dd8ff97
refactor: get bitmap for disabled verifiers to only do one time per b…
IAvecilla Oct 9, 2024
58e5ac6
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
IAvecilla Oct 9, 2024
6924fa8
chore: fix format
IAvecilla Oct 9, 2024
698378a
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
IAvecilla Oct 15, 2024
28b47ed
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
IAvecilla Oct 17, 2024
c81f39b
chore: improve error handling and message for sdk and batcher
IAvecilla Oct 17, 2024
9858afb
feat: check for disabled verifiers proof inside the batch queue
IAvecilla Oct 17, 2024
16398e0
chore: update function signature to check for disabled verifiers
IAvecilla Oct 17, 2024
fdf020a
chore: flush the queue everytime without checking for disabled verifiers
IAvecilla Oct 17, 2024
babfd40
Update operator/pkg/operator.go
uri-99 Oct 17, 2024
1ebb8aa
Update operator/pkg/utils_test.go
uri-99 Oct 17, 2024
218c25a
Update operator/pkg/utils_test.go
uri-99 Oct 17, 2024
61a7c54
Update operator/pkg/utils_test.go
uri-99 Oct 17, 2024
b85dfb2
add scope for disable_verifiers_lock
entropidelic Oct 17, 2024
985f53c
Update operator/pkg/operator.go
entropidelic Oct 17, 2024
ba233b2
chore: add comment in the cast for the disabled verifiers bitmap
IAvecilla Oct 18, 2024
8accb46
chore: upgrade solidity script to correctly initialize disabled verif…
IAvecilla Oct 18, 2024
0573db2
chore: update anvil state
IAvecilla Oct 18, 2024
1432539
chore: add makefile targets to run new upgrade scripts
IAvecilla Oct 18, 2024
62b31d1
fix: update solidity script name
IAvecilla Oct 18, 2024
58934bf
fix: anvil upgrade script
uri-99 Oct 18, 2024
67b315a
chore: better text print
uri-99 Oct 18, 2024
742563b
chore: remove unused addr
uri-99 Oct 18, 2024
9438f62
Merge branch 'staging' into 1082-add-a-bitmap-in-ethereum-to-disable-…
uri-99 Oct 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ jobs:
run: go build operator/cmd/main.go
- name: Build aggregator
run: go build aggregator/cmd/main.go

2 changes: 1 addition & 1 deletion .github/workflows/build-and-test-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
cargo build --all

test:
runs-on: ubuntu-latest
runs-on: aligned-runner
needs: build
steps:
- name: Checkout code
Expand Down
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ anvil_upgrade_add_aggregator:
@echo "Adding Aggregator to Aligned Contracts..."
. contracts/scripts/anvil/upgrade_add_aggregator_to_service_manager.sh

anvil_upgrade_initialize_disable_verifiers:
@echo "Initializing disabled verifiers..."
. contracts/scripts/anvil/upgrade_disabled_verifiers_in_service_manager.sh

lint_contracts:
@cd contracts && npm run lint:sol

Expand Down Expand Up @@ -230,6 +234,23 @@ operator_register_with_aligned_layer:
operator_deposit_and_register: operator_deposit_into_strategy operator_register_with_aligned_layer


# The verifier ID to enable or disable corresponds to the index of the verifier in the `ProvingSystemID` enum.
verifier_enable_devnet:
@echo "Enabling verifier with id: $(VERIFIER_ID)"
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 RPC_URL=http://localhost:8545 OUTPUT_PATH=./script/output/devnet/alignedlayer_deployment_output.json ./contracts/scripts/enable_verifier.sh $(VERIFIER_ID)

verifier_disable_devnet:
@echo "Disabling verifier with id: $(VERIFIER_ID)"
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 RPC_URL=http://localhost:8545 OUTPUT_PATH=./script/output/devnet/alignedlayer_deployment_output.json ./contracts/scripts/disable_verifier.sh $(VERIFIER_ID)

verifier_enable:
@echo "Enabling verifier with ID: $(VERIFIER_ID)"
@. contracts/scripts/.env && . contracts/scripts/enable_verifier.sh $(VERIFIER_ID)

verifier_disable:
@echo "Disabling verifier with ID: $(VERIFIER_ID)"
@. contracts/scripts/.env && . contracts/scripts/disable_verifier.sh $(VERIFIER_ID)

__BATCHER__:

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

upgrade_initialize_disabled_verifiers:
@echo "Adding disabled verifiers to Aligned Service Manager..."
@. contracts/scripts/.env && . contracts/scripts/upgrade_disabled_verifiers_in_service_manager.sh

deploy_verify_batch_inclusion_caller:
@echo "Deploying VerifyBatchInclusionCaller contract..."
@. examples/verify/.env && . examples/verify/scripts/deploy_verify_batch_inclusion_caller.sh
Expand Down
2 changes: 2 additions & 0 deletions batcher/aligned-batcher/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ impl ConfigFromYaml {
pub struct Addresses {
#[serde(rename = "batcherPaymentService")]
pub batcher_payment_service: String,
#[serde(rename = "alignedLayerServiceManager")]
pub service_manager: String,
}

#[derive(Debug, Deserialize)]
Expand Down
123 changes: 4 additions & 119 deletions batcher/aligned-batcher/src/eth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,120 +1,5 @@
use std::str::FromStr;
use std::sync::Arc;
pub(crate) mod payment_service;
pub(crate) mod service_manager;
pub mod utils;

use aligned_sdk::eth::batcher_payment_service::BatcherPaymentServiceContract;
use ethers::prelude::k256::ecdsa::SigningKey;
use ethers::prelude::*;
use gas_escalator::{Frequency, GeometricGasPrice};
use log::info;

use crate::{config::ECDSAConfig, types::errors::BatcherSendError};

#[derive(Debug, Clone, EthEvent)]
pub struct BatchVerified {
pub batch_merkle_root: [u8; 32],
}

pub type SignerMiddlewareT =
SignerMiddleware<GasEscalatorMiddleware<Provider<RetryClient<Http>>>, Wallet<SigningKey>>;

pub type BatcherPaymentService = BatcherPaymentServiceContract<SignerMiddlewareT>;

const MAX_RETRIES: u32 = 15; // Max retries for the retry client. Will only retry on network errors
const INITIAL_BACKOFF: u64 = 1000; // Initial backoff for the retry client in milliseconds, will increase every retry
const GAS_MULTIPLIER: f64 = 1.125; // Multiplier for the gas price for gas escalator
const GAS_ESCALATOR_INTERVAL: u64 = 12; // Time in seconds between gas escalations

#[derive(Debug, Clone)]
pub struct CreateNewTaskFeeParams {
pub fee_for_aggregator: U256,
pub fee_per_proof: U256,
pub gas_price: U256,
pub respond_to_task_fee_limit: U256,
}

impl CreateNewTaskFeeParams {
pub fn new(
fee_for_aggregator: U256,
fee_per_proof: U256,
gas_price: U256,
respond_to_task_fee_limit: U256,
) -> Self {
CreateNewTaskFeeParams {
fee_for_aggregator,
fee_per_proof,
gas_price,
respond_to_task_fee_limit,
}
}
}

pub fn get_provider(eth_rpc_url: String) -> Result<Provider<RetryClient<Http>>, anyhow::Error> {
let provider = Http::from_str(eth_rpc_url.as_str())
.map_err(|e| anyhow::Error::msg(format!("Failed to create provider: {}", e)))?;

let client = RetryClient::new(
provider,
Box::<ethers::providers::HttpRateLimitRetryPolicy>::default(),
MAX_RETRIES,
INITIAL_BACKOFF,
);

Ok(Provider::<RetryClient<Http>>::new(client))
}

pub async fn get_batcher_payment_service(
provider: Provider<RetryClient<Http>>,
ecdsa_config: ECDSAConfig,
contract_address: String,
) -> Result<BatcherPaymentService, anyhow::Error> {
let chain_id = provider.get_chainid().await?;

let escalator = GeometricGasPrice::new(GAS_MULTIPLIER, GAS_ESCALATOR_INTERVAL, None::<u64>);

let provider = GasEscalatorMiddleware::new(provider, escalator, Frequency::PerBlock);

// get private key from keystore
let wallet = Wallet::decrypt_keystore(
&ecdsa_config.private_key_store_path,
&ecdsa_config.private_key_store_password,
)?
.with_chain_id(chain_id.as_u64());

let signer = Arc::new(SignerMiddleware::new(provider, wallet));

let service_manager =
BatcherPaymentService::new(H160::from_str(contract_address.as_str())?, signer);

Ok(service_manager)
}

pub async fn try_create_new_task(
batch_merkle_root: [u8; 32],
batch_data_pointer: String,
proofs_submitters: Vec<Address>,
fee_params: CreateNewTaskFeeParams,
payment_service: &BatcherPaymentService,
) -> Result<TransactionReceipt, BatcherSendError> {
let call = payment_service
.create_new_task(
batch_merkle_root,
batch_data_pointer,
proofs_submitters,
fee_params.fee_for_aggregator,
fee_params.fee_per_proof,
fee_params.respond_to_task_fee_limit,
)
.gas_price(fee_params.gas_price);

info!("Creating task for: {}", hex::encode(batch_merkle_root));

let pending_tx = call.send().await.map_err(|err| match err {
ContractError::Revert(err) => BatcherSendError::TransactionReverted(err.to_string()),
_ => BatcherSendError::UnknownError(err.to_string()),
})?;

pending_tx
.await
.map_err(|err| BatcherSendError::UnknownError(err.to_string()))?
.ok_or(BatcherSendError::ReceiptNotFound)
}
pub use utils::get_provider;
103 changes: 103 additions & 0 deletions batcher/aligned-batcher/src/eth/payment_service.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use std::str::FromStr;
use std::sync::Arc;

use aligned_sdk::eth::batcher_payment_service::BatcherPaymentServiceContract;
use ethers::prelude::k256::ecdsa::SigningKey;
use ethers::prelude::*;
use gas_escalator::{Frequency, GeometricGasPrice};
use log::info;

use crate::{config::ECDSAConfig, types::errors::BatcherSendError};

use super::utils::{GAS_ESCALATOR_INTERVAL, GAS_MULTIPLIER};

#[derive(Debug, Clone, EthEvent)]
pub struct BatchVerified {
pub batch_merkle_root: [u8; 32],
}

pub type SignerMiddlewareT =
SignerMiddleware<GasEscalatorMiddleware<Provider<RetryClient<Http>>>, Wallet<SigningKey>>;

pub type BatcherPaymentService = BatcherPaymentServiceContract<SignerMiddlewareT>;

#[derive(Debug, Clone)]
pub struct CreateNewTaskFeeParams {
pub fee_for_aggregator: U256,
pub fee_per_proof: U256,
pub gas_price: U256,
pub respond_to_task_fee_limit: U256,
}

impl CreateNewTaskFeeParams {
pub fn new(
fee_for_aggregator: U256,
fee_per_proof: U256,
gas_price: U256,
respond_to_task_fee_limit: U256,
) -> Self {
CreateNewTaskFeeParams {
fee_for_aggregator,
fee_per_proof,
gas_price,
respond_to_task_fee_limit,
}
}
}

pub async fn get_batcher_payment_service(
provider: Provider<RetryClient<Http>>,
ecdsa_config: ECDSAConfig,
contract_address: String,
) -> Result<BatcherPaymentService, anyhow::Error> {
let chain_id = provider.get_chainid().await?;

let escalator = GeometricGasPrice::new(GAS_MULTIPLIER, GAS_ESCALATOR_INTERVAL, None::<u64>);

let provider = GasEscalatorMiddleware::new(provider, escalator, Frequency::PerBlock);

// get private key from keystore
let wallet = Wallet::decrypt_keystore(
&ecdsa_config.private_key_store_path,
&ecdsa_config.private_key_store_password,
)?
.with_chain_id(chain_id.as_u64());

let signer = Arc::new(SignerMiddleware::new(provider, wallet));

let payment_service =
BatcherPaymentService::new(H160::from_str(contract_address.as_str())?, signer);

Ok(payment_service)
}

pub async fn try_create_new_task(
batch_merkle_root: [u8; 32],
batch_data_pointer: String,
proofs_submitters: Vec<Address>,
fee_params: CreateNewTaskFeeParams,
payment_service: &BatcherPaymentService,
) -> Result<TransactionReceipt, BatcherSendError> {
let call = payment_service
.create_new_task(
batch_merkle_root,
batch_data_pointer,
proofs_submitters,
fee_params.fee_for_aggregator,
fee_params.fee_per_proof,
fee_params.respond_to_task_fee_limit,
)
.gas_price(fee_params.gas_price);

info!("Creating task for: {}", hex::encode(batch_merkle_root));

let pending_tx = call.send().await.map_err(|err| match err {
ContractError::Revert(err) => BatcherSendError::TransactionReverted(err.to_string()),
_ => BatcherSendError::UnknownError(err.to_string()),
})?;

pending_tx
.await
.map_err(|err| BatcherSendError::UnknownError(err.to_string()))?
.ok_or(BatcherSendError::ReceiptNotFound)
}
47 changes: 47 additions & 0 deletions batcher/aligned-batcher/src/eth/service_manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use std::{str::FromStr, sync::Arc};

use aligned_sdk::eth::aligned_service_manager::AlignedLayerServiceManagerContract;
use ethers::{
core::k256::ecdsa::SigningKey,
middleware::{
gas_escalator::{Frequency, GeometricGasPrice},
GasEscalatorMiddleware, SignerMiddleware,
},
providers::{Http, Middleware, Provider, RetryClient},
signers::{Signer, Wallet},
types::H160,
};

use crate::config::ECDSAConfig;

use super::utils::{GAS_ESCALATOR_INTERVAL, GAS_MULTIPLIER};

pub type SignerMiddlewareT =
SignerMiddleware<GasEscalatorMiddleware<Provider<RetryClient<Http>>>, Wallet<SigningKey>>;

pub type ServiceManager = AlignedLayerServiceManagerContract<SignerMiddlewareT>;

pub async fn get_service_manager(
provider: Provider<RetryClient<Http>>,
ecdsa_config: ECDSAConfig,
contract_address: String,
) -> Result<ServiceManager, anyhow::Error> {
let chain_id = provider.get_chainid().await?;

let escalator = GeometricGasPrice::new(GAS_MULTIPLIER, GAS_ESCALATOR_INTERVAL, None::<u64>);

let provider = GasEscalatorMiddleware::new(provider, escalator, Frequency::PerBlock);

// get private key from keystore
let wallet = Wallet::decrypt_keystore(
&ecdsa_config.private_key_store_path,
&ecdsa_config.private_key_store_password,
)?
.with_chain_id(chain_id.as_u64());

let signer = Arc::new(SignerMiddleware::new(provider, wallet));

let service_manager = ServiceManager::new(H160::from_str(contract_address.as_str())?, signer);

Ok(service_manager)
}
22 changes: 22 additions & 0 deletions batcher/aligned-batcher/src/eth/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::str::FromStr;

use ethers::providers::{Http, Provider, RetryClient};

const MAX_RETRIES: u32 = 15; // Max retries for the retry client. Will only retry on network errors
const INITIAL_BACKOFF: u64 = 1000; // Initial backoff for the retry client in milliseconds, will increase every retry
pub(crate) const GAS_MULTIPLIER: f64 = 1.125; // Multiplier for the gas price for gas escalator
pub(crate) const GAS_ESCALATOR_INTERVAL: u64 = 12; // Time in seconds between gas escalations

pub fn get_provider(eth_rpc_url: String) -> Result<Provider<RetryClient<Http>>, anyhow::Error> {
let provider = Http::from_str(eth_rpc_url.as_str())
.map_err(|e| anyhow::Error::msg(format!("Failed to create provider: {}", e)))?;

let client = RetryClient::new(
provider,
Box::<ethers::providers::HttpRateLimitRetryPolicy>::default(),
MAX_RETRIES,
INITIAL_BACKOFF,
);

Ok(Provider::<RetryClient<Http>>::new(client))
}
Loading
Loading