core/vm: fixed clearing issue on return data

This commit is contained in:
Jeffrey Wilcke 2017-06-15 14:14:14 +02:00
parent edf95ec610
commit 797172bfe8
2 changed files with 26 additions and 21 deletions

View file

@ -231,9 +231,9 @@ func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret
case !operation.jumps: case !operation.jumps:
pc++ pc++
} }
// if the operation returned a value make sure that is also set // if the operation clears the return data (e.g. it has returning data)
// the last return data. // set the last return to the result of the operation.
if res != nil { if operation.clearsReturndata {
in.returnData = res in.returnData = res
} }
} }

View file

@ -53,11 +53,13 @@ type operation struct {
valid bool valid bool
// reverts determined whether the operation reverts state // reverts determined whether the operation reverts state
reverts bool reverts bool
// clearsReturndata determines whether the opertions clears the return data
clearsReturndata bool
} }
var ( var (
frontierInstructionSet = NewFrontierInstructionSet() frontierInstructionSet = NewFrontierInstructionSet()
homesteadInstructionSet = NewHomesteadInstructionSet() homesteadInstructionSet = NewHomesteadInstructionSet()
metropolisInstructionSet = NewMetropolisInstructionSet() metropolisInstructionSet = NewMetropolisInstructionSet()
) )
@ -881,26 +883,29 @@ func NewFrontierInstructionSet() [256]operation {
writes: true, writes: true,
}, },
CREATE: { CREATE: {
execute: opCreate, execute: opCreate,
gasCost: gasCreate, gasCost: gasCreate,
validateStack: makeStackFunc(3, 1), validateStack: makeStackFunc(3, 1),
memorySize: memoryCreate, memorySize: memoryCreate,
valid: true, valid: true,
writes: true, writes: true,
clearsReturndata: true,
}, },
CALL: { CALL: {
execute: opCall, execute: opCall,
gasCost: gasCall, gasCost: gasCall,
validateStack: makeStackFunc(7, 1), validateStack: makeStackFunc(7, 1),
memorySize: memoryCall, memorySize: memoryCall,
valid: true, valid: true,
clearsReturndata: true,
}, },
CALLCODE: { CALLCODE: {
execute: opCallCode, execute: opCallCode,
gasCost: gasCallCode, gasCost: gasCallCode,
validateStack: makeStackFunc(7, 1), validateStack: makeStackFunc(7, 1),
memorySize: memoryCall, memorySize: memoryCall,
valid: true, valid: true,
clearsReturndata: true,
}, },
RETURN: { RETURN: {
execute: opReturn, execute: opReturn,