Skip to content

Commit 22f3db8

Browse files
karim-enfrolvanya
andauthored
chore: remove bls flag and some getter (#947)
* chore: remove bls flag and some getter * fix: issues found during review --------- Co-authored-by: Ivan Frolov <frolvanya@gmail.com>
1 parent f537d96 commit 22f3db8

File tree

8 files changed

+34
-45
lines changed

8 files changed

+34
-45
lines changed

β€Žcontracts/near/Cargo.lockβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žcontracts/near/eth2-client/Cargo.tomlβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "eth2-client"
3-
version = "0.5.0"
3+
version = "0.6.0"
44
authors = ["Aurora <hello@aurora.dev>"]
55
edition = "2021"
66
repository.workspace = true
@@ -53,7 +53,6 @@ rstest = "0.24.0"
5353

5454

5555
[features]
56-
default = ["logs", "mainnet", "bls"]
57-
bls = []
56+
default = ["logs", "mainnet"]
5857
logs = []
5958
mainnet = []

β€Žcontracts/near/eth2-client/src/lib.rsβ€Ž

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@ use near_sdk::{
1818
};
1919
use tree_hash::TreeHash;
2020

21-
#[cfg(feature = "bls")]
2221
use amcl::bls381::bls381::utils::serialize_uncompressed_g1;
23-
#[cfg(feature = "bls")]
2422
use amcl::bls381::ecp::ECP;
25-
#[cfg(feature = "bls")]
2623
use amcl::bls381::fp2::FP2;
27-
#[cfg(feature = "bls")]
2824
use amcl::bls381::hash_to_curve::hash_to_field_fp2;
2925

3026
mod migrate;
@@ -111,7 +107,7 @@ impl Eth2Client {
111107
);
112108

113109
require!(
114-
(cfg!(feature = "bls") && args.verify_bls_signatures)
110+
args.verify_bls_signatures
115111
|| args.trusted_signer.is_some(),
116112
"The client can't be executed in the trustless mode without BLS sigs verification on Mainnet"
117113
);
@@ -360,28 +356,16 @@ impl Eth2Client {
360356
self.trusted_signer = trusted_signer;
361357
}
362358

363-
pub fn get_trusted_signer(&self) -> Option<AccountId> {
364-
self.trusted_signer.clone()
365-
}
366-
367359
#[access_control_any(roles(Role::DAO))]
368360
pub fn update_trusted_blocks_submitter(&mut self, trusted_blocks_submitter: Option<AccountId>) {
369361
self.trusted_blocks_submitter = trusted_blocks_submitter;
370362
}
371363

372-
pub fn get_trusted_blocks_submitter(&self) -> Option<AccountId> {
373-
self.trusted_blocks_submitter.clone()
374-
}
375-
376364
#[access_control_any(roles(Role::DAO))]
377365
pub fn update_hashes_gc_threshold(&mut self, hashes_gc_threshold: u64) {
378366
self.hashes_gc_threshold = hashes_gc_threshold;
379367
}
380368

381-
pub fn get_hashes_gc_threshold(&self) -> u64 {
382-
self.hashes_gc_threshold
383-
}
384-
385369
#[access_control_any(roles(Role::DAO))]
386370
pub fn attach_full_access_key(&self, public_key: PublicKey) -> Promise {
387371
Promise::new(env::current_account_id()).add_full_access_key(public_key)
@@ -392,6 +376,17 @@ impl Eth2Client {
392376
self.verify_bls_signatures = enabled;
393377
}
394378

379+
pub fn get_config(self) -> ContractConfig {
380+
ContractConfig {
381+
trusted_signer: self.trusted_signer,
382+
validate_updates: self.validate_updates,
383+
verify_bls_signatures: self.verify_bls_signatures,
384+
hashes_gc_threshold: self.hashes_gc_threshold,
385+
network: self.network,
386+
trusted_blocks_submitter: self.trusted_blocks_submitter,
387+
}
388+
}
389+
395390
pub fn version(&self) -> String {
396391
env!("CARGO_PKG_VERSION").to_owned()
397392
}
@@ -424,7 +419,6 @@ impl Eth2Client {
424419
)
425420
);
426421

427-
#[cfg(feature = "bls")]
428422
if self.verify_bls_signatures {
429423
self.verify_bls_signatures(update, sync_committee_bits, finalized_period);
430424
}
@@ -527,7 +521,6 @@ impl Eth2Client {
527521
}
528522
}
529523

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

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

