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

wip eth indexer #929

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
357 changes: 336 additions & 21 deletions chain-signatures/Cargo.lock

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion chain-signatures/crypto-shared/src/kdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use k256::{
Scalar, Secp256k1, SecretKey,
};
use near_account_id::AccountId;
use sha3::{Digest, Sha3_256};
use sha3::{Digest, Keccak256, Sha3_256};

// Constant prefix that ensures epsilon derivation values are used specifically for
// near-mpc-recovery with key derivation protocol vX.Y.Z.
Expand All @@ -28,6 +28,15 @@ pub fn derive_epsilon(predecessor_id: &AccountId, path: &str) -> Scalar {
Scalar::from_non_biased(hash)
}

const EPSILON_DERIVATION_PREFIX_ETH: &str = "near-mpc-recovery v0.2.0 epsilon derivation:";
pub fn derive_epsilon_eth(requester: String, path: &str) -> Scalar {
let derivation_path = format!("{EPSILON_DERIVATION_PREFIX_ETH}{},{}", requester, path);
let mut hasher = Keccak256::new();
hasher.update(derivation_path);
let hash: [u8; 32] = hasher.finalize().into();
Scalar::from_non_biased(hash)
}

pub fn derive_key(public_key: PublicKey, epsilon: Scalar) -> PublicKey {
(<Secp256k1 as CurveArithmetic>::ProjectivePoint::GENERATOR * epsilon + public_key).to_affine()
}
Expand Down
1 change: 1 addition & 0 deletions chain-signatures/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ tokio-retry = "0.3"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-stackdriver = "0.10.0"
web3 = "0.19.0"
url = { version = "2.4.0", features = ["serde"] }

near-account-id = "1.0.0"
Expand Down
17 changes: 16 additions & 1 deletion chain-signatures/node/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::config::{Config, LocalConfig, NetworkConfig, OverrideConfig};
use crate::gcp::GcpService;
use crate::protocol::{MpcSignProtocol, SignQueue};
use crate::{http_client, indexer, mesh, storage, web};
use crate::{http_client, indexer, indexer_eth, mesh, storage, web};
use clap::Parser;
use deadpool_redis::Runtime;
use local_ip_address::local_ip;
Expand Down Expand Up @@ -51,6 +51,9 @@ pub enum Cli {
/// NEAR Lake Indexer options
#[clap(flatten)]
indexer_options: indexer::Options,
/// Ethereum Indexer options
#[clap(flatten)]
indexer_eth_options: indexer_eth::Options,
/// Local address that other peers can use to message this node.
#[arg(long, env("MPC_LOCAL_ADDRESS"))]
my_address: Option<Url>,
Expand Down Expand Up @@ -83,6 +86,7 @@ impl Cli {
cipher_sk,
sign_sk,
indexer_options,
indexer_eth_options,
my_address,
storage_options,
override_config,
Expand Down Expand Up @@ -127,6 +131,7 @@ impl Cli {
}

args.extend(indexer_options.into_str_args());
args.extend(indexer_eth_options.into_str_args());
args.extend(storage_options.into_str_args());
args.extend(mesh_options.into_str_args());
args.extend(message_options.into_str_args());
Expand Down Expand Up @@ -182,6 +187,7 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> {
cipher_sk,
sign_sk,
indexer_options,
indexer_eth_options,
my_address,
storage_options,
override_config,
Expand All @@ -203,6 +209,13 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> {
&gcp_service,
&rt,
)?;
let (eth_indexer_handle, eth_indexer) = indexer_eth::run(
&indexer_eth_options,
&account_id,
&sign_queue,
&gcp_service,
&rt,
)?;

let key_storage =
storage::secret_storage::init(Some(&gcp_service), &storage_options, &account_id);
Expand Down Expand Up @@ -274,6 +287,8 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> {
tracing::info!("spinning down");

indexer_handle.join().unwrap()?;
eth_indexer_handle.join().unwrap()?;

anyhow::Ok(())
})?;
}
Expand Down
3 changes: 2 additions & 1 deletion chain-signatures/node/src/indexer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::gcp::error::DatastoreStorageError;
use crate::gcp::GcpService;
use crate::protocol::{SignQueue, SignRequest};
use crate::protocol::{Chain, SignQueue, SignRequest};
use crate::types::LatestBlockHeight;
use crypto_shared::{derive_epsilon, ScalarExt};
use k256::Scalar;
Expand Down Expand Up @@ -257,6 +257,7 @@ async fn handle_block(
entropy,
// TODO: use indexer timestamp instead.
time_added: Instant::now(),
chain: Chain::NEAR,
});
}
}
Expand Down
Loading
Loading