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 29, 2021
1 parent 1b9c5e3 commit 46fbfd4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
9 changes: 9 additions & 0 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,10 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b
scope.Contract.Gas += returnGas

if suberr == ErrExecutionReverted {
interpreter.returnData = res // set REVERT data to return data buffer
return res, nil
}
interpreter.returnData = nil // clear dirty return data buffer
return nil, nil
}

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

if suberr == ErrExecutionReverted {
interpreter.returnData = res // set REVERT data to return data buffer
return res, nil
}
interpreter.returnData = nil // clear dirty return data buffer
return nil, nil
}

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

interpreter.returnData = ret
return ret, nil
}

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

interpreter.returnData = ret
return ret, nil
}

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

interpreter.returnData = ret
return ret, nil
}

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

interpreter.returnData = ret
return ret, nil
}

Expand All @@ -777,6 +785,7 @@ 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()))

interpreter.returnData = ret
return ret, ErrExecutionReverted
}

Expand Down
5 changes: 0 additions & 5 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
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
10 changes: 1 addition & 9 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ type operation struct {
// memorySize returns the memory size required for the operation
memorySize memorySizeFunc

writes bool // determines whether this a state modifying operation
returns bool // determines whether the operations sets the return data content
writes bool // determines whether this a state modifying operation
}

var (
Expand Down Expand Up @@ -125,7 +124,6 @@ func newConstantinopleInstructionSet() JumpTable {
maxStack: maxStack(4, 1),
memorySize: memoryCreate2,
writes: true,
returns: true,
}
return instructionSet
}
Expand All @@ -141,7 +139,6 @@ func newByzantiumInstructionSet() JumpTable {
minStack: minStack(6, 1),
maxStack: maxStack(6, 1),
memorySize: memoryStaticCall,
returns: true,
}
instructionSet[RETURNDATASIZE] = &operation{
execute: opReturnDataSize,
Expand All @@ -163,7 +160,6 @@ func newByzantiumInstructionSet() JumpTable {
minStack: minStack(2, 0),
maxStack: maxStack(2, 0),
memorySize: memoryRevert,
returns: true,
}
return instructionSet
}
Expand Down Expand Up @@ -200,7 +196,6 @@ func newHomesteadInstructionSet() JumpTable {
minStack: minStack(6, 1),
maxStack: maxStack(6, 1),
memorySize: memoryDelegateCall,
returns: true,
}
return instructionSet
}
Expand Down Expand Up @@ -986,7 +981,6 @@ func newFrontierInstructionSet() JumpTable {
maxStack: maxStack(3, 1),
memorySize: memoryCreate,
writes: true,
returns: true,
},
CALL: {
execute: opCall,
Expand All @@ -995,7 +989,6 @@ func newFrontierInstructionSet() JumpTable {
minStack: minStack(7, 1),
maxStack: maxStack(7, 1),
memorySize: memoryCall,
returns: true,
},
CALLCODE: {
execute: opCallCode,
Expand All @@ -1004,7 +997,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 46fbfd4

Please sign in to comment.