mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 14:31:05 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ddddc989d | |||
| 5992ad0043 | |||
| 2fd96f6188 | |||
| 06d324259c | |||
| 7669320e31 | |||
| ea0ff27c6f | |||
| 60e41a9210 | |||
| 0089d58d85 | |||
| 09c8f64eef | |||
| 4e6c562fac | |||
| 12a8685f11 | |||
| ce1766dc64 | |||
| 2c1097ef36 | |||
| a5ad9a917a | |||
| c929dc9b03 |
@@ -2,6 +2,7 @@ import os
|
||||
import sys
|
||||
import json
|
||||
import requests
|
||||
from datetime import datetime
|
||||
|
||||
def validate_github_token():
|
||||
"""Validate that GITHUB_TOKEN environment variable is set."""
|
||||
@@ -26,70 +27,26 @@ def fetch_release_data(repo, tag):
|
||||
print(f"Error fetching release data: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
def fetch_checksum_file(release_data):
|
||||
"""
|
||||
Fetch the checksum.txt file from the release assets
|
||||
and parse it into a dictionary mapping file names to their SHA256 checksums.
|
||||
"""
|
||||
checksums = {}
|
||||
|
||||
# Find the checksum.txt asset URL
|
||||
checksum_asset = None
|
||||
for asset in release_data['assets']:
|
||||
if asset['name'] == 'checksums.txt':
|
||||
checksum_asset = asset
|
||||
break
|
||||
|
||||
if not checksum_asset:
|
||||
print("Warning: checksum.txt file not found in release assets.")
|
||||
return checksums
|
||||
|
||||
# Download the checksum file
|
||||
headers = {
|
||||
'Authorization': f"Bearer {os.environ['GITHUB_TOKEN']}",
|
||||
'Accept': 'application/octet-stream'
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.get(checksum_asset['browser_download_url'], headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
# Parse checksum file
|
||||
for line in response.text.splitlines():
|
||||
if line.strip():
|
||||
checksum, filename = line.strip().split(None, 1)
|
||||
checksums[filename] = checksum
|
||||
|
||||
return checksums
|
||||
except requests.RequestException as e:
|
||||
print(f"Error fetching checksum file: {e}")
|
||||
return checksums
|
||||
except Exception as e:
|
||||
print(f"Error parsing checksum file: {e}")
|
||||
return checksums
|
||||
|
||||
def extract_build_hash(target_commitish):
|
||||
"""Extract the first 8 characters of the commit hash."""
|
||||
return f"commit.{target_commitish[:8]}"
|
||||
|
||||
def generate_asset_json(release_data, asset, checksums):
|
||||
def generate_asset_json(release_data, asset):
|
||||
"""Generate JSON for a specific asset."""
|
||||
version = release_data['tag_name'].lstrip('v')
|
||||
build = extract_build_hash(release_data['target_commitish'])
|
||||
long_version = f"{version}+{build}"
|
||||
|
||||
# Get SHA256 checksum if available
|
||||
sha256 = checksums.get(asset['name'], "")
|
||||
path = f"{asset['name']}+{long_version}"
|
||||
|
||||
return {
|
||||
"path": path,
|
||||
"name": asset['name'],
|
||||
"version": version,
|
||||
"build": build,
|
||||
"longVersion": long_version,
|
||||
"url": asset['browser_download_url'],
|
||||
"sha256": sha256,
|
||||
"firstSolcVersion": os.environ.get("FIRST_SOLC_VERSION", ""),
|
||||
"lastSolcVersion": os.environ.get("LAST_SOLC_VERSION", "")
|
||||
"firstSolcVersion": os.environ["FIRST_SOLC_VERSION"],
|
||||
"lastSolcVersion": os.environ["LAST_SOLC_VERSION"]
|
||||
}
|
||||
|
||||
def save_platform_json(platform_folder, asset_json, tag):
|
||||
@@ -112,14 +69,14 @@ def save_platform_json(platform_folder, asset_json, tag):
|
||||
# Remove any existing entry with the same path
|
||||
list_data['builds'] = [
|
||||
build for build in list_data['builds']
|
||||
if build['version'] != asset_json['version']
|
||||
if build['path'] != asset_json['path']
|
||||
]
|
||||
# Add the new build
|
||||
list_data['builds'].append(asset_json)
|
||||
|
||||
# Update releases
|
||||
version = asset_json['version']
|
||||
list_data['releases'][version] = f"{asset_json['name']}+{asset_json['longVersion']}"
|
||||
list_data['releases'][version] = asset_json['path']
|
||||
|
||||
# Update latest release
|
||||
list_data['latestRelease'] = version
|
||||
@@ -141,9 +98,6 @@ def main():
|
||||
# Fetch release data
|
||||
release_data = fetch_release_data(repo, tag)
|
||||
|
||||
# Fetch checksums
|
||||
checksums = fetch_checksum_file(release_data)
|
||||
|
||||
# Mapping of asset names to platform folders
|
||||
platform_mapping = {
|
||||
'resolc-x86_64-unknown-linux-musl': 'linux',
|
||||
@@ -157,7 +111,7 @@ def main():
|
||||
platform_name = platform_mapping.get(asset['name'])
|
||||
if platform_name:
|
||||
platform_folder = os.path.join(platform_name)
|
||||
asset_json = generate_asset_json(release_data, asset, checksums)
|
||||
asset_json = generate_asset_json(release_data, asset)
|
||||
save_platform_json(platform_folder, asset_json, tag)
|
||||
print(f"Processed {asset['name']} for {platform_name}")
|
||||
|
||||
|
||||
@@ -249,15 +249,6 @@ jobs:
|
||||
chmod +x resolc-x86_64-unknown-linux-musl
|
||||
chmod +x resolc-universal-apple-darwin
|
||||
|
||||
- name: Create sha-256 checksum
|
||||
run: |
|
||||
shasum -a 256 resolc-x86_64-unknown-linux-musl > checksums.txt
|
||||
shasum -a 256 resolc-universal-apple-darwin >> checksums.txt
|
||||
shasum -a 256 resolc-x86_64-pc-windows-msvc.exe >> checksums.txt
|
||||
shasum -a 256 resolc.js >> checksums.txt
|
||||
shasum -a 256 resolc.wasm >> checksums.txt
|
||||
shasum -a 256 resolc_web.js >> checksums.txt
|
||||
|
||||
- uses: actions/create-github-app-token@v1
|
||||
id: app-token
|
||||
with:
|
||||
@@ -285,4 +276,3 @@ jobs:
|
||||
resolc.js
|
||||
resolc.wasm
|
||||
resolc_web.js
|
||||
checksums.txt
|
||||
|
||||
+1
-14
@@ -6,19 +6,6 @@ This is a development pre-release.
|
||||
|
||||
Supported `polkadot-sdk` rev:`c29e72a8628835e34deb6aa7db9a78a2e4eabcee`
|
||||
|
||||
### Added
|
||||
|
||||
### Changed
|
||||
|
||||
### 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.
|
||||
@@ -27,7 +14,7 @@ Supported `polkadot-sdk` rev:`c29e72a8628835e34deb6aa7db9a78a2e4eabcee`
|
||||
|
||||
### 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.
|
||||
- Runner `resolc` using webkit is no longer supported.
|
||||
|
||||
### Fixed
|
||||
- A missing byte swap for the create2 salt value.
|
||||
|
||||
Generated
+17
-17
@@ -4553,7 +4553,7 @@ checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104"
|
||||
|
||||
[[package]]
|
||||
name = "lld-sys"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
@@ -8266,7 +8266,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-benchmarks"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"alloy-primitives",
|
||||
"criterion",
|
||||
@@ -8278,18 +8278,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-build-utils"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
|
||||
[[package]]
|
||||
name = "revive-builtins"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"revive-build-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "revive-common"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"serde",
|
||||
@@ -8299,7 +8299,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-differential"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"alloy-genesis",
|
||||
"alloy-primitives",
|
||||
@@ -8312,7 +8312,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-integration"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"alloy-primitives",
|
||||
"alloy-sol-types",
|
||||
@@ -8328,7 +8328,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-linker"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"libc",
|
||||
@@ -8340,7 +8340,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-llvm-builder"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
@@ -8362,7 +8362,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-llvm-context"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"hex",
|
||||
@@ -8384,7 +8384,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-runner"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"alloy-primitives",
|
||||
"hex",
|
||||
@@ -8400,7 +8400,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-runtime-api"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"inkwell",
|
||||
@@ -8410,7 +8410,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-solc-json-interface"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"rayon",
|
||||
@@ -8422,7 +8422,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-solidity"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
@@ -8449,7 +8449,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revive-stdlib"
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
dependencies = [
|
||||
"inkwell",
|
||||
"revive-build-utils",
|
||||
@@ -11117,9 +11117,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.44.2"
|
||||
version = "1.43.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48"
|
||||
checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"bytes",
|
||||
|
||||
+15
-15
@@ -3,7 +3,7 @@ resolver = "2"
|
||||
members = ["crates/*"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
authors = [
|
||||
"Cyrill Leutwiler <cyrill@parity.io>",
|
||||
"Parity Technologies <admin@parity.io>",
|
||||
@@ -14,20 +14,20 @@ repository = "https://github.com/paritytech/revive"
|
||||
rust-version = "1.81.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
revive-benchmarks = { version = "0.1.0-dev.13", path = "crates/benchmarks" }
|
||||
revive-builtins = { version = "0.1.0-dev.13", path = "crates/builtins" }
|
||||
revive-common = { version = "0.1.0-dev.13", path = "crates/common" }
|
||||
revive-differential = { version = "0.1.0-dev.13", path = "crates/differential" }
|
||||
revive-integration = { version = "0.1.0-dev.13", path = "crates/integration" }
|
||||
revive-linker = { version = "0.1.0-dev.13", path = "crates/linker" }
|
||||
lld-sys = { version = "0.1.0-dev.13", path = "crates/lld-sys" }
|
||||
revive-llvm-context = { version = "0.1.0-dev.13", path = "crates/llvm-context" }
|
||||
revive-runtime-api = { version = "0.1.0-dev.13", path = "crates/runtime-api" }
|
||||
revive-runner = { version = "0.1.0-dev.13", path = "crates/runner" }
|
||||
revive-solc-json-interface = { version = "0.1.0-dev.13", path = "crates/solc-json-interface" }
|
||||
revive-solidity = { version = "0.1.0-dev.13", path = "crates/solidity" }
|
||||
revive-stdlib = { version = "0.1.0-dev.13", path = "crates/stdlib" }
|
||||
revive-build-utils = { version = "0.1.0-dev.13", path = "crates/build-utils" }
|
||||
revive-benchmarks = { version = "0.1.0-dev.12", path = "crates/benchmarks" }
|
||||
revive-builtins = { version = "0.1.0-dev.12", path = "crates/builtins" }
|
||||
revive-common = { version = "0.1.0-dev.12", path = "crates/common" }
|
||||
revive-differential = { version = "0.1.0-dev.12", path = "crates/differential" }
|
||||
revive-integration = { version = "0.1.0-dev.12", path = "crates/integration" }
|
||||
revive-linker = { version = "0.1.0-dev.12", path = "crates/linker" }
|
||||
lld-sys = { version = "0.1.0-dev.12", path = "crates/lld-sys" }
|
||||
revive-llvm-context = { version = "0.1.0-dev.12", path = "crates/llvm-context" }
|
||||
revive-runtime-api = { version = "0.1.0-dev.12", path = "crates/runtime-api" }
|
||||
revive-runner = { version = "0.1.0-dev.12", path = "crates/runner" }
|
||||
revive-solc-json-interface = { version = "0.1.0-dev.12", path = "crates/solc-json-interface" }
|
||||
revive-solidity = { version = "0.1.0-dev.12", path = "crates/solidity" }
|
||||
revive-stdlib = { version = "0.1.0-dev.12", path = "crates/stdlib" }
|
||||
revive-build-utils = { version = "0.1.0-dev.12", path = "crates/build-utils" }
|
||||
|
||||
hex = "0.4.3"
|
||||
cc = "1.2"
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ RUN make install-llvm-builder
|
||||
RUN revive-llvm --target-env musl clone
|
||||
RUN revive-llvm --target-env musl build --llvm-projects lld --llvm-projects clang
|
||||
|
||||
FROM messense/rust-musl-cross@sha256:68b86bc7cb2867259e6b233415a665ff4469c28b57763e78c3bfea1c68091561 AS resolc-builder
|
||||
FROM messense/rust-musl-cross:x86_64-musl AS resolc-builder
|
||||
WORKDIR /opt/revive
|
||||
|
||||
RUN apt update && \
|
||||
|
||||
@@ -15,58 +15,58 @@
|
||||
|
||||
### Baseline
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:--------|:-------------------------|:-------------------------------- |
|
||||
| **`0`** | `10.08 us` (✅ **1.00x**) | `10.32 us` (✅ **1.02x slower**) |
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:--------|:------------------------|:-------------------------------- |
|
||||
| **`0`** | `3.36 us` (✅ **1.00x**) | `11.84 us` (❌ *3.52x slower*) |
|
||||
|
||||
### OddPorduct
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:-------------|:--------------------------|:-------------------------------- |
|
||||
| **`10000`** | `3.60 ms` (✅ **1.00x**) | `1.57 ms` (🚀 **2.28x faster**) |
|
||||
| **`100000`** | `34.72 ms` (✅ **1.00x**) | `14.82 ms` (🚀 **2.34x faster**) |
|
||||
| **`300000`** | `105.01 ms` (✅ **1.00x**) | `44.11 ms` (🚀 **2.38x faster**) |
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:-------------|:-------------------------|:-------------------------------- |
|
||||
| **`10000`** | `3.11 ms` (✅ **1.00x**) | `1.53 ms` (🚀 **2.03x faster**) |
|
||||
| **`100000`** | `30.70 ms` (✅ **1.00x**) | `15.54 ms` (🚀 **1.98x faster**) |
|
||||
| **`300000`** | `92.68 ms` (✅ **1.00x**) | `45.47 ms` (🚀 **2.04x faster**) |
|
||||
|
||||
### TriangleNumber
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:-------------|:-------------------------|:-------------------------------- |
|
||||
| **`10000`** | `2.43 ms` (✅ **1.00x**) | `1.12 ms` (🚀 **2.17x faster**) |
|
||||
| **`100000`** | `24.20 ms` (✅ **1.00x**) | `10.86 ms` (🚀 **2.23x faster**) |
|
||||
| **`360000`** | `88.69 ms` (✅ **1.00x**) | `38.46 ms` (🚀 **2.31x faster**) |
|
||||
| **`10000`** | `2.29 ms` (✅ **1.00x**) | `1.09 ms` (🚀 **2.11x faster**) |
|
||||
| **`100000`** | `22.84 ms` (✅ **1.00x**) | `10.66 ms` (🚀 **2.14x faster**) |
|
||||
| **`360000`** | `82.29 ms` (✅ **1.00x**) | `37.01 ms` (🚀 **2.22x faster**) |
|
||||
|
||||
### FibonacciRecursive
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:---------|:--------------------------|:--------------------------------- |
|
||||
| **`12`** | `144.17 us` (✅ **1.00x**) | `150.85 us` (✅ **1.05x slower**) |
|
||||
| **`16`** | `938.71 us` (✅ **1.00x**) | `922.11 us` (✅ **1.02x faster**) |
|
||||
| **`20`** | `6.54 ms` (✅ **1.00x**) | `6.20 ms` (✅ **1.05x faster**) |
|
||||
| **`24`** | `45.73 ms` (✅ **1.00x**) | `41.98 ms` (✅ **1.09x faster**) |
|
||||
| **`12`** | `135.67 us` (✅ **1.00x**) | `125.02 us` (✅ **1.09x faster**) |
|
||||
| **`16`** | `903.75 us` (✅ **1.00x**) | `762.79 us` (✅ **1.18x faster**) |
|
||||
| **`20`** | `6.12 ms` (✅ **1.00x**) | `4.96 ms` (✅ **1.23x faster**) |
|
||||
| **`24`** | `42.05 ms` (✅ **1.00x**) | `33.86 ms` (✅ **1.24x faster**) |
|
||||
|
||||
### FibonacciIterative
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:----------|:-------------------------|:-------------------------------- |
|
||||
| **`64`** | `23.00 us` (✅ **1.00x**) | `31.88 us` (❌ *1.39x slower*) |
|
||||
| **`128`** | `35.28 us` (✅ **1.00x**) | `42.43 us` (❌ *1.20x slower*) |
|
||||
| **`256`** | `60.12 us` (✅ **1.00x**) | `61.20 us` (✅ **1.02x slower**) |
|
||||
| **`64`** | `15.04 us` (✅ **1.00x**) | `29.45 us` (❌ *1.96x slower*) |
|
||||
| **`128`** | `26.36 us` (✅ **1.00x**) | `42.19 us` (❌ *1.60x slower*) |
|
||||
| **`256`** | `48.61 us` (✅ **1.00x**) | `65.71 us` (❌ *1.35x slower*) |
|
||||
|
||||
### FibonacciBinet
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:----------|:-------------------------|:-------------------------------- |
|
||||
| **`64`** | `23.01 us` (✅ **1.00x**) | `47.74 us` (❌ *2.07x slower*) |
|
||||
| **`128`** | `25.44 us` (✅ **1.00x**) | `49.67 us` (❌ *1.95x slower*) |
|
||||
| **`256`** | `28.66 us` (✅ **1.00x**) | `53.01 us` (❌ *1.85x slower*) |
|
||||
| **`64`** | `15.22 us` (✅ **1.00x**) | `41.46 us` (❌ *2.72x slower*) |
|
||||
| **`128`** | `17.05 us` (✅ **1.00x**) | `42.84 us` (❌ *2.51x slower*) |
|
||||
| **`256`** | `19.00 us` (✅ **1.00x**) | `44.36 us` (❌ *2.34x slower*) |
|
||||
|
||||
### SHA1
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:----------|:--------------------------|:--------------------------------- |
|
||||
| **`1`** | `135.87 us` (✅ **1.00x**) | `243.75 us` (❌ *1.79x slower*) |
|
||||
| **`64`** | `258.45 us` (✅ **1.00x**) | `355.70 us` (❌ *1.38x slower*) |
|
||||
| **`512`** | `1.10 ms` (✅ **1.00x**) | `1.09 ms` (✅ **1.01x faster**) |
|
||||
| **`1`** | `110.04 us` (✅ **1.00x**) | `216.11 us` (❌ *1.96x slower*) |
|
||||
| **`64`** | `209.04 us` (✅ **1.00x**) | `309.48 us` (❌ *1.48x slower*) |
|
||||
| **`512`** | `903.65 us` (✅ **1.00x**) | `980.49 us` (✅ **1.09x slower**) |
|
||||
|
||||
---
|
||||
Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"Baseline": 950,
|
||||
"Computation": 2222,
|
||||
"DivisionArithmetics": 8802,
|
||||
"ERC20": 17601,
|
||||
"Events": 1628,
|
||||
"FibonacciIterative": 1485,
|
||||
"Flipper": 2089,
|
||||
"SHA1": 8230
|
||||
"Baseline": 1443,
|
||||
"Computation": 2788,
|
||||
"DivisionArithmetics": 9748,
|
||||
"ERC20": 19150,
|
||||
"Events": 2201,
|
||||
"FibonacciIterative": 2041,
|
||||
"Flipper": 2691,
|
||||
"SHA1": 8997
|
||||
}
|
||||
@@ -48,8 +48,6 @@ pub use self::polkavm::context::Context as PolkaVMContext;
|
||||
pub use self::polkavm::evm::arithmetic as polkavm_evm_arithmetic;
|
||||
pub use self::polkavm::evm::bitwise as polkavm_evm_bitwise;
|
||||
pub use self::polkavm::evm::call as polkavm_evm_call;
|
||||
pub use self::polkavm::evm::call::Call as PolkaVMCallFunction;
|
||||
pub use self::polkavm::evm::call::CallReentrancyHeuristic as PolkaVMCallReentrancyHeuristicFunction;
|
||||
pub use self::polkavm::evm::calldata as polkavm_evm_calldata;
|
||||
pub use self::polkavm::evm::comparison as polkavm_evm_comparison;
|
||||
pub use self::polkavm::evm::context as polkavm_evm_contract_context;
|
||||
|
||||
@@ -9,9 +9,6 @@ pub static XLEN: usize = revive_common::BIT_LENGTH_X32;
|
||||
/// The calldata size global variable name.
|
||||
pub static GLOBAL_CALLDATA_SIZE: &str = "calldatasize";
|
||||
|
||||
/// The spill buffer global variable name.
|
||||
pub static GLOBAL_ADDRESS_SPILL_BUFFER: &str = "address_spill_buffer";
|
||||
|
||||
/// The deployer call header size that consists of:
|
||||
/// - bytecode hash (32 bytes)
|
||||
pub const DEPLOYER_CALL_HEADER_SIZE: usize = revive_common::BYTE_LENGTH_WORD;
|
||||
|
||||
@@ -4,98 +4,61 @@
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Argument<'ctx> {
|
||||
/// The actual LLVM operand.
|
||||
pub value: Value<'ctx>,
|
||||
pub value: inkwell::values::BasicValueEnum<'ctx>,
|
||||
/// The original AST value. Used mostly for string literals.
|
||||
pub original: Option<String>,
|
||||
/// The preserved constant value, if available.
|
||||
pub constant: Option<num::BigUint>,
|
||||
}
|
||||
|
||||
/// The function argument can be either a pointer or a integer value.
|
||||
/// This disambiguation allows for lazy loading of variables.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Value<'ctx> {
|
||||
Register(inkwell::values::BasicValueEnum<'ctx>),
|
||||
Pointer {
|
||||
pointer: crate::polkavm::context::Pointer<'ctx>,
|
||||
id: String,
|
||||
},
|
||||
}
|
||||
|
||||
impl<'ctx> Argument<'ctx> {
|
||||
/// A shortcut constructor for register arguments.
|
||||
pub fn value(value: inkwell::values::BasicValueEnum<'ctx>) -> Self {
|
||||
/// The calldata offset argument index.
|
||||
pub const ARGUMENT_INDEX_CALLDATA_OFFSET: usize = 0;
|
||||
|
||||
/// The calldata length argument index.
|
||||
pub const ARGUMENT_INDEX_CALLDATA_LENGTH: usize = 1;
|
||||
|
||||
/// A shortcut constructor.
|
||||
pub fn new(value: inkwell::values::BasicValueEnum<'ctx>) -> Self {
|
||||
Self {
|
||||
value: Value::Register(value),
|
||||
value,
|
||||
original: None,
|
||||
constant: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A shortcut constructor for stack arguments.
|
||||
pub fn pointer(pointer: crate::polkavm::context::Pointer<'ctx>, id: String) -> Self {
|
||||
/// A shortcut constructor.
|
||||
pub fn new_with_original(
|
||||
value: inkwell::values::BasicValueEnum<'ctx>,
|
||||
original: String,
|
||||
) -> Self {
|
||||
Self {
|
||||
value: Value::Pointer { pointer, id },
|
||||
original: None,
|
||||
value,
|
||||
original: Some(original),
|
||||
constant: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the original decleratation value.
|
||||
pub fn with_original(mut self, original: String) -> Self {
|
||||
self.original = Some(original);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the constant value.
|
||||
pub fn with_constant(mut self, constant: num::BigUint) -> Self {
|
||||
self.constant = Some(constant);
|
||||
self
|
||||
/// A shortcut constructor.
|
||||
pub fn new_with_constant(
|
||||
value: inkwell::values::BasicValueEnum<'ctx>,
|
||||
constant: num::BigUint,
|
||||
) -> Self {
|
||||
Self {
|
||||
value,
|
||||
original: None,
|
||||
constant: Some(constant),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the inner LLVM value.
|
||||
///
|
||||
/// Panics if `self` is a pointer argument.
|
||||
pub fn _to_llvm_value(&self) -> inkwell::values::BasicValueEnum<'ctx> {
|
||||
match &self.value {
|
||||
Value::Register(value) => *value,
|
||||
Value::Pointer { .. } => unreachable!("invalid register value access"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Access the underlying value.
|
||||
///
|
||||
/// Will emit a stack load if `self` is a pointer argument.
|
||||
pub fn to_value<D: crate::polkavm::Dependency + Clone>(
|
||||
&self,
|
||||
context: &crate::polkavm::context::Context<'ctx, D>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
|
||||
match &self.value {
|
||||
Value::Register(value) => Ok(*value),
|
||||
Value::Pointer { pointer, id } => context.build_load(*pointer, id),
|
||||
}
|
||||
}
|
||||
|
||||
/// Access the underlying value.
|
||||
///
|
||||
/// Will emit a stack store if `self` is a value argument.
|
||||
pub fn to_pointer<D: crate::polkavm::Dependency + Clone>(
|
||||
&self,
|
||||
context: &crate::polkavm::context::Context<'ctx, D>,
|
||||
) -> anyhow::Result<crate::polkavm::context::Pointer<'ctx>> {
|
||||
match &self.value {
|
||||
Value::Register(value) => {
|
||||
let pointer = context.build_alloca_at_entry(context.word_type(), "pvm_arg");
|
||||
context.build_store(pointer, *value)?;
|
||||
Ok(pointer)
|
||||
}
|
||||
Value::Pointer { pointer, .. } => Ok(*pointer),
|
||||
}
|
||||
pub fn to_llvm(&self) -> inkwell::values::BasicValueEnum<'ctx> {
|
||||
self.value
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx> From<inkwell::values::BasicValueEnum<'ctx>> for Argument<'ctx> {
|
||||
fn from(value: inkwell::values::BasicValueEnum<'ctx>) -> Self {
|
||||
Self::value(value)
|
||||
Self::new(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,14 +31,6 @@ impl Entry {
|
||||
context.xlen_type().get_undef(),
|
||||
);
|
||||
|
||||
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER,
|
||||
address_type,
|
||||
AddressSpace::Stack,
|
||||
address_type.const_zero(),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -750,9 +750,7 @@ where
|
||||
address: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<Pointer<'ctx>> {
|
||||
let address_type = self.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
||||
let address_pointer = self
|
||||
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
|
||||
.into();
|
||||
let address_pointer = self.build_alloca_at_entry(address_type, "address_pointer");
|
||||
let address_truncated =
|
||||
self.builder()
|
||||
.build_int_truncate(address, address_type, "address_truncated")?;
|
||||
|
||||
@@ -19,7 +19,7 @@ where
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context
|
||||
.word_type()
|
||||
.fn_type(&[context.llvm().ptr_type(Default::default()).into()], false)
|
||||
.fn_type(&[context.word_type().into()], false)
|
||||
}
|
||||
|
||||
fn emit_body<'ctx>(
|
||||
@@ -59,7 +59,7 @@ where
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context
|
||||
.word_type()
|
||||
.fn_type(&[context.llvm().ptr_type(Default::default()).into()], false)
|
||||
.fn_type(&[context.word_type().into()], false)
|
||||
}
|
||||
|
||||
fn emit_body<'ctx>(
|
||||
@@ -94,10 +94,7 @@ where
|
||||
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context.void_type().fn_type(
|
||||
&[
|
||||
context.llvm().ptr_type(Default::default()).into(),
|
||||
context.llvm().ptr_type(Default::default()).into(),
|
||||
],
|
||||
&[context.word_type().into(), context.word_type().into()],
|
||||
false,
|
||||
)
|
||||
}
|
||||
@@ -141,10 +138,7 @@ where
|
||||
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context.void_type().fn_type(
|
||||
&[
|
||||
context.llvm().ptr_type(Default::default()).into(),
|
||||
context.llvm().ptr_type(Default::default()).into(),
|
||||
],
|
||||
&[context.word_type().into(), context.word_type().into()],
|
||||
false,
|
||||
)
|
||||
}
|
||||
@@ -179,17 +173,9 @@ where
|
||||
|
||||
fn emit_load<'ctx, D: Dependency + Clone>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
key: BasicValueEnum<'ctx>,
|
||||
mut key: BasicValueEnum<'ctx>,
|
||||
transient: bool,
|
||||
) -> anyhow::Result<BasicValueEnum<'ctx>> {
|
||||
let mut key = context.build_load(
|
||||
super::Pointer::new(
|
||||
context.word_type(),
|
||||
Default::default(),
|
||||
key.into_pointer_value(),
|
||||
),
|
||||
"key",
|
||||
)?;
|
||||
if !transient {
|
||||
key = context.build_byte_swap(key)?;
|
||||
}
|
||||
@@ -231,26 +217,10 @@ fn emit_load<'ctx, D: Dependency + Clone>(
|
||||
|
||||
fn emit_store<'ctx, D: Dependency + Clone>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
key: BasicValueEnum<'ctx>,
|
||||
value: BasicValueEnum<'ctx>,
|
||||
mut key: BasicValueEnum<'ctx>,
|
||||
mut value: BasicValueEnum<'ctx>,
|
||||
transient: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut key = context.build_load(
|
||||
super::Pointer::new(
|
||||
context.word_type(),
|
||||
Default::default(),
|
||||
key.into_pointer_value(),
|
||||
),
|
||||
"key",
|
||||
)?;
|
||||
let mut value = context.build_load(
|
||||
super::Pointer::new(
|
||||
context.word_type(),
|
||||
Default::default(),
|
||||
value.into_pointer_value(),
|
||||
),
|
||||
"key",
|
||||
)?;
|
||||
if !transient {
|
||||
key = context.build_byte_swap(key)?;
|
||||
value = context.build_byte_swap(value)?;
|
||||
|
||||
@@ -63,6 +63,7 @@ where
|
||||
let non_overflow_block = context.append_basic_block("shift_left_non_overflow");
|
||||
let join_block = context.append_basic_block("shift_left_join");
|
||||
|
||||
let result_pointer = context.build_alloca(context.word_type(), "shift_left_result_pointer");
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
shift,
|
||||
@@ -72,6 +73,7 @@ where
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||
|
||||
context.set_basic_block(overflow_block);
|
||||
context.build_store(result_pointer, context.word_const(0))?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(non_overflow_block);
|
||||
@@ -79,17 +81,11 @@ where
|
||||
context
|
||||
.builder()
|
||||
.build_left_shift(value, shift, "shift_left_non_overflow_result")?;
|
||||
context.build_store(result_pointer, value)?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(join_block);
|
||||
let result = context
|
||||
.builder()
|
||||
.build_phi(context.word_type(), "shift_left_value")?;
|
||||
result.add_incoming(&[
|
||||
(&value, non_overflow_block),
|
||||
(&context.word_const(0), overflow_block),
|
||||
]);
|
||||
Ok(result.as_basic_value())
|
||||
context.build_load(result_pointer, "shift_left_result")
|
||||
}
|
||||
|
||||
/// Translates the bitwise shift right.
|
||||
@@ -105,6 +101,7 @@ where
|
||||
let non_overflow_block = context.append_basic_block("shift_right_non_overflow");
|
||||
let join_block = context.append_basic_block("shift_right_join");
|
||||
|
||||
let result_pointer = context.build_alloca(context.word_type(), "shift_right_result_pointer");
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
shift,
|
||||
@@ -114,6 +111,7 @@ where
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||
|
||||
context.set_basic_block(overflow_block);
|
||||
context.build_store(result_pointer, context.word_const(0))?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(non_overflow_block);
|
||||
@@ -123,17 +121,11 @@ where
|
||||
false,
|
||||
"shift_right_non_overflow_result",
|
||||
)?;
|
||||
context.build_store(result_pointer, value)?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(join_block);
|
||||
let result = context
|
||||
.builder()
|
||||
.build_phi(context.word_type(), "shift_right_value")?;
|
||||
result.add_incoming(&[
|
||||
(&value, non_overflow_block),
|
||||
(&context.word_const(0), overflow_block),
|
||||
]);
|
||||
Ok(result.as_basic_value())
|
||||
context.build_load(result_pointer, "shift_right_result")
|
||||
}
|
||||
|
||||
/// Translates the arithmetic bitwise shift right.
|
||||
@@ -153,6 +145,8 @@ where
|
||||
let non_overflow_block = context.append_basic_block("shift_right_arithmetic_non_overflow");
|
||||
let join_block = context.append_basic_block("shift_right_arithmetic_join");
|
||||
|
||||
let result_pointer =
|
||||
context.build_alloca(context.word_type(), "shift_right_arithmetic_result_pointer");
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
shift,
|
||||
@@ -180,9 +174,11 @@ where
|
||||
)?;
|
||||
|
||||
context.set_basic_block(overflow_positive_block);
|
||||
context.build_store(result_pointer, context.word_const(0))?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(overflow_negative_block);
|
||||
context.build_store(result_pointer, context.word_type().const_all_ones())?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(non_overflow_block);
|
||||
@@ -192,21 +188,11 @@ where
|
||||
true,
|
||||
"shift_right_arithmetic_non_overflow_result",
|
||||
)?;
|
||||
context.build_store(result_pointer, value)?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(join_block);
|
||||
let result = context
|
||||
.builder()
|
||||
.build_phi(context.word_type(), "shift_arithmetic_right_value")?;
|
||||
result.add_incoming(&[
|
||||
(&value, non_overflow_block),
|
||||
(
|
||||
&context.word_type().const_all_ones(),
|
||||
overflow_negative_block,
|
||||
),
|
||||
(&context.word_const(0), overflow_block),
|
||||
]);
|
||||
Ok(result.as_basic_value())
|
||||
context.build_load(result_pointer, "shift_right_arithmetic_result")
|
||||
}
|
||||
|
||||
/// Translates the `byte` instruction, extracting the byte of `operand_2`
|
||||
|
||||
@@ -2,310 +2,117 @@
|
||||
|
||||
use inkwell::values::BasicValue;
|
||||
|
||||
use crate::polkavm::context::address_space::AddressSpace;
|
||||
use crate::polkavm::context::argument::Argument;
|
||||
use crate::polkavm::context::pointer::Pointer;
|
||||
use crate::polkavm::context::runtime::RuntimeFunction;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
use crate::polkavm::WriteLLVM;
|
||||
|
||||
const STATIC_CALL_FLAG: u32 = 0b0001_0000;
|
||||
const REENTRANT_CALL_FLAG: u32 = 0b0000_1000;
|
||||
const SOLIDITY_TRANSFER_GAS_STIPEND_THRESHOLD: u64 = 2300;
|
||||
|
||||
pub struct Call;
|
||||
|
||||
impl<D> RuntimeFunction<D> for Call
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
const NAME: &'static str = "__revive_call";
|
||||
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context.xlen_type().fn_type(
|
||||
&[
|
||||
context.xlen_type().into(),
|
||||
context.xlen_type().into(),
|
||||
context.xlen_type().into(),
|
||||
context.xlen_type().into(),
|
||||
context.xlen_type().into(),
|
||||
context.llvm().ptr_type(AddressSpace::Stack.into()).into(),
|
||||
context.llvm().ptr_type(AddressSpace::Stack.into()).into(),
|
||||
context.llvm().ptr_type(AddressSpace::Stack.into()).into(),
|
||||
],
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn emit_body<'ctx>(
|
||||
&self,
|
||||
context: &mut Context<'ctx, D>,
|
||||
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>> {
|
||||
let flags = Self::paramater(context, 0).into_int_value();
|
||||
let input_length = Self::paramater(context, 1).into_int_value();
|
||||
let output_length = Self::paramater(context, 2).into_int_value();
|
||||
let input_pointer = Self::paramater(context, 3).into_int_value();
|
||||
let output_pointer = Self::paramater(context, 4).into_int_value();
|
||||
let address_pointer = Self::paramater(context, 5).into_pointer_value();
|
||||
let value_pointer = Self::paramater(context, 6).into_pointer_value();
|
||||
let deposit_pointer = Self::paramater(context, 7).into_pointer_value();
|
||||
|
||||
let output_length_pointer =
|
||||
context.build_alloca_at_entry(context.xlen_type(), "output_length");
|
||||
context.build_store(output_length_pointer, output_length)?;
|
||||
|
||||
let input_pointer = context.build_heap_gep(input_pointer, input_length)?;
|
||||
let output_pointer = context.build_heap_gep(output_pointer, output_length)?;
|
||||
|
||||
let flags_and_callee = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
flags,
|
||||
Pointer::new(context.word_type(), AddressSpace::Stack, address_pointer).to_int(context),
|
||||
"address_and_callee",
|
||||
)?;
|
||||
let deposit_and_value = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
Pointer::new(context.word_type(), AddressSpace::Stack, deposit_pointer).to_int(context),
|
||||
Pointer::new(context.word_type(), AddressSpace::Stack, value_pointer).to_int(context),
|
||||
"deposit_and_value",
|
||||
)?;
|
||||
let input_data = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
input_length,
|
||||
input_pointer.to_int(context),
|
||||
"input_data",
|
||||
)?;
|
||||
let output_data = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
output_length_pointer.to_int(context),
|
||||
output_pointer.to_int(context),
|
||||
"output_data",
|
||||
)?;
|
||||
|
||||
let name = revive_runtime_api::polkavm_imports::CALL;
|
||||
let success = context
|
||||
.build_runtime_call(
|
||||
name,
|
||||
&[
|
||||
flags_and_callee.into(),
|
||||
context.register_type().const_all_ones().into(),
|
||||
context.register_type().const_all_ones().into(),
|
||||
deposit_and_value.into(),
|
||||
input_data.into(),
|
||||
output_data.into(),
|
||||
],
|
||||
)
|
||||
.unwrap_or_else(|| panic!("{name} should return a value"))
|
||||
.into_int_value();
|
||||
|
||||
let is_success = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::EQ,
|
||||
success,
|
||||
context.integer_const(revive_common::BIT_LENGTH_X64, 0),
|
||||
"is_success",
|
||||
)?;
|
||||
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(is_success, context.xlen_type(), "success")?
|
||||
.as_basic_value_enum()
|
||||
.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> WriteLLVM<D> for Call
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
<Self as RuntimeFunction<_>>::declare(self, context)
|
||||
}
|
||||
|
||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
<Self as RuntimeFunction<_>>::emit(&self, context)
|
||||
}
|
||||
}
|
||||
|
||||
/// Translates a contract call.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn call<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
gas: &Argument<'ctx>,
|
||||
address: &Argument<'ctx>,
|
||||
value: Option<&Argument<'ctx>>,
|
||||
input_offset: &Argument<'ctx>,
|
||||
input_length: &Argument<'ctx>,
|
||||
output_offset: &Argument<'ctx>,
|
||||
output_length: &Argument<'ctx>,
|
||||
gas: inkwell::values::IntValue<'ctx>,
|
||||
address: inkwell::values::IntValue<'ctx>,
|
||||
value: Option<inkwell::values::IntValue<'ctx>>,
|
||||
input_offset: inkwell::values::IntValue<'ctx>,
|
||||
input_length: inkwell::values::IntValue<'ctx>,
|
||||
output_offset: inkwell::values::IntValue<'ctx>,
|
||||
output_length: inkwell::values::IntValue<'ctx>,
|
||||
_constants: Vec<Option<num::BigUint>>,
|
||||
static_call: bool,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let input_offset =
|
||||
context.safe_truncate_int_to_xlen(input_offset.to_value(context)?.into_int_value())?;
|
||||
let input_length =
|
||||
context.safe_truncate_int_to_xlen(input_length.to_value(context)?.into_int_value())?;
|
||||
let address_pointer = context.build_address_argument_store(address)?;
|
||||
|
||||
let output_offset =
|
||||
context.safe_truncate_int_to_xlen(output_offset.to_value(context)?.into_int_value())?;
|
||||
let output_length =
|
||||
context.safe_truncate_int_to_xlen(output_length.to_value(context)?.into_int_value())?;
|
||||
let value = value.unwrap_or_else(|| context.word_const(0));
|
||||
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||
context.build_store(value_pointer, value)?;
|
||||
|
||||
let deposit_limit_pointer =
|
||||
context.build_alloca_at_entry(context.word_type(), "deposit_limit_pointer");
|
||||
let input_offset = context.safe_truncate_int_to_xlen(input_offset)?;
|
||||
let input_length = context.safe_truncate_int_to_xlen(input_length)?;
|
||||
let output_offset = context.safe_truncate_int_to_xlen(output_offset)?;
|
||||
let output_length = context.safe_truncate_int_to_xlen(output_length)?;
|
||||
|
||||
let flags = if static_call {
|
||||
context.build_store(deposit_limit_pointer, context.word_type().const_zero())?;
|
||||
let input_pointer = context.build_heap_gep(input_offset, input_length)?;
|
||||
let output_pointer = context.build_heap_gep(output_offset, output_length)?;
|
||||
|
||||
let output_length_pointer = context.build_alloca_at_entry(context.xlen_type(), "output_length");
|
||||
context.build_store(output_length_pointer, output_length)?;
|
||||
|
||||
let (flags, deposit_limit_value) = if static_call {
|
||||
let flags = REENTRANT_CALL_FLAG | STATIC_CALL_FLAG;
|
||||
context.xlen_type().const_int(flags as u64, false)
|
||||
(
|
||||
context.xlen_type().const_int(flags as u64, false),
|
||||
context.word_type().const_zero(),
|
||||
)
|
||||
} else {
|
||||
let name = <CallReentrancyHeuristic as RuntimeFunction<D>>::NAME;
|
||||
let declaration = <CallReentrancyHeuristic as RuntimeFunction<D>>::declaration(context);
|
||||
let gas = context.builder().build_int_truncate(
|
||||
gas.to_value(context)?.into_int_value(),
|
||||
context.xlen_type(),
|
||||
"gas",
|
||||
)?;
|
||||
let arguments = &[
|
||||
input_length.into(),
|
||||
output_length.into(),
|
||||
gas.into(),
|
||||
deposit_limit_pointer.value.into(),
|
||||
];
|
||||
context
|
||||
.build_call(declaration, arguments, "flags")
|
||||
.unwrap_or_else(|| panic!("runtime function {name} should return a value"))
|
||||
.into_int_value()
|
||||
call_reentrancy_heuristic(context, gas, input_length, output_length)?
|
||||
};
|
||||
|
||||
let value_pointer = match value {
|
||||
Some(argument) => argument.to_pointer(context)?,
|
||||
None => {
|
||||
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||
context.build_store(value_pointer, context.word_const(0))?;
|
||||
value_pointer
|
||||
}
|
||||
};
|
||||
let deposit_pointer = context.build_alloca_at_entry(context.word_type(), "deposit_pointer");
|
||||
context.build_store(deposit_pointer, deposit_limit_value)?;
|
||||
|
||||
let address_pointer =
|
||||
context.build_address_argument_store(address.to_value(context)?.into_int_value())?;
|
||||
let flags_and_callee = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
flags,
|
||||
address_pointer.to_int(context),
|
||||
"address_and_callee",
|
||||
)?;
|
||||
let deposit_and_value = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
deposit_pointer.to_int(context),
|
||||
value_pointer.to_int(context),
|
||||
"deposit_and_value",
|
||||
)?;
|
||||
let input_data = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
input_length,
|
||||
input_pointer.to_int(context),
|
||||
"input_data",
|
||||
)?;
|
||||
let output_data = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
output_length_pointer.to_int(context),
|
||||
output_pointer.to_int(context),
|
||||
"output_data",
|
||||
)?;
|
||||
|
||||
let name = <Call as RuntimeFunction<D>>::NAME;
|
||||
let arguments = &[
|
||||
flags.into(),
|
||||
input_length.into(),
|
||||
output_length.into(),
|
||||
input_offset.into(),
|
||||
output_offset.into(),
|
||||
address_pointer.value.into(),
|
||||
value_pointer.value.into(),
|
||||
deposit_limit_pointer.value.into(),
|
||||
];
|
||||
let declaration = <Call as RuntimeFunction<D>>::declaration(context);
|
||||
let result = context
|
||||
.build_call(declaration, arguments, "call_result_truncated")
|
||||
.unwrap_or_else(|| panic!("runtime function {name} should return a value"))
|
||||
let name = revive_runtime_api::polkavm_imports::CALL;
|
||||
let success = context
|
||||
.build_runtime_call(
|
||||
name,
|
||||
&[
|
||||
flags_and_callee.into(),
|
||||
context.register_type().const_all_ones().into(),
|
||||
context.register_type().const_all_ones().into(),
|
||||
deposit_and_value.into(),
|
||||
input_data.into(),
|
||||
output_data.into(),
|
||||
],
|
||||
)
|
||||
.unwrap_or_else(|| panic!("{name} should return a value"))
|
||||
.into_int_value();
|
||||
|
||||
let is_success = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::EQ,
|
||||
success,
|
||||
context.integer_const(revive_common::BIT_LENGTH_X64, 0),
|
||||
"is_success",
|
||||
)?;
|
||||
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(result, context.word_type(), "call_result")?
|
||||
.build_int_z_extend(is_success, context.word_type(), "success")?
|
||||
.as_basic_value_enum())
|
||||
|
||||
/*
|
||||
let address_pointer = context.build_address_argument_store(address)?;
|
||||
|
||||
let value = value.unwrap_or_else(|| context.word_const(0));
|
||||
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||
context.build_store(value_pointer, value)?;
|
||||
|
||||
let input_offset = context.safe_truncate_int_to_xlen(input_offset)?;
|
||||
let input_length = context.safe_truncate_int_to_xlen(input_length)?;
|
||||
let output_offset = context.safe_truncate_int_to_xlen(output_offset)?;
|
||||
let output_length = context.safe_truncate_int_to_xlen(output_length)?;
|
||||
|
||||
let input_pointer = context.build_heap_gep(input_offset, input_length)?;
|
||||
let output_pointer = context.build_heap_gep(output_offset, output_length)?;
|
||||
|
||||
let output_length_pointer = context.build_alloca_at_entry(context.xlen_type(), "output_length");
|
||||
context.build_store(output_length_pointer, output_length)?;
|
||||
|
||||
let (flags, deposit_limit_value) = if static_call {
|
||||
let flags = REENTRANT_CALL_FLAG | STATIC_CALL_FLAG;
|
||||
(
|
||||
context.xlen_type().const_int(flags as u64, false),
|
||||
context.word_type().const_zero(),
|
||||
)
|
||||
} else {
|
||||
call_reentrancy_heuristic(context, gas, input_length, output_length)?
|
||||
};
|
||||
|
||||
let deposit_pointer = context.build_alloca_at_entry(context.word_type(), "deposit_pointer");
|
||||
context.build_store(deposit_pointer, deposit_limit_value)?;
|
||||
|
||||
let flags_and_callee = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
flags,
|
||||
address_pointer.to_int(context),
|
||||
"address_and_callee",
|
||||
)?;
|
||||
let deposit_and_value = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
deposit_pointer.to_int(context),
|
||||
value_pointer.to_int(context),
|
||||
"deposit_and_value",
|
||||
)?;
|
||||
let input_data = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
input_length,
|
||||
input_pointer.to_int(context),
|
||||
"input_data",
|
||||
)?;
|
||||
let output_data = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
output_length_pointer.to_int(context),
|
||||
output_pointer.to_int(context),
|
||||
"output_data",
|
||||
)?;
|
||||
|
||||
let name = revive_runtime_api::polkavm_imports::CALL;
|
||||
let success = context
|
||||
.build_runtime_call(
|
||||
name,
|
||||
&[
|
||||
flags_and_callee.into(),
|
||||
context.register_type().const_all_ones().into(),
|
||||
context.register_type().const_all_ones().into(),
|
||||
deposit_and_value.into(),
|
||||
input_data.into(),
|
||||
output_data.into(),
|
||||
],
|
||||
)
|
||||
.unwrap_or_else(|| panic!("{name} should return a value"))
|
||||
.into_int_value();
|
||||
|
||||
let is_success = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::EQ,
|
||||
success,
|
||||
context.integer_const(revive_common::BIT_LENGTH_X64, 0),
|
||||
"is_success",
|
||||
)?;
|
||||
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(is_success, context.word_type(), "success")?
|
||||
.as_basic_value_enum())
|
||||
*/
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -409,110 +216,6 @@ where
|
||||
.as_basic_value_enum())
|
||||
}
|
||||
|
||||
pub struct CallReentrancyHeuristic;
|
||||
|
||||
impl<D> RuntimeFunction<D> for CallReentrancyHeuristic
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
const NAME: &'static str = "__revive_call_reentrancy_heuristic";
|
||||
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context.xlen_type().fn_type(
|
||||
&[
|
||||
// Input length
|
||||
context.xlen_type().into(),
|
||||
// Output length
|
||||
context.xlen_type().into(),
|
||||
// Gas
|
||||
context.xlen_type().into(),
|
||||
// Deposit limit value pointer
|
||||
context.llvm().ptr_type(AddressSpace::Stack.into()).into(),
|
||||
],
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn emit_body<'ctx>(
|
||||
&self,
|
||||
context: &mut Context<'ctx, D>,
|
||||
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>> {
|
||||
let input_length = Self::paramater(context, 0).into_int_value();
|
||||
let output_length = Self::paramater(context, 1).into_int_value();
|
||||
let gas = Self::paramater(context, 2).into_int_value();
|
||||
let deposit_pointer = Self::paramater(context, 3).into_pointer_value();
|
||||
|
||||
// Branch-free SSA implementation: First derive the heuristic boolean (int1) value.
|
||||
let input_length_or_output_length = context.builder().build_or(
|
||||
input_length,
|
||||
output_length,
|
||||
"input_length_or_output_length",
|
||||
)?;
|
||||
let is_no_input_no_output = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::EQ,
|
||||
context.xlen_type().const_zero(),
|
||||
input_length_or_output_length,
|
||||
"is_no_input_no_output",
|
||||
)?;
|
||||
let gas_stipend = context
|
||||
.xlen_type()
|
||||
.const_int(SOLIDITY_TRANSFER_GAS_STIPEND_THRESHOLD, false);
|
||||
let is_gas_stipend_for_transfer_or_send = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::EQ,
|
||||
gas,
|
||||
gas_stipend,
|
||||
"is_gas_stipend_for_transfer_or_send",
|
||||
)?;
|
||||
let is_balance_transfer = context.builder().build_and(
|
||||
is_no_input_no_output,
|
||||
is_gas_stipend_for_transfer_or_send,
|
||||
"is_balance_transfer",
|
||||
)?;
|
||||
let is_regular_call = context
|
||||
.builder()
|
||||
.build_not(is_balance_transfer, "is_balance_transfer_inverted")?;
|
||||
|
||||
// Call flag: Left shift the heuristic boolean value.
|
||||
let is_regular_call_xlen = context.builder().build_int_z_extend(
|
||||
is_regular_call,
|
||||
context.xlen_type(),
|
||||
"is_balance_transfer_xlen",
|
||||
)?;
|
||||
let call_flags = context.builder().build_left_shift(
|
||||
is_regular_call_xlen,
|
||||
context.xlen_type().const_int(3, false),
|
||||
"flags",
|
||||
)?;
|
||||
|
||||
// Deposit limit value: Sign-extended the heuristic boolean value.
|
||||
let deposit_limit_value = context.builder().build_int_s_extend(
|
||||
is_regular_call,
|
||||
context.word_type(),
|
||||
"deposit_limit_value",
|
||||
)?;
|
||||
|
||||
context.build_store(
|
||||
Pointer::new(context.word_type(), AddressSpace::Stack, deposit_pointer),
|
||||
deposit_limit_value,
|
||||
)?;
|
||||
|
||||
Ok(Some(call_flags.into()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> WriteLLVM<D> for CallReentrancyHeuristic
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
<Self as RuntimeFunction<_>>::declare(self, context)
|
||||
}
|
||||
|
||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
<Self as RuntimeFunction<_>>::emit(&self, context)
|
||||
}
|
||||
}
|
||||
|
||||
/// The Solidity `address.transfer` and `address.send` call detection heuristic.
|
||||
///
|
||||
/// # Why
|
||||
@@ -533,7 +236,7 @@ where
|
||||
///
|
||||
/// # Returns
|
||||
/// The call flags xlen `IntValue` and the deposit limit word `IntValue`.
|
||||
fn _call_reentrancy_heuristic<'ctx, D>(
|
||||
fn call_reentrancy_heuristic<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
gas: inkwell::values::IntValue<'ctx>,
|
||||
input_length: inkwell::values::IntValue<'ctx>,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use inkwell::values::BasicValue;
|
||||
|
||||
use crate::polkavm::context::pointer::Pointer;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
|
||||
@@ -50,9 +49,7 @@ where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
||||
let address_pointer: Pointer<'_> = context
|
||||
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
|
||||
.into();
|
||||
let address_pointer = context.build_alloca_at_entry(address_type, "origin_address");
|
||||
context.build_store(address_pointer, address_type.const_zero())?;
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::ORIGIN,
|
||||
@@ -100,13 +97,13 @@ where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let output_pointer = context.build_alloca_at_entry(context.word_type(), "blockhash_out_ptr");
|
||||
let index_pointer = context.build_alloca_at_entry(context.word_type(), "blockhash_index_ptr");
|
||||
context.build_store(index_pointer, index)?;
|
||||
let index_ptr = context.build_alloca_at_entry(context.word_type(), "blockhash_index_ptr");
|
||||
context.build_store(index_ptr, index)?;
|
||||
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::BLOCK_HASH,
|
||||
&[
|
||||
index_pointer.to_int(context).into(),
|
||||
index_ptr.to_int(context).into(),
|
||||
output_pointer.to_int(context).into(),
|
||||
],
|
||||
);
|
||||
@@ -130,9 +127,10 @@ pub fn coinbase<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let pointer: Pointer<'_> = context
|
||||
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
|
||||
.into();
|
||||
let pointer = context.build_alloca_at_entry(
|
||||
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
|
||||
"coinbase_output",
|
||||
);
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::BLOCK_AUTHOR,
|
||||
&[pointer.to_int(context).into()],
|
||||
@@ -157,9 +155,10 @@ pub fn address<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let pointer: Pointer<'_> = context
|
||||
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
|
||||
.into();
|
||||
let pointer = context.build_alloca_at_entry(
|
||||
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
|
||||
"address_output",
|
||||
);
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::ADDRESS,
|
||||
&[pointer.to_int(context).into()],
|
||||
@@ -174,9 +173,10 @@ pub fn caller<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let pointer: Pointer<'_> = context
|
||||
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
|
||||
.into();
|
||||
let pointer = context.build_alloca_at_entry(
|
||||
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
|
||||
"address_output",
|
||||
);
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::CALLER,
|
||||
&[pointer.to_int(context).into()],
|
||||
|
||||
@@ -119,8 +119,10 @@ where
|
||||
_ => error,
|
||||
})?;
|
||||
if contract_path.as_str() == parent {
|
||||
return Ok(Argument::value(context.word_const(0).as_basic_value_enum())
|
||||
.with_constant(num::BigUint::zero()));
|
||||
return Ok(Argument::new_with_constant(
|
||||
context.word_const(0).as_basic_value_enum(),
|
||||
num::BigUint::zero(),
|
||||
));
|
||||
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
|
||||
anyhow::bail!("type({}).runtimeCode is not supported", identifier);
|
||||
}
|
||||
@@ -129,7 +131,7 @@ where
|
||||
let hash_value = context
|
||||
.word_const_str_hex(hash_string.as_str())
|
||||
.as_basic_value_enum();
|
||||
Ok(Argument::value(hash_value).with_original(hash_string))
|
||||
Ok(Argument::new_with_original(hash_value, hash_string))
|
||||
}
|
||||
|
||||
/// Translates the deploy call header size instruction. the header consists of
|
||||
@@ -158,8 +160,10 @@ where
|
||||
_ => error,
|
||||
})?;
|
||||
if contract_path.as_str() == parent {
|
||||
return Ok(Argument::value(context.word_const(0).as_basic_value_enum())
|
||||
.with_constant(num::BigUint::zero()));
|
||||
return Ok(Argument::new_with_constant(
|
||||
context.word_const(0).as_basic_value_enum(),
|
||||
num::BigUint::zero(),
|
||||
));
|
||||
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
|
||||
anyhow::bail!("type({}).runtimeCode is not supported", identifier);
|
||||
}
|
||||
@@ -168,5 +172,5 @@ where
|
||||
let size_value = context
|
||||
.word_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64)
|
||||
.as_basic_value_enum();
|
||||
Ok(Argument::value(size_value).with_constant(size_bigint))
|
||||
Ok(Argument::new_with_constant(size_value, size_bigint))
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ pub fn value<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let output_pointer = context.build_alloca_at_entry(context.value_type(), "value_transferred");
|
||||
let output_pointer = context.build_alloca(context.value_type(), "value_transferred");
|
||||
context.build_store(output_pointer, context.word_const(0))?;
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::VALUE_TRANSFERRED,
|
||||
@@ -46,7 +46,8 @@ where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let address_pointer = context.build_address_argument_store(address)?;
|
||||
let balance_pointer = context.build_alloca_at_entry(context.word_type(), "balance_pointer");
|
||||
|
||||
let balance_pointer = context.build_alloca(context.word_type(), "balance_pointer");
|
||||
let balance = context.builder().build_ptr_to_int(
|
||||
balance_pointer.value,
|
||||
context.xlen_type(),
|
||||
@@ -68,7 +69,7 @@ pub fn self_balance<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let balance_pointer = context.build_alloca_at_entry(context.word_type(), "balance_pointer");
|
||||
let balance_pointer = context.build_alloca(context.word_type(), "balance_pointer");
|
||||
let balance = context.builder().build_ptr_to_int(
|
||||
balance_pointer.value,
|
||||
context.xlen_type(),
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
use crate::polkavm::context::runtime::RuntimeFunction;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
use crate::PolkaVMArgument;
|
||||
use crate::PolkaVMLoadStorageWordFunction;
|
||||
use crate::PolkaVMLoadTransientStorageWordFunction;
|
||||
use crate::PolkaVMStoreStorageWordFunction;
|
||||
@@ -12,14 +11,14 @@ use crate::PolkaVMStoreTransientStorageWordFunction;
|
||||
/// Translates the storage load.
|
||||
pub fn load<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
position: &PolkaVMArgument<'ctx>,
|
||||
position: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let name = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::NAME;
|
||||
let declaration = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
||||
let arguments = [position.to_pointer(context)?.value.into()];
|
||||
let arguments = [position.into()];
|
||||
Ok(context
|
||||
.build_call(declaration, &arguments, "storage_load")
|
||||
.unwrap_or_else(|| panic!("runtime function {name} should return a value")))
|
||||
@@ -28,17 +27,14 @@ where
|
||||
/// Translates the storage store.
|
||||
pub fn store<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
position: &PolkaVMArgument<'ctx>,
|
||||
value: &PolkaVMArgument<'ctx>,
|
||||
position: inkwell::values::IntValue<'ctx>,
|
||||
value: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let declaration = <PolkaVMStoreStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
||||
let arguments = [
|
||||
position.to_pointer(context)?.value.into(),
|
||||
value.to_pointer(context)?.value.into(),
|
||||
];
|
||||
let arguments = [position.into(), value.into()];
|
||||
context.build_call(declaration, &arguments, "storage_store");
|
||||
Ok(())
|
||||
}
|
||||
@@ -46,13 +42,13 @@ where
|
||||
/// Translates the transient storage load.
|
||||
pub fn transient_load<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
position: &PolkaVMArgument<'ctx>,
|
||||
position: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let name = <PolkaVMLoadTransientStorageWordFunction as RuntimeFunction<D>>::NAME;
|
||||
let arguments = [position.to_pointer(context)?.value.into()];
|
||||
let arguments = [position.into()];
|
||||
let declaration =
|
||||
<PolkaVMLoadTransientStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
||||
Ok(context
|
||||
@@ -63,18 +59,15 @@ where
|
||||
/// Translates the transient storage store.
|
||||
pub fn transient_store<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
position: &PolkaVMArgument<'ctx>,
|
||||
value: &PolkaVMArgument<'ctx>,
|
||||
position: inkwell::values::IntValue<'ctx>,
|
||||
value: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let declaration =
|
||||
<PolkaVMStoreTransientStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
||||
let arguments = [
|
||||
position.to_pointer(context)?.value.into(),
|
||||
value.to_pointer(context)?.value.into(),
|
||||
];
|
||||
let arguments = [position.into(), value.into()];
|
||||
context.build_call(declaration, &arguments, "transient_storage_store");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ pub fn build_solidity_with_options(
|
||||
SolcStandardJsonInputSettingsSelection::new_required(),
|
||||
SolcStandardJsonInputSettingsOptimizer::new(
|
||||
solc_optimizer_enabled,
|
||||
optimizer_settings.middle_end_as_string().chars().last(),
|
||||
None,
|
||||
&solc_version.default,
|
||||
false,
|
||||
),
|
||||
@@ -102,21 +102,16 @@ pub fn build_solidity_with_options(
|
||||
|
||||
let mut output = solc.standard_json(input, None, vec![], None)?;
|
||||
|
||||
let debug_config = revive_llvm_context::DebugConfig::new(
|
||||
None,
|
||||
optimizer_settings.middle_end_as_string() != "z",
|
||||
);
|
||||
|
||||
let project = Project::try_from_standard_json_output(
|
||||
&output,
|
||||
sources,
|
||||
libraries,
|
||||
&solc_version,
|
||||
&debug_config,
|
||||
&DEBUG_CONFIG,
|
||||
)?;
|
||||
|
||||
let build: crate::Build =
|
||||
project.compile(optimizer_settings, false, debug_config, Default::default())?;
|
||||
project.compile(optimizer_settings, false, DEBUG_CONFIG, Default::default())?;
|
||||
build.write_to_standard_json(&mut output, &solc_version)?;
|
||||
|
||||
Ok(output)
|
||||
|
||||
@@ -139,14 +139,13 @@ where
|
||||
identifier.inner,
|
||||
)
|
||||
})?;
|
||||
context.build_store(pointer, value.to_value(context)?)?;
|
||||
context.build_store(pointer, value.to_llvm())?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let value = value.to_value(context)?;
|
||||
let llvm_type = value.into_struct_value().get_type();
|
||||
let llvm_type = value.to_llvm().into_struct_value().get_type();
|
||||
let tuple_pointer = context.build_alloca(llvm_type, "assignment_pointer");
|
||||
context.build_store(tuple_pointer, value)?;
|
||||
context.build_store(tuple_pointer, value.to_llvm())?;
|
||||
|
||||
for (index, binding) in self.bindings.into_iter().enumerate() {
|
||||
context.set_debug_location(self.location.line, 0, None)?;
|
||||
|
||||
@@ -128,10 +128,7 @@ impl FunctionCall {
|
||||
Name::UserDefined(name) => {
|
||||
let mut values = Vec::with_capacity(self.arguments.len());
|
||||
for argument in self.arguments.into_iter().rev() {
|
||||
let value = argument
|
||||
.into_llvm(context)?
|
||||
.expect("Always exists")
|
||||
.to_value(context)?;
|
||||
let value = argument.into_llvm(context)?.expect("Always exists").value;
|
||||
values.push(value);
|
||||
}
|
||||
values.reverse();
|
||||
@@ -464,29 +461,36 @@ impl FunctionCall {
|
||||
}
|
||||
|
||||
Name::SLoad => {
|
||||
let arguments = self.pop_arguments::<D, 1>(context)?;
|
||||
revive_llvm_context::polkavm_evm_storage::load(context, &arguments[0]).map(Some)
|
||||
let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
|
||||
revive_llvm_context::polkavm_evm_storage::load(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::SStore => {
|
||||
let arguments = self.pop_arguments::<D, 2>(context)?;
|
||||
let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
|
||||
revive_llvm_context::polkavm_evm_storage::store(
|
||||
context,
|
||||
&arguments[0],
|
||||
&arguments[1],
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
)
|
||||
.map(|_| None)
|
||||
}
|
||||
Name::TLoad => {
|
||||
let arguments = self.pop_arguments::<D, 1>(context)?;
|
||||
revive_llvm_context::polkavm_evm_storage::transient_load(context, &arguments[0])
|
||||
.map(Some)
|
||||
let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
|
||||
revive_llvm_context::polkavm_evm_storage::transient_load(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::TStore => {
|
||||
let arguments = self.pop_arguments::<D, 2>(context)?;
|
||||
let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
|
||||
revive_llvm_context::polkavm_evm_storage::transient_store(
|
||||
context,
|
||||
&arguments[0],
|
||||
&arguments[1],
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
)
|
||||
.map(|_| None)
|
||||
}
|
||||
@@ -510,7 +514,7 @@ impl FunctionCall {
|
||||
let offset = context.solidity_mut().allocate_immutable(key.as_str())
|
||||
/ revive_common::BYTE_LENGTH_WORD;
|
||||
let index = context.xlen_type().const_int(offset as u64, false);
|
||||
let value = arguments[2].to_value(context)?.into_int_value();
|
||||
let value = arguments[2].value.into_int_value();
|
||||
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
|
||||
.map(|_| None)
|
||||
}
|
||||
@@ -716,16 +720,15 @@ impl FunctionCall {
|
||||
Name::Call => {
|
||||
let arguments = self.pop_arguments::<D, 7>(context)?;
|
||||
|
||||
let gas = &arguments[0];
|
||||
let address = &arguments[1];
|
||||
let value = &arguments[2];
|
||||
let input_offset = &arguments[3];
|
||||
let input_size = &arguments[4];
|
||||
let output_offset = &arguments[5];
|
||||
let output_size = &arguments[6];
|
||||
let gas = arguments[0].value.into_int_value();
|
||||
let address = arguments[1].value.into_int_value();
|
||||
let value = arguments[2].value.into_int_value();
|
||||
let input_offset = arguments[3].value.into_int_value();
|
||||
let input_size = arguments[4].value.into_int_value();
|
||||
let output_offset = arguments[5].value.into_int_value();
|
||||
let output_size = arguments[6].value.into_int_value();
|
||||
|
||||
let simulation_address: Vec<Option<num::BigUint>> = arguments
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|mut argument| argument.constant.take())
|
||||
.collect();
|
||||
@@ -747,15 +750,14 @@ impl FunctionCall {
|
||||
Name::StaticCall => {
|
||||
let arguments = self.pop_arguments::<D, 6>(context)?;
|
||||
|
||||
let gas = &arguments[0];
|
||||
let address = &arguments[1];
|
||||
let input_offset = &arguments[2];
|
||||
let input_size = &arguments[3];
|
||||
let output_offset = &arguments[4];
|
||||
let output_size = &arguments[5];
|
||||
let gas = arguments[0].value.into_int_value();
|
||||
let address = arguments[1].value.into_int_value();
|
||||
let input_offset = arguments[2].value.into_int_value();
|
||||
let input_size = arguments[3].value.into_int_value();
|
||||
let output_offset = arguments[4].value.into_int_value();
|
||||
let output_size = arguments[5].value.into_int_value();
|
||||
|
||||
let simulation_address: Vec<Option<num::BigUint>> = arguments
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|mut argument| argument.constant.take())
|
||||
.collect();
|
||||
@@ -777,12 +779,12 @@ impl FunctionCall {
|
||||
Name::DelegateCall => {
|
||||
let arguments = self.pop_arguments::<D, 6>(context)?;
|
||||
|
||||
let gas = arguments[0].to_value(context)?.into_int_value();
|
||||
let address = arguments[1].to_value(context)?.into_int_value();
|
||||
let input_offset = arguments[2].to_value(context)?.into_int_value();
|
||||
let input_size = arguments[3].to_value(context)?.into_int_value();
|
||||
let output_offset = arguments[4].to_value(context)?.into_int_value();
|
||||
let output_size = arguments[5].to_value(context)?.into_int_value();
|
||||
let gas = arguments[0].value.into_int_value();
|
||||
let address = arguments[1].value.into_int_value();
|
||||
let input_offset = arguments[2].value.into_int_value();
|
||||
let input_size = arguments[3].value.into_int_value();
|
||||
let output_offset = arguments[4].value.into_int_value();
|
||||
let output_size = arguments[5].value.into_int_value();
|
||||
|
||||
let simulation_address: Vec<Option<num::BigUint>> = arguments
|
||||
.into_iter()
|
||||
@@ -843,8 +845,7 @@ impl FunctionCall {
|
||||
})?;
|
||||
|
||||
revive_llvm_context::polkavm_evm_create::contract_hash(context, identifier)
|
||||
.and_then(|argument| argument.to_value(context))
|
||||
.map(Some)
|
||||
.map(|argument| Some(argument.value))
|
||||
}
|
||||
Name::DataSize => {
|
||||
let mut arguments = self.pop_arguments::<D, 1>(context)?;
|
||||
@@ -854,8 +855,7 @@ impl FunctionCall {
|
||||
})?;
|
||||
|
||||
revive_llvm_context::polkavm_evm_create::header_size(context, identifier)
|
||||
.and_then(|argument| argument.to_value(context))
|
||||
.map(Some)
|
||||
.map(|argument| Some(argument.value))
|
||||
}
|
||||
Name::DataCopy => {
|
||||
let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
|
||||
@@ -989,12 +989,7 @@ impl FunctionCall {
|
||||
{
|
||||
let mut arguments = Vec::with_capacity(N);
|
||||
for expression in self.arguments.drain(0..N).rev() {
|
||||
arguments.push(
|
||||
expression
|
||||
.into_llvm(context)?
|
||||
.expect("Always exists")
|
||||
.to_value(context)?,
|
||||
);
|
||||
arguments.push(expression.into_llvm(context)?.expect("Always exists").value);
|
||||
}
|
||||
arguments.reverse();
|
||||
|
||||
|
||||
@@ -97,7 +97,9 @@ impl Literal {
|
||||
BooleanLiteral::True => num::BigUint::one(),
|
||||
};
|
||||
|
||||
Ok(revive_llvm_context::PolkaVMArgument::value(value).with_constant(constant))
|
||||
Ok(revive_llvm_context::PolkaVMArgument::new_with_constant(
|
||||
value, constant,
|
||||
))
|
||||
}
|
||||
LexicalLiteral::Integer(inner) => {
|
||||
let r#type = self.yul_type.unwrap_or_default().into_llvm(context);
|
||||
@@ -125,7 +127,9 @@ impl Literal {
|
||||
}
|
||||
.expect("Always valid");
|
||||
|
||||
Ok(revive_llvm_context::PolkaVMArgument::value(value).with_constant(constant))
|
||||
Ok(revive_llvm_context::PolkaVMArgument::new_with_constant(
|
||||
value, constant,
|
||||
))
|
||||
}
|
||||
LexicalLiteral::String(inner) => {
|
||||
let string = inner.inner;
|
||||
@@ -196,10 +200,10 @@ impl Literal {
|
||||
};
|
||||
|
||||
if hex_string.len() > revive_common::BYTE_LENGTH_WORD * 2 {
|
||||
return Ok(revive_llvm_context::PolkaVMArgument::value(
|
||||
return Ok(revive_llvm_context::PolkaVMArgument::new_with_original(
|
||||
r#type.const_zero().as_basic_value_enum(),
|
||||
)
|
||||
.with_original(string));
|
||||
string,
|
||||
));
|
||||
}
|
||||
|
||||
if hex_string.len() < revive_common::BYTE_LENGTH_WORD * 2 {
|
||||
@@ -216,7 +220,9 @@ impl Literal {
|
||||
)
|
||||
.expect("The value is valid")
|
||||
.as_basic_value_enum();
|
||||
Ok(revive_llvm_context::PolkaVMArgument::value(value).with_original(string))
|
||||
Ok(revive_llvm_context::PolkaVMArgument::new_with_original(
|
||||
value, string,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,28 +119,36 @@ impl Expression {
|
||||
})
|
||||
.map(Some),
|
||||
Self::Identifier(identifier) => {
|
||||
let id = identifier.inner;
|
||||
|
||||
let pointer = context
|
||||
.current_function()
|
||||
.borrow()
|
||||
.get_stack_pointer(&id)
|
||||
.get_stack_pointer(identifier.inner.as_str())
|
||||
.ok_or_else(|| {
|
||||
anyhow::anyhow!("{} Undeclared variable `{}`", identifier.location, id)
|
||||
anyhow::anyhow!(
|
||||
"{} Undeclared variable `{}`",
|
||||
identifier.location,
|
||||
identifier.inner,
|
||||
)
|
||||
})?;
|
||||
|
||||
let constant = context.current_function().borrow().yul().get_constant(&id);
|
||||
let constant = context
|
||||
.current_function()
|
||||
.borrow()
|
||||
.yul()
|
||||
.get_constant(identifier.inner.as_str());
|
||||
|
||||
let argument = revive_llvm_context::PolkaVMArgument::pointer(pointer, id);
|
||||
let value = context.build_load(pointer, identifier.inner.as_str())?;
|
||||
|
||||
Ok(Some(match constant {
|
||||
Some(constant) => argument.with_constant(constant),
|
||||
_ => argument,
|
||||
}))
|
||||
match constant {
|
||||
Some(constant) => Ok(Some(
|
||||
revive_llvm_context::PolkaVMArgument::new_with_constant(value, constant),
|
||||
)),
|
||||
None => Ok(Some(value.into())),
|
||||
}
|
||||
}
|
||||
Self::FunctionCall(call) => Ok(call
|
||||
.into_llvm(context)?
|
||||
.map(revive_llvm_context::PolkaVMArgument::value)),
|
||||
.map(revive_llvm_context::PolkaVMArgument::new)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ where
|
||||
.condition
|
||||
.into_llvm(context)?
|
||||
.expect("Always exists")
|
||||
.to_value(context)?
|
||||
.to_llvm()
|
||||
.into_int_value();
|
||||
let condition = context.builder().build_int_z_extend_or_bit_cast(
|
||||
condition,
|
||||
|
||||
@@ -57,7 +57,7 @@ where
|
||||
.condition
|
||||
.into_llvm(context)?
|
||||
.expect("Always exists")
|
||||
.to_value(context)?
|
||||
.to_llvm()
|
||||
.into_int_value();
|
||||
let condition = context.builder().build_int_z_extend_or_bit_cast(
|
||||
condition,
|
||||
|
||||
@@ -188,9 +188,6 @@ where
|
||||
revive_llvm_context::PolkaVMLoadImmutableDataFunction.declare(context)?;
|
||||
revive_llvm_context::PolkaVMStoreImmutableDataFunction.declare(context)?;
|
||||
|
||||
revive_llvm_context::PolkaVMCallFunction.declare(context)?;
|
||||
revive_llvm_context::PolkaVMCallReentrancyHeuristicFunction.declare(context)?;
|
||||
|
||||
revive_llvm_context::PolkaVMLoadHeapWordFunction.declare(context)?;
|
||||
revive_llvm_context::PolkaVMStoreHeapWordFunction.declare(context)?;
|
||||
revive_llvm_context::PolkaVMLoadStorageWordFunction.declare(context)?;
|
||||
@@ -243,9 +240,6 @@ where
|
||||
revive_llvm_context::PolkaVMLoadImmutableDataFunction.into_llvm(context)?;
|
||||
revive_llvm_context::PolkaVMStoreImmutableDataFunction.into_llvm(context)?;
|
||||
|
||||
revive_llvm_context::PolkaVMCallFunction.into_llvm(context)?;
|
||||
revive_llvm_context::PolkaVMCallReentrancyHeuristicFunction.into_llvm(context)?;
|
||||
|
||||
revive_llvm_context::PolkaVMLoadHeapWordFunction.into_llvm(context)?;
|
||||
revive_llvm_context::PolkaVMStoreHeapWordFunction.into_llvm(context)?;
|
||||
revive_llvm_context::PolkaVMLoadStorageWordFunction.into_llvm(context)?;
|
||||
|
||||
@@ -137,7 +137,7 @@ where
|
||||
|
||||
let mut branches = Vec::with_capacity(self.cases.len());
|
||||
for (index, case) in self.cases.into_iter().enumerate() {
|
||||
let constant = case.literal.into_llvm(context)?.to_value(context)?;
|
||||
let constant = case.literal.into_llvm(context)?.to_llvm();
|
||||
|
||||
let expression_block = context
|
||||
.append_basic_block(format!("switch_case_branch_{}_block", index + 1).as_str());
|
||||
@@ -161,10 +161,7 @@ where
|
||||
|
||||
context.set_basic_block(current_block);
|
||||
context.builder().build_switch(
|
||||
scrutinee
|
||||
.expect("Always exists")
|
||||
.to_value(context)?
|
||||
.into_int_value(),
|
||||
scrutinee.expect("Always exists").to_llvm().into_int_value(),
|
||||
default_block,
|
||||
branches.as_slice(),
|
||||
)?;
|
||||
|
||||
@@ -121,7 +121,7 @@ where
|
||||
.insert_constant(identifier.inner.clone(), constant);
|
||||
}
|
||||
|
||||
value.to_value(context)?
|
||||
value.to_llvm()
|
||||
}
|
||||
None => r#type.const_zero().as_basic_value_enum(),
|
||||
}
|
||||
@@ -175,8 +175,7 @@ where
|
||||
.collect::<Vec<inkwell::types::BasicTypeEnum<'ctx>>>()
|
||||
.as_slice(),
|
||||
);
|
||||
let value = expression.to_value(context)?;
|
||||
if value.get_type() != llvm_type.as_basic_type_enum() {
|
||||
if expression.value.get_type() != llvm_type.as_basic_type_enum() {
|
||||
anyhow::bail!(
|
||||
"{} Assignment to {:?} received an invalid number of arguments",
|
||||
location,
|
||||
@@ -184,7 +183,7 @@ where
|
||||
);
|
||||
}
|
||||
let pointer = context.build_alloca(llvm_type, "bindings_pointer");
|
||||
context.build_store(pointer, value)?;
|
||||
context.build_store(pointer, expression.to_llvm())?;
|
||||
|
||||
for (index, binding) in self.bindings.into_iter().enumerate() {
|
||||
let pointer = context.build_gep(
|
||||
|
||||
Reference in New Issue
Block a user