Skip to content

Commit 2233a6c

Browse files
authored
Merge pull request #828 from gzliudan/upgrade_vm
upgrade core/vm
2 parents ed74ab2 + 240de84 commit 2233a6c

File tree

24 files changed

+146
-131
lines changed

24 files changed

+146
-131
lines changed

cmd/evm/runner.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ func runCmd(ctx *cli.Context) error {
162162
Value: flags.GlobalBig(ctx, ValueFlag.Name),
163163
EVMConfig: vm.Config{
164164
Tracer: tracer,
165-
Debug: ctx.Bool(DebugFlag.Name) || ctx.Bool(MachineFlag.Name),
166165
},
167166
}
168167

cmd/evm/staterunner.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ func stateTestCmd(ctx *cli.Context) error {
8383
// Iterate over all the tests, run them and aggregate the results
8484
cfg := vm.Config{
8585
Tracer: tracer,
86-
Debug: ctx.Bool(DebugFlag.Name) || ctx.Bool(MachineFlag.Name),
8786
}
8887
results := make([]StatetestResult, 0, len(tests))
8988
for key, test := range tests {

consensus/XDPoS/engines/engine_v1/engine.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/XinFinOrg/XDPoSChain/consensus"
1919
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils"
2020
"github.com/XinFinOrg/XDPoSChain/consensus/clique"
21-
"github.com/XinFinOrg/XDPoSChain/consensus/misc"
2221
"github.com/XinFinOrg/XDPoSChain/consensus/misc/eip1559"
2322
"github.com/XinFinOrg/XDPoSChain/core/state"
2423
"github.com/XinFinOrg/XDPoSChain/core/types"
@@ -206,10 +205,6 @@ func (x *XDPoS_v1) verifyHeader(chain consensus.ChainReader, header *types.Heade
206205
if header.UncleHash != utils.UncleHash {
207206
return utils.ErrInvalidUncleHash
208207
}
209-
// If all checks passed, validate any special fields for hard forks
210-
if err := misc.VerifyForkHashes(chain.Config(), header, false); err != nil {
211-
return err
212-
}
213208
// All basic checks passed, verify cascading fields
214209
return x.verifyCascadingFields(chain, header, parents, fullVerify)
215210
}

consensus/XDPoS/engines/engine_v2/verifyHeader.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
1010
"github.com/XinFinOrg/XDPoSChain/consensus"
1111
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils"
12-
"github.com/XinFinOrg/XDPoSChain/consensus/misc"
1312
"github.com/XinFinOrg/XDPoSChain/consensus/misc/eip1559"
1413
"github.com/XinFinOrg/XDPoSChain/core/types"
1514
"github.com/XinFinOrg/XDPoSChain/log"
@@ -162,11 +161,6 @@ func (x *XDPoS_v2) verifyHeader(chain consensus.ChainReader, header *types.Heade
162161
masterNodes = x.GetMasternodes(chain, header)
163162
}
164163

165-
// If all checks passed, validate any special fields for hard forks
166-
if err := misc.VerifyForkHashes(chain.Config(), header, false); err != nil {
167-
return err
168-
}
169-
170164
verified, validatorAddress, err := x.verifyMsgSignature(sigHash(header), header.Validator, masterNodes)
171165
if err != nil {
172166
for index, mn := range masterNodes {

consensus/clique/clique.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,6 @@ func (c *Clique) verifyHeader(chain consensus.ChainReader, header *types.Header,
328328
if header.GasUsed > header.GasLimit {
329329
return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed, header.GasLimit)
330330
}
331-
// If all checks passed, validate any special fields for hard forks
332-
if err := misc.VerifyForkHashes(chain.Config(), header, false); err != nil {
333-
return err
334-
}
335331
// All basic checks passed, verify cascading fields
336332
return c.verifyCascadingFields(chain, header, parents)
337333
}

consensus/ethash/consensus.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,6 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
283283
if err := misc.VerifyDAOHeaderExtraData(chain.Config(), header); err != nil {
284284
return err
285285
}
286-
if err := misc.VerifyForkHashes(chain.Config(), header, uncle); err != nil {
287-
return err
288-
}
289286
return nil
290287
}
291288

consensus/misc/forks.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

core/vm/analysis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (bits *bitvec) codeSegment(pos uint64) bool {
6363
// codeBitmap collects data locations in code.
6464
func codeBitmap(code []byte) bitvec {
6565
// The bitmap is 4 bytes longer than necessary, in case the code
66-
// ends with a PUSH32, the algorithm will push zeroes onto the
66+
// ends with a PUSH32, the algorithm will set bits on the
6767
// bitvector outside the bounds of the actual code.
6868
bits := make(bitvec, len(code)/8+1+4)
6969
return codeBitmapInternal(code, bits)

core/vm/evm.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ type EVM struct {
121121
// used throughout the execution of the tx.
122122
interpreter *EVMInterpreter
123123
// abort is used to abort the EVM calling operations
124-
// NOTE: must be set atomically
125-
abort int32
124+
abort atomic.Bool
126125
// callGasTemp holds the gas available for the current call. This is needed because the
127126
// available gas is calculated in gasCall* according to the 63/64 rule and later
128127
// applied in opCall*.
@@ -156,12 +155,12 @@ func (evm *EVM) Reset(txCtx TxContext, statedb StateDB) {
156155
// Cancel cancels any running EVM operation. This may be called concurrently and
157156
// it's safe to be called multiple times.
158157
func (evm *EVM) Cancel() {
159-
atomic.StoreInt32(&evm.abort, 1)
158+
evm.abort.Store(true)
160159
}
161160

162161
// Cancelled returns true if Cancel has been called
163162
func (evm *EVM) Cancelled() bool {
164-
return atomic.LoadInt32(&evm.abort) == 1
163+
return evm.abort.Load()
165164
}
166165

167166
// Interpreter returns the current interpreter
@@ -190,11 +189,12 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
190189
}
191190
snapshot := evm.StateDB.Snapshot()
192191
p, isPrecompile := evm.precompile(addr)
192+
debug := evm.Config.Tracer != nil
193193

194194
if !evm.StateDB.Exist(addr) {
195195
if !isPrecompile && evm.chainRules.IsEIP158 && value.Sign() == 0 {
196196
// Calling a non existing account, don't do anything, but ping the tracer
197-
if evm.Config.Debug {
197+
if debug {
198198
if evm.depth == 0 {
199199
evm.Config.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
200200
evm.Config.Tracer.CaptureEnd(ret, 0, 0, nil)
@@ -210,7 +210,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
210210
evm.Context.Transfer(evm.StateDB, caller.Address(), addr, value)
211211

212212
// Capture the tracer start/end events in debug mode
213-
if evm.Config.Debug {
213+
if debug {
214214
if evm.depth == 0 {
215215
evm.Config.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
216216

@@ -281,7 +281,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
281281
var snapshot = evm.StateDB.Snapshot()
282282

283283
// Invoke tracer hooks that signal entering/exiting a call frame
284-
if evm.Config.Debug {
284+
if evm.Config.Tracer != nil {
285285
evm.Config.Tracer.CaptureEnter(CALLCODE, caller.Address(), addr, input, gas, value)
286286
defer func(startGas uint64) {
287287
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
@@ -322,7 +322,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
322322
var snapshot = evm.StateDB.Snapshot()
323323

324324
// Invoke tracer hooks that signal entering/exiting a call frame
325-
if evm.Config.Debug {
325+
if evm.Config.Tracer != nil {
326326
evm.Config.Tracer.CaptureEnter(DELEGATECALL, caller.Address(), addr, input, gas, nil)
327327
defer func(startGas uint64) {
328328
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
@@ -372,7 +372,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
372372
evm.StateDB.AddBalance(addr, big0)
373373

374374
// Invoke tracer hooks that signal entering/exiting a call frame
375-
if evm.Config.Debug {
375+
if evm.Config.Tracer != nil {
376376
evm.Config.Tracer.CaptureEnter(STATICCALL, caller.Address(), addr, input, gas, nil)
377377
defer func(startGas uint64) {
378378
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
@@ -456,7 +456,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
456456
contract := NewContract(caller, AccountRef(address), value, gas)
457457
contract.SetCodeOptionalHash(&address, codeAndHash)
458458

459-
if evm.Config.Debug {
459+
if evm.Config.Tracer != nil {
460460
if evm.depth == 0 {
461461
evm.Config.Tracer.CaptureStart(evm, caller.Address(), address, true, codeAndHash.code, gas, value)
462462
} else {
@@ -500,7 +500,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
500500
}
501501
}
502502

503-
if evm.Config.Debug {
503+
if evm.Config.Tracer != nil {
504504
if evm.depth == 0 {
505505
evm.Config.Tracer.CaptureEnd(ret, gas-contract.Gas, time.Since(start), err)
506506
} else {

core/vm/instructions.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package vm
1818

1919
import (
20-
"sync/atomic"
21-
2220
"github.com/XinFinOrg/XDPoSChain/common"
2321
"github.com/XinFinOrg/XDPoSChain/core/types"
2422
"github.com/XinFinOrg/XDPoSChain/crypto"
@@ -544,7 +542,7 @@ func opSstore(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b
544542
}
545543

546544
func opJump(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
547-
if atomic.LoadInt32(&interpreter.evm.abort) != 0 {
545+
if interpreter.evm.abort.Load() {
548546
return nil, errStopToken
549547
}
550548
pos := scope.Stack.pop()
@@ -556,7 +554,7 @@ func opJump(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byt
556554
}
557555

558556
func opJumpi(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
559-
if atomic.LoadInt32(&interpreter.evm.abort) != 0 {
557+
if interpreter.evm.abort.Load() {
560558
return nil, errStopToken
561559
}
562560
pos, cond := scope.Stack.pop(), scope.Stack.pop()
@@ -838,9 +836,9 @@ func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
838836
balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address())
839837
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance)
840838
interpreter.evm.StateDB.SelfDestruct(scope.Contract.Address())
841-
if interpreter.evm.Config.Debug {
842-
interpreter.evm.Config.Tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
843-
interpreter.evm.Config.Tracer.CaptureExit([]byte{}, 0, nil)
839+
if tracer := interpreter.evm.Config.Tracer; tracer != nil {
840+
tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
841+
tracer.CaptureExit([]byte{}, 0, nil)
844842
}
845843
return nil, errStopToken
846844
}

0 commit comments

Comments
 (0)