merge errors fixed

This commit is contained in:
obscuren
2014-12-02 11:52:56 +01:00
38 changed files with 9811 additions and 579 deletions

View File

@ -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 ethutil.LeftPadBytes(crypto.Sha3(crypto.Ecrecover(append(hash, sig...))[1:])[12:], 32)
}

View File

@ -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]
}

View File

@ -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

View File

@ -163,7 +163,7 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, 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)
@ -181,6 +181,16 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) {
reqGs.Set(GasLog)
addStepGasUsage(new(big.Int).Mul(big.NewInt(int64(n)), GasLog))
addStepGasUsage(new(big.Int).Add(mSize, mStart))
case EXP:
require(2)
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:
reqGas.Set(ethutil.Big0)
@ -281,7 +291,6 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) {
addStepGasUsage(memGasUsage)
mem.Resize(newMemSize.Uint64())
}
}
@ -295,6 +304,8 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) {
return nil, new(big.Int), OOG(reqGas, gas)
}
mem.Resize(newMemSize.Uint64())
switch op {
// 0x20 range
case ADD: