Skip to content

Commit 2723b82

Browse files
authored
fix ccc panic CodeNotFound (#958)
1 parent 88414cc commit 2723b82

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

bus-mapping/src/circuit_input_builder/input_state_ref.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,20 @@ impl<'a> CircuitInputStateRef<'a> {
9090
let mut gas_left = prev_step.gas_left.0 - prev_step.gas_cost.0;
9191
// handling for contract creation tx
9292
let call = self.tx.calls()[0].clone();
93-
if call.is_create() {
93+
if call.is_create()
94+
&& call.is_success()
95+
&& prev_step.exec_state == ExecState::Op(OpcodeId::RETURN)
96+
{
9497
let code_hash = self.sdb.get_account(&call.address).1.code_hash;
95-
let bytecode_len = self.code(code_hash).unwrap().len() as u64;
96-
let deposit_cost = bytecode_len * GasCost::CODE_DEPOSIT_BYTE_COST.as_u64();
97-
assert!(
98-
gas_left >= deposit_cost,
99-
"gas left {gas_left} is not enough for deposit cost {deposit_cost}"
100-
);
101-
gas_left -= deposit_cost;
98+
if code_hash != CodeDB::empty_code_hash() {
99+
let bytecode_len = self.code(code_hash).unwrap().len() as u64;
100+
let deposit_cost = bytecode_len * GasCost::CODE_DEPOSIT_BYTE_COST.as_u64();
101+
assert!(
102+
gas_left >= deposit_cost,
103+
"gas left {gas_left} is not enough for deposit cost {deposit_cost}"
104+
);
105+
gas_left -= deposit_cost;
106+
}
102107
}
103108

104109
Gas(gas_left)

0 commit comments

Comments
 (0)