Skip to content

Commit

Permalink
Revert "Revert "feat: Control behavior of structs and map them when i…
Browse files Browse the repository at this point in the history
…ts a transaction""
  • Loading branch information
andreespirela authored Oct 21, 2024
1 parent f5ca406 commit 86150bd
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 3 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ members = [
"wvm-apps/wvm-exexed/crates/wvm-borsh/",
"wvm-apps/wvm-exexed/crates/static/",
"wvm-apps/wvm-exexed/crates/brotli/",
"wvm-apps/wvm-exexed/crates/tx/",
]
default-members = ["bin/reth"]
exclude = ["book/sources"]
Expand Down
1 change: 1 addition & 0 deletions wvm-apps/wvm-exexed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ wvm-borsh = { path = "crates/wvm-borsh" }
wvm-static = { path = "crates/static" }
exex-etl = { path = "crates/exex-etl" }
rbrotli = { path = "crates/brotli" }
wvm-tx = { path = "crates/tx" }
borsh.workspace = true

parse_duration.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,17 @@ mod arweave_read_pc_tests {
.to_vec()
);
}

#[test]
pub fn test_read_wvm_block_fix_test_141550_hash() {
let input = Bytes::from("141550;hash".as_bytes());
let PrecompileOutput { gas_used, bytes } = wvm_read_block_pc(&input, 100_000).unwrap();
assert_eq!(bytes.len(), 66);
assert_eq!(
bytes.to_vec(),
"0xb69e1a4a19c665b0573f74b2bf8e4824cb5b54176f4ad45b730f047e880cf5cc"
.as_bytes()
.to_vec()
);
}
}
20 changes: 20 additions & 0 deletions wvm-apps/wvm-exexed/crates/tx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "wvm-tx"
version.workspace = true
edition.workspace = true
rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
alloy-consensus.workspace = true
op-alloy-consensus.workspace = true
alloy-primitives.workspace = true
alloy-serde.workspace = true
alloy-eips.workspace = true
serde.workspace = true
serde_json.workspace = true
reth-primitives = { workspace = true }

