Skip to content

Commit

Permalink
core/vm: review changes (gas, comments)
Browse files Browse the repository at this point in the history
* Changed the gas for RETURNDATASIZE
* Added comments for read only check
* Fixed opReturnDataCopy
  • Loading branch information
obscuren committed Jun 24, 2017
1 parent 4eae3cc commit 43577cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
12 changes: 9 additions & 3 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import (

var (
bigZero = new(big.Int)
errWriteProtection = errors.New("evm write protection")
errWriteProtection = errors.New("evm: write protection")
errReadOutOfBound = errors.New("evm: read out of bound")
)

func opAdd(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
Expand Down Expand Up @@ -778,9 +779,14 @@ func opReturnDataCopy(pc *uint64, evm *EVM, contract *Contract, memory *Memory,
cOff = stack.pop()
l = stack.pop()
)
memory.Set(mOff.Uint64(), l.Uint64(), getData(evm.interpreter.returnData, cOff, l))
defer evm.interpreter.intPool.put(mOff, cOff, l)

cEnd := new(big.Int).Add(cOff, l)
if cEnd.BitLen() > 64 || uint64(len(evm.interpreter.returnData)) < cEnd.Uint64() {
return nil, errReadOutOfBound
}
memory.Set(mOff.Uint64(), l.Uint64(), evm.interpreter.returnData[cOff.Uint64():cEnd.Uint64()])

evm.interpreter.intPool.put(mOff, cOff, l)
return nil, nil
}

Expand Down
5 changes: 4 additions & 1 deletion core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ func (in *Interpreter) enforceRestrictions(op OpCode, operation operation, stack
if in.evm.chainRules.IsMetropolis {
if in.readonly {
// if the interpreter is operating in readonly mode, make sure no
// state-modifying operation is performed.
// state-modifying operation is performed. The 4th stack item
// for a call operation is the value. Transfering value from one
// account to the others means the state is modified and should also
// return with an error.
if operation.writes ||
((op == CALL || op == CALLCODE) && stack.Back(3).BitLen() > 0) {
return errWriteProtection
Expand Down
2 changes: 1 addition & 1 deletion core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewMetropolisInstructionSet() [256]operation {
}
instructionSet[RETURNDATASIZE] = operation{
execute: opReturnDataSize,
gasCost: constGasFunc(0), // TODO
gasCost: constGasFunc(GasQuickStep),
validateStack: makeStackFunc(0, 1),
valid: true,
}
Expand Down

0 comments on commit 43577cd

Please sign in to comment.