Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"ignore": [
"@nomicfoundation/config",
"@nomicfoundation/example-project",
"@nomicfoundation/hardhat-slang",
"@nomicfoundation/template-package",
"template-*"
],
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ jobs:
- name: Build All Packages
run: pnpm run --recursive --no-bail --filter './packages/**' --if-present build

# hardhat-slang is excluded, once part of core this filter can be dropped
- name: Publish All Packages (dry-run) and save list of packages that need publishing
run: pnpm publish --filter "./packages/**" -r --no-git-checks --access public --dry-run --report-summary
run: pnpm publish --filter "./packages/**" --filter "!@nomicfoundation/hardhat-slang" -r --no-git-checks --access public --dry-run --report-summary

- name: Store the package list to be published
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
Expand Down
69 changes: 69 additions & 0 deletions packages/hardhat-errors/src/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,19 @@ export const ERROR_CATEGORIES: {
},
},
},
HARDHAT_SLANG: {
min: 130000,
max: 139999,
pluginId: "hardhat-slang",
websiteTitle: "Hardhat Slang",
CATEGORIES: {
GENERAL: {
min: 130000,
max: 130099,
websiteSubTitle: "General errors",
},
},
},
};

export const ERRORS = {
Expand Down Expand Up @@ -3528,4 +3541,60 @@ Remove --grep-exclude, or run the tests that need it through the Mocha or Solidi
},
},
},
HARDHAT_SLANG: {
GENERAL: {
UNSUPPORTED_PLATFORM: {
number: 130000,
messageTemplate: `slang is not available for the current platform ({platform}/{arch}).

slang supports: linux/x64, linux/arm64, darwin (macOS), windows/x64.`,
websiteTitle: "Unsupported platform",
websiteDescription: `The slang compiler is not available for your current operating system and architecture combination.

slang supports: linux/x64, linux/arm64, darwin (macOS), windows/x64.`,
},
DOWNLOAD_FAILED: {
number: 130001,
messageTemplate: `Failed to download slang {version} after {attempts} attempts: {reason}`,
websiteTitle: "slang download failed",
websiteDescription: `The slang compiler binary could not be downloaded from the slang releases mirror used by Hardhat.

Check your internet connection, ensure that the slang releases mirror is reachable from your environment, and verify that the requested slang version exists.

Hardhat sends its requests through the proxy set in \`HTTPS_PROXY\` or \`HTTP_PROXY\`. If you are behind one, ensure that it can reach that mirror, or add it to \`NO_PROXY\` to connect directly.`,
},
BINARY_NOT_FOUND: {
number: 130002,
messageTemplate: `slang binary not found at {path}`,
websiteTitle: "slang binary not found",
websiteDescription: `The configured custom path for the slang binary does not exist.

Verify that the path in your Hardhat config points to a valid slang binary.`,
},
CHECKSUM_DOWNLOAD_FAILED: {
number: 130003,
messageTemplate: `Couldn't download the checksum for slang {version} from {url}: {reason}`,
websiteTitle: "Couldn't obtain the slang checksum",
websiteDescription: `Every slang binary is published alongside a \`.sha256\` checksum file, which Hardhat uses to verify the download. Hardhat couldn't obtain that checksum, so it refused to use the binary.

Check your internet connection, and ensure that the slang releases mirror is reachable from your environment.

Hardhat sends its requests through the proxy set in \`HTTPS_PROXY\` or \`HTTP_PROXY\`. If you are behind one, ensure that it can reach that mirror, or add it to \`NO_PROXY\` to connect directly.`,
},
INVALID_DOWNLOAD: {
number: 130004,
messageTemplate: `Couldn't download slang {version}: Checksum verification failed.

Please check your internet connection and try again.

If this error persists, run "npx hardhat clean --global".`,
websiteTitle: "Downloaded slang checksum verification failed",
websiteDescription: `Hardhat downloaded a slang binary, and its checksum didn't match the one published alongside it. The binary was deleted instead of being used.

The likeliest cause is a corrupted or incomplete download.

Please check your internet connection and try again. If this error persists, run \`npx hardhat clean --global\`.`,
},
},
},
} as const;
14 changes: 14 additions & 0 deletions packages/hardhat-slang/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Node modules
/node_modules

# Compilation output
/dist

# pnpm deploy output
/bundle

# test coverage output
coverage

