Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from semiotic-ai/joseph/tru-199-update-depende…
Browse files Browse the repository at this point in the history
…ncies-on-reth

Update dependencies on reth and revm
  • Loading branch information
suchapalaver authored Aug 7, 2024
2 parents 780707e + 3a287f0 commit 8d6de8a
Show file tree
Hide file tree
Showing 11 changed files with 757 additions and 801 deletions.
1,422 changes: 694 additions & 728 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 13 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.72"
alloy-primitives = "0.7.7"
alloy-rlp = "0.3.7"
bincode = "1.3.3"
clap = { version = "4.3.21", features = ["derive"] }
revm-primitives = "=1.1.2"
prost = "0.12.3"
prost-types = "0.12.3"
rand = "0.8.5"
reth-primitives = { git = "https://github.com/paradigmxyz/reth", version = "=0.1.0-alpha.4", tag = "v0.1.0-alpha.4" }
reth-rlp = { git = "https://github.com/paradigmxyz/reth", version = "=0.1.0-alpha.4", tag = "v0.1.0-alpha.4" }
thiserror = "1.0.44"
serde_json = "1.0.108"
rayon = "1.8.0"
reth-primitives = { git = "https://github.com/paradigmxyz/reth", version = "1.0.1", tag = "v1.0.1" }
reth-trie-common = { git = "https://github.com/paradigmxyz/reth", version = "1.0.1", tag = "v1.0.1" }
revm-primitives = "=6.0.0"
serde = { version = "1.0.196", features = ["derive"] }
zstd = "0.13.0"
serde_json = "1.0.108"
sf-protos = { git = "https://github.com/semiotic-ai/sf-protos.git", version = "0.1.0" }
simple-log = "1.6.0"
rayon = "1.8.0"
ethereum-types = "=0.14.1"
bincode = "1.3.3"
thiserror = "1.0.44"
tokio = { version = "1.35.0", features = ["full"] }
sf-protos = { git = "https://github.com/semiotic-ai/sf-protos.git", version = "0.1.0" }

prost = "0.12.3"
prost-types = "0.12.3"
zstd = "0.13.0"

