Skip to content
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: 1 addition & 1 deletion contracts/near/Cargo.lock

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

5 changes: 2 additions & 3 deletions contracts/near/eth2-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "eth2-client"
version = "0.5.0"
version = "0.6.0"
authors = ["Aurora <hello@aurora.dev>"]
edition = "2021"
repository.workspace = true
Expand Down Expand Up @@ -53,7 +53,6 @@ rstest = "0.24.0"


[features]
default = ["logs", "mainnet", "bls"]
bls = []
default = ["logs", "mainnet"]
logs = []
mainnet = []
37 changes: 15 additions & 22 deletions contracts/near/eth2-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ use near_sdk::{
};
use tree_hash::TreeHash;

#[cfg(feature = "bls")]
use amcl::bls381::bls381::utils::serialize_uncompressed_g1;
#[cfg(feature = "bls")]
use amcl::bls381::ecp::ECP;
#[cfg(feature = "bls")]
use amcl::bls381::fp2::FP2;
#[cfg(feature = "bls")]
use amcl::bls381::hash_to_curve::hash_to_field_fp2;

mod migrate;
Expand Down Expand Up @@ -111,7 +107,7 @@ impl Eth2Client {
);

require!(
(cfg!(feature = "bls") && args.verify_bls_signatures)
args.verify_bls_signatures
|| args.trusted_signer.is_some(),
"The client can't be executed in the trustless mode without BLS sigs verification on Mainnet"
);
Expand Down Expand Up @@ -360,28 +356,16 @@ impl Eth2Client {
self.trusted_signer = trusted_signer;
}

pub fn get_trusted_signer(&self) -> Option<AccountId> {
self.trusted_signer.clone()
}

#[access_control_any(roles(Role::DAO))]
pub fn update_trusted_blocks_submitter(&mut self, trusted_blocks_submitter: Option<AccountId>) {
self.trusted_blocks_submitter = trusted_blocks_submitter;
}

pub fn get_trusted_blocks_submitter(&self) -> Option<AccountId> {
self.trusted_blocks_submitter.clone()
}

#[access_control_any(roles(Role::DAO))]
pub fn update_hashes_gc_threshold(&mut self, hashes_gc_threshold: u64) {
self.hashes_gc_threshold = hashes_gc_threshold;
}

pub fn get_hashes_gc_threshold(&self) -> u64 {
self.hashes_gc_threshold
}

#[access_control_any(roles(Role::DAO))]
pub fn attach_full_access_key(&self, public_key: PublicKey) -> Promise {
Promise::new(env::current_account_id()).add_full_access_key(public_key)
Expand All @@ -392,6 +376,17 @@ impl Eth2Client {
self.verify_bls_signatures = enabled;
}

pub fn get_config(self) -> ContractConfig {
Comment thread
karim-en marked this conversation as resolved.
ContractConfig {
trusted_signer: self.trusted_signer,
validate_updates: self.validate_updates,
verify_bls_signatures: self.verify_bls_signatures,
hashes_gc_threshold: self.hashes_gc_threshold,
network: self.network,
trusted_blocks_submitter: self.trusted_blocks_submitter,
}
}

pub fn version(&self) -> String {
env!("CARGO_PKG_VERSION").to_owned()
}
Expand Down Expand Up @@ -424,7 +419,6 @@ impl Eth2Client {
)
);

#[cfg(feature = "bls")]
if self.verify_bls_signatures {
self.verify_bls_signatures(update, sync_committee_bits, finalized_period);
}
Expand Down Expand Up @@ -527,7 +521,6 @@ impl Eth2Client {
}
}

#[cfg(feature = "bls")]
fn verify_bls_signatures(
&self,
update: &LightClientUpdate,
Expand Down Expand Up @@ -574,8 +567,9 @@ impl Eth2Client {
let signature_bytes = update.sync_aggregate.sync_committee_signature.0.to_vec();

let dst: &[u8] = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_";
let msg_fp2 = hash_to_field_fp2(msg_bytes.as_slice(), 2, dst)
.expect("hash to field should not fail for given parameters");
let msg_fp2 = hash_to_field_fp2(msg_bytes.as_slice(), 2, dst).unwrap_or_else(|_| {
env::panic_str("hash to field should not fail for given parameters")
});

let mut msg_fp2_0 = [0u8; 96];
let mut msg_fp2_1 = [0u8; 96];
Expand Down Expand Up @@ -688,7 +682,6 @@ impl Eth2Client {
Some(head_block_number - tail_block_number)
}

#[cfg(feature = "bls")]
fn fp2_to_u8(u: &FP2, out: &mut [u8; 96]) {
u.getb().to_byte_array(&mut out[0..48], 0);
u.geta().to_byte_array(&mut out[48..96], 0);
Expand Down
16 changes: 0 additions & 16 deletions contracts/near/eth2-client/src/tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,21 +480,5 @@ mod tests {

Eth2Client::init(init_input);
}

#[test]
#[cfg_attr(feature = "bls", ignore)]
#[should_panic(
expected = "The client can't be executed in the trustless mode without BLS sigs verification on Mainnet"
)]
pub fn test_panic_on_init_in_trustless_mode_without_bls_feature_flag() {
let (_headers, _updates, init_input) = get_test_data(Some(InitOptions {
validate_updates: true,
verify_bls_signatures: true,
hashes_gc_threshold: 500,
trusted_signer: None,
}));

Eth2Client::init(init_input);
}
}
}
2 changes: 0 additions & 2 deletions contracts/near/eth2-client/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ cargo near build non-reproducible-wasm --no-abi --no-default-features --features
RUST_BACKTRACE=1 cargo test --jobs 8 --package eth2-client -- --nocapture

RUST_BACKTRACE=1 cargo test --no-default-features --jobs 8 --package eth2-client -- --nocapture

RUST_BACKTRACE=1 cargo test --no-default-features --features bls --jobs 8 --package eth2-client -- --nocapture
4 changes: 3 additions & 1 deletion contracts/near/eth2-utility/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bitvec::prelude::BitVec;
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use eth_types::eth2::*;
use eth_types::H256;
use near_sdk::near;
use tree_hash::TreeHash;

pub const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: u64 = 256;
Expand All @@ -28,7 +29,8 @@ pub struct GeneralizedIndex {
pub sync_committee_tree_index: u32,
}

#[derive(PartialEq, BorshSerialize, BorshDeserialize, BorshSchema)]
#[derive(PartialEq, BorshSerialize, BorshDeserialize, BorshSchema, Clone, Copy, Debug)]
#[near(serializers=[json])]
pub enum Network {
Mainnet,
Goerli,
Expand Down
13 changes: 13 additions & 0 deletions contracts/near/eth2-utility/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use eth_types::H256;
use near_sdk::near;
use near_sdk::AccountId;

use crate::consensus::Network;

/// Minimal information about a header.
#[derive(Clone)]
#[near(serializers=[borsh])]
Expand Down Expand Up @@ -32,3 +34,14 @@ pub enum ClientMode {
SubmitLightClientUpdate,
SubmitHeader,
}

#[derive(Clone)]
#[near(serializers=[json])]
pub struct ContractConfig {
pub trusted_signer: Option<AccountId>,
pub validate_updates: bool,
pub verify_bls_signatures: bool,
pub hashes_gc_threshold: u64,
pub network: Network,
pub trusted_blocks_submitter: Option<AccountId>,
}
Binary file modified contracts/near/res/eth2_client.wasm
Binary file not shown.
Loading