Transaction lifecycle

Transaction flow

transaction flow

The transaction lifecycle in Starknet involves the following high level steps:

1. Transaction Submission

A transaction is submitted to one of the gateways, functioning as the Mempool and marks the transaction status as RECEIVED.

2. Validation

2.1 Mempool validation

The Mempool performs validation on the transaction to check for its validity. If the transaction is invalid, it will not proceed to the next stages.

2.2 Sequencer validation

The sequencer performs validation on the transaction prior to execution to ensure that the transaction is still valid. If the transaction is invalid, it will not proceed to the next stages.

3. Execution

The sequencer operation sequentially applies the validated transactions to the state. If a transaction fails during execution, it will be included in the block with the status REVERTED.

4. Proof Generation

The Prover stage executes the operating system on the new block, computes the proof, and transmits it to L1.

Transaction status

The diagram below illustrates how each transaction status fits into the overall transaction flow:

txn flow

The following are the possible statuses of a transaction from the moment it’s sent by the user to the moment it’s validated by L1:

Finality statuses

NOT_RECEIVED

The transaction is not yet known to the sequencer.

RECEIVED

The transaction was received by the mempool. The transaction will now either execute successfully, be rejected or be reverted.

ACCEPTED_ON_L2

The transaction passed validation and entered an actual created block on L2.

ACCEPTED_ON_L1

The transaction was accepted on Ethereum.

Execution statuses

REJECTED

The transaction was received by the Mempool but failed validation in the sequencer. Such transactions will not be included in a block.

REVERTED

The transaction passed validation but failed during execution in the sequencer. They will be included in the block with the status REVERTED.

SUCEEDED

The transaction was successfully executed by the sequencer.

State Implications of a REVERTED Transaction

When a transaction is marked as REVERTED, the following state implications occur:

Nonce increases

The nonce value for the account of the failed transaction will increase despite the failure.

Fee charge

A fee will be charged for the execution of the transaction up to the point of failure.

Partial Reversion

All changes that occurred during the validate stage are not reverted. However, all changes that occurred during the execute stage are reverted, including no messages to L1 or events.

Fee Calculation

The fee charged for REVERTED transactions will be calculated as follows:

fee = Min(max_fee, consumed_resources)
Consumed Resources

The consumed_resources are the resources used for the execution of the transaction up to the point of failure. This includes Cairo steps, builtins, syscalls, L1 messages, events, and state diffs during the validate and execute stages.

Transaction receipt

The transaction receipt contains:

  • Basic transaction details (block identifiers and the index within the block).

  • A summary of the execution resources used by the transaction.

  • The events emitted .

  • A list of messages sent to L1.

  • A consumed L1 message (in case the transaction invokes an L1 handler).

The following is an example of a receipt:

{
  "execution_status": "SUCCEEDED",
  "finality_status": "ACCEPTED_ON_L2",
  "block_hash": "0x65fd9e8926b116fb51bf0955cc431cf6720ccea1afdc3769cbd39c1f5fc4973",
  "block_number": 307039,
  "transaction_index": 0,
  "transaction": {
    "transaction_hash": "0x7b5de063c4f341dacca79ceae12ff309da719a79e50e9b54b9f7c2dae3d6893",
    "version": "0x1",
    "max_fee": "0x2386f26fc10000",
    "signature": [
      "0x7bd8d271a6eef3dba6da8c5380ab880ea17b27a3c05af7ad8a3b4035dbebb64",
      "0x3c5c432d64fd4777df8198baa5e40a02b532e0ba7553b913177de08478e8d4c"
    ],
    "nonce": "0x1739",
    "sender_address": "0x219937256cd88844f9fdc9c33a2d6d492e253ae13814c2dc0ecab7f26919d46",
    "calldata": [
      "0x1",
      "0x7812357541c81dd9a320c2339c0c76add710db15f8cc29e8dde8e588cad4455",
      "0x3d7905601c217734671143d457f0db37f7f8883112abd34b92c4abfeafde0c3",
      "0x0",
      "0x2",
      "0x2",
      "0x4ebba09c4dd53270868365e0064826264ea916e6901af7e05bb1758b1bf5adc",
      "0x106ffe440d7c2192ec5f377b82538816e009b862a9afa9059c2e57c6a7c2242"
    ],
    "type": "INVOKE_FUNCTION"
  }
}