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: BLS aggregation #81

Merged
merged 117 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
e12d3c6
cids_multiplication
Aug 6, 2024
16e6439
wip
Aug 6, 2024
da6914e
latest
Aug 7, 2024
9c50a07
bls crate working
Aug 8, 2024
0ab90dd
bls crate and readme
Aug 8, 2024
88fb0c2
delete post.key file
Aug 8, 2024
bfe95ca
Merge branch 'main' into supernovahs/bls
supernovahs Aug 8, 2024
f579335
nits , delete keystore crate which is replaced by new bls keystore re…
Aug 8, 2024
defdaf3
change to https for rust bls bn254 dependency , and some clippy
Aug 8, 2024
6781f1f
Merge branch 'main' into supernovahs/bls
supernovahs Aug 9, 2024
52d6c85
merge nits
Aug 9, 2024
df90ecf
fix : mapto curve function
Aug 11, 2024
902b14e
complete sign message, verify message
Aug 12, 2024
30e22cc
move verify message and map to curve to bn254, nits
Aug 12, 2024
2a982b6
Merge branch 'main' into supernovahs/bls
supernovahs Aug 12, 2024
7693f67
update rust-bls-bn254 rev
Aug 12, 2024
1441538
add failing bls aggregator and chaincaller
TomasArrachea Aug 12, 2024
524d047
fix chaincaller pubkey addition
TomasArrachea Aug 12, 2024
425b168
refactor chaincaller and add bls utils
TomasArrachea Aug 13, 2024
924f983
WIP bls aggregation
TomasArrachea Aug 13, 2024
417b142
add affine point parse
TomasArrachea Aug 13, 2024
804370c
wip fixes
pablodeymo Aug 13, 2024
750eb3c
remove unused imports
TomasArrachea Aug 13, 2024
cda4770
remove unused crate
TomasArrachea Aug 13, 2024
b188ace
change aggregation quorum into bls point
TomasArrachea Aug 13, 2024
5ee156c
refactor verify signature
TomasArrachea Aug 13, 2024
dba5dc8
refactor check stake threshold
TomasArrachea Aug 13, 2024
e8cd3b8
format
TomasArrachea Aug 13, 2024
98bcc5e
add TestOperator struct
ricomateo Aug 14, 2024
98e6dcf
add FakeAvsRegistryService struct
ricomateo Aug 14, 2024
7622585
add AvsRegistryService trait + update BlsAggregatorService + add test…
ricomateo Aug 14, 2024
71c3ee8
add partial implementation of the AvsRegistryService trait for FakeAv…
ricomateo Aug 14, 2024
ce951a3
add the first bls aggregation test (not working yet)
ricomateo Aug 15, 2024
054b552
remove arc from aggregated_response_sender
ricomateo Aug 15, 2024
90277a9
change aggregated_response_receiver to mutex
ricomateo Aug 15, 2024
e83c5e4
change bls aggregator to pass reference in initialize_new_task
ricomateo Aug 15, 2024
f399efd
fix merge conflicts
ricomateo Aug 15, 2024
9e0b735
replace select macro for busy wait
ricomateo Aug 15, 2024
65f6c53
fix single_task_aggregator to match test output
TomasArrachea Aug 16, 2024
ee8c81c
implement aggregation for existing task
TomasArrachea Aug 16, 2024
4f340e1
add assert to the test
ricomateo Aug 16, 2024
6073702
add 2 tests and fix error with loops and channels
ricomateo Aug 16, 2024
cd778b1
add select! macro and add more tests
ricomateo Aug 16, 2024
d952e8b
fix bug in non_signers_operators_id
ricomateo Aug 16, 2024
edd00a1
fix test and remove prints
TomasArrachea Aug 16, 2024
5158a2f
fix tests agg signature g1
TomasArrachea Aug 16, 2024
922e565
fix small details on one of the tests
ricomateo Aug 16, 2024
807c554
test function with an example of timeout in the receive
pablodeymo Aug 16, 2024
d64bbf6
add timeout to the single_task_aggregator loop
ricomateo Aug 16, 2024
8c51bcf
remove timeout test
ricomateo Aug 16, 2024
ab2457b
refactor check stake threshold
TomasArrachea Aug 16, 2024
12cd989
fix conflicts
ricomateo Aug 16, 2024
a955e4f
Merge branch 'bls_aggregation' of github.com:lambdaclass/eigen-rs int…
ricomateo Aug 16, 2024
c9b6839
fix test
ricomateo Aug 16, 2024
6c770d3
add new test
ricomateo Aug 16, 2024
af85dcb
fix total stake per quorum bug
TomasArrachea Aug 16, 2024
2efa77a
add new test
ricomateo Aug 16, 2024
a14c172
doc for initialize_new_task
pablodeymo Aug 16, 2024
b7858bf
add test and timeout error response
TomasArrachea Aug 16, 2024
eaf0500
more doc functions
pablodeymo Aug 16, 2024
1be6489
add assert to one of the tests
ricomateo Aug 19, 2024
dea29f3
add new test (not working)
ricomateo Aug 19, 2024
2c8ba8d
fix error in g1point conversion
ricomateo Aug 19, 2024
dd38b82
add task not found error and test
TomasArrachea Aug 19, 2024
02e17a9
add new test
ricomateo Aug 19, 2024
575c21f
add test and rename task expired error
TomasArrachea Aug 19, 2024
894e32f
clippy
TomasArrachea Aug 19, 2024
cd271b6
Merge branch 'main' into bls_aggregation
TomasArrachea Aug 19, 2024
f38aa41
add errors to verify_signature
ricomateo Aug 19, 2024
ccf2ae9
clippy
TomasArrachea Aug 19, 2024
52891c0
unused comment removed
pablodeymo Aug 19, 2024
15638b9
Adding docs and refactoring functions
pablodeymo Aug 19, 2024
341d331
fix merge main
TomasArrachea Aug 19, 2024
21c49df
add test
TomasArrachea Aug 19, 2024
3d79735
docs added
pablodeymo Aug 19, 2024
d157e2c
fixing errors
pablodeymo Aug 19, 2024
f6bae37
fixing bug in non_signers_operators_ids
pablodeymo Aug 19, 2024
fe4a50d
add signature verification error handling
ricomateo Aug 19, 2024
d3fba43
remove unused method from AvsRegistryService trait
TomasArrachea Aug 19, 2024
98d81b6
fix wrong assert in test
ricomateo Aug 19, 2024
876653b
add integration test skeleton
TomasArrachea Aug 19, 2024
a03499f
add error handling and remove some cloning
ricomateo Aug 19, 2024
437ff17
fix merge main
TomasArrachea Aug 19, 2024
0bd346d
then_some
pablodeymo Aug 19, 2024
23f7887
clippy
pablodeymo Aug 19, 2024
d62779a
clippy
pablodeymo Aug 19, 2024
215218d
concurrency problem fixed
pablodeymo Aug 19, 2024
3940bf2
change how non_signer_pubkeys vector is obtained
ricomateo Aug 19, 2024
118e729
add error handling
ricomateo Aug 19, 2024
e680698
add aggregation functions to the tests
ricomateo Aug 20, 2024
ec2429e
add constants for the private keys used in tests
ricomateo Aug 20, 2024
bb8a48b
add function to aggregate operators
ricomateo Aug 20, 2024
1939b10
remove BlsAggregatorService cloning
ricomateo Aug 20, 2024
d413361
remove unnecessary generic from initialize_new_task
ricomateo Aug 20, 2024
09c230c
add error handling
ricomateo Aug 20, 2024
5eda51c
add build_aggregated_response function
ricomateo Aug 20, 2024
fecee48
fix clippy warnings
ricomateo Aug 20, 2024
fbc9199
change variable to be immutable
ricomateo Aug 20, 2024
b440efd
update docs
ricomateo Aug 20, 2024
c3f360b
remove comment
TomasArrachea Aug 20, 2024
34c8061
add more docs
ricomateo Aug 20, 2024
80259b7
mini comment added
pablodeymo Aug 20, 2024
360938e
improving quorum_threshold_percentage_map creation
pablodeymo Aug 20, 2024
8e75a40
changing loop to while let
pablodeymo Aug 20, 2024
0bb8202
digest_aggregated_operators improved
pablodeymo Aug 20, 2024
c371f4d
fix registry g2 point to affine bug and add test
TomasArrachea Aug 21, 2024
7cd9f95
remove new_unchecked
TomasArrachea Aug 21, 2024
7207750
fix bls aggregation response bug
TomasArrachea Aug 21, 2024
87f354d
add error handling for process_new_signature
TomasArrachea Aug 21, 2024
d240f49
typo
pablodeymo Aug 21, 2024
45e8c45
Add error return in get_operators_avs_state_at_block
pablodeymo Aug 21, 2024
18ea704
docs and unwrap removed in get_operator_info
pablodeymo Aug 21, 2024
8dea82d
fix chaincaller bug on key aggregation
TomasArrachea Aug 20, 2024
cfc3d51
docs added in AvsRegistryServiceChainCaller
pablodeymo Aug 21, 2024
1c40fbc
fix conflicts
ricomateo Aug 23, 2024
674e2d0
add error handling
ricomateo Aug 23, 2024
36066ef
clippy
pablodeymo Aug 26, 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
16 changes: 12 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ eigen-client-fireblocks = { path = "crates/chainio/clients/fireblocks" }
eigen-contract-bindings = { path = "crates/contracts/bindings/" }
eigen-crypto-bls = { path = "crates/crypto/bls/" }
eigen-crypto-bn254 = { path = "crates/crypto/bn254/" }
eigen-crypto-keystore = { path = "crates/crypto/keystore/" }
eigen-logging = { path = "crates/logging/" }
eigen-metrics = { version = "0.0.1-alpha", path = "crates/metrics/" }
eigen-metrics-collectors-economic = { path = "crates/metrics/collectors/economic" }
Expand Down Expand Up @@ -110,10 +109,11 @@ tokio = { version = "1.37.0", features = ["test-util", "full", "sync"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3", features = ["json"] }
url = "2.5.2"
uuid = { version = "1.10.0", features = ["v4"] }

#misc
rust-bls-bn254 = {git = "https://github.com/Layr-Labs/rust-bls-bn254.git", rev = "be3ef87", features = ["std"] }
uuid = { version = "1.10.0", features = ["v4"] }


#misc
parking_lot = "0.12"
Expand Down
6 changes: 5 additions & 1 deletion crates/chainio/clients/avsregistry/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub enum AvsRegistryError {
GetBlsApkRegistry,

/// Failed to get quorum count
#[error("Faield to get quorum count")]
#[error("Failed to get quorum count")]
GetQuorumCount,

/// Failed to ger operator state
Expand Down Expand Up @@ -141,6 +141,10 @@ pub enum AvsRegistryError {
/// BlsError compatibility
#[error("BlsError :{0}")]
BlsError(String),

/// Invalid Quorum Numbers
#[error("Invalid number of quorum numbers")]
InvalidQuorumNums,
}

impl From<ElContractsError> for AvsRegistryError {
Expand Down
18 changes: 12 additions & 6 deletions crates/chainio/clients/avsregistry/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ use alloy_primitives::{Address, Bytes, FixedBytes, B256, U256};
use alloy_provider::Provider;
use alloy_rpc_types::Filter;
use ark_ff::Zero;
use eigen_logging::logger::SharedLogger;
use eigen_logging::tracing_logger::TracingLogger;
use eigen_crypto_bls::{
alloy_registry_g1_point_to_g1_affine, alloy_registry_g2_point_to_g2_affine, BlsG1Point,
BlsG2Point,
};
use eigen_logging::{logger::SharedLogger, tracing_logger::TracingLogger};
use eigen_types::operator::{bitmap_to_quorum_ids, OperatorPubKeys};
use eigen_utils::NEW_PUBKEY_REGISTRATION_EVENT;
use eigen_utils::{
binding::{BLSApkRegistry, OperatorStateRetriever, RegistryCoordinator, StakeRegistry},
get_provider, get_ws_provider,
get_provider, get_ws_provider, NEW_PUBKEY_REGISTRATION_EVENT,
};
use num_bigint::BigInt;
use std::collections::HashMap;
Expand Down Expand Up @@ -428,8 +430,12 @@ impl AvsRegistryChainReader {
let g1_pub_key = data.pubkeyG1.clone();
let g2_pub_key = data.pubkeyG2.clone();
let operator_pub_key = OperatorPubKeys {
g1_pub_key,
g2_pub_key,
g1_pub_key: BlsG1Point::new(
alloy_registry_g1_point_to_g1_affine(g1_pub_key),
),
g2_pub_key: BlsG2Point::new(
alloy_registry_g2_point_to_g2_affine(g2_pub_key),
),
};
operator_pub_keys.push(operator_pub_key);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/chainio/clients/eth/src/instrumented_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ impl InstrumentedClient {
/// * `block_count` - The number of blocks to include in the collection.
/// * `last_block` - The last block number to include in the collection.
/// * `reward_percentiles` - A sorted list of percentage points used to
/// sample the effective priority fees per gas from each block. The samples are
/// taken in ascending order and weighted by gas usage. The list is sorted increasingly.
/// sample the effective priority fees per gas from each block. The samples are
/// taken in ascending order and weighted by gas usage. The list is sorted increasingly.
pub async fn fee_history(
&self,
block_count: u64,
Expand Down
121 changes: 115 additions & 6 deletions crates/crypto/bls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ pub mod error;
use crate::error::BlsError;
use ark_bn254::{Fq, Fr, G1Affine, G1Projective, G2Affine, G2Projective};
use ark_ec::{AffineRepr, CurveGroup};
use ark_ff::{fields::PrimeField, BigInt, BigInteger256};
use ark_ff::{fields::PrimeField, BigInt, BigInteger256, Fp2};
use eigen_crypto_bn254::utils::map_to_curve;
use eigen_utils::binding::RegistryCoordinator::{self};
use eigen_utils::binding::{
BLSApkRegistry,
RegistryCoordinator::{self},
};
use BLSApkRegistry::{G1Point as G1PointRegistry, G2Point as G2PointRegistry};
use RegistryCoordinator::{G1Point, G2Point};
pub type PrivateKey = Fr;
pub type PublicKey = G1Affine;
pub type BlsSignature = G1Affine;
pub type OperatorId = B256;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BlsG1Point {
g1: G1Affine,
}
Expand All @@ -35,7 +39,7 @@ impl BlsG1Point {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BlsG2Point {
g2: G2Affine,
}
Expand All @@ -50,8 +54,8 @@ impl BlsG2Point {
}
}

#[derive(Debug)]
/// Bls key pair with public key on G1
#[derive(Debug, Clone)]
pub struct BlsKeyPair {
/// Private Key
priv_key: Fr,
Expand Down Expand Up @@ -163,8 +167,60 @@ pub fn convert_to_g2_point(g2: G2Affine) -> Result<G2Point, BlsError> {
}
}

/// Convert [`G1Point`] to [`G1Affine`]
pub fn alloy_registry_g1_point_to_g1_affine(g1_point: G1PointRegistry) -> G1Affine {
let x_point = g1_point.X.into_limbs();
let x = Fq::new(BigInteger256::new(x_point));
let y_point = g1_point.Y.into_limbs();
let y = Fq::new(BigInteger256::new(y_point));
G1Affine::new(x, y)
}

/// Convert [`G1Point`] to [`G1Affine`]
pub fn alloy_registry_g2_point_to_g2_affine(g2_point: G2PointRegistry) -> G2Affine {
let x_fp2 = Fp2::new(
BigInteger256::new(g2_point.X[1].into_limbs()).into(),
BigInteger256::new(g2_point.X[0].into_limbs()).into(),
);
let y_fp2 = Fp2::new(
BigInteger256::new(g2_point.Y[1].into_limbs()).into(),
BigInteger256::new(g2_point.Y[0].into_limbs()).into(),
);
G2Affine::new(x_fp2, y_fp2)
}

/// Convert [`G2Affine`] to [`G2Point`]
pub fn convert_to_registry_g2_point(g2: G2Affine) -> Result<G2PointRegistry, BlsError> {
let x_point_result = g2.x();
let y_point_result = g2.y();

if let (Some(x_point), Some(y_point)) = (x_point_result, y_point_result) {
let x_point_c0 = x_point.c0;
let x_point_c1 = x_point.c1;
let y_point_c0 = y_point.c0;
let y_point_c1 = y_point.c1;

let x_0 = BigInt::new(x_point_c0.into_bigint().0);
let x_1 = BigInt::new(x_point_c1.into_bigint().0);
let y_0 = BigInt::new(y_point_c0.into_bigint().0);
let y_1 = BigInt::new(y_point_c1.into_bigint().0);

let x_u256_0 = U256::from_limbs(x_0.0);
let x_u256_1 = U256::from_limbs(x_1.0);
let y_u256_0 = U256::from_limbs(y_0.0);
let y_u256_1 = U256::from_limbs(y_1.0);

Ok(G2PointRegistry {
X: [x_u256_1, x_u256_0],
Y: [y_u256_1, y_u256_0],
})
} else {
Err(BlsError::InvalidG2Affine)
}
}

/// Signature instance on [`G1Affine`]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Signature {
g1_point: BlsG1Point,
}
Expand Down Expand Up @@ -394,4 +450,57 @@ mod tests {
signature.g1_point().g1()
));
}

#[test]
fn test_alloy_registry_g2_point_to_g2_affine() {
let registry_g2_point = G2PointRegistry {
X: [
U256::from_str(
"5757009320127825712028542414399286695979413866882055578475552905478799178978",
)
.unwrap(),
U256::from_str(
"21244616545128868564944750577089226156588822099825362793595203506897139322148",
)
.unwrap(),
],
Y: [
U256::from_str(
"14151879035050941576498647371309462393327101480686968228451570672809612016186",
)
.unwrap(),
U256::from_str(
"3459884663217117850014821742383597128426843416583591466170557027357262534805",
)
.unwrap(),
],
};

let g2_affine = alloy_registry_g2_point_to_g2_affine(registry_g2_point);
let expected_g2_affine = G2Affine {
x: Fq2::new(
Fq::from_str(
"21244616545128868564944750577089226156588822099825362793595203506897139322148",
)
.unwrap(),
Fq::from_str(
"5757009320127825712028542414399286695979413866882055578475552905478799178978",
)
.unwrap(),
),
y: Fq2::new(
Fq::from_str(
"3459884663217117850014821742383597128426843416583591466170557027357262534805",
)
.unwrap(),
Fq::from_str(
"14151879035050941576498647371309462393327101480686968228451570672809612016186",
)
.unwrap(),
),
infinity: false,
};

assert_eq!(g2_affine, expected_g2_affine);
}
}
5 changes: 2 additions & 3 deletions crates/services/avsregistry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ license-file.workspace = true

[dependencies]
alloy-primitives.workspace = true
eigen-chainio-utils.workspace = true
ark-bn254.workspace = true
ark-ec.workspace = true
eigen-client-avsregistry.workspace = true
eigen-crypto-bls.workspace = true
eigen-crypto-bn254.workspace = true
eigen-logging.workspace = true
eigen-services-operatorsinfo.workspace = true
eigen-types.workspace = true
eigen-utils.workspace = true
Loading
Loading