aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/interpreter.go
diff options
context:
space:
mode:
authorPaweł Bylica <chfast@gmail.com>2018-09-08 00:13:25 +0800
committerGuillaume Ballet <gballet@gmail.com>2018-09-08 00:13:25 +0800
commitae992a5d73311742389fce3f855575be98fc6972 (patch)
tree3ec8d1c90aea8f5b90e8866ac67052cb83f0ad1b /core/vm/interpreter.go
parent8b9b149d5412dd3c775caf4fc3df39ebad90184f (diff)
downloaddexon-ae992a5d73311742389fce3f855575be98fc6972.tar
dexon-ae992a5d73311742389fce3f855575be98fc6972.tar.gz
dexon-ae992a5d73311742389fce3f855575be98fc6972.tar.bz2
dexon-ae992a5d73311742389fce3f855575be98fc6972.tar.lz
dexon-ae992a5d73311742389fce3f855575be98fc6972.tar.xz
dexon-ae992a5d73311742389fce3f855575be98fc6972.tar.zst
dexon-ae992a5d73311742389fce3f855575be98fc6972.zip
core/vm: Hide read only flag from Interpreter interface (#17461)
Makes Interface interface a bit more stateless and abstract. Obviously this change is dictated by EVMC design. The EVMC tries to keep the responsibility for EVM features totally inside the VMs, if feasible. This makes VM "stateless" because VM does not need to pass any information between executions, all information is included in parameters of the execute function.
Diffstat (limited to 'core/vm/interpreter.go')
-rw-r--r--core/vm/interpreter.go25
1 files changed, 9 insertions, 16 deletions
diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go
index 1e9202424..0f1b07342 100644
--- a/core/vm/interpreter.go
+++ b/core/vm/interpreter.go
@@ -48,7 +48,7 @@ type Config struct {
type Interpreter interface {
// Run loops and evaluates the contract's code with the given input data and returns
// the return byte-slice and an error if one occurred.
- Run(contract *Contract, input []byte) ([]byte, error)
+ Run(contract *Contract, input []byte, static bool) ([]byte, error)
// CanRun tells if the contract, passed as an argument, can be
// run by the current interpreter. This is meant so that the
// caller can do something like:
@@ -61,10 +61,6 @@ type Interpreter interface {
// }
// ```
CanRun([]byte) bool
- // IsReadOnly reports if the interpreter is in read only mode.
- IsReadOnly() bool
- // SetReadOnly sets (or unsets) read only mode in the interpreter.
- SetReadOnly(bool)
}
// EVMInterpreter represents an EVM interpreter
@@ -125,7 +121,7 @@ func (in *EVMInterpreter) enforceRestrictions(op OpCode, operation operation, st
// It's important to note that any errors returned by the interpreter should be
// considered a revert-and-consume-all-gas operation except for
// errExecutionReverted which means revert-and-keep-gas-left.
-func (in *EVMInterpreter) Run(contract *Contract, input []byte) (ret []byte, err error) {
+func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (ret []byte, err error) {
if in.intPool == nil {
in.intPool = poolOfIntPools.get()
defer func() {
@@ -138,6 +134,13 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte) (ret []byte, err
in.evm.depth++
defer func() { in.evm.depth-- }()
+ // Make sure the readOnly is only set if we aren't in readOnly yet.
+ // This makes also sure that the readOnly flag isn't removed for child calls.
+ if readOnly && !in.readOnly {
+ in.readOnly = true
+ defer func() { in.readOnly = false }()
+ }
+
// Reset the previous call's return data. It's unimportant to preserve the old buffer
// as every returning call will return new data anyway.
in.returnData = nil
@@ -263,13 +266,3 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte) (ret []byte, err
func (in *EVMInterpreter) CanRun(code []byte) bool {
return true
}
-
-// IsReadOnly reports if the interpreter is in read only mode.
-func (in *EVMInterpreter) IsReadOnly() bool {
- return in.readOnly
-}
-
-// SetReadOnly sets (or unsets) read only mode in the interpreter.
-func (in *EVMInterpreter) SetReadOnly(ro bool) {
- in.readOnly = ro
-}