aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/instructions.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2017-08-16 18:07:33 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-08-16 18:43:08 +0800
commit9bd6068fefe5687735bed342f3545f515fa717c8 (patch)
treed68767398eedd0a07c055fc8e880c4b4ab565a70 /core/vm/instructions.go
parent76069eef38082089d2eaf99661a80e1a953bf271 (diff)
downloaddexon-9bd6068fefe5687735bed342f3545f515fa717c8.tar
dexon-9bd6068fefe5687735bed342f3545f515fa717c8.tar.gz
dexon-9bd6068fefe5687735bed342f3545f515fa717c8.tar.bz2
dexon-9bd6068fefe5687735bed342f3545f515fa717c8.tar.lz
dexon-9bd6068fefe5687735bed342f3545f515fa717c8.tar.xz
dexon-9bd6068fefe5687735bed342f3545f515fa717c8.tar.zst
dexon-9bd6068fefe5687735bed342f3545f515fa717c8.zip
core/vm: implement RETURNDATA metropolis opcodes
Diffstat (limited to 'core/vm/instructions.go')
-rw-r--r--core/vm/instructions.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/vm/instructions.go b/core/vm/instructions.go
index aaa8d7945..0dd9af096 100644
--- a/core/vm/instructions.go
+++ b/core/vm/instructions.go
@@ -31,6 +31,7 @@ import (
var (
bigZero = new(big.Int)
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) {
@@ -360,6 +361,28 @@ func opCalldataCopy(pc *uint64, evm *EVM, contract *Contract, memory *Memory, st
return nil, nil
}
+func opReturnDataSize(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
+ stack.push(evm.interpreter.intPool.get().SetUint64(uint64(len(evm.interpreter.returnData))))
+ return nil, nil
+}
+
+func opReturnDataCopy(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
+ var (
+ mOff = stack.pop()
+ cOff = stack.pop()
+ l = stack.pop()
+ )
+ 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()])
+
+ return nil, nil
+}
+
func opExtCodeSize(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
a := stack.pop()