Fixed EXP gas
This commit is contained in:
parent
a22056db59
commit
a052357872
@ -62,14 +62,14 @@ func S256(x *big.Int) *big.Int {
|
||||
}
|
||||
}
|
||||
|
||||
func FirstBitSet(v *big.Int) *big.Int {
|
||||
func FirstBitSet(v *big.Int) int {
|
||||
for i := 0; i < v.BitLen(); i++ {
|
||||
if v.Bit(i) > 0 {
|
||||
return big.NewInt(int64(i))
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
return big.NewInt(int64(v.BitLen()))
|
||||
return v.BitLen()
|
||||
}
|
||||
|
||||
// Big to bytes
|
||||
|
@ -2,7 +2,6 @@ package vm
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
@ -45,7 +44,6 @@ 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)
|
||||
@ -85,20 +83,10 @@ func RunVmTest(p string, t *testing.T) {
|
||||
|
||||
// I've created a new function for each tests so it's easier to identify where the problem lies if any of them fail.
|
||||
func TestVMArithmetic(t *testing.T) {
|
||||
//helper.Logger.SetLogLevel(5)
|
||||
const fn = "../files/vmtests/vmArithmeticTest.json"
|
||||
RunVmTest(fn, t)
|
||||
}
|
||||
|
||||
/*
|
||||
deleted?
|
||||
func TestVMSystemOperation(t *testing.T) {
|
||||
helper.Logger.SetLogLevel(5)
|
||||
const fn = "../files/vmtests/vmSystemOperationsTest.json"
|
||||
RunVmTest(fn, t)
|
||||
}
|
||||
*/
|
||||
|
||||
func TestBitwiseLogicOperation(t *testing.T) {
|
||||
const fn = "../files/vmtests/vmBitwiseLogicOperationTest.json"
|
||||
RunVmTest(fn, t)
|
||||
@ -126,7 +114,7 @@ func TestPushDupSwap(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVMSha3(t *testing.T) {
|
||||
helper.Logger.SetLogLevel(5)
|
||||
//helper.Logger.SetLogLevel(5)
|
||||
const fn = "../files/vmtests/vmSha3Test.json"
|
||||
RunVmTest(fn, t)
|
||||
}
|
||||
|
@ -172,12 +172,13 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
|
||||
case EXP:
|
||||
require(2)
|
||||
|
||||
expGas := ethutil.FirstBitSet(stack.data[stack.Len()-2])
|
||||
expGas.Div(expGas, u256(8))
|
||||
expGas.Sub(u256(32), expGas)
|
||||
expGas.Add(expGas, u256(1))
|
||||
|
||||
gas.Set(expGas)
|
||||
exp := new(big.Int).Set(stack.data[stack.Len()-2])
|
||||
nbytes := 0
|
||||
for exp.Cmp(ethutil.Big0) > 0 {
|
||||
nbytes += 1
|
||||
exp.Rsh(exp, 8)
|
||||
}
|
||||
gas.Set(big.NewInt(int64(nbytes + 1)))
|
||||
// Gas only
|
||||
case STOP:
|
||||
gas.Set(ethutil.Big0)
|
||||
|
Loading…
Reference in New Issue
Block a user