Skip to content

Commit

Permalink
core: Include guaranteed gas in the gas pool (ethereum#21)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
trianglesphere authored and protolambda committed Nov 4, 2022
1 parent db3c30f commit ed2e4d2
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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
Expand Down

0 comments on commit ed2e4d2

Please sign in to comment.