bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 73쪽 중 68쪽
essage consumption
At this point, the message is handled.
An L1→L2 message consists of the following:
* L1 sender's address
* L2 recipient's contract address
* Function selector
* Calldata array
* Message nonce
<Note>
The message nonce is maintained on the Starknet Core Contract on L1, and is incremented whenever a message is sent to L2. The nonce is used to avoid a hash collision between different L1 handler transactions that is caused by the same message being sent on L1 multiple times. For more information, see [L1→L2 structure](/learn/protocol/messaging#l2-→-l1-message-structure).
</Note>
### L1 → L2 message structure
For completeness, the following table describes the precise structure of both the message as it appears on L1 and the induced transaction as it appears on L2:
| FromAddress | ToAddress | Selector | Payload | Nonce | |
| - | - | - | - | - | - |
| `EthereumAddress` | `FieldElement` | `FieldElement` | `List` | `FieldElement` | |
### L1 → L2 message hashing
The hash of the message is computed on L1 as follows:
```
keccak256(
abi.encodePacked(
uint256(FromAddress),
ToAddress,
Nonce,
Selector,
Payload.length,
Payload
)
);
```
### L1 → L2 message cancellation
<Note>
The flow described here should only be used in edge cases such as bugs on the Layer 2 contract preventing message consumption.
</Note>
Consider that Alice sends an L1 asset to a Starknet bridge to transfer it to L2, which generates the corresponding L1→L2 message. Now, consider that the L2 message consumption doesn't function, which might happen due to a bug in the dApp's Cairo contract. This bug could result in Alice losing custody of their asset forever.
To mitigate this risk, the contract that initiated the L1→L2 message can cancel it by declaring the intent to cancel, waiting five days, and then completing the cancellation. This delay protects the sequencer from a DoS attack in the form of repeatedly sending and canceling a message before it is included in L1, rendering the L2 block which contains the activation of the corresponding L1 handler invalid.
The steps in this flow are as follows:
1. The user that initiated the L1→L2 message calls the [`startL1ToL2MessageCancellation`](https://github.com/starkware-libs/cairo-lang/blob/4e233516f52477ad158bc81a86ec2760471c1b65/src/starkware/starknet/eth/StarknetMessaging.sol#L134) function in the Starknet Core Contract.
2. The user waits five days until she can finalize the cancellation.
3. The user calls the [`cancelL1ToL2Message`](https://github.com/starkware-libs/cairo-lang/blob/4e233516f52477ad158bc81a86ec2760471c1b65/src/starkware/starknet/eth/StarknetMessaging.sol#L147) function.
### L1 → L2 message fees
An L1 → L2 message induces a transaction on L2, which, unlike regular transactions, is not sent by an account. This calls for a different mechanism for paying the transaction's fee, for otherwise the sequencer has no incentive of including L1 handler transactions inside a block.
To avoid having to interact with both L1 and L2 when sending a message, L1 → L2 messages are payable on L1, by sending ETH with the call to the payable function `sendMessageToL2` on the Starknet Core Contract.
The sequencer takes this fee in exchange for handling the message. The sequencer charges the fee in full upon updating the L1 state with the consumption of this message.
The fee itself is calculated in the [same manner](/learn/protocol/fees#overall-fee) as "regular" L2 transactions.
### L1 handler transaction
#### Transaction fields
| Version | ContractAddress | Selector | Calldata | Nonce | |
| - | - | - | - | - | - |
| `FieldElement` | `FieldElement` | `FieldElement` | `List` | `FieldElement` | |
<Note>
In an L1 handler transaction, the first element of the calldata is always the sender's Ethereum address.
</Note>
#### Hash calculation
The hash of the corresponding L1 handler transaction on L2 is computed as follows:
```cairo theme={null}
l1_handler_tx_hash = h(
"l1_handler",
version,
contract_address,
entry_point_selector,
h(calldata),
0,
chain_id,
nonce
)
```
Where:
* `l1_handler` is a constant prefix, encoded in bytes (ASCII), as big-endian.
* `version` is the transaction version. Only version 0 is currently supported.
* `chain_id` is a constant value that specifies the network to which this transaction is sent.
* *h* is the [Pedersen](/learn/protocol/cryptography#pedersen-hash) hash (note that since we're hashing an array, the # of inputs needs to be appended to the hash).
* `0` indicates that L1 to L2 message fees are charged on L1.
#### Caveats and limitations
* Since L1 handler transactions are not initiated by an account, invoking [`get_caller_address`](https://github.com/starkware-libs/cairo/blob/2203a47f8a098cd4718d03bd109ca014049419e7/corelib/src/starknet/info.cairo#L49) or similar account-related functions returns the address `0x0`.
* Starting from Starknet version 0.14.0:
* L1 handlers that fail execution will appear in a block as `REVERTED`, instead of only be written in the feeder gateway's database as `REJECTED`. The purpose of this change is to simplify the tracking of messages L1 → L2, and the implementation of `getMessageStatus` in particular.
* The `l1_gas`, `l2_gas`, and `l1_data_gas` execution resources of L1 handlers will be bounded as follows:
* `l2_gas` will bounded by $10^{8}$ (the same as `__validate__`'s)
* `l1_gas` and `l1_data_gas` will be bounded by $4 * 10^{4}$ and $2 * 10^{4}$, respectively (to allow for sending one L2 → L1 message)
#### Supported versions
| Current version | Deprecated versions | Unsupported versions |
| - | - | - |
| v0 | N/A | N/A |
# Security Council
Source: https://docs.starknet.io/learn/protocol/security-council
## Overview
The Starknet Security Council (SC) is a 12-member body that holds administrative control over Starknet's core contracts on both Starknet and Ethereum. Its purpose is to decentralize the ability to upgrade, pause, and unpause those contracts, so that no single organization can unilaterally change the protocol, while still allowing the network to respond to a live security incident within minutes.
## Member entities
The Council's 12 seats are held by individuals affiliated with the following organizations:
| Organization |
| - |
| StarkWare |
| Nethermind |
| Zellic |
| Hypernative |
| Pragma |
| AVNU |
| Cartridge |
| Ready |
| Karnot |
| Space Duck |
| Flying Muffins |
| Protolabs |
## Additional resources
* [SNIP 25](https://github.com/starknet-io/SNIPs/blob/main/SNIPS/snip-25.md) on GitHub
* [SNIP 25 discussion on the Starknet community forum](https://community.starknet.io/t/snip25-starknet-security-council-v1-0/115060)
* [Starknet Security Council's new framework for network security](https://www.starknet.io/blog/starknets-security-council/) on the Starknet blog
# SHARP
Source: https://docs.starknet.io/learn/protocol/sharp
## Overview
SHARP is [StarkWare's proof aggregator](#what_is_sharp), which uses [proof recursion](#proof_recursion_in_sharp) and [the S-two prover](#sharp_and_s_two) to make proving affordable for everyone, and is used by Starknet to reduce costs and improve efficiency within the network.
<Tip>
[Atlantic](https://docs.herodotus.cloud/atlantic/introduction) is a managed ZK Prover service that allows developers to easily integrate with SHARP.
</Tip>
Additional resources
* [*Save Costs and Enhance Ethereum's Scalability: If it's Written in Cairo, SHARP Can Prove it*](https://starkware.co/blog/joining-forces-sharp/) on the Starknet blog
* [*StarkWare's SHARP: Revolutionizing Ethereum Scaling with Recursive STARK Proofs*](https://www.youtube.com/watch?v=5kLm18E5ltg) in the StarkWare Scalability Series
* [*SHARP: StarkWare's Shared Prover*](https://www.youtube.com/watch?v=01tIeGBHsek) from Starknet Summit 2023
* [*SHARP - the backbone of Starknet* Starknet](https://www.youtube.com/watch?v=VMNreeZkAgI) and [*Introduction to SHARP verifier smart contact*](https://www.youtube.com/watch?v=jPxD9h7BdzU) community calls
* [*Starknet and zkSync: A comparative analysis*](https://www.nethermind.io/blog/starknet-and-zksync-a-comparative-analysis) by Nethermind
* [*Verifying Cairo proofs on Ethereum*](https://blog.zksecurity.xyz/posts/stark-evm-adapter/) by zkSecurity
* [*Proof aggregation techniques*](https://blog.lambdaclass.com/proof-aggregation-techniques/) by LambdaClass
## What is SHARP?
Being a provable programming language, Cairo allows generating STARK proofs for the validity of its execution, which can then be verified onchain to guarantee their correctness. SHARP (SHARed Prover) is a powerful system designed to generate a unified STARK proof for multiple Cairo programs and verify it on Ethereum. Leveraging the exponential asymmetry of the STARK protocol, this allows applications to share the cost of verifying proofs onchain with other applications, as well as "break down" their computations into several smaller computations without increasing costs.
For Starknet, this results in sending only a single proof per multiple blocks to Ethereum, and paying for its onchain verification only with respect to their relatize share in it.
## How does SHARP work?
### High-level overview
SHARP's architecture consists of several services that work together to generate proofs, which include:
1. The Gateway, through which external *Cairo position-independent executions (Cairo PIEs)* can be submitted to SHARP
2. The Job Creator, which processes external Cairo PIEs into *jobs* and prevents duplications
3. The Validator, which runs validation checks on each job, ensuring they can be proven successfully
4. The Scheduler, which determines which Cairo job are to be aggregated together
5. The Cairo Runner, which executes Cairo jobs and creates their Cairo PIEs
6. The Prover ([either Stone or S-two](#stone_and_s_two)), which generates STARK proofs of Cairo PIEs
7. The Dispatcher, which either packages proofs before sending them onchain, or [verifies them using the Cairo verifier, creates a corresponding recursive job, and sends it back to the validator](#proof_recursion)
8. The Blockchain Writer, which is responsible for sending packages from the dispatcher [onchain for verification](#onchain_verifier)
9. The Catcher, which monitors onchain transactions to ensure that they have been accepted
The following is a high-level overview of SHARP's architecture flow:
<Frame>
<img />
</Frame>
### Stone and S-two
SHARP uses [StarkWare's first-gen Stone prover](https://starkware.co/blog/open-sourcing-the-battle-tested-stone-prover/) to generate STARK proofs for all proofs it aggregates.
Starting from Starknet version 0.14.0, SHARP will use [StarkWare's next-gen S-Two prover](https://starkware.co/blog/s-two-prover/) for generating all proofs except those of [recursive tree roots](#proof_recursion), which will still to be generated using Stone. Continuing to use Stone for proving recursive tree roots is done to avoid changing SHARP's [onchain verifiers](#onchain_verifier).
### Proof recursion
Since its inception, SHARP has undergone a handful of efficiency upgrades, with the most powerful being the shift from a linear to a recursive model.
In the linear model, SHARP waited for enough programs to "fill up" a proof, and only then started the proving process for the whole bundle of programs.
In the recursive model, SHARP proves each statement upon its arrival, and instead of verifying it onchain, it verifies it offchain using a verifier program written in Cairo. Each two such verifications are then aggregated together and sent back to SHARP and the Cairo verifier, restarting the process. This continues recursively, with each new proof being sent to the Cairo verifier until a trigger is reached. At this point, the last proof in the series is sent to the Solidity verifier on Ethereum.
At first glance, recursive proofs may seem more complex and time-consuming. However, there are several benefits to this approach:
1. Parallelization: Recursive proofs enable work parallelization, reducing user latency and improving SHARP efficiency
2. Cheaper onchain costs: Parallelization enables SHARP to create larger proofs, which in turn result in reduced onchain costs
3. Lower cloud costs: Since each job is smaller, the required memory for processing is reduced, resulting in lower cloud costs
4. Cairo support: Recursive proofs only require support in Cairo, without the need to add support to the onchain verifiers
### Onchain verifier
SHARP's onchain verifiers is a set of multiple smart contracts responsible for verifying STARK proofs generated by SHARP, the key of which are:
* [`GpsStatementVerifier`](https://etherscan.io/address/0x47312450b3ac8b5b8e247a6bb6d523e7605bdb60), which serves as the primary verifier contract and relies on smaller verifier contracts that contain specific verification logic.
<Note>
For future enhancements or adjustments, a [`Proxy`](https://etherscan.io/address/0x47312450B3Ac8b5b8e247a6bB6d523e7605bDb60) and [`CallProxy`](https://etherscan.io/address/0xD4C4044ACa68ebBcB81B13cC2699e1Bca2d3F458) contracts are used allow seamless updates to the `GpsStatementVerifier` without compromising its foundational logic.
</Note>
* [`MemoryPageFactRegistry`](https://etherscan.io/address/0xfd14567eaf9ba941cb8c8a94eec14831ca7fd1b4), which maintains hashes of the proven programs' memory pages, primarily used to register outputs for data availability
* [`MerkleStatementContract`](https://etherscan.io/address/0x5899efea757e0dbd6d114b3375c23d7540f65fa4), which verifies the Merkle paths in the STARK proof
* [`FriStatementContract`](https://etherscan.io/address/0x3e6118da317f7a433031f03bb71ab870d87dd2dd), which is responsible for verifying the FRI layers in the STARK proof
The verification flow consists of the following steps:
1. The Dispatcher sends:
* Memory pages (usually many) to the `MemoryPageFactRegistry` contract
* Merkle statements (typically between 3 and 5) to the `MerkleStatementContract` contract
* Fri statements (generally ranging from 5 to 15) to the `FriStatementContract` contract
2. The Dispatcher send the proof to the `GpsStatementVerifier` contract
3. Starknet monitors the `GpsStatementVerifier` contract and updates its state once verification is complete
# SNOS
Source: https://docs.starknet.io/learn/protocol/snos
## Overview
As an L2 validity rollup, Starknet's state on Ethereum can't be updated without proving that all the blocks between the current state and the new state are valid. SNOS (**S**tark**N**et **O**perating **S**ystem) is [the key element in Starknet's architecture](#what_is_snos?) that [verifies the validity of Starknet blocks](#how_does_snos_work?) and is required for [updating Starknet's state](#using_snos_to_update_starknets_state). SNOS has two [implementations](#implementations), a fully-open source one in Rust and a partially open-source one in Python.
<Note>
SNOS is a key element in Starknet's architecture, but also one of its more complicated components. Some parts may require reading more than once, but don't hesitate to [reach out](https://github.com/starknet-io/starknet-docs/issues/new?assignees=landauraz\&title=Feedback%20for%20%22The%20Starknet%20operating%20system%22) if you feel further clarification is needed.
</Note>
## What is SNOS?
In Cairo, only statements of the form *"a specific Cairo program with specific inputs and produced specific outputs"* can be proven, which means that the statement *"A Starknet block is valid"* needs to expressed in the form of a Cairo program, inputs, and outputs.
This is where SNOS comes in: it is a Cairo Zero program that verifies the validity of blocks by getting an initial state and a list of transactions as input and outputting the state that is the result of applying these transactions on the initial state.
SNOS is the program required for updating Starknet's state on Ethereum ([up to some caveats](#os-and-core-contract)). As such, is it also the final arbiter on what does it mean for a transaction to execute correctly. For example, while a malicious sequencer can deviate from [the `INVOKE` transaction's behavior](/learn/protocol/transactions/#transaction_flow) by skipping the execution of `__validate__` before `__execute__` in the calling account contract, this specification is [enforced by SNOS](https://github.com/starkware-libs/cairo-lang/blob/8e11b8cc65ae1d0959328b1b4a40b92df8b58595/src/starkware/starknet/core/os/execution/execute_transactions.cairo#L390) and therefore this sequencer will not be able to produce the proof for the block in which this transaction was included.
## How does SNOS work?
### High-level overview
The following is a rough sketch of the SNOS program, starting at [os.cairo](https://github.com/starkware-libs/cairo-lang/blob/8e11b8cc65ae1d0959328b1b4a40b92df8b58595/src/starkware/starknet/core/os/os.cairo#L38)'s `main` function:
<Frame>
<img />
</Frame>
In broad strokes, SNOS's execution consists of the following steps:
1. Preprocessing: preparing the SNOS's inputs, which include the various hints that will be needed throughout the execution (for example, the Merkle path of every accessed storage slot and the code of every accessed contract)
2. Running the transactions: the bulk of SNOS's execution, where transactions are executed sequentially such that for each transaction:
* The associated account contract is loaded into the memory and called
* Inner contracts are called, such that [the entry `(contract_address, class_hash)` is added to a global state updates dictionary](https://github.com/starkware-libs/cairo-lang/blob/8e11b8cc65ae1d0959328b1b4a40b92df8b58595/src/starkware/starknet/core/os/execution/execute_entry_point.cairo#L149) for each loaded contract (which is needed to assert that the loaded code corresponds to the class hash that is part of the state commitment)
<Note>
Contract calls are in fact done non-deterministically, i.e. the contract's response are guessed and verified later. For more details, see [Syscall mechanism](#syscall-mechanism).
</Note>
* State updates are accumulated in the global state updates dictionary
3. Verifying that the new commitment corresponds to applying the updates accumulated in the global state updates dictionary to the old commitment (for more details, see the [`state_update` function in `state.cairo`](https://github.com/starkware-libs/cairo-lang/blob/8e11b8cc65ae1d0959328b1b4a40b92df8b58595/src/starkware/starknet/core/os/state/state.cairo#L40)).
4. Encoding the state diff and adding it to the output segment for [data availability](/learn/protocol/data-availability/) purposes (for more details, see the [`serialize_os_output` function in `output.cairo`](https://github.com/starkware-libs/cairo-lang/blob/8e11b8cc65ae1d0959328b1b4a40b92df8b58595/src/starkware/starknet/core/os/output.cairo#L71))
### Syscall mechanism
A contract can invoke [system calls](https://book.cairo-lang.org/appendix-08-system-calls.html) throughout its execution, which pass the control from the currently executing contract to SNOS itself. Such operations are required when a contract needs information that does not exist within its code, e.g. accessing the Starknet state to read a storage value or to call another contract.
SNOS's code heavily relies on non-determinism to handle system calls. Whenever a contract invokes some syscall, the request, alongside the guessed response, is recorded in a syscalls array. At the end of every entry point execution, we go over the syscalls array and verify that the responses were correct (for more details, see the [`execute_entry_point` function in `execute_transactions.cairo`](https://github.com/starkware-libs/cairo-lang/blob/8e11b8cc65ae1d0959328b1b4a40b92df8b58595/src/starkware/starknet/core/os/execution/execute_entry_point.cairo#L286)).
For syscalls such as [`get_execution_info`](https://book.cairo-lang.org/appendix-08-system-calls.html#g프로젝트로 돌아가기