1

Let's imagine the following extrinsic.

#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::might_panic_extrinsic())]
pub fn might_panic_extrinsic(origin: OriginFor<T>) -> DispatchResult {
    let member = ensure_signed(origin)?;
    let might_panic = custom_func().unwrap();
    Ok(())
}

What are the risks and consequences, security-wise and considering we are using the latest Substrate version, if my extrinsic panics due to the unwrap call ?

Will my node crash ? Will my runtime restart ? Will the extrinsic just be reverted, just like it would be for a custom Error ? Is there any security risk that the collator misses his slot ?

1
  • Why do you want to panic and crash when you can just return an error with a simple ?
    – Simson
    Commented Dec 5, 2023 at 6:06

1 Answer 1

1

Your node's runtime thread will crash, and that extrinsic won't be included in the block.

I recall that Frontier used this to prevent certain invalid extrinsics from being included in the block. (But I'm not sure about this now)

However, it is not recommended to write such code. You must ensure that this is not called in pallet::hooks. Panicking in hooks is not allowed, as it will result in your chain becoming brick.

There isn't a significant security risk for an offline collator. However, if all collators go offline, your chain will become unusable. Panic occurring on hooks could lead to this situation.

2
  • Thank you. Couldn't that be a way for an attacker to abuse the resources of a collator by spamming that same panicking extrinsic and making the runtime thread restarting over and over ?
    – clst
    Commented Dec 5, 2023 at 8:45
  • Actually, collator won't expose their nodes RPC. Extrinsic would only affect the RPC service nodes. That's why I said hooks would affect all nodes.
    – aurexav
    Commented Dec 5, 2023 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.