aboutsummaryrefslogtreecommitdiffstats
path: root/ethvm/common.go
blob: 6854a52197400520f7664441360cb4ed525ebdaf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package ethvm

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

    To256 = ethutil.To256
)

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
}