diff options
author | obscuren <geffobscura@gmail.com> | 2014-12-18 06:58:52 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-12-18 06:58:52 +0800 |
commit | 4dbdcaecb117d7e1fcaf0869f5d4602312552991 (patch) | |
tree | 2da5cc7174f2f0a26f6c5aa20d079f94858e24cb /vm | |
parent | b1c58b76a9588a90db5a773a997bb70265c378d3 (diff) | |
download | go-tangerine-4dbdcaecb117d7e1fcaf0869f5d4602312552991.tar go-tangerine-4dbdcaecb117d7e1fcaf0869f5d4602312552991.tar.gz go-tangerine-4dbdcaecb117d7e1fcaf0869f5d4602312552991.tar.bz2 go-tangerine-4dbdcaecb117d7e1fcaf0869f5d4602312552991.tar.lz go-tangerine-4dbdcaecb117d7e1fcaf0869f5d4602312552991.tar.xz go-tangerine-4dbdcaecb117d7e1fcaf0869f5d4602312552991.tar.zst go-tangerine-4dbdcaecb117d7e1fcaf0869f5d4602312552991.zip |
Moved pre-compiled, moved depth check
* Depth check has been moved to the execution
* Pre compiled execution has been moved to the VM
* PrecompiledAddress has been renamed to PrecompiledAccount
Diffstat (limited to 'vm')
-rw-r--r-- | vm/address.go | 12 | ||||
-rw-r--r-- | vm/common.go | 2 | ||||
-rw-r--r-- | vm/vm_debug.go | 24 |
3 files changed, 28 insertions, 10 deletions
diff --git a/vm/address.go b/vm/address.go index be8921a3b..611979c94 100644 --- a/vm/address.go +++ b/vm/address.go @@ -11,25 +11,25 @@ type Address interface { Call(in []byte) []byte } -type PrecompiledAddress struct { +type PrecompiledAccount struct { Gas func(l int) *big.Int fn func(in []byte) []byte } -func (self PrecompiledAddress) Call(in []byte) []byte { +func (self PrecompiledAccount) Call(in []byte) []byte { return self.fn(in) } -var Precompiled = map[uint64]*PrecompiledAddress{ - 1: &PrecompiledAddress{func(l int) *big.Int { +var Precompiled = map[string]*PrecompiledAccount{ + string(ethutil.LeftPadBytes([]byte{1}, 20)): &PrecompiledAccount{func(l int) *big.Int { return GasEcrecover }, ecrecoverFunc}, - 2: &PrecompiledAddress{func(l int) *big.Int { + string(ethutil.LeftPadBytes([]byte{2}, 20)): &PrecompiledAccount{func(l int) *big.Int { n := big.NewInt(int64(l+31)/32 + 1) n.Mul(n, GasSha256) return n }, sha256Func}, - 3: &PrecompiledAddress{func(l int) *big.Int { + string(ethutil.LeftPadBytes([]byte{3}, 20)): &PrecompiledAccount{func(l int) *big.Int { n := big.NewInt(int64(l+31)/32 + 1) n.Mul(n, GasRipemd) return n diff --git a/vm/common.go b/vm/common.go index 592d44ccd..3d6d377ca 100644 --- a/vm/common.go +++ b/vm/common.go @@ -48,7 +48,7 @@ var ( S256 = ethutil.S256 ) -const MaxCallDepth = 1025 +const MaxCallDepth = 1024 func calcMemSize(off, l *big.Int) *big.Int { if l.Cmp(ethutil.Big0) == 0 { diff --git a/vm/vm_debug.go b/vm/vm_debug.go index 8af1979b1..9da832a79 100644 --- a/vm/vm_debug.go +++ b/vm/vm_debug.go @@ -48,9 +48,8 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price * }) closure := NewClosure(msg, caller, me, code, gas, price) - if self.env.Depth() == MaxCallDepth { - //closure.UseGas(gas) - return closure.Return(nil), DepthError{} + if p := Precompiled[string(me.Address())]; p != nil { + return self.RunPrecompiled(p, callData, closure) } if self.Recoverable { @@ -941,6 +940,25 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price * } } +func (self *DebugVm) RunPrecompiled(p *PrecompiledAccount, callData []byte, closure *Closure) (ret []byte, err error) { + gas := p.Gas(len(callData)) + if closure.UseGas(gas) { + ret = p.Call(callData) + self.Printf("NATIVE_FUNC => %x", ret) + self.Endl() + + return closure.Return(ret), nil + } else { + self.Endl() + + tmp := new(big.Int).Set(closure.Gas) + + closure.UseGas(closure.Gas) + + return closure.Return(nil), OOG(gas, tmp) + } +} + func (self *DebugVm) Printf(format string, v ...interface{}) VirtualMachine { if self.logTy == LogTyPretty { self.logStr += fmt.Sprintf(format, v...) |