From c71a1eaef774c556b12e9e450fd7c71314992eef Mon Sep 17 00:00:00 2001 From: Tjemmmic Date: Tue, 13 Aug 2024 19:33:04 -0500 Subject: [PATCH] Debugging, Testing, and Cleanup --- avs/incredible-squaring-avs/build.rs | 2 +- avs/tangle-avs/build.rs | 2 +- .../src/TangleValidatorServiceManager.sol | 7 +- test-utils/Cargo.toml | 8 ++ test-utils/keystore/bls | 2 +- test-utils/keystore/ecdsa | 2 +- test-utils/scripts/avs_rebuild_contracts.sh | 25 +++++++ .../{rebuild.sh => rebuild_contracts.sh} | 0 test-utils/src/anvil/abi.rs | 4 - .../src/anvil/testnet/incredible_squaring.rs | 73 ++----------------- test-utils/src/incredible_squaring.rs | 12 ++- utils/src/avs_registry/writer.rs | 49 ++++++++++--- utils/src/crypto/bls.rs | 14 ++-- utils/src/crypto/bn254.rs | 63 ++-------------- utils/src/crypto/pairing_products.rs | 16 ++-- 15 files changed, 118 insertions(+), 161 deletions(-) create mode 100644 test-utils/scripts/avs_rebuild_contracts.sh rename test-utils/scripts/{rebuild.sh => rebuild_contracts.sh} (100%) diff --git a/avs/incredible-squaring-avs/build.rs b/avs/incredible-squaring-avs/build.rs index d4e1a19..6ad9d8b 100644 --- a/avs/incredible-squaring-avs/build.rs +++ b/avs/incredible-squaring-avs/build.rs @@ -19,7 +19,7 @@ fn main() { if full_path.exists() { println!("cargo:rerun-if-changed={}", full_path.display()); - let status = Command::new("forge") + let status = Command::new("/home/tjemmmic/.foundry/bin/forge") .current_dir(&full_path) .arg("build") .status() diff --git a/avs/tangle-avs/build.rs b/avs/tangle-avs/build.rs index d4e1a19..6ad9d8b 100644 --- a/avs/tangle-avs/build.rs +++ b/avs/tangle-avs/build.rs @@ -19,7 +19,7 @@ fn main() { if full_path.exists() { println!("cargo:rerun-if-changed={}", full_path.display()); - let status = Command::new("forge") + let status = Command::new("/home/tjemmmic/.foundry/bin/forge") .current_dir(&full_path) .arg("build") .status() diff --git a/avs/tangle-avs/contracts/src/TangleValidatorServiceManager.sol b/avs/tangle-avs/contracts/src/TangleValidatorServiceManager.sol index 5bb637e..0939c45 100644 --- a/avs/tangle-avs/contracts/src/TangleValidatorServiceManager.sol +++ b/avs/tangle-avs/contracts/src/TangleValidatorServiceManager.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.20; -import "./eigenlayer-contracts/src/contracts/libraries/BytesLib.sol"; -import "./ITangleValidatorTaskManager.sol"; -import "./eigenlayer-middleware/src/ServiceManagerBase.sol"; +import "eigenlayer-middleware/lib/eigenlayer-contracts/src/contracts/libraries/BytesLib.sol"; +import "src/ITangleValidatorTaskManager.sol"; +import "eigenlayer-middleware/src/ServiceManagerBase.sol"; /** * @title Primary entrypoint for procuring services from TangleValidator. @@ -32,7 +32,6 @@ contract TangleValidatorServiceManager is ServiceManagerBase { ) ServiceManagerBase( _avsDirectory, - IRewardsCoordinator(address(0)), // inc-sq doesn't need to deal with payments _registryCoordinator, _stakeRegistry ) diff --git a/test-utils/Cargo.toml b/test-utils/Cargo.toml index 100ae58..ab3eda5 100644 --- a/test-utils/Cargo.toml +++ b/test-utils/Cargo.toml @@ -7,6 +7,14 @@ license.workspace = true homepage.workspace = true repository.workspace = true +#[lib] +#name = "test_utils" +#path = "src/lib.rs" +# +#[[bin]] +#name = "incredible_squaring" +#path = "src/incredible_squaring.rs" + [dependencies] alloy-abi.workspace = true alloy-contract.workspace = true diff --git a/test-utils/keystore/bls b/test-utils/keystore/bls index 4ac13e9..efe69c8 100644 --- a/test-utils/keystore/bls +++ b/test-utils/keystore/bls @@ -1 +1 @@ -{"pub_key":{"x":"0x13b15d57e069eee24b23c82947dc6cd57a7c87e965c5dc325ca1e770dd52ad01","y":"0x5d262729c016f000f161c8edef2b55061520c6786042ef93fa61cea057e5b8f"},"crypto":{"encrypted_data":"7FQ+MQN6ZIQaTK20rdiVunAGtZE3SP5fWkKn54spoled8Z4c0+xd06/Hq43Kp3YI","nonce":"qVgmzWcYA4GtWKzP","password_hash":"JHNjcnlwdCRsbj0xNyxyPTgscD0xJHdCdWtNcU5NMmZkenMxaGxwczRVOXckZVRLQUtnbHhHK2lVZlBBakZ5K0tkMXYxNDRveUl6NUUzS2hmT3kzNUNCTQ=="}} \ No newline at end of file +{"pub_key":{"x":"0x2ed159b38ebb1317b82c3a816202ff8b39788b7996164384f7b79eb06ccdb330","y":"0x7a559aedbd3b933c7dd94234b805419be6a22065e646d23b4b1fe8e92fcd823"},"crypto":{"encrypted_data":"MiC+DCC00z+Lg4J9HGfzZqOPnghgiqJiXQ2982hWSnBoLwdvR4+U+YzG7SIXXWh/","nonce":"q+YU8mhCLsll8KDk","password_hash":"JHNjcnlwdCRsbj0xNyxyPTgscD0xJHk5bUR4NGFxM0hmYXU4Ti94U3BiOWckZGhJYWpid1JwN3ZidmQvMDR1VTlITDc3cVNNNkd4YWpYcWZLSWVGb0ZxRQ=="}} \ No newline at end of file diff --git a/test-utils/keystore/ecdsa b/test-utils/keystore/ecdsa index c0eea57..a6ae8b0 100644 --- a/test-utils/keystore/ecdsa +++ b/test-utils/keystore/ecdsa @@ -1 +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"} \ No newline at end of file +{"address":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","crypto":{"Cipher":"aes-128-ctr","CipherText":"1113254d033cc52729222bd5742459a4d054a449aff3def44ae3018fb8dc7748","CipherParams":{"IV":"7e85c58ecd9e5ecb8fc36fdaac3aab96"},"KDF":"scrypt","KDFParams":{"n":17,"r":8,"p":1,"dklen":32,"salt":"f480c3532ddbd9f2c23be95ad94072d3df15284c556d3ba6b0b6fa286ece18e0"},"MAC":"d55830a172e2ac50764a4426c96fe1f9e68ded4470cd234bc0b44a7eea981643"},"id":"99d8665f-eb45-49d0-936d-c69965cb5835","version":"3"} \ No newline at end of file diff --git a/test-utils/scripts/avs_rebuild_contracts.sh b/test-utils/scripts/avs_rebuild_contracts.sh new file mode 100644 index 0000000..30160fb --- /dev/null +++ b/test-utils/scripts/avs_rebuild_contracts.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Define the directories +DIR1="./../avs/incredible-squaring-avs/contracts" +DIR2="./../avs/tangle-avs/contract" + +# Function to run forge commands in a directory +run_forge_commands() { + local dir=$1 + echo "Running forge commands in $dir" + cd "$dir" || exit + forge clean + forge build + cd - || exit +} + +# Run forge commands in both directories +run_forge_commands "$DIR1" +run_forge_commands "$DIR2" + +# Run cargo test in the starting directory +#echo "Running cargo test in the current directory" +#cargo test + +echo "Rebuilt all AVS Smart Contracts!" \ No newline at end of file diff --git a/test-utils/scripts/rebuild.sh b/test-utils/scripts/rebuild_contracts.sh similarity index 100% rename from test-utils/scripts/rebuild.sh rename to test-utils/scripts/rebuild_contracts.sh diff --git a/test-utils/src/anvil/abi.rs b/test-utils/src/anvil/abi.rs index 68d0010..8ccb69f 100644 --- a/test-utils/src/anvil/abi.rs +++ b/test-utils/src/anvil/abi.rs @@ -1,7 +1,3 @@ -use alloy_sol_types::abi; -use alloy_sol_types::abi::Token; -use sha3::{Digest, Keccak256}; - /// Macro that acts as the Rust equivalent of Solidity's `abi.encodeWithSelector`. Returns [alloy_primitives::Bytes] #[macro_export] macro_rules! encode_params { diff --git a/test-utils/src/anvil/testnet/incredible_squaring.rs b/test-utils/src/anvil/testnet/incredible_squaring.rs index 4b5e3ac..f7e5b41 100644 --- a/test-utils/src/anvil/testnet/incredible_squaring.rs +++ b/test-utils/src/anvil/testnet/incredible_squaring.rs @@ -1,29 +1,15 @@ use crate::encode_params; -use alloy::signers::Signer; -use alloy_primitives::{address, Address, Bytes, Keccak256, Uint, U256}; -use alloy_provider::network::{TransactionBuilder, TxSigner}; +use alloy_primitives::{address, Address, Bytes, Keccak256, U256}; use alloy_provider::{Provider, ProviderBuilder}; -use alloy_rpc_types_eth::BlockId; -use alloy_signer_local::PrivateKeySigner; -use alloy_sol_types::{ - abi::Encoder, - abi::{self, token::*}, - private::SolTypeValue, - SolValue, Word, -}; -use alloy_transport_ws::WsConnect; +use alloy_sol_types::{abi, SolValue}; use anvil::spawn; -use ark_bn254::{Fq as F, Fr, G1Affine, G2Affine, G2Projective}; use eigen_contracts::{ RegistryCoordinator::{OperatorSetParam, StrategyParams}, *, }; -use gadget_common::subxt_signer::bip39::rand_core::OsRng; use incredible_squaring_avs::avs::{ IncredibleSquaringServiceManager, IncredibleSquaringTaskManager, }; -use k256::{ecdsa::VerifyingKey, elliptic_curve::SecretKey}; -use std::{path::Path, time::Duration}; use url::Url; pub static BLS_PASSWORD: &str = "BLS_PASSWORD"; @@ -46,7 +32,7 @@ pub async fn run_anvil_testnet() -> ContractAddresses { // Initialize the logger let _ = env_logger::try_init(); - let (api, mut handle) = spawn( + let (api, handle) = spawn( anvil::NodeConfig::test() .with_port(8545) .with_print_logs(true) @@ -81,7 +67,7 @@ pub async fn run_anvil_testnet() -> ContractAddresses { let _gas_price = provider.get_gas_price().await.unwrap(); // Empty address for initial deployment of all contracts - let empty_address = Address::default(); + let _empty_address = Address::default(); // let strategy_manager_addr = address!("Dc64a140Aa3E981100a9becA4E685f962f0cF6C9"); // let delegation_manager_addr = address!("Cf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"); @@ -477,7 +463,7 @@ pub async fn run_anvil_testnet() -> ContractAddresses { for j in 0..number_of_quorums { quorums_strategy_params.push(Vec::::new()); quorums_minimum_stake.push(0); - for k in 0..number_of_strategies { + for _k in 0..number_of_strategies { quorums_strategy_params[j].push(StrategyParams { strategy: strategies[j], multiplier: 1, @@ -488,37 +474,7 @@ pub async fn run_anvil_testnet() -> ContractAddresses { // Function with signature initialize(address,address,address,address,uint256,(uint32,uint16,uint16)[],uint96[],(address,uint96)[][]) and selector 0xdd8283f3. let function_signature = "initialize(address,address,address,address,uint256,(uint32,uint16,uint16)[],uint96[],(address,uint96)[][])"; - let single_test = 0.tokenize(); - println!("Word Tokenize: {:?}", single_test); - let vec_test = quorum_operator_set_params.tokenize(); - println!("Vec Tokenize: {:?}", vec_test); - - let encoded_word = abi::encode(&single_test); - - let encoded_vec = abi::encode(&vec_test); - - println!( - "Quorums Strategy Params: Strategy: {:?} Multiplier: {:?}", - quorums_strategy_params[0][0].strategy, quorums_strategy_params[0][0].multiplier - ); - println!("Quorum Operator Set Params: Max Operators: {:?}, Kick BIPs of Operator Stake: {:?}, Kick BIPs of Total Stake: {:?}", quorum_operator_set_params[0].maxOperatorCount, quorum_operator_set_params[0].kickBIPsOfOperatorStake, quorum_operator_set_params[0].kickBIPsOfTotalStake); - println!("Quorums Minimum Stake: {:?}", quorums_minimum_stake); - - // let mut hasher = Keccak256::new(); - // hasher.update(function_signature); - // let function_selector = &hasher.finalize()[..4]; - // let mut data = Vec::from(function_selector); - // data.extend_from_slice(&abi::encode(&pausers[0].tokenize())); - // data.extend_from_slice(&abi::encode(&pausers[0].tokenize())); - // data.extend_from_slice(&abi::encode(&pausers[0].tokenize())); - // data.extend_from_slice(&abi::encode(&pausers[1].tokenize())); - // data.extend_from_slice(&abi::encode(&0.tokenize())); - // data.extend_from_slice(&abi::encode(&quorum_operator_set_params.tokenize())); - // data.extend_from_slice(&abi::encode(&quorums_minimum_stake.tokenize())); - // data.extend_from_slice(&abi::encode(&quorums_strategy_params.tokenize())); - // let encoded_data = alloy_primitives::Bytes::from(data); - - let encoded_data = encode_params!( + let _encoded_data = encode_params!( function_signature, pausers[0], pausers[0], @@ -529,23 +485,6 @@ pub async fn run_anvil_testnet() -> ContractAddresses { quorums_minimum_stake, quorums_strategy_params ); - // let registry_coordinator_upgrade = incredible_squaring_proxy_admin - // .upgradeAndCall( - // registry_coordinator_addr, - // registry_coordinator_implementation_addr, - // encoded_data, - // ) - // // .from(dev_account) - // .send() - // .await - // .unwrap() - // .get_receipt() - // .await - // .unwrap(); - // log::info!( - // "Registry Coordinator Upgrade Receipt: {:?}", - // registry_coordinator_upgrade - // ); let registry_coordinator_upgrade = incredible_squaring_proxy_admin .upgrade( diff --git a/test-utils/src/incredible_squaring.rs b/test-utils/src/incredible_squaring.rs index baace1a..2d48eaa 100644 --- a/test-utils/src/incredible_squaring.rs +++ b/test-utils/src/incredible_squaring.rs @@ -1,3 +1,4 @@ +#[allow(dead_code)] use crate::anvil::testnet::incredible_squaring::*; use alloy_provider::Provider; use alloy_provider::ProviderBuilder; @@ -7,6 +8,15 @@ use incredible_squaring_avs::operator::*; use k256::ecdsa::SigningKey; use k256::elliptic_curve::SecretKey; +#[tokio::main] +async fn main() { + let _ = env_logger::try_init(); + run_full_incredible_squaring_test().await; +} + +/// THIS FUNCTION IS FOR TESTING ONLY +/// +/// Runs the Incredible Squaring Testnet and then creates an Operator that connects and registers. async fn run_full_incredible_squaring_test() { let _ = env_logger::try_init(); @@ -70,7 +80,7 @@ async fn run_full_incredible_squaring_test() { let operator_info_service = OperatorInfoService {}; let hex_key = - hex::decode("59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d").unwrap(); + hex::decode("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80").unwrap(); let secret_key = SecretKey::from_slice(&hex_key).unwrap(); let signing_key = SigningKey::from(secret_key.clone()); let signer = EigenGadgetSigner { diff --git a/utils/src/avs_registry/writer.rs b/utils/src/avs_registry/writer.rs index 853b01f..5db547b 100644 --- a/utils/src/avs_registry/writer.rs +++ b/utils/src/avs_registry/writer.rs @@ -1,7 +1,8 @@ #![allow(async_fn_in_trait)] use super::{AvsRegistryContractManager, AvsRegistryContractResult}; -use crate::crypto::bls::{G1Point, KeyPair}; +use crate::crypto::bls::{g1_point_to_ark_point, g1_point_to_g1_projective, G1Point, KeyPair}; +use crate::crypto::bn254::get_g2_generator; use crate::crypto::ecdsa::ToAddress; use crate::el_contracts::reader::ElReader; use crate::{types::*, Config}; @@ -10,6 +11,8 @@ use alloy_provider::Provider; use alloy_rpc_types::TransactionReceipt; use alloy_signer::k256::ecdsa; use alloy_signer::Signer as alloySigner; +use ark_ec::pairing::Pairing; +use ark_ec::CurveGroup; use eigen_contracts::RegistryCoordinator; use eigen_contracts::RegistryCoordinator::SignatureWithSaltAndExpiry; use k256::ecdsa::VerifyingKey; @@ -58,7 +61,6 @@ impl AvsRegistryChainWriterTrait for AvsRegistryContractManager { quorum_numbers: Bytes, socket: String, ) -> AvsRegistryContractResult { - log::info!("Signing Key: {:?}", operator_ecdsa_private_key); let operator_addr = operator_ecdsa_private_key.verifying_key().to_address(); log::info!("Operator address: {:?}", operator_addr); let registry_coordinator = @@ -89,14 +91,21 @@ impl AvsRegistryChainWriterTrait for AvsRegistryContractManager { g1_point.y ); - let signed_msg = bls_key_pair.sign_hashed_to_curve_message(&g1_point); + let signed_msg = bls_key_pair + .sign_hashed_to_curve_message(&g1_point) + .g1_point; let g1_pubkey_bn254 = bls_key_pair.get_pub_key_g1(); let g2_pubkey_bn254 = bls_key_pair.get_pub_key_g2(); + log::info!( + "SIGNED MESSAGE G1POINT: X: {:?}, Y: {:?}", + signed_msg.x, + signed_msg.y + ); let pubkey_reg_params = RegistryCoordinator::PubkeyRegistrationParams { pubkeyRegistrationSignature: RegistryCoordinator::G1Point { - X: signed_msg.g1_point.x, - Y: signed_msg.g1_point.y, + X: signed_msg.x, + Y: signed_msg.y, }, pubkeyG1: RegistryCoordinator::G1Point { X: g1_pubkey_bn254.x, @@ -107,6 +116,22 @@ impl AvsRegistryChainWriterTrait for AvsRegistryContractManager { Y: g2_pubkey_bn254.y, }, }; + log::info!( + "REGISTRY COORDINATOR G1POINT: X: {:?}, Y: {:?}", + pubkey_reg_params.pubkeyRegistrationSignature.X, + pubkey_reg_params.pubkeyRegistrationSignature.Y + ); + + let signature = g1_point_to_g1_projective(&signed_msg); + // PAIRING TEST + let e1 = ark_bn254::Bn254::pairing(signature.into_affine(), get_g2_generator().unwrap()); + + let e2 = ark_bn254::Bn254::pairing( + g1_point_to_ark_point(&g1_point), + bls_key_pair.get_pub_key_g2().to_ark_g2(), + ); + + assert_eq!(e1, e2); // Generate a random salt and 1 hour expiry for the signature let mut rng = rand::thread_rng(); @@ -164,12 +189,14 @@ impl AvsRegistryChainWriterTrait for AvsRegistryContractManager { expiry: operator_to_avs_registration_sig_expiry, }; - let tx = registry_coordinator.registerOperator( - quorum_numbers, - socket, - pubkey_reg_params, - operator_signature_with_salt_and_expiry, - ); + let tx = registry_coordinator + .registerOperator( + quorum_numbers, + socket, + pubkey_reg_params, + operator_signature_with_salt_and_expiry, + ) + .from(operator_addr); let receipt = tx.send().await?.get_receipt().await.unwrap(); diff --git a/utils/src/crypto/bls.rs b/utils/src/crypto/bls.rs index 8ebef8c..7d5a2cd 100644 --- a/utils/src/crypto/bls.rs +++ b/utils/src/crypto/bls.rs @@ -1,3 +1,6 @@ +use super::bn254::{ + get_g2_generator, map_to_curve, mul_by_generator_g1, point_to_u256, u256_to_point, +}; use crate::types::AvsError; use alloy_primitives::U256; use ark_bn254::Fq as F; @@ -22,8 +25,6 @@ use std::fs; use std::ops::Neg; use std::path::Path; -use super::bn254::{map_to_curve, mul_by_generator_g1, point_to_u256, u256_to_point}; - #[derive(Clone, Debug, Serialize, Deserialize)] struct EncryptedBLSKeyJSONV3 { pub pub_key: G1Point, @@ -356,11 +357,10 @@ impl Signature { let p_projective = [g1_point_to_ark_point(&p[0]), g1_point_to_ark_point(&p[1])]; let q_projective = [g2_point_to_ark_point(&q[0]), g2_point_to_ark_point(&q[1])]; - // // If Pairing Left and Right are equal, then the signature is valid as well - // let g2_gen = g2_point_to_ark_point(&G2Point::generator()); - // let pairing_left = Bn254::pairing(self.g1_point.to_ark_g1(), g2_gen); - // let pairing_right = Bn254::pairing(msg_affine, g2_point_to_ark_point(&pubkey.clone())); - // println!("Pairing Comparison: {:?}", pairing_left == pairing_right); + // If Pairing Left and Right are equal, then the signature is valid as well + let e1 = Bn254::pairing(self.g1_point.to_ark_g1(), get_g2_generator().unwrap()); + let e2 = Bn254::pairing(msg_affine, g2_point_to_ark_point(&pubkey.clone())); + log::info!("Are e1 and e2 pairings equal? {:?}", e1 == e2); let pairing_result = Bn254::multi_pairing(p_projective, q_projective); Ok(pairing_result.0.is_one()) diff --git a/utils/src/crypto/bn254.rs b/utils/src/crypto/bn254.rs index 8ff7866..d1af2b5 100644 --- a/utils/src/crypto/bn254.rs +++ b/utils/src/crypto/bn254.rs @@ -1,12 +1,12 @@ use crate::types::AvsError; use alloy_primitives::U256; -use ark_bn254::{Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projective}; +use ark_bn254::{Fr, G1Affine, G1Projective, G2Affine, G2Projective}; use ark_ff::{BigInteger, BigInteger256}; use ark_ff::{Field, One, PrimeField}; use std::ops::Mul; -use std::str::FromStr; use ark_bn254::Fq as F; +use ark_ec::AffineRepr; pub fn map_to_curve(digest: &[u8; 32]) -> G1Projective { let one = F::one(); @@ -68,62 +68,15 @@ pub fn biginteger256_to_u256(bi: BigInteger256) -> U256 { } pub fn get_g1_generator() -> Result { - let x_result = F::from_str("1"); - - let y_result = F::from_str("2"); - - match x_result { - Ok(x) => match y_result { - Ok(y) => Ok(G1Affine::new(x, y)), - Err(_) => Err(AvsError::KeyError( - "Invalid G1 Generator Y Result".to_string(), - )), - }, - Err(_) => Err(AvsError::KeyError( - "Invalid G1 Generator X Result".to_string(), - )), - } + // let g1_affine = G1Affine::new(G1_GENERATOR_X, G1_GENERATOR_Y); + let g1_affine = G1Affine::generator(); + Ok(g1_affine) } pub fn get_g2_generator() -> Result { - let x_0_result = F::from_str( - "10857046999023057135944570762232829481370756359578518086990519993285655852781", - ); - - let x_1result = F::from_str( - "11559732032986387107991004021392285783925812861821192530917403151452391805634", - ); - - match x_0_result { - Ok(x_0) => { - match x_1result { - Ok(x_1) => { - let x = Fq2::new(x_0, x_1); - - let y_0_result = F::from_str("8495653923123431417604973247489272438418190587263600148770280649306958101930"); - - match y_0_result { - Ok(y_0) => { - let y_1_result = F::from_str("4082367875863433681332203403145435568316851327593401208105741076214120093531"); - - match y_1_result { - Ok(y_1) => { - let y = Fq2::new(y_0, y_1); - Ok(G2Affine::new(x, y)) - } - Err(_) => { - Err(AvsError::KeyError("Invalid G2 Generator Y1".to_string())) - } - } - } - Err(_) => Err(AvsError::KeyError("Invalid G2 Generator Y0".to_string())), - } - } - Err(_) => Err(AvsError::KeyError("Invalid G2 Generator X1".to_string())), - } - } - Err(_) => Err(AvsError::KeyError("Invalid G2 Generator X0".to_string())), - } + // let g2_affine = G2Affine::new(G2_GENERATOR_X, G2_GENERATOR_Y); + let g2_affine = G2Affine::generator(); + Ok(g2_affine) } pub fn mul_by_generator_g1(pvt_key: Fr) -> Result { diff --git a/utils/src/crypto/pairing_products.rs b/utils/src/crypto/pairing_products.rs index f495f0a..2c52934 100644 --- a/utils/src/crypto/pairing_products.rs +++ b/utils/src/crypto/pairing_products.rs @@ -10,8 +10,8 @@ use std::{ marker::PhantomData, }; -#[cfg(feature = "parallel")] -use rayon::prelude::*; +// #[cfg(feature = "parallel")] +// use rayon::prelude::*; pub type Error = Box; @@ -88,9 +88,9 @@ pub fn cfg_multi_pairing(left: &[P::G1], right: &[P::G2]) -> Option< .collect::>(); // We want to process N chunks in parallel where N is the number of threads available - #[cfg(feature = "parallel")] - let num_chunks = rayon::current_num_threads(); - #[cfg(not(feature = "parallel"))] + // #[cfg(feature = "parallel")] + // let num_chunks = rayon::current_num_threads(); + // #[cfg(not(feature = "parallel"))] let num_chunks = 1; let chunk_size = if num_chunks <= left.len() { @@ -100,9 +100,9 @@ pub fn cfg_multi_pairing(left: &[P::G1], right: &[P::G2]) -> Option< 1 }; - #[cfg(feature = "parallel")] - let (left_chunks, right_chunks) = (left.par_chunks(chunk_size), right.par_chunks(chunk_size)); - #[cfg(not(feature = "parallel"))] + // #[cfg(feature = "parallel")] + // let (left_chunks, right_chunks) = (left.par_chunks(chunk_size), right.par_chunks(chunk_size)); + // #[cfg(not(feature = "parallel"))] let (left_chunks, right_chunks) = (left.chunks(chunk_size), right.chunks(chunk_size)); // Compute all the (partial) pairings and take the product. We have to take the product over