aboutsummaryrefslogtreecommitdiffstats
path: root/vm/gas.go
blob: a19afeb67ae7eb8a71d1f0bec9e40d4eb152f9a1 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package vm

import "math/big"

type req struct {
    stack int
    gas   *big.Int
}

var _baseCheck = map[OpCode]req{
    //       Req stack  Gas price
    ADD:          {2, GasFastestStep},
    LT:           {2, GasFastestStep},
    GT:           {2, GasFastestStep},
    SLT:          {2, GasFastestStep},
    SGT:          {2, GasFastestStep},
    EQ:           {2, GasFastestStep},
    ISZERO:       {1, GasFastestStep},
    SUB:          {2, GasFastestStep},
    AND:          {2, GasFastestStep},
    OR:           {2, GasFastestStep},
    XOR:          {2, GasFastestStep},
    NOT:          {1, GasFastestStep},
    BYTE:         {2, GasFastestStep},
    CALLDATALOAD: {1, GasFastestStep},
    CALLDATACOPY: {3, GasFastestStep},
    MLOAD:        {1, GasFastestStep},
    MSTORE:       {2, GasFastestStep},
    MSTORE8:      {2, GasFastestStep},
    CODECOPY:     {3, GasFastestStep},
    MUL:          {2, GasFastStep},
    DIV:          {2, GasFastStep},
    SDIV:         {2, GasFastStep},
    MOD:          {2, GasFastStep},
    SMOD:         {2, GasFastStep},
    SIGNEXTEND:   {2, GasFastStep},
    ADDMOD:       {3, GasMidStep},
    MULMOD:       {3, GasMidStep},
    JUMP:         {1, GasMidStep},
    JUMPI:        {2, GasSlowStep},
    EXP:          {2, GasSlowStep},
    ADDRESS:      {0, GasQuickStep},
    ORIGIN:       {0, GasQuickStep},
    CALLER:       {0, GasQuickStep},
    CALLVALUE:    {0, GasQuickStep},
    CODESIZE:     {0, GasQuickStep},
    GASPRICE:     {0, GasQuickStep},
    COINBASE:     {0, GasQuickStep},
    TIMESTAMP:    {0, GasQuickStep},
    NUMBER:       {0, GasQuickStep},
    CALLDATASIZE: {0, GasQuickStep},
    DIFFICULTY:   {0, GasQuickStep},
    GASLIMIT:     {0, GasQuickStep},
    POP:          {0, GasQuickStep},
    PC:           {0, GasQuickStep},
    MSIZE:        {0, GasQuickStep},
    GAS:          {0, GasQuickStep},
    BLOCKHASH:    {1, GasExtStep},
    BALANCE:      {0, GasExtStep},
    EXTCODESIZE:  {1, GasExtStep},
    EXTCODECOPY:  {4, GasExtStep},
    SLOAD:        {1, GasStorageGet},
    SSTORE:       {2, Zero},
    SHA3:         {1, GasSha3Base},
    CREATE:       {3, GasCreate},
    CALL:         {7, GasCall},
    CALLCODE:     {7, GasCall},
    JUMPDEST:     {0, GasJumpDest},
    SUICIDE:      {1, Zero},
    RETURN:       {2, Zero},
}

func baseCheck(op OpCode, stack *stack, gas *big.Int) {
    if r, ok := _baseCheck[op]; ok {
        stack.require(r.stack)

        gas.Add(gas, r.gas)
    }
}

func toWordSize(size *big.Int) *big.Int {
    tmp := new(big.Int)
    tmp.Add(size, u256(31))
    tmp.Div(tmp, u256(32))
    return tmp
}
deletions'>-0/+69 * www/piwik: update 2.12.1 -> 2.13.0robak2015-05-013-36/+146 * - Update to 7.2.0sunpoet2015-05-012-5/+3 * Horde package update:mm2015-05-016-9/+9 * Fix typo.osa2015-05-011-1/+1 * www/chromium: fix build with GCC (FreeBSD < 10)rene2015-05-011-0/+11 * Update to 0.303, and sort plist.adamw2015-05-013-21/+21 * Update to 5.90090. Add a couple more TEST_DEPENDS for more comprehensiveadamw2015-05-013-4/+12 * Fix warnings when using rc scriptfeld2015-05-012-3/+3 * www/squid: Add MAP_NOSYNC flay to mmap callmarino2015-05-013-0/+23 * Remove expired ports:rene2015-04-305-39/+0 * - Fix debug option that was always ongarga2015-04-303-3/+51 * Move each pkg-{plist,descr} into its own port, cleanup @dirrm*mat2015-04-307-11/+5 * www/chromium: update to 42.0.2311.135rene2015-04-302-5/+5 * Remove useless code.osa2015-04-302-4/+0 * Update to 0.5.7bapt2015-04-302-3/+3 * Flask-Cors is a simple extension to Flask allowing you to support cross-originwen2015-04-294-0/+28 * Update from 5.0.6 to 5.0.7:osa2015-04-298-13/+13 * Enable check for passenger third-party module compiled in nginx.osa2015-04-291-0/+7 * Add support for stream and stream_ssl modules.osa2015-04-291-0/+13 * Remove needless code.osa2015-04-291-6/+0 * Upgrade from 1.8.0 to 1.9.0.osa2015-04-292-7/+6 * Update my email address and give a few ports to ruby@mmoll2015-04-291-1/+1 * www/chromium: fix patching on FreeBSD < 10 (linking still fails because of arene2015-04-292-22/+0 * - Update to 4.2.1sunpoet2015-04-292-3/+3 * USES=xfce: Stop overriding MASTER_SITE_SUBDIR.bdrewery2015-04-291-2/+1 * Include high availability patch to give us feature parity with Linuxfeld2015-04-282-1/+31 * - Update to 3.1.21 [1]culot2015-04-282-3/+5 * New port: www/itopvg2015-04-285-0/+92 * Update to 0.002.adamw2015-04-272-3/+3 * - Update to 5.13sunpoet2015-04-272-3/+3 * - Add LICENSEsunpoet2015-04-271-1/+4 * - Update to 1.8.1sunpoet2015-04-273-3/+90 * - Fix build on 9.x (OpenSSL 0.9.8)sunpoet2015-04-271-0/+23 * Update to 0.55, and remove unnecessary DOCS option.adamw2015-04-272-8/+4 * Update to 0.160000, and fix whitespace alignment.adamw2015-04-272-32/+32 * www/chromium: update to 42.0.2311.90rene2015-04-27