Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,6 @@ type callMsg struct {
func (m callMsg) From() common.Address { return m.CallMsg.From }
func (m callMsg) Nonce() uint64 { return 0 }
func (m callMsg) IsFake() bool { return true }
func (m callMsg) IsSystemTx() bool { return false }
func (m callMsg) To() *common.Address { return m.CallMsg.To }
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }
Expand All @@ -885,6 +884,8 @@ func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
func (m callMsg) Data() []byte { return m.CallMsg.Data }
func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }
func (m callMsg) IsSystemTx() bool { return false }
func (m callMsg) IsDepositTx() bool { return false }
func (m callMsg) Mint() *big.Int { return nil }
func (m callMsg) RollupDataGas() uint64 { return 0 }

Expand Down
3 changes: 1 addition & 2 deletions core/rollup_l1_cost.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
)
Expand All @@ -47,7 +46,7 @@ func NewL1CostFunc(config *params.ChainConfig, statedb vm.StateDB) vm.L1CostFunc
var l1BaseFee, overhead, scalar, decimals, divisor *big.Int
return func(blockNum uint64, msg vm.RollupMessage) *big.Int {
rollupDataGas := msg.RollupDataGas() // Only fake txs for RPC view-calls are 0.
if config.Optimism == nil || msg.Nonce() == types.DepositsNonce || rollupDataGas == 0 {
if config.Optimism == nil || msg.IsDepositTx() || rollupDataGas == 0 {
return nil
}
if blockNum != cacheBlockNum {
Expand Down
14 changes: 7 additions & 7 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ type Message interface {
Gas() uint64
Value() *big.Int

// Mint is nil if there is no minting
Mint() *big.Int
RollupDataGas() uint64
IsSystemTx() bool // IsSystemTx indicates the message, if also a deposit, does not emit gas usage.
IsDepositTx() bool // IsDepositTx indicates the message is force-included and can persist a mint.
Mint() *big.Int // Mint is the amount to mint before EVM processing, or nil if there is no minting.
RollupDataGas() uint64 // RollupDataGas indicates the rollup cost of the message, 0 if not a rollup or no cost.

Nonce() uint64
IsFake() bool
IsSystemTx() bool
Data() []byte
AccessList() types.AccessList
}
Expand Down Expand Up @@ -229,7 +229,7 @@ func (st *StateTransition) buyGas() error {
}

func (st *StateTransition) preCheck() error {
if st.msg.Nonce() == types.DepositsNonce {
if st.msg.IsDepositTx() {
// No fee fields to check, no nonce to check, and no need to check if EOA (L1 already verified it for us)
// Gas is free, but no refunds!
st.initialGas = st.msg.Gas()
Expand Down Expand Up @@ -309,7 +309,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
result, err := st.innerTransitionDb()
// Failed deposits must still be included. Unless we cannot produce the block at all due to the gas limit.
// On deposit failure, we rewind any state changes from after the minting, and increment the nonce.
if err != nil && err != ErrGasLimitReached && st.msg.Nonce() == types.DepositsNonce {
if err != nil && err != ErrGasLimitReached && st.msg.IsDepositTx() {
st.state.RevertToSnapshot(snap)
// Even though we revert the state changes, always increment the nonce for the next deposit transaction
st.state.SetNonce(st.msg.From(), st.state.GetNonce(st.msg.From())+1)
Expand Down Expand Up @@ -391,7 +391,7 @@ func (st *StateTransition) innerTransitionDb() (*ExecutionResult, error) {
}

// if deposit: skip refunds, skip tipping coinbase
if st.msg.Nonce() == types.DepositsNonce {
if st.msg.IsDepositTx() {
// Record deposits as using all their gas (matches the gas pool)
// System Transactions are special & are not recorded as using any gas (anywhere)
gasUsed := st.msg.Gas()
Expand Down
6 changes: 1 addition & 5 deletions core/types/deposit_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ func (tx *DepositTx) copy() TxData {
return cpy
}

// DepositsNonce identifies a deposit, since go-ethereum abstracts all transaction types to a core.Message.
// Deposits do not set a nonce, deposits are included by the system and cannot be repeated or included elsewhere.
const DepositsNonce uint64 = 0xffff_ffff_ffff_fffd

// accessors for innerTx.
func (tx *DepositTx) txType() byte { return DepositTxType }
func (tx *DepositTx) chainID() *big.Int { return common.Big0 }
Expand All @@ -78,7 +74,7 @@ func (tx *DepositTx) gasFeeCap() *big.Int { return new(big.Int) }
func (tx *DepositTx) gasTipCap() *big.Int { return new(big.Int) }
func (tx *DepositTx) gasPrice() *big.Int { return new(big.Int) }
func (tx *DepositTx) value() *big.Int { return tx.Value }
func (tx *DepositTx) nonce() uint64 { return DepositsNonce }
func (tx *DepositTx) nonce() uint64 { return 0 }
func (tx *DepositTx) to() *common.Address { return tx.To }
func (tx *DepositTx) isSystemTx() bool { return tx.IsSystemTransaction }

Expand Down
33 changes: 21 additions & 12 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ func (tx *Transaction) Mint() *big.Int {
return nil
}

// IsDepositTx returns true if the transaction is a deposit tx type.
func (tx *Transaction) IsDepositTx() bool {
return tx.Type() == DepositTxType
}

// IsSystemTx returns true for deposits that are system transactions. These transactions
// are executed in an unmetered environment & do not contribute to the block gas limit.
func (tx *Transaction) IsSystemTx() bool {
Expand Down Expand Up @@ -656,9 +661,11 @@ type Message struct {
data []byte
accessList AccessList
isFake bool
isSystemTx bool
mint *big.Int
l1CostGas uint64
// Optimism rollup fields
isSystemTx bool
isDepositTx bool
mint *big.Int
l1CostGas uint64
}

func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice, gasFeeCap, gasTipCap *big.Int, data []byte, accessList AccessList, isFake bool) Message {
Expand All @@ -674,9 +681,11 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
data: data,
accessList: accessList,
isFake: isFake,
isSystemTx: false,
mint: nil,
l1CostGas: 0,
// Optimism rollup fields
isSystemTx: false,
isDepositTx: false,
mint: nil,
l1CostGas: 0,
}
}

Expand All @@ -693,12 +702,11 @@ func (tx *Transaction) AsMessage(s Signer, baseFee *big.Int) (Message, error) {
data: tx.Data(),
accessList: tx.AccessList(),
isFake: false,
isSystemTx: tx.inner.isSystemTx(),
}
if dep, ok := tx.inner.(*DepositTx); ok {
msg.mint = dep.Mint
} else {
msg.l1CostGas = tx.RollupDataGas()
// Optimism rollup fields
isSystemTx: tx.inner.isSystemTx(),
isDepositTx: tx.IsDepositTx(),
mint: tx.Mint(),
l1CostGas: tx.RollupDataGas(),
}
// If baseFee provided, set gasPrice to effectiveGasPrice.
if baseFee != nil {
Expand All @@ -721,6 +729,7 @@ func (m Message) Data() []byte { return m.data }
func (m Message) AccessList() AccessList { return m.accessList }
func (m Message) IsFake() bool { return m.isFake }
func (m Message) IsSystemTx() bool { return m.isSystemTx }
func (m Message) IsDepositTx() bool { return m.isDepositTx }
func (m Message) Mint() *big.Int { return m.mint }
func (m Message) RollupDataGas() uint64 { return m.l1CostGas }

Expand Down
4 changes: 3 additions & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
"sync/atomic"
"time"

"github.com/holiman/uint256"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
)

// emptyCodeHash is used by create to ensure deployment is disallowed to already
Expand All @@ -34,6 +35,7 @@ var emptyCodeHash = crypto.Keccak256Hash(nil)
type RollupMessage interface {
Nonce() uint64
RollupDataGas() uint64
IsDepositTx() bool
}

type (
Expand Down