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

testing, cleanups ,docs #12

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions crates/chainio/clients/avsregistry/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! AvsRegistry methods for reading, writing and subscribing purposes.

use alloy_primitives::B256;

#[allow(dead_code)]
/// Reader module
pub mod reader;
Expand Down
7 changes: 4 additions & 3 deletions crates/chainio/clients/avsregistry/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ trait AvsRegistryReader {
}

impl AvsRegistryChainReader {
/// New AvsRegistryChainReader instance
pub fn new(
registry_coordinator_addr: Address,
bls_apk_registry_addr: Address,
Expand Down Expand Up @@ -360,7 +361,7 @@ impl AvsRegistryChainReader {
.call()
.await?;
let RegistryCoordinator::getOperatorIdReturn { _0: operator_id } = operator_id_return;
return Ok(operator_id);
Ok(operator_id)
}

/// Get Operator from operator id
Expand Down Expand Up @@ -447,7 +448,7 @@ impl AvsRegistryChainReader {
println!("logs length {:?}", logs.len());
debug!(transactionLogs = ?logs, "avsRegistryChainReader.QueryExistingRegisteredOperatorPubKeys");

for (_, v_log) in logs.iter().enumerate() {
for v_log in logs.iter() {
let pub_key_reg_option = v_log
.log_decode::<BLSApkRegistry::NewPubkeyRegistration>()
.ok();
Expand Down Expand Up @@ -505,7 +506,7 @@ impl AvsRegistryChainReader {

let logs = provider.get_logs(&filter).await?;

for (_, v_log) in logs.iter().enumerate() {
for v_log in logs.iter() {
let socket_update_filter_option = v_log
.log_decode::<RegistryCoordinator::OperatorSocketUpdate>()
.ok();
Expand Down
8 changes: 5 additions & 3 deletions crates/chainio/clients/avsregistry/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use alloy_provider::{
use alloy_provider::{Provider, ProviderBuilder};
use alloy_rpc_types::Filter;
use alloy_transport::BoxTransport;
use BLSApkRegistry::{BLSApkRegistryEvents, BLSApkRegistryInstance, NewPubkeyRegistration};
use BLSApkRegistry::BLSApkRegistryInstance;

/// AvsRegistry Chain Subscriber struct
#[derive(Debug)]
Expand All @@ -24,10 +24,12 @@ pub struct AvsRegistryChainSubscriber {
}

impl AvsRegistryChainSubscriber {
/// New avs registry subscriber instance
pub fn new(provider: String) -> Self {
return AvsRegistryChainSubscriber { provider };
AvsRegistryChainSubscriber { provider }
}

/// Returns blsapkregistry instance
pub async fn build(
&self,
bls_apk_registry_addr: Address,
Expand All @@ -52,7 +54,7 @@ impl AvsRegistryChainSubscriber {
.await?;
let bls_apk_reg = BLSApkRegistry::new(bls_apk_registry_addr, provider);

return Ok(bls_apk_reg);
Ok(bls_apk_reg)
}

/// Utility function that returns new pubkey registration filter
Expand Down
5 changes: 2 additions & 3 deletions crates/chainio/clients/avsregistry/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ sol!(
);

use alloy_primitives::{Address, Bytes, FixedBytes, TxHash, U256};
use alloy_provider::{Provider, ProviderBuilder};
use alloy_provider::ProviderBuilder;
use eigen_crypto_bls::attestation::KeyPair;
use tracing::info;
use RegistryCoordinator::SignatureWithSaltAndExpiry;

/// AvsRegistry Writer
#[derive(Debug)]
pub struct AvsRegistryChainWriter {
service_manager_addr: Address,
Expand Down Expand Up @@ -130,7 +131,6 @@ impl AvsRegistryChainWriter {

async fn reigster_operator_in_quorum_with_avs_registry_coordinator(
&self,
pvt_key: &str,
bls_key_pair: KeyPair,
operator_to_avs_registration_sig_salt: FixedBytes<32>,
operator_to_avs_registration_sig_expiry: U256,
Expand Down Expand Up @@ -276,7 +276,6 @@ impl AvsRegistryChainWriter {
async fn deregister_operator(
&self,
quorum_numbers: Bytes,
pub_key: G1Point,
) -> Result<TxHash, Box<dyn std::error::Error>> {
info!("deregistering operator with the AVS's registry coordinator");
let url = Url::parse(&self.provider).expect("Wrong rpc url");
Expand Down
1 change: 1 addition & 0 deletions crates/chainio/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ark_bn254::G2Projective;
use ark_ff::BigInteger256;
sol!(
#[allow(missing_docs)]
#[allow(clippy::too_many_arguments)]
#[sol(rpc)]
RegistryCoordinator,
"../../../crates/contracts/bindings/utils/json/RegistryCoordinator.json"
Expand Down
16 changes: 7 additions & 9 deletions crates/crypto/bls/src/attestation.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use crate::error::BlsError;
use alloy_primitives::U256;
use ark_bn254::{Bn254, Fq, Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projective};
use ark_ec::{
pairing::{prepare_g1, prepare_g2, Pairing},
AffineRepr, CurveGroup,
};
use ark_ff::{BigInteger256, Field, Fp256, One, PrimeField};
use ark_bn254::{Bn254, Fq, Fq2, Fr, G1Affine, G1Projective, G2Projective};
use ark_ec::{pairing::Pairing, CurveGroup};
use ark_ff::{BigInteger256, Field, One, PrimeField};
use eigen_crypto_bn254::utils::{
get_g2_generator, mul_by_generator_g1, mul_by_generator_g2, u256_to_bigint256,
};
use hex::FromHex;
use std::fmt::Write;
use std::ops::{Add, Mul};
use std::{fmt::Write, io::Read};
pub fn new_fp_element(x: BigInteger256) -> Fq {
Fq::from(x)
}
Expand Down Expand Up @@ -268,16 +265,17 @@ mod tests {

// Check that the signature is not zero
assert_ne!(signature.sig(), G1Projective::zero());

let mut wrong_message = [0u8; 32];
rng.fill_bytes(&mut wrong_message);
// Check that the signature verifies
assert!(signature.verify_signature(pub_key_g2, &message));
assert!(!signature.verify_signature(pub_key_g2, &wrong_message))
}

#[tokio::test]
async fn test_signature_verification_invalid() {
let mut rng = thread_rng();
let private_key = Fr::rand(&mut rng);
println!("private key :{:?}", private_key);
let keypair = KeyPair::new(private_key).unwrap();

let mut message = [0u8; 32];
Expand Down
26 changes: 13 additions & 13 deletions crates/services/bls_aggregation/src/bls_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ use eigen_crypto_bls::attestation::{G1Point, G2Point, Signature};
use eigen_services_avsregistry::chaincaller::AvsRegistryServiceChainCaller;
use eigen_types::{
avs::{SignedTaskResponseDigest, TaskIndex, TaskResponseDigest},
operator::BLSApkRegistry,
operator::{OperatorAvsState, QuorumThresholdPercentage, QuorumThresholdPercentages},
};

use alloy_primitives::{FixedBytes, U256};
use eigen_crypto_bn254::utils::u256_to_bigint256;
use ethers::core::k256::FieldBytes;
use std::collections::HashMap;
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use tokio::time::{self, Duration};
Expand Down Expand Up @@ -93,14 +91,16 @@ impl BlsAggregatorService {
tokio::spawn(async move {
while let Some(signed_response) = rx.recv().await {
// Process each signed response here
self_clone.single_task_aggregator(
task_index,
task_created_block,
quorum_nums.clone(),
quorum_threshold_percentages.clone(),
time_to_expiry,
signed_response,
);
self_clone
.single_task_aggregator(
task_index,
task_created_block,
quorum_nums.clone(),
quorum_threshold_percentages.clone(),
time_to_expiry,
signed_response,
)
.await;
}
});
}
Expand Down Expand Up @@ -214,7 +214,7 @@ impl BlsAggregatorService {
}
else{
let mut operator_id_set = HashMap::new();
operator_id_set.insert(signed_task_digest.operator_id.clone(),true);
operator_id_set.insert(signed_task_digest.operator_id,true);
// first operator

if let Some(avs_state) = operator_state_avs.get(&signed_task_digest.operator_id.clone()){
Expand Down Expand Up @@ -244,7 +244,7 @@ impl BlsAggregatorService {
});

let mut non_signers_g1_pub_keys: Vec<G1Point> = vec![];
for (i,operator_id) in non_signers_operators_ids.iter().enumerate(){
for operator_id in non_signers_operators_ids.iter(){

if let Some(operator) = operator_state_avs.get(operator_id){
if let Some(keys) = &operator.operator_info.pub_keys{
Expand Down Expand Up @@ -338,6 +338,6 @@ impl BlsAggregatorService {
}
}

return true;
true
}
}
Loading