From 2723b82fb5d538d6fcc7b2dd0d84d3df8818499f Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Tue, 19 Sep 2023 09:47:13 +0800 Subject: [PATCH] fix ccc panic CodeNotFound (#958) --- .../circuit_input_builder/input_state_ref.rs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bus-mapping/src/circuit_input_builder/input_state_ref.rs b/bus-mapping/src/circuit_input_builder/input_state_ref.rs index 467da714bf..4f4ff05c1a 100644 --- a/bus-mapping/src/circuit_input_builder/input_state_ref.rs +++ b/bus-mapping/src/circuit_input_builder/input_state_ref.rs @@ -90,15 +90,20 @@ impl<'a> CircuitInputStateRef<'a> { let mut gas_left = prev_step.gas_left.0 - prev_step.gas_cost.0; // handling for contract creation tx let call = self.tx.calls()[0].clone(); - if call.is_create() { + if call.is_create() + && call.is_success() + && prev_step.exec_state == ExecState::Op(OpcodeId::RETURN) + { let code_hash = self.sdb.get_account(&call.address).1.code_hash; - let bytecode_len = self.code(code_hash).unwrap().len() as u64; - let deposit_cost = bytecode_len * GasCost::CODE_DEPOSIT_BYTE_COST.as_u64(); - assert!( - gas_left >= deposit_cost, - "gas left {gas_left} is not enough for deposit cost {deposit_cost}" - ); - gas_left -= deposit_cost; + if code_hash != CodeDB::empty_code_hash() { + let bytecode_len = self.code(code_hash).unwrap().len() as u64; + let deposit_cost = bytecode_len * GasCost::CODE_DEPOSIT_BYTE_COST.as_u64(); + assert!( + gas_left >= deposit_cost, + "gas left {gas_left} is not enough for deposit cost {deposit_cost}" + ); + gas_left -= deposit_cost; + } } Gas(gas_left)