vm: catch stack underflow on Peek()

This commit is contained in:
Ethan Buchman 2015-08-08 22:20:19 -04:00
parent 4ee387d077
commit 807bd662b2
1 changed files with 4 additions and 0 deletions

View File

@ -104,6 +104,10 @@ func (st *Stack) Dup(n int) {
// Not an opcode, costs no gas.
func (st *Stack) Peek() Word256 {
if st.ptr == 0 {
st.setErr(ErrDataStackUnderflow)
return Zero256
}
return st.data[st.ptr-1]
}