### Install Starknet Development Tools using `asdf` Source: https://docs.starknet.io/build/quickstart/appendix Installs Scarb, Starknet Foundry, and Starknet Devnet using the `asdf` version manager. This process involves adding the respective plugins, installing the latest versions, and setting them as the global default. It concludes with verification commands. ```bash asdf plugin add scarb asdf install scarb latest asdf set -u scarb latest asdf plugin add starknet-foundry asdf install starknet-foundry latest asdf set -u starknet-foundry latest asdf plugin add starknet-devnet asdf install starknet-devnet latest asdf set -u starknet-devnet latest ``` ```bash scarb --version snforge --version && sncast --version starknet-devnet --version ``` -------------------------------- ### Install WSL and Ubuntu on Windows Source: https://docs.starknet.io/build/quickstart/appendix Installs the Windows Subsystem for Linux (WSL) and the default Ubuntu distribution. This is a prerequisite for setting up Starknet development tools on Windows. It may require a system reboot. ```bash wsl --install ``` ```bash dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart ``` -------------------------------- ### Install prerequisite packages in Ubuntu (WSL) Source: https://docs.starknet.io/build/quickstart/environment-setup Updates the package list and installs essential development tools like curl, git, and build-essential within the Ubuntu environment on Windows using WSL. These are necessary for further installations. ```bash sudo apt update sudo apt install -y curl git build-essential ``` -------------------------------- ### Install `asdf` Version Manager Source: https://docs.starknet.io/build/quickstart/appendix Installs the `asdf` version manager using Homebrew. `asdf` allows for easy switching between different versions of tools like Scarb, Starknet Foundry, and Starknet Devnet. It adds `asdf` to the bashrc for persistent use. ```bash brew install asdf echo '. "$(brew --prefix asdf)/libexec/asdf.sh"' >> ~/.bashrc source ~/.bashrc ``` ```bash asdf --version ``` -------------------------------- ### Install Homebrew on MacOS/Linux Source: https://docs.starknet.io/build/quickstart/appendix Installs the Homebrew package manager on MacOS and Linux systems. Homebrew simplifies the installation of various command-line tools and software. After installation, it configures the shell environment. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.profile source ~/.profile ``` ```bash brew --version ``` -------------------------------- ### Successful Attestation Service Output Example Source: https://docs.starknet.io/secure/quickstart/attesting-to-blocks This output demonstrates a successful run of the attestation service. It includes initial attestation information such as staker address, stake amount, and epoch details. Subsequent log entries indicate the start of a new epoch, the sending of an attestation transaction, and its confirmation. ```shell 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 ``` -------------------------------- ### Manage Scarb Versions with ASDF Source: https://docs.starknet.io/build/quickstart/appendix This command sequence demonstrates how to manage different Scarb versions for a project using the `asdf` version manager. Use `asdf install scarb ` to install a specific Scarb version and `asdf set scarb ` to set it as the local version for the current project directory. ```bash asdf install scarb asdf set scarb ``` -------------------------------- ### Install asdf using Homebrew Source: https://docs.starknet.io/build/quickstart/environment-setup Installs the 'asdf' version manager using the Homebrew package manager. Ensure Homebrew is installed before running this command. ```bash brew install asdf ``` -------------------------------- ### Rust Range Usage Examples Source: https://docs.starknet.io/build/corelib/core-ops-range-Range Demonstrates how to create and use `Range` instances in Rust. Shows range comparison and iteration. The `start..end` syntax directly creates a `Range` object. ```rust assert!((3..5) == core::ops::Range { start: 3, end: 5 }); let mut sum = 0; for i in 3..6 { sum += i; } assert!(sum == 3 + 4 + 5); ``` -------------------------------- ### Install Starknet tools on MacOS/Linux using Starkup Source: https://docs.starknet.io/build/quickstart/environment-setup Installs Scarb, Starknet Foundry, and Starknet Devnet on MacOS and Linux systems using the Starkup installer script. This is the recommended method for these operating systems. ```bash curl --proto '=https' --tlsv1.2 -sSf https://sh.starkup.sh | sh ``` -------------------------------- ### Initialize NPM Package and Install Starknet.js Source: https://docs.starknet.io/build/starknet-by-example/applications/simple-storage Initializes a new npm package and installs the 'starknet' library as a dependency. This is the first step in setting up a project to interact with Starknet contracts using JavaScript. ```bash npm init npm install starknet@next ``` -------------------------------- ### Install Homebrew on Ubuntu (WSL) Source: https://docs.starknet.io/build/quickstart/environment-setup Installs the Homebrew package manager within the Ubuntu environment on Windows using WSL. Homebrew is then added to the shell environment for use. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.profile source ~/.profile ``` -------------------------------- ### Install WSL and Ubuntu on Windows Source: https://docs.starknet.io/build/quickstart/environment-setup Installs the Windows Subsystem for Linux (WSL) and the default Ubuntu distribution using a PowerShell command. This is a prerequisite for setting up Starknet development tools on Windows. ```powershell wsl --install ``` -------------------------------- ### Example Usage of StoragePathEntry Source: https://docs.starknet.io/build/corelib/core-starknet-storage-map-StoragePathEntry An example demonstrating how to use the StoragePathEntry trait to get the storage path for a balance of a specific address. It imports necessary types from the starknet crate and uses the entry method. ```rust use starknet::ContractAddress; use starknet::storage::{Map, StoragePathEntry}; #[storage] struct Storage { balances: Map, } // Get the storage path for the balance of a specific address let balance_path = self.balances.entry(address); ``` -------------------------------- ### Verify Homebrew installation on Ubuntu (WSL) Source: https://docs.starknet.io/build/quickstart/environment-setup Checks if the Homebrew package manager has been installed successfully within the Ubuntu environment on Windows via WSL by displaying its version. ```bash brew --version ``` -------------------------------- ### Rust: Example Usage of Add Trait Source: https://docs.starknet.io/build/corelib/core-traits-Add Provides examples of using the `Add` trait in StarkNet's Rust environment. The first example shows addition with primitive unsigned integer types. The second example demonstrates the `add` function directly, which is part of the `Add` trait. ```rust assert!(1_u8 + 2_u8 == 3_u8); ``` ```rust assert!(12 + 1 == 13); ``` -------------------------------- ### Commit-Reveal Usage Example in StarkNet (Rust) Source: https://docs.starknet.io/build/starknet-by-example/advanced/commit-reveal An example demonstrating how to use the Commit-Reveal pattern off-chain and on-chain with StarkNet. It shows the computation of the commitment hash and the subsequent calls to the contract's commit and reveal functions. This example assumes the contract is deployed and accessible. ```rust // Off-chain, compute the commitment hash for secret let secret = "My secret"; let offchain_commitment = PedersenTrait::new(secret).finalize(); // Commit on-chain contract.commit(offchain_commitment); // Reveal on-chain and assert the result let reveal_result = contract.reveal(secret); ``` -------------------------------- ### Install Starknet Foundry with asdf Source: https://docs.starknet.io/build/quickstart/environment-setup Adds the Starknet Foundry plugin to 'asdf', installs the latest version of Starknet Foundry, and sets it as the global default. This simplifies managing Starknet Foundry versions. ```bash asdf plugin add starknet-foundry asdf install starknet-foundry latest asdf set -u starknet-foundry latest ``` -------------------------------- ### Verify asdf Installation Source: https://docs.starknet.io/build/quickstart/environment-setup Checks if 'asdf' has been installed correctly by displaying its version number. This command confirms that the 'asdf' executable is accessible in the system's PATH. ```bash asdf --version ``` -------------------------------- ### Install Starknet Devnet with asdf Source: https://docs.starknet.io/build/quickstart/environment-setup Adds the Starknet Devnet plugin to 'asdf', installs the latest version of Starknet Devnet, and sets it as the global default. This allows for streamlined management of Starknet Devnet versions. ```bash asdf plugin add starknet-devnet asdf install starknet-devnet latest asdf set -u starknet-devnet latest ``` -------------------------------- ### Verify Starknet tool installations on MacOS/Linux Source: https://docs.starknet.io/build/quickstart/environment-setup Checks if Scarb, Starknet Foundry (snforge, sncast), and Starknet Devnet are installed correctly by querying their version numbers. Successful execution shows the version information for each tool. ```bash scarb --version snforge --version && sncast --version starknet-devnet --version ``` -------------------------------- ### Install Scarb with asdf Source: https://docs.starknet.io/build/quickstart/environment-setup Adds the Scarb plugin to 'asdf', installs the latest version of Scarb, and sets it as the global default. This enables easy management of Scarb versions. ```bash asdf plugin add scarb asdf install scarb latest asdf set -u scarb latest ``` -------------------------------- ### Example of BoxTrait::new in Rust Source: https://docs.starknet.io/build/corelib/core-box-BoxTrait Demonstrates the usage of the BoxTrait::new function to create a boxed integer. This example illustrates how to initialize a Box with a value. ```rust let x = 42; let boxed_x = BoxTrait::new(x); ``` -------------------------------- ### Example of BoxTrait::as_snapshot in Rust Source: https://docs.starknet.io/build/corelib/core-box-BoxTrait Demonstrates the usage of BoxTrait::as_snapshot to create a Box of a snapshot from an array. This example highlights its utility for non-copyable types. ```rust let snap_boxed_arr = @BoxTraits::new(array![1, 2, 3]); let boxed_snap_arr = snap_boxed_arr.as_snapshot(); let snap_arr = boxed_snap_arr.unbox(); ``` -------------------------------- ### Initialize Trusted Setup Ceremony (Bash) Source: https://docs.starknet.io/build/starknet-by-example/advanced/verify-proofs Initializes the 'Powers of Tau' phase of the trusted setup ceremony for Groth16 zk-SNARKs using 'snarkjs'. This command generates the initial tau power file required for subsequent contribution steps. The ceremony is crucial for generating the proving and verification keys. ```bash mkdir target/ptau && cd target/ptau snarkjs powersoftau new bn128 12 pot12_0000.ptau -v ``` -------------------------------- ### Rust Display Trait Usage Example Source: https://docs.starknet.io/build/corelib/core-fmt-Display An example demonstrating the usage of the Display trait in Rust. It shows how to format a ByteArray using the standard empty format specifier "{}" with println! macro. ```rust let word: ByteArray = "123"; println!("{}", word); ``` -------------------------------- ### Install rclone File Manager (Shell) Source: https://docs.starknet.io/secure/quickstart/running-a-node Installs the rclone file manager, a tool used for downloading data snapshots from cloud storage. This script is for Linux, macOS, and BSD systems. ```shell sudo -v ; curl https://rclone.org/install.sh | sudo bash ``` -------------------------------- ### GET /get_version Source: https://docs.starknet.io/learn/cheatsheets/starkgate-reference Returns the current version of StarkGate. ```APIDOC ## GET /get_version ### Description Returns the current version of StarkGate. ### Method GET ### Endpoint /get_version ### Parameters None. ### Response #### Success Response (200) - **felt252** (string) - The current version of StarkGate. #### Response Example ```json { "felt252": "v2.0.1" } ``` ``` -------------------------------- ### GET /get_remaining_withdrawal_quota Source: https://docs.starknet.io/learn/cheatsheets/starkgate-reference Returns the amount a user can withdraw within the current 24-hour period (starting at 00:00 UTC). ```APIDOC ## GET /get_remaining_withdrawal_quota ### Description Returns the amount that the user can withdraw within the current 24-hour time period. The time period begins at 00:00 UTC. ### Method GET ### Endpoint /get_remaining_withdrawal_quota ### Parameters #### Query Parameters - **l1_token_address** (string) - Required - The L1 address of the ERC-20 token contract. ### Response #### Success Response (200) - **u256** (string) - The amount that can currently be withdrawn from the bridge, in units defined by the ERC-20 token contract. #### Response Example ```json { "u256": "1000000000000000000" } ``` ``` -------------------------------- ### Create Starknet Keystore File Source: https://docs.starknet.io/build/quickstart/appendix Creates an encrypted keystore file for a Starknet account using `starkli`. This involves exporting a private key from a wallet and providing a password to encrypt it. The output is saved to `keystore.json`. ```terminal starkli signer keystore from-key keystore.json ``` -------------------------------- ### Get Caller Address in Starknet (Rust) Source: https://docs.starknet.io/build/corelib/core-starknet-info-get_caller_address Retrieves the address of the caller contract. Returns 0 if there is no caller, such as when a transaction starts execution within an account contract. Use `get_execution_info().tx_info.unbox().account_contract_address` for the originating account contract address. ```rust use starknet::get_caller_address; let caller = get_caller_address(); ``` -------------------------------- ### Reading from StarkNet Storage Maps (Rust) Source: https://docs.starknet.io/build/corelib/core-starknet-storage-map-StorageMapReadAccess Example demonstrating how to read from single and nested storage Maps using the StorageMapReadAccess trait in StarkNet. It shows the usage of the .read() method on Map instances. ```rust use starknet::ContractAddress; use starknet::storage::{Map, StorageMapReadAccess, StoragePathEntry}; #[storage] struct Storage { balances: Map, allowances: Map>, } fn read_storage(self: @ContractState, address: ContractAddress) { // Read from single mapping let balance = self.balances.read(address); // Read from nested mapping let allowance = self.allowances.entry(owner).read(spender); } ``` -------------------------------- ### Define Countable Component in Rust Source: https://docs.starknet.io/build/starknet-by-example/basic/components/dependencies Defines a basic 'Countable' component with 'get' and 'increment' functions. It uses StarkNet's component system and storage for state management. This serves as a foundational example for demonstrating component dependencies. ```rust #[starknet::interface] pub trait ICountable { fn get(self: @TContractState) -> u32; fn increment(ref self: TContractState); } #[starknet::component] pub mod countable_component { use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; #[storage] pub struct Storage { countable_value: u32, } #[embeddable_as(Countable)] impl CountableImpl> of super::ICountable> { fn get(self: @ComponentState) -> u32 { self.countable_value.read() } fn increment(ref self: ComponentState) { self.countable_value.write(self.countable_value.read() + 1); } } } ``` -------------------------------- ### Secp256PointTrait Usage Examples in Rust Source: https://docs.starknet.io/build/corelib/core-starknet-secp256_trait-Secp256PointTrait Demonstrates the usage of the Secp256PointTrait in StarkNet, showing how to retrieve the generator point, get coordinates, perform point addition, and scalar multiplication. It utilizes `SyscallResultTrait` for handling syscall results. ```rust use starknet::SyscallResultTrait; use starknet::secp256k1::Secp256k1Point; use starknet::secp256_trait::Secp256PointTrait; use starknet::secp256_trait::Secp256Trait; let generator = Secp256Trait::::get_generator_point(); assert!( Secp256PointTrait::get_coordinates(generator) .unwrap_syscall() == ( 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798, 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8, ), ); let point = Secp256PointTrait::add(generator, generator); let other_point = Secp256PointTrait::mul(generator, 2); ``` -------------------------------- ### Get Unspent Gas and Assert Consumption in Rust Source: https://docs.starknet.io/build/corelib/core-testing-get_unspent_gas Demonstrates how to use `get_unspent_gas` to capture gas usage before and after executing a gas-intensive function. It then asserts that the gas consumed is within expected bounds. This example is useful for performance testing and gas budget validation in StarkNet smart contracts. ```rust use core::testing::get_unspent_gas; fn gas_heavy_function() { // ... some gas-intensive code } fn test_gas_consumption() { let gas_before = get_unspent_gas(); gas_heavy_function(); let gas_after = get_unspent_gas(); assert!(gas_after - gas_before u128 implicits(GasBuiltin) nopanic; ``` -------------------------------- ### Generate new Starknet project with Scarb Source: https://docs.starknet.io/build/quickstart/hellostarknet Use the Scarb command-line tool to generate a new Starknet project. This command initializes a new directory with a default contract structure and test runner setup. ```bash scarb new hello_starknet ``` -------------------------------- ### Rust: Proving StarkNet IO Components Source: https://docs.starknet.io/learn/S-two-book/air-development/components/index This Rust code snippet demonstrates the process of proving StarkNet IO components. It involves generating trace columns, creating statement objects, committing to trace columns, drawing random elements, generating LogUp columns, committing to LogUp columns, and finally generating the Stark proof. ```rust fn main() { // --snip-- // Create trace columns let scheduling_trace = gen_scheduling_trace(log_size); let computing_trace = gen_computing_trace(log_size, &scheduling_trace[0], &scheduling_trace[1]); // Statement 0 let statement0 = ComponentsStatement0 { log_size }; statement0.mix_into(channel); // Commit to the trace columns let mut tree_builder = commitment_scheme.tree_builder(); tree_builder.extend_evals([scheduling_trace.clone(), computing_trace.clone()].concat()); tree_builder.commit(channel); // Draw random elements to use when creating the random linear combination of lookup values in the LogUp columns let lookup_elements = ComputationLookupElements::draw(channel); // Create LogUp columns let (scheduling_logup_cols, scheduling_claimed_sum) = gen_scheduling_logup_trace( log_size, &scheduling_trace[0], &scheduling_trace[1], &lookup_elements, ); let (computing_logup_cols, computing_claimed_sum) = gen_computing_logup_trace( log_size, &computing_trace[0], &computing_trace[2], &lookup_elements, ); // Statement 1 let statement1 = ComponentsStatement1 { scheduling_claimed_sum, computing_claimed_sum, }; statement1.mix_into(channel); // Commit to the LogUp columns let mut tree_builder = commitment_scheme.tree_builder(); tree_builder.extend_evals([scheduling_logup_cols, computing_logup_cols].concat()); tree_builder.commit(channel); let components = Components::new(&statement0, &lookup_elements, &statement1); let stark_proof = prove(&components.component_provers(), channel, commitment_scheme).unwrap(); let proof = ComponentsProof { statement0, statement1, stark_proof, }; // --snip-- } ``` -------------------------------- ### IntoIterator::into_iter Function Example in Rust Source: https://docs.starknet.io/build/corelib/core-iter-traits-collect-IntoIterator Provides an example of calling the `into_iter` function on an array, which returns an iterator. The example demonstrates consuming the iterator using `next()`. ```rust let mut iter = array![1, 2, 3].into_iter(); assert_eq!(Some(1), iter.next()); assert_eq!(Some(2), iter.next()); assert_eq!(Some(3), iter.next()); assert_eq!(None, iter.next()); ``` -------------------------------- ### Fetch Documentation Navigation Data Source: https://docs.starknet.io/build/corelib/core-SegmentArena This example demonstrates how to fetch navigation and other documentation pages from the StarkNet website. It uses a direct URL to download the 'llms.txt' file, which likely contains structured data for website navigation and content indexing. This is a common pattern for dynamically loading documentation resources. ```shell curl https://docs.starknet.io/llms.txt ``` -------------------------------- ### Prove and verify StarkNet components in Rust Source: https://docs.starknet.io/learn/S-two-book/air-development/preprocessed-trace/index Illustrates the final steps of creating a 'FrameworkComponent' with the 'TestEval' struct, then generating a proof and subsequently verifying it. This involves committing to commitments, mixing the log size, and calling the 'prove' and 'verify' functions. ```rust fn main() { ... // Create a component let component = FrameworkComponent::::new( &mut TraceLocationAllocator::default(), TestEval { is_first_id: is_first_column.id(), log_size, }, QM31::zero(), ); // Prove let proof = prove(&[&component], channel, commitment_scheme).unwrap(); // Verify let channel = &mut Blake2sChannel::default(); let commitment_scheme = &mut CommitmentSchemeVerifier::::new(config); let sizes = component.trace_log_degree_bounds(); commitment_scheme.commit(proof.commitments[0], &sizes[0], channel); channel.mix_u64(log_size as u64); commitment_scheme.commit(proof.commitments[1], &sizes[1], channel); verify(&[&component], channel, commitment_scheme, proof).unwrap(); } ``` -------------------------------- ### Get Block Info Source: https://docs.starknet.io/build/corelib/core-starknet-info-get_block_info Retrieves the block information for the current block on the StarkNet network. ```APIDOC ## GET /starknet/info/get_block_info ### Description Returns the block information for the current block. ### Method GET ### Endpoint /starknet/info/get_block_info ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example None ### Response #### Success Response (200) - **block_info** (object) - An object containing details about the current block. - **block_number** (number) - The number of the current block. - **block_timestamp** (number) - The timestamp of the current block. - **sequencer_address** (string) - The address of the sequencer for the current block. #### Response Example ```json { "block_number": 12345, "block_timestamp": 1678886400, "sequencer_address": "0x123abc" } ``` ``` -------------------------------- ### Get Block Timestamp Source: https://docs.starknet.io/build/corelib/core-starknet-info-get_block_timestamp Retrieves the timestamp of the current block in the StarkNet network. ```APIDOC ## GET /core/starknet/info/get_block_timestamp ### Description Returns the timestamp of the current block. ### Method GET ### Endpoint /core/starknet/info/get_block_timestamp ### Parameters No parameters available for this endpoint. ### Request Example No request body is needed for this GET request. ### Response #### Success Response (200) - **block_timestamp** (u64) - The timestamp of the current block. ``` -------------------------------- ### Fetch Predeployed Starknet Account on Sepolia Source: https://docs.starknet.io/build/quickstart/appendix Fetches a predeployed Starknet account on the Sepolia testnet using `starkli`. It requires the smart wallet address and outputs the account information to `account.json`. The network is explicitly set to 'sepolia'. ```terminal starkli account fetch \ \ --output account.json \ --network=sepolia ``` -------------------------------- ### Rust SubAssign Function Example Source: https://docs.starknet.io/build/corelib/core-ops-arith-SubAssign Demonstrates the usage of the sub_assign function from the SubAssign trait in Rust. This example shows how to perform subtraction assignment on a mutable u8 variable. ```rust let mut x: u8 = 3; x -= x; assert!(x == 0); ``` -------------------------------- ### Rust Clone Trait Example Source: https://docs.starknet.io/build/corelib/core-clone-Clone An example demonstrating the usage of the `clone` function on a Rust array. It verifies that cloning an array produces an identical copy. ```rust let arr = array![1, 2, 3]; assert!(arr == arr.clone()); ``` -------------------------------- ### Generate zkey file for StarkNet Zk-SNARKs Source: https://docs.starknet.io/build/starknet-by-example/advanced/verify-proofs Generates a Groth16 setup zkey file required for StarkNet Zk-SNARKs. This involves setting up the circuit using the compiled circuit (r1cs), the finalized ptau file, and outputs the initial zkey file. ```bash cd .. snarkjs groth16 setup circuit.r1cs ptau/pot12_final.ptau circuit_0000.zkey ``` -------------------------------- ### Run Equilibrium's Attestation Service with Docker Source: https://docs.starknet.io/secure/quickstart/attesting-to-blocks This command launches Equilibrium's attestation service using Docker. It requires setting the OPERATIONAL_PRIVATE_KEY environment variable and providing staking and attestation contract addresses, along with the operational address and node URL. The `--local-signer` flag indicates the use of a local signing mechanism. ```shell docker run -it --rm --network host \ -e VALIDATOR_ATTESTATION_OPERATIONAL_PRIVATE_KEY=$OPERATIONAL_PRIVATE_KEY \ ghcr.io/eqlabs/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 ``` -------------------------------- ### Import and Use Array from Cairo Corelib Source: https://docs.starknet.io/build/corelib/intro Demonstrates how to import the Array module from the Cairo core library and append an element to a new array. This is a fundamental example for using Corelib's data structures. ```rust use core::array::Array; fn main() { let mut arr = Array::new(); arr.append(42); } ``` -------------------------------- ### Create New Rust Project with Cargo Source: https://docs.starknet.io/learn/S-two-book/air-development/writing-a-simple-air/hello-world Initializes a new Rust project using the Cargo build system. This command creates a new directory with a basic project structure. ```bash cargo new stwo-example ``` -------------------------------- ### Rust Rem Function Example Source: https://docs.starknet.io/build/corelib/core-traits-Rem Provides an example of the 'rem' function in action. It illustrates performing the remainder operation on unsigned 8-bit integers and asserting the expected result. ```rust assert!(12_u8 % 10_u8 == 2_u8); ``` -------------------------------- ### Rust Rem Trait Example Usage Source: https://docs.starknet.io/build/corelib/core-traits-Rem Demonstrates the usage of the Rem trait with an example. It shows how to perform the remainder operation using the '%' operator on unsigned 8-bit integers. ```rust assert!(3_u8 % 2_u8 == 1_u8); ``` -------------------------------- ### Rust Neg Trait Function Usage Example Source: https://docs.starknet.io/build/corelib/core-traits-Neg An example showcasing the usage of the `neg` function provided by the `Neg` trait to perform unary negation on an `i8` integer. ```rust let x: i8 = 1; assert!(-x == -1); ``` -------------------------------- ### Verify Proofs and Commitments in Rust Source: https://docs.starknet.io/learn/S-two-book/air-development/components This Rust code demonstrates the verification process for a StarkNet proof. It includes steps for verifying claimed sums, unpacking the proof, setting up commitment schemes, and committing to various statements and columns. The function ultimately calls a verify function to complete the process. ```rust fn main() { // --snip-- // Verify claimed sums assert_eq!( scheduling_claimed_sum + computing_claimed_sum, SecureField::zero() ); // Unpack proof let statement0 = proof.statement0; let statement1 = proof.statement1; let stark_proof = proof.stark_proof; // Create channel and commitment scheme let channel = &mut Blake2sChannel::default(); let commitment_scheme = &mut CommitmentSchemeVerifier::::new(config); let log_sizes = statement0.log_sizes(); // Preprocessed columns. commitment_scheme.commit(stark_proof.commitments[0], &log_sizes[0], channel); // Commit to statement 0 statement0.mix_into(channel); // Trace columns. commitment_scheme.commit(stark_proof.commitments[1], &log_sizes[1], channel); // Draw lookup element. let lookup_elements = ComputationLookupElements::draw(channel); // Commit to statement 1 statement1.mix_into(channel); // Interaction columns. commitment_scheme.commit(stark_proof.commitments[2], &log_sizes[2], channel); // Create components let components = Components::new(&statement0, &lookup_elements, &statement1); verify( &components.components(), channel, commitment_scheme, stark_proof, ) .unwrap(); } ``` -------------------------------- ### Example of BoxTrait::unbox in Rust Source: https://docs.starknet.io/build/corelib/core-box-BoxTrait Shows how to use the BoxTrait::unbox function to retrieve a value from a Box. This example verifies that the unboxed value matches the original value. ```rust let boxed = BoxTrait::new(42); assert!(boxed.unbox() == 42); ``` -------------------------------- ### Prove StarkNet Components in Rust Source: https://docs.starknet.io/learn/S-two-book/air-development/components This Rust code snippet demonstrates the process of proving StarkNet components. It involves generating scheduling and computing traces, creating statement objects, committing to traces and LogUp columns, and finally generating the Stark proof. Dependencies include various StarkNet internal components and commitment schemes. ```rust fn main() { // --snip-- // Create trace columns let scheduling_trace = gen_scheduling_trace(log_size); let computing_trace = gen_computing_trace(log_size, &scheduling_trace[0], &scheduling_trace[1]); // Statement 0 let statement0 = ComponentsStatement0 { log_size }; statement0.mix_into(channel); // Commit to the trace columns let mut tree_builder = commitment_scheme.tree_builder(); tree_builder.extend_evals([scheduling_trace.clone(), computing_trace.clone()].concat()); tree_builder.commit(channel); // Draw random elements to use when creating the random linear combination of lookup values in the LogUp columns let lookup_elements = ComputationLookupElements::draw(channel); // Create LogUp columns let (scheduling_logup_cols, scheduling_claimed_sum) = gen_scheduling_logup_trace( log_size, &scheduling_trace[0], &scheduling_trace[1], &lookup_elements, ); let (computing_logup_cols, computing_claimed_sum) = gen_computing_logup_trace( log_size, &computing_trace[0], &computing_trace[2], &lookup_elements, ); // Statement 1 let statement1 = ComponentsStatement1 { scheduling_claimed_sum, computing_claimed_sum, }; statement1.mix_into(channel); // Commit to the LogUp columns let mut tree_builder = commitment_scheme.tree_builder(); tree_builder.extend_evals([scheduling_logup_cols, computing_logup_cols].concat()); tree_builder.commit(channel); let components = Components::new(&statement0, &lookup_elements, &statement1); let stark_proof = prove(&components.component_provers(), channel, commitment_scheme).unwrap(); let proof = ComponentsProof { statement0, statement1, stark_proof, }; // --snip-- } ``` -------------------------------- ### Optimized Carry Calculation by Inlining (Python) Source: https://docs.starknet.io/learn/S-two-book/cairo-air/add-opcode This example shows an optimization technique where carry calculations are inlined to reduce the number of constraints and avoid dedicated columns for intermediate carry values. The second-limb carry calculation is shown as an illustration. ```python carry_limb_2 = (op0[1] + op1[1] + ((op0[0] + op1[0] - dst[0] - sub_p_bit) / 2^9) - dst[1]) / 2^9 ``` -------------------------------- ### Rust Neg Trait Implementation Example for Sign Enum Source: https://docs.starknet.io/build/corelib/core-traits-Neg An example demonstrating the implementation of the `Neg` trait for a custom `Sign` enum. This allows negating the sign of an enum value. ```rust #[derive(Copy, Drop, PartialEq)] enum Sign { Negative, Zero, Positive, } impl SignNeg of Neg { fn neg(a: Sign) -> Sign { match a { Sign::Negative => Sign::Positive, Sign::Zero => Sign::Zero, Sign::Positive => Sign::Negative, } } } // A negative positive is a negative assert!(-Sign::Positive == Sign::Negative); // A double negative is a positive assert!(-Sign::Negative == Sign::Positive); // Zero is its own negation assert!(-Sign::Zero == Sign::Zero); ``` -------------------------------- ### BitXor Usage Example with u8 in Rust Source: https://docs.starknet.io/build/corelib/core-traits-BitXor A simple example demonstrating the usage of the bitxor function with unsigned 8-bit integers (u8) in Rust. It shows a basic XOR operation and assertion. ```rust assert!(1_u8 ^ 2_u8 == 3); ``` -------------------------------- ### Set up Starknet Provider and Account Address Source: https://docs.starknet.io/build/starknet-by-example/applications/simple-storage Establishes a connection to the Starknet network using a provider and defines the account address. This code snippet imports necessary modules from starknet.js and sets up the environment for contract interaction. ```javascript // [!include ~/listings/applications/simple_storage_starknetjs/index.js:imports] // [!include ~/listings/applications/simple_storage_starknetjs/index.js:provider] const accountAddress = // 'PASTE_ACCOUNT_ADDRESS_HERE'; ``` -------------------------------- ### Verify Proof Statements and Commitments in Rust Source: https://docs.starknet.io/learn/S-two-book/air-development/components/index This Rust code snippet demonstrates the verification process of a StarkNet proof. It asserts the claimed sums, unpacks the proof into statements and the Stark proof, and then sets up a channel and commitment scheme. It proceeds to commit to preprocessed columns, statement 0, trace columns, and interaction columns, drawing lookup elements and committing to statement 1 before finally verifying the components. ```rust fn main() { // --snip-- // Verify claimed sums assert_eq!( scheduling_claimed_sum + computing_claimed_sum, SecureField::zero() ); // Unpack proof let statement0 = proof.statement0; let statement1 = proof.statement1; let stark_proof = proof.stark_proof; // Create channel and commitment scheme let channel = &mut Blake2sChannel::default(); let commitment_scheme = &mut CommitmentSchemeVerifier::::new(config); let log_sizes = statement0.log_sizes(); // Preprocessed columns. commitment_scheme.commit(stark_proof.commitments[0], &log_sizes[0], channel); // Commit to statement 0 statement0.mix_into(channel); // Trace columns. commitment_scheme.commit(stark_proof.commitments[1], &log_sizes[1], channel); // Draw lookup element. let lookup_elements = ComputationLookupElements::draw(channel); // Commit to statement 1 statement1.mix_into(channel); // Interaction columns. commitment_scheme.commit(stark_proof.commitments[2], &log_sizes[2], channel); // Create components let components = Components::new(&statement0, &lookup_elements, &statement1); verify( &components.components(), channel, commitment_scheme, stark_proof, ) .unwrap(); } ```