From 4186467129c55fcf6e6690addc529252851b9e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 4 Oct 2018 13:32:04 +0200 Subject: [PATCH] Don't hash the init_code of CREATE. (#9688) --- ethcore/evm/src/interpreter/mod.rs | 3 +-- ethcore/evm/src/interpreter/shared_cache.rs | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ethcore/evm/src/interpreter/mod.rs b/ethcore/evm/src/interpreter/mod.rs index 7da3d2a1a..d16615320 100644 --- a/ethcore/evm/src/interpreter/mod.rs +++ b/ethcore/evm/src/interpreter/mod.rs @@ -385,8 +385,7 @@ impl Interpreter { match result { InstructionResult::JumpToPosition(position) => { if self.valid_jump_destinations.is_none() { - let code_hash = self.params.code_hash.clone().unwrap_or_else(|| keccak(self.reader.code.as_ref())); - self.valid_jump_destinations = Some(self.cache.jump_destinations(&code_hash, &self.reader.code)); + self.valid_jump_destinations = Some(self.cache.jump_destinations(&self.params.code_hash, &self.reader.code)); } let jump_destinations = self.valid_jump_destinations.as_ref().expect("jump_destinations are initialized on first jump; qed"); let pos = self.verify_jump(position, jump_destinations)?; diff --git a/ethcore/evm/src/interpreter/shared_cache.rs b/ethcore/evm/src/interpreter/shared_cache.rs index f4a7f47f9..63c4f507d 100644 --- a/ethcore/evm/src/interpreter/shared_cache.rs +++ b/ethcore/evm/src/interpreter/shared_cache.rs @@ -50,17 +50,22 @@ impl SharedCache { } /// Get jump destinations bitmap for a contract. - pub fn jump_destinations(&self, code_hash: &H256, code: &[u8]) -> Arc { - if code_hash == &KECCAK_EMPTY { - return Self::find_jump_destinations(code); - } + pub fn jump_destinations(&self, code_hash: &Option, code: &[u8]) -> Arc { + if let Some(ref code_hash) = code_hash { + if code_hash == &KECCAK_EMPTY { + return Self::find_jump_destinations(code); + } - if let Some(d) = self.jump_destinations.lock().get_mut(code_hash) { - return d.0.clone(); + if let Some(d) = self.jump_destinations.lock().get_mut(code_hash) { + return d.0.clone(); + } } let d = Self::find_jump_destinations(code); - self.jump_destinations.lock().insert(code_hash.clone(), Bits(d.clone())); + + if let Some(ref code_hash) = code_hash { + self.jump_destinations.lock().insert(*code_hash, Bits(d.clone())); + } d }