Skip to content

Commit

Permalink
Bls Keystore and Mnemonic (#72)
Browse files Browse the repository at this point in the history
This PR integrates https://github.com/Layr-Labs/rust-bls-bn254 

- [x] [Keystore]

- [x] [Mnemonic]

---------

Co-authored-by: ricomateo <mrico@fi.uba.ar>
Co-authored-by: tomasarrachea <tomas.arrachea@lambdaclass.com>
Co-authored-by: Pablo Deymonnaz <deymonnaz@gmail.com>
Co-authored-by: Mateo Rico <ricomateo@users.noreply.github.com>
Co-authored-by: Pablo Deymonnaz <pdeymon@fi.uba.ar>
Co-authored-by: supernovahs <supernovahs@proton.me>
  • Loading branch information
7 people authored Aug 16, 2024
1 parent ed99b9b commit 5d9a2cc
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 25 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/contracts/bindings/utils/middleware
Submodule middleware updated 54 files
+0 −3 .gitmodules
+29 −3 LICENSE
+24 −10 README.md
+ audits/M2 Mainnet - Dedaub - Feb 2024.pdf
+2 −2 docs/README.md
+1 −1 docs/ServiceManagerBase.md
+1 −1 docs/experimental/AVS-Guide.md
+1 −0 foundry.toml
+0 −1 lib/ds-test
+1 −1 lib/eigenlayer-contracts
+1 −1 lib/forge-std
+8 −4 src/BLSApkRegistry.sol
+116 −62 src/BLSSignatureChecker.sol
+175 −0 src/EjectionManager.sol
+5 −1 src/IndexRegistry.sol
+33 −0 src/OperatorStateRetriever.sol
+52 −9 src/RegistryCoordinator.sol
+6 −1 src/RegistryCoordinatorStorage.sol
+93 −28 src/ServiceManagerBase.sol
+53 −0 src/ServiceManagerBaseStorage.sol
+3 −3 src/ServiceManagerRouter.sol
+22 −10 src/StakeRegistry.sol
+24 −3 src/interfaces/IECDSAStakeRegistryEventsAndErrors.sol
+55 −0 src/interfaces/IEjectionManager.sol
+15 −41 src/interfaces/IServiceManager.sol
+61 −0 src/interfaces/IServiceManagerUI.sol
+283 −0 src/unaudited/ECDSAServiceManagerBase.sol
+204 −75 src/unaudited/ECDSAStakeRegistry.sol
+10 −3 src/unaudited/ECDSAStakeRegistryStorage.sol
+14 −10 src/unaudited/examples/ECDSAStakeRegistryPermissioned.sol
+69 −0 test/events/IServiceManagerBaseEvents.sol
+1 −1 test/ffi/BLSPubKeyCompendiumFFI.t.sol
+6 −1 test/integration/CoreRegistration.t.sol
+117 −61 test/integration/IntegrationDeployer.t.sol
+1 −1 test/integration/TimeMachine.t.sol
+4 −2 test/integration/User.t.sol
+3 −3 test/mocks/DelegationMock.sol
+22 −0 test/mocks/ECDSAServiceManagerMock.sol
+14 −0 test/mocks/ECDSAStakeRegistryMock.sol
+78 −0 test/mocks/RewardsCoordinatorMock.sol
+9 −3 test/mocks/ServiceManagerMock.sol
+368 −146 test/unit/BLSApkRegistryUnit.t.sol
+1 −1 test/unit/BitmapUtils.t.sol
+186 −0 test/unit/ECDSAServiceManager.t.sol
+60 −14 test/unit/ECDSAStakeRegistryEqualWeightUnit.t.sol
+48 −16 test/unit/ECDSAStakeRegistryPermissionedUnit.t.sol
+472 −105 test/unit/ECDSAStakeRegistryUnit.t.sol
+399 −0 test/unit/EjectionManagerUnit.t.sol
+266 −110 test/unit/OperatorStateRetrieverUnit.t.sol
+56 −0 test/unit/RegistryCoordinatorUnit.t.sol
+527 −0 test/unit/ServiceManagerBase.t.sol
+1 −0 test/unit/ServiceManagerRouter.t.sol
+820 −411 test/unit/StakeRegistryUnit.t.sol
+122 −91 test/utils/MockAVSDeployer.sol
2 changes: 2 additions & 0 deletions crates/eigen-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ark-ec.workspace = true
ark-ff.workspace = true
ark-serialize.workspace = true
clap.workspace = true
colored = "2.1.0"
eigen-crypto-bls.workspace = true
eigen-testing-utils.workspace = true
eigen-types.workspace = true
Expand All @@ -25,6 +26,7 @@ k256.workspace = true
num-bigint.workspace = true
rand.workspace = true
rand_core.workspace = true
rust-bls-bn254.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
Expand Down
79 changes: 78 additions & 1 deletion crates/eigen-cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use crate::ANVIL_RPC_URL;
use alloy_primitives::Address;
use clap::{ArgGroup, Parser, Subcommand};

use rust_bls_bn254::{
CHINESE_SIMPLIFIED_WORD_LIST, CHINESE_TRADITIONAL_WORD_LIST, CZECH_WORD_LIST,
ENGLISH_WORD_LIST, ITALIAN_WORD_LIST, KOREAN_WORD_LIST, PORTUGUESE_WORD_LIST,
SPANISH_WORD_LIST,
};
#[derive(Parser, Debug)]
#[command(
about = "Eigenlayer CLI tools",
Expand Down Expand Up @@ -102,10 +106,83 @@ It creates the following artifacts based on arguments
#[arg(long, help = "password to encrypt key")]
password: Option<String>,
},

