Starknet 백서

Starknet

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 73쪽 중 72쪽

ticipate in the network or that the network will continue to function as intended. The technical documents provided herein describe certain planned and specified economic fundamentals of a digital asset, STRK. These materials are intended for informational purposes only and are meant to outline the usage and functionalities of the asset within Starknet. It is important to understand that the primary purpose of STRK is to pay for fees, provide a mechanism for securing consensus, and allow for decentralized governance on Starknet; it is not intended to serve as an investment. Starknet relies upon third parties to adopt and implement the software and protocols as users of Starknet. It also relies, in whole or partly, on third parties to develop, supply and otherwise support it. As a Layer 2 network over Ethereum, Starknet also relies upon third parties maintaining and operating the Ethereum network. There is no assurance or guarantee that those third parties will complete their work, properly carry out their obligations, and/or otherwise meet anyone’s needs. STRK, as the native token of Starknet, may be subject to the risks of the Starknet network, including, without limitation, the following: (i) the technology associated with Starknet may not function as intended; (ii) the details of the Starknet token economics including the total supply and distribution schedule may be changed due to decisions made, amongst other, by the consensus of participants of the Starknet network; (iii) Starknet may fail to attract sufficient interest from key stakeholders or users; (iv) Starknet may not progress satisfactorily and Starknet tokens may not be useful or valuable; (v) Starknet may suffer from attacks by hackers or other individuals; and (vi) Starknet is comprised of open-source technologies that depend on a network of computers to run certain software programs to process transactions, and because of this model StarkWare and the Starknet Foundation have very limited control over Starknet. Risks related to blockchain technology in general and Starknet in particular may impact the usefulness of Starknet, and, in turn, the utility or value of STRK. The software and hardware, technology and technical concepts and theories applicable to Starknet and STRK are still in an early development stage and there is no warranty that Starknet will achieve any specific level of functionality or success, nor that the underlying technology will be uninterrupted or error-free, and there is an inherent risk that the technology could contain weaknesses, vulnerabilities or bugs causing, potentially, the complete loss of any Starknet tokens held by Starknet users. As with most commonly used public blockchains, STRKs held in user accounts are most commonly accessed using a private key that corresponds to the address at which they are stored. However, alternative access mechanisms, such as biometrics, multisignature setups, or other authentication methods, are also available depending on the account’s contract code. If the private key, or the "seed" used to create the address and corresponding private key are lost or stolen, the tokens associated with that address might be unrecoverable and might be permanently lost. Public blockchain-based systems, including Starknet and the underlying Ethereum network, depend on independent verifiers, and therefore may be vulnerable to consensus attacks including, but not limited to, double-spend attacks, majority voting power attacks, race condition attacks, and censorship attacks. These attacks, if successful, could result in the permanent loss of STRK. Starknet, STRK, and blockchain technology are nascent, and there may be additional risks not described above or that may be new or unanticipated. We recommend only using Starknet or holding STRK if you are familiar with the technology and aware of the risks. This document and its contents are not, and should not be construed as, an offer to sell, or the solicitation of an offer to buy, any tokens, nor should it or any part of it form the basis or be relied on in connection with any contract or commitment whatsoever. This document is not advice of any kind, including legal, investment, financial, tax, or any other professional advice. Nothing in this document should be read or interpreted as a guarantee or promise of how the Starknet network or its STRK will develop, be utilized, or accrue value. All information in this document is provided on an “as is” basis without any representation or warranty of any kind. This document only outlines current plans, which could change at the discretion of various parties, and the success of which will depend on many factors outside of StarkWare and the Starknet Foundation’s control. Such future statements necessarily involve known and unknown risks, which may cause actual performance and results in future periods to differ materially from what we have described or implied in this document. StarkWare and the Starknet Foundation disclaim all warranties, express or implied, to the fullest extent permitted by law with respect to the functionality of Starknet and STRK. ## Further reading Learn more in the [**STRK MICAr White Paper**](https://drive.google.com/file/d/1GtHtJbpAEgkh2FpZkdJjidwA4DkpSYEO/view?usp=sharing), published on behalf of Tzolkin GmbH # Transactions Source: https://docs.starknet.io/learn/protocol/transactions ## Overview Transactions are cryptographically signed instructions from accounts that update the state of the Starknet network. Starknet supports only [three types](#transaction_types) of transactions, with each type going through the same [lifecycle](#transaction_lifecycle) to receive its [execution and finality statuses](#transaction_statuses). Every transaction that was executed successfully is issued a [receipt](#transaction_receipt), which includes its statuses, as well as other information about it. Additional information * [Transaction fields and hash calculations reference](/learn/cheatsheets/transactions-reference/) in *References* * [`starknet_api_openrpc.json`](https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json) in the `starknet-specs` GitHub repository ## Transaction types Starknet supports the following types of transactions: | | | | - | - | | `DECLARE` | Introduces a new contract class to Starknet, enabling other contracts to either deploy instances of it or use it via a library call<Tip> For more information about contract classes and instances, see the Cairo Book. </Tip> | | `INVOKE` | Invokes a function in an existing contract instance, undergoing validation and execution initiated by the caller account's [`__validate__ and __execute__ functions`](/learn/protocol/accounts/#starknets_account_structure) (respectively).<Note> 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. </Note> | | `DEPLOY_ACCOUNT` | Deploys a new account contract to Starknet.<Tip> For more information about deploying a new account, see Accounts. </Tip> | <Note> The [`L1HandlerTransaction type`](/learn/protocol/messaging/#l1_handler_transaction) 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). 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. </Note> 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: | Type | Current version | Deprecated versions | Unsupported versions | | - | - | - | - | | `INVOKE` | v3 | None | v1, v0 | | `DECLARE` | v3 | None | v2, v1, v0 | | `DEPLOY_ACCOUNT` | v3 | None | v1 | <Warning> Do not submit a transaction that uses an unsupported transaction type, as it cannot be included in a proof, and therefore cannot become part of a Starknet block. Sending transaction that use deprecated versions is still supported, but support will be removed in an upcoming Starknet release. </Warning> ## Transaction lifecycle The high-level steps in the Starknet transaction lifecycle are as follows: 1. **Transaction submission:** A transaction is submitted to a sequencer by a full node. 2. **Mempool validation:** The sequencer's [mempool](#transaction_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. 3. **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. 4. **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. 5. **Proof generation and verification:** The prover uses the [Starknet operating system](/learn/protocol/snos/) 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. ### Mempools 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. The introduction of mempools will have the following implications on how transactions are processed: * **Nonces**: Transactions with a nonce greater than the sender's current nonce + $x$ will be rejected by the mempool, where: * A sender's current nonce is the sender's nonce in the latest finalized state at the time the transaction is received * X is 200 for `INVOKE` and `DEPLOY_ACCOUNT` transactions and $x = 0$ for `DECLARE` transactions (i.e., no declares with future nonces) * **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%. If the transaction was submitted with zero tip, it can still be replaced by another transaction with zero tip. <Note> 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. </Note> * **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 * **`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 ## Transaction statuses Since Starknet version 0.14.0, the finality statuses are the following: | Type | Status | Description | | - | - | - | | **Finality** | `NOT_RECEIVED` | The transaction is not yet known to any sequencer. | | | `RECEIVED` | A full node has successfully submitted the transaction to a sequencer.<Note> 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.<br /><br />Therefore, relying on RECEIVED statuses requires initiating sticky HTTP sessions with your full node provider. </Note> | | | `CANDIDATE` | The transaction was written to the feeder gateway's storage by a sequencer.<Note> 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. </Note> | | | `PRE_CONFIRMED` | The transaction was successfully executed by a sequencer and its receipt was written to the feeder gateway's storage. | | | `ACCEPTED_ON_L2` | The transaction was included in a block finalized by the consensus protocol. | | | `ACCEPTED_ON_L1` | 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. | | **Execution** | `REVERTED` | The transaction failed during execution by a sequencer, and was included in a block as reverted.<Note> Since the DEPLOY\_ACCOUNT and DECLARE transactions don't have an execution phase, they cannot be reverted. </Note> | | | `SUCCEEDED` | The transaction was successfully executed by a sequencer and is included in a block. | ### State implications of reverted transactions When a transaction is marked as `REVERTED`, the following state implications occur: | | | | - | - | | Nonce increases | The nonce value for the account of the failed transaction iterates despite the failure. | | Fee charge | The sequencer charges a fee for the execution of the transaction up to the point of failure, and a respective `Transfer` event is emitted. | | Partial reversion | All changes that occurred during the validation stage are not reverted. However, all changes that occurred during the execution stage are reverted, including all messages to L1 or any events that were emitted during this stage. Events might still be emitted from the validation stage or the fee charge stage. | | Fee calculation | The fee charged for `REVERTED` transactions is the smaller of the following two values:<br /><br />• The maximum fee that the user is willing to pay, either `max_fee` (pre-v3 transactions) or $\texttt{max\_amount} \cdot \texttt{max\_price\_per\_unit}$ (v3 transactions).<br /><br />• The total consumed resources.<Note> Consumed resources are resources used for the execution of the transaction up to the point of failure, including Cairo steps, builtins, syscalls, L1 messages, events, and state diffs during the validation and execution stages. </Note> | ## Transaction receipt A transaction receipt can be obtained by using the Starknet API's `starknet_getTransactionReceipt` endpoint and contains the following fields: | | | | - | - | | `transaction_hash` | The hash of the transaction. | | `actual_fee` | The actual fee paid for the transaction. | | `finality_status` | The finality status of the transaction. | | `execution_status` | The execution status of the transaction. | | `block_hash` | The hash of the block that includes the transaction | | `block_number` | The sequential number of the block that includes the transaction | | `messages_sent` | A list of messages sent to L1. | | `events` | The events emitted. | | `execution_resource` | A summary of the execution resources used by the transaction. | | `type` | The type of the transaction. | The following is an example of a transaction receipt: ```json theme={null} { "jsonrpc": "2.0", "result": { "actual_fee": "0x221db5dbf6db", "block_hash": "0x301fc0d09c5810600af7bb9610be10596ad6f4e6d28a60d397dd148f0962a88", "block_number": 906096, "events": [ { "data": [ "0x181de8b0cd32999a5cc962c5f724bc0f6a322f02957b80e1d5fef49a87588b7", "0x0", "0x9184e72a000", "0x0" ], "from_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", "keys": [ "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9" ] }, { "data": [ "0x764da020183e28a48ee38a9474f84e7e5ff13194", "0x9184e72a000", "0x0", "0x181de8b0cd32999a5cc962c5f724bc0f6a322f02957b80e1d5fef49a87588b7" ], "from_address": "0x73314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b82", "keys": [ "0x194fc63c49b0f07c8e7a78476844837255213824bd6cb81e0ccfb949921aad1" ] }, { "data": [ "0x181de8b0cd32999a5cc962c5f724bc0f6a322f02957b80e1d5fef49a87588b7", "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8", "0x221db5dbf6db", "0x0" ], "from_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", "keys": [ "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9" ] } ], "execution_status": "SUCCEEDED", "finality_status": "ACCEPTED_ON_L2", "messages_sent": [ { "from_address": "0x73314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b82", "payload": [ "0x0", "0x764da020183e28a48ee38a9474f84e7e5ff13194", "0x9184e72a000", "0x0" ], "to_address": "0xc3511006c04ef1d78af4c8e0e74ec18a6e64ff9e" } ], "transaction_hash": "0xdeadbeef", "type": "INVOKE" }, "id": 1 } ``` # Attesting to blocks Source: https://docs.starknet.io/secure/quickstart/attesting-to-blocks ## Overview Welcome to the third installment of the *Help secure Starknet* guide! 🛡️ Starting from its second phase, the staking protocol requires validators to prove they are actively preserving the history of the network by submitting attestations to randomly assigned blocks in each epoch. This installment of the series will therefore walk you through [running attestation service](#running-pathfinders-attestation-service). <Note> To run a Nethermind's attestation service, see [the instructions in its GitHub repository](https://github.com/NethermindEth/starknet-staking-v2/tree/main?tab=readme-ov-file#starknet-staking-v2). </Note> ## Running attestation service Luckily, running [attestation service](https://github.com/software-mansion/starknet-validator-attestation/tree/main) is as simple as running: ```shell theme={null} docker run -it --rm --network host \ -e VALIDATOR_ATTESTATION_OPERATIONAL_PRIVATE_KEY=$OPERATIONAL_PRIVATE_KEY \ ghcr.io/software-mansion/starknet-validator-attestation \ --staking-contract-address 0x03745ab04a431fc02871a139be6b93d9260b0ff3e779ad9c8b377183b23109f1 \ --attestation-contract-address 0x03f32e152b9637c31bfcf73e434f78591067a01ba070505ff6ee195642c9acfb \ --staker-operational-address $OPERATIONAL_ADDRESS \ --node-url http://localhost:9545/rpc/v0_8 \ --local-signer ``` If successful, the result should look similar to the following: ```shell theme={null} Current attestation info staker_address=0x48f8ddc0bc864f33d4c47b79a1f0e1460e0777d0b0224d8c291f1039523306e operational_address=0x48f8ddc0bc864f33d4c47b79a1f0e1460e0777d0b0224d8c291f1039523306e stake=100000000000000000000 epoch_id=1201 epoch_start=712773 epoch_length=40 attestation_window=16 2025-04-22T11:04:22.716449Z INFO starknet_validator_attestation::state: New epoch started staker_address=0x48f8ddc0bc864f33d4c47b79a1f0e1460e0777d0b0224d8c291f1039523306e operational_address=0x48f8ddc0bc864f33d4c47b79a1f0e1460e0777d0b0224d8c291f1039523306e stake=100000000000000000000 epoch_id=1205 epoch_start=712933 epoch_length=40 attestation_window=16 2025-04-22T11:11:00.263344Z INFO starknet_validator_attestation::state: Attestation transaction sent transaction_hash=0x79f9f5ec8dbfca48a132e8d23caad15455c6e0dc98ec517a7013c374d7d5501 2025-04-22T11:11:03.017827Z INFO starknet_validator_attestation::state: Attestation confirmed staker_address=0x48f8ddc0bc864f33d4c47b79a1f0e1460e0777d0b0224d8c291f1039523306e epoch_id=1205 ``` # Becoming a validator Source: https://docs.sta
프로젝트로 돌아가기