Starknet 백서

Starknet

원문

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

et_execution_info), which returns the block hash and number, correctness means consistency with the value given to SNOS as input. For contract calls, however, one needs to execute the called contract and verify that the actual response and the guessed response are identical. But how can we guess the responses to all the contract calls before executing them? For that, it is important to distinguish two different styles-of-execution that a Starknet block goes through: * The first one is done by a sequencer, when constructing the block from incoming transactions * The second one is done by a prover, when executing SNOS in order to generate a proof for the (already finalized) block Therefore, when running the OS, we already know what is going to happen: the block has already been executed by the sequencer, and so we know exactly what contracts and storage slots will be accessed, what each internal call will return, and so on. It's worth noting that in the first execution, the sequencer can run in whatever way he chooses. In fact, he doesn't even have to run through the Cairo VM at all, but rather [precompile contracts to machine code and run them natively](https://github.com/lambdaclass/cairo_native). Moreover, sequencers can also impose restrictions that are not enforced by SNOS. Such discrepancy between the two executions may seem like a bug, but as long as these restrictions only protect the sequencers themselves, rather than the correctness of execution, there is no reason for SNOS to enforce them. A good example for such restriction is the [limits on validation functions](/learn/protocol/accounts/#limitations_of_validation) that protect the sequencer from DoS attacks. It is crucial, however, that both executions agree on the execution semantics, since, as mentioned in [What is SNOS?](#what_is_snos), SNOS is the final arbiter and if it disagrees on the validity of the block, the sequencer will not be able to produce a proof for that block (and the only way forward would be a reorg on Starknet). ### Multiblock input Starting from Starknet version 0.14.0, block times on Starknet will be substantially shorter, leading to more frequent but also smaller blocks. As every run of SNOS on a single block incurs a fixed cost which is independent of the size of the block, producing e.g. twice as many blocks also doubles this fixed cost. To mitigate this, SNOS will be modified in version 0.14.0 to receive multiple blocks as inputs. This also amortizes other non-negligible costs over a larger number of blocks: For example, if both block 10 and 11 use the same contract, SNOS loads and hashes its code only once instead of twice. ## Using SNOS to update Starknet's state The Starknet Core contract is the contract responsible for storing and updating Starknet's state on Ethereum. As of Starknet v0.13.2 and as part of [SHARP's applicative recursion feature](https://community.starknet.io/t/starknet-v0-13-2-pre-release-notes/114223#starknet-applicative-recursion-3), proofs of SNOS's execution are not enough to update the Starknet Core contract. Instead, it is required to submit an "applicative proof" of a different program called [the applicative bootloader](https://github.com/starkware-libs/cairo-lang/blob/8e11b8cc65ae1d0959328b1b4a40b92df8b58595/src/starkware/cairo/bootloaders/applicative_bootloader/applicative_bootloader.cairo#L15). The way the applicative bootloader works is by verifying a proof of one or more executions of a base program $B$ and then using their outputs as input to an aggregator program $A$. In the case of Starknet, $B$ is the SNOS program and $A$ is a new cairo program that squashes the state diffs of several blocks (the code of which can be found in the [cairo-lang GitHub repository](https://github.com/starkware-libs/cairo-lang/blob/8e11b8cc65ae1d0959328b1b4a40b92df8b58595/src/starkware/starknet/core/aggregator/main.cairo#L8)). This way, individual executions of SNOS for some block range can be "squashed" into a single program whose valid execution attests to the validity of all blocks within that range and whose output is the squashed state diff of these blocks. In order to verify that an "applicative proof" used the correct SNOS and aggregator programs, their program hashes must be stored in the Starknet Core contract. As each Starknet version is associated with a given SNOS program, this means that breaking protocol changes must be accompanied by an update to SNOS's (and possibly the aggregator's) program hash registered in the Starknet Core contract. <Tip> You can read the program hashes currently registered in the Starknet Core contract by using its [`programHash`](https://etherscan.io/address/0xc662c410c0ecf747543f5ba90660f6abebd9c8c4#readProxyContract#F13) (for SNOS's program hash) and [`aggregatorProgramHash`](https://etherscan.io/address/0xc662c410c0ecf747543f5ba90660f6abebd9c8c4#readProxyContract#F1) (for the aggregator's program hash) functions. </Tip> Finally, the Starknet Core contract is also responsible for verifying the few things that SNOS can't, including: * Verifying that the state given to SNOS as input is Starknet's current state on Ethereum * Verifying that all [L1→L2 messages](/learn/protocol/messaging/#l1-l2-messages) were sent on Ethereum ## Implementations The Cairo code of SNOS is available in the [cairo-lang GitHub repository](https://github.com/starkware-libs/cairo-lang/tree/8e11b8cc65ae1d0959328b1b4a40b92df8b58595/src/starkware/starknet/core/os). However, this repository does not include all the hints implementation, which are necessary to locally run SNOS. The current implementation of these hints in Python is now deprecated, and will no longer be maintained in future Starknet versions. <Warning> As part of the transition of Starknet's infrastructure to Rust, SNOS's Pythonic hints implementation is deprecated, and will no longer be maintained in future Starknet versions. </Warning> Instead, a new Rust implementation of the hints, including initializing all inputs of SNOS via a Starknet full node connection, is available in the [SNOS GitHub repository](https://github.com/keep-starknet-strange/snos/tree/cb2a6d26faeb658492756fe100bbdf5b1600c768). At the time of writing, this codebase supports the execution of SNOS for Starknet version 0.13.2. # Staking Source: https://docs.starknet.io/learn/protocol/staking ## Overview While Starknet is currently still centralized, it is [gradually](#roadmap) moving towards employing a [staking protocol](#protocol), handing over the responsibilities of producing, attesting, and proving blocks to validators. To facilitate this gradual implementation, the protocol's architecture is divided into several [components](#components), ensuring maximum flexibility and ease of upgrades. However, anyone holding STRK or BTC can already stake their tokens and earn rewards based on their level of participation by following [a few simple steps](#procedures). <Tip> If you are only interested in learning how to stake on Starknet, feel free to skip straight to [Procedures](#procedures). </Tip> <Note> Starting Q3 2025, Starknet's staking protocol enables BTC holders to lock their assets on Starknet and earn staking rewards in STRK, by supporting a curated selection of tokenized BTC representations ("wrappers") for direct BTC staking on Starknet. To review all BTC wrappers, use the staking contract's [`get_active_tokens`](https://github.com/starkware-libs/starknet-staking/blob/main/docs/spec.md#get_active_tokens) function. </Note> Additional resources * Staking dashboards by [Endur](https://dashboard.endur.fi/), [Voyager](https://voyager.online/staking-dashboard), [AlignedStake](https://www.aligned-stake.com/), and [Staking Rewards](https://www.stakingrewards.com/stake-app?input=starknet) * [Staking](https://www.starknet.io/staking) on starknet.io * [`starknet-staking`](https://github.com/starkware-libs/starknet-staking/tree/%40staking/contracts-v1.0.1-dev.510) on GitHub (deployed tag) * [Starknet launches phase 1 of its staking initiative on mainnet](https://www.starknet.io/blog/staking-phase-1/) on the Starknet blog * [SNIP 28: Staking V2 proposal](https://community.starknet.io/t/snip-28-staking-v2-proposal/115250) on the Starknet community forum * [SNIP 31: Bitcoin staking on Starknet](https://community.starknet.io/t/bitcoin-staking-on-starknet/115696) ## Roadmap Naturally, handing over the responsibility for maintaining and securing Starknet to validators in one day is neither feasible nor desirable. Instead, the staking protocol is implemented in incremental phases, with each phase bringing additional requirements from validators until they fully maintain and secure the network. The protocol is currently in the second of four phases, illustrated in following figure: <Warning> The staking protocol is currently in its second phase on both Sepolia and Mainnet. </Warning> <Frame> <img alt="" /> </Frame> ## Protocol The following sections describe the details of Starknet's staking protocol. The parameters used in the protocol are summarized in the following table: | Parameter | Mainnet | Sepolia | | - | - | - | | Minimum stake for validators | 20K STRK | 1 STRK | | Effective inflation coefficient ($\hat{C}$) | 4% | 2.13% | | Withdrawal security lockup | 7 days | 5 minutes | | Epoch length ($E$) | 1132 blocks | 231 blocks | | Epoch duration | 3600 seconds | 1200 seconds | | Attestation window ($W$) | 50 blocks | 30 blocks | | Number of epochs used for latency ($k$) | 1 epoch | 1 epoch | | Weight of BTC in staking power ($\alpha$) | 0.25 | 0.25 | ### Roles Starknet's staking protocol features two options for participation: * Staking directly as validators: Staking a minimum of 20,000 STRK and earning rewards by handling any responsibilities the protocol requires * Staking indirectly as delegators: Delegating STRK or BTC to validators who allow delegation and sharing in their rewards without handling any of their responsibilities <Note> Validators can choose whether to allow delegation or not. </Note> ### Epochs Starting from its second phase, the staking protocol introduces the notion of *epochs* (similarly to many other protocols). Epochs represent checkpoints, such that changes made in epoch $i$ are applied in epoch $i+k$, where $k$ is a new latency parameter. For example, the following figure illustrates a scenario where in epoch $i$ validator $A$ has 50K STRK staked and someone delegates an additional 10K STRK to them, and in epoch $i+1$ someone undelegates 30K STRK from $A$: <Frame> <img alt="" /> </Frame> ### Validator power The staking power of a validator staking $s$ amount of STRK and $b$ amount of BTC is defined as follows: $$ (1 - \alpha) \cdot \frac{s}{S} + \alpha \cdot \frac{b}{B} $$ where: * $\alpha = 0.25$ is a parameter determining BTC's weight in the staking power * $S$ and $B$ are the total STRK and BTC staked, respectively ### Validator responsibilities Starting from its second phase, the staking protocol requires validators to attest to blocks by running one of the followings: * The [Juno](https://juno.nethermind.io/hardware-requirements) full node with [Nethermind's attestation tool](https://github.com/NethermindEth/starknet-staking-v2/blob/main/README.md) * The [Pathfinder](https://docs.swmansion.com/pathfinder/getting-started/hardware-requirements) full node with [attestation tool](https://github.com/software-mansion/starknet-validator-attestation/blob/main/README.md) How does the block attestation mechanism work? In each epoch, each validator is assigned a single block whose relative number within the epoch is defined as follows: $$ h(\text{staked amount},\text{epoch id},\text{validator address}) \mod (E-W) $$ where: * $E$ is the number of blocks in an epoch, termed *epoch length* * $W$ is the number of blocks applicable for attestation submittal, termed *attestation window* During each epoch, validators have the opportunity to attest to their assigned block by submitting an `attest` transaction, which must be included within the attestation window. For example, if $W = 20$ and $N$ is the relative block number assigned to validator $A$, then $A$ must submit an `attest` transaction between the blocks whose relative number within the epoch are $N+1$ and $N+20$. <Note> In the second phase of the protocol, each Validator is required to perform only one attestation per epoch. </Note> The `attest` transaction includes the block hash of the attested block, ensuring validators actively use full nodes, as they need to continuously track block hashes. Additionally, the attestation is publicly verifiable, ensuring validators' reliability is publicly tested — a crucial prerequisite before handing them any core responsibilities. ### Rewards Staking rewards are issued in newly minted STRK tokens, based on a minting curve. The minting curve balances participation and inflation by adjusting the distributed rewards according to the total STRK locked in the protocol. The total minting rate percentage ($M$) is defined as follows: $$ M = \frac{\hat{C}}{10} \cdot \sqrt{\sigma} $$ where: * $\hat{C}$ is the effective inflation coefficient * $\sigma$ is the percentage of STRK staked out of the total STRK supply Annual reward percentages (APR) can therefore be calculated using the following formulas: * For STRK: $100 \cdot \frac{M}{\sigma} \cdot (1-\alpha)$ * For BTC: $(\alpha \cdot T \cdot \frac{M}{100} \cdot \frac{\text{STRK price}}{\text{BTC price}}) / B$ where: * $B$ is the total BTC staked * $T$ is the total STRK supply Rewards are distributed per epoch to validators in proportion to their staking power only if they performed their attestations in the epoch, on an "all or nothing" basis (i.e., validators that submitted a transaction during the epoch that proves they tracked the network will receive all the rewards for the epoch based on their staked amount, while validators that didn't will get no rewards for the epoch's entire duration). Rewards that go directly to the validator will accumulate in their account, and the rest will accumulate for delegators according to their share in the pool. <Note> [As previously described](#epochs), stakers that enter the protocol on epoch $i$ will start getting rewards only on epoch $i+k$, and stakers that signal an intent to exit the protocol on epoch $i$ will still get rewards until epoch $i$. </Note> ### Commissions The staking protocols enables validator to set a commission that is deducted from their delegators' rewards. Starting from its second phase, the staking protocol allows validators to increase their commission. To avoid an unexpected increase in commissions, validators must commit to a certain maximum commission $M$ and the last date (in epochs) that this commitment is relevant for. Until this date arrives, validators cannot increase their commission beyond $M$, but can freely change their commission in the range $[0,M]$. ### Latencies The following latencies are set in place: * To disincentivise sudden large withdrawals that could destabilize the network, funds are subject to a 7-day lockup after signaling an unstake intent, during which no rewards are earned and funds cannot be withdrawn. * Starting from the second phase of the protocol, to prevent delegator from switching too quickly between validators while still promoting a competitive delegation market, a switch intent that is signaled on epoch $i$ takes effect only on epoch $i+1$. ### Addresses To reduce exposure to threats and enhance security, multiple addresses are defined for both validators and delegators: * Validator addresses: * Staking address: Used for staking, adding stake, and unstaking. This address is only needed when entering or exiting the protocol and handles large amounts of STRK, and therefore is best kept by a cold wallet with minimal activity. * Rewards address: Used for receiving rewards. This address is only needed when receiving rewards, and therefore is best kept by a cold wallet. * Operational address: Used for operational purposes, such as block attestations (starting from the protocol's second phase), block proposing (starting from the protocol's third phase), etc. This address is used frequently and doesn't handle large amounts of funds, and therefore is best kept by a hot wallet. Starting from the protocol's second phase, however, hacking the operational address can lead to a lose of yield for the validator and its delegators. * Pools addresses: Used for pooling stake delegations for a specific token. For each token that a Staker is open to receiving delegations in, a unique delegation pool contract (with its own address) is created for users to delegate funds to. These pool contracts are automatically deployed for the Staker when they invoke the staking contract’s `set_open_for_delegation` function. <Warning> If your operational address uses local signing, the account associated with it must be deployed and unprotected (e.g., no Ready Wallet Guardian or Braavos hardware signer). </Warning> * Delegator addresses: * Staking address: Used for delegating stake, adding stake and unstaking. This address is only needed when entering or exiting the protocol and handles large amounts of STRK, and therefore is best kept by a cold wallet with minimal activity. * Rewards Address: Used for receiving rewards. This address is only needed when receiving rewards, and therefore is best kept by a cold wallet. The protocol uses a hierarchical approach between the staking and rewards addresses, and both validators and delegator can also use their staking address whenever their rewards address is required. ## Components The implementation of Starknet's staking protocol is divided into several contracts, summarized in the following figure: <Frame> <img alt="" /> </Frame> This modular architecture allows for targeted upgrades and improvements without affecting the entire system. Access control mechanisms are also in place to ensure that only authorized parties can make critical changes, further enhancing the security of the staking process. The following table details the key components of the protocol: | Contract | Description | | - | - | | Staking | The staking contract is the core of the staking system, managing the entire lifecycle of staking, from initial staking to claiming rewards and unstaking.<br />The staking contract also stores the `StakerInfo` data structure, which holds detailed information about each validator, including their staked amount, unclaimed rewards, delegation details, and operational parameters, and helps to ensure that validators' information is accurately tracked and updated. | | Delegation pooling | All delegation interactions, such as entering or exiting a pool, are enabled through the delegation pooling contract, which tracks each delegator's contribution, calculates their rewards, and manages the delegation lifecycle.<br />The delegation pooling contract also stores the `PoolMemberInfo` data structure, which holds information about each delegator's contributions, rewards, and status within the pool, and helps manage and calculate the delegation and reward distribution processes for pool members. | | Reward Supplier | The reward supplier contract is responsible for calculating and supplying the staking rewards based on the minting curve, ensuring the rewards are distributed fairly and in accordance with the protocol's economic parameters. | | Minting Curve | The minting curve contract defines the economic model that governs reward distribution, ensuring that the network's inflation is managed while incentivizing participation of stakers. | | Attestation | The attestation contract manages the tracking of successful validator attestations, by verifying whether the validator has correctly attested to their assigned block within a designated attestation window. | ## Procedures The following tables detail the procedures
프로젝트로 돌아가기