-
Notifications
You must be signed in to change notification settings - Fork 512
/
evm.go
63 lines (48 loc) · 1.3 KB
/
evm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package evm
import (
"errors"
"github.com/0xPolygon/polygon-edge/chain"
"github.com/0xPolygon/polygon-edge/state/runtime"
)
var _ runtime.Runtime = &EVM{}
// EVM is the ethereum virtual machine
type EVM struct {
}
// NewEVM creates a new EVM
func NewEVM() *EVM {
return &EVM{}
}
// CanRun implements the runtime interface
func (e *EVM) CanRun(*runtime.Contract, runtime.Host, *chain.ForksInTime) bool {
return true
}
// Name implements the runtime interface
func (e *EVM) Name() string {
return "evm"
}
// Run implements the runtime interface
func (e *EVM) Run(c *runtime.Contract, host runtime.Host, config *chain.ForksInTime) *runtime.ExecutionResult {
contract := acquireState()
contract.resetReturnData()
contract.msg = c
contract.code = c.Code
contract.evm = e
contract.gas = c.Gas
contract.host = host
contract.config = config
contract.bitmap.setCode(c.Code)
ret, err := contract.Run()
// We are probably doing this append magic to make sure that the slice doesn't have more capacity than it needs
var returnValue []byte
returnValue = append(returnValue[:0], ret...)
gasLeft := contract.gas
releaseState(contract)
if err != nil && !errors.Is(err, errRevert) {
gasLeft = 0
}
return &runtime.ExecutionResult{
ReturnValue: returnValue,
GasLeft: gasLeft,
Err: err,
}
}