#[command(
about = "Using Pbkfd2 / scrypt encryption to secure the bls key.",
alias = "b"
)]
BlsConvert {
#[arg(long, help = "Bls keystore type (pbkdf2 or scrypt)")]
#[clap(value_enum)]
key_type: BlsKeystoreType,

#[arg(long, help = "bls key to encrypt in hex")]
secret_key: String,

#[arg(long, help = "file path to store key")]
output_path: String,

#[arg(long, help = "password to encrypt key(default is empty string)")]
password: Option<String>,
},
#[command(about = "Create a new mnemonic from default word lists", alias = "md")]
CreateNewMnemonicFromDefaultWordList {
#[arg(long, help = "Mnemonic language select")]
#[clap(value_enum)]
language: MnemonicLanguage,
},
#[command(
about = "Create a new mnemonic from given word list at path",
alias = "mp"
)]
CreateNewMnemonicFromPath {
#[arg(long, help = "Mnemonic language select")]
#[clap(value_enum)]
language: MnemonicLanguage,
#[arg(long, help = "Path to a the directory where lists are stored)")]
path: String,
},
}

#[derive(clap::ValueEnum, Debug, Clone)]
pub enum KeyType {
Ecdsa,
Bls,
}

#[derive(clap::ValueEnum, Debug, Clone)]
pub enum BlsKeystoreType {
Pbkdf2,
Scrypt,
}

#[derive(clap::ValueEnum, Debug, Clone)]
pub enum MnemonicLanguage {
English,
ChineseSimplified,
ChineseTraditional,
Italian,
Czech,
Korean,
Portuguese,
Spanish,
}

impl MnemonicLanguage {
pub fn try_from(&self) -> (&str, &str) {
match self {
MnemonicLanguage::English => ("english", ENGLISH_WORD_LIST),
MnemonicLanguage::ChineseSimplified => {
("chinese_simplified", CHINESE_SIMPLIFIED_WORD_LIST)
}
MnemonicLanguage::ChineseTraditional => {
("chinese_traditional", CHINESE_TRADITIONAL_WORD_LIST)
}
MnemonicLanguage::Italian => ("italian", ITALIAN_WORD_LIST),
MnemonicLanguage::Czech => ("czech", CZECH_WORD_LIST),
MnemonicLanguage::Korean => ("korean", KOREAN_WORD_LIST),
MnemonicLanguage::Portuguese => ("portuguese", PORTUGUESE_WORD_LIST),
MnemonicLanguage::Spanish => ("spanish", SPANISH_WORD_LIST),
}
}
}
60 changes: 60 additions & 0 deletions crates/eigen-cli/src/bls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use crate::args::BlsKeystoreType;
use crate::EigenBlsKeyStoreError;
use rust_bls_bn254::keystores::{pbkdf2_keystore::Pbkdf2Keystore, scrypt_keystore::ScryptKeystore};

/// BlsKeystore
pub enum BlsKeystore {
Pbkdf2,
Scrypt,
}

impl BlsKeystore {
/// Create a new [`BlsKeystore`] instance.
/// [`BlsKeystore::Pbkdft`] or [`BlsKeystore::Scrypt`]
pub fn new_keystore(
self,
secret_key: String,
output_path: String,
password: Option<&str>,
) -> Result<(), EigenBlsKeyStoreError> {
match self {
BlsKeystore::Pbkdf2 => {
let key_hex = hex::decode(secret_key)?;
let bls_key = key_hex.as_slice();
let mut keystore = Pbkdf2Keystore::new();
keystore.encrypt(
bls_key,
password.unwrap_or_default(),
&output_path.to_string(),
None,
None,
)?;
keystore.to_keystore().save(&output_path.to_string())?;
Ok(())
}
BlsKeystore::Scrypt => {
let key_hex = hex::decode(secret_key)?;
let bls_key = key_hex.as_slice();
let mut keystore = ScryptKeystore::new();
keystore.encrypt(
bls_key,
password.unwrap_or_default(),
&output_path.to_string(),
None,
None,
)?;
keystore.to_keystore().save(&output_path.to_string())?;
Ok(())
}
}
}
}

impl From<BlsKeystoreType> for BlsKeystore {
fn from(value: BlsKeystoreType) -> Self {
match value {
BlsKeystoreType::Pbkdf2 => BlsKeystore::Pbkdf2,
BlsKeystoreType::Scrypt => BlsKeystore::Scrypt,
}
}
}
Loading

0 comments on commit 5d9a2cc

Please sign in to comment.