Skip to content

Commit

Permalink
use elchainwriter instead of manual
Browse files Browse the repository at this point in the history
  • Loading branch information
supernovahs committed Jan 10, 2025
1 parent 1b89d88 commit 3364840
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 58 deletions.
132 changes: 76 additions & 56 deletions bin/incredible-squaring-avs/src/commands/avs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use alloy::dyn_abi::DynSolValue;
use alloy::hex;
use alloy::primitives::aliases::U96;
use alloy::primitives::{Address, FixedBytes, U256};
use alloy::providers::Provider;
use alloy::signers::local::{LocalSigner, PrivateKeySigner};
use clap::value_parser;
use clap::{Args, Parser};
use eigen_client_avsregistry::error::AvsRegistryError;
use eigen_client_elcontracts::reader::ELChainReader;
use eigen_client_elcontracts::{error::ElContractsError, writer::ELChainWriter};
use eigen_crypto_bls::{
alloy_g1_point_to_g1_affine, convert_to_g1_point, convert_to_g2_point, BlsKeyPair,
};
use eigen_crypto_bls::BlsKeyPair;
use eigen_logging::{get_logger, init_logger, log_level::LogLevel};
use eigen_metrics::prometheus::init_registry;
use eigen_testing_utils::anvil_constants::{
Expand All @@ -21,7 +17,7 @@ use eigen_testing_utils::anvil_constants::{
};
use eigen_types::operator::Operator;
use eigen_utils::allocationmanager::AllocationManager::{self, OperatorSet};
use eigen_utils::allocationmanager::IAllocationManagerTypes::{AllocateParams, RegisterParams};
use eigen_utils::allocationmanager::IAllocationManagerTypes::AllocateParams;
use eigen_utils::registrycoordinator::RegistryCoordinator;
use eigen_utils::{get_provider, get_signer};
use incredible_avs::builder::{AvsBuilder, DefaultAvsLauncher, LaunchAvs};
Expand Down Expand Up @@ -908,56 +904,80 @@ pub async fn register_for_operator_sets(
}
let s = signer.to_field_bytes();
let pvt_key = hex::encode(s).to_string();
let allocation_manager_instance =
AllocationManager::new(allocation_manager, get_signer(&pvt_key, rpc_url));

let contract_registry_coordinator =
RegistryCoordinator::new(registry_coordinator_address, get_provider(rpc_url));

let g1_hashed_msg_to_sign = contract_registry_coordinator
.pubkeyRegistrationMessageHash(signer.address())
.call()
.await
.map_err(|_| AvsRegistryError::PubKeyRegistrationMessageHash)?
._0;

let sig = bls_key_pair
.sign_hashed_to_curve_message(alloy_g1_point_to_g1_affine(g1_hashed_msg_to_sign))
.g1_point();
let alloy_g1_point_signed_msg = convert_to_g1_point(sig.g1())?;
let g1_pub_key_bn254 = convert_to_g1_point(bls_key_pair.public_key().g1())?;
let g2_pub_key_bn254 = convert_to_g2_point(bls_key_pair.public_key_g2().g2())?;

let g2_point_x: Vec<DynSolValue> = vec![
DynSolValue::Uint(g2_pub_key_bn254.X[0], 256),
DynSolValue::Uint(g2_pub_key_bn254.X[1], 256),
];
let g2_point_y: Vec<DynSolValue> = vec![
DynSolValue::Uint(g2_pub_key_bn254.Y[0], 256),
DynSolValue::Uint(g2_pub_key_bn254.Y[1], 256),
];
let encoded_params_with_socket = DynSolValue::Tuple(vec![
DynSolValue::String(socket),
DynSolValue::Uint(alloy_g1_point_signed_msg.X, 256),
DynSolValue::Uint(alloy_g1_point_signed_msg.Y, 256),
DynSolValue::Uint(g1_pub_key_bn254.X, 256),
DynSolValue::Uint(g1_pub_key_bn254.Y, 256),
DynSolValue::FixedArray(g2_point_x),
DynSolValue::FixedArray(g2_point_y),
])
.abi_encode_params();
let register_params = RegisterParams {
avs,
operatorSetIds: vec![operator_set_id],
data: encoded_params_with_socket.into(),
};
Ok(allocation_manager_instance
.registerForOperatorSets(signer.address(), register_params)
.send()
.await?
.get_receipt()
.await?
.transaction_hash)
let el_chain_reader = ELChainReader::new(
get_logger(),
allocation_manager,
Address::ZERO,
Address::ZERO,
Address::ZERO,
Address::ZERO,
rpc_url.to_string(),
); // zero address means we don't require that address for registering to operator sets
let el_chain_writer = ELChainWriter::new(
Address::ZERO,
Address::ZERO,
Address::ZERO,
Address::ZERO,
allocation_manager,
registry_coordinator_address,
el_chain_reader,
rpc_url.to_string(),
pvt_key,
);
Ok(el_chain_writer
.register_for_operator_sets(
signer.address(),
avs,
[operator_set_id].to_vec(),
bls_key_pair,
&socket,
)
.await?)
// ALTERNATIVE WAY OF ENCODING DATA MANUALLY USINg ALLOY IF YOU DON"T WANT TO USE ELChainWriter
// let g1_hashed_msg_to_sign = contract_registry_coordinator
// .pubkeyRegistrationMessageHash(signer.address())
// .call()
// .await
// .map_err(|_| AvsRegistryError::PubKeyRegistrationMessageHash)?
// ._0;

// let sig = bls_key_pair
// .sign_hashed_to_curve_message(alloy_g1_point_to_g1_affine(g1_hashed_msg_to_sign))
// .g1_point();
// let alloy_g1_point_signed_msg = convert_to_g1_point(sig.g1())?;
// let g1_pub_key_bn254 = convert_to_g1_point(bls_key_pair.public_key().g1())?;
// let g2_pub_key_bn254 = convert_to_g2_point(bls_key_pair.public_key_g2().g2())?;

// let g2_point_x: Vec<DynSolValue> = vec![
// DynSolValue::Uint(g2_pub_key_bn254.X[0], 256),
// DynSolValue::Uint(g2_pub_key_bn254.X[1], 256),
// ];
// let g2_point_y: Vec<DynSolValue> = vec![
// DynSolValue::Uint(g2_pub_key_bn254.Y[0], 256),
// DynSolValue::Uint(g2_pub_key_bn254.Y[1], 256),
// ];
// let encoded_params_with_socket = DynSolValue::Tuple(vec![
// DynSolValue::String(socket),
// DynSolValue::Uint(alloy_g1_point_signed_msg.X, 256),
// DynSolValue::Uint(alloy_g1_point_signed_msg.Y, 256),
// DynSolValue::Uint(g1_pub_key_bn254.X, 256),
// DynSolValue::Uint(g1_pub_key_bn254.Y, 256),
// DynSolValue::FixedArray(g2_point_x),
// DynSolValue::FixedArray(g2_point_y),
// ])
// .abi_encode_params();
// let register_params = RegisterParams {
// avs,
// operatorSetIds: vec![operator_set_id],
// data: encoded_params_with_socket.into(),
// };
// Ok(allocation_manager_instance
// .registerForOperatorSets(signer.address(), register_params)
// .send()
// .await?
// .get_receipt()
// .await?
// .transaction_hash)
}

