Skip to content

fix: add nil check for OnTxStart before calling tracer hook#1078

Open
Bue-von-hon wants to merge 1 commit intocosmos:mainfrom
Bue-von-hon:issue-209
Open

fix: add nil check for OnTxStart before calling tracer hook#1078
Bue-von-hon wants to merge 1 commit intocosmos:mainfrom
Bue-von-hon:issue-209

Conversation

@Bue-von-hon
Copy link
Copy Markdown

Description

Calling vmCfg.Tracer.OnTxStart without a nil check causes a panic when a custom tracer does not implement the OnTxStart field. Added a nil guard consistent with the existing OnTxEnd check.

Closes #209


Author Checklist

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the main branch

Calling vmCfg.Tracer.OnTxStart without a nil check causes a panic when
a custom tracer does not implement the OnTxStart field. Added a nil
guard consistent with the existing OnTxEnd check.

Closes cosmos#209
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 15, 2026

Greptile Summary

This PR adds a nil guard for vmCfg.Tracer.OnTxStart in ApplyMessageWithConfig, preventing a panic when a custom tracing.Hooks instance leaves the OnTxStart function field unset. The fix is minimal, correct, and consistent with the existing nil check already applied to OnTxEnd in the same block.

  • tracing.Hooks (from go-ethereum) is a struct with function-typed fields rather than an interface, so any field can be nil if a custom tracer doesn't populate it.
  • The previous code called vmCfg.Tracer.OnTxStart(...) directly after confirming vmCfg.Tracer != nil, but never checked whether the OnTxStart field itself was non-nil — causing a nil-function-call panic for custom tracers that omit it.
  • The added if vmCfg.Tracer.OnTxStart != nil guard mirrors the identical guard already present for OnTxEnd on the very next line.

Confidence Score: 5/5

  • This PR is safe to merge — it is a targeted, one-line nil guard that closes a real panic path with no side effects.
  • The change is a single conditional guard, directly mirrors an existing pattern in the same code block, and has no logic changes beyond preventing a nil function call dereference.
  • No files require special attention.

Important Files Changed

Filename Overview
x/vm/keeper/state_transition.go Adds a nil guard for vmCfg.Tracer.OnTxStart before invoking it, matching the existing nil check for OnTxEnd. Correctly prevents a panic when a custom tracing.Hooks struct leaves OnTxStart unset (nil function field).

Last reviewed commit: e74482a

@Bue-von-hon
Copy link
Copy Markdown
Author

Please review.
I'm new to this and don't know who to mention, so I'm just leaving a comment here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracer.OnTxStart may cause panic if not implemented by custom tracers

2 participants