aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/intpool.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2017-02-02 22:25:42 +0800
committerGitHub <noreply@github.com>2017-02-02 22:25:42 +0800
commit8b57c494908637a5c0e74f8f7a13b3218e026757 (patch)
treed5c7842eea6959c3b91dba00e8452a79d735a2a3 /core/vm/intpool.go
parent296450451b090393b2dd11d057c5b72cb4d92356 (diff)
downloadgo-tangerine-8b57c494908637a5c0e74f8f7a13b3218e026757.tar
go-tangerine-8b57c494908637a5c0e74f8f7a13b3218e026757.tar.gz
go-tangerine-8b57c494908637a5c0e74f8f7a13b3218e026757.tar.bz2
go-tangerine-8b57c494908637a5c0e74f8f7a13b3218e026757.tar.lz
go-tangerine-8b57c494908637a5c0e74f8f7a13b3218e026757.tar.xz
go-tangerine-8b57c494908637a5c0e74f8f7a13b3218e026757.tar.zst
go-tangerine-8b57c494908637a5c0e74f8f7a13b3218e026757.zip
params: core, core/vm, miner: 64bit gas instructions (#3514)
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
Diffstat (limited to 'core/vm/intpool.go')
-rw-r--r--core/vm/intpool.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/core/vm/intpool.go b/core/vm/intpool.go
new file mode 100644
index 000000000..4f1228e14
--- /dev/null
+++ b/core/vm/intpool.go
@@ -0,0 +1,49 @@
+// Copyright 2017 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/big"
+
+var checkVal = big.NewInt(-42)
+
+// intPool is a pool of big integers that
+// can be reused for all big.Int operations.
+type intPool struct {
+ pool *Stack
+}
+
+func newIntPool() *intPool {
+ return &intPool{pool: newstack()}
+}
+
+func (p *intPool) get() *big.Int {
+ if p.pool.len() > 0 {
+ return p.pool.pop()
+ }
+ return new(big.Int)
+}
+func (p *intPool) put(is ...*big.Int) {
+ for _, i := range is {
+ // verifyPool is a build flag. Pool verification makes sure the integrity
+ // of the integer pool by comparing values to a default value.
+ if verifyPool {
+ i.Set(checkVal)
+ }
+
+ p.pool.push(i)
+ }
+}