580574
let mut msg_fp2_0 = [0u8; 96];
581575
let mut msg_fp2_1 = [0u8; 96];
@@ -688,7 +682,6 @@ impl Eth2Client {
688682
Some(head_block_number - tail_block_number)
689683
}
690684

691-
#[cfg(feature = "bls")]
692685
fn fp2_to_u8(u: &FP2, out: &mut [u8; 96]) {
693686
u.getb().to_byte_array(&mut out[0..48], 0);
694687
u.geta().to_byte_array(&mut out[48..96], 0);

β€Žcontracts/near/eth2-client/src/tests/unit_tests.rsβ€Ž

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -480,21 +480,5 @@ mod tests {
480480

481481
Eth2Client::init(init_input);
482482
}
483-
484-
#[test]
485-
#[cfg_attr(feature = "bls", ignore)]
486-
#[should_panic(
487-
expected = "The client can't be executed in the trustless mode without BLS sigs verification on Mainnet"
488-
)]
489-
pub fn test_panic_on_init_in_trustless_mode_without_bls_feature_flag() {
490-
let (_headers, _updates, init_input) = get_test_data(Some(InitOptions {
491-
validate_updates: true,
492-
verify_bls_signatures: true,
493-
hashes_gc_threshold: 500,
494-
trusted_signer: None,
495-
}));
496-
497-
Eth2Client::init(init_input);
498-
}
499483
}
500484
}

β€Žcontracts/near/eth2-client/test.shβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ cargo near build non-reproducible-wasm --no-abi --no-default-features --features
55
RUST_BACKTRACE=1 cargo test --jobs 8 --package eth2-client -- --nocapture
66

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

β€Žcontracts/near/eth2-utility/src/consensus.rsβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use bitvec::prelude::BitVec;
55
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
66
use eth_types::eth2::*;
77
use eth_types::H256;
8+
use near_sdk::near;
89
use tree_hash::TreeHash;
910

1011
pub const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: u64 = 256;
@@ -28,7 +29,8 @@ pub struct GeneralizedIndex {
2829
pub sync_committee_tree_index: u32,
2930
}
3031

31-
#[derive(PartialEq, BorshSerialize, BorshDeserialize, BorshSchema)]
32+
#[derive(PartialEq, BorshSerialize, BorshDeserialize, BorshSchema, Clone, Copy, Debug)]
33+
#[near(serializers=[json])]
3234
pub enum Network {
3335
Mainnet,
3436
Goerli,

β€Žcontracts/near/eth2-utility/src/types.rsβ€Ž

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use eth_types::H256;
44
use near_sdk::near;
55
use near_sdk::AccountId;
66

7+
use crate::consensus::Network;
8+
79
/// Minimal information about a header.
810
#[derive(Clone)]
911
#[near(serializers=[borsh])]
@@ -32,3 +34,14 @@ pub enum ClientMode {
3234
SubmitLightClientUpdate,
3335
SubmitHeader,
3436
}
37+
38+
#[derive(Clone)]
39+
#[near(serializers=[json])]
40+
pub struct ContractConfig {
41+
pub trusted_signer: Option<AccountId>,
42+
pub validate_updates: bool,
43+
pub verify_bls_signatures: bool,
44+
pub hashes_gc_threshold: u64,
45+
pub network: Network,
46+
pub trusted_blocks_submitter: Option<AccountId>,
47+
}
43.5 KB
Binary file not shown.

0 commit comments

Comments
Β (0)