Skip to content

Commit

Permalink
Merge pull request expanse-org#33 from happyuc-project/huc/v0.0.5
Browse files Browse the repository at this point in the history
fix bug: jump over the evm interpreter when send hucer to contract
  • Loading branch information
ldcc authored Jun 15, 2018
2 parents b584ca8 + 62f2121 commit 73ecc8c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
13 changes: 6 additions & 7 deletions core/vm/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,17 @@ type Contract struct {
CodeHash common.Hash
CodeAddr *common.Address
Input []byte

Gas uint64
value *big.Int

Args []byte
Gas uint64
value *big.Int
Args []byte

DelegateCall bool
creation bool
}

// NewContract returns a new contract environment for the execution of EVM.
func NewContract(caller ContractRef, object ContractRef, value *big.Int, gas uint64) *Contract {
c := &Contract{CallerAddress: caller.Address(), caller: caller, self: object, Args: nil}
func NewContract(caller ContractRef, object ContractRef, value *big.Int, gas uint64, creation bool) *Contract {
c := &Contract{CallerAddress: caller.Address(), caller: caller, self: object, Args: nil, creation: creation}

if parent, ok := caller.(*Contract); ok {
// Reuse JUMPDEST analysis from parent context if available.
Expand Down
10 changes: 5 additions & 5 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas

// Initialise a new contract and set the code that is to be used by the EVM.
// The contract is a scoped environment for this execution context only.
contract := NewContract(caller, to, value, gas)
contract := NewContract(caller, to, value, gas, false)
contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr))

start := time.Now()
Expand Down Expand Up @@ -220,7 +220,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
// initialise a new contract and set the code that is to be used by the
// EVM. The contract is a scoped environment for this execution context
// only.
contract := NewContract(caller, to, value, gas)
contract := NewContract(caller, to, value, gas, false)
contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr))

ret, err = run(evm, contract, input)
Expand Down Expand Up @@ -253,7 +253,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
)

// Initialise a new contract and make initialise the delegate values
contract := NewContract(caller, to, nil, gas).AsDelegate()
contract := NewContract(caller, to, nil, gas, false).AsDelegate()
contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr))

ret, err = run(evm, contract, input)
Expand Down Expand Up @@ -293,7 +293,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
// Initialise a new contract and set the code that is to be used by the
// EVM. The contract is a scoped environment for this execution context
// only.
contract := NewContract(caller, to, new(big.Int), gas)
contract := NewContract(caller, to, new(big.Int), gas, false)
contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr))

// When an error was returned by the EVM or when setting the creation code
Expand Down Expand Up @@ -337,7 +337,7 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
// initialise a new contract and set the code that is to be used by the
// EVM. The contract is a scoped environment for this execution context
// only.
contract := NewContract(caller, AccountRef(contractAddr), value, gas)
contract := NewContract(caller, AccountRef(contractAddr), value, gas, true)
contract.SetCallCode(&contractAddr, crypto.Keccak256Hash(code), code)

if evm.vmConfig.NoRecursion && evm.depth > 0 {
Expand Down
2 changes: 1 addition & 1 deletion core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (in *Interpreter) Run(contract *Contract, input []byte) (ret []byte, err er
in.returnData = nil

// Don't bother with the execution if there's no code.
if len(contract.Code) == 0 {
if len(contract.Code) == 0 || len(input) == 0 && !contract.creation {
return nil, nil
}

Expand Down
6 changes: 3 additions & 3 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func (self *worker) commitNewWork() {
panic(false)
}

log.Trace("Commit new mining work", "number", work.Block.Number(), "txs num", work.tcount, "uncles", len(uncles))
log.Info("Commit new mining work", "number", work.Block.Number(), "txs num", work.tcount, "uncles", len(uncles))
self.unconfirmed.Shift(work.Block.NumberU64() - 1)
self.push(work)
self.updateSnapshot()
Expand Down Expand Up @@ -555,8 +555,8 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB
log.Trace("Skipping transaction with low nonce", "sender", from, "nonce", tx.Nonce())
txs.Shift()
case core.ErrNonceTooHigh:
// Reorg notification data race between the transaction pool and miner, skip account =
log.Trace("Skipping account with hight nonce", "sender", from, "nonce", tx.Nonce())
// Reorg notification data race between the transaction pool and miner, skip account
log.Trace("Skipping account with high nonce", "sender", from, "nonce", tx.Nonce())
txs.Pop()
case nil:
// Everything ok, collect the logs and shift in the next transaction from the same account
Expand Down

0 comments on commit 73ecc8c

Please sign in to comment.