Skip to content

cmd/abigen: (v2) added a package-level error for event signature mismatch - #34076

Merged
MariusVanDerWijden merged 2 commits into
ethereum:masterfrom
rglKali:master
Apr 13, 2026
Merged

cmd/abigen: (v2) added a package-level error for event signature mismatch#34076
MariusVanDerWijden merged 2 commits into
ethereum:masterfrom
rglKali:master

Conversation

@rglKali

@rglKali rglKali commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces the inline errors.New("event signature mismatch") in generated UnpackXxxEvent methods with per-event package-level sentinel errors (e.g. ErrTransferSignatureMismatch, ErrApprovalSignatureMismatch), allowing callers to reliably distinguish a topic mismatch from a genuine decoding failure via errors.Is.

Each event gets its own sentinel, generated via the abigen template:

var ErrTransferSignatureMismatch = errors.New("event signature mismatch")

This scoping is intentional — it allows callers to be precise about which event was mismatched, which is useful when routing logs across multiple unpackers.

Motivation

Previously, all errors returned from UnpackXxxEvent were indistinguishable without string matching. This is especially problematic when processing logs sourced from eth_getBlockReceipts, where a caller receives the full set of logs for a block across all contracts and event types. In that context, a signature mismatch is expected and should be skipped, while any other error (malformed data, topic parsing failure) indicates something is genuinely wrong and should halt execution:

for _, log := range blockLogs {
    event, err := contract.UnpackTransferEvent(log)
    if errors.Is(err, gen.ErrTransferSignatureMismatch) {
        continue // not our event, expected
    }
    if err != nil {
        return fmt.Errorf("unexpected decode failure: %w", err) // alert
    }
    // process event
}

Changes:

  • abigen template: generates a ErrXxxSignatureMismatch sentinel per event and returns it on topic mismatch instead of an inline error
  • Existing generated bindings & testdata: regenerated to reflect the update

Implements #34075

@rglKali rglKali changed the title abigenv2: added a package-level error for event signature mismatch cmd/abigen: (v2) added a package-level error for event signature mismatch Mar 23, 2026
@jwasinger

Copy link
Copy Markdown
Contributor

Makes sense to me. I'll tag this so we can discuss it as a team.

@lightclient

Copy link
Copy Markdown
Member

Generally makes sense. One question is if this error should be defined in the abigen package or like you have here where it is generated for each file. I don't have a great intuition which is more correct to be honest.

Comment thread accounts/abi/abigen/source2.go.tpl Outdated
@rglKali
rglKali requested a review from jwasinger March 24, 2026 16:58

@MariusVanDerWijden MariusVanDerWijden left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MariusVanDerWijden
MariusVanDerWijden merged commit 289826f into ethereum:master Apr 13, 2026
7 of 8 checks passed
@MariusVanDerWijden MariusVanDerWijden added this to the 1.17.3 milestone Apr 13, 2026
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.

4 participants