In the process of Starknet becoming more decentralized, the development of the network is also transitioning towards a decentralized approach. The upcoming version of Starknet will be developed based on a public specification, enabling infrastructure providers and developers to prepare for future versions in advance.
This post is a part of this ongoing process, and for upcoming versions, we plan to share detailed SNIPs in advance.
This post proposes an enhancement to Starknet v0.12.1, addressing the issue of valuable sequencer resources being allocated to processing transactions that do not contribute to the final block. Currently, failed transactions do not pay fees, resulting in a flood of failed transactions occupying the space intended for other fee-paying transactions. To optimize the utilization of the sequencer capacity and fully leverage Starknet’s processing potential for valid transactions, the proposal suggests charging fees and including failed transactions in a block in a trusted manner. This enhancement elimantes the inefficiency observed in Starknet v0.11.0, where no fees are charged for failed transactions, resulting in significant investments of up to 66% of the sequencer capacity on transactions that are not included in the block.
Outline of the proposal
In a high-level perspective, the current process in Starknet involves a transaction being initially accepted by one of the gateways, functioning as the Mempool, marking its status as RECEIVED. The Sequencer operation, a single service, then sequentially applies the transactions to the state, marking them as ACCEPTED_ON_L2. The Prover stage executes the operating system on the new block, computes the proof, and transmits it to L1.
The proposed changes aim to enhance this process. Firstly, a validation stage will be added to the mempool to prevent invalid transactions from consuming valuable time of the sequencer. This ensures that only valid transactions proceed further. Additionally, transactions that fail during the execution stage in the sequencer will be included in the block with the status REVERTED.
Protocol changes
In the context of Starknet, the protocol level refers to modifications made to the underlying Starknet OS cairo program that is proven. This section outlines the necessary changes at the protocol level to enable the inclusion of failed transactions in a block.
-
Transaction status:
REVERTED
- the transaction passed validation but failed in execution.
-
State implications of REVERTED transaction:
- Nonce increases
- Fee charge
- All changes that occurred during the
__validate__
stage are not reverted. - All changes that occurred during the
__execute__
are reverted. Specifically, no messages to L1 or events.
-
The fee that will be charged is fee = Min(max_fee, consumed_resources) * configurable_factor when the configurable_factor will be 1.
-
This will ensure that transactions will never pay more than the user signed and only for the actual resources used if possible.
-
The consumed_resources are the resource used for the execution of the transaction by the point that it failed:
- Cairo steps, builtins and syscalls in
__execute__
until the failure point. - Cairo steps, builtins, syscalls, L1 messages, events and state diffs during
__validate__
- Cairo steps, builtins and syscalls in
-
-
The Starknet OS will execute the following for failed transactions:
__validate__
- Nonce increment
- Fee transfer
-
In the future, when only Cairo 1.0 is supported on Starknet, the OS will prove REVERTED transactions by executing the entire transaction.
API changes
This section describes the API-level changes necessary to support the inclusion of failed transactions.
See changes in starknet-specs
-
TRANSACTION_TRACE: trace of a failed invoke tx will include the revert reason for the failed execution and will not include the execute call stack.
- In the future, when only Cairo 1.0 is supported on Starknet, the call stack of execute until the failiure point will be accsseible through the trace.
-
New TXN_STATUS: REVERTED.
- Txs which pass validate, have the right nonce and are from an account with enough balance, and
__execute__
entrypoint failed afterward, will be included in a block and have the status REVERTED.
- Txs which pass validate, have the right nonce and are from an account with enough balance, and
-
New fields will be added to the transaction receipt in order to better describe the transaction status in light of the newly introduced
REVERTED
status, as discussed in this post. This allows for transactions to be both unsuccessful and included in a block that is accepted on L2/L1.-
finality_status
- will indicate the finality status of each transaction. It can have the valuesRECEIVED
,ACCEPTED_ON_L2
, orACCEPTED_ON_L1
. TheRECEIVED
status signifies a transaction that passed the validation in the Mempool but wasn’t included in a block yet.ACCEPTED_ON_L2
andACCEPTED_ON_L1
indicate that the transaction was included in a block that was accepted on L2 or L1, respectively -
execution_status
- will indicate the execution status of the transaction itself. It can have the valuesREJECTED
,REVERTED
, orSUCCEEDED
. TheREJECTED
status is assigned to transactions that failed during the__validate__
phase in the sequencer after passing validation in the Mempool. Transactions with theREVERTED
status failed during the__execute__
phase, whileSUCCEEDED
indicates successful transactions. Transactions with the REJECTED status will not be included in a block and will always have the finality_statusRECEIVED
-
The existing status field will be retained for backward compatibility and can have the following values:
RECEIVED
,REJECTED
,REVERTED
,ACCEPTED_ON_L2
, orACCEPTED_ON_L1
. For reverted transactions, regardless of whether they are included in a block accepted on L1 or L2, the status will be indicated asREVERTED
-
StarkWare’s Current Sequencer changes
The current centralized sequencer implementation in Starknet will undergo specific modifications to facilitate the successful inclusion of failed transactions. This section, which is not part of the Protocol/API changes, provides an explanation of the validation process that will be conducted in the temporary centralized sequencer of Starknet, as its behavior impacts all users of Starknet:
The validation phase in the gateway
- Check max_fee is higher than the minimal tx cost
- Check Account balance is at least max_fee
- Check nonce is bigger than the current nonce
- Execute
__validate__
- Limit #txs per account in the Gateway
Rejected status for transactions
REJECTED
- will denote a transaction that passed the gateway and didn’t pass validation in the sequencer. This status is not part of the protocol, as the rejected transaction will not get included in a block.
Conclusion
The proposed changes in Starknet v0.12.1 aim to improve the efficiency of the sequencer capacity by addressing the issue of processing failed transactions. Through the inclusion of failed valid-transactions in a block and charge fee for them, Starknet aims to optimize its processing potential for valid transactions.