[features]
optimism = ["reth-primitives/optimism"]
241 changes: 241 additions & 0 deletions wvm-apps/wvm-exexed/crates/tx/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
use alloy_eips::eip2930::AccessList;
use alloy_eips::eip7702::SignedAuthorization;
use alloy_primitives::{Address, Bytes, ChainId, TxKind, B256, U256};
use reth_primitives::Transaction;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct TxLegacy {
#[serde(default, with = "alloy_serde::quantity::opt", skip_serializing_if = "Option::is_none")]
#[serde(rename = "chainId", alias = "chain_id")]
pub chain_id: Option<ChainId>,
#[serde(with = "alloy_serde::quantity")]
pub nonce: u64,
#[serde(rename = "gasPrice", alias = "gas_price")]
#[serde(with = "alloy_serde::quantity")]
pub gas_price: u128,
#[serde(rename = "gasLimit", alias = "gas_limit")]
#[serde(with = "alloy_serde::quantity")]
pub gas_limit: u64,
#[serde(default, skip_serializing_if = "TxKind::is_create")]
pub to: TxKind,
pub value: U256,
pub input: Bytes,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct TxEip7702 {
#[serde(with = "alloy_serde::quantity")]
#[serde(rename = "chainId", alias = "chain_id")]
pub chain_id: ChainId,
#[serde(with = "alloy_serde::quantity")]
pub nonce: u64,
#[serde(rename = "gasLimit", alias = "gas_limit")]
#[serde(with = "alloy_serde::quantity")]
pub gas_limit: u64,
#[serde(rename = "maxFeePerGas", alias = "max_fee_per_gas")]
#[serde(with = "alloy_serde::quantity")]
pub max_fee_per_gas: u128,
#[serde(rename = "maxPriorityFeePerGas", alias = "max_priority_fee_per_gas")]
#[serde(with = "alloy_serde::quantity")]
pub max_priority_fee_per_gas: u128,

pub to: Address,
pub value: U256,
#[serde(rename = "accessList", alias = "access_list")]
pub access_list: AccessList,
#[serde(rename = "authorizationList", alias = "authorization_list")]
pub authorization_list: Vec<SignedAuthorization>,
pub input: Bytes,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct TxEip4844 {
#[serde(rename = "chainId", alias = "chain_id")]
#[serde(with = "alloy_serde::quantity")]
pub chain_id: ChainId,
#[serde(with = "alloy_serde::quantity")]
pub nonce: u64,

#[serde(rename = "gasLimit", alias = "gas_limit")]
#[serde(with = "alloy_serde::quantity")]
pub gas_limit: u64,

#[serde(rename = "maxFeePerGas", alias = "max_fee_per_gas")]
#[serde(with = "alloy_serde::quantity")]
pub max_fee_per_gas: u128,

#[serde(rename = "maxPriorityFeePerGas", alias = "max_priority_fee_per_gas")]
#[serde(with = "alloy_serde::quantity")]
pub max_priority_fee_per_gas: u128,

pub to: Address,

pub value: U256,

pub access_list: AccessList,

pub blob_versioned_hashes: Vec<B256>,

#[serde(rename = "maxFeePerBlobGas", alias = "max_fee_per_blob_gas")]
#[serde(with = "alloy_serde::quantity")]
pub max_fee_per_blob_gas: u128,
pub input: Bytes,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct TxEip2930 {
#[serde(with = "alloy_serde::quantity")]
#[serde(rename = "chainId", alias = "chain_id")]
pub chain_id: ChainId,
#[serde(with = "alloy_serde::quantity")]
pub nonce: u64,
#[serde(rename = "gasPrice", alias = "gas_price")]
#[serde(with = "alloy_serde::quantity")]
pub gas_price: u128,
#[serde(rename = "gasLimit", alias = "gas_limit")]
#[serde(with = "alloy_serde::quantity")]
pub gas_limit: u64,
#[serde(default, skip_serializing_if = "TxKind::is_create")]
pub to: TxKind,
pub value: U256,
#[serde(rename = "accessList", alias = "access_list")]
pub access_list: AccessList,
pub input: Bytes,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct TxEip1559 {
#[serde(with = "alloy_serde::quantity")]
#[serde(rename = "chainId", alias = "chain_id")]
pub chain_id: ChainId,
#[serde(with = "alloy_serde::quantity")]
pub nonce: u64,
#[serde(rename = "gasLimit", alias = "gas_limit")]
#[serde(with = "alloy_serde::quantity")]
pub gas_limit: u64,
#[serde(rename = "maxFeePerGas", alias = "max_fee_per_gas")]
#[serde(with = "alloy_serde::quantity")]
pub max_fee_per_gas: u128,
#[serde(rename = "maxPriorityFeePerGas", alias = "max_priority_fee_per_gas")]
#[serde(with = "alloy_serde::quantity")]
pub max_priority_fee_per_gas: u128,
#[serde(default, skip_serializing_if = "TxKind::is_create")]
pub to: TxKind,
pub value: U256,
#[serde(rename = "accessList", alias = "access_list")]
pub access_list: AccessList,
pub input: Bytes,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct TxDeposit {
#[serde(rename = "sourceHash", alias = "source_hash")]
pub source_hash: B256,
pub from: Address,
#[serde(default, skip_serializing_if = "TxKind::is_create")]
pub to: TxKind,
#[serde(default, with = "alloy_serde::quantity::opt")]
pub mint: Option<u128>,
pub value: U256,
#[serde(rename = "gasLimit", alias = "gas_limit")]
#[serde(with = "alloy_serde::quantity")]
pub gas_limit: u64,
#[serde(
with = "alloy_serde::quantity",
rename = "isSystemTx",
alias = "is_system_transaction"
)]
pub is_system_transaction: bool,
pub input: Bytes,
}

#[derive(Serialize, Deserialize, Debug)]
pub enum WvmTransaction {
Legacy(TxLegacy),
Eip2930(TxEip2930),
Eip1559(TxEip1559),
Eip4844(TxEip4844),
Eip7702(TxEip7702),
#[cfg(feature = "optimism")]
Deposit(TxDeposit),
}

impl Into<Transaction> for WvmTransaction {
fn into(self) -> Transaction {
match self {
WvmTransaction::Legacy(data) => Transaction::Legacy(alloy_consensus::TxLegacy {
chain_id: data.chain_id,
nonce: data.nonce,
gas_price: data.gas_price,
gas_limit: data.gas_limit,
to: data.to,
value: data.value,
input: data.input,
}),
WvmTransaction::Eip2930(data) => Transaction::Eip2930(alloy_consensus::TxEip2930 {
chain_id: data.chain_id,
nonce: data.nonce,
gas_price: data.gas_price,
gas_limit: data.gas_limit,
to: data.to,
value: data.value,
access_list: data.access_list,
input: data.input,
}),
WvmTransaction::Eip1559(data) => Transaction::Eip1559(alloy_consensus::TxEip1559 {
chain_id: data.chain_id,
nonce: data.nonce,
gas_limit: data.gas_limit,
max_fee_per_gas: data.max_fee_per_gas,
max_priority_fee_per_gas: data.max_priority_fee_per_gas,
to: data.to,
value: data.value,
access_list: data.access_list,
input: data.input,
}),
WvmTransaction::Eip4844(data) => Transaction::Eip4844(alloy_consensus::TxEip4844 {
chain_id: data.chain_id,
nonce: data.nonce,
gas_limit: data.gas_limit,
max_fee_per_gas: data.max_fee_per_gas,
max_priority_fee_per_gas: data.max_priority_fee_per_gas,
to: data.to,
value: data.value,
access_list: data.access_list,
blob_versioned_hashes: data.blob_versioned_hashes,
max_fee_per_blob_gas: data.max_fee_per_blob_gas,
input: data.input,
}),
WvmTransaction::Eip7702(data) => Transaction::Eip7702(alloy_consensus::TxEip7702 {
chain_id: data.chain_id,
nonce: data.nonce,
gas_limit: data.gas_limit,
max_fee_per_gas: data.max_fee_per_gas,
max_priority_fee_per_gas: data.max_priority_fee_per_gas,
to: data.to,
value: data.value,
access_list: data.access_list,
authorization_list: data.authorization_list,
input: data.input,
}),
#[cfg(feature = "optimism")]
WvmTransaction::Deposit(data) => Transaction::Deposit(op_alloy_consensus::TxDeposit {
source_hash: data.source_hash,
gas_limit: data.gas_limit,
to: data.to,
mint: data.mint,
value: data.value,
input: data.input,
from: data.from,
is_system_transaction: data.is_system_transaction,
}),
}
}
}
1 change: 1 addition & 0 deletions wvm-apps/wvm-exexed/crates/wvm-borsh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tokio = "1.38.0"
borsh.workspace = true
reth-primitives.workspace = true
alloy-primitives.workspace = true
wvm-tx = { path = "../tx" }


[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion wvm-apps/wvm-exexed/crates/wvm-borsh/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub struct BorshSignature(pub Signature);

pub fn to_signature(bytes: &[u8]) -> std::io::Result<Signature> {
if bytes.len() != 65 {
return Err(Error::from(ErrorKind::UnexpectedEof))
return Err(Error::from(ErrorKind::UnexpectedEof));
}

let mut r_bytes = [0u8; 32];
Expand Down
Loading

0 comments on commit 86150bd

Please sign in to comment.