@@ -20,21 +20,18 @@ package main
20
20
import (
21
21
"fmt"
22
22
"io/ioutil"
23
- "math/big"
24
23
"os"
25
- "runtime"
24
+ goruntime "runtime"
26
25
"time"
27
26
28
27
"github.com/ethereum/go-ethereum/cmd/utils"
29
28
"github.com/ethereum/go-ethereum/common"
30
- "github.com/ethereum/go-ethereum/core"
31
29
"github.com/ethereum/go-ethereum/core/state"
32
- "github.com/ethereum/go-ethereum/core/types"
33
30
"github.com/ethereum/go-ethereum/core/vm"
31
+ "github.com/ethereum/go-ethereum/core/vm/runtime"
34
32
"github.com/ethereum/go-ethereum/crypto"
35
33
"github.com/ethereum/go-ethereum/ethdb"
36
34
"github.com/ethereum/go-ethereum/logger/glog"
37
- "github.com/ethereum/go-ethereum/params"
38
35
"gopkg.in/urfave/cli.v1"
39
36
)
40
37
@@ -129,13 +126,6 @@ func run(ctx *cli.Context) error {
129
126
130
127
logger := vm .NewStructLogger (nil )
131
128
132
- vmenv := NewEnv (statedb , common .StringToAddress ("evmuser" ), common .Big (ctx .GlobalString (ValueFlag .Name )), vm.Config {
133
- Debug : ctx .GlobalBool (DebugFlag .Name ),
134
- ForceJit : ctx .GlobalBool (ForceJitFlag .Name ),
135
- EnableJit : ! ctx .GlobalBool (DisableJitFlag .Name ),
136
- Tracer : logger ,
137
- })
138
-
139
129
tstart := time .Now ()
140
130
141
131
var (
@@ -168,25 +158,30 @@ func run(ctx *cli.Context) error {
168
158
169
159
if ctx .GlobalBool (CreateFlag .Name ) {
170
160
input := append (code , common .Hex2Bytes (ctx .GlobalString (InputFlag .Name ))... )
171
- ret , _ , err = vmenv .Create (
172
- sender ,
173
- input ,
174
- common .Big (ctx .GlobalString (GasFlag .Name )),
175
- common .Big (ctx .GlobalString (PriceFlag .Name )),
176
- common .Big (ctx .GlobalString (ValueFlag .Name )),
177
- )
161
+ ret , _ , err = runtime .Create (input , & runtime.Config {
162
+ Origin : sender .Address (),
163
+ State : statedb ,
164
+ GasLimit : common .Big (ctx .GlobalString (GasFlag .Name )),
165
+ GasPrice : common .Big (ctx .GlobalString (PriceFlag .Name )),
166
+ Value : common .Big (ctx .GlobalString (ValueFlag .Name )),
167
+ EVMConfig : vm.Config {
168
+ Tracer : logger ,
169
+ },
170
+ })
178
171
} else {
179
172
receiver := statedb .CreateAccount (common .StringToAddress ("receiver" ))
180
-
181
173
receiver .SetCode (crypto .Keccak256Hash (code ), code )
182
- ret , err = vmenv .Call (
183
- sender ,
184
- receiver .Address (),
185
- common .Hex2Bytes (ctx .GlobalString (InputFlag .Name )),
186
- common .Big (ctx .GlobalString (GasFlag .Name )),
187
- common .Big (ctx .GlobalString (PriceFlag .Name )),
188
- common .Big (ctx .GlobalString (ValueFlag .Name )),
189
- )
174
+
175
+ ret , err = runtime .Call (receiver .Address (), common .Hex2Bytes (ctx .GlobalString (InputFlag .Name )), & runtime.Config {
176
+ Origin : sender .Address (),
177
+ State : statedb ,
178
+ GasLimit : common .Big (ctx .GlobalString (GasFlag .Name )),
179
+ GasPrice : common .Big (ctx .GlobalString (PriceFlag .Name )),
180
+ Value : common .Big (ctx .GlobalString (ValueFlag .Name )),
181
+ EVMConfig : vm.Config {
182
+ Tracer : logger ,
183
+ },
184
+ })
190
185
}
191
186
vmdone := time .Since (tstart )
192
187
@@ -197,8 +192,8 @@ func run(ctx *cli.Context) error {
197
192
vm .StdErrFormat (logger .StructLogs ())
198
193
199
194
if ctx .GlobalBool (SysStatFlag .Name ) {
200
- var mem runtime .MemStats
201
- runtime .ReadMemStats (& mem )
195
+ var mem goruntime .MemStats
196
+ goruntime .ReadMemStats (& mem )
202
197
fmt .Printf ("vm took %v\n " , vmdone )
203
198
fmt .Printf (`alloc: %d
204
199
tot alloc: %d
@@ -223,87 +218,3 @@ func main() {
223
218
os .Exit (1 )
224
219
}
225
220
}
226
-
227
- type VMEnv struct {
228
- state * state.StateDB
229
- block * types.Block
230
-
231
- transactor * common.Address
232
- value * big.Int
233
-
234
- depth int
235
- Gas * big.Int
236
- time * big.Int
237
- logs []vm.StructLog
238
-
239
- evm * vm.EVM
240
- }
241
-
242
- func NewEnv (state * state.StateDB , transactor common.Address , value * big.Int , cfg vm.Config ) * VMEnv {
243
- env := & VMEnv {
244
- state : state ,
245
- transactor : & transactor ,
246
- value : value ,
247
- time : big .NewInt (time .Now ().Unix ()),
248
- }
249
-
250
- env .evm = vm .New (env , cfg )
251
- return env
252
- }
253
-
254
- // ruleSet implements vm.ChainConfig and will always default to the homestead rule set.
255
- type ruleSet struct {}
256
-
257
- func (ruleSet ) IsHomestead (* big.Int ) bool { return true }
258
- func (ruleSet ) GasTable (* big.Int ) params.GasTable {
259
- return params .GasTableHomesteadGasRepriceFork
260
- }
261
-
262
- func (self * VMEnv ) ChainConfig () * params.ChainConfig { return params .TestChainConfig }
263
- func (self * VMEnv ) Vm () vm.Vm { return self .evm }
264
- func (self * VMEnv ) Db () vm.Database { return self .state }
265
- func (self * VMEnv ) SnapshotDatabase () int { return self .state .Snapshot () }
266
- func (self * VMEnv ) RevertToSnapshot (snap int ) { self .state .RevertToSnapshot (snap ) }
267
- func (self * VMEnv ) Origin () common.Address { return * self .transactor }
268
- func (self * VMEnv ) BlockNumber () * big.Int { return common .Big0 }
269
- func (self * VMEnv ) Coinbase () common.Address { return * self .transactor }
270
- func (self * VMEnv ) Time () * big.Int { return self .time }
271
- func (self * VMEnv ) Difficulty () * big.Int { return common .Big1 }
272
- func (self * VMEnv ) BlockHash () []byte { return make ([]byte , 32 ) }
273
- func (self * VMEnv ) Value () * big.Int { return self .value }
274
- func (self * VMEnv ) GasLimit () * big.Int { return big .NewInt (1000000000 ) }
275
- func (self * VMEnv ) VmType () vm.Type { return vm .StdVmTy }
276
- func (self * VMEnv ) Depth () int { return 0 }
277
- func (self * VMEnv ) SetDepth (i int ) { self .depth = i }
278
- func (self * VMEnv ) GetHash (n uint64 ) common.Hash {
279
- if self .block .Number ().Cmp (big .NewInt (int64 (n ))) == 0 {
280
- return self .block .Hash ()
281
- }
282
- return common.Hash {}
283
- }
284
- func (self * VMEnv ) AddLog (log * vm.Log ) {
285
- self .state .AddLog (log )
286
- }
287
- func (self * VMEnv ) CanTransfer (from common.Address , balance * big.Int ) bool {
288
- return self .state .GetBalance (from ).Cmp (balance ) >= 0
289
- }
290
- func (self * VMEnv ) Transfer (from , to vm.Account , amount * big.Int ) {
291
- core .Transfer (from , to , amount )
292
- }
293
-
294
- func (self * VMEnv ) Call (caller vm.ContractRef , addr common.Address , data []byte , gas , price , value * big.Int ) ([]byte , error ) {
295
- self .Gas = gas
296
- return core .Call (self , caller , addr , data , gas , price , value )
297
- }
298
-
299
- func (self * VMEnv ) CallCode (caller vm.ContractRef , addr common.Address , data []byte , gas , price , value * big.Int ) ([]byte , error ) {
300
- return core .CallCode (self , caller , addr , data , gas , price , value )
301
- }
302
-
303
- func (self * VMEnv ) DelegateCall (caller vm.ContractRef , addr common.Address , data []byte , gas , price * big.Int ) ([]byte , error ) {
304
- return core .DelegateCall (self , caller , addr , data , gas , price )
305
- }
306
-
307
- func (self * VMEnv ) Create (caller vm.ContractRef , data []byte , gas , price , value * big.Int ) ([]byte , common.Address , error ) {
308
- return core .Create (self , caller , data , gas , price , value )
309
- }
0 commit comments