Skip to content

Commit

Permalink
core/vm: set return data in instruction impls
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Nov 22, 2021
1 parent 122fb71 commit 1719289
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
16 changes: 16 additions & 0 deletions core/vm/instructions.go
Expand Up @@ -596,8 +596,11 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b
scope.Contract.Gas += returnGas

if suberr == ErrExecutionReverted {
// set the return data
interpreter.returnData = res
return res, nil
}
interpreter.returnData = nil
return nil, nil
}

Expand Down Expand Up @@ -632,8 +635,11 @@ func opCreate2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]
scope.Contract.Gas += returnGas

if suberr == ErrExecutionReverted {
// set the return data
interpreter.returnData = res
return res, nil
}
interpreter.returnData = nil
return nil, nil
}

Expand Down Expand Up @@ -672,6 +678,8 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byt
}
scope.Contract.Gas += returnGas

// set the return data
interpreter.returnData = ret
return ret, nil
}

Expand Down Expand Up @@ -707,6 +715,8 @@ func opCallCode(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
}
scope.Contract.Gas += returnGas

// set the return data
interpreter.returnData = ret
return ret, nil
}

Expand Down Expand Up @@ -735,6 +745,8 @@ func opDelegateCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
}
scope.Contract.Gas += returnGas

// set the return data
interpreter.returnData = ret
return ret, nil
}

Expand Down Expand Up @@ -763,6 +775,8 @@ func opStaticCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
}
scope.Contract.Gas += returnGas

// set the return data
interpreter.returnData = ret
return ret, nil
}

Expand All @@ -777,6 +791,8 @@ func opRevert(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b
offset, size := scope.Stack.pop(), scope.Stack.pop()
ret := scope.Memory.GetPtr(int64(offset.Uint64()), int64(size.Uint64()))

// set the return data
interpreter.returnData = ret
return ret, ErrExecutionReverted
}

Expand Down
5 changes: 0 additions & 5 deletions core/vm/interpreter.go
Expand Up @@ -259,11 +259,6 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (

// execute the operation
res, err = operation.execute(&pc, in, callContext)
// if the operation clears the return data (e.g. it has returning data)
// set the last return to the result of the operation.
if operation.returns {
in.returnData = res
}

if err != nil {
break
Expand Down
7 changes: 0 additions & 7 deletions core/vm/jump_table.go
Expand Up @@ -128,7 +128,6 @@ func newConstantinopleInstructionSet() JumpTable {
maxStack: maxStack(4, 1),
memorySize: memoryCreate2,
writes: true,
returns: true,
}
return instructionSet
}
Expand All @@ -144,7 +143,6 @@ func newByzantiumInstructionSet() JumpTable {
minStack: minStack(6, 1),
maxStack: maxStack(6, 1),
memorySize: memoryStaticCall,
returns: true,
}
instructionSet[RETURNDATASIZE] = &operation{
execute: opReturnDataSize,
Expand All @@ -166,7 +164,6 @@ func newByzantiumInstructionSet() JumpTable {
minStack: minStack(2, 0),
maxStack: maxStack(2, 0),
memorySize: memoryRevert,
returns: true,
}
return instructionSet
}
Expand Down Expand Up @@ -203,7 +200,6 @@ func newHomesteadInstructionSet() JumpTable {
minStack: minStack(6, 1),
maxStack: maxStack(6, 1),
memorySize: memoryDelegateCall,
returns: true,
}
return instructionSet
}
Expand Down Expand Up @@ -989,7 +985,6 @@ func newFrontierInstructionSet() JumpTable {
maxStack: maxStack(3, 1),
memorySize: memoryCreate,
writes: true,
returns: true,
},
CALL: {
execute: opCall,
Expand All @@ -998,7 +993,6 @@ func newFrontierInstructionSet() JumpTable {
minStack: minStack(7, 1),
maxStack: maxStack(7, 1),
memorySize: memoryCall,
returns: true,
},
CALLCODE: {
execute: opCallCode,
Expand All @@ -1007,7 +1001,6 @@ func newFrontierInstructionSet() JumpTable {
minStack: minStack(7, 1),
maxStack: maxStack(7, 1),
memorySize: memoryCall,
returns: true,
},
RETURN: {
execute: opReturn,
Expand Down

0 comments on commit 1719289

Please sign in to comment.