Skip to content

Commit

Permalink
2 operators support (#11)
Browse files Browse the repository at this point in the history
* update submodule to 0.2.1

* use latest sdk

* remove state dump, add eigenlayer-contracts submodule v0.4.3-mainnet-rewards-programmatic-incentives

* scripts WIP

* scripts working

* makefile update, some cilppy

* chore: update integration tests deps

* exclude incredible-binding crate in ci

* exclude incredible-binding in cargo check ci

* ignore clippy in bindings crate

* fmt

* install forge in ci

* add docker anvil in ci, comment the failing test for now

* fix:enter correct directory in ci

* port the rewards scripts and tests from hello world, use foundry-toolchain in ci

* nudge ci

* fix : payment script revert, todo: write correct reward params

* payment script working

* add payment script in make file

* cleanup

* remove eigenlayer-contracts from gitmodules

* use get_signer, fmt

* readme update

* remapping

* remove foundry toolchain ,install foundry using cargo

* fix: yml

* modify contract path in sh file, dd back toolchain for foundry

* update deploy-eigenlayer.sh

* update rev

* fix: submodule in ci, update readme

* add submodules in yml

* update middleware

* middleware update

* add forge-std

* testing ci

* update rev

* checking

* update middleware

* cd into contracts

* update .sh

* cd into contracts only once

* hit and trial

* fix: eigenlayer.sh script

* vv

* add submodule in ci

* env in ci

* 2 operators support

* clean up

* fix quorum, client

* fix:tests

* update readme

* fix:merge conflicts

* remove unwrap

* use separate config file and reuse error

* clippy

* common config for test in operators

* deploy-eigenlayer with debug comments

* print return value in deploy-eigenlayer.sh

* change foundry image to latest

* clean up

---------

Co-authored-by: supernovahs <[email protected]>
Co-authored-by: Pablo Deymonnaz <[email protected]>
  • Loading branch information
3 people authored Nov 26, 2024
1 parent 42292e4 commit c350328
Show file tree
Hide file tree
Showing 30 changed files with 1,975 additions and 861 deletions.
1,842 changes: 1,111 additions & 731 deletions Cargo.lock

Large diffs are not rendered by default.

45 changes: 22 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = ["crates/aggregator",
"crates/chainio",
"crates/testing-utils",
"crates/task_generator",
"crates/operator_2"
]

resolver = "2"
Expand Down Expand Up @@ -40,13 +41,11 @@ thiserror = "1.0.61"
ark-bn254 = { version = "0.4.0", features = ["curve"], default-features = false }
futures-util = "0.3.31"
metrics = "0.24.0"
reqwest = "0.12.5"
reqwest = "0.12.9"
serde_json = "1.0.120"
#alloy
alloy = { version = "0.4.2", features = ["full","signer-keystore","reqwest"] }
alloy-provider = { version = "0.4.2", default-features = false, features = [
"reqwest",
] }
alloy = { version = "0.5.3", features = ["full","signer-keystore","reqwest"] }
alloy-provider = "0.5.3"
serde = "1.0.203"
tracing = "0.1.40"
tempfile = "3"
Expand All @@ -67,25 +66,25 @@ incredible-challenger = {path = "crates/challenger/"}
incredible-chainio = {path = "crates/chainio/"}
incredible-testing-utils = {path = "crates/testing-utils/"}
incredible-task-generator = {path = "crates/task_generator/"}
incredible-operator-2 = {path = "crates/operator_2/" , features = ["default"]}

# eigensdk-rs
eigen-client-avsregistry = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-testing-utils ={ git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-crypto-bls = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-types = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-metrics = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-utils = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-contract-bindings = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-cli ={ git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-logging ={ git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-crypto-bn254 = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-client-elcontracts = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-services-operatorsinfo = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-services-avsregistry = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-services-blsaggregation = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-metrics-collectors-rpc-calls = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-client-eth = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}
eigen-nodeapi = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "fd283bd"}


eigen-client-avsregistry = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-testing-utils ={ git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-crypto-bls = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-types = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-metrics = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-utils = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-contract-bindings = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-cli ={ git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-logging ={ git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-crypto-bn254 = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-client-elcontracts = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-services-operatorsinfo = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-services-avsregistry = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-services-blsaggregation = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-metrics-collectors-rpc-calls = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-client-eth = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}
eigen-nodeapi = { git = "https://github.com/Layr-Labs/eigensdk-rs", rev = "7967e1c"}

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ reset_anvil:
start_docker:
$(MAKE) reset_anvil
docker run -d --name anvil -p 8545:8545 --entrypoint anvil \
ghcr.io/foundry-rs/foundry:nightly-5b7e4cb3c882b28f3c32ba580de27ce7381f415a --host 0.0.0.0
ghcr.io/foundry-rs/foundry:latest --host 0.0.0.0
sleep 2

pr:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ Basic repo demoing a simple AVS middleware with full eigenlayer integration, in
anvil
```

- Copy env vars
- git submodule and copy env
```sh
git submodule update --init --recursive
cp contracts/.env.example contracts/.env
```


- Deploy eigenlayer and avs contracts and setup payments
```sh
deploy-el-and-avs-contracts
Expand Down
143 changes: 129 additions & 14 deletions bin/incredible-squaring-avs/src/commands/avs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloy::primitives::{Address, Bytes, FixedBytes, U256};
use alloy::providers::Provider;
use alloy::signers::local::{LocalSigner, PrivateKeySigner};
use clap::value_parser;
use clap::{Args, Parser};
Expand All @@ -13,6 +14,7 @@ use eigen_testing_utils::anvil_constants::{
ANVIL_HTTP_URL,
};
use eigen_types::operator::Operator;
use eigen_utils::get_provider;
use incredible_avs::builder::{AvsBuilder, DefaultAvsLauncher, LaunchAvs};
use incredible_config::IncredibleConfig;
use incredible_testing_utils::{
Expand All @@ -26,7 +28,7 @@ use std::net::SocketAddr;
use std::process::{Command, Stdio};
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
use tracing::{debug, info};
use tracing::debug;

/// No Additional arguments
#[derive(Debug, Clone, Copy, Default, Args)]
Expand Down Expand Up @@ -68,6 +70,18 @@ pub struct AvsCommand<Ext: Args + fmt::Debug = NoArgs> {
#[arg(long, value_name = "ECDSA_KEYSTORE_PASSWORD", default_value = "test")]
ecdsa_keystore_password: String,

/// ECDSA key store path file
#[arg(
long,
value_name = "ECDSA_KEYSTORE_2_PATH",
default_value = "./crates/testing-utils/src/ecdsa_keystore_2.json"
)]
ecdsa_keystore_2_path: String,

/// ECDSA keystore path password
#[arg(long, value_name = "ECDSA_KEYSTORE_2_PASSWORD", default_value = "test")]
ecdsa_keystore_2_password: String,

/// Registry coordinator address
#[arg(long, value_name = "REGISTRY_COORDINATOR_ADDR")]
registry_coordinator_address: Option<String>,
Expand Down Expand Up @@ -104,6 +118,18 @@ pub struct AvsCommand<Ext: Args + fmt::Debug = NoArgs> {
)]
bls_keystore_password: String,

/// bls keystore path
#[arg(
long,
value_name = "BLS_KEYSTORE_2_PATH",
default_value = "./crates/testing-utils/src/bls_keystore_2.json"
)]
bls_keystore_2_path: String,

/// bls keystore password
#[arg(long, value_name = "BLS_KEYSTORE_2_PASSWORD", default_value = "test")]
bls_keystore_2_password: String,

/// Operator Id
#[arg(
long,
Expand All @@ -112,6 +138,14 @@ pub struct AvsCommand<Ext: Args + fmt::Debug = NoArgs> {
)]
operator_id: String,

