mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
core/vm: add push* functions
This commit is contained in:
parent
cf2eb01815
commit
f237940141
2 changed files with 29 additions and 13 deletions
|
|
@ -231,7 +231,7 @@ func opSAR(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte
|
|||
}
|
||||
|
||||
func opKeccak256(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
offset, size := scope.Stack.pop(), scope.Stack.peek()
|
||||
offset, size := scope.Stack.pop(), scope.Stack.pop()
|
||||
data := scope.Memory.GetPtr(offset.Uint64(), size.Uint64())
|
||||
|
||||
if interpreter.hasher == nil {
|
||||
|
|
@ -246,29 +246,29 @@ func opKeccak256(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) (
|
|||
if evm.Config.EnablePreimageRecording {
|
||||
evm.StateDB.AddPreimage(interpreter.hasherBuf, data)
|
||||
}
|
||||
size.SetBytes(interpreter.hasherBuf[:])
|
||||
scope.Stack.pushBytes(interpreter.hasherBuf[:])
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func opAddress(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
scope.Stack.push(new(uint256.Int).SetBytes(scope.Contract.Address().Bytes()))
|
||||
scope.Stack.pushBytes(scope.Contract.Address().Bytes())
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func opBalance(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
slot := scope.Stack.peek()
|
||||
slot := scope.Stack.pop()
|
||||
address := common.Address(slot.Bytes20())
|
||||
slot.Set(interpreter.evm.StateDB.GetBalance(address))
|
||||
scope.Stack.push(interpreter.evm.StateDB.GetBalance(address))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func opOrigin(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
scope.Stack.push(new(uint256.Int).SetBytes(interpreter.evm.Origin.Bytes()))
|
||||
scope.Stack.pushBytes(interpreter.evm.Origin.Bytes())
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func opCaller(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
scope.Stack.push(new(uint256.Int).SetBytes(scope.Contract.Caller().Bytes()))
|
||||
scope.Stack.pushBytes(scope.Contract.Caller().Bytes())
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
@ -289,7 +289,7 @@ func opCallDataLoad(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
|
|||
}
|
||||
|
||||
func opCallDataSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
scope.Stack.push(new(uint256.Int).SetUint64(uint64(len(scope.Contract.Input))))
|
||||
scope.Stack.pushU64(uint64(len(scope.Contract.Input)))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
@ -312,7 +312,7 @@ func opCallDataCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
|
|||
}
|
||||
|
||||
func opReturnDataSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
scope.Stack.push(new(uint256.Int).SetUint64(uint64(len(interpreter.returnData))))
|
||||
scope.Stack.pushU64(uint64(len(interpreter.returnData)))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
@ -339,13 +339,13 @@ func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeConte
|
|||
}
|
||||
|
||||
func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
slot := scope.Stack.peek()
|
||||
slot.SetUint64(uint64(interpreter.evm.StateDB.GetCodeSize(slot.Bytes20())))
|
||||
slot := scope.Stack.pop()
|
||||
scope.Stack.pushU64(uint64(interpreter.evm.StateDB.GetCodeSize(slot.Bytes20())))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func opCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
scope.Stack.push(new(uint256.Int).SetUint64(uint64(len(scope.Contract.Code))))
|
||||
scope.Stack.pushU64(uint64(len(scope.Contract.Code)))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,11 +56,27 @@ func (st *Stack) push(d *uint256.Int) {
|
|||
if st.size == len(st.data) {
|
||||
st.data = append(st.data, *d)
|
||||
} else {
|
||||
st.data[st.size] = *d
|
||||
st.data[st.size].Set(d)
|
||||
}
|
||||
st.size++
|
||||
}
|
||||
|
||||
func (st *Stack) pushBytes(d []byte) {
|
||||
if st.size == len(st.data) {
|
||||
st.data = append(st.data, uint256.Int{})
|
||||
}
|
||||
st.data[st.size].SetBytes(d)
|
||||
st.size++
|
||||
}
|
||||
|
||||
func (st *Stack) pushU64(d uint64) {
|
||||
if st.size == len(st.data) {
|
||||
st.data = append(st.data, uint256.Int{})
|
||||
}
|
||||
st.data[st.size].SetUint64(d)
|
||||
st.size++
|
||||
}
|
||||
|
||||
func (st *Stack) pop() (ret uint256.Int) {
|
||||
ret = st.data[st.size-1]
|
||||
st.size--
|
||||
|
|
|
|||
Loading…
Reference in a new issue