From 8f94997472d04843b6fd1aec9602d6d29b469612 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Fri, 26 Jun 2015 01:50:31 +0000 Subject: [PATCH] label/remove panics in vm --- vm/native.go | 2 ++ vm/stack.go | 1 + vm/vm.go | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/vm/native.go b/vm/native.go index 8aff146d9..fef0a7718 100644 --- a/vm/native.go +++ b/vm/native.go @@ -52,6 +52,7 @@ func sha256Func(input []byte, gas *uint64) (output []byte, err error) { } // Hash hasher := sha256.New() + // CONTRACT: this does not err _, err = hasher.Write(input) if err != nil { panic(err) @@ -69,6 +70,7 @@ func ripemd160Func(input []byte, gas *uint64) (output []byte, err error) { } // Hash hasher := ripemd160.New() + // CONTRACT: this does not err _, err = hasher.Write(input) if err != nil { panic(err) diff --git a/vm/stack.go b/vm/stack.go index 500ff4d15..f0d88d2a1 100644 --- a/vm/stack.go +++ b/vm/stack.go @@ -47,6 +47,7 @@ func (st *Stack) Push(d Word256) { st.ptr++ } +// currently only called after Sha3 func (st *Stack) PushBytes(bz []byte) { if len(bz) != 32 { panic("Invalid bytes size: expected 32") diff --git a/vm/vm.go b/vm/vm.go index 6a814655b..caffed1ef 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -100,6 +100,7 @@ func (vm *VM) Call(caller, callee *Account, code, input []byte, value uint64, ga *exception = err.Error() err := transfer(callee, caller, value) if err != nil { + // data has been corrupted in ram panic("Could not return value to caller") } } @@ -784,7 +785,7 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value uint64, ga default: dbg.Printf("(pc) %-3v Invalid opcode %X\n", pc, op) - panic(fmt.Errorf("Invalid opcode %X", op)) + return nil, fmt.Errorf("Invalid opcode %X", op) } pc++