aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-03 18:18:50 +0800
committerobscuren <geffobscura@gmail.com>2015-03-03 18:18:50 +0800
commitfa910966ede699f90b2760d7a11ac0ef5dbda029 (patch)
tree0e75b1ad8ee2c6431d05335c72fc061bbe505727
parent2f647c443a6faf3a0639f9e54fdd262fe917b49b (diff)
downloaddexon-fa910966ede699f90b2760d7a11ac0ef5dbda029.tar
dexon-fa910966ede699f90b2760d7a11ac0ef5dbda029.tar.gz
dexon-fa910966ede699f90b2760d7a11ac0ef5dbda029.tar.bz2
dexon-fa910966ede699f90b2760d7a11ac0ef5dbda029.tar.lz
dexon-fa910966ede699f90b2760d7a11ac0ef5dbda029.tar.xz
dexon-fa910966ede699f90b2760d7a11ac0ef5dbda029.tar.zst
dexon-fa910966ede699f90b2760d7a11ac0ef5dbda029.zip
Redone rlp
-rw-r--r--tests/vm/gh_test.go2
-rw-r--r--vm/vm.go11
2 files changed, 5 insertions, 8 deletions
diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go
index f8c42f09c..f2e3685a0 100644
--- a/tests/vm/gh_test.go
+++ b/tests/vm/gh_test.go
@@ -80,7 +80,7 @@ func RunVmTest(p string, t *testing.T) {
for name, test := range tests {
helper.Logger.SetLogLevel(4)
- if name != "env1" {
+ if name != "mul7" {
continue
}
db, _ := ethdb.NewMemDatabase()
diff --git a/vm/vm.go b/vm/vm.go
index 9f8d5e8df..b9c7f73a8 100644
--- a/vm/vm.go
+++ b/vm/vm.go
@@ -844,7 +844,7 @@ func baseCheck(op OpCode, stack *Stack, gas *big.Int) {
func toWordSize(size *big.Int) *big.Int {
tmp := new(big.Int)
- tmp.Add(tmp, u256(31))
+ tmp.Add(size, u256(31))
tmp.Div(tmp, u256(32))
return tmp
}
@@ -951,9 +951,7 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo
}
if newMemSize.Cmp(ethutil.Big0) > 0 {
- newMemSize.Add(newMemSize, u256(31))
- newMemSize.Div(newMemSize, u256(32))
- newMemSize.Mul(newMemSize, u256(32))
+ newMemSize = toWordSize(newMemSize)
if newMemSize.Cmp(u256(int64(mem.Len()))) > 0 {
//memGasUsage := new(big.Int).Sub(newMemSize, u256(int64(mem.Len())))
@@ -961,15 +959,14 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo
//memGasUsage.Div(memGasUsage, u256(32))
//Old: full_memory_gas_cost = W + floor(W*W / 1024), W = words in memory
+ pow := new(big.Int).Exp(oldSize, ethutil.Big2, Zero)
oldSize := toWordSize(big.NewInt(int64(mem.Len())))
linCoef := new(big.Int).Mul(oldSize, GasMemWord)
- pow := new(big.Int)
- pow.Exp(oldSize, ethutil.Big2, Zero)
quadCoef := new(big.Int).Div(pow, GasQuadCoeffDenom)
oldTotalFee := new(big.Int).Add(linCoef, quadCoef)
- linCoef = new(big.Int).Mul(newMemSize, GasMemWord)
pow.Exp(newMemSize, ethutil.Big2, Zero)
+ linCoef = new(big.Int).Mul(newMemSize, GasMemWord)
quadCoef = new(big.Int).Div(pow, GasQuadCoeffDenom)
newTotalFee := new(big.Int).Add(linCoef, quadCoef)