/// Operator Id
#[arg(
long,
value_name = "OPERATOR_2_ID",
default_value = "0x17a0935b43b64cc3536d48621208fddb680ef8998561f0a1669a3ccda66676be"
)]
operator_2_id: String,

/// Operator State retreiver
#[arg(long, value_name = "OPERATOR_STATE_RETRIEVER_ADDRESS")]
operator_state_retriever_addr: Option<String>,
Expand All @@ -132,6 +166,14 @@ pub struct AvsCommand<Ext: Args + fmt::Debug = NoArgs> {
)]
operator_address: String,

/// Operator2 Address
#[arg(
long,
value_name = "OPERATOR_2_ADDRESS",
default_value = "0x0b065a0423f076a340f37e16e1ce22e23d66caf2"
)]
operator_2_address: String,

#[arg(long, value_name = "REGISTER_OPERATOR", default_value = "true")]
register_operator: bool,

Expand All @@ -142,6 +184,13 @@ pub struct AvsCommand<Ext: Args + fmt::Debug = NoArgs> {
)]
operator_to_avs_registration_sig_salt: String,

#[arg(
long,
value_name = "OPERATOR_TO_AVS_REGISTRATION_SIG_SALT",
default_value = "b345f720903a3ecfd59f3de456dd9d266c2ce540b05e8c909106962684d9afa3"
)]
operator_2_to_avs_registration_sig_salt: String,

