Don't hash the init_code of CREATE. (#9688)

This commit is contained in:
Tomasz Drwięga 2018-10-04 13:32:04 +02:00 committed by Marek Kotewicz
parent 726884afcb
commit 4186467129
2 changed files with 13 additions and 9 deletions

View File

@ -385,8 +385,7 @@ impl<Cost: CostType> Interpreter<Cost> {
match result { match result {
InstructionResult::JumpToPosition(position) => { InstructionResult::JumpToPosition(position) => {
if self.valid_jump_destinations.is_none() { 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(&self.params.code_hash, &self.reader.code));
self.valid_jump_destinations = Some(self.cache.jump_destinations(&code_hash, &self.reader.code));
} }
let jump_destinations = self.valid_jump_destinations.as_ref().expect("jump_destinations are initialized on first jump; qed"); 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)?; let pos = self.verify_jump(position, jump_destinations)?;

View File

@ -50,7 +50,8 @@ impl SharedCache {
} }
/// Get jump destinations bitmap for a contract. /// Get jump destinations bitmap for a contract.
pub fn jump_destinations(&self, code_hash: &H256, code: &[u8]) -> Arc<BitSet> { pub fn jump_destinations(&self, code_hash: &Option<H256>, code: &[u8]) -> Arc<BitSet> {
if let Some(ref code_hash) = code_hash {
if code_hash == &KECCAK_EMPTY { if code_hash == &KECCAK_EMPTY {
return Self::find_jump_destinations(code); return Self::find_jump_destinations(code);
} }
@ -58,9 +59,13 @@ impl SharedCache {
if let Some(d) = self.jump_destinations.lock().get_mut(code_hash) { if let Some(d) = self.jump_destinations.lock().get_mut(code_hash) {
return d.0.clone(); return d.0.clone();
} }
}
let d = Self::find_jump_destinations(code); 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 d
} }