Redone rlp

This commit is contained in:
obscuren 2015-03-03 11:18:50 +01:00
parent 2f647c443a
commit fa910966ed
2 changed files with 5 additions and 8 deletions

View File

@ -80,7 +80,7 @@ func RunVmTest(p string, t *testing.T) {
for name, test := range tests { for name, test := range tests {
helper.Logger.SetLogLevel(4) helper.Logger.SetLogLevel(4)
if name != "env1" { if name != "mul7" {
continue continue
} }
db, _ := ethdb.NewMemDatabase() db, _ := ethdb.NewMemDatabase()

View File

@ -844,7 +844,7 @@ func baseCheck(op OpCode, stack *Stack, gas *big.Int) {
func toWordSize(size *big.Int) *big.Int { func toWordSize(size *big.Int) *big.Int {
tmp := new(big.Int) tmp := new(big.Int)
tmp.Add(tmp, u256(31)) tmp.Add(size, u256(31))
tmp.Div(tmp, u256(32)) tmp.Div(tmp, u256(32))
return tmp return tmp
} }
@ -951,9 +951,7 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo
} }
if newMemSize.Cmp(ethutil.Big0) > 0 { if newMemSize.Cmp(ethutil.Big0) > 0 {
newMemSize.Add(newMemSize, u256(31)) newMemSize = toWordSize(newMemSize)
newMemSize.Div(newMemSize, u256(32))
newMemSize.Mul(newMemSize, u256(32))
if newMemSize.Cmp(u256(int64(mem.Len()))) > 0 { if newMemSize.Cmp(u256(int64(mem.Len()))) > 0 {
//memGasUsage := new(big.Int).Sub(newMemSize, u256(int64(mem.Len()))) //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)) //memGasUsage.Div(memGasUsage, u256(32))
//Old: full_memory_gas_cost = W + floor(W*W / 1024), W = words in memory //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()))) oldSize := toWordSize(big.NewInt(int64(mem.Len())))
linCoef := new(big.Int).Mul(oldSize, GasMemWord) linCoef := new(big.Int).Mul(oldSize, GasMemWord)
pow := new(big.Int)
pow.Exp(oldSize, ethutil.Big2, Zero)
quadCoef := new(big.Int).Div(pow, GasQuadCoeffDenom) quadCoef := new(big.Int).Div(pow, GasQuadCoeffDenom)
oldTotalFee := new(big.Int).Add(linCoef, quadCoef) oldTotalFee := new(big.Int).Add(linCoef, quadCoef)
linCoef = new(big.Int).Mul(newMemSize, GasMemWord)
pow.Exp(newMemSize, ethutil.Big2, Zero) pow.Exp(newMemSize, ethutil.Big2, Zero)
linCoef = new(big.Int).Mul(newMemSize, GasMemWord)
quadCoef = new(big.Int).Div(pow, GasQuadCoeffDenom) quadCoef = new(big.Int).Div(pow, GasQuadCoeffDenom)
newTotalFee := new(big.Int).Add(linCoef, quadCoef) newTotalFee := new(big.Int).Add(linCoef, quadCoef)