From ed2e4d2cb8abf04b24e984f13d9db8362e426cb1 Mon Sep 17 00:00:00 2001 From: Joshua Gutow Date: Wed, 1 Jun 2022 10:35:33 -0700 Subject: [PATCH] core: Include guaranteed gas in the gas pool (#21) This now requires L1 to limit the total amount of guaranteed gas that is provided to deposits. This includes the guaranteed gas in the total gas used in order to limit the number of normal transactions in a block and enable accurate EIP-1559 basefee updates. --- core/state_transition.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index d97a8d629cf9..7c0643a2ff10 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -301,7 +301,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { // 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) result = &ExecutionResult{ - UsedGas: 0, // No gas charge on non-EVM fails like balance checks, congestion is controlled on L1 + UsedGas: st.msg.Gas(), // Always record the deposit using the full amount of gas Err: fmt.Errorf("failed deposit: %w", err), ReturnData: nil, } @@ -341,17 +341,15 @@ func (st *StateTransition) innerTransitionDb() (*ExecutionResult, error) { contractCreation = msg.To() == nil ) - if st.msg.Nonce() != types.DepositsNonce { - // Check clauses 4-5, subtract intrinsic gas if everything is correct - gas, err := IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, rules.IsHomestead, rules.IsIstanbul) - if err != nil { - return nil, err - } - if st.gas < gas { - return nil, fmt.Errorf("%w: have %d, want %d", ErrIntrinsicGas, st.gas, gas) - } - st.gas -= gas + // Check clauses 4-5, subtract intrinsic gas if everything is correct + gas, err := IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, rules.IsHomestead, rules.IsIstanbul) + if err != nil { + return nil, err + } + if st.gas < gas { + return nil, fmt.Errorf("%w: have %d, want %d", ErrIntrinsicGas, st.gas, gas) } + st.gas -= gas // Check clause 6 if msg.Value().Sign() > 0 && !st.evm.Context.CanTransfer(st.state, msg.From(), msg.Value()) { @@ -377,7 +375,7 @@ func (st *StateTransition) innerTransitionDb() (*ExecutionResult, error) { // if deposit: skip refunds, skip tipping coinbase if st.msg.Nonce() == types.DepositsNonce { return &ExecutionResult{ - UsedGas: 0, // Ignore actual used gas for deposits (until full deposit gas design is done) + UsedGas: st.msg.Gas(), // Always record the deposit using the full amount of gas Err: vmerr, ReturnData: ret, }, nil