core/vm: avoid unnecessary use of big.Int:BitLen()

This commit is contained in:
Martin Holst Swende 2019-03-11 20:38:50 +01:00
parent 81a2fb8c4e
commit fd4bee4f21
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
3 changed files with 4 additions and 4 deletions

View file

@ -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 // 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 // is smaller than the requested amount. Therefor we return the new gas instead
// of returning an error. // of returning an error.
if callCost.BitLen() > 64 || gas < callCost.Uint64() { if !callCost.IsUint64() || gas < callCost.Uint64() {
return gas, nil return gas, nil
} }
} }
if callCost.BitLen() > 64 { if !callCost.IsUint64() {
return 0, errGasUintOverflow return 0, errGasUintOverflow
} }

View file

@ -467,7 +467,7 @@ func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contrac
) )
defer interpreter.intPool.put(memOffset, dataOffset, length, end) 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 return nil, errReturnDataOutOfBounds
} }
memory.Set(memOffset.Uint64(), length.Uint64(), interpreter.returnData[dataOffset.Uint64():end.Uint64()]) memory.Set(memOffset.Uint64(), length.Uint64(), interpreter.returnData[dataOffset.Uint64():end.Uint64()])

View file

@ -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 // for a call operation is the value. Transferring value from one
// account to the others means the state is modified and should also // account to the others means the state is modified and should also
// return with an error. // 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 return nil, errWriteProtection
} }
} }