mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-22 19:40:36 +00:00
c12f4df910
Reworked the EVM gas instructions to use 64bit integers rather than arbitrary size big ints. All gas operations, be it additions, multiplications or divisions, are checked and guarded against 64 bit integer overflows. In additon, most of the protocol paramaters in the params package have been converted to uint64 and are now constants rather than variables. * common/math: added overflow check ops * core: vmenv, env renamed to evm * eth, internal/ethapi, les: unmetered eth_call and cancel methods * core/vm: implemented big.Int pool for evm instructions * core/vm: unexported intPool methods & verification methods * core/vm: added memoryGasCost overflow check and test
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
// Copyright 2014 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package vm
|
|
|
|
import (
|
|
"math"
|
|
"math/big"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
)
|
|
|
|
var (
|
|
U256 = common.U256 // Shortcut to common.U256
|
|
S256 = common.S256 // Shortcut to common.S256
|
|
)
|
|
|
|
// calculates the memory size required for a step
|
|
func calcMemSize(off, l *big.Int) *big.Int {
|
|
if l.Cmp(common.Big0) == 0 {
|
|
return common.Big0
|
|
}
|
|
|
|
return new(big.Int).Add(off, l)
|
|
}
|
|
|
|
// getData returns a slice from the data based on the start and size and pads
|
|
// up to size with zero's. This function is overflow safe.
|
|
func getData(data []byte, start, size *big.Int) []byte {
|
|
dlen := big.NewInt(int64(len(data)))
|
|
|
|
s := common.BigMin(start, dlen)
|
|
e := common.BigMin(new(big.Int).Add(s, size), dlen)
|
|
return common.RightPadBytes(data[s.Uint64():e.Uint64()], int(size.Uint64()))
|
|
}
|
|
|
|
// bigUint64 returns the integer casted to a uint64 and returns whether it
|
|
// overflowed in the process.
|
|
func bigUint64(v *big.Int) (uint64, bool) {
|
|
return v.Uint64(), v.BitLen() > 64
|
|
}
|
|
|
|
// toWordSize returns the ceiled word size required for memory expansion.
|
|
func toWordSize(size uint64) uint64 {
|
|
if size > math.MaxUint64-31 {
|
|
return math.MaxUint64/32 + 1
|
|
}
|
|
|
|
return (size + 31) / 32
|
|
}
|