We manage your security to weather the AI storm →

← Resource Hub

How to Monitor Smart Contract Events and Catch Exploits

By Daniel GelfandPublished 7 min read

Part of our guide to onchain monitoring

How to Monitor Smart Contract Events and Catch Exploits

Quick answer. Start from a safety property, not an attacker address. Trigger on events, explain with traces and decide on state read at one block hash. Attach evidence, replay past attacks and benign activity, then run each rule in shadow mode before it pages anyone.

Watch: How to Monitor Smart Contract Events and Catch Exploits 1:46
Video transcript

Logs arrive after a transaction executes, so no rule can stop it. Strong detectors can flag the first damaging one, starting from a safety property.

A trigger decides when to evaluate. A condition decides whether a property failed. Severity is consequence. Confidence, tracked separately, is certainty.

For a custody vault, read holdings and liabilities at the same block hash. Fire when holdings fall below liabilities. A failed read raises a coverage alert.

Events select activity, traces explain internal calls, state establishes the result. For upgrades, read proxy slots too, because change events are recommended, not required.

Turn incidents into properties, not address lists. Euler's team describes its 2023 version one exploit as a donation path with no health check. For bridges, test release-to-message matching on Nomad's records.

Guardian's Veranta review found an interface declaring four event fields while the extension emitted five, so monitors could miss position rolls. The low severity finding is resolved.

Replay archived evidence offline, never the exploit itself. Pair each attack with benign twins, then break the pipeline with duplicate logs, reorgs and dropped connections.

Ship each rule in shadow mode first. Review benign matches, promote it with a named owner, and retest after any deployment change.

Guardian's Web3 MDR runs custom monitors beside out-of-the-box detectors, with an engineer on every alert. Read the guide, or talk to Guardian.

What a Detector Can Catch

When teams decide how to monitor smart contract events, a log subscription is the usual first step. That shows activity. It does not tell you a property has failed.

Geth log subscriptions deliver matching logs from newly imported blocks. By then the transaction has already executed, so no rule can interrupt it.[1]

A rule can still spot the first damaging transaction. If an authorized response lands in time, it can contain the transactions that follow.

This guide is for the engineer writing and testing individual rules. For orientation, read what is onchain monitoring; for what to cover, use our DeFi monitoring detectors checklist.

Detector Anatomy

Every rule has three parts. The trigger decides when to evaluate. The condition decides whether a safety property failed.

Severity describes the consequence, not the certainty. Track confidence separately, so a likely benign upgrade to a vault holding funds still pages as Critical.

Take a simple custody vault. At each processed block, read its token holdings and its redeemable liabilities at the same block hash.

EIP-1898, a Final specification, lets eth_call and eth_getStorageAt name a block hash. With requireCanonical set, a node should return an error for a noncanonical block.[2]

The specification alone does not prove your provider supports it, so test that first.

Fire when holdings plus a justified rounding tolerance fall below liabilities. If either read fails, return UNKNOWN and raise a coverage alert.

The alert carries both values, the token, the block hash and the rule version. Lending markets and strategy vaults need their own definitions of backing.

Foundry's guide warns that checking invariants less often can miss violations restored between checks. A block-end rule shares that blind spot inside each block.[3]

Spec fieldWhat it holds
ID and versionStable name, version bumped on any logic change
ScopeChain, addresses and the pinned ABI the rule decodes
TriggerEvent, block, trace or schedule that starts evaluation
Inputs and boundaryReads required, and the block or transaction they describe
PredicateThe property, written as a testable inequality or match
Severity and confidenceConsequence tier, plus a separate certainty level
Missing dataWhat happens when an input is unavailable: UNKNOWN, never pass
Dedup keyFields that collapse repeat deliveries into one alert
EvidenceTransactions, block hash, decoded values and rule version
Owner and runbookNamed responder and first actions they may take

Event vs Trace vs State Detectors

Use events to select activity, traces to explain internal execution and state to establish the result. Each source fails differently.

For a non-anonymous Solidity event, topic0 hashes the name and canonical parameter types. Indexed arguments sit in topics, the rest in data.[4]

Indexed strings, arrays and structs appear only as hashes. A rule that needs the original value must read it from data or state.

Geth's callTracer returns nested call frames with their errors. Its onlyTopCall option drops subcalls, so leave it off when a rule needs internal calls.[5]

prestateTracer in diffMode reports a transaction's state before and after. It does not show every intermediate state.

Upgrades show why state decides. ERC-1967 fixes the implementation, beacon and admin slots, but says changes SHOULD emit events, not MUST.[6]

So read the slots as well as the events. For a beacon proxy, read the beacon address and call its implementation() function.

Compare the effective implementation with an approved deployment record kept outside the monitored system. A known signer does not prove a change was approved.

SourceAnswersMisses
EventsWhat the contract announced, cheaply filteredSilent state changes; topics a stale ABI no longer matches
TracesInternal calls, delegatecalls and revertsArbitrary intermediate storage; providers that do not serve traces
StateThe result at a named blockHow it got there; changes reversed within the block

Patterns From Real Exploits

Turn each incident into a property, not an address list. A new attacker usually brings new addresses, so a list mostly catches repeats.

Euler's January 10, 2024 retrospective dates its V1 exploit to March 13, 2023. The team describes a donation path that reduced collateral with no health check.[7]

The team also describes multiple exploit transactions, which is where containment after the first one matters. This is historical V1 behavior, not a finding about Euler V2.

The property: after any collateral-reducing operation, the account still meets its health requirement. Add a protocol-level check for accounting losses no event explains.

Nomad's official dataset dates its bridge incident to August 1, 2022. Reuters reported the theft and Nomad's acknowledgment on August 2.[8, 9]

