How to Use the Fuel Execution Environment

Feb 10, 2024 | Blockchain

The Fuel execution environment is a powerful toolkit designed to implement the FuelVM specification utilized by various projects, including fuel-core and the Sway compiler. This blog will guide you through the essentials of setting up and utilizing the different crates available to help effectively harness this environment.

Understanding the Crates

The Fuel execution environment consists of several crates that play distinct roles, similar to a team of specialists working together on a project:

  • fuel-asm: This crate contains the instruction set of FuelVM, like a reference sheet of commands you can operate within the VM.
  • fuel-compression: Think of this as your efficient filing cabinet, compressing different transaction types for reduced storage.
  • fuel-crypto: These are the security guards of your data, featuring cryptographic primitives necessary for secure operations in Fuel Rust projects.
  • fuel-merkle: A systematic breadcrumb trail, allowing you to trace transactions back through the layers of proof requirements.
  • fuel-storage: This crate serves as the communication channel, linking multiple components without direct access to each other.
  • fuel-tx: The blueprint and validator for transactions, handling definitions, serialization, and ensuring everything adheres to specifications.
  • fuel-types: The building blocks here, defining common atomic types used across most crates.
  • fuel-vm: The engine driving everything; it executes the operation codes generated by the Sway compiler.

Testing Your Setup

To ensure everything is functioning as intended, you can run the Continuous Integration (CI) checks using the ci_checks.sh script found in the repository. This script requires pre-installed tools and can be executed with:

shell
source ci_checks.sh

If you encounter any issues and need troubleshooting assistance, make sure to check your tool installations, as missing tools can often be the culprit.

Reporting Bugs

If you discover any unexpected behavior or bugs, please open an issue including:

  • A description of the problem (including useful links)
  • A runnable script with detailed instructions
  • A repository containing the reproduction code
  • A unit test utilizing the pure opcodes from fuel-asm

How to Use Pure Opcodes

The fuel-vm crate includes numerous unit tests for each opcode, ensuring that everything functions correctly. Utilizing test helpers can significantly streamline the process of reproducing bugs and verifying expected behaviors:

rust
#[test_case(JumpMode::Absolute, 0, 0, 100 = Ok(4); absolute jump)]

Here, you can create a new test case whenever you find unexpected behavior associated with an opcode.

Building Custom Scripts and Transactions

If you want to run your custom scripts, you can use the test_helpers::run_script function:

rust
#[test]
fn dynamic_call_frame_ops_bug_missing_ssp_check() {
    let ops = vec![
        op::cfs(RegId::SP),
        op::slli(0x10, RegId::ONE, 26),
        op::aloc(0x10),
        op::sw(RegId::ZERO, 0x10, 0),
        op::ret(RegId::ONE),
    ];
    let receipts = run_script(ops);
    assert_panics(receipts, PanicReason::MemoryOverflow);
}

This code snippet sets up a test to check if the script panics correctly upon a specific operation!

Troubleshooting

If you run into any issues while utilizing the Fuel execution environment, consider these troubleshooting tips:

  • Verify that all dependencies are installed as required by the scripts.
  • Ensure that your code adheres to the specifications defined by the FuelVM.
  • If a bug arises, refer to the unit tests available for guidance on how to reproduce it, or ask for help in communities dedicated to this repository.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox