Starknet 백서

Starknet

원문

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

e `decommitment`. * Initialize `last_layer_hashes` to track computed hashes from the previous layer. 2. **Layer-by-Layer Verification:** * For each layer (from largest to smallest): * Get the number of columns in the current layer (`n_columns_in_layer`) from the map `n_columns_per_log_size`. * Prepare iterators for previous layer queries (`prev_layer_queries`), previous layer hashes (`prev_layer_hashes`) and current layer column queries (`layer_column_queries`). * For each node index: * **Reconstruct `node_hashes`:** Use computed hashes from the `prev_layer_hashes` or read missing sibling hashes from `hash_witness`. * **Get Node Values:** If the node is queried, read column values from `queried_values`; otherwise, read from `column_witness`. * **Compute Hash:** Use the hash function to compute the hash of the current node from its children hashes and column values. * Store the computed hash for propagation to the next layer. 3. **Final Verification:** * Check that all witnesses and queried values have been fully consumed (no excess data). * Verify that the computed root matches the expected root stored in the verifier. * Return `Ok(())` if verification succeeds, or an appropriate error otherwise. ### Example: Verify the decommitment The same example from the [decommit process](/learn/S-two-book/how-it-works/vcs/merkle_prover#example%3A-decommit-process) is used to verify the output of the `decommit` function. The input to the `verify` function is as follows: * `queries_per_log_size`: $[(2, [0]), (1, [1])]$ * `queried_values`: $[\textcolor{red}{a}, \textcolor{green}{p}, \textcolor{blue}{v}]$ * `decommitment`: * `hash_witness`: $[h_{01}, h_{10}, h_{11}]$ * `column_witness`: $[\textcolor{blue}{u}]$ Below is a walkthrough of the main loop in the `verify` function, showing how the verifier reconstructs the Merkle root: * **layer\_log\_size = 2 (columns of size 4):** * `n_columns_in_layer`: 2 (for $\textcolor{red}{\text{\textit{Column} 0}}$ and $\textcolor{green}{\text{\textit{Column} 1}}$) * `last_layer_hashes`: `None` (first layer) * `prev_layer_queries`: empty * `layer_column_queries`: $[0]$ * For `node_index = 0`: * `node_hashes`: `None` (no previous layer) * `node_values`: Read from `queried_values` → $[\textcolor{red}{a}, \textcolor{green}{p}]$ * Compute hash: $h_{00} = H(\textcolor{red}{a}, \textcolor{green}{p})$ * Add to `layer_total_queries`: $(0, h_{00})$ * At this stage: `last_layer_hashes` = $[(0, h_{00})]$ * **layer\_log\_size = 1 (columns of size 2):** * `n_columns_in_layer`: 1 (for $\textcolor{blue}{\text{\textit{Column} 2}}$) * `last_layer_hashes`: $[(0, h_{00})]$ * `prev_layer_queries`: $[0]$ * `layer_column_queries`: $[1]$ * For `node_index = 0`: * `node_hashes`: Left child is $h_{00}$ (computed from `last_layer_hashes`), right child $h_{01}$ read from `hash_witness` * `node_values`: Read from `column_witness` → $[\textcolor{blue}{u}]$ * Compute hash: $h_0 = H(h_{00}, h_{01}, \textcolor{blue}{u})$ * Add to `layer_total_queries`: $(0, h_0)$ * For `node_index = 1`: * `node_hashes`: Both children $h_{10}, h_{11}$ read from `hash_witness` * `node_values`: Read from `queried_values` → $[\textcolor{blue}{v}]$ * Compute hash: $h_1 = H(h_{10}, h_{11}, \textcolor{blue}{v})$ * Add to `layer_total_queries`: $(1, h_1)$ * At this stage: `last_layer_hashes` = $[(0, h_0), (1, h_1)]$ * **layer\_log\_size = 0 (root):** * `n_columns_in_layer`: 0 (no columns of size 1) * `last_layer_hashes`: $[(0, h_0), (1, h_1)]$ * `prev_layer_queries`: $[0, 1]$ * `layer_column_queries`: empty * For `node_index = 0`: * `node_hashes`: Left child is $h_0$, right child is $h_1$ (both computed from `last_layer_hashes`) * `node_values`: empty (no columns) * Compute hash: $root = H(h_0, h_1)$ * Add to `layer_total_queries`: $(0, root)$ * At this stage: `last_layer_hashes` = $[(0, root)]$ **Final verification:** * Check that all iterators are exhausted: `hash_witness`, `queried_values`, and `column_witness` should all be empty. * Compare the computed `root` with the expected root stored in the `MerkleVerifier`. * If they match, return `Ok(())`; otherwise, return `Err(MerkleVerificationError::RootMismatch)`. # Introduction Source: https://docs.starknet.io/learn/S-two-book/introduction S-two is a state-of-the-art framework for creating STARK proofs that provides the following features: * A frontend designed to be flexible to allow you to express your own constraints * A backend that leverages Circle STARKs over the Mersenne31 prime field for fast prover performance * Seamlessly integrated with Cairo This book will guide you through the process of creating your own constraints and then proving them using S-two. It will also provide in-depth explanations of the inner workings of how S-two implements Circle STARKs. # Why S-two? Source: https://docs.starknet.io/learn/S-two-book/why-stwo Before we dive into why we should choose S-two, let's define some terminology. When we talked about proof systems in the previous section, we mentioned that we can create a proof of a statement using a proof system. In reality, however, we first need to structure the function involved in the statement in a way that it can be proven. This structuring part is often referred to as the **frontend**, while the rest of the process of creating a proof is commonly referred to as the **backend**. With that out of the way, let's dive into some of the advantages of using S-two. First, S-two is a standalone framework that provides both the frontend and backend and therefore handles the entire proving process. There are other frameworks that only provide the frontend or the backend, which has its advantages as its modular structure makes it possible to pick and choose a backend or frontend of one's liking. However, having a single integrated frontend and backend reduces the complexity of the system and is also easier to maintain. In addition, S-two's frontend structures statements as an **Algebraic Intermediate Representation (AIR)**, which is a representation that is especially useful for proving statements that are repetitive (e.g. the CPU in a VM, which essentially repeats the same fetch-decode-execute over and over again). S-two's backend is also optimized for prover performance. This is due to largely three factors. 1. It implements **STARKs**, or hash-based SNARKs, which boasts a faster prover compared to elliptic curve-based SNARKs like Groth16 or PLONK. This improvement comes mainly from running the majority of the computation in a small prime field (32 bits); Elliptic curve-based SNARKs, on the other hand, need to use big prime fields (e.g. 254-bit prime fields), which incur a lot of overhead as most computation does not require that many bits. 2. Even amongst multiple STARK backends, however, S-two provides state-of-the-art prover performance by running the **Mersenne-31 prime field** (modulo $2^{31} - 1$), which is faster than another popular 32-bit prime field like BabyBear (modulo $2^{31} - 2^{27} + 1$). We suggest going through [this post](https://blog.zksecurity.xyz/posts/circle-starks-1/) for a breakdown of why this is the case. 3. Finally, S-two offers **various CPU and GPU optimizations** that improves prover performance as shown in [Figure 1](#figure-1) below. It can also be compiled to WASM, allowing for fast proving in web environments. <div> <img alt="" /> *Figure 1: Prover performance optimizations in S-two* </div> One of the drawbacks of STARKs is that they have a larger proof size compared to elliptic curve-based SNARKs. One way to mitigate this drawback is by batching multiple proofs together to form a single proof. <Note> **On zero-knowledge:** As of the time of this writing, S-two does not provide the "zero-knowledge" feature. "Zero-knowledge" here refers to the fact that the proof should not reveal any additional information other than the validity of the statement, which is not true for S-two as it reveals to the verifier commitments to its witness values without hiding them by e.g. adding randomness. This reveals **some information** about the witness values, which may be used in conjunction with other information to infer the witness values. </Note> # Why Use a Proof System? Source: https://docs.starknet.io/learn/S-two-book/why-use-a-proof-system At its core, a proof system proves that a statement is valid. For example, it can prove that a function with a certain input results in a certain output, i.e. $C(x)=y$. To check the statement, we can do it either directly by computing $C(x)$ and comparing the result to $y$, or indirectly by verifying the proof. The verifier can benefit from the second option in terms of time and space, if the time to verify the proof is faster than the time to compute the function, or the size of the proof is smaller than the input to the statement. This property of a proof system is often referred to as **succinctness**, and it is exactly why proof systems have seen wide adoption in the blockchain space, where computation on-chain is much more expensive compared to off-chain computation. Using a proof system, it becomes possible to replace a large collection of computation to be executed on-chain with a proof of execution of the same collection of computations and verifying it on-chain. This way, proofs can be generated off-chain using large machines and verified on-chain with much less computation. But there are applications of proof systems beyond just blockchains. Generally speaking, it can be used as auxiliary data to verify that the computation of an untrusted party was done correctly. For example, when we delegate computation to an untrusted server, we can ask it to provide a proof along with the computation result that the result indeed came from running a specific computation. Another example could be to ask a server running an ML model to provide proof that it ran inference on the correct model. The size of the accompanying proof and the time to verify it will be negligible compared to the cost of running the computation, but we gain the guarantee that the computation was done correctly. Another optional feature of proof systems is **zero-knowledge**, which means that the proof reveals nothing about the computation other than its validity. In general, the output $y$ of the computation $C(x)=y$ will be public (i.e. revealed to the verifier), but the input $x$ will be, without loss of generality, private from the verifier. With this feature, the intermediate values computed by the prover while computing $C(x)$ will also be hidden from the verifier. # Chain information Source: https://docs.starknet.io/learn/cheatsheets/chain-info <Tip> You can get the latest updates delivered to your inbox by subscribing to the [Starknet Devs Newsletter](https://www.starknet.io/starknet-devs-newsletter/). </Tip> ## Current versions | Environment | Starknet version | Sierra version | Cairo version | | - | - | - | - | | Mainnet | 0.14.4 | 1.9.0 | 2.0.0 - 2.19.0 | | Sepolia | 0.14.4 | 1.9.0 | 2.0.0 - 2.19.0 | ## Current limits (mainnet) <Warning> The following limits are subject to revisions and change on a regular basis </Warning> <Note> Starting from v0.13.0, blockifier-related constants and limits are defined for each Starknet version in a JSON file called `versioned_constants` in the [blockifier's resources directory](https://github.com/starkware-libs/sequencer/tree/main/crates/blockifier/resources). Starting from v0.13.5, resources are denominated in units of L2 gas, L1 gas, and L1 data gas. </Note> | Entity | Description | Limit | | - | - | - | | Block time | The maximum amount of time within which a preconfirmed block is closed, if no other limit is met | 9.5 seconds | | Block recommended time | The amount of time after which preconfirmed block is closed, if there are no transactions in the mempool and no transactions being executed ATM | 2 seconds | | Max L2 gas per block | The maximum amount of L2 gas that a block can contain<br /><br />**Note:** This limit ensures block production times remains consistent and predictable. | 6 \* 10^9 | | Max transactions per block | The maximum amount of transactions in a single block | 500 | | Max L2 gas per transaction | The maximum number of computational steps, measured in L2 gas, that a transaction can contain when processed on the Starknet network<br /><br />**Note:** This limit is important for ensuring the efficient execution of transactions and preventing potential congestion. | 1.11\*10^9 | | Max state updates per transaction | The maximum number of storage updates that a single transaction can generate<br /><br />**Note:** This limit helps maintain network stability and predictable performance. | 2,490 | | Max number of events per transaction | The maximum number of events that a transaction can emit during its execution | 1,000 | | Max number of data felts per event | The maximum number of felts that an event can contain in its `data` array | 300 | | Max number of key felts per event | The maximum number of felts that an event can contain in its `keys` array | 50 | | Max L2 gas for `validate` | The maximum number of computational steps, measured in Cairo steps, for a `validate` function | 10^8 | | Max contract bytecode size | The maximum size of the bytecode or program that a smart contract can have on Starknet | 81,920 felts | | Max contract class size | The maximum size for the Sierra file of a contract class within Starknet<br /><br />**Note:** This limit is important for ensuring the network's scalability and security. | 4,089,446 bytes | | IP address limits | The amount of contract reads that a single IP address can make (in order to reduce network spam) | 200 per min per IP address | | Signature length | The maximum length of a signature | 4,000 felts | | Calldata length | The maximum length of a transaction calldata | 5,000 felts | ### Block builtin limits <Warning> Currently, block builtin limits apply only for Sepolia. For more information, see [the release notes for Starknet version 0.13.6](/learn/cheatsheets/version-notes#starknet_v0_13_6_8_jul_25). </Warning> | Builtin | Limit | | - | - | | Range Check | 57,142,857 | | ECDSA | 3,000 | | Poseidon | 479,961 | | Pedersen | 493,827 | | Bitwise | 6,861,063 | | EC OP | 6,994 | | Keccak | 9,790 | | Range Check 96 | 71,428,571 | | Add Mod | 16,000,000 | | Mul Mod | 6,622,516 | ## Deprecated features <Note> A deprecated feature is a feature that is still supported, but support will be removed in a future release of Starknet. </Note> | Name | Description | | - | - | | Cairo 0 | [Starknet v0.11.0](/learn/cheatsheets/version-notes#version0.11.0) introduces Cairo 1.0 smart contracts. | | Transaction signing only over two resources | RPC version 0.8, introduced in Starknet 0.13.5, only supports `v3` transactions that sign over three resources (L1 gas, L2 gas and L1 data gas), removing support for transaction versions `v0`, `v1`, and `v2`, and for `v3` transactions that sign only over two resources (L1 gas and L2 gas).<br /><br />Starting from version v0.14.0, Starknet will stop accepting these transactions altogether, and will only accept `v3` transactions compliant with RPC 0.8. | ## Unsupported and removed features <Note> An unsupported feature is a feature that is no longer supported. A removed feature is a feature that has been entirely removed. </Note> | Name | Description | | - | - | | Starknet CLI | Support for the Starknet CLI has been removed. Instead use [`Starkli or Starknet Foundry's sncast`](./tools). | | Goerli testnet | Goerli testnet support was removed April 2, 2024. Sepolia testnet replaces Goerli testnet.<br /><br />Starknet started migrating to Sepolia testnet on November 15th, 2023. For more information on the Goerli deprecation, see [the deprecation announcement on Ethereum's site](https://ethereum.org/nb/developers/docs/networks/#ethereum-testnets).<br /><br />Full nodes, API services, SDKs, and other Starknet developer tools have migrated to Sepolia as well.<br /><br />**Note:** Sepolia's state and history are relatively small. Sepolia [supports declaring classes of CairoZero and Cairo v2.0.0 and higher](/learn/cheatsheets/version-notes). | | Starknet feeder gateway | The Starknet feeder gateway, a temporary solution for querying the sequencer's state, is being replaced by Starknet full nodes (Pathfinder, Juno, Deoxys, Papyrus) and RPC services. For more information, see [Full nodes and API services](./tools).<br /><br />Support for the feeder gateway queries that are not required for full nodes to synchronize on the state of Starknet will stop according to the following schedule:<br /><br />**Environment** \| **Date**<br />Integration \| 1 November 2023<br />Testnet \| 15 November 2023<br />Mainnet \| 19 December 2023<br /><br />Queries that are required for full nodes to synchronize on the state of Starknet are still supported.<br /><br />For more information, see the Community Forum post [*Feeder Gateway Deprecation*](https://community.starknet.io/t/feeder-gateway-deprecation/100233). | | Free L1-> L2 messaging | Previously, sending a message from L1 to L2 had an optional fee associated.<br /><br />From [Starknet v0.11.0](/learn/cheatsheets/version-notes#version0.11.0), the fee mechanism is enforced and the ability to send L1->L2 messages without the corresponding L2 fee has been removed.<br /><br />See [here](/learn/protocol/messaging#l1-l2-message-fees) for more details. | | `invoke` transaction v0 | `invoke` transaction v0 has been removed since [Starknet v0.11.0](/learn/cheatsheets/version-notes#version0.11.0). | | `declare` transaction v0 | `declare` transaction v0 has been removed since [Starknet v0.11.0](/learn/cheatsheets/version-notes#version0.11.0). | | `deploy` transaction | The `deploy` transaction has been removed since [Starknet v0.10.3](/learn/cheatsheets/version-notes#version0.10.3).<br /><br />To deploy new contract instances, you can use the [`deploy system call`](https://book.cairo-lang.org/appendix-08-system-calls.html#deploy). | ## Important addresses ### General #### Mainnet | | | | - | - | | Sequencer base URL | alpha-mainnet.starknet.io | | Core contract | 0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4 | | SHARP verifier contract | 0x47312450B3Ac8b5b8e247a6bB6d523e7605bDb60 | #### Sepolia | | | | - | - | | Sequencer base URL | alpha-sepolia.starknet.io | | Core contract | 0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057 | | SHARP verifier contract | 0x07ec0D28e50322Eb0C159B9090ecF3aeA8346DFe | ### Tokens #### Mainnet | | | | - | - | | STRK contract | 0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d | | ETH contract | 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 | | vSTRK contract | 0x0782f0ddca11d9950bc3220e35ac82cf868778edb67a5e58b39838544bc4cd0f | #### Sepolia | | | | - | - | | STRK contract | 0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d | | ETH contract | 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 | | vSTRK contract | 0x035c332b8de00874e702b4831c84b22281fb3246f714475496d74e644f35d492 | ### StarkGate #### Mainnet | | | | - | - | | StarkgateManager contract | 0x0c5aE94f8939182F2D06097025324D1E537d5B60 | | StarkgateRegistry contract | 0x1268cc171c54F2000402DfF20E93E60DF4c96812 | | L1 StarknetTokenBridge contract | 0xF5b6Ee2CAEb6769659f6C091D209DfdCaF3F69Eb | | L2 StarknetTokenBridge contract | 0x0616757a151c21f9be8775098d591c2807316d992bbc3bb1a5c1821630589256 | | Bridged tokens | [https://github.com/starknet-io/starknet-addresses/blob/master/bridged\_tokens/mainnet.json](https://github.com/starknet-io/starknet-addresses/blob/master/bridged_tokens/mainnet.json) | #### Sepolia | | | | - | - | | Bridged tokens | [https://github.com/starknet-io/starknet-addresses/blob/master/bridged\_tokens/sepolia.json](https://github.com/starknet-io/starknet-addresses/blob/master/bridged_tokens/s
프로젝트로 돌아가기