Skip to content
35 changes: 6 additions & 29 deletions execution/types/aa_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,9 @@ func (tx *AccountAbstractionTransaction) EncodingSize() int {

func (tx *AccountAbstractionTransaction) EncodeRLP(w io.Writer) error {
payloadSize, accessListLen, authorizationsLen := tx.payloadSize()
envelopSize := 1 + rlp.ListPrefixLen(payloadSize) + payloadSize
b := rlp.NewEncodingBuf()
defer b.Release()
// encode envelope size
if err := rlp.EncodeStringPrefix(envelopSize, w, b[:]); err != nil {
return err
}
// encode TxType
b[0] = AccountAbstractionTxType
if _, err := w.Write(b[:1]); err != nil {
return err
}

if err := tx.encodePayload(w, b[:], payloadSize, accessListLen, authorizationsLen); err != nil {
return err
}

return nil
return encodeRLPTyped(w, AccountAbstractionTxType, payloadSize, func(w io.Writer, b []byte) error {
return tx.encodePayload(w, b, payloadSize, accessListLen, authorizationsLen)
})
}

func (tx *AccountAbstractionTransaction) encodePayload(w io.Writer, b []byte, payloadSize, accessListLen, authorizationsLen int) error {
Expand Down Expand Up @@ -461,17 +446,9 @@ func (tx *AccountAbstractionTransaction) DecodeRLP(s *rlp.Stream) error {

func (tx *AccountAbstractionTransaction) MarshalBinary(w io.Writer) error {
payloadSize, accessListLen, authorizationsLen := tx.payloadSize()
b := rlp.NewEncodingBuf()
defer b.Release()
// encode TxType
b[0] = AccountAbstractionTxType
if _, err := w.Write(b[:1]); err != nil {
return err
}
if err := tx.encodePayload(w, b[:], payloadSize, accessListLen, authorizationsLen); err != nil {
return err
}
return nil
return marshalTyped(w, AccountAbstractionTxType, func(w io.Writer, b []byte) error {
return tx.encodePayload(w, b, payloadSize, accessListLen, authorizationsLen)
})
}

func (tx *AccountAbstractionTransaction) PreTransactionGasCost(rules *chain.Rules, hasEIP3860 bool) (uint64, error) {
Expand Down
77 changes: 9 additions & 68 deletions execution/types/access_list_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,9 @@ func encodeAccessList(al AccessList, w io.Writer, b []byte) error {
// transactions, it returns the type and payload.
func (tx *AccessListTx) MarshalBinary(w io.Writer) error {
payloadSize, accessListLen := tx.payloadSize()
b := rlp.NewEncodingBuf()
defer b.Release()
// encode TxType
b[0] = AccessListTxType
if _, err := w.Write(b[:1]); err != nil {
return err
}
if err := tx.encodePayload(w, b[:], payloadSize, accessListLen); err != nil {
return err
}
return nil
return marshalTyped(w, AccessListTxType, func(w io.Writer, b []byte) error {
return tx.encodePayload(w, b, payloadSize, accessListLen)
})
}

func (tx *AccessListTx) encodePayload(w io.Writer, b []byte, payloadSize, accessListLen int) error {
Expand Down Expand Up @@ -230,42 +222,15 @@ func (tx *AccessListTx) encodePayload(w io.Writer, b []byte, payloadSize, access
if err := encodeAccessList(tx.AccessList, w, b); err != nil {
return err
}
// encode V
if err := rlp.EncodeUint256(tx.V, w, b); err != nil {
return err
}
// encode R
if err := rlp.EncodeUint256(tx.R, w, b); err != nil {
return err
}
// encode S
if err := rlp.EncodeUint256(tx.S, w, b); err != nil {
return err
}
return nil

return tx.encodeVRS(w, b)
}

// EncodeRLP implements rlp.Encoder
func (tx *AccessListTx) EncodeRLP(w io.Writer) error {
payloadSize, accessListLen := tx.payloadSize()
// size of struct prefix and TxType
envelopeSize := 1 + rlp.ListPrefixLen(payloadSize) + payloadSize
b := rlp.NewEncodingBuf()
defer b.Release()
// envelope
if err := rlp.EncodeStringPrefix(envelopeSize, w, b[:]); err != nil {
return err
}
// encode TxType
b[0] = AccessListTxType
if _, err := w.Write(b[:1]); err != nil {
return err
}
if err := tx.encodePayload(w, b[:], payloadSize, accessListLen); err != nil {
return err
}
return nil
return encodeRLPTyped(w, AccessListTxType, payloadSize, func(w io.Writer, b []byte) error {
return tx.encodePayload(w, b, payloadSize, accessListLen)
})
}

func decodeAccessList(al *AccessList, s *rlp.Stream) error {
Expand Down Expand Up @@ -392,14 +357,9 @@ func (tx *AccessListTx) AsMessage(s Signer, _ *uint256.Int, rules *chain.Rules)

func (tx *AccessListTx) WithSignature(signer Signer, sig []byte) (Transaction, error) {
cpy := tx.copy()
r, s, v, err := signer.SignatureValues(tx, sig)
if err != nil {
if err := applySignature(signer, tx, sig, &cpy.CommonTx, &cpy.ChainID); err != nil {
return nil, err
}
cpy.R.Set(r)
cpy.S.Set(s)
cpy.V.Set(v)
cpy.ChainID = *signer.ChainID()
return cpy, nil
}

Expand Down Expand Up @@ -452,25 +412,6 @@ func (tx *AccessListTx) GetChainID() *uint256.Int {
return &tx.ChainID
}

func (tx *AccessListTx) cachedSender() (sender accounts.Address, ok bool) {
s := tx.from
if s.IsNil() {
return sender, false
}
return s, true
}

func (tx *AccessListTx) Sender(signer Signer) (accounts.Address, error) {
if from := tx.from; !from.IsNil() {
if !from.IsZero() { // Sender address can never be zero in a transaction with a valid signer
return from, nil
}
}

addr, err := signer.Sender(tx)
if err != nil {
return accounts.ZeroAddress, err
}
tx.from = addr
return addr, nil
return recoverSender(tx, &tx.TransactionMisc, signer)
}
175 changes: 14 additions & 161 deletions execution/types/blob_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,8 @@ func (stx *BlobTx) AsMessage(s Signer, baseFee *uint256.Int, rules *chain.Rules)
return &msg, nil
}

func (stx *BlobTx) cachedSender() (sender accounts.Address, ok bool) {
s := stx.from
if s.IsNil() {
return sender, false
}
return s, true
}

func (stx *BlobTx) Sender(signer Signer) (accounts.Address, error) {
if from := stx.from; !from.IsNil() && !from.IsZero() {
// Sender address can never be zero in a transaction with a valid signer
return from, nil
}
addr, err := signer.Sender(stx)
if err != nil {
return accounts.ZeroAddress, err
}
stx.from = addr
return addr, nil
return recoverSender(stx, &stx.TransactionMisc, signer)
}

func (stx *BlobTx) Hash() common.Hash {
Expand Down Expand Up @@ -186,14 +169,9 @@ func (stx *BlobTx) SigningHash(chainID *uint256.Int) common.Hash {

func (stx *BlobTx) WithSignature(signer Signer, sig []byte) (Transaction, error) {
cpy := stx.copy()
r, s, v, err := signer.SignatureValues(stx, sig)
if err != nil {
if err := applySignature(signer, stx, sig, &cpy.CommonTx, &cpy.ChainID); err != nil {
return nil, err
}
cpy.R.Set(r)
cpy.S.Set(s)
cpy.V.Set(v)
cpy.ChainID = *signer.ChainID()
return cpy, nil
}

Expand Down Expand Up @@ -236,181 +214,56 @@ func encodeBlobVersionedHashes(hashes []common.Hash, w io.Writer, b []byte) erro
}

func (stx *BlobTx) encodePayload(w io.Writer, b []byte, payloadSize, accessListLen, blobHashesLen int) error {
// prefix
if err := rlp.EncodeListPrefix(payloadSize, w, b); err != nil {
return err
}
// encode ChainID
if err := rlp.EncodeUint256(stx.ChainID, w, b); err != nil {
return err
}
// encode Nonce
if err := rlp.EncodeU64(stx.Nonce, w, b); err != nil {
return err
}
// encode MaxPriorityFeePerGas
if err := rlp.EncodeUint256(stx.TipCap, w, b); err != nil {
return err
}
// encode MaxFeePerGas
if err := rlp.EncodeUint256(stx.FeeCap, w, b); err != nil {
return err
}
// encode GasLimit
if err := rlp.EncodeU64(stx.GasLimit, w, b); err != nil {
return err
}
// encode To
if err := EncodeOptionalAddress(stx.To, w, b); err != nil {
if err := stx.encode1559Prefix(w, b, payloadSize, accessListLen); err != nil {
return err
}
// encode Value
if err := rlp.EncodeUint256(stx.Value, w, b); err != nil {
return err
}
// encode Data
if err := rlp.EncodeString(stx.Data, w, b); err != nil {
return err
}
// prefix
if err := rlp.EncodeListPrefix(accessListLen, w, b); err != nil {
return err
}
// encode AccessList
if err := encodeAccessList(stx.AccessList, w, b); err != nil {
return err
}
// encode MaxFeePerBlobGas
if err := rlp.EncodeUint256(stx.MaxFeePerBlobGas, w, b); err != nil {
return err
}
// prefix
if err := rlp.EncodeListPrefix(blobHashesLen, w, b); err != nil {
return err
}
// encode BlobVersionedHashes
if err := encodeBlobVersionedHashes(stx.BlobVersionedHashes, w, b); err != nil {
return err
}
// encode V
if err := rlp.EncodeUint256(stx.V, w, b); err != nil {
return err
}
// encode R
if err := rlp.EncodeUint256(stx.R, w, b); err != nil {
return err
}
// encode S
if err := rlp.EncodeUint256(stx.S, w, b); err != nil {
return err
}
return nil
return stx.encodeVRS(w, b)
}

func (stx *BlobTx) EncodeRLP(w io.Writer) error {
if stx.To == nil {
return ErrNilToFieldTx
}
payloadSize, accessListLen, blobHashesLen := stx.payloadSize()
// size of struct prefix and TxType
envelopeSize := 1 + rlp.ListPrefixLen(payloadSize) + payloadSize
b := rlp.NewEncodingBuf()
defer b.Release()
// envelope
if err := rlp.EncodeStringPrefix(envelopeSize, w, b[:]); err != nil {
return err
}
// encode TxType
b[0] = BlobTxType
if _, err := w.Write(b[:1]); err != nil {
return err
}
if err := stx.encodePayload(w, b[:], payloadSize, accessListLen, blobHashesLen); err != nil {
return err
}
return nil
return encodeRLPTyped(w, BlobTxType, payloadSize, func(w io.Writer, b []byte) error {
return stx.encodePayload(w, b, payloadSize, accessListLen, blobHashesLen)
})
}

func (stx *BlobTx) MarshalBinary(w io.Writer) error {
if stx.To == nil {
return ErrNilToFieldTx
}
payloadSize, accessListLen, blobHashesLen := stx.payloadSize()
b := rlp.NewEncodingBuf()
defer b.Release()
// encode TxType
b[0] = BlobTxType
if _, err := w.Write(b[:1]); err != nil {
return err
}
if err := stx.encodePayload(w, b[:], payloadSize, accessListLen, blobHashesLen); err != nil {
return err
}
return nil
return marshalTyped(w, BlobTxType, func(w io.Writer, b []byte) error {
return stx.encodePayload(w, b, payloadSize, accessListLen, blobHashesLen)
})
}

func (stx *BlobTx) DecodeRLP(s *rlp.Stream) error {
_, err := s.List()
if err != nil {
return err
}
if err = s.ReadUint256(&stx.ChainID); err != nil {
return err
}
if stx.Nonce, err = s.Uint64(); err != nil {
return err
}
if err = s.ReadUint256(&stx.TipCap); err != nil {
return err
}
if err = s.ReadUint256(&stx.FeeCap); err != nil {
return err
}
if stx.GasLimit, err = s.Uint64(); err != nil {
if err := stx.decode1559Prefix(s, true); err != nil {
return err
}
stx.To = &common.Address{}
if kind, size, err := s.Kind(); err != nil {
if err := s.ReadUint256(&stx.MaxFeePerBlobGas); err != nil {
return err
} else if kind == rlp.Byte {
return fmt.Errorf("wrong size for To: 1")
} else if size != 20 {
return fmt.Errorf("wrong size for To: %d", size)
}
if err = s.ReadBytes(stx.To[:]); err != nil {
return err
}
if err = s.ReadUint256(&stx.Value); err != nil {
return err
}
if stx.Data, err = s.Bytes(); err != nil {
return err
}
// decode AccessList
stx.AccessList = AccessList{}
if err = decodeAccessList(&stx.AccessList, s); err != nil {
return err
}
// decode MaxFeePerBlobGas
if err = s.ReadUint256(&stx.MaxFeePerBlobGas); err != nil {
return err
}
// decode BlobVersionedHashes
stx.BlobVersionedHashes = []common.Hash{}
if err = decodeBlobVersionedHashes(&stx.BlobVersionedHashes, s); err != nil {
if err := decodeBlobVersionedHashes(&stx.BlobVersionedHashes, s); err != nil {
return err
}
if len(stx.BlobVersionedHashes) == 0 {
return errors.New("a blob stx must contain at least one blob")
}
// decode V
if err = s.ReadUint256(&stx.V); err != nil {
return err
}
if err = s.ReadUint256(&stx.R); err != nil {
return err
}
if err = s.ReadUint256(&stx.S); err != nil {
if err := stx.decodeVRS(s); err != nil {
return err
}
return s.ListEnd()
Expand Down
Loading
Loading