2014-10-18 04:31:20 -07:00
|
|
|
package vm
|
2014-07-22 02:54:48 -07:00
|
|
|
|
|
|
|
import (
|
2014-10-14 02:48:52 -07:00
|
|
|
"math/big"
|
|
|
|
|
2014-10-23 06:01:27 -07:00
|
|
|
"github.com/ethereum/go-ethereum/ethlog"
|
|
|
|
"github.com/ethereum/go-ethereum/ethutil"
|
2014-07-22 02:54:48 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var vmlogger = ethlog.NewLogger("VM")
|
|
|
|
|
2014-10-14 02:48:52 -07:00
|
|
|
type Type int
|
|
|
|
|
|
|
|
const (
|
|
|
|
StandardVmTy Type = iota
|
|
|
|
DebugVmTy
|
|
|
|
|
|
|
|
MaxVmTy
|
|
|
|
)
|
|
|
|
|
2014-07-22 02:54:48 -07:00
|
|
|
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)
|
2014-10-27 03:44:16 -07:00
|
|
|
GasLog = big.NewInt(32)
|
2014-07-22 02:54:48 -07:00
|
|
|
|
|
|
|
Pow256 = ethutil.BigPow(2, 256)
|
|
|
|
|
|
|
|
LogTyPretty byte = 0x1
|
|
|
|
LogTyDiff byte = 0x2
|
2014-10-14 02:48:52 -07:00
|
|
|
|
2014-10-15 08:12:26 -07:00
|
|
|
U256 = ethutil.U256
|
|
|
|
S256 = ethutil.S256
|
2014-07-22 02:54:48 -07:00
|
|
|
)
|
2014-10-14 02:48:52 -07:00
|
|
|
|
2014-10-22 16:01:26 -07:00
|
|
|
const MaxCallDepth = 1025
|
2014-10-14 02:48:52 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|