Skip to content

Commit

Permalink
Prevent marshaling gas price in case of dynamic fee transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Aug 8, 2023
1 parent ec7ffb3 commit ff3c370
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
20 changes: 11 additions & 9 deletions structs_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,20 @@ func (t *Transaction) marshalJSON(a *fastjson.Arena) *fastjson.Value {
if t.Value != nil {
o.Set("value", a.NewString(fmt.Sprintf("0x%x", t.Value)))
}
o.Set("gasPrice", a.NewString(fmt.Sprintf("0x%x", t.GasPrice)))

if t.Type == TransactionDynamicFee {
if t.MaxPriorityFeePerGas != nil {
o.Set("maxPriorityFeePerGas", a.NewString(fmt.Sprintf("0x%x", t.MaxPriorityFeePerGas)))
}
if t.MaxFeePerGas != nil {
o.Set("maxFeePerGas", a.NewString(fmt.Sprintf("0x%x", t.MaxFeePerGas)))
}
} else {
o.Set("gasPrice", a.NewString(fmt.Sprintf("0x%x", t.GasPrice)))
}
// gas limit fields
if t.Gas != 0 {
o.Set("gas", a.NewString(fmt.Sprintf("0x%x", t.Gas)))
}
if t.MaxPriorityFeePerGas != nil {
o.Set("maxPriorityFeePerGas", a.NewString(fmt.Sprintf("0x%x", t.MaxPriorityFeePerGas)))
}
if t.MaxFeePerGas != nil {
o.Set("maxFeePerGas", a.NewString(fmt.Sprintf("0x%x", t.MaxFeePerGas)))
}

if t.Nonce != 0 {
// we can remove this once we include support for custom nonces
Expand Down Expand Up @@ -298,4 +300,4 @@ func (s StateOverride) MarshalJSON() ([]byte, error) {
defaultArena.Put(a)

return res, nil
}
}
22 changes: 11 additions & 11 deletions structs_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,17 @@ func (t *Transaction) unmarshalJSON(v *fastjson.Value) error {
if err = decodeAddr(&t.From, v, "from"); err != nil {
return err
}
if t.GasPrice, err = decodeUint(v, "gasPrice"); err != nil {
return err
if typ == TransactionDynamicFee {
if t.MaxPriorityFeePerGas, err = decodeBigInt(t.MaxPriorityFeePerGas, v, "maxPriorityFeePerGas"); err != nil {
return err
}
if t.MaxFeePerGas, err = decodeBigInt(t.MaxFeePerGas, v, "maxFeePerGas"); err != nil {
return err
}
} else {
if t.GasPrice, err = decodeUint(v, "gasPrice"); err != nil {
return err
}
}
if t.Input, err = decodeBytes(t.Input[:0], v, "input"); err != nil {
return err
Expand Down Expand Up @@ -207,15 +216,6 @@ func (t *Transaction) unmarshalJSON(v *fastjson.Value) error {
return err
}

if typ == TransactionDynamicFee {
if t.MaxPriorityFeePerGas, err = decodeBigInt(t.MaxPriorityFeePerGas, v, "maxPriorityFeePerGas"); err != nil {
return err
}
if t.MaxFeePerGas, err = decodeBigInt(t.MaxFeePerGas, v, "maxFeePerGas"); err != nil {
return err
}
}

// Check if the block hash field is set
// If it's not -> the transaction is a pending txn, so these fields should be omitted
// If it is -> the transaction is a sealed txn, so these fields should be included
Expand Down
3 changes: 1 addition & 2 deletions testsuite/transaction-eip1159.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"from": "0x0000000000000000000000000000000000000001",
"input": "0x00",
"value": "0x0",
"gasPrice": "0x0",
"gas": "0x10",
"maxPriorityFeePerGas": "0x10",
"maxFeePerGas": "0x10",
"gas": "0x10",
"nonce": "0x10",
"to": null,
"v":"0x25",
Expand Down

0 comments on commit ff3c370

Please sign in to comment.