A Federal Trade Commission complaint, published December 16, 2025, alleges that a June 21, 2022 code update interacted with an existing initialization entry. The FTC says Nomad's contract then authenticated messages incorrectly, so unprocessed messages could release bridge assets.[10, 11]

The repository publishes exploit transactions, the events emitted in them and message-lifecycle records. Those make candidate fixtures for bridge rules.

The property: every destination release matches a source message on domain, asset, recipient, amount and consumption status. Treat this as a test to run against those records, not a proven catch.

Guardian's Veranta V2 review found a proxy-facing ABI declaring a four-field event while the delegatecalled extension emitted five fields at the proxy address (Low, L-01, resolved).[12]

Different fields mean a different topic0, so monitors using the generated ABI could silently miss position rolls. Test the event producer, not just the decoder.[4]

Testing Against Historical Attacks

Replay evidence, never exploits. Feed archived receipts, logs, traces and state snapshots into the rule offline, with nothing broadcast.

Pin each fixture to its chain, block hashes, transaction order, ABI and rule version.

Build rolling baselines from the history before the incident. Seeding them from current state or later attacker labels leaks the answer into the test.

Pair every attack fixture with benign twins: large withdrawals, liquidations and approved upgrades. Assert the first alerting transaction, its severity and its evidence fields.

Keep one property register shared with code testing. Guardian's invariant suites turn safety properties into reusable executable tests, and Helix tests code continuously as it changes.[13, 14]

For each property, record the test assertion, its production inputs, its observation boundary and its blind spots. Our Foundry invariant testing guide covers the test side.

A ghost variable that sums every deposit may have no readable onchain equivalent. Log that as a coverage gap rather than approximating it.

Code regression and detector regression are separate suites. Require both to pass after any relevant upgrade.

Then break the pipeline on purpose. Geth subscriptions end with their connection, and reorganizations can send removed logs and repeat a transaction's logs.[1]

Historical block times cannot measure live latency. In production, time observation, evaluation, notification and containment separately.

  • Duplicate delivery of the same log: one alert, keyed by block hash and log index.
  • Reorg with removed logs: orphaned contributions reversed in every rolling total.
  • Dropped connection: gap backfilled with eth_getLogs, which filters by address, topics and block range, from the last persisted checkpoint.[15]
  • Trace or historical state unavailable: UNKNOWN plus a coverage alert.
  • Unknown topic at a monitored address, or an expected event missing: alert on both.[4]
  • Restart mid-block: no lost or double-counted blocks after recovery.
  • Delayed notification channel: escalation to a backup within the runbook's window.

Deploying and Maintaining

Ship every new rule in shadow mode. It evaluates and logs but pages nobody until its benign matches have been reviewed.

Promote it to paging only with documented coverage, evidence fields, a named owner and a passing end-to-end delivery test.

Automate containment only for narrow, validated conditions. An onchain response needs a privilege granted in advance and a tested action path.[16]

Who holds that privilege, and how signers are reached, belongs in your DeFi incident response plan.

Keep monitoring credentials read-only and separate from action credentials. Give every maintenance suppression an expiry and a logged approver.

Retest after any ABI, role, oracle or deployment change. Each one can silently move the topics, slots or addresses a rule depends on.[6, 12]

Guardian's Web3 MDR can run a protocol-specific rule like the custody check above as a custom monitor, beside out-of-the-box detectors for known exploit patterns, with an engineer on each alert.[14]

Buying rather than building? Our onchain monitoring vendor scorecard applies the same replay approach to vendors.

Detectors built around your own contracts

Guardian's Web3 MDR runs monitors customized to your protocol beside out-of-the-box detectors, with an engineer on every alert and response authority agreed before any incident.

Frequently Asked Questions

Can a detector see an exploit before it lands onchain?

Sometimes. Watching pending transactions adds a signal where a public mempool exists. Flashbots Protect, however, sends transactions to a private mempool, so some attacks give no pending warning.[17]

How should a detector handle chain reorganizations?

Treat each log as provisional until its block reaches the finality depth you set for that severity. If a block is orphaned, retract or amend any alert already sent from it, and record why.

Do these patterns work on Solana or NEAR?

The method does: property, earliest evidence, same-point state reads, replay fixtures. The mechanics do not. Event topics, ERC-1967 slots and Geth tracers are EVM concepts, so each non-EVM chain needs its own inputs and finality rules.[4, 5, 6]

Sources

  1. Geth: Real-time Events
  2. Ethereum Improvement Proposals: EIP-1898: Add blockHash to defaultBlock methods
  3. Foundry: Invariant Testing
  4. Solidity: Contract ABI Specification
  5. Geth: Built-in tracers
  6. Ethereum Improvement Proposals: ERC-1967: Proxy Storage Slots
  7. Euler Labs: War & Peace: Behind the Scenes of Euler’s $240M Exploit Recovery
  8. Nomad: Nomad Hack Data
  9. Reuters, syndicated by Euronews: U.S. crypto firm Nomad hit by $190 million theft
  10. Federal Trade Commission: Complaint: In the Matter of Illusory Systems, Inc., also d/b/a Nomad
  11. Federal Trade Commission: Illusory Systems/Nomad
  12. Guardian: Veranta V2 Review: L-01, ABIs misdeclare delegatecall-emitted events
  13. Guardian: Foundry Invariant Testing: Handlers, Ghost Variables, Actors
  14. Guardian: Guardian Announces Managed Security
  15. Ethereum: JSON-RPC API
  16. Guardian: What Is Onchain Monitoring? A Guide for Security Teams
  17. Flashbots: MEV Protection Overview
  18. Cointelegraph: Euler Finance attack: How it happened, and what can be learned