|
| 1 | +--- |
| 2 | +section: cre |
| 3 | +title: "Finality and Confidence Levels" |
| 4 | +date: Last Modified |
| 5 | +sdkLang: "go" |
| 6 | +pageId: "concepts-finality" |
| 7 | +metadata: |
| 8 | + description: "Understand how CRE handles blockchain finality across different chains, including confidence levels, finality tags, and block depth configurations." |
| 9 | + datePublished: "2025-12-10" |
| 10 | + lastModified: "2025-12-10" |
| 11 | +--- |
| 12 | + |
| 13 | +import { Aside, CopyText } from "@components" |
| 14 | + |
| 15 | +Finality determines when a blockchain transaction is considered irreversible. Until a block is finalized, it could be reorganized (replaced by a different block if the chain temporarily forks), which means any data you read from it might change. |
| 16 | + |
| 17 | +Different blockchains achieve finality in different ways and at different speeds. CRE abstracts these differences through **confidence levels**, allowing you to specify your finality requirements without needing to know the underlying chain-specific implementation. |
| 18 | + |
| 19 | +## Understanding CRE's finality model |
| 20 | + |
| 21 | +CRE provides three confidence levels for reading blockchain data and monitoring events. These levels work consistently across all supported chains. |
| 22 | + |
| 23 | +### The three confidence levels |
| 24 | + |
| 25 | +| Confidence Level | Description | Use Case | |
| 26 | +| ---------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | |
| 27 | +| **`LATEST`** | The most recent block. No finality guarantees—the block could still be reorganized. | Non-critical, time-sensitive operations where speed matters more than certainty. | |
| 28 | +| **`SAFE`** | A block that is unlikely to be reorganized, but not yet fully finalized. | A balance between speed and security for most operations. | |
| 29 | +| **`FINALIZED`** | A block that is considered irreversible. This is the safest option. | Critical operations where you need absolute certainty the data won't change. | |
| 30 | + |
| 31 | +**Choosing the right level:** |
| 32 | + |
| 33 | +- **`FINALIZED`** — Use for financial transactions, critical state updates, or when incorrect data could cause significant issues |
| 34 | +- **`SAFE`** — Use when you need reasonable confidence without waiting for full finality (good for most monitoring/alerting) |
| 35 | +- **`LATEST`** — Use for real-time dashboards or displays where speed matters more than guaranteed accuracy |
| 36 | + |
| 37 | +### How confidence levels map to chains |
| 38 | + |
| 39 | +**SAFE and LATEST:** |
| 40 | + |
| 41 | +CRE uses the chain's native `safe` and `latest` block tags respectively for all supported chains. |
| 42 | + |
| 43 | +**FINALIZED:** |
| 44 | + |
| 45 | +When you specify `FINALIZED` in your workflow, CRE automatically maps this to a native finality tag or a block depth threshold depending on the chain. |
| 46 | + |
| 47 | +| Chain | Finality Method | Block Depth | |
| 48 | +| ------------------------------- | ---------------------------- | ----------- | |
| 49 | +| Arbitrum One / Arbitrum Sepolia | Native `finalized` tag | — | |
| 50 | +| Avalanche / Avalanche Fuji | Native `finalized` tag | — | |
| 51 | +| Base / Base Sepolia | Native `finalized` tag | — | |
| 52 | +| BNB Chain / BNB Testnet | Native `finalized` tag | — | |
| 53 | +| Ethereum / Ethereum Sepolia | Native `finalized` tag | — | |
| 54 | +| OP Mainnet / OP Sepolia | Native `finalized` tag | — | |
| 55 | +| Polygon / Polygon Amoy | Block depth (500 blocks ago) | 500 | |
| 56 | + |
| 57 | +## Finality for chain reads |
| 58 | + |
| 59 | +Chain read operations ([`CallContract`](/cre/reference/sdk/evm-client-go#callcontract), [`BalanceAt`](/cre/reference/sdk/evm-client-go#balanceat), [`FilterLogs`](/cre/reference/sdk/evm-client-go#filterlogs), etc.) support confidence levels and custom block depths. |
| 60 | + |
| 61 | +### Using confidence levels |
| 62 | + |
| 63 | +For most read operations, use the standard confidence levels by passing `-2` (latest) or `-3` (finalized) as the `BlockNumber` parameter. If you don't specify a block number, CRE defaults to `LATEST`. |
| 64 | + |
| 65 | +**Note:** The `SAFE` confidence level is not available for chain reads—only `LATEST` and `FINALIZED` are supported. |
| 66 | + |
| 67 | +### Custom block depths |
| 68 | + |
| 69 | +For use cases requiring fixed confirmation thresholds or historical state verification, you can specify **any explicit block number** instead of using the predefined confidence levels. This enables you to: |
| 70 | + |
| 71 | +- Implement custom finality rules tailored to your risk profile (e.g., "always wait 1,000 blocks") |
| 72 | +- Meet regulatory requirements that mandate fixed, auditable confirmation thresholds |
| 73 | +- Query historical state at specific past block heights for analysis or verification |
| 74 | + |
| 75 | +**When to use custom block depths:** |
| 76 | + |
| 77 | +- **Regulatory compliance** — Your interactions require provable, fixed confirmation thresholds for auditors |
| 78 | +- **Changing chain parameters** — The chain's finality definition may change, but your security model must remain constant |
| 79 | +- **Historical verification** — You need to verify state at a specific moment |
| 80 | + |
| 81 | +**Implementation:** |
| 82 | + |
| 83 | +You can pass any `*big.Int` directly as the `BlockNumber` parameter. The SDK accepts both special values (like `-2` for latest, `-3` for finalized) and positive integers for explicit block heights. See [Onchain Read](/cre/guides/workflow/using-evm-client/onchain-read-go#custom-block-depths) for examples. |
| 84 | + |
| 85 | +## Finality for chain writes |
| 86 | + |
| 87 | +Chain write operations return a [`WriteReportReply`](/cre/reference/sdk/evm-client-go#evmwritereportreply) when the transaction is included in a block, not when it reaches finality. |
| 88 | + |
| 89 | +### What a successful response means |
| 90 | + |
| 91 | +When [`WriteReportReply`](/cre/reference/sdk/evm-client-go#evmwritereportreply) returns with `TxStatus` equal to `SUCCESS`: |
| 92 | + |
| 93 | +- Your transaction was **included in a block** |
| 94 | +- The transaction is **not necessarily finalized** yet |
| 95 | + |
| 96 | +The reply is returned as soon as the transaction appears in a block, not when the block reaches finality. This is important for time-sensitive workflows, but it means the transaction could still be reorganized. |
| 97 | + |
| 98 | +### Reorg handling |
| 99 | + |
| 100 | +If a block containing your transaction is reorganized: |
| 101 | + |
| 102 | +- CRE's Transaction Manager (TXM) automatically resubmits your transaction |
| 103 | +- Gas bumping is applied as needed to ensure the transaction is included |
| 104 | +- **Important:** The transaction hash may change during resubmission |
| 105 | +- You are not automatically notified if the hash changes |
| 106 | + |
| 107 | +<Aside type="caution" title="For mission-critical applications"> |
| 108 | + If you need absolute certainty that your write transaction reached finality, implement post-write verification by |
| 109 | + reading the blockchain state after a custom number of confirmations. Do not rely solely on `WriteReportReply` for |
| 110 | + finality confirmation. |
| 111 | +</Aside> |
| 112 | + |
| 113 | +## Finality for event triggers |
| 114 | + |
| 115 | +EVM Log Triggers must use the three confidence levels (`LATEST`, `SAFE`, or `FINALIZED`). Custom block depths are not supported for triggers. |
| 116 | + |
| 117 | +By default, triggers use `SAFE` if no confidence level is specified. For details on configuring trigger confidence levels, see [EVM Log Trigger](/cre/reference/sdk/triggers/evm-log-trigger-go#evmfilterlogtriggerrequest). |
0 commit comments