Skip to main content

thalir_core/
lib.rs

1/*! Core IR types and builders for smart contract analysis.
2 *
3 * Auditing requires a structured representation where security-critical operations are explicit.
4 * This crate provides the building blocks to construct and manipulate IR that preserves Solidity's
5 * semantics while exposing the patterns auditors care about.
6 */
7
8pub mod analysis;
9pub mod block;
10pub mod builder;
11pub mod codegen;
12pub mod contract;
13pub mod cursor;
14pub mod extensions;
15pub mod format;
16pub mod function;
17pub mod inst_builder;
18pub mod instructions;
19pub mod ir_persist;
20pub mod metadata;
21pub mod obfuscation;
22pub mod source_location;
23pub mod types;
24pub mod values;
25
26pub use block::{BasicBlock, BlockId, BlockParam, Terminator};
27pub use builder::{ContractBuilder, FunctionBuilder};
28pub use contract::{Contract, ContractMetadata, StorageLayout};
29pub use function::{Function, FunctionBody, FunctionSignature, Mutability, Visibility};
30pub use instructions::Instruction;
31pub use metadata::{OptimizationHints, SecurityMetadata};
32pub use obfuscation::{
33    ObfuscationConfig, ObfuscationLevel, ObfuscationMapping, ObfuscationPass, VulnerabilityMapper,
34};
35pub use source_location::SourceFiles;
36pub use types::{Type, TypeRegistry};
37pub use values::{Constant, Location, SourceLocation, Value};
38
39use thiserror::Error;
40
41#[derive(Error, Debug)]
42pub enum IrError {
43    #[error("Type error: {0}")]
44    TypeError(String),
45    #[error("Invalid instruction: {0}")]
46    InvalidInstruction(String),
47    #[error("Builder error: {0}")]
48    BuilderError(String),
49    #[error("Contract not found: {0}")]
50    ContractNotFound(String),
51    #[error("Transform error: {0}")]
52    TransformError(String),
53    #[error("Cranelift error: {0}")]
54    CraneliftError(String),
55}
56
57pub type Result<T> = std::result::Result<T, IrError>;
58
59#[cfg(test)]
60mod tests;