fuel_vm/
lib.rs

1//! FuelVM implementation
2
3#![cfg_attr(not(feature = "std"), no_std)]
4#![warn(missing_docs)]
5#![deny(unsafe_code)]
6#![deny(unused_must_use)]
7#![deny(unused_crate_dependencies)]
8#![deny(
9    clippy::arithmetic_side_effects,
10    clippy::cast_sign_loss,
11    clippy::cast_possible_truncation,
12    clippy::cast_possible_wrap,
13    clippy::string_slice
14)]
15
16#[doc(hidden)] // Needed by some of the exported macros
17pub extern crate alloc;
18
19extern crate core;
20#[cfg(feature = "std")]
21extern crate libm as _; // Not needed with stdlib
22
23#[cfg(test)]
24use criterion as _;
25
26pub mod backtrace;
27pub mod call;
28pub mod checked_transaction;
29pub mod constraints;
30pub mod consts;
31pub mod context;
32mod convert;
33pub mod crypto;
34pub mod error;
35pub mod interpreter;
36#[cfg(feature = "test-helpers")]
37pub mod memory_client;
38pub mod pool;
39pub mod predicate;
40pub mod state;
41pub mod storage;
42pub mod transactor;
43pub mod util;
44
45#[cfg(feature = "profile-any")]
46pub mod profiler;
47
48#[cfg(test)]
49mod tests;
50
51#[cfg(not(feature = "profile-any"))]
52/// Placeholder
53pub mod profiler {
54    use crate::constraints::InstructionLocation;
55
56    /// Placeholder profiler.
57    #[derive(Default, Debug, Clone)]
58    pub struct Profiler;
59
60    impl Profiler {
61        /// Set the current coverage location.
62        pub fn set_coverage(&mut self, _location: InstructionLocation) {}
63
64        /// Add gas to the current coverage location.
65        pub fn add_gas(&mut self, _location: InstructionLocation, _gas_use: u64) {}
66    }
67}
68
69// Fully re-export fuel dependencies
70#[doc(no_inline)]
71pub use fuel_asm;
72#[doc(no_inline)]
73#[cfg(feature = "da-compression")]
74pub use fuel_compression;
75#[doc(no_inline)]
76pub use fuel_crypto;
77#[doc(no_inline)]
78pub use fuel_merkle;
79#[doc(no_inline)]
80pub use fuel_storage;
81#[doc(no_inline)]
82pub use fuel_tx;
83#[doc(no_inline)]
84pub use fuel_types;
85
86pub mod prelude {
87    //! Required implementations for full functionality
88    #[doc(no_inline)]
89    pub use fuel_asm::{
90        GMArgs,
91        GTFArgs,
92        Instruction,
93        Opcode,
94        PanicReason,
95        RegId,
96    };
97    #[doc(no_inline)]
98    pub use fuel_crypto::{
99        Hasher,
100        Message,
101        PublicKey,
102        SecretKey,
103        Signature,
104    };
105    #[doc(no_inline)]
106    pub use fuel_storage::{
107        MerkleRoot,
108        MerkleRootStorage,
109        StorageAsMut,
110        StorageAsRef,
111        StorageInspect,
112        StorageMutate,
113    };
114    #[doc(no_inline)]
115    pub use fuel_tx::*;
116    #[doc(no_inline)]
117    pub use fuel_types::{
118        Address,
119        AssetId,
120        BlobId,
121        Bytes32,
122        Bytes4,
123        Bytes64,
124        Bytes8,
125        ContractId,
126        Immediate06,
127        Immediate12,
128        Immediate18,
129        Immediate24,
130        RegisterId,
131        Salt,
132        Word,
133    };
134
135    pub use crate::{
136        backtrace::Backtrace,
137        call::{
138            Call,
139            CallFrame,
140        },
141        context::Context,
142        error::{
143            Bug,
144            BugVariant,
145            InterpreterError,
146            RuntimeError,
147        },
148        interpreter::{
149            predicates,
150            ExecutableTransaction,
151            Interpreter,
152            Memory,
153            MemoryInstance,
154            MemoryRange,
155        },
156        pool::VmMemoryPool,
157        predicate::RuntimePredicate,
158        state::{
159            Debugger,
160            ProgramState,
161            StateTransition,
162            StateTransitionRef,
163        },
164        storage::{
165            predicate::PredicateStorage,
166            InterpreterStorage,
167        },
168        transactor::Transactor,
169    };
170
171    pub use crate::state::{
172        Breakpoint,
173        DebugEval,
174    };
175
176    #[cfg(any(test, feature = "test-helpers"))]
177    pub use crate::{
178        checked_transaction::{
179            builder::TransactionBuilderExt,
180            IntoChecked,
181        },
182        memory_client::MemoryClient,
183        storage::MemoryStorage,
184        util::test_helpers::TestBuilder,
185    };
186
187    #[cfg(all(
188        feature = "profile-gas",
189        feature = "std",
190        any(test, feature = "test-helpers")
191    ))]
192    pub use crate::util::gas_profiling::GasProfiler;
193
194    pub use crate::profiler::Profiler;
195    #[cfg(feature = "profile-any")]
196    pub use crate::profiler::{
197        CoverageProfilingData,
198        GasProfilingData,
199        InstructionLocation,
200        PerLocationIter,
201        PerLocationKeys,
202        PerLocationValues,
203        ProfileReceiver,
204        ProfilingData,
205        StderrReceiver,
206    };
207}