/// Deposit into strategy
Expand Down
2 changes: 1 addition & 1 deletion contracts/script/deployments/core/31337.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"lastUpdate":{"timestamp":"1736505854","block_number":"1"},"addresses":{"proxyAdmin":"0xe7f1725e7734ce288f8367e1bb143e90bb3f0512","delegation":"0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9","delegationManagerImpl":"0x322813fd9a801c5507c9de605d63cea4f2ce6c44","avsDirectory":"0xb7f8bc63bbcad18155201308c8f3540b07f84f5e","avsDirectoryImpl":"0x4a679253410272dd5232b3ff7cf5dbb88f295319","strategyManager":"0xa513e6e4b8f2a923d98304ec87f64353c4d5c853","strategyManagerImpl":"0x7a2088a1bfc9d81c55368ae168c2c02570cb814f","eigenPodManager":"0xc6e7df5e7b4f2a278906862b61205850344d4e7d","eigenPodManagerImpl":"0x67d269191c92caf3cd7723f116c85e6e9bf55933","strategyFactory":"0x68b1d87f95878fe05b998f19b66f4baba5de1aed","rewardsCoordinator":"0x0dcd1bf9a1b36ce34237eeafef220932846bcd82","pauserRegistry":"0x959922be3caee4b8cd9a407cc3ac1c251c2007b1","strategyBeacon":"0xa82ff9afd8f496c3d6ac40e2a0f282e47488cfc9","allocationManager":"0x8a791620dd6260079bf849dc5567adc3f2fdc318","permissionController":"0x4ed7c70f96b99c776995fb64377f0d4ab3b0e1c1"}}
{"lastUpdate":{"timestamp":"1736518407","block_number":"1"},"addresses":{"proxyAdmin":"0xe7f1725e7734ce288f8367e1bb143e90bb3f0512","delegation":"0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9","delegationManagerImpl":"0x322813fd9a801c5507c9de605d63cea4f2ce6c44","avsDirectory":"0xb7f8bc63bbcad18155201308c8f3540b07f84f5e","avsDirectoryImpl":"0x4a679253410272dd5232b3ff7cf5dbb88f295319","strategyManager":"0xa513e6e4b8f2a923d98304ec87f64353c4d5c853","strategyManagerImpl":"0x7a2088a1bfc9d81c55368ae168c2c02570cb814f","eigenPodManager":"0xc6e7df5e7b4f2a278906862b61205850344d4e7d","eigenPodManagerImpl":"0x67d269191c92caf3cd7723f116c85e6e9bf55933","strategyFactory":"0x68b1d87f95878fe05b998f19b66f4baba5de1aed","rewardsCoordinator":"0x0dcd1bf9a1b36ce34237eeafef220932846bcd82","pauserRegistry":"0x959922be3caee4b8cd9a407cc3ac1c251c2007b1","strategyBeacon":"0xa82ff9afd8f496c3d6ac40e2a0f282e47488cfc9","allocationManager":"0x8a791620dd6260079bf849dc5567adc3f2fdc318","permissionController":"0x4ed7c70f96b99c776995fb64377f0d4ab3b0e1c1"}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"lastUpdate":{"timestamp":"1736505897","block_number":"44"},"addresses":{"proxyAdmin":"0x1291be112d480055dafd8a610b7d1e203891c274","IncredibleSquaringServiceManager":"0xb7278a61aa25c888815afc32ad3cc52ff24fe575","incredibleSquaringServiceManagerImpl":"0x202cce504e04bed6fc0521238ddf04bc9e8e15ab","IncredibleSquaringTaskManager":"0x7969c5ed335650692bc04293b07f5bf2e7a673c0","registryCoordinator":"0xc351628eb244ec633d5f21fbd6621e1a683b1181","blsapkRegistry":"0xcbeaf3bde82155f56486fb5a1072cb8baaf547cc","indexRegistry":"0xb0d4afd8879ed9f52b28595d31b441d079b2ca07","stakeRegistry":"0x82e01223d51eb87e16a03e24687edf0f294da6f1","operatorStateRetriever":"0xdbc43ba45381e02825b14322cddd15ec4b3164e6","strategy":"0x5e3d0fde6f793b3115a9e7f5ebc195bbeed35d6c","pauserRegistry":"0x0000000000000000000000000000000000000000","token":"0x0000000000000000000000000000000000000000","instantSlasher":"0x1fa02b2d6a771842690194cf62d91bdd92bfe28d"}}
{"lastUpdate":{"timestamp":"1736518450","block_number":"44"},"addresses":{"proxyAdmin":"0x1291be112d480055dafd8a610b7d1e203891c274","IncredibleSquaringServiceManager":"0xb7278a61aa25c888815afc32ad3cc52ff24fe575","incredibleSquaringServiceManagerImpl":"0x202cce504e04bed6fc0521238ddf04bc9e8e15ab","IncredibleSquaringTaskManager":"0x7969c5ed335650692bc04293b07f5bf2e7a673c0","registryCoordinator":"0xc351628eb244ec633d5f21fbd6621e1a683b1181","blsapkRegistry":"0xcbeaf3bde82155f56486fb5a1072cb8baaf547cc","indexRegistry":"0xb0d4afd8879ed9f52b28595d31b441d079b2ca07","stakeRegistry":"0x82e01223d51eb87e16a03e24687edf0f294da6f1","operatorStateRetriever":"0xdbc43ba45381e02825b14322cddd15ec4b3164e6","strategy":"0x5e3d0fde6f793b3115a9e7f5ebc195bbeed35d6c","pauserRegistry":"0x0000000000000000000000000000000000000000","token":"0x0000000000000000000000000000000000000000","instantSlasher":"0x1fa02b2d6a771842690194cf62d91bdd92bfe28d"}}

0 comments on commit 3364840

Please sign in to comment.