Skip to content

Commit

Permalink
Debugging Contracts and some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjemmmic committed Aug 10, 2024
1 parent 53a6e48 commit a55799d
Show file tree
Hide file tree
Showing 18 changed files with 133 additions and 106 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ picky-asn1-der = "0.5.0"
hyper = "1.3.1"
pin-project-lite = "0.2.14"
http-body-util = "0.1.1"
ethers = "2.0.14"

anvil = { git = "https://github.com/foundry-rs/foundry.git" }
foundry-common = { git = "https://github.com/foundry-rs/foundry.git" }
Expand Down
1 change: 0 additions & 1 deletion avs/incredible-squaring-avs/src/avs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pub mod subscriber;
pub mod writer;

use alloy_primitives::{Address, Bytes, U256};
use alloy_provider::Provider;
use alloy_rpc_types::{Log, TransactionReceipt};
use alloy_sol_types::sol;
use eigen_contracts::RegistryCoordinator;
Expand Down
4 changes: 1 addition & 3 deletions avs/incredible-squaring-avs/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::avs::{
use crate::get_task_response_digest;
use crate::rpc_client::AggregatorRpcClient;
use alloy_contract::private::Ethereum;
use alloy_primitives::{address, Address, Bytes, ChainId, FixedBytes, Signature, B256, U256};
use alloy_primitives::{Address, Bytes, ChainId, FixedBytes, Signature, B256, U256};
use alloy_provider::{Provider, RootProvider};
use alloy_rpc_types::Log;
use alloy_signer_local::PrivateKeySigner;
Expand All @@ -25,11 +25,9 @@ use eigen_utils::node_api::NodeApi;
use eigen_utils::services::operator_info::OperatorInfoServiceTrait;
use eigen_utils::types::{AvsError, OperatorInfo};
use eigen_utils::Config;
use gadget_common::subxt_signer::bip39::rand;
use k256::ecdsa::{SigningKey, VerifyingKey};
use log::error;
use prometheus::Registry;
use rand::Rng;
use std::future::Future;
use std::pin::Pin;
use std::str::FromStr;
Expand Down
2 changes: 1 addition & 1 deletion avs/tangle-avs/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl<T: Config> Operator<T> {
.as_secs()
+ 3600,
);
let register_result = avs_registry_contract_manager
let _register_result = avs_registry_contract_manager
.register_operator_in_quorum_with_avs_registry_coordinator(
&ecdsa_signing_key,
sig_salt,
Expand Down
7 changes: 7 additions & 0 deletions contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ sol!(
"./out/RegistryCoordinator.sol/RegistryCoordinator.json"
);

sol!(
#[allow(missing_docs, clippy::too_many_arguments)]
#[sol(rpc)]
IRegistryCoordinator,
"./out/IRegistryCoordinator.sol/IRegistryCoordinator.json"
);

sol!(
#[allow(missing_docs)]
#[sol(rpc)]
Expand Down
4 changes: 3 additions & 1 deletion test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ thiserror.workspace = true
tokio.workspace = true
ethabi = "18.0.0"
anvil.workspace = true
ethers.workspace = true

#tokio = { workspace = true, features = ["full"] }
alloy = { workspace = true, features = ["serde", "signers"] }
Expand All @@ -61,4 +62,5 @@ url.workspace = true
#ark-ec.workspace = true
#ark-ff.workspace = true
ark-bn254.workspace = true
sha3 = "0.10.8"
sha3 = "0.10.8"
nix = "0.28.0"
1 change: 1 addition & 0 deletions test-utils/keystore/bls
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pub_key":{"x":"0x13b15d57e069eee24b23c82947dc6cd57a7c87e965c5dc325ca1e770dd52ad01","y":"0x5d262729c016f000f161c8edef2b55061520c6786042ef93fa61cea057e5b8f"},"crypto":{"encrypted_data":"7FQ+MQN6ZIQaTK20rdiVunAGtZE3SP5fWkKn54spoled8Z4c0+xd06/Hq43Kp3YI","nonce":"qVgmzWcYA4GtWKzP","password_hash":"JHNjcnlwdCRsbj0xNyxyPTgscD0xJHdCdWtNcU5NMmZkenMxaGxwczRVOXckZVRLQUtnbHhHK2lVZlBBakZ5K0tkMXYxNDRveUl6NUUzS2hmT3kzNUNCTQ=="}}
1 change: 1 addition & 0 deletions test-utils/keystore/ecdsa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","crypto":{"Cipher":"aes-128-ctr","CipherText":"664c7c0cfe1fd5c56d8724fb2b6dab05b9586055d782a498dadce199b58dbfce","CipherParams":{"IV":"be94caa22073e77a88139e12552516d8"},"KDF":"scrypt","KDFParams":{"n":17,"r":8,"p":1,"dklen":32,"salt":"e79a8ed192e4ed4c06c7d436280a16465ee8fa6b0d4379c0776d37911c050b0c"},"MAC":"6877ae9c653c0e938ee8012eeee3371f03c3584564223a5c7113552e452ae4c3"},"id":"0e1a54e2-b697-4c66-9b04-a4e3dc733f12","version":"3"}
55 changes: 2 additions & 53 deletions test-utils/src/anvil/anvil.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
use crate::test_utils;
use ethers::core::k256::{
ecdsa::SigningKey, elliptic_curve::generic_array::GenericArray, SecretKey,
};
use ethers::{
types::{Address, Chain},
utils::secret_key_to_address,
};
use ethers::{types::Address, utils::secret_key_to_address};
use std::{
io::{BufRead, BufReader},
path::PathBuf,
process::{Child, Command},
time::{Duration, Instant},
};
// use webb::evm::ethers::core::k256::{
// ecdsa::SigningKey, elliptic_curve::generic_array::GenericArray,
// SecretKey as K256SecretKey,
// };

// use webb::evm::ethers::{
// types::{Address, Chain},
// utils::secret_key_to_address,
// };

/// How long we will wait for anvil to indicate that it is ready.
const ANVIL_STARTUP_TIMEOUT_MILLIS: u64 = 10_000;
Expand Down Expand Up @@ -94,22 +81,6 @@ impl Drop for AnvilInstance {
/// # Panics
///
/// If `spawn` is called without `anvil` being available in the user's $PATH
///
/// # Example
///
/// ```no_run
/// use eigen_utils::test_utils::anvil::Anvil;
///
/// let port = 8545u16;
/// let url = format!("http://localhost:{}", port).to_string();
///
/// let anvil = Anvil::new()
/// .port(port)
/// .mnemonic("abstract vacuum mammal awkward pudding scene penalty purchase dinner depart evoke puzzle")
/// .spawn();
///
/// drop(anvil); // this will kill the instance
/// ```
#[derive(Debug, Clone, Default)]
#[must_use = "This Builder struct does nothing unless it is `spawn`ed"]
pub struct Anvil {
Expand All @@ -127,33 +98,11 @@ pub struct Anvil {
impl Anvil {
/// Creates an empty Anvil builder.
/// The default port is 8545. The mnemonic is chosen randomly.
///
/// # Example
///
/// ```no_run
/// # use eigen_utils::test_utils::anvil::Anvil;
/// fn a() {
/// let anvil = Anvil::default().spawn();
///
/// println!("Anvil running at `{}`", anvil.endpoint());
/// }
/// ```
pub fn new() -> Self {
Self::default()
}

/// Creates an Anvil builder which will execute `anvil` at the given path.
///
/// # Example
///
/// ```no_run
/// # use eigen_utils::test_utils::anvil::Anvil;
/// fn a() {
/// let anvil = Anvil::at("~/.foundry/bin/anvil").spawn();
///
/// println!("Anvil running at `{}`", anvil.endpoint());
/// }
/// ```
pub fn at(path: impl Into<PathBuf>) -> Self {
Self::new().path(path)
}
Expand Down Expand Up @@ -253,7 +202,7 @@ impl Anvil {
let port = if let Some(port) = self.port {
port
} else {
test_utils::random_port::random_port()
crate::anvil::random_port::random_port()
};
cmd.arg("-p").arg(port.to_string());

Expand Down
6 changes: 3 additions & 3 deletions test-utils/src/anvil/local_chain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::test_utils;
use crate::test_utils::anvil::{Anvil, AnvilInstance};
use crate::anvil::anvil::{Anvil, AnvilInstance};
use crate::anvil::random_port;
use ethers::signers::Signer;
use std::sync::Arc;

Expand Down Expand Up @@ -97,7 +97,7 @@ impl LocalEvmChain {
let port = if port.is_some() {
port.unwrap()
} else {
test_utils::random_port::random_port()
random_port::random_port()
};
let mut anvil = Anvil::new()
.port(port)
Expand Down
98 changes: 78 additions & 20 deletions test-utils/src/anvil/testnet/incredible_squaring.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::encode_params;
use alloy::signers::Signer;
use alloy_primitives::{address, bytes::Bytes, Address, Keccak256, Uint, U256};
use alloy_primitives::{address, Address, Bytes, Keccak256, Uint, U256};
use alloy_provider::network::{TransactionBuilder, TxSigner};
use alloy_provider::{Provider, ProviderBuilder};
use alloy_rpc_types_eth::BlockId;
Expand Down Expand Up @@ -46,7 +46,14 @@ pub async fn run_anvil_testnet() -> ContractAddresses {
// Initialize the logger
let _ = env_logger::try_init();

let (api, mut handle) = spawn(anvil::NodeConfig::test().with_port(8545)).await;
let (api, mut handle) = spawn(
anvil::NodeConfig::test()
.with_port(8545)
.with_print_logs(true)
.disable_block_gas_limit(true)
.with_steps_tracing(true),
)
.await;
api.anvil_auto_impersonate_account(true).await.unwrap();

let _http_provider = ProviderBuilder::new()
Expand Down Expand Up @@ -319,20 +326,20 @@ pub async fn run_anvil_testnet() -> ContractAddresses {
);
let &registry_coordinator_addr = registry_coordinator.address();

let bls_apk_registry = BlsApkRegistry::new(
TransparentUpgradeableProxy::deploy(
provider.clone(),
empty_contract_addr,
incredible_squaring_proxy_admin_addr,
Bytes::from(""),
)
.await
.unwrap()
.address()
.clone(),
provider.clone(),
);
let &bls_apk_registry_addr = bls_apk_registry.address();
// let bls_apk_registry = BlsApkRegistry::new(
// TransparentUpgradeableProxy::deploy(
// provider.clone(),
// empty_contract_addr,
// incredible_squaring_proxy_admin_addr,
// Bytes::from(""),
// )
// .await
// .unwrap()
// .address()
// .clone(),
// provider.clone(),
// );
// let &bls_apk_registry_addr = bls_apk_registry.address();

let bls_apk_registry = IBlsApkRegistry::new(
TransparentUpgradeableProxy::deploy(
Expand Down Expand Up @@ -553,6 +560,28 @@ pub async fn run_anvil_testnet() -> ContractAddresses {
.unwrap();
assert!(registry_coordinator_upgrade.status());

let registry_coordinator_initialization = registry_coordinator
.initialize(
pausers[0],
pausers[0],
pausers[0],
pausers[1],
U256::from(0),
quorum_operator_set_params,
quorums_minimum_stake,
quorums_strategy_params,
)
.send()
.await
.unwrap()
.get_receipt()
.await
.unwrap();
log::info!(
"Registry Coordinator Initialization Receipt: {:?}",
registry_coordinator_initialization
);

let incredible_squaring_service_manager_implementation =
IncredibleSquaringServiceManager::deploy(
provider.clone(),
Expand Down Expand Up @@ -619,7 +648,7 @@ pub async fn run_anvil_testnet() -> ContractAddresses {
registry_coordinator_addr,
TASK_RESPONSE_WINDOW_BLOCK,
)
.from(dev_account)
// .from(dev_account)
.send()
.await
.unwrap()
Expand All @@ -634,7 +663,7 @@ pub async fn run_anvil_testnet() -> ContractAddresses {
let incredible_squaring_task_manager_upgrade = incredible_squaring_proxy_admin
.upgradeAndCall(
incredible_squaring_task_manager_addr,
incredible_squaring_service_manager_implementation_addr,
incredible_squaring_task_manager_implementation_addr,
alloy_primitives::Bytes::from(encoded_data),
)
.send()
Expand All @@ -648,6 +677,34 @@ pub async fn run_anvil_testnet() -> ContractAddresses {
incredible_squaring_task_manager_upgrade
);

let eigen_pod_manager = EigenPodManager::deploy(
provider.clone(),
empty_contract_addr,
empty_contract_addr,
strategy_manager_addr,
from,
delegation_manager_addr,
)
.await
.unwrap();
let &eigen_pod_manager_addr = eigen_pod_manager.address();

let slasher_addr = dev_account;
let delegation_manager = DelegationManager::deploy(
provider.clone(),
strategy_manager_addr,
slasher_addr,
eigen_pod_manager_addr,
)
.await
.unwrap();
let &delegation_manager_addr = delegation_manager.address();

let avs_directory = AVSDirectory::deploy(provider.clone(), delegation_manager_addr)
.await
.unwrap();
let &avs_directory_addr = avs_directory.address();

log::info!("ERC20MOCK ADDRESS: {:?}", erc20_mock_addr);
log::info!("ERC20MOCK STRATEGY ADDRESS: {:?}", erc20_mock_strategy_addr);
log::info!(
Expand Down Expand Up @@ -678,6 +735,7 @@ pub async fn run_anvil_testnet() -> ContractAddresses {
"OPERATOR STATE RETRIEVER ADDRESS: {:?}",
operator_state_retriever_addr
);
log::info!("DELEGATION MANAGER ADDRESS: {:?}", delegation_manager_addr);

// let _block = provider
// .get_block(BlockId::latest(), false.into())
Expand Down Expand Up @@ -723,8 +781,8 @@ pub async fn run_anvil_testnet() -> ContractAddresses {
// tokio::spawn(task_spawner);

ContractAddresses {
service_manager: incredible_squaring_service_manager_implementation_addr,
registry_coordinator: registry_coordinator_implementation_addr,
service_manager: incredible_squaring_service_manager_addr,
registry_coordinator: registry_coordinator_addr,
operator_state_retriever: operator_state_retriever_addr,
delegation_manager: delegation_manager_addr,
avs_directory: avs_directory_addr,
Expand Down
Loading

0 comments on commit a55799d

Please sign in to comment.