Expand description
Solidity Expression Interpreter
A Rust-based interpreter for Solidity expressions with focus on predicate evaluation. Evaluates boolean expressions, comparisons, and logical operations commonly used in smart contracts.
§Features
- Predicate evaluation: expressions that return boolean values
- Variable context: support for variable bindings and lookups
- Type system: handle Solidity’s basic types (bool, uint, int, string, address, bytes)
- Error handling: comprehensive error reporting for runtime issues
§Supported Operations
- Literals:
true
,false
,42
,"hello"
,hex"deadbeef"
,unicode"hello"
- Binary ops:
+
,-
,*
,/
,%
,**
,==
,!=
,<
,<=
,>
,>=
,&&
,||
,&
,|
,^
,<<
,>>
,>>>
- Unary ops:
+
,-
,!
,~
- Conditional:
condition ? true_expr : false_expr
- Variables: variable lookup with context management
- Built-ins:
keccak256()
,sha256()
,ripemd160()
,ecrecover()
(mock implementations)
§Value Types
Bool(bool)
:true
,false
UInt(u64)
:0
,42
,1000
Int(i64)
:-1
,0
,42
String(String)
:"hello"
,"world"
Address(String)
:"0x1234..."
Bytes(Vec<u8>)
:[0x12, 0x34, ...]
Null
: null/undefined
§Boolean Conversion
All values convert to boolean for predicate evaluation:
Bool(true)
→true
,Bool(false)
→false
UInt(0)
→false
,UInt(n)
→true
Int(0)
→false
,Int(n)
→true
String("")
→false
,String(s)
→true
Address("0x0000...")
→false
, other addresses →true
Bytes([])
→false
, non-empty bytes →true
Null
→false
§Limitations
Intentional limitations for predicate evaluation:
- No assignment operations (predicate evaluation shouldn ’t mutate state)
- No object creation (new expressions not supported)
- No complex types (arrays/mappings/structs limited)
- No member/index access (not yet implemented)
§Architecture
- Parser integration: uses existing Solidity parser to generate AST
- Context management: maintains variable bindings and function definitions
- Type system: runtime type checking and conversion
- Error propagation: comprehensive error handling throughout evaluation
- Extensibility: designed to be easily extended with new operations and types