paradigmxyz / reth

Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol, in Rust
https://reth.rs/
Apache License 2.0
3.37k stars 851 forks source link

fix: prevent CREATE tx for EIP-4844 types #8291

Closed fgimenez closed 3 weeks ago

fgimenez commented 3 weeks ago

EIP-4844 transactions have a restriction that they should not allow CREATE transactions.

In this PR the to field in TxEip4844 is changed from TxKind to Address, so that it can't be decoded into TxKind::Create.

joshieDo commented 3 weeks ago

this is most likely not sound. TxKind occupies one bit inside the bitflag struct. If set, it will decode an address, otherwise it wont. This bitflag struct more or less dictates what to decode or how many bytes to decode from.

Changing this to Address, will make it not backwards compatible since, this bit will now be part of the next field which is not right.

Note the cargo expansion below B1.

main:

#[allow(clippy::identity_op)]
            pub struct TxEip4844Flags {
                bytes: [::core::primitive::u8; {
                    ((({
                        0usize + <B4 as ::modular_bitfield::Specifier>::BITS
                            + <B4 as ::modular_bitfield::Specifier>::BITS
                            + <B4 as ::modular_bitfield::Specifier>::BITS
                            + <B5 as ::modular_bitfield::Specifier>::BITS
                            + <B5 as ::modular_bitfield::Specifier>::BITS
                            + <B1 as ::modular_bitfield::Specifier>::BITS
                            + <B6 as ::modular_bitfield::Specifier>::BITS
                            + <B5 as ::modular_bitfield::Specifier>::BITS
                            + <B6 as ::modular_bitfield::Specifier>::BITS
                    } - 1) / 8) + 1) * 8
                } / 8usize],

this branch:

#[allow(clippy::identity_op)]
            pub struct TxEip4844Flags {
                bytes: [::core::primitive::u8; {
                    ((({
                        0usize + <B4 as ::modular_bitfield::Specifier>::BITS
                            + <B4 as ::modular_bitfield::Specifier>::BITS
                            + <B4 as ::modular_bitfield::Specifier>::BITS
                            + <B5 as ::modular_bitfield::Specifier>::BITS
                            + <B5 as ::modular_bitfield::Specifier>::BITS
                            + <B6 as ::modular_bitfield::Specifier>::BITS
                            + <B5 as ::modular_bitfield::Specifier>::BITS
                            + <B7 as ::modular_bitfield::Specifier>::BITS
                    } - 1) / 8) + 1) * 8
                } / 8usize],

Note the missing bit on this branch macro expansion.