Compare commits

...

5 Commits

Author SHA1 Message Date
kvpanch 4ab11a09a9 Merge branch 'main' into kvpanch/llvm_21 2025-12-16 07:13:09 -05: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
kvp c952471647 Update code base to use LLVM 21 2025-12-15 18:34:58 -05:00
xermicus 91bd1b0b4e Do not build the book during test (#432)
Avoid spurious changes in the build output directory.
2025-12-15 14:16:03 +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
39 changed files with 1351 additions and 1236 deletions
+56 -36
View File
@@ -26,11 +26,14 @@ runs:
# Extract version from branch name (e.g., "18.x" from "release/18.x")
VERSION_PREFIX=$(echo "$BRANCH" | sed 's|release/||' | sed 's|\.x$||')
echo "Detected LLVM version prefix from submodule branch: $VERSION_PREFIX"
# Special case: pin LLVM 18 to specific version 18.1.8
if [ "$VERSION_PREFIX" = "18" ]; then
echo "Using pinned version for LLVM 18: llvm-18.1.8"
echo "version_prefix=llvm-18.1.8" >> $GITHUB_OUTPUT
elif [ "$VERSION_PREFIX" = "21" ]; then
echo "Using pinned version for LLVM 21: llvm-21.1.6"
echo "version_prefix=llvm-21.1.6" >> $GITHUB_OUTPUT
else
echo "version_prefix=llvm-$VERSION_PREFIX" >> $GITHUB_OUTPUT
fi
@@ -42,7 +45,7 @@ runs:
echo "Using explicitly provided version: ${{ inputs.version }}"
echo "version_prefix=${{ inputs.version }}" >> $GITHUB_OUTPUT
fi
- name: find asset
id: find
uses: actions/github-script@v7
@@ -53,12 +56,15 @@ runs:
result-encoding: string
script: |
let page = 1;
let releases = [];
let allReleases = [];
let target = process.env.target
let versionPrefix = process.env.version_prefix
do {
// Fetch all releases from all pages
core.info('Fetching releases from revive repository...');
let hasMorePages = true;
while (hasMorePages) {
const res = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
@@ -66,43 +72,57 @@ runs:
page,
});
releases = res.data
releases.sort((a, b) => {
return (a.published_at < b.published_at) ? 1 : ((a.published_at > b.published_at) ? -1 : 0);
});
let llvmRelease;
if (versionPrefix) {
// Search for latest release matching the version prefix
llvmRelease = releases.find(release => {
return release.tag_name.startsWith(versionPrefix);
});
if (llvmRelease) {
core.info(`Found LLVM release matching prefix '${versionPrefix}': ${llvmRelease.tag_name}`);
}
if (res.data.length > 0) {
core.info(`Page ${page}: Fetched ${res.data.length} releases`);
allReleases.push(...res.data);
page++;
} else {
// Find latest LLVM release
llvmRelease = releases.find(release => {
return release.tag_name.startsWith('llvm-');
});
if (llvmRelease) {
core.info(`Found latest LLVM version: ${llvmRelease.tag_name}`);
}
hasMorePages = false;
}
}
if (llvmRelease){
let asset = llvmRelease.assets.find(asset =>{
return asset.name.includes(target);
});
if (!asset){
core.setFailed(`Artifact for '${target}' not found in release ${llvmRelease.tag_name} (${llvmRelease.html_url})`);
process.exit();
}
return asset.browser_download_url;
core.info(`Total releases fetched: ${allReleases.length}`);
// Sort all releases by publication date (newest first)
allReleases.sort((a, b) => {
return (a.published_at < b.published_at) ? 1 : ((a.published_at > b.published_at) ? -1 : 0);
});
// Debug: Print all LLVM releases
const llvmReleases = allReleases.filter(r => r.tag_name.startsWith('llvm-'));
core.info(`Found ${llvmReleases.length} LLVM releases in total:`);
llvmReleases.forEach(r => {
core.info(` - ${r.tag_name} (published: ${r.published_at})`);
});
// Find the appropriate LLVM release
let llvmRelease;
if (versionPrefix) {
// Search for latest release matching the version prefix
llvmRelease = llvmReleases.find(release => {
return release.tag_name.startsWith(versionPrefix);
});
if (llvmRelease) {
core.info(`Selected LLVM release matching prefix '${versionPrefix}': ${llvmRelease.tag_name}`);
}
} else {
// Find latest LLVM release (first in sorted list)
llvmRelease = llvmReleases[0];
if (llvmRelease) {
core.info(`Selected latest LLVM version: ${llvmRelease.tag_name}`);
}
}
page++;
} while(releases.length > 0);
if (llvmRelease) {
let asset = llvmRelease.assets.find(asset => {
return asset.name.includes(target);
});
if (!asset) {
core.setFailed(`Artifact for '${target}' not found in release ${llvmRelease.tag_name} (${llvmRelease.html_url})`);
process.exit();
}
return asset.browser_download_url;
}
if (versionPrefix) {
core.setFailed(`No LLVM releases matching prefix '${versionPrefix}' found! Please check the version.`);
+4 -1
View File
@@ -25,9 +25,12 @@ jobs:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- name: Install mdBook
- name: Install and test the mdBook
run: make test-book
- name: Build book
run: mdbook build book
- name: Build book to tmp
run: mdbook build book -d docs-tmp
+1 -1
View File
@@ -85,7 +85,7 @@ jobs:
cat /etc/apt/sources.list
sudo sed -i 's/jammy/noble/g' /etc/apt/sources.list
cat /etc/apt/sources.list
sudo apt-get update && sudo apt-get install -y cmake ninja-build curl git libssl-dev pkg-config clang lld musl xz-utils libc6-dev gcc-multilib
sudo apt-get update && sudo apt-get install -y cmake ninja-build curl git libssl-dev pkg-config clang lld musl xz-utils libc6-dev gcc-multilib g++ build-essential linux-libc-dev
- name: Install Dependencies
if: ${{ matrix.host == 'macos' }}
+3 -3
View File
@@ -92,7 +92,7 @@ jobs:
if: ${{ matrix.type == 'native' }}
shell: bash
run: |
export LLVM_SYS_181_PREFIX=$PWD/llvm-${{ matrix.target }}
export LLVM_SYS_211_PREFIX=$PWD/llvm-${{ matrix.target }}
make install-bin
mv target/release/resolc resolc-${{ matrix.target }} || mv target/release/resolc.exe resolc-${{ matrix.target }}.exe
@@ -103,7 +103,7 @@ jobs:
cd /opt/revive
chown -R root:root .
apt update && apt upgrade -y && apt install -y pkg-config
export LLVM_SYS_181_PREFIX=/opt/revive/llvm-${{ matrix.target }}
export LLVM_SYS_211_PREFIX=/opt/revive/llvm-${{ matrix.target }}
make install-bin
mv target/${{ matrix.target }}/release/resolc resolc-${{ matrix.target }}
"
@@ -163,7 +163,7 @@ jobs:
- name: Build
run: |
export LLVM_SYS_181_PREFIX=$PWD/llvm-x86_64-unknown-linux-gnu
export LLVM_SYS_211_PREFIX=$PWD/llvm-x86_64-unknown-linux-gnu
export REVIVE_LLVM_TARGET_PREFIX=$PWD/llvm-wasm32-unknown-emscripten
source emsdk/emsdk_env.sh
make install-wasm
+1 -1
View File
@@ -47,7 +47,7 @@ jobs:
- name: Set LLVM Environment Variables
run: |
echo "LLVM_SYS_181_PREFIX=$(pwd)/llvm-x86_64-unknown-linux-gnu" >> $GITHUB_ENV
echo "LLVM_SYS_211_PREFIX=$(pwd)/llvm-x86_64-unknown-linux-gnu" >> $GITHUB_ENV
echo "REVIVE_LLVM_TARGET_PREFIX=$(pwd)/llvm-wasm32-unknown-emscripten" >> $GITHUB_ENV
- name: Build Revive
+1 -1
View File
@@ -38,7 +38,7 @@ jobs:
- name: Set LLVM Environment Variables
run: |
echo "LLVM_SYS_181_PREFIX=$(pwd)/llvm-x86_64-unknown-linux-gnu" >> $GITHUB_ENV
echo "LLVM_SYS_211_PREFIX=$(pwd)/llvm-x86_64-unknown-linux-gnu" >> $GITHUB_ENV
- name: Install Geth
run: |
+1 -1
View File
@@ -1,4 +1,4 @@
[submodule "llvm"]
path = llvm
url = https://github.com/llvm/llvm-project.git
branch = release/18.x
branch = release/21.x
+3 -1
View File
@@ -4,7 +4,7 @@
This is a development pre-release.
Supported `polkadot-sdk` rev: `2509.0.0`
Supported `polkadot-sdk` rev: `unstable2507`
### Added
- The comprehensive revive compiler book documentation page: https://paritytech.github.io/revive/
@@ -14,6 +14,8 @@ Supported `polkadot-sdk` rev: `2509.0.0`
### 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.
### Fixed:
- The missing `STOP` instruction at the end of `code` blocks.
Generated
+1030 -1036
View File
File diff suppressed because it is too large Load Diff
+4 -3
View File
@@ -76,13 +76,14 @@ normpath = "1.5"
# polkadot-sdk and friends
codec = { version = "3.7.5", default-features = false, package = "parity-scale-codec" }
scale-info = { version = "2.11.6", default-features = false }
polkadot-sdk = { version = "2509.0.0" }
polkadot-sdk = { version = "=2507.4.0" }
# llvm
[workspace.dependencies.inkwell]
version = "0.6.0"
git = "https://github.com/TheDan64/inkwell.git"
branch = "master"
default-features = false
features = ["serde", "llvm18-1", "no-libffi-linking", "target-riscv"]
features = ["serde", "llvm21-1", "no-libffi-linking", "target-riscv"]
[profile.bench]
inherits = "release"
+1 -1
View File
@@ -21,7 +21,7 @@ RUN apt update && \
COPY . .
COPY --from=llvm-builder /opt/revive/target-llvm /opt/revive/target-llvm
ENV LLVM_SYS_181_PREFIX=/opt/revive/target-llvm/musl/target-final
ENV LLVM_SYS_211_PREFIX=/opt/revive/target-llvm/musl/target-final
RUN make install-bin
FROM alpine:latest
-1
View File
@@ -92,7 +92,6 @@ test-llvm-builder:
test-book:
cargo install mdbook --version 0.5.1 --locked
mdbook test book
mdbook build book
bench: install-bin
cargo criterion --all --all-features --message-format=json \
+5 -5
View File
@@ -69,9 +69,9 @@ Download the [latest LLVM build](https://github.com/paritytech/revive/releases?q
> xattr -rc </path/to/the/extracted/archive>/target-llvm/gnu/target-final/bin/*
> ```
After extracting the archive, point `$LLVM_SYS_181_PREFIX` to it:
After extracting the archive, point `$LLVM_SYS_211_PREFIX` to it:
```sh
export LLVM_SYS_181_PREFIX=</path/to/the/extracted/archive>/target-llvm/gnu/target-final
export LLVM_SYS_211_PREFIX=</path/to/the/extracted/archive>/target-llvm/gnu/target-final
```
</details>
@@ -79,18 +79,18 @@ export LLVM_SYS_181_PREFIX=</path/to/the/extracted/archive>/target-llvm/gnu/targ
<details>
<summary>Building from source</summary>
The `Makefile` provides a shortcut target to obtain a compatible LLVM build, using the provided [revive-llvm](crates/llvm-builder/README.md) utility. Once installed, point `$LLVM_SYS_181_PREFIX` to the installation afterwards:
The `Makefile` provides a shortcut target to obtain a compatible LLVM build, using the provided [revive-llvm](crates/llvm-builder/README.md) utility. Once installed, point `$LLVM_SYS_211_PREFIX` to the installation afterwards:
```sh
make install-llvm
export LLVM_SYS_181_PREFIX=${PWD}/target-llvm/gnu/target-final
export LLVM_SYS_211_PREFIX=${PWD}/target-llvm/gnu/target-final
```
</details>
### 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](#LLVM)).
To build the `resolc` Solidity frontend executable, make sure you have obtained a compatible LLVM build and did export the `LLVM_SYS_211_PREFIX` environment variable pointing to it (see [above](#LLVM)).
To install the `resolc` Solidity frontend executable:
+1 -1
View File
@@ -1,7 +1,7 @@
//! The compiler build utilities library.
/// The revive LLVM host dependency directory prefix environment variable.
pub const REVIVE_LLVM_HOST_PREFIX: &str = "LLVM_SYS_181_PREFIX";
pub const REVIVE_LLVM_HOST_PREFIX: &str = "LLVM_SYS_211_PREFIX";
/// The revive LLVM target dependency directory prefix environment variable.
pub const REVIVE_LLVM_TARGET_PREFIX: &str = "REVIVE_LLVM_TARGET_PREFIX";
+5 -5
View File
@@ -1,10 +1,10 @@
{
"Baseline": 911,
"Computation": 2293,
"DivisionArithmetics": 14353,
"ERC20": 16936,
"Computation": 2337,
"DivisionArithmetics": 14488,
"ERC20": 17041,
"Events": 1672,
"FibonacciIterative": 1454,
"Flipper": 2083,
"SHA1": 7727
"Flipper": 2106,
"SHA1": 7814
}
+1 -1
View File
@@ -26,6 +26,6 @@ pragma solidity ^0.8;
contract BaseFee {
constructor() payable {
assert(block.basefee == 0);
assert(block.basefee > 0);
}
}
-1
View File
@@ -26,7 +26,6 @@ pragma solidity ^0.8;
contract GasLeft {
constructor() payable {
assert(gasleft() > gasleft());
assert(gasleft() > 0 && gasleft() < 0xffffffffffffffff);
}
}
+1 -1
View File
@@ -26,6 +26,6 @@ pragma solidity ^0.8;
contract GasLimit {
constructor() payable {
assert(block.gaslimit == 2000000000000);
assert(block.gaslimit > 0);
}
}
+1 -1
View File
@@ -26,6 +26,6 @@ pragma solidity ^0.8;
contract GasPrice {
constructor() payable {
assert(tx.gasprice == 1000);
assert(tx.gasprice > 1000);
}
}
+45
View File
@@ -669,3 +669,48 @@ fn sbrk_bounds_checks() {
"not seeing a trap means the contract did not catch the OOB"
);
}
#[test]
fn invalid_opcode_works() {
let code = &build_yul(&[(
"invalid.yul",
r#"object "Test" {
code {
invalid()
}
object "Test_deployed" {
code {
invalid()
}
}
}"#,
)])
.unwrap()["invalid.yul:Test"];
let results = Specs {
actions: vec![
Instantiate {
origin: TestAddress::Alice,
value: 0,
gas_limit: Some(GAS_LIMIT),
storage_deposit_limit: None,
code: Code::Bytes(code.to_vec()),
data: Default::default(),
salt: OptionalHex::default(),
},
VerifyCall(VerifyCallExpectation {
success: false,
..Default::default()
}),
],
differential: false,
..Default::default()
}
.run();
let CallResult::Instantiate { result, .. } = results.last().unwrap() else {
unreachable!()
};
assert_eq!(result.weight_consumed, GAS_LIMIT);
}
+28
View File
@@ -14,6 +14,7 @@ fn set_rustc_link_flags() {
"lldELF",
"lldCommon",
"lldMachO",
"lldWasm",
"LLVMSupport",
"LLVMLinker",
"LLVMCore",
@@ -68,6 +69,33 @@ fn set_rustc_link_flags() {
"LLVMBitReader",
"LLVMRemarks",
"LLVMBitstreamReader",
"LLVMTextAPI",
"LLVMDebugInfoDWARFLowLevel",
"LLVMDebugInfoGSYM",
"LLVMDebugInfoMSF",
"LLVMDebugInfoPDB",
"LLVMDebugInfoBTF",
"LLVMInterfaceStub",
"LLVMCGData",
"LLVMMIRParser",
"LLVMDWARFLinker",
"LLVMDWARFLinkerParallel",
"LLVMDWARFLinkerClassic",
"LLVMLibDriver",
"LLVMDlltoolDriver",
"LLVMTextAPIBinaryReader",
"LLVMCoverage",
"LLVMLineEditor",
"LLVMRISCVTargetMCA",
"LLVMRuntimeDyld",
"LLVMDWP",
"LLVMDWARFCFIChecker",
"LLVMDebugInfoLogicalView",
"LLVMMCA",
"LLVMipo",
"LLVMVectorize",
"LLVMSandboxIR",
"LLVMExtensions",
] {
println!("cargo:rustc-link-lib=static={lib}");
}
+2 -2
View File
@@ -82,10 +82,10 @@ Obtain a compatible build for your host platform from the release section of thi
Build artifacts end up in the `./target-llvm/gnu/target-final/` directory by default.
The `gnu` directory depends on the supported archticture and will either be `gnu`, `musl` or `emscripten`.
You now need to export the final target directory `$LLVM_SYS_181_PREFIX`:
You now need to export the final target directory `$LLVM_SYS_211_PREFIX`:
```shell
export LLVM_SYS_181_PREFIX=${PWD}/target-llvm/gnu/target-final
export LLVM_SYS_211_PREFIX=${PWD}/target-llvm/gnu/target-final
```
If built with the `--enable-tests` option, test tools will be in the `./target-llvm/gnu/build-final/` directory, along with copies of the build artifacts. For all supported build options, run `revive-llvm build --help`.
@@ -221,7 +221,6 @@ fn build_host(
"-DCOMPILER_RT_BUILD_MEMPROF='Off'",
"-DCOMPILER_RT_BUILD_ORC='Off'",
"-DCOMPILER_RT_DEFAULT_TARGET_ARCH='aarch64'",
"-DCOMPILER_RT_DEFAULT_TARGET_ONLY='On'",
])
.args(crate::platforms::shared::SHARED_BUILD_OPTS)
.args(crate::platforms::shared::shared_build_opts_ccache(
@@ -219,7 +219,6 @@ fn build_host(
"-DCOMPILER_RT_BUILD_MEMPROF='Off'",
"-DCOMPILER_RT_BUILD_ORC='Off'",
"-DCOMPILER_RT_DEFAULT_TARGET_ARCH='x86_64'",
"-DCOMPILER_RT_DEFAULT_TARGET_ONLY='On'",
"-DLIBCLANG_BUILD_STATIC='On'",
"-DBUILD_SHARED_LIBS='Off'",
])
+1 -1
View File
@@ -38,7 +38,7 @@ pub const MUSL_SNAPSHOTS_URL: &str = "https://git.musl-libc.org/cgit/musl/snapsh
pub const EMSDK_SOURCE_URL: &str = "https://github.com/emscripten-core/emsdk.git";
/// The emscripten SDK version.
pub const EMSDK_VERSION: &str = "4.0.9";
pub const EMSDK_VERSION: &str = "4.0.20";
/// The subprocess runner.
///
@@ -8,7 +8,7 @@ use serde::Serialize;
/// inside of the LLVM build directory. This order is actually generated during the building.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Attribute {
Unused = 0,
// FirstEnumAttr = 1,
AllocAlign = 1,
AllocatedPointer = 2,
AlwaysInline = 3,
@@ -16,92 +16,107 @@ pub enum Attribute {
Cold = 5,
Convergent = 6,
CoroDestroyOnlyWhenComplete = 7,
DeadOnUnwind = 8,
DisableSanitizerInstrumentation = 9,
FnRetThunkExtern = 10,
Hot = 11,
ImmArg = 12,
InReg = 13,
InlineHint = 14,
JumpTable = 15,
MinSize = 16,
MustProgress = 17,
Naked = 18,
Nest = 19,
NoAlias = 20,
NoBuiltin = 21,
NoCallback = 22,
NoCapture = 23,
NoCfCheck = 24,
NoDuplicate = 25,
NoFree = 26,
NoImplicitFloat = 27,
NoInline = 28,
NoMerge = 29,
NoProfile = 30,
NoRecurse = 31,
NoRedZone = 32,
NoReturn = 33,
NoSanitizeBounds = 34,
NoSanitizeCoverage = 35,
NoSync = 36,
NoUndef = 37,
NoUnwind = 38,
NonLazyBind = 39,
NonNull = 40,
NullPointerIsValid = 41,
OptForFuzzing = 42,
OptimizeForDebugging = 43,
OptimizeForSize = 44,
OptimizeNone = 45,
PresplitCoroutine = 46,
ReadNone = 47,
ReadOnly = 48,
Returned = 49,
ReturnsTwice = 50,
SExt = 51,
SafeStack = 52,
SanitizeAddress = 53,
SanitizeHWAddress = 54,
SanitizeMemTag = 55,
SanitizeMemory = 56,
SanitizeThread = 57,
ShadowCallStack = 58,
SkipProfile = 59,
Speculatable = 60,
SpeculativeLoadHardening = 61,
StackProtect = 62,
StackProtectReq = 63,
StackProtectStrong = 64,
StrictFP = 65,
SwiftAsync = 66,
SwiftError = 67,
SwiftSelf = 68,
WillReturn = 69,
Writable = 70,
WriteOnly = 71,
ZExt = 72,
// LastEnumAttr = 72,
// FirstTypeAttr = 73,
ByRef = 73,
ByVal = 74,
ElementType = 75,
InAlloca = 76,
Preallocated = 77,
StructRet = 78,
// LastTypeAttr = 78,
// FirstIntAttr = 79,
Alignment = 79,
AllocKind = 80,
AllocSize = 81,
Dereferenceable = 82,
DereferenceableOrNull = 83,
Memory = 84,
NoFPClass = 85,
StackAlignment = 86,
UWTable = 87,
VScaleRange = 88,
// LastIntAttr = 88,
CoroElideSafe = 8,
DeadOnReturn = 9,
DeadOnUnwind = 10,
DisableSanitizerInstrumentation = 11,
FnRetThunkExtern = 12,
Hot = 13,
HybridPatchable = 14,
ImmArg = 15,
InReg = 16,
InlineHint = 17,
JumpTable = 18,
MinSize = 19,
MustProgress = 20,
Naked = 21,
Nest = 22,
NoAlias = 23,
NoBuiltin = 24,
NoCallback = 25,
NoCfCheck = 26,
NoDivergenceSource = 27,
NoDuplicate = 28,
NoExt = 29,
NoFree = 30,
NoImplicitFloat = 31,
NoInline = 32,
NoMerge = 33,
NoProfile = 34,
NoRecurse = 35,
NoRedZone = 36,
NoReturn = 37,
NoSanitizeBounds = 38,
NoSanitizeCoverage = 39,
NoSync = 40,
NoUndef = 41,
NoUnwind = 42,
NonLazyBind = 43,
NonNull = 44,
NullPointerIsValid = 45,
OptForFuzzing = 46,
OptimizeForDebugging = 47,
OptimizeForSize = 48,
OptimizeNone = 49,
PresplitCoroutine = 50,
ReadNone = 51,
ReadOnly = 52,
Returned = 53,
ReturnsTwice = 54,
SExt = 55,
SafeStack = 56,
SanitizeAddress = 57,
SanitizeHWAddress = 58,
SanitizeMemTag = 59,
SanitizeMemory = 60,
SanitizeNumericalStability = 61,
SanitizeRealtime = 62,
SanitizeRealtimeBlocking = 63,
SanitizeThread = 64,
SanitizeType = 65,
ShadowCallStack = 66,
SkipProfile = 67,
Speculatable = 68,
SpeculativeLoadHardening = 69,
StackProtect = 70,
StackProtectReq = 71,
StackProtectStrong = 72,
StrictFP = 73,
SwiftAsync = 74,
SwiftError = 75,
SwiftSelf = 76,
WillReturn = 77,
Writable = 78,
WriteOnly = 79,
ZExt = 80,
//LastEnumAttr = 80,
//FirstTypeAttr = 81,
ByRef = 81,
ByVal = 82,
ElementType = 83,
InAlloca = 84,
Preallocated = 85,
StructRet = 86,
//LastTypeAttr = 86,
//FirstIntAttr = 87,
Alignment = 87,
AllocKind = 88,
AllocSize = 89,
Captures = 90,
Dereferenceable = 91,
DereferenceableOrNull = 92,
Memory = 93,
NoFPClass = 94,
StackAlignment = 95,
UWTable = 96,
VScaleRange = 97,
//LastIntAttr = 97,
//FirstConstantRangeAttr = 98,
Range = 98,
//LastConstantRangeAttr = 98,
//FirstConstantRangeListAttr = 99,
Initializes = 99,
//LastConstantRangeListAttr = 99,
}
impl TryFrom<&str> for Attribute {
@@ -51,11 +51,11 @@ impl RuntimeFunction for WordToPointer {
)?;
let block_continue = context.append_basic_block("offset_pointer_ok");
let block_trap = context.append_basic_block("offset_pointer_overflow");
context.build_conditional_branch(is_overflow, block_trap, block_continue)?;
let block_invalid = context.append_basic_block("offset_pointer_overflow");
context.build_conditional_branch(is_overflow, block_invalid, block_continue)?;
context.set_basic_block(block_trap);
context.build_call(context.intrinsics().trap, &[], "invalid_trap");
context.set_basic_block(block_invalid);
context.build_runtime_call(revive_runtime_api::polkavm_imports::INVALID, &[]);
context.build_unreachable();
context.set_basic_block(block_continue);
+5 -12
View File
@@ -838,8 +838,7 @@ impl<'ctx> Context<'ctx> {
.builder()
.build_call(intrinsic, &[value.into()], "call_byte_swap")?
.try_as_basic_value()
.left()
.unwrap())
.unwrap_basic())
}
/// Builds a GEP instruction.
@@ -912,7 +911,7 @@ impl<'ctx> Context<'ctx> {
)
.unwrap()
.try_as_basic_value()
.left()
.basic()
}
/// Builds a call to the runtime API `import`, where `import` is a "getter" API.
@@ -950,7 +949,7 @@ impl<'ctx> Context<'ctx> {
)
.unwrap();
self.modify_call_site_value(arguments, call_site_value, function);
call_site_value.try_as_basic_value().left()
call_site_value.try_as_basic_value().basic()
}
/// Sets the alignment to `1`, since all non-stack memory pages have such alignment.
@@ -1082,13 +1081,7 @@ impl<'ctx> Context<'ctx> {
Ok(call_site_value
.try_as_basic_value()
.left()
.unwrap_or_else(|| {
panic!(
"revive runtime function {} should return a value",
<PolkaVMSbrkFunction as RuntimeFunction>::NAME,
)
})
.unwrap_basic()
.into_pointer_value())
}
@@ -1277,7 +1270,7 @@ impl<'ctx> Context<'ctx> {
call_site_value.add_attribute(
inkwell::attributes::AttributeLoc::Param(index as u32),
self.llvm
.create_enum_attribute(Attribute::NoCapture as u32, 0),
.create_enum_attribute(Attribute::Captures as u32, 0), // captures(none)
);
call_site_value.add_attribute(
inkwell::attributes::AttributeLoc::Param(index as u32),
@@ -275,6 +275,6 @@ pub fn count_leading_zeros<'ctx>(
"clz",
)?
.try_as_basic_value()
.left()
.basic()
.expect("the llvm.ctlz should return a value"))
}
@@ -52,12 +52,14 @@ pub fn stop(context: &mut Context) -> anyhow::Result<()> {
/// Translates the `invalid` instruction.
/// Burns all gas using an out-of-bounds memory store, causing a panic.
pub fn invalid(context: &mut Context) -> anyhow::Result<()> {
crate::polkavm::evm::memory::store(
context,
context.word_type().const_all_ones(),
context.word_const(0),
)?;
context.build_call(context.intrinsics().trap, &[], "invalid_trap");
let invalid_block = context.append_basic_block("explicit_invalid");
context.build_unconditional_branch(invalid_block);
context.set_basic_block(invalid_block);
context.build_runtime_call(revive_runtime_api::polkavm_imports::INVALID, &[]);
context.build_unreachable();
context.set_basic_block(context.append_basic_block("dead_code"));
Ok(())
}
+1 -1
View File
@@ -42,7 +42,7 @@ mimalloc = { version = "0.1.46", default-features = false }
[target.'cfg(target_os = "emscripten")'.dependencies]
libc = { workspace = true }
inkwell = { workspace = true, features = ["target-riscv", "llvm18-1-no-llvm-linking"]}
inkwell = { workspace = true, features = ["target-riscv", "llvm21-1-no-llvm-linking"]}
[build-dependencies]
git2 = { workspace = true, default-features = false }
+10 -5
View File
@@ -59,7 +59,7 @@ pub const CHARLIE: H160 = H160([3u8; 20]);
/// Default gas limit
pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000_000, 3 * 1024 * 1024 * 1024);
/// Default deposit limit
pub const DEPOSIT_LIMIT: Balance = 10_000_000;
pub const DEPOSIT_LIMIT: Balance = 100_000_000_000;
/// The native to ETH balance factor.
pub const ETH_RATIO: Balance = 1_000_000;
@@ -97,14 +97,19 @@ impl ExtBuilder {
.unwrap();
let mut ext = sp_io::TestExternalities::new(t);
let checking_account = Pallet::<Runtime>::account_id();
ext.register_extension(KeystoreExt::new(MemoryKeystore::new()));
ext.execute_with(|| {
let _ = <Runtime as Config>::Currency::deposit_creating(
&Pallet::<Runtime>::account_id(),
<Runtime as Config>::Currency::minimum_balance(),
&checking_account,
1_000_000_000_000,
);
System::set_block_number(1);
assert_ok!(Pallet::<Runtime>::map_account(RuntimeOrigin::signed(
checking_account
)));
});
ext
@@ -115,7 +120,7 @@ impl ExtBuilder {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VerifyCallExpectation {
/// When provided, the expected gas consumed
pub gas_consumed: Option<Weight>,
pub gas_consumed: Option<u128>,
/// When provided, the expected output
#[serde(default, with = "hex")]
pub output: OptionalHex<Vec<u8>>,
@@ -238,7 +243,7 @@ impl CallResult {
}
/// Get the gas consumed by the call
fn gas_consumed(&self) -> Weight {
fn gas_consumed(&self) -> u128 {
match self {
Self::Exec { result, .. } => result.gas_consumed,
Self::Instantiate { result, .. } => result.gas_consumed,
+2 -1
View File
@@ -2,7 +2,7 @@ use frame_support::{runtime, traits::FindAuthor, weights::constants::WEIGHT_REF_
use pallet_revive::AccountId32Mapper;
use polkadot_sdk::*;
use polkadot_sdk::{
polkadot_sdk_frame::{log, runtime::prelude::*},
polkadot_sdk_frame::runtime::prelude::*,
sp_runtime::{AccountId32, Perbill},
};
@@ -72,6 +72,7 @@ parameter_types! {
#[derive_impl(pallet_revive::config_preludes::TestDefaultConfig)]
impl pallet_revive::Config for Runtime {
type Balance = Balance;
type Time = Timestamp;
type Currency = Balances;
type DepositPerByte = DepositPerByte;
+14 -9
View File
@@ -1,6 +1,6 @@
use std::{str::FromStr, time::Instant};
use polkadot_sdk::pallet_revive::Pallet;
use polkadot_sdk::pallet_revive::{ExecConfig, Pallet, TransactionLimits};
use serde::{Deserialize, Serialize};
use crate::*;
@@ -210,9 +210,9 @@ impl Default for Specs {
Self {
differential: false,
balances: vec![
(ALICE, 1_000_000_000),
(BOB, 1_000_000_000),
(CHARLIE, 1_000_000_000),
(ALICE, 1_000_000_000_000),
(BOB, 1_000_000_000_000),
(CHARLIE, 1_000_000_000_000),
],
actions: Default::default(),
}
@@ -447,12 +447,14 @@ impl Specs {
let result = Contracts::bare_instantiate(
origin,
value.into(),
gas_limit.unwrap_or(GAS_LIMIT),
storage_deposit_limit.unwrap_or(DEPOSIT_LIMIT).into(),
TransactionLimits::WeightAndDeposit {
weight_limit: gas_limit.unwrap_or(GAS_LIMIT),
deposit_limit: storage_deposit_limit.unwrap_or(DEPOSIT_LIMIT),
},
code,
data,
salt.0,
pallet_revive::BumpNonce::No,
ExecConfig::new_substrate_tx(),
);
results.push(CallResult::Instantiate {
result,
@@ -486,9 +488,12 @@ impl Specs {
RuntimeOrigin::signed(origin.to_account_id(&results)),
dest.to_eth_addr(&results),
value.into(),
gas_limit.unwrap_or(GAS_LIMIT),
storage_deposit_limit.unwrap_or(DEPOSIT_LIMIT).into(),
TransactionLimits::WeightAndDeposit {
weight_limit: gas_limit.unwrap_or(GAS_LIMIT),
deposit_limit: storage_deposit_limit.unwrap_or(DEPOSIT_LIMIT),
},
data,
ExecConfig::new_substrate_tx(),
);
results.push(CallResult::Exec {
result,
+1 -1
View File
@@ -9,7 +9,7 @@ description = "Implements the low level runtime API bindings with pallet contrac
[dependencies]
anyhow = { workspace = true }
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm18-1"] }
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm21-1"] }
revive-common = { workspace = true }
+2
View File
@@ -69,6 +69,8 @@ POLKAVM_IMPORT(uint64_t, code_size, uint32_t)
POLKAVM_IMPORT(void, code_hash, uint32_t, uint32_t)
POLKAVM_IMPORT(void, consume_all_gas)
POLKAVM_IMPORT(uint32_t, delegate_call, uint64_t, uint64_t, uint64_t, uint32_t, uint64_t, uint64_t)
POLKAVM_IMPORT(void, deposit_event, uint32_t, uint32_t, uint32_t, uint32_t)
+4 -1
View File
@@ -48,6 +48,8 @@ pub static HASH_KECCAK_256: &str = "hash_keccak_256";
pub static INSTANTIATE: &str = "instantiate";
pub static INVALID: &str = "consume_all_gas";
pub static NOW: &str = "now";
pub static ORIGIN: &str = "origin";
@@ -70,7 +72,7 @@ pub static VALUE_TRANSFERRED: &str = "value_transferred";
/// All imported runtime API symbols.
/// Useful for configuring common attributes and linkage.
pub static IMPORTS: [&str; 33] = [
pub static IMPORTS: [&str; 34] = [
ADDRESS,
BALANCE,
BALANCE_OF,
@@ -94,6 +96,7 @@ pub static IMPORTS: [&str; 33] = [
GET_STORAGE,
HASH_KECCAK_256,
INSTANTIATE,
INVALID,
NOW,
ORIGIN,
REF_TIME_LEFT,
+1 -1
View File
@@ -7,7 +7,7 @@ repository.workspace = true
description = "revive compiler stdlib components"
[dependencies]
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm18-1"] }
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm21-1"] }
[build-dependencies]
revive-build-utils = { workspace = true }
+1 -1
Submodule llvm updated: 3b5b5c1ec4...f68f64eb81