#[arg(long, value_name = "SOCKET", default_value = "incredible-socket")]
socket: String,

Expand Down Expand Up @@ -178,6 +227,16 @@ pub struct AvsCommand<Ext: Args + fmt::Debug = NoArgs> {
)]
operator_pvt_key: String,

#[arg(
long,
value_name = "OPERATOR_2_PVT_KEY",
default_value = "0x9385907a38014b53604fd848bf907453f3b4f774db8ffa72b9960f06b238eb15"
)]
operator_2_pvt_key: String,

#[arg(long, value_name = "OPERATOR_2_SIG_EXPIRY")]
operator_2_sig_expiry: Option<String>,

#[arg(
long,
value_name = "NODE_API_ADDRESS",
Expand Down Expand Up @@ -280,6 +339,7 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
operator_address,
register_operator,
operator_to_avs_registration_sig_salt,
operator_2_to_avs_registration_sig_salt,
socket,
quorum_number,
sig_expiry,
Expand All @@ -291,6 +351,14 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
metrics_address,
node_api_address,
config_path,
ecdsa_keystore_2_path,
ecdsa_keystore_2_password,
bls_keystore_2_path,
bls_keystore_2_password,
operator_2_pvt_key,
operator_2_sig_expiry,
operator_2_address,
operator_2_id,
..
} = *self;
if let Some(config_path) = config_path {
Expand All @@ -317,6 +385,8 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
config.set_quorum_number(quorum_number);
config.set_operator_id(operator_id);
config.set_operator_address(operator_address);
config.set_operator_2_address(operator_2_address);
config.set_operator_2_id(operator_2_id);
}
config.set_erc20_mock_strategy_address(
erc20_mock_strategy_address.unwrap_or(erc20_mock_strategy_address_anvil.to_string()),
Expand All @@ -326,10 +396,12 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
.clone()
.unwrap_or(delegation_manager_address_anvil.to_string()),
);
config.set_operator_2_quorum_number("00".to_string());
config.set_avs_directory_address(
avs_directory_addr.unwrap_or(avs_directory_address_anvil.to_string()),
);
config.set_operator_signing_key(operator_pvt_key);
config.set_operator_2_signing_key(operator_2_pvt_key);
// use value from config , if None , then use anvil
config.set_registry_coordinator_addr(
registry_coordinator_address
Expand All @@ -348,6 +420,11 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
config.set_task_manager_address(
task_manager_addr.unwrap_or(incredible_squaring_task_manager_address_anvil.to_string()),
);

config.set_ecdsa_keystore_2_path(ecdsa_keystore_2_path.clone());
config.set_ecdsa_keystore_2_pasword(ecdsa_keystore_2_password.clone());
config
.set_operator_2_registration_sig_salt(operator_2_to_avs_registration_sig_salt.clone());
let now = SystemTime::now();
let mut expiry: U256 = U256::from(0);
if let Ok(duration_since_epoch) = now.duration_since(UNIX_EPOCH) {
Expand All @@ -360,6 +437,13 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
}
// provided expiry , if not , use default expiry : 10000 seconds
config.set_sig_expiry(sig_expiry.unwrap_or(expiry.to_string()).to_string());
config.set_bls_keystore_2_path(bls_keystore_2_path.clone());
config.set_bls_keystore_2_password(bls_keystore_2_password.clone());
config.set_operator_2_sig_expiry(
operator_2_sig_expiry
.unwrap_or(expiry.to_string())
.to_string(),
);
let socket_addr_metrics: SocketAddr = SocketAddr::from_str(&config.metrics_port_address())?;
init_registry(socket_addr_metrics);
if register_operator {
Expand All @@ -380,8 +464,47 @@ impl<Ext: clap::Args + fmt::Debug + Send + Sync + 'static> AvsCommand<Ext> {
config.sig_expiry()?,
config.quorum_number()?,
config.socket().to_string(),
U256::from(5000),
)
.await;

let _ = register_operator_with_el_and_avs(
config.operator_2_pvt_key(),
rpc_url.clone(),
ecdsa_keystore_2_path.clone(),
ecdsa_keystore_2_password.clone(),
config.registry_coordinator_addr()?,
config.operator_state_retriever_addr()?,
config.delegation_manager_addr()?,
config.avs_directory_addr()?,
config.strategy_manager_addr()?,
config.erc20_mock_strategy_addr()?,
&bls_keystore_2_path,
&bls_keystore_2_password,
config.operator_2_to_avs_registration_sig_salt()?,
config.operator_2_sig_expiry()?,
config.operator_2_quorum_number()?,
config.operator_2_socket().to_string(),
U256::from(7000),
)
.await;

let current_block_number = get_provider(&rpc_url).get_block_number().await?;

fn mine_anvil_block(rpc_url: &str, blocks: u64) {
Command::new("cast")
.args([
"rpc",
"anvil_mine",
&blocks.to_string(),
"--rpc-url",
rpc_url,
])
.stdout(Stdio::null())
.output()
.expect("Failed to execute command");
}
mine_anvil_block(&rpc_url, current_block_number);
}
let avs_launcher = DefaultAvsLauncher::new();
let avs_builder = AvsBuilder::new(config);
Expand Down Expand Up @@ -410,16 +533,15 @@ pub async fn register_operator_with_el_and_avs(
operator_to_avs_registration_sig_expiry: U256,
quorum_numbers: Bytes,
socket: String,
deposit_tokens: U256,
) -> eyre::Result<()> {
info!("start registering the operator ");
let signer;
if let Some(operator_key) = operator_pvt_key {
signer = PrivateKeySigner::from_str(&operator_key)?;
} else {
signer = LocalSigner::decrypt_keystore(ecdsa_keystore_path, ecdsa_keystore_password)?;
}
let s = signer.to_field_bytes();

let avs_registry_writer = AvsRegistryChainWriter::build_avs_registry_chain_writer(
get_logger(),
rpc_url.clone(),
Expand All @@ -430,7 +552,9 @@ pub async fn register_operator_with_el_and_avs(
.await?;

// Read BlsKey from path
let keystore = Keystore::from_file(bls_keystore_path)?.decrypt(bls_keystore_password)?;
let keystore = Keystore::from_file(bls_keystore_path)?
.decrypt(bls_keystore_password)
.unwrap();
let fr_key: String = keystore.iter().map(|&value| value as char).collect();
let key_pair = BlsKeyPair::new(fr_key)?;
let el_chain_reader = ELChainReader::new(
Expand Down Expand Up @@ -460,7 +584,7 @@ pub async fn register_operator_with_el_and_avs(
let _ = el_chain_writer
.register_as_operator(operator_details)
.await?;
deposit_into_strategy(erc20_strategy_address, U256::from(10000), el_chain_writer).await?;
deposit_into_strategy(erc20_strategy_address, deposit_tokens, el_chain_writer).await?;
let tx_hash = avs_registry_writer
.register_operator_in_quorum_with_avs_registry_coordinator(
key_pair,
Expand All @@ -475,15 +599,6 @@ pub async fn register_operator_with_el_and_avs(
tx_hash
);

fn mine_anvil_block(rpc_url: &str) {
Command::new("cast")
.args(["rpc", "anvil_mine", "120", "--rpc-url", rpc_url])
.stdout(Stdio::null())
.output()
.expect("Failed to execute command");
}
mine_anvil_block(&rpc_url);

Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/anvil/deploy-avs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ parent_path=$(
cd "$parent_path"

cd ../
forge script script/IncredibleSquaringDeployer.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --slow
forge script script/IncredibleSquaringDeployer.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

forge script script/ContractsRegistry.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --slow

Expand Down
Loading

0 comments on commit c350328

Please sign in to comment.