DTVM_SolSDK is a compiler that translates Solidity's Yul intermediate representation into WebAssembly (Wasm), enabling Ethereum smart contracts to run in Wasm environments.
- Rust 1.83 or newer
- LLVM 16
- Solidity Compiler 0.8.25
- Binaryen (for wasm tools like wasm2wat)
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
# Install LLVM 16
apt update
apt install -y llvm-16 llvm-16-dev
# Install Solidity Compiler
apt-get install software-properties-common
add-apt-repository ppa:ethereum/ethereum
apt-get update
apt-get install solc
# Install Binaryen
apt install -y binaryen# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
# Install LLVM 16
brew install llvm@16
# Install Solidity Compiler
brew tap ethereum/ethereum
brew install solidity
# Install Binaryen
brew install binaryendocker/- Dockerfile and related scripts for building the compilersrc/- Core compiler source codetests/- Compiler test suiteyul2ir/- Yul IR parser and LLVM IR generator
stdlib/- Standard library modules that provide common functionality and utilitieslib- Additional libraries or external dependenciestools- Scripts for various tasks like formattingexamples/- Example Solidity contracts and compilation scriptsdocs/- Project documentation
-
Compilation Pipeline:
- Solidity source → Yul IR (using solc compiler)
- Yul IR → WebAssembly (using yul2wasm)
-
Compilation Stages:
- Parsing Yul IR
- Generating LLVM IR
- Optimizing LLVM IR
- Generating WebAssembly binary
When adding new features to yul2wasm:
-
Understanding Yul IR:
- Familiarize yourself with Solidity's Yul Intermediate Representation syntax and semantics
- Reference: https://docs.soliditylang.org/en/latest/yul.html
-
Making Compiler Changes:
- Modify the parser for new Yul syntax support
- Update LLVM IR generation for new features
- Add appropriate tests to verify the functionality
-
Testing:
- Unit tests:
cargo test - Integration tests: Use example contracts in
examples/directory
- Unit tests:
-
Debug Logging:
- Use the
--verboseflag when running yul2wasm - For advanced debugging, use the
--debugflag to generate additional debug information
- Use the
-
Examining LLVM IR and Assembly:
- Intermediate files are generated during compilation with proper flags
- Check
.llfiles for LLVM IR and.sfiles for assembly output
-
Testing with Example Contracts:
- The
examples/directory contains various smart contracts to test against - Use these as benchmarks for your changes
- The
-
Code Style:
- Follow Rust code conventions
- Run
cargo fmtbefore submitting code - Use
cargo clippyfor linting
-
Pull Request Process:
- Create a new branch for your feature/fix
- Include tests for new functionality
- Update documentation as needed
- Submit a PR with a clear description of changes
-
Documentation:
- Update relevant documentation in the
docs/directory - Include examples for new features
- Comment complex code sections
- Update relevant documentation in the
When optimizing the compiler:
-
LLVM Optimization Levels:
- Default is
-O2for maximum optimization - Consider compilation time vs. performance trade-offs
- Default is
-
Wasm Size Optimization:
- Binaryen's
wasm-optcan further optimize the generated Wasm
- Binaryen's
- Memory Management: WebAssembly has specific memory models; ensure proper memory handling
- Stack Limitations: Watch for stack usage in complex contracts
- ABI Compatibility: Ensure compatibility with Ethereum ABI encoding/decoding