refactor(evm): Remove duplicate defined variables (#559)

Refactor: Remove duplicate defined variables
This commit is contained in:
DongXi Huang 2023-11-12 21:17:37 +08:00 committed by GitHub
parent 65a3a7fc23
commit d537451863
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,8 +43,10 @@ The state transitioning model does all the necessary work to work out a valid ne
3) Create a new state object if the recipient is \0*32 3) Create a new state object if the recipient is \0*32
4) Value transfer 4) Value transfer
== If contract creation == == If contract creation ==
4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object 4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object
== end == == end ==
5) Run Script section 5) Run Script section
6) Derive new state root 6) Derive new state root
@ -315,13 +317,13 @@ func (st *StateTransition) preCheck() error {
// TransitionDb will transition the state by applying the current message and // TransitionDb will transition the state by applying the current message and
// returning the evm execution result with following fields. // returning the evm execution result with following fields.
// //
// - used gas: // - used gas:
// total gas used (including gas being refunded) // total gas used (including gas being refunded)
// - returndata: // - returndata:
// the returned data from evm // the returned data from evm
// - concrete execution error: // - concrete execution error:
// various **EVM** error which aborts the execution, // various **EVM** error which aborts the execution,
// e.g. ErrOutOfGas, ErrExecutionReverted // e.g. ErrOutOfGas, ErrExecutionReverted
// //
// However if any consensus issue encountered, return the error directly with // However if any consensus issue encountered, return the error directly with
// nil evm execution result. // nil evm execution result.
@ -340,16 +342,16 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
if err := st.preCheck(); err != nil { if err := st.preCheck(); err != nil {
return nil, err return nil, err
} }
msg := st.msg
sender := vm.AccountRef(msg.From()) var (
homestead := st.evm.ChainConfig().IsHomestead(st.evm.Context.BlockNumber) msg = st.msg
istanbul := st.evm.ChainConfig().IsIstanbul(st.evm.Context.BlockNumber) sender = vm.AccountRef(msg.From())
shanghai := st.evm.ChainConfig().IsShanghai(st.evm.Context.BlockNumber) rules = st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber)
london := st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) contractCreation = msg.To() == nil
contractCreation := msg.To() == nil )
// Check clauses 4-5, subtract intrinsic gas if everything is correct // Check clauses 4-5, subtract intrinsic gas if everything is correct
gas, err := IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, homestead, istanbul, shanghai) gas, err := IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, rules.IsHomestead, rules.IsIstanbul, rules.IsShanghai)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -363,8 +365,6 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
return nil, fmt.Errorf("%w: address %v", ErrInsufficientFundsForTransfer, msg.From().Hex()) return nil, fmt.Errorf("%w: address %v", ErrInsufficientFundsForTransfer, msg.From().Hex())
} }
rules := st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber)
// Check whether the init code size has been exceeded. // Check whether the init code size has been exceeded.
if rules.IsShanghai && contractCreation && len(st.data) > params.MaxInitCodeSize { if rules.IsShanghai && contractCreation && len(st.data) > params.MaxInitCodeSize {
return nil, fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(st.data), params.MaxInitCodeSize) return nil, fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(st.data), params.MaxInitCodeSize)
@ -397,7 +397,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
}, nil }, nil
} }
if !london { if !rules.IsLondon {
// Before EIP-3529: refunds were capped to gasUsed / 2 // Before EIP-3529: refunds were capped to gasUsed / 2
st.refundGas(params.RefundQuotient) st.refundGas(params.RefundQuotient)
} else { } else {
@ -405,7 +405,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
st.refundGas(params.RefundQuotientEIP3529) st.refundGas(params.RefundQuotientEIP3529)
} }
effectiveTip := st.gasPrice effectiveTip := st.gasPrice
if london { if rules.IsLondon {
if st.evm.Context.BaseFee != nil { if st.evm.Context.BaseFee != nil {
effectiveTip = cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee)) effectiveTip = cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee))
} else { } else {