Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
### 2025-10-17

- Replaces incremental iteration with a one-time precompute method that scans the entire bytecode, building a `BitVec<u8, Msb0>` where bits mark valid `JUMPDEST` positions, skipping `PUSH1..PUSH32` data bytes.
- Updates `is_blacklisted` to O(1) bit lookup.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog shouldn't change. If anything, log that it was recently removed in a new entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_blacklisted's case is particular since it was already dead when that change happened, but I see why we might not want to pretend it never happened

Maybe adding a note or a strikethrough?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that changelog shouldn't be removed, but only appends.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored previous version in 454e767


### 2025-10-14

Expand Down
8 changes: 0 additions & 8 deletions cmd/ethrex/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use ethrex_p2p::{
sync::SyncMode,
types::{Node, NodeRecord},
};
use ethrex_rlp::decode::RLPDecode;
use hex::FromHexError;
use secp256k1::{PublicKey, SecretKey};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -65,13 +64,6 @@ pub fn read_chain_file(chain_rlp_path: &str) -> Vec<Block> {
decode::chain_file(chain_file).expect("Failed to decode chain rlp file")
}

pub fn read_block_file(block_file_path: &str) -> Block {
let encoded_block = std::fs::read(block_file_path)
.unwrap_or_else(|_| panic!("Failed to read block file with path {block_file_path}"));
Block::decode(&encoded_block)
.unwrap_or_else(|_| panic!("Failed to decode block file {block_file_path}"))
}
Comment on lines -68 to -73
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though the import command used this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done by read_chain_file, which is almost identical.


pub fn parse_sync_mode(s: &str) -> eyre::Result<SyncMode> {
match s {
"full" => Ok(SyncMode::Full),
Expand Down
27 changes: 0 additions & 27 deletions crates/common/serde_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use serde::{Deserialize, Deserializer, Serializer, de::Error, ser::SerializeSeq}
pub mod u256 {
use super::*;
use ethereum_types::U256;
use serde_json::Number;

pub mod dec_str {
use super::*;
Expand All @@ -25,32 +24,6 @@ pub mod u256 {
}
}

pub fn deser_number<'de, D>(d: D) -> Result<U256, D::Error>
where
D: Deserializer<'de>,
{
let value = Number::deserialize(d)?.to_string();
U256::from_dec_str(&value).map_err(|e| D::Error::custom(e.to_string()))
}

pub fn deser_number_opt<'de, D>(d: D) -> Result<Option<U256>, D::Error>
where
D: Deserializer<'de>,
{
// Handle the null case explicitly
let opt = Option::<Number>::deserialize(d)?;
match opt {
Some(number) => {
// Convert number to string and parse to U256
let value = number.to_string();
U256::from_dec_str(&value)
.map(Some)
.map_err(|e| D::Error::custom(e.to_string()))
}
None => Ok(None),
}
}

pub fn deser_hex_str<'de, D>(d: D) -> Result<U256, D::Error>
where
D: Deserializer<'de>,
Expand Down
71 changes: 1 addition & 70 deletions crates/common/types/block_execution_witness.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
use std::collections::{BTreeMap, BTreeSet};
use std::fmt;
use std::str::FromStr;

use crate::rkyv_utils::H160Wrapper;
use crate::types::{Block, Code};
use crate::{
constants::EMPTY_KECCACK_HASH,
types::{AccountState, AccountUpdate, BlockHeader, ChainConfig},
utils::decode_hex,
};
use bytes::Bytes;
use ethereum_types::{Address, H256, U256};
use ethrex_crypto::keccak::keccak_hash;
use ethrex_rlp::error::RLPDecodeError;
use ethrex_rlp::{decode::RLPDecode, encode::RLPEncode};
use ethrex_trie::{EMPTY_TRIE_HASH, Node, Trie, TrieError};
use rkyv::with::{Identity, MapKV};
use serde::de::{SeqAccess, Visitor};
use serde::ser::SerializeSeq;
use serde::{Deserialize, Deserializer, Serialize, Serializer, de};
use serde::{Deserialize, Serialize};

/// State produced by the guest program execution inside the zkVM. It is
/// essentially built from the `ExecutionWitness`.
Expand Down Expand Up @@ -460,69 +454,6 @@ impl GuestProgramState {
}
}

pub fn serialize_code<S>(map: &BTreeMap<H256, Bytes>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut seq_serializer = serializer.serialize_seq(Some(map.len()))?;
for (code_hash, code) in map {
let code_hash = format!("0x{}", hex::encode(code_hash));
let code = format!("0x{}", hex::encode(code));

let mut obj = serde_json::Map::new();
obj.insert(code_hash, serde_json::Value::String(code));

seq_serializer.serialize_element(&obj)?;
}
seq_serializer.end()
}

pub fn deserialize_code<'de, D>(deserializer: D) -> Result<BTreeMap<H256, Bytes>, D::Error>
where
D: Deserializer<'de>,
{
struct BytesVecVisitor;

impl<'de> Visitor<'de> for BytesVecVisitor {
type Value = BTreeMap<H256, Bytes>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a list of hex-encoded strings")
}

fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
let mut map = BTreeMap::new();

#[derive(Deserialize)]
struct CodeEntry(BTreeMap<String, String>);

while let Some(CodeEntry(entry)) = seq.next_element::<CodeEntry>()? {
if entry.len() != 1 {
return Err(de::Error::custom(
"Each object must contain exactly one key",
));
}

for (k, v) in entry {
let code_hash =
H256::from_str(k.trim_start_matches("0x")).map_err(de::Error::custom)?;

let bytecode =
decode_hex(v.trim_start_matches("0x")).map_err(de::Error::custom)?;

map.insert(code_hash, Bytes::from(bytecode));
}
}
Ok(map)
}
}

deserializer.deserialize_seq(BytesVecVisitor)
}

