Simplification of Mixed Boolean-Arithmetic (MBA) expressions.
MBA expressions interleave bitwise operators (&, |, ^, ~) with
arithmetic ones (+, -, *) to obscure an otherwise simple value. They
are a common code-obfuscation primitive; rumba-core recovers the
underlying expression.
Overview
- [
expr::Expr] is the expression tree. Build one directly with the standard operators (+,-,*,&,|,^,!) over [expr::Expr::Var] and constants, or enable theparsefeature to read one from a string with [parser::parse_expr]. - [
simplify::simplify_mba] reduces an expression on a given bit width. Pass a [simplify::SimplifyCache] via [simplify::simplify_mba_cached] to reuse linear solves across many calls.
Simplification is best-effort: it returns a [simplify::SolveError] or
leaves the input untouched rather than aborting the process.
Example
use ;
use simplify_mba;
let x = Var;
let y = Var;
// (x ^ y) + 2*(x & y) is an MBA encoding of x + y.
let mba = + 2u64 * ;
let simplified = simplify_mba.expect;
// The result is semantically equal to x + y.
assert!;
Features
parse— string parsing of expressions via [parser].jit— JIT-compiled evaluation for faster semantic checks.
The solver's contract is best-effort: it must degrade to a SolveError (or
leave the input alone) rather than abort the process. Forbid silent unwrap()
and panic! in library code so every fallible spot is either handled or an
explicit, message-carrying expect(). Tests may still unwrap freely.