### Set up Homebrew and Core Utilities Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Installs Homebrew and the 'coreutils' package, which provides essential command-line utilities like 'sha256sum'. Ensures Homebrew is added to the user's profile for correct environment setup. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` ```bash echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/carmencheng/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)" ``` ```bash brew install coreutils ``` -------------------------------- ### Build and Test LayerZero V2 Project Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/README.md Standard commands to install dependencies, build the project, and run tests. Ensure you have Node.js and Yarn installed. ```bash yarn && yarn build && yarn test ``` -------------------------------- ### Install solana-verify Tool Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Install the solana-verify CLI tool to check program hashes. This tool is essential for verifying the integrity of deployed Solana programs. ```bash cargo install solana-verify ``` -------------------------------- ### Install Tart for macOS VMs Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Installs tart, a tool for managing macOS virtual machines. ```bash brew install cirruslabs/cli/tart ``` -------------------------------- ### Install Repository Dependencies Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Navigate to the LayerZero-v2 repository and install project dependencies using yarn. This step is crucial before building the contracts. ```bash cd ~/Desktop/layerzero/monorepo yarn ``` -------------------------------- ### Install Rust Toolchain Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Installs the Rust programming language toolchain, specifically version 1.75.0, which is required for building and deploying Solana programs. ```bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain=1.75.0 . "$HOME/.cargo/env" ``` -------------------------------- ### Install Solana CLI Tools Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Installs the Solana command-line interface tools, version v1.17.31, enabling interaction with the Solana network and building Solana programs. Updates the PATH environment variable. ```bash curl -o- -sSfL https://release.solana.com/v1.17.31/install | bash export PATH="/Users/carmencheng/.local/share/solana/install/active_release/bin:$PATH" ``` -------------------------------- ### Install and Use Anchor Framework Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Installs the Anchor framework for Solana smart contract development, including a specific version manager (avm) and sets the active Anchor version to 0.29.0. ```bash cargo install --git https://github.com/coral-xyz/anchor avm --force avm install 0.29.0 avm use 0.29.0 ``` -------------------------------- ### Build Solana Program with Anchor Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/README.md Compiles the Solana program using the Anchor framework. This command also handles dependency installation. ```shell anchor build ``` -------------------------------- ### Install Homebrew on macOS Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Installs Homebrew, a package manager for macOS, to manage dependencies. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### Install NVM and Node.js Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Installs Node Version Manager (NVM) and Node.js version 20, which are required for running JavaScript tools within the monorepo build process. ```bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" ``` ```bash nvm install 20 ``` -------------------------------- ### Global ID Assignment Example Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/ptb-builders/ptb-move-call/README.md Demonstrates how to assign global IDs to specific results using the `result_ids` field. Use zero bytes32 for unassigned results. If no global ID is needed, use an empty array. ```json { "result_ids": ["id1", "0x0", "id3"] } ``` ```json { "result_ids": [] } ``` -------------------------------- ### Caller Validation in Handle Call Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/dynamic-call/README.md Provides an example of correctly validating the caller's identity before processing a call. Use `assert_caller` to ensure the call originates from the expected address, preventing unauthorized access. ```move public fun handle_call(call: Call, cap: &CallCap) { // Assert that the call came from the expected caller call.assert_caller(@expected_caller_address); let result = process_call_logic(call.param()); call.complete(cap, result); } ``` -------------------------------- ### Create Admin User and Switch Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Creates a new user account named 'carmencheng' with administrative privileges and switches to it. Note: The username 'carmencheng' is required due to tooling limitations. ```bash sudo sysadminctl -addUser carmencheng -fullName "" -password admin sudo dscl . -append /Groups/admin GroupMembership carmencheng ``` ```bash su - carmencheng ``` -------------------------------- ### Sequential Batch Creation with Nonces Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/dynamic-call/README.md Illustrates the correct sequential usage of nonces for creating child batches. Nonce values must increment by one for each new batch to ensure proper ordering and prevent skips. ```move call.new_child_batch(&cap, 1); // First batch // ... process batch 1 ... call.new_child_batch(&cap, 2); // Second batch ``` -------------------------------- ### Build Solana Program with Anchor Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Navigate to the Solana programs directory and build the contracts using the Anchor framework. This command compiles the smart contracts. ```bash cd ~/Desktop/layerzero/monorepo/packages/layerzero-v2/solana/programs anchor build ``` -------------------------------- ### Sequential Batch Creation in Call Module Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/sui/contracts/dynamic-call/README.md Illustrates the correct usage of sequential nonces for creating child batches. Ensure nonces are incremented sequentially to avoid skipping batches. ```move // ✅ CORRECT: Sequential nonce usage call.new_child_batch(&cap, 1); // First batch // ... process batch 1 ... call.new_child_batch(&cap, 2); // Second batch // ❌ INCORRECT: Non-sequential nonces call.new_child_batch(&cap, 1); call.new_child_batch(&cap, 3); // Skips nonce 2 ``` -------------------------------- ### Traditional Dynamic Dispatch (Pseudocode) Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/dynamic-call/README.md Illustrates a traditional dynamic dispatch pattern using interfaces and runtime selection, which is not directly supported in Move. ```pseudocode // Interface-based polymorphism - unsupported in Move interface MessageLib { function send(packet: Packet) -> Receipt; function quote(packet: Packet) -> Fee; } // Runtime selection and dynamic dispatch let lib: MessageLib = resolveLibrary(config); let receipt = lib.send(packet); // Dynamic method resolution ``` -------------------------------- ### Deploy Solana Program Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/README.md Deploys the compiled Solana program to the network using the Solana CLI. Ensure you have the correct program ID and compiled program file. ```shell solana program deploy --program-id ./keypair/xxx.json ./target/deploy/xxx.so ``` -------------------------------- ### Correct Parameter Type Specificity Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/sui/contracts/dynamic-call/README.md Demonstrates the correct way to define distinct parameter types for different execution intents to ensure type safety and prevent misrouting. ```move public struct SendMessageParams has copy, drop, store { packet: Packet, options: vector } public struct QuoteMessageParams has copy, drop, store { packet: Packet, options: vector } ``` -------------------------------- ### PTB Construction Execution Flow Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/sui/contracts/ptb-builders/ptb-move-call/README.md Illustrates the step-by-step process of constructing and executing a Programmable Transaction Block (PTB) in LayerZero V2, from initial construction to blockchain submission. ```text 1. Root PTB Construction → Developer creates root PTB with direct calls and/or builder calls 2. Off-chain Simulation → Builder calls route to their respective component builders 3. PTB Expansion → Each builder produces call sequences (may include more builder calls) 4. PTB Assembly → Calls produced by builder combined into the root PTB 5. Recursive Expansion → Process repeats until all builder calls are resolved 6. Blockchain Submission → Final PTB with only direct calls executed atomically ``` -------------------------------- ### Call Module: Dynamic Dispatch Emulation Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/dynamic-call/README.md Demonstrates how the Call Module emulates dynamic dispatch in Move by creating a call object for runtime target determination with compile-time safety. ```move // Runtime target determination with compile-time safety let call = call::create( &caller_cap, resolve_library_address(config), // Runtime resolution false, // Bidirectional communication send_params, ctx ); // Type-safe parameter passing and result collection // ... call flows to selected library ... call.complete(&library_cap, receipt); // Guaranteed result extraction let (callee_addr, params, receipt) = call.destroy(&caller_cap); ``` -------------------------------- ### Correct Parameter Type Specificity in Move Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/dynamic-call/README.md Demonstrates the correct way to define distinct, intent-specific parameter types for functions to ensure type safety and prevent misrouting. ```move // ✅ CORRECT: Intent-specific types prevent misrouting public struct SendMessageParams has copy, drop, store { packet: Packet, options: vector } public struct QuoteMessageParams has copy, drop, store { packet: Packet, options: vector } ``` -------------------------------- ### Enable Parameter Mutability in Call Module Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/dynamic-call/README.md Demonstrates how to enable and use mutable parameters within the Call module. Ensure mutability is enabled explicitly by the caller before the callee attempts to modify parameters. ```move let mut call = call::create( &caller_cap, callee_address, false, params, ctx ); // Explicitly enable parameter mutability (only caller can do this) call.enable_mutable_param(&caller_cap); // Now callee can modify parameters public fun process_call(call: &mut Call, cap: &CallCap) { let params = call.param_mut(cap); // Requires mutable_param = true // ... modify parameters ... } ``` -------------------------------- ### Manage macOS VM with Tart Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Clones a base macOS Sonoma image, runs it, and provides a command to delete it when no longer needed. ```bash tart clone ghcr.io/cirruslabs/macos-sonoma-base:latest sonoma-base tart run sonoma-base ``` ```bash tart delete sonoma-base ``` -------------------------------- ### Download and Verify On-Chain Program Hash Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Retrieve and verify the program hash of a deployed contract on the Solana network using its public endpoint and address. ```bash solana-verify get-program-hash -u https://api.mainnet-beta.solana.com 76y77prsiCMvXMjuoZ5VRrhG5qYBrUMYTE5WgHqgjEn6 ``` -------------------------------- ### Set Rust Toolchain to Nightly Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/README.md Ensures the Rust toolchain is set to the nightly version, which is a prerequisite for building the Solana programs. ```shell rustup default nightly ``` -------------------------------- ### FIFO Destruction Order for Children Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/dynamic-call/README.md Demonstrates the required First-In, First-Out (FIFO) order for destroying child calls. Children must be destroyed in the same order they were created to avoid errors. ```move let (_, _, result1) = call.destroy_child(&cap, child1); // First created let (_, _, result2) = call.destroy_child(&cap, child2); // Second created ``` -------------------------------- ### Enable Corepack Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Enables Corepack, a tool for managing package managers like Yarn, which is necessary for the build process. ```bash corepack enable ``` -------------------------------- ### SSH into macOS VM Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Connects to the running macOS virtual machine via SSH using default credentials. ```bash ssh admin@$(tart ip sonoma-base) ``` -------------------------------- ### Incorrect Parameter Type Specificity in Move Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/dynamic-call/README.md Illustrates an incorrect approach using generic parameter types, which can lead to processing errors and security vulnerabilities due to potential misrouting. ```move // ❌ INCORRECT: Generic types enable processing errors public struct MessageParams has copy, drop, store { packet: Packet, options: vector } ``` -------------------------------- ### Generate Executable Hash Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Compute the SHA256 hash of the compiled Solana program executable. This is used to verify the local build. ```bash solana-verify get-executable-hash ./target/deploy/endpoint.so ``` -------------------------------- ### Run Solana Program Tests Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/README.md Executes the test suite for the Solana program. The TEST_SCOPES environment variable can be used to filter tests. ```shell yarn test ``` ```shell TEST_SCOPES=uln yarn test ``` ```shell anchor test --skip-build ``` -------------------------------- ### Clone LayerZero Repository Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/solana/programs/verify-contracts.md Clones the LayerZero-v2 monorepo and checks out a specific commit required for verification. Refer to the Program Hash Table for commit details. ```bash git clone https://github.com/LayerZero-Labs/LayerZero-v2.git ~/Desktop/layerzero/monorepo ``` ```bash cd ~/Desktop/layerzero/monorepo git checkout 37c598b3e6e218c5e00c8b0dcd42f984e5b13147 ``` -------------------------------- ### Incorrect Parameter Type Specificity Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/sui/contracts/dynamic-call/README.md Illustrates an incorrect approach to parameter definition using generic types, which can lead to processing errors and security vulnerabilities. ```move public struct MessageParams has copy, drop, store { packet: Packet, options: vector } ``` -------------------------------- ### FIFO Destruction Order for Child Calls Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/sui/contracts/dynamic-call/README.md Explains the First-In, First-Out (FIFO) destruction order for child calls. Children must be destroyed in the order they were created to avoid errors. ```move // ✅ CORRECT: Destroy in creation order let (_, _, result1) = call.destroy_child(&cap, child1); // First created let (_, _, result2) = call.destroy_child(&cap, child2); // Second created // ❌ INCORRECT: Out-of-order destruction let (_, _, result2) = call.destroy_child(&cap, child2); // Will fail let (_, _, result1) = call.destroy_child(&cap, child1); ``` -------------------------------- ### CallCap Structure and CapType Enum Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/sui/contracts/dynamic-call/README.md Defines the `CallCap` structure for authorization and the `CapType` enum to differentiate between individual and package capabilities. ```move public struct CallCap has key, store { id: UID, cap_type: CapType, } public enum CapType has copy, drop, store { Individual, Package(address), } ``` -------------------------------- ### CallCap Structure and CapType Enum Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/dynamic-call/README.md Defines the `CallCap` structure for authorization and the `CapType` enum to differentiate between individual and package capabilities. ```move public struct CallCap has key, store { id: UID, // IOTA object identifier cap_type: CapType, // Determines identity resolution mechanism } public enum CapType has copy, drop, store { Individual, // Uses UID address as identifier Package(address), // Uses package address as identifier } ``` -------------------------------- ### Marking the Last Child in a Batch Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/sui/contracts/dynamic-call/README.md Shows how to correctly mark the last child in a batch using the `is_last` flag. Failure to mark the last child will prevent the batch from completing. ```move // ✅ CORRECT: Mark last child in batch let child1 = call.create_child(&cap, addr1, params1, false, ctx); let child2 = call.create_child(&cap, addr2, params2, true, ctx); // is_last=true // ❌ INCORRECT: No last child marking let child1 = call.create_child(&cap, addr1, params1, false, ctx); let child2 = call.create_child(&cap, addr2, params2, false, ctx); // Batch never completes ``` -------------------------------- ### Marking the Last Child in a Batch Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/dynamic-call/README.md Shows how to correctly mark the last child in a batch by setting `is_last=true` during its creation. This signals the completion of the batch and is crucial for proper batch management. ```move let child1 = call.create_child(&cap, addr1, params1, false, ctx); let child2 = call.create_child(&cap, addr2, params2, true, ctx); // is_last=true ``` -------------------------------- ### Caller Validation in Call Handling Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/sui/contracts/dynamic-call/README.md Demonstrates how to validate the caller's identity before processing a call. This is a crucial security measure to prevent unauthorized access. ```move // ✅ CORRECT: Validate caller identity before processing public fun handle_call(call: Call, cap: &CallCap) { // Assert that the call came from the expected caller call.assert_caller(@expected_caller_address); let result = process_call_logic(call.param()); call.complete(cap, result); } // ❌ INCORRECT: No caller validation - security risk public fun unsafe_handle_call(call: Call, cap: &CallCap) { // Missing caller validation - any contract can call this if the param is public let result = process_call_logic(call.param()); call.complete(cap, result); } ``` -------------------------------- ### CallStatus Lifecycle State Enumeration Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/sui/contracts/dynamic-call/README.md Enumerates the possible lifecycle states for a call, including Active, Creating, Waiting, and Completed. Each state has specific associated operations. ```move enum CallStatus { Active, Creating, Waiting, Completed } ``` -------------------------------- ### CallStatus Enum for Lifecycle Management Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/dynamic-call/README.md Enumerates the possible lifecycle states for a call, including Active, Creating, Waiting, and Completed. Each state has specific permitted operations. ```move enum CallStatus { Active, // Ready for batch creation or completion Creating, // Constructing child call batch Waiting, // Awaiting child call destruction Completed // Result available, ready for destruction } ``` -------------------------------- ### LayerZero V2 Call Data Structure Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/iota/contracts/dynamic-call/README.md Defines the core `Call` struct used in LayerZero V2 for cross-contract communication. It encapsulates all necessary information for managing a call's lifecycle, parameters, results, and batching. ```move public struct Call { id: address, caller: address, callee: address, one_way: bool, param: Param, mutable_param: bool, result: Option, parent_id: address, batch_nonce: u64, child_batch: vector
, status: CallStatus, } ``` -------------------------------- ### Move Call Interface Source: https://github.com/layerzero-labs/layerzero-v2/blob/main/packages/layerzero-v2/sui/contracts/ptb-builders/ptb-move-call/README.md Defines the structure for a Move function call within the PTB system, including arguments, builder call designation, and result identifiers. ```typescript interface MoveCall { function: string; // Target function identifier args: Argument[]; // Function arguments is_builder_call: boolean; // Call type designation result_ids: (bytes32)[]; // Global IDs for results } enum Argument { ID(bytes32), Object(ObjectID), Pure(bytes), NestedResult(u16, u16) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.