diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-10-01 20:44:53 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-10-01 21:01:58 +0800 |
commit | cb84e3f02953f2df166ae69369d222dcbbd7d78d (patch) | |
tree | 68eb52c91a136e820f3656e394847c4e695afa63 /core/vm | |
parent | d8715fba1a366944a069397775fc52a30358eff3 (diff) | |
download | go-tangerine-cb84e3f02953f2df166ae69369d222dcbbd7d78d.tar.gz go-tangerine-cb84e3f02953f2df166ae69369d222dcbbd7d78d.tar.zst go-tangerine-cb84e3f02953f2df166ae69369d222dcbbd7d78d.zip |
cmd, core, internal, light, tests: avoid hashing the code in the VM
Diffstat (limited to 'core/vm')
-rw-r--r-- | core/vm/contract.go | 11 | ||||
-rw-r--r-- | core/vm/environment.go | 3 | ||||
-rw-r--r-- | core/vm/jit_test.go | 2 | ||||
-rw-r--r-- | core/vm/logger_test.go | 2 | ||||
-rw-r--r-- | core/vm/runtime/runtime.go | 2 | ||||
-rw-r--r-- | core/vm/vm.go | 9 |
6 files changed, 17 insertions, 12 deletions
diff --git a/core/vm/contract.go b/core/vm/contract.go index 844d3f328..70455a4c2 100644 --- a/core/vm/contract.go +++ b/core/vm/contract.go @@ -27,7 +27,7 @@ type ContractRef interface { ReturnGas(*big.Int, *big.Int) Address() common.Address Value() *big.Int - SetCode([]byte) + SetCode(common.Hash, []byte) ForEachStorage(callback func(key, value common.Hash) bool) } @@ -44,8 +44,9 @@ type Contract struct { jumpdests destinations // result of JUMPDEST analysis. Code []byte - Input []byte + CodeHash common.Hash CodeAddr *common.Address + Input []byte value, Gas, UsedGas, Price *big.Int @@ -143,14 +144,16 @@ func (c *Contract) Value() *big.Int { } // SetCode sets the code to the contract -func (self *Contract) SetCode(code []byte) { +func (self *Contract) SetCode(hash common.Hash, code []byte) { self.Code = code + self.CodeHash = hash } // SetCallCode sets the code of the contract and address of the backing data // object -func (self *Contract) SetCallCode(addr *common.Address, code []byte) { +func (self *Contract) SetCallCode(addr *common.Address, hash common.Hash, code []byte) { self.Code = code + self.CodeHash = hash self.CodeAddr = addr } diff --git a/core/vm/environment.go b/core/vm/environment.go index 4bd03de7e..daf6fb90d 100644 --- a/core/vm/environment.go +++ b/core/vm/environment.go @@ -94,6 +94,7 @@ type Database interface { GetNonce(common.Address) uint64 SetNonce(common.Address, uint64) + GetCodeHash(common.Address) common.Hash GetCodeSize(common.Address) int GetCode(common.Address) []byte SetCode(common.Address, []byte) @@ -118,7 +119,7 @@ type Account interface { Balance() *big.Int Address() common.Address ReturnGas(*big.Int, *big.Int) - SetCode([]byte) + SetCode(common.Hash, []byte) ForEachStorage(cb func(key, value common.Hash) bool) Value() *big.Int } diff --git a/core/vm/jit_test.go b/core/vm/jit_test.go index 809abfea9..e6922aeb7 100644 --- a/core/vm/jit_test.go +++ b/core/vm/jit_test.go @@ -135,7 +135,7 @@ func (account) SetNonce(uint64) {} func (account) Balance() *big.Int { return nil } func (account) Address() common.Address { return common.Address{} } func (account) ReturnGas(*big.Int, *big.Int) {} -func (account) SetCode([]byte) {} +func (account) SetCode(common.Hash, []byte) {} func (account) ForEachStorage(cb func(key, value common.Hash) bool) {} func runVmBench(test vmBench, b *testing.B) { diff --git a/core/vm/logger_test.go b/core/vm/logger_test.go index e85bca227..d4d164eb6 100644 --- a/core/vm/logger_test.go +++ b/core/vm/logger_test.go @@ -30,7 +30,7 @@ type dummyContractRef struct { func (dummyContractRef) ReturnGas(*big.Int, *big.Int) {} func (dummyContractRef) Address() common.Address { return common.Address{} } func (dummyContractRef) Value() *big.Int { return new(big.Int) } -func (dummyContractRef) SetCode([]byte) {} +func (dummyContractRef) SetCode(common.Hash, []byte) {} func (d *dummyContractRef) ForEachStorage(callback func(key, value common.Hash) bool) { d.calledForEach = true } diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 309d508c3..6d980cb32 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -104,7 +104,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) { receiver = cfg.State.CreateAccount(common.StringToAddress("contract")) ) // set the receiver's (the executing contract) code for execution. - receiver.SetCode(code) + receiver.SetCode(crypto.Keccak256Hash(code), code) // Call the code with the given configuration. ret, err := vmenv.Call( diff --git a/core/vm/vm.go b/core/vm/vm.go index 9d7b55058..5d78b4a2a 100644 --- a/core/vm/vm.go +++ b/core/vm/vm.go @@ -71,10 +71,11 @@ func (evm *EVM) Run(contract *Contract, input []byte) (ret []byte, err error) { return nil, nil } - var ( - codehash = crypto.Keccak256Hash(contract.Code) // codehash is used when doing jump dest caching - program *Program - ) + codehash := contract.CodeHash // codehash is used when doing jump dest caching + if codehash == (common.Hash{}) { + codehash = crypto.Keccak256Hash(contract.Code) + } + var program *Program if evm.cfg.EnableJit { // If the JIT is enabled check the status of the JIT program, // if it doesn't exist compile a new program in a separate |