From fd4bee4f2184cd53a044d5c0e576cbccddc1490f Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 11 Mar 2019 20:38:50 +0100 Subject: [PATCH] core/vm: avoid unnecessary use of big.Int:BitLen() --- core/vm/gas.go | 4 ++-- core/vm/instructions.go | 2 +- core/vm/interpreter.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/vm/gas.go b/core/vm/gas.go index dba1b3a02f..022a84f243 100644 --- a/core/vm/gas.go +++ b/core/vm/gas.go @@ -43,11 +43,11 @@ func callGas(gasTable params.GasTable, availableGas, base uint64, callCost *big. // If the bit length exceeds 64 bit we know that the newly calculated "gas" for EIP150 // is smaller than the requested amount. Therefor we return the new gas instead // of returning an error. - if callCost.BitLen() > 64 || gas < callCost.Uint64() { + if !callCost.IsUint64() || gas < callCost.Uint64() { return gas, nil } } - if callCost.BitLen() > 64 { + if !callCost.IsUint64() { return 0, errGasUintOverflow } diff --git a/core/vm/instructions.go b/core/vm/instructions.go index ebf5a9dbf5..2a062d7e77 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -467,7 +467,7 @@ func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contrac ) defer interpreter.intPool.put(memOffset, dataOffset, length, end) - if end.BitLen() > 64 || uint64(len(interpreter.returnData)) < end.Uint64() { + if !end.IsUint64() || uint64(len(interpreter.returnData)) < end.Uint64() { return nil, errReturnDataOutOfBounds } memory.Set(memOffset.Uint64(), length.Uint64(), interpreter.returnData[dataOffset.Uint64():end.Uint64()]) diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index e454711b8e..4176653700 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -214,7 +214,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( // for a call operation is the value. Transferring value from one // account to the others means the state is modified and should also // return with an error. - if operation.writes || (op == CALL && stack.Back(2).BitLen() > 0) { + if operation.writes || (op == CALL && stack.Back(2).Sign() != 0) { return nil, errWriteProtection } }