diff options
author | obscuren <geffobscura@gmail.com> | 2014-10-18 19:31:20 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-10-18 19:31:20 +0800 |
commit | 20c742e47406c13ebc6427951f6fcf1b0056ea26 (patch) | |
tree | e8112a93626c0f20ca5aa9ac91ea2d1be07150d9 /vm/common.go | |
parent | a02dc4ccc321bdee2a670eecdf5c3bac01fc290b (diff) | |
download | go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.gz go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.bz2 go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.lz go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.xz go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.tar.zst go-tangerine-20c742e47406c13ebc6427951f6fcf1b0056ea26.zip |
Moved ethvm => vm
Diffstat (limited to 'vm/common.go')
-rw-r--r-- | vm/common.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/vm/common.go b/vm/common.go new file mode 100644 index 000000000..6921b38ff --- /dev/null +++ b/vm/common.go @@ -0,0 +1,66 @@ +package vm + +import ( + "math/big" + + "github.com/ethereum/eth-go/ethlog" + "github.com/ethereum/eth-go/ethutil" +) + +var vmlogger = ethlog.NewLogger("VM") + +type Type int + +const ( + StandardVmTy Type = iota + DebugVmTy + + MaxVmTy +) + +var ( + GasStep = big.NewInt(1) + GasSha = big.NewInt(20) + GasSLoad = big.NewInt(20) + GasSStore = big.NewInt(100) + GasBalance = big.NewInt(20) + GasCreate = big.NewInt(100) + GasCall = big.NewInt(20) + GasMemory = big.NewInt(1) + GasData = big.NewInt(5) + GasTx = big.NewInt(500) + + Pow256 = ethutil.BigPow(2, 256) + + LogTyPretty byte = 0x1 + LogTyDiff byte = 0x2 + + U256 = ethutil.U256 + S256 = ethutil.S256 +) + +const MaxCallDepth = 1024 + +func calcMemSize(off, l *big.Int) *big.Int { + if l.Cmp(ethutil.Big0) == 0 { + return ethutil.Big0 + } + + return new(big.Int).Add(off, l) +} + +// Simple helper +func u256(n int64) *big.Int { + return big.NewInt(n) +} + +// Mainly used for print variables and passing to Print* +func toValue(val *big.Int) interface{} { + // Let's assume a string on right padded zero's + b := val.Bytes() + if b[0] != 0 && b[len(b)-1] == 0x0 && b[len(b)-2] == 0x0 { + return string(b) + } + + return val +} |