Starknet 백서

Starknet

원문

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

_BLOWUP_FACTOR + config.fri_config.log_blowup_factor, ) .circle_domain() .half_coset, ); ``` To prove that the composition polynomial evaluates to 0 over the trace domain (since the composition polynomial is composed of constraints that evaluates to 0 over the trace domain), we first divide the composition polynomial by the **vanishing polynomial**, which is a polynomial that evaluates to 0 over the trace domain. If the composition polynomial is created correctly, this will result in a polynomial instead of a rational function, and we can perform FRI over this polynomial to prove this. Thus, we need to commit to this new polynomial, which is called the **quotient polynomial**. We can calculate its degree by subtracting the degree of the vanishing polynomial from the degree of the composition polynomial. Since the trace is of size `1 << log_num_rows`, the degree of the vanishing polynomial will be `1 << log_num_rows - 1`, so the resulting degree will be `1 << (log_num_rows + LOG_CONSTRAINT_EVAL_BLOWUP_FACTOR) - (1 << log_num_rows - 1)`. However, since we can only commit to a power of two degree, we can just use the `1 << (log_num_rows + LOG_CONSTRAINT_EVAL_BLOWUP_FACTOR)` value. If we apply the FRI blowup as well, we finally end up with the following log domain size: `log_num_rows + LOG_CONSTRAINT_EVAL_BLOWUP_FACTOR + config.fri_config.log_blowup_factor`. Using the new `TestEval` struct, we can create a new `FrameworkComponent::<TestEval>` component, which the prover will use to evaluate the constraint. For now, we can ignore the other parameters of the `FrameworkComponent::<TestEval>` constructor. We now move on to the final section where we finally create and verify a proof. <Info> Finally, we can break down what an Algebraic Intermediate Representation (AIR) means. *Algebraic* means that we are using polynomials to represent the constraints. *Intermediate Representation* means that this is a modified representation of our statement so that it can be proven. So AIR is just another way of saying that we are representing statements to be proven as constraints over polynomials. </Info> # From Spreadsheet to Trace Polynomials Source: https://docs.starknet.io/learn/S-two-book/air-development/writing-a-simple-air/from-spreadsheet-to-trace-polynomials <div> <img alt="" /> *Figure 1: Prover workflow: Trace polynomials* </div> In the previous section, we created a table (aka spreadsheet). In this section, we will convert the table into something called trace polynomials. <div> <img alt="" /> *Figure 2: From spreadsheet to trace polynomials* </div> In STARKs, the computation trace is represented as evaluations of a polynomial over some domain. Typically this domain is a coset of a multiplicative subgroup. But since the multiplicative subgroup of M31 is not smooth, S-two works over the circle group which is the subgroup of degree-2 extension of M31 (as explained in the [Mersenne Primes](../../how-it-works/mersenne-prime) and [Circle Group](../../how-it-works/circle-group) sections). Thus the domain in S-two is formed of points $(x_i, y_i)$ on the circle curve. Note that when we interpolate a polynomial over the points on the circle curve, we get a bivariate trace polynomial $f_j(x, y)$. We will explain why using a polynomial representation is useful in the next section, but for now, let's see how we can create trace polynomials for our code. Note that we are building upon the code from the previous section, so there's not much new code here. ```rust theme={null} fn main() { // --snip-- // Convert table to trace polynomials let domain = CanonicCoset::new(log_num_rows).circle_domain(); let _trace: ColumnVec<CircleEvaluation<SimdBackend, M31, BitReversedOrder>> = vec![col_1, col_2] .into_iter() .map(|col| CircleEvaluation::new(domain, col)) .collect(); } ``` Here, `domain` refers to the $(x_i, y_i)$ values used to interpolate the trace polynomials. For example, $(x_1, y_1), (x_2, y_2)$ in [Figure 2](#figure-2) are the domain values for our example. Note that when creating the domain, we set the `log_num_rows` to the log of the actual number of rows that are used in the table. In our example, we set it to 4 since S-two requires that we use at least 16 rows. For a background on what `CanonicCoset` and `.circle_domain()` mean, you can refer to the [Circle Group](../../how-it-works/circle-group) section. Now that we have created 2 trace polynomials for our 2 columns, let's move on to the next section where we commit to those polynomials! # Hello World Source: https://docs.starknet.io/learn/S-two-book/air-development/writing-a-simple-air/hello-world Let's first set up a Rust project with S-two. ```bash theme={null} $ cargo new stwo-example ``` We need to specify the nightly Rust version to use S-two. ```bash theme={null} $ echo -e "[toolchain]\nchannel = \"nightly-2025-01-02\"" > rust-toolchain.toml ``` Now let's edit the `Cargo.toml` file as follows: ```rust,ignore theme={null} [package] name = "stwo-examples" version = "0.1.0" edition = "2021" license = "MIT" [dependencies] stwo = { git = "https://github.com/starkware-libs/stwo.git", rev = "75a6b0ac9bcc7101d8658445dded51923ab2586f", features = ["prover"]} stwo-constraint-framework = { git = "https://github.com/starkware-libs/stwo.git", rev = "75a6b0ac9bcc7101d8658445dded51923ab2586f", package = "stwo-constraint-framework", features = ["prover"] } num-traits = "0.2.17" itertools = "0.12.0" rand = "0.8.5" ``` We are all set! # Introduction Source: https://docs.starknet.io/learn/S-two-book/air-development/writing-a-simple-air/index <div> <img alt="" /> *Figure 1: Proving lifecycle in S-two* </div> Welcome to the guide for writing AIRs in S-two! In this section, we will go through the process of writing a simple AIR from scratch. This requires some understanding of the proving lifecycle in S-two, so we added a diagram showing a high-level overview of the whole process. As we go through each step, please note that the diagram may contain more steps than the code. This is because there are steps that are abstracted away by the S-two implementation, but are necessary to understand the code that we write when creating an AIR. # Proving and Verifying an AIR Source: https://docs.starknet.io/learn/S-two-book/air-development/writing-a-simple-air/proving-an-air <div> <img alt="" /> *Figure 1: Prover workflow: perform FRI and PoW* </div> We're finally ready for the last step: prove and verify an AIR! Since the code is relatively short, let us present it first and then go over the details. ```rust theme={null} fn main() { // --snip-- // Prove let proof = prove(&[&component], channel, commitment_scheme).unwrap(); // Verify let channel = &mut Blake2sChannel::default(); let commitment_scheme = &mut CommitmentSchemeVerifier::<Blake2sMerkleChannel>::new(config); let sizes = component.trace_log_degree_bounds(); commitment_scheme.commit(proof.commitments[0], &sizes[0], channel); channel.mix_u64(log_num_rows as u64); commitment_scheme.commit(proof.commitments[1], &sizes[1], channel); verify(&[&component], channel, commitment_scheme, proof).unwrap(); } ``` ## Prove As you can see, there is only a single line of code added to create the proof. The `prove` function performs the FRI and PoW operations under the hood, although, technically, the constraint-related steps in [Figure 1](#figure-1) were not performed in the previous section and are only performed once `prove` is called. ## Verify In order to verify our proof, we need to check that the constraints are satisfied using the commitments from the proof. In order to do that, we need to set up a `Blake2sChannel` and `CommitmentSchemeVerifier<Blake2sMerkleChannel>`, along with the same `PcsConfig` that we used when creating the proof. Then, we need to recreate the Fiat-Shamir channel by passing the Merkle tree commitments and the `log_num_rows` to the `CommitmentSchemeVerifier` instance by calling `commit` (remember: the order is important!). Then, we can verify the proof using the `verify` function. <Callout icon="question"> Try setting the dummy values in the table to 1 instead of 0. Does it fail? If so, can you see why? </Callout> Congratulations! We have come full circle. We now know how to create a table, convert it to trace polynomials, commit to them, create constraints over the trace polynomials, and prove and verify the constraints (i.e. an AIR). In the following sections, we will go over some more complicated AIRs to explain S-two's other features. # Writing a Spreadsheet Source: https://docs.starknet.io/learn/S-two-book/air-development/writing-a-simple-air/writing-a-spreadsheet <div> <img alt="" /> *Figure 1: Prover workflow: Create a table* </div> In order to write a proof, we first need to create a table of rows and columns. This is no different from writing integers to an Excel spreadsheet as we can see in [Figure 2](#figure-2). <div> <img alt="" /> *Figure 2: From spreadsheet to table* </div> But there is a slight caveat to consider when creating the table. S-two implements [SIMD operations](https://en.wikipedia.org/wiki/Single_instruction,_multiple_data) to speed up the prover in the CPU, but this requires providing the table cells in chunks of 16 rows. Simply put, this is because S-two supports 16 lanes of 32-bit integers, which means that the same instruction can be run simultaneously for 16 different data. Alas, for our table, we will need to create 14 dummy rows to make the total number of rows equal to 16, as shown in [Figure 3](#figure-3). For the sake of simplicity, however, we will omit the dummy rows in the diagrams of the following sections. <div> <img alt="" /> *Figure 3: Creating a table with 16 rows* </div> Given all that, let's create this table using S-two. ```rust theme={null} use stwo::prover::{ backend::{ simd::{column::BaseColumn, m31::N_LANES}, Column, }, }; use stwo::core::fields::m31::M31; fn main() { let num_rows = N_LANES; let mut col_1 = BaseColumn::zeros(num_rows as usize); col_1.set(0, M31::from(1)); col_1.set(1, M31::from(7)); let mut col_2 = BaseColumn::zeros(num_rows as usize); col_2.set(0, M31::from(5)); col_2.set(1, M31::from(11)); } ``` As mentioned above, we instantiate the `num_rows` of our table as `N_LANES=16` to accommodate SIMD operations. Then we create a `BaseColumn` of `N_LANES=16` rows for each column and populate the first two rows with our values and the rest with dummy values. Note that the values in the `BaseColumn` need to be of type `M31`, which refers to the Mersenne-31 prime field that S-two uses. This means that the integers in the table must lie in the range $[0, 2^{31}-1)$. Now that we have our table, let's move on! # Awesome S-two Source: https://docs.starknet.io/learn/S-two-book/awesome-stwo/index <Callout type="success"> Explore the community-curated [Awesome S-two](https://github.com/keep-starknet-strange/awesome-stwo) list for more resources and projects building on S-two. </Callout> # Benchmarks Report Source: https://docs.starknet.io/learn/S-two-book/benchmarks/index * Overview of zkVM and Proof Systems | zkVM / Proof System | Architecture | Frontend | Backend | Security Bits | | :- | :- | :- | :- | :- | | [RISC Zero](https://github.com/risc0/risc0) | RISC-V | Rust | STARK-based | 96 bits | | [SP1](https://github.com/succinctlabs/sp1) | RISC-V | Rust | STARK-based | 100 bits | | [OpenVM](https://github.com/openvm-org/openvm) | RISC-V | Rust | STARK-based | 100 bits | | [Jolt](https://github.com/a16z/jolt) | RISC-V | Rust | Lookup-based | - | | [Stone](https://github.com/starkware-libs/stone-prover) | Cairo VM | Cairo | STARK-based | 100 bits | | [S-two](https://github.com/starkware-libs/stwo) | Cairo VM | Cairo | STARK-based | 96 bits | * All benchmarks presented here are **CPU-only** and do not utilize any GPU acceleration. * Stone benchmarks were generated using the `dynamic` layout with these [configurations](https://github.com/zksecurity/zkvm-benchmarks/tree/master/stone/configs). * The benchmarks for SP1, R0 and OpenVM use compressed or succinct prover type, which aggregates all the STARK proofs into a single STARK proof. * Benchmarks which run out of memory have been indicated by `💾` and benchmarks which generate errors in proof generation have been indicated by `❌` in the tables. ## Time and Commit Hash * **Commit Hash**: f27856ec17fbd9e85ec31cba9c2cb9e96d8dd08f * **Timestamp**: Thursday, July 03, 2025 20:52:50 UTC ## System Information ### OS Version Ubuntu 24.04.2 LTS ### CPU Info * **Architecture**: x86\_64 * **CPU(s)**: 48 * **Model name**: AMD EPYC-Rome Processor * **Thread(s) per core**: 2 * **Core(s) per socket**: 24 * **Socket(s)**: 1 * **L3 cache**: 16 MiB (1 instance) ### Memory Info * **MemTotal**: 184.25 GB * **MemFree**: 166.19 GB * **MemAvailable**: 178.69 GB ## Fibonacci Benchmark `n` Fibonacci iterations. ### Prover Time (s) | n | jolt | sp1 | openvm | r0 | stone | stwo | | -: | -: | -: | -: | -: | -: | -: | | 32768 | 3.208 | 15.003 | 34.291 | 17.128 | 56.325 | 13.198 | | 65536 | 5.183 | 18.252 | 42.403 | 29.241 | 95.468 | 11.372 | | 131072 | 9.17 | 24.982 | 57.978 | 52.298 | 💾 | 12.886 | | 262144 | 15.771 | 39.327 | 92.229 | 86.743 | 💾 | 12.587 | | 524288 | 28.16 | 54.812 | 158.128 | 167.607 | 💾 | 16.166 | | 1048576 | 54.42 | 72.028 | 320.082 | 306.386 | 💾 | 18.612 | | 2097152 | 107.89 | 128.215 | 515.567 | 605.92 | 💾 | 31.047 | | 4194304 | ❌ | 222.332 | 1042.58 | 1206.76 | 💾 | 60.939 | <img alt="" /> ### Verifier Time (ms) | n | jolt | sp1 | openvm | r0 | stone | stwo | | -: | -: | -: | -: | -: | -: | -: | | 32768 | 53.0 | 108 | 142 | 23 | 92.0 | 41 | | 65536 | 77.0 | 107 | 139 | 10 | 113.0 | 16 | | 131072 | 58.0 | 101 | 140 | 23 | 💾 | 18 | | 262144 | 103.0 | 100 | 141 | 22 | 💾 | 89 | | 524288 | 56.0 | 83 | 140 | 24 | 💾 | 14 | | 1048576 | 104.0 | 83 | 57 | 23 | 💾 | 414 | | 2097152 | 98.0 | 84 | 57 | 10 | 💾 | 367 | | 4194304 | ❌ | 83 | 57 | 23 | 💾 | 10 | <img alt="" /> ### Proof Size (KB) | n | jolt | sp1 | openvm | r0 | stone | stwo | | -: | -: | -: | -: | -: | -: | -: | | 32768 | 187.615 | 1315.53 | 1708.31 | 223.234 | 125.608 | 789.578 | | 65536 | 197.799 | 1315.53 | 1708.31 | 223.234 | 129.8 | 783.63 | | 131072 | 208.399 | 1315.53 | 1708.31 | 223.234 | 💾 | 783.834 | | 262144 | 219.415 | 1315.53 | 1708.31 | 223.234 | 💾 | 802.678 | | 524288 | 230.847 | 1315.53 | 1708.31 | 223.234 | 💾 | 801.194 | | 1048576 | 242.695 | 1315.53 | 852.937 | 223.234 | 💾 | 808.038 | | 2097152 | 254.959 | 1315.53 | 852.937 | 223.234 | 💾 | 819.122 | | 4194304 | ❌ | 1315.53 | 816.649 | 223.234 | 💾 | 866.882 | <img alt="" /> ### Cycle Count | n | jolt | sp1 | r0 | stone | stwo | | -: | -: | -: | -: | -: | -: | | 32768 | 196974 | 168808 | 166215 | 229390 | 262143 | | 65536 | 393582 | 332648 | 330055 | 458766 | 524287 | | 131072 | 786798 | 660328 | 657735 | 💾 | 1048575 | | 262144 | 1573230 | 1315688 | 1313095 | 💾 | 2097151 | | 524288 | 3146041 | 2626408 | 2623815 | 💾 | 4194303 | | 1048576 | 6291822 | 5247848 | 5245255 | 💾 | 8388607 | | 2097152 | 12583293 | 10490728 | 10488135 | 💾 | 16777215 | | 4194304 | ❌ | 20976488 | 20973895 | 💾 | 33554431 | <img alt="" /> ### Peak Memory (GB) | n | jolt | sp1 | openvm | r0 | stone | stwo | | -: | -: | -: | -: | -: | -: | -: | | 32768 | 6.44 | 5.12 | 7 | 2.3 | 59.44 | 11.08 | | 65536 | 5.83 | 6.42 | 5.43 | 4.58 | 118.54 | 11.46 | | 131072 | 8.79 | 9.18 | 5.43 | 9.15 | 💾 | 12.2 | | 262144 | 14.73 | 14.3 | 6.57 | 9.17 | 💾 | 14.01 | | 524288 | 26.95 | 15.12 | 12.22 | 9.17 | 💾 | 17.57 | | 1048576 | 50.85 | 25.94 | 12.22 | 9.17 | 💾 | 24.57 | | 2097152 | 98.93 | 35.61 | 12.42 | 9.18 | 💾 | 38.62 | | 4194304 | ❌ | 51.25 | 12.43 | 9.18 | 💾 | 72.26 | <img alt="" /> ## Sha2 Benchmark Sha256 hash of `n` bytes. For Stone, the [cairo implementation of sha256](https://github.com/cartridge-gg/cairo-sha256) by cartridge was used for benchmarking and for other zkvms [sha2 Rust crate](https://crates.io/crates/sha2) was used for benchmarking. ### Prover Time (s) | n | jolt | sp1 | openvm | r0 | stone | stwo | sp1-precompile | r0-precompile | openvm-precompile | | -: | -: | -: | -: | -: | -: | -: | -: | -: | -: | | 256 | 1.657 | 12.71 | 28.943 | 11.196 | 10.835 | 17.978 | 34.019 | 8.316 | 44.301 | | 512 | 1.711 | 13.184 | 29.561 | 11.306 | 19.88 | 15.051 | 33.991 | 11.33 | 43.728 | | 1024 | 2.173 | 13.863 | 30.609 | 17.136 | 31.021 | 16.833 | 33.83 | 11.201 | 44.897 | | 2048 | 3.324 | 15.021 | 34.184 | 28.934 | 31.294 | 17.726 | 34.531 | 17.174 | 44.683 | | 4096 | ❌ | 16.88 | 39.38 | 52.487 | 66.539 | 14.084 | 34.418 | 28.982 | 47.701 | | 8192 | ❌ | 24.037 | 50.539 | 86.688 | 116.467 | 14.979 | 35.564 | 52.48 | 48.995 | | 16384 | ❌ | 37.958 | 78.057 | 167.856 | 💾 | 21.402 | 38.267 | 110.887 | 52.865 | | 32768 | ❌ | 52.566 | 129.842 | 300.572 | 💾 | 16.555 | 46.209 | 184.873 | 60.148 | | 65536 | ❌ | 72.136 | 249.403 | 589.84 | 💾 | 18.384 | 60.138 | 357.716 | 79.957 | | 131072 | ❌ | 136.592 | 532.796 | 1172.21 | 💾 | 27.871 | 87.29 | 709.726 | 124.996 | | 262144 | ❌ | 257.02 | 916.603 | 2338.03 | 💾 | 27.362 | 121.022 | 1415.34 | 219.654 | | 524288 | ❌ | 513.726 | 1790.29 | 4673.32 | 💾 | 43.242 | 233.959 | 2825.46 | 393.678 | <img alt="" /> ### Verifier Time (ms) | n | jolt | sp1 | openvm | r0 | stone | stwo | sp1-precompile | r0-precompile | openvm-precompile | | -: | -: | -: | -: | -: | -: | -: | -: | -: | -: | | 256 | 50.0 | 108 | 141 | 10 | 428.0 | 10 | 83 | 22 | 142 | | 512 | 49.0 | 113 | 144 | 20 | 418.0 | 11 | 106 | 23 | 141 | | 1024 | 49.0 | 102 | 140 | 23 | 426.0 | 11 | 90 | 15 | 141 | | 2048 | 75.0 | 97 | 140 | 22 | 440.0 | 11 | 109 | 22 | 142 | | 4096 | ❌ | 106 | 139 | 22 | 454.0 | 11 | 99 | 23 | 141 | | 8192 | ❌ | 109 | 141 | 22 | 525.0 | 11 | 87 | 22 | 142 | | 16384 | ❌ | 82 | 144 | 22 | 💾 | 42 | 92 | 23 | 142 | | 32768 | ❌ | 94 | 140 | 23 | 💾 | 49 | 102 | 15 | 142 | | 65536 | ❌ | 83 | 141 | 23 | 💾 | 143 | 95 | 23 | 141 | | 131072 | ❌ | 83 | 57 | 24 | 💾 | 441 | 83 | 24 | 141 | | 262144 | ❌ | 83 | 56 | 24 | 💾 | 236 | 83 | 23 | 142 | | 524288 | ❌ | 83 | 56 | 23 | 💾 | 12 | 82 | 24 | 141 | <img alt="" /> ### Proof Size (KB) | n | jolt | sp1 | openvm | r0 | stone | stwo | sp1-precompile | r0-precompile | openvm-precompile | | -: | -: | -: | -: | -: | -: | -: | -: | -: | -: | | 256 | 172.143 | 1315.56 | 1708.31 | 223.482 | 104.104 | 986.394 | 1315.56 | 223.482 | 1784.35 | | 512 | 172.143 | 1315.56 | 1708.31 | 223.482 | 114.152 | 1000.61 | 1315.56 | 223.482 | 1784.35 | | 1024 | 181.495 | 1315.56 | 1708.31 | 223.482 | 117.224 | 1011.16 | 1315.56 | 223.482 | 1784.35 | | 2048 | 191.263 | 1315.56 | 1708.31 | 223.482 | 120.04 | 1011.71 | 1315.56 | 223.482 | 1784.35 | | 4096 | ❌ | 1315.56 | 1708.31 | 223.482 | 126.632 | 1007.77 | 1315.56 | 223.482 | 1784.35 | | 8192 | ❌ | 1315.56 | 1708.31 | 223.482 | 130.824 | 1013.42 | 1315.56 | 223.482 | 1784.35 | | 16384 | ❌ | 1315.56 | 1708.31 | 223.482 | 💾 | 1005.31 | 1315.56 | 223.482 | 1784.35 | | 32768 | ❌ | 1315.56 | 1708.31 | 223.482 | 💾 | 1018.49 | 1315.56 | 223.482 | 1784.35 | | 65536 | ❌ | 1315.56 | 1708.31 | 223.482 | 💾 | 1017.72 | 1315.56 | 223.482 | 1784.35 | | 131072 | ❌ | 1315.56 | 852.937 | 223.482 | 💾 | 1037.15 | 1315.56 | 223.482 | 1784.35 | | 262144 | ❌ | 1315.56 | 852.937 | 223.482 | 💾 | 1045.93 | 1315.56 | 223.482 | 1784.35 | | 524288 | ❌ | 1315.56 | 816.649 | 223.482 | 💾 | 1092.14 | 1315.56 | 223.482 | 1784.35 | <img alt="" /> ### Cycle Count | n | jolt | sp1 | r0 | stone | stwo | sp1-precompile | r0-precompile | | -: | -: | -: | -: | -: | -: | -: | -: | | 256 | 35325.0 | 33911 | 51280 | 14791.0 | 131071 | 11492 | 31643 | | 512 | 60893.0 | 52743 | 90848 | 29233.0 | 131071 | 15820 | 55467 | | 1024 | 112029 | 90407 | 169984 | 46295.0 | 131071 | 24476 | 103133 | | 2048 | 214301 | 165735 | 328256 | 80419.0 | 131071 | 41788 | 198463 | | 4096 | ❌ | 316391 | 644800 | 160489 | 262143 | 76412 | 389106 | | 8192 | ❌ | 617703 | 1277888 | 308807 | 52
프로젝트로 돌아가기