From 6dc46d3341dc5fa25bd005f9606de258874139be Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 1 Dec 2014 20:18:09 +0100 Subject: Changed the way transactions are being added to the transaction pool --- vm/vm_debug.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'vm') diff --git a/vm/vm_debug.go b/vm/vm_debug.go index ae5a20175..18d3018a0 100644 --- a/vm/vm_debug.go +++ b/vm/vm_debug.go @@ -151,7 +151,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) { // Stack checks only case ISZERO, CALLDATALOAD, POP, JUMP, NOT: // 1 require(1) - case ADD, SUB, DIV, SDIV, MOD, SMOD, EXP, LT, GT, SLT, SGT, EQ, AND, OR, XOR, BYTE: // 2 + case ADD, SUB, DIV, SDIV, MOD, SMOD, LT, GT, SLT, SGT, EQ, AND, OR, XOR, BYTE: // 2 require(2) case ADDMOD, MULMOD: // 3 require(3) @@ -169,6 +169,15 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) { gas.Set(GasLog) addStepGasUsage(new(big.Int).Mul(big.NewInt(int64(n)), GasLog)) addStepGasUsage(new(big.Int).Add(mSize, mStart)) + 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) // Gas only case STOP: gas.Set(ethutil.Big0) -- cgit From d33987cb44529db4f3e117d4b242b1796d41520d Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 1 Dec 2014 20:20:55 +0100 Subject: Additional fees for *COPY --- vm/vm_debug.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'vm') diff --git a/vm/vm_debug.go b/vm/vm_debug.go index 18d3018a0..b9c1d4bc6 100644 --- a/vm/vm_debug.go +++ b/vm/vm_debug.go @@ -264,6 +264,12 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) { newMemSize.Div(newMemSize, u256(32)) newMemSize.Mul(newMemSize, u256(32)) + switch op { + // Additional gas usage on *CODPY + case CALLDATACOPY, CODECOPY, EXTCODECOPY: + addStepGasUsage(new(big.Int).Div(newMemSize, u256(32))) + } + if newMemSize.Cmp(u256(int64(mem.Len()))) > 0 { memGasUsage := new(big.Int).Sub(newMemSize, u256(int64(mem.Len()))) memGasUsage.Mul(GasMemory, memGasUsage) -- cgit From a22056db5988bfa2b1354e0092eabb734c30701c Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 1 Dec 2014 20:49:56 +0100 Subject: Make an attempt to pay for the gas prior to expanding the mem. --- vm/closure.go | 2 +- vm/vm_debug.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'vm') diff --git a/vm/closure.go b/vm/closure.go index ef9bbca93..5bd8c1bb8 100644 --- a/vm/closure.go +++ b/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] } diff --git a/vm/vm_debug.go b/vm/vm_debug.go index b9c1d4bc6..4daa3ab5b 100644 --- a/vm/vm_debug.go +++ b/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: -- cgit From a052357872217d5e99e7ee1a7a4b524b53addcdd Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 1 Dec 2014 22:05:38 +0100 Subject: Fixed EXP gas --- vm/vm_debug.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'vm') diff --git a/vm/vm_debug.go b/vm/vm_debug.go index 4daa3ab5b..ea94987d1 100644 --- a/vm/vm_debug.go +++ b/vm/vm_debug.go @@ -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) -- cgit From 2df8ad6307d741d0a6d2f746d53f97c7b27ad796 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 2 Dec 2014 00:03:53 +0100 Subject: Added state tests --- vm/address.go | 8 ++++++-- vm/execution.go | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'vm') diff --git a/vm/address.go b/vm/address.go index 235143b34..86ae705bc 100644 --- a/vm/address.go +++ b/vm/address.go @@ -31,12 +31,16 @@ func sha256Func(in []byte) []byte { } func ripemd160Func(in []byte) []byte { - return ethutil.RightPadBytes(crypto.Ripemd160(in), 32) + return ethutil.LeftPadBytes(crypto.Ripemd160(in), 32) } func ecrecoverFunc(in []byte) []byte { // In case of an invalid sig. Defaults to return nil defer func() { recover() }() - return crypto.Ecrecover(in) + hash := in[:32] + v := ethutil.BigD(in[32:64]).Bytes()[0] - 27 + sig := append(in[64:], v) + + return crypto.Sha3(crypto.Ecrecover(append(hash, sig...))[1:]) } diff --git a/vm/execution.go b/vm/execution.go index c23164f82..8c04cf536 100644 --- a/vm/execution.go +++ b/vm/execution.go @@ -69,6 +69,7 @@ func (self *Execution) exec(code, caddr []byte, caller ClosureRef) (ret []byte, if self.Gas.Cmp(p.Gas) >= 0 { ret = p.Call(self.input) self.vm.Printf("NATIVE_FUNC(%x) => %x", naddr, ret) + self.vm.Endl() } } else { // Create a new callable closure -- cgit From 99481a245adc2c4814ab6b38d94d63114f7bbb15 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 2 Dec 2014 11:37:33 +0100 Subject: Check for known block err and ignore --- vm/address.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vm') diff --git a/vm/address.go b/vm/address.go index 86ae705bc..06bd35f6b 100644 --- a/vm/address.go +++ b/vm/address.go @@ -42,5 +42,5 @@ func ecrecoverFunc(in []byte) []byte { v := ethutil.BigD(in[32:64]).Bytes()[0] - 27 sig := append(in[64:], v) - return crypto.Sha3(crypto.Ecrecover(append(hash, sig...))[1:]) + return ethutil.LeftPadBytes(crypto.Sha3(crypto.Ecrecover(append(hash, sig...))[1:])[12:], 32) } -- cgit