2014-10-18 06:31:20 -05:00
|
|
|
package vm
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/big"
|
|
|
|
|
2014-10-31 06:37:43 -05:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2014-10-23 08:01:27 -05:00
|
|
|
"github.com/ethereum/go-ethereum/ethutil"
|
2014-10-31 08:43:14 -05:00
|
|
|
"github.com/ethereum/go-ethereum/state"
|
2014-10-14 04:48:52 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type DebugVm struct {
|
|
|
|
env Environment
|
|
|
|
|
|
|
|
logTy byte
|
|
|
|
logStr string
|
|
|
|
|
|
|
|
err error
|
|
|
|
|
|
|
|
// Debugging
|
|
|
|
Dbg Debugger
|
|
|
|
|
|
|
|
BreakPoints []int64
|
|
|
|
Stepping bool
|
|
|
|
Fn string
|
|
|
|
|
|
|
|
Recoverable bool
|
|
|
|
|
|
|
|
depth int
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDebugVm(env Environment) *DebugVm {
|
|
|
|
lt := LogTyPretty
|
|
|
|
if ethutil.Config.Diff {
|
|
|
|
lt = LogTyDiff
|
|
|
|
}
|
|
|
|
|
|
|
|
return &DebugVm{env: env, logTy: lt, Recoverable: true}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
|
|
|
|
self.depth++
|
|
|
|
|
Squashed commit of the following:
commit 79d7cbfc4a9cf3d70ae01dea8ee76c770af33211
Merge: 9120274 1c1ba8d
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Nov 4 13:32:11 2014 +0100
Merge remote-tracking branch 'origin/develop' into develop
commit 9120274a46d696cda6d595b2ec5acc2947eb2b46
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Nov 4 13:31:27 2014 +0100
Update tests to latest protocol changes (PoC7)
commit 1c1ba8d161817b391ea296391ad3ede3e71c0aa1
Merge: 014d370 3aebe53
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Nov 4 13:30:52 2014 +0100
Merge pull request #31 from CJentzsch/develop
Restructered tests in folders in accordance to test suites
commit 3aebe532e536eb6f6766ccac456c07023ab822e1
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Mon Nov 3 13:58:21 2014 +0100
Updated vmNamecoin.json to new sstore prices
commit 8a0be21839cf8bb7d3d80a2b61c8433b5d3a8bfd
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Mon Nov 3 13:53:00 2014 +0100
Added example state test
commit 83643addbc3d50c6a79611a5d8700aad5fb1df16
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Mon Nov 3 13:36:25 2014 +0100
removed systemoperationstests
commit 3930ca3a9a377107d5792b3e7202f79c688f1a67
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Mon Nov 3 13:22:15 2014 +0100
Restructered tests in folders in accordance to test suites
commit 014d370b5d5d0a807cc31a2fc3a8c5313ccd7ea4
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Wed Oct 29 21:23:56 2014 +0100
New SIGNEXTEND tets
commit 155d449be206f5276f689770006ecbbb203dd6ad
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Wed Oct 29 20:59:05 2014 +0100
New tests for BNOT and SIGNEXTEND
commit c9eae764b8921a5d6c929b8544cb9acdb920453c
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Oct 28 12:58:27 2014 +0100
Update SSTORE gas cost and BNOT instead of NEG
commit ad2a75ac58ddcb06316f68d0fdaa8e80828a990c
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Thu Oct 23 16:05:49 2014 +0200
Added new recursive bombs
commit 834c52af6406b9af429104408ca7bcbc525efe5c
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Thu Oct 23 12:01:05 2014 +0200
Changing gas cost to zero at stackunderflow
commit c73a8a89d23cbdaf80875667437d57c3ee32f08a
Author: Jeffrey Wilcke <obscuren@users.noreply.github.com>
Date: Wed Oct 22 13:04:45 2014 +0200
Reverted back to original value.
commit b9a8c924227996ef281d44ccfcc72c7618027f91
Author: martin becze <wanderer@users.noreply.github.com>
Date: Tue Oct 21 17:02:52 2014 -0400
fix spelling error
commit b48ae74af441c00cdce487416be448b0df3d4323
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Oct 21 17:26:26 2014 +0200
Added failing random tests
commit bee0a4100c69cabfa361e36831ec0f64187188f3
Merge: 5050d20 b315da6
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Oct 21 17:15:05 2014 +0200
Merge remote-tracking branch 'origin/master' into develop
commit 5050d20b4d0321e3e4ea2f118781c7bb96a3d7b5
Merge: 7516685 ba35362
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Mon Oct 20 20:18:20 2014 +0200
Merge pull request #26 from wanderer/develop
Add a package.json for node.js
commit ba35362876caa03b11c7ce777d959b99accbcfb0
Author: wanderer <mjbecze@gmail.com>
Date: Sun Oct 19 23:59:47 2014 -0400
turned tests into a node module
commit 751668571e390e6bceb515d082222aa31b5e5b14
Author: ethers <ethereum@outlook.com>
Date: Thu Oct 16 17:08:20 2014 -0700
json was invalid and missing quotes
commit 0e687cee479acfd82861e13d2022ad430fc78d78
Author: Jeffrey Wilcke <obscuren@users.noreply.github.com>
Date: Thu Oct 16 17:13:24 2014 +0200
Update vmEnvironmentalInfoTest.json
commit 78a78e2e6cffb9357f2281070d83bf869ab8b2f4
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Wed Oct 15 14:19:11 2014 +0200
updated genesis_hash
commit b315da618b55b581ba8e87f83b2ab5175841392e
Merge: 7a7e198 0a76a3a
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Oct 14 10:33:26 2014 +0200
Merge pull request #23 from ethers/fix22
numbers should be strings #22
commit 0a76a3a312951e852509e2b378b2b5b3f87135b0
Author: ethers <ethereum@outlook.com>
Date: Mon Oct 13 14:45:30 2014 -0700
numbers should be strings #22
commit 1f67385f130422588f92341fe82c2435b160fe84
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Sat Oct 11 13:18:00 2014 +0200
Added some MUL tests
commit 7a7e198395f776d0a95d252ddc3b30492b9d3cff
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Sat Oct 11 13:11:59 2014 +0200
Added some MUL tests
commit 46eb6283ae6c147f7efa910dadc18a504b6725ed
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Sat Oct 11 12:18:13 2014 +0200
tested new opcodes (JUMPDEST,CALLCODE) and created test for CALL/CREATE depth
commit 8d38d62d1053ed7552211105e26b2e248a3db747
Author: Nick Savers <nicksavers@gmail.com>
Date: Fri Oct 10 18:09:41 2014 +0200
INVALID stops the operation and doesn't cost gas
commit ed6eba7c8ebc0cbb65ccd45b047823f9acc1471b
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Wed Oct 8 19:08:48 2014 +0200
Update + ABA recursive bomb which needs maximum recursion limit of 1024
commit 2d72050db1c67d9d6912ce6ade80dbe5685749ff
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Wed Oct 8 14:37:18 2014 +0200
Applied recent protocol changes (PoC7) to existin tests
commit dfe66cab3fb533003ddaec7250d8fffbf3fbad65
Merge: 4513623 1a67a96
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Wed Oct 8 11:05:51 2014 +0200
Merge remote-tracking branch 'origin/develop'
Conflicts:
genesishashestest.json
commit 1a67a96cff2fba02e57a82d65007cec99dcc313c
Merge: a4f5f45 ffd6bc9
Author: vbuterin <v@buterin.com>
Date: Tue Oct 7 15:10:23 2014 +0100
Merge pull request #18 from CJentzsch/develop
CallToNameRegistratorOutOfGas balance correction
commit ffd6bc97adfbc83b6e0c50cdf072fd58f94ace69
Merge: a4f5f45 9779d67
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Oct 7 15:47:34 2014 +0200
Merge remote-tracking branch 'origin/develop' into develop
commit 9779d67b8cdf4e99818a5eeadbc3aebd7527b1a9
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Oct 7 15:45:53 2014 +0200
CallToNameRegistratorOutOfGas balance correction
Even if execution fails, the value gets transferred.
commit a4f5f45228b6f3ebf8ea77c47515149a3df2bc24
Merge: 49a9f47 b6d7cba
Author: vbuterin <v@buterin.com>
Date: Tue Oct 7 14:13:12 2014 +0100
Merge pull request #17 from CJentzsch/develop
Added A calls B calls A contracts
commit b6d7cba49914362297c0fcac48d868ffe3bdf06a
Merge: 865cb40 49a9f47
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Oct 7 15:02:51 2014 +0200
Merge remote-tracking branch 'upstream/develop' into develop
commit 865cb4083d33de2a9115ee39c73aea56b0c34fe8
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Oct 7 15:02:36 2014 +0200
Added A calls B calls A contracts
commit 49a9f47aec2dbd6e321298947929b3d0b5abc280
Merge: 3b0ec43 94a493b
Author: Jeffrey Wilcke <obscuren@users.noreply.github.com>
Date: Tue Oct 7 10:56:17 2014 +0200
Merge pull request #16 from CJentzsch/develop
corrected amount of used gas for CallToNameRegistratorOutOfGas
commit 94a493b0d94163e3de96e1c4bb389ef745756f30
Merge: 72853c4 3b0ec43
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Oct 7 10:51:32 2014 +0200
Merge remote-tracking branch 'upstream/develop' into develop
commit 72853c4382fa1b51e384223da34427d3579fe48a
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Oct 7 10:51:07 2014 +0200
corrected amount of used gas for CallToNameRegistratorOutOfGas
commit 3b0ec436e4c6808f98f1bc5bb5c66b4d2be4b4be
Merge: aec3252 222068b
Author: vbuterin <v@buterin.com>
Date: Tue Oct 7 05:52:43 2014 +0100
Merge pull request #15 from CJentzsch/develop
corrected tests and different style for storage
commit 222068b9bac6c386e499cb6b0fc2af562fcd309e
Merge: c169653 aec3252
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Mon Oct 6 21:17:28 2014 +0200
Merge remote-tracking branch 'upstream/develop' into develop
commit c1696531a646309b2b286abb7552eb05f1278cd1
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Mon Oct 6 21:17:09 2014 +0200
corrected tests and different style for storage
commit aec3252b8e9f6d37b5cf3dbe0c1678e08929d291
Merge: 25f9fd5 e17a909
Author: vbuterin <v@buterin.com>
Date: Mon Oct 6 09:39:46 2014 +0100
Merge pull request #14 from CJentzsch/develop
corrected gas limit in vmSystemOperationsTest
commit e17a909f70af18fbfc0216c061a663e8778e7d5c
Merge: 33fcab5 25f9fd5
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Mon Oct 6 10:31:51 2014 +0200
Merge remote-tracking branch 'upstream/develop' into develop
commit 33fcab57273731f449e9504d15c5d22cbe773e2a
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Mon Oct 6 10:30:04 2014 +0200
Bug fix, corrected gasLimit in vmSystemOperationsTest
commit 25f9fd542a4ab27a5a66668a72b84d4bf7c292e6
Author: Vitalik Buterin <v@buterin.com>
Date: Sat Oct 4 15:47:00 2014 -0400
one more vm test
commit 2d561a5373faf392e51f8c579c936549db2966d3
Author: Vitalik Buterin <v@buterin.com>
Date: Sat Oct 4 15:15:37 2014 -0400
separated out vmtests
commit b0c48fa8d69ae02e01931a5675fc58ff9e84aba3
Merge: cb8261a 6cae166
Author: vbuterin <v@buterin.com>
Date: Sat Oct 4 17:18:02 2014 +0100
Merge pull request #13 from CJentzsch/develop
Added comprehensive EVM test suite. All commands are tested.
commit 6cae166f6f1e3f4eaaef6a9036c597b6064b263a
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Wed Oct 1 15:34:23 2014 +0200
Delete tmp.json
commit 4ff906fbc271ee3aee3eb5db135e591eb187793a
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Wed Oct 1 14:06:32 2014 +0200
corrected CALLSTATELESS tests
commit 5b3fee6806a69545e572725add73c297e9473eee
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Mon Sep 29 13:08:44 2014 +0200
Completed vm tests. Added ADDMOD, MULMOD, POST, CALLSTATELESS
commit 9cdd2180833d98cf967929e07cab6638c2e933d0
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Sat Sep 27 21:48:09 2014 +0200
Added IOandFlowOperation-, PushDupSwap- and SystemOperations- tests. Removed empty storage from adresses.
commit 28ed968b46590bd8f3e5bb25606e8f83e0ee9b9e
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Sep 23 15:49:22 2014 +0200
Added blockInfoTest
commit ffbd5a35b597d2908fa0fa37d9b2aeaf30aee155
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Tue Sep 23 15:37:52 2014 +0200
Added environmentalInfo- and sha3- test
commit 54c14f1ff3f7ec66d755181be32a13e0404110d9
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Mon Sep 22 13:06:57 2014 +0200
Added bitwise logic operation test
commit d0af113aab3991fecbde29933f4a77884fafdf60
Author: Christoph Jentzsch <jentzsch.software@gmail.com>
Date: Sat Sep 20 01:42:51 2014 +0200
Added vm arithmetic test
commit cb8261a78b56197e421bce5ac2afb7147f5acb45
Author: Jeffrey Wilcke <obscuren@users.noreply.github.com>
Date: Fri Sep 19 13:15:44 2014 +0200
Update genesishashestest.json
commit 4513623da1110e74a236abf0357ad00ff7a38126
Author: Maran <maran.hidskes@gmail.com>
Date: Tue Jul 22 12:24:46 2014 +0200
Update keyaddrtest to be valid JSON
commit e8cb5c221d4763c8c26ac73f99609b64a595f4b3
Author: Vitalik Buterin <v@buterin.com>
Date: Mon Jul 21 23:30:33 2014 -0400
Added next/prev trie test
commit 98823c04b30ef0be478c69a11edc3f9f6dff567e
Author: Vitalik Buterin <v@buterin.com>
Date: Mon Jul 14 02:51:31 2014 -0400
Replaced with deterministic test
commit 357eb21e4d5d9d6713ba7c63a76bd597a57d6a0e
Author: Vitalik Buterin <v@buterin.com>
Date: Sun Jul 13 16:12:56 2014 -0400
Added my own random and namecoin tests (pyethereum)
commit 00cd0cce8f0fc0ca8aa2c8ca424954d4932672f2
Author: Gav Wood <i@gavwood.com>
Date: Sat Jul 12 21:20:04 2014 +0200
Output hex strings.
commit ddfa3af45da9d5d81da38745ae23ee93ce390c2b
Author: Gav Wood <i@gavwood.com>
Date: Thu Jul 10 11:28:35 2014 +0100
Everything a string.
commit d659f469a9ddcdd144a332da64b826908b0f7872
Author: Gav Wood <i@gavwood.com>
Date: Thu Jul 10 10:16:25 2014 +0100
Code fixes.
commit 5e83ea82283f042df384d7ff20183ba51760d893
Author: Gav Wood <i@gavwood.com>
Date: Sun Jul 6 16:17:12 2014 +0200
Prettier VM tests.
commit a09aae0efe9a1cb94be3e0386532c532262956ec
Author: Gav Wood <i@gavwood.com>
Date: Sun Jul 6 15:46:01 2014 +0200
Fix VM tests.
commit ec9a044a17779f0b3814bffa8c058b4091d6d13d
Merge: 4bb6461 5e0123f
Author: Jeffrey Wilcke <obscuren@users.noreply.github.com>
Date: Fri Jul 4 15:56:52 2014 +0200
Merge pull request #10 from romanman/patch-1
Update vmtests.json
commit 5e0123fbe1573dcf8157995f3ef2f7ce625235a4
Author: romanman <roman.mandeleil@gmail.com>
Date: Fri Jul 4 10:23:04 2014 +0100
Update vmtests.json
commit 2b6da2f5f21b60ebca44a5866888b00f736f92b2
Author: romanman <roman.mandeleil@gmail.com>
Date: Thu Jul 3 17:45:04 2014 +0100
Update vmtests.json
arith testcase updated
commit 4bb646117d0034fb459c07e6955b1c9cca802fa9
Merge: bba3898 a33b309
Author: Gav Wood <i@gavwood.com>
Date: Wed Jul 2 19:43:22 2014 +0200
Merge branch 'develop' of github.com:/ethereum/tests into develop
commit bba38980bdfa6ba6fddf0419479ad2405a3cb079
Author: Gav Wood <i@gavwood.com>
Date: Wed Jul 2 19:43:06 2014 +0200
New tests.
commit a33b309d99b36c4c57083d5e77422c3f2bba4bbe
Author: Vitalik Buterin <v@buterin.com>
Date: Wed Jul 2 10:14:05 2014 -0400
Testing submodules
commit 50318217ca875d23147eddfa7cc0326242db90bf
Author: Vitalik Buterin <v@buterin.com>
Date: Wed Jul 2 10:10:46 2014 -0400
Testing submodules
commit 57fa655522fc9696adcc7a6a25b64afd569b0758
Author: Vitalik Buterin <v@buterin.com>
Date: Wed Jul 2 10:09:08 2014 -0400
Testing submodules
commit ea0eb0a8c82521322bd0359d1c42fc013c433d2e
Author: Gav Wood <i@gavwood.com>
Date: Tue Jul 1 15:19:34 2014 +0200
Latest genesis block.
commit 25bb76b69c90ebd44a271d7c180a4a4b86845018
Author: Jeffrey Wilcke <obscuren@users.noreply.github.com>
Date: Mon Jun 30 13:25:04 2014 +0200
Reset
commit 74c6d8424e7d91ccd592c179794bc74e63c0d8c0
Author: Jeffrey Wilcke <obscuren@users.noreply.github.com>
Date: Mon Jun 30 12:10:06 2014 +0200
Updated wrong test
commit 9ea3a60291f2ca68a54198d53e4c40fffb09f6b3
Author: Jeffrey Wilcke <obscuren@users.noreply.github.com>
Date: Sat Jun 28 18:48:28 2014 +0200
Fixed roots
commit 5fc3ac0e925cdfe95632024f574fb945558491b8
Author: Gav Wood <i@gavwood.com>
Date: Sat Jun 28 18:40:06 2014 +0200
Simple hex test.
commit edd3a00c2a8d78867d8bb1557697455729a03027
Author: Gav Wood <i@gavwood.com>
Date: Sat Jun 28 18:22:18 2014 +0200
Additional test for jeff. Now use the 0x... notation.
commit 5021e0dd83bdb8b23ca3dcc72293c6737e8165a8
Author: Gav Wood <i@gavwood.com>
Date: Fri Jun 27 21:35:26 2014 +0200
VM test framework updated.
commit c818d132022c228c5b04ab82871f5971049b0c6d
Author: Gav Wood <i@gavwood.com>
Date: Fri Jun 27 18:18:24 2014 +0200
Removed arrays from Trie tests JSON as per conformance guide and changed
vocabulary to match other tests.
VM test updates.
commit 714770ffb3bb037e2daeaa37a6f4f4066387abe3
Author: Gav Wood <i@gavwood.com>
Date: Wed Jun 11 11:32:42 2014 +0100
Added Gav's new address.
commit 9345bc13d40e6d288c37b650ace1db0c41a89d84
Merge: a2257f3 78576dd
Author: Gav Wood <i@gavwood.com>
Date: Fri May 30 17:50:38 2014 +0200
Merge branch 'master' of github.com:ethereum/tests into develop
commit a2257f3471dd4b472bc156be4575ea0f26a8a046
Author: Gav Wood <i@gavwood.com>
Date: Fri May 30 17:50:18 2014 +0200
VM tests.
commit 78576dd3d3d4bf46af19d703affdd42f221e49c9
Author: Heiko Heiko <heiko@heiko.org>
Date: Fri May 30 17:19:09 2014 +0200
changes based on new account structure nonce, balance, storage, code
commit 125839e84833ec25e0fdd4fbd545772ba706fe6b
Merge: 42e14ec 356a329
Author: Jeffrey Wilcke <obscuren@users.noreply.github.com>
Date: Thu May 22 09:58:45 2014 +0200
Merge pull request #5 from bkirwi/master
Fix invalid JSON (removed trailing comma) and add test names
commit 356a3296bc7eeac8b1b65aa843b5856cd786c4cf
Author: Ben Kirwin <ben@kirw.in>
Date: Thu May 22 00:20:48 2014 -0400
Add some arbitrary test names
This should now conform to the format specified in the README.
commit 42e14ec54fa57c2373625d21e5b47f597c748bf5
Author: Chen Houwu <chenhouwu@gmail.com>
Date: Wed May 21 23:27:40 2014 +0800
revert to correct data
commit 4300197a748de29cc5c93fd77f13cae029dad49e
Author: Chen Houwu <chenhouwu@gmail.com>
Date: Wed May 21 22:42:23 2014 +0800
fix: wrong sha3 hash because of the wrong rlp hex
commit a0d01b1a0b59555e38ea694ff864f2aa25a0d953
Author: Chen Houwu <chenhouwu@gmail.com>
Date: Wed May 21 22:29:53 2014 +0800
fix: wrong rlp hex
commit 6bc2fc74054a418e7cfca9cf9144237a5e4fa65f
Merge: 66bc366 c31a93c
Author: Jeffrey Wilcke <obscuren@users.noreply.github.com>
Date: Wed May 21 14:11:37 2014 +0200
Merge pull request #4 from ethers/master
fix file name that seems to have been a typo
commit c31a93c27a9048df92fcf53a2201c6e3737a40fd
Author: ethers <ethereum@outlook.com>
Date: Tue May 20 15:42:39 2014 -0700
fix file name that seems to have been a typo
commit 66bc3665c17e1eec309e5a40b2a9c74273fb639a
Author: Heiko Heiko <heiko@heiko.org>
Date: Tue May 20 17:36:35 2014 +0200
fix: represent integers as strings
commit ede5499da624d95db1cad63939be56f7bdaa6389
Author: Heiko Heiko <heiko@heiko.org>
Date: Tue May 20 17:21:09 2014 +0200
add: current initial alloc and genesis hashes
commit 5131429abbe6d2636064e17b45c99827a904c345
Author: Ben Kirwin <ben@kirw.in>
Date: Mon May 19 11:18:31 2014 -0400
Delete a comma
This should now be parseable as JSON.
commit f44a85933110dd3ef362090f512678e99ae80256
Author: Chen Houwu <chenhouwu@gmail.com>
Date: Sun May 18 15:04:42 2014 +0800
add: case when value is long, ensure it's not get rlp encoded as node
commit e1ae4ad4495dd13fba6346274971a8871cb32607
Author: Gav Wood <i@gavwood.com>
Date: Mon May 12 14:40:47 2014 +0100
PoC-5 VM tests.
commit 2b6c136dda0d55a0ebd228bff029d97411c9cec6
Author: Vitalik Buterin <v@buterin.com>
Date: Sun May 11 21:42:41 2014 -0400
Moved txt to json
commit cbccbf977ca7bde15a661a4b453ea062e62ac856
Merge: edbb8d4 45a0974
Author: Vitalik Buterin <v@buterin.com>
Date: Thu May 8 21:54:48 2014 -0400
New commit
commit edbb8d407ecfbcbb6504659cbd9bdabdb93369e3
Author: Vitalik Buterin <v@buterin.com>
Date: Tue May 6 16:53:43 2014 -0400
Removed unneeded test, added new tests
commit 45a0974f6f32511119e40a27042fdd571fe47a16
Merge: 15dd8fd 5fd2a98
Author: Gav Wood <i@gavwood.com>
Date: Sun Apr 27 12:53:47 2014 +0100
Merge pull request #3 from autolycus/develop
Fixed formatting and added test cases
commit 5fd2a98fcb4f6a648160204d1b20b0f980d55b9d
Author: Carl Allendorph <callendorph@gmail.com>
Date: Sat Apr 19 13:26:14 2014 -0700
Added some new test cases for the rlp encoding.
commit 4ba150954ef8ac72416a35f06fdad9c6d7ed461d
Author: Carl Allendorph <callendorph@gmail.com>
Date: Sat Apr 19 12:48:42 2014 -0700
Converted spaces to tabs to be compliant with the coding standards defined in cpp-ethereum
commit 15dd8fd794a0dc305ef7696d0c2a68e032bc9759
Author: Gav Wood <i@gavwood.com>
Date: Fri Feb 28 12:54:47 2014 +0000
RLP tests and Trie updates.
commit 33f80fef211c2d51162c1856e50448be3d90c214
Author: Gav Wood <i@gavwood.com>
Date: Fri Feb 28 11:39:35 2014 +0000
Hex encode tests done.
commit e1f5e12abb38f8cedb4a589b1347fb01c3da902a
Author: Gav Wood <i@gavwood.com>
Date: Fri Feb 28 11:22:49 2014 +0000
Fix RLP tests.
commit f87ce15ad201a6d97e2654e5dc5a3181873d1719
Author: Gav Wood <i@gavwood.com>
Date: Thu Feb 27 13:28:11 2014 +0000
Fix empty string.
commit c006ed4ffd7d00124dbcb44d4e7ca05d6d9ddc12
Author: Gav Wood <i@gavwood.com>
Date: Mon Feb 24 10:24:39 2014 +0000
Tests fix.
commit 510ff563639e71224306d9af0e50a28a9d624b8f
Author: Gav Wood <i@gavwood.com>
Date: Fri Feb 21 18:54:08 2014 +0000
Updated the tests.
commit a0ec84383218ea80b4c0b99e09710fae182a2379
Author: Gav Wood <i@gavwood.com>
Date: Fri Feb 21 18:49:24 2014 +0000
Moved over to new format, but RLP tests still need updating.
commit 660cd26f31b3979149950c1fdea995b85a774c1c
Author: Gav Wood <i@gavwood.com>
Date: Fri Feb 21 18:35:51 2014 +0000
More docs.
commit 6ad14c1a157e707fd15c87816e8ad872f69790db
Author: Gav Wood <i@gavwood.com>
Date: Fri Feb 21 18:33:39 2014 +0000
Added VM test suite.
Added TODO.
Renamed old files.
commit f91ad7b3857ec9157e7df7f315d942afb7594da0
Author: Vitalik Buterin <v@buterin.com>
Date: Wed Jan 8 11:26:58 2014 -0500
update trie algorithm
commit 6da295446203889ac5a4a365b397bb45766c9ad8
Merge: cc42246 131c610
Author: Vitalik Buterin <v@buterin.com>
Date: Wed Jan 8 08:15:38 2014 -0500
merge
commit cc4224675f1f70242f91ee7d2d1295bed6f0dc01
Author: Vitalik Buterin <v@buterin.com>
Date: Tue Jan 7 14:35:26 2014 -0500
Updated trie test
commit 131c610da66203f708391485aa42fc7a81f01ef7
Merge: 121632b 7613302
Author: vbuterin <v@buterin.com>
Date: Wed Jan 1 06:40:54 2014 -0800
Merge pull request #1 from obscuren/master
Update trietest.txt
commit 7613302b491b3f6406b1ea3c8292adf6d41860d0
Author: obscuren <obscuren@users.noreply.github.com>
Date: Wed Jan 1 15:25:21 2014 +0100
Update trietest.txt
New proposed explanatory format
commit 121632bedd1c84a0af847b923aa4b803556722c0
Author: Vitalik Buterin <v@buterin.com>
Date: Wed Jan 1 08:26:18 2014 -0500
Added obscure's tests
commit ef6c5506c3fcdecf779184ad81d92db9315c2488
Author: Vitalik Buterin <v@buterin.com>
Date: Tue Dec 31 19:04:48 2013 -0500
Fixed tests a bit
commit 345e4bcfefb45a66a09b1761570405a03c67b9d2
Merge: 2c81698 e4bbea4
Author: Vitalik Buterin <v@buterin.com>
Date: Tue Dec 31 15:52:46 2013 -0500
Merge branch 'master' of github.com:ethereum/tests
commit 2c81698f31e7e579335a2ab8706f96397a68f018
Author: Vitalik Buterin <v@buterin.com>
Date: Mon Dec 30 21:09:40 2013 -0500
Added first three tests
commit e4bbea400f7df275faf47ea643256d68495b35aa
Author: vbuterin <v@buterin.com>
Date: Mon Dec 30 18:09:03 2013 -0800
Initial commit
2014-11-04 10:11:19 -06:00
|
|
|
if self.Recoverable {
|
|
|
|
// Recover from any require exception
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
self.Endl()
|
|
|
|
|
|
|
|
ret = closure.Return(nil)
|
|
|
|
|
|
|
|
err = fmt.Errorf("%v", r)
|
|
|
|
// No error should be set. Recover is used with require
|
|
|
|
// Is this too error prone?
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
var (
|
|
|
|
op OpCode
|
|
|
|
|
2014-11-04 11:18:57 -06:00
|
|
|
destinations = analyseJumpDests(closure.Code)
|
|
|
|
mem = &Memory{}
|
|
|
|
stack = NewStack()
|
|
|
|
pc = big.NewInt(0)
|
|
|
|
step = 0
|
|
|
|
prevStep = 0
|
|
|
|
statedb = self.env.State()
|
|
|
|
require = func(m int) {
|
2014-10-15 10:12:26 -05:00
|
|
|
if stack.Len() < m {
|
|
|
|
panic(fmt.Sprintf("%04v (%v) stack err size = %d, required = %d", pc, op, stack.Len(), m))
|
|
|
|
}
|
|
|
|
}
|
2014-10-16 11:27:05 -05:00
|
|
|
|
2014-11-04 11:18:57 -06:00
|
|
|
jump = func(from, to *big.Int) {
|
|
|
|
p := int(to.Int64())
|
2014-10-16 11:27:05 -05:00
|
|
|
|
2014-11-04 11:18:57 -06:00
|
|
|
self.Printf(" ~> %v", to)
|
2014-10-16 11:27:05 -05:00
|
|
|
// Return to start
|
|
|
|
if p == 0 {
|
|
|
|
pc = big.NewInt(0)
|
|
|
|
} else {
|
2014-11-04 11:18:57 -06:00
|
|
|
nop := OpCode(closure.GetOp(p))
|
|
|
|
if !(nop == JUMPDEST || destinations[from.Int64()] != nil) {
|
2014-10-16 11:27:05 -05:00
|
|
|
panic(fmt.Sprintf("JUMP missed JUMPDEST (%v) %v", nop, p))
|
|
|
|
}
|
|
|
|
|
2014-11-04 11:18:57 -06:00
|
|
|
pc = to
|
|
|
|
|
2014-10-16 11:27:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
self.Endl()
|
|
|
|
}
|
2014-10-15 10:12:26 -05:00
|
|
|
)
|
|
|
|
|
2014-10-14 04:48:52 -05:00
|
|
|
// Debug hook
|
|
|
|
if self.Dbg != nil {
|
|
|
|
self.Dbg.SetCode(closure.Code)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't bother with the execution if there's no code.
|
|
|
|
if len(closure.Code) == 0 {
|
|
|
|
return closure.Return(nil), nil
|
|
|
|
}
|
|
|
|
|
2014-10-20 04:53:11 -05:00
|
|
|
vmlogger.Debugf("(%d) %x gas: %v (d) %x\n", self.depth, closure.Address(), closure.Gas, closure.Args)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
for {
|
|
|
|
prevStep = step
|
|
|
|
// The base for all big integer arithmetic
|
|
|
|
base := new(big.Int)
|
|
|
|
|
|
|
|
step++
|
|
|
|
// Get the memory location of pc
|
2014-10-23 07:04:00 -05:00
|
|
|
op = closure.GetOp(int(pc.Uint64()))
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
// XXX Leave this Println intact. Don't change this to the log system.
|
|
|
|
// Used for creating diffs between implementations
|
|
|
|
if self.logTy == LogTyDiff {
|
|
|
|
switch op {
|
|
|
|
case STOP, RETURN, SUICIDE:
|
2014-10-31 08:43:14 -05:00
|
|
|
statedb.GetStateObject(closure.Address()).EachStorage(func(key string, value *ethutil.Value) {
|
2014-10-14 04:48:52 -05:00
|
|
|
value.Decode()
|
|
|
|
fmt.Printf("%x %x\n", new(big.Int).SetBytes([]byte(key)).Bytes(), value.Bytes())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
b := pc.Bytes()
|
|
|
|
if len(b) == 0 {
|
|
|
|
b = []byte{0}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%x %x %x %x\n", closure.Address(), b, []byte{byte(op)}, closure.Gas.Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
gas := new(big.Int)
|
|
|
|
addStepGasUsage := func(amount *big.Int) {
|
|
|
|
if amount.Cmp(ethutil.Big0) >= 0 {
|
|
|
|
gas.Add(gas, amount)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addStepGasUsage(GasStep)
|
|
|
|
|
|
|
|
var newMemSize *big.Int = ethutil.Big0
|
2014-10-23 03:14:55 -05:00
|
|
|
// Stack Check, memory resize & gas phase
|
2014-10-14 04:48:52 -05:00
|
|
|
switch op {
|
2014-10-23 03:14:55 -05:00
|
|
|
// Stack checks only
|
2014-10-31 19:18:03 -05:00
|
|
|
case ISZERO, CALLDATALOAD, POP, JUMP, NOT: // 1
|
2014-10-23 03:14:55 -05:00
|
|
|
require(1)
|
|
|
|
case ADD, SUB, DIV, SDIV, MOD, SMOD, EXP, LT, GT, SLT, SGT, EQ, AND, OR, XOR, BYTE: // 2
|
|
|
|
require(2)
|
|
|
|
case ADDMOD, MULMOD: // 3
|
|
|
|
require(3)
|
|
|
|
case SWAP1, SWAP2, SWAP3, SWAP4, SWAP5, SWAP6, SWAP7, SWAP8, SWAP9, SWAP10, SWAP11, SWAP12, SWAP13, SWAP14, SWAP15, SWAP16:
|
|
|
|
n := int(op - SWAP1 + 2)
|
|
|
|
require(n)
|
|
|
|
case DUP1, DUP2, DUP3, DUP4, DUP5, DUP6, DUP7, DUP8, DUP9, DUP10, DUP11, DUP12, DUP13, DUP14, DUP15, DUP16:
|
|
|
|
n := int(op - DUP1 + 1)
|
|
|
|
require(n)
|
2014-10-27 05:44:16 -05:00
|
|
|
case LOG0, LOG1, LOG2, LOG3, LOG4:
|
|
|
|
n := int(op - LOG0)
|
|
|
|
require(n + 2)
|
|
|
|
|
|
|
|
mSize, mStart := stack.Peekn()
|
|
|
|
gas.Set(GasLog)
|
|
|
|
addStepGasUsage(new(big.Int).Mul(big.NewInt(int64(n)), GasLog))
|
|
|
|
addStepGasUsage(new(big.Int).Add(mSize, mStart))
|
2014-10-23 03:14:55 -05:00
|
|
|
// Gas only
|
2014-10-14 04:48:52 -05:00
|
|
|
case STOP:
|
|
|
|
gas.Set(ethutil.Big0)
|
|
|
|
case SUICIDE:
|
2014-10-23 03:14:55 -05:00
|
|
|
require(1)
|
|
|
|
|
2014-10-14 04:48:52 -05:00
|
|
|
gas.Set(ethutil.Big0)
|
|
|
|
case SLOAD:
|
2014-10-28 07:26:30 -05:00
|
|
|
require(1)
|
|
|
|
|
2014-10-14 04:48:52 -05:00
|
|
|
gas.Set(GasSLoad)
|
2014-10-23 03:14:55 -05:00
|
|
|
// Memory resize & Gas
|
2014-10-14 04:48:52 -05:00
|
|
|
case SSTORE:
|
2014-10-28 07:26:30 -05:00
|
|
|
require(2)
|
|
|
|
|
2014-10-14 04:48:52 -05:00
|
|
|
var mult *big.Int
|
|
|
|
y, x := stack.Peekn()
|
|
|
|
val := closure.GetStorage(x)
|
|
|
|
if val.BigInt().Cmp(ethutil.Big0) == 0 && len(y.Bytes()) > 0 {
|
2014-10-27 05:44:16 -05:00
|
|
|
// 0 => non 0
|
|
|
|
mult = ethutil.Big3
|
2014-10-14 04:48:52 -05:00
|
|
|
} else if val.BigInt().Cmp(ethutil.Big0) != 0 && len(y.Bytes()) == 0 {
|
2014-10-31 08:43:14 -05:00
|
|
|
statedb.Refund(closure.caller.Address(), GasSStoreRefund, closure.Price)
|
2014-10-28 07:22:04 -05:00
|
|
|
|
2014-10-14 04:48:52 -05:00
|
|
|
mult = ethutil.Big0
|
|
|
|
} else {
|
2014-10-27 05:44:16 -05:00
|
|
|
// non 0 => non 0
|
2014-10-14 04:48:52 -05:00
|
|
|
mult = ethutil.Big1
|
|
|
|
}
|
2014-10-27 05:44:16 -05:00
|
|
|
gas.Set(new(big.Int).Mul(mult, GasSStore))
|
2014-10-14 04:48:52 -05:00
|
|
|
case BALANCE:
|
2014-10-23 03:14:55 -05:00
|
|
|
require(1)
|
2014-10-14 04:48:52 -05:00
|
|
|
gas.Set(GasBalance)
|
|
|
|
case MSTORE:
|
|
|
|
require(2)
|
|
|
|
newMemSize = calcMemSize(stack.Peek(), u256(32))
|
|
|
|
case MLOAD:
|
|
|
|
require(1)
|
|
|
|
|
|
|
|
newMemSize = calcMemSize(stack.Peek(), u256(32))
|
|
|
|
case MSTORE8:
|
|
|
|
require(2)
|
|
|
|
newMemSize = calcMemSize(stack.Peek(), u256(1))
|
|
|
|
case RETURN:
|
|
|
|
require(2)
|
|
|
|
|
|
|
|
newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-2])
|
|
|
|
case SHA3:
|
|
|
|
require(2)
|
|
|
|
|
|
|
|
gas.Set(GasSha)
|
|
|
|
|
|
|
|
newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-2])
|
|
|
|
case CALLDATACOPY:
|
|
|
|
require(2)
|
|
|
|
|
|
|
|
newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-3])
|
|
|
|
case CODECOPY:
|
|
|
|
require(3)
|
|
|
|
|
|
|
|
newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-3])
|
|
|
|
case EXTCODECOPY:
|
|
|
|
require(4)
|
|
|
|
|
|
|
|
newMemSize = calcMemSize(stack.data[stack.Len()-2], stack.data[stack.Len()-4])
|
|
|
|
case CALL, CALLCODE:
|
|
|
|
require(7)
|
|
|
|
gas.Set(GasCall)
|
|
|
|
addStepGasUsage(stack.data[stack.Len()-1])
|
|
|
|
|
|
|
|
x := calcMemSize(stack.data[stack.Len()-6], stack.data[stack.Len()-7])
|
|
|
|
y := calcMemSize(stack.data[stack.Len()-4], stack.data[stack.Len()-5])
|
|
|
|
|
|
|
|
newMemSize = ethutil.BigMax(x, y)
|
|
|
|
case CREATE:
|
|
|
|
require(3)
|
|
|
|
gas.Set(GasCreate)
|
|
|
|
|
|
|
|
newMemSize = calcMemSize(stack.data[stack.Len()-2], stack.data[stack.Len()-3])
|
|
|
|
}
|
|
|
|
|
|
|
|
if newMemSize.Cmp(ethutil.Big0) > 0 {
|
|
|
|
newMemSize.Add(newMemSize, u256(31))
|
|
|
|
newMemSize.Div(newMemSize, u256(32))
|
|
|
|
newMemSize.Mul(newMemSize, u256(32))
|
|
|
|
|
|
|
|
if newMemSize.Cmp(u256(int64(mem.Len()))) > 0 {
|
|
|
|
memGasUsage := new(big.Int).Sub(newMemSize, u256(int64(mem.Len())))
|
|
|
|
memGasUsage.Mul(GasMemory, memGasUsage)
|
|
|
|
memGasUsage.Div(memGasUsage, u256(32))
|
|
|
|
|
|
|
|
addStepGasUsage(memGasUsage)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-16 06:38:21 -05:00
|
|
|
self.Printf("(pc) %-3d -o- %-14s", pc, op.String())
|
|
|
|
self.Printf(" (g) %-3v (%v)", gas, closure.Gas)
|
|
|
|
|
2014-10-14 04:48:52 -05:00
|
|
|
if !closure.UseGas(gas) {
|
2014-10-16 06:38:21 -05:00
|
|
|
self.Endl()
|
|
|
|
|
2014-10-23 07:04:00 -05:00
|
|
|
tmp := new(big.Int).Set(closure.Gas)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
closure.UseGas(closure.Gas)
|
|
|
|
|
2014-10-23 07:04:00 -05:00
|
|
|
return closure.Return(nil), OOG(gas, tmp)
|
2014-10-14 04:48:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
mem.Resize(newMemSize.Uint64())
|
|
|
|
|
|
|
|
switch op {
|
2014-10-22 18:01:26 -05:00
|
|
|
// 0x20 range
|
2014-10-14 04:48:52 -05:00
|
|
|
case ADD:
|
|
|
|
x, y := stack.Popn()
|
|
|
|
self.Printf(" %v + %v", y, x)
|
|
|
|
|
|
|
|
base.Add(y, x)
|
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
U256(base)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" = %v", base)
|
|
|
|
// Pop result back on the stack
|
|
|
|
stack.Push(base)
|
|
|
|
case SUB:
|
|
|
|
x, y := stack.Popn()
|
|
|
|
self.Printf(" %v - %v", y, x)
|
|
|
|
|
|
|
|
base.Sub(y, x)
|
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
U256(base)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" = %v", base)
|
|
|
|
// Pop result back on the stack
|
|
|
|
stack.Push(base)
|
|
|
|
case MUL:
|
|
|
|
x, y := stack.Popn()
|
|
|
|
self.Printf(" %v * %v", y, x)
|
|
|
|
|
|
|
|
base.Mul(y, x)
|
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
U256(base)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" = %v", base)
|
|
|
|
// Pop result back on the stack
|
|
|
|
stack.Push(base)
|
|
|
|
case DIV:
|
2014-10-15 10:12:26 -05:00
|
|
|
x, y := stack.Pop(), stack.Pop()
|
|
|
|
self.Printf(" %v / %v", x, y)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
if y.Cmp(ethutil.Big0) != 0 {
|
|
|
|
base.Div(x, y)
|
2014-10-14 04:48:52 -05:00
|
|
|
}
|
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
U256(base)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" = %v", base)
|
|
|
|
// Pop result back on the stack
|
|
|
|
stack.Push(base)
|
|
|
|
case SDIV:
|
2014-10-15 10:12:26 -05:00
|
|
|
x, y := S256(stack.Pop()), S256(stack.Pop())
|
2014-10-14 04:48:52 -05:00
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
self.Printf(" %v / %v", x, y)
|
|
|
|
|
|
|
|
if y.Cmp(ethutil.Big0) == 0 {
|
|
|
|
base.Set(ethutil.Big0)
|
|
|
|
} else {
|
|
|
|
n := new(big.Int)
|
|
|
|
if new(big.Int).Mul(x, y).Cmp(ethutil.Big0) < 0 {
|
|
|
|
n.SetInt64(-1)
|
|
|
|
} else {
|
|
|
|
n.SetInt64(1)
|
|
|
|
}
|
2014-10-14 04:48:52 -05:00
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
base.Div(x.Abs(x), y.Abs(y)).Mul(base, n)
|
|
|
|
|
|
|
|
U256(base)
|
|
|
|
}
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" = %v", base)
|
|
|
|
stack.Push(base)
|
|
|
|
case MOD:
|
2014-10-15 10:12:26 -05:00
|
|
|
x, y := stack.Pop(), stack.Pop()
|
2014-10-14 04:48:52 -05:00
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
self.Printf(" %v %% %v", x, y)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
if y.Cmp(ethutil.Big0) == 0 {
|
|
|
|
base.Set(ethutil.Big0)
|
|
|
|
} else {
|
|
|
|
base.Mod(x, y)
|
|
|
|
}
|
2014-10-14 04:48:52 -05:00
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
U256(base)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" = %v", base)
|
|
|
|
stack.Push(base)
|
|
|
|
case SMOD:
|
2014-10-15 10:12:26 -05:00
|
|
|
x, y := S256(stack.Pop()), S256(stack.Pop())
|
|
|
|
|
|
|
|
self.Printf(" %v %% %v", x, y)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
if y.Cmp(ethutil.Big0) == 0 {
|
|
|
|
base.Set(ethutil.Big0)
|
|
|
|
} else {
|
|
|
|
n := new(big.Int)
|
|
|
|
if x.Cmp(ethutil.Big0) < 0 {
|
|
|
|
n.SetInt64(-1)
|
|
|
|
} else {
|
|
|
|
n.SetInt64(1)
|
|
|
|
}
|
2014-10-14 04:48:52 -05:00
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
base.Mod(x.Abs(x), y.Abs(y)).Mul(base, n)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
U256(base)
|
|
|
|
}
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" = %v", base)
|
|
|
|
stack.Push(base)
|
|
|
|
|
|
|
|
case EXP:
|
|
|
|
x, y := stack.Popn()
|
|
|
|
|
|
|
|
self.Printf(" %v ** %v", y, x)
|
|
|
|
|
|
|
|
base.Exp(y, x, Pow256)
|
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
U256(base)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" = %v", base)
|
|
|
|
|
|
|
|
stack.Push(base)
|
2014-10-31 20:14:55 -05:00
|
|
|
case SIGNEXTEND:
|
|
|
|
back := stack.Pop().Uint64()
|
2014-11-02 12:39:45 -06:00
|
|
|
if back < 31 {
|
2014-10-31 20:14:55 -05:00
|
|
|
bit := uint(back*8 + 7)
|
|
|
|
num := stack.Pop()
|
|
|
|
mask := new(big.Int).Lsh(ethutil.Big1, bit)
|
|
|
|
mask.Sub(mask, ethutil.Big1)
|
|
|
|
if ethutil.BitTest(num, int(bit)) {
|
|
|
|
num.Or(num, mask.Not(mask))
|
|
|
|
} else {
|
|
|
|
num.And(num, mask)
|
|
|
|
}
|
2014-11-04 11:18:57 -06:00
|
|
|
|
|
|
|
num = U256(num)
|
|
|
|
|
|
|
|
self.Printf(" = %v", num)
|
|
|
|
|
2014-10-31 20:14:55 -05:00
|
|
|
stack.Push(num)
|
|
|
|
}
|
2014-10-31 19:18:03 -05:00
|
|
|
case NOT:
|
2014-10-27 05:44:16 -05:00
|
|
|
base.Sub(Pow256, stack.Pop()).Sub(base, ethutil.Big1)
|
2014-10-15 10:12:26 -05:00
|
|
|
|
2014-10-27 05:44:16 -05:00
|
|
|
// Not needed
|
|
|
|
//base = U256(base)
|
2014-10-15 10:12:26 -05:00
|
|
|
|
2014-10-14 04:48:52 -05:00
|
|
|
stack.Push(base)
|
|
|
|
case LT:
|
|
|
|
x, y := stack.Popn()
|
|
|
|
self.Printf(" %v < %v", y, x)
|
|
|
|
// x < y
|
|
|
|
if y.Cmp(x) < 0 {
|
|
|
|
stack.Push(ethutil.BigTrue)
|
|
|
|
} else {
|
|
|
|
stack.Push(ethutil.BigFalse)
|
|
|
|
}
|
|
|
|
case GT:
|
|
|
|
x, y := stack.Popn()
|
|
|
|
self.Printf(" %v > %v", y, x)
|
|
|
|
|
|
|
|
// x > y
|
|
|
|
if y.Cmp(x) > 0 {
|
|
|
|
stack.Push(ethutil.BigTrue)
|
|
|
|
} else {
|
|
|
|
stack.Push(ethutil.BigFalse)
|
|
|
|
}
|
|
|
|
|
|
|
|
case SLT:
|
2014-10-15 10:12:26 -05:00
|
|
|
y, x := S256(stack.Pop()), S256(stack.Pop())
|
2014-10-14 04:48:52 -05:00
|
|
|
self.Printf(" %v < %v", y, x)
|
|
|
|
// x < y
|
2014-10-15 10:12:26 -05:00
|
|
|
if y.Cmp(S256(x)) < 0 {
|
2014-10-14 04:48:52 -05:00
|
|
|
stack.Push(ethutil.BigTrue)
|
|
|
|
} else {
|
|
|
|
stack.Push(ethutil.BigFalse)
|
|
|
|
}
|
|
|
|
case SGT:
|
2014-10-15 10:12:26 -05:00
|
|
|
y, x := S256(stack.Pop()), S256(stack.Pop())
|
2014-10-14 04:48:52 -05:00
|
|
|
self.Printf(" %v > %v", y, x)
|
|
|
|
|
|
|
|
// x > y
|
|
|
|
if y.Cmp(x) > 0 {
|
|
|
|
stack.Push(ethutil.BigTrue)
|
|
|
|
} else {
|
|
|
|
stack.Push(ethutil.BigFalse)
|
|
|
|
}
|
|
|
|
|
|
|
|
case EQ:
|
|
|
|
x, y := stack.Popn()
|
|
|
|
self.Printf(" %v == %v", y, x)
|
|
|
|
|
|
|
|
// x == y
|
|
|
|
if x.Cmp(y) == 0 {
|
|
|
|
stack.Push(ethutil.BigTrue)
|
|
|
|
} else {
|
|
|
|
stack.Push(ethutil.BigFalse)
|
|
|
|
}
|
2014-10-31 19:18:03 -05:00
|
|
|
case ISZERO:
|
2014-10-14 04:48:52 -05:00
|
|
|
x := stack.Pop()
|
|
|
|
if x.Cmp(ethutil.BigFalse) > 0 {
|
|
|
|
stack.Push(ethutil.BigFalse)
|
|
|
|
} else {
|
|
|
|
stack.Push(ethutil.BigTrue)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x10 range
|
|
|
|
case AND:
|
|
|
|
x, y := stack.Popn()
|
|
|
|
self.Printf(" %v & %v", y, x)
|
|
|
|
|
|
|
|
stack.Push(base.And(y, x))
|
|
|
|
case OR:
|
|
|
|
x, y := stack.Popn()
|
|
|
|
self.Printf(" %v | %v", y, x)
|
|
|
|
|
|
|
|
stack.Push(base.Or(y, x))
|
|
|
|
case XOR:
|
|
|
|
x, y := stack.Popn()
|
|
|
|
self.Printf(" %v ^ %v", y, x)
|
|
|
|
|
|
|
|
stack.Push(base.Xor(y, x))
|
|
|
|
case BYTE:
|
|
|
|
val, th := stack.Popn()
|
2014-10-16 11:27:05 -05:00
|
|
|
|
|
|
|
if th.Cmp(big.NewInt(32)) < 0 {
|
2014-10-14 04:48:52 -05:00
|
|
|
byt := big.NewInt(int64(ethutil.LeftPadBytes(val.Bytes(), 32)[th.Int64()]))
|
|
|
|
|
2014-10-16 11:27:05 -05:00
|
|
|
base.Set(byt)
|
2014-10-14 04:48:52 -05:00
|
|
|
} else {
|
2014-10-16 11:27:05 -05:00
|
|
|
base.Set(ethutil.BigFalse)
|
2014-10-14 04:48:52 -05:00
|
|
|
}
|
2014-10-16 11:27:05 -05:00
|
|
|
|
|
|
|
self.Printf(" => 0x%x", base.Bytes())
|
|
|
|
|
|
|
|
stack.Push(base)
|
2014-10-14 04:48:52 -05:00
|
|
|
case ADDMOD:
|
|
|
|
|
|
|
|
x := stack.Pop()
|
|
|
|
y := stack.Pop()
|
|
|
|
z := stack.Pop()
|
|
|
|
|
|
|
|
base.Add(x, y)
|
|
|
|
base.Mod(base, z)
|
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
U256(base)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" = %v", base)
|
|
|
|
|
|
|
|
stack.Push(base)
|
|
|
|
case MULMOD:
|
|
|
|
|
|
|
|
x := stack.Pop()
|
|
|
|
y := stack.Pop()
|
|
|
|
z := stack.Pop()
|
|
|
|
|
|
|
|
base.Mul(x, y)
|
|
|
|
base.Mod(base, z)
|
|
|
|
|
2014-10-15 10:12:26 -05:00
|
|
|
U256(base)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" = %v", base)
|
|
|
|
|
|
|
|
stack.Push(base)
|
|
|
|
|
|
|
|
// 0x20 range
|
|
|
|
case SHA3:
|
|
|
|
size, offset := stack.Popn()
|
2014-10-31 06:37:43 -05:00
|
|
|
data := crypto.Sha3(mem.Get(offset.Int64(), size.Int64()))
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
stack.Push(ethutil.BigD(data))
|
|
|
|
|
|
|
|
self.Printf(" => %x", data)
|
|
|
|
// 0x30 range
|
|
|
|
case ADDRESS:
|
|
|
|
stack.Push(ethutil.BigD(closure.Address()))
|
|
|
|
|
|
|
|
self.Printf(" => %x", closure.Address())
|
|
|
|
case BALANCE:
|
|
|
|
|
|
|
|
addr := stack.Pop().Bytes()
|
2014-10-31 08:43:14 -05:00
|
|
|
balance := statedb.GetBalance(addr)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
stack.Push(balance)
|
|
|
|
|
|
|
|
self.Printf(" => %v (%x)", balance, addr)
|
|
|
|
case ORIGIN:
|
|
|
|
origin := self.env.Origin()
|
|
|
|
|
|
|
|
stack.Push(ethutil.BigD(origin))
|
|
|
|
|
|
|
|
self.Printf(" => %x", origin)
|
|
|
|
case CALLER:
|
|
|
|
caller := closure.caller.Address()
|
|
|
|
stack.Push(ethutil.BigD(caller))
|
|
|
|
|
|
|
|
self.Printf(" => %x", caller)
|
|
|
|
case CALLVALUE:
|
2014-10-14 17:40:41 -05:00
|
|
|
value := closure.exe.value
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
stack.Push(value)
|
|
|
|
|
|
|
|
self.Printf(" => %v", value)
|
|
|
|
case CALLDATALOAD:
|
|
|
|
var (
|
|
|
|
offset = stack.Pop()
|
|
|
|
data = make([]byte, 32)
|
|
|
|
lenData = big.NewInt(int64(len(closure.Args)))
|
|
|
|
)
|
|
|
|
|
|
|
|
if lenData.Cmp(offset) >= 0 {
|
|
|
|
length := new(big.Int).Add(offset, ethutil.Big32)
|
|
|
|
length = ethutil.BigMin(length, lenData)
|
|
|
|
|
|
|
|
copy(data, closure.Args[offset.Int64():length.Int64()])
|
|
|
|
}
|
|
|
|
|
|
|
|
self.Printf(" => 0x%x", data)
|
|
|
|
|
|
|
|
stack.Push(ethutil.BigD(data))
|
|
|
|
case CALLDATASIZE:
|
|
|
|
l := int64(len(closure.Args))
|
|
|
|
stack.Push(big.NewInt(l))
|
|
|
|
|
|
|
|
self.Printf(" => %d", l)
|
|
|
|
case CALLDATACOPY:
|
|
|
|
var (
|
|
|
|
size = int64(len(closure.Args))
|
|
|
|
mOff = stack.Pop().Int64()
|
|
|
|
cOff = stack.Pop().Int64()
|
|
|
|
l = stack.Pop().Int64()
|
|
|
|
)
|
|
|
|
|
|
|
|
if cOff > size {
|
|
|
|
cOff = 0
|
|
|
|
l = 0
|
|
|
|
} else if cOff+l > size {
|
|
|
|
l = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
code := closure.Args[cOff : cOff+l]
|
|
|
|
|
|
|
|
mem.Set(mOff, l, code)
|
|
|
|
case CODESIZE, EXTCODESIZE:
|
|
|
|
var code []byte
|
2014-10-16 11:27:05 -05:00
|
|
|
if op == EXTCODESIZE {
|
2014-10-14 04:48:52 -05:00
|
|
|
addr := stack.Pop().Bytes()
|
|
|
|
|
2014-10-31 08:43:14 -05:00
|
|
|
code = statedb.GetCode(addr)
|
2014-10-14 04:48:52 -05:00
|
|
|
} else {
|
|
|
|
code = closure.Code
|
|
|
|
}
|
|
|
|
|
|
|
|
l := big.NewInt(int64(len(code)))
|
|
|
|
stack.Push(l)
|
|
|
|
|
|
|
|
self.Printf(" => %d", l)
|
|
|
|
case CODECOPY, EXTCODECOPY:
|
|
|
|
var code []byte
|
|
|
|
if op == EXTCODECOPY {
|
|
|
|
addr := stack.Pop().Bytes()
|
|
|
|
|
2014-10-31 08:43:14 -05:00
|
|
|
code = statedb.GetCode(addr)
|
2014-10-14 04:48:52 -05:00
|
|
|
} else {
|
|
|
|
code = closure.Code
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
size = int64(len(code))
|
|
|
|
mOff = stack.Pop().Int64()
|
|
|
|
cOff = stack.Pop().Int64()
|
|
|
|
l = stack.Pop().Int64()
|
|
|
|
)
|
|
|
|
|
|
|
|
if cOff > size {
|
|
|
|
cOff = 0
|
|
|
|
l = 0
|
|
|
|
} else if cOff+l > size {
|
|
|
|
l = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
codeCopy := code[cOff : cOff+l]
|
|
|
|
|
|
|
|
mem.Set(mOff, l, codeCopy)
|
|
|
|
case GASPRICE:
|
|
|
|
stack.Push(closure.Price)
|
|
|
|
|
|
|
|
self.Printf(" => %v", closure.Price)
|
|
|
|
|
|
|
|
// 0x40 range
|
|
|
|
case PREVHASH:
|
|
|
|
prevHash := self.env.PrevHash()
|
|
|
|
|
|
|
|
stack.Push(ethutil.BigD(prevHash))
|
|
|
|
|
|
|
|
self.Printf(" => 0x%x", prevHash)
|
|
|
|
case COINBASE:
|
|
|
|
coinbase := self.env.Coinbase()
|
|
|
|
|
|
|
|
stack.Push(ethutil.BigD(coinbase))
|
|
|
|
|
|
|
|
self.Printf(" => 0x%x", coinbase)
|
|
|
|
case TIMESTAMP:
|
|
|
|
time := self.env.Time()
|
|
|
|
|
|
|
|
stack.Push(big.NewInt(time))
|
|
|
|
|
|
|
|
self.Printf(" => 0x%x", time)
|
|
|
|
case NUMBER:
|
|
|
|
number := self.env.BlockNumber()
|
|
|
|
|
|
|
|
stack.Push(number)
|
|
|
|
|
|
|
|
self.Printf(" => 0x%x", number.Bytes())
|
|
|
|
case DIFFICULTY:
|
|
|
|
difficulty := self.env.Difficulty()
|
|
|
|
|
|
|
|
stack.Push(difficulty)
|
|
|
|
|
|
|
|
self.Printf(" => 0x%x", difficulty.Bytes())
|
|
|
|
case GASLIMIT:
|
2014-10-16 11:27:05 -05:00
|
|
|
stack.Push(self.env.GasLimit())
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
// 0x50 range
|
|
|
|
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
|
|
|
|
a := big.NewInt(int64(op) - int64(PUSH1) + 1)
|
|
|
|
pc.Add(pc, ethutil.Big1)
|
|
|
|
data := closure.Gets(pc, a)
|
|
|
|
val := ethutil.BigD(data.Bytes())
|
|
|
|
// Push value to stack
|
|
|
|
stack.Push(val)
|
|
|
|
pc.Add(pc, a.Sub(a, big.NewInt(1)))
|
|
|
|
|
|
|
|
step += int(op) - int(PUSH1) + 1
|
|
|
|
|
|
|
|
self.Printf(" => 0x%x", data.Bytes())
|
|
|
|
case POP:
|
|
|
|
stack.Pop()
|
|
|
|
case DUP1, DUP2, DUP3, DUP4, DUP5, DUP6, DUP7, DUP8, DUP9, DUP10, DUP11, DUP12, DUP13, DUP14, DUP15, DUP16:
|
|
|
|
n := int(op - DUP1 + 1)
|
|
|
|
v := stack.Dupn(n)
|
|
|
|
|
|
|
|
self.Printf(" => [%d] 0x%x", n, stack.Peek().Bytes())
|
|
|
|
|
|
|
|
if OpCode(closure.Get(new(big.Int).Add(pc, ethutil.Big1)).Uint()) == POP && OpCode(closure.Get(new(big.Int).Add(pc, big.NewInt(2))).Uint()) == POP {
|
|
|
|
fmt.Println(toValue(v))
|
|
|
|
}
|
|
|
|
case SWAP1, SWAP2, SWAP3, SWAP4, SWAP5, SWAP6, SWAP7, SWAP8, SWAP9, SWAP10, SWAP11, SWAP12, SWAP13, SWAP14, SWAP15, SWAP16:
|
|
|
|
n := int(op - SWAP1 + 2)
|
|
|
|
x, y := stack.Swapn(n)
|
|
|
|
|
|
|
|
self.Printf(" => [%d] %x [0] %x", n, x.Bytes(), y.Bytes())
|
2014-10-27 05:44:16 -05:00
|
|
|
case LOG0, LOG1, LOG2, LOG3, LOG4:
|
|
|
|
n := int(op - LOG0)
|
2014-10-29 04:34:40 -05:00
|
|
|
topics := make([][]byte, n)
|
2014-10-27 05:44:16 -05:00
|
|
|
mSize, mStart := stack.Pop().Int64(), stack.Pop().Int64()
|
|
|
|
data := mem.Geti(mStart, mSize)
|
|
|
|
for i := 0; i < n; i++ {
|
2014-10-29 04:34:40 -05:00
|
|
|
topics[i] = stack.Pop().Bytes()
|
2014-10-27 05:44:16 -05:00
|
|
|
}
|
2014-10-31 08:43:14 -05:00
|
|
|
self.env.AddLog(state.Log{closure.Address(), topics, data})
|
2014-10-14 04:48:52 -05:00
|
|
|
case MLOAD:
|
|
|
|
offset := stack.Pop()
|
|
|
|
val := ethutil.BigD(mem.Get(offset.Int64(), 32))
|
|
|
|
stack.Push(val)
|
|
|
|
|
|
|
|
self.Printf(" => 0x%x", val.Bytes())
|
|
|
|
case MSTORE: // Store the value at stack top-1 in to memory at location stack top
|
|
|
|
// Pop value of the stack
|
|
|
|
val, mStart := stack.Popn()
|
|
|
|
mem.Set(mStart.Int64(), 32, ethutil.BigToBytes(val, 256))
|
|
|
|
|
|
|
|
self.Printf(" => 0x%x", val)
|
|
|
|
case MSTORE8:
|
|
|
|
off := stack.Pop()
|
|
|
|
val := stack.Pop()
|
|
|
|
|
|
|
|
mem.store[off.Int64()] = byte(val.Int64() & 0xff)
|
|
|
|
|
|
|
|
self.Printf(" => [%v] 0x%x", off, val)
|
|
|
|
case SLOAD:
|
|
|
|
loc := stack.Pop()
|
2014-10-31 08:43:14 -05:00
|
|
|
val := ethutil.BigD(statedb.GetState(closure.Address(), loc.Bytes()))
|
2014-10-16 06:38:21 -05:00
|
|
|
stack.Push(val)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" {0x%x : 0x%x}", loc.Bytes(), val.Bytes())
|
|
|
|
case SSTORE:
|
|
|
|
val, loc := stack.Popn()
|
2014-10-31 08:43:14 -05:00
|
|
|
statedb.SetState(closure.Address(), loc.Bytes(), val)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
2014-10-14 17:40:41 -05:00
|
|
|
// Debug sessions are allowed to run without message
|
|
|
|
if closure.message != nil {
|
|
|
|
closure.message.AddStorageChange(loc.Bytes())
|
|
|
|
}
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" {0x%x : 0x%x}", loc.Bytes(), val.Bytes())
|
|
|
|
case JUMP:
|
2014-10-16 06:38:21 -05:00
|
|
|
|
2014-11-04 11:18:57 -06:00
|
|
|
jump(pc, stack.Pop())
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
continue
|
|
|
|
case JUMPI:
|
|
|
|
cond, pos := stack.Popn()
|
|
|
|
|
2014-10-16 11:27:05 -05:00
|
|
|
if cond.Cmp(ethutil.BigTrue) >= 0 {
|
2014-11-04 11:18:57 -06:00
|
|
|
jump(pc, pos)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
2014-10-16 11:27:05 -05:00
|
|
|
|
2014-10-14 04:48:52 -05:00
|
|
|
case JUMPDEST:
|
|
|
|
case PC:
|
|
|
|
stack.Push(pc)
|
|
|
|
case MSIZE:
|
|
|
|
stack.Push(big.NewInt(int64(mem.Len())))
|
|
|
|
case GAS:
|
|
|
|
stack.Push(closure.Gas)
|
|
|
|
// 0x60 range
|
|
|
|
case CREATE:
|
|
|
|
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
value = stack.Pop()
|
|
|
|
size, offset = stack.Popn()
|
|
|
|
input = mem.Get(offset.Int64(), size.Int64())
|
|
|
|
gas = new(big.Int).Set(closure.Gas)
|
|
|
|
|
|
|
|
// Snapshot the current stack so we are able to
|
|
|
|
// revert back to it later.
|
|
|
|
//snapshot = self.env.State().Copy()
|
|
|
|
)
|
|
|
|
|
|
|
|
// Generate a new address
|
2014-10-31 08:43:14 -05:00
|
|
|
n := statedb.GetNonce(closure.Address())
|
2014-10-31 06:37:43 -05:00
|
|
|
addr := crypto.CreateAddress(closure.Address(), n)
|
2014-10-31 08:43:14 -05:00
|
|
|
statedb.SetNonce(closure.Address(), n+1)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
self.Printf(" (*) %x", addr).Endl()
|
|
|
|
|
|
|
|
closure.UseGas(closure.Gas)
|
|
|
|
|
|
|
|
msg := NewExecution(self, addr, input, gas, closure.Price, value)
|
2014-10-16 11:27:05 -05:00
|
|
|
ret, err := msg.Create(closure)
|
2014-10-14 04:48:52 -05:00
|
|
|
if err != nil {
|
|
|
|
stack.Push(ethutil.BigFalse)
|
|
|
|
|
|
|
|
// Revert the state as it was before.
|
|
|
|
//self.env.State().Set(snapshot)
|
|
|
|
|
|
|
|
self.Printf("CREATE err %v", err)
|
|
|
|
} else {
|
|
|
|
msg.object.Code = ret
|
|
|
|
|
|
|
|
stack.Push(ethutil.BigD(addr))
|
|
|
|
}
|
|
|
|
|
|
|
|
self.Endl()
|
|
|
|
|
|
|
|
// Debug hook
|
|
|
|
if self.Dbg != nil {
|
|
|
|
self.Dbg.SetCode(closure.Code)
|
|
|
|
}
|
|
|
|
case CALL, CALLCODE:
|
|
|
|
self.Endl()
|
|
|
|
|
|
|
|
gas := stack.Pop()
|
|
|
|
// Pop gas and value of the stack.
|
|
|
|
value, addr := stack.Popn()
|
|
|
|
// Pop input size and offset
|
|
|
|
inSize, inOffset := stack.Popn()
|
|
|
|
// Pop return size and offset
|
|
|
|
retSize, retOffset := stack.Popn()
|
|
|
|
|
|
|
|
// Get the arguments from the memory
|
|
|
|
args := mem.Get(inOffset.Int64(), inSize.Int64())
|
|
|
|
|
|
|
|
var executeAddr []byte
|
|
|
|
if op == CALLCODE {
|
|
|
|
executeAddr = closure.Address()
|
|
|
|
} else {
|
|
|
|
executeAddr = addr.Bytes()
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := NewExecution(self, executeAddr, args, gas, closure.Price, value)
|
|
|
|
ret, err := msg.Exec(addr.Bytes(), closure)
|
|
|
|
if err != nil {
|
|
|
|
stack.Push(ethutil.BigFalse)
|
|
|
|
|
2014-10-16 06:38:21 -05:00
|
|
|
vmlogger.Debugln(err)
|
2014-10-14 04:48:52 -05:00
|
|
|
} else {
|
|
|
|
stack.Push(ethutil.BigTrue)
|
|
|
|
|
|
|
|
mem.Set(retOffset.Int64(), retSize.Int64(), ret)
|
|
|
|
}
|
2014-10-16 06:38:21 -05:00
|
|
|
self.Printf("resume %x", closure.Address())
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
// Debug hook
|
|
|
|
if self.Dbg != nil {
|
|
|
|
self.Dbg.SetCode(closure.Code)
|
|
|
|
}
|
|
|
|
|
|
|
|
case RETURN:
|
|
|
|
size, offset := stack.Popn()
|
|
|
|
ret := mem.Get(offset.Int64(), size.Int64())
|
|
|
|
|
|
|
|
self.Printf(" => (%d) 0x%x", len(ret), ret).Endl()
|
|
|
|
|
|
|
|
return closure.Return(ret), nil
|
|
|
|
case SUICIDE:
|
|
|
|
|
2014-10-31 08:43:14 -05:00
|
|
|
receiver := statedb.GetOrNewStateObject(stack.Pop().Bytes())
|
2014-10-14 04:48:52 -05:00
|
|
|
|
2014-10-31 08:43:14 -05:00
|
|
|
receiver.AddAmount(statedb.GetBalance(closure.Address()))
|
|
|
|
statedb.Delete(closure.Address())
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
fallthrough
|
|
|
|
case STOP: // Stop the closure
|
|
|
|
self.Endl()
|
|
|
|
|
|
|
|
return closure.Return(nil), nil
|
|
|
|
default:
|
|
|
|
vmlogger.Debugf("(pc) %-3v Invalid opcode %x\n", pc, op)
|
|
|
|
|
|
|
|
//panic(fmt.Sprintf("Invalid opcode %x", op))
|
2014-10-16 11:27:05 -05:00
|
|
|
closure.ReturnGas(big.NewInt(1), nil)
|
2014-10-14 04:48:52 -05:00
|
|
|
|
|
|
|
return closure.Return(nil), fmt.Errorf("Invalid opcode %x", op)
|
|
|
|
}
|
|
|
|
|
|
|
|
pc.Add(pc, ethutil.Big1)
|
|
|
|
|
|
|
|
self.Endl()
|
|
|
|
|
|
|
|
if self.Dbg != nil {
|
|
|
|
for _, instrNo := range self.Dbg.BreakPoints() {
|
|
|
|
if pc.Cmp(big.NewInt(instrNo)) == 0 {
|
|
|
|
self.Stepping = true
|
|
|
|
|
2014-10-31 08:43:14 -05:00
|
|
|
if !self.Dbg.BreakHook(prevStep, op, mem, stack, statedb.GetStateObject(closure.Address())) {
|
2014-10-14 04:48:52 -05:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
} else if self.Stepping {
|
2014-10-31 08:43:14 -05:00
|
|
|
if !self.Dbg.StepHook(prevStep, op, mem, stack, statedb.GetStateObject(closure.Address())) {
|
2014-10-14 04:48:52 -05:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 06:37:26 -05:00
|
|
|
func (self *DebugVm) Printf(format string, v ...interface{}) VirtualMachine {
|
2014-10-14 04:48:52 -05:00
|
|
|
if self.logTy == LogTyPretty {
|
|
|
|
self.logStr += fmt.Sprintf(format, v...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
2014-10-14 06:37:26 -05:00
|
|
|
func (self *DebugVm) Endl() VirtualMachine {
|
2014-10-14 04:48:52 -05:00
|
|
|
if self.logTy == LogTyPretty {
|
|
|
|
vmlogger.Debugln(self.logStr)
|
|
|
|
self.logStr = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *DebugVm) Env() Environment {
|
|
|
|
return self.env
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *DebugVm) Depth() int {
|
|
|
|
return self.depth
|
|
|
|
}
|