xermicus b238913a7d emit YUL builtins debug line info and fix debug info source file (#358)
This PR fixes and enhances debug info generation:
1. Adds line information for each lowered YUL builtin and the `if`
statement.
2. Fixes the debug info source path to match the YUL file of the
contract dumped to the `--debug-output-dir`.

This improves inspection of the generated code a lot. Excerpt from
`llvm-objdump -Sl /tmp/dbg/contracts_EndpointV2.sol.EndpointV2.so`:

```
; /tmp/dbg/contracts_EndpointV2.sol.EndpointV2.yul:203
;                 let _1 := memoryguard(0x80)
   13c3e: 3aa5b023      sd      a0, 0x3a0(a1)
   13c42: 38a5bc23      sd      a0, 0x398(a1)
   13c46: 38a5b823      sd      a0, 0x390(a1)
   13c4a: 08000513      li      a0, 0x80
   13c4e: 38a5b423      sd      a0, 0x388(a1)
; /tmp/dbg/contracts_EndpointV2.sol.EndpointV2.yul:204
;                 mstore(64, _1)
   13c52: 3885b503      ld      a0, 0x388(a1)
   13c56: 3905b603      ld      a2, 0x390(a1)
   13c5a: 3985b683      ld      a3, 0x398(a1)
   13c5e: 3a05b703      ld      a4, 0x3a0(a1)
   13c62: 38e5b023      sd      a4, 0x380(a1)
   13c66: 36d5bc23      sd      a3, 0x378(a1)
   13c6a: 36c5b823      sd      a2, 0x370(a1)
   13c6e: 36a5b423      sd      a0, 0x368(a1)
   13c72: 04000513      li      a0, 0x40
   13c76: 65d9          lui     a1, 0x16
   13c78: a605859b      addiw   a1, a1, -0x5a0
   13c7c: 95a6          add     a1, a1, s1
   13c7e: 00000097      auipc   ra, 0x0
   13c82: 000080e7      jalr    ra <__runtime+0x1de>

0000000000013c86 <.Lpcrel_hi27>:
; /tmp/dbg/contracts_EndpointV2.sol.EndpointV2.yul:205
;                 if iszero(lt(calldatasize(), 4))
   13c86: 00000517      auipc   a0, 0x0
   13c8a: 00053503      ld      a0, 0x0(a0)
   13c8e: 4108          lw      a0, 0x0(a0)
   13c90: 4591          li      a1, 0x4
   13c92: 06b56263      bltu    a0, a1, 0x13cf6 <.Lpcrel_hi27+0x70>
   13c96: a009          j       0x13c98 <.Lpcrel_hi27+0x12>
```

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-07-04 19:56:52 +02:00
2025-06-28 12:32:48 +02:00
2025-04-30 21:48:11 +02:00
2025-05-08 12:36:11 +02:00
2025-06-28 12:32:48 +02:00
2025-06-28 12:32:48 +02:00
2025-01-13 15:58:27 +01:00
2025-05-09 20:00:58 +02:00
2025-05-08 12:36:11 +02:00
2024-03-12 12:06:02 +01:00
2024-03-12 12:06:02 +01:00
2025-01-16 10:45:43 +01:00
2025-05-27 09:48:43 +02:00
2025-06-28 12:32:48 +02:00
2025-05-27 09:48:43 +02:00
2025-05-28 08:15:41 +02:00
2025-01-13 15:58:27 +01:00

CI Docs

revive

YUL recompiler to LLVM, targetting RISC-V on PolkaVM.

Visit contracts.polkadot.io to learn more about contracts on Polkadot!

Status

This is experimental software in active development and not ready just yet for production usage. Please do report any compiler related issues or missing features that are not yet known to us here.

Discussion around the development is hosted on the Polkadot Forum.

Installation

Building Solidity contracts for PolkaVM requires installing the following two compilers:

resolc binary releases

resolc is distributed as a standalone binary (with solc as the only external dependency). Please download one of our binary releases for your target platform and mind the platform specific instructions below.

MacOS users

MacOS users need to clear the downloaded attribute from the binary and set the executable flag.

xattr -rc resolc-universal-apple-darwin
chmod +x resolc-universal-apple-darwin
Linux users

Linux users need to set the executable flag.

chmod +x resolc-x86_64-unknown-linux-musl

resolc NPM package

We distribute the revive compiler as node.js module and hardhat plugin.

Note: The solc dependency is bundled via NPM packaging and defaults to the latest supported version.

Building from source

Building revive requires a stable Rust installation and a C++ toolchain for building LLVM on your system.

LLVM

revive depends on a custom build of LLVM v18.1.8 with the RISC-V embedded target, including the compiler-rt builtins. You can either download a build from our releases (recommended for older hardware) or build it from source.

Download from our LLVM releases

Download the latest LLVM build from our releases.

MacOS users need to clear the downloaded attribute from all binaries after extracting the archive:

xattr -rc </path/to/the/extracted/archive>/target-llvm/gnu/target-final/bin/*

After extracting the archive, point $LLVM_SYS_181_PREFIX to it:

export LLVM_SYS_181_PREFIX=</path/to/the/extracted/archive>/target-llvm/gnu/target-final
Building from source

Use the provided revive-llvm utility to compile a compatible LLVM build locally and point $LLVM_SYS_181_PREFIX to the installation afterwards.

The Makefile provides a shortcut target to obtain a compatible LLVM build:

make install-llvm
export LLVM_SYS_181_PREFIX=${PWD}/target-llvm/gnu/target-final

The resolc Solidity frontend

To build the resolc Solidity frontend executable, make sure you have obtained a compatible LLVM build and did export the LLVM_SYS_181_PREFIX environment variable pointing to it (see above).

To install the resolc Solidity frontend executable:

make install-bin
resolc --version

Cross-compilation to Wasm

Cross-compile the resolc.js frontend executable to Wasm for running it in a Node.js or browser environment. The REVIVE_LLVM_TARGET_PREFIX environment variable is used to control the target environment LLVM dependency.

Instructions for cross-compilation to wasm32-unknown-emscripten
# Build the host LLVM dependency with PolkaVM target support
make install-llvm
export LLVM_SYS_181_PREFIX=${PWD}/target-llvm/gnu/target-final

# Build the target LLVM dependency with PolkaVM target support
revive-llvm --target-env emscripten clone
source emsdk/emsdk_env.sh
revive-llvm --target-env emscripten build --llvm-projects lld
export REVIVE_LLVM_TARGET_PREFIX=${PWD}/target-llvm/emscripten/target-final

# Build the resolc frontend executable
make install-wasm
make test-wasm

Development

Please consult the Makefile targets to learn how to run tests and benchmarks. Ensure that your branch passes make test locally when submitting a pull request.

Design overview

See the relevant section in our documentation to learn more about how the compiler works.

Tests

Before running the tests, ensure that Geth (Go Ethereum) is installed on your system. Follow the installation guide here: Installing Geth. Once Geth is installed, you can run the tests using the following command:

make test

Acknowledgements

The revive compiler project, after some early experiments with EVM bytecode translations, decided to fork the era-compiler framework. Frontend, code generator and some supporting libraries are based of ZKSync zksolc. I'd like to express my gratitude and thank the original authors for providing a useable code base under a generous license.

S
Description
No description provided
Readme 26 MiB
Languages
Rust 87.9%
Solidity 5.8%
JavaScript 2.3%
Python 0.9%
C 0.9%
Other 2.1%