Skip to content
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
2 changes: 1 addition & 1 deletion contracts/near/eth-types/src/eth2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use borsh::{BorshDeserialize, BorshSerialize};
use std::io::{Error, Write};
use tree_hash::MerkleHasher;
use tree_hash::{MerkleHasher, TreeHash};

#[cfg(not(target_arch = "wasm32"))]
use {
Expand Down
27 changes: 14 additions & 13 deletions contracts/near/eth-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use sha3::{Digest, Keccak256, Keccak512};

use std::io::{Error, Write};
#[cfg(feature = "eth2")]
use tree_hash::{PackedEncoding, TreeHash, TreeHashType};
use tree_hash::PackedEncoding;

#[cfg(feature = "eth2")]
pub mod eth2;
Expand Down Expand Up @@ -154,14 +154,15 @@ pub type Signature = H520;

#[derive(Debug, Clone, BorshSerialize, BorshDeserialize, BorshSchema)]
#[cfg_attr(not(target_arch = "wasm32"), derive(Serialize, Deserialize))]
#[cfg_attr(not(target_arch = "wasm32"), serde(rename_all = "camelCase"))]
pub struct BlockHeader {
pub parent_hash: H256,
pub uncles_hash: H256,
pub author: Address,
pub sha3_uncles: H256,
pub miner: Address,
pub state_root: H256,
pub transactions_root: H256,
pub receipts_root: H256,
pub log_bloom: Bloom,
pub logs_bloom: Bloom,
pub difficulty: U256,
#[cfg_attr(
all(feature = "eth2", not(target_arch = "wasm32")),
Expand Down Expand Up @@ -263,12 +264,12 @@ impl BlockHeader {
stream.begin_list(list_size);

stream.append(&self.parent_hash);
stream.append(&self.uncles_hash);
stream.append(&self.author);
stream.append(&self.sha3_uncles);
stream.append(&self.miner);
stream.append(&self.state_root);
stream.append(&self.transactions_root);
stream.append(&self.receipts_root);
stream.append(&self.log_bloom);
stream.append(&self.logs_bloom);
stream.append(&self.difficulty);
stream.append(&self.number);
stream.append(&self.gas_limit);
Expand Down Expand Up @@ -326,12 +327,12 @@ impl RlpDecodable for BlockHeader {
fn decode(serialized: &Rlp) -> Result<Self, RlpDecoderError> {
let mut block_header = BlockHeader {
parent_hash: serialized.val_at(0)?,
uncles_hash: serialized.val_at(1)?,
author: serialized.val_at(2)?,
sha3_uncles: serialized.val_at(1)?,
miner: serialized.val_at(2)?,
state_root: serialized.val_at(3)?,
transactions_root: serialized.val_at(4)?,
receipts_root: serialized.val_at(5)?,
log_bloom: serialized.val_at(6)?,
logs_bloom: serialized.val_at(6)?,
difficulty: serialized.val_at(7)?,
number: serialized.val_at(8)?,
gas_limit: serialized.val_at(9)?,
Expand Down Expand Up @@ -411,7 +412,7 @@ impl rlp::Encodable for LogEntry {
pub struct Receipt {
pub status: bool,
pub gas_used: U256,
pub log_bloom: Bloom,
pub logs_bloom: Bloom,
pub logs: Vec<LogEntry>,
}

Expand All @@ -436,7 +437,7 @@ impl rlp::Decodable for Receipt {
pub struct RlpDeriveReceipt {
pub status: bool,
pub gas_used: U256,
pub log_bloom: Bloom,
pub logs_bloom: Bloom,
pub logs: Vec<LogEntry>,
}

Expand All @@ -445,7 +446,7 @@ impl From<RlpDeriveReceipt> for Receipt {
Self {
status: receipt.status,
gas_used: receipt.gas_used,
log_bloom: receipt.log_bloom,
logs_bloom: receipt.logs_bloom,
logs: receipt.logs,
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/near/eth2-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ rstest = "0.24.0"


[features]
default = ["logs", "mainnet", "bls"]
default = ["logs", "bls"]
bls = []
logs = []
mainnet = []
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions contracts/near/eth2-client/src/data/sepolia/new.json
Git LFS file not shown
21 changes: 8 additions & 13 deletions contracts/near/eth2-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ impl Eth2Client {
#[init]
#[private]
pub fn init(#[serializer(borsh)] args: InitInput) -> Self {
let network =
Network::from_str(args.network.as_str()).unwrap_or_else(|e| env::panic_str(e.as_str()));

#[cfg(feature = "mainnet")]
{
require!(
Expand Down Expand Up @@ -137,7 +134,7 @@ impl Eth2Client {
validate_updates: args.validate_updates,
verify_bls_signatures: args.verify_bls_signatures,
hashes_gc_threshold: args.hashes_gc_threshold,
network,
network: args.network,
finalized_execution_blocks: LookupMap::new(StorageKey::FinalizedExecutionBlocks),
finalized_beacon_header: args.finalized_beacon_header.into(),
finalized_execution_header: LazyOption::new(
Expand Down Expand Up @@ -469,6 +466,7 @@ impl Eth2Client {
// to match the finalized checkpoint root saved in the state of `attested_header`.
let generalized_index =
config.get_generalized_index_constants(update.finalized_header.beacon.slot);
near_sdk::env::log_str(&format!("Generalized index: {:#?}", generalized_index));
require!(
verify_merkle_proof(
H256(update.finalized_header.beacon.tree_hash_root().0.into()),
Expand All @@ -491,17 +489,14 @@ impl Eth2Client {
let generalized_index =
config.get_generalized_index_constants(update.attested_header.beacon.slot);

let sync_committee_update = update
.next_sync_committee
.as_ref()
.unwrap_or_else(|| env::panic_str("The sync committee update is missed"));

require!(
verify_merkle_proof(
H256(
update
.next_sync_committee
.clone()
.unwrap()
.tree_hash_root()
.0
.into()
),
H256(sync_committee_update.tree_hash_root().0.into()),
&update.next_sync_committee_branch.clone().unwrap(),
generalized_index
.sync_committee_tree_depth
Expand Down
5 changes: 3 additions & 2 deletions contracts/near/eth2-client/src/tests/integration_sepolia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ mod sepolia_integration_tests {
use crate::tests::utils::get_sepolia_test_data;
use crate::tests::utils::InitOptions;
use borsh::{BorshDeserialize, BorshSerialize};
use eth2_utility::consensus::Network;
use eth2_utility::types::InitInput;
use eth_types::eth2::{BeaconBlockHeader, SyncCommittee, FinalizedHeader};
use eth_types::eth2::{BeaconBlockHeader, FinalizedHeader, SyncCommittee};
use eth_types::{Address, Bloom, H256, H64, U256};
use near_sdk::{Gas, NearToken};
use near_workspaces::operations::Function;
Expand Down Expand Up @@ -51,7 +52,7 @@ mod sepolia_integration_tests {

#[derive(Clone, BorshDeserialize, BorshSerialize)]
struct InitInputV1 {
pub network: String,
pub network: Network,
pub finalized_execution_header: BlockHeaderV1,
pub finalized_beacon_header: FinalizedHeader,
pub current_sync_committee: SyncCommittee,
Expand Down
Loading
Loading