Skip to content

fix: skip forged non-protocol logs in v1 outbound parsers#4574

Open
bit2swaz wants to merge 2 commits intozeta-chain:mainfrom
bit2swaz:fix/v1-outbound-skip-forged-logs
Open

fix: skip forged non-protocol logs in v1 outbound parsers#4574
bit2swaz wants to merge 2 commits intozeta-chain:mainfrom
bit2swaz:fix/v1-outbound-skip-forged-logs

Conversation

@bit2swaz
Copy link
Copy Markdown

@bit2swaz bit2swaz commented Apr 23, 2026

Follow-up to #4567
Closes #4573

Root cause:
The legacy v1 outbound parsers iterate receipt logs, attempt ABI parsing, and then validate the parsed log with ValidateEvmTxLog. A forged log from a non-protocol contract can still parse successfully if it reuses the same event signature and ABI shape. The old code then returned immediately on emitter-address mismatch, which prevented the parser from reaching the later valid protocol log in the same receipt.

Fix:
For the affected v1 outbound parsers, skip logs whose emitter address does not match the expected protocol contract before calling ValidateEvmTxLog. Keep ValidateEvmTxLog for candidate protocol logs so removed-log, tx-hash, and topic-count validation behavior remains unchanged.

Affected paths:

  • parseAndCheckZetaEvent
  • parseAndCheckWithdrawnEvent

Tests:

  • Added forged-first regression coverage for:
    • ZetaReceived
    • ZetaReverted
    • Withdrawn
  • Verified the new regression tests fail before the fix with emitter-address mismatch errors.
  • Verified the focused v1 parser tests pass after the fix.
  • Verified the full zetaclient/chains/evm/observer package passes under Go 1.23.9.

Notes:

  • Wrong expected contract-address cases now resolve to "no event found" rather than a validation abort, which matches the new skip-and-continue semantics.
  • No additional same-pattern outbound paths remain in this observer package after the v1 and v2 fixes.

Note

Medium Risk
Touches outbound receipt parsing used to determine cross-chain receive status/value; while the change is small, it affects core confirmation/voting behavior and could cause missed events if address checks are wrong.

Overview
Hardens outbound receipt parsing to ignore forged/non-protocol logs that reuse protocol event signatures. The v1 parsers (parseAndCheckZetaEvent, parseAndCheckWithdrawnEvent) and v2 outbound parsers now skip logs whose Address is not the expected contract before running ValidateEvmTxLog, allowing the parser to continue scanning and find the later legitimate protocol log.

Updates and expands tests to match the new semantics (wrong contract address now yields “no event found”), and adds regression coverage that prepends a forged log to real receipts/events to ensure parsing still succeeds.

Reviewed by Cursor Bugbot for commit bd2e6d3. Configure here.

Greptile Summary

This PR fixes a forged-log bypass in the EVM outbound parsers (v1 and v2) where a non-protocol contract emitting an event with the same ABI signature could cause an early validation failure that prevented the parser from reaching the real protocol log later in the receipt. The fix consistently adds an emitter-address check (vLog.Address != protocolAddr → continue) immediately after a successful ABI parse and before ValidateEvmTxLog, converting the old abort-on-mismatch into a skip-and-continue across all nine affected parsers.

Confidence Score: 5/5

Safe to merge; fix is minimal, correctly applied to all affected parsers, and well-covered by new regression tests.

The patch is a narrow, consistent change (one 3-line guard per parser) with no logic regressions. All nine parsers (v1 and v2) receive the same treatment, existing tests are updated to reflect the new semantics, and targeted forged-first tests are added for all affected paths. No P0/P1 findings were identified.

No files require special attention.

Important Files Changed

Filename Overview
zetaclient/chains/evm/observer/outbound.go Adds emitter-address guard before ValidateEvmTxLog in parseAndCheckZetaEvent (ZetaReceived + ZetaReverted) and parseAndCheckWithdrawnEvent, replacing an early-return-on-mismatch pattern with continue-and-skip so the loop can reach a later valid protocol log.
zetaclient/chains/evm/observer/v2_outbound.go Applies the same address-before-validate guard to all six v2 parsers (GatewayExecuted, GatewayReverted, ZetaConnectorWithdraw, ERC20CustodyWithdraw, ERC20CustodyWithdrawAndCall, ZetaConnectorWithdrawAndCall).
zetaclient/chains/evm/observer/outbound_test.go Updates three existing address-mismatch tests to expect 'no event found' errors and adds forged-first regression tests for ZetaReceived, ZetaReverted, and ERC20 Withdrawn; adds helper functions receiptWithPrependedForgedLog, cloneEVMLog, and three mustFind* utilities.
zetaclient/chains/evm/observer/v2_outbound_test.go New test file with a table-driven test covering all six v2 parsers under the forged-first scenario; includes ABI-based log constructors for each event type.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Start: iterate receipt.Logs] --> B[Try ABI parse]
    B -- parse error --> A
    B -- parse OK --> C{vLog.Address == protocolAddr?}
    C -- No --> A
    C -- Yes --> D[ValidateEvmTxLog\ntx-hash, topic-count, address]
    D -- validation error --> E[Return error]
    D -- OK --> F[Check receiver / amount / index]
    F -- mismatch --> G[Return error]
    F -- match --> H[Return event ✓]
    A -- no logs left --> I[Return 'no event found' error]
