fix(data-fetcher): authenticate bridge event emitter before indexing transfers#613
Open
vladb-ai wants to merge 2 commits into
Open
fix(data-fetcher): authenticate bridge event emitter before indexing transfers#613vladb-ai wants to merge 2 commits into
vladb-ai wants to merge 2 commits into
Conversation
…transfers The bridge transfer handlers selected work purely by event topic and returned matches() === true unconditionally, so any L2 contract could emit ABI-shaped DepositFinalizedAssetRouter / WithdrawalInitiatedAssetRouter or legacy FinalizeDeposit / WithdrawalInitiated logs and have them indexed as real bridge deposits/withdrawals with attacker-chosen from/to/amount/token. Asset Router handlers: require the log emitter to be the L2 Asset Router system contract (L2_ASSET_ROUTER_ADDRESS, 0x..010003), which is deployed at the same fixed address on Era and every ZK chain (verified on Era mainnet and ZKsync OS mainnet). Legacy shared-bridge handlers: legacy events have no single authoritative emitter (canonical shared bridge plus deployment-specific custom token bridges, e.g. Lido wstETH), so authenticate against a trusted set built from zks_getBridgeContracts (cached) plus a configurable allowlist via the new TRUSTED_LEGACY_BRIDGE_ADDRESSES env var. Chains without zks_getBridgeContracts (e.g. ZKsync OS) fall back to the allowlist; they emit no legacy events. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ache RPC fallback Follow-up to the bridge emitter authentication fix, addressing review findings: 1. Observability for the legacy allowlist trade-off: with an empty allowlist the legacy handlers silently drop real custom-bridge transfers (e.g. Lido wstETH). Add a skipped_untrusted_legacy_bridge_logs_total metric and a debug log naming the skipped emitter so operators can discover bridges to allowlist instead of losing the data silently. Logic moved into BlockchainService.isTrustedLegacyBridgeEmitter. 2. Document the TRUSTED_LEGACY_BRIDGE_ADDRESSES env var in .env.example and the data-fetcher README, including the Era mainnet Lido wstETH example. 3. Cache the trusted-set fallback on deterministic zks_getBridgeContracts failures (e.g. -32601 method not found) so a failing call is not re-issued for every legacy log; only transient network errors remain uncached and are retried. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The bridge transfer handlers in
data-fetcherselect work purely by event topic and theirmatches()returnedtrueunconditionally, never checking the log emitter. As a result any unprivileged L2 contract can emit ABI-shaped bridge logs and have them indexed as real bridge deposits/withdrawals with attacker-chosenfrom/to/amount/token:DepositFinalizedAssetRouter/WithdrawalInitiatedAssetRouter(Asset Router path)FinalizeDeposit/WithdrawalInitiated(legacy shared-bridge path)These fabricated transfers surface in the explorer UI and the public API (e.g. on a victim address's
/transfers), i.e. misrepresentation of transaction data. No fund safety impact; data-integrity only.Fix
Asset Router handlers — require the emitter to be the L2 Asset Router system contract (
L2_ASSET_ROUTER_ADDRESS,0x…010003). This is deployed at the same fixed address on Era and every ZK chain, so the check is chain-agnostic with no config.Legacy shared-bridge handlers — legacy events have no single authoritative emitter (the canonical shared bridge plus deployment-specific custom token bridges, e.g. Lido wstETH). They are authenticated against a trusted set built from:
zks_getBridgeContracts(canonical bridges; cached), andTRUSTED_LEGACY_BRIDGE_ADDRESSESenv var (comma-separated).Chains that don't implement
zks_getBridgeContracts(e.g. ZKsync OS) fall back to the allowlist; they emit no legacy events.Verification
data-fetchersuite green (400 tests; new accept/reject cases for both handler families +getTrustedLegacyBridgeAddresses). Lint clean.0x…010003; the patched handler accepts those and rejects other emitters.TRUSTED_LEGACY_BRIDGE_ADDRESSESre-includes it, and an attacker emitter is rejected.Operator note
To keep indexing legitimate custom legacy bridges, set
TRUSTED_LEGACY_BRIDGE_ADDRESSES. For Era mainnet this includes at least the Lido wstETH bridge0xe1d6a50e7101c8f8db77352897ee3f1ac53f782b. Recommend scanning historical legacy-topic emitters per network to seed this list before rollout so no legitimate custom-bridge transfers are dropped.🤖 Generated with Claude Code