mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 19:11:04 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 528da2d9c9 | |||
| a25937ae79 |
@@ -1,4 +1,4 @@
|
||||
name: "Get Emscripten SDK"
|
||||
name: "get emsdk"
|
||||
inputs:
|
||||
version:
|
||||
description: ""
|
||||
@@ -9,6 +9,7 @@ inputs:
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
|
||||
- name: install emsdk
|
||||
shell: bash
|
||||
run: |
|
||||
@@ -16,4 +17,4 @@ runs:
|
||||
cd emsdk
|
||||
git checkout tags/${{ inputs.version }}
|
||||
./emsdk install ${{ inputs.version }}
|
||||
./emsdk activate ${{ inputs.version }}
|
||||
./emsdk activate ${{ inputs.version }}
|
||||
@@ -1,12 +1,29 @@
|
||||
# example:
|
||||
# - uses: ./.github/actions/get-llvm
|
||||
#
|
||||
# - name: get llvm
|
||||
# uses: ./.github/actions/get-llvm
|
||||
# with:
|
||||
# target: x86_64-unknown-linux-gnu
|
||||
# releasePrefix: llvm-
|
||||
# artifactArch: macos-arm64
|
||||
# dir: target-llvm/macos
|
||||
|
||||
name: "Download LLVM"
|
||||
name: "get llvm"
|
||||
inputs:
|
||||
target:
|
||||
artifactArch:
|
||||
required: true
|
||||
releasePrefix:
|
||||
description: "LLVM release tag prefix to search"
|
||||
required: false
|
||||
default: "llvm-"
|
||||
dir:
|
||||
description: "Archive extract path (`tar -C`)"
|
||||
required: false
|
||||
default: "./"
|
||||
stripComponents:
|
||||
description: "Strip UMBER leading components from file names on extraction (`tar --strip-components`)"
|
||||
required: false
|
||||
default: 0
|
||||
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
@@ -15,15 +32,16 @@ runs:
|
||||
id: find
|
||||
uses: actions/github-script@v7
|
||||
env:
|
||||
target: ${{ inputs.target }}
|
||||
releasePrefix: ${{ inputs.releasePrefix }}
|
||||
artifactArch: ${{ inputs.artifactArch }}
|
||||
with:
|
||||
result-encoding: string
|
||||
script: |
|
||||
let page = 1;
|
||||
let releases = [];
|
||||
|
||||
let releasePrefix = "llvm-"
|
||||
let target = process.env.target
|
||||
let releasePrefix = process.env.releasePrefix
|
||||
let artifactArch = process.env.artifactArch
|
||||
|
||||
do {
|
||||
const res = await github.rest.repos.listReleases({
|
||||
@@ -43,10 +61,10 @@ runs:
|
||||
});
|
||||
if (llvmLatestRelease){
|
||||
let asset = llvmLatestRelease.assets.find(asset =>{
|
||||
return asset.name.includes(target);
|
||||
return asset.name.includes(artifactArch);
|
||||
});
|
||||
if (!asset){
|
||||
core.setFailed(`Artifact for '${target}' not found in release ${llvmLatestRelease.tag_name} (${llvmLatestRelease.html_url})`);
|
||||
core.setFailed(`Artifact for '${artifactArch}' not found in release ${llvmLatestRelease.tag_name} (${llvmLatestRelease.html_url})`);
|
||||
process.exit();
|
||||
}
|
||||
return asset.browser_download_url;
|
||||
@@ -61,10 +79,13 @@ runs:
|
||||
- name: download
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p ${{ inputs.dir }}
|
||||
curl -sSLo llvm.tar.gz ${{ steps.find.outputs.result }}
|
||||
ls -al
|
||||
|
||||
- name: unpack
|
||||
shell: bash
|
||||
run: |
|
||||
tar -xf llvm.tar.gz
|
||||
tar -xf llvm.tar.gz -C ${{ inputs.dir }} --strip-components=${{ inputs.stripComponents }}
|
||||
rm llvm.tar.gz
|
||||
ls -al ${{ inputs.dir }}
|
||||
@@ -1,36 +0,0 @@
|
||||
name: "Install Solidity Compiler"
|
||||
description: "Installs the Ethereum solc Solidity compiler frontend executable"
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Figure out Solc Download URL
|
||||
shell: bash
|
||||
run: |
|
||||
if [[ "${{ runner.os }}" == "Linux" ]]; then
|
||||
echo "SOLC_NAME=solc-static-linux" >> $GITHUB_ENV
|
||||
elif [[ "${{ runner.os }}" == "Windows" ]]; then
|
||||
echo "SOLC_NAME=solc-windows.exe" >> $GITHUB_ENV
|
||||
else
|
||||
echo "SOLC_NAME=solc-macos" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Download Solc
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p solc
|
||||
curl -sSL --output solc/solc https://github.com/ethereum/solidity/releases/download/v0.8.29/${SOLC_NAME}
|
||||
|
||||
- name: Make Solc Executable
|
||||
if: ${{ runner.os == 'Windows' }}
|
||||
shell: bash
|
||||
run: |
|
||||
echo "$(pwd -W)\\solc" >> $GITHUB_PATH
|
||||
mv solc/solc solc/solc.exe
|
||||
|
||||
- name: Make Solc Executable
|
||||
if: ${{ runner.os != 'Windows' }}
|
||||
shell: bash
|
||||
run: |
|
||||
echo "$(pwd)/solc" >> $GITHUB_PATH
|
||||
chmod +x solc/solc
|
||||
@@ -1,165 +0,0 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import requests
|
||||
|
||||
def validate_github_token():
|
||||
"""Validate that GITHUB_TOKEN environment variable is set."""
|
||||
if 'GITHUB_TOKEN' not in os.environ:
|
||||
print("Error: GITHUB_TOKEN environment variable is not set.")
|
||||
sys.exit(1)
|
||||
|
||||
def fetch_release_data(repo, tag):
|
||||
"""Fetch release data from GitHub API."""
|
||||
url = f"https://api.github.com/repos/{repo}/releases/tags/{tag}"
|
||||
headers = {
|
||||
'Authorization': f"Bearer {os.environ['GITHUB_TOKEN']}",
|
||||
'Accept': 'application/vnd.github+json',
|
||||
'X-GitHub-Api-Version': '2022-11-28'
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.get(url, headers=headers)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except requests.RequestException as e:
|
||||
print(f"Error fetching release data: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
def fetch_checksum_file(release_data):
|
||||
"""
|
||||
Fetch the checksum.txt file from the release assets
|
||||
and parse it into a dictionary mapping file names to their SHA256 checksums.
|
||||
"""
|
||||
checksums = {}
|
||||
|
||||
# Find the checksum.txt asset URL
|
||||
checksum_asset = None
|
||||
for asset in release_data['assets']:
|
||||
if asset['name'] == 'checksums.txt':
|
||||
checksum_asset = asset
|
||||
break
|
||||
|
||||
if not checksum_asset:
|
||||
print("Warning: checksum.txt file not found in release assets.")
|
||||
return checksums
|
||||
|
||||
# Download the checksum file
|
||||
headers = {
|
||||
'Authorization': f"Bearer {os.environ['GITHUB_TOKEN']}",
|
||||
'Accept': 'application/octet-stream'
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.get(checksum_asset['browser_download_url'], headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
# Parse checksum file
|
||||
for line in response.text.splitlines():
|
||||
if line.strip():
|
||||
checksum, filename = line.strip().split(None, 1)
|
||||
checksums[filename] = checksum
|
||||
|
||||
return checksums
|
||||
except requests.RequestException as e:
|
||||
print(f"Error fetching checksum file: {e}")
|
||||
return checksums
|
||||
except Exception as e:
|
||||
print(f"Error parsing checksum file: {e}")
|
||||
return checksums
|
||||
|
||||
def extract_build_hash(target_commitish):
|
||||
"""Extract the first 8 characters of the commit hash."""
|
||||
return f"commit.{target_commitish[:8]}"
|
||||
|
||||
def generate_asset_json(release_data, asset, checksums):
|
||||
"""Generate JSON for a specific asset."""
|
||||
version = release_data['tag_name'].lstrip('v')
|
||||
build = extract_build_hash(release_data['target_commitish'])
|
||||
long_version = f"{version}+{build}"
|
||||
|
||||
# Get SHA256 checksum if available
|
||||
sha256 = checksums.get(asset['name'], "")
|
||||
|
||||
return {
|
||||
"name": asset['name'],
|
||||
"version": version,
|
||||
"build": build,
|
||||
"longVersion": long_version,
|
||||
"url": asset['browser_download_url'],
|
||||
"sha256": sha256,
|
||||
"firstSolcVersion": os.environ.get("FIRST_SOLC_VERSION", ""),
|
||||
"lastSolcVersion": os.environ.get("LAST_SOLC_VERSION", "")
|
||||
}
|
||||
|
||||
def save_platform_json(platform_folder, asset_json, tag):
|
||||
"""Save asset JSON and update list.json for a specific platform."""
|
||||
# Create platform folder if it doesn't exist
|
||||
os.makedirs(platform_folder, exist_ok=True)
|
||||
|
||||
# Update or create list.json
|
||||
list_file_path = os.path.join(platform_folder, "list.json")
|
||||
|
||||
if os.path.exists(list_file_path):
|
||||
with open(list_file_path, 'r') as f:
|
||||
try:
|
||||
list_data = json.load(f)
|
||||
except json.JSONDecodeError:
|
||||
list_data = {"builds": [], "releases": {}, "latestRelease": ""}
|
||||
else:
|
||||
list_data = {"builds": [], "releases": {}, "latestRelease": ""}
|
||||
|
||||
# Remove any existing entry with the same path
|
||||
list_data['builds'] = [
|
||||
build for build in list_data['builds']
|
||||
if build['version'] != asset_json['version']
|
||||
]
|
||||
# Add the new build
|
||||
list_data['builds'].append(asset_json)
|
||||
|
||||
# Update releases
|
||||
version = asset_json['version']
|
||||
list_data['releases'][version] = f"{asset_json['name']}+{asset_json['longVersion']}"
|
||||
|
||||
# Update latest release
|
||||
list_data['latestRelease'] = version
|
||||
|
||||
with open(list_file_path, 'w') as f:
|
||||
json.dump(list_data, f, indent=4)
|
||||
|
||||
def main():
|
||||
# Validate arguments
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: python script.py <repo> <tag>")
|
||||
sys.exit(1)
|
||||
|
||||
repo, tag = sys.argv[1], sys.argv[2]
|
||||
|
||||
# Validate GitHub token
|
||||
validate_github_token()
|
||||
|
||||
# Fetch release data
|
||||
release_data = fetch_release_data(repo, tag)
|
||||
|
||||
# Fetch checksums
|
||||
checksums = fetch_checksum_file(release_data)
|
||||
|
||||
# Mapping of asset names to platform folders
|
||||
platform_mapping = {
|
||||
'resolc-x86_64-unknown-linux-musl': 'linux',
|
||||
'resolc-universal-apple-darwin': 'macos',
|
||||
'resolc-x86_64-pc-windows-msvc.exe': 'windows',
|
||||
'resolc_web.js': 'wasm'
|
||||
}
|
||||
|
||||
# Process each asset
|
||||
for asset in release_data['assets']:
|
||||
platform_name = platform_mapping.get(asset['name'])
|
||||
if platform_name:
|
||||
platform_folder = os.path.join(platform_name)
|
||||
asset_json = generate_asset_json(release_data, asset, checksums)
|
||||
save_platform_json(platform_folder, asset_json, tag)
|
||||
print(f"Processed {asset['name']} for {platform_name}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,10 +1,10 @@
|
||||
name: Test Wasm Version
|
||||
name: Build revive-wasm
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
types: [opened, synchronize]
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
@@ -15,38 +15,48 @@ env:
|
||||
REVIVE_WASM_INSTALL_DIR: ${{ github.workspace }}/target/wasm32-unknown-emscripten/release
|
||||
|
||||
jobs:
|
||||
build:
|
||||
build-revive-wasm:
|
||||
runs-on: ubuntu-24.04
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
|
||||
- name: Install Rust stable toolchain
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
components: rust-src
|
||||
target: wasm32-unknown-emscripten
|
||||
# without this it will override our rust flags
|
||||
rustflags: ""
|
||||
|
||||
- name: Download Host LLVM
|
||||
- name: get llvm gnu
|
||||
uses: ./.github/actions/get-llvm
|
||||
with:
|
||||
target: x86_64-unknown-linux-gnu
|
||||
|
||||
- name: Download Wasm LLVM
|
||||
artifactArch: x86_64-linux-gnu
|
||||
- name: get llvm emscripten
|
||||
uses: ./.github/actions/get-llvm
|
||||
with:
|
||||
target: wasm32-unknown-emscripten
|
||||
artifactArch: emscripten
|
||||
|
||||
- name: Install emsdk
|
||||
- name: install emsdk
|
||||
uses: ./.github/actions/get-emsdk
|
||||
|
||||
- name: Set LLVM Environment Variables
|
||||
- name: Setup revive environment variables
|
||||
run: |
|
||||
echo "LLVM_SYS_181_PREFIX=$(pwd)/llvm-x86_64-unknown-linux-gnu" >> $GITHUB_ENV
|
||||
echo "REVIVE_LLVM_TARGET_PREFIX=$(pwd)/llvm-wasm32-unknown-emscripten" >> $GITHUB_ENV
|
||||
echo "LLVM_SYS_181_PREFIX=$(pwd)/target-llvm/gnu/target-final" >> $GITHUB_ENV
|
||||
echo "REVIVE_LLVM_TARGET_PREFIX=$(pwd)/target-llvm/emscripten/target-final" >> $GITHUB_ENV
|
||||
|
||||
- name: Build Revive
|
||||
- run: |
|
||||
rustup show
|
||||
cargo --version
|
||||
rustup +nightly show
|
||||
cargo +nightly --version
|
||||
cmake --version
|
||||
bash --version
|
||||
|
||||
- name: Build revive
|
||||
run: |
|
||||
source emsdk/emsdk_env.sh
|
||||
make install-wasm
|
||||
@@ -60,8 +70,8 @@ jobs:
|
||||
${{ env.REVIVE_WASM_INSTALL_DIR }}/resolc_web.js
|
||||
retention-days: 1
|
||||
|
||||
test:
|
||||
needs: build
|
||||
test-revive-wasm:
|
||||
needs: build-revive-wasm
|
||||
strategy:
|
||||
matrix:
|
||||
os: ["ubuntu-24.04", "macos-14", "windows-2022"]
|
||||
@@ -83,7 +93,7 @@ jobs:
|
||||
with:
|
||||
node-version: "20"
|
||||
|
||||
- name: Install Node Packages
|
||||
- name: Install packages
|
||||
run: npm install
|
||||
|
||||
- name: Run Playwright tests
|
||||
@@ -1,64 +0,0 @@
|
||||
name: Generate JSON for resolc-bin
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
generateJson:
|
||||
runs-on: ubuntu-latest
|
||||
if: contains(github.event.release.tag_name, 'llvm') == false
|
||||
environment: tags
|
||||
env:
|
||||
# the token is needed for json_generator.py
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: tmp
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: paritytech/resolc-bin
|
||||
path: resolc-bin
|
||||
|
||||
- uses: actions/create-github-app-token@v1
|
||||
id: app-token
|
||||
with:
|
||||
app-id: ${{ secrets.REVIVE_JSON_APP_ID }}
|
||||
private-key: ${{ secrets.REVIVE_JSON_APP_KEY }}
|
||||
owner: paritytech
|
||||
repositories: resolc-bin
|
||||
|
||||
- name: Generate json and push
|
||||
env:
|
||||
TOKEN: ${{ steps.app-token.outputs.token }}
|
||||
APP_NAME: "paritytech-revive-json"
|
||||
Green: "\e[32m"
|
||||
NC: "\e[0m"
|
||||
run: |
|
||||
sudo apt-get update && sudo apt-get install -y wget
|
||||
wget https://github.com/${GITHUB_REPOSITORY}/releases/download/${GITHUB_REF_NAME}/resolc-x86_64-unknown-linux-musl
|
||||
chmod +x resolc-x86_64-unknown-linux-musl
|
||||
export FIRST_SOLC_VERSION=$(./resolc-x86_64-unknown-linux-musl --supported-solc-versions | cut -f 1 -d "," | tr -d ">=")
|
||||
export LAST_SOLC_VERSION=$(./resolc-x86_64-unknown-linux-musl --supported-solc-versions | cut -f 2 -d "," | tr -d "<=")
|
||||
|
||||
cd resolc-bin
|
||||
python ../tmp/.github/scripts/json_generator.py ${GITHUB_REPOSITORY} ${{ github.event.release.tag_name }}
|
||||
|
||||
echo "${Green}Add new remote with gh app token${NC}"
|
||||
git remote set-url origin $(git config remote.origin.url | sed "s/github.com/${APP_NAME}:${TOKEN}@github.com/g")
|
||||
|
||||
echo "${Green}Remove http section that causes issues with gh app auth token${NC}"
|
||||
sed -i.bak '/\[http/d' ./.git/config
|
||||
sed -i.bak '/extraheader/d' ./.git/config
|
||||
|
||||
git config user.email "ci@parity.io"
|
||||
git config user.name "${APP_NAME}"
|
||||
|
||||
git add .
|
||||
git commit -m "Update json"
|
||||
git push origin main
|
||||
|
||||
echo "::notice::info.list files were successfully published to https://github.com/paritytech/resolc-bin"
|
||||
@@ -1,4 +1,5 @@
|
||||
name: Release LLVM
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
@@ -8,15 +9,15 @@ on:
|
||||
description: llvm version in "x.x.x" format, e.g. "18.1.8"
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
create-release-draft:
|
||||
runs-on: ubuntu-24.04
|
||||
create-release:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
outputs:
|
||||
@@ -26,107 +27,145 @@ jobs:
|
||||
run: |
|
||||
echo "version=llvm-${{ inputs.llvm_version }}-revive.${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Create Release
|
||||
- name: create release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
name: ${{ steps.resolve-version.outputs.version }}
|
||||
body: "LLVM is a dependency of revive. The LLVM releases are used by our CI to build revive."
|
||||
draft: true
|
||||
name: "LLVM binaries release: ${{ steps.resolve-version.outputs.version }}"
|
||||
body: "This release includes binaries of LLVM, used to compile revive itself"
|
||||
make_latest: "false"
|
||||
tag_name: ${{ steps.resolve-version.outputs.version }}
|
||||
|
||||
build:
|
||||
build-macos:
|
||||
strategy:
|
||||
matrix:
|
||||
target: [x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl, wasm32-unknown-emscripten, aarch64-apple-darwin, x86_64-apple-darwin, x86_64-pc-windows-msvc]
|
||||
os: [macos-14, macos-13]
|
||||
include:
|
||||
- target: x86_64-unknown-linux-gnu
|
||||
builder-arg: gnu
|
||||
host: linux
|
||||
runner: parity-large
|
||||
- target: x86_64-unknown-linux-musl
|
||||
builder-arg: musl
|
||||
host: linux
|
||||
runner: parity-large
|
||||
- target: wasm32-unknown-emscripten
|
||||
builder-arg: emscripten
|
||||
host: linux
|
||||
runner: parity-large
|
||||
- target: aarch64-apple-darwin
|
||||
builder-arg: gnu
|
||||
host: macos
|
||||
runner: macos-14
|
||||
- target: x86_64-apple-darwin
|
||||
builder-arg: gnu
|
||||
host: macos
|
||||
runner: macos-13
|
||||
- target: x86_64-pc-windows-msvc
|
||||
builder-arg: gnu
|
||||
host: windows
|
||||
runner: windows-2022
|
||||
needs: create-release-draft
|
||||
runs-on: ${{ matrix.runner }}
|
||||
- os: macos-13
|
||||
arch: x64
|
||||
- os: macos-14
|
||||
arch: arm64
|
||||
needs: create-release
|
||||
runs-on: ${{ matrix.os }}
|
||||
name: "build-macos-${{ matrix.arch }}"
|
||||
env:
|
||||
RUST_LOG: trace
|
||||
permissions:
|
||||
contents: write # for uploading assets to release
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
# without this it will override our rust flags
|
||||
rustflags: ""
|
||||
cache-key: ${{ matrix.target }}
|
||||
|
||||
- name: Install Dependencies
|
||||
if: ${{ matrix.host == 'linux' }}
|
||||
run: |
|
||||
sudo apt-get update && sudo apt-get install -y cmake ninja-build curl git libssl-dev pkg-config clang lld musl
|
||||
|
||||
- name: Install Dependencies
|
||||
if: ${{ matrix.host == 'macos' }}
|
||||
- name: install macos deps
|
||||
run: |
|
||||
brew install ninja
|
||||
|
||||
- name: Install LLVM Builder
|
||||
- name: versions
|
||||
run: |
|
||||
cargo install --path crates/llvm-builder
|
||||
|
||||
- name: Clone LLVM
|
||||
run: |
|
||||
revive-llvm --target-env ${{ matrix.builder-arg }} clone
|
||||
rustup show
|
||||
cargo --version
|
||||
cmake --version
|
||||
echo "bash:" && bash --version
|
||||
echo "ninja:" && ninja --version
|
||||
echo "clang:" && clang --version
|
||||
|
||||
- name: Build LLVM
|
||||
if: ${{ matrix.target != 'wasm32-unknown-emscripten' }}
|
||||
run: |
|
||||
revive-llvm --target-env ${{ matrix.builder-arg }} build --llvm-projects lld --llvm-projects clang
|
||||
make install-llvm
|
||||
|
||||
- name: Build LLVM
|
||||
if: ${{ matrix.target == 'wasm32-unknown-emscripten' }}
|
||||
- name: clean
|
||||
# check removed files
|
||||
run: |
|
||||
source emsdk/emsdk_env.sh
|
||||
revive-llvm --target-env ${{ matrix.builder-arg }} build --llvm-projects lld
|
||||
cd target-llvm/gnu/target-final/bin/
|
||||
rm diagtool llvm-libtool-darwin llvm-lipo llvm-pdbutil llvm-dwarfdump llvm-nm llvm-readobj llvm-cfi-verify \
|
||||
sancov llvm-debuginfo-analyzer llvm-objdump llvm-profgen llvm-extract llvm-jitlink llvm-c-test llvm-gsymutil llvm-dwp \
|
||||
dsymutil llvm-dwarfutil llvm-exegesis lli clang-rename bugpoint clang-extdef-mapping clang-refactor c-index-test \
|
||||
llvm-reduce llvm-lto clang-linker-wrapper llc llvm-lto2
|
||||
|
||||
- name: Remove Unnecessary Binaries
|
||||
shell: bash
|
||||
- name: package artifacts
|
||||
run: |
|
||||
cd target-llvm/${{ matrix.builder-arg }}/target-final/bin/
|
||||
rm -f diagtool* llvm-libtool-darwin* llvm-lipo* llvm-pdbutil* llvm-dwarfdump* llvm-nm* llvm-readobj* llvm-cfi-verify* \
|
||||
sancov* llvm-debuginfo-analyzer* llvm-objdump* llvm-profgen* llvm-extract* llvm-jitlink* llvm-c-test* llvm-gsymutil* llvm-dwp* \
|
||||
dsymutil* llvm-dwarfutil* llvm-exegesis* lli clang-rename* bugpoint* clang-extdef-mapping* clang-refactor* c-index-test* \
|
||||
llvm-reduce* llvm-lto* clang-linker-wrapper* llc* llvm-lto2* llvm-otool* llvm-readelf* \
|
||||
clang-repl* clang-check* clang-scan-deps*
|
||||
cd -
|
||||
tar -czf "${{ needs.create-release.outputs.version }}-macos-${{ matrix.arch }}.tar.gz" target-llvm/gnu/target-final
|
||||
|
||||
- name: Package Artifact
|
||||
shell: bash
|
||||
run: |
|
||||
mv target-llvm/${{ matrix.builder-arg }}/target-final/ llvm-${{ matrix.target }}
|
||||
tar -czf "${{ needs.create-release-draft.outputs.version }}-${{ matrix.target }}.tar.gz" llvm-${{ matrix.target }}
|
||||
|
||||
- name: Add Artifact to Release
|
||||
- name: upload archive to release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: ${{ needs.create-release-draft.outputs.version }}
|
||||
draft: true
|
||||
make_latest: "false"
|
||||
tag_name: ${{ needs.create-release.outputs.version }}
|
||||
files: |
|
||||
${{ needs.create-release-draft.outputs.version }}-${{ matrix.target }}.tar.gz
|
||||
${{ needs.create-release.outputs.version }}-macos-${{ matrix.arch }}.tar.gz
|
||||
|
||||
|
||||
build-linux-all:
|
||||
needs: create-release
|
||||
runs-on: parity-large
|
||||
env:
|
||||
RUST_LOG: trace
|
||||
permissions:
|
||||
contents: write # for uploading assets to release
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: install linux deps
|
||||
run: |
|
||||
sudo apt-get update && sudo apt-get install -y cmake ninja-build curl git libssl-dev pkg-config clang lld musl
|
||||
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
components: rust-src
|
||||
target: wasm32-unknown-emscripten
|
||||
rustflags: ""
|
||||
|
||||
- name: versions
|
||||
run: |
|
||||
rustup show
|
||||
cargo --version
|
||||
cmake --version
|
||||
echo "bash:" && bash --version
|
||||
echo "ninja:" && ninja --version
|
||||
echo "clang:" && clang --version
|
||||
|
||||
- name: Build host LLVM
|
||||
run: |
|
||||
make install-llvm
|
||||
|
||||
- name: Build gnu LLVM
|
||||
run: |
|
||||
revive-llvm clone
|
||||
revive-llvm build --llvm-projects lld --llvm-projects clang
|
||||
|
||||
- name: Build musl LLVM
|
||||
run: |
|
||||
revive-llvm --target-env musl build --llvm-projects lld --llvm-projects clang
|
||||
|
||||
- name: Build emscripten LLVM
|
||||
run: |
|
||||
revive-llvm --target-env emscripten clone
|
||||
source emsdk/emsdk_env.sh
|
||||
revive-llvm --target-env emscripten build --llvm-projects lld
|
||||
|
||||
- name: clean
|
||||
# check removed files
|
||||
run: |
|
||||
for target in gnu emscripten musl; do
|
||||
cd target-llvm/${target}/target-final/bin/
|
||||
rm -rf diagtool llvm-libtool-darwin llvm-lipo llvm-pdbutil llvm-dwarfdump llvm-nm llvm-readobj llvm-cfi-verify \
|
||||
sancov llvm-debuginfo-analyzer llvm-objdump llvm-profgen llvm-extract llvm-jitlink llvm-c-test llvm-gsymutil llvm-dwp \
|
||||
dsymutil llvm-dwarfutil llvm-exegesis lli clang-rename bugpoint clang-extdef-mapping clang-refactor c-index-test \
|
||||
llvm-reduce llvm-lto clang-linker-wrapper llc llvm-lto2 llvm-otool llvm-readelf
|
||||
cd -
|
||||
done
|
||||
|
||||
- name: package artifacts
|
||||
run: |
|
||||
tar -czf "${{ needs.create-release.outputs.version }}-x86_64-linux-gnu-linux.tar.gz" target-llvm/gnu/target-final
|
||||
tar -czf "${{ needs.create-release.outputs.version }}-x86_64-linux-musl.tar.gz" target-llvm/musl/target-final
|
||||
tar -czf "${{ needs.create-release.outputs.version }}-wasm32-unknown-emscripten.tar.gz" target-llvm/emscripten/target-final
|
||||
|
||||
- name: upload archive to release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
make_latest: "false"
|
||||
tag_name: ${{ needs.create-release.outputs.version }}
|
||||
files: |
|
||||
${{ needs.create-release.outputs.version }}-x86_64-linux-gnu-linux.tar.gz
|
||||
${{ needs.create-release.outputs.version }}-x86_64-linux-musl.tar.gz
|
||||
${{ needs.create-release.outputs.version }}-wasm32-unknown-emscripten.tar.gz
|
||||
|
||||
+210
-164
@@ -1,61 +1,59 @@
|
||||
name: Build & Release
|
||||
name: Release
|
||||
run-name: Release ${{ github.ref_name }}
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
tags:
|
||||
- "v*"
|
||||
branches:
|
||||
- "main"
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
types: [opened, synchronize, labeled, unlabeled]
|
||||
types: [opened, synchronize, reopened, ready_for_review, labeled]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
#rust-musl-cross:x86_64-musl
|
||||
RUST_MUSL_CROSS_IMAGE: messense/rust-musl-cross@sha256:68b86bc7cb2867259e6b233415a665ff4469c28b57763e78c3bfea1c68091561
|
||||
RUST_LOG: trace
|
||||
|
||||
jobs:
|
||||
check-version-changed:
|
||||
tag:
|
||||
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'release-test')
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
contents: write
|
||||
env:
|
||||
CURRENT_TAG: ${{ github.ref_name }}
|
||||
outputs:
|
||||
TAG: ${{ steps.versions.outputs.TAG }}
|
||||
PKG_VER: ${{ steps.versions.outputs.PKG_VER }}
|
||||
RELEASE_NOTES: ${{ steps.versions.outputs.RELEASE_NOTES }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-tags: "true"
|
||||
fetch-depth: 0
|
||||
|
||||
# Check that tag and version in Cargo.toml match
|
||||
- name: Check versions
|
||||
- name: Versions
|
||||
id: versions
|
||||
run: |
|
||||
if [[ $CURRENT_TAG == 'main' ]];
|
||||
then
|
||||
echo "::notice::Tag $CURRENT_TAG is not a release tag, skipping the check in the main branch";
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ $CURRENT_TAG != "v"* ]];
|
||||
then
|
||||
echo "::notice::Tag $CURRENT_TAG is not a release tag, skipping the check in a PR";
|
||||
exit 0
|
||||
fi
|
||||
|
||||
export CURRENT_TAG=$(git describe --tags --abbrev=0 --exclude "llvm-*")
|
||||
export PKG_VER=v$(cat Cargo.toml | grep -A 5 package] | grep version | cut -d '=' -f 2 | tr -d '"' | tr -d " ")
|
||||
echo "Current tag $CURRENT_TAG"
|
||||
echo "Package version $PKG_VER"
|
||||
#
|
||||
if [[ $CURRENT_TAG != $PKG_VER ]];
|
||||
echo "PKG_VER=$PKG_VER" >> $GITHUB_OUTPUT
|
||||
if [[ $CURRENT_TAG == $PKG_VER ]];
|
||||
then
|
||||
echo "::error::Tag $CURRENT_TAG doesn't match package version $PKG_VER in Cargo.toml, please fix";
|
||||
exit 1
|
||||
echo "Tag is up to date. Nothing to do.";
|
||||
export TAG=old;
|
||||
else
|
||||
echo "Tag was updated.";
|
||||
export TAG=new;
|
||||
fi
|
||||
echo "TAG=$TAG" >> $GITHUB_OUTPUT
|
||||
|
||||
# Generating release notes early, in order to avoid checkout at the last step
|
||||
export RELEASE_NOTES="$(sed '/^## '${CURRENT_TAG}'/,/^## v/!d' CHANGELOG.md | sed -e '1d' -e '$d')"
|
||||
export RELEASE_NOTES="$(sed '/^## '${PKG_VER}'/,/^## v/!d' CHANGELOG.md | sed -e '1d' -e '$d')"
|
||||
|
||||
echo "Release notes:"
|
||||
echo "$RELEASE_NOTES"
|
||||
@@ -64,124 +62,190 @@ jobs:
|
||||
echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT
|
||||
echo 'EOF' >> $GITHUB_OUTPUT
|
||||
|
||||
build:
|
||||
build-macos:
|
||||
strategy:
|
||||
matrix:
|
||||
target:
|
||||
[
|
||||
x86_64-unknown-linux-musl,
|
||||
aarch64-apple-darwin,
|
||||
x86_64-apple-darwin,
|
||||
x86_64-pc-windows-msvc,
|
||||
]
|
||||
os: [macos-14, macos-13]
|
||||
include:
|
||||
- target: x86_64-unknown-linux-musl
|
||||
type: musl
|
||||
runner: ubuntu-24.04
|
||||
- target: aarch64-apple-darwin
|
||||
type: native
|
||||
runner: macos-14
|
||||
- target: x86_64-apple-darwin
|
||||
type: native
|
||||
runner: macos-13
|
||||
- target: x86_64-pc-windows-msvc
|
||||
type: native
|
||||
runner: windows-2022
|
||||
runs-on: ${{ matrix.runner }}
|
||||
needs: [check-version-changed]
|
||||
- os: macos-13
|
||||
arch: x64
|
||||
- os: macos-14
|
||||
arch: arm64
|
||||
if: ${{ needs.tag.outputs.TAG == 'new' }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
name: build-macos
|
||||
needs: [tag]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
# without this it will override our rust flags
|
||||
rustflags: ""
|
||||
cache-key: ${{ matrix.target }}
|
||||
|
||||
- name: Download LLVM
|
||||
- name: get llvm
|
||||
uses: ./.github/actions/get-llvm
|
||||
with:
|
||||
target: ${{ matrix.target }}
|
||||
releasePrefix: llvm-
|
||||
artifactArch: macos-${{ matrix.arch }}
|
||||
dir: ./
|
||||
|
||||
- name: Build
|
||||
if: ${{ matrix.type == 'native' }}
|
||||
shell: bash
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
components: rust-src
|
||||
target: wasm32-unknown-emscripten
|
||||
rustflags: ""
|
||||
|
||||
- name: install macos deps
|
||||
run: |
|
||||
export LLVM_SYS_181_PREFIX=$PWD/llvm-${{ matrix.target }}
|
||||
brew install ninja
|
||||
|
||||
- name: versions
|
||||
run: |
|
||||
rustup show
|
||||
cargo --version
|
||||
cmake --version
|
||||
echo "bash:" && bash --version
|
||||
echo "ninja:" && ninja --version
|
||||
echo "clang:" && clang --version
|
||||
|
||||
- name: build revive
|
||||
run: |
|
||||
export LLVM_SYS_181_PREFIX=$PWD/target-llvm/gnu/target-final
|
||||
make install-bin
|
||||
mv target/release/resolc resolc-${{ matrix.target }} || mv target/release/resolc.exe resolc-${{ matrix.target }}.exe
|
||||
cp ./target/release/resolc ./target/release/resolc-${{ matrix.arch }}
|
||||
|
||||
- name: Build
|
||||
if: ${{ matrix.type == 'musl' }}
|
||||
- name: check revive
|
||||
run: |
|
||||
docker run -v $PWD:/opt/revive $RUST_MUSL_CROSS_IMAGE /bin/bash -c "
|
||||
cd /opt/revive
|
||||
chown -R root:root .
|
||||
apt update && apt upgrade -y && apt install -y pkg-config
|
||||
export LLVM_SYS_181_PREFIX=/opt/revive/llvm-${{ matrix.target }}
|
||||
make install-bin
|
||||
mv target/${{ matrix.target }}/release/resolc resolc-${{ matrix.target }}
|
||||
"
|
||||
sudo chown -R $(id -u):$(id -g) .
|
||||
|
||||
- name: Install Solc
|
||||
uses: ./.github/actions/get-solc
|
||||
|
||||
- name: Basic Sanity Check
|
||||
shell: bash
|
||||
run: |
|
||||
result=$(./resolc-${{ matrix.target }} --bin crates/integration/contracts/flipper.sol)
|
||||
mkdir solc
|
||||
curl -sSLo solc/solc https://github.com/ethereum/solidity/releases/download/v0.8.28/solc-macos
|
||||
chmod +x solc/solc
|
||||
PATH=$PWD/solc:$PATH
|
||||
result=$(./target/release/resolc-${{ matrix.arch }} --bin crates/integration/contracts/flipper.sol)
|
||||
echo $result
|
||||
if [[ $result == *'0x50564d'* ]]; then exit 0; else exit 1; fi
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: resolc-${{ matrix.target }}
|
||||
path: resolc-${{ matrix.target }}*
|
||||
name: "revive-macos-${{ matrix.arch }}"
|
||||
path: |
|
||||
./target/release/resolc-${{ matrix.arch }}
|
||||
retention-days: 1
|
||||
|
||||
build-wasm:
|
||||
runs-on: ubuntu-24.04
|
||||
needs: [check-version-changed]
|
||||
env:
|
||||
RELEASE_RESOLC_WASM_URI: https://github.com/paritytech/revive-workflow-test/releases/download/${{ github.ref_name }}/resolc.wasm
|
||||
macos-universal-binary:
|
||||
runs-on: macos-14
|
||||
needs: [build-macos]
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: revive-macos-*
|
||||
path: revive-macos
|
||||
|
||||
- name: run lipo
|
||||
run: |
|
||||
lipo revive-macos/revive-macos-arm64/resolc-arm64 revive-macos/revive-macos-x64/resolc-x64 -create -output resolc-macos
|
||||
|
||||
- name: compress macos artifact
|
||||
run: |
|
||||
chmod +x resolc-macos
|
||||
tar -czf resolc-macos.tar.gz ./resolc-macos
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: revive-macos
|
||||
path: |
|
||||
resolc-macos.tar.gz
|
||||
retention-days: 1
|
||||
|
||||
build-linux-all:
|
||||
if: ${{ needs.tag.outputs.TAG == 'new' }}
|
||||
runs-on: parity-large
|
||||
needs: [tag]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: install linux deps
|
||||
run: |
|
||||
sudo apt-get update && sudo apt-get install -y cmake ninja-build \
|
||||
curl git libssl-dev pkg-config clang lld musl
|
||||
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
components: rust-src
|
||||
target: wasm32-unknown-emscripten
|
||||
# without this it will override our rust flags
|
||||
rustflags: ""
|
||||
|
||||
- name: Download Host LLVM
|
||||
uses: ./.github/actions/get-llvm
|
||||
with:
|
||||
target: x86_64-unknown-linux-gnu
|
||||
|
||||
- name: Download Wasm LLVM
|
||||
uses: ./.github/actions/get-llvm
|
||||
with:
|
||||
target: wasm32-unknown-emscripten
|
||||
|
||||
- name: Download EMSDK
|
||||
uses: ./.github/actions/get-emsdk
|
||||
|
||||
- name: Build
|
||||
- name: versions
|
||||
run: |
|
||||
export LLVM_SYS_181_PREFIX=$PWD/llvm-x86_64-unknown-linux-gnu
|
||||
export REVIVE_LLVM_TARGET_PREFIX=$PWD/llvm-wasm32-unknown-emscripten
|
||||
source emsdk/emsdk_env.sh
|
||||
make install-wasm
|
||||
chmod -x ./target/wasm32-unknown-emscripten/release/resolc.wasm
|
||||
rustup show
|
||||
cargo --version
|
||||
cmake --version
|
||||
echo "bash:" && bash --version
|
||||
echo "ninja:" && ninja --version
|
||||
echo "clang:" && clang --version
|
||||
|
||||
- name: get llvm musl
|
||||
uses: ./.github/actions/get-llvm
|
||||
with:
|
||||
releasePrefix: llvm-
|
||||
artifactArch: x86_64-linux-musl
|
||||
dir: ./
|
||||
|
||||
# Build revive
|
||||
|
||||
- name: build musl
|
||||
run: |
|
||||
mkdir resolc-out
|
||||
docker run -v $PWD:/opt/revive $RUST_MUSL_CROSS_IMAGE /bin/bash -c "
|
||||
cd /opt/revive
|
||||
apt update && apt upgrade -y && apt install -y pkg-config
|
||||
export LLVM_SYS_181_PREFIX=/opt/revive/target-llvm/musl/target-final
|
||||
make install-bin
|
||||
cp /root/.cargo/bin/resolc /opt/revive/resolc-out/resolc-static-linux
|
||||
"
|
||||
|
||||
- name: check musl
|
||||
run: |
|
||||
mkdir solc
|
||||
curl -sSLo solc/solc https://github.com/ethereum/solidity/releases/download/v0.8.28/solc-static-linux
|
||||
chmod +x solc/solc
|
||||
PATH=$PWD/solc:$PATH
|
||||
result=$(./resolc-out/resolc-static-linux --bin crates/integration/contracts/flipper.sol)
|
||||
echo $result
|
||||
if [[ $result == *'0x50564d'* ]]; then exit 0; else exit 1; fi
|
||||
|
||||
- name: compress musl artifact
|
||||
run: |
|
||||
tar --strip-components 2 -czf resolc-static-linux.tar.gz ./resolc-out/resolc-static-linux
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: revive-linux
|
||||
path: |
|
||||
./resolc-static-linux.tar.gz
|
||||
retention-days: 1
|
||||
|
||||
- name: Set Up Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "20"
|
||||
|
||||
- name: Basic Sanity Check
|
||||
- name: get llvm emscripten
|
||||
uses: ./.github/actions/get-llvm
|
||||
with:
|
||||
artifactArch: emscripten
|
||||
|
||||
- name: install emsdk
|
||||
uses: ./.github/actions/get-emsdk
|
||||
|
||||
- name: build wasm
|
||||
run: |
|
||||
mkdir -p solc
|
||||
curl -sSLo solc/soljson.js https://github.com/ethereum/solidity/releases/download/v0.8.29/soljson.js
|
||||
export LLVM_SYS_181_PREFIX=$PWD/target-llvm/musl/target-final
|
||||
export REVIVE_LLVM_TARGET_PREFIX=$PWD/target-llvm/emscripten/target-final
|
||||
source emsdk/emsdk_env.sh
|
||||
rustup target add wasm32-unknown-emscripten
|
||||
make install-wasm
|
||||
|
||||
- name: check wasm
|
||||
run: |
|
||||
curl -sSLo solc/soljson.js https://github.com/ethereum/solidity/releases/download/v0.8.28/soljson.js
|
||||
node -e "
|
||||
const soljson = require('solc/soljson');
|
||||
const createRevive = require('./target/wasm32-unknown-emscripten/release/resolc.js');
|
||||
@@ -216,73 +280,55 @@ jobs:
|
||||
if(!bytecode.startsWith('50564d')) { process.exit(1); }
|
||||
"
|
||||
|
||||
- name: Compress Artifact
|
||||
- name: compress wasm artifact
|
||||
run: |
|
||||
mkdir -p resolc-wasm32-unknown-emscripten
|
||||
mv ./target/wasm32-unknown-emscripten/release/resolc.js ./resolc-wasm32-unknown-emscripten/
|
||||
mv ./target/wasm32-unknown-emscripten/release/resolc.wasm ./resolc-wasm32-unknown-emscripten/
|
||||
mv ./target/wasm32-unknown-emscripten/release/resolc_web.js ./resolc-wasm32-unknown-emscripten/
|
||||
tar --strip-components 4 -czf resolc-wasm.tar.gz \
|
||||
./target/wasm32-unknown-emscripten/release/resolc.js \
|
||||
./target/wasm32-unknown-emscripten/release/resolc.wasm \
|
||||
./target/wasm32-unknown-emscripten/release/resolc_web.js
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: resolc-wasm32-unknown-emscripten
|
||||
path: resolc-wasm32-unknown-emscripten/*
|
||||
name: revive-wasm
|
||||
path: |
|
||||
resolc-wasm.tar.gz
|
||||
retention-days: 1
|
||||
|
||||
create-release:
|
||||
if: startsWith(github.ref_name, 'v')
|
||||
needs: [check-version-changed, build-wasm]
|
||||
runs-on: macos-14
|
||||
environment: tags
|
||||
if: github.event_name != 'pull_request'
|
||||
needs: [tag, build-linux-all, macos-universal-binary]
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Download Artifacts
|
||||
- name: Download revive-wasm
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
merge-multiple: true
|
||||
name: revive-wasm
|
||||
path: resolc-wasm/
|
||||
|
||||
- name: Create macOS Fat Binary
|
||||
run: |
|
||||
lipo resolc-aarch64-apple-darwin resolc-x86_64-apple-darwin -create -output resolc-universal-apple-darwin
|
||||
|
||||
- name: Make Executable
|
||||
run: |
|
||||
chmod +x resolc-x86_64-unknown-linux-musl
|
||||
chmod +x resolc-universal-apple-darwin
|
||||
|
||||
- name: Create sha-256 checksum
|
||||
run: |
|
||||
shasum -a 256 resolc-x86_64-unknown-linux-musl > checksums.txt
|
||||
shasum -a 256 resolc-universal-apple-darwin >> checksums.txt
|
||||
shasum -a 256 resolc-x86_64-pc-windows-msvc.exe >> checksums.txt
|
||||
shasum -a 256 resolc.js >> checksums.txt
|
||||
shasum -a 256 resolc.wasm >> checksums.txt
|
||||
shasum -a 256 resolc_web.js >> checksums.txt
|
||||
|
||||
- uses: actions/create-github-app-token@v1
|
||||
id: app-token
|
||||
- name: Download revive-linux
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
app-id: ${{ secrets.REVIVE_RELEASE_APP_ID }}
|
||||
private-key: ${{ secrets.REVIVE_RELEASE_APP_KEY }}
|
||||
name: revive-linux
|
||||
path: resolc-linux/
|
||||
|
||||
- name: Download revive-macos
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: revive-macos
|
||||
path: resolc-macos/
|
||||
|
||||
- name: create-release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
body: |
|
||||
## Changelog
|
||||
${{ needs.check-version-changed.outputs.RELEASE_NOTES }}
|
||||
|
||||
## Note for macOS Users
|
||||
The macOS binary is unsigned and it needs to be made runnable using `xattr -c resolc-universal-apple-darwin`.
|
||||
tag_name: ${{ github.ref_name }}
|
||||
name: ${{ github.ref_name }}
|
||||
prerelease: true
|
||||
token: ${{ steps.app-token.outputs.token }}
|
||||
body: ${{ needs.tag.outputs.RELEASE_NOTES }}
|
||||
tag_name: ${{ needs.tag.outputs.PKG_VER }}
|
||||
name: ${{ needs.tag.outputs.PKG_VER }}
|
||||
draft: true
|
||||
target_commitish: ${{ github.sha }}
|
||||
files: |
|
||||
resolc-x86_64-unknown-linux-musl
|
||||
resolc-universal-apple-darwin
|
||||
resolc-x86_64-pc-windows-msvc.exe
|
||||
resolc.js
|
||||
resolc.wasm
|
||||
resolc_web.js
|
||||
checksums.txt
|
||||
./resolc-linux/resolc-static-linux.tar.gz
|
||||
./resolc-macos/resolc-macos.tar.gz
|
||||
./resolc-wasm/resolc-wasm.tar.gz
|
||||
|
||||
|
||||
@@ -1,45 +1,43 @@
|
||||
name: Test LLVM Builder
|
||||
on:
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
types: [opened, synchronize]
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
paths:
|
||||
- 'LLVM.lock'
|
||||
- 'crates/llvm-builder/**'
|
||||
- '.github/workflows/test-llvm-builder.yml'
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
- '.github/workflows/revive-llvm-test.yml'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
runner: [parity-large, macos-14, windows-2022]
|
||||
runner: [parity-large, macos-14, macos-13]
|
||||
runs-on: ${{ matrix.runner }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
# without this it will override our rust flags
|
||||
rustflags: ""
|
||||
cache-key: ${{ matrix.runner }}
|
||||
|
||||
- name: Install Dependencies
|
||||
- name: Install apt dependencies
|
||||
if: matrix.runner == 'parity-large'
|
||||
run: |
|
||||
sudo apt update && sudo apt-get install -y cmake ninja-build curl git libssl-dev pkg-config clang lld musl
|
||||
|
||||
- name: Install Dependencies
|
||||
if: matrix.runner == 'macos-14'
|
||||
- name: Install macos dependencies
|
||||
if: matrix.runner == 'macos-14' || matrix.runner == 'macos-13'
|
||||
run: |
|
||||
brew install ninja
|
||||
|
||||
- name: Test
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
components: rust-src
|
||||
rustflags: ""
|
||||
|
||||
- run: |
|
||||
rustup show
|
||||
cargo --version
|
||||
cmake --version
|
||||
bash --version
|
||||
|
||||
- name: Test llvm-builder
|
||||
run: make test-llvm-builder
|
||||
env:
|
||||
RUST_LOG: trace
|
||||
@@ -0,0 +1,64 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build-ubuntu-x86:
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install solc
|
||||
run: |
|
||||
mkdir -p solc
|
||||
curl -sSL --output solc/solc https://github.com/ethereum/solidity/releases/download/v0.8.28/solc-static-linux
|
||||
chmod +x solc/solc
|
||||
echo "$(pwd)/solc/" >> $GITHUB_PATH
|
||||
|
||||
- name: Install LLVM
|
||||
run: |
|
||||
curl -sSL --output llvm.tar.xz https://github.com/paritytech/revive/releases/download/v0.1.0-dev.7/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-24.04.tar.xz
|
||||
mkdir llvm18
|
||||
tar Jxf llvm.tar.xz -C llvm18/
|
||||
echo "LLVM_SYS_181_PREFIX=$(pwd)/llvm18" >> $GITHUB_ENV
|
||||
|
||||
- name: Install geth
|
||||
run: |
|
||||
sudo add-apt-repository -y ppa:ethereum/ethereum
|
||||
sudo apt update
|
||||
sudo apt install -y ethereum
|
||||
|
||||
# Disabled for now (always install the latest version despite setting it):
|
||||
# https://github.com/bnjbvr/cargo-machete/issues/156
|
||||
#- name: Machete
|
||||
# uses: bnjbvr/cargo-machete@v0.7.0
|
||||
|
||||
- name: Format
|
||||
run: make format
|
||||
|
||||
- name: Clippy
|
||||
run: make clippy
|
||||
|
||||
- name: Test cargo workspace
|
||||
run: make test-workspace
|
||||
|
||||
- name: Test CLI
|
||||
run: make test-cli
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ github.job }}-resolc
|
||||
path: ./target/release/resolc
|
||||
retention-days: 1
|
||||
@@ -1,57 +0,0 @@
|
||||
name: Test
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
types: [opened, synchronize]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
# without this it will override our rust flags
|
||||
rustflags: ""
|
||||
|
||||
- name: Install Solc
|
||||
uses: ./.github/actions/get-solc
|
||||
|
||||
- name: Download LLVM
|
||||
uses: ./.github/actions/get-llvm
|
||||
with:
|
||||
target: x86_64-unknown-linux-gnu
|
||||
|
||||
- name: Set LLVM Environment Variables
|
||||
run: |
|
||||
echo "LLVM_SYS_181_PREFIX=$(pwd)/llvm-x86_64-unknown-linux-gnu" >> $GITHUB_ENV
|
||||
|
||||
- name: Install Geth
|
||||
run: |
|
||||
sudo add-apt-repository -y ppa:ethereum/ethereum
|
||||
sudo apt update
|
||||
sudo apt install -y ethereum
|
||||
|
||||
- name: Machete
|
||||
uses: bnjbvr/cargo-machete@v0.7.1
|
||||
|
||||
- name: Format
|
||||
run: make format
|
||||
|
||||
- name: Clippy
|
||||
run: make clippy
|
||||
|
||||
- name: Test cargo workspace
|
||||
run: make test-workspace
|
||||
|
||||
- name: Test CLI
|
||||
run: make test-cli
|
||||
@@ -2,36 +2,6 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
This is a development pre-release.
|
||||
|
||||
Supported `polkadot-sdk` rev:`c29e72a8628835e34deb6aa7db9a78a2e4eabcee`
|
||||
|
||||
### Added
|
||||
|
||||
### Changed
|
||||
|
||||
### Fixed
|
||||
- Constructors avoid storing zero sized immutable data on exit.
|
||||
|
||||
## v0.1.0-dev.13
|
||||
|
||||
This is a development pre-release.
|
||||
|
||||
Supported `polkadot-sdk` rev:`c29e72a8628835e34deb6aa7db9a78a2e4eabcee`
|
||||
|
||||
### Added
|
||||
- Support for solc v0.8.29
|
||||
- Decouples the solc JSON-input-output type definitions from the Solidity fronted and expose them via a dedicated crate.
|
||||
- `--supported-solc-versions` for `resolc` binary to return a `semver` range of supported `solc` versions.
|
||||
- Support for passing LLVM command line options via the prcoess input or providing one or more `--llvm-arg='..'` resolc CLI flag. This allows more fine-grained control over the LLVM backend configuration.
|
||||
|
||||
### Changed
|
||||
- Storage keys and values are big endian. This was a pre-mature optimization because for the contract itself it this is a no-op and thus not observable. However we should consider the storage layout as part of the contract ABI. The endianness of transient storage values are still kept as-is.
|
||||
- Running `resolc` using webkit is no longer supported.
|
||||
|
||||
### Fixed
|
||||
- A missing byte swap for the create2 salt value.
|
||||
|
||||
## v0.1.0-dev.12
|
||||
|
||||
This is a development pre-release.
|
||||
|
||||
Generated
+390
-407
File diff suppressed because it is too large
Load Diff
+15
-16
@@ -3,7 +3,7 @@ resolver = "2"
|
||||
members = ["crates/*"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0-dev.13"
|
||||
version = "0.1.0-dev.12"
|
||||
authors = [
|
||||
"Cyrill Leutwiler <cyrill@parity.io>",
|
||||
"Parity Technologies <admin@parity.io>",
|
||||
@@ -14,20 +14,19 @@ repository = "https://github.com/paritytech/revive"
|
||||
rust-version = "1.81.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
revive-benchmarks = { version = "0.1.0-dev.13", path = "crates/benchmarks" }
|
||||
revive-builtins = { version = "0.1.0-dev.13", path = "crates/builtins" }
|
||||
revive-common = { version = "0.1.0-dev.13", path = "crates/common" }
|
||||
revive-differential = { version = "0.1.0-dev.13", path = "crates/differential" }
|
||||
revive-integration = { version = "0.1.0-dev.13", path = "crates/integration" }
|
||||
revive-linker = { version = "0.1.0-dev.13", path = "crates/linker" }
|
||||
lld-sys = { version = "0.1.0-dev.13", path = "crates/lld-sys" }
|
||||
revive-llvm-context = { version = "0.1.0-dev.13", path = "crates/llvm-context" }
|
||||
revive-runtime-api = { version = "0.1.0-dev.13", path = "crates/runtime-api" }
|
||||
revive-runner = { version = "0.1.0-dev.13", path = "crates/runner" }
|
||||
revive-solc-json-interface = { version = "0.1.0-dev.13", path = "crates/solc-json-interface" }
|
||||
revive-solidity = { version = "0.1.0-dev.13", path = "crates/solidity" }
|
||||
revive-stdlib = { version = "0.1.0-dev.13", path = "crates/stdlib" }
|
||||
revive-build-utils = { version = "0.1.0-dev.13", path = "crates/build-utils" }
|
||||
revive-benchmarks = { version = "0.1.0-dev.12", path = "crates/benchmarks" }
|
||||
revive-builtins = { version = "0.1.0-dev.12", path = "crates/builtins" }
|
||||
revive-common = { version = "0.1.0-dev.12", path = "crates/common" }
|
||||
revive-differential = { version = "0.1.0-dev.12", path = "crates/differential" }
|
||||
revive-integration = { version = "0.1.0-dev.12", path = "crates/integration" }
|
||||
revive-linker = { version = "0.1.0-dev.12", path = "crates/linker" }
|
||||
lld-sys = { version = "0.1.0-dev.12", path = "crates/lld-sys" }
|
||||
revive-llvm-context = { version = "0.1.0-dev.12", path = "crates/llvm-context" }
|
||||
revive-runtime-api = { version = "0.1.0-dev.12", path = "crates/runtime-api" }
|
||||
revive-runner = { version = "0.1.0-dev.12", path = "crates/runner" }
|
||||
revive-solidity = { version = "0.1.0-dev.12", path = "crates/solidity" }
|
||||
revive-stdlib = { version = "0.1.0-dev.12", path = "crates/stdlib" }
|
||||
revive-build-utils = { version = "0.1.0-dev.12", path = "crates/build-utils" }
|
||||
|
||||
hex = "0.4.3"
|
||||
cc = "1.2"
|
||||
@@ -73,7 +72,7 @@ assert_fs = "1.1"
|
||||
# polkadot-sdk and friends
|
||||
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
|
||||
scale-info = { version = "2.11.6", default-features = false }
|
||||
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c29e72a8628835e34deb6aa7db9a78a2e4eabcee" }
|
||||
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "21f6f0705e53c15aa2b8a5706b208200447774a9" }
|
||||
|
||||
# llvm
|
||||
[workspace.dependencies.inkwell]
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ RUN make install-llvm-builder
|
||||
RUN revive-llvm --target-env musl clone
|
||||
RUN revive-llvm --target-env musl build --llvm-projects lld --llvm-projects clang
|
||||
|
||||
FROM messense/rust-musl-cross@sha256:68b86bc7cb2867259e6b233415a665ff4469c28b57763e78c3bfea1c68091561 AS resolc-builder
|
||||
FROM messense/rust-musl-cross:x86_64-musl AS resolc-builder
|
||||
WORKDIR /opt/revive
|
||||
|
||||
RUN apt update && \
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
install: install-bin install-npm
|
||||
|
||||
install-bin:
|
||||
cargo install --locked --path crates/solidity
|
||||
cargo install --path crates/solidity
|
||||
|
||||
install-npm:
|
||||
npm install && npm fund
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||

|
||||

|
||||
[](https://contracts.polkadot.io/revive_compiler/)
|
||||
|
||||
# revive
|
||||
|
||||
+5
-8
@@ -4,14 +4,11 @@ Prior to the first stable release we neither have formal release processes nor d
|
||||
|
||||
To create a new pre-release:
|
||||
|
||||
1. Create a release PR which updates the `-dev.X` versions in the workspace `Cargo.toml` and updates the `CHANGELOG.md` accordingly.
|
||||
2. If the CI passes, merge the release PR.
|
||||
3. Push a tag that has the same `-dev.X` version as in `Cargo.toml`
|
||||
4. The release workflow will attempt to build and publish a new pre-release if the latest tag does match the cargo package version.
|
||||
5. Wait for the `Release` workflow to finish. It should create the pre-release with the same `-dev.X` name.
|
||||
6. Check that pre-release was created on the [Releases page](https://github.com/paritytech/revive/releases) with all artifacts.
|
||||
7. After the release is published, another workflow should start automatically and update json files in https://github.com/paritytech/resolc-bin. Check the changes.
|
||||
8. Update the [contract-docs](https://github.com/paritytech/contract-docs/) accordingly
|
||||
1. Create a release PR which updates the `-dev.X` versions in the workspace `Cargo.toml` and updates the `CHANGELOG.md` accordingly. Add the `release-test` label to trigger the release workflows.
|
||||
2. If the CI passes, merge the release PR. The release workflow will attempt to build and publish a new release whenever the latest git tag does not match the cargo package version.
|
||||
3. Wait for the `Release` workflow to finish. If the workflow fails after the `build-linux-all` step, check if a tag has been created and delete it before restarting or pushing updates. Note: It's more convenient to debug the release workflow in a fork (the fork has to be under the `paritytech` org to access `parity-large` runners).
|
||||
4. Check draft release on [Releases page](https://github.com/paritytech/revive/releases) and publish (should contain `resolc.js`, `resolc.wasm`, `resolc-web.js`, and `resolc-static-linux` release assets)
|
||||
5. Update the [contract-docs](https://github.com/paritytech/contract-docs/) accordingly
|
||||
|
||||
# LLVM release
|
||||
|
||||
|
||||
@@ -15,58 +15,58 @@
|
||||
|
||||
### Baseline
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:--------|:-------------------------|:-------------------------------- |
|
||||
| **`0`** | `10.08 us` (✅ **1.00x**) | `10.32 us` (✅ **1.02x slower**) |
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:--------|:------------------------|:-------------------------------- |
|
||||
| **`0`** | `3.36 us` (✅ **1.00x**) | `11.84 us` (❌ *3.52x slower*) |
|
||||
|
||||
### OddPorduct
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:-------------|:--------------------------|:-------------------------------- |
|
||||
| **`10000`** | `3.60 ms` (✅ **1.00x**) | `1.57 ms` (🚀 **2.28x faster**) |
|
||||
| **`100000`** | `34.72 ms` (✅ **1.00x**) | `14.82 ms` (🚀 **2.34x faster**) |
|
||||
| **`300000`** | `105.01 ms` (✅ **1.00x**) | `44.11 ms` (🚀 **2.38x faster**) |
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:-------------|:-------------------------|:-------------------------------- |
|
||||
| **`10000`** | `3.11 ms` (✅ **1.00x**) | `1.53 ms` (🚀 **2.03x faster**) |
|
||||
| **`100000`** | `30.70 ms` (✅ **1.00x**) | `15.54 ms` (🚀 **1.98x faster**) |
|
||||
| **`300000`** | `92.68 ms` (✅ **1.00x**) | `45.47 ms` (🚀 **2.04x faster**) |
|
||||
|
||||
### TriangleNumber
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:-------------|:-------------------------|:-------------------------------- |
|
||||
| **`10000`** | `2.43 ms` (✅ **1.00x**) | `1.12 ms` (🚀 **2.17x faster**) |
|
||||
| **`100000`** | `24.20 ms` (✅ **1.00x**) | `10.86 ms` (🚀 **2.23x faster**) |
|
||||
| **`360000`** | `88.69 ms` (✅ **1.00x**) | `38.46 ms` (🚀 **2.31x faster**) |
|
||||
| **`10000`** | `2.29 ms` (✅ **1.00x**) | `1.09 ms` (🚀 **2.11x faster**) |
|
||||
| **`100000`** | `22.84 ms` (✅ **1.00x**) | `10.66 ms` (🚀 **2.14x faster**) |
|
||||
| **`360000`** | `82.29 ms` (✅ **1.00x**) | `37.01 ms` (🚀 **2.22x faster**) |
|
||||
|
||||
### FibonacciRecursive
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:---------|:--------------------------|:--------------------------------- |
|
||||
| **`12`** | `144.17 us` (✅ **1.00x**) | `150.85 us` (✅ **1.05x slower**) |
|
||||
| **`16`** | `938.71 us` (✅ **1.00x**) | `922.11 us` (✅ **1.02x faster**) |
|
||||
| **`20`** | `6.54 ms` (✅ **1.00x**) | `6.20 ms` (✅ **1.05x faster**) |
|
||||
| **`24`** | `45.73 ms` (✅ **1.00x**) | `41.98 ms` (✅ **1.09x faster**) |
|
||||
| **`12`** | `135.67 us` (✅ **1.00x**) | `125.02 us` (✅ **1.09x faster**) |
|
||||
| **`16`** | `903.75 us` (✅ **1.00x**) | `762.79 us` (✅ **1.18x faster**) |
|
||||
| **`20`** | `6.12 ms` (✅ **1.00x**) | `4.96 ms` (✅ **1.23x faster**) |
|
||||
| **`24`** | `42.05 ms` (✅ **1.00x**) | `33.86 ms` (✅ **1.24x faster**) |
|
||||
|
||||
### FibonacciIterative
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:----------|:-------------------------|:-------------------------------- |
|
||||
| **`64`** | `23.00 us` (✅ **1.00x**) | `31.88 us` (❌ *1.39x slower*) |
|
||||
| **`128`** | `35.28 us` (✅ **1.00x**) | `42.43 us` (❌ *1.20x slower*) |
|
||||
| **`256`** | `60.12 us` (✅ **1.00x**) | `61.20 us` (✅ **1.02x slower**) |
|
||||
| **`64`** | `15.04 us` (✅ **1.00x**) | `29.45 us` (❌ *1.96x slower*) |
|
||||
| **`128`** | `26.36 us` (✅ **1.00x**) | `42.19 us` (❌ *1.60x slower*) |
|
||||
| **`256`** | `48.61 us` (✅ **1.00x**) | `65.71 us` (❌ *1.35x slower*) |
|
||||
|
||||
### FibonacciBinet
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:----------|:-------------------------|:-------------------------------- |
|
||||
| **`64`** | `23.01 us` (✅ **1.00x**) | `47.74 us` (❌ *2.07x slower*) |
|
||||
| **`128`** | `25.44 us` (✅ **1.00x**) | `49.67 us` (❌ *1.95x slower*) |
|
||||
| **`256`** | `28.66 us` (✅ **1.00x**) | `53.01 us` (❌ *1.85x slower*) |
|
||||
| **`64`** | `15.22 us` (✅ **1.00x**) | `41.46 us` (❌ *2.72x slower*) |
|
||||
| **`128`** | `17.05 us` (✅ **1.00x**) | `42.84 us` (❌ *2.51x slower*) |
|
||||
| **`256`** | `19.00 us` (✅ **1.00x**) | `44.36 us` (❌ *2.34x slower*) |
|
||||
|
||||
### SHA1
|
||||
|
||||
| | `EVM` | `PVMInterpreter` |
|
||||
|:----------|:--------------------------|:--------------------------------- |
|
||||
| **`1`** | `135.87 us` (✅ **1.00x**) | `243.75 us` (❌ *1.79x slower*) |
|
||||
| **`64`** | `258.45 us` (✅ **1.00x**) | `355.70 us` (❌ *1.38x slower*) |
|
||||
| **`512`** | `1.10 ms` (✅ **1.00x**) | `1.09 ms` (✅ **1.01x faster**) |
|
||||
| **`1`** | `110.04 us` (✅ **1.00x**) | `216.11 us` (❌ *1.96x slower*) |
|
||||
| **`64`** | `209.04 us` (✅ **1.00x**) | `309.48 us` (❌ *1.48x slower*) |
|
||||
| **`512`** | `903.65 us` (✅ **1.00x**) | `980.49 us` (✅ **1.09x slower**) |
|
||||
|
||||
---
|
||||
Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"Baseline": 950,
|
||||
"Computation": 2222,
|
||||
"DivisionArithmetics": 8802,
|
||||
"ERC20": 17601,
|
||||
"Events": 1628,
|
||||
"FibonacciIterative": 1485,
|
||||
"Flipper": 2089,
|
||||
"SHA1": 8230
|
||||
"Baseline": 1443,
|
||||
"Computation": 2788,
|
||||
"DivisionArithmetics": 9748,
|
||||
"ERC20": 19203,
|
||||
"Events": 2201,
|
||||
"FibonacciIterative": 2041,
|
||||
"Flipper": 2632,
|
||||
"SHA1": 8958
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
contract Predicted {
|
||||
uint public salt;
|
||||
|
||||
constructor(uint _salt) {
|
||||
salt = _salt;
|
||||
}
|
||||
}
|
||||
|
||||
contract AddressPredictor {
|
||||
constructor(uint _salt, bytes memory _bytecode) payable {
|
||||
address deployed = address(new Predicted{salt: bytes32(_salt)}(_salt));
|
||||
address predicted = predictAddress(_salt, _bytecode);
|
||||
assert(deployed == predicted);
|
||||
}
|
||||
|
||||
function predictAddress(
|
||||
uint _foo,
|
||||
bytes memory _bytecode
|
||||
) public view returns (address predicted) {
|
||||
bytes32 addr = keccak256(
|
||||
abi.encodePacked(
|
||||
bytes1(0xff),
|
||||
address(this),
|
||||
bytes32(_foo),
|
||||
keccak256(abi.encodePacked(_bytecode, abi.encode(_foo)))
|
||||
)
|
||||
);
|
||||
predicted = address(uint160(uint(addr)));
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
/* runner.json
|
||||
{
|
||||
"differential": true,
|
||||
"actions": [
|
||||
{
|
||||
"Instantiate": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "DelegateCaller"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "e466c6c9"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
contract DelegateCaller {
|
||||
function delegateNoContract() external returns (bool) {
|
||||
address testAddress = 0x0000000000000000000000000000000000000000;
|
||||
(bool success, ) = testAddress.delegatecall(
|
||||
abi.encodeWithSignature("test()")
|
||||
);
|
||||
return success;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
/* runner.json
|
||||
{
|
||||
"differential": true,
|
||||
"actions": [
|
||||
{
|
||||
"Instantiate": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "FunctionType"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "b8c9d365"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
contract FunctionType {
|
||||
uint public immutable x = 42;
|
||||
|
||||
function h() public view returns (function() external view returns (uint)) {
|
||||
return this.x;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.29;
|
||||
|
||||
/* runner.json
|
||||
{
|
||||
"differential": true,
|
||||
"actions": [
|
||||
{
|
||||
"Instantiate": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "LayoutAt"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "a7a0d537"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "15393349"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
contract LayoutAt layout at 0xDEADBEEF + 0xCAFEBABE {
|
||||
uint[3] public something;
|
||||
|
||||
constructor() payable {
|
||||
something[0] = 1337;
|
||||
something[1] = 42;
|
||||
something[2] = 69;
|
||||
}
|
||||
|
||||
function slotOfSomething() public pure returns (uint ret) {
|
||||
assembly {
|
||||
ret := something.slot
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8;
|
||||
|
||||
/* runner.json
|
||||
{
|
||||
"differential": true,
|
||||
"actions": [
|
||||
{
|
||||
"Instantiate": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "MCopyOverlap"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "afdce848"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
function copy(
|
||||
uint dstOffset,
|
||||
uint srcOffset,
|
||||
uint length
|
||||
) pure returns (bytes memory out) {
|
||||
out = hex"2222222222222222333333333333333344444444444444445555555555555555"
|
||||
hex"6666666666666666777777777777777788888888888888889999999999999999"
|
||||
hex"aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbccccccccccccccccdddddddddddddddd";
|
||||
assembly {
|
||||
mcopy(
|
||||
add(add(out, 0x20), dstOffset),
|
||||
add(add(out, 0x20), srcOffset),
|
||||
length
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
contract MCopyOverlap {
|
||||
function mcopy_to_right_overlap() public pure returns (bytes memory) {
|
||||
return copy(0x20, 0x10, 0x30);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ pragma solidity ^0.8;
|
||||
"Instantiated": 0
|
||||
},
|
||||
"key": "0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"expected": "0000000000000000000000000000000000000000000000000000000000000001"
|
||||
"expected": "0100000000000000000000000000000000000000000000000000000000000000"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -250,17 +250,6 @@ sol!(
|
||||
);
|
||||
case!("Storage.sol", Storage, transientCall, storage_transient, value: U256);
|
||||
|
||||
sol!(
|
||||
contract Predicted {
|
||||
constructor(uint _foo);
|
||||
}
|
||||
contract AddressPredictor {
|
||||
constructor(uint _foo, bytes memory _bytecode) payable;
|
||||
}
|
||||
);
|
||||
case!("AddressPredictor.sol", Predicted, constructorCall, predicted_constructor, salt: U256);
|
||||
case!("AddressPredictor.sol", AddressPredictor, constructorCall, address_predictor_constructor, salt: U256, bytecode: Bytes);
|
||||
|
||||
impl Contract {
|
||||
pub fn build(calldata: Vec<u8>, name: &'static str, code: &str) -> Self {
|
||||
Self {
|
||||
|
||||
@@ -33,7 +33,6 @@ test_spec!(msize, "MSize", "MSize.sol");
|
||||
test_spec!(sha1, "SHA1", "SHA1.sol");
|
||||
test_spec!(block, "Block", "Block.sol");
|
||||
test_spec!(mcopy, "MCopy", "MCopy.sol");
|
||||
test_spec!(mcopy_overlap, "MCopyOverlap", "MCopyOverlap.sol");
|
||||
test_spec!(events, "Events", "Events.sol");
|
||||
test_spec!(storage, "Storage", "Storage.sol");
|
||||
test_spec!(mstore8, "MStore8", "MStore8.sol");
|
||||
@@ -57,9 +56,6 @@ test_spec!(transfer, "Transfer", "Transfer.sol");
|
||||
test_spec!(send, "Send", "Send.sol");
|
||||
test_spec!(function_pointer, "FunctionPointer", "FunctionPointer.sol");
|
||||
test_spec!(mload, "MLoad", "MLoad.sol");
|
||||
test_spec!(delegate_no_contract, "DelegateCaller", "DelegateCaller.sol");
|
||||
test_spec!(function_type, "FunctionType", "FunctionType.sol");
|
||||
test_spec!(layout_at, "LayoutAt", "LayoutAt.sol");
|
||||
|
||||
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
||||
vec![Instantiate {
|
||||
@@ -486,31 +482,3 @@ fn transfer_denies_reentrancy() {
|
||||
}
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create2_salt() {
|
||||
let salt = U256::from(777);
|
||||
let predicted = Contract::predicted_constructor(salt).pvm_runtime;
|
||||
let predictor = Contract::address_predictor_constructor(salt, predicted.clone().into());
|
||||
Specs {
|
||||
actions: vec![
|
||||
Upload {
|
||||
origin: TestAddress::Alice,
|
||||
code: Code::Bytes(predicted),
|
||||
storage_deposit_limit: None,
|
||||
},
|
||||
Instantiate {
|
||||
origin: TestAddress::Alice,
|
||||
value: 0,
|
||||
gas_limit: Some(GAS_LIMIT),
|
||||
storage_deposit_limit: None,
|
||||
code: Code::Bytes(predictor.pvm_runtime),
|
||||
data: predictor.calldata,
|
||||
salt: OptionalHex::default(),
|
||||
},
|
||||
],
|
||||
differential: false,
|
||||
..Default::default()
|
||||
}
|
||||
.run();
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ fn main() {
|
||||
revive_build_utils::llvm_cxx_flags()
|
||||
.split_whitespace()
|
||||
.fold(&mut cc::Build::new(), |builder, flag| builder.flag(flag))
|
||||
.warnings(false)
|
||||
.flag("-Wno-unused-parameter")
|
||||
.cpp(true)
|
||||
.file("src/linker.cpp")
|
||||
.compile("liblinker.a");
|
||||
|
||||
@@ -32,7 +32,6 @@ tar = { workspace = true }
|
||||
flate2 = { workspace = true }
|
||||
env_logger = { workspace = true }
|
||||
log = { workspace = true }
|
||||
which = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = { workspace = true }
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
//! Utilities for compiling the LLVM compiler-rt builtins.
|
||||
|
||||
use crate::utils::path_windows_to_unix as to_unix;
|
||||
use std::{env::consts::EXE_EXTENSION, process::Command};
|
||||
|
||||
/// Static CFLAGS variable passed to the compiler building the compiler-rt builtins.
|
||||
const C_FLAGS: [&str; 6] = [
|
||||
"--target=riscv64",
|
||||
@@ -47,31 +44,24 @@ fn cmake_dynamic_args(
|
||||
|
||||
let mut clang_path = llvm_target_host.to_path_buf();
|
||||
clang_path.push("bin/clang");
|
||||
clang_path.set_extension(EXE_EXTENSION);
|
||||
|
||||
let mut clangxx_path = llvm_target_host.to_path_buf();
|
||||
clangxx_path.push("bin/clang++");
|
||||
clangxx_path.set_extension(EXE_EXTENSION);
|
||||
|
||||
let mut llvm_config_path = llvm_target_host.to_path_buf();
|
||||
llvm_config_path.push("bin/llvm-config");
|
||||
llvm_config_path.set_extension(EXE_EXTENSION);
|
||||
|
||||
let mut ar_path = llvm_target_host.to_path_buf();
|
||||
ar_path.push("bin/llvm-ar");
|
||||
ar_path.set_extension(EXE_EXTENSION);
|
||||
|
||||
let mut nm_path = llvm_target_host.to_path_buf();
|
||||
nm_path.push("bin/llvm-nm");
|
||||
nm_path.set_extension(EXE_EXTENSION);
|
||||
|
||||
let mut ranlib_path = llvm_target_host.to_path_buf();
|
||||
ranlib_path.push("bin/llvm-ranlib");
|
||||
ranlib_path.set_extension(EXE_EXTENSION);
|
||||
|
||||
let mut linker_path = llvm_target_host.to_path_buf();
|
||||
linker_path.push("bin/ld.lld");
|
||||
linker_path.set_extension(EXE_EXTENSION);
|
||||
|
||||
Ok([
|
||||
format!(
|
||||
@@ -86,18 +76,12 @@ fn cmake_dynamic_args(
|
||||
format!("-DCMAKE_C_FLAGS='{}'", C_FLAGS.join(" ")),
|
||||
format!("-DCMAKE_ASM_FLAGS='{}'", C_FLAGS.join(" ")),
|
||||
format!("-DCMAKE_CXX_FLAGS='{}'", C_FLAGS.join(" ")),
|
||||
format!(
|
||||
"-DCMAKE_C_COMPILER='{}'",
|
||||
to_unix(clang_path.clone())?.display()
|
||||
),
|
||||
format!("-DCMAKE_ASM_COMPILER='{}'", to_unix(clang_path)?.display()),
|
||||
format!(
|
||||
"-DCMAKE_CXX_COMPILER='{}'",
|
||||
to_unix(clangxx_path)?.display()
|
||||
),
|
||||
format!("-DCMAKE_AR='{}'", to_unix(ar_path)?.display()),
|
||||
format!("-DCMAKE_NM='{}'", to_unix(nm_path)?.display()),
|
||||
format!("-DCMAKE_RANLIB='{}'", to_unix(ranlib_path)?.display()),
|
||||
format!("-DCMAKE_C_COMPILER='{}'", clang_path.to_string_lossy()),
|
||||
format!("-DCMAKE_ASM_COMPILER='{}'", clang_path.to_string_lossy()),
|
||||
format!("-DCMAKE_CXX_COMPILER='{}'", clangxx_path.to_string_lossy()),
|
||||
format!("-DCMAKE_AR='{}'", ar_path.to_string_lossy()),
|
||||
format!("-DCMAKE_NM='{}'", nm_path.to_string_lossy()),
|
||||
format!("-DCMAKE_RANLIB='{}'", ranlib_path.to_string_lossy()),
|
||||
format!(
|
||||
"-DLLVM_CONFIG_PATH='{}'",
|
||||
llvm_config_path.to_string_lossy()
|
||||
@@ -117,13 +101,7 @@ pub fn build(
|
||||
log::info!("building compiler-rt for rv64emac");
|
||||
|
||||
crate::utils::check_presence("cmake")?;
|
||||
|
||||
let generator = if cfg!(target_os = "windows") {
|
||||
"Visual Studio 17 2022"
|
||||
} else {
|
||||
crate::utils::check_presence("ninja")?;
|
||||
"Ninja"
|
||||
};
|
||||
crate::utils::check_presence("ninja")?;
|
||||
|
||||
let llvm_module_compiler_rt = crate::LLVMPath::llvm_module_compiler_rt()?;
|
||||
let llvm_compiler_rt_build = crate::LLVMPath::llvm_build_compiler_rt()?;
|
||||
@@ -136,7 +114,7 @@ pub fn build(
|
||||
"-B",
|
||||
llvm_compiler_rt_build.to_string_lossy().as_ref(),
|
||||
"-G",
|
||||
generator,
|
||||
"Ninja",
|
||||
])
|
||||
.args(CMAKE_STATIC_ARGS)
|
||||
.args(cmake_dynamic_args(build_type, target_env)?)
|
||||
@@ -153,17 +131,7 @@ pub fn build(
|
||||
"LLVM compiler-rt building cmake",
|
||||
)?;
|
||||
|
||||
crate::utils::command(
|
||||
Command::new("cmake").args([
|
||||
"--build",
|
||||
llvm_compiler_rt_build.to_string_lossy().as_ref(),
|
||||
"--target",
|
||||
"install",
|
||||
"--config",
|
||||
build_type.to_string().as_str(),
|
||||
]),
|
||||
"Building",
|
||||
)?;
|
||||
crate::utils::ninja(&llvm_compiler_rt_build)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ pub fn build(
|
||||
sanitizer,
|
||||
)?;
|
||||
} else if cfg!(target_os = "windows") {
|
||||
platforms::x86_64_windows_msvc::build(
|
||||
platforms::x86_64_windows_gnu::build(
|
||||
build_type,
|
||||
targets,
|
||||
llvm_projects,
|
||||
|
||||
@@ -8,7 +8,7 @@ pub mod wasm32_emscripten;
|
||||
pub mod x86_64_linux_gnu;
|
||||
pub mod x86_64_linux_musl;
|
||||
pub mod x86_64_macos;
|
||||
pub mod x86_64_windows_msvc;
|
||||
pub mod x86_64_windows_gnu;
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
/// The build options shared by all platforms.
|
||||
pub const SHARED_BUILD_OPTS: [&str; 21] = [
|
||||
pub const SHARED_BUILD_OPTS: [&str; 19] = [
|
||||
"-DPACKAGE_VENDOR='Parity Technologies'",
|
||||
"-DCMAKE_BUILD_WITH_INSTALL_RPATH=1",
|
||||
"-DLLVM_BUILD_DOCS='Off'",
|
||||
@@ -28,8 +28,6 @@ pub const SHARED_BUILD_OPTS: [&str; 21] = [
|
||||
"-DCMAKE_EXPORT_COMPILE_COMMANDS='On'",
|
||||
"-DPython3_FIND_REGISTRY='LAST'", // Use Python version from $PATH, not from registry
|
||||
"-DBUG_REPORT_URL='https://github.com/paritytech/contract-issues/issues/'",
|
||||
"-DCLANG_ENABLE_ARCMT='Off'",
|
||||
"-DCLANG_ENABLE_STATIC_ANALYZER='Off'",
|
||||
];
|
||||
|
||||
/// The build options shared by all platforms except MUSL.
|
||||
|
||||
+24
-12
@@ -1,6 +1,7 @@
|
||||
//! The revive LLVM amd64 `windows-gnu` builder.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
use crate::build_type::BuildType;
|
||||
@@ -27,6 +28,10 @@ pub fn build(
|
||||
sanitizer: Option<Sanitizer>,
|
||||
) -> anyhow::Result<()> {
|
||||
crate::utils::check_presence("cmake")?;
|
||||
crate::utils::check_presence("clang")?;
|
||||
crate::utils::check_presence("clang++")?;
|
||||
crate::utils::check_presence("lld")?;
|
||||
crate::utils::check_presence("ninja")?;
|
||||
|
||||
let llvm_module_llvm =
|
||||
LLVMPath::llvm_module_llvm().and_then(crate::utils::path_windows_to_unix)?;
|
||||
@@ -43,12 +48,15 @@ pub fn build(
|
||||
"-B",
|
||||
llvm_build_final.to_string_lossy().as_ref(),
|
||||
"-G",
|
||||
"Visual Studio 17 2022",
|
||||
"Ninja",
|
||||
format!(
|
||||
"-DCMAKE_INSTALL_PREFIX='{}'",
|
||||
llvm_target_final.to_string_lossy().as_ref(),
|
||||
)
|
||||
.as_str(),
|
||||
format!("-DCMAKE_BUILD_TYPE='{build_type}'").as_str(),
|
||||
"-DCMAKE_C_COMPILER='clang'",
|
||||
"-DCMAKE_CXX_COMPILER='clang++'",
|
||||
format!(
|
||||
"-DLLVM_TARGETS_TO_BUILD='{}'",
|
||||
targets
|
||||
@@ -67,7 +75,7 @@ pub fn build(
|
||||
.join(";")
|
||||
)
|
||||
.as_str(),
|
||||
"-DLLVM_BUILD_LLVM_C_DYLIB=Off",
|
||||
"-DLLVM_USE_LINKER='lld'",
|
||||
])
|
||||
.args(crate::platforms::shared::shared_build_opts_default_target(
|
||||
default_target,
|
||||
@@ -99,16 +107,20 @@ pub fn build(
|
||||
"LLVM building cmake",
|
||||
)?;
|
||||
|
||||
crate::utils::command(
|
||||
Command::new("cmake").args([
|
||||
"--build",
|
||||
llvm_build_final.to_string_lossy().as_ref(),
|
||||
"--target",
|
||||
"install",
|
||||
"--config",
|
||||
build_type.to_string().as_str(),
|
||||
]),
|
||||
"Building with msbuild",
|
||||
crate::utils::ninja(llvm_build_final.as_ref())?;
|
||||
|
||||
let libstdcpp_source_path = match std::env::var("LIBSTDCPP_SOURCE_PATH") {
|
||||
Ok(libstdcpp_source_path) => PathBuf::from(libstdcpp_source_path),
|
||||
Err(error) => anyhow::bail!(
|
||||
"The `LIBSTDCPP_SOURCE_PATH` must be set to the path to the libstdc++.a static library: {}", error
|
||||
),
|
||||
};
|
||||
let mut libstdcpp_destination_path = llvm_target_final;
|
||||
libstdcpp_destination_path.push("./lib/libstdc++.a");
|
||||
fs_extra::file::copy(
|
||||
crate::utils::path_windows_to_unix(libstdcpp_source_path)?,
|
||||
crate::utils::path_windows_to_unix(libstdcpp_destination_path)?,
|
||||
&fs_extra::file::CopyOptions::default(),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
@@ -7,7 +7,6 @@ use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Context;
|
||||
use path_slash::PathBufExt;
|
||||
|
||||
/// The LLVM host repository URL.
|
||||
@@ -132,8 +131,11 @@ pub fn path_windows_to_unix<P: AsRef<Path> + PathBufExt>(path: P) -> anyhow::Res
|
||||
|
||||
/// Checks if the tool exists in the system.
|
||||
pub fn check_presence(name: &str) -> anyhow::Result<()> {
|
||||
which::which(name).with_context(|| format!("Tool `{name}` is missing. Please install"))?;
|
||||
Ok(())
|
||||
let description = &format!("checking the `{name}` executable");
|
||||
log::info!("{description}");
|
||||
|
||||
command(Command::new("which").arg(name), description)
|
||||
.map_err(|_| anyhow::anyhow!("Tool `{}` is missing. Please install", name))
|
||||
}
|
||||
|
||||
/// Identify XCode version using `pkgutil`.
|
||||
|
||||
@@ -22,7 +22,6 @@ num = { workspace = true }
|
||||
hex = { workspace = true }
|
||||
sha3 = { workspace = true }
|
||||
inkwell = { workspace = true }
|
||||
libc = { workspace = true }
|
||||
polkavm-disassembler = { workspace = true }
|
||||
polkavm-common = { workspace = true }
|
||||
|
||||
@@ -30,4 +29,3 @@ revive-common = { workspace = true }
|
||||
revive-runtime-api = { workspace = true }
|
||||
revive-linker = { workspace = true }
|
||||
revive-stdlib = { workspace = true }
|
||||
revive-solc-json-interface = { workspace = true }
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
//! The LLVM context library.
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::sync::OnceLock;
|
||||
pub(crate) mod debug_config;
|
||||
pub(crate) mod optimizer;
|
||||
pub(crate) mod polkavm;
|
||||
pub(crate) mod target_machine;
|
||||
|
||||
pub use self::debug_config::ir_type::IRType as DebugConfigIR;
|
||||
pub use self::debug_config::DebugConfig;
|
||||
@@ -36,9 +38,7 @@ pub use self::polkavm::context::function::Function as PolkaVMFunction;
|
||||
pub use self::polkavm::context::global::Global as PolkaVMGlobal;
|
||||
pub use self::polkavm::context::pointer::heap::LoadWord as PolkaVMLoadHeapWordFunction;
|
||||
pub use self::polkavm::context::pointer::heap::StoreWord as PolkaVMStoreHeapWordFunction;
|
||||
pub use self::polkavm::context::pointer::storage::LoadTransientWord as PolkaVMLoadTransientStorageWordFunction;
|
||||
pub use self::polkavm::context::pointer::storage::LoadWord as PolkaVMLoadStorageWordFunction;
|
||||
pub use self::polkavm::context::pointer::storage::StoreTransientWord as PolkaVMStoreTransientStorageWordFunction;
|
||||
pub use self::polkavm::context::pointer::storage::StoreWord as PolkaVMStoreStorageWordFunction;
|
||||
pub use self::polkavm::context::pointer::Pointer as PolkaVMPointer;
|
||||
pub use self::polkavm::context::r#loop::Loop as PolkaVMLoop;
|
||||
@@ -48,8 +48,6 @@ pub use self::polkavm::context::Context as PolkaVMContext;
|
||||
pub use self::polkavm::evm::arithmetic as polkavm_evm_arithmetic;
|
||||
pub use self::polkavm::evm::bitwise as polkavm_evm_bitwise;
|
||||
pub use self::polkavm::evm::call as polkavm_evm_call;
|
||||
pub use self::polkavm::evm::call::Call as PolkaVMCallFunction;
|
||||
pub use self::polkavm::evm::call::CallReentrancyHeuristic as PolkaVMCallReentrancyHeuristicFunction;
|
||||
pub use self::polkavm::evm::calldata as polkavm_evm_calldata;
|
||||
pub use self::polkavm::evm::comparison as polkavm_evm_comparison;
|
||||
pub use self::polkavm::evm::context as polkavm_evm_contract_context;
|
||||
@@ -68,6 +66,7 @@ pub use self::polkavm::evm::memory as polkavm_evm_memory;
|
||||
pub use self::polkavm::evm::r#return as polkavm_evm_return;
|
||||
pub use self::polkavm::evm::return_data as polkavm_evm_return_data;
|
||||
pub use self::polkavm::evm::storage as polkavm_evm_storage;
|
||||
pub use self::polkavm::metadata_hash::MetadataHash as PolkaVMMetadataHash;
|
||||
pub use self::polkavm::r#const as polkavm_const;
|
||||
pub use self::polkavm::Dependency as PolkaVMDependency;
|
||||
pub use self::polkavm::DummyDependency as PolkaVMDummyDependency;
|
||||
@@ -76,41 +75,9 @@ pub use self::polkavm::WriteLLVM as PolkaVMWriteLLVM;
|
||||
pub use self::target_machine::target::Target;
|
||||
pub use self::target_machine::TargetMachine;
|
||||
|
||||
pub(crate) mod debug_config;
|
||||
pub(crate) mod optimizer;
|
||||
pub(crate) mod polkavm;
|
||||
pub(crate) mod target_machine;
|
||||
|
||||
static DID_INITIALIZE: OnceLock<()> = OnceLock::new();
|
||||
|
||||
/// Initializes the LLVM compiler backend.
|
||||
///
|
||||
/// This is a no-op if called subsequentially.
|
||||
///
|
||||
/// `llvm_arguments` are passed as-is to the LLVM CL options parser.
|
||||
pub fn initialize_llvm(target: Target, name: &str, llvm_arguments: &[String]) {
|
||||
let Ok(_) = DID_INITIALIZE.set(()) else {
|
||||
return; // Tests don't go through a recursive process
|
||||
};
|
||||
|
||||
let argv = [name.to_string()]
|
||||
.iter()
|
||||
.chain(llvm_arguments)
|
||||
.map(|arg| CString::new(arg.as_bytes()).unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
let argv: Vec<*const libc::c_char> = argv.iter().map(|arg| arg.as_ptr()).collect();
|
||||
let overview = CString::new("").unwrap();
|
||||
unsafe {
|
||||
inkwell::llvm_sys::support::LLVMParseCommandLineOptions(
|
||||
argv.len() as i32,
|
||||
argv.as_ptr(),
|
||||
overview.as_ptr(),
|
||||
);
|
||||
}
|
||||
|
||||
inkwell::support::enable_llvm_pretty_stack_trace();
|
||||
|
||||
/// Initializes the target machine.
|
||||
pub fn initialize_target(target: Target) {
|
||||
match target {
|
||||
Target::PVM => inkwell::targets::Target::initialize_riscv(&Default::default()),
|
||||
Target::PVM => self::polkavm::initialize_target(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
pub mod size_level;
|
||||
|
||||
use revive_solc_json_interface::SolcStandardJsonInputSettingsOptimizer;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
@@ -227,18 +226,3 @@ impl std::fmt::Display for Settings {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&SolcStandardJsonInputSettingsOptimizer> for Settings {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: &SolcStandardJsonInputSettingsOptimizer) -> Result<Self, Self::Error> {
|
||||
let mut result = match value.mode {
|
||||
Some(mode) => Self::try_from_cli(mode)?,
|
||||
None => Self::cycles(),
|
||||
};
|
||||
if value.fallback_to_optimizing_for_size.unwrap_or_default() {
|
||||
result.enable_fallback_to_size();
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,6 @@ pub static XLEN: usize = revive_common::BIT_LENGTH_X32;
|
||||
/// The calldata size global variable name.
|
||||
pub static GLOBAL_CALLDATA_SIZE: &str = "calldatasize";
|
||||
|
||||
/// The spill buffer global variable name.
|
||||
pub static GLOBAL_ADDRESS_SPILL_BUFFER: &str = "address_spill_buffer";
|
||||
|
||||
/// The deployer call header size that consists of:
|
||||
/// - bytecode hash (32 bytes)
|
||||
pub const DEPLOYER_CALL_HEADER_SIZE: usize = revive_common::BYTE_LENGTH_WORD;
|
||||
|
||||
@@ -8,6 +8,10 @@ pub enum AddressSpace {
|
||||
Stack,
|
||||
/// The heap memory.
|
||||
Heap,
|
||||
/// The generic memory page.
|
||||
Storage,
|
||||
/// The transient storage.
|
||||
TransientStorage,
|
||||
}
|
||||
|
||||
impl From<AddressSpace> for inkwell::AddressSpace {
|
||||
@@ -15,6 +19,8 @@ impl From<AddressSpace> for inkwell::AddressSpace {
|
||||
match value {
|
||||
AddressSpace::Stack => Self::from(0),
|
||||
AddressSpace::Heap => Self::from(1),
|
||||
AddressSpace::Storage => Self::from(5),
|
||||
AddressSpace::TransientStorage => Self::from(6),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,98 +4,61 @@
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Argument<'ctx> {
|
||||
/// The actual LLVM operand.
|
||||
pub value: Value<'ctx>,
|
||||
pub value: inkwell::values::BasicValueEnum<'ctx>,
|
||||
/// The original AST value. Used mostly for string literals.
|
||||
pub original: Option<String>,
|
||||
/// The preserved constant value, if available.
|
||||
pub constant: Option<num::BigUint>,
|
||||
}
|
||||
|
||||
/// The function argument can be either a pointer or a integer value.
|
||||
/// This disambiguation allows for lazy loading of variables.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Value<'ctx> {
|
||||
Register(inkwell::values::BasicValueEnum<'ctx>),
|
||||
Pointer {
|
||||
pointer: crate::polkavm::context::Pointer<'ctx>,
|
||||
id: String,
|
||||
},
|
||||
}
|
||||
|
||||
impl<'ctx> Argument<'ctx> {
|
||||
/// A shortcut constructor for register arguments.
|
||||
pub fn value(value: inkwell::values::BasicValueEnum<'ctx>) -> Self {
|
||||
/// The calldata offset argument index.
|
||||
pub const ARGUMENT_INDEX_CALLDATA_OFFSET: usize = 0;
|
||||
|
||||
/// The calldata length argument index.
|
||||
pub const ARGUMENT_INDEX_CALLDATA_LENGTH: usize = 1;
|
||||
|
||||
/// A shortcut constructor.
|
||||
pub fn new(value: inkwell::values::BasicValueEnum<'ctx>) -> Self {
|
||||
Self {
|
||||
value: Value::Register(value),
|
||||
value,
|
||||
original: None,
|
||||
constant: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A shortcut constructor for stack arguments.
|
||||
pub fn pointer(pointer: crate::polkavm::context::Pointer<'ctx>, id: String) -> Self {
|
||||
/// A shortcut constructor.
|
||||
pub fn new_with_original(
|
||||
value: inkwell::values::BasicValueEnum<'ctx>,
|
||||
original: String,
|
||||
) -> Self {
|
||||
Self {
|
||||
value: Value::Pointer { pointer, id },
|
||||
original: None,
|
||||
value,
|
||||
original: Some(original),
|
||||
constant: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the original decleratation value.
|
||||
pub fn with_original(mut self, original: String) -> Self {
|
||||
self.original = Some(original);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the constant value.
|
||||
pub fn with_constant(mut self, constant: num::BigUint) -> Self {
|
||||
self.constant = Some(constant);
|
||||
self
|
||||
/// A shortcut constructor.
|
||||
pub fn new_with_constant(
|
||||
value: inkwell::values::BasicValueEnum<'ctx>,
|
||||
constant: num::BigUint,
|
||||
) -> Self {
|
||||
Self {
|
||||
value,
|
||||
original: None,
|
||||
constant: Some(constant),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the inner LLVM value.
|
||||
///
|
||||
/// Panics if `self` is a pointer argument.
|
||||
pub fn _to_llvm_value(&self) -> inkwell::values::BasicValueEnum<'ctx> {
|
||||
match &self.value {
|
||||
Value::Register(value) => *value,
|
||||
Value::Pointer { .. } => unreachable!("invalid register value access"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Access the underlying value.
|
||||
///
|
||||
/// Will emit a stack load if `self` is a pointer argument.
|
||||
pub fn to_value<D: crate::polkavm::Dependency + Clone>(
|
||||
&self,
|
||||
context: &crate::polkavm::context::Context<'ctx, D>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
|
||||
match &self.value {
|
||||
Value::Register(value) => Ok(*value),
|
||||
Value::Pointer { pointer, id } => context.build_load(*pointer, id),
|
||||
}
|
||||
}
|
||||
|
||||
/// Access the underlying value.
|
||||
///
|
||||
/// Will emit a stack store if `self` is a value argument.
|
||||
pub fn to_pointer<D: crate::polkavm::Dependency + Clone>(
|
||||
&self,
|
||||
context: &crate::polkavm::context::Context<'ctx, D>,
|
||||
) -> anyhow::Result<crate::polkavm::context::Pointer<'ctx>> {
|
||||
match &self.value {
|
||||
Value::Register(value) => {
|
||||
let pointer = context.build_alloca_at_entry(context.word_type(), "pvm_arg");
|
||||
context.build_store(pointer, *value)?;
|
||||
Ok(pointer)
|
||||
}
|
||||
Value::Pointer { pointer, .. } => Ok(*pointer),
|
||||
}
|
||||
pub fn to_llvm(&self) -> inkwell::values::BasicValueEnum<'ctx> {
|
||||
self.value
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx> From<inkwell::values::BasicValueEnum<'ctx>> for Argument<'ctx> {
|
||||
fn from(value: inkwell::values::BasicValueEnum<'ctx>) -> Self {
|
||||
Self::value(value)
|
||||
Self::new(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
//! The LLVM runtime functions.
|
||||
|
||||
use inkwell::types::BasicType;
|
||||
|
||||
use crate::optimizer::Optimizer;
|
||||
use crate::polkavm::context::address_space::AddressSpace;
|
||||
use crate::polkavm::context::function::declaration::Declaration as FunctionDeclaration;
|
||||
use crate::polkavm::context::function::Function;
|
||||
|
||||
@@ -16,6 +19,9 @@ pub struct LLVMRuntime<'ctx> {
|
||||
pub exp: FunctionDeclaration<'ctx>,
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub sign_extend: FunctionDeclaration<'ctx>,
|
||||
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub sha3: FunctionDeclaration<'ctx>,
|
||||
}
|
||||
|
||||
impl<'ctx> LLVMRuntime<'ctx> {
|
||||
@@ -31,6 +37,9 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
/// The corresponding runtime function name.
|
||||
pub const FUNCTION_SIGNEXTEND: &'static str = "__signextend";
|
||||
|
||||
/// The corresponding runtime function name.
|
||||
pub const FUNCTION_SHA3: &'static str = "__sha3";
|
||||
|
||||
/// A shortcut constructor.
|
||||
pub fn new(
|
||||
llvm: &'ctx inkwell::context::Context,
|
||||
@@ -56,11 +65,43 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
Function::set_default_attributes(llvm, sign_extend, optimizer);
|
||||
Function::set_pure_function_attributes(llvm, sign_extend);
|
||||
|
||||
let sha3 = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_SHA3,
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.fn_type(
|
||||
vec![
|
||||
llvm.ptr_type(AddressSpace::Heap.into())
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BOOLEAN as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
]
|
||||
.as_slice(),
|
||||
false,
|
||||
),
|
||||
Some(inkwell::module::Linkage::External),
|
||||
);
|
||||
Function::set_default_attributes(llvm, sha3, optimizer);
|
||||
Function::set_attributes(
|
||||
llvm,
|
||||
sha3,
|
||||
//vec![Attribute::ArgMemOnly, Attribute::ReadOnly],
|
||||
&[],
|
||||
false,
|
||||
);
|
||||
|
||||
Self {
|
||||
add_mod,
|
||||
mul_mod,
|
||||
exp,
|
||||
sign_extend,
|
||||
|
||||
sha3,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,14 +31,6 @@ impl Entry {
|
||||
context.xlen_type().get_undef(),
|
||||
);
|
||||
|
||||
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER,
|
||||
address_type,
|
||||
AddressSpace::Stack,
|
||||
address_type.const_zero(),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -83,8 +83,6 @@ where
|
||||
current_function: Option<Rc<RefCell<Function<'ctx>>>>,
|
||||
/// The loop context stack.
|
||||
loop_stack: Vec<Loop<'ctx>>,
|
||||
/// The extra LLVM arguments that were used during target initialization.
|
||||
llvm_arguments: &'ctx [String],
|
||||
|
||||
/// The project dependency manager. It can be any entity implementing the trait.
|
||||
/// The manager is used to get information about contracts and their dependencies during
|
||||
@@ -225,7 +223,6 @@ where
|
||||
dependency_manager: Option<D>,
|
||||
include_metadata_hash: bool,
|
||||
debug_config: DebugConfig,
|
||||
llvm_arguments: &'ctx [String],
|
||||
) -> Self {
|
||||
Self::set_data_layout(llvm, &module);
|
||||
Self::link_stdlib_module(llvm, &module);
|
||||
@@ -253,7 +250,6 @@ where
|
||||
functions: HashMap::with_capacity(Self::FUNCTIONS_HASHMAP_INITIAL_CAPACITY),
|
||||
current_function: None,
|
||||
loop_stack: Vec::with_capacity(Self::LOOP_STACK_INITIAL_CAPACITY),
|
||||
llvm_arguments,
|
||||
|
||||
dependency_manager,
|
||||
include_metadata_hash,
|
||||
@@ -643,7 +639,6 @@ where
|
||||
self.optimizer.settings().to_owned(),
|
||||
self.include_metadata_hash,
|
||||
self.debug_config.clone(),
|
||||
self.llvm_arguments,
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -750,9 +745,7 @@ where
|
||||
address: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<Pointer<'ctx>> {
|
||||
let address_type = self.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
||||
let address_pointer = self
|
||||
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
|
||||
.into();
|
||||
let address_pointer = self.build_alloca_at_entry(address_type, "address_pointer");
|
||||
let address_truncated =
|
||||
self.builder()
|
||||
.build_int_truncate(address, address_type, "address_truncated")?;
|
||||
@@ -795,6 +788,9 @@ where
|
||||
panic!("revive runtime function {name} should return a value")
|
||||
}))
|
||||
}
|
||||
AddressSpace::Storage | AddressSpace::TransientStorage => {
|
||||
unreachable!("should use the runtime function")
|
||||
}
|
||||
AddressSpace::Stack => {
|
||||
let value = self
|
||||
.builder()
|
||||
@@ -827,6 +823,9 @@ where
|
||||
];
|
||||
self.build_call(declaration, &arguments, "heap_store");
|
||||
}
|
||||
AddressSpace::Storage | AddressSpace::TransientStorage => {
|
||||
unreachable!("should use the runtime function")
|
||||
}
|
||||
AddressSpace::Stack => {
|
||||
let instruction = self.builder.build_store(pointer.value, value).unwrap();
|
||||
instruction
|
||||
@@ -871,6 +870,9 @@ where
|
||||
where
|
||||
T: BasicType<'ctx>,
|
||||
{
|
||||
assert_ne!(pointer.address_space, AddressSpace::Storage);
|
||||
assert_ne!(pointer.address_space, AddressSpace::TransientStorage);
|
||||
|
||||
let value = unsafe {
|
||||
self.builder
|
||||
.build_gep(pointer.r#type, pointer.value, indexes, name)
|
||||
@@ -1296,6 +1298,13 @@ where
|
||||
inkwell::attributes::AttributeLoc::Param(index as u32),
|
||||
self.llvm.create_enum_attribute(Attribute::NoFree as u32, 0),
|
||||
);
|
||||
if function == self.llvm_runtime().sha3 {
|
||||
call_site_value.add_attribute(
|
||||
inkwell::attributes::AttributeLoc::Param(index as u32),
|
||||
self.llvm
|
||||
.create_enum_attribute(Attribute::ReadOnly as u32, 0),
|
||||
);
|
||||
}
|
||||
if Some(argument.get_type()) == function.r#type.get_return_type() {
|
||||
if function
|
||||
.r#type
|
||||
|
||||
@@ -17,20 +17,47 @@ where
|
||||
const NAME: &'static str = "__revive_load_storage_word";
|
||||
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context
|
||||
.word_type()
|
||||
.fn_type(&[context.llvm().ptr_type(Default::default()).into()], false)
|
||||
context.word_type().fn_type(
|
||||
&[context.xlen_type().into(), context.word_type().into()],
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn emit_body<'ctx>(
|
||||
&self,
|
||||
context: &mut Context<'ctx, D>,
|
||||
) -> anyhow::Result<Option<BasicValueEnum<'ctx>>> {
|
||||
Ok(Some(emit_load(
|
||||
context,
|
||||
Self::paramater(context, 0),
|
||||
false,
|
||||
)?))
|
||||
let is_transient = Self::paramater(context, 0);
|
||||
let key_value = Self::paramater(context, 1);
|
||||
|
||||
let key_pointer = context.build_alloca_at_entry(context.word_type(), "key_pointer");
|
||||
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||
let length_pointer = context.build_alloca_at_entry(context.xlen_type(), "length_pointer");
|
||||
|
||||
context
|
||||
.builder()
|
||||
.build_store(key_pointer.value, key_value)?;
|
||||
context.build_store(value_pointer, context.word_const(0))?;
|
||||
context.build_store(
|
||||
length_pointer,
|
||||
context
|
||||
.xlen_type()
|
||||
.const_int(revive_common::BYTE_LENGTH_WORD as u64, false),
|
||||
)?;
|
||||
|
||||
let arguments = [
|
||||
is_transient,
|
||||
key_pointer.to_int(context).into(),
|
||||
context.xlen_type().const_all_ones().into(),
|
||||
value_pointer.to_int(context).into(),
|
||||
length_pointer.to_int(context).into(),
|
||||
];
|
||||
context.build_runtime_call(revive_runtime_api::polkavm_imports::GET_STORAGE, &arguments);
|
||||
|
||||
// We do not to check the return value: Solidity assumes infallible loads.
|
||||
// If a key doesn't exist the "zero" value is returned (ensured by above write).
|
||||
|
||||
Ok(Some(context.build_load(value_pointer, "storage_value")?))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,42 +74,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Load a word size value from a transient storage pointer.
|
||||
pub struct LoadTransientWord;
|
||||
|
||||
impl<D> RuntimeFunction<D> for LoadTransientWord
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
const NAME: &'static str = "__revive_load_transient_storage_word";
|
||||
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context
|
||||
.word_type()
|
||||
.fn_type(&[context.llvm().ptr_type(Default::default()).into()], false)
|
||||
}
|
||||
|
||||
fn emit_body<'ctx>(
|
||||
&self,
|
||||
context: &mut Context<'ctx, D>,
|
||||
) -> anyhow::Result<Option<BasicValueEnum<'ctx>>> {
|
||||
Ok(Some(emit_load(context, Self::paramater(context, 0), true)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> WriteLLVM<D> for LoadTransientWord
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
/// Store a word size value through a storage pointer.
|
||||
pub struct StoreWord;
|
||||
|
||||
@@ -95,8 +86,9 @@ where
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context.void_type().fn_type(
|
||||
&[
|
||||
context.llvm().ptr_type(Default::default()).into(),
|
||||
context.llvm().ptr_type(Default::default()).into(),
|
||||
context.xlen_type().into(),
|
||||
context.word_type().into(),
|
||||
context.word_type().into(),
|
||||
],
|
||||
false,
|
||||
)
|
||||
@@ -106,12 +98,24 @@ where
|
||||
&self,
|
||||
context: &mut Context<'ctx, D>,
|
||||
) -> anyhow::Result<Option<BasicValueEnum<'ctx>>> {
|
||||
emit_store(
|
||||
context,
|
||||
Self::paramater(context, 0),
|
||||
Self::paramater(context, 1),
|
||||
false,
|
||||
)?;
|
||||
let is_transient = Self::paramater(context, 0);
|
||||
let key = Self::paramater(context, 1);
|
||||
let value = Self::paramater(context, 2);
|
||||
|
||||
let key_pointer = context.build_alloca_at_entry(context.word_type(), "key_pointer");
|
||||
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||
|
||||
context.build_store(key_pointer, key)?;
|
||||
context.build_store(value_pointer, value)?;
|
||||
|
||||
let arguments = [
|
||||
is_transient,
|
||||
key_pointer.to_int(context).into(),
|
||||
context.xlen_type().const_all_ones().into(),
|
||||
value_pointer.to_int(context).into(),
|
||||
context.integer_const(crate::polkavm::XLEN, 32).into(),
|
||||
];
|
||||
context.build_runtime_call(revive_runtime_api::polkavm_imports::SET_STORAGE, &arguments);
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
@@ -129,149 +133,3 @@ where
|
||||
<Self as RuntimeFunction<_>>::emit(&self, context)
|
||||
}
|
||||
}
|
||||
|
||||
/// Store a word size value through a transient storage pointer.
|
||||
pub struct StoreTransientWord;
|
||||
|
||||
impl<D> RuntimeFunction<D> for StoreTransientWord
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
const NAME: &'static str = "__revive_store_transient_storage_word";
|
||||
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context.void_type().fn_type(
|
||||
&[
|
||||
context.llvm().ptr_type(Default::default()).into(),
|
||||
context.llvm().ptr_type(Default::default()).into(),
|
||||
],
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn emit_body<'ctx>(
|
||||
&self,
|
||||
context: &mut Context<'ctx, D>,
|
||||
) -> anyhow::Result<Option<BasicValueEnum<'ctx>>> {
|
||||
emit_store(
|
||||
context,
|
||||
Self::paramater(context, 0),
|
||||
Self::paramater(context, 1),
|
||||
true,
|
||||
)?;
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> WriteLLVM<D> for StoreTransientWord
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_load<'ctx, D: Dependency + Clone>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
key: BasicValueEnum<'ctx>,
|
||||
transient: bool,
|
||||
) -> anyhow::Result<BasicValueEnum<'ctx>> {
|
||||
let mut key = context.build_load(
|
||||
super::Pointer::new(
|
||||
context.word_type(),
|
||||
Default::default(),
|
||||
key.into_pointer_value(),
|
||||
),
|
||||
"key",
|
||||
)?;
|
||||
if !transient {
|
||||
key = context.build_byte_swap(key)?;
|
||||
}
|
||||
|
||||
let key_pointer = context.build_alloca_at_entry(context.word_type(), "key_pointer");
|
||||
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||
let length_pointer = context.build_alloca_at_entry(context.xlen_type(), "length_pointer");
|
||||
|
||||
context.builder().build_store(key_pointer.value, key)?;
|
||||
context.build_store(value_pointer, context.word_const(0))?;
|
||||
context.build_store(
|
||||
length_pointer,
|
||||
context
|
||||
.xlen_type()
|
||||
.const_int(revive_common::BYTE_LENGTH_WORD as u64, false),
|
||||
)?;
|
||||
|
||||
let is_transient = context.xlen_type().const_int(transient as u64, false);
|
||||
|
||||
let arguments = [
|
||||
is_transient.into(),
|
||||
key_pointer.to_int(context).into(),
|
||||
context.xlen_type().const_all_ones().into(),
|
||||
value_pointer.to_int(context).into(),
|
||||
length_pointer.to_int(context).into(),
|
||||
];
|
||||
context.build_runtime_call(revive_runtime_api::polkavm_imports::GET_STORAGE, &arguments);
|
||||
|
||||
// We do not to check the return value: Solidity assumes infallible loads.
|
||||
// If a key doesn't exist the "zero" value is returned (ensured by above write).
|
||||
|
||||
let value = context.build_load(value_pointer, "storage_value")?;
|
||||
Ok(if transient {
|
||||
value
|
||||
} else {
|
||||
context.build_byte_swap(value)?
|
||||
})
|
||||
}
|
||||
|
||||
fn emit_store<'ctx, D: Dependency + Clone>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
key: BasicValueEnum<'ctx>,
|
||||
value: BasicValueEnum<'ctx>,
|
||||
transient: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut key = context.build_load(
|
||||
super::Pointer::new(
|
||||
context.word_type(),
|
||||
Default::default(),
|
||||
key.into_pointer_value(),
|
||||
),
|
||||
"key",
|
||||
)?;
|
||||
let mut value = context.build_load(
|
||||
super::Pointer::new(
|
||||
context.word_type(),
|
||||
Default::default(),
|
||||
value.into_pointer_value(),
|
||||
),
|
||||
"key",
|
||||
)?;
|
||||
if !transient {
|
||||
key = context.build_byte_swap(key)?;
|
||||
value = context.build_byte_swap(value)?;
|
||||
}
|
||||
|
||||
let key_pointer = context.build_alloca_at_entry(context.word_type(), "key_pointer");
|
||||
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||
|
||||
context.build_store(key_pointer, key)?;
|
||||
context.build_store(value_pointer, value)?;
|
||||
|
||||
let is_transient = context.xlen_type().const_int(transient as u64, false);
|
||||
|
||||
let arguments = [
|
||||
is_transient.into(),
|
||||
key_pointer.to_int(context).into(),
|
||||
context.xlen_type().const_all_ones().into(),
|
||||
value_pointer.to_int(context).into(),
|
||||
context.integer_const(crate::polkavm::XLEN, 32).into(),
|
||||
];
|
||||
context.build_runtime_call(revive_runtime_api::polkavm_imports::SET_STORAGE, &arguments);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -10,20 +10,12 @@ pub fn create_context(
|
||||
llvm: &inkwell::context::Context,
|
||||
optimizer_settings: OptimizerSettings,
|
||||
) -> Context<DummyDependency> {
|
||||
crate::initialize_llvm(crate::Target::PVM, "resolc", Default::default());
|
||||
crate::polkavm::initialize_target();
|
||||
|
||||
let module = llvm.create_module("test");
|
||||
let optimizer = Optimizer::new(optimizer_settings);
|
||||
|
||||
Context::<DummyDependency>::new(
|
||||
llvm,
|
||||
module,
|
||||
optimizer,
|
||||
None,
|
||||
true,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
)
|
||||
Context::<DummyDependency>::new(llvm, module, optimizer, None, true, Default::default())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -63,6 +63,7 @@ where
|
||||
let non_overflow_block = context.append_basic_block("shift_left_non_overflow");
|
||||
let join_block = context.append_basic_block("shift_left_join");
|
||||
|
||||
let result_pointer = context.build_alloca(context.word_type(), "shift_left_result_pointer");
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
shift,
|
||||
@@ -72,6 +73,7 @@ where
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||
|
||||
context.set_basic_block(overflow_block);
|
||||
context.build_store(result_pointer, context.word_const(0))?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(non_overflow_block);
|
||||
@@ -79,17 +81,11 @@ where
|
||||
context
|
||||
.builder()
|
||||
.build_left_shift(value, shift, "shift_left_non_overflow_result")?;
|
||||
context.build_store(result_pointer, value)?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(join_block);
|
||||
let result = context
|
||||
.builder()
|
||||
.build_phi(context.word_type(), "shift_left_value")?;
|
||||
result.add_incoming(&[
|
||||
(&value, non_overflow_block),
|
||||
(&context.word_const(0), overflow_block),
|
||||
]);
|
||||
Ok(result.as_basic_value())
|
||||
context.build_load(result_pointer, "shift_left_result")
|
||||
}
|
||||
|
||||
/// Translates the bitwise shift right.
|
||||
@@ -105,6 +101,7 @@ where
|
||||
let non_overflow_block = context.append_basic_block("shift_right_non_overflow");
|
||||
let join_block = context.append_basic_block("shift_right_join");
|
||||
|
||||
let result_pointer = context.build_alloca(context.word_type(), "shift_right_result_pointer");
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
shift,
|
||||
@@ -114,6 +111,7 @@ where
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||
|
||||
context.set_basic_block(overflow_block);
|
||||
context.build_store(result_pointer, context.word_const(0))?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(non_overflow_block);
|
||||
@@ -123,17 +121,11 @@ where
|
||||
false,
|
||||
"shift_right_non_overflow_result",
|
||||
)?;
|
||||
context.build_store(result_pointer, value)?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(join_block);
|
||||
let result = context
|
||||
.builder()
|
||||
.build_phi(context.word_type(), "shift_right_value")?;
|
||||
result.add_incoming(&[
|
||||
(&value, non_overflow_block),
|
||||
(&context.word_const(0), overflow_block),
|
||||
]);
|
||||
Ok(result.as_basic_value())
|
||||
context.build_load(result_pointer, "shift_right_result")
|
||||
}
|
||||
|
||||
/// Translates the arithmetic bitwise shift right.
|
||||
@@ -153,6 +145,8 @@ where
|
||||
let non_overflow_block = context.append_basic_block("shift_right_arithmetic_non_overflow");
|
||||
let join_block = context.append_basic_block("shift_right_arithmetic_join");
|
||||
|
||||
let result_pointer =
|
||||
context.build_alloca(context.word_type(), "shift_right_arithmetic_result_pointer");
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
shift,
|
||||
@@ -180,9 +174,11 @@ where
|
||||
)?;
|
||||
|
||||
context.set_basic_block(overflow_positive_block);
|
||||
context.build_store(result_pointer, context.word_const(0))?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(overflow_negative_block);
|
||||
context.build_store(result_pointer, context.word_type().const_all_ones())?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(non_overflow_block);
|
||||
@@ -192,21 +188,11 @@ where
|
||||
true,
|
||||
"shift_right_arithmetic_non_overflow_result",
|
||||
)?;
|
||||
context.build_store(result_pointer, value)?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(join_block);
|
||||
let result = context
|
||||
.builder()
|
||||
.build_phi(context.word_type(), "shift_arithmetic_right_value")?;
|
||||
result.add_incoming(&[
|
||||
(&value, non_overflow_block),
|
||||
(
|
||||
&context.word_type().const_all_ones(),
|
||||
overflow_negative_block,
|
||||
),
|
||||
(&context.word_const(0), overflow_block),
|
||||
]);
|
||||
Ok(result.as_basic_value())
|
||||
context.build_load(result_pointer, "shift_right_arithmetic_result")
|
||||
}
|
||||
|
||||
/// Translates the `byte` instruction, extracting the byte of `operand_2`
|
||||
|
||||
@@ -2,310 +2,117 @@
|
||||
|
||||
use inkwell::values::BasicValue;
|
||||
|
||||
use crate::polkavm::context::address_space::AddressSpace;
|
||||
use crate::polkavm::context::argument::Argument;
|
||||
use crate::polkavm::context::pointer::Pointer;
|
||||
use crate::polkavm::context::runtime::RuntimeFunction;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
use crate::polkavm::WriteLLVM;
|
||||
|
||||
const STATIC_CALL_FLAG: u32 = 0b0001_0000;
|
||||
const REENTRANT_CALL_FLAG: u32 = 0b0000_1000;
|
||||
const SOLIDITY_TRANSFER_GAS_STIPEND_THRESHOLD: u64 = 2300;
|
||||
|
||||
pub struct Call;
|
||||
|
||||
impl<D> RuntimeFunction<D> for Call
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
const NAME: &'static str = "__revive_call";
|
||||
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context.xlen_type().fn_type(
|
||||
&[
|
||||
context.xlen_type().into(),
|
||||
context.xlen_type().into(),
|
||||
context.xlen_type().into(),
|
||||
context.xlen_type().into(),
|
||||
context.xlen_type().into(),
|
||||
context.llvm().ptr_type(AddressSpace::Stack.into()).into(),
|
||||
context.llvm().ptr_type(AddressSpace::Stack.into()).into(),
|
||||
context.llvm().ptr_type(AddressSpace::Stack.into()).into(),
|
||||
],
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn emit_body<'ctx>(
|
||||
&self,
|
||||
context: &mut Context<'ctx, D>,
|
||||
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>> {
|
||||
let flags = Self::paramater(context, 0).into_int_value();
|
||||
let input_length = Self::paramater(context, 1).into_int_value();
|
||||
let output_length = Self::paramater(context, 2).into_int_value();
|
||||
let input_pointer = Self::paramater(context, 3).into_int_value();
|
||||
let output_pointer = Self::paramater(context, 4).into_int_value();
|
||||
let address_pointer = Self::paramater(context, 5).into_pointer_value();
|
||||
let value_pointer = Self::paramater(context, 6).into_pointer_value();
|
||||
let deposit_pointer = Self::paramater(context, 7).into_pointer_value();
|
||||
|
||||
let output_length_pointer =
|
||||
context.build_alloca_at_entry(context.xlen_type(), "output_length");
|
||||
context.build_store(output_length_pointer, output_length)?;
|
||||
|
||||
let input_pointer = context.build_heap_gep(input_pointer, input_length)?;
|
||||
let output_pointer = context.build_heap_gep(output_pointer, output_length)?;
|
||||
|
||||
let flags_and_callee = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
flags,
|
||||
Pointer::new(context.word_type(), AddressSpace::Stack, address_pointer).to_int(context),
|
||||
"address_and_callee",
|
||||
)?;
|
||||
let deposit_and_value = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
Pointer::new(context.word_type(), AddressSpace::Stack, deposit_pointer).to_int(context),
|
||||
Pointer::new(context.word_type(), AddressSpace::Stack, value_pointer).to_int(context),
|
||||
"deposit_and_value",
|
||||
)?;
|
||||
let input_data = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
input_length,
|
||||
input_pointer.to_int(context),
|
||||
"input_data",
|
||||
)?;
|
||||
let output_data = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
output_length_pointer.to_int(context),
|
||||
output_pointer.to_int(context),
|
||||
"output_data",
|
||||
)?;
|
||||
|
||||
let name = revive_runtime_api::polkavm_imports::CALL;
|
||||
let success = context
|
||||
.build_runtime_call(
|
||||
name,
|
||||
&[
|
||||
flags_and_callee.into(),
|
||||
context.register_type().const_all_ones().into(),
|
||||
context.register_type().const_all_ones().into(),
|
||||
deposit_and_value.into(),
|
||||
input_data.into(),
|
||||
output_data.into(),
|
||||
],
|
||||
)
|
||||
.unwrap_or_else(|| panic!("{name} should return a value"))
|
||||
.into_int_value();
|
||||
|
||||
let is_success = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::EQ,
|
||||
success,
|
||||
context.integer_const(revive_common::BIT_LENGTH_X64, 0),
|
||||
"is_success",
|
||||
)?;
|
||||
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(is_success, context.xlen_type(), "success")?
|
||||
.as_basic_value_enum()
|
||||
.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> WriteLLVM<D> for Call
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
<Self as RuntimeFunction<_>>::declare(self, context)
|
||||
}
|
||||
|
||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
<Self as RuntimeFunction<_>>::emit(&self, context)
|
||||
}
|
||||
}
|
||||
|
||||
/// Translates a contract call.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn call<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
gas: &Argument<'ctx>,
|
||||
address: &Argument<'ctx>,
|
||||
value: Option<&Argument<'ctx>>,
|
||||
input_offset: &Argument<'ctx>,
|
||||
input_length: &Argument<'ctx>,
|
||||
output_offset: &Argument<'ctx>,
|
||||
output_length: &Argument<'ctx>,
|
||||
gas: inkwell::values::IntValue<'ctx>,
|
||||
address: inkwell::values::IntValue<'ctx>,
|
||||
value: Option<inkwell::values::IntValue<'ctx>>,
|
||||
input_offset: inkwell::values::IntValue<'ctx>,
|
||||
input_length: inkwell::values::IntValue<'ctx>,
|
||||
output_offset: inkwell::values::IntValue<'ctx>,
|
||||
output_length: inkwell::values::IntValue<'ctx>,
|
||||
_constants: Vec<Option<num::BigUint>>,
|
||||
static_call: bool,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let input_offset =
|
||||
context.safe_truncate_int_to_xlen(input_offset.to_value(context)?.into_int_value())?;
|
||||
let input_length =
|
||||
context.safe_truncate_int_to_xlen(input_length.to_value(context)?.into_int_value())?;
|
||||
let address_pointer = context.build_address_argument_store(address)?;
|
||||
|
||||
let output_offset =
|
||||
context.safe_truncate_int_to_xlen(output_offset.to_value(context)?.into_int_value())?;
|
||||
let output_length =
|
||||
context.safe_truncate_int_to_xlen(output_length.to_value(context)?.into_int_value())?;
|
||||
let value = value.unwrap_or_else(|| context.word_const(0));
|
||||
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||
context.build_store(value_pointer, value)?;
|
||||
|
||||
let deposit_limit_pointer =
|
||||
context.build_alloca_at_entry(context.word_type(), "deposit_limit_pointer");
|
||||
let input_offset = context.safe_truncate_int_to_xlen(input_offset)?;
|
||||
let input_length = context.safe_truncate_int_to_xlen(input_length)?;
|
||||
let output_offset = context.safe_truncate_int_to_xlen(output_offset)?;
|
||||
let output_length = context.safe_truncate_int_to_xlen(output_length)?;
|
||||
|
||||
let flags = if static_call {
|
||||
context.build_store(deposit_limit_pointer, context.word_type().const_zero())?;
|
||||
let input_pointer = context.build_heap_gep(input_offset, input_length)?;
|
||||
let output_pointer = context.build_heap_gep(output_offset, output_length)?;
|
||||
|
||||
let output_length_pointer = context.build_alloca_at_entry(context.xlen_type(), "output_length");
|
||||
context.build_store(output_length_pointer, output_length)?;
|
||||
|
||||
let (flags, deposit_limit_value) = if static_call {
|
||||
let flags = REENTRANT_CALL_FLAG | STATIC_CALL_FLAG;
|
||||
context.xlen_type().const_int(flags as u64, false)
|
||||
(
|
||||
context.xlen_type().const_int(flags as u64, false),
|
||||
context.word_type().const_zero(),
|
||||
)
|
||||
} else {
|
||||
let name = <CallReentrancyHeuristic as RuntimeFunction<D>>::NAME;
|
||||
let declaration = <CallReentrancyHeuristic as RuntimeFunction<D>>::declaration(context);
|
||||
let gas = context.builder().build_int_truncate(
|
||||
gas.to_value(context)?.into_int_value(),
|
||||
context.xlen_type(),
|
||||
"gas",
|
||||
)?;
|
||||
let arguments = &[
|
||||
input_length.into(),
|
||||
output_length.into(),
|
||||
gas.into(),
|
||||
deposit_limit_pointer.value.into(),
|
||||
];
|
||||
context
|
||||
.build_call(declaration, arguments, "flags")
|
||||
.unwrap_or_else(|| panic!("runtime function {name} should return a value"))
|
||||
.into_int_value()
|
||||
call_reentrancy_heuristic(context, gas, input_length, output_length)?
|
||||
};
|
||||
|
||||
let value_pointer = match value {
|
||||
Some(argument) => argument.to_pointer(context)?,
|
||||
None => {
|
||||
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||
context.build_store(value_pointer, context.word_const(0))?;
|
||||
value_pointer
|
||||
}
|
||||
};
|
||||
let deposit_pointer = context.build_alloca_at_entry(context.word_type(), "deposit_pointer");
|
||||
context.build_store(deposit_pointer, deposit_limit_value)?;
|
||||
|
||||
let address_pointer =
|
||||
context.build_address_argument_store(address.to_value(context)?.into_int_value())?;
|
||||
let flags_and_callee = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
flags,
|
||||
address_pointer.to_int(context),
|
||||
"address_and_callee",
|
||||
)?;
|
||||
let deposit_and_value = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
deposit_pointer.to_int(context),
|
||||
value_pointer.to_int(context),
|
||||
"deposit_and_value",
|
||||
)?;
|
||||
let input_data = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
input_length,
|
||||
input_pointer.to_int(context),
|
||||
"input_data",
|
||||
)?;
|
||||
let output_data = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
output_length_pointer.to_int(context),
|
||||
output_pointer.to_int(context),
|
||||
"output_data",
|
||||
)?;
|
||||
|
||||
let name = <Call as RuntimeFunction<D>>::NAME;
|
||||
let arguments = &[
|
||||
flags.into(),
|
||||
input_length.into(),
|
||||
output_length.into(),
|
||||
input_offset.into(),
|
||||
output_offset.into(),
|
||||
address_pointer.value.into(),
|
||||
value_pointer.value.into(),
|
||||
deposit_limit_pointer.value.into(),
|
||||
];
|
||||
let declaration = <Call as RuntimeFunction<D>>::declaration(context);
|
||||
let result = context
|
||||
.build_call(declaration, arguments, "call_result_truncated")
|
||||
.unwrap_or_else(|| panic!("runtime function {name} should return a value"))
|
||||
let name = revive_runtime_api::polkavm_imports::CALL;
|
||||
let success = context
|
||||
.build_runtime_call(
|
||||
name,
|
||||
&[
|
||||
flags_and_callee.into(),
|
||||
context.register_type().const_all_ones().into(),
|
||||
context.register_type().const_all_ones().into(),
|
||||
deposit_and_value.into(),
|
||||
input_data.into(),
|
||||
output_data.into(),
|
||||
],
|
||||
)
|
||||
.unwrap_or_else(|| panic!("{name} should return a value"))
|
||||
.into_int_value();
|
||||
|
||||
let is_success = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::EQ,
|
||||
success,
|
||||
context.integer_const(revive_common::BIT_LENGTH_X64, 0),
|
||||
"is_success",
|
||||
)?;
|
||||
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(result, context.word_type(), "call_result")?
|
||||
.build_int_z_extend(is_success, context.word_type(), "success")?
|
||||
.as_basic_value_enum())
|
||||
|
||||
/*
|
||||
let address_pointer = context.build_address_argument_store(address)?;
|
||||
|
||||
let value = value.unwrap_or_else(|| context.word_const(0));
|
||||
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||
context.build_store(value_pointer, value)?;
|
||||
|
||||
let input_offset = context.safe_truncate_int_to_xlen(input_offset)?;
|
||||
let input_length = context.safe_truncate_int_to_xlen(input_length)?;
|
||||
let output_offset = context.safe_truncate_int_to_xlen(output_offset)?;
|
||||
let output_length = context.safe_truncate_int_to_xlen(output_length)?;
|
||||
|
||||
let input_pointer = context.build_heap_gep(input_offset, input_length)?;
|
||||
let output_pointer = context.build_heap_gep(output_offset, output_length)?;
|
||||
|
||||
let output_length_pointer = context.build_alloca_at_entry(context.xlen_type(), "output_length");
|
||||
context.build_store(output_length_pointer, output_length)?;
|
||||
|
||||
let (flags, deposit_limit_value) = if static_call {
|
||||
let flags = REENTRANT_CALL_FLAG | STATIC_CALL_FLAG;
|
||||
(
|
||||
context.xlen_type().const_int(flags as u64, false),
|
||||
context.word_type().const_zero(),
|
||||
)
|
||||
} else {
|
||||
call_reentrancy_heuristic(context, gas, input_length, output_length)?
|
||||
};
|
||||
|
||||
let deposit_pointer = context.build_alloca_at_entry(context.word_type(), "deposit_pointer");
|
||||
context.build_store(deposit_pointer, deposit_limit_value)?;
|
||||
|
||||
let flags_and_callee = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
flags,
|
||||
address_pointer.to_int(context),
|
||||
"address_and_callee",
|
||||
)?;
|
||||
let deposit_and_value = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
deposit_pointer.to_int(context),
|
||||
value_pointer.to_int(context),
|
||||
"deposit_and_value",
|
||||
)?;
|
||||
let input_data = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
input_length,
|
||||
input_pointer.to_int(context),
|
||||
"input_data",
|
||||
)?;
|
||||
let output_data = revive_runtime_api::calling_convention::pack_hi_lo_reg(
|
||||
context.builder(),
|
||||
context.llvm(),
|
||||
output_length_pointer.to_int(context),
|
||||
output_pointer.to_int(context),
|
||||
"output_data",
|
||||
)?;
|
||||
|
||||
let name = revive_runtime_api::polkavm_imports::CALL;
|
||||
let success = context
|
||||
.build_runtime_call(
|
||||
name,
|
||||
&[
|
||||
flags_and_callee.into(),
|
||||
context.register_type().const_all_ones().into(),
|
||||
context.register_type().const_all_ones().into(),
|
||||
deposit_and_value.into(),
|
||||
input_data.into(),
|
||||
output_data.into(),
|
||||
],
|
||||
)
|
||||
.unwrap_or_else(|| panic!("{name} should return a value"))
|
||||
.into_int_value();
|
||||
|
||||
let is_success = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::EQ,
|
||||
success,
|
||||
context.integer_const(revive_common::BIT_LENGTH_X64, 0),
|
||||
"is_success",
|
||||
)?;
|
||||
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(is_success, context.word_type(), "success")?
|
||||
.as_basic_value_enum())
|
||||
*/
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -409,110 +216,6 @@ where
|
||||
.as_basic_value_enum())
|
||||
}
|
||||
|
||||
pub struct CallReentrancyHeuristic;
|
||||
|
||||
impl<D> RuntimeFunction<D> for CallReentrancyHeuristic
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
const NAME: &'static str = "__revive_call_reentrancy_heuristic";
|
||||
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context.xlen_type().fn_type(
|
||||
&[
|
||||
// Input length
|
||||
context.xlen_type().into(),
|
||||
// Output length
|
||||
context.xlen_type().into(),
|
||||
// Gas
|
||||
context.xlen_type().into(),
|
||||
// Deposit limit value pointer
|
||||
context.llvm().ptr_type(AddressSpace::Stack.into()).into(),
|
||||
],
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn emit_body<'ctx>(
|
||||
&self,
|
||||
context: &mut Context<'ctx, D>,
|
||||
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>> {
|
||||
let input_length = Self::paramater(context, 0).into_int_value();
|
||||
let output_length = Self::paramater(context, 1).into_int_value();
|
||||
let gas = Self::paramater(context, 2).into_int_value();
|
||||
let deposit_pointer = Self::paramater(context, 3).into_pointer_value();
|
||||
|
||||
// Branch-free SSA implementation: First derive the heuristic boolean (int1) value.
|
||||
let input_length_or_output_length = context.builder().build_or(
|
||||
input_length,
|
||||
output_length,
|
||||
"input_length_or_output_length",
|
||||
)?;
|
||||
let is_no_input_no_output = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::EQ,
|
||||
context.xlen_type().const_zero(),
|
||||
input_length_or_output_length,
|
||||
"is_no_input_no_output",
|
||||
)?;
|
||||
let gas_stipend = context
|
||||
.xlen_type()
|
||||
.const_int(SOLIDITY_TRANSFER_GAS_STIPEND_THRESHOLD, false);
|
||||
let is_gas_stipend_for_transfer_or_send = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::EQ,
|
||||
gas,
|
||||
gas_stipend,
|
||||
"is_gas_stipend_for_transfer_or_send",
|
||||
)?;
|
||||
let is_balance_transfer = context.builder().build_and(
|
||||
is_no_input_no_output,
|
||||
is_gas_stipend_for_transfer_or_send,
|
||||
"is_balance_transfer",
|
||||
)?;
|
||||
let is_regular_call = context
|
||||
.builder()
|
||||
.build_not(is_balance_transfer, "is_balance_transfer_inverted")?;
|
||||
|
||||
// Call flag: Left shift the heuristic boolean value.
|
||||
let is_regular_call_xlen = context.builder().build_int_z_extend(
|
||||
is_regular_call,
|
||||
context.xlen_type(),
|
||||
"is_balance_transfer_xlen",
|
||||
)?;
|
||||
let call_flags = context.builder().build_left_shift(
|
||||
is_regular_call_xlen,
|
||||
context.xlen_type().const_int(3, false),
|
||||
"flags",
|
||||
)?;
|
||||
|
||||
// Deposit limit value: Sign-extended the heuristic boolean value.
|
||||
let deposit_limit_value = context.builder().build_int_s_extend(
|
||||
is_regular_call,
|
||||
context.word_type(),
|
||||
"deposit_limit_value",
|
||||
)?;
|
||||
|
||||
context.build_store(
|
||||
Pointer::new(context.word_type(), AddressSpace::Stack, deposit_pointer),
|
||||
deposit_limit_value,
|
||||
)?;
|
||||
|
||||
Ok(Some(call_flags.into()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> WriteLLVM<D> for CallReentrancyHeuristic
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
<Self as RuntimeFunction<_>>::declare(self, context)
|
||||
}
|
||||
|
||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
<Self as RuntimeFunction<_>>::emit(&self, context)
|
||||
}
|
||||
}
|
||||
|
||||
/// The Solidity `address.transfer` and `address.send` call detection heuristic.
|
||||
///
|
||||
/// # Why
|
||||
@@ -533,7 +236,7 @@ where
|
||||
///
|
||||
/// # Returns
|
||||
/// The call flags xlen `IntValue` and the deposit limit word `IntValue`.
|
||||
fn _call_reentrancy_heuristic<'ctx, D>(
|
||||
fn call_reentrancy_heuristic<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
gas: inkwell::values::IntValue<'ctx>,
|
||||
input_length: inkwell::values::IntValue<'ctx>,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use inkwell::values::BasicValue;
|
||||
|
||||
use crate::polkavm::context::pointer::Pointer;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
|
||||
@@ -50,9 +49,7 @@ where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
||||
let address_pointer: Pointer<'_> = context
|
||||
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
|
||||
.into();
|
||||
let address_pointer = context.build_alloca_at_entry(address_type, "origin_address");
|
||||
context.build_store(address_pointer, address_type.const_zero())?;
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::ORIGIN,
|
||||
@@ -100,13 +97,13 @@ where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let output_pointer = context.build_alloca_at_entry(context.word_type(), "blockhash_out_ptr");
|
||||
let index_pointer = context.build_alloca_at_entry(context.word_type(), "blockhash_index_ptr");
|
||||
context.build_store(index_pointer, index)?;
|
||||
let index_ptr = context.build_alloca_at_entry(context.word_type(), "blockhash_index_ptr");
|
||||
context.build_store(index_ptr, index)?;
|
||||
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::BLOCK_HASH,
|
||||
&[
|
||||
index_pointer.to_int(context).into(),
|
||||
index_ptr.to_int(context).into(),
|
||||
output_pointer.to_int(context).into(),
|
||||
],
|
||||
);
|
||||
@@ -130,9 +127,10 @@ pub fn coinbase<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let pointer: Pointer<'_> = context
|
||||
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
|
||||
.into();
|
||||
let pointer = context.build_alloca_at_entry(
|
||||
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
|
||||
"coinbase_output",
|
||||
);
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::BLOCK_AUTHOR,
|
||||
&[pointer.to_int(context).into()],
|
||||
@@ -157,9 +155,10 @@ pub fn address<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let pointer: Pointer<'_> = context
|
||||
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
|
||||
.into();
|
||||
let pointer = context.build_alloca_at_entry(
|
||||
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
|
||||
"address_output",
|
||||
);
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::ADDRESS,
|
||||
&[pointer.to_int(context).into()],
|
||||
@@ -174,9 +173,10 @@ pub fn caller<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let pointer: Pointer<'_> = context
|
||||
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
|
||||
.into();
|
||||
let pointer = context.build_alloca_at_entry(
|
||||
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
|
||||
"address_output",
|
||||
);
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::CALLER,
|
||||
&[pointer.to_int(context).into()],
|
||||
|
||||
@@ -32,7 +32,6 @@ where
|
||||
let salt_pointer = match salt {
|
||||
Some(salt) => {
|
||||
let salt_pointer = context.build_alloca_at_entry(context.word_type(), "salt_pointer");
|
||||
let salt = context.build_byte_swap(salt.into())?;
|
||||
context.build_store(salt_pointer, salt)?;
|
||||
salt_pointer
|
||||
}
|
||||
@@ -119,8 +118,10 @@ where
|
||||
_ => error,
|
||||
})?;
|
||||
if contract_path.as_str() == parent {
|
||||
return Ok(Argument::value(context.word_const(0).as_basic_value_enum())
|
||||
.with_constant(num::BigUint::zero()));
|
||||
return Ok(Argument::new_with_constant(
|
||||
context.word_const(0).as_basic_value_enum(),
|
||||
num::BigUint::zero(),
|
||||
));
|
||||
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
|
||||
anyhow::bail!("type({}).runtimeCode is not supported", identifier);
|
||||
}
|
||||
@@ -129,7 +130,7 @@ where
|
||||
let hash_value = context
|
||||
.word_const_str_hex(hash_string.as_str())
|
||||
.as_basic_value_enum();
|
||||
Ok(Argument::value(hash_value).with_original(hash_string))
|
||||
Ok(Argument::new_with_original(hash_value, hash_string))
|
||||
}
|
||||
|
||||
/// Translates the deploy call header size instruction. the header consists of
|
||||
@@ -158,8 +159,10 @@ where
|
||||
_ => error,
|
||||
})?;
|
||||
if contract_path.as_str() == parent {
|
||||
return Ok(Argument::value(context.word_const(0).as_basic_value_enum())
|
||||
.with_constant(num::BigUint::zero()));
|
||||
return Ok(Argument::new_with_constant(
|
||||
context.word_const(0).as_basic_value_enum(),
|
||||
num::BigUint::zero(),
|
||||
));
|
||||
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
|
||||
anyhow::bail!("type({}).runtimeCode is not supported", identifier);
|
||||
}
|
||||
@@ -168,5 +171,5 @@ where
|
||||
let size_value = context
|
||||
.word_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64)
|
||||
.as_basic_value_enum();
|
||||
Ok(Argument::value(size_value).with_constant(size_bigint))
|
||||
Ok(Argument::new_with_constant(size_value, size_bigint))
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ pub fn value<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let output_pointer = context.build_alloca_at_entry(context.value_type(), "value_transferred");
|
||||
let output_pointer = context.build_alloca(context.value_type(), "value_transferred");
|
||||
context.build_store(output_pointer, context.word_const(0))?;
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::VALUE_TRANSFERRED,
|
||||
@@ -46,7 +46,8 @@ where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let address_pointer = context.build_address_argument_store(address)?;
|
||||
let balance_pointer = context.build_alloca_at_entry(context.word_type(), "balance_pointer");
|
||||
|
||||
let balance_pointer = context.build_alloca(context.word_type(), "balance_pointer");
|
||||
let balance = context.builder().build_ptr_to_int(
|
||||
balance_pointer.value,
|
||||
context.xlen_type(),
|
||||
@@ -68,7 +69,7 @@ pub fn self_balance<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let balance_pointer = context.build_alloca_at_entry(context.word_type(), "balance_pointer");
|
||||
let balance_pointer = context.build_alloca(context.word_type(), "balance_pointer");
|
||||
let balance = context.builder().build_ptr_to_int(
|
||||
balance_pointer.value,
|
||||
context.xlen_type(),
|
||||
|
||||
@@ -3,23 +3,20 @@
|
||||
use crate::polkavm::context::runtime::RuntimeFunction;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
use crate::PolkaVMArgument;
|
||||
use crate::PolkaVMLoadStorageWordFunction;
|
||||
use crate::PolkaVMLoadTransientStorageWordFunction;
|
||||
use crate::PolkaVMStoreStorageWordFunction;
|
||||
use crate::PolkaVMStoreTransientStorageWordFunction;
|
||||
|
||||
/// Translates the storage load.
|
||||
pub fn load<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
position: &PolkaVMArgument<'ctx>,
|
||||
position: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let name = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::NAME;
|
||||
let declaration = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
||||
let arguments = [position.to_pointer(context)?.value.into()];
|
||||
let arguments = [context.xlen_type().const_zero().into(), position.into()];
|
||||
Ok(context
|
||||
.build_call(declaration, &arguments, "storage_load")
|
||||
.unwrap_or_else(|| panic!("runtime function {name} should return a value")))
|
||||
@@ -28,16 +25,17 @@ where
|
||||
/// Translates the storage store.
|
||||
pub fn store<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
position: &PolkaVMArgument<'ctx>,
|
||||
value: &PolkaVMArgument<'ctx>,
|
||||
position: inkwell::values::IntValue<'ctx>,
|
||||
value: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let declaration = <PolkaVMStoreStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
||||
let arguments = [
|
||||
position.to_pointer(context)?.value.into(),
|
||||
value.to_pointer(context)?.value.into(),
|
||||
context.xlen_type().const_zero().into(),
|
||||
position.into(),
|
||||
value.into(),
|
||||
];
|
||||
context.build_call(declaration, &arguments, "storage_store");
|
||||
Ok(())
|
||||
@@ -46,35 +44,37 @@ where
|
||||
/// Translates the transient storage load.
|
||||
pub fn transient_load<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
position: &PolkaVMArgument<'ctx>,
|
||||
position: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let name = <PolkaVMLoadTransientStorageWordFunction as RuntimeFunction<D>>::NAME;
|
||||
let arguments = [position.to_pointer(context)?.value.into()];
|
||||
let declaration =
|
||||
<PolkaVMLoadTransientStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
||||
let name = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::NAME;
|
||||
let declaration = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
||||
let arguments = [
|
||||
context.xlen_type().const_int(1, false).into(),
|
||||
position.into(),
|
||||
];
|
||||
Ok(context
|
||||
.build_call(declaration, &arguments, "transient_storage_load")
|
||||
.build_call(declaration, &arguments, "storage_load")
|
||||
.unwrap_or_else(|| panic!("runtime function {name} should return a value")))
|
||||
}
|
||||
|
||||
/// Translates the transient storage store.
|
||||
pub fn transient_store<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
position: &PolkaVMArgument<'ctx>,
|
||||
value: &PolkaVMArgument<'ctx>,
|
||||
position: inkwell::values::IntValue<'ctx>,
|
||||
value: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let declaration =
|
||||
<PolkaVMStoreTransientStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
||||
let declaration = <PolkaVMStoreStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
||||
let arguments = [
|
||||
position.to_pointer(context)?.value.into(),
|
||||
value.to_pointer(context)?.value.into(),
|
||||
context.xlen_type().const_int(1, false).into(),
|
||||
position.into(),
|
||||
value.into(),
|
||||
];
|
||||
context.build_call(declaration, &arguments, "transient_storage_store");
|
||||
context.build_call(declaration, &arguments, "storage_store");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
pub mod r#const;
|
||||
pub mod context;
|
||||
pub mod evm;
|
||||
pub mod metadata_hash;
|
||||
|
||||
pub use self::r#const::*;
|
||||
|
||||
@@ -17,6 +18,11 @@ use sha3::Digest;
|
||||
use self::context::build::Build;
|
||||
use self::context::Context;
|
||||
|
||||
/// Initializes the PolkaVM target machine.
|
||||
pub fn initialize_target() {
|
||||
inkwell::targets::Target::initialize_riscv(&Default::default());
|
||||
}
|
||||
|
||||
/// Builds PolkaVM assembly text.
|
||||
pub fn build_assembly_text(
|
||||
contract_path: &str,
|
||||
@@ -89,7 +95,6 @@ pub trait Dependency {
|
||||
optimizer_settings: OptimizerSettings,
|
||||
include_metadata_hash: bool,
|
||||
debug_config: DebugConfig,
|
||||
llvm_arguments: &[String],
|
||||
) -> anyhow::Result<String>;
|
||||
|
||||
/// Resolves a full contract path.
|
||||
@@ -110,7 +115,6 @@ impl Dependency for DummyDependency {
|
||||
_optimizer_settings: OptimizerSettings,
|
||||
_include_metadata_hash: bool,
|
||||
_debug_config: DebugConfig,
|
||||
_llvm_arguments: &[String],
|
||||
) -> anyhow::Result<String> {
|
||||
Ok(String::new())
|
||||
}
|
||||
|
||||
@@ -106,10 +106,14 @@ impl SpecsAction {
|
||||
};
|
||||
|
||||
for (key, expected) in storage {
|
||||
let mut key = **key;
|
||||
let mut expected = **expected;
|
||||
key.reverse();
|
||||
expected.reverse();
|
||||
actions.push(Self::VerifyStorage {
|
||||
contract: account_pvm.clone(),
|
||||
key: **key,
|
||||
expected: **expected,
|
||||
key,
|
||||
expected,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
[package]
|
||||
name = "revive-solc-json-interface"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
repository.workspace = true
|
||||
rust-version.workspace = true
|
||||
description = "Rust bindings for the solc standard JSON and combined JSON interface"
|
||||
|
||||
[features]
|
||||
default = ["parallel"]
|
||||
parallel = ["rayon"]
|
||||
resolc = [] # The resolc binary adds a bunch of custom fields to the format
|
||||
|
||||
[dependencies]
|
||||
revive-common = { workspace = true }
|
||||
|
||||
anyhow = { workspace = true }
|
||||
rayon = { workspace = true, optional = true }
|
||||
semver = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
@@ -1,27 +0,0 @@
|
||||
//! This crates provides (de)serializable Rust types for interacting
|
||||
//! `solc` via the [JSON-input-output][0] interface.
|
||||
//!
|
||||
//! [0]: https://docs.soliditylang.org/en/latest/using-the-compiler.html#compiler-input-and-output-json-description
|
||||
|
||||
pub use self::combined_json::contract::Contract as CombinedJsonContract;
|
||||
pub use self::standard_json::input::language::Language as SolcStandardJsonInputLanguage;
|
||||
pub use self::standard_json::input::settings::metadata::Metadata as SolcStandardJsonInputSettingsMetadata;
|
||||
pub use self::standard_json::input::settings::metadata_hash::MetadataHash as SolcStandardJsonInputSettingsMetadataHash;
|
||||
pub use self::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
|
||||
pub use self::standard_json::input::settings::selection::file::flag::Flag as SolcStandardJsonInputSettingsSelectionFileFlag;
|
||||
pub use self::standard_json::input::settings::selection::file::File as SolcStandardJsonInputSettingsSelectionFile;
|
||||
pub use self::standard_json::input::settings::selection::Selection as SolcStandardJsonInputSettingsSelection;
|
||||
pub use self::standard_json::input::settings::Settings as SolcStandardJsonInputSettings;
|
||||
pub use self::standard_json::input::source::Source as SolcStandardJsonInputSource;
|
||||
pub use self::standard_json::input::Input as SolcStandardJsonInput;
|
||||
pub use self::standard_json::output::contract::evm::bytecode::Bytecode as SolcStandardJsonOutputContractEVMBytecode;
|
||||
pub use self::standard_json::output::contract::evm::EVM as SolcStandardJsonOutputContractEVM;
|
||||
pub use self::standard_json::output::contract::Contract as SolcStandardJsonOutputContract;
|
||||
pub use self::standard_json::output::Output as SolcStandardJsonOutput;
|
||||
#[cfg(feature = "resolc")]
|
||||
pub use self::warning::Warning as ResolcWarning;
|
||||
|
||||
pub mod combined_json;
|
||||
pub mod standard_json;
|
||||
#[cfg(feature = "resolc")]
|
||||
pub mod warning;
|
||||
@@ -1,4 +0,0 @@
|
||||
//! The `solc <input>.sol --standard-json` interface input and output.
|
||||
|
||||
pub mod input;
|
||||
pub mod output;
|
||||
@@ -1,71 +0,0 @@
|
||||
//! The `solc --standard-json` output.
|
||||
|
||||
pub mod contract;
|
||||
pub mod error;
|
||||
pub mod source;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
#[cfg(feature = "resolc")]
|
||||
use crate::warning::Warning;
|
||||
|
||||
use self::contract::Contract;
|
||||
use self::error::Error as SolcStandardJsonOutputError;
|
||||
use self::source::Source;
|
||||
|
||||
/// The `solc --standard-json` output.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct Output {
|
||||
/// The file-contract hashmap.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub contracts: Option<BTreeMap<String, BTreeMap<String, Contract>>>,
|
||||
/// The source code mapping data.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub sources: Option<BTreeMap<String, Source>>,
|
||||
/// The compilation errors and warnings.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub errors: Option<Vec<SolcStandardJsonOutputError>>,
|
||||
/// The `solc` compiler version.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub version: Option<String>,
|
||||
/// The `solc` compiler long version.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub long_version: Option<String>,
|
||||
/// The `resolc` compiler version.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub revive_version: Option<String>,
|
||||
}
|
||||
|
||||
impl Output {
|
||||
/// Traverses the AST and returns the list of additional errors and warnings.
|
||||
#[cfg(feature = "resolc")]
|
||||
pub fn preprocess_ast(&mut self, suppressed_warnings: &[Warning]) -> anyhow::Result<()> {
|
||||
let sources = match self.sources.as_ref() {
|
||||
Some(sources) => sources,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
let mut messages = Vec::new();
|
||||
for (path, source) in sources.iter() {
|
||||
if let Some(ast) = source.ast.as_ref() {
|
||||
let mut polkavm_messages = Source::get_messages(ast, suppressed_warnings);
|
||||
for message in polkavm_messages.iter_mut() {
|
||||
message.push_contract_path(path.as_str());
|
||||
}
|
||||
messages.extend(polkavm_messages);
|
||||
}
|
||||
}
|
||||
self.errors = match self.errors.take() {
|
||||
Some(mut errors) => {
|
||||
errors.extend(messages);
|
||||
Some(errors)
|
||||
}
|
||||
None => Some(messages),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,6 @@ inkwell = { workspace = true }
|
||||
|
||||
revive-common = { workspace = true }
|
||||
revive-llvm-context = { workspace = true }
|
||||
revive-solc-json-interface = { workspace = true, features = ["resolc"] }
|
||||
|
||||
[target.'cfg(target_env = "musl")'.dependencies]
|
||||
mimalloc = { version = "*", default-features = false }
|
||||
|
||||
@@ -5,11 +5,12 @@ use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
use revive_solc_json_interface::CombinedJsonContract;
|
||||
use revive_solc_json_interface::SolcStandardJsonOutputContract;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::solc::combined_json::contract::Contract as CombinedJsonContract;
|
||||
use crate::solc::standard_json::output::contract::Contract as StandardJsonOutputContract;
|
||||
|
||||
/// The Solidity contract build.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Contract {
|
||||
@@ -130,7 +131,7 @@ impl Contract {
|
||||
/// Writes the contract text assembly and bytecode to the standard JSON.
|
||||
pub fn write_to_standard_json(
|
||||
self,
|
||||
standard_json_contract: &mut SolcStandardJsonOutputContract,
|
||||
standard_json_contract: &mut StandardJsonOutputContract,
|
||||
) -> anyhow::Result<()> {
|
||||
standard_json_contract.metadata = Some(self.metadata_json);
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@ pub mod contract;
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::Path;
|
||||
|
||||
use revive_solc_json_interface::combined_json::CombinedJson;
|
||||
use revive_solc_json_interface::SolcStandardJsonOutput;
|
||||
|
||||
use crate::solc::combined_json::CombinedJson;
|
||||
use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
||||
use crate::solc::version::Version as SolcVersion;
|
||||
use crate::ResolcVersion;
|
||||
|
||||
@@ -67,7 +66,7 @@ impl Build {
|
||||
/// Writes all contracts assembly and bytecode to the standard JSON.
|
||||
pub fn write_to_standard_json(
|
||||
mut self,
|
||||
standard_json: &mut SolcStandardJsonOutput,
|
||||
standard_json: &mut StandardJsonOutput,
|
||||
solc_version: &SolcVersion,
|
||||
) -> anyhow::Result<()> {
|
||||
let contracts = match standard_json.contracts.as_mut() {
|
||||
|
||||
+31
-58
@@ -7,6 +7,7 @@ pub(crate) mod process;
|
||||
pub(crate) mod project;
|
||||
pub(crate) mod solc;
|
||||
pub(crate) mod version;
|
||||
pub(crate) mod warning;
|
||||
pub(crate) mod yul;
|
||||
|
||||
pub use self::build::contract::Contract as ContractBuild;
|
||||
@@ -22,16 +23,29 @@ pub use self::process::Process;
|
||||
pub use self::project::contract::Contract as ProjectContract;
|
||||
pub use self::project::Project;
|
||||
pub use self::r#const::*;
|
||||
pub use self::solc::combined_json::contract::Contract as SolcCombinedJsonContract;
|
||||
pub use self::solc::combined_json::CombinedJson as SolcCombinedJson;
|
||||
#[cfg(not(target_os = "emscripten"))]
|
||||
pub use self::solc::solc_compiler::SolcCompiler;
|
||||
#[cfg(target_os = "emscripten")]
|
||||
pub use self::solc::soljson_compiler::SoljsonCompiler;
|
||||
pub use self::solc::standard_json::input::language::Language as SolcStandardJsonInputLanguage;
|
||||
pub use self::solc::standard_json::input::settings::metadata::Metadata as SolcStandardJsonInputSettingsMetadata;
|
||||
pub use self::solc::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
|
||||
pub use self::solc::standard_json::input::settings::selection::file::flag::Flag as SolcStandardJsonInputSettingsSelectionFileFlag;
|
||||
pub use self::solc::standard_json::input::settings::selection::file::File as SolcStandardJsonInputSettingsSelectionFile;
|
||||
pub use self::solc::standard_json::input::settings::selection::Selection as SolcStandardJsonInputSettingsSelection;
|
||||
pub use self::solc::standard_json::input::settings::Settings as SolcStandardJsonInputSettings;
|
||||
pub use self::solc::standard_json::input::source::Source as SolcStandardJsonInputSource;
|
||||
pub use self::solc::standard_json::input::Input as SolcStandardJsonInput;
|
||||
pub use self::solc::standard_json::output::contract::evm::bytecode::Bytecode as SolcStandardJsonOutputContractEVMBytecode;
|
||||
pub use self::solc::standard_json::output::contract::evm::EVM as SolcStandardJsonOutputContractEVM;
|
||||
pub use self::solc::standard_json::output::contract::Contract as SolcStandardJsonOutputContract;
|
||||
pub use self::solc::standard_json::output::Output as SolcStandardJsonOutput;
|
||||
pub use self::solc::version::Version as SolcVersion;
|
||||
pub use self::solc::Compiler;
|
||||
pub use self::solc::FIRST_SUPPORTED_VERSION as SolcFirstSupportedVersion;
|
||||
pub use self::solc::LAST_SUPPORTED_VERSION as SolcLastSupportedVersion;
|
||||
pub use self::version::Version as ResolcVersion;
|
||||
|
||||
pub use self::warning::Warning;
|
||||
#[cfg(not(target_os = "emscripten"))]
|
||||
pub mod test_utils;
|
||||
pub mod tests;
|
||||
@@ -40,13 +54,6 @@ use std::collections::BTreeSet;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use revive_solc_json_interface::standard_json::input::settings::metadata_hash::MetadataHash;
|
||||
use revive_solc_json_interface::ResolcWarning;
|
||||
use revive_solc_json_interface::SolcStandardJsonInput;
|
||||
use revive_solc_json_interface::SolcStandardJsonInputLanguage;
|
||||
use revive_solc_json_interface::SolcStandardJsonInputSettingsOptimizer;
|
||||
use revive_solc_json_interface::SolcStandardJsonInputSettingsSelection;
|
||||
|
||||
/// Runs the Yul mode.
|
||||
pub fn yul<T: Compiler>(
|
||||
input_files: &[PathBuf],
|
||||
@@ -54,7 +61,6 @@ pub fn yul<T: Compiler>(
|
||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||
include_metadata_hash: bool,
|
||||
debug_config: revive_llvm_context::DebugConfig,
|
||||
llvm_arguments: &[String],
|
||||
) -> anyhow::Result<Build> {
|
||||
let path = match input_files.len() {
|
||||
1 => input_files.first().expect("Always exists"),
|
||||
@@ -75,12 +81,7 @@ pub fn yul<T: Compiler>(
|
||||
let solc_validator = Some(&*solc);
|
||||
let project = Project::try_from_yul_path(path, solc_validator)?;
|
||||
|
||||
let build = project.compile(
|
||||
optimizer_settings,
|
||||
include_metadata_hash,
|
||||
debug_config,
|
||||
llvm_arguments,
|
||||
)?;
|
||||
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||
|
||||
Ok(build)
|
||||
}
|
||||
@@ -91,7 +92,6 @@ pub fn llvm_ir(
|
||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||
include_metadata_hash: bool,
|
||||
debug_config: revive_llvm_context::DebugConfig,
|
||||
llvm_arguments: &[String],
|
||||
) -> anyhow::Result<Build> {
|
||||
let path = match input_files.len() {
|
||||
1 => input_files.first().expect("Always exists"),
|
||||
@@ -104,12 +104,7 @@ pub fn llvm_ir(
|
||||
|
||||
let project = Project::try_from_llvm_ir_path(path)?;
|
||||
|
||||
let build = project.compile(
|
||||
optimizer_settings,
|
||||
include_metadata_hash,
|
||||
debug_config,
|
||||
llvm_arguments,
|
||||
)?;
|
||||
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||
|
||||
Ok(build)
|
||||
}
|
||||
@@ -128,9 +123,8 @@ pub fn standard_output<T: Compiler>(
|
||||
include_paths: Vec<String>,
|
||||
allow_paths: Option<String>,
|
||||
remappings: Option<BTreeSet<String>>,
|
||||
suppressed_warnings: Option<Vec<ResolcWarning>>,
|
||||
suppressed_warnings: Option<Vec<Warning>>,
|
||||
debug_config: revive_llvm_context::DebugConfig,
|
||||
llvm_arguments: &[String],
|
||||
) -> anyhow::Result<Build> {
|
||||
let solc_version = solc.version()?;
|
||||
|
||||
@@ -158,7 +152,7 @@ pub fn standard_output<T: Compiler>(
|
||||
.collect();
|
||||
|
||||
let libraries = solc_input.settings.libraries.clone().unwrap_or_default();
|
||||
let solc_output = solc.standard_json(solc_input, base_path, include_paths, allow_paths)?;
|
||||
let mut solc_output = solc.standard_json(solc_input, base_path, include_paths, allow_paths)?;
|
||||
|
||||
if let Some(errors) = solc_output.errors.as_deref() {
|
||||
let mut has_errors = false;
|
||||
@@ -176,20 +170,10 @@ pub fn standard_output<T: Compiler>(
|
||||
}
|
||||
}
|
||||
|
||||
let project = Project::try_from_standard_json_output(
|
||||
&solc_output,
|
||||
source_code_files,
|
||||
libraries,
|
||||
&solc_version,
|
||||
&debug_config,
|
||||
)?;
|
||||
let project =
|
||||
solc_output.try_to_project(source_code_files, libraries, &solc_version, &debug_config)?;
|
||||
|
||||
let build = project.compile(
|
||||
optimizer_settings,
|
||||
include_metadata_hash,
|
||||
debug_config,
|
||||
llvm_arguments,
|
||||
)?;
|
||||
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||
|
||||
Ok(build)
|
||||
}
|
||||
@@ -202,7 +186,6 @@ pub fn standard_json<T: Compiler>(
|
||||
include_paths: Vec<String>,
|
||||
allow_paths: Option<String>,
|
||||
debug_config: revive_llvm_context::DebugConfig,
|
||||
llvm_arguments: &[String],
|
||||
) -> anyhow::Result<()> {
|
||||
let solc_version = solc.version()?;
|
||||
|
||||
@@ -217,7 +200,9 @@ pub fn standard_json<T: Compiler>(
|
||||
revive_llvm_context::OptimizerSettings::try_from(&solc_input.settings.optimizer)?;
|
||||
|
||||
let include_metadata_hash = match solc_input.settings.metadata {
|
||||
Some(ref metadata) => metadata.bytecode_hash != Some(MetadataHash::None),
|
||||
Some(ref metadata) => {
|
||||
metadata.bytecode_hash != Some(revive_llvm_context::PolkaVMMetadataHash::None)
|
||||
}
|
||||
None => true,
|
||||
};
|
||||
|
||||
@@ -233,24 +218,14 @@ pub fn standard_json<T: Compiler>(
|
||||
}
|
||||
}
|
||||
|
||||
let project = Project::try_from_standard_json_output(
|
||||
&solc_output,
|
||||
source_code_files,
|
||||
libraries,
|
||||
&solc_version,
|
||||
&debug_config,
|
||||
)?;
|
||||
let project =
|
||||
solc_output.try_to_project(source_code_files, libraries, &solc_version, &debug_config)?;
|
||||
|
||||
if detect_missing_libraries {
|
||||
let missing_libraries = project.get_missing_libraries();
|
||||
missing_libraries.write_to_standard_json(&mut solc_output, &solc_version)?;
|
||||
} else {
|
||||
let build = project.compile(
|
||||
optimizer_settings,
|
||||
include_metadata_hash,
|
||||
debug_config,
|
||||
llvm_arguments,
|
||||
)?;
|
||||
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||
build.write_to_standard_json(&mut solc_output, &solc_version)?;
|
||||
}
|
||||
serde_json::to_writer(std::io::stdout(), &solc_output)?;
|
||||
@@ -272,11 +247,10 @@ pub fn combined_json<T: Compiler>(
|
||||
include_paths: Vec<String>,
|
||||
allow_paths: Option<String>,
|
||||
remappings: Option<BTreeSet<String>>,
|
||||
suppressed_warnings: Option<Vec<ResolcWarning>>,
|
||||
suppressed_warnings: Option<Vec<Warning>>,
|
||||
debug_config: revive_llvm_context::DebugConfig,
|
||||
output_directory: Option<PathBuf>,
|
||||
overwrite: bool,
|
||||
llvm_arguments: &[String],
|
||||
) -> anyhow::Result<()> {
|
||||
let build = standard_output(
|
||||
input_files,
|
||||
@@ -292,7 +266,6 @@ pub fn combined_json<T: Compiler>(
|
||||
remappings,
|
||||
suppressed_warnings,
|
||||
debug_config,
|
||||
llvm_arguments,
|
||||
)?;
|
||||
|
||||
let mut combined_json = solc.combined_json(input_files, format.as_str())?;
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use revive_solc_json_interface::SolcStandardJsonOutput;
|
||||
|
||||
use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
||||
use crate::solc::version::Version as SolcVersion;
|
||||
use crate::ResolcVersion;
|
||||
|
||||
@@ -23,7 +22,7 @@ impl MissingLibraries {
|
||||
/// Writes the missing libraries to the standard JSON.
|
||||
pub fn write_to_standard_json(
|
||||
mut self,
|
||||
standard_json: &mut SolcStandardJsonOutput,
|
||||
standard_json: &mut StandardJsonOutput,
|
||||
solc_version: &SolcVersion,
|
||||
) -> anyhow::Result<()> {
|
||||
let contracts = match standard_json.contracts.as_mut() {
|
||||
|
||||
@@ -20,8 +20,6 @@ pub struct Input {
|
||||
pub optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||
/// The debug output config.
|
||||
pub debug_config: revive_llvm_context::DebugConfig,
|
||||
/// The extra LLVM arguments give used for manual control.
|
||||
pub llvm_arguments: Vec<String>,
|
||||
}
|
||||
|
||||
impl Input {
|
||||
@@ -32,7 +30,6 @@ impl Input {
|
||||
include_metadata_hash: bool,
|
||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||
debug_config: revive_llvm_context::DebugConfig,
|
||||
llvm_arguments: Vec<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
contract,
|
||||
@@ -40,7 +37,6 @@ impl Input {
|
||||
include_metadata_hash,
|
||||
optimizer_settings,
|
||||
debug_config,
|
||||
llvm_arguments,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,19 +37,11 @@ pub trait Process {
|
||||
}
|
||||
|
||||
let input: Input = revive_common::deserialize_from_slice(buffer.as_slice())?;
|
||||
|
||||
revive_llvm_context::initialize_llvm(
|
||||
revive_llvm_context::Target::PVM,
|
||||
crate::DEFAULT_EXECUTABLE_NAME,
|
||||
&input.llvm_arguments,
|
||||
);
|
||||
|
||||
let result = input.contract.compile(
|
||||
input.project,
|
||||
input.optimizer_settings,
|
||||
input.include_metadata_hash,
|
||||
input.debug_config,
|
||||
&input.llvm_arguments,
|
||||
);
|
||||
|
||||
match result {
|
||||
|
||||
@@ -18,8 +18,6 @@ pub struct Metadata {
|
||||
pub revive_version: String,
|
||||
/// The PolkaVM compiler optimizer settings.
|
||||
pub optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||
/// The extra LLVM arguments give used for manual control.
|
||||
pub llvm_arguments: Vec<String>,
|
||||
}
|
||||
|
||||
impl Metadata {
|
||||
@@ -29,7 +27,6 @@ impl Metadata {
|
||||
solc_version: String,
|
||||
revive_pallet_version: Option<semver::Version>,
|
||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||
llvm_arguments: Vec<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
solc_metadata,
|
||||
@@ -37,7 +34,6 @@ impl Metadata {
|
||||
revive_pallet_version,
|
||||
revive_version: ResolcVersion::default().long,
|
||||
optimizer_settings,
|
||||
llvm_arguments,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ impl Contract {
|
||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||
include_metadata_hash: bool,
|
||||
debug_config: revive_llvm_context::DebugConfig,
|
||||
llvm_arguments: &[String],
|
||||
) -> anyhow::Result<ContractBuild> {
|
||||
let llvm = inkwell::context::Context::create();
|
||||
let optimizer = revive_llvm_context::Optimizer::new(optimizer_settings);
|
||||
@@ -90,7 +89,6 @@ impl Contract {
|
||||
version.long.clone(),
|
||||
version.l2_revision.clone(),
|
||||
optimizer.settings().to_owned(),
|
||||
llvm_arguments.to_vec(),
|
||||
);
|
||||
let metadata_json = serde_json::to_value(&metadata).expect("Always valid");
|
||||
let metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]> = if include_metadata_hash
|
||||
@@ -122,7 +120,6 @@ impl Contract {
|
||||
Some(project),
|
||||
include_metadata_hash,
|
||||
debug_config,
|
||||
llvm_arguments,
|
||||
);
|
||||
context.set_solidity_data(revive_llvm_context::PolkaVMContextSolidityData::default());
|
||||
match self.ir {
|
||||
|
||||
@@ -9,7 +9,6 @@ use std::path::Path;
|
||||
|
||||
#[cfg(feature = "parallel")]
|
||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||
use revive_solc_json_interface::SolcStandardJsonOutput;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use sha3::Digest;
|
||||
@@ -66,7 +65,6 @@ impl Project {
|
||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||
include_metadata_hash: bool,
|
||||
debug_config: revive_llvm_context::DebugConfig,
|
||||
llvm_arguments: &[String],
|
||||
) -> anyhow::Result<Build> {
|
||||
let project = self.clone();
|
||||
#[cfg(feature = "parallel")]
|
||||
@@ -82,7 +80,6 @@ impl Project {
|
||||
include_metadata_hash,
|
||||
optimizer_settings.clone(),
|
||||
debug_config.clone(),
|
||||
llvm_arguments.to_vec(),
|
||||
);
|
||||
let process_output = {
|
||||
#[cfg(target_os = "emscripten")]
|
||||
@@ -246,69 +243,6 @@ impl Project {
|
||||
BTreeMap::new(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Converts the `solc` JSON output into a convenient project.
|
||||
pub fn try_from_standard_json_output(
|
||||
output: &SolcStandardJsonOutput,
|
||||
source_code_files: BTreeMap<String, String>,
|
||||
libraries: BTreeMap<String, BTreeMap<String, String>>,
|
||||
solc_version: &SolcVersion,
|
||||
debug_config: &revive_llvm_context::DebugConfig,
|
||||
) -> anyhow::Result<Self> {
|
||||
let files = match output.contracts.as_ref() {
|
||||
Some(files) => files,
|
||||
None => match &output.errors {
|
||||
Some(errors) if errors.iter().any(|e| e.severity == "error") => {
|
||||
anyhow::bail!(serde_json::to_string_pretty(errors).expect("Always valid"));
|
||||
}
|
||||
_ => &BTreeMap::new(),
|
||||
},
|
||||
};
|
||||
let mut project_contracts = BTreeMap::new();
|
||||
|
||||
for (path, contracts) in files.iter() {
|
||||
for (name, contract) in contracts.iter() {
|
||||
let full_path = format!("{path}:{name}");
|
||||
|
||||
let ir_optimized = match contract.ir_optimized.to_owned() {
|
||||
Some(ir_optimized) => ir_optimized,
|
||||
None => continue,
|
||||
};
|
||||
if ir_optimized.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
debug_config.dump_yul(full_path.as_str(), ir_optimized.as_str())?;
|
||||
|
||||
let mut lexer = Lexer::new(ir_optimized.to_owned());
|
||||
let object = Object::parse(&mut lexer, None).map_err(|error| {
|
||||
anyhow::anyhow!("Contract `{}` parsing error: {:?}", full_path, error)
|
||||
})?;
|
||||
|
||||
let source = IR::new_yul(ir_optimized.to_owned(), object);
|
||||
|
||||
let source_code = source_code_files
|
||||
.get(path.as_str())
|
||||
.ok_or_else(|| anyhow::anyhow!("Source code for path `{}` not found", path))?;
|
||||
let source_hash = sha3::Keccak256::digest(source_code.as_bytes()).into();
|
||||
|
||||
let project_contract = Contract::new(
|
||||
full_path.clone(),
|
||||
source_hash,
|
||||
solc_version.to_owned(),
|
||||
source,
|
||||
contract.metadata.to_owned(),
|
||||
);
|
||||
project_contracts.insert(full_path, project_contract);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Project::new(
|
||||
solc_version.to_owned(),
|
||||
project_contracts,
|
||||
libraries,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl revive_llvm_context::PolkaVMDependency for Project {
|
||||
@@ -318,7 +252,6 @@ impl revive_llvm_context::PolkaVMDependency for Project {
|
||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||
include_metadata_hash: bool,
|
||||
debug_config: revive_llvm_context::DebugConfig,
|
||||
llvm_arguments: &[String],
|
||||
) -> anyhow::Result<String> {
|
||||
let contract_path = project.resolve_path(identifier)?;
|
||||
let contract = project
|
||||
@@ -338,7 +271,6 @@ impl revive_llvm_context::PolkaVMDependency for Project {
|
||||
optimizer_settings,
|
||||
include_metadata_hash,
|
||||
debug_config,
|
||||
llvm_arguments,
|
||||
)
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!(
|
||||
|
||||
@@ -19,10 +19,6 @@ pub struct Arguments {
|
||||
#[arg(long = "version")]
|
||||
pub version: bool,
|
||||
|
||||
/// Print supported `solc` versions and exit.
|
||||
#[arg(long = "supported-solc-versions")]
|
||||
pub supported_solc_versions: bool,
|
||||
|
||||
/// Print the licence and exit.
|
||||
#[arg(long = "license")]
|
||||
pub license: bool,
|
||||
@@ -166,10 +162,6 @@ pub struct Arguments {
|
||||
#[cfg(debug_assertions)]
|
||||
#[arg(long = "recursive-process-input")]
|
||||
pub recursive_process_input: Option<String>,
|
||||
|
||||
#[arg(long = "llvm-arg")]
|
||||
/// These are passed to LLVM as the command line to allow manual control.
|
||||
pub llvm_arguments: Vec<String>,
|
||||
}
|
||||
|
||||
impl Arguments {
|
||||
@@ -179,12 +171,6 @@ impl Arguments {
|
||||
anyhow::bail!("No other options are allowed while getting the compiler version.");
|
||||
}
|
||||
|
||||
if self.supported_solc_versions && std::env::args().count() > 2 {
|
||||
anyhow::bail!(
|
||||
"No other options are allowed while getting the supported `solc` versions."
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
if self.recursive_process_input.is_some() && !self.recursive_process {
|
||||
anyhow::bail!("--process-input can be only used when --recursive-process is given");
|
||||
|
||||
@@ -41,16 +41,6 @@ fn main_inner() -> anyhow::Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if arguments.supported_solc_versions {
|
||||
writeln!(
|
||||
std::io::stdout(),
|
||||
">={},<={}",
|
||||
revive_solidity::SolcFirstSupportedVersion,
|
||||
revive_solidity::SolcLastSupportedVersion,
|
||||
)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if arguments.license {
|
||||
let license_mit = include_str!("../../../../LICENSE-MIT");
|
||||
let license_apache = include_str!("../../../../LICENSE-APACHE");
|
||||
@@ -64,6 +54,8 @@ fn main_inner() -> anyhow::Result<()> {
|
||||
.stack_size(RAYON_WORKER_STACK_SIZE)
|
||||
.build_global()
|
||||
.expect("Thread pool configuration failure");
|
||||
inkwell::support::enable_llvm_pretty_stack_trace();
|
||||
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM); // TODO: pass from CLI
|
||||
|
||||
if arguments.recursive_process {
|
||||
#[cfg(debug_assertions)]
|
||||
@@ -102,7 +94,7 @@ fn main_inner() -> anyhow::Result<()> {
|
||||
let (input_files, remappings) = arguments.split_input_files_and_remappings()?;
|
||||
|
||||
let suppressed_warnings = match arguments.suppress_warnings {
|
||||
Some(warnings) => Some(revive_solc_json_interface::ResolcWarning::try_from_strings(
|
||||
Some(warnings) => Some(revive_solidity::Warning::try_from_strings(
|
||||
warnings.as_slice(),
|
||||
)?),
|
||||
None => None,
|
||||
@@ -140,10 +132,8 @@ fn main_inner() -> anyhow::Result<()> {
|
||||
let include_metadata_hash = match arguments.metadata_hash {
|
||||
Some(metadata_hash) => {
|
||||
let metadata =
|
||||
revive_solc_json_interface::SolcStandardJsonInputSettingsMetadataHash::from_str(
|
||||
metadata_hash.as_str(),
|
||||
)?;
|
||||
metadata != revive_solc_json_interface::SolcStandardJsonInputSettingsMetadataHash::None
|
||||
revive_llvm_context::PolkaVMMetadataHash::from_str(metadata_hash.as_str())?;
|
||||
metadata != revive_llvm_context::PolkaVMMetadataHash::None
|
||||
}
|
||||
None => true,
|
||||
};
|
||||
@@ -155,7 +145,6 @@ fn main_inner() -> anyhow::Result<()> {
|
||||
optimizer_settings,
|
||||
include_metadata_hash,
|
||||
debug_config,
|
||||
&arguments.llvm_arguments,
|
||||
)
|
||||
} else if arguments.llvm_ir {
|
||||
revive_solidity::llvm_ir(
|
||||
@@ -163,7 +152,6 @@ fn main_inner() -> anyhow::Result<()> {
|
||||
optimizer_settings,
|
||||
include_metadata_hash,
|
||||
debug_config,
|
||||
&arguments.llvm_arguments,
|
||||
)
|
||||
} else if arguments.standard_json {
|
||||
revive_solidity::standard_json(
|
||||
@@ -173,7 +161,6 @@ fn main_inner() -> anyhow::Result<()> {
|
||||
arguments.include_paths,
|
||||
arguments.allow_paths,
|
||||
debug_config,
|
||||
&arguments.llvm_arguments,
|
||||
)?;
|
||||
return Ok(());
|
||||
} else if let Some(format) = arguments.combined_json {
|
||||
@@ -194,7 +181,6 @@ fn main_inner() -> anyhow::Result<()> {
|
||||
debug_config,
|
||||
arguments.output_directory,
|
||||
arguments.overwrite,
|
||||
&arguments.llvm_arguments,
|
||||
)?;
|
||||
return Ok(());
|
||||
} else {
|
||||
@@ -212,7 +198,6 @@ fn main_inner() -> anyhow::Result<()> {
|
||||
remappings,
|
||||
suppressed_warnings,
|
||||
debug_config,
|
||||
&arguments.llvm_arguments,
|
||||
)
|
||||
}?;
|
||||
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
//! The Solidity compiler.
|
||||
|
||||
pub mod combined_json;
|
||||
#[cfg(not(target_os = "emscripten"))]
|
||||
pub mod solc_compiler;
|
||||
#[cfg(target_os = "emscripten")]
|
||||
pub mod soljson_compiler;
|
||||
pub mod standard_json;
|
||||
pub mod version;
|
||||
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use revive_solc_json_interface::combined_json::CombinedJson;
|
||||
use revive_solc_json_interface::SolcStandardJsonInput;
|
||||
use revive_solc_json_interface::SolcStandardJsonOutput;
|
||||
|
||||
use self::combined_json::CombinedJson;
|
||||
use self::standard_json::input::Input as StandardJsonInput;
|
||||
use self::standard_json::output::Output as StandardJsonOutput;
|
||||
use self::version::Version;
|
||||
|
||||
/// The first version of `solc` with the support of standard JSON interface.
|
||||
pub const FIRST_SUPPORTED_VERSION: semver::Version = semver::Version::new(0, 8, 0);
|
||||
|
||||
/// The last supported version of `solc`.
|
||||
pub const LAST_SUPPORTED_VERSION: semver::Version = semver::Version::new(0, 8, 29);
|
||||
pub const LAST_SUPPORTED_VERSION: semver::Version = semver::Version::new(0, 8, 28);
|
||||
|
||||
/// `--include-path` was introduced in solc `0.8.8` <https://github.com/ethereum/solidity/releases/tag/v0.8.8>
|
||||
pub const FIRST_INCLUDE_PATH_VERSION: semver::Version = semver::Version::new(0, 8, 8);
|
||||
@@ -29,11 +30,11 @@ pub trait Compiler {
|
||||
/// Compiles the Solidity `--standard-json` input into Yul IR.
|
||||
fn standard_json(
|
||||
&mut self,
|
||||
input: SolcStandardJsonInput,
|
||||
input: StandardJsonInput,
|
||||
base_path: Option<String>,
|
||||
include_paths: Vec<String>,
|
||||
allow_paths: Option<String>,
|
||||
) -> anyhow::Result<SolcStandardJsonOutput>;
|
||||
) -> anyhow::Result<StandardJsonOutput>;
|
||||
|
||||
/// The `solc --combined-json abi,hashes...` mirror.
|
||||
fn combined_json(
|
||||
|
||||
@@ -4,10 +4,9 @@ use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use revive_solc_json_interface::combined_json::CombinedJson;
|
||||
use revive_solc_json_interface::SolcStandardJsonInput;
|
||||
use revive_solc_json_interface::SolcStandardJsonOutput;
|
||||
|
||||
use crate::solc::combined_json::CombinedJson;
|
||||
use crate::solc::standard_json::input::Input as StandardJsonInput;
|
||||
use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
||||
use crate::solc::version::Version;
|
||||
|
||||
use super::Compiler;
|
||||
@@ -40,11 +39,11 @@ impl Compiler for SolcCompiler {
|
||||
/// Compiles the Solidity `--standard-json` input into Yul IR.
|
||||
fn standard_json(
|
||||
&mut self,
|
||||
mut input: SolcStandardJsonInput,
|
||||
mut input: StandardJsonInput,
|
||||
base_path: Option<String>,
|
||||
include_paths: Vec<String>,
|
||||
allow_paths: Option<String>,
|
||||
) -> anyhow::Result<SolcStandardJsonOutput> {
|
||||
) -> anyhow::Result<StandardJsonOutput> {
|
||||
let version = self.version()?.validate(&include_paths)?.default;
|
||||
|
||||
let mut command = std::process::Command::new(self.executable.as_str());
|
||||
@@ -94,7 +93,7 @@ impl Compiler for SolcCompiler {
|
||||
);
|
||||
}
|
||||
|
||||
let mut output: SolcStandardJsonOutput =
|
||||
let mut output: StandardJsonOutput =
|
||||
revive_common::deserialize_from_slice(output.stdout.as_slice()).map_err(|error| {
|
||||
anyhow::anyhow!(
|
||||
"{} subprocess output parsing error: {}\n{}",
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use revive_solc_json_interface::combined_json::CombinedJson;
|
||||
use revive_solc_json_interface::SolcStandardJsonInput;
|
||||
use revive_solc_json_interface::SolcStandardJsonOutput;
|
||||
|
||||
use crate::solc::combined_json::CombinedJson;
|
||||
use crate::solc::standard_json::input::Input as StandardJsonInput;
|
||||
use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
||||
use crate::solc::version::Version;
|
||||
use anyhow::Context;
|
||||
use std::ffi::{c_char, c_void, CStr, CString};
|
||||
@@ -25,11 +24,11 @@ impl Compiler for SoljsonCompiler {
|
||||
/// Compiles the Solidity `--standard-json` input into Yul IR.
|
||||
fn standard_json(
|
||||
&mut self,
|
||||
mut input: SolcStandardJsonInput,
|
||||
mut input: StandardJsonInput,
|
||||
base_path: Option<String>,
|
||||
include_paths: Vec<String>,
|
||||
allow_paths: Option<String>,
|
||||
) -> anyhow::Result<SolcStandardJsonOutput> {
|
||||
) -> anyhow::Result<StandardJsonOutput> {
|
||||
if !include_paths.is_empty() {
|
||||
anyhow::bail!("configuring include paths is not supported with solJson")
|
||||
}
|
||||
@@ -47,8 +46,8 @@ impl Compiler for SoljsonCompiler {
|
||||
|
||||
let input_json = serde_json::to_string(&input).expect("Always valid");
|
||||
let out = Self::compile_standard_json(input_json)?;
|
||||
let mut output: SolcStandardJsonOutput =
|
||||
revive_common::deserialize_from_slice(out.as_bytes()).map_err(|error| {
|
||||
let mut output: StandardJsonOutput = revive_common::deserialize_from_slice(out.as_bytes())
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!(
|
||||
"Soljson output parsing error: {}\n{}",
|
||||
error,
|
||||
|
||||
+5
-9
@@ -8,15 +8,14 @@ use std::collections::BTreeMap;
|
||||
use std::collections::BTreeSet;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[cfg(all(feature = "parallel", feature = "resolc"))]
|
||||
#[cfg(feature = "parallel")]
|
||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::standard_json::input::settings::metadata::Metadata as SolcStandardJsonInputSettingsMetadata;
|
||||
use crate::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
|
||||
use crate::standard_json::input::settings::selection::Selection as SolcStandardJsonInputSettingsSelection;
|
||||
#[cfg(feature = "resolc")]
|
||||
use crate::solc::standard_json::input::settings::metadata::Metadata as SolcStandardJsonInputSettingsMetadata;
|
||||
use crate::solc::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
|
||||
use crate::solc::standard_json::input::settings::selection::Selection as SolcStandardJsonInputSettingsSelection;
|
||||
use crate::warning::Warning;
|
||||
|
||||
use self::language::Language;
|
||||
@@ -34,7 +33,6 @@ pub struct Input {
|
||||
/// The compiler settings.
|
||||
pub settings: Settings,
|
||||
/// The suppressed warnings.
|
||||
#[cfg(feature = "resolc")]
|
||||
#[serde(skip_serializing)]
|
||||
pub suppressed_warnings: Option<Vec<Warning>>,
|
||||
}
|
||||
@@ -62,7 +60,7 @@ impl Input {
|
||||
output_selection: SolcStandardJsonInputSettingsSelection,
|
||||
optimizer: SolcStandardJsonInputSettingsOptimizer,
|
||||
metadata: Option<SolcStandardJsonInputSettingsMetadata>,
|
||||
#[cfg(feature = "resolc")] suppressed_warnings: Option<Vec<Warning>>,
|
||||
suppressed_warnings: Option<Vec<Warning>>,
|
||||
) -> anyhow::Result<Self> {
|
||||
let mut paths: BTreeSet<PathBuf> = paths.iter().cloned().collect();
|
||||
let libraries = Settings::parse_libraries(library_map)?;
|
||||
@@ -91,14 +89,12 @@ impl Input {
|
||||
optimizer,
|
||||
metadata,
|
||||
),
|
||||
#[cfg(feature = "resolc")]
|
||||
suppressed_warnings,
|
||||
})
|
||||
}
|
||||
|
||||
/// A shortcut constructor from source code.
|
||||
/// Only for the integration test purposes.
|
||||
#[cfg(feature = "resolc")]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn try_from_sources(
|
||||
evm_version: Option<revive_common::EVMVersion>,
|
||||
+2
-4
@@ -3,20 +3,18 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::standard_json::input::settings::metadata_hash::MetadataHash;
|
||||
|
||||
/// The `solc --standard-json` input settings metadata.
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Metadata {
|
||||
/// The bytecode hash mode.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub bytecode_hash: Option<MetadataHash>,
|
||||
pub bytecode_hash: Option<revive_llvm_context::PolkaVMMetadataHash>,
|
||||
}
|
||||
|
||||
impl Metadata {
|
||||
/// A shortcut constructor.
|
||||
pub fn new(bytecode_hash: MetadataHash) -> Self {
|
||||
pub fn new(bytecode_hash: revive_llvm_context::PolkaVMMetadataHash) -> Self {
|
||||
Self {
|
||||
bytecode_hash: Some(bytecode_hash),
|
||||
}
|
||||
-1
@@ -1,7 +1,6 @@
|
||||
//! The `solc --standard-json` input settings.
|
||||
|
||||
pub mod metadata;
|
||||
pub mod metadata_hash;
|
||||
pub mod optimizer;
|
||||
pub mod selection;
|
||||
|
||||
+15
@@ -49,3 +49,18 @@ impl Optimizer {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&Optimizer> for revive_llvm_context::OptimizerSettings {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: &Optimizer) -> Result<Self, Self::Error> {
|
||||
let mut result = match value.mode {
|
||||
Some(mode) => Self::try_from_cli(mode)?,
|
||||
None => Self::cycles(),
|
||||
};
|
||||
if value.fallback_to_optimizing_for_size.unwrap_or_default() {
|
||||
result.enable_fallback_to_size();
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
//! The `solc <input>.sol --standard-json`.
|
||||
|
||||
pub mod input;
|
||||
pub mod output;
|
||||
@@ -0,0 +1,138 @@
|
||||
//! The `solc --standard-json` output.
|
||||
|
||||
pub mod contract;
|
||||
pub mod error;
|
||||
pub mod source;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use sha3::Digest;
|
||||
|
||||
use crate::project::contract::ir::IR as ProjectContractIR;
|
||||
use crate::project::contract::Contract as ProjectContract;
|
||||
use crate::project::Project;
|
||||
use crate::solc::version::Version as SolcVersion;
|
||||
use crate::warning::Warning;
|
||||
use crate::yul::lexer::Lexer;
|
||||
use crate::yul::parser::statement::object::Object;
|
||||
|
||||
use self::contract::Contract;
|
||||
use self::error::Error as SolcStandardJsonOutputError;
|
||||
use self::source::Source;
|
||||
/// The `solc --standard-json` output.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct Output {
|
||||
/// The file-contract hashmap.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub contracts: Option<BTreeMap<String, BTreeMap<String, Contract>>>,
|
||||
/// The source code mapping data.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub sources: Option<BTreeMap<String, Source>>,
|
||||
/// The compilation errors and warnings.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub errors: Option<Vec<SolcStandardJsonOutputError>>,
|
||||
/// The `solc` compiler version.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub version: Option<String>,
|
||||
/// The `solc` compiler long version.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub long_version: Option<String>,
|
||||
/// The `resolc` compiler version.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub revive_version: Option<String>,
|
||||
}
|
||||
|
||||
impl Output {
|
||||
/// Converts the `solc` JSON output into a convenient project.
|
||||
pub fn try_to_project(
|
||||
&mut self,
|
||||
source_code_files: BTreeMap<String, String>,
|
||||
libraries: BTreeMap<String, BTreeMap<String, String>>,
|
||||
solc_version: &SolcVersion,
|
||||
debug_config: &revive_llvm_context::DebugConfig,
|
||||
) -> anyhow::Result<Project> {
|
||||
let files = match self.contracts.as_ref() {
|
||||
Some(files) => files,
|
||||
None => match &self.errors {
|
||||
Some(errors) if errors.iter().any(|e| e.severity == "error") => {
|
||||
anyhow::bail!(serde_json::to_string_pretty(errors).expect("Always valid"));
|
||||
}
|
||||
_ => &BTreeMap::new(),
|
||||
},
|
||||
};
|
||||
let mut project_contracts = BTreeMap::new();
|
||||
|
||||
for (path, contracts) in files.iter() {
|
||||
for (name, contract) in contracts.iter() {
|
||||
let full_path = format!("{path}:{name}");
|
||||
|
||||
let ir_optimized = match contract.ir_optimized.to_owned() {
|
||||
Some(ir_optimized) => ir_optimized,
|
||||
None => continue,
|
||||
};
|
||||
if ir_optimized.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
debug_config.dump_yul(full_path.as_str(), ir_optimized.as_str())?;
|
||||
|
||||
let mut lexer = Lexer::new(ir_optimized.to_owned());
|
||||
let object = Object::parse(&mut lexer, None).map_err(|error| {
|
||||
anyhow::anyhow!("Contract `{}` parsing error: {:?}", full_path, error)
|
||||
})?;
|
||||
|
||||
let source = ProjectContractIR::new_yul(ir_optimized.to_owned(), object);
|
||||
|
||||
let source_code = source_code_files
|
||||
.get(path.as_str())
|
||||
.ok_or_else(|| anyhow::anyhow!("Source code for path `{}` not found", path))?;
|
||||
let source_hash = sha3::Keccak256::digest(source_code.as_bytes()).into();
|
||||
|
||||
let project_contract = ProjectContract::new(
|
||||
full_path.clone(),
|
||||
source_hash,
|
||||
solc_version.to_owned(),
|
||||
source,
|
||||
contract.metadata.to_owned(),
|
||||
);
|
||||
project_contracts.insert(full_path, project_contract);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Project::new(
|
||||
solc_version.to_owned(),
|
||||
project_contracts,
|
||||
libraries,
|
||||
))
|
||||
}
|
||||
|
||||
/// Traverses the AST and returns the list of additional errors and warnings.
|
||||
pub fn preprocess_ast(&mut self, suppressed_warnings: &[Warning]) -> anyhow::Result<()> {
|
||||
let sources = match self.sources.as_ref() {
|
||||
Some(sources) => sources,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
let mut messages = Vec::new();
|
||||
for (path, source) in sources.iter() {
|
||||
if let Some(ast) = source.ast.as_ref() {
|
||||
let mut polkavm_messages = Source::get_messages(ast, suppressed_warnings);
|
||||
for message in polkavm_messages.iter_mut() {
|
||||
message.push_contract_path(path.as_str());
|
||||
}
|
||||
messages.extend(polkavm_messages);
|
||||
}
|
||||
}
|
||||
self.errors = match self.errors.take() {
|
||||
Some(mut errors) => {
|
||||
errors.extend(messages);
|
||||
Some(errors)
|
||||
}
|
||||
None => Some(messages),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -3,8 +3,7 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::standard_json::output::error::Error as SolcStandardJsonOutputError;
|
||||
#[cfg(feature = "resolc")]
|
||||
use crate::solc::standard_json::output::error::Error as SolcStandardJsonOutputError;
|
||||
use crate::warning::Warning;
|
||||
|
||||
/// The `solc --standard-json` output source.
|
||||
@@ -132,7 +131,6 @@ impl Source {
|
||||
}
|
||||
|
||||
/// Returns the list of messages for some specific parts of the AST.
|
||||
#[cfg(feature = "resolc")]
|
||||
pub fn get_messages(
|
||||
ast: &serde_json::Value,
|
||||
suppressed_warnings: &[Warning],
|
||||
@@ -196,7 +194,7 @@ impl Source {
|
||||
_ => None,
|
||||
},
|
||||
)
|
||||
.next_back()
|
||||
.last()
|
||||
.ok_or_else(|| anyhow::anyhow!("The last contract not found in the AST"))
|
||||
}
|
||||
}
|
||||
@@ -7,17 +7,17 @@ use std::sync::Mutex;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use revive_llvm_context::OptimizerSettings;
|
||||
use revive_solc_json_interface::standard_json::output::contract::evm::bytecode::Bytecode;
|
||||
use revive_solc_json_interface::standard_json::output::contract::evm::bytecode::DeployedBytecode;
|
||||
use revive_solc_json_interface::warning::Warning;
|
||||
use revive_solc_json_interface::SolcStandardJsonInput;
|
||||
use revive_solc_json_interface::SolcStandardJsonInputSettingsOptimizer;
|
||||
use revive_solc_json_interface::SolcStandardJsonInputSettingsSelection;
|
||||
use revive_solc_json_interface::SolcStandardJsonOutput;
|
||||
|
||||
use crate::project::Project;
|
||||
use crate::solc::solc_compiler::SolcCompiler;
|
||||
use crate::solc::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
|
||||
use crate::solc::standard_json::input::settings::selection::Selection as SolcStandardJsonInputSettingsSelection;
|
||||
use crate::solc::standard_json::input::Input as SolcStandardJsonInput;
|
||||
use crate::solc::standard_json::output::contract::evm::bytecode::Bytecode;
|
||||
use crate::solc::standard_json::output::contract::evm::bytecode::DeployedBytecode;
|
||||
use crate::solc::standard_json::output::Output as SolcStandardJsonOutput;
|
||||
use crate::solc::Compiler;
|
||||
use crate::warning::Warning;
|
||||
|
||||
static PVM_BLOB_CACHE: Lazy<Mutex<HashMap<CachedBlob, Vec<u8>>>> = Lazy::new(Default::default);
|
||||
static EVM_BLOB_CACHE: Lazy<Mutex<HashMap<CachedBlob, Vec<u8>>>> = Lazy::new(Default::default);
|
||||
@@ -73,11 +73,7 @@ pub fn build_solidity_with_options(
|
||||
check_dependencies();
|
||||
|
||||
inkwell::support::enable_llvm_pretty_stack_trace();
|
||||
revive_llvm_context::initialize_llvm(
|
||||
revive_llvm_context::Target::PVM,
|
||||
crate::DEFAULT_EXECUTABLE_NAME,
|
||||
&[],
|
||||
);
|
||||
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
||||
let _ = crate::process::native_process::EXECUTABLE
|
||||
.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
|
||||
|
||||
@@ -92,7 +88,7 @@ pub fn build_solidity_with_options(
|
||||
SolcStandardJsonInputSettingsSelection::new_required(),
|
||||
SolcStandardJsonInputSettingsOptimizer::new(
|
||||
solc_optimizer_enabled,
|
||||
optimizer_settings.middle_end_as_string().chars().last(),
|
||||
None,
|
||||
&solc_version.default,
|
||||
false,
|
||||
),
|
||||
@@ -102,21 +98,9 @@ pub fn build_solidity_with_options(
|
||||
|
||||
let mut output = solc.standard_json(input, None, vec![], None)?;
|
||||
|
||||
let debug_config = revive_llvm_context::DebugConfig::new(
|
||||
None,
|
||||
optimizer_settings.middle_end_as_string() != "z",
|
||||
);
|
||||
let project = output.try_to_project(sources, libraries, &solc_version, &DEBUG_CONFIG)?;
|
||||
|
||||
let project = Project::try_from_standard_json_output(
|
||||
&output,
|
||||
sources,
|
||||
libraries,
|
||||
&solc_version,
|
||||
&debug_config,
|
||||
)?;
|
||||
|
||||
let build: crate::Build =
|
||||
project.compile(optimizer_settings, false, debug_config, Default::default())?;
|
||||
let build: crate::Build = project.compile(optimizer_settings, false, DEBUG_CONFIG)?;
|
||||
build.write_to_standard_json(&mut output, &solc_version)?;
|
||||
|
||||
Ok(output)
|
||||
@@ -132,11 +116,7 @@ pub fn build_solidity_with_options_evm(
|
||||
check_dependencies();
|
||||
|
||||
inkwell::support::enable_llvm_pretty_stack_trace();
|
||||
revive_llvm_context::initialize_llvm(
|
||||
revive_llvm_context::Target::PVM,
|
||||
crate::DEFAULT_EXECUTABLE_NAME,
|
||||
&[],
|
||||
);
|
||||
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
||||
let _ = crate::process::native_process::EXECUTABLE
|
||||
.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
|
||||
|
||||
@@ -188,11 +168,7 @@ pub fn build_solidity_and_detect_missing_libraries(
|
||||
check_dependencies();
|
||||
|
||||
inkwell::support::enable_llvm_pretty_stack_trace();
|
||||
revive_llvm_context::initialize_llvm(
|
||||
revive_llvm_context::Target::PVM,
|
||||
crate::DEFAULT_EXECUTABLE_NAME,
|
||||
&[],
|
||||
);
|
||||
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
||||
let _ = crate::process::native_process::EXECUTABLE
|
||||
.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
|
||||
|
||||
@@ -212,13 +188,7 @@ pub fn build_solidity_and_detect_missing_libraries(
|
||||
|
||||
let mut output = solc.standard_json(input, None, vec![], None)?;
|
||||
|
||||
let project = Project::try_from_standard_json_output(
|
||||
&output,
|
||||
sources,
|
||||
libraries,
|
||||
&solc_version,
|
||||
&DEBUG_CONFIG,
|
||||
)?;
|
||||
let project = output.try_to_project(sources, libraries, &solc_version, &DEBUG_CONFIG)?;
|
||||
|
||||
let missing_libraries = project.get_missing_libraries();
|
||||
missing_libraries.write_to_standard_json(&mut output, &solc.version()?)?;
|
||||
@@ -231,11 +201,7 @@ pub fn build_yul(source_code: &str) -> anyhow::Result<()> {
|
||||
check_dependencies();
|
||||
|
||||
inkwell::support::enable_llvm_pretty_stack_trace();
|
||||
revive_llvm_context::initialize_llvm(
|
||||
revive_llvm_context::Target::PVM,
|
||||
crate::DEFAULT_EXECUTABLE_NAME,
|
||||
&[],
|
||||
);
|
||||
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
||||
let optimizer_settings = revive_llvm_context::OptimizerSettings::none();
|
||||
|
||||
let project = Project::try_from_yul_string::<SolcCompiler>(
|
||||
@@ -243,7 +209,7 @@ pub fn build_yul(source_code: &str) -> anyhow::Result<()> {
|
||||
source_code,
|
||||
None,
|
||||
)?;
|
||||
let _build = project.compile(optimizer_settings, false, DEBUG_CONFIG, Default::default())?;
|
||||
let _build = project.compile(optimizer_settings, false, DEBUG_CONFIG)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use revive_solc_json_interface::warning::Warning;
|
||||
use crate::warning::Warning;
|
||||
|
||||
pub const ECRECOVER_TEST_SOURCE: &str = r#"
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
//! `resolc` custom compiler warnings.
|
||||
//!
|
||||
//! The revive compiler adds warnings only applicable when compilng
|
||||
//! to the revive stack on Polkadot to the output.
|
||||
//! The compiler warning.
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
// The `resolc` custom compiler warning.
|
||||
/// The compiler warning.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum Warning {
|
||||
/// The warning for eponymous feature.
|
||||
EcRecover,
|
||||
/// The warning for eponymous feature.
|
||||
SendTransfer,
|
||||
/// The warning for eponymous feature.
|
||||
ExtCodeSize,
|
||||
/// The warning for eponymous feature.
|
||||
TxOrigin,
|
||||
/// The warning for eponymous feature.
|
||||
BlockTimestamp,
|
||||
/// The warning for eponymous feature.
|
||||
BlockNumber,
|
||||
/// The warning for eponymous feature.
|
||||
BlockHash,
|
||||
}
|
||||
|
||||
@@ -139,14 +139,13 @@ where
|
||||
identifier.inner,
|
||||
)
|
||||
})?;
|
||||
context.build_store(pointer, value.to_value(context)?)?;
|
||||
context.build_store(pointer, value.to_llvm())?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let value = value.to_value(context)?;
|
||||
let llvm_type = value.into_struct_value().get_type();
|
||||
let llvm_type = value.to_llvm().into_struct_value().get_type();
|
||||
let tuple_pointer = context.build_alloca(llvm_type, "assignment_pointer");
|
||||
context.build_store(tuple_pointer, value)?;
|
||||
context.build_store(tuple_pointer, value.to_llvm())?;
|
||||
|
||||
for (index, binding) in self.bindings.into_iter().enumerate() {
|
||||
context.set_debug_location(self.location.line, 0, None)?;
|
||||
|
||||
@@ -128,10 +128,7 @@ impl FunctionCall {
|
||||
Name::UserDefined(name) => {
|
||||
let mut values = Vec::with_capacity(self.arguments.len());
|
||||
for argument in self.arguments.into_iter().rev() {
|
||||
let value = argument
|
||||
.into_llvm(context)?
|
||||
.expect("Always exists")
|
||||
.to_value(context)?;
|
||||
let value = argument.into_llvm(context)?.expect("Always exists").value;
|
||||
values.push(value);
|
||||
}
|
||||
values.reverse();
|
||||
@@ -464,29 +461,36 @@ impl FunctionCall {
|
||||
}
|
||||
|
||||
Name::SLoad => {
|
||||
let arguments = self.pop_arguments::<D, 1>(context)?;
|
||||
revive_llvm_context::polkavm_evm_storage::load(context, &arguments[0]).map(Some)
|
||||
let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
|
||||
revive_llvm_context::polkavm_evm_storage::load(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::SStore => {
|
||||
let arguments = self.pop_arguments::<D, 2>(context)?;
|
||||
let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
|
||||
revive_llvm_context::polkavm_evm_storage::store(
|
||||
context,
|
||||
&arguments[0],
|
||||
&arguments[1],
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
)
|
||||
.map(|_| None)
|
||||
}
|
||||
Name::TLoad => {
|
||||
let arguments = self.pop_arguments::<D, 1>(context)?;
|
||||
revive_llvm_context::polkavm_evm_storage::transient_load(context, &arguments[0])
|
||||
.map(Some)
|
||||
let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
|
||||
revive_llvm_context::polkavm_evm_storage::transient_load(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::TStore => {
|
||||
let arguments = self.pop_arguments::<D, 2>(context)?;
|
||||
let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
|
||||
revive_llvm_context::polkavm_evm_storage::transient_store(
|
||||
context,
|
||||
&arguments[0],
|
||||
&arguments[1],
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
)
|
||||
.map(|_| None)
|
||||
}
|
||||
@@ -510,7 +514,7 @@ impl FunctionCall {
|
||||
let offset = context.solidity_mut().allocate_immutable(key.as_str())
|
||||
/ revive_common::BYTE_LENGTH_WORD;
|
||||
let index = context.xlen_type().const_int(offset as u64, false);
|
||||
let value = arguments[2].to_value(context)?.into_int_value();
|
||||
let value = arguments[2].value.into_int_value();
|
||||
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
|
||||
.map(|_| None)
|
||||
}
|
||||
@@ -716,16 +720,15 @@ impl FunctionCall {
|
||||
Name::Call => {
|
||||
let arguments = self.pop_arguments::<D, 7>(context)?;
|
||||
|
||||
let gas = &arguments[0];
|
||||
let address = &arguments[1];
|
||||
let value = &arguments[2];
|
||||
let input_offset = &arguments[3];
|
||||
let input_size = &arguments[4];
|
||||
let output_offset = &arguments[5];
|
||||
let output_size = &arguments[6];
|
||||
let gas = arguments[0].value.into_int_value();
|
||||
let address = arguments[1].value.into_int_value();
|
||||
let value = arguments[2].value.into_int_value();
|
||||
let input_offset = arguments[3].value.into_int_value();
|
||||
let input_size = arguments[4].value.into_int_value();
|
||||
let output_offset = arguments[5].value.into_int_value();
|
||||
let output_size = arguments[6].value.into_int_value();
|
||||
|
||||
let simulation_address: Vec<Option<num::BigUint>> = arguments
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|mut argument| argument.constant.take())
|
||||
.collect();
|
||||
@@ -747,15 +750,14 @@ impl FunctionCall {
|
||||
Name::StaticCall => {
|
||||
let arguments = self.pop_arguments::<D, 6>(context)?;
|
||||
|
||||
let gas = &arguments[0];
|
||||
let address = &arguments[1];
|
||||
let input_offset = &arguments[2];
|
||||
let input_size = &arguments[3];
|
||||
let output_offset = &arguments[4];
|
||||
let output_size = &arguments[5];
|
||||
let gas = arguments[0].value.into_int_value();
|
||||
let address = arguments[1].value.into_int_value();
|
||||
let input_offset = arguments[2].value.into_int_value();
|
||||
let input_size = arguments[3].value.into_int_value();
|
||||
let output_offset = arguments[4].value.into_int_value();
|
||||
let output_size = arguments[5].value.into_int_value();
|
||||
|
||||
let simulation_address: Vec<Option<num::BigUint>> = arguments
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|mut argument| argument.constant.take())
|
||||
.collect();
|
||||
@@ -777,12 +779,12 @@ impl FunctionCall {
|
||||
Name::DelegateCall => {
|
||||
let arguments = self.pop_arguments::<D, 6>(context)?;
|
||||
|
||||
let gas = arguments[0].to_value(context)?.into_int_value();
|
||||
let address = arguments[1].to_value(context)?.into_int_value();
|
||||
let input_offset = arguments[2].to_value(context)?.into_int_value();
|
||||
let input_size = arguments[3].to_value(context)?.into_int_value();
|
||||
let output_offset = arguments[4].to_value(context)?.into_int_value();
|
||||
let output_size = arguments[5].to_value(context)?.into_int_value();
|
||||
let gas = arguments[0].value.into_int_value();
|
||||
let address = arguments[1].value.into_int_value();
|
||||
let input_offset = arguments[2].value.into_int_value();
|
||||
let input_size = arguments[3].value.into_int_value();
|
||||
let output_offset = arguments[4].value.into_int_value();
|
||||
let output_size = arguments[5].value.into_int_value();
|
||||
|
||||
let simulation_address: Vec<Option<num::BigUint>> = arguments
|
||||
.into_iter()
|
||||
@@ -843,8 +845,7 @@ impl FunctionCall {
|
||||
})?;
|
||||
|
||||
revive_llvm_context::polkavm_evm_create::contract_hash(context, identifier)
|
||||
.and_then(|argument| argument.to_value(context))
|
||||
.map(Some)
|
||||
.map(|argument| Some(argument.value))
|
||||
}
|
||||
Name::DataSize => {
|
||||
let mut arguments = self.pop_arguments::<D, 1>(context)?;
|
||||
@@ -854,8 +855,7 @@ impl FunctionCall {
|
||||
})?;
|
||||
|
||||
revive_llvm_context::polkavm_evm_create::header_size(context, identifier)
|
||||
.and_then(|argument| argument.to_value(context))
|
||||
.map(Some)
|
||||
.map(|argument| Some(argument.value))
|
||||
}
|
||||
Name::DataCopy => {
|
||||
let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
|
||||
@@ -989,12 +989,7 @@ impl FunctionCall {
|
||||
{
|
||||
let mut arguments = Vec::with_capacity(N);
|
||||
for expression in self.arguments.drain(0..N).rev() {
|
||||
arguments.push(
|
||||
expression
|
||||
.into_llvm(context)?
|
||||
.expect("Always exists")
|
||||
.to_value(context)?,
|
||||
);
|
||||
arguments.push(expression.into_llvm(context)?.expect("Always exists").value);
|
||||
}
|
||||
arguments.reverse();
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user