mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
fix: use correct encoding for L1 data fee of EIP2718 transactions (#793)
* fix: use correct encoding for L1 data fee of EIP2718 transactions * add tests * lint * Update rollup/fees/rollup_fee.go Co-authored-by: Ömer Faruk Irmak <omerfirmak@gmail.com> --------- Co-authored-by: Ömer Faruk Irmak <omerfirmak@gmail.com>
This commit is contained in:
parent
8c7491ae1e
commit
9ec83a509a
4 changed files with 46 additions and 17 deletions
|
|
@ -40,7 +40,6 @@ var (
|
||||||
ErrInvalidTxType = errors.New("transaction type not valid in this context")
|
ErrInvalidTxType = errors.New("transaction type not valid in this context")
|
||||||
ErrTxTypeNotSupported = errors.New("transaction type not supported")
|
ErrTxTypeNotSupported = errors.New("transaction type not supported")
|
||||||
ErrGasFeeCapTooLow = errors.New("fee cap less than base fee")
|
ErrGasFeeCapTooLow = errors.New("fee cap less than base fee")
|
||||||
errEmptyTypedTx = errors.New("empty typed transaction bytes")
|
|
||||||
errShortTypedTx = errors.New("typed transaction too short")
|
errShortTypedTx = errors.New("typed transaction too short")
|
||||||
errInvalidYParity = errors.New("'yParity' field must be 0 or 1")
|
errInvalidYParity = errors.New("'yParity' field must be 0 or 1")
|
||||||
errVYParityMismatch = errors.New("'v' and 'yParity' fields do not match")
|
errVYParityMismatch = errors.New("'v' and 'yParity' fields do not match")
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ func TestDecodeEmptyTypedTx(t *testing.T) {
|
||||||
input := []byte{0x80}
|
input := []byte{0x80}
|
||||||
var tx Transaction
|
var tx Transaction
|
||||||
err := rlp.DecodeBytes(input, &tx)
|
err := rlp.DecodeBytes(input, &tx)
|
||||||
if err != errEmptyTypedTx {
|
if err != errShortTypedTx {
|
||||||
t.Fatal("wrong error:", err)
|
t.Fatal("wrong error:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -94,11 +94,33 @@ func TestTransactionSigHash(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTransactionEncode(t *testing.T) {
|
func TestTransactionEncode(t *testing.T) {
|
||||||
|
should := common.FromHex("f86103018207d094b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a8255441ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa08887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3")
|
||||||
|
|
||||||
|
// EncodeToBytes
|
||||||
txb, err := rlp.EncodeToBytes(rightvrsTx)
|
txb, err := rlp.EncodeToBytes(rightvrsTx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("encode error: %v", err)
|
t.Fatalf("encode error: %v", err)
|
||||||
}
|
}
|
||||||
should := common.FromHex("f86103018207d094b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a8255441ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa08887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3")
|
if !bytes.Equal(txb, should) {
|
||||||
|
t.Errorf("encoded RLP mismatch, got %x", txb)
|
||||||
|
}
|
||||||
|
|
||||||
|
// tx.EncodeRLP
|
||||||
|
raw := new(bytes.Buffer)
|
||||||
|
err = rightvrsTx.EncodeRLP(raw)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("encode error: %v", err)
|
||||||
|
}
|
||||||
|
txb = raw.Bytes()
|
||||||
|
if !bytes.Equal(txb, should) {
|
||||||
|
t.Errorf("encoded RLP mismatch, got %x", txb)
|
||||||
|
}
|
||||||
|
|
||||||
|
// tx.MarshalBinary
|
||||||
|
txb, err = rightvrsTx.MarshalBinary()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("encode error: %v", err)
|
||||||
|
}
|
||||||
if !bytes.Equal(txb, should) {
|
if !bytes.Equal(txb, should) {
|
||||||
t.Errorf("encoded RLP mismatch, got %x", txb)
|
t.Errorf("encoded RLP mismatch, got %x", txb)
|
||||||
}
|
}
|
||||||
|
|
@ -194,6 +216,7 @@ func TestEIP2930Signer(t *testing.T) {
|
||||||
func TestEIP2718TransactionEncode(t *testing.T) {
|
func TestEIP2718TransactionEncode(t *testing.T) {
|
||||||
// RLP representation
|
// RLP representation
|
||||||
{
|
{
|
||||||
|
// rlp.EncodeToBytes
|
||||||
have, err := rlp.EncodeToBytes(signedEip2718Tx)
|
have, err := rlp.EncodeToBytes(signedEip2718Tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("encode error: %v", err)
|
t.Fatalf("encode error: %v", err)
|
||||||
|
|
@ -202,6 +225,17 @@ func TestEIP2718TransactionEncode(t *testing.T) {
|
||||||
if !bytes.Equal(have, want) {
|
if !bytes.Equal(have, want) {
|
||||||
t.Errorf("encoded RLP mismatch, got %x", have)
|
t.Errorf("encoded RLP mismatch, got %x", have)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tx.EncodeRLP
|
||||||
|
raw := new(bytes.Buffer)
|
||||||
|
err = signedEip2718Tx.EncodeRLP(raw)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("encode error: %v", err)
|
||||||
|
}
|
||||||
|
have = raw.Bytes()
|
||||||
|
if !bytes.Equal(have, want) {
|
||||||
|
t.Errorf("encoded RLP mismatch, got %x", have)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Binary representation
|
// Binary representation
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 5 // Major version component of the current release
|
VersionMajor = 5 // Major version component of the current release
|
||||||
VersionMinor = 3 // Minor version component of the current release
|
VersionMinor = 3 // Minor version component of the current release
|
||||||
VersionPatch = 33 // Patch version component of the current release
|
VersionPatch = 34 // Patch version component of the current release
|
||||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package fees
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/scroll-tech/go-ethereum/common"
|
"github.com/scroll-tech/go-ethereum/common"
|
||||||
|
|
@ -40,7 +41,6 @@ type Message interface {
|
||||||
// required to compute the L1 fee
|
// required to compute the L1 fee
|
||||||
type StateDB interface {
|
type StateDB interface {
|
||||||
GetState(common.Address, common.Hash) common.Hash
|
GetState(common.Address, common.Hash) common.Hash
|
||||||
GetBalance(addr common.Address) *big.Int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type gpoState struct {
|
type gpoState struct {
|
||||||
|
|
@ -64,7 +64,7 @@ func EstimateL1DataFeeForMessage(msg Message, baseFee *big.Int, config *params.C
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
raw, err := rlpEncode(tx)
|
raw, err := tx.MarshalBinary()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -133,16 +133,6 @@ func asUnsignedDynamicTx(msg Message, chainID *big.Int) *types.Transaction {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// rlpEncode RLP encodes the transaction into bytes
|
|
||||||
func rlpEncode(tx *types.Transaction) ([]byte, error) {
|
|
||||||
raw := new(bytes.Buffer)
|
|
||||||
if err := tx.EncodeRLP(raw); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return raw.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func readGPOStorageSlots(addr common.Address, state StateDB) gpoState {
|
func readGPOStorageSlots(addr common.Address, state StateDB) gpoState {
|
||||||
var gpoState gpoState
|
var gpoState gpoState
|
||||||
gpoState.l1BaseFee = state.GetState(addr, rcfg.L1BaseFeeSlot).Big()
|
gpoState.l1BaseFee = state.GetState(addr, rcfg.L1BaseFeeSlot).Big()
|
||||||
|
|
@ -216,7 +206,7 @@ func CalculateL1DataFee(tx *types.Transaction, state StateDB, config *params.Cha
|
||||||
return big.NewInt(0), nil
|
return big.NewInt(0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
raw, err := rlpEncode(tx)
|
raw, err := tx.MarshalBinary()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -231,6 +221,12 @@ func CalculateL1DataFee(tx *types.Transaction, state StateDB, config *params.Cha
|
||||||
l1DataFee = calculateEncodedL1DataFeeCurie(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.commitScalar, gpoState.blobScalar)
|
l1DataFee = calculateEncodedL1DataFeeCurie(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.commitScalar, gpoState.blobScalar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensure l1DataFee fits into uint64 for circuit compatibility
|
||||||
|
// (note: in practice this value should never be this big)
|
||||||
|
if !l1DataFee.IsUint64() {
|
||||||
|
l1DataFee.SetUint64(math.MaxUint64)
|
||||||
|
}
|
||||||
|
|
||||||
return l1DataFee, nil
|
return l1DataFee, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue