mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-12 15:03:45 +00:00
core/vm: review changes (gas, comments)
* Changed the gas for RETURNDATASIZE * Added comments for read only check * Fixed opReturnDataCopy
This commit is contained in:
parent
4eae3cc25c
commit
43577cdf04
3 changed files with 14 additions and 5 deletions
|
|
@ -30,7 +30,8 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bigZero = new(big.Int)
|
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) {
|
func opAdd(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
||||||
|
|
@ -778,9 +779,14 @@ func opReturnDataCopy(pc *uint64, evm *EVM, contract *Contract, memory *Memory,
|
||||||
cOff = stack.pop()
|
cOff = stack.pop()
|
||||||
l = 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
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,10 @@ func (in *Interpreter) enforceRestrictions(op OpCode, operation operation, stack
|
||||||
if in.evm.chainRules.IsMetropolis {
|
if in.evm.chainRules.IsMetropolis {
|
||||||
if in.readonly {
|
if in.readonly {
|
||||||
// if the interpreter is operating in readonly mode, make sure no
|
// 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 ||
|
if operation.writes ||
|
||||||
((op == CALL || op == CALLCODE) && stack.Back(3).BitLen() > 0) {
|
((op == CALL || op == CALLCODE) && stack.Back(3).BitLen() > 0) {
|
||||||
return errWriteProtection
|
return errWriteProtection
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ func NewMetropolisInstructionSet() [256]operation {
|
||||||
}
|
}
|
||||||
instructionSet[RETURNDATASIZE] = operation{
|
instructionSet[RETURNDATASIZE] = operation{
|
||||||
execute: opReturnDataSize,
|
execute: opReturnDataSize,
|
||||||
gasCost: constGasFunc(0), // TODO
|
gasCost: constGasFunc(GasQuickStep),
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue