Huff-AST
Huff-AST is an Abstract Syntax Tree (AST) implementation for Huff, crafted in Rust to facilitate seamless conversion between Solidity and Huff. This project was born out of a compelling idea during the last Huff hackathon: a development tool capable of converting Solidity to Huff and vice versa. Faced with the challenge of choosing a feasible implementation method within a limited time frame, several approaches were considered.
Implementation Approaches
-
Bytecode Reverse Engineering:
- Initially contemplating bytecode extraction and reverse engineering, it was quickly dismissed due to the complexity and unreliability of converting bytecode to Solidity. The potential for inaccuracies and the considerable development time required led to the exploration of a more reliable solution.
-
AST-Based Conversion:
- Recognizing that both Huff and Solidity are Ethereum Virtual Machine (EVM)-compatible languages, the decision was made to generate ASTs for both and abstract away the language-specific details. The conversion process involves:
- AST Generation: Parsing the source code of the input language (e.g., Solidity) to generate its AST.
- IR Generation: Converting the AST into an intermediate representation that abstracts away language-specific details.
- Language-Specific Transformation: Applying algorithms and rules to the IR to handle differences between the source and target languages.
- Transformed IR: Producing a transformed IR that captures the essence of the program in the target language.
- Code Generation: Finally, generating code in the target language using the transformed IR.
The challenge arose during the time-constrained Huff hackathon, prompting the decision to open a private repository for future development, leaving the door open for a more comprehensive exploration.