Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm: move interpreter.readOnly check and remove operation.writes field #2033

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions blockchain/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,9 @@ func opGas(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte
}

func opCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
if interpreter.readOnly {
return nil, ErrWriteProtection
}
var (
value = scope.Stack.pop()
offset, size = scope.Stack.pop(), scope.Stack.pop()
Expand Down Expand Up @@ -624,6 +627,9 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b
}

func opCreate2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
if interpreter.readOnly {
return nil, ErrWriteProtection
}
var (
endowment = scope.Stack.pop()
offset, size = scope.Stack.pop(), scope.Stack.pop()
Expand Down
11 changes: 0 additions & 11 deletions blockchain/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,6 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte) (ret []byte, err
} else if sLen > operation.maxStack {
return nil, fmt.Errorf("stack limit reached %d (%d)", sLen, operation.maxStack)
}
// If the operation is valid, enforce and write restrictions
if in.readOnly {
// If the interpreter is operating in readonly mode, make sure no
// state-modifying operation is performed. The 3rd stack item
// for a call operation is the value. Transferring value from one
// account to the others means the state is modified and should also
// return with an error.
if operation.writes || (op == CALL && stack.Back(2).Sign() != 0) {
return nil, ErrWriteProtection
}
}

// Static portion of gas
cost = operation.constantGas // For tracing
Expand Down
11 changes: 0 additions & 11 deletions blockchain/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ type operation struct {
// computationCost represents approximated execution time of an operation.
// This value will be used to limit the execution time of a transaction on EVM.
computationCost uint64

writes bool // determines whether this a state modifying operation
}

var (
Expand Down Expand Up @@ -149,7 +147,6 @@ func newConstantinopleInstructionSet() JumpTable {
minStack: minStack(4, 1),
maxStack: maxStack(4, 1),
memorySize: memoryCreate2,
writes: true,
computationCost: params.Create2ComputationCost,
}
return instructionSet
Expand Down Expand Up @@ -571,7 +568,6 @@ func newFrontierInstructionSet() JumpTable {
dynamicGas: gasSStore,
minStack: minStack(2, 0),
maxStack: maxStack(2, 0),
writes: true,
computationCost: params.SstoreComputationCost,
},
JUMP: {
Expand Down Expand Up @@ -1070,7 +1066,6 @@ func newFrontierInstructionSet() JumpTable {
minStack: minStack(2, 0),
maxStack: maxStack(2, 0),
memorySize: memoryLog,
writes: true,
computationCost: params.Log0ComputationCost,
},
LOG1: {
Expand All @@ -1079,7 +1074,6 @@ func newFrontierInstructionSet() JumpTable {
minStack: minStack(3, 0),
maxStack: maxStack(3, 0),
memorySize: memoryLog,
writes: true,
computationCost: params.Log1ComputationCost,
},
LOG2: {
Expand All @@ -1088,7 +1082,6 @@ func newFrontierInstructionSet() JumpTable {
minStack: minStack(4, 0),
maxStack: maxStack(4, 0),
memorySize: memoryLog,
writes: true,
computationCost: params.Log2ComputationCost,
},
LOG3: {
Expand All @@ -1097,7 +1090,6 @@ func newFrontierInstructionSet() JumpTable {
minStack: minStack(5, 0),
maxStack: maxStack(5, 0),
memorySize: memoryLog,
writes: true,
computationCost: params.Log3ComputationCost,
},
LOG4: {
Expand All @@ -1106,7 +1098,6 @@ func newFrontierInstructionSet() JumpTable {
minStack: minStack(6, 0),
maxStack: maxStack(6, 0),
memorySize: memoryLog,
writes: true,
computationCost: params.Log4ComputationCost,
},
CREATE: {
Expand All @@ -1116,7 +1107,6 @@ func newFrontierInstructionSet() JumpTable {
minStack: minStack(3, 1),
maxStack: maxStack(3, 1),
memorySize: memoryCreate,
writes: true,
computationCost: params.CreateComputationCost,
},
CALL: {
Expand Down Expand Up @@ -1150,7 +1140,6 @@ func newFrontierInstructionSet() JumpTable {
dynamicGas: gasSelfdestruct,
minStack: minStack(1, 0),
maxStack: maxStack(1, 0),
writes: true,
computationCost: params.SelfDestructComputationCost,
},
}
Expand Down
2 changes: 2 additions & 0 deletions blockchain/vm/logger_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (l *JSONLogger) CaptureStart(env *EVM, from common.Address, to common.Addre
}

// CaptureState outputs state information on the logger.
// TODO: Add rData (return data) later
func (l *JSONLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, scope *ScopeContext, depth int, err error) {
memory := scope.Memory
stack := scope.Stack
Expand Down Expand Up @@ -74,6 +75,7 @@ func (l *JSONLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint

// CaptureFault outputs state information on the logger.
func (l *JSONLogger) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, scope *ScopeContext, depth int, err error) {
l.CaptureState(env, pc, op, gas, cost, scope, depth, err)
}

// CaptureEnd is triggered at end of execution.
Expand Down