# all the tmp folders in the fixture projects
/test/fixture-projects/tmp/
6 changes: 6 additions & 0 deletions packages/hardhat-slang/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules
/dist
/coverage
CHANGELOG.md
/test/fixture-projects/**/artifacts
/test/fixture-projects/**/cache
9 changes: 9 additions & 0 deletions packages/hardhat-slang/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2026 Nomic Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
177 changes: 177 additions & 0 deletions packages/hardhat-slang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Hardhat Slang plugin

This plugin enables the new `slang` Solidity compiler in Hardhat.

The `slang` compiler is experimental and is not ready for production use-cases. Use it for test builds and test execution locally, and keep using `solc` for production use-cases (including during deployment, for example with `hardhat-ignition` and in your CI). Care should be taken before enabling compilation with `slang` in other build profiles, see the configuration flags below.

## Installation

```bash
npm install --save-dev @nomicfoundation/hardhat-slang
```

Then add the plugin to your `hardhat.config.ts`, pin a `slang` release, and create a `slang` build profile. You must use the build profiles config format, which requires both a `default` and a `slang` profile:

```typescript
import { defineConfig } from "hardhat/config";
import hardhatSlang from "@nomicfoundation/hardhat-slang";

export default defineConfig({
plugins: [hardhatSlang],
solidity: {
profiles: {
default: {
version: "0.8.34",
},
slang: {
type: "slang",
version: "0.8.34",
},
},
},
slang: {
version: "0.1.0-pre.2026-10-01",
},
});
```

The `default` profile uses solc as usual. The `slang` profile uses the slang compiler, identified by `type: "slang"`. The `version` of a `type: "slang"` entry is still the Solidity version, exactly as with solc: Hardhat uses it to resolve pragmas and group files into compilation jobs. Which `slang` binary compiles them is decided separately, by `slang.version`.

## Usage

Run tests or compile using the slang build profile:

```bash
hardhat test --build-profile slang
hardhat build --build-profile slang
Comment on lines +42 to +46
```

The default profile continues to use solc as usual:

```bash
hardhat build # uses solc (default profile)
```

## Configuration

### Pinning a slang release

Unlike solc, one `slang` binary compiles a range of Solidity versions (`0.8.x`). The plugin therefore downloads a single release, the one pinned in `slang.version`, and uses it for every `type: "slang"` compiler entry. Each entry's Solidity `version` must fall inside the range supported by the pinned release (see [Supported Solidity versions](#supported-solidity-versions)); anything outside is a validation error.

`slang.version` is required whenever a `type: "slang"` entry needs a download. Entries with a custom `path` (see below) don't.

### Multi-version example

You can configure the `slang` profile with multiple compilers. Compilers without `type: "slang"` will use solc:

```typescript
export default defineConfig({
plugins: [hardhatSlang],
solidity: {
profiles: {
default: {
compilers: [{ version: "0.8.34" }, { version: "0.8.20" }],
},
slang: {
compilers: [
{ type: "slang", version: "0.8.34" }, // compiled by the pinned slang release
{ type: "slang", version: "0.8.20" }, // same binary, different Solidity version
{ version: "0.7.6" }, // uses solc; outside the slang range
],
},
},
},
slang: {
version: "0.1.0-pre.2026-10-01",
},
});
```

### Options