Loading

Reviews (1): Last reviewed commit: "fix: skip forged non-protocol v1 outboun..." | Re-trigger Greptile

Copilot AI review requested due to automatic review settings April 23, 2026 21:20
@bit2swaz bit2swaz requested a review from a team as a code owner April 23, 2026 21:20
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

Warning

Rate limit exceeded

@bit2swaz has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 35 minutes and 13 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 35 minutes and 13 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4aca896b-75dc-4e3f-8cd0-3084f8e83b61

📥 Commits

Reviewing files that changed from the base of the PR and between 9a516a3 and bd2e6d3.

📒 Files selected for processing (4)
  • zetaclient/chains/evm/observer/outbound.go
  • zetaclient/chains/evm/observer/outbound_test.go
  • zetaclient/chains/evm/observer/v2_outbound.go
  • zetaclient/chains/evm/observer/v2_outbound_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes legacy (v1) outbound receipt parsing so forged same-signature logs from non-protocol contracts don’t cause early aborts, allowing the parser to continue scanning and pick up the later valid protocol log in the same receipt. Also applies the same “skip non-protocol emitter before validation” pattern to v2 outbound parsers and adds regression coverage.

Changes:

  • Skip logs whose Address doesn’t match the expected protocol contract before calling ValidateEvmTxLog in v1 and v2 outbound parsers.
  • Update v1 outbound tests to reflect new “no event found” behavior on wrong expected contract address and add forged-first regression cases.
  • Add a v2 outbound regression test covering forged-first ordering across the relevant v2 parsers.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
zetaclient/chains/evm/observer/outbound.go Updates v1 parseAndCheckZetaEvent and parseAndCheckWithdrawnEvent to skip parsed events from unexpected emitter addresses.
zetaclient/chains/evm/observer/v2_outbound.go Applies the same emitter-address skip behavior to v2 outbound parse-and-check functions.
zetaclient/chains/evm/observer/outbound_test.go Adjusts mismatch expectations and adds forged-first regression tests plus helper utilities for forging logs.
zetaclient/chains/evm/observer/v2_outbound_test.go Adds regression test ensuring v2 outbound parsers skip forged logs and successfully parse the later valid protocol log.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 73 to +80
for _, vLog := range receipt.Logs {
executed, err := gateway.GatewayEVMFilterer.ParseExecuted(*vLog)
if err != nil {
continue
}
if vLog.Address != gatewayAddr {
continue
}
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

The new emitter-address guard still ABI-parses the log before checking vLog.Address. Since receipts are untrusted input, consider checking vLog.Address != <expected> at the start of the loop (before Parse*) to skip non-protocol logs without doing any ABI unpacking. This reduces unnecessary work and limits potential CPU amplification if a receipt contains many same-signature forged logs. Apply the same ordering to the other parseAndCheck* loops in this file that follow this pattern.

Copilot uses AI. Check for mistakes.
Comment on lines 306 to 314
for _, vLog := range receipt.Logs {
// try parsing ZetaReceived event
received, err := connector.ZetaConnectorNonEthFilterer.ParseZetaReceived(*vLog)
if err == nil {
if vLog.Address != connectorAddr {
continue
}
err = common.ValidateEvmTxLog(vLog, connectorAddr, receipt.TxHash.Hex(), common.TopicsZetaReceived)
if err != nil {
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

The emitter-address check is currently performed only after a successful ABI parse (ParseZetaReceived / ParseZetaReverted / ParseWithdrawn). Consider moving the vLog.Address != <expected> guard to the top of the receipt-log loop (before attempting any Parse* call) so forged logs from other contracts are skipped without doing ABI decoding. This keeps the new skip-and-continue semantics while avoiding unnecessary work on attacker-controlled receipts.

Copilot uses AI. Check for mistakes.
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.

fix: v1 outbound parsers abort on forged same-signature logs instead of continuing

2 participants