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