|
|
@ -25,6 +25,7 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
goruntime "runtime" |
|
|
|
goruntime "runtime" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/cmd/evm/internal/compiler" |
|
|
|
"github.com/ethereum/go-ethereum/cmd/utils" |
|
|
|
"github.com/ethereum/go-ethereum/cmd/utils" |
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/core/state" |
|
|
|
"github.com/ethereum/go-ethereum/core/state" |
|
|
@ -53,7 +54,6 @@ func runCmd(ctx *cli.Context) error { |
|
|
|
statedb, _ = state.New(common.Hash{}, db) |
|
|
|
statedb, _ = state.New(common.Hash{}, db) |
|
|
|
sender = common.StringToAddress("sender") |
|
|
|
sender = common.StringToAddress("sender") |
|
|
|
logger = vm.NewStructLogger(nil) |
|
|
|
logger = vm.NewStructLogger(nil) |
|
|
|
tstart = time.Now() |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
statedb.CreateAccount(sender) |
|
|
|
statedb.CreateAccount(sender) |
|
|
|
|
|
|
|
|
|
|
@ -62,7 +62,18 @@ func runCmd(ctx *cli.Context) error { |
|
|
|
ret []byte |
|
|
|
ret []byte |
|
|
|
err error |
|
|
|
err error |
|
|
|
) |
|
|
|
) |
|
|
|
if ctx.GlobalString(CodeFlag.Name) != "" { |
|
|
|
if fn := ctx.Args().First(); len(fn) > 0 { |
|
|
|
|
|
|
|
src, err := ioutil.ReadFile(fn) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bin, err := compiler.Compile(fn, src, false) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
code = common.Hex2Bytes(bin) |
|
|
|
|
|
|
|
} else if ctx.GlobalString(CodeFlag.Name) != "" { |
|
|
|
code = common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name)) |
|
|
|
code = common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var hexcode []byte |
|
|
|
var hexcode []byte |
|
|
@ -84,9 +95,7 @@ func runCmd(ctx *cli.Context) error { |
|
|
|
code = common.Hex2Bytes(string(bytes.TrimRight(hexcode, "\n"))) |
|
|
|
code = common.Hex2Bytes(string(bytes.TrimRight(hexcode, "\n"))) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ctx.GlobalBool(CreateFlag.Name) { |
|
|
|
runtimeConfig := runtime.Config{ |
|
|
|
input := append(code, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name))...) |
|
|
|
|
|
|
|
ret, _, err = runtime.Create(input, &runtime.Config{ |
|
|
|
|
|
|
|
Origin: sender, |
|
|
|
Origin: sender, |
|
|
|
State: statedb, |
|
|
|
State: statedb, |
|
|
|
GasLimit: ctx.GlobalUint64(GasFlag.Name), |
|
|
|
GasLimit: ctx.GlobalUint64(GasFlag.Name), |
|
|
@ -97,46 +106,43 @@ func runCmd(ctx *cli.Context) error { |
|
|
|
Debug: ctx.GlobalBool(DebugFlag.Name), |
|
|
|
Debug: ctx.GlobalBool(DebugFlag.Name), |
|
|
|
DisableGasMetering: ctx.GlobalBool(DisableGasMeteringFlag.Name), |
|
|
|
DisableGasMetering: ctx.GlobalBool(DisableGasMeteringFlag.Name), |
|
|
|
}, |
|
|
|
}, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tstart := time.Now() |
|
|
|
|
|
|
|
if ctx.GlobalBool(CreateFlag.Name) { |
|
|
|
|
|
|
|
input := append(code, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name))...) |
|
|
|
|
|
|
|
ret, _, err = runtime.Create(input, &runtimeConfig) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
receiver := common.StringToAddress("receiver") |
|
|
|
receiver := common.StringToAddress("receiver") |
|
|
|
statedb.SetCode(receiver, code) |
|
|
|
statedb.SetCode(receiver, code) |
|
|
|
|
|
|
|
|
|
|
|
ret, err = runtime.Call(receiver, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)), &runtime.Config{ |
|
|
|
ret, err = runtime.Call(receiver, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)), &runtimeConfig) |
|
|
|
Origin: sender, |
|
|
|
|
|
|
|
State: statedb, |
|
|
|
|
|
|
|
GasLimit: ctx.GlobalUint64(GasFlag.Name), |
|
|
|
|
|
|
|
GasPrice: utils.GlobalBig(ctx, PriceFlag.Name), |
|
|
|
|
|
|
|
Value: utils.GlobalBig(ctx, ValueFlag.Name), |
|
|
|
|
|
|
|
EVMConfig: vm.Config{ |
|
|
|
|
|
|
|
Tracer: logger, |
|
|
|
|
|
|
|
Debug: ctx.GlobalBool(DebugFlag.Name), |
|
|
|
|
|
|
|
DisableGasMetering: ctx.GlobalBool(DisableGasMeteringFlag.Name), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
vmdone := time.Since(tstart) |
|
|
|
execTime := time.Since(tstart) |
|
|
|
|
|
|
|
|
|
|
|
if ctx.GlobalBool(DumpFlag.Name) { |
|
|
|
if ctx.GlobalBool(DumpFlag.Name) { |
|
|
|
statedb.Commit(true) |
|
|
|
statedb.Commit(true) |
|
|
|
fmt.Println(string(statedb.Dump())) |
|
|
|
fmt.Println(string(statedb.Dump())) |
|
|
|
} |
|
|
|
} |
|
|
|
vm.StdErrFormat(logger.StructLogs()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.GlobalBool(SysStatFlag.Name) { |
|
|
|
if ctx.GlobalBool(DebugFlag.Name) { |
|
|
|
|
|
|
|
fmt.Fprintln(os.Stderr, "#### TRACE ####") |
|
|
|
|
|
|
|
vm.WriteTrace(os.Stderr, logger.StructLogs()) |
|
|
|
|
|
|
|
fmt.Fprintln(os.Stderr, "#### LOGS ####") |
|
|
|
|
|
|
|
vm.WriteLogs(os.Stderr, statedb.Logs()) |
|
|
|
|
|
|
|
|
|
|
|
var mem goruntime.MemStats |
|
|
|
var mem goruntime.MemStats |
|
|
|
goruntime.ReadMemStats(&mem) |
|
|
|
goruntime.ReadMemStats(&mem) |
|
|
|
fmt.Printf("vm took %v\n", vmdone) |
|
|
|
fmt.Fprintf(os.Stderr, `evm execution time: %v |
|
|
|
fmt.Printf(`alloc: %d |
|
|
|
heap objects: %d |
|
|
|
tot alloc: %d |
|
|
|
allocations: %d |
|
|
|
no. malloc: %d |
|
|
|
total allocations: %d |
|
|
|
heap alloc: %d |
|
|
|
GC calls: %d |
|
|
|
heap objs: %d |
|
|
|
|
|
|
|
num gc: %d |
|
|
|
`, execTime, mem.HeapObjects, mem.Alloc, mem.TotalAlloc, mem.NumGC) |
|
|
|
`, mem.Alloc, mem.TotalAlloc, mem.Mallocs, mem.HeapAlloc, mem.HeapObjects, mem.NumGC) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fmt.Printf("OUT: 0x%x", ret) |
|
|
|
fmt.Printf("0x%x", ret) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
fmt.Printf(" error: %v", err) |
|
|
|
fmt.Printf(" error: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|