- `version` (`string`), the slang release to download and compile with. See [Supported Solidity versions](#supported-solidity-versions) for the known releases.
- `dangerouslyAllowSlangInProduction` (`boolean`, default: `false`), allows compiler type `"slang"` in build profiles other than `slang`. By default, using `type: "slang"` in any other profile (e.g. `default`, `production`) will produce a validation error.

```typescript
export default defineConfig({
plugins: [hardhatSlang],
solidity: {
profiles: {
default: {
type: "slang", // not recommended, allowed only because of the option below
version: "0.8.34",
},
slang: {
type: "slang",
version: "0.8.34",
},
},
},
slang: {
version: "0.1.0-pre.2026-10-01",
dangerouslyAllowSlangInProduction: true,
},
});
```

### Using a custom binary

Point a compiler entry at a locally built binary with `path`. The entry skips the download and the Solidity range check, and the plugin reads the compiler version from the binary's `--version` output:

```typescript
slang: {
type: "slang",
version: "0.8.34",
path: "/path/to/slang",
},
```

### Optimization level

slang optimizes via LLVM; set the level per profile with `settings.optimizer.mode`:

| Mode | What it does |
| ----- | ----------------------------------------------------- |
| `"1"` | Least optimization, fastest to compile (the default). |
| `"2"` | More runtime optimization. |
| `"3"` | Best runtime performance. |
| `"s"` | Smaller bytecode. |
| `"z"` | Smallest bytecode. |

There is **no "off"**: the minimum is `"1"`, so LLVM always optimizes. The solc-specific knobs `optimizer.enabled` and `viaIR` have no effect on the slang pipeline, which has neither the solc optimizer nor a Yul step; the plugin passes them through untouched.

For example, optimizing for size instead of performance:

```typescript
import { defineConfig } from "hardhat/config";
import hardhatSlang from "@nomicfoundation/hardhat-slang";

export default defineConfig({
plugins: [hardhatSlang],
solidity: {
profiles: {
default: { version: "0.8.34" },
slang: {
type: "slang",
version: "0.8.34",
settings: { optimizer: { mode: "z" } }, // optimize for size
},
},
},
slang: {
version: "0.1.0-pre.2026-10-01",
},
});
```

### Supported Solidity versions

Each slang release supports a range of Solidity versions:

| slang release | Solidity versions | Notes |
| --- | --- | --- |
| `0.1.0-pre.2026-10-01` | `0.8.0` to `0.8.37` | Internal prerelease (solx tag `b74af542`, 2026-10-01) downloaded from GitHub. |

### EVM version support

slang supports EVM versions `cancun`, `prague`, and `osaka`. Using an older EVM target (e.g., `paris`, `shanghai`) with compiler type `"slang"` will result in a validation error.
3 changes: 3 additions & 0 deletions packages/hardhat-slang/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createConfig } from "../config/eslint.config.js";

export default createConfig(import.meta.filename);
69 changes: 69 additions & 0 deletions packages/hardhat-slang/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "@nomicfoundation/hardhat-slang",
"version": "3.0.0",
"description": "Hardhat plugin for using the slang compiler in test builds",
"homepage": "https://github.com/NomicFoundation/hardhat/tree/main/packages/hardhat-slang",
"repository": {
"type": "git",
"url": "https://github.com/NomicFoundation/hardhat",
"directory": "packages/hardhat-slang"
},
"author": "Nomic Foundation",
"license": "MIT",
"type": "module",
"types": "dist/src/index.d.ts",
"exports": {
".": "./dist/src/index.js",
"./package.json": "./package.json"
},
"keywords": [
"ethereum",
"smart-contracts",
"hardhat",
"slang",
"compiler"
],
"scripts": {
"lint": "pnpm eslint && pnpm prettier --check",
"lint:fix": "pnpm eslint --fix && pnpm prettier --write",
"eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"prettier": "prettier \"**/*.{ts,js,md,json}\"",
"test": "node --import tsx/esm --test --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"test:only": "node --import tsx/esm --test --test-only --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"test:coverage": "c8 --reporter html --reporter text --all --exclude test --exclude \"src/**/{types,type-extensions}.ts\" --src src node --import tsx/esm --test --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"pretest": "pnpm build",
"pretest:only": "pnpm build",
"build": "tsc --build .",
"prepublishOnly": "pnpm build",
"clean": "rimraf dist"
},
"files": [
"dist/src/",
"src/",
"CHANGELOG.md",
"LICENSE",
"README.md"
],
"devDependencies": {
"@nomicfoundation/hardhat-node-test-reporter": "workspace:^3.1.0",
"@nomicfoundation/hardhat-slang-solx": "workspace:^",
"@nomicfoundation/hardhat-test-utils": "workspace:^",
"@types/node": "^22.0.0",
"c8": "^12.0.0",
"eslint": "9.39.5",
"hardhat": "workspace:^3.15.0",
"prettier": "3.9.9",
"rimraf": "^6.1.3",
"tsx": "^4.23.1",
"typescript": "~6.0.3"
},
"dependencies": {
"@nomicfoundation/hardhat-errors": "workspace:^3.1.0",
"@nomicfoundation/hardhat-utils": "workspace:^4.3.0",
"@nomicfoundation/hardhat-zod-utils": "workspace:^3.0.5",
"zod": "^3.23.8"
},
"peerDependencies": {
"hardhat": "workspace:^3.15.0"
}
}
Loading
Loading