Skip to content

Commit

Permalink
Merge pull request #15 from pnetwork-association/new-eth-tx-type
Browse files Browse the repository at this point in the history
feat(ethereum): < -adds new eth tx type
  • Loading branch information
gskapka authored Jan 30, 2024
2 parents 434326d + f0a2950 commit cb0a15e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion common/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ license = "MIT"
publish = false
edition = "2021"
name = "ethereum"
version = "6.12.0"
version = "6.13.0"
readme = "README.md"
rust-version = "1.56"
keywords = ["defi", "crypto"]
Expand Down
2 changes: 1 addition & 1 deletion common/ethereum/src/eth_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ mod tests {
#[test]
fn should_get_receipt_type_from_non_legacy_receipt() {
let receipt = get_eip1559_non_legacy_receipt();
let expected_result = EthReceiptType::EIP2718;
let expected_result = EthReceiptType::EIP1559;
let result = receipt.get_receipt_type().unwrap();
assert_eq!(result, expected_result);
}
Expand Down
38 changes: 31 additions & 7 deletions common/ethereum/src/eth_receipt_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ use strum_macros::EnumIter;
#[derive(Clone, Debug, EnumIter, Eq, PartialEq, Serialize, Deserialize)]
pub enum EthReceiptType {
Legacy,
EIP2718,
EIP2930,
EIP2930, // NOTE: Optional access lists: https://eips.ethereum.org/EIPS/eip-2930
EIP1559, // NOTE: New tx pricing mechanism: https://eips.ethereum.org/EIPS/eip-1559
EIP4844, // NOTE: Dencun-fork blob-carrying txs: https://eips.ethereum.org/EIPS/eip-4844
EIP2718, // NOTE: The original EIP introducing new tx envelopes: https://eips.ethereum.org/EIPS/eip-2718
ArbitrumRetryTxType,
ArbitrumLegacyTxType,
ArbitrumDepositTxType,
Expand All @@ -26,7 +28,8 @@ impl EthReceiptType {
match byte {
0x00 => Self::Legacy,
0x01 => Self::EIP2930,
0x02 => Self::EIP2718,
0x02 => Self::EIP1559,
0x03 => Self::EIP4844,
0x68 => Self::ArbitrumRetryTxType,
0x64 => Self::ArbitrumDepositTxType,
0x65 => Self::ArbitrumUnsignedTxType,
Expand All @@ -42,14 +45,18 @@ impl EthReceiptType {
match self {
Self::Legacy => 0x00,
Self::EIP2930 => 0x01,
Self::EIP2718 => 0x02,
Self::EIP4844 => 0x03,
Self::ArbitrumRetryTxType => 0x68,
Self::ArbitrumLegacyTxType => 0x78,
Self::ArbitrumDepositTxType => 0x64,
Self::ArbitrumUnsignedTxType => 0x65,
Self::ArbitrumContractTxType => 0x66,
Self::ArbitrumInternalTxType => 0x6a,
Self::ArbitrumSubmitRetryableTxType => 0x69,
// NOTE: This is to remain backwards compatible where an earlier bug caused
// some submission materail to have a type "EIP2718" when it should in fact
// have been "0x2" or "EIP1559".
Self::EIP1559 | Self::EIP2718 => 0x02,
}
}

Expand All @@ -63,10 +70,11 @@ impl fmt::Display for EthReceiptType {
let s = match self {
Self::Legacy => "0x0",
Self::EIP2930 => "0x1",
Self::EIP2718 => "0x2",
Self::EIP4844 => "0x3",
Self::ArbitrumRetryTxType => "0x68",
Self::ArbitrumLegacyTxType => "0x78",
Self::ArbitrumDepositTxType => "0x64",
Self::EIP1559 | Self::EIP2718 => "0x2", // NOTE: Ibid
Self::ArbitrumUnsignedTxType => "0x65",
Self::ArbitrumContractTxType => "0x66",
Self::ArbitrumInternalTxType => "0x6a",
Expand All @@ -83,7 +91,8 @@ impl FromStr for EthReceiptType {
match s {
"0x0" | "0" => Ok(Self::Legacy),
"EIP2930" | "0x1" | "1" => Ok(Self::EIP2930),
"EIP2718" | "0x2" | "2" => Ok(Self::EIP2718),
"EIP4844" | "0x3" | "3" => Ok(Self::EIP4844),
"EIP1559" | "EIP2718" | "0x2" | "2" => Ok(Self::EIP1559), // NOTE: Ibid
"ArbitrumRetryTxType" | "0x68" | "68" => Ok(Self::ArbitrumRetryTxType),
"ArbitrumLegacyTxType" | "0x78" | "78" => Ok(Self::ArbitrumLegacyTxType),
"ArbitrumDepositTxType" | "0x64" | "64" => Ok(Self::ArbitrumDepositTxType),
Expand All @@ -98,15 +107,23 @@ impl FromStr for EthReceiptType {

#[cfg(test)]
mod tests {
use std::fs::read_to_string;

use common::types::Bytes;
use strum::IntoEnumIterator;

use super::*;
use crate::EthSubmissionMaterial;

#[test]
fn should_make_receipt_types_byte_roundtrip() {
let expected_results = EthReceiptType::iter().collect::<Vec<EthReceiptType>>();
let expected_results = EthReceiptType::iter()
// NOTE: We remove the following due to bug explained in notes above
.filter(|x| x != &EthReceiptType::EIP2718)
.collect::<Vec<EthReceiptType>>();
let bytes = EthReceiptType::iter()
// NOTE: Ibid
.filter(|x| x != &EthReceiptType::EIP2718)
.map(|receipt_type| receipt_type.to_byte())
.collect::<Bytes>();
let results = bytes
Expand All @@ -115,4 +132,11 @@ mod tests {
.collect::<Vec<EthReceiptType>>();
assert_eq!(results, expected_results);
}

#[test]
fn should_parse_submission_material_with_eip4844_receipt_type() {
let p = "src/test_utils/goerli-sub-mat-with-eip-4844-receipt-type.json";
let r = EthSubmissionMaterial::from_str(&read_to_string(p).unwrap());
assert!(r.is_ok());
}
}

Large diffs are not rendered by default.

0 comments on commit cb0a15e

Please sign in to comment.