Files
revive/CHANGELOG.md
T
LJ 32763fedf2 Fix Windows bytecode divergence during LLVM LSR (#570)
## Description

Our differential bytecode comparison tests detected a bytecode mismatch
between the Linux/macOS builds and the Windows build for a
[contract](https://github.com/paritytech/resolc-compiler-tests/blob/4647018d64eab6ccff30d22c753f02b90e9fc7e3/fixtures/solidity/simple/internal_function_pointers/sort/bubble.sol)
implementing recursive bubble sort, specifically with these opt
settings:
* Solc optimizer disabled
* Newyork enabled
* `-Oz`

This PR applies an [LLVM
patch](https://github.com/llvm/llvm-project/pull/190587) which fixes the
divergence for contracts with loops that index array elements at
constant offsets from a Solidity `uint8` loop variable, observed with
the above opt settings.

## Cause

The first divergence occurs in an LLVM Loop Strength Reduction (LSR)
decision, on `bubbleSort`'s loop (`for (uint8 i = 0; i < ARRAY_SIZE -
start - 1; i++)` with `array[i]`/`array[i+1]` accesses):

```diff
-  %lsr.iv = phi i32 [ 0, %for_cond.preheader153 ], [ %lsr.iv.next, %if_join64 ]   ; Linux/macOS
+  %lsr.iv = phi i32 [ 1, %for_cond.preheader153 ], [ %lsr.iv.next, %if_join64 ]   ; Windows
+  %3 = add i32 %lsr.iv, -1                                                        ; Windows
 ...
-  %3 = add i32 %lsr.iv, 1                                                         ; Linux/macOS
 ...
   %lsr.iv.next = add nuw nsw i32 %lsr.iv, 1   ; identical on both platforms: step is +1 either way
```

In LLVM's `{Start,+,Step}` recurrence notation (value starts at `Start`,
changes by `Step` per loop iteration), the three constants in the diff
represent: recurrence *start*, use-site *offset*, and recurrence *step*.
Only the first two differ between the platforms:

**Linux/macOS** (the `array[i]` calls take `%lsr.iv` directly; the
`array[i+1]` calls take `%3`):

| Line | Constant | Role |
|---|---|---|
| `%lsr.iv = phi i32 [ 0, … ]` | `0` | **Start**: the register's value
on loop entry (`i`) (holds 0, 1, 2, …) |
| `%3 = add i32 %lsr.iv, 1` | `+1` | **Use-site offset**: derives the
*other* index (`i + 1`) from the register each iteration. (No register
is dedicated to `%3`) |
| `%lsr.iv.next = add … , 1` | `+1` | **Step**: how much the register
advances each iteration |

**Windows** (mirrored: the `array[i+1]` calls take `%lsr.iv` directly;
the `array[i]` calls take `%3`):

| Line | Constant | Role |
|---|---|---|
| `%lsr.iv = phi i32 [ 1, … ]` | `1` | **Start**: the register's value
on loop entry (`i + 1`) (holds 1, 2, 3, …) |
| `%3 = add i32 %lsr.iv, -1` | `-1` | **Use-site offset**: derives the
*other* index (`i`) from the register each iteration. (No register is
dedicated to `%3`) |
| `%lsr.iv.next = add … , 1` | `+1` | **Step**: identical |

The two solutions are mirror images with exactly equal cost, because
`getSetupCost()` (the patched function) rated *any* constant induction
variable (IV) start equally (a 0-start and a 1-start IV cost the same).
LSR keeps the first solution it enumerates, and the enumeration order
derives from walking SSA use-lists, whose in-memory order differed
between our Linux/macOS and Windows builds of LLVM.

Thus both platforms compute the indices `i` and `i + 1` each iteration
(functionally identical), but the LSR decision of which of the two
recurrences becomes the loop-carried value (the phi) differs, which
affects register allocation.

> [!NOTE]
> The equal cost tie can only arise if LSR processes the loop at all,
and LSR only forms uses for induction variables of a 32-bit or 64-bit
integer in our case.

## Partial solution

The [upstream fix](https://github.com/llvm/llvm-project/pull/190587)
updates `getSetupCost()` to return `0` for constant IV starts whose
materialization is `TCC_Free` (which immediate `0` on RISC-V is), which
is now cheaper than non-zero starts, resulting in the same LSR decision
(no tie to decide on) on Windows as well.

As zero-start IVs are most common, this fix addresses the most common
scenarios, but it is still only a partial fix as it specifically solves
only the zero-start case. (I'm currently writing up another issue
regarding this.)

## Verification

I created a draft LLVM release that was built with the patch applied,
then reran all workflows using the draft release, including temporarily
testing more opt settings for the bytecode comparisons which ran
successfully (no mismatches) with the following `retester` modes (see
[this
run](https://github.com/paritytech/revive/actions/runs/28970814016/job/85982029937)):
* `NY M0 S+`
* `NY M0 S-`
* `NY M3 S+`
* `NY M3 S-`
* `NY Mz S+`
* `NY Mz S-`
* `Y M0 S+`
* `Y M0 S-`
* `Y M3 S+`
* `Y M3 S-`
* `Y Mz S+`
* `Y Mz S-`

All E2E tests also ran as it does today (allowing all Yul and newyork IR
`retester` modes), completing successfully.
2026-07-09 13:17:28 +02:00

17 KiB

Changelog

Unreleased

Supported polkadot-sdk rev: 2604.2.0

Fixed

  • Restored the top-level revive_version field in --standard-json output and the resolc_version field in --combined-json output, both of which stopped being populated in v0.4.0. #557
  • ICE triggered by --disable-solc-optimizer --newyork where inlined loops could emit an unterminated basic block in the inlined entrypoint. #561
  • --newyork: dead-store elimination could drop a store whose memory expansion an intervening msize() observes, so msize() read a stale (unexpanded) value. #565
  • --newyork: dead-store elimination could drop a store that a later overlapping unaligned mload reads, returning zeroed memory instead of the stored bytes. #563
  • --newyork: an unaligned full-word mload/mstore overlapping a word kept native (little-endian) by the heap optimization returned byte-swapped bytes. #562
  • --newyork: a calldatacopy/codecopy/returndatacopy to a dynamic destination that could overwrite the free-memory-pointer word truncated a subsequent mload(0x40) to 0. #564
  • --newyork: a full-width value stored to the free-memory-pointer slot (e.g. a function parameter >= 2^64) was narrowed to 64 bits, inserting a checked truncation that consumed all gas. #567
  • --newyork: an unaligned mstore corrupting the free-memory-pointer word let a later store through the corrupted pointer silently succeed where EVM runs out of gas. #566
  • Fixed a bytecode divergence (yet functionally equivalent) between the resolc Linux/macOS builds and the Windows build for contracts with loops indexing array elements at constant offsets from a uint8 loop variable (e.g. array[i]/array[i + 1]), compiled with --newyork at -Oz with the solc optimizer disabled. #570

v1.3.0

Supported polkadot-sdk rev: 2604.2.0

Added

  • The newyork IR code size optimization pipeline, selectable via the --newyork CLI flag or the settings.polkavm.newyork standard JSON input field. This can reduce code size by up to 50%. Considered a new and experimental feature, switched off by default. #519

Changed

  • The latest supported polkadot-sdk version is now 2604.2.0

v1.2.0

Supported polkadot-sdk rev: 2603

Changed

  • Updated LLVM from 21.1.8 to LLVM 22.1.4

Added

  • Support for solc v0.8.35.

Fixed

  • A constant folding bug causing incorrect translation of a signed remainder edge case. The affected pattern (Solidity % or Yul smod):
    • SREM over the two constant operands type(int256).min and -1.
    • At least one of the two constants needs folding (i.e. not just type(int256).min % -1), and is written specifically such that solc doesn't fold but LLVM does, resulting in UB (signed-overflow).
  • Fix mulmod returning out-of-range result for large moduli.

v1.1.0

Supported polkadot-sdk rev: 2603

Added

  • Support for solc v0.8.34.
  • Inherit STDERR in recursive processes, allowing debug logs to be printed to the console #485

Fixed

  • npm package: The --bin CLI flag was not producing bytecode because the outputSelection was not updated to explicitly requested it.
  • Yul mode now properly exits when solc reports validation errors (e.g., invalid hex literals), matching --standard-json behavior. #477
  • Fixed a bytecode divergence (yet functionally equivalent) between the resolc Linux/macOS builds and the Windows build for Solidity contracts containing a value multiplied by itself (e.g. via explicit squaring or exponentiation), manifesting primarily when using optimization level -O0. #500
  • Recursive processes use the current executable by default #484
  • Work around some LLVM indeterminism problem #500

Changed

  • Updated LLVM from 18.1.8 to LLVM 21.1.8
  • Updated musl to 1.2.5
  • Updated inkwell to 0.8.0
  • Updated polkavm-* to 0.31.0
  • Updated EMSDK to 5.0.0
  • Switched building LLVM for Windows from Visual Studio to MSVC-compatible Clang (clang-cl) and Ninja. #497
  • Append optnone and noinline for -O0 optlevel #502

v1.0.0

Supported polkadot-sdk rev: unstable2507

Changed

  • Removed the revive-explorer utility.

Fixed

  • OOB access in calldataload and calldatacopy should always produce zero values instead of consuming all gas.
  • The superfluous byte swap in linkersymbol.
  • Compiling with --standard-json now compiles to PolkaVM bytecode only for the contracts explicitly requested in the outputSelection, significantly improving compilation time when none or a subset of files requests bytecode. PR#461
  • Compiling with --standard-json now outputs only the explicitly requested output (e.g. evm.assembly, evm.bytecode, ast, etc.). PR#461
// Example:
{
  "settings": {
    // ...
    "outputSelection": {
      "path/to/my/file1.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"]
      },
      "path/to/my/file2.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).
        "": []
      },
    }
  }
}

v0.6.0

This is a development pre-release.

Supported polkadot-sdk rev: unstable2507

Added

Changed

  • Instruct the LLVM backend and linker to --relax (may lead to smaller contract code size).
  • Standard JSON mode: Don't forward EVM bytecode related output selections to solc.
  • The supported polkadot-sdk release is unstable2507.
  • The INVALID opcode and OOB memory accesses now consume all remaining gas.
  • Emit the call_evm and delegate_call_evm syscalls for contract calls.
  • The revive-runner can execute arbitrarily large contract blobs.
  • Set the default PolkaVM stack and heap size values to 128KB.

Fixed:

  • The missing STOP instruction at the end of code blocks.
  • The missing bounds check in the internal sbrk implementation.
  • The call gas is no longer ignored.
  • The settings.polkavm.memoryConfig object and its fields are now in camelCase.

v0.5.0

This is a development pre-release.

Supported polkadot-sdk rev: 2509.0.0

Added

  • Support for SELFDESTRUCT.

Changed

  • Emulated EVM heap memory accesses of zero length are never out of bounds.
  • Switched to newer and cheaper storage syscalls (omits reads and writes of 0 values).

Fixed

  • Introduced a workaround avoiding compiler crashes caused by a bug in LLVM affecting SDIV.
  • An off-by-one bug affecting SDIV overflow semantics.

v0.4.1

This is a development pre-release.

Supported polkadot-sdk rev: 2503.0.1

Changed

  • The ast output is no longer pruned in standard JSON mode (required for foundry).
  • Support standard_json.output_selection to also look at per file settings.

v0.4.0

This is a development pre-release.

Supported polkadot-sdk rev: 2503.0.1

Changed

  • Remove the broken --llvm-ir mode.
  • Remove the unused fallback for size optimization setting.
  • Unlinked contract binaries are emitted as raw ELF objects.

Added

  • Line debug information per YUL builtin and for if statements.
  • Column numbers in debug information.
  • Support for the YUL optimizer details in the standard json input definition.
  • The revive-explorer compiler utility.
  • revive-yul: The AST visitor interface.
  • The --link deploy time linking mode.

Fixed

  • The debug info source file matches the YUL path in --debug-output-dir, allowing tools to display the source line.
  • Incosistent type forwarding in JSON output (empty string vs. null object).
  • The solc automatic import resolution.
  • Compiler panic on missing libraries definition.

v0.3.0

This is a development pre-release.

Supported polkadot-sdk rev: 2503.0.1

Fixed

  • llvm-context: Bugfix the SAR YUL builtin translation.
  • runtime-api: Add the missing memset builtin.
  • npm package: Bugfix the exports field defined in the package.json.

v0.2.0

This is a development pre-release.

Supported polkadot-sdk rev: 2503.0.1

Changed

  • Removed the license printer from the resolc binary.
  • EVM bytecode is no longer requested from solc (except in test utils) leading to less compilation work in the pipeline.

Fixed

  • solc-json-interface: Serializing of any custom key in the JSON input is only skipped if not provided.
  • npm package resolution no longer fails with an 'ERR_PACKAGE_PATH_NOT_EXPORTED' error for packages defining exports fields in the package.json.

v0.1.0

This is a development pre-release.

Supported polkadot-sdk rev: 2503.0.1

Added

  • Add the PolkaVM heap size, stack size and debug info CLI compiler options to the standard JSON settings. This makes the standard JSON input succint for reproducible builds.

Changed

  • Supported polkadot-sdk version is now 2503.0.1
  • The emsdk version is now 4.0.9

Fixed

v0.1.0-dev.16

This is a development pre-release.

Supported polkadot-sdk rev:c29e72a8628835e34deb6aa7db9a78a2e4eabcee

Added

  • Move the npm package from paritytech/js-revive, into this repo. The package @parity/resolc will be deployed to npm for each release.
  • Support for solc v0.8.30

Changed

  • By default, heavy size optimizations are applied.

Fixed

  • @parity/resolc: The solc dependency package is constrained to the latest supported version, preventing breaking the package ever time a new solc package was released.
  • The resolc npm package no longer ignores the optimizer settings

v0.1.0-dev.14

This is a development pre-release.

Supported polkadot-sdk rev:c29e72a8628835e34deb6aa7db9a78a2e4eabcee

Added

  • The revive-runner helper utility binary which helps to run contracts locally without a blockchain node.
  • Allow configuration of the EVM heap memory size and stack size via CLI flags and JSON input settings.

Changed

  • The default PVM stack memory size was increased from 16kb to 32kb.

Fixed

  • Constructors avoid storing zero sized immutable data on exit.

v0.1.0-dev.13

This is a development pre-release.

Supported polkadot-sdk rev:c29e72a8628835e34deb6aa7db9a78a2e4eabcee

Added

  • Support for solc v0.8.29
  • Decouples the solc JSON-input-output type definitions from the Solidity fronted and expose them via a dedicated crate.
  • --supported-solc-versions for resolc binary to return a semver range of supported solc versions.
  • Support for passing LLVM command line options via the prcoess input or providing one or more --llvm-arg='..' resolc CLI flag. This allows more fine-grained control over the LLVM backend configuration.

Changed

  • Storage keys and values are big endian. This was a pre-mature optimization because for the contract itself it this is a no-op and thus not observable. However we should consider the storage layout as part of the contract ABI. The endianness of transient storage values are still kept as-is.
  • Running resolc using webkit is no longer supported.

Fixed

  • A missing byte swap for the create2 salt value.

v0.1.0-dev.12

This is a development pre-release.

Supported polkadot-sdk rev: 21f6f0705e53c15aa2b8a5706b208200447774a9

Added

  • Per file output selection for --standard-json mode.
  • The ir output selection option for --standard-json mode.

Changed

  • Improved code size: Large contracts compile to smaller code blobs when enabling aggressive size optimizations (-Oz).

Fixed

v0.1.0-dev.11

This is a development pre-release.

Supported polkadot-sdk rev: 274a781e8ca1a9432c7ec87593bd93214abbff50

Added

Changed

Fixed

  • A bug causing incorrect loads from the emulated EVM linear memory.
  • A missing integer truncate after switching to 64bit.

v0.1.0-dev.10

This is a development pre-release.

Supported polkadot-sdk rev: 274a781e8ca1a9432c7ec87593bd93214abbff50

Added

  • Support for the coinbase opcode.
  • The resolc web JS version.

Changed

  • Missing the --overwrite flag emits an error instead of a warning.
  • The resolc executable prints the help by default.
  • Removed support for legacy EVM assembly (EVMLA) translation.
  • integration: identify cached code blobs on source code to fix potential confusions.
  • Setting base, include or allow paths in emscripten is now a hard error.
  • Employ a heuristic to detect address.transfer and address.send calls. If detected, the re-entrant call flag is not set and 0 deposit limit is endowed.

Fixed

  • Solidity: Add the solc --libraries files to sources.
  • A data race in tests.
  • Fix broken pipe errors.
  • llvm-builder: Allow warnings.
  • solidity: Fix the custom compiler warning messages.

v0.1.0-dev.9

This is a development pre-release.

Added

Changed

  • Syscalls with more than 6 arguments now pack them into registers.

Fixed

  • Remove reloading of the resolc.js file (fix issue with relative path in web worker)

v0.1.0-dev.8

This is a development pre-release.

Added

  • The revive-llvm-builder crate with the revive-llvm helper utility for streamlined management of the LLVM framework dependency.
  • Initial support for running resolc in the browser.

Changed

  • Suported contracts runtime is polkadot-sdk git version d62a90c8c729acd98c7e9a5cab9803b8b211ffc5.
  • The minimum supported Rust version is 1.81.0.
  • Error out early instead of invoking solc with invalid base or include path flags.

Fixed

  • Decouple the LLVM target dependency from the LLVM host dependency.
  • Do not error out if no files and no errors were produced. This aligns resolc closer to solc.
  • Fixes input normalization in the Wasm version.

v0.1.0-dev.7

This is a development pre-release.

Added

  • Implement the GASPRICE opcode.
  • Implement the BASEFEE opcode.
  • Implement the GASLIMIT opcode.

Changed

  • The GAS opcode now returns the remaining ref_time.
  • Contracts can now be supplied call data input of arbitrary size.
  • Some syscalls now return the value in a register, slightly improving emitted contract code.
  • Calls forward maximum weight limits instead of 0, anticipating a change in polkadot-sdk where weight limits of 0 no longer interprets as uncapped limit.

Fixed

  • A linker bug which was preventing certain contracts from linking with the PVM linker.
  • JS: Fix encoding conversion from JS string (UTF-16) to UTF-8.
  • The git commit hash slug is always displayed in the version string.

v0.1.0-dev.6

This is a development pre-release.

Added

  • Implement the BLOCKHASH opcode.
  • Implement delegate calls.
  • Implement the GASPRICE opcode. Currently hard-coded to return 1.
  • The ELF shared object contract artifact is dumped into the debug output directory.
  • Initial support for emitting debug info (opt in via the -g flag)

Changed

  • resolc now emits 64bit PolkaVM blobs, reducing contract code size and execution time.
  • The RISC-V bit-manipulation target feature (zbb) is enabled.

Fixed

  • Compilation to Wasm (for usage in node and web browsers)

v0.1.0-dev.5

This is development pre-release.

Added

  • Implement the CODESIZE and EXTCODESIZE opcodes.

Changed

  • Include the full revive version in the contract metadata.

Fixed

v0.1.0-dev-4

This is development pre-release.

Added

  • Support the ORIGIN opcode.

Changed

  • Update polkavm to v0.14.0.
  • Enable the a, fast-unaligned-access and xtheadcondmov LLVM target features, decreasing the code size for some contracts.

Fixed