fn hash_address(address: &Address) -> Vec<u8> {
keccak_hash(address.to_fixed_bytes()).to_vec()
}
Expand Down
46 changes: 1 addition & 45 deletions crates/common/types/l2/fee_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bytes::Bytes;
use ethereum_types::{Address, H256, U256};
use ethereum_types::Address;
use rkyv::{Archive, Deserialize as RDeserialize, Serialize as RSerialize};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -216,24 +216,6 @@ impl Decoder {
Ok(res)
}

pub fn get_u256(&mut self) -> Result<U256, DecoderError> {
let res = U256::from_big_endian(self.bytes.get(self.offset..self.offset + 32).ok_or(
DecoderError::FailedToDeserializeStateDiff("Not enough bytes".to_string()),
)?);
self.offset += 32;

Ok(res)
}

pub fn get_h256(&mut self) -> Result<H256, DecoderError> {
let res = H256::from_slice(self.bytes.get(self.offset..self.offset + 32).ok_or(
DecoderError::FailedToDeserializeStateDiff("Not enough bytes".to_string()),
)?);
self.offset += 32;

Ok(res)
}

pub fn get_u8(&mut self) -> Result<u8, DecoderError> {
let res = self
.bytes
Expand All @@ -246,23 +228,6 @@ impl Decoder {
Ok(*res)
}

pub fn get_u16(&mut self) -> Result<u16, DecoderError> {
let res = u16::from_be_bytes(
self.bytes
.get(self.offset..self.offset + 2)
.ok_or(DecoderError::FailedToDeserializeStateDiff(
"Not enough bytes".to_string(),
))?
.try_into()
.map_err(|_| {
DecoderError::FailedToDeserializeStateDiff("Cannot parse u16".to_string())
})?,
);
self.offset += 2;

Ok(res)
}

pub fn get_u64(&mut self) -> Result<u64, DecoderError> {
let res = u64::from_be_bytes(
self.bytes
Expand All @@ -279,13 +244,4 @@ impl Decoder {

Ok(res)
}

pub fn get_bytes(&mut self, size: usize) -> Result<Bytes, DecoderError> {
let res = self.bytes.get(self.offset..self.offset + size).ok_or(
DecoderError::FailedToDeserializeStateDiff("Not enough bytes".to_string()),
)?;
self.offset += size;

Ok(Bytes::copy_from_slice(res))
}
}
5 changes: 0 additions & 5 deletions crates/common/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,6 @@ impl EIP4844Transaction {
self.rlp_encode_as_pooled_tx(&mut buf, blobs_bundle);
buf.len()
}
pub fn rlp_encode_as_pooled_tx_to_vec(&self, blobs_bundle: &BlobsBundle) -> Vec<u8> {
let mut buf = Vec::new();
self.rlp_encode_as_pooled_tx(&mut buf, blobs_bundle);
buf
}
}

impl RLPEncode for EIP7702Transaction {
Expand Down
7 changes: 0 additions & 7 deletions crates/l2/common/src/l1_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ pub fn get_l1_message_hash(msg: &L1Message) -> H256 {
keccak(msg.encode())
}

pub fn get_block_l1_message_hashes(receipts: &[Receipt]) -> Vec<H256> {
get_block_l1_messages(receipts)
.iter()
.map(get_l1_message_hash)
.collect()
}

pub fn get_block_l1_messages(receipts: &[Receipt]) -> Vec<L1Message> {
static L1MESSAGE_EVENT_SELECTOR: LazyLock<H256> =
LazyLock::new(|| keccak("L1Message(address,bytes32,uint256)".as_bytes()));
Expand Down
63 changes: 1 addition & 62 deletions crates/l2/networking/rpc/clients.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
use std::str::FromStr;

use crate::l2::batch::RpcBatch;
use bytes::Bytes;
use ethrex_common::Address;
use ethrex_common::H256;
use ethrex_common::U256;
use ethrex_common::types::{AuthorizationList, AuthorizationTupleEntry};
use ethrex_l2_common::l1_messages::L1MessageProof;
use ethrex_rpc::clients::eth::errors::GetL1BlobBaseFeeRequestError;
use ethrex_rpc::clients::eth::errors::GetL1FeeVaultAddressError;
use ethrex_rpc::clients::eth::errors::GetOperatorFeeError;
use ethrex_rpc::clients::eth::errors::GetOperatorFeeVaultAddressError;
use ethrex_rpc::clients::eth::errors::SendEthrexTransactionError;
use ethrex_rpc::types::block_identifier::BlockIdentifier;
use ethrex_rpc::{
EthClient,
clients::{
EthClientError,
eth::{
RpcResponse,
errors::{
GetBaseFeeVaultAddressError, GetBatchByNumberError, GetBatchNumberError,
GetMessageProofError,
},
errors::{GetBaseFeeVaultAddressError, GetBatchNumberError, GetMessageProofError},
},
},
utils::RpcRequest,
};
use hex;
use serde_json::json;

pub async fn get_message_proof(
Expand All @@ -47,23 +37,6 @@ pub async fn get_message_proof(
}
}

pub async fn get_batch_by_number(
client: &EthClient,
batch_number: u64,
) -> Result<RpcBatch, EthClientError> {
let params = Some(vec![json!(format!("{batch_number:#x}")), json!(true)]);
let request = RpcRequest::new("ethrex_getBatchByNumber", params);

match client.send_request(request).await? {
RpcResponse::Success(result) => serde_json::from_value(result.result)
.map_err(GetBatchByNumberError::SerdeJSONError)
.map_err(EthClientError::from),
RpcResponse::Error(error_response) => {
Err(GetBatchByNumberError::RPCError(error_response.error.message).into())
}
}
}

pub async fn get_batch_number(client: &EthClient) -> Result<u64, EthClientError> {
let request = RpcRequest::new("ethrex_batchNumber", None);

Expand Down Expand Up @@ -169,37 +142,3 @@ pub async fn get_l1_blob_base_fee_per_gas(
}
}
}

pub async fn send_ethrex_transaction(
client: &EthClient,
to: Address,
data: Bytes,
authorization_list: Option<AuthorizationList>,
) -> Result<H256, EthClientError> {
let authorization_list = authorization_list.map(|list| {
list.iter()
.map(AuthorizationTupleEntry::from)
.collect::<Vec<_>>()
});

let payload = json!({
"to": format!("{to:#x}"),
"data": format!("0x{}", hex::encode(data)),
"authorizationList": authorization_list,
});
let request = RpcRequest::new("ethrex_sendTransaction", Some(vec![payload]));

match client.send_request(request).await? {
RpcResponse::Success(result) => {
let tx_hash_str: String = serde_json::from_value(result.result)
.map_err(SendEthrexTransactionError::SerdeJSONError)
.map_err(EthClientError::from)?;
H256::from_str(&tx_hash_str)
.map_err(|e| SendEthrexTransactionError::ParseHashError(e.to_string()))
.map_err(EthClientError::from)
}
RpcResponse::Error(error_response) => {
Err(SendEthrexTransactionError::RPCError(error_response.error.message).into())
}
}
}
Loading