[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
Expand Down
6 changes: 3 additions & 3 deletions src/headers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
pub mod error;

use crate::headers::error::BlockHeaderError;
use reth_primitives::H256;
use reth_primitives::B256;
use serde::{Deserialize, Serialize};
use sf_protos::ethereum::r#type::v2::{Block, BlockHeader};
use std::fs::File;

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct BlockHeaderRoots {
pub receipt_root: H256,
pub transactions_root: H256,
pub receipt_root: B256,
pub transactions_root: B256,
}

impl TryFrom<BlockHeader> for BlockHeaderRoots {
Expand Down
19 changes: 8 additions & 11 deletions src/receipts/logs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::receipts::error::ReceiptError;
use reth_primitives::{hex, Address, Bytes, Log, H256};
use reth_primitives::{hex, Address, Bytes, Log, LogData, B256};
use std::convert::TryInto;

// type BlockLog = crate::protos::block::Log;
use sf_protos::ethereum::r#type::v2::Log as BlockLog;

pub fn map_logs(logs: &[BlockLog]) -> Result<Vec<Log>, ReceiptError> {
Expand All @@ -18,23 +17,21 @@ pub fn block_log_to_log(log: &BlockLog) -> Result<Log, ReceiptError> {

let address = Address::from(slice);
let topics = map_topics(&log.topics)?;
let data = Bytes::from(log.data.as_slice());
let log_data = Bytes::copy_from_slice(log.data.as_slice());

Ok(Log {
address,
topics,
data,
})
let data = LogData::new_unchecked(topics, log_data);

Ok(Log { address, data })
}

fn map_topics(topics: &[Vec<u8>]) -> Result<Vec<H256>, ReceiptError> {
fn map_topics(topics: &[Vec<u8>]) -> Result<Vec<B256>, ReceiptError> {
topics.iter().map(map_topic).collect()
}

fn map_topic(topic: &Vec<u8>) -> Result<H256, ReceiptError> {
fn map_topic(topic: &Vec<u8>) -> Result<B256, ReceiptError> {
let slice: [u8; 32] = topic
.as_slice()
.try_into()
.map_err(|_| ReceiptError::InvalidTopic(hex::encode(topic)))?;
Ok(H256::from(slice))
Ok(B256::from(slice))
}
23 changes: 10 additions & 13 deletions src/receipts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ pub mod error;
pub mod logs;
pub mod receipt;

// use crate::protos::block::Block;
use crate::receipts::error::ReceiptError;
use crate::receipts::receipt::FullReceipt;
use reth_primitives::bytes::BufMut;
use reth_primitives::hex;
use reth_primitives::proofs::ordered_trie_root_with_encoder;
use reth_rlp::Encodable;
use revm_primitives::B256;
use alloy_rlp::{Encodable, Header};
use reth_primitives::{hex, B256};
use reth_trie_common::root::ordered_trie_root_with_encoder;
use sf_protos::ethereum::r#type::v2::Block;

const BYZANTINUM_FORK_BLOCK: u64 = 4_370_000;
Expand All @@ -26,9 +23,9 @@ pub fn check_receipt_root(block: &Block) -> Result<(), ReceiptError> {
Some(ref header) => header.receipt_root.as_slice(),
None => return Err(ReceiptError::MissingRoot),
};
if computed_root.as_bytes() != receipt_root {
if computed_root.as_slice() != receipt_root {
return Err(ReceiptError::MismatchedRoot(
hex::encode(computed_root.as_bytes()),
hex::encode(computed_root.as_slice()),
hex::encode(receipt_root),
));
}
Expand Down Expand Up @@ -73,11 +70,11 @@ fn calc_receipt_root(block: &Block) -> Result<B256, ReceiptError> {
/// and a mutable reference to a type implementing the [`BufMut`].
/// All the data from the receipts in written into the `BufMut` buffer
fn get_encoder(block: &Block) -> fn(&FullReceipt, &mut dyn BufMut) {
fn get_encoder(block: &Block) -> fn(&FullReceipt, &mut Vec<u8>) {
if block.number >= BYZANTINUM_FORK_BLOCK {
|r: &FullReceipt, out: &mut dyn BufMut| r.receipt.encode_inner(out, false)
|r: &FullReceipt, out: &mut Vec<u8>| r.receipt.encode_inner(out, false)
} else {
|r: &FullReceipt, out: &mut dyn BufMut| {
|r: &FullReceipt, out: &mut Vec<u8>| {
receipt_rlp_header(r).encode(out);
r.state_root.as_slice().encode(out);
r.receipt.receipt.cumulative_gas_used.encode(out);
Expand All @@ -88,13 +85,13 @@ fn get_encoder(block: &Block) -> fn(&FullReceipt, &mut dyn BufMut) {
}

/// Encodes receipt header using [RLP serialization](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp)
fn receipt_rlp_header(receipt: &FullReceipt) -> reth_rlp::Header {
fn receipt_rlp_header(receipt: &FullReceipt) -> Header {
let payload_length = receipt.state_root.as_slice().length()
+ receipt.receipt.receipt.cumulative_gas_used.length()
+ receipt.receipt.bloom.length()
+ receipt.receipt.receipt.logs.length();

reth_rlp::Header {
Header {
list: true,
payload_length,
}
Expand Down
3 changes: 2 additions & 1 deletion src/receipts/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::receipts::error::ReceiptError;
use crate::receipts::logs::map_logs;
use crate::transactions::tx_type::map_tx_type;
use alloy_primitives::FixedBytes;
use reth_primitives::{hex, Bloom, Log, Receipt, ReceiptWithBloom};
use sf_protos::ethereum::r#type::v2::TransactionTrace;

Expand Down Expand Up @@ -51,7 +52,7 @@ fn map_bloom(slice: &[u8]) -> Result<Bloom, ReceiptError> {
let array: [u8; 256] = slice
.try_into()
.expect("Slice length doesn't match array length");
Ok(Bloom(array))
Ok(Bloom(FixedBytes(array)))
} else {
Err(ReceiptError::InvalidBloom(hex::encode(slice)))
}
Expand Down
7 changes: 3 additions & 4 deletions src/transactions/access_list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// use crate::protos::block::AccessTuple;
use crate::transactions::error::TransactionError;
use reth_primitives::{hex, AccessList, AccessListItem, Address, H256};
use reth_primitives::{hex, AccessList, AccessListItem, Address, B256};
use sf_protos::ethereum::r#type::v2::AccessTuple;

pub(crate) fn compute_access_list(
Expand All @@ -25,9 +24,9 @@ pub fn atuple_to_alist_item(tuple: &AccessTuple) -> Result<AccessListItem, Trans
.as_slice()
.try_into()
.map_err(|_| TransactionError::InvalidStorageKey(hex::encode(key.clone())))?;
Ok(H256::from(key_bytes))
Ok(B256::from(key_bytes))
})
.collect::<Result<Vec<H256>, TransactionError>>()?;
.collect::<Result<Vec<B256>, TransactionError>>()?;

Ok(AccessListItem {
address,
Expand Down
22 changes: 9 additions & 13 deletions src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ mod transaction;
mod transaction_signed;

use crate::transactions::error::TransactionError;
use reth_primitives::proofs::calculate_transaction_root;
use reth_primitives::{hex, TransactionSigned, U128};
use reth_primitives::{hex, proofs::calculate_transaction_root, TransactionSigned, U128};
use sf_protos::ethereum::r#type::v2::{BigInt, Block};
use std::u128;

use self::transaction_signed::trace_to_signed;

Expand All @@ -28,9 +26,9 @@ pub fn check_transaction_root(block: &Block) -> Result<(), TransactionError> {
None => return Err(TransactionError::MissingHeader),
};

if tx_root.as_bytes() != block_header.transactions_root.as_slice() {
if tx_root.as_slice() != block_header.transactions_root.as_slice() {
return Err(TransactionError::MismatchedRoot(
hex::encode(tx_root.as_bytes()),
hex::encode(tx_root.as_slice()),
hex::encode(block_header.transactions_root.as_slice()),
));
}
Expand All @@ -51,7 +49,7 @@ mod tests {
use crate::transactions::bigint_to_u128;
use crate::transactions::transaction_signed::trace_to_signed;
use prost::Message;
use reth_primitives::{Address, Bytes, TransactionKind, TxHash, TxType, U256};
use reth_primitives::{Address, Bytes, TxHash, TxKind, TxType, U256};
use sf_protos::bstream::v1::Block as BstreamBlock;
use sf_protos::ethereum::r#type::v2::transaction_trace::Type;
use sf_protos::ethereum::r#type::v2::{BigInt, Block};
Expand Down Expand Up @@ -93,7 +91,7 @@ mod tests {

let tx_details = transaction.transaction;

assert_eq!(tx_details.value(), 0);
assert_eq!(tx_details.value(), U256::from(0));
assert_eq!(tx_details.nonce(), 3807);

assert_eq!(tx_details.max_fee_per_gas(), 141_363_047_052);
Expand All @@ -111,14 +109,12 @@ mod tests {

assert_eq!(*tx_details.input(), Bytes::from_str("0x38ed1739000000000000000000000000000000000000000000000000482a1c73000800000000000000000000000000000000000000000009c14e785bf4910843948926c200000000000000000000000000000000000000000000000000000000000000a00000000000000000000000006b4b968dcecfd3d197ce04dc8925f919308153660000000000000000000000000000000000000000000000000000000064b040870000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000370a366f402e2e41cdbbe54ecec12aae0cce1955").unwrap());

assert_eq!(tx_details.tx_type(), TxType::EIP1559);
assert_eq!(tx_details.tx_type(), TxType::Eip1559);
assert_eq!(tx_details.chain_id(), Some(1));

assert_eq!(
*tx_details.kind(),
TransactionKind::Call(
Address::from_str("0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D").unwrap()
)
tx_details.kind(),
TxKind::Call(Address::from_str("0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D").unwrap())
);

let signature = transaction.signature;
Expand Down Expand Up @@ -211,7 +207,7 @@ mod tests {

let tx_details = transaction.transaction;

assert_eq!(*tx_details.kind(), TransactionKind::Create);
assert_eq!(tx_details.kind(), TxKind::Create);
assert_eq!(transaction.hash.as_slice(), trace.hash.as_slice());
}
}
19 changes: 10 additions & 9 deletions src/transactions/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// use crate::protos::block::{CallType, TransactionTrace};
use crate::transactions::access_list::compute_access_list;
use crate::transactions::error::TransactionError;
use crate::transactions::tx_type::map_tx_type;
use alloy_primitives::{TxKind, Uint};
use reth_primitives::{
Address, Bytes, ChainId, Transaction, TransactionKind, TxEip1559, TxEip2930, TxLegacy, TxType,
Address, Bytes, ChainId, Transaction, TxEip1559, TxEip2930, TxLegacy, TxType,
};
use sf_protos::ethereum::r#type::v2::{BigInt, CallType, TransactionTrace};

Expand All @@ -30,8 +30,8 @@ pub fn trace_to_transaction(trace: &TransactionTrace) -> Result<Transaction, Tra
Some(value) => value,
None => BigInt { bytes: vec![0] },
};
let value = bigint_to_u128(trace_value)?;
let input = Bytes::from(trace.input.as_slice());
let value = Uint::from(bigint_to_u128(trace_value)?);
let input = Bytes::copy_from_slice(trace.input.as_slice());

let transaction: Transaction = match tx_type {
TxType::Legacy => {
Expand All @@ -53,7 +53,7 @@ pub fn trace_to_transaction(trace: &TransactionTrace) -> Result<Transaction, Tra
input,
})
}
TxType::EIP2930 => {
TxType::Eip2930 => {
let access_list = compute_access_list(&trace.access_list)?;

Transaction::Eip2930(TxEip2930 {
Expand All @@ -67,7 +67,7 @@ pub fn trace_to_transaction(trace: &TransactionTrace) -> Result<Transaction, Tra
input,
})
}
TxType::EIP1559 => {
TxType::Eip1559 => {
let access_list = compute_access_list(&trace.access_list)?;

let trace_max_fee_per_gas = match trace.max_fee_per_gas.clone() {
Expand All @@ -94,20 +94,21 @@ pub fn trace_to_transaction(trace: &TransactionTrace) -> Result<Transaction, Tra
input,
})
}
TxType::Eip4844 => unimplemented!(),
};

Ok(transaction)
}

pub fn get_tx_kind(trace: &TransactionTrace) -> Result<TransactionKind, TransactionError> {
pub fn get_tx_kind(trace: &TransactionTrace) -> Result<TxKind, TransactionError> {
let first_call = trace.calls.first().ok_or(TransactionError::MissingCall)?;

let call_type = first_call.call_type();

if call_type == CallType::Create {
Ok(TransactionKind::Create)
Ok(TxKind::Create)
} else {
let address = Address::from_slice(trace.to.as_slice());
Ok(TransactionKind::Call(address))
Ok(TxKind::Call(address))
}
}
5 changes: 3 additions & 2 deletions src/transactions/transaction_signed.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::transactions::error::TransactionError;
use alloy_primitives::FixedBytes;
use reth_primitives::TransactionSigned;
use revm_primitives::{hex, B256};
use revm_primitives::hex;
use sf_protos::ethereum::r#type::v2::TransactionTrace;
use std::str::FromStr;

Expand All @@ -9,7 +10,7 @@ use super::{signature::signature_from_trace, transaction::trace_to_transaction};
pub fn trace_to_signed(trace: &TransactionTrace) -> Result<TransactionSigned, TransactionError> {
let transaction = trace_to_transaction(trace)?;
let signature = signature_from_trace(trace)?;
let hash = B256::from_str(&hex::encode(trace.hash.as_slice()))
let hash = FixedBytes::from_str(&hex::encode(trace.hash.as_slice()))
.map_err(|_| TransactionError::MissingCall)?;
let tx_signed = TransactionSigned {
transaction,
Expand Down
5 changes: 2 additions & 3 deletions src/transactions/tx_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// use crate::protos::block::transaction_trace::Type;
use reth_primitives::TxType;
use sf_protos::ethereum::r#type::v2::transaction_trace::Type;
use thiserror::Error;
Expand All @@ -12,8 +11,8 @@ pub enum TransactionTypeError {
fn tx_to_reth_tx(tx_type: Type) -> TxType {
match tx_type {
Type::TrxTypeLegacy => TxType::Legacy,
Type::TrxTypeAccessList => TxType::EIP2930,
Type::TrxTypeDynamicFee => TxType::EIP1559,
Type::TrxTypeAccessList => TxType::Eip2930,
Type::TrxTypeDynamicFee => TxType::Eip1559,
}
}

Expand Down

0 comments on commit 8d6de8a

Please sign in to comment.