core/vm: EVMJIT: fix some pending issues

This commit is contained in:
Paweł Bylica 2016-12-22 20:45:14 +01:00
parent 9391a910b6
commit 4e677b3dc0
No known key found for this signature in database
GPG key ID: 7A0C037434FE77EF

View file

@ -38,17 +38,17 @@ static struct evm_instance* new_evmjit()
} }
static struct evm_result evm_execute(struct evm_instance* instance, static struct evm_result evm_execute(struct evm_instance* instance,
struct evm_env* env, struct evm_env* env, enum evm_mode mode, struct evm_uint256be code_hash,
enum evm_mode mode, uint8_t const* code, size_t code_size, int64_t gas, uint8_t const* input,
struct evm_uint256be code_hash, size_t input_size, struct evm_uint256be value)
uint8_t const* code,
size_t code_size,
int64_t gas,
uint8_t const* input,
size_t input_size,
struct evm_uint256be value)
{ {
return instance->execute(instance, env, mode, code_hash, code, code_size, gas, input, input_size, value); return instance->execute(instance, env, mode, code_hash, code, code_size,
gas, input, input_size, value);
}
static void evm_release_result(struct evm_result* result)
{
result->release(result);
} }
#cgo CFLAGS: -I/home/chfast/Projects/ethereum/evmjit/include #cgo CFLAGS: -I/home/chfast/Projects/ethereum/evmjit/include
@ -58,7 +58,6 @@ import "C"
import ( import (
"fmt" "fmt"
"math"
"math/big" "math/big"
"reflect" "reflect"
"sync" "sync"
@ -294,9 +293,6 @@ func call(
output := GoByteSlice(pOutput, outputSize) output := GoByteSlice(pOutput, outputSize)
bigGas := new(big.Int).SetInt64(gas) bigGas := new(big.Int).SetInt64(gas)
// FIXME: C.EVM_CALL_FAILURE not available.
const callFailure = math.MinInt64
switch kind { switch kind {
case C.EVM_CALL: case C.EVM_CALL:
// fmt.Printf("CALL(gas %d, %x)\n", bigGas, address) // fmt.Printf("CALL(gas %d, %x)\n", bigGas, address)
@ -308,13 +304,9 @@ func call(
if err == nil { if err == nil {
copy(output, ret) copy(output, ret)
assert(gasLeft <= gas, fmt.Sprintf("%d <= %d", gasLeft, gas)) assert(gasLeft <= gas, fmt.Sprintf("%d <= %d", gasLeft, gas))
// This can happen for precompiled contracts:
// if (gasLeft == gas) {
// assert(len(output) == 0, fmt.Sprintf("Non-zero output: %d %x", len(output), output))
// }
return gasLeft return gasLeft
} }
return gasLeft | callFailure return gasLeft | C.EVM_CALL_FAILURE
case C.EVM_CALLCODE: case C.EVM_CALLCODE:
// fmt.Printf("CALLCODE(gas %d, %x, value %d)\n", bigGas, address, value) // fmt.Printf("CALLCODE(gas %d, %x, value %d)\n", bigGas, address, value)
ctx.contract.Gas.SetInt64(0) ctx.contract.Gas.SetInt64(0)
@ -328,7 +320,7 @@ func call(
} else { } else {
// fmt.Printf("Error: %v\n", err) // fmt.Printf("Error: %v\n", err)
} }
return gasLeft | callFailure return gasLeft | C.EVM_CALL_FAILURE
case C.EVM_DELEGATECALL: case C.EVM_DELEGATECALL:
// fmt.Printf("DELEGATECALL(gas %d, %x)\n", bigGas, address) // fmt.Printf("DELEGATECALL(gas %d, %x)\n", bigGas, address)
ctx.contract.Gas.SetInt64(0) ctx.contract.Gas.SetInt64(0)
@ -340,7 +332,7 @@ func call(
copy(output, ret) copy(output, ret)
return gasLeft return gasLeft
} }
return gasLeft | callFailure return gasLeft | C.EVM_CALL_FAILURE
case C.EVM_CREATE: case C.EVM_CREATE:
// fmt.Printf("DELEGATECALL(gas %d, %x)\n", bigGas, address) // fmt.Printf("DELEGATECALL(gas %d, %x)\n", bigGas, address)
ctx.contract.Gas.SetInt64(0) ctx.contract.Gas.SetInt64(0)
@ -349,7 +341,7 @@ func call(
assert(gasLeft <= gas, fmt.Sprintf("%d <= %d", gasLeft, gas)) assert(gasLeft <= gas, fmt.Sprintf("%d <= %d", gasLeft, gas))
if (ctx.env.ChainConfig().IsHomestead(ctx.env.BlockNumber) && err == CodeStoreOutOfGasError) || if (ctx.env.ChainConfig().IsHomestead(ctx.env.BlockNumber) && err == CodeStoreOutOfGasError) ||
(err != nil && err != CodeStoreOutOfGasError) { (err != nil && err != CodeStoreOutOfGasError) {
return callFailure return C.EVM_CALL_FAILURE
} else { } else {
copy(output, addr[:]) copy(output, addr[:])
return gasLeft return gasLeft
@ -423,14 +415,11 @@ func (evm *EVMJIT) Run(contract *Contract, input []byte) (ret []byte, err error)
err = OutOfGasError err = OutOfGasError
} }
if r.internal_memory != nil { C.evm_release_result(&r)
C.free(r.internal_memory)
}
return output, err return output, err
} }
func (evm *EVMJIT) RunPrecompiled(p *PrecompiledAccount, input []byte, contract *Contract) (ret []byte, err error) { func (evm *EVMJIT) RunPrecompiled(p *PrecompiledAccount, input []byte, contract *Contract) (ret []byte, err error) {
// fmt.Printf("PRECOMPILED %x\n", *contract.CodeAddr)
gas := p.Gas(len(input)) gas := p.Gas(len(input))
if contract.UseGas(gas) { if contract.UseGas(gas) {
ret = p.Call(input) ret = p.Call(input)