diff options
author | JM <jm@dexon.org> | 2019-01-15 23:33:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-15 23:33:28 +0800 |
commit | 020c8a477578cef3764b54f33d9ca0cf6caf7631 (patch) | |
tree | 08a669a19cc428b8c48dad180f1f32096885826b | |
parent | bdde6109ffa6fa4d295708a2a75271186a12c761 (diff) | |
download | dexon-020c8a477578cef3764b54f33d9ca0cf6caf7631.tar dexon-020c8a477578cef3764b54f33d9ca0cf6caf7631.tar.gz dexon-020c8a477578cef3764b54f33d9ca0cf6caf7631.tar.bz2 dexon-020c8a477578cef3764b54f33d9ca0cf6caf7631.tar.lz dexon-020c8a477578cef3764b54f33d9ca0cf6caf7631.tar.xz dexon-020c8a477578cef3764b54f33d9ca0cf6caf7631.tar.zst dexon-020c8a477578cef3764b54f33d9ca0cf6caf7631.zip |
core: vm: refactor file structure (#151)
For support other vm types, this pr modified the core/vm file
structures.
-rw-r--r-- | accounts/abi/bind/backends/simulated.go | 2 | ||||
-rw-r--r-- | cmd/evm/runner.go | 4 | ||||
-rw-r--r-- | cmd/evm/staterunner.go | 2 | ||||
-rw-r--r-- | cmd/utils/flags.go | 2 | ||||
-rw-r--r-- | consensus/clique/snapshot_test.go | 2 | ||||
-rw-r--r-- | consensus/dexcon/dexcon.go | 2 | ||||
-rw-r--r-- | consensus/dexcon/dexcon_test.go | 2 | ||||
-rw-r--r-- | core/asm/asm.go | 2 | ||||
-rw-r--r-- | core/asm/compiler.go | 2 | ||||
-rw-r--r-- | core/bench_test.go | 2 | ||||
-rw-r--r-- | core/block_validator_test.go | 2 | ||||
-rw-r--r-- | core/blockchain.go | 2 | ||||
-rw-r--r-- | core/blockchain_test.go | 2 | ||||
-rw-r--r-- | core/chain_makers.go | 2 | ||||
-rw-r--r-- | core/chain_makers_test.go | 2 | ||||
-rw-r--r-- | core/dao_test.go | 2 | ||||
-rw-r--r-- | core/evm.go | 2 | ||||
-rw-r--r-- | core/genesis.go | 2 | ||||
-rw-r--r-- | core/genesis_test.go | 2 | ||||
-rw-r--r-- | core/governance.go | 2 | ||||
-rw-r--r-- | core/state_processor.go | 2 | ||||
-rw-r--r-- | core/state_transition.go | 11 | ||||
-rw-r--r-- | core/types.go | 2 | ||||
-rw-r--r-- | core/vm/common.go | 12 | ||||
-rw-r--r-- | core/vm/evm/analysis.go (renamed from core/vm/analysis.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/analysis_test.go (renamed from core/vm/analysis_test.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/contract.go (renamed from core/vm/contract.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/contracts.go (renamed from core/vm/contracts.go) | 37 | ||||
-rw-r--r-- | core/vm/evm/contracts_test.go (renamed from core/vm/contracts_test.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/doc.go (renamed from core/vm/doc.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/evm.go (renamed from core/vm/evm.go) | 27 | ||||
-rw-r--r-- | core/vm/evm/evm_test.go (renamed from core/vm/evm_test.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/gas.go (renamed from core/vm/gas.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/gas_table.go (renamed from core/vm/gas_table.go) | 95 | ||||
-rw-r--r-- | core/vm/evm/gas_table_test.go (renamed from core/vm/gas_table_test.go) | 12 | ||||
-rw-r--r-- | core/vm/evm/gen_structlog.go (renamed from core/vm/gen_structlog.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/governance.go (renamed from core/vm/governance.go) | 5 | ||||
-rw-r--r-- | core/vm/evm/governance_abi.go (renamed from core/vm/governance_abi.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/governance_test.go (renamed from core/vm/governance_test.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/instructions.go (renamed from core/vm/instructions.go) | 517 | ||||
-rw-r--r-- | core/vm/evm/instructions_test.go (renamed from core/vm/instructions_test.go) | 87 | ||||
-rw-r--r-- | core/vm/evm/interface.go (renamed from core/vm/interface.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/interpreter.go (renamed from core/vm/interpreter.go) | 31 | ||||
-rw-r--r-- | core/vm/evm/jump_table.go (renamed from core/vm/jump_table.go) | 292 | ||||
-rw-r--r-- | core/vm/evm/logger.go (renamed from core/vm/logger.go) | 23 | ||||
-rw-r--r-- | core/vm/evm/logger_json.go (renamed from core/vm/logger_json.go) | 9 | ||||
-rw-r--r-- | core/vm/evm/logger_test.go (renamed from core/vm/logger_test.go) | 11 | ||||
-rw-r--r-- | core/vm/evm/memory_table.go | 98 | ||||
-rw-r--r-- | core/vm/evm/opcodes.go (renamed from core/vm/opcodes.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/runtime/doc.go (renamed from core/vm/runtime/doc.go) | 0 | ||||
-rw-r--r-- | core/vm/evm/runtime/env.go (renamed from core/vm/runtime/env.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/runtime/fuzz.go (renamed from core/vm/runtime/fuzz.go) | 0 | ||||
-rw-r--r-- | core/vm/evm/runtime/runtime.go (renamed from core/vm/runtime/runtime.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/runtime/runtime_example_test.go (renamed from core/vm/runtime/runtime_example_test.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/runtime/runtime_test.go (renamed from core/vm/runtime/runtime_test.go) | 2 | ||||
-rw-r--r-- | core/vm/evm/stack.go | 24 | ||||
-rw-r--r-- | core/vm/int_pool_verifier.go | 4 | ||||
-rw-r--r-- | core/vm/int_pool_verifier_empty.go | 4 | ||||
-rw-r--r-- | core/vm/intpool.go | 74 | ||||
-rw-r--r-- | core/vm/intpool_test.go | 26 | ||||
-rw-r--r-- | core/vm/memory.go | 48 | ||||
-rw-r--r-- | core/vm/memory_table.go | 97 | ||||
-rw-r--r-- | core/vm/stack.go | 69 | ||||
-rw-r--r-- | core/vm/stack_table.go | 20 | ||||
-rw-r--r-- | dex/api_backend.go | 2 | ||||
-rw-r--r-- | dex/api_tracer.go | 2 | ||||
-rw-r--r-- | dex/app_test.go | 2 | ||||
-rw-r--r-- | dex/backend.go | 2 | ||||
-rw-r--r-- | dex/downloader/downloader.go | 2 | ||||
-rw-r--r-- | dex/downloader/downloader_test.go | 2 | ||||
-rw-r--r-- | dex/downloader/testchain_test.go | 2 | ||||
-rw-r--r-- | dex/governance.go | 2 | ||||
-rw-r--r-- | dex/helper_test.go | 2 | ||||
-rw-r--r-- | eth/api_backend.go | 2 | ||||
-rw-r--r-- | eth/api_tracer.go | 2 | ||||
-rw-r--r-- | eth/backend.go | 2 | ||||
-rw-r--r-- | eth/handler_test.go | 2 | ||||
-rw-r--r-- | eth/helper_test.go | 2 | ||||
-rw-r--r-- | eth/tracers/tracer.go | 27 | ||||
-rw-r--r-- | eth/tracers/tracer_test.go | 2 | ||||
-rw-r--r-- | eth/tracers/tracers_test.go | 2 | ||||
-rw-r--r-- | indexer/blockchain.go | 2 | ||||
-rw-r--r-- | internal/ethapi/api.go | 2 | ||||
-rw-r--r-- | internal/ethapi/backend.go | 2 | ||||
-rw-r--r-- | les/api_backend.go | 2 | ||||
-rw-r--r-- | les/helper_test.go | 2 | ||||
-rw-r--r-- | les/odr_test.go | 2 | ||||
-rw-r--r-- | light/odr_test.go | 2 | ||||
-rw-r--r-- | light/trie_test.go | 2 | ||||
-rw-r--r-- | light/txpool_test.go | 2 | ||||
-rw-r--r-- | miner/worker_test.go | 2 | ||||
-rw-r--r-- | tests/block_test_util.go | 2 | ||||
-rw-r--r-- | tests/state_test.go | 2 | ||||
-rw-r--r-- | tests/state_test_util.go | 2 | ||||
-rw-r--r-- | tests/vm_test.go | 2 | ||||
-rw-r--r-- | tests/vm_test_util.go | 2 |
96 files changed, 911 insertions, 889 deletions
diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index c4048b503..7f1adfe76 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -34,7 +34,7 @@ import ( "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/eth/filters" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" diff --git a/cmd/evm/runner.go b/cmd/evm/runner.go index 114b9fd60..48782b496 100644 --- a/cmd/evm/runner.go +++ b/cmd/evm/runner.go @@ -32,8 +32,8 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/state" - "github.com/dexon-foundation/dexon/core/vm" - "github.com/dexon-foundation/dexon/core/vm/runtime" + vm "github.com/dexon-foundation/dexon/core/vm/evm" + "github.com/dexon-foundation/dexon/core/vm/evm/runtime" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/log" "github.com/dexon-foundation/dexon/params" diff --git a/cmd/evm/staterunner.go b/cmd/evm/staterunner.go index b76dc3ca4..ee96a539c 100644 --- a/cmd/evm/staterunner.go +++ b/cmd/evm/staterunner.go @@ -24,7 +24,7 @@ import ( "os" "github.com/dexon-foundation/dexon/core/state" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/log" "github.com/dexon-foundation/dexon/tests" diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index d7402b035..946136143 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -36,7 +36,7 @@ import ( "github.com/dexon-foundation/dexon/consensus/ethash" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/state" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/dashboard" "github.com/dexon-foundation/dexon/dex" diff --git a/consensus/clique/snapshot_test.go b/consensus/clique/snapshot_test.go index d60005c7c..4ea86a77f 100644 --- a/consensus/clique/snapshot_test.go +++ b/consensus/clique/snapshot_test.go @@ -25,7 +25,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" diff --git a/consensus/dexcon/dexcon.go b/consensus/dexcon/dexcon.go index 4480f64cb..b7f5f23f4 100644 --- a/consensus/dexcon/dexcon.go +++ b/consensus/dexcon/dexcon.go @@ -23,7 +23,7 @@ import ( "github.com/dexon-foundation/dexon/consensus" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/rpc" ) diff --git a/consensus/dexcon/dexcon_test.go b/consensus/dexcon/dexcon_test.go index 7ba1be876..7b41da7e1 100644 --- a/consensus/dexcon/dexcon_test.go +++ b/consensus/dexcon/dexcon_test.go @@ -25,7 +25,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/state" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" diff --git a/core/asm/asm.go b/core/asm/asm.go index 8dbb45ed3..164f3c29e 100644 --- a/core/asm/asm.go +++ b/core/asm/asm.go @@ -21,7 +21,7 @@ import ( "encoding/hex" "fmt" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" ) // Iterator for disassembled EVM instructions diff --git a/core/asm/compiler.go b/core/asm/compiler.go index b1c7c76f0..9a2f4a9aa 100644 --- a/core/asm/compiler.go +++ b/core/asm/compiler.go @@ -23,7 +23,7 @@ import ( "strings" "github.com/dexon-foundation/dexon/common/math" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" ) // Compiler contains information about the parsed source diff --git a/core/bench_test.go b/core/bench_test.go index c9a9bf735..98d46176a 100644 --- a/core/bench_test.go +++ b/core/bench_test.go @@ -28,7 +28,7 @@ import ( "github.com/dexon-foundation/dexon/consensus/ethash" "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" diff --git a/core/block_validator_test.go b/core/block_validator_test.go index f22653aca..5ae85c796 100644 --- a/core/block_validator_test.go +++ b/core/block_validator_test.go @@ -23,7 +23,7 @@ import ( "github.com/dexon-foundation/dexon/consensus/ethash" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" ) diff --git a/core/blockchain.go b/core/blockchain.go index 2e5265782..8c441eb19 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -41,7 +41,7 @@ import ( "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 183534b89..6598cbf3b 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -34,7 +34,7 @@ import ( "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" diff --git a/core/chain_makers.go b/core/chain_makers.go index 8325547c9..19ac8661b 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -36,7 +36,7 @@ import ( "github.com/dexon-foundation/dexon/consensus/misc" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go index 97896e87d..78c242df1 100644 --- a/core/chain_makers_test.go +++ b/core/chain_makers_test.go @@ -22,7 +22,7 @@ import ( "github.com/dexon-foundation/dexon/consensus/ethash" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" diff --git a/core/dao_test.go b/core/dao_test.go index 785aab5f2..7e437c1d9 100644 --- a/core/dao_test.go +++ b/core/dao_test.go @@ -21,7 +21,7 @@ import ( "testing" "github.com/dexon-foundation/dexon/consensus/ethash" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" ) diff --git a/core/evm.go b/core/evm.go index 9e4f00f7c..4d0ddcff2 100644 --- a/core/evm.go +++ b/core/evm.go @@ -23,7 +23,7 @@ import ( "github.com/dexon-foundation/dexon/consensus" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" ) // ChainContext supports retrieving headers and consensus parameters from the diff --git a/core/genesis.go b/core/genesis.go index 042084b34..1a1b43365 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -32,7 +32,7 @@ import ( "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/log" diff --git a/core/genesis_test.go b/core/genesis_test.go index 267086f9b..8cab2ad27 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -25,7 +25,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/consensus/ethash" "github.com/dexon-foundation/dexon/core/rawdb" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" ) diff --git a/core/governance.go b/core/governance.go index 538cd2b96..653336368 100644 --- a/core/governance.go +++ b/core/governance.go @@ -10,7 +10,7 @@ import ( dkgTypes "github.com/dexon-foundation/dexon-consensus/core/types/dkg" "github.com/dexon-foundation/dexon/core/state" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/log" "github.com/dexon-foundation/dexon/rlp" ) diff --git a/core/state_processor.go b/core/state_processor.go index eaeb36f78..ff2d5fbe4 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -22,7 +22,7 @@ import ( "github.com/dexon-foundation/dexon/consensus/misc" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/params" ) diff --git a/core/state_transition.go b/core/state_transition.go index 3b5ea6a2f..044bf594b 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -23,6 +23,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/vm" + "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/log" "github.com/dexon-foundation/dexon/params" ) @@ -56,8 +57,8 @@ type StateTransition struct { initialGas uint64 value *big.Int data []byte - state vm.StateDB - evm *vm.EVM + state evm.StateDB + evm *evm.EVM } // Message represents a message sent to a contract. @@ -109,7 +110,7 @@ func IntrinsicGas(data []byte, contractCreation, homestead bool) (uint64, error) } // NewStateTransition initialises and returns a new state transition object. -func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition { +func NewStateTransition(evm *evm.EVM, msg Message, gp *GasPool) *StateTransition { return &StateTransition{ gp: gp, evm: evm, @@ -128,7 +129,7 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition // the gas used (which includes gas refunds) and an error if it failed. An error always // indicates a core error meaning that the message would always fail for that particular // state and would never be accepted within a block. -func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool) ([]byte, uint64, bool, error) { +func ApplyMessage(evm *evm.EVM, msg Message, gp *GasPool) ([]byte, uint64, bool, error) { return NewStateTransition(evm, msg, gp).TransitionDb() } @@ -185,7 +186,7 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo return } msg := st.msg - sender := vm.AccountRef(msg.From()) + sender := evm.AccountRef(msg.From()) homestead := st.evm.ChainConfig().IsHomestead(st.evm.BlockNumber) contractCreation := msg.To() == nil diff --git a/core/types.go b/core/types.go index 327031b01..538776b88 100644 --- a/core/types.go +++ b/core/types.go @@ -19,7 +19,7 @@ package core import ( "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" ) // Validator is an interface which defines the standard for block validation. It diff --git a/core/vm/common.go b/core/vm/common.go index 7702b2a86..6b8c4667b 100644 --- a/core/vm/common.go +++ b/core/vm/common.go @@ -24,7 +24,7 @@ import ( ) // calculates the memory size required for a step -func calcMemSize(off, l *big.Int) *big.Int { +func CalcMemSize(off, l *big.Int) *big.Int { if l.Sign() == 0 { return common.Big0 } @@ -34,7 +34,7 @@ func calcMemSize(off, l *big.Int) *big.Int { // 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 uint64, size uint64) []byte { +func GetData(data []byte, start uint64, size uint64) []byte { length := uint64(len(data)) if start > length { start = length @@ -48,7 +48,7 @@ func getData(data []byte, start uint64, size uint64) []byte { // getDataBig 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 getDataBig(data []byte, start *big.Int, size *big.Int) []byte { +func GetDataBig(data []byte, start *big.Int, size *big.Int) []byte { dlen := big.NewInt(int64(len(data))) s := math.BigMin(start, dlen) @@ -58,12 +58,12 @@ func getDataBig(data []byte, start *big.Int, size *big.Int) []byte { // bigUint64 returns the integer casted to a uint64 and returns whether it // overflowed in the process. -func bigUint64(v *big.Int) (uint64, bool) { +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 { +func ToWordSize(size uint64) uint64 { if size > math.MaxUint64-31 { return math.MaxUint64/32 + 1 } @@ -71,7 +71,7 @@ func toWordSize(size uint64) uint64 { return (size + 31) / 32 } -func allZero(b []byte) bool { +func AllZero(b []byte) bool { for _, byte := range b { if byte != 0 { return false diff --git a/core/vm/analysis.go b/core/vm/evm/analysis.go index 0ccf47b97..5e430f965 100644 --- a/core/vm/analysis.go +++ b/core/vm/evm/analysis.go @@ -14,7 +14,7 @@ // 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 +package evm // bitvec is a bit vector which maps bytes in a program. // An unset bit means the byte is an opcode, a set bit means diff --git a/core/vm/analysis_test.go b/core/vm/evm/analysis_test.go index c4fe93474..6805f6076 100644 --- a/core/vm/analysis_test.go +++ b/core/vm/evm/analysis_test.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "testing" diff --git a/core/vm/contract.go b/core/vm/evm/contract.go index 751da072e..a7ce2ddfd 100644 --- a/core/vm/contract.go +++ b/core/vm/evm/contract.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "math/big" diff --git a/core/vm/contracts.go b/core/vm/evm/contracts.go index ac8fd22df..52bb0a83b 100644 --- a/core/vm/contracts.go +++ b/core/vm/evm/contracts.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "crypto/sha256" @@ -23,6 +23,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/common/math" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/crypto/bn256" "github.com/dexon-foundation/dexon/params" @@ -65,7 +66,7 @@ func RunPrecompiledContract(p PrecompiledContract, input []byte, contract *Contr if contract.UseGas(gas) { return p.Run(input) } - return nil, ErrOutOfGas + return nil, vm.ErrOutOfGas } // ECRECOVER implemented as a native contract. @@ -87,7 +88,7 @@ func (c *ecrecover) Run(input []byte) ([]byte, error) { v := input[63] - 27 // tighter sig s values input homestead only apply to tx sigs - if !allZero(input[32:63]) || !crypto.ValidateSignatureValues(v, r, s, false) { + if !vm.AllZero(input[32:63]) || !crypto.ValidateSignatureValues(v, r, s, false) { return nil, nil } // v needs to be at the end for libsecp256k1 @@ -166,9 +167,9 @@ var ( // RequiredGas returns the gas required to execute the pre-compiled contract. func (c *bigModExp) RequiredGas(input []byte) uint64 { var ( - baseLen = new(big.Int).SetBytes(getData(input, 0, 32)) - expLen = new(big.Int).SetBytes(getData(input, 32, 32)) - modLen = new(big.Int).SetBytes(getData(input, 64, 32)) + baseLen = new(big.Int).SetBytes(vm.GetData(input, 0, 32)) + expLen = new(big.Int).SetBytes(vm.GetData(input, 32, 32)) + modLen = new(big.Int).SetBytes(vm.GetData(input, 64, 32)) ) if len(input) > 96 { input = input[96:] @@ -181,9 +182,9 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 { expHead = new(big.Int) } else { if expLen.Cmp(big32) > 0 { - expHead = new(big.Int).SetBytes(getData(input, baseLen.Uint64(), 32)) + expHead = new(big.Int).SetBytes(vm.GetData(input, baseLen.Uint64(), 32)) } else { - expHead = new(big.Int).SetBytes(getData(input, baseLen.Uint64(), expLen.Uint64())) + expHead = new(big.Int).SetBytes(vm.GetData(input, baseLen.Uint64(), expLen.Uint64())) } } // Calculate the adjusted exponent length @@ -225,9 +226,9 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 { func (c *bigModExp) Run(input []byte) ([]byte, error) { var ( - baseLen = new(big.Int).SetBytes(getData(input, 0, 32)).Uint64() - expLen = new(big.Int).SetBytes(getData(input, 32, 32)).Uint64() - modLen = new(big.Int).SetBytes(getData(input, 64, 32)).Uint64() + baseLen = new(big.Int).SetBytes(vm.GetData(input, 0, 32)).Uint64() + expLen = new(big.Int).SetBytes(vm.GetData(input, 32, 32)).Uint64() + modLen = new(big.Int).SetBytes(vm.GetData(input, 64, 32)).Uint64() ) if len(input) > 96 { input = input[96:] @@ -240,9 +241,9 @@ func (c *bigModExp) Run(input []byte) ([]byte, error) { } // Retrieve the operands and execute the exponentiation var ( - base = new(big.Int).SetBytes(getData(input, 0, baseLen)) - exp = new(big.Int).SetBytes(getData(input, baseLen, expLen)) - mod = new(big.Int).SetBytes(getData(input, baseLen+expLen, modLen)) + base = new(big.Int).SetBytes(vm.GetData(input, 0, baseLen)) + exp = new(big.Int).SetBytes(vm.GetData(input, baseLen, expLen)) + mod = new(big.Int).SetBytes(vm.GetData(input, baseLen+expLen, modLen)) ) if mod.BitLen() == 0 { // Modulo 0 is undefined, return zero @@ -280,11 +281,11 @@ func (c *bn256Add) RequiredGas(input []byte) uint64 { } func (c *bn256Add) Run(input []byte) ([]byte, error) { - x, err := newCurvePoint(getData(input, 0, 64)) + x, err := newCurvePoint(vm.GetData(input, 0, 64)) if err != nil { return nil, err } - y, err := newCurvePoint(getData(input, 64, 64)) + y, err := newCurvePoint(vm.GetData(input, 64, 64)) if err != nil { return nil, err } @@ -302,12 +303,12 @@ func (c *bn256ScalarMul) RequiredGas(input []byte) uint64 { } func (c *bn256ScalarMul) Run(input []byte) ([]byte, error) { - p, err := newCurvePoint(getData(input, 0, 64)) + p, err := newCurvePoint(vm.GetData(input, 0, 64)) if err != nil { return nil, err } res := new(bn256.G1) - res.ScalarMult(p, new(big.Int).SetBytes(getData(input, 64, 32))) + res.ScalarMult(p, new(big.Int).SetBytes(vm.GetData(input, 64, 32))) return res.Marshal(), nil } diff --git a/core/vm/contracts_test.go b/core/vm/evm/contracts_test.go index f0090fcce..4b43f777b 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/evm/contracts_test.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "fmt" diff --git a/core/vm/doc.go b/core/vm/evm/doc.go index 5864d0cfa..27986e0c4 100644 --- a/core/vm/doc.go +++ b/core/vm/evm/doc.go @@ -21,4 +21,4 @@ The vm package implements one EVM, a byte code VM. The BC (Byte Code) VM loops over a set of bytes and executes them according to the set of rules defined in the Ethereum yellow paper. */ -package vm +package evm diff --git a/core/vm/evm.go b/core/vm/evm/evm.go index 64f71e530..e5f6625f1 100644 --- a/core/vm/evm.go +++ b/core/vm/evm/evm.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "math/big" @@ -23,6 +23,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/state" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/params" ) @@ -72,7 +73,7 @@ func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, err return interpreter.Run(contract, input, readOnly) } } - return nil, ErrNoCompatibleInterpreter + return nil, vm.ErrNoCompatibleInterpreter } // Context provides the EVM with auxiliary information. Once provided @@ -198,11 +199,11 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas // Fail if we're trying to execute above the call depth limit if evm.depth > int(params.CallCreateDepth) { - return nil, gas, ErrDepth + return nil, gas, vm.ErrDepth } // Fail if we're trying to transfer more than the available balance if !evm.Context.CanTransfer(evm.StateDB, caller.Address(), value) { - return nil, gas, ErrInsufficientBalance + return nil, gas, vm.ErrInsufficientBalance } var ( @@ -269,11 +270,11 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, // Fail if we're trying to execute above the call depth limit if evm.depth > int(params.CallCreateDepth) { - return nil, gas, ErrDepth + return nil, gas, vm.ErrDepth } // Fail if we're trying to transfer more than the available balance if !evm.CanTransfer(evm.StateDB, caller.Address(), value) { - return nil, gas, ErrInsufficientBalance + return nil, gas, vm.ErrInsufficientBalance } var ( @@ -307,7 +308,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by } // Fail if we're trying to execute above the call depth limit if evm.depth > int(params.CallCreateDepth) { - return nil, gas, ErrDepth + return nil, gas, vm.ErrDepth } var ( @@ -339,7 +340,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte } // Fail if we're trying to execute above the call depth limit if evm.depth > int(params.CallCreateDepth) { - return nil, gas, ErrDepth + return nil, gas, vm.ErrDepth } var ( @@ -388,10 +389,10 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, // Depth check execution. Fail if we're trying to execute above the // limit. if evm.depth > int(params.CallCreateDepth) { - return nil, common.Address{}, gas, ErrDepth + return nil, common.Address{}, gas, vm.ErrDepth } if !evm.CanTransfer(evm.StateDB, caller.Address(), value) { - return nil, common.Address{}, gas, ErrInsufficientBalance + return nil, common.Address{}, gas, vm.ErrInsufficientBalance } nonce := evm.StateDB.GetNonce(caller.Address()) evm.StateDB.SetNonce(caller.Address(), nonce+1) @@ -399,7 +400,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, // Ensure there's no existing contract already at the designated address contractHash := evm.StateDB.GetCodeHash(address) if evm.StateDB.GetNonce(address) != 0 || (contractHash != (common.Hash{}) && contractHash != emptyCodeHash) { - return nil, common.Address{}, 0, ErrContractAddressCollision + return nil, common.Address{}, 0, vm.ErrContractAddressCollision } // Create a new account on the state snapshot := evm.StateDB.Snapshot() @@ -437,14 +438,14 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, if contract.UseGas(createDataGas) { evm.StateDB.SetCode(address, ret) } else { - err = ErrCodeStoreOutOfGas + err = vm.ErrCodeStoreOutOfGas } } // When an error was returned by the EVM or when setting the creation code // above we revert to the snapshot and consume any gas remaining. Additionally // when we're in homestead this also counts for code storage gas errors. - if maxCodeSizeExceeded || (err != nil && (evm.ChainConfig().IsHomestead(evm.BlockNumber) || err != ErrCodeStoreOutOfGas)) { + if maxCodeSizeExceeded || (err != nil && (evm.ChainConfig().IsHomestead(evm.BlockNumber) || err != vm.ErrCodeStoreOutOfGas)) { evm.StateDB.RevertToSnapshot(snapshot) if err != errExecutionReverted { contract.UseGas(contract.Gas) diff --git a/core/vm/evm_test.go b/core/vm/evm/evm_test.go index 4b2714351..2e382c15f 100644 --- a/core/vm/evm_test.go +++ b/core/vm/evm/evm_test.go @@ -15,7 +15,7 @@ // along with the dexon-consensus library. If not, see // <http://www.gnu.org/licenses/>. -package vm +package evm import ( "fmt" diff --git a/core/vm/gas.go b/core/vm/evm/gas.go index 52c3b02f1..edd772423 100644 --- a/core/vm/gas.go +++ b/core/vm/evm/gas.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "math/big" diff --git a/core/vm/gas_table.go b/core/vm/evm/gas_table.go index c3fd01dc3..22370d3f1 100644 --- a/core/vm/gas_table.go +++ b/core/vm/evm/gas_table.go @@ -14,17 +14,18 @@ // 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 +package evm import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/common/math" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/params" ) // memoryGasCosts calculates the quadratic gas for memory expansion. It does so // only for the memory region that is expanded, not the total memory. -func memoryGasCost(mem *Memory, newMemSize uint64) (uint64, error) { +func memoryGasCost(mem *vm.Memory, newMemSize uint64) (uint64, error) { if newMemSize == 0 { return 0, nil @@ -40,7 +41,7 @@ func memoryGasCost(mem *Memory, newMemSize uint64) (uint64, error) { return 0, errGasUintOverflow } - newMemSizeWords := toWordSize(newMemSize) + newMemSizeWords := vm.ToWordSize(newMemSize) newMemSize = newMemSizeWords * 32 if newMemSize > uint64(mem.Len()) { @@ -49,8 +50,8 @@ func memoryGasCost(mem *Memory, newMemSize uint64) (uint64, error) { quadCoef := square / params.QuadCoeffDiv newTotalFee := linCoef + quadCoef - fee := newTotalFee - mem.lastGasCost - mem.lastGasCost = newTotalFee + fee := newTotalFee - mem.LastGasCost + mem.LastGasCost = newTotalFee return fee, nil } @@ -58,12 +59,12 @@ func memoryGasCost(mem *Memory, newMemSize uint64) (uint64, error) { } func constGasFunc(gas uint64) gasFunc { - return func(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { + return func(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { return gas, nil } } -func gasCallDataCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasCallDataCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { gas, err := memoryGasCost(mem, memorySize) if err != nil { return 0, err @@ -74,12 +75,12 @@ func gasCallDataCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *St return 0, errGasUintOverflow } - words, overflow := bigUint64(stack.Back(2)) + words, overflow := vm.BigUint64(stack.Back(2)) if overflow { return 0, errGasUintOverflow } - if words, overflow = math.SafeMul(toWordSize(words), params.CopyGas); overflow { + if words, overflow = math.SafeMul(vm.ToWordSize(words), params.CopyGas); overflow { return 0, errGasUintOverflow } @@ -89,7 +90,7 @@ func gasCallDataCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *St return gas, nil } -func gasReturnDataCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasReturnDataCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { gas, err := memoryGasCost(mem, memorySize) if err != nil { return 0, err @@ -100,12 +101,12 @@ func gasReturnDataCopy(gt params.GasTable, evm *EVM, contract *Contract, stack * return 0, errGasUintOverflow } - words, overflow := bigUint64(stack.Back(2)) + words, overflow := vm.BigUint64(stack.Back(2)) if overflow { return 0, errGasUintOverflow } - if words, overflow = math.SafeMul(toWordSize(words), params.CopyGas); overflow { + if words, overflow = math.SafeMul(vm.ToWordSize(words), params.CopyGas); overflow { return 0, errGasUintOverflow } @@ -115,7 +116,7 @@ func gasReturnDataCopy(gt params.GasTable, evm *EVM, contract *Contract, stack * return gas, nil } -func gasSStore(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasSStore(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { var ( y, x = stack.Back(1), stack.Back(0) current = evm.StateDB.GetState(contract.Address(), common.BigToHash(x)) @@ -183,8 +184,8 @@ func gasSStore(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, m } func makeGasLog(n uint64) gasFunc { - return func(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { - requestedSize, overflow := bigUint64(stack.Back(1)) + return func(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { + requestedSize, overflow := vm.BigUint64(stack.Back(1)) if overflow { return 0, errGasUintOverflow } @@ -212,7 +213,7 @@ func makeGasLog(n uint64) gasFunc { } } -func gasSha3(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasSha3(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { var overflow bool gas, err := memoryGasCost(mem, memorySize) if err != nil { @@ -223,11 +224,11 @@ func gasSha3(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem return 0, errGasUintOverflow } - wordGas, overflow := bigUint64(stack.Back(1)) + wordGas, overflow := vm.BigUint64(stack.Back(1)) if overflow { return 0, errGasUintOverflow } - if wordGas, overflow = math.SafeMul(toWordSize(wordGas), params.Sha3WordGas); overflow { + if wordGas, overflow = math.SafeMul(vm.ToWordSize(wordGas), params.Sha3WordGas); overflow { return 0, errGasUintOverflow } if gas, overflow = math.SafeAdd(gas, wordGas); overflow { @@ -236,7 +237,7 @@ func gasSha3(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem return gas, nil } -func gasCodeCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasCodeCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { gas, err := memoryGasCost(mem, memorySize) if err != nil { return 0, err @@ -247,11 +248,11 @@ func gasCodeCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, return 0, errGasUintOverflow } - wordGas, overflow := bigUint64(stack.Back(2)) + wordGas, overflow := vm.BigUint64(stack.Back(2)) if overflow { return 0, errGasUintOverflow } - if wordGas, overflow = math.SafeMul(toWordSize(wordGas), params.CopyGas); overflow { + if wordGas, overflow = math.SafeMul(vm.ToWordSize(wordGas), params.CopyGas); overflow { return 0, errGasUintOverflow } if gas, overflow = math.SafeAdd(gas, wordGas); overflow { @@ -260,7 +261,7 @@ func gasCodeCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, return gas, nil } -func gasExtCodeCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasExtCodeCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { gas, err := memoryGasCost(mem, memorySize) if err != nil { return 0, err @@ -271,12 +272,12 @@ func gasExtCodeCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *Sta return 0, errGasUintOverflow } - wordGas, overflow := bigUint64(stack.Back(3)) + wordGas, overflow := vm.BigUint64(stack.Back(3)) if overflow { return 0, errGasUintOverflow } - if wordGas, overflow = math.SafeMul(toWordSize(wordGas), params.CopyGas); overflow { + if wordGas, overflow = math.SafeMul(vm.ToWordSize(wordGas), params.CopyGas); overflow { return 0, errGasUintOverflow } @@ -286,11 +287,11 @@ func gasExtCodeCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *Sta return gas, nil } -func gasExtCodeHash(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasExtCodeHash(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { return gt.ExtcodeHash, nil } -func gasMLoad(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasMLoad(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { var overflow bool gas, err := memoryGasCost(mem, memorySize) if err != nil { @@ -302,7 +303,7 @@ func gasMLoad(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, me return gas, nil } -func gasMStore8(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasMStore8(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { var overflow bool gas, err := memoryGasCost(mem, memorySize) if err != nil { @@ -314,7 +315,7 @@ func gasMStore8(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, return gas, nil } -func gasMStore(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasMStore(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { var overflow bool gas, err := memoryGasCost(mem, memorySize) if err != nil { @@ -326,7 +327,7 @@ func gasMStore(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, m return gas, nil } -func gasCreate(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasCreate(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { var overflow bool gas, err := memoryGasCost(mem, memorySize) if err != nil { @@ -338,7 +339,7 @@ func gasCreate(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, m return gas, nil } -func gasCreate2(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasCreate2(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { var overflow bool gas, err := memoryGasCost(mem, memorySize) if err != nil { @@ -347,11 +348,11 @@ func gasCreate2(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, if gas, overflow = math.SafeAdd(gas, params.Create2Gas); overflow { return 0, errGasUintOverflow } - wordGas, overflow := bigUint64(stack.Back(2)) + wordGas, overflow := vm.BigUint64(stack.Back(2)) if overflow { return 0, errGasUintOverflow } - if wordGas, overflow = math.SafeMul(toWordSize(wordGas), params.Sha3WordGas); overflow { + if wordGas, overflow = math.SafeMul(vm.ToWordSize(wordGas), params.Sha3WordGas); overflow { return 0, errGasUintOverflow } if gas, overflow = math.SafeAdd(gas, wordGas); overflow { @@ -361,20 +362,20 @@ func gasCreate2(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, return gas, nil } -func gasBalance(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasBalance(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { return gt.Balance, nil } -func gasExtCodeSize(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasExtCodeSize(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { return gt.ExtcodeSize, nil } -func gasSLoad(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasSLoad(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { return gt.SLoad, nil } -func gasExp(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { - expByteLen := uint64((stack.data[stack.len()-2].BitLen() + 7) / 8) +func gasExp(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { + expByteLen := uint64((stack.Data[stack.Len()-2].BitLen() + 7) / 8) var ( gas = expByteLen * gt.ExpByte // no overflow check required. Max is 256 * ExpByte gas @@ -386,7 +387,7 @@ func gasExp(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem return gas, nil } -func gasCall(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasCall(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { var ( gas = gt.Calls transfersValue = stack.Back(2).Sign() != 0 @@ -422,7 +423,7 @@ func gasCall(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem return gas, nil } -func gasCallCode(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasCallCode(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { gas := gt.Calls if stack.Back(2).Sign() != 0 { gas += params.CallValueTransferGas @@ -446,15 +447,15 @@ func gasCallCode(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, return gas, nil } -func gasReturn(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasReturn(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { return memoryGasCost(mem, memorySize) } -func gasRevert(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasRevert(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { return memoryGasCost(mem, memorySize) } -func gasSuicide(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasSuicide(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { var gas uint64 // EIP150 homestead gas reprice fork: if evm.ChainConfig().IsEIP150(evm.BlockNumber) { @@ -480,7 +481,7 @@ func gasSuicide(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, return gas, nil } -func gasDelegateCall(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasDelegateCall(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { gas, err := memoryGasCost(mem, memorySize) if err != nil { return 0, err @@ -500,7 +501,7 @@ func gasDelegateCall(gt params.GasTable, evm *EVM, contract *Contract, stack *St return gas, nil } -func gasStaticCall(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasStaticCall(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { gas, err := memoryGasCost(mem, memorySize) if err != nil { return 0, err @@ -520,14 +521,14 @@ func gasStaticCall(gt params.GasTable, evm *EVM, contract *Contract, stack *Stac return gas, nil } -func gasPush(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasPush(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { return GasFastestStep, nil } -func gasSwap(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasSwap(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { return GasFastestStep, nil } -func gasDup(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { +func gasDup(gt params.GasTable, evm *EVM, contract *Contract, stack *vm.Stack, mem *vm.Memory, memorySize uint64) (uint64, error) { return GasFastestStep, nil } diff --git a/core/vm/gas_table_test.go b/core/vm/evm/gas_table_test.go index 1b91aee56..35a902c67 100644 --- a/core/vm/gas_table_test.go +++ b/core/vm/evm/gas_table_test.go @@ -14,14 +14,18 @@ // 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 +package evm -import "testing" +import ( + "testing" + + "github.com/dexon-foundation/dexon/core/vm" +) func TestMemoryGasCost(t *testing.T) { //size := uint64(math.MaxUint64 - 64) size := uint64(0xffffffffe0) - v, err := memoryGasCost(&Memory{}, size) + v, err := memoryGasCost(&vm.Memory{}, size) if err != nil { t.Error("didn't expect error:", err) } @@ -29,7 +33,7 @@ func TestMemoryGasCost(t *testing.T) { t.Errorf("Expected: 36028899963961341, got %d", v) } - _, err = memoryGasCost(&Memory{}, size+1) + _, err = memoryGasCost(&vm.Memory{}, size+1) if err == nil { t.Error("expected error") } diff --git a/core/vm/gen_structlog.go b/core/vm/evm/gen_structlog.go index a3da8734f..600af4b52 100644 --- a/core/vm/gen_structlog.go +++ b/core/vm/evm/gen_structlog.go @@ -1,6 +1,6 @@ // Code generated by github.com/fjl/gencodec. DO NOT EDIT. -package vm +package evm import ( "encoding/json" diff --git a/core/vm/governance.go b/core/vm/evm/governance.go index 09a5a90e1..8b31d3a01 100644 --- a/core/vm/governance.go +++ b/core/vm/evm/governance.go @@ -15,7 +15,7 @@ // along with the dexon-consensus library. If not, see // <http://www.gnu.org/licenses/>. -package vm +package evm import ( "bytes" @@ -35,6 +35,7 @@ import ( "github.com/dexon-foundation/dexon-consensus/core" coreCrypto "github.com/dexon-foundation/dexon-consensus/core/crypto" coreUtils "github.com/dexon-foundation/dexon-consensus/core/utils" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon-consensus/core/crypto/ecdsa" coreTypes "github.com/dexon-foundation/dexon-consensus/core/types" @@ -1554,7 +1555,7 @@ func (g *GovernanceContract) transfer(from, to common.Address, amount *big.Int) func (g *GovernanceContract) useGas(gas uint64) ([]byte, error) { if !g.contract.UseGas(gas) { - return nil, ErrOutOfGas + return nil, vm.ErrOutOfGas } return nil, nil } diff --git a/core/vm/governance_abi.go b/core/vm/evm/governance_abi.go index 0e66e113a..966c4c4f3 100644 --- a/core/vm/governance_abi.go +++ b/core/vm/evm/governance_abi.go @@ -15,7 +15,7 @@ // along with the dexon-consensus library. If not, see // <http://www.gnu.org/licenses/>. -package vm +package evm // The governance ABI is generated from: // https://github.com/dexon-foundation/governance-abi diff --git a/core/vm/governance_test.go b/core/vm/evm/governance_test.go index b1dedc315..1a67516ec 100644 --- a/core/vm/governance_test.go +++ b/core/vm/evm/governance_test.go @@ -15,7 +15,7 @@ // along with the dexon-consensus library. If not, see // <http://www.gnu.org/licenses/>. -package vm +package evm import ( "bytes" diff --git a/core/vm/instructions.go b/core/vm/evm/instructions.go index beb4c6b73..be81d6d9d 100644 --- a/core/vm/instructions.go +++ b/core/vm/evm/instructions.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "encoding/binary" @@ -25,6 +25,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/common/math" "github.com/dexon-foundation/dexon/core/types" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/crypto/sha3" "github.com/dexon-foundation/dexon/params" @@ -50,48 +51,48 @@ func init() { } } -func opAdd(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.peek() +func opAdd(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Peek() math.U256(y.Add(x, y)) - interpreter.intPool.put(x) + interpreter.intPool.Put(x) return nil, nil } -func opSub(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.peek() +func opSub(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Peek() math.U256(y.Sub(x, y)) - interpreter.intPool.put(x) + interpreter.intPool.Put(x) return nil, nil } -func opMul(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.pop() - stack.push(math.U256(x.Mul(x, y))) +func opMul(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Pop() + stack.Push(math.U256(x.Mul(x, y))) - interpreter.intPool.put(y) + interpreter.intPool.Put(y) return nil, nil } -func opDiv(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.peek() +func opDiv(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Peek() if y.Sign() != 0 { math.U256(y.Div(x, y)) } else { y.SetUint64(0) } - interpreter.intPool.put(x) + interpreter.intPool.Put(x) return nil, nil } -func opSdiv(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := math.S256(stack.pop()), math.S256(stack.pop()) - res := interpreter.intPool.getZero() +func opSdiv(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := math.S256(stack.Pop()), math.S256(stack.Pop()) + res := interpreter.intPool.GetZero() if y.Sign() == 0 || x.Sign() == 0 { - stack.push(res) + stack.Push(res) } else { if x.Sign() != y.Sign() { res.Div(x.Abs(x), y.Abs(y)) @@ -99,29 +100,29 @@ func opSdiv(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory } else { res.Div(x.Abs(x), y.Abs(y)) } - stack.push(math.U256(res)) + stack.Push(math.U256(res)) } - interpreter.intPool.put(x, y) + interpreter.intPool.Put(x, y) return nil, nil } -func opMod(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.pop() +func opMod(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Pop() if y.Sign() == 0 { - stack.push(x.SetUint64(0)) + stack.Push(x.SetUint64(0)) } else { - stack.push(math.U256(x.Mod(x, y))) + stack.Push(math.U256(x.Mod(x, y))) } - interpreter.intPool.put(y) + interpreter.intPool.Put(y) return nil, nil } -func opSmod(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := math.S256(stack.pop()), math.S256(stack.pop()) - res := interpreter.intPool.getZero() +func opSmod(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := math.S256(stack.Pop()), math.S256(stack.Pop()) + res := interpreter.intPool.GetZero() if y.Sign() == 0 { - stack.push(res) + stack.Push(res) } else { if x.Sign() < 0 { res.Mod(x.Abs(x), y.Abs(y)) @@ -129,31 +130,31 @@ func opSmod(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory } else { res.Mod(x.Abs(x), y.Abs(y)) } - stack.push(math.U256(res)) + stack.Push(math.U256(res)) } - interpreter.intPool.put(x, y) + interpreter.intPool.Put(x, y) return nil, nil } -func opExp(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - base, exponent := stack.pop(), stack.pop() +func opExp(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + base, exponent := stack.Pop(), stack.Pop() if base.Cmp(big2) == 0 && exponent.Cmp(big256) == -1 { exp := exponent.Int64() - stack.push(interpreter.intPool.get().Set(power2[exp])) + stack.Push(interpreter.intPool.Get().Set(power2[exp])) } else { - stack.push(math.Exp(base, exponent)) + stack.Push(math.Exp(base, exponent)) } - interpreter.intPool.put(base, exponent) + interpreter.intPool.Put(base, exponent) return nil, nil } -func opSignExtend(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - back := stack.pop() +func opSignExtend(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + back := stack.Pop() if back.Cmp(big.NewInt(31)) < 0 { bit := uint(back.Uint64()*8 + 7) - num := stack.pop() + num := stack.Pop() mask := back.Lsh(common.Big1, bit) mask.Sub(mask, common.Big1) if num.Bit(int(bit)) > 0 { @@ -162,43 +163,43 @@ func opSignExtend(pc *uint64, interpreter *EVMInterpreter, contract *Contract, m num.And(num, mask) } - stack.push(math.U256(num)) + stack.Push(math.U256(num)) } - interpreter.intPool.put(back) + interpreter.intPool.Put(back) return nil, nil } -func opNot(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x := stack.peek() +func opNot(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x := stack.Peek() math.U256(x.Not(x)) return nil, nil } -func opLt(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.peek() +func opLt(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Peek() if x.Cmp(y) < 0 { y.SetUint64(1) } else { y.SetUint64(0) } - interpreter.intPool.put(x) + interpreter.intPool.Put(x) return nil, nil } -func opGt(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.peek() +func opGt(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Peek() if x.Cmp(y) > 0 { y.SetUint64(1) } else { y.SetUint64(0) } - interpreter.intPool.put(x) + interpreter.intPool.Put(x) return nil, nil } -func opSlt(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.peek() +func opSlt(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Peek() xSign := x.Cmp(tt255) ySign := y.Cmp(tt255) @@ -217,12 +218,12 @@ func opSlt(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory * y.SetUint64(0) } } - interpreter.intPool.put(x) + interpreter.intPool.Put(x) return nil, nil } -func opSgt(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.peek() +func opSgt(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Peek() xSign := x.Cmp(tt255) ySign := y.Cmp(tt255) @@ -241,23 +242,23 @@ func opSgt(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory * y.SetUint64(0) } } - interpreter.intPool.put(x) + interpreter.intPool.Put(x) return nil, nil } -func opEq(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.peek() +func opEq(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Peek() if x.Cmp(y) == 0 { y.SetUint64(1) } else { y.SetUint64(0) } - interpreter.intPool.put(x) + interpreter.intPool.Put(x) return nil, nil } -func opIszero(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x := stack.peek() +func opIszero(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x := stack.Peek() if x.Sign() > 0 { x.SetUint64(0) } else { @@ -266,75 +267,75 @@ func opIszero(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memor return nil, nil } -func opAnd(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.pop() - stack.push(x.And(x, y)) +func opAnd(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Pop() + stack.Push(x.And(x, y)) - interpreter.intPool.put(y) + interpreter.intPool.Put(y) return nil, nil } -func opOr(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.peek() +func opOr(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Peek() y.Or(x, y) - interpreter.intPool.put(x) + interpreter.intPool.Put(x) return nil, nil } -func opXor(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y := stack.pop(), stack.peek() +func opXor(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y := stack.Pop(), stack.Peek() y.Xor(x, y) - interpreter.intPool.put(x) + interpreter.intPool.Put(x) return nil, nil } -func opByte(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - th, val := stack.pop(), stack.peek() +func opByte(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + th, val := stack.Pop(), stack.Peek() if th.Cmp(common.Big32) < 0 { b := math.Byte(val, 32, int(th.Int64())) val.SetUint64(uint64(b)) } else { val.SetUint64(0) } - interpreter.intPool.put(th) + interpreter.intPool.Put(th) return nil, nil } -func opAddmod(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y, z := stack.pop(), stack.pop(), stack.pop() +func opAddmod(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y, z := stack.Pop(), stack.Pop(), stack.Pop() if z.Cmp(bigZero) > 0 { x.Add(x, y) x.Mod(x, z) - stack.push(math.U256(x)) + stack.Push(math.U256(x)) } else { - stack.push(x.SetUint64(0)) + stack.Push(x.SetUint64(0)) } - interpreter.intPool.put(y, z) + interpreter.intPool.Put(y, z) return nil, nil } -func opMulmod(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - x, y, z := stack.pop(), stack.pop(), stack.pop() +func opMulmod(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + x, y, z := stack.Pop(), stack.Pop(), stack.Pop() if z.Cmp(bigZero) > 0 { x.Mul(x, y) x.Mod(x, z) - stack.push(math.U256(x)) + stack.Push(math.U256(x)) } else { - stack.push(x.SetUint64(0)) + stack.Push(x.SetUint64(0)) } - interpreter.intPool.put(y, z) + interpreter.intPool.Put(y, z) return nil, nil } // opSHL implements Shift Left // The SHL instruction (shift left) pops 2 values from the stack, first arg1 and then arg2, // and pushes on the stack arg2 shifted to the left by arg1 number of bits. -func opSHL(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSHL(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { // Note, second operand is left in the stack; accumulate result into it, and no need to push it afterwards - shift, value := math.U256(stack.pop()), math.U256(stack.peek()) - defer interpreter.intPool.put(shift) // First operand back into the pool + shift, value := math.U256(stack.Pop()), math.U256(stack.Peek()) + defer interpreter.intPool.Put(shift) // First operand back into the pool if shift.Cmp(common.Big256) >= 0 { value.SetUint64(0) @@ -349,10 +350,10 @@ func opSHL(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory * // opSHR implements Logical Shift Right // The SHR instruction (logical shift right) pops 2 values from the stack, first arg1 and then arg2, // and pushes on the stack arg2 shifted to the right by arg1 number of bits with zero fill. -func opSHR(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSHR(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { // Note, second operand is left in the stack; accumulate result into it, and no need to push it afterwards - shift, value := math.U256(stack.pop()), math.U256(stack.peek()) - defer interpreter.intPool.put(shift) // First operand back into the pool + shift, value := math.U256(stack.Pop()), math.U256(stack.Peek()) + defer interpreter.intPool.Put(shift) // First operand back into the pool if shift.Cmp(common.Big256) >= 0 { value.SetUint64(0) @@ -367,10 +368,10 @@ func opSHR(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory * // opSAR implements Arithmetic Shift Right // The SAR instruction (arithmetic shift right) pops 2 values from the stack, first arg1 and then arg2, // and pushes on the stack arg2 shifted to the right by arg1 number of bits with sign extension. -func opSAR(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSAR(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { // Note, S256 returns (potentially) a new bigint, so we're popping, not peeking this one - shift, value := math.U256(stack.pop()), math.S256(stack.pop()) - defer interpreter.intPool.put(shift) // First operand back into the pool + shift, value := math.U256(stack.Pop()), math.S256(stack.Pop()) + defer interpreter.intPool.Put(shift) // First operand back into the pool if shift.Cmp(common.Big256) >= 0 { if value.Sign() >= 0 { @@ -378,18 +379,18 @@ func opSAR(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory * } else { value.SetInt64(-1) } - stack.push(math.U256(value)) + stack.Push(math.U256(value)) return nil, nil } n := uint(shift.Uint64()) value.Rsh(value, n) - stack.push(math.U256(value)) + stack.Push(math.U256(value)) return nil, nil } -func opSha3(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - offset, size := stack.pop(), stack.pop() +func opSha3(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + offset, size := stack.Pop(), stack.Pop() data := memory.Get(offset.Int64(), size.Int64()) if interpreter.hasher == nil { @@ -404,13 +405,13 @@ func opSha3(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory if evm.vmConfig.EnablePreimageRecording { evm.StateDB.AddPreimage(interpreter.hasherBuf, data) } - stack.push(interpreter.intPool.get().SetBytes(interpreter.hasherBuf[:])) + stack.Push(interpreter.intPool.Get().SetBytes(interpreter.hasherBuf[:])) - interpreter.intPool.put(offset, size) + interpreter.intPool.Put(offset, size) return nil, nil } -func opRand(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opRand(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { evm := interpreter.evm nonce := evm.StateDB.GetNonce(contract.Caller()) @@ -426,72 +427,72 @@ func opRand(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory binaryNonce, binaryGas) - stack.push(interpreter.intPool.get().SetBytes(hash)) + stack.Push(interpreter.intPool.Get().SetBytes(hash)) return nil, nil } -func opAddress(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(contract.Address().Big()) +func opAddress(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(contract.Address().Big()) return nil, nil } -func opBalance(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - slot := stack.peek() +func opBalance(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + slot := stack.Peek() slot.Set(interpreter.evm.StateDB.GetBalance(common.BigToAddress(slot))) return nil, nil } -func opOrigin(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(interpreter.evm.Origin.Big()) +func opOrigin(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(interpreter.evm.Origin.Big()) return nil, nil } -func opCaller(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(contract.Caller().Big()) +func opCaller(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(contract.Caller().Big()) return nil, nil } -func opCallValue(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(interpreter.intPool.get().Set(contract.value)) +func opCallValue(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(interpreter.intPool.Get().Set(contract.value)) return nil, nil } -func opCallDataLoad(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(interpreter.intPool.get().SetBytes(getDataBig(contract.Input, stack.pop(), big32))) +func opCallDataLoad(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(interpreter.intPool.Get().SetBytes(vm.GetDataBig(contract.Input, stack.Pop(), big32))) return nil, nil } -func opCallDataSize(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(interpreter.intPool.get().SetInt64(int64(len(contract.Input)))) +func opCallDataSize(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(interpreter.intPool.Get().SetInt64(int64(len(contract.Input)))) return nil, nil } -func opCallDataCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCallDataCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { var ( - memOffset = stack.pop() - dataOffset = stack.pop() - length = stack.pop() + memOffset = stack.Pop() + dataOffset = stack.Pop() + length = stack.Pop() ) - memory.Set(memOffset.Uint64(), length.Uint64(), getDataBig(contract.Input, dataOffset, length)) + memory.Set(memOffset.Uint64(), length.Uint64(), vm.GetDataBig(contract.Input, dataOffset, length)) - interpreter.intPool.put(memOffset, dataOffset, length) + interpreter.intPool.Put(memOffset, dataOffset, length) return nil, nil } -func opReturnDataSize(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(interpreter.intPool.get().SetUint64(uint64(len(interpreter.returnData)))) +func opReturnDataSize(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(interpreter.intPool.Get().SetUint64(uint64(len(interpreter.returnData)))) return nil, nil } -func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { var ( - memOffset = stack.pop() - dataOffset = stack.pop() - length = stack.pop() + memOffset = stack.Pop() + dataOffset = stack.Pop() + length = stack.Pop() - end = interpreter.intPool.get().Add(dataOffset, length) + end = interpreter.intPool.Get().Add(dataOffset, length) ) - defer interpreter.intPool.put(memOffset, dataOffset, length, end) + defer interpreter.intPool.Put(memOffset, dataOffset, length, end) if end.BitLen() > 64 || uint64(len(interpreter.returnData)) < end.Uint64() { return nil, errReturnDataOutOfBounds @@ -501,44 +502,44 @@ func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contrac return nil, nil } -func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - slot := stack.peek() +func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + slot := stack.Peek() slot.SetUint64(uint64(interpreter.evm.StateDB.GetCodeSize(common.BigToAddress(slot)))) return nil, nil } -func opCodeSize(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - l := interpreter.intPool.get().SetInt64(int64(len(contract.Code))) - stack.push(l) +func opCodeSize(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + l := interpreter.intPool.Get().SetInt64(int64(len(contract.Code))) + stack.Push(l) return nil, nil } -func opCodeCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCodeCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { var ( - memOffset = stack.pop() - codeOffset = stack.pop() - length = stack.pop() + memOffset = stack.Pop() + codeOffset = stack.Pop() + length = stack.Pop() ) - codeCopy := getDataBig(contract.Code, codeOffset, length) + codeCopy := vm.GetDataBig(contract.Code, codeOffset, length) memory.Set(memOffset.Uint64(), length.Uint64(), codeCopy) - interpreter.intPool.put(memOffset, codeOffset, length) + interpreter.intPool.Put(memOffset, codeOffset, length) return nil, nil } -func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { var ( - addr = common.BigToAddress(stack.pop()) - memOffset = stack.pop() - codeOffset = stack.pop() - length = stack.pop() + addr = common.BigToAddress(stack.Pop()) + memOffset = stack.Pop() + codeOffset = stack.Pop() + length = stack.Pop() ) - codeCopy := getDataBig(interpreter.evm.StateDB.GetCode(addr), codeOffset, length) + codeCopy := vm.GetDataBig(interpreter.evm.StateDB.GetCode(addr), codeOffset, length) memory.Set(memOffset.Uint64(), length.Uint64(), codeCopy) - interpreter.intPool.put(memOffset, codeOffset, length) + interpreter.intPool.Put(memOffset, codeOffset, length) return nil, nil } @@ -568,8 +569,8 @@ func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contract, // // (6) Caller tries to get the code hash for an account which is marked as deleted, // this account should be regarded as a non-existent account and zero should be returned. -func opExtCodeHash(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - slot := stack.peek() +func opExtCodeHash(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + slot := stack.Peek() address := common.BigToAddress(slot) if interpreter.evm.StateDB.Empty(address) { slot.SetUint64(0) @@ -579,109 +580,109 @@ func opExtCodeHash(pc *uint64, interpreter *EVMInterpreter, contract *Contract, return nil, nil } -func opGasprice(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(interpreter.intPool.get().Set(interpreter.evm.GasPrice)) +func opGasprice(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(interpreter.intPool.Get().Set(interpreter.evm.GasPrice)) return nil, nil } -func opBlockhash(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - num := stack.pop() +func opBlockhash(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + num := stack.Pop() - n := interpreter.intPool.get().Sub(interpreter.evm.BlockNumber, common.Big257) + n := interpreter.intPool.Get().Sub(interpreter.evm.BlockNumber, common.Big257) if num.Cmp(n) > 0 && num.Cmp(interpreter.evm.BlockNumber) < 0 { - stack.push(interpreter.evm.GetHash(num.Uint64()).Big()) + stack.Push(interpreter.evm.GetHash(num.Uint64()).Big()) } else { - stack.push(interpreter.intPool.getZero()) + stack.Push(interpreter.intPool.GetZero()) } - interpreter.intPool.put(num, n) + interpreter.intPool.Put(num, n) return nil, nil } -func opCoinbase(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(interpreter.evm.Coinbase.Big()) +func opCoinbase(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(interpreter.evm.Coinbase.Big()) return nil, nil } -func opTimestamp(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(math.U256(interpreter.intPool.get().Set(interpreter.evm.Time))) +func opTimestamp(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(math.U256(interpreter.intPool.Get().Set(interpreter.evm.Time))) return nil, nil } -func opNumber(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(math.U256(interpreter.intPool.get().Set(interpreter.evm.BlockNumber))) +func opNumber(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(math.U256(interpreter.intPool.Get().Set(interpreter.evm.BlockNumber))) return nil, nil } -func opDifficulty(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(math.U256(interpreter.intPool.get().Set(interpreter.evm.Difficulty))) +func opDifficulty(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(math.U256(interpreter.intPool.Get().Set(interpreter.evm.Difficulty))) return nil, nil } -func opGasLimit(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(math.U256(interpreter.intPool.get().SetUint64(interpreter.evm.GasLimit))) +func opGasLimit(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(math.U256(interpreter.intPool.Get().SetUint64(interpreter.evm.GasLimit))) return nil, nil } -func opPop(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - interpreter.intPool.put(stack.pop()) +func opPop(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + interpreter.intPool.Put(stack.Pop()) return nil, nil } -func opMload(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - offset := stack.pop() - val := interpreter.intPool.get().SetBytes(memory.Get(offset.Int64(), 32)) - stack.push(val) +func opMload(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + offset := stack.Pop() + val := interpreter.intPool.Get().SetBytes(memory.Get(offset.Int64(), 32)) + stack.Push(val) - interpreter.intPool.put(offset) + interpreter.intPool.Put(offset) return nil, nil } -func opMstore(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opMstore(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { // pop value of the stack - mStart, val := stack.pop(), stack.pop() + mStart, val := stack.Pop(), stack.Pop() memory.Set32(mStart.Uint64(), val) - interpreter.intPool.put(mStart, val) + interpreter.intPool.Put(mStart, val) return nil, nil } -func opMstore8(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - off, val := stack.pop().Int64(), stack.pop().Int64() - memory.store[off] = byte(val & 0xff) +func opMstore8(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + off, val := stack.Pop().Int64(), stack.Pop().Int64() + memory.Store[off] = byte(val & 0xff) return nil, nil } -func opSload(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - loc := stack.peek() +func opSload(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + loc := stack.Peek() val := interpreter.evm.StateDB.GetState(contract.Address(), common.BigToHash(loc)) loc.SetBytes(val.Bytes()) return nil, nil } -func opSstore(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - loc := common.BigToHash(stack.pop()) - val := stack.pop() +func opSstore(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + loc := common.BigToHash(stack.Pop()) + val := stack.Pop() interpreter.evm.StateDB.SetState(contract.Address(), loc, common.BigToHash(val)) - interpreter.intPool.put(val) + interpreter.intPool.Put(val) return nil, nil } -func opJump(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - pos := stack.pop() +func opJump(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + pos := stack.Pop() if !contract.validJumpdest(pos) { nop := contract.GetOp(pos.Uint64()) return nil, fmt.Errorf("invalid jump destination (%v) %v", nop, pos) } *pc = pos.Uint64() - interpreter.intPool.put(pos) + interpreter.intPool.Put(pos) return nil, nil } -func opJumpi(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - pos, cond := stack.pop(), stack.pop() +func opJumpi(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + pos, cond := stack.Pop(), stack.Pop() if cond.Sign() != 0 { if !contract.validJumpdest(pos) { nop := contract.GetOp(pos.Uint64()) @@ -692,33 +693,33 @@ func opJumpi(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *pc++ } - interpreter.intPool.put(pos, cond) + interpreter.intPool.Put(pos, cond) return nil, nil } -func opJumpdest(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opJumpdest(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { return nil, nil } -func opPc(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(interpreter.intPool.get().SetUint64(*pc)) +func opPc(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(interpreter.intPool.Get().SetUint64(*pc)) return nil, nil } -func opMsize(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(interpreter.intPool.get().SetInt64(int64(memory.Len()))) +func opMsize(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(interpreter.intPool.Get().SetInt64(int64(memory.Len()))) return nil, nil } -func opGas(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(interpreter.intPool.get().SetUint64(contract.Gas)) +func opGas(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Push(interpreter.intPool.Get().SetUint64(contract.Gas)) return nil, nil } -func opCreate(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCreate(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { var ( - value = stack.pop() - offset, size = stack.pop(), stack.pop() + value = stack.Pop() + offset, size = stack.Pop(), stack.Pop() input = memory.Get(offset.Int64(), size.Int64()) gas = contract.Gas ) @@ -732,15 +733,15 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memor // homestead we must check for CodeStoreOutOfGasError (homestead only // rule) and treat as an error, if the ruleset is frontier we must // ignore this error and pretend the operation was successful. - if interpreter.evm.ChainConfig().IsHomestead(interpreter.evm.BlockNumber) && suberr == ErrCodeStoreOutOfGas { - stack.push(interpreter.intPool.getZero()) - } else if suberr != nil && suberr != ErrCodeStoreOutOfGas { - stack.push(interpreter.intPool.getZero()) + if interpreter.evm.ChainConfig().IsHomestead(interpreter.evm.BlockNumber) && suberr == vm.ErrCodeStoreOutOfGas { + stack.Push(interpreter.intPool.GetZero()) + } else if suberr != nil && suberr != vm.ErrCodeStoreOutOfGas { + stack.Push(interpreter.intPool.GetZero()) } else { - stack.push(addr.Big()) + stack.Push(addr.Big()) } contract.Gas += returnGas - interpreter.intPool.put(value, offset, size) + interpreter.intPool.Put(value, offset, size) if suberr == errExecutionReverted { return res, nil @@ -748,11 +749,11 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memor return nil, nil } -func opCreate2(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCreate2(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { var ( - endowment = stack.pop() - offset, size = stack.pop(), stack.pop() - salt = stack.pop() + endowment = stack.Pop() + offset, size = stack.Pop(), stack.Pop() + salt = stack.Pop() input = memory.Get(offset.Int64(), size.Int64()) gas = contract.Gas ) @@ -763,12 +764,12 @@ func opCreate2(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memo res, addr, returnGas, suberr := interpreter.evm.Create2(contract, input, gas, endowment, salt) // Push item on the stack based on the returned error. if suberr != nil { - stack.push(interpreter.intPool.getZero()) + stack.Push(interpreter.intPool.GetZero()) } else { - stack.push(addr.Big()) + stack.Push(addr.Big()) } contract.Gas += returnGas - interpreter.intPool.put(endowment, offset, size, salt) + interpreter.intPool.Put(endowment, offset, size, salt) if suberr == errExecutionReverted { return res, nil @@ -776,12 +777,12 @@ func opCreate2(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memo return nil, nil } -func opCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { // Pop gas. The actual gas in interpreter.evm.callGasTemp. - interpreter.intPool.put(stack.pop()) + interpreter.intPool.Put(stack.Pop()) gas := interpreter.evm.callGasTemp // Pop other call parameters. - addr, value, inOffset, inSize, retOffset, retSize := stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop() + addr, value, inOffset, inSize, retOffset, retSize := stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop() toAddr := common.BigToAddress(addr) value = math.U256(value) // Get the arguments from the memory. @@ -792,25 +793,25 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory } ret, returnGas, err := interpreter.evm.Call(contract, toAddr, args, gas, value) if err != nil { - stack.push(interpreter.intPool.getZero()) + stack.Push(interpreter.intPool.GetZero()) } else { - stack.push(interpreter.intPool.get().SetUint64(1)) + stack.Push(interpreter.intPool.Get().SetUint64(1)) } if err == nil || err == errExecutionReverted { memory.Set(retOffset.Uint64(), retSize.Uint64(), ret) } contract.Gas += returnGas - interpreter.intPool.put(addr, value, inOffset, inSize, retOffset, retSize) + interpreter.intPool.Put(addr, value, inOffset, inSize, retOffset, retSize) return ret, nil } -func opCallCode(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opCallCode(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { // Pop gas. The actual gas is in interpreter.evm.callGasTemp. - interpreter.intPool.put(stack.pop()) + interpreter.intPool.Put(stack.Pop()) gas := interpreter.evm.callGasTemp // Pop other call parameters. - addr, value, inOffset, inSize, retOffset, retSize := stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop() + addr, value, inOffset, inSize, retOffset, retSize := stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop() toAddr := common.BigToAddress(addr) value = math.U256(value) // Get arguments from the memory. @@ -821,92 +822,92 @@ func opCallCode(pc *uint64, interpreter *EVMInterpreter, contract *Contract, mem } ret, returnGas, err := interpreter.evm.CallCode(contract, toAddr, args, gas, value) if err != nil { - stack.push(interpreter.intPool.getZero()) + stack.Push(interpreter.intPool.GetZero()) } else { - stack.push(interpreter.intPool.get().SetUint64(1)) + stack.Push(interpreter.intPool.Get().SetUint64(1)) } if err == nil || err == errExecutionReverted { memory.Set(retOffset.Uint64(), retSize.Uint64(), ret) } contract.Gas += returnGas - interpreter.intPool.put(addr, value, inOffset, inSize, retOffset, retSize) + interpreter.intPool.Put(addr, value, inOffset, inSize, retOffset, retSize) return ret, nil } -func opDelegateCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opDelegateCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { // Pop gas. The actual gas is in interpreter.evm.callGasTemp. - interpreter.intPool.put(stack.pop()) + interpreter.intPool.Put(stack.Pop()) gas := interpreter.evm.callGasTemp // Pop other call parameters. - addr, inOffset, inSize, retOffset, retSize := stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop() + addr, inOffset, inSize, retOffset, retSize := stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop() toAddr := common.BigToAddress(addr) // Get arguments from the memory. args := memory.Get(inOffset.Int64(), inSize.Int64()) ret, returnGas, err := interpreter.evm.DelegateCall(contract, toAddr, args, gas) if err != nil { - stack.push(interpreter.intPool.getZero()) + stack.Push(interpreter.intPool.GetZero()) } else { - stack.push(interpreter.intPool.get().SetUint64(1)) + stack.Push(interpreter.intPool.Get().SetUint64(1)) } if err == nil || err == errExecutionReverted { memory.Set(retOffset.Uint64(), retSize.Uint64(), ret) } contract.Gas += returnGas - interpreter.intPool.put(addr, inOffset, inSize, retOffset, retSize) + interpreter.intPool.Put(addr, inOffset, inSize, retOffset, retSize) return ret, nil } -func opStaticCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opStaticCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { // Pop gas. The actual gas is in interpreter.evm.callGasTemp. - interpreter.intPool.put(stack.pop()) + interpreter.intPool.Put(stack.Pop()) gas := interpreter.evm.callGasTemp // Pop other call parameters. - addr, inOffset, inSize, retOffset, retSize := stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop() + addr, inOffset, inSize, retOffset, retSize := stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop(), stack.Pop() toAddr := common.BigToAddress(addr) // Get arguments from the memory. args := memory.Get(inOffset.Int64(), inSize.Int64()) ret, returnGas, err := interpreter.evm.StaticCall(contract, toAddr, args, gas) if err != nil { - stack.push(interpreter.intPool.getZero()) + stack.Push(interpreter.intPool.GetZero()) } else { - stack.push(interpreter.intPool.get().SetUint64(1)) + stack.Push(interpreter.intPool.Get().SetUint64(1)) } if err == nil || err == errExecutionReverted { memory.Set(retOffset.Uint64(), retSize.Uint64(), ret) } contract.Gas += returnGas - interpreter.intPool.put(addr, inOffset, inSize, retOffset, retSize) + interpreter.intPool.Put(addr, inOffset, inSize, retOffset, retSize) return ret, nil } -func opReturn(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - offset, size := stack.pop(), stack.pop() +func opReturn(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + offset, size := stack.Pop(), stack.Pop() ret := memory.GetPtr(offset.Int64(), size.Int64()) - interpreter.intPool.put(offset, size) + interpreter.intPool.Put(offset, size) return ret, nil } -func opRevert(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - offset, size := stack.pop(), stack.pop() +func opRevert(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + offset, size := stack.Pop(), stack.Pop() ret := memory.GetPtr(offset.Int64(), size.Int64()) - interpreter.intPool.put(offset, size) + interpreter.intPool.Put(offset, size) return ret, nil } -func opStop(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opStop(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { return nil, nil } -func opSuicide(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { +func opSuicide(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { balance := interpreter.evm.StateDB.GetBalance(contract.Address()) - interpreter.evm.StateDB.AddBalance(common.BigToAddress(stack.pop()), balance) + interpreter.evm.StateDB.AddBalance(common.BigToAddress(stack.Pop()), balance) interpreter.evm.StateDB.Suicide(contract.Address()) return nil, nil @@ -916,11 +917,11 @@ func opSuicide(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memo // make log instruction function func makeLog(size int) executionFunc { - return func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { + return func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { topics := make([]common.Hash, size) - mStart, mSize := stack.pop(), stack.pop() + mStart, mSize := stack.Pop(), stack.Pop() for i := 0; i < size; i++ { - topics[i] = common.BigToHash(stack.pop()) + topics[i] = common.BigToHash(stack.Pop()) } d := memory.Get(mStart.Int64(), mSize.Int64()) @@ -933,14 +934,14 @@ func makeLog(size int) executionFunc { BlockNumber: interpreter.evm.BlockNumber.Uint64(), }) - interpreter.intPool.put(mStart, mSize) + interpreter.intPool.Put(mStart, mSize) return nil, nil } } // make push instruction function func makePush(size uint64, pushByteSize int) executionFunc { - return func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { + return func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { codeLen := len(contract.Code) startMin := codeLen @@ -953,8 +954,8 @@ func makePush(size uint64, pushByteSize int) executionFunc { endMin = startMin + pushByteSize } - integer := interpreter.intPool.get() - stack.push(integer.SetBytes(common.RightPadBytes(contract.Code[startMin:endMin], pushByteSize))) + integer := interpreter.intPool.Get() + stack.Push(integer.SetBytes(common.RightPadBytes(contract.Code[startMin:endMin], pushByteSize))) *pc += size return nil, nil @@ -963,8 +964,8 @@ func makePush(size uint64, pushByteSize int) executionFunc { // make dup instruction function func makeDup(size int64) executionFunc { - return func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.dup(interpreter.intPool, int(size)) + return func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Dup(interpreter.intPool, int(size)) return nil, nil } } @@ -973,8 +974,8 @@ func makeDup(size int64) executionFunc { func makeSwap(size int64) executionFunc { // switch n + 1 otherwise n would be swapped with n size++ - return func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.swap(int(size)) + return func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) { + stack.Swap(int(size)) return nil, nil } } diff --git a/core/vm/instructions_test.go b/core/vm/evm/instructions_test.go index 04c03e1a6..9e677dde3 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/evm/instructions_test.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "bytes" @@ -22,6 +22,7 @@ import ( "testing" "github.com/dexon-foundation/dexon/common" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/params" ) @@ -32,37 +33,37 @@ type twoOperandTest struct { expected string } -func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error)) { +func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error)) { var ( env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) - stack = newstack() + stack = NewStack() pc = uint64(0) evmInterpreter = NewEVMInterpreter(env, env.vmConfig) ) env.interpreter = evmInterpreter - evmInterpreter.intPool = poolOfIntPools.get() + evmInterpreter.intPool = vm.PoolOfIntPools.Get() for i, test := range tests { x := new(big.Int).SetBytes(common.Hex2Bytes(test.x)) shift := new(big.Int).SetBytes(common.Hex2Bytes(test.y)) expected := new(big.Int).SetBytes(common.Hex2Bytes(test.expected)) - stack.push(x) - stack.push(shift) + stack.Push(x) + stack.Push(shift) opFn(&pc, evmInterpreter, nil, nil, stack) - actual := stack.pop() + actual := stack.Pop() if actual.Cmp(expected) != 0 { t.Errorf("Testcase %d, expected %v, got %v", i, expected, actual) } // Check pool usage // 1.pool is not allowed to contain anything on the stack // 2.pool is not allowed to contain the same pointers twice - if evmInterpreter.intPool.pool.len() > 0 { + if evmInterpreter.intPool.Pool.Len() > 0 { poolvals := make(map[*big.Int]struct{}) poolvals[actual] = struct{}{} - for evmInterpreter.intPool.pool.len() > 0 { - key := evmInterpreter.intPool.get() + for evmInterpreter.intPool.Pool.Len() > 0 { + key := evmInterpreter.intPool.Get() if _, exist := poolvals[key]; exist { t.Errorf("Testcase %d, pool contains double-entry", i) } @@ -70,18 +71,18 @@ func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64 } } } - poolOfIntPools.put(evmInterpreter.intPool) + vm.PoolOfIntPools.Put(evmInterpreter.intPool) } func TestByteOp(t *testing.T) { var ( env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) - stack = newstack() + stack = NewStack() evmInterpreter = NewEVMInterpreter(env, env.vmConfig) ) env.interpreter = evmInterpreter - evmInterpreter.intPool = poolOfIntPools.get() + evmInterpreter.intPool = vm.PoolOfIntPools.Get() tests := []struct { v string th uint64 @@ -100,15 +101,15 @@ func TestByteOp(t *testing.T) { for _, test := range tests { val := new(big.Int).SetBytes(common.Hex2Bytes(test.v)) th := new(big.Int).SetUint64(test.th) - stack.push(val) - stack.push(th) + stack.Push(val) + stack.Push(th) opByte(&pc, evmInterpreter, nil, nil, stack) - actual := stack.pop() + actual := stack.Pop() if actual.Cmp(test.expected) != 0 { t.Fatalf("Expected [%v] %v:th byte to be %v, was %v.", test.v, test.th, test.expected, actual) } } - poolOfIntPools.put(evmInterpreter.intPool) + vm.PoolOfIntPools.Put(evmInterpreter.intPool) } func TestSHL(t *testing.T) { @@ -208,15 +209,15 @@ func TestSLT(t *testing.T) { testTwoOperandOp(t, tests, opSlt) } -func opBenchmark(bench *testing.B, op func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error), args ...string) { +func opBenchmark(bench *testing.B, op func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error), args ...string) { var ( env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) - stack = newstack() + stack = NewStack() evmInterpreter = NewEVMInterpreter(env, env.vmConfig) ) env.interpreter = evmInterpreter - evmInterpreter.intPool = poolOfIntPools.get() + evmInterpreter.intPool = vm.PoolOfIntPools.Get() // convert args byteArgs := make([][]byte, len(args)) for i, arg := range args { @@ -227,12 +228,12 @@ func opBenchmark(bench *testing.B, op func(pc *uint64, interpreter *EVMInterpret for i := 0; i < bench.N; i++ { for _, arg := range byteArgs { a := new(big.Int).SetBytes(arg) - stack.push(a) + stack.Push(a) } op(&pc, evmInterpreter, nil, nil, stack) - stack.pop() + stack.Pop() } - poolOfIntPools.put(evmInterpreter.intPool) + vm.PoolOfIntPools.Put(evmInterpreter.intPool) } func BenchmarkOpAdd64(b *testing.B) { @@ -446,39 +447,39 @@ func BenchmarkOpIsZero(b *testing.B) { func TestOpMstore(t *testing.T) { var ( env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) - stack = newstack() - mem = NewMemory() + stack = NewStack() + mem = vm.NewMemory() evmInterpreter = NewEVMInterpreter(env, env.vmConfig) ) env.interpreter = evmInterpreter - evmInterpreter.intPool = poolOfIntPools.get() + evmInterpreter.intPool = vm.PoolOfIntPools.Get() mem.Resize(64) pc := uint64(0) v := "abcdef00000000000000abba000000000deaf000000c0de00100000000133700" - stack.pushN(new(big.Int).SetBytes(common.Hex2Bytes(v)), big.NewInt(0)) + stack.PushN(new(big.Int).SetBytes(common.Hex2Bytes(v)), big.NewInt(0)) opMstore(&pc, evmInterpreter, nil, mem, stack) if got := common.Bytes2Hex(mem.Get(0, 32)); got != v { t.Fatalf("Mstore fail, got %v, expected %v", got, v) } - stack.pushN(big.NewInt(0x1), big.NewInt(0)) + stack.PushN(big.NewInt(0x1), big.NewInt(0)) opMstore(&pc, evmInterpreter, nil, mem, stack) if common.Bytes2Hex(mem.Get(0, 32)) != "0000000000000000000000000000000000000000000000000000000000000001" { t.Fatalf("Mstore failed to overwrite previous value") } - poolOfIntPools.put(evmInterpreter.intPool) + vm.PoolOfIntPools.Put(evmInterpreter.intPool) } func BenchmarkOpMstore(bench *testing.B) { var ( env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) - stack = newstack() - mem = NewMemory() + stack = NewStack() + mem = vm.NewMemory() evmInterpreter = NewEVMInterpreter(env, env.vmConfig) ) env.interpreter = evmInterpreter - evmInterpreter.intPool = poolOfIntPools.get() + evmInterpreter.intPool = vm.PoolOfIntPools.Get() mem.Resize(64) pc := uint64(0) memStart := big.NewInt(0) @@ -486,31 +487,31 @@ func BenchmarkOpMstore(bench *testing.B) { bench.ResetTimer() for i := 0; i < bench.N; i++ { - stack.pushN(value, memStart) + stack.PushN(value, memStart) opMstore(&pc, evmInterpreter, nil, mem, stack) } - poolOfIntPools.put(evmInterpreter.intPool) + vm.PoolOfIntPools.Put(evmInterpreter.intPool) } func BenchmarkOpSHA3(bench *testing.B) { var ( env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) - stack = newstack() - mem = NewMemory() + stack = NewStack() + mem = vm.NewMemory() evmInterpreter = NewEVMInterpreter(env, env.vmConfig) ) env.interpreter = evmInterpreter - evmInterpreter.intPool = poolOfIntPools.get() + evmInterpreter.intPool = vm.PoolOfIntPools.Get() mem.Resize(32) pc := uint64(0) start := big.NewInt(0) bench.ResetTimer() for i := 0; i < bench.N; i++ { - stack.pushN(big.NewInt(32), start) + stack.PushN(big.NewInt(32), start) opSha3(&pc, evmInterpreter, nil, mem, stack) } - poolOfIntPools.put(evmInterpreter.intPool) + vm.PoolOfIntPools.Put(evmInterpreter.intPool) } func TestCreate2Addreses(t *testing.T) { @@ -572,11 +573,11 @@ func TestCreate2Addreses(t *testing.T) { codeHash := crypto.Keccak256(code) address := crypto.CreateAddress2(origin, salt, codeHash) /* - stack := newstack() + stack := NewStack() // salt, but we don't need that for this test - stack.push(big.NewInt(int64(len(code)))) //size - stack.push(big.NewInt(0)) // memstart - stack.push(big.NewInt(0)) // value + stack.Push(big.NewInt(int64(len(code)))) //size + stack.Push(big.NewInt(0)) // memstart + stack.Push(big.NewInt(0)) // value gas, _ := gasCreate2(params.GasTable{}, nil, nil, stack, nil, 0) fmt.Printf("Example %d\n* address `0x%x`\n* salt `0x%x`\n* init_code `0x%x`\n* gas (assuming no mem expansion): `%v`\n* result: `%s`\n\n", i,origin, salt, code, gas, address.String()) */ diff --git a/core/vm/interface.go b/core/vm/evm/interface.go index 3e86a4ff2..20e5f34a9 100644 --- a/core/vm/interface.go +++ b/core/vm/evm/interface.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "math/big" diff --git a/core/vm/interpreter.go b/core/vm/evm/interpreter.go index ffe5ff626..ca3ddd05a 100644 --- a/core/vm/interpreter.go +++ b/core/vm/evm/interpreter.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "fmt" @@ -23,6 +23,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/common/math" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/params" ) @@ -87,7 +88,7 @@ type EVMInterpreter struct { cfg Config gasTable params.GasTable - intPool *intPool + intPool *vm.IntPool hasher keccakState // Keccak256 hasher instance shared across opcodes hasherBuf common.Hash // Keccak256 hasher result array shared aross opcodes @@ -121,7 +122,7 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter { } } -func (in *EVMInterpreter) enforceRestrictions(op OpCode, operation operation, stack *Stack) error { +func (in *EVMInterpreter) enforceRestrictions(op OpCode, operation operation, stack *vm.Stack) error { if in.evm.chainRules.IsByzantium { if in.readOnly { // If the interpreter is operating in readonly mode, make sure no @@ -145,9 +146,9 @@ func (in *EVMInterpreter) enforceRestrictions(op OpCode, operation operation, st // errExecutionReverted which means revert-and-keep-gas-left. func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (ret []byte, err error) { if in.intPool == nil { - in.intPool = poolOfIntPools.get() + in.intPool = vm.PoolOfIntPools.Get() defer func() { - poolOfIntPools.put(in.intPool) + vm.PoolOfIntPools.Put(in.intPool) in.intPool = nil }() } @@ -173,9 +174,9 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( } var ( - op OpCode // current opcode - mem = NewMemory() // bound memory - stack = newstack() // local stack + op OpCode // current opcode + mem = vm.NewMemory() // bound memory + stack = NewStack() // local stack // For optimisation reason we're using uint64 as the program counter. // It's theoretically possible to go above 2^64. The YP defines the PC // to be uint256. Practically much less so feasible. @@ -190,8 +191,8 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( // Reclaim the stack as an int pool when the execution stops defer func() { - in.intPool.put(stack.data...) - recyclestack(stack) + in.intPool.Put(stack.Data...) + Recyclestack(stack) }() if in.cfg.Debug { @@ -234,13 +235,13 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( // calculate the new memory size and expand the memory to fit // the operation if operation.memorySize != nil { - memSize, overflow := bigUint64(operation.memorySize(stack)) + memSize, overflow := vm.BigUint64(operation.memorySize(stack)) if overflow { return nil, errGasUintOverflow } // memory is expanded in words of 32 bytes. Gas // is also calculated in words. - if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + if memorySize, overflow = math.SafeMul(vm.ToWordSize(memSize), 32); overflow { return nil, errGasUintOverflow } } @@ -248,7 +249,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( // cost is explicitly set so that the capture state defer method can get the proper cost cost, err = operation.gasCost(in.gasTable, in.evm, contract, stack, mem, memorySize) if err != nil || !contract.UseGas(cost) { - return nil, ErrOutOfGas + return nil, vm.ErrOutOfGas } if memorySize > 0 { mem.Resize(memorySize) @@ -263,8 +264,8 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( res, err := operation.execute(&pc, in, contract, mem, stack) // verifyPool is a build flag. Pool verification makes sure the integrity // of the integer pool by comparing values to a default value. - if verifyPool { - verifyIntegerPool(in.intPool) + if vm.VerifyPool { + vm.VerifyIntegerPool(in.intPool) } // if the operation clears the return data (e.g. it has returning data) // set the last return to the result of the operation. diff --git a/core/vm/jump_table.go b/core/vm/evm/jump_table.go index 608e34419..da2f50c5a 100644 --- a/core/vm/jump_table.go +++ b/core/vm/evm/jump_table.go @@ -14,20 +14,20 @@ // 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 +package evm import ( "errors" "math/big" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/params" ) type ( - executionFunc func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) - gasFunc func(params.GasTable, *EVM, *Contract, *Stack, *Memory, uint64) (uint64, error) // last parameter is the requested memory size as a uint64 - stackValidationFunc func(*Stack) error - memorySizeFunc func(*Stack) *big.Int + executionFunc func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *vm.Memory, stack *vm.Stack) ([]byte, error) + gasFunc func(params.GasTable, *EVM, *Contract, *vm.Stack, *vm.Memory, uint64) (uint64, error) // last parameter is the requested memory size as a uint64 + memorySizeFunc func(*vm.Stack) *big.Int ) var errGasUintOverflow = errors.New("gas uint64 overflow") @@ -38,7 +38,7 @@ type operation struct { // gasCost is the gas function and returns the gas required for execution gasCost gasFunc // validateStack validates the stack (size) for the operation - validateStack stackValidationFunc + validateStack vm.StackValidationFunc // memorySize returns the memory size required for the operation memorySize memorySizeFunc @@ -65,31 +65,31 @@ func newConstantinopleInstructionSet() [256]operation { instructionSet[SHL] = operation{ execute: opSHL, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, } instructionSet[SHR] = operation{ execute: opSHR, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, } instructionSet[SAR] = operation{ execute: opSAR, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, } instructionSet[EXTCODEHASH] = operation{ execute: opExtCodeHash, gasCost: gasExtCodeHash, - validateStack: makeStackFunc(1, 1), + validateStack: vm.MakeStackFunc(1, 1), valid: true, } instructionSet[CREATE2] = operation{ execute: opCreate2, gasCost: gasCreate2, - validateStack: makeStackFunc(4, 1), + validateStack: vm.MakeStackFunc(4, 1), memorySize: memoryCreate2, valid: true, writes: true, @@ -106,7 +106,7 @@ func newByzantiumInstructionSet() [256]operation { instructionSet[STATICCALL] = operation{ execute: opStaticCall, gasCost: gasStaticCall, - validateStack: makeStackFunc(6, 1), + validateStack: vm.MakeStackFunc(6, 1), memorySize: memoryStaticCall, valid: true, returns: true, @@ -114,20 +114,20 @@ func newByzantiumInstructionSet() [256]operation { instructionSet[RETURNDATASIZE] = operation{ execute: opReturnDataSize, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, } instructionSet[RETURNDATACOPY] = operation{ execute: opReturnDataCopy, gasCost: gasReturnDataCopy, - validateStack: makeStackFunc(3, 0), + validateStack: vm.MakeStackFunc(3, 0), memorySize: memoryReturnDataCopy, valid: true, } instructionSet[REVERT] = operation{ execute: opRevert, gasCost: gasRevert, - validateStack: makeStackFunc(2, 0), + validateStack: vm.MakeStackFunc(2, 0), memorySize: memoryRevert, valid: true, reverts: true, @@ -143,7 +143,7 @@ func newHomesteadInstructionSet() [256]operation { instructionSet[DELEGATECALL] = operation{ execute: opDelegateCall, gasCost: gasDelegateCall, - validateStack: makeStackFunc(6, 1), + validateStack: vm.MakeStackFunc(6, 1), memorySize: memoryDelegateCall, valid: true, returns: true, @@ -158,289 +158,289 @@ func newFrontierInstructionSet() [256]operation { STOP: { execute: opStop, gasCost: constGasFunc(0), - validateStack: makeStackFunc(0, 0), + validateStack: vm.MakeStackFunc(0, 0), halts: true, valid: true, }, ADD: { execute: opAdd, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, MUL: { execute: opMul, gasCost: constGasFunc(GasFastStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, SUB: { execute: opSub, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, DIV: { execute: opDiv, gasCost: constGasFunc(GasFastStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, SDIV: { execute: opSdiv, gasCost: constGasFunc(GasFastStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, MOD: { execute: opMod, gasCost: constGasFunc(GasFastStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, SMOD: { execute: opSmod, gasCost: constGasFunc(GasFastStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, ADDMOD: { execute: opAddmod, gasCost: constGasFunc(GasMidStep), - validateStack: makeStackFunc(3, 1), + validateStack: vm.MakeStackFunc(3, 1), valid: true, }, MULMOD: { execute: opMulmod, gasCost: constGasFunc(GasMidStep), - validateStack: makeStackFunc(3, 1), + validateStack: vm.MakeStackFunc(3, 1), valid: true, }, EXP: { execute: opExp, gasCost: gasExp, - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, SIGNEXTEND: { execute: opSignExtend, gasCost: constGasFunc(GasFastStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, LT: { execute: opLt, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, GT: { execute: opGt, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, SLT: { execute: opSlt, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, SGT: { execute: opSgt, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, EQ: { execute: opEq, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, ISZERO: { execute: opIszero, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(1, 1), + validateStack: vm.MakeStackFunc(1, 1), valid: true, }, AND: { execute: opAnd, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, XOR: { execute: opXor, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, OR: { execute: opOr, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, NOT: { execute: opNot, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(1, 1), + validateStack: vm.MakeStackFunc(1, 1), valid: true, }, BYTE: { execute: opByte, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), valid: true, }, SHA3: { execute: opSha3, gasCost: gasSha3, - validateStack: makeStackFunc(2, 1), + validateStack: vm.MakeStackFunc(2, 1), memorySize: memorySha3, valid: true, }, RAND: { execute: opRand, gasCost: constGasFunc(params.RandGas), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, ADDRESS: { execute: opAddress, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, BALANCE: { execute: opBalance, gasCost: gasBalance, - validateStack: makeStackFunc(1, 1), + validateStack: vm.MakeStackFunc(1, 1), valid: true, }, ORIGIN: { execute: opOrigin, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, CALLER: { execute: opCaller, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, CALLVALUE: { execute: opCallValue, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, CALLDATALOAD: { execute: opCallDataLoad, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(1, 1), + validateStack: vm.MakeStackFunc(1, 1), valid: true, }, CALLDATASIZE: { execute: opCallDataSize, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, CALLDATACOPY: { execute: opCallDataCopy, gasCost: gasCallDataCopy, - validateStack: makeStackFunc(3, 0), + validateStack: vm.MakeStackFunc(3, 0), memorySize: memoryCallDataCopy, valid: true, }, CODESIZE: { execute: opCodeSize, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, CODECOPY: { execute: opCodeCopy, gasCost: gasCodeCopy, - validateStack: makeStackFunc(3, 0), + validateStack: vm.MakeStackFunc(3, 0), memorySize: memoryCodeCopy, valid: true, }, GASPRICE: { execute: opGasprice, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, EXTCODESIZE: { execute: opExtCodeSize, gasCost: gasExtCodeSize, - validateStack: makeStackFunc(1, 1), + validateStack: vm.MakeStackFunc(1, 1), valid: true, }, EXTCODECOPY: { execute: opExtCodeCopy, gasCost: gasExtCodeCopy, - validateStack: makeStackFunc(4, 0), + validateStack: vm.MakeStackFunc(4, 0), memorySize: memoryExtCodeCopy, valid: true, }, BLOCKHASH: { execute: opBlockhash, gasCost: constGasFunc(GasExtStep), - validateStack: makeStackFunc(1, 1), + validateStack: vm.MakeStackFunc(1, 1), valid: true, }, COINBASE: { execute: opCoinbase, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, TIMESTAMP: { execute: opTimestamp, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, NUMBER: { execute: opNumber, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, DIFFICULTY: { execute: opDifficulty, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, GASLIMIT: { execute: opGasLimit, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, POP: { execute: opPop, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(1, 0), + validateStack: vm.MakeStackFunc(1, 0), valid: true, }, MLOAD: { execute: opMload, gasCost: gasMLoad, - validateStack: makeStackFunc(1, 1), + validateStack: vm.MakeStackFunc(1, 1), memorySize: memoryMLoad, valid: true, }, MSTORE: { execute: opMstore, gasCost: gasMStore, - validateStack: makeStackFunc(2, 0), + validateStack: vm.MakeStackFunc(2, 0), memorySize: memoryMStore, valid: true, }, @@ -448,449 +448,449 @@ func newFrontierInstructionSet() [256]operation { execute: opMstore8, gasCost: gasMStore8, memorySize: memoryMStore8, - validateStack: makeStackFunc(2, 0), + validateStack: vm.MakeStackFunc(2, 0), valid: true, }, SLOAD: { execute: opSload, gasCost: gasSLoad, - validateStack: makeStackFunc(1, 1), + validateStack: vm.MakeStackFunc(1, 1), valid: true, }, SSTORE: { execute: opSstore, gasCost: gasSStore, - validateStack: makeStackFunc(2, 0), + validateStack: vm.MakeStackFunc(2, 0), valid: true, writes: true, }, JUMP: { execute: opJump, gasCost: constGasFunc(GasMidStep), - validateStack: makeStackFunc(1, 0), + validateStack: vm.MakeStackFunc(1, 0), jumps: true, valid: true, }, JUMPI: { execute: opJumpi, gasCost: constGasFunc(GasSlowStep), - validateStack: makeStackFunc(2, 0), + validateStack: vm.MakeStackFunc(2, 0), jumps: true, valid: true, }, PC: { execute: opPc, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, MSIZE: { execute: opMsize, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, GAS: { execute: opGas, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, JUMPDEST: { execute: opJumpdest, gasCost: constGasFunc(params.JumpdestGas), - validateStack: makeStackFunc(0, 0), + validateStack: vm.MakeStackFunc(0, 0), valid: true, }, PUSH1: { execute: makePush(1, 1), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH2: { execute: makePush(2, 2), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH3: { execute: makePush(3, 3), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH4: { execute: makePush(4, 4), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH5: { execute: makePush(5, 5), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH6: { execute: makePush(6, 6), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH7: { execute: makePush(7, 7), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH8: { execute: makePush(8, 8), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH9: { execute: makePush(9, 9), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH10: { execute: makePush(10, 10), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH11: { execute: makePush(11, 11), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH12: { execute: makePush(12, 12), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH13: { execute: makePush(13, 13), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH14: { execute: makePush(14, 14), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH15: { execute: makePush(15, 15), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH16: { execute: makePush(16, 16), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH17: { execute: makePush(17, 17), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH18: { execute: makePush(18, 18), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH19: { execute: makePush(19, 19), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH20: { execute: makePush(20, 20), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH21: { execute: makePush(21, 21), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH22: { execute: makePush(22, 22), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH23: { execute: makePush(23, 23), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH24: { execute: makePush(24, 24), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH25: { execute: makePush(25, 25), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH26: { execute: makePush(26, 26), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH27: { execute: makePush(27, 27), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH28: { execute: makePush(28, 28), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH29: { execute: makePush(29, 29), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH30: { execute: makePush(30, 30), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH31: { execute: makePush(31, 31), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, PUSH32: { execute: makePush(32, 32), gasCost: gasPush, - validateStack: makeStackFunc(0, 1), + validateStack: vm.MakeStackFunc(0, 1), valid: true, }, DUP1: { execute: makeDup(1), gasCost: gasDup, - validateStack: makeDupStackFunc(1), + validateStack: vm.MakeDupStackFunc(1), valid: true, }, DUP2: { execute: makeDup(2), gasCost: gasDup, - validateStack: makeDupStackFunc(2), + validateStack: vm.MakeDupStackFunc(2), valid: true, }, DUP3: { execute: makeDup(3), gasCost: gasDup, - validateStack: makeDupStackFunc(3), + validateStack: vm.MakeDupStackFunc(3), valid: true, }, DUP4: { execute: makeDup(4), gasCost: gasDup, - validateStack: makeDupStackFunc(4), + validateStack: vm.MakeDupStackFunc(4), valid: true, }, DUP5: { execute: makeDup(5), gasCost: gasDup, - validateStack: makeDupStackFunc(5), + validateStack: vm.MakeDupStackFunc(5), valid: true, }, DUP6: { execute: makeDup(6), gasCost: gasDup, - validateStack: makeDupStackFunc(6), + validateStack: vm.MakeDupStackFunc(6), valid: true, }, DUP7: { execute: makeDup(7), gasCost: gasDup, - validateStack: makeDupStackFunc(7), + validateStack: vm.MakeDupStackFunc(7), valid: true, }, DUP8: { execute: makeDup(8), gasCost: gasDup, - validateStack: makeDupStackFunc(8), + validateStack: vm.MakeDupStackFunc(8), valid: true, }, DUP9: { execute: makeDup(9), gasCost: gasDup, - validateStack: makeDupStackFunc(9), + validateStack: vm.MakeDupStackFunc(9), valid: true, }, DUP10: { execute: makeDup(10), gasCost: gasDup, - validateStack: makeDupStackFunc(10), + validateStack: vm.MakeDupStackFunc(10), valid: true, }, DUP11: { execute: makeDup(11), gasCost: gasDup, - validateStack: makeDupStackFunc(11), + validateStack: vm.MakeDupStackFunc(11), valid: true, }, DUP12: { execute: makeDup(12), gasCost: gasDup, - validateStack: makeDupStackFunc(12), + validateStack: vm.MakeDupStackFunc(12), valid: true, }, DUP13: { execute: makeDup(13), gasCost: gasDup, - validateStack: makeDupStackFunc(13), + validateStack: vm.MakeDupStackFunc(13), valid: true, }, DUP14: { execute: makeDup(14), gasCost: gasDup, - validateStack: makeDupStackFunc(14), + validateStack: vm.MakeDupStackFunc(14), valid: true, }, DUP15: { execute: makeDup(15), gasCost: gasDup, - validateStack: makeDupStackFunc(15), + validateStack: vm.MakeDupStackFunc(15), valid: true, }, DUP16: { execute: makeDup(16), gasCost: gasDup, - validateStack: makeDupStackFunc(16), + validateStack: vm.MakeDupStackFunc(16), valid: true, }, SWAP1: { execute: makeSwap(1), gasCost: gasSwap, - validateStack: makeSwapStackFunc(2), + validateStack: vm.MakeSwapStackFunc(2), valid: true, }, SWAP2: { execute: makeSwap(2), gasCost: gasSwap, - validateStack: makeSwapStackFunc(3), + validateStack: vm.MakeSwapStackFunc(3), valid: true, }, SWAP3: { execute: makeSwap(3), gasCost: gasSwap, - validateStack: makeSwapStackFunc(4), + validateStack: vm.MakeSwapStackFunc(4), valid: true, }, SWAP4: { execute: makeSwap(4), gasCost: gasSwap, - validateStack: makeSwapStackFunc(5), + validateStack: vm.MakeSwapStackFunc(5), valid: true, }, SWAP5: { execute: makeSwap(5), gasCost: gasSwap, - validateStack: makeSwapStackFunc(6), + validateStack: vm.MakeSwapStackFunc(6), valid: true, }, SWAP6: { execute: makeSwap(6), gasCost: gasSwap, - validateStack: makeSwapStackFunc(7), + validateStack: vm.MakeSwapStackFunc(7), valid: true, }, SWAP7: { execute: makeSwap(7), gasCost: gasSwap, - validateStack: makeSwapStackFunc(8), + validateStack: vm.MakeSwapStackFunc(8), valid: true, }, SWAP8: { execute: makeSwap(8), gasCost: gasSwap, - validateStack: makeSwapStackFunc(9), + validateStack: vm.MakeSwapStackFunc(9), valid: true, }, SWAP9: { execute: makeSwap(9), gasCost: gasSwap, - validateStack: makeSwapStackFunc(10), + validateStack: vm.MakeSwapStackFunc(10), valid: true, }, SWAP10: { execute: makeSwap(10), gasCost: gasSwap, - validateStack: makeSwapStackFunc(11), + validateStack: vm.MakeSwapStackFunc(11), valid: true, }, SWAP11: { execute: makeSwap(11), gasCost: gasSwap, - validateStack: makeSwapStackFunc(12), + validateStack: vm.MakeSwapStackFunc(12), valid: true, }, SWAP12: { execute: makeSwap(12), gasCost: gasSwap, - validateStack: makeSwapStackFunc(13), + validateStack: vm.MakeSwapStackFunc(13), valid: true, }, SWAP13: { execute: makeSwap(13), gasCost: gasSwap, - validateStack: makeSwapStackFunc(14), + validateStack: vm.MakeSwapStackFunc(14), valid: true, }, SWAP14: { execute: makeSwap(14), gasCost: gasSwap, - validateStack: makeSwapStackFunc(15), + validateStack: vm.MakeSwapStackFunc(15), valid: true, }, SWAP15: { execute: makeSwap(15), gasCost: gasSwap, - validateStack: makeSwapStackFunc(16), + validateStack: vm.MakeSwapStackFunc(16), valid: true, }, SWAP16: { execute: makeSwap(16), gasCost: gasSwap, - validateStack: makeSwapStackFunc(17), + validateStack: vm.MakeSwapStackFunc(17), valid: true, }, LOG0: { execute: makeLog(0), gasCost: makeGasLog(0), - validateStack: makeStackFunc(2, 0), + validateStack: vm.MakeStackFunc(2, 0), memorySize: memoryLog, valid: true, writes: true, @@ -898,7 +898,7 @@ func newFrontierInstructionSet() [256]operation { LOG1: { execute: makeLog(1), gasCost: makeGasLog(1), - validateStack: makeStackFunc(3, 0), + validateStack: vm.MakeStackFunc(3, 0), memorySize: memoryLog, valid: true, writes: true, @@ -906,7 +906,7 @@ func newFrontierInstructionSet() [256]operation { LOG2: { execute: makeLog(2), gasCost: makeGasLog(2), - validateStack: makeStackFunc(4, 0), + validateStack: vm.MakeStackFunc(4, 0), memorySize: memoryLog, valid: true, writes: true, @@ -914,7 +914,7 @@ func newFrontierInstructionSet() [256]operation { LOG3: { execute: makeLog(3), gasCost: makeGasLog(3), - validateStack: makeStackFunc(5, 0), + validateStack: vm.MakeStackFunc(5, 0), memorySize: memoryLog, valid: true, writes: true, @@ -922,7 +922,7 @@ func newFrontierInstructionSet() [256]operation { LOG4: { execute: makeLog(4), gasCost: makeGasLog(4), - validateStack: makeStackFunc(6, 0), + validateStack: vm.MakeStackFunc(6, 0), memorySize: memoryLog, valid: true, writes: true, @@ -930,7 +930,7 @@ func newFrontierInstructionSet() [256]operation { CREATE: { execute: opCreate, gasCost: gasCreate, - validateStack: makeStackFunc(3, 1), + validateStack: vm.MakeStackFunc(3, 1), memorySize: memoryCreate, valid: true, writes: true, @@ -939,7 +939,7 @@ func newFrontierInstructionSet() [256]operation { CALL: { execute: opCall, gasCost: gasCall, - validateStack: makeStackFunc(7, 1), + validateStack: vm.MakeStackFunc(7, 1), memorySize: memoryCall, valid: true, returns: true, @@ -947,7 +947,7 @@ func newFrontierInstructionSet() [256]operation { CALLCODE: { execute: opCallCode, gasCost: gasCallCode, - validateStack: makeStackFunc(7, 1), + validateStack: vm.MakeStackFunc(7, 1), memorySize: memoryCall, valid: true, returns: true, @@ -955,7 +955,7 @@ func newFrontierInstructionSet() [256]operation { RETURN: { execute: opReturn, gasCost: gasReturn, - validateStack: makeStackFunc(2, 0), + validateStack: vm.MakeStackFunc(2, 0), memorySize: memoryReturn, halts: true, valid: true, @@ -963,7 +963,7 @@ func newFrontierInstructionSet() [256]operation { SELFDESTRUCT: { execute: opSuicide, gasCost: gasSuicide, - validateStack: makeStackFunc(1, 0), + validateStack: vm.MakeStackFunc(1, 0), halts: true, valid: true, writes: true, diff --git a/core/vm/logger.go b/core/vm/evm/logger.go index fd36c26d5..f51943b14 100644 --- a/core/vm/logger.go +++ b/core/vm/evm/logger.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "encoding/hex" @@ -27,6 +27,7 @@ import ( "github.com/dexon-foundation/dexon/common/hexutil" "github.com/dexon-foundation/dexon/common/math" "github.com/dexon-foundation/dexon/core/types" + "github.com/dexon-foundation/dexon/core/vm" ) // Storage represents a contract's storage. @@ -99,8 +100,8 @@ func (s *StructLog) ErrorString() string { // if you need to retain them beyond the current call. type Tracer interface { CaptureStart(from common.Address, to common.Address, call bool, input []byte, gas uint64, value *big.Int) error - CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error - CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error + CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *Contract, depth int, err error) error + CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *Contract, depth int, err error) error CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error } @@ -137,10 +138,10 @@ func (l *StructLogger) CaptureStart(from common.Address, to common.Address, crea // CaptureState logs a new structured log message and pushes it out to the environment // // CaptureState also tracks SSTORE ops to track dirty values. -func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error { +func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *Contract, depth int, err error) error { // check if already accumulated the specified number of logs if l.cfg.Limit != 0 && l.cfg.Limit <= len(l.logs) { - return ErrTraceLimitReached + return vm.ErrTraceLimitReached } // initialise new changed values storage container for this contract @@ -151,10 +152,10 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui // capture SSTORE opcodes and determine the changed value and store // it in the local storage container. - if op == SSTORE && stack.len() >= 2 { + if op == SSTORE && stack.Len() >= 2 { var ( - value = common.BigToHash(stack.data[stack.len()-2]) - address = common.BigToHash(stack.data[stack.len()-1]) + value = common.BigToHash(stack.Data[stack.Len()-2]) + address = common.BigToHash(stack.Data[stack.Len()-1]) ) l.changedValues[contract.Address()][address] = value } @@ -167,8 +168,8 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui // Copy a snapshot of the current stack state to a new buffer var stck []*big.Int if !l.cfg.DisableStack { - stck = make([]*big.Int, len(stack.Data())) - for i, item := range stack.Data() { + stck = make([]*big.Int, len(stack.Data)) + for i, item := range stack.Data { stck[i] = new(big.Int).Set(item) } } @@ -186,7 +187,7 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui // CaptureFault implements the Tracer interface to trace an execution fault // while running an opcode. -func (l *StructLogger) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error { +func (l *StructLogger) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *Contract, depth int, err error) error { return nil } diff --git a/core/vm/logger_json.go b/core/vm/evm/logger_json.go index dedc1476e..05b53437c 100644 --- a/core/vm/logger_json.go +++ b/core/vm/evm/logger_json.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. -package vm +package evm import ( "encoding/json" @@ -24,6 +24,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/common/math" + "github.com/dexon-foundation/dexon/core/vm" ) type JSONLogger struct { @@ -42,7 +43,7 @@ func (l *JSONLogger) CaptureStart(from common.Address, to common.Address, create } // CaptureState outputs state information on the logger. -func (l *JSONLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error { +func (l *JSONLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *Contract, depth int, err error) error { log := StructLog{ Pc: pc, Op: op, @@ -58,13 +59,13 @@ func (l *JSONLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint log.Memory = memory.Data() } if !l.cfg.DisableStack { - log.Stack = stack.Data() + log.Stack = stack.Data } return l.encoder.Encode(log) } // CaptureFault outputs state information on the logger. -func (l *JSONLogger) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error { +func (l *JSONLogger) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *Contract, depth int, err error) error { return nil } diff --git a/core/vm/logger_test.go b/core/vm/evm/logger_test.go index 560893c50..a8e0e9044 100644 --- a/core/vm/logger_test.go +++ b/core/vm/evm/logger_test.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "math/big" @@ -22,6 +22,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/state" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/params" ) @@ -52,12 +53,12 @@ func TestStoreCapture(t *testing.T) { var ( env = NewEVM(Context{}, &dummyStatedb{}, params.TestChainConfig, Config{}) logger = NewStructLogger(nil) - mem = NewMemory() - stack = newstack() + mem = vm.NewMemory() + stack = NewStack() contract = NewContract(&dummyContractRef{}, &dummyContractRef{}, new(big.Int), 0) ) - stack.push(big.NewInt(1)) - stack.push(big.NewInt(0)) + stack.Push(big.NewInt(1)) + stack.Push(big.NewInt(0)) var index common.Hash logger.CaptureState(env, 0, SSTORE, 0, 0, mem, stack, contract, 0, nil) if len(logger.changedValues[contract.Address()]) == 0 { diff --git a/core/vm/evm/memory_table.go b/core/vm/evm/memory_table.go new file mode 100644 index 000000000..c27e95a4a --- /dev/null +++ b/core/vm/evm/memory_table.go @@ -0,0 +1,98 @@ +// 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 evm + +import ( + "math/big" + + "github.com/dexon-foundation/dexon/common/math" + "github.com/dexon-foundation/dexon/core/vm" +) + +func memorySha3(stack *vm.Stack) *big.Int { + return vm.CalcMemSize(stack.Back(0), stack.Back(1)) +} + +func memoryCallDataCopy(stack *vm.Stack) *big.Int { + return vm.CalcMemSize(stack.Back(0), stack.Back(2)) +} + +func memoryReturnDataCopy(stack *vm.Stack) *big.Int { + return vm.CalcMemSize(stack.Back(0), stack.Back(2)) +} + +func memoryCodeCopy(stack *vm.Stack) *big.Int { + return vm.CalcMemSize(stack.Back(0), stack.Back(2)) +} + +func memoryExtCodeCopy(stack *vm.Stack) *big.Int { + return vm.CalcMemSize(stack.Back(1), stack.Back(3)) +} + +func memoryMLoad(stack *vm.Stack) *big.Int { + return vm.CalcMemSize(stack.Back(0), big32) +} + +func memoryMStore8(stack *vm.Stack) *big.Int { + return vm.CalcMemSize(stack.Back(0), big1) +} + +func memoryMStore(stack *vm.Stack) *big.Int { + return vm.CalcMemSize(stack.Back(0), big32) +} + +func memoryCreate(stack *vm.Stack) *big.Int { + return vm.CalcMemSize(stack.Back(1), stack.Back(2)) +} + +func memoryCreate2(stack *vm.Stack) *big.Int { + return vm.CalcMemSize(stack.Back(1), stack.Back(2)) +} + +func memoryCall(stack *vm.Stack) *big.Int { + x := vm.CalcMemSize(stack.Back(5), stack.Back(6)) + y := vm.CalcMemSize(stack.Back(3), stack.Back(4)) + + return math.BigMax(x, y) +} + +func memoryDelegateCall(stack *vm.Stack) *big.Int { + x := vm.CalcMemSize(stack.Back(4), stack.Back(5)) + y := vm.CalcMemSize(stack.Back(2), stack.Back(3)) + + return math.BigMax(x, y) +} + +func memoryStaticCall(stack *vm.Stack) *big.Int { + x := vm.CalcMemSize(stack.Back(4), stack.Back(5)) + y := vm.CalcMemSize(stack.Back(2), stack.Back(3)) + + return math.BigMax(x, y) +} + +func memoryReturn(stack *vm.Stack) *big.Int { + return vm.CalcMemSize(stack.Back(0), stack.Back(1)) +} + +func memoryRevert(stack *vm.Stack) *big.Int { + return vm.CalcMemSize(stack.Back(0), stack.Back(1)) +} + +func memoryLog(stack *vm.Stack) *big.Int { + mSize, mStart := stack.Back(1), stack.Back(0) + return vm.CalcMemSize(mStart, mSize) +} diff --git a/core/vm/opcodes.go b/core/vm/evm/opcodes.go index 8762d4b43..22ff00c7d 100644 --- a/core/vm/opcodes.go +++ b/core/vm/evm/opcodes.go @@ -14,7 +14,7 @@ // 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 +package evm import ( "fmt" diff --git a/core/vm/runtime/doc.go b/core/vm/evm/runtime/doc.go index a3b464a7d..a3b464a7d 100644 --- a/core/vm/runtime/doc.go +++ b/core/vm/evm/runtime/doc.go diff --git a/core/vm/runtime/env.go b/core/vm/evm/runtime/env.go index 6f241a329..c46580140 100644 --- a/core/vm/runtime/env.go +++ b/core/vm/evm/runtime/env.go @@ -19,7 +19,7 @@ package runtime import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" ) func NewEnv(cfg *Config) *vm.EVM { diff --git a/core/vm/runtime/fuzz.go b/core/vm/evm/runtime/fuzz.go index cb9ff08b5..cb9ff08b5 100644 --- a/core/vm/runtime/fuzz.go +++ b/core/vm/evm/runtime/fuzz.go diff --git a/core/vm/runtime/runtime.go b/core/vm/evm/runtime/runtime.go index 5656f661a..93e6322f4 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/evm/runtime/runtime.go @@ -23,7 +23,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/state" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" diff --git a/core/vm/runtime/runtime_example_test.go b/core/vm/evm/runtime/runtime_example_test.go index 036cfe558..c6050a771 100644 --- a/core/vm/runtime/runtime_example_test.go +++ b/core/vm/evm/runtime/runtime_example_test.go @@ -20,7 +20,7 @@ import ( "fmt" "github.com/dexon-foundation/dexon/common" - "github.com/dexon-foundation/dexon/core/vm/runtime" + "github.com/dexon-foundation/dexon/core/vm/evm/runtime" ) func ExampleExecute() { diff --git a/core/vm/runtime/runtime_test.go b/core/vm/evm/runtime/runtime_test.go index fe03bd43f..43b8da325 100644 --- a/core/vm/runtime/runtime_test.go +++ b/core/vm/evm/runtime/runtime_test.go @@ -24,7 +24,7 @@ import ( "github.com/dexon-foundation/dexon/accounts/abi" "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/state" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" ) diff --git a/core/vm/evm/stack.go b/core/vm/evm/stack.go new file mode 100644 index 000000000..4545201ce --- /dev/null +++ b/core/vm/evm/stack.go @@ -0,0 +1,24 @@ +package evm + +import ( + "math/big" + "sync" + + "github.com/dexon-foundation/dexon/core/vm" +) + +var stackPool = sync.Pool{ + New: func() interface{} { + return &vm.Stack{Data: make([]*big.Int, 0, 1024)} + }, +} + +func NewStack() *vm.Stack { + stack := stackPool.Get().(*vm.Stack) + stack.Data = stack.Data[:0] + return stack +} + +func Recyclestack(stack *vm.Stack) { + stackPool.Put(stack) +} diff --git a/core/vm/int_pool_verifier.go b/core/vm/int_pool_verifier.go index 82fbfed69..c03408b5f 100644 --- a/core/vm/int_pool_verifier.go +++ b/core/vm/int_pool_verifier.go @@ -20,9 +20,9 @@ package vm import "fmt" -const verifyPool = true +const VerifyPool = true -func verifyIntegerPool(ip *intPool) { +func VerifyIntegerPool(ip *IntPool) { for i, item := range ip.pool.data { if item.Cmp(checkVal) != 0 { panic(fmt.Sprintf("%d'th item failed aggressive pool check. Value was modified", i)) diff --git a/core/vm/int_pool_verifier_empty.go b/core/vm/int_pool_verifier_empty.go index a5f1dc02b..66d99f16f 100644 --- a/core/vm/int_pool_verifier_empty.go +++ b/core/vm/int_pool_verifier_empty.go @@ -18,6 +18,6 @@ package vm -const verifyPool = false +const VerifyPool = false -func verifyIntegerPool(ip *intPool) {} +func VerifyIntegerPool(ip *IntPool) {} diff --git a/core/vm/intpool.go b/core/vm/intpool.go index 917a78d56..9e73b8b71 100644 --- a/core/vm/intpool.go +++ b/core/vm/intpool.go @@ -23,84 +23,84 @@ import ( var checkVal = big.NewInt(-42) -const poolLimit = 256 +const PoolLimit = 256 -// intPool is a pool of big integers that +// IntPool is a Pool of big integers that // can be reused for all big.Int operations. -type intPool struct { - pool *Stack +type IntPool struct { + Pool *Stack } -func newIntPool() *intPool { - return &intPool{pool: newstack()} +func newIntPool() *IntPool { + return &IntPool{Pool: &Stack{Data: make([]*big.Int, 0, 1024)}} } -// get retrieves a big int from the pool, allocating one if the pool is empty. +// get retrieves a big int from the Pool, allocating one if the Pool is empty. // Note, the returned int's value is arbitrary and will not be zeroed! -func (p *intPool) get() *big.Int { - if p.pool.len() > 0 { - return p.pool.pop() +func (p *IntPool) Get() *big.Int { + if p.Pool.Len() > 0 { + return p.Pool.Pop() } return new(big.Int) } -// getZero retrieves a big int from the pool, setting it to zero or allocating -// a new one if the pool is empty. -func (p *intPool) getZero() *big.Int { - if p.pool.len() > 0 { - return p.pool.pop().SetUint64(0) +// getZero retrieves a big int from the Pool, setting it to zero or allocating +// a new one if the Pool is empty. +func (p *IntPool) GetZero() *big.Int { + if p.Pool.Len() > 0 { + return p.Pool.Pop().SetUint64(0) } return new(big.Int) } -// put returns an allocated big int to the pool to be later reused by get calls. +// put returns an allocated big int to the Pool to be later reused by get calls. // Note, the values as saved as is; neither put nor get zeroes the ints out! -func (p *intPool) put(is ...*big.Int) { - if len(p.pool.data) > poolLimit { +func (p *IntPool) Put(is ...*big.Int) { + if len(p.Pool.Data) > PoolLimit { return } 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 { + // of the integer Pool by comparing values to a default value. + if VerifyPool { i.Set(checkVal) } - p.pool.push(i) + p.Pool.Push(i) } } -// The intPool pool's default capacity -const poolDefaultCap = 25 +// The IntPool Pool's default capacity +const PoolDefaultCap = 25 -// intPoolPool manages a pool of intPools. -type intPoolPool struct { - pools []*intPool +// IntPoolPool manages a Pool of IntPools. +type IntPoolPool struct { + Pools []*IntPool lock sync.Mutex } -var poolOfIntPools = &intPoolPool{ - pools: make([]*intPool, 0, poolDefaultCap), +var PoolOfIntPools = &IntPoolPool{ + Pools: make([]*IntPool, 0, PoolDefaultCap), } -// get is looking for an available pool to return. -func (ipp *intPoolPool) get() *intPool { +// get is looking for an available Pool to return. +func (ipp *IntPoolPool) Get() *IntPool { ipp.lock.Lock() defer ipp.lock.Unlock() - if len(poolOfIntPools.pools) > 0 { - ip := ipp.pools[len(ipp.pools)-1] - ipp.pools = ipp.pools[:len(ipp.pools)-1] + if len(PoolOfIntPools.Pools) > 0 { + ip := ipp.Pools[len(ipp.Pools)-1] + ipp.Pools = ipp.Pools[:len(ipp.Pools)-1] return ip } return newIntPool() } -// put a pool that has been allocated with get. -func (ipp *intPoolPool) put(ip *intPool) { +// put a Pool that has been allocated with get. +func (ipp *IntPoolPool) Put(ip *IntPool) { ipp.lock.Lock() defer ipp.lock.Unlock() - if len(ipp.pools) < cap(ipp.pools) { - ipp.pools = append(ipp.pools, ip) + if len(ipp.Pools) < cap(ipp.Pools) { + ipp.Pools = append(ipp.Pools, ip) } } diff --git a/core/vm/intpool_test.go b/core/vm/intpool_test.go index 6c0d00f3c..120d9a682 100644 --- a/core/vm/intpool_test.go +++ b/core/vm/intpool_test.go @@ -21,35 +21,35 @@ import ( ) func TestIntPoolPoolGet(t *testing.T) { - poolOfIntPools.pools = make([]*intPool, 0, poolDefaultCap) + PoolOfIntPools.Pools = make([]*IntPool, 0, PoolDefaultCap) - nip := poolOfIntPools.get() + nip := PoolOfIntPools.Get() if nip == nil { t.Fatalf("Invalid pool allocation") } } func TestIntPoolPoolPut(t *testing.T) { - poolOfIntPools.pools = make([]*intPool, 0, poolDefaultCap) + PoolOfIntPools.Pools = make([]*IntPool, 0, PoolDefaultCap) - nip := poolOfIntPools.get() - if len(poolOfIntPools.pools) != 0 { + nip := PoolOfIntPools.Get() + if len(PoolOfIntPools.Pools) != 0 { t.Fatalf("Pool got added to list when none should have been") } - poolOfIntPools.put(nip) - if len(poolOfIntPools.pools) == 0 { + PoolOfIntPools.Put(nip) + if len(PoolOfIntPools.Pools) == 0 { t.Fatalf("Pool did not get added to list when one should have been") } } func TestIntPoolPoolReUse(t *testing.T) { - poolOfIntPools.pools = make([]*intPool, 0, poolDefaultCap) - nip := poolOfIntPools.get() - poolOfIntPools.put(nip) - poolOfIntPools.get() + PoolOfIntPools.Pools = make([]*IntPool, 0, PoolDefaultCap) + nip := PoolOfIntPools.Get() + PoolOfIntPools.Put(nip) + PoolOfIntPools.Get() - if len(poolOfIntPools.pools) != 0 { - t.Fatalf("Invalid number of pools. Got %d, expected %d", len(poolOfIntPools.pools), 0) + if len(PoolOfIntPools.Pools) != 0 { + t.Fatalf("Invalid number of pools. Got %d, expected %d", len(PoolOfIntPools.Pools), 0) } } diff --git a/core/vm/memory.go b/core/vm/memory.go index 65ffe26c7..bbfa4cc2a 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -25,8 +25,8 @@ import ( // Memory implements a simple memory model for the ethereum virtual machine. type Memory struct { - store []byte - lastGasCost uint64 + Store []byte + LastGasCost uint64 } // NewMemory returns a new memory model. @@ -39,33 +39,33 @@ func (m *Memory) Set(offset, size uint64, value []byte) { // It's possible the offset is greater than 0 and size equals 0. This is because // the calcMemSize (common.go) could potentially return 0 when size is zero (NO-OP) if size > 0 { - // length of store may never be less than offset + size. - // The store should be resized PRIOR to setting the memory - if offset+size > uint64(len(m.store)) { - panic("invalid memory: store empty") + // length of.Store may never be less than offset + size. + // The.Store should be resized PRIOR to setting the memory + if offset+size > uint64(len(m.Store)) { + panic("invalid memory:.Store empty") } - copy(m.store[offset:offset+size], value) + copy(m.Store[offset:offset+size], value) } } // Set32 sets the 32 bytes starting at offset to the value of val, left-padded with zeroes to // 32 bytes. func (m *Memory) Set32(offset uint64, val *big.Int) { - // length of store may never be less than offset + size. - // The store should be resized PRIOR to setting the memory - if offset+32 > uint64(len(m.store)) { - panic("invalid memory: store empty") + // length of.Store may never be less than offset + size. + // The.Store should be resized PRIOR to setting the memory + if offset+32 > uint64(len(m.Store)) { + panic("invalid memory:.Store empty") } // Zero the memory area - copy(m.store[offset:offset+32], []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) + copy(m.Store[offset:offset+32], []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) // Fill in relevant bits - math.ReadBits(val, m.store[offset:offset+32]) + math.ReadBits(val, m.Store[offset:offset+32]) } // Resize resizes the memory to size func (m *Memory) Resize(size uint64) { if uint64(m.Len()) < size { - m.store = append(m.store, make([]byte, size-uint64(m.Len()))...) + m.Store = append(m.Store, make([]byte, size-uint64(m.Len()))...) } } @@ -75,9 +75,9 @@ func (m *Memory) Get(offset, size int64) (cpy []byte) { return nil } - if len(m.store) > int(offset) { + if len(m.Store) > int(offset) { cpy = make([]byte, size) - copy(cpy, m.store[offset:offset+size]) + copy(cpy, m.Store[offset:offset+size]) return } @@ -91,8 +91,8 @@ func (m *Memory) GetPtr(offset, size int64) []byte { return nil } - if len(m.store) > int(offset) { - return m.store[offset : offset+size] + if len(m.Store) > int(offset) { + return m.Store[offset : offset+size] } return nil @@ -100,21 +100,21 @@ func (m *Memory) GetPtr(offset, size int64) []byte { // Len returns the length of the backing slice func (m *Memory) Len() int { - return len(m.store) + return len(m.Store) } // Data returns the backing slice func (m *Memory) Data() []byte { - return m.store + return m.Store } // Print dumps the content of the memory. func (m *Memory) Print() { - fmt.Printf("### mem %d bytes ###\n", len(m.store)) - if len(m.store) > 0 { + fmt.Printf("### mem %d bytes ###\n", len(m.Store)) + if len(m.Store) > 0 { addr := 0 - for i := 0; i+32 <= len(m.store); i += 32 { - fmt.Printf("%03d: % x\n", addr, m.store[i:i+32]) + for i := 0; i+32 <= len(m.Store); i += 32 { + fmt.Printf("%03d: % x\n", addr, m.Store[i:i+32]) addr++ } } else { diff --git a/core/vm/memory_table.go b/core/vm/memory_table.go deleted file mode 100644 index 13f15b943..000000000 --- a/core/vm/memory_table.go +++ /dev/null @@ -1,97 +0,0 @@ -// 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" - - "github.com/dexon-foundation/dexon/common/math" -) - -func memorySha3(stack *Stack) *big.Int { - return calcMemSize(stack.Back(0), stack.Back(1)) -} - -func memoryCallDataCopy(stack *Stack) *big.Int { - return calcMemSize(stack.Back(0), stack.Back(2)) -} - -func memoryReturnDataCopy(stack *Stack) *big.Int { - return calcMemSize(stack.Back(0), stack.Back(2)) -} - -func memoryCodeCopy(stack *Stack) *big.Int { - return calcMemSize(stack.Back(0), stack.Back(2)) -} - -func memoryExtCodeCopy(stack *Stack) *big.Int { - return calcMemSize(stack.Back(1), stack.Back(3)) -} - -func memoryMLoad(stack *Stack) *big.Int { - return calcMemSize(stack.Back(0), big32) -} - -func memoryMStore8(stack *Stack) *big.Int { - return calcMemSize(stack.Back(0), big1) -} - -func memoryMStore(stack *Stack) *big.Int { - return calcMemSize(stack.Back(0), big32) -} - -func memoryCreate(stack *Stack) *big.Int { - return calcMemSize(stack.Back(1), stack.Back(2)) -} - -func memoryCreate2(stack *Stack) *big.Int { - return calcMemSize(stack.Back(1), stack.Back(2)) -} - -func memoryCall(stack *Stack) *big.Int { - x := calcMemSize(stack.Back(5), stack.Back(6)) - y := calcMemSize(stack.Back(3), stack.Back(4)) - - return math.BigMax(x, y) -} - -func memoryDelegateCall(stack *Stack) *big.Int { - x := calcMemSize(stack.Back(4), stack.Back(5)) - y := calcMemSize(stack.Back(2), stack.Back(3)) - - return math.BigMax(x, y) -} - -func memoryStaticCall(stack *Stack) *big.Int { - x := calcMemSize(stack.Back(4), stack.Back(5)) - y := calcMemSize(stack.Back(2), stack.Back(3)) - - return math.BigMax(x, y) -} - -func memoryReturn(stack *Stack) *big.Int { - return calcMemSize(stack.Back(0), stack.Back(1)) -} - -func memoryRevert(stack *Stack) *big.Int { - return calcMemSize(stack.Back(0), stack.Back(1)) -} - -func memoryLog(stack *Stack) *big.Int { - mSize, mStart := stack.Back(1), stack.Back(0) - return calcMemSize(mStart, mSize) -} diff --git a/core/vm/stack.go b/core/vm/stack.go index 14b1c289b..45553d499 100644 --- a/core/vm/stack.go +++ b/core/vm/stack.go @@ -13,83 +13,60 @@ // // 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 ( "fmt" "math/big" - "sync" ) -var stackPool = sync.Pool{ - New: func() interface{} { - return &Stack{data: make([]*big.Int, 0, 1024)} - }, -} - // Stack is an object for basic stack operations. Items popped to the stack are // expected to be changed and modified. stack does not take care of adding newly // initialised objects. type Stack struct { - data []*big.Int -} - -func newstack() *Stack { - stack := stackPool.Get().(*Stack) - stack.data = stack.data[:0] - return stack -} - -func recyclestack(stack *Stack) { - stackPool.Put(stack) -} - -// Data returns the underlying big.Int array. -func (st *Stack) Data() []*big.Int { - return st.data + Data []*big.Int } -func (st *Stack) push(d *big.Int) { +func (st *Stack) Push(d *big.Int) { // NOTE push limit (1024) is checked in baseCheck //stackItem := new(big.Int).Set(d) - //st.data = append(st.data, stackItem) - st.data = append(st.data, d) + //st.Data = append(st.Data, stackItem) + st.Data = append(st.Data, d) } -func (st *Stack) pushN(ds ...*big.Int) { - st.data = append(st.data, ds...) +func (st *Stack) PushN(ds ...*big.Int) { + st.Data = append(st.Data, ds...) } -func (st *Stack) pop() (ret *big.Int) { - ret = st.data[len(st.data)-1] - st.data = st.data[:len(st.data)-1] +func (st *Stack) Pop() (ret *big.Int) { + ret = st.Data[len(st.Data)-1] + st.Data = st.Data[:len(st.Data)-1] return } -func (st *Stack) len() int { - return len(st.data) +func (st *Stack) Len() int { + return len(st.Data) } -func (st *Stack) swap(n int) { - st.data[st.len()-n], st.data[st.len()-1] = st.data[st.len()-1], st.data[st.len()-n] +func (st *Stack) Swap(n int) { + st.Data[st.Len()-n], st.Data[st.Len()-1] = st.Data[st.Len()-1], st.Data[st.Len()-n] } -func (st *Stack) dup(pool *intPool, n int) { - st.push(pool.get().Set(st.data[st.len()-n])) +func (st *Stack) Dup(pool *IntPool, n int) { + st.Push(pool.Get().Set(st.Data[st.Len()-n])) } -func (st *Stack) peek() *big.Int { - return st.data[st.len()-1] +func (st *Stack) Peek() *big.Int { + return st.Data[st.Len()-1] } // Back returns the n'th item in stack func (st *Stack) Back(n int) *big.Int { - return st.data[st.len()-n-1] + return st.Data[st.Len()-n-1] } -func (st *Stack) require(n int) error { - if st.len() < n { - return fmt.Errorf("stack underflow (%d <=> %d)", len(st.data), n) +func (st *Stack) Require(n int) error { + if st.Len() < n { + return fmt.Errorf("stack underflow (%d <=> %d)", len(st.Data), n) } return nil } @@ -97,8 +74,8 @@ func (st *Stack) require(n int) error { // Print dumps the content of the stack func (st *Stack) Print() { fmt.Println("### stack ###") - if len(st.data) > 0 { - for i, val := range st.data { + if len(st.Data) > 0 { + for i, val := range st.Data { fmt.Printf("%-3d %v\n", i, val) } } else { diff --git a/core/vm/stack_table.go b/core/vm/stack_table.go index df544aef8..187d8fa1f 100644 --- a/core/vm/stack_table.go +++ b/core/vm/stack_table.go @@ -22,23 +22,27 @@ import ( "github.com/dexon-foundation/dexon/params" ) -func makeStackFunc(pop, push int) stackValidationFunc { +type ( + StackValidationFunc func(*Stack) error +) + +func MakeStackFunc(pop, push int) StackValidationFunc { return func(stack *Stack) error { - if err := stack.require(pop); err != nil { + if err := stack.Require(pop); err != nil { return err } - if stack.len()+push-pop > int(params.StackLimit) { - return fmt.Errorf("stack limit reached %d (%d)", stack.len(), params.StackLimit) + if stack.Len()+push-pop > int(params.StackLimit) { + return fmt.Errorf("stack limit reached %d (%d)", stack.Len(), params.StackLimit) } return nil } } -func makeDupStackFunc(n int) stackValidationFunc { - return makeStackFunc(n, n+1) +func MakeDupStackFunc(n int) StackValidationFunc { + return MakeStackFunc(n, n+1) } -func makeSwapStackFunc(n int) stackValidationFunc { - return makeStackFunc(n, n) +func MakeSwapStackFunc(n int) StackValidationFunc { + return MakeStackFunc(n, n) } diff --git a/dex/api_backend.go b/dex/api_backend.go index 719625946..42f3c2dce 100644 --- a/dex/api_backend.go +++ b/dex/api_backend.go @@ -28,7 +28,7 @@ import ( "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/eth/gasprice" "github.com/dexon-foundation/dexon/internal/ethapi" diff --git a/dex/api_tracer.go b/dex/api_tracer.go index bb6acd764..450f0bfab 100644 --- a/dex/api_tracer.go +++ b/dex/api_tracer.go @@ -32,7 +32,7 @@ import ( "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/eth/tracers" "github.com/dexon-foundation/dexon/internal/ethapi" "github.com/dexon-foundation/dexon/log" diff --git a/dex/app_test.go b/dex/app_test.go index 7d665a0af..7c867959a 100644 --- a/dex/app_test.go +++ b/dex/app_test.go @@ -16,7 +16,7 @@ import ( "github.com/dexon-foundation/dexon/consensus/dexcon" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" diff --git a/dex/backend.go b/dex/backend.go index dc107c610..ced39b01c 100644 --- a/dex/backend.go +++ b/dex/backend.go @@ -27,7 +27,7 @@ import ( "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/bloombits" "github.com/dexon-foundation/dexon/core/rawdb" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/dex/downloader" "github.com/dexon-foundation/dexon/eth/filters" "github.com/dexon-foundation/dexon/eth/gasprice" diff --git a/dex/downloader/downloader.go b/dex/downloader/downloader.go index 6ff8c122e..dc73cd448 100644 --- a/dex/downloader/downloader.go +++ b/dex/downloader/downloader.go @@ -30,7 +30,7 @@ import ( "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" diff --git a/dex/downloader/downloader_test.go b/dex/downloader/downloader_test.go index 0d92ad97f..4347ad8a5 100644 --- a/dex/downloader/downloader_test.go +++ b/dex/downloader/downloader_test.go @@ -29,7 +29,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" "github.com/dexon-foundation/dexon/trie" diff --git a/dex/downloader/testchain_test.go b/dex/downloader/testchain_test.go index 810fb41b3..ff94fa6cb 100644 --- a/dex/downloader/testchain_test.go +++ b/dex/downloader/testchain_test.go @@ -25,7 +25,7 @@ import ( "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" diff --git a/dex/governance.go b/dex/governance.go index 0d5a7c926..26a174b55 100644 --- a/dex/governance.go +++ b/dex/governance.go @@ -33,7 +33,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/log" "github.com/dexon-foundation/dexon/params" diff --git a/dex/helper_test.go b/dex/helper_test.go index e3d6aa3b7..db7a4ef8e 100644 --- a/dex/helper_test.go +++ b/dex/helper_test.go @@ -31,7 +31,7 @@ import ( "github.com/dexon-foundation/dexon/consensus/ethash" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/dex/downloader" "github.com/dexon-foundation/dexon/ethdb" diff --git a/eth/api_backend.go b/eth/api_backend.go index 32faea206..9c8fe2684 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -27,7 +27,7 @@ import ( "github.com/dexon-foundation/dexon/core/bloombits" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/eth/gasprice" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" diff --git a/eth/api_tracer.go b/eth/api_tracer.go index 974917f60..ed446d878 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -34,7 +34,7 @@ import ( "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/eth/tracers" "github.com/dexon-foundation/dexon/internal/ethapi" "github.com/dexon-foundation/dexon/log" diff --git a/eth/backend.go b/eth/backend.go index 50d7779a3..28265d5ae 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -35,7 +35,7 @@ import ( "github.com/dexon-foundation/dexon/core/bloombits" "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/eth/downloader" "github.com/dexon-foundation/dexon/eth/filters" "github.com/dexon-foundation/dexon/eth/gasprice" diff --git a/eth/handler_test.go b/eth/handler_test.go index a9fdaa87f..4041fbe59 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -29,7 +29,7 @@ import ( "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/eth/downloader" "github.com/dexon-foundation/dexon/ethdb" diff --git a/eth/helper_test.go b/eth/helper_test.go index e4d7a28fb..a6e90e7c1 100644 --- a/eth/helper_test.go +++ b/eth/helper_test.go @@ -32,7 +32,7 @@ import ( "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/eth/downloader" "github.com/dexon-foundation/dexon/ethdb" diff --git a/eth/tracers/tracer.go b/eth/tracers/tracer.go index 082bb8912..89b2c3585 100644 --- a/eth/tracers/tracer.go +++ b/eth/tracers/tracer.go @@ -28,6 +28,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/common/hexutil" "github.com/dexon-foundation/dexon/core/vm" + "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/log" duktape "gopkg.in/olebedev/go-duktape.v3" @@ -68,7 +69,7 @@ func pushBigInt(n *big.Int, ctx *duktape.Context) { // opWrapper provides a JavaScript wrapper around OpCode. type opWrapper struct { - op vm.OpCode + op evm.OpCode } // pushObject assembles a JSVM object wrapping a swappable opcode and pushes it @@ -140,20 +141,20 @@ func (mw *memoryWrapper) pushObject(vm *duktape.Context) { vm.PutPropString(obj, "getUint") } -// stackWrapper provides a JavaScript wrapper around vm.Stack. +// stackWrapper provides a JavaScript wrapper around evm.Stack. type stackWrapper struct { stack *vm.Stack } // peek returns the nth-from-the-top element of the stack. func (sw *stackWrapper) peek(idx int) *big.Int { - if len(sw.stack.Data()) <= idx { + if len(sw.stack.Data) <= idx { // TODO(karalabe): We can't js-throw from Go inside duktape inside Go. The Go // runtime goes belly up https://github.com/golang/go/issues/15639. - log.Warn("Tracer accessed out of bound stack", "size", len(sw.stack.Data()), "index", idx) + log.Warn("Tracer accessed out of bound stack", "size", len(sw.stack.Data), "index", idx) return new(big.Int) } - return sw.stack.Data()[len(sw.stack.Data())-idx-1] + return sw.stack.Data[len(sw.stack.Data)-idx-1] } // pushObject assembles a JSVM object wrapping a swappable stack and pushes it @@ -161,7 +162,7 @@ func (sw *stackWrapper) peek(idx int) *big.Int { func (sw *stackWrapper) pushObject(vm *duktape.Context) { obj := vm.PushObject() - vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushInt(len(sw.stack.Data())); return 1 }) + vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushInt(len(sw.stack.Data)); return 1 }) vm.PutPropString(obj, "length") // Generate the `peek` method which takes an int and returns a bigint @@ -175,9 +176,9 @@ func (sw *stackWrapper) pushObject(vm *duktape.Context) { vm.PutPropString(obj, "peek") } -// dbWrapper provides a JavaScript wrapper around vm.Database. +// dbWrapper provides a JavaScript wrapper around evm.Database. type dbWrapper struct { - db vm.StateDB + db evm.StateDB } // pushObject assembles a JSVM object wrapping a swappable database and pushes it @@ -230,9 +231,9 @@ func (dw *dbWrapper) pushObject(vm *duktape.Context) { vm.PutPropString(obj, "exists") } -// contractWrapper provides a JavaScript wrapper around vm.Contract +// contractWrapper provides a JavaScript wrapper around evm.Contract type contractWrapper struct { - contract *vm.Contract + contract *evm.Contract } // pushObject assembles a JSVM object wrapping a swappable contract and pushes it @@ -368,7 +369,7 @@ func New(code string) (*Tracer, error) { return 1 }) tracer.vm.PushGlobalGoFunction("isPrecompiled", func(ctx *duktape.Context) int { - _, ok := vm.PrecompiledContractsByzantium[common.BytesToAddress(popSlice(ctx))] + _, ok := evm.PrecompiledContractsByzantium[common.BytesToAddress(popSlice(ctx))] ctx.PushBoolean(ok) return 1 }) @@ -510,7 +511,7 @@ func (jst *Tracer) CaptureStart(from common.Address, to common.Address, create b } // CaptureState implements the Tracer interface to trace a single step of VM execution. -func (jst *Tracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { +func (jst *Tracer) CaptureState(env *evm.EVM, pc uint64, op evm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *evm.Contract, depth int, err error) error { if jst.err == nil { // Initialize the context if it wasn't done yet if !jst.inited { @@ -549,7 +550,7 @@ func (jst *Tracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost // CaptureFault implements the Tracer interface to trace an execution fault // while running an opcode. -func (jst *Tracer) CaptureFault(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { +func (jst *Tracer) CaptureFault(env *evm.EVM, pc uint64, op evm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *evm.Contract, depth int, err error) error { if jst.err == nil { // Apart from the error, everything matches the previous invocation jst.errorValue = new(string) diff --git a/eth/tracers/tracer_test.go b/eth/tracers/tracer_test.go index 75140a5db..eacc9a591 100644 --- a/eth/tracers/tracer_test.go +++ b/eth/tracers/tracer_test.go @@ -26,7 +26,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/state" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/params" ) diff --git a/eth/tracers/tracers_test.go b/eth/tracers/tracers_test.go index 116402400..f6eb519ed 100644 --- a/eth/tracers/tracers_test.go +++ b/eth/tracers/tracers_test.go @@ -30,7 +30,7 @@ import ( "github.com/dexon-foundation/dexon/common/math" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/rlp" "github.com/dexon-foundation/dexon/tests" diff --git a/indexer/blockchain.go b/indexer/blockchain.go index f3275f882..369184e15 100644 --- a/indexer/blockchain.go +++ b/indexer/blockchain.go @@ -11,7 +11,7 @@ import ( "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/event" "github.com/dexon-foundation/dexon/params" "github.com/dexon-foundation/dexon/rlp" diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 7bcf44814..96c4c2e5d 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -35,7 +35,7 @@ import ( "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/log" "github.com/dexon-foundation/dexon/p2p" diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 51f236890..ebbdf87e3 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -27,7 +27,7 @@ import ( "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" "github.com/dexon-foundation/dexon/params" diff --git a/les/api_backend.go b/les/api_backend.go index 770aa8515..d42b4fcb8 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -28,7 +28,7 @@ import ( "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/eth/gasprice" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" diff --git a/les/helper_test.go b/les/helper_test.go index 2ce78f0c9..550fb1905 100644 --- a/les/helper_test.go +++ b/les/helper_test.go @@ -30,7 +30,7 @@ import ( "github.com/dexon-foundation/dexon/consensus/ethash" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/eth" "github.com/dexon-foundation/dexon/ethdb" diff --git a/les/odr_test.go b/les/odr_test.go index 9a6b1ef88..f6e6e873b 100644 --- a/les/odr_test.go +++ b/les/odr_test.go @@ -29,7 +29,7 @@ import ( "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/light" "github.com/dexon-foundation/dexon/params" diff --git a/light/odr_test.go b/light/odr_test.go index 34e1f6f7c..08d4bce32 100644 --- a/light/odr_test.go +++ b/light/odr_test.go @@ -31,7 +31,7 @@ import ( "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" diff --git a/light/trie_test.go b/light/trie_test.go index e0eee22e1..72b709ea6 100644 --- a/light/trie_test.go +++ b/light/trie_test.go @@ -26,7 +26,7 @@ import ( "github.com/dexon-foundation/dexon/consensus/ethash" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/state" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" "github.com/dexon-foundation/dexon/trie" diff --git a/light/txpool_test.go b/light/txpool_test.go index b7e6fe5b3..4775261d9 100644 --- a/light/txpool_test.go +++ b/light/txpool_test.go @@ -27,7 +27,7 @@ import ( "github.com/dexon-foundation/dexon/consensus/ethash" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" ) diff --git a/miner/worker_test.go b/miner/worker_test.go index eb25e27f2..8919c1e3a 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -27,7 +27,7 @@ import ( "github.com/dexon-foundation/dexon/consensus/ethash" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" diff --git a/tests/block_test_util.go b/tests/block_test_util.go index 130d1eda3..7d5c391fa 100644 --- a/tests/block_test_util.go +++ b/tests/block_test_util.go @@ -32,7 +32,7 @@ import ( "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" "github.com/dexon-foundation/dexon/rlp" diff --git a/tests/state_test.go b/tests/state_test.go index dcba09bf3..41b2224e9 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -24,7 +24,7 @@ import ( "testing" "github.com/dexon-foundation/dexon/cmd/utils" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" ) func TestState(t *testing.T) { diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 5d0923dd1..17d9834d5 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -29,7 +29,7 @@ import ( "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/crypto/sha3" "github.com/dexon-foundation/dexon/ethdb" diff --git a/tests/vm_test.go b/tests/vm_test.go index a5d5b2ba5..b7746188c 100644 --- a/tests/vm_test.go +++ b/tests/vm_test.go @@ -19,7 +19,7 @@ package tests import ( "testing" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" ) func TestVM(t *testing.T) { diff --git a/tests/vm_test_util.go b/tests/vm_test_util.go index d79d18fbf..316213ea5 100644 --- a/tests/vm_test_util.go +++ b/tests/vm_test_util.go @@ -27,7 +27,7 @@ import ( "github.com/dexon-foundation/dexon/common/math" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/state" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/params" |