Skip to content

Commit b3df00f

Browse files
authored
v0.14.0 transactions (#1635)
* init * cont * finish * minor fix * typo fix * invoke rebuild * minor change
1 parent 9980b72 commit b3df00f

File tree

1 file changed

+109
-45
lines changed

1 file changed

+109
-45
lines changed

components/Starknet/modules/architecture/pages/transactions.adoc

Lines changed: 109 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
= Transactions
22

33
== Overview
4-
Transactions are cryptographically signed instructions from accounts that update the state of the Starknet network. Starknet supports only xref:transaction_types[three types] of transactions, with each type going through the same xref:transaction_lifecycle[lifecycle] to receive its xref:transaction_statuses[execution and finality statuses]. Each transaction is issued a xref:transaction_receipt[receipt], which includes its statuses and other information about it.
4+
Transactions are cryptographically signed instructions from accounts that update the state of the Starknet network. Starknet supports only xref:transaction_types[three types] of transactions, with each type going through the same xref:transaction_lifecycle[lifecycle] to receive its xref:transaction_statuses[execution and finality statuses]. Every transaction that was executed successfully is issued a xref:transaction_receipt[receipt], which includes its statuses, as well as other information about it.
55

66
.Additional information
77

@@ -12,40 +12,33 @@ Transactions are cryptographically signed instructions from accounts that update
1212
Starknet supports the following types of transactions:
1313

1414
[horizontal,labelwidth="20"]
15-
`DECLARE`:: Declares new contract classes, enabling new contract instances.
16-
`INVOKE`:: Invokes an existing function in a contract.
17-
`DEPLOY_ACCOUNT`:: Deploys new account contracts in smart wallets.
15+
`DECLARE`:: Introduces a new contract class to Starknet, enabling other contracts to either deploy instances of it or use it via a library call
16+
+
17+
[TIP]
18+
====
19+
For more information about contract classes and instances, see the https://book.cairo-lang.org/ch100-01-contracts-classes-and-instances.html[Cairo Book].
20+
====
1821

22+
`INVOKE`:: Invokes a function in an existing contract instance, undergoing validation and execution initiated by the caller account's xref:accounts.adoc#starknets_account_structure[`+__validate__+` and `+__execute__+` functions] (respectively).
23+
+
1924
[NOTE]
2025
====
21-
The xref:messaging.adoc#l1_handler_transaction[`L1HandlerTransaction` type] is also a valid transaction type within Starknet, be it cannot be broadcast through the Starknet API like other transaction types, as it was specifically designed for internal Starknet operations (particularly, handling messages from L1 to L2).
22-
23-
The `DEPLOY` transaction type existed in Starknet for deploying account before being replaced by `DEPLOY_ACCOUNT`. `DEPLOY` only had one version (v0) and is now unsupported by Starknet.
26+
The validation stage verifies that the caller account approves the transaction. Because an account's `+__validate__+` and `+__execute__+` functions can contain any logic, the caller account ultimately determines how to handle the `INVOKE` transaction.
2427
====
2528

26-
// === `INVOKE`
27-
28-
// The `INVOKE` transaction type invokes a function in an existing contract instance. The contract code of the account that sends the `INVOKE` transaction determines how to process the transaction.
29-
30-
// [NOTE]
31-
// ====
32-
// Because an account's `+__validate__+` and `+__execute__+` functions can contain any logic, the account ultimately determines how to handle the `INVOKE` transaction.
33-
// ====
34-
35-
// Every `INVOKE` transaction in Starknet undergoes the validation and execution stages, initiated by the `+__validate__+` and `+__execute__+` functions. The validation stage verifies that the account that sent the transaction approves it.
36-
37-
// === `DECLARE`
38-
39-
// The `DECLARE` transaction introduces new contract classes into the state of Starknet, enabling other contracts to deploy instances of those classes or use them in a library call. For more information, see xref:architecture:smart-contracts/contract-classes.adoc[contract classes].
40-
41-
// === `DEPLOY_ACCOUNT`
42-
43-
// Since StarkNet v0.10.1 the `DEPLOY_ACCOUNT` transaction replaces the `DEPLOY` transaction for deploying account contracts.
29+
`DEPLOY_ACCOUNT`:: Deploys a new account contract to Starknet.
30+
+
31+
[TIP]
32+
====
33+
For more information about deploying a new account, see xref:accounts.adoc#deploying_a_new_account[Accounts].
34+
====
4435

45-
// To use it, you should first pre-fund your new account address so that you can pay the
46-
// transaction fee. You can then send the `DEPLOY_ACCOUNT` transaction.
36+
[NOTE]
37+
====
38+
The xref:messaging.adoc#l1_handler_transaction[`L1HandlerTransaction` type] is also a valid transaction type within Starknet, be it cannot be broadcast through the Starknet API like other transaction types, as it was specifically designed for internal Starknet operations (particularly, handling messages from L1 to L2).
4739
48-
// For more information, see xref:accounts/deploying-new-accounts.adoc[].
40+
The `DEPLOY` transaction type existed in Starknet for deploying account before being replaced by `DEPLOY_ACCOUNT`. `DEPLOY` only had one version (v0) and is now unsupported by Starknet.
41+
====
4942

5043
Each transaction type is versioned, with versions increasing when the fields that comprise the transaction change, either with the addition of a new field or the removal of an existing field. The following table summarizes the current, deprecated, and unsupported versions of each transaction type:
5144

@@ -55,18 +48,18 @@ Each transaction type is versioned, with versions increasing when the fields tha
5548

5649
|`INVOKE`
5750
| v3
58-
| v1, v0
5951
| None
52+
| v1, v0
6053

6154
|`DECLARE`
6255
| v3
63-
| v2, v1
64-
| v0
56+
| None
57+
| v2, v1, v0
6558

6659
|`DEPLOY_ACCOUNT`
6760
| v3
68-
| v1
6961
| None
62+
| v1
7063
|===
7164

7265
[IMPORTANT]
@@ -79,29 +72,55 @@ Sending transaction that use deprecated versions is still supported, but support
7972
== Transaction lifecycle
8073
The high-level steps in the Starknet transaction lifecycle are as follows:
8174

82-
. *Transaction submission:* A transaction is submitted to one of the gateways, which functions as the mempool, and marks it as received.
75+
. *Transaction submission:* A transaction is submitted to a sequencer by a full node.
8376

8477
. *Mempool validation:*
85-
The mempool performs preliminary validation of the transaction, such as ensuring that its invoker's balance exceeds the transaction's `max_fee` value, assuring the transaction's calldata length is within the legal limit, and more. If the transaction is invalid, it does not proceed.
86-
+
87-
[NOTE]
88-
====
89-
Mempool validation in this context is analogous to Ethereum's signature checking, and includes running the account's `+__validate__+` function for an `INVOKE` transaction, `+__validate_declare__+` for a `DECLARE` transaction, or `+__validate_deploy__+` for a `DEPLOY_ACCOUNT` transaction.
90-
====
78+
The sequencer's xref:transaction_mempool[mempool] performs preliminary validation of the transaction, such as ensuring that its invoker's balance exceeds the transaction's `max_fee` value, assuring the transaction's calldata length is within the legal limit, and more. If the transaction is invalid, it does not proceed.
79+
// +
80+
// [NOTE]
81+
// ====
82+
// Mempool validation in this context is analogous to Ethereum's signature checking, and includes running the account's `+__validate__+` function for an `INVOKE` transaction, `+__validate_declare__+` for a `DECLARE` transaction, or `+__validate_deploy__+` for a `DEPLOY_ACCOUNT` transaction.
83+
// ====
9184
. *Sequencer validation:* The sequencer performs preliminary validation of the transaction before executing it to ensure that the transaction is still valid. If the transaction is invalid, it does not proceed.
9285
+
86+
// [NOTE]
87+
// ====
88+
// The sequencer repeats the same validation performed by the mempool.
89+
// ====
90+
91+
. *Execution:* The sequencer batches all transactions that passed the preliminary validation into a block, and applies them to the state sequentially. If a transaction fails during execution, it is included in the block with as reverted.
92+
93+
. *Proof generation and verification:* The prover uses the xref:os.adoc[Starknet operating system] to computes the proof for the correct execution of all transactions in the block, and transmits it to the L1 verifier, which verifies it. At this point, the L1 state is updated to include the transaction.
94+
95+
=== Mempools
96+
97+
Up to and including Starknet v0.13.5, transactions were received and ordered by the sequencer in a first-in-first-out (FIFO) fashion. Starting from Starknet v0.14.0, each sequencer will instead maintain a mempool, decouping the transaction order of arrival from the transaction ordering in blocks, for which they are can decide their own policy.
98+
99+
The introduction of mempools will have the following implications on how transactions are processed:
100+
101+
* *Nonces*: Transactions with a nonce greater than the sender's current nonce + stem:[x] will be rejected by the mempool, where:
102+
** A sender's current nonce is the sender's nonce in the latest finalized state at the time the transaction is received
103+
** stem:[50 \leq x \leq 100] is still TBD for `INVOKE` and `DEPLOY_ACCOUNT` transactions and stem:[x = 0] for `DECLARE` transactions (i.e., no declares with future nonces)
104+
105+
* *Fee escalation*: A transaction in the mempool can be replaced by a transaction sent from the same account with the same nonce and both `tip` and `max_l2_gas_price` increased by at least 10%
106+
+
93107
[NOTE]
94108
====
95-
The sequencer repeats the same validation performed by the mempool.
109+
There are unlikely edge cases in which a transaction is not replaced despite submitting a valid transaction to replace it, such as the existing transaction entering a block while the new one is still processed in the gateway.
96110
====
97111

98-
. *Execution:* The sequencer batches all transactions that passed the preliminary validation into a block, and applies them to the state sequentially. If a transaction fails during execution, it is included in the block with as reverted.
112+
* *Transaction time-to-live (TTL)*: Transactions that cannot be included in a block and have exceeded their TTL, currently configured to be 5 mins, are periodically evicted from the mempool
99113

100-
. *Proof generation and verification:* The prover uses the xref:os.adoc[Starknet operating system] to computes the proof for the correct execution of all transactions in the block, and transmits it to the L1 verifier, which verifies it. At this point, the L1 state is updated to include the transaction.
114+
* *`DECLARE` transactions time-to-mature (TTM)*: Before being inserted into the mempool, `DECLARE` transactions are sent to a "waiting room" until they exceed their TTM, where TTM < TTL but is still TBD. While in the "waiting room", `DECLARE` transactions can't be replaced, and transactions sent with the same nonce as a transaction in the "waiting room" by the same account are rejected
115+
// +
116+
// [NOTE]
117+
// ====
118+
// The motivation for the `DECLARE` transactions "waiting room" is to impede a DoS attack where a `DECLARE` transaction is submitted and its code is compiled, but is then reaplced by sending a transaction with the same nonce while it matures.
119+
// ====
101120

102121
== Transaction statuses
103122

104-
The following are the possible statuses of a transaction from the moment a user sends it until the moment it passes the L1 verifier:
123+
A transaction's state is represented by the following _finality_ and _execution_ statuses:
105124

106125
[cols="1,2,4"]
107126
|===
@@ -141,9 +160,54 @@ Since the `DEPLOY_ACCOUNT` and `DECLARE` transactions don't have an execution ph
141160
| The transaction was successfully executed by the sequencer and is included in a block.
142161
|===
143162

144-
The diagram below illustrates how each transaction status fits into the overall transaction flow:
163+
Starting from Starknet version 0.14.0, these statuses will change to the following:
164+
165+
[cols="1,2,4"]
166+
|===
167+
| Type | Status | Description
168+
169+
.6+.^| *Finality*
170+
171+
| `NOT_RECEIVED`
172+
| The transaction is not yet known to any sequencer.
173+
174+
| `RECEIVED`
175+
a| A full node has successfully submitted the transaction to a sequencer.
176+
[NOTE]
177+
====
178+
As there is currently no P2P protocol between full nodes for updating on each other about received transactions, querying a different node than the one that submitted the transaction for its status will result in a `Transaction hash not found` error.
145179
146-
image::txn-flow.png[]
180+
Therefore, relying on `RECEIVED` statuses requires initiating sticky HTTP sessions with your full node provider.
181+
====
182+
183+
| `PRE-CONFIRMED`
184+
a| The transaction was written to the feeder gateway's storage by a sequencer.
185+
[NOTE]
186+
====
187+
As the transaction hasn't been executed yet, no execution information is available and only the transaction hash is written to the feeder gateway's storage.
188+
====
189+
190+
| `EXECUTED`
191+
| The transaction was successfully executed by a sequencer and its receipt was written to the feeder gateway's storage.
192+
193+
| `ACCEPTED_ON_L2`
194+
| The transaction was included in a block finalized by the consensus protocol.
195+
196+
| `ACCEPTED_ON_L1`
197+
| The Starknet state on L1 moved to a block height which is greater than or equal to the height of the block containing the transaction.
198+
199+
.2+.^| *Execution*
200+
201+
| `REVERTED`
202+
a| The transaction failed during execution by a sequencer, and was included in a block as reverted.
203+
[NOTE]
204+
====
205+
Since the `DEPLOY_ACCOUNT` and `DECLARE` transactions don't have an execution phase, they cannot be reverted.
206+
====
207+
208+
| `SUCCEEDED`
209+
| The transaction was successfully executed by a sequencer and is included in a block.
210+
|===
147211

148212
=== State implications of reverted transactions
149213

0 commit comments

Comments
 (0)