浏览代码

Make an attempt to pay for the gas prior to expanding the mem.

obscuren 11 年之前
父节点
当前提交
a22056db59
共有 3 个文件被更改,包括 7 次插入3 次删除
  1. 4 1
      tests/vm/gh_test.go
  2. 1 1
      vm/closure.go
  3. 2 1
      vm/vm_debug.go

+ 4 - 1
tests/vm/gh_test.go

@@ -2,6 +2,7 @@ package vm
 
 import (
 	"bytes"
+	"fmt"
 	"testing"
 
 	"github.com/ethereum/go-ethereum/ethutil"
@@ -44,6 +45,7 @@ func RunVmTest(p string, t *testing.T) {
 	helper.CreateFileTests(t, p, &tests)
 
 	for name, test := range tests {
+		fmt.Println(name)
 		state := state.New(helper.NewTrie())
 		for addr, account := range test.Pre {
 			obj := StateObjectFromAccount(addr, account)
@@ -113,7 +115,7 @@ func TestEnvironmentalInfo(t *testing.T) {
 }
 
 func TestFlowOperation(t *testing.T) {
-	helper.Logger.SetLogLevel(5)
+	//helper.Logger.SetLogLevel(5)
 	const fn = "../files/vmtests/vmIOandFlowOperationsTest.json"
 	RunVmTest(fn, t)
 }
@@ -124,6 +126,7 @@ func TestPushDupSwap(t *testing.T) {
 }
 
 func TestVMSha3(t *testing.T) {
+	helper.Logger.SetLogLevel(5)
 	const fn = "../files/vmtests/vmSha3Test.json"
 	RunVmTest(fn, t)
 }

+ 1 - 1
vm/closure.go

@@ -64,7 +64,7 @@ func (c *Closure) GetOp(x int) OpCode {
 }
 
 func (c *Closure) GetByte(x int) byte {
-	if x < len(c.Code) {
+	if x > -1 && x < len(c.Code) {
 		return c.Code[x]
 	}
 

+ 2 - 1
vm/vm_debug.go

@@ -277,7 +277,6 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
 
 				addStepGasUsage(memGasUsage)
 
-				mem.Resize(newMemSize.Uint64())
 			}
 
 		}
@@ -295,6 +294,8 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
 			return closure.Return(nil), OOG(gas, tmp)
 		}
 
+		mem.Resize(newMemSize.Uint64())
+
 		switch op {
 		// 0x20 range
 		case ADD: