Commit Graph
332 Commits
Author SHA1 Message Date
xermicus ee869cdd18 Support solc v0.8.35 (#512)
- Support solc v0.8.35
- The new `erc7201` is comptime (already translated to a constant in
Yul)

Didn't spot any relevant breakage or addition in the release notes so
should be no-brainer.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2026-05-01 20:14:36 +02:00
kvpanch 8326aa3aed Update LLVM from 21 to 22 (#505) 2026-04-28 14:28:14 -04:00
xermicus f887e75545 Release resolc v1.1.0 (#504)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2026-04-13 22:06:26 +02:00
xermicus 255f5cc31b Update dependencies (#503)
- Rust dependencies
- JS dependencies
- Retester submodule

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2026-04-13 14:59:24 +02:00
kvpanch b3cd402549 Append optnone and noinline for -O0 optlevel (#502)
This appears to be NFC change as new pass manager handles
--passes=default<O0> correctly. Still must be useful as a safeguard and
possibly for the old pass manager that is still used by backend.

```
Contract                        Without (bytes)   With noinline+optnone (bytes)
─────────────────────────────── ───────────────── ────────────────────────────
contract.sol:C                            1,266                          1,266
Fibonacci:Iterative                       2,506                          2,506
Storage                                   3,671                          3,671
Fibonacci:Recursive                       3,794                          3,794
Computation                               5,776                          5,776
Fibonacci:Binet                           8,786                          8,786
large_div_rem                            10,705                          10,705
DivisionArithmetics                      14,831                          14,831
ERC20                                    32,288                          32,288
ERC20Tester                              34,589                          34,589
```
2026-04-09 22:33:21 -04:00
LJ 41d8593a5a Remove stripping of minsize attribute for functions with 256-bit integer division (#501)
## Description

We previously had a workaround to strip `minsize` attributes for
functions with 256-bit integer division due to a crash in the LLVM
backend. We now [patch](https://github.com/paritytech/revive/pull/500)
LLVM with the fix, allowing us to use `minsize` with correct backend
optimization, making the workaround unnecessary.
2026-04-09 20:54:05 +02:00
LJ 3dc84349d9 Apply LLVM patches for deterministic operand order and correct peephole optimization for minsize (#500)
## Description

Applies LLVM patches that have not been backported to the major version
used in our submodule:

* [LLVM PR #163679](https://github.com/llvm/llvm-project/pull/163679)
  * *"[RISCV] Allow large div peephole optimization for minsize"*
* Fixes peephole optimization of large integers when `minsize` function
attribute is set.
* (Our revive codebase used a workaround that can be removed once this
500 PR is merged and we publish a new LLVM release.)
* [LLVM PR #190219](https://github.com/llvm/llvm-project/pull/190219)
* *"[TargetLowering] Speculative fix for a non-determinism issue between
different compilers"*
* Operand ordering of `mul i256` were different depending on the target
ABI when building LLVM, producing different RISC-V and PVM bytecode for
our Windows vs macOS/linux builds.
* The bytecode divergence (yet functionally equivalent) affected
Solidity contracts containing a value [multiplied by
itself](https://github.com/llvm/llvm-project/issues/190148) (e.g. via
explicit squaring or exponentiation), manifesting primarily when using
optimization level `-O0`.
2026-04-09 17:33:09 +02:00
LJ 8c41f93ace Build LLVM for Windows using MSVC-compatible Clang (#497)
## Description

Switches the Windows LLVM build from Visual Studio to `clang-cl` +
`lld-link` (Clang's MSVC-compatible drivers) with Ninja.

This is in order to better match the Clang toolchain used on our Linux
and macOS variants, while keeping the MSVC ABI.

It also speeds up the build time by at least 2x on Windows.
2026-04-09 07:51:37 +02:00
kvpanchandLJ 61ac247135 Provide unique name from closures with same name (#488)
In YUL it's possible to declare closure with a same name, but in
different scope, which previously resulted to func name conflict during
LLVM IR construction.
To solve this, track YUL scope when building LLVM IR and a special
counter that increments every time function with the same name exists in
LLVM module.
There's still assert if somehow within the same scope there 2 functions
with the same name, which should be forbidden by Yul

Fixes: #474

---------

Co-authored-by: LJ <81748770+elle-j@users.noreply.github.com>
2026-03-10 10:55:42 -04:00
xermicus dc155efc73 runtime-api: remove the spurious +fast-unaligned-access flag (#491)
Slipped through in #120

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2026-03-10 11:27:50 +01:00
kvpanch 5aebcc76ab Disable LLVM warnings and enable LTO in emscripten build (#487)
Fixed #148 and last task of #156
2026-03-04 09:41:38 -05:00
kvpanch 810a36b18b Update EMSDK to 5.0.0 (#479)
Emscripten 4.0.12 introduced breaking change by changing module factory
to always return promise even if `WASM_ASYNC_COMPILATION=0`. To overcome this, build emscripten compiler without MODULARIZE with custom export of `createRevive`.
2026-02-23 15:48:07 -05:00
xermicus 71d584dd6e inhert stderr for recursive process (#485)
Allows for debug logs. The stdout stay piped as its used for
intra-process communication.

Signed-off-by: xermicus <bigcyrill@hotmail.com>
2026-02-22 18:57:20 +01:00
xermicus 073276696f recursive processes use the current executable by default (#484)
- Recursive processes spawn the currently running executable by default,
removing the annoyance of mixing different compiler builds during
contract compilation.
- Remove the unused `once_cell` dependency.

Signed-off-by: xermicus <bigcyrill@hotmail.com>
2026-02-22 18:14:21 +01:00
xermicusandClaude Opus 4.6 c0a7596617 support solc v0.8.34 (#482)
As a drive-by fix, the get-llvm action now ignores LLVM releases marked
as pre-release.

---------

Signed-off-by: xermicus <bigcyrill@hotmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 14:27:03 +01:00
xermicusandminimax-m2.5 d8d998c114 Fix Yul mode discarding solc validation errors (#478)
In `--yul` mode, resolc now properly exits when solc reports validation
errors (e.g., invalid hex literals, variable redeclarations), matching
`--standard-json behavior.`

`runs_without_input_file` was adapted because it was relying on it where
the new behavior correctly matches solc --strict-assembly.

Closes #477

Co-authored-by: minimax-m2.5 <neo@zion>

---------

Signed-off-by: xermicus <bigcyrill@hotmail.com>
2026-02-16 11:03:24 +01:00
0cd949aa66 Update code base to use LLVM 21 (#434)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: LJ <81748770+elle-j@users.noreply.github.com>
Co-authored-by: xermicus <cyrill@parity.io>
2026-02-06 12:23:48 -05:00
xermicus b080c1d86c resolc v1.0.0 (#465)
This marks a milestone: Smart contracts on Polkadot Asset Hub are live
and we release the first compiler version!

Signed-off-by: xermicus <bigcyrill@hotmail.com>
2026-01-29 19:17:08 +01:00
LJandxermicus a4163512ff Improve compilation time in standard JSON mode and honor requested output (#461)
# Description

Compilation times for resolc were significantly slower than solc when:
* Multiple files were included in the JSON input file via
`--standard-json`
* And none of the files requested code generation
* (If only a subset of files requested code generation, both resolc and
solc were very slow)

Reason:
* Resolc unconditionally generated bytecode for all contracts, even if
not requested.
* When compiling to PolkaVM bytecode, we need to pass additional flags
(e.g. `irOptimized`) to solc. If these flags were not explicitly
requested, resolc also added these to the requested output since PolkaVM
bytecode was always generated.

## Breaking Changes

The following changes are breaking, but fix the semantics to match its
intended behavior:

* Compiling with `--standard-json` now compiles to PolkaVM bytecode
***only*** for the contracts explicitly requested in the
`outputSelection`.
* Compiling with `--standard-json` now outputs ***only*** the explicitly
requested output (e.g. `evm.assembly`, `evm.bytecode`, `ast`, etc.).

```jsonc
// Example:
{
  "settings": {
    // ...
    "outputSelection": {
      "src/common/GasService.sol": {
        // Contracts in this file will generate bytecode.
        // Only these fields of the JSON output selection will be in the `contracts` output.
        "*": ["abi", "evm.methodIdentifiers", "metadata", "evm.bytecode"],
        // Only this field of the JSON output selection will be in the `sources` output.
        "": ["ast"]
      },
      "src/common/Gateway.sol": {
        // No contracts in this file will generate bytecode.
        "*": ["abi", "evm.methodIdentifiers", "metadata"],
        // No `ast` will be in the `sources` output (only the automatically added `id`,
        // similar to solc as this is not a configurable output selection).
        "": []
      },
    }
  }
}
```

## Performance Improvements

When e.g. the standard JSON input file includes multiple files and
requests output for every contract as per this setting:

```jsonc
{
  "settings": {
    // ...
    "optimizer": { "enabled": true, "runs": 1 },
    "viaIR": true,
    "outputSelection": {
      "src/common/GasService.sol": {
        "*": ["abi", "evm.methodIdentifiers", "metadata", "evm.bytecode"],
      },
      // Rest of files..
    }
  }
}
```

The differences in compilation times depending on whether `evm.bytecode`
is selected in every file, one file, or no files can be seen below:

| Solc Optimizer (runs=1) | ViaIR | Request `abi`,
`evm.methodIdentifiers`, `metadata` | Request `evm.bytecode` | resolc
before | resolc after | solc v0.8.33 |

|:-----------------------:|:-----:|:---------:|:---------:|:-------------:|:------------:|:----------:|
| ✅ | ✅ | All files | All files | `~14.5s` | `~14.5s` | `~13.5s` |
| ✅ | ✅ | All files | One file | `~14.5s` | `~450ms` | `~13.5s` |
| ✅ | ✅ | All files | No files | `~14.5s` | `~390ms` | `~350ms` |

**Observations:**

* `resolc before` is roughly the same no matter the request
  * This is due to unconditionally generating bytecode
* When not requesting bytecode for any contracts:
  * `resolc after` now compiles in ~390ms (vs ~14.5s), similar to `solc`
* Neither `solc` nor `resolc after` generates bytecode when none of the
contracts request it
* When requesting bytecode for all contracts in _only one_ file:
  * `resolc after` now compiles in ~450ms (vs ~14.5s)
* `solc` still compiles in the same time as when requesting bytecode for
all contracts in all files
* This is something they have tried to improve (see
[Solidity#15373](https://github.com/argotorg/solidity/issues/15373) and
[Solidity#15615](https://github.com/argotorg/solidity/issues/15615)),
and the intended behavior seems to now be that bytecode should only be
generated when explicitly requested for each contract.
* Even though PRs have merged to try to fix it, their issue seems to
persist as of v0.8.33.

# Open Questions

* Foundry:
  * [x] Pruning of the AST:
* Just saw [this past
commit](https://github.com/paritytech/revive/pull/385) to not prune the
AST for Foundry compatibility.
    * Can Foundry not explicitly request `"": "ast"`?
    * **Answer:**
* Pruning the AST when not requested should be fine, as long as Foundry
explicitly requests it when needed.
      * Will be tested by Foundry maintainer.

# Review Notes

Changes in `docs/` (~25 files) can be skipped as they are automatically
updated after adding content to `book/` and rebuilding it.

# Resolved Issues

Closes #326

---------

Co-authored-by: xermicus <cyrill@parity.io>
2026-01-28 23:04:22 +01:00
xermicus 95ae938ddf Add missing 63/64 rule documentation and a test (#462)
- Prominently point out the important differences of the `pallet-revive`
runtime.
- Add a test case illustrating the problem.

See also: https://github.com/paritytech/contract-issues/issues/257

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2026-01-27 19:43:14 +01:00
LJ c601377c2d Add integration test for deleting struct (#459)
Differentially tests the behavior of deleting a struct with a member
that do not occupy the full 32-byte slot. From [this
issue](https://github.com/paritytech/contract-issues/issues/118) it was
unclear whether the `delete` was expected to reset only the bytes
occupied or the entire slot. The current behavior of resetting the
entire slot is expected.
2026-01-20 14:34:27 +01:00
xermicus 50e4d47bc6 update Rust dependencies (#456)
Signed-off-by: xermicus <cyrill@parity.io>
2026-01-15 13:55:14 +01:00
xermicus 289af875db remove superfluous byte swap in linkersymbol builtin translation (#455)
- Remove the superfluous byte swap in the `linkersymbol` builtin
translation.
- Support testing the `linkersymbol` builtin translation in the runner
specs.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2026-01-15 12:43:46 +01:00
LJ f5fe3faa71 Add default values to compiler arguments (#451)
## Description

Adds default values to the compiler arguments below when parsed by
`clap`. This does not change previous user-facing behavior as these
defaults were implemented using different logic, but improves the UX and
the visibility of the exact defaults used.

**Example output from `resolc --help`:**
(Only affected arguments are shown here, and some of their descriptions
have been omitted here.)
```
Options:

  -O, --optimization <OPTIMIZATION>
          Set the optimization parameter -O[0 | 1 | 2 | 3 | s | z]. Use `3` for best performance and `z` for minimal size
          
          [default: z]

      --metadata-hash <METADATA_HASH>
          Set the metadata hash type. Available types: `none`, `ipfs`, `keccak256`
          
          [default: keccak256]

      --heap-size <HEAP_SIZE>
          The emulated EVM linear heap memory static buffer size in bytes.
          ...
          
          [default: 131072]

      --stack-size <STACK_SIZE>
          The contracts total stack size in bytes.
          ...
          
          [default: 131072]
```

## Resolved Issues

Closes #446
2026-01-14 19:22:03 +01:00
xermicus 285065632e remove the revive-explorer (#450)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2026-01-13 10:43:25 +01:00
xermicus a1a4f8e6ea Clip OOB values in call data load and copy (#448)
The OOB logic is implemented in the runtime but truncation circumvented
it.

Closes #263

---------

Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2026-01-13 10:15:31 +01:00
xermicus 81ce306735 release v0.6.0 (#445)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2026-01-08 11:45:11 +01:00
kvpanchandxermicus 540ec03cd7 Added 2 options to control expected result to revive-runner (#438)
Added 2 options to control expected result to `revive-runner`:
```
      --verify-failure <VERIFY_FAILURE>
          The expected call result of the contract execution

          Possible values:
          - instantiate: The contract instantiation must fail
          - call:        The contract execution must fail

      --verify-call-gas-consumed <VERIFY_CALL_GAS_CONSUMED>
          The expected amount of consumed gas by the contract execution
```

---------

Co-authored-by: xermicus <bigcyrill@hotmail.com>
2026-01-07 21:36:33 -05:00
Marian Radu 4c85a3113d Set the default PolkaVM stack and heap size values to 128KB. (#441)
Fixes https://github.com/paritytech/contract-issues/issues/149

A few test cases from v2-periphery-polkadot are hitting the PVM stack
limit when the contracts are compiled using resolc version 0.5.0. The
same tests pass if the contracts are compiled with a resolc version that
includes commit:
https://github.com/paritytech/revive/commit/878ca91689b99220f7ffd40df760613b7314de86.

After a brief discussion with @xermicus, we propose to set the default
PolkaVM stack and heap size values to 128KB, since we have already
encountered tests that hit the stack size limit and, without real world
data, it is difficult to determine the optimal values.
2026-01-07 14:27:17 +01:00
xermicus d8c23130bb revive-runner: enable PVM logs (#442)
This PR fixes a small oversight from #431: Set the debug config of the
revive-runner `Runtime` such that we get the PVM logs back. Since the
revive runner runtime is mainly meant for debugging, I further decided
to enable unlimited contract sizes and disable [EIP
3607](https://eips.ethereum.org/EIPS/eip-3607) too.

---------

Signed-off-by: xermicus <cyrill@parity.io>
2026-01-06 18:31:45 +01:00
xermicus 13070a4bdf Ensure correct flags are passed to solc in std json mode (#440)
This tests the marketplace contracts to compile fine. In prior versions
this fails to compile, hitting the solc "Stack too deep" error.

Closes #409

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2026-01-06 11:16:59 +01:00
xermicus cfcd2ff77c Support solc v0.8.33 (#439)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2026-01-05 10:59:45 +01:00
xermicus be6f734cfc Use the EVM call gas syscall variants (#436)
- Emit the `call_evm` and `delegate_call_evm` syscalls for contract
calls.
- The call gas is no longer ignored.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-12-18 17:01:24 +01:00
xermicus 25ee4eef5a dedicated safe integer truncation integration test (#435)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-12-17 10:25:41 +01:00
xermicus 9446132608 Emit consume_all_gas in invalid and bounds checks (#433)
Closes #374

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-12-16 10:04:51 +01:00
xermicus e568a924ae update to polkadot-sdk unstable2507 (#431)
Support for `polkadot-sdk` release `unstable2507`. This release will be
deployed to Kusama and is supposed the first one on Polkadot.

---------

Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-12-15 14:02:48 +01:00
xermicus 11f82c8488 Support solc v0.8.31 (#430)
- Support for solc v0.8.31.
- Support for the `clz` Yul builtin.

---------

Signed-off-by: xermicus <cyrill@parity.io>
2025-12-05 15:25:13 +01:00
xermicus 45ceab7dc7 Additional bounds check in sbrk (#428)
Close #356

Signed-off-by: xermicus <cyrill@parity.io>
2025-12-03 16:00:19 +01:00
LJandxermicus 0742227c5a Implement Yul to LLVM IR compilation benchmarks (#407)
# Description

Closes [#404](https://github.com/paritytech/revive/issues/404)

Adds compilation time benchmarks for:

* Parsing of Yul source code -> AST Object
* Lowering of AST Object -> LLVM IR (unoptimized)

The benchmarks can be run from the root via:

```sh
# Run all benchmarks in the revive-yul crate (parsing + lowering)
make bench-yul
```

HTML reports will be generated under `target/criterion`, and a summary
of the results at
[crates/yul/BENCHMARKS_PARSE_M4PRO.md](https://github.com/paritytech/revive/blob/lj/compilation-benchmarks-yul/crates/yul/BENCHMARKS_PARSE_M4PRO.md)
and
[crates/yul/BENCHMARKS_LOWER_M4PRO.md](https://github.com/paritytech/revive/blob/lj/compilation-benchmarks-yul/crates/yul/BENCHMARKS_LOWER_M4PRO.md)
(currently from running on a Mac M4 Pro).

---------

Co-authored-by: xermicus <cyrill@parity.io>
2025-11-25 12:00:06 +01:00
xermicus d97d094a8a Update the Rust dependencies (#420)
The `Cargo.lock` kept changing locally on all my hosts. Not sure why
exactly - maybe it got forgotten in a recent PR. I took it as an
opportunity to quickly update the Rust dependencies.

---------

Signed-off-by: xermicus <bigcyrill@hotmail.com>
2025-11-21 15:34:21 +01:00
LJ ad61b6e3c9 Implement resolc end-to-end compilation benchmarks (#406)
# Description

Closes [#403](https://github.com/paritytech/revive/issues/403)

Adds compilation time benchmarks for resolc end-to-end.

The benchmarks can be run from the root via:

```sh
make bench-resolc
```

HTML reports will be generated under `target/criterion`, and a summary
of the results at
[crates/resolc/BENCHMARKS_M4PRO.md](https://github.com/paritytech/revive/blob/lj/compilation-benchmarks/crates/resolc/BENCHMARKS_M4PRO.md)
(currently from running on a Mac M4 Pro).
2025-11-19 12:16:07 +01:00
kvpanch e78f3cc419 add LLVM 18.x as a git submodule (#399)
This changeset is based on https://github.com/paritytech/revive/pull/346
2025-11-18 16:10:15 -05:00
xermicus a1090cfa5a revive-yul: fix the code block exit (#414)
This PR fixes the missing `STOP` instruction at the end of `code`
blocks.

---------

Signed-off-by: xermicus <bigcyrill@hotmail.com>
2025-11-17 18:47:58 +01:00
xermicus dd48baadc7 resolc: fix the Yul test utils (#413)
- Fixes multiple bugs in the Yul test util helpers.
- The simple Yul builder utility helper now returns the contract builds.

Signed-off-by: xermicus <bigcyrill@hotmail.com>
2025-11-17 17:45:03 +01:00
xermicus 79aaca1a85 std json: do not request EVM bytecode (#410)
These compiler outputs are irrelevant for the `resolc` compilation
pipeline. It can also break the compilation pipeline. For example, solc
may reject the code without via-ir or fail during the EVM codegen phase
with stack too deep errors - which is not relevant to us.

---------

Signed-off-by: xermicus <cyrill@parity.io>
2025-11-13 10:32:32 +01:00
xermicus 878ca91689 RISCV relaxations (#408)
This PR enables RISC-V relaxations and changes to internal linkage for internal function and global symbols.

See also:
https://github.com/llvm/llvm-project/issues/167381#issuecomment-3513830043

Signed-off-by: xermicus <cyrill@parity.io>
2025-11-11 17:27:53 +01:00
xermicus 046455db06 release v0.5.0 (#401)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-11-03 16:10:20 +01:00
xermicus 70037e1136 initial SELFDESTRUCT support (#400)
Note:
- The unstable interface in `v2509.0.0` of `polkadot-sdk` is required.
- The differential test fails against EVM in `v2509.0.0` of
`polkadot-sdk`.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-11-03 15:04:04 +01:00
xermicus c0cdde5a5a llvm-context: fix off-by-one in SDIV overflow semantics (#398)
- Fix the wrong predicate (the negative side in 2s complement has one
more bit)
- Increase test coverage

Signed-off-by: xermicus <cyrill@parity.io>
2025-10-31 14:07:01 +01:00
xermicus df1921ba93 runtime-api: sync syscall function signatures with pallet (#397)
This PR synchronizes the syscall function signatures in the runtime-api
with the current revive pallet API surface.

Signed-off-by: xermicus <cyrill@parity.io>
2025-10-30 14:43:55 +01:00