Skip to content

Commit

Permalink
fix ccc panic CodeNotFound (#958)
Browse files Browse the repository at this point in the history
  • Loading branch information
lispc authored Sep 19, 2023
1 parent 88414cc commit 2723b82
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2723b82

Please sign in to comment.