mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 15:41:04 +00:00
Compare commits
132 Commits
calls
...
v0.1.0-dev.6
| Author | SHA1 | Date | |
|---|---|---|---|
| 0110258d81 | |||
| f0d9d44dce | |||
| 3f6cd115ee | |||
| 7c00bbb0fc | |||
| 423a494621 | |||
| 08112e3449 | |||
| db6ca1fcfa | |||
| 54d154a73c | |||
| 93f1deb6a5 | |||
| 9a150b13f3 | |||
| 677cef9c0f | |||
| d25be523c1 | |||
| 6a4fd1e991 | |||
| 81915ddbcb | |||
| 0f25bac4bd | |||
| 7d41495587 | |||
| d6d5acfcce | |||
| 130ac48bf0 | |||
| b65fa2e42c | |||
| 1eb1083d40 | |||
| 4c0c74f7f4 | |||
| 229c0d452d | |||
| 4e024655a1 | |||
| 01b5ed5ba3 | |||
| 892c9b5fbe | |||
| 84d47fa738 | |||
| dbb47fd13e | |||
| 87f2bcefb3 | |||
| 05925f25f1 | |||
| 8990b2a486 | |||
| 89ddfb28c8 | |||
| 32d4b2309c | |||
| a772ff1354 | |||
| 0a82addf02 | |||
| 491850760f | |||
| fcbe00f4a9 | |||
| 77406264ea | |||
| cdebf69fc0 | |||
| f36d62ca73 | |||
| 39e504703e | |||
| 63da7212a1 | |||
| 3072c03600 | |||
| d88ddb25bd | |||
| 87dd77b784 | |||
| cece20deb1 | |||
| f57ab96eed | |||
| 3232382d96 | |||
| 6a120463c2 | |||
| 881b88354c | |||
| c9dd347755 | |||
| 140545ea15 | |||
| 010a2ed223 | |||
| 563864dd25 | |||
| ce8bf3d9ef | |||
| f947984671 | |||
| 14991f40ac | |||
| 6d16790f83 | |||
| 64fefe76b5 | |||
| f59b47df7b | |||
| 6e6fe20c71 | |||
| 93d2f3b9d9 | |||
| 8a225871ee | |||
| 677aedc6f3 | |||
| 90423ffb6b | |||
| 255176978a | |||
| 9a8003afbf | |||
| 7f3d0cecb2 | |||
| 18376432f1 | |||
| 007b79ee62 | |||
| 8c7d18aec7 | |||
| c0a82ce6d2 | |||
| c51d50bc88 | |||
| 94445bab93 | |||
| a934ec204e | |||
| b6baf6cfd9 | |||
| b7b28efded | |||
| d260472330 | |||
| 4f6debcbe3 | |||
| 9b23e19479 | |||
| 88a888d138 | |||
| 4cce4a729e | |||
| 9267a2af02 | |||
| 173ace72cb | |||
| 37ab2b6782 | |||
| 43d2ef3ce9 | |||
| 68564f9866 | |||
| 36d9317831 | |||
| 5b3b90db83 | |||
| a4043ecde7 | |||
| f985f42370 | |||
| aae25107a2 | |||
| cc38c37481 | |||
| e56feb95be | |||
| 995b115c5f | |||
| ee83d28a51 | |||
| 82ae22c163 | |||
| 20e3560398 | |||
| 5bf31db660 | |||
| f0f344a139 | |||
| 92a18460e4 | |||
| e5233fc46e | |||
| adda5a0f12 | |||
| d9842b5427 | |||
| 6335c34a2b | |||
| 49d2157a84 | |||
| e131eebf50 | |||
| 705d1d7866 | |||
| d5d419cefc | |||
| 8b7fe8e3d7 | |||
| b344e0cff5 | |||
| 0e6a6d12c3 | |||
| 77fe683f18 | |||
| e8fcd6118e | |||
| ad46e94ebd | |||
| 6585973e99 | |||
| 066acc4663 | |||
| 287272b789 | |||
| f621971a13 | |||
| b8bd44b62a | |||
| d8c708eba5 | |||
| 72d958392b | |||
| 616f044633 | |||
| 7dc8e6051e | |||
| 783fa640e4 | |||
| f086c57442 | |||
| 0f2b55f6ff | |||
| ac9215329c | |||
| 6635a0b337 | |||
| 77df88b3cb | |||
| 2955f77772 | |||
| d77ee1e0d4 | |||
| 5ac67bdc0d |
@@ -0,0 +1,38 @@
|
|||||||
|
name: Build revive-debian
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
REVIVE_DEBIAN_PACKAGE: revive-debian-x86
|
||||||
|
DEBIAN_CONTAINER: revive-builder-debian-x86
|
||||||
|
DEBIAN_CONTAINER_BUILDER: build-debian-builder.sh
|
||||||
|
DEBIAN_CONTAINER_RUNNER: run-debian-builder.sh
|
||||||
|
REVIVE_DEBIAN_INSTALL: ${{ github.workspace }}/target/release
|
||||||
|
REVIVE_DEBIAN_BINARY: resolc
|
||||||
|
RUST_VERSION: "1.80"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-revive-debian-x86:
|
||||||
|
name: debian-container-x86
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: build-container
|
||||||
|
run: |
|
||||||
|
(cd utils && ./${{ env.DEBIAN_CONTAINER_BUILDER}} --build-arg RUST_VERSION=${{ env.RUST_VERSION}} . )
|
||||||
|
|
||||||
|
- name: build-revive-debian
|
||||||
|
run: |
|
||||||
|
rustup show
|
||||||
|
cargo --version
|
||||||
|
rustup +nightly show
|
||||||
|
cargo +nightly --version
|
||||||
|
bash --version
|
||||||
|
utils/${{ env.DEBIAN_CONTAINER_RUNNER }} utils/build-revive.sh -o ${{ env.REVIVE_DEBIAN_INSTALL}}
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ env.REVIVE_DEBIAN_PACKAGE }}
|
||||||
|
path: ${{ env.REVIVE_DEBIAN_INSTALL }}/${{ env.REVIVE_DEBIAN_BINARY }}
|
||||||
|
retention-days: 1
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
name: Build revive-wasm
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["main"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["main"]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
REVIVE_WASM_INSTALL_DIR: ${{ github.workspace }}/target/wasm32-unknown-emscripten/release
|
||||||
|
EMSCRIPTEN_VERSION: 3.1.64
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-revive-wasm:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Cache LLVM build
|
||||||
|
id: cache-llvm
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
llvm18.0-emscripten
|
||||||
|
# Use a unique key based on LLVM version or configuration files to avoid cache invalidation
|
||||||
|
key: llvm-build-${{ runner.os }}-${{ hashFiles('clone-llvm.sh', 'emscripten-build-llvm.sh') }}
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update && sudo apt-get install -y cmake ninja-build libncurses5
|
||||||
|
rustup target add wasm32-unknown-emscripten
|
||||||
|
# Install LLVM required for the compiler runtime, runtime-api and stdlib
|
||||||
|
curl -sSL --output llvm.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.4/clang+llvm-18.1.4-x86_64-linux-gnu-ubuntu-18.04.tar.xz
|
||||||
|
tar Jxf llvm.tar.xz
|
||||||
|
mv clang+llvm-18.1.4-x86_64-linux-gnu-ubuntu-18.04 llvm18/
|
||||||
|
echo "$(pwd)/llvm18/bin" >> $GITHUB_PATH
|
||||||
|
# Install Emscripten
|
||||||
|
git clone https://github.com/emscripten-core/emsdk.git
|
||||||
|
cd emsdk
|
||||||
|
./emsdk install ${{ env.EMSCRIPTEN_VERSION }}
|
||||||
|
./emsdk activate ${{ env.EMSCRIPTEN_VERSION }}
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
rustup show
|
||||||
|
cargo --version
|
||||||
|
rustup +nightly show
|
||||||
|
cargo +nightly --version
|
||||||
|
cmake --version
|
||||||
|
bash --version
|
||||||
|
llvm-config --version
|
||||||
|
|
||||||
|
- name: Build LLVM
|
||||||
|
if: steps.cache-llvm.outputs.cache-hit != 'true'
|
||||||
|
run: |
|
||||||
|
export EMSDK_ROOT=${PWD}/emsdk
|
||||||
|
./emscripten-build-llvm.sh
|
||||||
|
|
||||||
|
- name: Use Cached LLVM
|
||||||
|
if: steps.cache-llvm.outputs.cache-hit == 'true'
|
||||||
|
run: |
|
||||||
|
echo "Using cached LLVM"
|
||||||
|
|
||||||
|
- name: Build revive
|
||||||
|
run: |
|
||||||
|
export LLVM_LINK_PREFIX=${PWD}/llvm18.0-emscripten
|
||||||
|
source ./emsdk/emsdk_env.sh
|
||||||
|
make install-wasm
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: revive-wasm
|
||||||
|
path: |
|
||||||
|
${{ env.REVIVE_WASM_INSTALL_DIR }}/resolc.js
|
||||||
|
${{ env.REVIVE_WASM_INSTALL_DIR }}/resolc.wasm
|
||||||
|
retention-days: 1
|
||||||
@@ -19,7 +19,7 @@ jobs:
|
|||||||
- name: Install solc
|
- name: Install solc
|
||||||
run: |
|
run: |
|
||||||
mkdir -p solc
|
mkdir -p solc
|
||||||
curl -sSL --output solc/solc https://github.com/ethereum/solidity/releases/download/v0.8.26/solc-static-linux
|
curl -sSL --output solc/solc https://github.com/ethereum/solidity/releases/download/v0.8.28/solc-static-linux
|
||||||
chmod +x solc/solc
|
chmod +x solc/solc
|
||||||
echo "$(pwd)/solc/" >> $GITHUB_PATH
|
echo "$(pwd)/solc/" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
/*.s
|
/*.s
|
||||||
/llvm-project
|
/llvm-project
|
||||||
/llvm18.0
|
/llvm18.0
|
||||||
|
/llvm18.0-emscripten
|
||||||
node_modules
|
node_modules
|
||||||
artifacts
|
artifacts
|
||||||
tmp
|
tmp
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
## v0.1.0-dev.6
|
||||||
|
|
||||||
|
This is a development pre-release.
|
||||||
|
|
||||||
|
# Added
|
||||||
|
- Implement the `BLOCKHASH` opcode.
|
||||||
|
- Implement delegate calls.
|
||||||
|
- Implement the `GASPRICE` opcode. Currently hard-coded to return `1`.
|
||||||
|
- The ELF shared object contract artifact is dumped into the debug output directory.
|
||||||
|
- Initial support for emitting debug info (opt in via the `-g` flag)
|
||||||
|
|
||||||
|
# Changed
|
||||||
|
- resolc now emits 64bit PolkaVM blobs, reducing contract code size and execution time.
|
||||||
|
- The RISC-V bit-manipulation target feature (`zbb`) is enabled.
|
||||||
|
|
||||||
|
# Fixed
|
||||||
|
- Compilation to Wasm (for usage in node and web browsers)
|
||||||
|
|
||||||
|
|
||||||
|
## v0.1.0-dev.5
|
||||||
|
|
||||||
|
This is development pre-release.
|
||||||
|
|
||||||
|
# Added
|
||||||
|
- Implement the `CODESIZE` and `EXTCODESIZE` opcodes.
|
||||||
|
|
||||||
|
# Changed
|
||||||
|
- Include the full revive version in the contract metadata.
|
||||||
|
|
||||||
|
# Fixed
|
||||||
|
|
||||||
|
## v0.1.0-dev-4
|
||||||
|
|
||||||
|
This is development pre-release.
|
||||||
|
|
||||||
|
# Added
|
||||||
|
- Support the `ORIGIN` opcode.
|
||||||
|
|
||||||
|
# Changed
|
||||||
|
- Update polkavm to `v0.14.0`.
|
||||||
|
- Enable the `a`, `fast-unaligned-access` and `xtheadcondmov` LLVM target features, decreasing the code size for some contracts.
|
||||||
|
|
||||||
|
# Fixed
|
||||||
Generated
+2459
-979
File diff suppressed because it is too large
Load Diff
+22
-20
@@ -3,28 +3,29 @@ resolver = "2"
|
|||||||
members = ["crates/*"]
|
members = ["crates/*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.1.0"
|
version = "0.1.0-dev.6"
|
||||||
authors = [
|
authors = [
|
||||||
"Cyrill Leutwiler <cyrill@parity.io>",
|
"Cyrill Leutwiler <cyrill@parity.io>",
|
||||||
"Parity Technologies <admin@parity.io>",
|
"Parity Technologies <admin@parity.io>",
|
||||||
]
|
]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
repository = "https://github.com/xermicus/revive"
|
repository = "https://github.com/paritytech/revive"
|
||||||
|
rust-version = "1.80.0"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
revive-benchmarks = { version = "0.1.0", path = "crates/benchmarks" }
|
revive-benchmarks = { version = "0.1.0-dev.6", path = "crates/benchmarks" }
|
||||||
revive-builtins = { version = "0.1.0", path = "crates/builtins" }
|
revive-builtins = { version = "0.1.0-dev.6", path = "crates/builtins" }
|
||||||
revive-common = { version = "0.1.0", path = "crates/common" }
|
revive-common = { version = "0.1.0-dev.6", path = "crates/common" }
|
||||||
revive-differential = { version = "0.1.0", path = "crates/differential" }
|
revive-differential = { version = "0.1.0-dev.6", path = "crates/differential" }
|
||||||
revive-integration = { version = "0.1.0", path = "crates/integration" }
|
revive-integration = { version = "0.1.0-dev.6", path = "crates/integration" }
|
||||||
revive-linker = { version = "0.1.0", path = "crates/linker" }
|
revive-linker = { version = "0.1.0-dev.6", path = "crates/linker" }
|
||||||
lld-sys = { version = "0.1.0", path = "crates/lld-sys" }
|
lld-sys = { version = "0.1.0-dev.6", path = "crates/lld-sys" }
|
||||||
revive-llvm-context = { version = "0.1.0", path = "crates/llvm-context" }
|
revive-llvm-context = { version = "0.1.0-dev.6", path = "crates/llvm-context" }
|
||||||
revive-runtime-api = { version = "0.1.0", path = "crates/runtime-api" }
|
revive-runtime-api = { version = "0.1.0-dev.6", path = "crates/runtime-api" }
|
||||||
revive-runner = { version = "0.1.0", path = "crates/runner" }
|
revive-runner = { version = "0.1.0-dev.6", path = "crates/runner" }
|
||||||
revive-solidity = { version = "0.1.0", path = "crates/solidity" }
|
revive-solidity = { version = "0.1.0-dev.6", path = "crates/solidity" }
|
||||||
revive-stdlib = { version = "0.1.0", path = "crates/stdlib" }
|
revive-stdlib = { version = "0.1.0-dev.6", path = "crates/stdlib" }
|
||||||
|
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
petgraph = "0.6"
|
petgraph = "0.6"
|
||||||
@@ -50,10 +51,10 @@ path-slash = "0.2"
|
|||||||
rayon = "1.8"
|
rayon = "1.8"
|
||||||
clap = { version = "4", default-features = false, features = ["derive"] }
|
clap = { version = "4", default-features = false, features = ["derive"] }
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
polkavm-common = "0.10"
|
polkavm-common = "0.17"
|
||||||
polkavm-linker = "0.10"
|
polkavm-linker = "0.17"
|
||||||
polkavm-disassembler = "0.10"
|
polkavm-disassembler = "0.17"
|
||||||
polkavm = "0.10"
|
polkavm = "0.17"
|
||||||
alloy-primitives = { version = "0.8", features = ["serde"] }
|
alloy-primitives = { version = "0.8", features = ["serde"] }
|
||||||
alloy-sol-types = "0.8"
|
alloy-sol-types = "0.8"
|
||||||
alloy-genesis = "0.3"
|
alloy-genesis = "0.3"
|
||||||
@@ -66,11 +67,12 @@ log = { version = "0.4" }
|
|||||||
# polkadot-sdk and friends
|
# polkadot-sdk and friends
|
||||||
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
|
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
|
||||||
scale-info = { version = "2.11.1", default-features = false }
|
scale-info = { version = "2.11.1", default-features = false }
|
||||||
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "d7b575338b2c647e04fc48bfbe00ea8f492fb580" }
|
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "447902eff4a574e66894ad60cb41999b05bf5e84" }
|
||||||
|
|
||||||
# llvm
|
# llvm
|
||||||
[workspace.dependencies.inkwell]
|
[workspace.dependencies.inkwell]
|
||||||
version = "0.5"
|
git = "https://github.com/TheDan64/inkwell.git"
|
||||||
|
rev = "7b410298b6a93450adaa90b1841d5805a3038f12"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["serde", "llvm18-0", "no-libffi-linking", "target-riscv"]
|
features = ["serde", "llvm18-0", "no-libffi-linking", "target-riscv"]
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,19 @@
|
|||||||
.PHONY: install format test test-solidity test-cli test-integration test-workspace clean docs docs-build
|
.PHONY: install format test test-solidity test-cli test-integration test-workspace clean docs docs-build
|
||||||
|
|
||||||
|
RUSTFLAGS_EMSCRIPTEN := \
|
||||||
|
-Clink-arg=-sEXPORTED_FUNCTIONS=_main,_free,_malloc \
|
||||||
|
-Clink-arg=-sNO_INVOKE_RUN \
|
||||||
|
-Clink-arg=-sEXIT_RUNTIME \
|
||||||
|
-Clink-arg=-sINITIAL_MEMORY=64MB \
|
||||||
|
-Clink-arg=-sTOTAL_MEMORY=3GB \
|
||||||
|
-Clink-arg=-sALLOW_MEMORY_GROWTH \
|
||||||
|
-Clink-arg=-sEXPORTED_RUNTIME_METHODS=FS,callMain,stringToNewUTF8,cwrap \
|
||||||
|
-Clink-arg=-sMODULARIZE \
|
||||||
|
-Clink-arg=-sEXPORT_NAME=createRevive \
|
||||||
|
-Clink-arg=-sWASM_ASYNC_COMPILATION=0 \
|
||||||
|
-Clink-arg=--js-library=js/embed/soljson_interface.js \
|
||||||
|
-Clink-arg=--pre-js=js/embed/pre.js
|
||||||
|
|
||||||
install: install-bin install-npm
|
install: install-bin install-npm
|
||||||
|
|
||||||
install-bin:
|
install-bin:
|
||||||
@@ -8,11 +22,24 @@ install-bin:
|
|||||||
install-npm:
|
install-npm:
|
||||||
npm install && npm fund
|
npm install && npm fund
|
||||||
|
|
||||||
|
install-wasm:
|
||||||
|
RUSTFLAGS='$(RUSTFLAGS_EMSCRIPTEN)' cargo build --target wasm32-unknown-emscripten -p revive-solidity --release --no-default-features
|
||||||
|
npm install
|
||||||
|
|
||||||
|
# install-revive: Build and install to the directory specified in REVIVE_INSTALL_DIR
|
||||||
|
ifeq ($(origin REVIVE_INSTALL_DIR), undefined)
|
||||||
|
REVIVE_INSTALL_DIR=`pwd`/release/revive-debian
|
||||||
|
endif
|
||||||
|
install-revive:
|
||||||
|
cargo install --path crates/solidity --root $(REVIVE_INSTALL_DIR)
|
||||||
|
|
||||||
format:
|
format:
|
||||||
cargo fmt --all --check
|
cargo fmt --all --check
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
cargo clippy --all-features --workspace --tests --benches -- --deny warnings --allow dead_code
|
||||||
|
|
||||||
test: format clippy test-cli test-workspace
|
test: format clippy test-cli test-workspace
|
||||||
cargo test --workspace
|
|
||||||
|
|
||||||
test-integration: install-bin
|
test-integration: install-bin
|
||||||
cargo test --package revive-integration
|
cargo test --package revive-integration
|
||||||
@@ -38,9 +65,6 @@ bench: install-bin
|
|||||||
cargo criterion --all --all-features --message-format=json \
|
cargo criterion --all --all-features --message-format=json \
|
||||||
| criterion-table > crates/benchmarks/BENCHMARKS.md
|
| criterion-table > crates/benchmarks/BENCHMARKS.md
|
||||||
|
|
||||||
clippy:
|
|
||||||
cargo clippy --all-features --workspace --tests --benches
|
|
||||||
|
|
||||||
docs: docs-build
|
docs: docs-build
|
||||||
mdbook serve --open docs/
|
mdbook serve --open docs/
|
||||||
|
|
||||||
@@ -52,4 +76,6 @@ clean:
|
|||||||
rm -rf node_modules ; \
|
rm -rf node_modules ; \
|
||||||
rm -rf crates/solidity/src/tests/cli-tests/artifacts ; \
|
rm -rf crates/solidity/src/tests/cli-tests/artifacts ; \
|
||||||
cargo uninstall revive-solidity ; \
|
cargo uninstall revive-solidity ; \
|
||||||
rm -f package-lock.json
|
rm -f package-lock.json ; \
|
||||||
|
rm -rf js/dist ; \
|
||||||
|
rm -f js/src/resolc.{wasm,js}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||

|

|
||||||
|
[](https://contracts.polkadot.io)
|
||||||
|
|
||||||
# revive
|
# revive
|
||||||
|
|
||||||
YUL and EVM assembly recompiler to LLVM, targetting RISC-V on [PolkaVM](https://github.com/koute/polkavm).
|
YUL and EVM assembly recompiler to LLVM, targetting RISC-V on [PolkaVM](https://github.com/koute/polkavm).
|
||||||
|
|
||||||
[Frontend](https://github.com/matter-labs/era-compiler-solidity) and [code generator](https://github.com/matter-labs/era-compiler-llvm-context) are based of ZKSync `zksolc`.
|
Visit [contracts.polkadot.io](https://contracts.polkadot.io) to learn more about contracts on Polkadot!
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
This is experimental software in active development and not ready just yet for production usage.
|
This is experimental software in active development and not ready just yet for production usage. Please do report any compiler related issues or missing features that are [not yet known to us](https://contracts.polkadot.io/known_issues/) here.
|
||||||
|
|
||||||
Discussion around the development is hosted on the [Polkadot Forum](https://forum.polkadot.network/t/contracts-update-solidity-on-polkavm/6949#a-new-solidity-compiler-1).
|
Discussion around the development is hosted on the [Polkadot Forum](https://forum.polkadot.network/t/contracts-update-solidity-on-polkavm/6949#a-new-solidity-compiler-1).
|
||||||
|
|
||||||
@@ -27,7 +28,25 @@ resolc --version
|
|||||||
|
|
||||||
### LLVM
|
### LLVM
|
||||||
|
|
||||||
`revive` requires a build of LLVM 18.1.4 or later including `compiler-rt`. Use the provided [build-llvm.sh](build-llvm.sh) build script to compile a compatible LLVM build locally in `$PWD/llvm18.0` (don't forget to add that to `$PATH` afterwards).
|
`revive` requires a build of LLVM 18.1.4 or later including `compiler-rt`. Use the provided [build-llvm.sh](build-llvm.sh) build script to compile a compatible LLVM build locally in `$PWD/llvm18.0` (don't forget to add that to `$PATH` afterwards).
|
||||||
|
|
||||||
|
### Cross-compilation to WASM
|
||||||
|
|
||||||
|
Cross-compiles the Revive compiler to WASM for running it in a Node.js or browser environment.
|
||||||
|
|
||||||
|
Install [emscripten](https://emscripten.org/docs/getting_started/downloads.html). Tested on version 3.1.64.
|
||||||
|
To build resolc.js execute:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash build-llvm.sh
|
||||||
|
export PATH=${PWD}/llvm18.0/bin:$PATH
|
||||||
|
export EMSDK_ROOT=<PATH_TO_EMSCRIPTEN_SDK>
|
||||||
|
bash emscripten-build-llvm.sh
|
||||||
|
source $EMSDK_ROOT/emsdk_env.sh
|
||||||
|
export LLVM_LINK_PREFIX=${PWD}/llvm18.0-emscripten
|
||||||
|
export PATH=$PATH:$PWD/llvm18.0-emscripten/bin/
|
||||||
|
make install-wasm
|
||||||
|
```
|
||||||
|
|
||||||
### Development
|
### Development
|
||||||
|
|
||||||
@@ -35,4 +54,15 @@ Please consult the [Makefile](Makefile) targets to learn how to run tests and be
|
|||||||
Ensure that your branch passes `make test` locally when submitting a pull request.
|
Ensure that your branch passes `make test` locally when submitting a pull request.
|
||||||
|
|
||||||
## Design overview
|
## Design overview
|
||||||
|
|
||||||
`revive` uses [solc](https://github.com/ethereum/solidity/), the Ethereum Solidity compiler, as the [Solidity frontend](crates/solidity/src/lib.rs) to process smart contracts written in Solidity. The YUL IR code (or legacy EVM assembly as a fallback for older `solc` versions) emitted by `solc` is then translated to LLVM IR, targetting [Polkadots `revive` pallet](https://docs.rs/pallet-revive/latest/pallet_revive/trait.SyscallDoc.html).
|
`revive` uses [solc](https://github.com/ethereum/solidity/), the Ethereum Solidity compiler, as the [Solidity frontend](crates/solidity/src/lib.rs) to process smart contracts written in Solidity. The YUL IR code (or legacy EVM assembly as a fallback for older `solc` versions) emitted by `solc` is then translated to LLVM IR, targetting [Polkadots `revive` pallet](https://docs.rs/pallet-revive/latest/pallet_revive/trait.SyscallDoc.html).
|
||||||
|
[Frontend](https://github.com/matter-labs/era-compiler-solidity) and [code generator](https://github.com/matter-labs/era-compiler-llvm-context) are based of ZKSync `zksolc`.
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
|
||||||
|
Before running the tests, ensure that Geth (Go Ethereum) is installed on your system. Follow the installation guide here: [Installing Geth](https://geth.ethereum.org/docs/getting-started/installing-geth).
|
||||||
|
Once Geth is installed, you can run the tests using the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make test
|
||||||
|
```
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
# Release checklist
|
||||||
|
|
||||||
|
Prior to the first stable release we neither have formal release processes nor do we follow a fixed release schedule.
|
||||||
|
|
||||||
|
To create a new pre-release:
|
||||||
|
|
||||||
|
1. Merge a release PR which updates the `-dev.X` versions in the workspace `Cargo.toml` and updates the `CHANGELOG.md` accordingly
|
||||||
|
2. Push a release tag to `main`
|
||||||
|
3. Manually trigger the `Build revive-debian` action
|
||||||
|
4. Create a __pre-release__ from the tag and manually upload the build artifact generated by the action
|
||||||
|
5. Update the [contract-docs](https://github.com/paritytech/contract-docs/) accordingly
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# Known issues
|
||||||
|
|
||||||
|
The following is known and we are either working on it or it is a hard limitation. Please do not open a new issue.
|
||||||
|
|
||||||
|
## Release
|
||||||
|
|
||||||
|
`0.1.0-dev-2`
|
||||||
|
|
||||||
|
## Missing features
|
||||||
|
|
||||||
|
- [Libraries with public functions are not supported](https://github.com/paritytech/revive/issues/91)
|
||||||
|
- [Automatic import resolution is not supported](https://github.com/paritytech/revive/issues/98)
|
||||||
|
- The emulated EVM linear contract memory is limited to 64kb in size. Will be fixed with support for metered dynamic memory.
|
||||||
|
- [The contract calldata is currently limited to 1kb in size](https://github.com/paritytech/revive/issues/57)
|
||||||
|
- [EIP-4844 opcodes are not supported](https://github.com/paritytech/revive/issues/64)
|
||||||
|
- [Delegate calls are not supported](https://github.com/paritytech/revive/issues/67)
|
||||||
|
- [The `blockhash` opcode is not supported](https://github.com/paritytech/revive/issues/61)
|
||||||
|
- [The `extcodesize` opcode is not supported](https://github.com/paritytech/revive/issues/58)
|
||||||
|
- [The `origin` opcode is not supported](https://github.com/paritytech/revive/issues/59)
|
||||||
|
- [Gas limits for contract calls are ignored](https://github.com/paritytech/revive/issues/60)
|
||||||
|
- [Gas related opcodes are not supported](https://github.com/paritytech/revive/issues/60)
|
||||||
|
- IPFS metadata hashes are not supported
|
||||||
|
- [Compiled contract artifacts can exceed the pallet static memory limit and fail to deploy](https://github.com/paritytech/revive/issues/96).
|
||||||
|
- [Transfers to inexistant accounts will fail if the transferred value lies below the ED.](https://github.com/paritytech/revive/issues/83) Will be fixed in the pallet to make the ED completely transparent for contracts.
|
||||||
|
|
||||||
|
## Wontfix
|
||||||
|
|
||||||
|
Please consult our documentation to learn more about Solidity and EVM features likely to remain unsupported (and why they will not be supported).
|
||||||
|
|
||||||
|
TODO: Insert link to the relevant documentation section.
|
||||||
+3
-7
@@ -5,17 +5,13 @@ set -euo pipefail
|
|||||||
INSTALL_DIR="${PWD}/llvm18.0"
|
INSTALL_DIR="${PWD}/llvm18.0"
|
||||||
mkdir -p ${INSTALL_DIR}
|
mkdir -p ${INSTALL_DIR}
|
||||||
|
|
||||||
|
|
||||||
# Clone LLVM 18 (any revision after commit bd32aaa is supposed to work)
|
|
||||||
if [ ! -d "llvm-project" ]; then
|
|
||||||
git clone --depth 1 --branch release/18.x https://github.com/llvm/llvm-project.git
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Build LLVM, clang
|
# Build LLVM, clang
|
||||||
LLVM_SRC_PREFIX=${PWD}/llvm-project
|
LLVM_SRC_PREFIX=${PWD}/llvm-project
|
||||||
LLVM_SRC_DIR=${LLVM_SRC_PREFIX}/llvm
|
LLVM_SRC_DIR=${LLVM_SRC_PREFIX}/llvm
|
||||||
LLVM_BUILD_DIR=${PWD}/build/llvm
|
LLVM_BUILD_DIR=${PWD}/build/llvm
|
||||||
|
|
||||||
|
./clone-llvm.sh "${LLVM_SRC_PREFIX}"
|
||||||
|
|
||||||
if [ ! -d ${LLVM_BUILD_DIR} ] ; then
|
if [ ! -d ${LLVM_BUILD_DIR} ] ; then
|
||||||
mkdir -p ${LLVM_BUILD_DIR}
|
mkdir -p ${LLVM_BUILD_DIR}
|
||||||
fi
|
fi
|
||||||
|
|||||||
Executable
+18
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Default directory for cloning the llvm-project repository
|
||||||
|
DEFAULT_DIR="llvm-project"
|
||||||
|
|
||||||
|
# Check if a directory argument is provided
|
||||||
|
if [ $# -eq 1 ]; then
|
||||||
|
DIR=$1
|
||||||
|
else
|
||||||
|
DIR=$DEFAULT_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clone LLVM 18 (any revision after commit bd32aaa is supposed to work)
|
||||||
|
if [ ! -d "${DIR}" ]; then
|
||||||
|
git clone --depth 1 --branch release/18.x https://github.com/llvm/llvm-project.git "${DIR}"
|
||||||
|
fi
|
||||||
@@ -17,56 +17,56 @@
|
|||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:--------|:------------------------|:-------------------------------- |
|
|:--------|:------------------------|:-------------------------------- |
|
||||||
| **`0`** | `5.97 us` (✅ **1.00x**) | `27.04 us` (❌ *4.53x slower*) |
|
| **`0`** | `3.36 us` (✅ **1.00x**) | `11.84 us` (❌ *3.52x slower*) |
|
||||||
|
|
||||||
### OddPorduct
|
### OddPorduct
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:-------------|:--------------------------|:-------------------------------- |
|
|:-------------|:-------------------------|:-------------------------------- |
|
||||||
| **`10000`** | `4.26 ms` (✅ **1.00x**) | `2.88 ms` (✅ **1.48x faster**) |
|
| **`10000`** | `3.11 ms` (✅ **1.00x**) | `1.53 ms` (🚀 **2.03x faster**) |
|
||||||
| **`100000`** | `42.37 ms` (✅ **1.00x**) | `28.35 ms` (✅ **1.49x faster**) |
|
| **`100000`** | `30.70 ms` (✅ **1.00x**) | `15.54 ms` (🚀 **1.98x faster**) |
|
||||||
| **`300000`** | `127.88 ms` (✅ **1.00x**) | `88.43 ms` (✅ **1.45x faster**) |
|
| **`300000`** | `92.68 ms` (✅ **1.00x**) | `45.47 ms` (🚀 **2.04x faster**) |
|
||||||
|
|
||||||
### TriangleNumber
|
### TriangleNumber
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:-------------|:--------------------------|:-------------------------------- |
|
|:-------------|:-------------------------|:-------------------------------- |
|
||||||
| **`10000`** | `2.85 ms` (✅ **1.00x**) | `2.37 ms` (✅ **1.20x faster**) |
|
| **`10000`** | `2.29 ms` (✅ **1.00x**) | `1.09 ms` (🚀 **2.11x faster**) |
|
||||||
| **`100000`** | `27.85 ms` (✅ **1.00x**) | `23.01 ms` (✅ **1.21x faster**) |
|
| **`100000`** | `22.84 ms` (✅ **1.00x**) | `10.66 ms` (🚀 **2.14x faster**) |
|
||||||
| **`360000`** | `103.01 ms` (✅ **1.00x**) | `83.66 ms` (✅ **1.23x faster**) |
|
| **`360000`** | `82.29 ms` (✅ **1.00x**) | `37.01 ms` (🚀 **2.22x faster**) |
|
||||||
|
|
||||||
### FibonacciRecursive
|
### FibonacciRecursive
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:---------|:--------------------------|:--------------------------------- |
|
|:---------|:--------------------------|:--------------------------------- |
|
||||||
| **`12`** | `195.19 us` (✅ **1.00x**) | `333.53 us` (❌ *1.71x slower*) |
|
| **`12`** | `135.67 us` (✅ **1.00x**) | `125.02 us` (✅ **1.09x faster**) |
|
||||||
| **`16`** | `1.22 ms` (✅ **1.00x**) | `1.97 ms` (❌ *1.62x slower*) |
|
| **`16`** | `903.75 us` (✅ **1.00x**) | `762.79 us` (✅ **1.18x faster**) |
|
||||||
| **`20`** | `8.14 ms` (✅ **1.00x**) | `13.20 ms` (❌ *1.62x slower*) |
|
| **`20`** | `6.12 ms` (✅ **1.00x**) | `4.96 ms` (✅ **1.23x faster**) |
|
||||||
| **`24`** | `55.09 ms` (✅ **1.00x**) | `88.56 ms` (❌ *1.61x slower*) |
|
| **`24`** | `42.05 ms` (✅ **1.00x**) | `33.86 ms` (✅ **1.24x faster**) |
|
||||||
|
|
||||||
### FibonacciIterative
|
### FibonacciIterative
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:----------|:-------------------------|:--------------------------------- |
|
|:----------|:-------------------------|:-------------------------------- |
|
||||||
| **`64`** | `33.39 us` (✅ **1.00x**) | `86.02 us` (❌ *2.58x slower*) |
|
| **`64`** | `15.04 us` (✅ **1.00x**) | `29.45 us` (❌ *1.96x slower*) |
|
||||||
| **`128`** | `52.91 us` (✅ **1.00x**) | `126.38 us` (❌ *2.39x slower*) |
|
| **`128`** | `26.36 us` (✅ **1.00x**) | `42.19 us` (❌ *1.60x slower*) |
|
||||||
| **`256`** | `82.33 us` (✅ **1.00x**) | `208.74 us` (❌ *2.54x slower*) |
|
| **`256`** | `48.61 us` (✅ **1.00x**) | `65.71 us` (❌ *1.35x slower*) |
|
||||||
|
|
||||||
### FibonacciBinet
|
### FibonacciBinet
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:----------|:-------------------------|:--------------------------------- |
|
|:----------|:-------------------------|:-------------------------------- |
|
||||||
| **`64`** | `32.29 us` (✅ **1.00x**) | `161.75 us` (❌ *5.01x slower*) |
|
| **`64`** | `15.22 us` (✅ **1.00x**) | `41.46 us` (❌ *2.72x slower*) |
|
||||||
| **`128`** | `36.02 us` (✅ **1.00x**) | `172.59 us` (❌ *4.79x slower*) |
|
| **`128`** | `17.05 us` (✅ **1.00x**) | `42.84 us` (❌ *2.51x slower*) |
|
||||||
| **`256`** | `41.21 us` (✅ **1.00x**) | `185.30 us` (❌ *4.50x slower*) |
|
| **`256`** | `19.00 us` (✅ **1.00x**) | `44.36 us` (❌ *2.34x slower*) |
|
||||||
|
|
||||||
### SHA1
|
### SHA1
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:----------|:--------------------------|:--------------------------------- |
|
|:----------|:--------------------------|:--------------------------------- |
|
||||||
| **`1`** | `160.17 us` (✅ **1.00x**) | `403.46 us` (❌ *2.52x slower*) |
|
| **`1`** | `110.04 us` (✅ **1.00x**) | `216.11 us` (❌ *1.96x slower*) |
|
||||||
| **`64`** | `286.69 us` (✅ **1.00x**) | `479.79 us` (❌ *1.67x slower*) |
|
| **`64`** | `209.04 us` (✅ **1.00x**) | `309.48 us` (❌ *1.48x slower*) |
|
||||||
| **`512`** | `1.18 ms` (✅ **1.00x**) | `1.37 ms` (❌ *1.16x slower*) |
|
| **`512`** | `903.65 us` (✅ **1.00x**) | `980.49 us` (✅ **1.09x slower**) |
|
||||||
|
|
||||||
---
|
---
|
||||||
Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
|
Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
|
||||||
|
|||||||
@@ -8,7 +8,4 @@ authors.workspace = true
|
|||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
description = "compiler builtins for the revive compiler"
|
description = "compiler builtins for the revive compiler"
|
||||||
|
|
||||||
[features]
|
|
||||||
riscv-64 = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
use std::{env, fs, io::Read, path::Path, process::Command};
|
use std::{env, fs, io::Read, path::Path, process::Command};
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
pub const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv32.a";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
pub const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
pub const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ description = "Shared constants of the revive compiler"
|
|||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[features]
|
|
||||||
riscv-64 = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub const BIT_LENGTH_ETH_ADDRESS: usize =
|
|||||||
pub const BIT_LENGTH_WORD: usize = crate::byte_length::BYTE_LENGTH_WORD * BIT_LENGTH_BYTE;
|
pub const BIT_LENGTH_WORD: usize = crate::byte_length::BYTE_LENGTH_WORD * BIT_LENGTH_BYTE;
|
||||||
|
|
||||||
/// Bit length of the runtime value type.
|
/// Bit length of the runtime value type.
|
||||||
pub const BIT_LENGTH_VALUE: usize = crate::byte_length::BYTE_LENGTH_VALUE * BIT_LENGTH_BYTE;
|
pub const BIT_LENGTH_VALUE: usize = BIT_LENGTH_WORD;
|
||||||
|
|
||||||
/// Bit length of thre runimte block number type.
|
/// Bit length of thre runimte block number type.
|
||||||
pub const BIT_LENGTH_BLOCK_NUMBER: usize =
|
pub const BIT_LENGTH_BLOCK_NUMBER: usize =
|
||||||
|
|||||||
@@ -6,15 +6,12 @@ pub const BYTE_LENGTH_BYTE: usize = 1;
|
|||||||
/// The x86 word byte-length.
|
/// The x86 word byte-length.
|
||||||
pub const BYTE_LENGTH_X32: usize = 4;
|
pub const BYTE_LENGTH_X32: usize = 4;
|
||||||
|
|
||||||
/// Native stack alignment size in bytes
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
pub const BYTE_LENGTH_STACK_ALIGN: usize = 4;
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
pub const BYTE_LENGTH_STACK_ALIGN: usize = 8;
|
|
||||||
|
|
||||||
/// The x86_64 word byte-length.
|
/// The x86_64 word byte-length.
|
||||||
pub const BYTE_LENGTH_X64: usize = 8;
|
pub const BYTE_LENGTH_X64: usize = 8;
|
||||||
|
|
||||||
|
/// EVM native stack alignment size in bytes
|
||||||
|
pub const BYTE_LENGTH_STACK_ALIGN: usize = 32;
|
||||||
|
|
||||||
/// The ETH address byte-length.
|
/// The ETH address byte-length.
|
||||||
pub const BYTE_LENGTH_ETH_ADDRESS: usize = 20;
|
pub const BYTE_LENGTH_ETH_ADDRESS: usize = 20;
|
||||||
|
|
||||||
|
|||||||
@@ -41,3 +41,6 @@ pub static EXTENSION_POLKAVM_ASSEMBLY: &str = "pvmasm";
|
|||||||
|
|
||||||
/// The PolkaVM bytecode file extension.
|
/// The PolkaVM bytecode file extension.
|
||||||
pub static EXTENSION_POLKAVM_BINARY: &str = "pvm";
|
pub static EXTENSION_POLKAVM_BINARY: &str = "pvm";
|
||||||
|
|
||||||
|
/// The ELF shared object file extension.
|
||||||
|
pub static EXTENSION_SHARED_OBJECT: &str = "so";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"chainId": 1,
|
"chainId": 420420420,
|
||||||
"homesteadBlock": 0,
|
"homesteadBlock": 0,
|
||||||
"eip150Block": 0,
|
"eip150Block": 0,
|
||||||
"eip155Block": 0,
|
"eip155Block": 0,
|
||||||
@@ -26,5 +26,15 @@
|
|||||||
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
"timestamp": "0x00",
|
"timestamp": "0x00",
|
||||||
"alloc": {}
|
"alloc": {
|
||||||
|
"0101010101010101010101010101010101010101": {
|
||||||
|
"balance": "1000000000"
|
||||||
|
},
|
||||||
|
"0202020202020202020202020202020202020202": {
|
||||||
|
"balance": "1000000000"
|
||||||
|
},
|
||||||
|
"0303030303030303030303030303030303030303": {
|
||||||
|
"balance": "1000000000"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ const EXECUTABLE_ARGS_BENCH: [&str; 6] = [
|
|||||||
"-",
|
"-",
|
||||||
];
|
];
|
||||||
const GAS_USED_MARKER: &str = "EVM gas used:";
|
const GAS_USED_MARKER: &str = "EVM gas used:";
|
||||||
const REVERT_MARKER: &str = "error: execution reverted";
|
const REVERT_MARKER: &str = " error: ";
|
||||||
|
|
||||||
/// The geth EVM state dump structure
|
/// The geth EVM state dump structure
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||||
@@ -100,10 +100,9 @@ pub struct EvmOutput {
|
|||||||
impl EvmOutput {
|
impl EvmOutput {
|
||||||
/// Return if there was no error found.
|
/// Return if there was no error found.
|
||||||
///
|
///
|
||||||
/// Panics if the gas used is zero as this indicates nothing was run, i.e.
|
/// Panics if the gas used is zero as this indicates nothing was run.
|
||||||
/// there was no receiving account but still no error is reported.
|
|
||||||
pub fn run_success(&self) -> bool {
|
pub fn run_success(&self) -> bool {
|
||||||
assert_ne!(self.gas_used, U256::ZERO, "nothing was executed");
|
assert_ne!(self.gas_used, U256::ZERO, "nothing was executed: {self:?}");
|
||||||
self.error.is_none()
|
self.error.is_none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -558,6 +557,7 @@ allocated bytes: 3711"#;
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore] // https://github.com/ethereum/go-ethereum/issues/30778
|
||||||
fn bench_flipper() {
|
fn bench_flipper() {
|
||||||
let log_runtime = Evm::default()
|
let log_runtime = Evm::default()
|
||||||
.code_blob(EVM_BIN_RUNTIME_FIXTURE.as_bytes().to_vec())
|
.code_blob(EVM_BIN_RUNTIME_FIXTURE.as_bytes().to_vec())
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"Baseline": 878,
|
"Baseline": 1073,
|
||||||
"Computation": 4305,
|
"Computation": 2469,
|
||||||
"DivisionArithmetics": 39774,
|
"DivisionArithmetics": 15041,
|
||||||
"ERC20": 53405,
|
"ERC20": 23282,
|
||||||
"Events": 1693,
|
"Events": 1615,
|
||||||
"FibonacciIterative": 2917,
|
"FibonacciIterative": 1676,
|
||||||
"Flipper": 3570,
|
"Flipper": 2378,
|
||||||
"SHA1": 32557
|
"SHA1": 17076
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
pragma solidity ^0.8;
|
||||||
|
|
||||||
|
/* runner.json
|
||||||
|
{
|
||||||
|
"differential": false,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"Instantiate": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "BlockHash"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"data": "4545454545454545454545454545454545454545454545454545454545454545"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
contract BlockHash {
|
||||||
|
constructor(bytes32 expected) payable {
|
||||||
|
assert(blockhash(0) == expected);
|
||||||
|
assert(blockhash(1) == 0);
|
||||||
|
assert(
|
||||||
|
blockhash(
|
||||||
|
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
||||||
|
) == 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,19 +2,57 @@
|
|||||||
|
|
||||||
pragma solidity ^0.8;
|
pragma solidity ^0.8;
|
||||||
|
|
||||||
contract Call {
|
/* runner.json
|
||||||
function value_transfer(address payable destination) public payable {
|
{
|
||||||
destination.transfer(msg.value);
|
"differential": true,
|
||||||
}
|
"actions": [
|
||||||
|
{
|
||||||
|
"Upload": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "Callee"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Instantiate": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "Caller"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"value": 123
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
},
|
||||||
|
"data": "5a6535fc00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004cafebabe00000000000000000000000000000000000000000000000000000000"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
contract Callee {
|
||||||
function echo(bytes memory payload) public pure returns (bytes memory) {
|
function echo(bytes memory payload) public pure returns (bytes memory) {
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
function call(
|
receive() external payable {}
|
||||||
address callee,
|
}
|
||||||
bytes memory payload
|
|
||||||
) public pure returns (bytes memory) {
|
contract Caller {
|
||||||
return Call(callee).echo(payload);
|
constructor() payable {
|
||||||
|
Callee callee = new Callee();
|
||||||
|
payable(address(callee)).transfer(msg.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function call(bytes memory payload) public returns (bytes memory) {
|
||||||
|
Callee callee = new Callee();
|
||||||
|
return callee.echo(payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,14 @@ pragma solidity ^0.8;
|
|||||||
},
|
},
|
||||||
"data": "fc9c8d39"
|
"data": "fc9c8d39"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
},
|
||||||
|
"data": "3af973b1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -43,4 +51,12 @@ contract Context {
|
|||||||
function caller() public view returns (address ret) {
|
function caller() public view returns (address ret) {
|
||||||
ret = msg.sender;
|
ret = msg.sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function chain_id() public view returns (uint) {
|
||||||
|
uint256 id;
|
||||||
|
assembly {
|
||||||
|
id := chainid()
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,64 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
pragma solidity ^0.8.24;
|
pragma solidity ^0.8;
|
||||||
|
|
||||||
|
/* runner.json
|
||||||
|
{
|
||||||
|
"differential": true,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"Upload": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "CreateA"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Instantiate": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "CreateB"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
},
|
||||||
|
"value": 10000
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
contract CreateA {
|
contract CreateA {
|
||||||
address creator;
|
constructor() payable {}
|
||||||
|
|
||||||
constructor() payable {
|
|
||||||
creator = msg.sender;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contract CreateB {
|
contract CreateB {
|
||||||
|
|||||||
@@ -4,30 +4,32 @@ pragma solidity ^0.8.24;
|
|||||||
|
|
||||||
/* runner.json
|
/* runner.json
|
||||||
{
|
{
|
||||||
"actions": [
|
"differential": true,
|
||||||
|
"actions": [
|
||||||
{
|
{
|
||||||
"Instantiate": {}
|
"Instantiate": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "TestSha3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Call": {
|
"Call": {
|
||||||
"dest": {
|
"dest": {
|
||||||
"Instantiated": 0
|
"Instantiated": 0
|
||||||
},
|
},
|
||||||
"data": "f9fbd5540000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000c68656c6c6f20776f726c64210000000000000000000000000000000000000000"
|
"data": "f9fbd5540000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000c68656c6c6f20776f726c64210000000000000000000000000000000000000000"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"VerifyCall": {
|
|
||||||
"success": true,
|
|
||||||
"output": "57caa176af1ac0433c5df30e8dabcd2ec1af1e92a26eced5f719b88458777cd6"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
contract TestSha3 {
|
contract TestSha3 {
|
||||||
function test(string memory _pre) external payable returns (bytes32 hash) {
|
function test(string memory _pre) external payable returns (bytes32) {
|
||||||
hash = keccak256(bytes(_pre));
|
bytes32 hash = keccak256(bytes(_pre));
|
||||||
|
return bytes32(uint(hash) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
pragma solidity ^0.8;
|
||||||
|
|
||||||
|
/* runner.json
|
||||||
|
{
|
||||||
|
"differential": true,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"Upload": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "Logic"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Instantiate": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "Tester"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
},
|
||||||
|
"value": 123,
|
||||||
|
"data": "6466414b0000000000000000000000000000000000000000000000000000000000000020"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
contract Logic {
|
||||||
|
// NOTE: storage layout must be the same as contract Tester
|
||||||
|
uint256 public num;
|
||||||
|
address public sender;
|
||||||
|
uint256 public value;
|
||||||
|
|
||||||
|
uint public immutable multiplier = 4;
|
||||||
|
|
||||||
|
event DidSetVars();
|
||||||
|
|
||||||
|
function setVars(uint256 _num) public payable returns (uint256) {
|
||||||
|
num = _num * multiplier;
|
||||||
|
sender = msg.sender;
|
||||||
|
value = msg.value;
|
||||||
|
emit DidSetVars();
|
||||||
|
return _num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Tester {
|
||||||
|
uint256 public num;
|
||||||
|
address public sender;
|
||||||
|
uint256 public value;
|
||||||
|
|
||||||
|
uint public immutable multiplier = 2;
|
||||||
|
|
||||||
|
function setVars(uint256 _num) public payable returns (bool, bytes memory) {
|
||||||
|
Logic impl = new Logic();
|
||||||
|
|
||||||
|
// Tester's storage is set, Logic is not modified.
|
||||||
|
(bool success, bytes memory data) = address(impl).delegatecall(
|
||||||
|
abi.encodeWithSignature("setVars(uint256)", _num)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(success);
|
||||||
|
assert(impl.num() == 0);
|
||||||
|
assert(impl.sender() == address(0));
|
||||||
|
assert(impl.value() == 0);
|
||||||
|
assert(num == _num * 4);
|
||||||
|
assert(sender == msg.sender);
|
||||||
|
assert(value == msg.value);
|
||||||
|
|
||||||
|
return (success, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,11 +4,27 @@ pragma solidity ^0.8;
|
|||||||
|
|
||||||
/* runner.json
|
/* runner.json
|
||||||
{
|
{
|
||||||
|
"differential": true,
|
||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
"Instantiate": {}
|
"Upload": {
|
||||||
}
|
"code": {
|
||||||
]
|
"Solidity": {
|
||||||
|
"contract": "ERC20"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Instantiate": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "ERC20Tester"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -82,3 +98,26 @@ contract ERC20 is IERC20 {
|
|||||||
emit Transfer(msg.sender, address(0), amount);
|
emit Transfer(msg.sender, address(0), amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contract ERC20Tester {
|
||||||
|
constructor() {
|
||||||
|
address BOB = address(0xffffffffffffffffffffffffffffffffffffff);
|
||||||
|
ERC20 token = new ERC20();
|
||||||
|
assert(token.decimals() == 18);
|
||||||
|
|
||||||
|
token.mint(300);
|
||||||
|
assert(token.balanceOf(address(this)) == 300);
|
||||||
|
token.transfer(BOB, 100);
|
||||||
|
assert(token.balanceOf(address(this)) == 200);
|
||||||
|
assert(token.balanceOf(BOB) == 100);
|
||||||
|
|
||||||
|
token.approve(address(this), 100);
|
||||||
|
|
||||||
|
token.transferFrom(address(this), BOB, 100);
|
||||||
|
assert(token.balanceOf(BOB) == 200);
|
||||||
|
assert(token.balanceOf(address(this)) == 100);
|
||||||
|
|
||||||
|
token.burn(100);
|
||||||
|
assert(token.balanceOf(address(this)) == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,12 +22,7 @@ pragma solidity ^0.8;
|
|||||||
},
|
},
|
||||||
"data": "4d43bec90000000000000000000000000000000000000000000000000000000000000000"
|
"data": "4d43bec90000000000000000000000000000000000000000000000000000000000000000"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
]
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* TODO when pallet_revive accepts Solidity event topics
|
|
||||||
{
|
{
|
||||||
"Call": {
|
"Call": {
|
||||||
"dest": {
|
"dest": {
|
||||||
@@ -36,7 +31,8 @@ pragma solidity ^0.8;
|
|||||||
"data": "4d43bec9000000000000000000000000000000000000000000000000000000000000007b"
|
"data": "4d43bec9000000000000000000000000000000000000000000000000000000000000007b"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
contract Events {
|
contract Events {
|
||||||
|
|||||||
@@ -14,4 +14,16 @@ contract ExtCode {
|
|||||||
ret := codesize()
|
ret := codesize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ExtCodeHash(address who) public view returns (bytes32 ret) {
|
||||||
|
assembly {
|
||||||
|
ret := extcodehash(who)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function CodeHash() public view returns (bytes32 ret) {
|
||||||
|
assembly {
|
||||||
|
ret := extcodehash(address())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
pragma solidity ^0.8;
|
||||||
|
|
||||||
|
/* runner.json
|
||||||
|
{
|
||||||
|
"differential": false,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"Instantiate": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "GasPrice"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"VerifyCall": {
|
||||||
|
"success": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
contract GasPrice {
|
||||||
|
constructor() payable {
|
||||||
|
assert(tx.gasprice == 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.8;
|
||||||
|
|
||||||
|
/* runner.json
|
||||||
|
{
|
||||||
|
"differential": true,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"Upload": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "ImmutablesTester"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Instantiate": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "Immutables"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
contract ImmutablesTester {
|
||||||
|
// Read should work in the runtime code
|
||||||
|
uint public immutable foo;
|
||||||
|
// Read should work in the runtime code
|
||||||
|
uint public immutable bar;
|
||||||
|
// Read should work in the runtime code
|
||||||
|
uint public immutable zoo;
|
||||||
|
|
||||||
|
// Assign and read should work in the constructor
|
||||||
|
constructor(uint _foo) payable {
|
||||||
|
foo = _foo;
|
||||||
|
bar = foo + 1;
|
||||||
|
zoo = bar + 2;
|
||||||
|
|
||||||
|
assert(zoo == _foo + 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Immutables {
|
||||||
|
fallback() external {
|
||||||
|
ImmutablesTester tester = new ImmutablesTester(127);
|
||||||
|
|
||||||
|
assert(tester.foo() == 127);
|
||||||
|
assert(tester.bar() == tester.foo() + 1);
|
||||||
|
assert(tester.zoo() == tester.bar() + 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ pragma solidity ^0.8;
|
|||||||
|
|
||||||
/* runner.json
|
/* runner.json
|
||||||
{
|
{
|
||||||
|
"differential": true,
|
||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
"Instantiate": {
|
"Instantiate": {
|
||||||
@@ -23,12 +24,6 @@ pragma solidity ^0.8;
|
|||||||
"data": "f016832c"
|
"data": "f016832c"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"VerifyCall": {
|
|
||||||
"success": true,
|
|
||||||
"output": "0000000000000000000000000000000000000000000000000000000000000060"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"Call": {
|
"Call": {
|
||||||
"dest": {
|
"dest": {
|
||||||
@@ -36,12 +31,6 @@ pragma solidity ^0.8;
|
|||||||
},
|
},
|
||||||
"data": "f4a63aa5"
|
"data": "f4a63aa5"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"VerifyCall": {
|
|
||||||
"success": true,
|
|
||||||
"output": "0000000000000000000000000000000000000000000000000000000000000084"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
pragma solidity ^0.8;
|
||||||
|
|
||||||
|
/* runner.json
|
||||||
|
{
|
||||||
|
"differential": true,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"Upload": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "Callee"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Instantiate": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "ReturnDataOob"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
contract Callee {
|
||||||
|
function echo(bytes memory payload) public pure returns (bytes memory) {
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract ReturnDataOob {
|
||||||
|
fallback() external {
|
||||||
|
new Callee().echo(hex"1234");
|
||||||
|
assembly {
|
||||||
|
let pos := mload(64)
|
||||||
|
let size := add(returndatasize(), 1)
|
||||||
|
returndatacopy(pos, 0, size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,14 @@ pragma solidity ^0.8;
|
|||||||
},
|
},
|
||||||
"data": "fabc9efaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
"data": "fabc9efaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
},
|
||||||
|
"data": "558b9f9bffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -30,10 +38,18 @@ pragma solidity ^0.8;
|
|||||||
contract Storage {
|
contract Storage {
|
||||||
function transient(uint value) public returns (uint ret) {
|
function transient(uint value) public returns (uint ret) {
|
||||||
assembly {
|
assembly {
|
||||||
let slot := 123
|
let slot := 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00
|
||||||
tstore(slot, value)
|
tstore(slot, value)
|
||||||
let success := call(0, 0, 0, 0, 0, 0, 0)
|
let success := call(0, 0, 0, 0, 0, 0, 0)
|
||||||
ret := tload(slot)
|
ret := tload(slot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function persistent(uint value) public returns (uint ret) {
|
||||||
|
assembly {
|
||||||
|
let slot := 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00
|
||||||
|
sstore(slot, value)
|
||||||
|
ret := sload(slot)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
/* runner.json
|
||||||
|
{
|
||||||
|
"differential": true,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"Upload": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "TransactionOrigin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Instantiate": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "TransactionTester"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
},
|
||||||
|
"data": "f8a8fd6d"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
contract TransactionTester {
|
||||||
|
constructor() payable {
|
||||||
|
assert(tx.origin == new TransactionOrigin().test());
|
||||||
|
}
|
||||||
|
|
||||||
|
function test() public payable returns (address ret) {
|
||||||
|
ret = tx.origin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract TransactionOrigin {
|
||||||
|
function test() public payable returns (address ret) {
|
||||||
|
assert(msg.sender != tx.origin);
|
||||||
|
|
||||||
|
ret = tx.origin;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.8;
|
||||||
|
|
||||||
|
/* runner.json
|
||||||
|
{
|
||||||
|
"differential": true,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"Instantiate": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "Transfer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"value": 11
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
},
|
||||||
|
"data": "1c8d16b30000000000000000000000000303030303030303030303030303030303030303000000000000000000000000000000000000000000000000000000000000000a"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
},
|
||||||
|
"data": "fb9e8d0500000000000000000000000003030303030303030303030303030303030303030000000000000000000000000000000000000000000000000000000000000001"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
contract Transfer {
|
||||||
|
constructor() payable {
|
||||||
|
transfer_self(msg.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function address_self() internal view returns (address payable) {
|
||||||
|
return payable(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
function transfer_self(uint _amount) public payable {
|
||||||
|
transfer_to(address_self(), _amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
function transfer_to(address payable _dest, uint _amount) public payable {
|
||||||
|
_dest.transfer(_amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,18 @@ pragma solidity ^0.8;
|
|||||||
{
|
{
|
||||||
"differential": true,
|
"differential": true,
|
||||||
"actions": [
|
"actions": [
|
||||||
|
{
|
||||||
|
"Upload": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "ValueTester"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"Instantiate": {
|
"Instantiate": {
|
||||||
|
"value": 1024,
|
||||||
"code": {
|
"code": {
|
||||||
"Solidity": {
|
"Solidity": {
|
||||||
"contract": "Value"
|
"contract": "Value"
|
||||||
@@ -19,6 +29,7 @@ pragma solidity ^0.8;
|
|||||||
"dest": {
|
"dest": {
|
||||||
"Instantiated": 0
|
"Instantiated": 0
|
||||||
},
|
},
|
||||||
|
"value": 123,
|
||||||
"data": "3fa4f245"
|
"data": "3fa4f245"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,12 +37,30 @@ pragma solidity ^0.8;
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
contract ValueTester {
|
||||||
|
constructor() payable {}
|
||||||
|
|
||||||
|
function balance_self() public view returns (uint ret) {
|
||||||
|
ret = address(this).balance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
contract Value {
|
contract Value {
|
||||||
|
constructor() payable {
|
||||||
|
ValueTester tester = new ValueTester{value: msg.value}();
|
||||||
|
|
||||||
|
// own account
|
||||||
|
assert(address(this).balance == 0);
|
||||||
|
|
||||||
|
// tester account
|
||||||
|
assert(address(tester).balance == msg.value);
|
||||||
|
assert(tester.balance_self() == msg.value);
|
||||||
|
|
||||||
|
// non-existant account
|
||||||
|
assert(address(0xdeadbeef).balance == 0);
|
||||||
|
}
|
||||||
|
|
||||||
function value() public payable returns (uint ret) {
|
function value() public payable returns (uint ret) {
|
||||||
ret = msg.value;
|
ret = msg.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function balance_of(address _address) public view returns (uint ret) {
|
|
||||||
ret = _address.balance;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,10 +178,16 @@ sol!(
|
|||||||
function ExtCodeSize(address who) public view returns (uint ret);
|
function ExtCodeSize(address who) public view returns (uint ret);
|
||||||
|
|
||||||
function CodeSize() public pure returns (uint ret);
|
function CodeSize() public pure returns (uint ret);
|
||||||
|
|
||||||
|
function ExtCodeHash(address who) public view returns (bytes32 ret);
|
||||||
|
|
||||||
|
function CodeHash() public view returns (bytes32 ret);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
case!("ExtCode.sol", ExtCode, ExtCodeSizeCall, ext_code_size, address: Address);
|
case!("ExtCode.sol", ExtCode, ExtCodeSizeCall, ext_code_size, address: Address);
|
||||||
case!("ExtCode.sol", ExtCode, CodeSizeCall, code_size,);
|
case!("ExtCode.sol", ExtCode, CodeSizeCall, code_size,);
|
||||||
|
case!("ExtCode.sol", ExtCode, ExtCodeHashCall, ext_code_hash, address: Address);
|
||||||
|
case!("ExtCode.sol", ExtCode, CodeHashCall, code_hash,);
|
||||||
|
|
||||||
sol!(
|
sol!(
|
||||||
contract MCopy {
|
contract MCopy {
|
||||||
@@ -209,9 +215,11 @@ case!("Call.sol", "Call", vec![], call_constructor);
|
|||||||
sol!(
|
sol!(
|
||||||
contract Value {
|
contract Value {
|
||||||
function balance_of(address _address) public view returns (uint ret);
|
function balance_of(address _address) public view returns (uint ret);
|
||||||
|
function balance_self() public view returns (uint ret);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
case!("Value.sol", Value, balance_ofCall, value_balance_of, address: Address);
|
case!("Value.sol", Value, balance_ofCall, value_balance_of, address: Address);
|
||||||
|
case!("Value.sol", Value, balance_selfCall, value_balance_self,);
|
||||||
|
|
||||||
sol!(
|
sol!(
|
||||||
contract Bitwise {
|
contract Bitwise {
|
||||||
|
|||||||
+211
-137
@@ -6,6 +6,10 @@ use SpecsAction::*;
|
|||||||
|
|
||||||
use crate::cases::Contract;
|
use crate::cases::Contract;
|
||||||
|
|
||||||
|
/// Parameters:
|
||||||
|
/// - The function name of the test
|
||||||
|
/// - The contract name to fill in empty code based on the file path
|
||||||
|
/// - The contract source file
|
||||||
macro_rules! test_spec {
|
macro_rules! test_spec {
|
||||||
($test_name:ident, $contract_name:literal, $source_file:literal) => {
|
($test_name:ident, $contract_name:literal, $source_file:literal) => {
|
||||||
#[test]
|
#[test]
|
||||||
@@ -26,7 +30,6 @@ test_spec!(hash_keccak_256, "TestSha3", "Crypto.sol");
|
|||||||
test_spec!(erc20, "ERC20", "ERC20.sol");
|
test_spec!(erc20, "ERC20", "ERC20.sol");
|
||||||
test_spec!(computation, "Computation", "Computation.sol");
|
test_spec!(computation, "Computation", "Computation.sol");
|
||||||
test_spec!(msize, "MSize", "MSize.sol");
|
test_spec!(msize, "MSize", "MSize.sol");
|
||||||
test_spec!(transferred_value, "Value", "Value.sol");
|
|
||||||
test_spec!(sha1, "SHA1", "SHA1.sol");
|
test_spec!(sha1, "SHA1", "SHA1.sol");
|
||||||
test_spec!(block, "Block", "Block.sol");
|
test_spec!(block, "Block", "Block.sol");
|
||||||
test_spec!(mcopy, "MCopy", "MCopy.sol");
|
test_spec!(mcopy, "MCopy", "MCopy.sol");
|
||||||
@@ -34,6 +37,16 @@ test_spec!(events, "Events", "Events.sol");
|
|||||||
test_spec!(storage, "Storage", "Storage.sol");
|
test_spec!(storage, "Storage", "Storage.sol");
|
||||||
test_spec!(mstore8, "MStore8", "MStore8.sol");
|
test_spec!(mstore8, "MStore8", "MStore8.sol");
|
||||||
test_spec!(address, "Context", "Context.sol");
|
test_spec!(address, "Context", "Context.sol");
|
||||||
|
test_spec!(balance, "Value", "Value.sol");
|
||||||
|
test_spec!(create, "CreateB", "Create.sol");
|
||||||
|
test_spec!(call, "Caller", "Call.sol");
|
||||||
|
test_spec!(transfer, "Transfer", "Transfer.sol");
|
||||||
|
test_spec!(return_data_oob, "ReturnDataOob", "ReturnDataOob.sol");
|
||||||
|
test_spec!(immutables, "Immutables", "Immutables.sol");
|
||||||
|
test_spec!(transaction, "Transaction", "Transaction.sol");
|
||||||
|
test_spec!(block_hash, "BlockHash", "BlockHash.sol");
|
||||||
|
test_spec!(delegate, "Delegate", "Delegate.sol");
|
||||||
|
test_spec!(gas_price, "GasPrice", "GasPrice.sol");
|
||||||
|
|
||||||
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
||||||
vec![Instantiate {
|
vec![Instantiate {
|
||||||
@@ -221,66 +234,206 @@ fn signed_remainder() {
|
|||||||
data: Contract::division_arithmetics_smod(n, d).calldata,
|
data: Contract::division_arithmetics_smod(n, d).calldata,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_differential(actions);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ext_code_hash() {
|
||||||
|
let mut actions = instantiate("contracts/ExtCode.sol", "ExtCode");
|
||||||
|
|
||||||
|
// First do contract instantiation to figure out address and code hash
|
||||||
|
let results = Specs {
|
||||||
|
actions: actions.clone(),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.run();
|
||||||
|
let (addr, code_hash) = match results.first().cloned() {
|
||||||
|
Some(CallResult::Instantiate {
|
||||||
|
result, code_hash, ..
|
||||||
|
}) => (result.result.unwrap().addr, code_hash),
|
||||||
|
_ => panic!("instantiate contract failed"),
|
||||||
|
};
|
||||||
|
|
||||||
|
// code hash of itself
|
||||||
|
actions.push(Call {
|
||||||
|
origin: TestAddress::Alice,
|
||||||
|
dest: TestAddress::Instantiated(0),
|
||||||
|
value: 0,
|
||||||
|
gas_limit: None,
|
||||||
|
storage_deposit_limit: None,
|
||||||
|
data: Contract::code_hash().calldata,
|
||||||
|
});
|
||||||
|
actions.push(VerifyCall(VerifyCallExpectation {
|
||||||
|
success: true,
|
||||||
|
output: OptionalHex::from(code_hash.as_bytes().to_vec()),
|
||||||
|
gas_consumed: None,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// code hash for a given contract address
|
||||||
|
actions.push(Call {
|
||||||
|
origin: TestAddress::Alice,
|
||||||
|
dest: TestAddress::Instantiated(0),
|
||||||
|
value: 0,
|
||||||
|
gas_limit: None,
|
||||||
|
storage_deposit_limit: None,
|
||||||
|
data: Contract::ext_code_hash(Address::from(addr.to_fixed_bytes())).calldata,
|
||||||
|
});
|
||||||
|
actions.push(VerifyCall(VerifyCallExpectation {
|
||||||
|
success: true,
|
||||||
|
output: OptionalHex::from(code_hash.as_bytes().to_vec()),
|
||||||
|
gas_consumed: None,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// EOA returns fixed hash
|
||||||
|
actions.push(Call {
|
||||||
|
origin: TestAddress::Alice,
|
||||||
|
dest: TestAddress::Instantiated(0),
|
||||||
|
value: 0,
|
||||||
|
gas_limit: None,
|
||||||
|
storage_deposit_limit: None,
|
||||||
|
data: Contract::ext_code_hash(Address::from(CHARLIE.to_fixed_bytes())).calldata,
|
||||||
|
});
|
||||||
|
actions.push(VerifyCall(VerifyCallExpectation {
|
||||||
|
success: true,
|
||||||
|
output: OptionalHex::from(
|
||||||
|
hex!("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").to_vec(),
|
||||||
|
),
|
||||||
|
gas_consumed: None,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// non-existing account
|
||||||
|
actions.push(Call {
|
||||||
|
origin: TestAddress::Alice,
|
||||||
|
dest: TestAddress::Instantiated(0),
|
||||||
|
value: 0,
|
||||||
|
gas_limit: None,
|
||||||
|
storage_deposit_limit: None,
|
||||||
|
data: Contract::ext_code_hash(Address::from([8u8; 20])).calldata,
|
||||||
|
});
|
||||||
|
actions.push(VerifyCall(VerifyCallExpectation {
|
||||||
|
success: true,
|
||||||
|
output: OptionalHex::from([0u8; 32].to_vec()),
|
||||||
|
gas_consumed: None,
|
||||||
|
}));
|
||||||
|
|
||||||
|
Specs {
|
||||||
|
actions,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ext_code_size() {
|
||||||
|
let alice = Address::from(ALICE.0);
|
||||||
|
let own_address = alice.create(0);
|
||||||
|
let baseline_address = alice.create2([0u8; 32], keccak256(Contract::baseline().pvm_runtime));
|
||||||
|
|
||||||
|
let own_code_size = U256::from(
|
||||||
|
Contract::ext_code_size(Default::default())
|
||||||
|
.pvm_runtime
|
||||||
|
.len(),
|
||||||
|
);
|
||||||
|
let baseline_code_size = U256::from(Contract::baseline().pvm_runtime.len());
|
||||||
|
|
||||||
|
Specs {
|
||||||
|
actions: vec![
|
||||||
|
// Instantiate the test contract
|
||||||
|
instantiate("contracts/ExtCode.sol", "ExtCode").remove(0),
|
||||||
|
// Instantiate the baseline contract
|
||||||
|
Instantiate {
|
||||||
|
origin: TestAddress::Alice,
|
||||||
|
value: 0,
|
||||||
|
gas_limit: Some(GAS_LIMIT),
|
||||||
|
storage_deposit_limit: None,
|
||||||
|
code: Code::Solidity {
|
||||||
|
path: Some("contracts/Baseline.sol".into()),
|
||||||
|
contract: "Baseline".to_string(),
|
||||||
|
solc_optimizer: None,
|
||||||
|
pipeline: None,
|
||||||
|
},
|
||||||
|
data: vec![],
|
||||||
|
salt: OptionalHex::from([0; 32]),
|
||||||
|
},
|
||||||
|
// Alice is not a contract and returns a code size of 0
|
||||||
|
Call {
|
||||||
|
origin: TestAddress::Alice,
|
||||||
|
dest: TestAddress::Instantiated(0),
|
||||||
|
value: 0,
|
||||||
|
gas_limit: None,
|
||||||
|
storage_deposit_limit: None,
|
||||||
|
data: Contract::ext_code_size(alice).calldata,
|
||||||
|
},
|
||||||
|
VerifyCall(VerifyCallExpectation {
|
||||||
|
success: true,
|
||||||
|
output: OptionalHex::from([0u8; 32].to_vec()),
|
||||||
|
gas_consumed: None,
|
||||||
|
}),
|
||||||
|
// Unknown address returns a code size of 0
|
||||||
|
Call {
|
||||||
|
origin: TestAddress::Alice,
|
||||||
|
dest: TestAddress::Instantiated(0),
|
||||||
|
value: 0,
|
||||||
|
gas_limit: None,
|
||||||
|
storage_deposit_limit: None,
|
||||||
|
data: Contract::ext_code_size(Address::from([0xff; 20])).calldata,
|
||||||
|
},
|
||||||
|
VerifyCall(VerifyCallExpectation {
|
||||||
|
success: true,
|
||||||
|
output: OptionalHex::from([0u8; 32].to_vec()),
|
||||||
|
gas_consumed: None,
|
||||||
|
}),
|
||||||
|
// Own address via extcodesize returns own code size
|
||||||
|
Call {
|
||||||
|
origin: TestAddress::Alice,
|
||||||
|
dest: TestAddress::Instantiated(0),
|
||||||
|
value: 0,
|
||||||
|
gas_limit: None,
|
||||||
|
storage_deposit_limit: None,
|
||||||
|
data: Contract::ext_code_size(own_address).calldata,
|
||||||
|
},
|
||||||
|
VerifyCall(VerifyCallExpectation {
|
||||||
|
success: true,
|
||||||
|
output: OptionalHex::from(own_code_size.to_be_bytes::<32>().to_vec()),
|
||||||
|
gas_consumed: None,
|
||||||
|
}),
|
||||||
|
// Own address via codesize returns own code size
|
||||||
|
Call {
|
||||||
|
origin: TestAddress::Alice,
|
||||||
|
dest: TestAddress::Instantiated(0),
|
||||||
|
value: 0,
|
||||||
|
gas_limit: None,
|
||||||
|
storage_deposit_limit: None,
|
||||||
|
data: Contract::code_size().calldata,
|
||||||
|
},
|
||||||
|
VerifyCall(VerifyCallExpectation {
|
||||||
|
success: true,
|
||||||
|
output: OptionalHex::from(own_code_size.to_be_bytes::<32>().to_vec()),
|
||||||
|
gas_consumed: None,
|
||||||
|
}),
|
||||||
|
// Baseline address returns the baseline code size
|
||||||
|
Call {
|
||||||
|
origin: TestAddress::Alice,
|
||||||
|
dest: TestAddress::Instantiated(0),
|
||||||
|
value: 0,
|
||||||
|
gas_limit: None,
|
||||||
|
storage_deposit_limit: None,
|
||||||
|
data: Contract::ext_code_size(baseline_address).calldata,
|
||||||
|
},
|
||||||
|
VerifyCall(VerifyCallExpectation {
|
||||||
|
success: true,
|
||||||
|
output: OptionalHex::from(baseline_code_size.to_be_bytes::<32>().to_vec()),
|
||||||
|
gas_consumed: None,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#[test]
|
// These test were implement for the mock-runtime and need to be ported yet.
|
||||||
fn events() {
|
|
||||||
assert_success(&Contract::event(U256::ZERO), true);
|
|
||||||
assert_success(&Contract::event(U256::from(123)), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn balance() {
|
|
||||||
let (_, output) = assert_success(&Contract::value_balance_of(Default::default()), false);
|
|
||||||
|
|
||||||
let expected = U256::ZERO;
|
|
||||||
let received = U256::from_be_slice(&output.data);
|
|
||||||
assert_eq!(expected, received);
|
|
||||||
|
|
||||||
let expected = U256::from(54589);
|
|
||||||
let (mut state, address) = State::new_deployed(Contract::value_balance_of(Default::default()));
|
|
||||||
state.accounts_mut().get_mut(&address).unwrap().value = expected;
|
|
||||||
|
|
||||||
let contract = Contract::value_balance_of(address);
|
|
||||||
let (_, output) = state
|
|
||||||
.transaction()
|
|
||||||
.with_default_account(&contract.pvm_runtime)
|
|
||||||
.calldata(contract.calldata)
|
|
||||||
.call();
|
|
||||||
|
|
||||||
assert_eq!(ReturnFlags::Success, output.flags);
|
|
||||||
|
|
||||||
let received = U256::from_be_slice(&output.data);
|
|
||||||
assert_eq!(expected, received)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn create2() {
|
|
||||||
let mut state = State::default();
|
|
||||||
let contract_a = Contract::create_a();
|
|
||||||
state.upload_code(&contract_a.pvm_runtime);
|
|
||||||
|
|
||||||
let contract = Contract::create_b();
|
|
||||||
let (state, output) = state
|
|
||||||
.transaction()
|
|
||||||
.with_default_account(&contract.pvm_runtime)
|
|
||||||
.calldata(contract.calldata)
|
|
||||||
.call();
|
|
||||||
|
|
||||||
assert_eq!(output.flags, ReturnFlags::Success);
|
|
||||||
assert_eq!(state.accounts().len(), 2);
|
|
||||||
|
|
||||||
for address in state.accounts().keys() {
|
|
||||||
if *address != Transaction::default_address() {
|
|
||||||
let derived_address = Transaction::default_address().create2(
|
|
||||||
B256::from(U256::from(1)),
|
|
||||||
keccak256(&contract_a.pvm_runtime).0,
|
|
||||||
);
|
|
||||||
assert_eq!(*address, derived_address);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create2_failure() {
|
fn create2_failure() {
|
||||||
@@ -307,83 +460,4 @@ fn create2_failure() {
|
|||||||
|
|
||||||
assert_eq!(output.flags, ReturnFlags::Revert);
|
assert_eq!(output.flags, ReturnFlags::Revert);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn create_with_value() {
|
|
||||||
let mut state = State::default();
|
|
||||||
state.upload_code(&Contract::create_a().pvm_runtime);
|
|
||||||
let amount = U256::from(123);
|
|
||||||
|
|
||||||
let contract = Contract::create_b();
|
|
||||||
let (state, output) = state
|
|
||||||
.transaction()
|
|
||||||
.with_default_account(&contract.pvm_runtime)
|
|
||||||
.callvalue(amount)
|
|
||||||
.call();
|
|
||||||
|
|
||||||
assert_eq!(output.flags, ReturnFlags::Success);
|
|
||||||
assert_eq!(state.accounts().len(), 2);
|
|
||||||
|
|
||||||
for (address, account) in state.accounts() {
|
|
||||||
if *address == Transaction::default_address() {
|
|
||||||
assert_eq!(account.value, U256::ZERO);
|
|
||||||
} else {
|
|
||||||
assert_eq!(account.value, amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn ext_code_size() {
|
|
||||||
let contract = Contract::ext_code_size(Transaction::default_address());
|
|
||||||
let (_, output) = assert_success(&contract, false);
|
|
||||||
let received = U256::from_be_slice(&output.data);
|
|
||||||
let expected = U256::from(contract.pvm_runtime.len());
|
|
||||||
assert_eq!(received, expected);
|
|
||||||
|
|
||||||
let contract = Contract::ext_code_size(Default::default());
|
|
||||||
let (_, output) = assert_success(&contract, false);
|
|
||||||
let received = U256::from_be_slice(&output.data);
|
|
||||||
let expected = U256::ZERO;
|
|
||||||
assert_eq!(received, expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn code_size() {
|
|
||||||
let contract = Contract::code_size();
|
|
||||||
let (_, output) = assert_success(&contract, false);
|
|
||||||
let expected = U256::from(contract.pvm_runtime.len());
|
|
||||||
let received = U256::from_be_slice(&output.data);
|
|
||||||
assert_eq!(expected, received);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn value_transfer() {
|
|
||||||
// Succeeds in remix (shanghai) but traps the interpreter
|
|
||||||
let (state, _) = assert_success(&Contract::call_value_transfer(Default::default()), false);
|
|
||||||
|
|
||||||
assert_eq!(state.accounts().len(), 2);
|
|
||||||
assert!(state.accounts().get(&Address::default()).is_some());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn echo() {
|
|
||||||
let (state, address) = State::new_deployed(Contract::call_constructor());
|
|
||||||
|
|
||||||
let expected = vec![1, 2, 3, 4, 5];
|
|
||||||
let contract = Contract::call_call(address, expected.clone());
|
|
||||||
let (_, output) = state
|
|
||||||
.transaction()
|
|
||||||
.with_default_account(&contract.pvm_runtime)
|
|
||||||
.calldata(contract.calldata)
|
|
||||||
.call();
|
|
||||||
|
|
||||||
assert_eq!(output.flags, ReturnFlags::Success);
|
|
||||||
|
|
||||||
let received = alloy_primitives::Bytes::abi_decode(&output.data, true)
|
|
||||||
.unwrap()
|
|
||||||
.to_vec();
|
|
||||||
|
|
||||||
assert_eq!(expected, received);
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ repository.workspace = true
|
|||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
description = "revive compiler linker utils"
|
description = "revive compiler linker utils"
|
||||||
|
|
||||||
[features]
|
|
||||||
riscv-64 = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
inkwell = { workspace = true }
|
inkwell = { workspace = true }
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
|
|||||||
@@ -8,14 +8,7 @@ SECTIONS {
|
|||||||
.text : { KEEP(*(.text.polkavm_export)) *(.text .text.*) }
|
.text : { KEEP(*(.text.polkavm_export)) *(.text .text.*) }
|
||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv32.a";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
const BUILTINS_LIB_NAME: &str = "clang_rt.builtins-riscv32";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
const BUILTINS_LIB_NAME: &str = "clang_rt.builtins-riscv64";
|
const BUILTINS_LIB_NAME: &str = "clang_rt.builtins-riscv64";
|
||||||
|
|
||||||
fn invoke_lld(cmd_args: &[&str]) -> bool {
|
fn invoke_lld(cmd_args: &[&str]) -> bool {
|
||||||
@@ -29,9 +22,10 @@ fn invoke_lld(cmd_args: &[&str]) -> bool {
|
|||||||
unsafe { LLDELFLink(args.as_ptr(), args.len()) == 0 }
|
unsafe { LLDELFLink(args.as_ptr(), args.len()) == 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn polkavm_linker<T: AsRef<[u8]>>(code: T) -> anyhow::Result<Vec<u8>> {
|
pub fn polkavm_linker<T: AsRef<[u8]>>(code: T, strip_binary: bool) -> anyhow::Result<Vec<u8>> {
|
||||||
let mut config = polkavm_linker::Config::default();
|
let mut config = polkavm_linker::Config::default();
|
||||||
config.set_strip(true);
|
config.set_strip(strip_binary);
|
||||||
|
config.set_optimize(true);
|
||||||
|
|
||||||
polkavm_linker::program_from_elf(config, code.as_ref())
|
polkavm_linker::program_from_elf(config, code.as_ref())
|
||||||
.map_err(|reason| anyhow::anyhow!("polkavm linker failed: {}", reason))
|
.map_err(|reason| anyhow::anyhow!("polkavm linker failed: {}", reason))
|
||||||
@@ -78,10 +72,5 @@ pub fn link<T: AsRef<[u8]>>(input: T) -> anyhow::Result<Vec<u8>> {
|
|||||||
return Err(anyhow::anyhow!("ld.lld failed"));
|
return Err(anyhow::anyhow!("ld.lld failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if env::var("PVM_LINKER_DUMP_SO").is_ok() {
|
Ok(fs::read(&output_path)?)
|
||||||
fs::copy(&output_path, "/tmp/out.so")?;
|
|
||||||
};
|
|
||||||
|
|
||||||
let blob = fs::read(&output_path)?;
|
|
||||||
polkavm_linker(blob)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+76
-8
@@ -1,5 +1,19 @@
|
|||||||
fn llvm_config(arg: &str) -> String {
|
use std::{
|
||||||
let output = std::process::Command::new("llvm-config")
|
env,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
|
const LLVM_LINK_PREFIX: &str = "LLVM_LINK_PREFIX";
|
||||||
|
|
||||||
|
fn locate_llvm_config() -> PathBuf {
|
||||||
|
let prefix = env::var_os(LLVM_LINK_PREFIX)
|
||||||
|
.map(|p| PathBuf::from(p).join("bin"))
|
||||||
|
.unwrap_or_default();
|
||||||
|
prefix.join("llvm-config")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn llvm_config(llvm_config_path: &Path, arg: &str) -> String {
|
||||||
|
let output = std::process::Command::new(llvm_config_path)
|
||||||
.args([arg])
|
.args([arg])
|
||||||
.output()
|
.output()
|
||||||
.unwrap_or_else(|_| panic!("`llvm-config {arg}` failed"));
|
.unwrap_or_else(|_| panic!("`llvm-config {arg}` failed"));
|
||||||
@@ -8,8 +22,11 @@ fn llvm_config(arg: &str) -> String {
|
|||||||
.unwrap_or_else(|_| panic!("output of `llvm-config {arg}` should be utf8"))
|
.unwrap_or_else(|_| panic!("output of `llvm-config {arg}` should be utf8"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_rustc_link_flags() {
|
fn set_rustc_link_flags(llvm_config_path: &Path) {
|
||||||
println!("cargo:rustc-link-search=native={}", llvm_config("--libdir"));
|
println!(
|
||||||
|
"cargo:rustc-link-search=native={}",
|
||||||
|
llvm_config(llvm_config_path, "--libdir")
|
||||||
|
);
|
||||||
|
|
||||||
for lib in [
|
for lib in [
|
||||||
"lldELF",
|
"lldELF",
|
||||||
@@ -22,19 +39,70 @@ fn set_rustc_link_flags() {
|
|||||||
"LLVMTargetParser",
|
"LLVMTargetParser",
|
||||||
"LLVMBinaryFormat",
|
"LLVMBinaryFormat",
|
||||||
"LLVMDemangle",
|
"LLVMDemangle",
|
||||||
|
// The `llvm-sys` crate relies on `llvm-config` to obtain a list of required LLVM libraries
|
||||||
|
// during the build process. This works well in typical native environments, where `llvm-config`
|
||||||
|
// can accurately list the necessary libraries.
|
||||||
|
// However, when cross-compiling to WebAssembly using Emscripten, `llvm-config` fails to recognize
|
||||||
|
// JavaScript-based libraries, making it necessary to manually inject the required dependencies.
|
||||||
|
"LLVMRISCVDisassembler",
|
||||||
|
"LLVMRISCVAsmParser",
|
||||||
|
"LLVMRISCVCodeGen",
|
||||||
|
"LLVMRISCVDesc",
|
||||||
|
"LLVMRISCVInfo",
|
||||||
|
"LLVMExecutionEngine",
|
||||||
|
"LLVMOption",
|
||||||
|
"LLVMMCDisassembler",
|
||||||
|
"LLVMPasses",
|
||||||
|
"LLVMHipStdPar",
|
||||||
|
"LLVMCFGuard",
|
||||||
|
"LLVMCoroutines",
|
||||||
|
"LLVMipo",
|
||||||
|
"LLVMVectorize",
|
||||||
|
"LLVMInstrumentation",
|
||||||
|
"LLVMFrontendOpenMP",
|
||||||
|
"LLVMFrontendOffloading",
|
||||||
|
"LLVMGlobalISel",
|
||||||
|
"LLVMAsmPrinter",
|
||||||
|
"LLVMSelectionDAG",
|
||||||
|
"LLVMCodeGen",
|
||||||
|
"LLVMTarget",
|
||||||
|
"LLVMObjCARCOpts",
|
||||||
|
"LLVMCodeGenTypes",
|
||||||
|
"LLVMIRPrinter",
|
||||||
|
"LLVMScalarOpts",
|
||||||
|
"LLVMInstCombine",
|
||||||
|
"LLVMAggressiveInstCombine",
|
||||||
|
"LLVMTransformUtils",
|
||||||
|
"LLVMBitWriter",
|
||||||
|
"LLVMAnalysis",
|
||||||
|
"LLVMProfileData",
|
||||||
|
"LLVMDebugInfoDWARF",
|
||||||
|
"LLVMObject",
|
||||||
|
"LLVMMCParser",
|
||||||
|
"LLVMIRReader",
|
||||||
|
"LLVMAsmParser",
|
||||||
|
"LLVMMC",
|
||||||
|
"LLVMDebugInfoCodeView",
|
||||||
|
"LLVMBitReader",
|
||||||
|
"LLVMRemarks",
|
||||||
|
"LLVMBitstreamReader",
|
||||||
] {
|
] {
|
||||||
println!("cargo:rustc-link-lib=static={lib}");
|
println!("cargo:rustc-link-lib=static={lib}");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
|
||||||
{
|
if target_os == "linux" {
|
||||||
println!("cargo:rustc-link-lib=dylib=stdc++");
|
println!("cargo:rustc-link-lib=dylib=stdc++");
|
||||||
println!("cargo:rustc-link-lib=tinfo");
|
println!("cargo:rustc-link-lib=tinfo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
llvm_config("--cxxflags")
|
println!("cargo:rerun-if-env-changed={}", LLVM_LINK_PREFIX);
|
||||||
|
|
||||||
|
let llvm_config_path = locate_llvm_config();
|
||||||
|
|
||||||
|
llvm_config(&llvm_config_path, "--cxxflags")
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
.fold(&mut cc::Build::new(), |builder, flag| builder.flag(flag))
|
.fold(&mut cc::Build::new(), |builder, flag| builder.flag(flag))
|
||||||
.flag("-Wno-unused-parameter")
|
.flag("-Wno-unused-parameter")
|
||||||
@@ -42,7 +110,7 @@ fn main() {
|
|||||||
.file("src/linker.cpp")
|
.file("src/linker.cpp")
|
||||||
.compile("liblinker.a");
|
.compile("liblinker.a");
|
||||||
|
|
||||||
set_rustc_link_flags();
|
set_rustc_link_flags(&llvm_config_path);
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ description = "Shared front end code of the revive PolkaVM compilers"
|
|||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[features]
|
|
||||||
riscv-zbb = []
|
|
||||||
riscv-64 = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
semver = { workspace = true }
|
semver = { workspace = true }
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ pub enum IRType {
|
|||||||
LLVM,
|
LLVM,
|
||||||
/// Whether to dump the assembly code.
|
/// Whether to dump the assembly code.
|
||||||
Assembly,
|
Assembly,
|
||||||
|
/// Whether to dump the ELF shared object
|
||||||
|
SO,
|
||||||
/// Whether to jump JSON
|
/// Whether to jump JSON
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
JSON,
|
JSON,
|
||||||
@@ -31,6 +33,7 @@ impl IRType {
|
|||||||
Self::Assembly => revive_common::EXTENSION_POLKAVM_ASSEMBLY,
|
Self::Assembly => revive_common::EXTENSION_POLKAVM_ASSEMBLY,
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
Self::JSON => revive_common::EXTENSION_JSON,
|
Self::JSON => revive_common::EXTENSION_JSON,
|
||||||
|
Self::SO => revive_common::EXTENSION_SHARED_OBJECT,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,41 +13,52 @@ use self::ir_type::IRType;
|
|||||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||||
pub struct DebugConfig {
|
pub struct DebugConfig {
|
||||||
/// The directory to dump the IRs to.
|
/// The directory to dump the IRs to.
|
||||||
pub output_directory: PathBuf,
|
pub output_directory: Option<PathBuf>,
|
||||||
|
/// Whether debug info should be emitted.
|
||||||
|
pub emit_debug_info: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DebugConfig {
|
impl DebugConfig {
|
||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
pub fn new(output_directory: PathBuf) -> Self {
|
pub const fn new(output_directory: Option<PathBuf>, emit_debug_info: bool) -> Self {
|
||||||
Self { output_directory }
|
Self {
|
||||||
|
output_directory,
|
||||||
|
emit_debug_info,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dumps the Yul IR.
|
/// Dumps the Yul IR.
|
||||||
pub fn dump_yul(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
pub fn dump_yul(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
||||||
let mut file_path = self.output_directory.to_owned();
|
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::Yul);
|
let mut file_path = output_directory.to_owned();
|
||||||
file_path.push(full_file_name);
|
let full_file_name = Self::full_file_name(contract_path, None, IRType::Yul);
|
||||||
std::fs::write(file_path, code)?;
|
file_path.push(full_file_name);
|
||||||
|
std::fs::write(file_path, code)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dumps the EVM legacy assembly IR.
|
/// Dumps the EVM legacy assembly IR.
|
||||||
pub fn dump_evmla(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
pub fn dump_evmla(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
||||||
let mut file_path = self.output_directory.to_owned();
|
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::EVMLA);
|
let mut file_path = output_directory.to_owned();
|
||||||
file_path.push(full_file_name);
|
let full_file_name = Self::full_file_name(contract_path, None, IRType::EVMLA);
|
||||||
std::fs::write(file_path, code)?;
|
file_path.push(full_file_name);
|
||||||
|
std::fs::write(file_path, code)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dumps the Ethereal IR.
|
/// Dumps the Ethereal IR.
|
||||||
pub fn dump_ethir(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
pub fn dump_ethir(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
||||||
let mut file_path = self.output_directory.to_owned();
|
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::EthIR);
|
let mut file_path = output_directory.to_owned();
|
||||||
file_path.push(full_file_name);
|
let full_file_name = Self::full_file_name(contract_path, None, IRType::EthIR);
|
||||||
std::fs::write(file_path, code)?;
|
file_path.push(full_file_name);
|
||||||
|
std::fs::write(file_path, code)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -58,12 +69,15 @@ impl DebugConfig {
|
|||||||
contract_path: &str,
|
contract_path: &str,
|
||||||
module: &inkwell::module::Module,
|
module: &inkwell::module::Module,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let llvm_code = module.print_to_string().to_string();
|
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||||
|
let llvm_code = module.print_to_string().to_string();
|
||||||
|
|
||||||
let mut file_path = self.output_directory.to_owned();
|
let mut file_path = output_directory.to_owned();
|
||||||
let full_file_name = Self::full_file_name(contract_path, Some("unoptimized"), IRType::LLVM);
|
let full_file_name =
|
||||||
file_path.push(full_file_name);
|
Self::full_file_name(contract_path, Some("unoptimized"), IRType::LLVM);
|
||||||
std::fs::write(file_path, llvm_code)?;
|
file_path.push(full_file_name);
|
||||||
|
std::fs::write(file_path, llvm_code)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -74,22 +88,39 @@ impl DebugConfig {
|
|||||||
contract_path: &str,
|
contract_path: &str,
|
||||||
module: &inkwell::module::Module,
|
module: &inkwell::module::Module,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let llvm_code = module.print_to_string().to_string();
|
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||||
|
let llvm_code = module.print_to_string().to_string();
|
||||||
|
|
||||||
let mut file_path = self.output_directory.to_owned();
|
let mut file_path = output_directory.to_owned();
|
||||||
let full_file_name = Self::full_file_name(contract_path, Some("optimized"), IRType::LLVM);
|
let full_file_name =
|
||||||
file_path.push(full_file_name);
|
Self::full_file_name(contract_path, Some("optimized"), IRType::LLVM);
|
||||||
std::fs::write(file_path, llvm_code)?;
|
file_path.push(full_file_name);
|
||||||
|
std::fs::write(file_path, llvm_code)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dumps the assembly.
|
/// Dumps the assembly.
|
||||||
pub fn dump_assembly(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
pub fn dump_assembly(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
||||||
let mut file_path = self.output_directory.to_owned();
|
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::Assembly);
|
let mut file_path = output_directory.to_owned();
|
||||||
file_path.push(full_file_name);
|
let full_file_name = Self::full_file_name(contract_path, None, IRType::Assembly);
|
||||||
std::fs::write(file_path, code)?;
|
file_path.push(full_file_name);
|
||||||
|
std::fs::write(file_path, code)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Dumps the code object.
|
||||||
|
pub fn dump_object(&self, contract_path: &str, code: &[u8]) -> anyhow::Result<()> {
|
||||||
|
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||||
|
let mut file_path = output_directory.to_owned();
|
||||||
|
let full_file_name = Self::full_file_name(contract_path, None, IRType::SO);
|
||||||
|
file_path.push(full_file_name);
|
||||||
|
std::fs::write(file_path, code)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -102,10 +133,12 @@ impl DebugConfig {
|
|||||||
contract_suffix: Option<&str>,
|
contract_suffix: Option<&str>,
|
||||||
stage_json: &Vec<u8>,
|
stage_json: &Vec<u8>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let mut file_path = self.output_directory.to_owned();
|
if let Some(output_directory) = self.output_directory.as_ref() {
|
||||||
let full_file_name = Self::full_file_name(contract_path, contract_suffix, IRType::JSON);
|
let mut file_path = output_directory.to_owned();
|
||||||
file_path.push(full_file_name);
|
let full_file_name = Self::full_file_name(contract_path, contract_suffix, IRType::JSON);
|
||||||
std::fs::write(file_path, stage_json)?;
|
file_path.push(full_file_name);
|
||||||
|
std::fs::write(file_path, stage_json)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub use self::polkavm::context::argument::Argument as PolkaVMArgument;
|
|||||||
pub use self::polkavm::context::attribute::Attribute as PolkaVMAttribute;
|
pub use self::polkavm::context::attribute::Attribute as PolkaVMAttribute;
|
||||||
pub use self::polkavm::context::build::Build as PolkaVMBuild;
|
pub use self::polkavm::context::build::Build as PolkaVMBuild;
|
||||||
pub use self::polkavm::context::code_type::CodeType as PolkaVMCodeType;
|
pub use self::polkavm::context::code_type::CodeType as PolkaVMCodeType;
|
||||||
|
pub use self::polkavm::context::debug_info::DebugInfo;
|
||||||
pub use self::polkavm::context::evmla_data::EVMLAData as PolkaVMContextEVMLAData;
|
pub use self::polkavm::context::evmla_data::EVMLAData as PolkaVMContextEVMLAData;
|
||||||
pub use self::polkavm::context::function::block::evmla_data::key::Key as PolkaVMFunctionBlockKey;
|
pub use self::polkavm::context::function::block::evmla_data::key::Key as PolkaVMFunctionBlockKey;
|
||||||
pub use self::polkavm::context::function::block::evmla_data::EVMLAData as PolkaVMFunctionBlockEVMLAData;
|
pub use self::polkavm::context::function::block::evmla_data::EVMLAData as PolkaVMFunctionBlockEVMLAData;
|
||||||
@@ -27,9 +28,11 @@ pub use self::polkavm::context::function::llvm_runtime::LLVMRuntime as PolkaVMLL
|
|||||||
pub use self::polkavm::context::function::r#return::Return as PolkaVMFunctionReturn;
|
pub use self::polkavm::context::function::r#return::Return as PolkaVMFunctionReturn;
|
||||||
pub use self::polkavm::context::function::runtime::deploy_code::DeployCode as PolkaVMDeployCodeFunction;
|
pub use self::polkavm::context::function::runtime::deploy_code::DeployCode as PolkaVMDeployCodeFunction;
|
||||||
pub use self::polkavm::context::function::runtime::entry::Entry as PolkaVMEntryFunction;
|
pub use self::polkavm::context::function::runtime::entry::Entry as PolkaVMEntryFunction;
|
||||||
|
pub use self::polkavm::context::function::runtime::immutable_data_load::ImmutableDataLoad as PolkaVMImmutableDataLoadFunction;
|
||||||
pub use self::polkavm::context::function::runtime::runtime_code::RuntimeCode as PolkaVMRuntimeCodeFunction;
|
pub use self::polkavm::context::function::runtime::runtime_code::RuntimeCode as PolkaVMRuntimeCodeFunction;
|
||||||
pub use self::polkavm::context::function::runtime::FUNCTION_DEPLOY_CODE as PolkaVMFunctionDeployCode;
|
pub use self::polkavm::context::function::runtime::FUNCTION_DEPLOY_CODE as PolkaVMFunctionDeployCode;
|
||||||
pub use self::polkavm::context::function::runtime::FUNCTION_ENTRY as PolkaVMFunctionEntry;
|
pub use self::polkavm::context::function::runtime::FUNCTION_ENTRY as PolkaVMFunctionEntry;
|
||||||
|
pub use self::polkavm::context::function::runtime::FUNCTION_LOAD_IMMUTABLE_DATA as PolkaVMFunctionImmutableDataLoad;
|
||||||
pub use self::polkavm::context::function::runtime::FUNCTION_RUNTIME_CODE as PolkaVMFunctionRuntimeCode;
|
pub use self::polkavm::context::function::runtime::FUNCTION_RUNTIME_CODE as PolkaVMFunctionRuntimeCode;
|
||||||
pub use self::polkavm::context::function::yul_data::YulData as PolkaVMFunctionYulData;
|
pub use self::polkavm::context::function::yul_data::YulData as PolkaVMFunctionYulData;
|
||||||
pub use self::polkavm::context::function::Function as PolkaVMFunction;
|
pub use self::polkavm::context::function::Function as PolkaVMFunction;
|
||||||
@@ -58,7 +61,6 @@ 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::evm::storage as polkavm_evm_storage;
|
||||||
pub use self::polkavm::metadata_hash::MetadataHash as PolkaVMMetadataHash;
|
pub use self::polkavm::metadata_hash::MetadataHash as PolkaVMMetadataHash;
|
||||||
pub use self::polkavm::r#const as polkavm_const;
|
pub use self::polkavm::r#const as polkavm_const;
|
||||||
pub use self::polkavm::utils as polkavm_utils;
|
|
||||||
pub use self::polkavm::Dependency as PolkaVMDependency;
|
pub use self::polkavm::Dependency as PolkaVMDependency;
|
||||||
pub use self::polkavm::DummyDependency as PolkaVMDummyDependency;
|
pub use self::polkavm::DummyDependency as PolkaVMDummyDependency;
|
||||||
pub use self::polkavm::DummyLLVMWritable as PolkaVMDummyLLVMWritable;
|
pub use self::polkavm::DummyLLVMWritable as PolkaVMDummyLLVMWritable;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use itertools::Itertools;
|
|||||||
|
|
||||||
use self::size_level::SizeLevel;
|
use self::size_level::SizeLevel;
|
||||||
|
|
||||||
/// The LLVM optimizer settings.
|
/// The LLVM optimizer and code-gen settings.
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Eq)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Eq)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
/// The middle-end optimization level.
|
/// The middle-end optimization level.
|
||||||
@@ -21,8 +21,6 @@ pub struct Settings {
|
|||||||
|
|
||||||
/// Fallback to optimizing for size if the bytecode is too large.
|
/// Fallback to optimizing for size if the bytecode is too large.
|
||||||
pub is_fallback_to_size_enabled: bool,
|
pub is_fallback_to_size_enabled: bool,
|
||||||
/// Whether the system request memoization is disabled.
|
|
||||||
pub is_system_request_memoization_disabled: bool,
|
|
||||||
|
|
||||||
/// Whether the LLVM `verify each` option is enabled.
|
/// Whether the LLVM `verify each` option is enabled.
|
||||||
pub is_verify_each_enabled: bool,
|
pub is_verify_each_enabled: bool,
|
||||||
@@ -43,7 +41,6 @@ impl Settings {
|
|||||||
level_back_end,
|
level_back_end,
|
||||||
|
|
||||||
is_fallback_to_size_enabled: false,
|
is_fallback_to_size_enabled: false,
|
||||||
is_system_request_memoization_disabled: false,
|
|
||||||
|
|
||||||
is_verify_each_enabled: false,
|
is_verify_each_enabled: false,
|
||||||
is_debug_logging_enabled: false,
|
is_debug_logging_enabled: false,
|
||||||
@@ -65,7 +62,6 @@ impl Settings {
|
|||||||
level_back_end,
|
level_back_end,
|
||||||
|
|
||||||
is_fallback_to_size_enabled: false,
|
is_fallback_to_size_enabled: false,
|
||||||
is_system_request_memoization_disabled: false,
|
|
||||||
|
|
||||||
is_verify_each_enabled,
|
is_verify_each_enabled,
|
||||||
is_debug_logging_enabled,
|
is_debug_logging_enabled,
|
||||||
@@ -206,20 +202,10 @@ impl Settings {
|
|||||||
self.is_fallback_to_size_enabled = true;
|
self.is_fallback_to_size_enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disables the system request memoization.
|
|
||||||
pub fn disable_system_request_memoization(&mut self) {
|
|
||||||
self.is_system_request_memoization_disabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the fallback to optimizing for size is enabled.
|
/// Whether the fallback to optimizing for size is enabled.
|
||||||
pub fn is_fallback_to_size_enabled(&self) -> bool {
|
pub fn is_fallback_to_size_enabled(&self) -> bool {
|
||||||
self.is_fallback_to_size_enabled
|
self.is_fallback_to_size_enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the system request memoization is disabled.
|
|
||||||
pub fn is_system_request_memoization_disabled(&self) -> bool {
|
|
||||||
self.is_system_request_memoization_disabled
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for Settings {
|
impl PartialEq for Settings {
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
//! The LLVM context constants.
|
//! The LLVM context constants.
|
||||||
|
|
||||||
/// Runtime API methods.
|
|
||||||
pub mod runtime_api;
|
|
||||||
|
|
||||||
/// The LLVM framework version.
|
/// The LLVM framework version.
|
||||||
pub const LLVM_VERSION: semver::Version = semver::Version::new(18, 1, 4);
|
pub const LLVM_VERSION: semver::Version = semver::Version::new(18, 1, 4);
|
||||||
|
|
||||||
/// The PolkaVM version.
|
/// The pointer width sized type.
|
||||||
pub const ZKEVM_VERSION: semver::Version = semver::Version::new(1, 3, 2);
|
|
||||||
|
|
||||||
/// The register width sized type
|
|
||||||
pub static XLEN: usize = revive_common::BIT_LENGTH_X32;
|
pub static XLEN: usize = revive_common::BIT_LENGTH_X32;
|
||||||
|
|
||||||
/// The heap memory pointer pointer global variable name.
|
/// The heap memory pointer pointer global variable name.
|
||||||
@@ -21,49 +15,9 @@ pub static GLOBAL_CALLDATA_POINTER: &str = "ptr_calldata";
|
|||||||
/// The calldata size global variable name.
|
/// The calldata size global variable name.
|
||||||
pub static GLOBAL_CALLDATA_SIZE: &str = "calldatasize";
|
pub static GLOBAL_CALLDATA_SIZE: &str = "calldatasize";
|
||||||
|
|
||||||
/// The return data pointer global variable name.
|
|
||||||
pub static GLOBAL_RETURN_DATA_POINTER: &str = "ptr_return_data";
|
|
||||||
|
|
||||||
/// The return data size pointer global variable name.
|
|
||||||
pub static GLOBAL_RETURN_DATA_SIZE: &str = "returndatasize";
|
|
||||||
|
|
||||||
/// The call flags global variable name.
|
/// The call flags global variable name.
|
||||||
pub static GLOBAL_CALL_FLAGS: &str = "call_flags";
|
pub static GLOBAL_CALL_FLAGS: &str = "call_flags";
|
||||||
|
|
||||||
/// The constant array global variable name prefix.
|
|
||||||
pub static GLOBAL_CONST_ARRAY_PREFIX: &str = "const_array_";
|
|
||||||
|
|
||||||
/// The global verbatim getter identifier prefix.
|
|
||||||
pub static GLOBAL_VERBATIM_GETTER_PREFIX: &str = "get_global::";
|
|
||||||
|
|
||||||
/// The static word size.
|
|
||||||
pub static GLOBAL_I256_SIZE: &str = "i256_size";
|
|
||||||
|
|
||||||
/// The static value size.
|
|
||||||
pub static GLOBAL_I160_SIZE: &str = "i160_size";
|
|
||||||
|
|
||||||
/// The static i64 size.
|
|
||||||
pub static GLOBAL_I64_SIZE: &str = "i64_size";
|
|
||||||
|
|
||||||
/// The external call data offset in the auxiliary heap.
|
|
||||||
pub const HEAP_AUX_OFFSET_EXTERNAL_CALL: u64 = 0;
|
|
||||||
|
|
||||||
/// The constructor return data offset in the auxiliary heap.
|
|
||||||
pub const HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA: u64 =
|
|
||||||
8 * (revive_common::BYTE_LENGTH_WORD as u64);
|
|
||||||
|
|
||||||
/// The `create` method deployer signature.
|
|
||||||
pub static DEPLOYER_SIGNATURE_CREATE: &str = "create(bytes32,bytes32,bytes)";
|
|
||||||
|
|
||||||
/// The `create2` method deployer signature.
|
|
||||||
pub static DEPLOYER_SIGNATURE_CREATE2: &str = "create2(bytes32,bytes32,bytes)";
|
|
||||||
|
|
||||||
/// The absence of system call bit.
|
|
||||||
pub const NO_SYSTEM_CALL_BIT: bool = false;
|
|
||||||
|
|
||||||
/// The system call bit.
|
|
||||||
pub const SYSTEM_CALL_BIT: bool = true;
|
|
||||||
|
|
||||||
/// The deployer call header size that consists of:
|
/// The deployer call header size that consists of:
|
||||||
/// - bytecode hash (32 bytes)
|
/// - bytecode hash (32 bytes)
|
||||||
pub const DEPLOYER_CALL_HEADER_SIZE: usize = revive_common::BYTE_LENGTH_WORD;
|
pub const DEPLOYER_CALL_HEADER_SIZE: usize = revive_common::BYTE_LENGTH_WORD;
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
//! Runtime API import and export symbols.
|
|
||||||
|
|
||||||
pub mod exports {
|
|
||||||
/// The contract deploy export.
|
|
||||||
pub static CALL: &str = "call";
|
|
||||||
|
|
||||||
/// The contract call export.
|
|
||||||
pub static DEPLOY: &str = "deploy";
|
|
||||||
|
|
||||||
/// All exported symbols.
|
|
||||||
/// Useful for configuring common attributes and linkage.
|
|
||||||
pub static EXPORTS: [&str; 2] = [CALL, DEPLOY];
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod imports {
|
|
||||||
pub static ADDRESS: &str = "address";
|
|
||||||
|
|
||||||
pub static BALANCE: &str = "balance";
|
|
||||||
|
|
||||||
pub static BLOCK_NUMBER: &str = "block_number";
|
|
||||||
|
|
||||||
pub static CALL: &str = "call";
|
|
||||||
|
|
||||||
pub static CALLER: &str = "caller";
|
|
||||||
|
|
||||||
pub static CODE_SIZE: &str = "code_size";
|
|
||||||
|
|
||||||
pub static DEPOSIT_EVENT: &str = "deposit_event";
|
|
||||||
|
|
||||||
pub static GET_STORAGE: &str = "get_storage";
|
|
||||||
|
|
||||||
pub static HASH_KECCAK_256: &str = "hash_keccak_256";
|
|
||||||
|
|
||||||
pub static INPUT: &str = "input";
|
|
||||||
|
|
||||||
pub static INSTANTIATE: &str = "instantiate";
|
|
||||||
|
|
||||||
pub static NOW: &str = "now";
|
|
||||||
|
|
||||||
pub static RETURN: &str = "seal_return";
|
|
||||||
|
|
||||||
pub static RETURNDATACOPY: &str = "returndatacopy";
|
|
||||||
|
|
||||||
pub static SET_STORAGE: &str = "set_storage";
|
|
||||||
|
|
||||||
pub static VALUE_TRANSFERRED: &str = "value_transferred";
|
|
||||||
|
|
||||||
/// All imported runtime API symbols.
|
|
||||||
/// Useful for configuring common attributes and linkage.
|
|
||||||
pub static IMPORTS: [&str; 16] = [
|
|
||||||
ADDRESS,
|
|
||||||
BALANCE,
|
|
||||||
BLOCK_NUMBER,
|
|
||||||
CALL,
|
|
||||||
CALLER,
|
|
||||||
CODE_SIZE,
|
|
||||||
DEPOSIT_EVENT,
|
|
||||||
GET_STORAGE,
|
|
||||||
HASH_KECCAK_256,
|
|
||||||
INPUT,
|
|
||||||
INSTANTIATE,
|
|
||||||
NOW,
|
|
||||||
RETURN,
|
|
||||||
RETURNDATACOPY,
|
|
||||||
SET_STORAGE,
|
|
||||||
VALUE_TRANSFERRED,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// PolkaVM __sbrk API symbol to extend the heap memory.
|
|
||||||
pub static SBRK: &str = "__sbrk";
|
|
||||||
@@ -1,7 +1,43 @@
|
|||||||
//! The LLVM debug information.
|
//! The LLVM debug information.
|
||||||
|
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use inkwell::debug_info::AsDIScope;
|
use inkwell::debug_info::AsDIScope;
|
||||||
use num::Zero;
|
use inkwell::debug_info::DIScope;
|
||||||
|
|
||||||
|
/// Debug info scope stack
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
pub struct ScopeStack<'ctx> {
|
||||||
|
stack: Vec<DIScope<'ctx>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Abstract the type of the DIScope stack.
|
||||||
|
impl<'ctx> ScopeStack<'ctx> {
|
||||||
|
pub fn from(item: DIScope<'ctx>) -> Self {
|
||||||
|
Self { stack: vec![item] }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the top of the scope stack, or None if the stack is empty.
|
||||||
|
pub fn top(&self) -> Option<DIScope<'ctx>> {
|
||||||
|
self.stack.last().copied()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Push a scope onto the stack.
|
||||||
|
pub fn push(&mut self, scope: DIScope<'ctx>) {
|
||||||
|
self.stack.push(scope)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pop the scope at the top of the stack and return it.
|
||||||
|
/// Return None if the stack is empty.
|
||||||
|
pub fn pop(&mut self) -> Option<DIScope<'ctx>> {
|
||||||
|
self.stack.pop()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the number of scopes on the stack.
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.stack.len()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The LLVM debug information.
|
/// The LLVM debug information.
|
||||||
pub struct DebugInfo<'ctx> {
|
pub struct DebugInfo<'ctx> {
|
||||||
@@ -9,6 +45,8 @@ pub struct DebugInfo<'ctx> {
|
|||||||
compile_unit: inkwell::debug_info::DICompileUnit<'ctx>,
|
compile_unit: inkwell::debug_info::DICompileUnit<'ctx>,
|
||||||
/// The debug info builder.
|
/// The debug info builder.
|
||||||
builder: inkwell::debug_info::DebugInfoBuilder<'ctx>,
|
builder: inkwell::debug_info::DebugInfoBuilder<'ctx>,
|
||||||
|
/// Enclosing debug info scopes.
|
||||||
|
scope_stack: RefCell<ScopeStack<'ctx>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ctx> DebugInfo<'ctx> {
|
impl<'ctx> DebugInfo<'ctx> {
|
||||||
@@ -35,19 +73,43 @@ impl<'ctx> DebugInfo<'ctx> {
|
|||||||
Self {
|
Self {
|
||||||
compile_unit,
|
compile_unit,
|
||||||
builder,
|
builder,
|
||||||
|
scope_stack: RefCell::new(ScopeStack::from(compile_unit.as_debug_info_scope())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Prepare an LLVM-IR module for debug-info generation
|
||||||
|
pub fn initialize_module(
|
||||||
|
&self,
|
||||||
|
llvm: &'ctx inkwell::context::Context,
|
||||||
|
module: &inkwell::module::Module<'ctx>,
|
||||||
|
) {
|
||||||
|
let debug_metadata_value = llvm
|
||||||
|
.i32_type()
|
||||||
|
.const_int(inkwell::debug_info::debug_metadata_version() as u64, false);
|
||||||
|
module.add_basic_value_flag(
|
||||||
|
"Debug Info Version",
|
||||||
|
inkwell::module::FlagBehavior::Warning,
|
||||||
|
debug_metadata_value,
|
||||||
|
);
|
||||||
|
self.push_scope(self.compilation_unit().get_file().as_debug_info_scope());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Finalize debug-info for an LLVM-IR module.
|
||||||
|
pub fn finalize_module(&self) {
|
||||||
|
self.builder().finalize()
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a function info.
|
/// Creates a function info.
|
||||||
pub fn create_function(
|
pub fn create_function(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
) -> anyhow::Result<inkwell::debug_info::DISubprogram<'ctx>> {
|
) -> anyhow::Result<inkwell::debug_info::DISubprogram<'ctx>> {
|
||||||
|
let flags = inkwell::debug_info::DIFlagsConstants::ZERO;
|
||||||
let subroutine_type = self.builder.create_subroutine_type(
|
let subroutine_type = self.builder.create_subroutine_type(
|
||||||
self.compile_unit.get_file(),
|
self.compile_unit.get_file(),
|
||||||
Some(self.create_type(revive_common::BIT_LENGTH_FIELD)?),
|
Some(self.create_word_type(Some(flags))?.as_type()),
|
||||||
&[],
|
&[],
|
||||||
inkwell::debug_info::DIFlags::zero(),
|
flags,
|
||||||
);
|
);
|
||||||
|
|
||||||
let function = self.builder.create_function(
|
let function = self.builder.create_function(
|
||||||
@@ -60,7 +122,7 @@ impl<'ctx> DebugInfo<'ctx> {
|
|||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
1,
|
1,
|
||||||
inkwell::debug_info::DIFlags::zero(),
|
flags,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -74,24 +136,55 @@ impl<'ctx> DebugInfo<'ctx> {
|
|||||||
Ok(function)
|
Ok(function)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a primitive type info.
|
/// Creates primitive integer type debug-info.
|
||||||
pub fn create_type(
|
pub fn create_primitive_type(
|
||||||
&self,
|
&self,
|
||||||
bit_length: usize,
|
bit_length: usize,
|
||||||
) -> anyhow::Result<inkwell::debug_info::DIType<'ctx>> {
|
flags: Option<inkwell::debug_info::DIFlags>,
|
||||||
|
) -> anyhow::Result<inkwell::debug_info::DIBasicType<'ctx>> {
|
||||||
|
let di_flags = flags.unwrap_or(inkwell::debug_info::DIFlagsConstants::ZERO);
|
||||||
|
let di_encoding: u32 = 0;
|
||||||
|
let type_name = String::from("U") + bit_length.to_string().as_str();
|
||||||
self.builder
|
self.builder
|
||||||
.create_basic_type(
|
.create_basic_type(type_name.as_str(), bit_length as u64, di_encoding, di_flags)
|
||||||
"U256",
|
|
||||||
bit_length as u64,
|
|
||||||
0,
|
|
||||||
inkwell::debug_info::DIFlags::zero(),
|
|
||||||
)
|
|
||||||
.map(|basic_type| basic_type.as_type())
|
|
||||||
.map_err(|error| anyhow::anyhow!("Debug info error: {}", error))
|
.map_err(|error| anyhow::anyhow!("Debug info error: {}", error))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finalizes the builder.
|
/// Returns the debug-info model of word-sized integer types.
|
||||||
pub fn finalize(&self) {
|
pub fn create_word_type(
|
||||||
self.builder.finalize();
|
&self,
|
||||||
|
flags: Option<inkwell::debug_info::DIFlags>,
|
||||||
|
) -> anyhow::Result<inkwell::debug_info::DIBasicType<'ctx>> {
|
||||||
|
self.create_primitive_type(revive_common::BIT_LENGTH_WORD, flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the DIBuilder.
|
||||||
|
pub fn builder(&self) -> &inkwell::debug_info::DebugInfoBuilder<'ctx> {
|
||||||
|
&self.builder
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the compilation unit. {
|
||||||
|
pub fn compilation_unit(&self) -> &inkwell::debug_info::DICompileUnit<'ctx> {
|
||||||
|
&self.compile_unit
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Push a debug-info scope onto the stack.
|
||||||
|
pub fn push_scope(&self, scope: DIScope<'ctx>) {
|
||||||
|
self.scope_stack.borrow_mut().push(scope)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pop the top of the debug-info scope stack and return it.
|
||||||
|
pub fn pop_scope(&self) -> Option<DIScope<'ctx>> {
|
||||||
|
self.scope_stack.borrow_mut().pop()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the top of the debug-info scope stack.
|
||||||
|
pub fn top_scope(&self) -> Option<DIScope<'ctx>> {
|
||||||
|
self.scope_stack.borrow().top()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the number of debug-info scopes on the scope stack.
|
||||||
|
pub fn num_scopes(&self) -> usize {
|
||||||
|
self.scope_stack.borrow().len()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,8 @@ impl<'ctx> Declaration<'ctx> {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
Self { r#type, value }
|
Self { r#type, value }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn function_value(&self) -> inkwell::values::FunctionValue<'ctx> {
|
||||||
|
self.value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,15 +11,6 @@ use crate::polkavm::context::function::Function;
|
|||||||
/// The functions are automatically linked to the LLVM implementations if the signatures match.
|
/// The functions are automatically linked to the LLVM implementations if the signatures match.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct LLVMRuntime<'ctx> {
|
pub struct LLVMRuntime<'ctx> {
|
||||||
/// The corresponding LLVM runtime function.
|
|
||||||
pub shl: FunctionDeclaration<'ctx>,
|
|
||||||
/// The corresponding LLVM runtime function.
|
|
||||||
pub shr: FunctionDeclaration<'ctx>,
|
|
||||||
/// The corresponding LLVM runtime function.
|
|
||||||
pub sar: FunctionDeclaration<'ctx>,
|
|
||||||
/// The corresponding LLVM runtime function.
|
|
||||||
pub byte: FunctionDeclaration<'ctx>,
|
|
||||||
|
|
||||||
/// The corresponding LLVM runtime function.
|
/// The corresponding LLVM runtime function.
|
||||||
pub add_mod: FunctionDeclaration<'ctx>,
|
pub add_mod: FunctionDeclaration<'ctx>,
|
||||||
/// The corresponding LLVM runtime function.
|
/// The corresponding LLVM runtime function.
|
||||||
@@ -31,32 +22,9 @@ pub struct LLVMRuntime<'ctx> {
|
|||||||
|
|
||||||
/// The corresponding LLVM runtime function.
|
/// The corresponding LLVM runtime function.
|
||||||
pub sha3: FunctionDeclaration<'ctx>,
|
pub sha3: FunctionDeclaration<'ctx>,
|
||||||
|
|
||||||
/// The corresponding LLVM runtime function.
|
|
||||||
pub r#return: FunctionDeclaration<'ctx>,
|
|
||||||
/// The corresponding LLVM runtime function.
|
|
||||||
pub revert: FunctionDeclaration<'ctx>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ctx> LLVMRuntime<'ctx> {
|
impl<'ctx> LLVMRuntime<'ctx> {
|
||||||
/// The LLVM personality function name.
|
|
||||||
pub const FUNCTION_PERSONALITY: &'static str = "__personality";
|
|
||||||
|
|
||||||
/// The LLVM exception throwing function name.
|
|
||||||
pub const FUNCTION_CXA_THROW: &'static str = "__cxa_throw";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_SHL: &'static str = "__shl";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_SHR: &'static str = "__shr";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_SAR: &'static str = "__sar";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_BYTE: &'static str = "__byte";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
/// The corresponding runtime function name.
|
||||||
pub const FUNCTION_ADDMOD: &'static str = "__addmod";
|
pub const FUNCTION_ADDMOD: &'static str = "__addmod";
|
||||||
|
|
||||||
@@ -72,121 +40,12 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
/// The corresponding runtime function name.
|
/// The corresponding runtime function name.
|
||||||
pub const FUNCTION_SHA3: &'static str = "__sha3";
|
pub const FUNCTION_SHA3: &'static str = "__sha3";
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_SYSTEM_REQUEST: &'static str = "__system_request";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_FARCALL: &'static str = "__farcall";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_STATICCALL: &'static str = "__staticcall";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_DELEGATECALL: &'static str = "__delegatecall";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_MIMICCALL: &'static str = "__mimiccall";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_FARCALL_BYREF: &'static str = "__farcall_byref";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_STATICCALL_BYREF: &'static str = "__staticcall_byref";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_DELEGATECALL_BYREF: &'static str = "__delegatecall_byref";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_MIMICCALL_BYREF: &'static str = "__mimiccall_byref";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_RETURN: &'static str = "__return";
|
|
||||||
|
|
||||||
/// The corresponding runtime function name.
|
|
||||||
pub const FUNCTION_REVERT: &'static str = "__revert";
|
|
||||||
|
|
||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
llvm: &'ctx inkwell::context::Context,
|
llvm: &'ctx inkwell::context::Context,
|
||||||
module: &inkwell::module::Module<'ctx>,
|
module: &inkwell::module::Module<'ctx>,
|
||||||
optimizer: &Optimizer,
|
optimizer: &Optimizer,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let shl = Self::declare(
|
|
||||||
module,
|
|
||||||
Self::FUNCTION_SHL,
|
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
|
||||||
.fn_type(
|
|
||||||
vec![
|
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
|
||||||
.as_basic_type_enum()
|
|
||||||
.into();
|
|
||||||
2
|
|
||||||
]
|
|
||||||
.as_slice(),
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
Some(inkwell::module::Linkage::External),
|
|
||||||
);
|
|
||||||
Function::set_default_attributes(llvm, shl, optimizer);
|
|
||||||
Function::set_pure_function_attributes(llvm, shl);
|
|
||||||
|
|
||||||
let shr = Self::declare(
|
|
||||||
module,
|
|
||||||
Self::FUNCTION_SHR,
|
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
|
||||||
.fn_type(
|
|
||||||
vec![
|
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
|
||||||
.as_basic_type_enum()
|
|
||||||
.into();
|
|
||||||
2
|
|
||||||
]
|
|
||||||
.as_slice(),
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
Some(inkwell::module::Linkage::External),
|
|
||||||
);
|
|
||||||
Function::set_default_attributes(llvm, shr, optimizer);
|
|
||||||
Function::set_pure_function_attributes(llvm, shr);
|
|
||||||
|
|
||||||
let sar = Self::declare(
|
|
||||||
module,
|
|
||||||
Self::FUNCTION_SAR,
|
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
|
||||||
.fn_type(
|
|
||||||
vec![
|
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
|
||||||
.as_basic_type_enum()
|
|
||||||
.into();
|
|
||||||
2
|
|
||||||
]
|
|
||||||
.as_slice(),
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
Some(inkwell::module::Linkage::External),
|
|
||||||
);
|
|
||||||
Function::set_default_attributes(llvm, sar, optimizer);
|
|
||||||
Function::set_pure_function_attributes(llvm, sar);
|
|
||||||
|
|
||||||
let byte = Self::declare(
|
|
||||||
module,
|
|
||||||
Self::FUNCTION_BYTE,
|
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
|
||||||
.fn_type(
|
|
||||||
vec![
|
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
|
||||||
.as_basic_type_enum()
|
|
||||||
.into();
|
|
||||||
2
|
|
||||||
]
|
|
||||||
.as_slice(),
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
Some(inkwell::module::Linkage::External),
|
|
||||||
);
|
|
||||||
Function::set_default_attributes(llvm, byte, optimizer);
|
|
||||||
Function::set_pure_function_attributes(llvm, byte);
|
|
||||||
|
|
||||||
let add_mod =
|
let add_mod =
|
||||||
Self::define(module, Self::FUNCTION_ADDMOD).expect("should be declared in stdlib");
|
Self::define(module, Self::FUNCTION_ADDMOD).expect("should be declared in stdlib");
|
||||||
Function::set_default_attributes(llvm, add_mod, optimizer);
|
Function::set_default_attributes(llvm, add_mod, optimizer);
|
||||||
@@ -236,54 +95,13 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
let r#return = Self::declare(
|
|
||||||
module,
|
|
||||||
Self::FUNCTION_RETURN,
|
|
||||||
llvm.void_type().fn_type(
|
|
||||||
vec![
|
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
|
||||||
.as_basic_type_enum()
|
|
||||||
.into();
|
|
||||||
3
|
|
||||||
]
|
|
||||||
.as_slice(),
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
Some(inkwell::module::Linkage::External),
|
|
||||||
);
|
|
||||||
Function::set_default_attributes(llvm, r#return, optimizer);
|
|
||||||
let revert = Self::declare(
|
|
||||||
module,
|
|
||||||
Self::FUNCTION_REVERT,
|
|
||||||
llvm.void_type().fn_type(
|
|
||||||
vec![
|
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
|
||||||
.as_basic_type_enum()
|
|
||||||
.into();
|
|
||||||
3
|
|
||||||
]
|
|
||||||
.as_slice(),
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
Some(inkwell::module::Linkage::External),
|
|
||||||
);
|
|
||||||
Function::set_default_attributes(llvm, revert, optimizer);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
shl,
|
|
||||||
shr,
|
|
||||||
sar,
|
|
||||||
byte,
|
|
||||||
|
|
||||||
add_mod,
|
add_mod,
|
||||||
mul_mod,
|
mul_mod,
|
||||||
exp,
|
exp,
|
||||||
sign_extend,
|
sign_extend,
|
||||||
|
|
||||||
sha3,
|
sha3,
|
||||||
|
|
||||||
r#return,
|
|
||||||
revert,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ pub mod yul_data;
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use inkwell::debug_info::AsDIScope;
|
||||||
|
|
||||||
use crate::optimizer::settings::size_level::SizeLevel;
|
use crate::optimizer::settings::size_level::SizeLevel;
|
||||||
use crate::optimizer::Optimizer;
|
use crate::optimizer::Optimizer;
|
||||||
use crate::polkavm::context::attribute::Attribute;
|
use crate::polkavm::context::attribute::Attribute;
|
||||||
@@ -48,12 +50,6 @@ pub struct Function<'ctx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'ctx> Function<'ctx> {
|
impl<'ctx> Function<'ctx> {
|
||||||
/// The near call ABI function prefix.
|
|
||||||
pub const ZKSYNC_NEAR_CALL_ABI_PREFIX: &'static str = "ZKSYNC_NEAR_CALL";
|
|
||||||
|
|
||||||
/// The near call ABI exception handler name.
|
|
||||||
pub const ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER: &'static str = "ZKSYNC_CATCH_NEAR_CALL";
|
|
||||||
|
|
||||||
/// The stack hashmap default capacity.
|
/// The stack hashmap default capacity.
|
||||||
const STACK_HASHMAP_INITIAL_CAPACITY: usize = 64;
|
const STACK_HASHMAP_INITIAL_CAPACITY: usize = 64;
|
||||||
|
|
||||||
@@ -91,13 +87,8 @@ impl<'ctx> Function<'ctx> {
|
|||||||
|| (name.starts_with("__")
|
|| (name.starts_with("__")
|
||||||
&& name != self::runtime::FUNCTION_ENTRY
|
&& name != self::runtime::FUNCTION_ENTRY
|
||||||
&& name != self::runtime::FUNCTION_DEPLOY_CODE
|
&& name != self::runtime::FUNCTION_DEPLOY_CODE
|
||||||
&& name != self::runtime::FUNCTION_RUNTIME_CODE)
|
&& name != self::runtime::FUNCTION_RUNTIME_CODE
|
||||||
}
|
&& name != self::runtime::FUNCTION_LOAD_IMMUTABLE_DATA)
|
||||||
|
|
||||||
/// Checks whether the function is related to the near call ABI.
|
|
||||||
pub fn is_near_call_abi(name: &str) -> bool {
|
|
||||||
name.starts_with(Self::ZKSYNC_NEAR_CALL_ABI_PREFIX)
|
|
||||||
|| name == Self::ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the LLVM function declaration.
|
/// Returns the LLVM function declaration.
|
||||||
@@ -105,6 +96,14 @@ impl<'ctx> Function<'ctx> {
|
|||||||
self.declaration
|
self.declaration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the debug-info scope.
|
||||||
|
pub fn get_debug_scope(&self) -> Option<inkwell::debug_info::DIScope<'ctx>> {
|
||||||
|
self.declaration()
|
||||||
|
.function_value()
|
||||||
|
.get_subprogram()
|
||||||
|
.map(|scp| scp.as_debug_info_scope())
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the N-th parameter of the function.
|
/// Returns the N-th parameter of the function.
|
||||||
pub fn get_nth_param(&self, index: usize) -> inkwell::values::BasicValueEnum<'ctx> {
|
pub fn get_nth_param(&self, index: usize) -> inkwell::values::BasicValueEnum<'ctx> {
|
||||||
self.declaration()
|
self.declaration()
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ where
|
|||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
let function_type =
|
let function_type = context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0);
|
||||||
context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0, false);
|
|
||||||
context.add_function(
|
context.add_function(
|
||||||
runtime::FUNCTION_DEPLOY_CODE,
|
runtime::FUNCTION_DEPLOY_CODE,
|
||||||
function_type,
|
function_type,
|
||||||
@@ -55,12 +54,14 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
context.set_current_function(runtime::FUNCTION_DEPLOY_CODE)?;
|
context.set_current_function(runtime::FUNCTION_DEPLOY_CODE, None)?;
|
||||||
|
|
||||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||||
context.set_code_type(CodeType::Deploy);
|
context.set_code_type(CodeType::Deploy);
|
||||||
|
|
||||||
self.inner.into_llvm(context)?;
|
self.inner.into_llvm(context)?;
|
||||||
|
context.set_debug_location(0, 0, None)?;
|
||||||
|
|
||||||
match context
|
match context
|
||||||
.basic_block()
|
.basic_block()
|
||||||
.get_last_instruction()
|
.get_last_instruction()
|
||||||
@@ -73,8 +74,11 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.set_basic_block(context.current_function().borrow().return_block());
|
context.set_basic_block(context.current_function().borrow().return_block());
|
||||||
|
context.set_debug_location(0, 0, None)?;
|
||||||
context.build_return(None);
|
context.build_return(None);
|
||||||
|
|
||||||
|
context.pop_debug_scope();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
//! The entry function.
|
//! The entry function.
|
||||||
|
|
||||||
use inkwell::types::BasicType;
|
use inkwell::types::BasicType;
|
||||||
use inkwell::values::BasicValue;
|
|
||||||
|
|
||||||
use crate::polkavm::context::address_space::AddressSpace;
|
use crate::polkavm::context::address_space::AddressSpace;
|
||||||
use crate::polkavm::context::function::runtime;
|
use crate::polkavm::context::function::runtime;
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::r#const::*;
|
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
use crate::polkavm::WriteLLVM;
|
use crate::polkavm::WriteLLVM;
|
||||||
|
|
||||||
@@ -20,14 +18,8 @@ impl Entry {
|
|||||||
/// The call flags argument index.
|
/// The call flags argument index.
|
||||||
pub const ARGUMENT_INDEX_CALL_FLAGS: usize = 0;
|
pub const ARGUMENT_INDEX_CALL_FLAGS: usize = 0;
|
||||||
|
|
||||||
/// The number of mandatory arguments.
|
/// Reserve 1kb for calldata.
|
||||||
pub const MANDATORY_ARGUMENTS_COUNT: usize = 2;
|
pub const MAX_CALLDATA_SIZE: usize = 1024;
|
||||||
|
|
||||||
/// Reserve 1mb for calldata.
|
|
||||||
pub const MAX_CALLDATA_SIZE: usize = 1024 * 1024;
|
|
||||||
|
|
||||||
/// Reserve 1mb for returndata.
|
|
||||||
pub const MAX_RETURNDATA_SIZE: usize = 1024 * 1024;
|
|
||||||
|
|
||||||
/// Initializes the global variables.
|
/// Initializes the global variables.
|
||||||
/// The pointers are not initialized, because it's not possible to create a null pointer.
|
/// The pointers are not initialized, because it's not possible to create a null pointer.
|
||||||
@@ -43,14 +35,6 @@ impl Entry {
|
|||||||
calldata_type.get_undef(),
|
calldata_type.get_undef(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let returndata_type = context.array_type(context.byte_type(), Self::MAX_RETURNDATA_SIZE);
|
|
||||||
context.set_global(
|
|
||||||
crate::polkavm::GLOBAL_RETURN_DATA_POINTER,
|
|
||||||
returndata_type,
|
|
||||||
AddressSpace::Stack,
|
|
||||||
returndata_type.get_undef(),
|
|
||||||
);
|
|
||||||
|
|
||||||
context.set_global(
|
context.set_global(
|
||||||
crate::polkavm::GLOBAL_HEAP_MEMORY_POINTER,
|
crate::polkavm::GLOBAL_HEAP_MEMORY_POINTER,
|
||||||
context.llvm().ptr_type(AddressSpace::Heap.into()),
|
context.llvm().ptr_type(AddressSpace::Heap.into()),
|
||||||
@@ -61,7 +45,10 @@ impl Entry {
|
|||||||
context
|
context
|
||||||
.get_global(crate::polkavm::GLOBAL_HEAP_MEMORY_POINTER)?
|
.get_global(crate::polkavm::GLOBAL_HEAP_MEMORY_POINTER)?
|
||||||
.into(),
|
.into(),
|
||||||
context.build_sbrk(context.integer_const(crate::polkavm::XLEN, 0))?,
|
context.build_sbrk(
|
||||||
|
context.xlen_type().const_zero(),
|
||||||
|
context.xlen_type().const_zero(),
|
||||||
|
)?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
context.set_global(
|
context.set_global(
|
||||||
@@ -70,12 +57,6 @@ impl Entry {
|
|||||||
AddressSpace::Stack,
|
AddressSpace::Stack,
|
||||||
context.word_undef(),
|
context.word_undef(),
|
||||||
);
|
);
|
||||||
context.set_global(
|
|
||||||
crate::polkavm::GLOBAL_RETURN_DATA_SIZE,
|
|
||||||
context.xlen_type(),
|
|
||||||
AddressSpace::Stack,
|
|
||||||
context.xlen_type().const_zero().as_basic_value_enum(),
|
|
||||||
);
|
|
||||||
|
|
||||||
context.set_global(
|
context.set_global(
|
||||||
crate::polkavm::GLOBAL_CALL_FLAGS,
|
crate::polkavm::GLOBAL_CALL_FLAGS,
|
||||||
@@ -84,33 +65,6 @@ impl Entry {
|
|||||||
context.word_const(0),
|
context.word_const(0),
|
||||||
);
|
);
|
||||||
|
|
||||||
context.set_global(
|
|
||||||
crate::polkavm::GLOBAL_I256_SIZE,
|
|
||||||
context.xlen_type(),
|
|
||||||
AddressSpace::Stack,
|
|
||||||
context.integer_const(
|
|
||||||
crate::polkavm::XLEN,
|
|
||||||
revive_common::BYTE_LENGTH_X64 as u64 * 4,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
context.set_global(
|
|
||||||
crate::polkavm::GLOBAL_I160_SIZE,
|
|
||||||
context.xlen_type(),
|
|
||||||
AddressSpace::Stack,
|
|
||||||
context.integer_const(
|
|
||||||
crate::polkavm::XLEN,
|
|
||||||
revive_common::BYTE_LENGTH_X64 as u64 * 2 + revive_common::BYTE_LENGTH_X32 as u64,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
context.set_global(
|
|
||||||
crate::polkavm::GLOBAL_I64_SIZE,
|
|
||||||
context.xlen_type(),
|
|
||||||
AddressSpace::Stack,
|
|
||||||
context.integer_const(crate::polkavm::XLEN, revive_common::BYTE_LENGTH_X64 as u64),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +84,7 @@ impl Entry {
|
|||||||
"input_pointer_casted",
|
"input_pointer_casted",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let length_pointer = context.build_alloca(context.xlen_type(), "len_ptr");
|
let length_pointer = context.build_alloca_at_entry(context.xlen_type(), "len_ptr");
|
||||||
let length_pointer_casted = context.builder.build_ptr_to_int(
|
let length_pointer_casted = context.builder.build_ptr_to_int(
|
||||||
length_pointer.value,
|
length_pointer.value,
|
||||||
context.xlen_type(),
|
context.xlen_type(),
|
||||||
@@ -142,7 +96,7 @@ impl Entry {
|
|||||||
context.integer_const(crate::polkavm::XLEN, Self::MAX_CALLDATA_SIZE as u64),
|
context.integer_const(crate::polkavm::XLEN, Self::MAX_CALLDATA_SIZE as u64),
|
||||||
)?;
|
)?;
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(
|
||||||
runtime_api::imports::INPUT,
|
revive_runtime_api::polkavm_imports::INPUT,
|
||||||
&[input_pointer_casted.into(), length_pointer_casted.into()],
|
&[input_pointer_casted.into(), length_pointer_casted.into()],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -171,6 +125,8 @@ impl Entry {
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
|
context.set_debug_location(0, 0, None)?;
|
||||||
|
|
||||||
let is_deploy = context
|
let is_deploy = context
|
||||||
.current_function()
|
.current_function()
|
||||||
.borrow()
|
.borrow()
|
||||||
@@ -221,7 +177,7 @@ where
|
|||||||
{
|
{
|
||||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
let entry_arguments = vec![context.bool_type().as_basic_type_enum()];
|
let entry_arguments = vec![context.bool_type().as_basic_type_enum()];
|
||||||
let entry_function_type = context.function_type(entry_arguments, 0, false);
|
let entry_function_type = context.function_type(entry_arguments, 0);
|
||||||
context.add_function(
|
context.add_function(
|
||||||
runtime::FUNCTION_ENTRY,
|
runtime::FUNCTION_ENTRY,
|
||||||
entry_function_type,
|
entry_function_type,
|
||||||
@@ -229,6 +185,18 @@ where
|
|||||||
Some(inkwell::module::Linkage::External),
|
Some(inkwell::module::Linkage::External),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
context.declare_global(
|
||||||
|
revive_runtime_api::immutable_data::GLOBAL_IMMUTABLE_DATA_POINTER,
|
||||||
|
context.word_type().array_type(0),
|
||||||
|
AddressSpace::Stack,
|
||||||
|
);
|
||||||
|
|
||||||
|
context.declare_global(
|
||||||
|
revive_runtime_api::immutable_data::GLOBAL_IMMUTABLE_DATA_SIZE,
|
||||||
|
context.xlen_type(),
|
||||||
|
AddressSpace::Stack,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +216,7 @@ where
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
context.set_current_function(runtime::FUNCTION_ENTRY)?;
|
context.set_current_function(runtime::FUNCTION_ENTRY, None)?;
|
||||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||||
|
|
||||||
Self::initialize_globals(context)?;
|
Self::initialize_globals(context)?;
|
||||||
@@ -259,6 +227,8 @@ where
|
|||||||
context.set_basic_block(context.current_function().borrow().return_block());
|
context.set_basic_block(context.current_function().borrow().return_block());
|
||||||
context.build_unreachable();
|
context.build_unreachable();
|
||||||
|
|
||||||
|
context.pop_debug_scope();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
//! The immutable data runtime function.
|
||||||
|
|
||||||
|
use crate::polkavm::context::address_space::AddressSpace;
|
||||||
|
use crate::polkavm::context::function::runtime;
|
||||||
|
use crate::polkavm::context::pointer::Pointer;
|
||||||
|
use crate::polkavm::context::Context;
|
||||||
|
use crate::polkavm::Dependency;
|
||||||
|
use crate::polkavm::WriteLLVM;
|
||||||
|
|
||||||
|
/// A function for requesting the immutable data from the runtime.
|
||||||
|
/// This is a special function that is only used by the front-end generated code.
|
||||||
|
///
|
||||||
|
/// The runtime API is called lazily and subsequent calls are no-ops.
|
||||||
|
///
|
||||||
|
/// The bytes written is asserted to match the expected length.
|
||||||
|
/// This should never fail; the length is known.
|
||||||
|
/// However, this is a one time assertion, hence worth it.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ImmutableDataLoad;
|
||||||
|
|
||||||
|
impl<D> WriteLLVM<D> for ImmutableDataLoad
|
||||||
|
where
|
||||||
|
D: Dependency + Clone,
|
||||||
|
{
|
||||||
|
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
|
context.add_function(
|
||||||
|
runtime::FUNCTION_LOAD_IMMUTABLE_DATA,
|
||||||
|
context.void_type().fn_type(Default::default(), false),
|
||||||
|
0,
|
||||||
|
Some(inkwell::module::Linkage::Private),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
|
context.set_current_function(runtime::FUNCTION_LOAD_IMMUTABLE_DATA, None)?;
|
||||||
|
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||||
|
|
||||||
|
let immutable_data_size_pointer = context
|
||||||
|
.get_global(revive_runtime_api::immutable_data::GLOBAL_IMMUTABLE_DATA_SIZE)?
|
||||||
|
.value
|
||||||
|
.as_pointer_value();
|
||||||
|
let immutable_data_size = context.build_load(
|
||||||
|
Pointer::new(
|
||||||
|
context.xlen_type(),
|
||||||
|
AddressSpace::Stack,
|
||||||
|
immutable_data_size_pointer,
|
||||||
|
),
|
||||||
|
"immutable_data_size_load",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let load_immutable_data_block = context.append_basic_block("load_immutables_block");
|
||||||
|
let return_block = context.current_function().borrow().return_block();
|
||||||
|
let immutable_data_size_is_zero = context.builder().build_int_compare(
|
||||||
|
inkwell::IntPredicate::EQ,
|
||||||
|
context.xlen_type().const_zero(),
|
||||||
|
immutable_data_size.into_int_value(),
|
||||||
|
"immutable_data_size_is_zero",
|
||||||
|
)?;
|
||||||
|
context.build_conditional_branch(
|
||||||
|
immutable_data_size_is_zero,
|
||||||
|
return_block,
|
||||||
|
load_immutable_data_block,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
context.set_basic_block(load_immutable_data_block);
|
||||||
|
let output_pointer = context
|
||||||
|
.get_global(revive_runtime_api::immutable_data::GLOBAL_IMMUTABLE_DATA_POINTER)?
|
||||||
|
.value
|
||||||
|
.as_pointer_value();
|
||||||
|
context.build_runtime_call(
|
||||||
|
revive_runtime_api::polkavm_imports::GET_IMMUTABLE_DATA,
|
||||||
|
&[
|
||||||
|
context
|
||||||
|
.builder()
|
||||||
|
.build_ptr_to_int(output_pointer, context.xlen_type(), "ptr_to_xlen")?
|
||||||
|
.into(),
|
||||||
|
context
|
||||||
|
.builder()
|
||||||
|
.build_ptr_to_int(
|
||||||
|
immutable_data_size_pointer,
|
||||||
|
context.xlen_type(),
|
||||||
|
"ptr_to_xlen",
|
||||||
|
)?
|
||||||
|
.into(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
let bytes_written = context.builder().build_load(
|
||||||
|
context.xlen_type(),
|
||||||
|
immutable_data_size_pointer,
|
||||||
|
"bytes_written",
|
||||||
|
)?;
|
||||||
|
context.builder().build_store(
|
||||||
|
immutable_data_size_pointer,
|
||||||
|
context.xlen_type().const_zero(),
|
||||||
|
)?;
|
||||||
|
let overflow_block = context.append_basic_block("immutable_data_overflow");
|
||||||
|
let is_overflow = context.builder().build_int_compare(
|
||||||
|
inkwell::IntPredicate::UGT,
|
||||||
|
immutable_data_size.into_int_value(),
|
||||||
|
bytes_written.into_int_value(),
|
||||||
|
"is_overflow",
|
||||||
|
)?;
|
||||||
|
context.build_conditional_branch(is_overflow, overflow_block, return_block)?;
|
||||||
|
|
||||||
|
context.set_basic_block(overflow_block);
|
||||||
|
context.build_call(context.intrinsics().trap, &[], "invalid_trap");
|
||||||
|
context.build_unreachable();
|
||||||
|
|
||||||
|
context.set_basic_block(return_block);
|
||||||
|
context.build_return(None);
|
||||||
|
|
||||||
|
context.pop_debug_scope();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
pub mod deploy_code;
|
pub mod deploy_code;
|
||||||
pub mod entry;
|
pub mod entry;
|
||||||
|
pub mod immutable_data_load;
|
||||||
pub mod runtime_code;
|
pub mod runtime_code;
|
||||||
|
|
||||||
/// The main entry function name.
|
/// The main entry function name.
|
||||||
@@ -12,3 +13,6 @@ pub const FUNCTION_DEPLOY_CODE: &str = "__deploy";
|
|||||||
|
|
||||||
/// The runtime code function name.
|
/// The runtime code function name.
|
||||||
pub const FUNCTION_RUNTIME_CODE: &str = "__runtime";
|
pub const FUNCTION_RUNTIME_CODE: &str = "__runtime";
|
||||||
|
|
||||||
|
/// The immutable data load function name.
|
||||||
|
pub const FUNCTION_LOAD_IMMUTABLE_DATA: &str = "__immutable_data_load";
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ where
|
|||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
let function_type =
|
let function_type = context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0);
|
||||||
context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0, false);
|
|
||||||
context.add_function(
|
context.add_function(
|
||||||
runtime::FUNCTION_RUNTIME_CODE,
|
runtime::FUNCTION_RUNTIME_CODE,
|
||||||
function_type,
|
function_type,
|
||||||
@@ -55,11 +54,14 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
context.set_current_function(runtime::FUNCTION_RUNTIME_CODE)?;
|
context.set_current_function(runtime::FUNCTION_RUNTIME_CODE, None)?;
|
||||||
|
|
||||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||||
context.set_code_type(CodeType::Runtime);
|
context.set_code_type(CodeType::Runtime);
|
||||||
|
|
||||||
self.inner.into_llvm(context)?;
|
self.inner.into_llvm(context)?;
|
||||||
|
context.set_debug_location(0, 0, None)?;
|
||||||
|
|
||||||
match context
|
match context
|
||||||
.basic_block()
|
.basic_block()
|
||||||
.get_last_instruction()
|
.get_last_instruction()
|
||||||
@@ -74,6 +76,8 @@ where
|
|||||||
context.set_basic_block(context.current_function().borrow().return_block());
|
context.set_basic_block(context.current_function().borrow().return_block());
|
||||||
context.build_unreachable();
|
context.build_unreachable();
|
||||||
|
|
||||||
|
context.pop_debug_scope();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,4 +51,31 @@ impl<'ctx> Global<'ctx> {
|
|||||||
|
|
||||||
global
|
global
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Construct an external global.
|
||||||
|
pub fn declare<D, T>(
|
||||||
|
context: &mut Context<'ctx, D>,
|
||||||
|
r#type: T,
|
||||||
|
address_space: AddressSpace,
|
||||||
|
name: &str,
|
||||||
|
) -> Self
|
||||||
|
where
|
||||||
|
D: PolkaVMDependency + Clone,
|
||||||
|
T: BasicType<'ctx>,
|
||||||
|
{
|
||||||
|
let r#type = r#type.as_basic_type_enum();
|
||||||
|
|
||||||
|
let value = context
|
||||||
|
.module()
|
||||||
|
.add_global(r#type, Some(address_space.into()), name);
|
||||||
|
let global = Self { r#type, value };
|
||||||
|
|
||||||
|
global.value.set_linkage(inkwell::module::Linkage::External);
|
||||||
|
global
|
||||||
|
.value
|
||||||
|
.set_visibility(inkwell::GlobalVisibility::Default);
|
||||||
|
global.value.set_externally_initialized(true);
|
||||||
|
|
||||||
|
global
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ pub mod argument;
|
|||||||
pub mod attribute;
|
pub mod attribute;
|
||||||
pub mod build;
|
pub mod build;
|
||||||
pub mod code_type;
|
pub mod code_type;
|
||||||
// pub mod debug_info;
|
pub mod debug_info;
|
||||||
pub mod evmla_data;
|
pub mod evmla_data;
|
||||||
pub mod function;
|
pub mod function;
|
||||||
pub mod global;
|
pub mod global;
|
||||||
@@ -21,12 +21,13 @@ use std::cell::RefCell;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use inkwell::debug_info::AsDIScope;
|
||||||
|
use inkwell::debug_info::DIScope;
|
||||||
use inkwell::types::BasicType;
|
use inkwell::types::BasicType;
|
||||||
use inkwell::values::BasicValue;
|
use inkwell::values::BasicValue;
|
||||||
|
|
||||||
use crate::optimizer::settings::Settings as OptimizerSettings;
|
use crate::optimizer::settings::Settings as OptimizerSettings;
|
||||||
use crate::optimizer::Optimizer;
|
use crate::optimizer::Optimizer;
|
||||||
use crate::polkavm::r#const::*;
|
|
||||||
use crate::polkavm::DebugConfig;
|
use crate::polkavm::DebugConfig;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
use crate::target_machine::target::Target;
|
use crate::target_machine::target::Target;
|
||||||
@@ -36,7 +37,7 @@ use self::address_space::AddressSpace;
|
|||||||
use self::attribute::Attribute;
|
use self::attribute::Attribute;
|
||||||
use self::build::Build;
|
use self::build::Build;
|
||||||
use self::code_type::CodeType;
|
use self::code_type::CodeType;
|
||||||
// use self::debug_info::DebugInfo;
|
use self::debug_info::DebugInfo;
|
||||||
use self::evmla_data::EVMLAData;
|
use self::evmla_data::EVMLAData;
|
||||||
use self::function::declaration::Declaration as FunctionDeclaration;
|
use self::function::declaration::Declaration as FunctionDeclaration;
|
||||||
use self::function::intrinsics::Intrinsics;
|
use self::function::intrinsics::Intrinsics;
|
||||||
@@ -86,9 +87,9 @@ where
|
|||||||
/// Whether to append the metadata hash at the end of bytecode.
|
/// Whether to append the metadata hash at the end of bytecode.
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
/// The debug info of the current module.
|
/// The debug info of the current module.
|
||||||
// debug_info: DebugInfo<'ctx>,
|
debug_info: Option<DebugInfo<'ctx>>,
|
||||||
/// The debug configuration telling whether to dump the needed IRs.
|
/// The debug configuration telling whether to dump the needed IRs.
|
||||||
debug_config: Option<DebugConfig>,
|
debug_config: DebugConfig,
|
||||||
|
|
||||||
/// The Solidity data.
|
/// The Solidity data.
|
||||||
solidity_data: Option<SolidityData>,
|
solidity_data: Option<SolidityData>,
|
||||||
@@ -136,10 +137,10 @@ where
|
|||||||
)
|
)
|
||||||
.expect("the PolkaVM imports module should be linkable");
|
.expect("the PolkaVM imports module should be linkable");
|
||||||
|
|
||||||
for import in runtime_api::imports::IMPORTS {
|
for import in revive_runtime_api::polkavm_imports::IMPORTS {
|
||||||
module
|
module
|
||||||
.get_function(import)
|
.get_function(import)
|
||||||
.expect("should be declared")
|
.unwrap_or_else(|| panic!("{import} import should be declared"))
|
||||||
.set_linkage(inkwell::module::Linkage::External);
|
.set_linkage(inkwell::module::Linkage::External);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,6 +163,19 @@ where
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn link_immutable_data(&self, contract_path: &str) -> anyhow::Result<()> {
|
||||||
|
let size = self.solidity().immutables_size() as u32;
|
||||||
|
let immutables = revive_runtime_api::immutable_data::module(self.llvm(), size);
|
||||||
|
|
||||||
|
self.module.link_in_module(immutables).map_err(|error| {
|
||||||
|
anyhow::anyhow!(
|
||||||
|
"The contract `{}` immutable data module linking error: {}",
|
||||||
|
contract_path,
|
||||||
|
error
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Configure the PolkaVM minimum stack size.
|
/// Configure the PolkaVM minimum stack size.
|
||||||
fn set_polkavm_stack_size(
|
fn set_polkavm_stack_size(
|
||||||
llvm: &'ctx inkwell::context::Context,
|
llvm: &'ctx inkwell::context::Context,
|
||||||
@@ -189,6 +203,16 @@ where
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configure the revive datalayout.
|
||||||
|
fn set_data_layout(
|
||||||
|
llvm: &'ctx inkwell::context::Context,
|
||||||
|
module: &inkwell::module::Module<'ctx>,
|
||||||
|
) {
|
||||||
|
let source_module = revive_stdlib::module(llvm, "revive_stdlib").unwrap();
|
||||||
|
let data_layout = source_module.get_data_layout();
|
||||||
|
module.set_data_layout(&data_layout);
|
||||||
|
}
|
||||||
|
|
||||||
/// Initializes a new LLVM context.
|
/// Initializes a new LLVM context.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
llvm: &'ctx inkwell::context::Context,
|
llvm: &'ctx inkwell::context::Context,
|
||||||
@@ -196,8 +220,9 @@ where
|
|||||||
optimizer: Optimizer,
|
optimizer: Optimizer,
|
||||||
dependency_manager: Option<D>,
|
dependency_manager: Option<D>,
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: Option<DebugConfig>,
|
debug_config: DebugConfig,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
Self::set_data_layout(llvm, &module);
|
||||||
Self::link_stdlib_module(llvm, &module);
|
Self::link_stdlib_module(llvm, &module);
|
||||||
Self::link_polkavm_imports(llvm, &module);
|
Self::link_polkavm_imports(llvm, &module);
|
||||||
Self::set_polkavm_stack_size(llvm, &module, Self::POLKAVM_STACK_SIZE);
|
Self::set_polkavm_stack_size(llvm, &module, Self::POLKAVM_STACK_SIZE);
|
||||||
@@ -205,6 +230,11 @@ where
|
|||||||
|
|
||||||
let intrinsics = Intrinsics::new(llvm, &module);
|
let intrinsics = Intrinsics::new(llvm, &module);
|
||||||
let llvm_runtime = LLVMRuntime::new(llvm, &module, &optimizer);
|
let llvm_runtime = LLVMRuntime::new(llvm, &module, &optimizer);
|
||||||
|
let debug_info = debug_config.emit_debug_info.then(|| {
|
||||||
|
let debug_info = DebugInfo::new(&module);
|
||||||
|
debug_info.initialize_module(llvm, &module);
|
||||||
|
debug_info
|
||||||
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
llvm,
|
llvm,
|
||||||
@@ -221,7 +251,8 @@ where
|
|||||||
|
|
||||||
dependency_manager,
|
dependency_manager,
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
// debug_info,
|
|
||||||
|
debug_info,
|
||||||
debug_config,
|
debug_config,
|
||||||
|
|
||||||
solidity_data: None,
|
solidity_data: None,
|
||||||
@@ -239,13 +270,14 @@ where
|
|||||||
let module_clone = self.module.clone();
|
let module_clone = self.module.clone();
|
||||||
|
|
||||||
self.link_polkavm_exports(contract_path)?;
|
self.link_polkavm_exports(contract_path)?;
|
||||||
|
self.link_immutable_data(contract_path)?;
|
||||||
|
|
||||||
let target_machine = TargetMachine::new(Target::PVM, self.optimizer.settings())?;
|
let target_machine = TargetMachine::new(Target::PVM, self.optimizer.settings())?;
|
||||||
target_machine.set_target_data(self.module());
|
self.module().set_triple(&target_machine.get_triple());
|
||||||
|
|
||||||
|
self.debug_config
|
||||||
|
.dump_llvm_ir_unoptimized(contract_path, self.module())?;
|
||||||
|
|
||||||
if let Some(ref debug_config) = self.debug_config {
|
|
||||||
debug_config.dump_llvm_ir_unoptimized(contract_path, self.module())?;
|
|
||||||
}
|
|
||||||
self.verify().map_err(|error| {
|
self.verify().map_err(|error| {
|
||||||
anyhow::anyhow!(
|
anyhow::anyhow!(
|
||||||
"The contract `{}` unoptimized LLVM IR verification error: {}",
|
"The contract `{}` unoptimized LLVM IR verification error: {}",
|
||||||
@@ -263,9 +295,10 @@ where
|
|||||||
error
|
error
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
if let Some(ref debug_config) = self.debug_config {
|
|
||||||
debug_config.dump_llvm_ir_optimized(contract_path, self.module())?;
|
self.debug_config
|
||||||
}
|
.dump_llvm_ir_optimized(contract_path, self.module())?;
|
||||||
|
|
||||||
self.verify().map_err(|error| {
|
self.verify().map_err(|error| {
|
||||||
anyhow::anyhow!(
|
anyhow::anyhow!(
|
||||||
"The contract `{}` optimized LLVM IR verification error: {}",
|
"The contract `{}` optimized LLVM IR verification error: {}",
|
||||||
@@ -284,11 +317,17 @@ where
|
|||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let bytecode = revive_linker::link(buffer.as_slice())?;
|
let shared_object = revive_linker::link(buffer.as_slice())?;
|
||||||
|
|
||||||
|
self.debug_config
|
||||||
|
.dump_object(contract_path, &shared_object)?;
|
||||||
|
|
||||||
|
let polkavm_bytecode =
|
||||||
|
revive_linker::polkavm_linker(shared_object, !self.debug_config().emit_debug_info)?;
|
||||||
|
|
||||||
let build = match crate::polkavm::build_assembly_text(
|
let build = match crate::polkavm::build_assembly_text(
|
||||||
contract_path,
|
contract_path,
|
||||||
&bytecode,
|
&polkavm_bytecode,
|
||||||
metadata_hash,
|
metadata_hash,
|
||||||
self.debug_config(),
|
self.debug_config(),
|
||||||
) {
|
) {
|
||||||
@@ -381,6 +420,15 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Declare an external global.
|
||||||
|
pub fn declare_global<T>(&mut self, name: &str, r#type: T, address_space: AddressSpace)
|
||||||
|
where
|
||||||
|
T: BasicType<'ctx> + Clone + Copy,
|
||||||
|
{
|
||||||
|
let global = Global::declare(self, r#type, address_space, name);
|
||||||
|
self.globals.insert(name.to_owned(), global);
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the LLVM intrinsics collection reference.
|
/// Returns the LLVM intrinsics collection reference.
|
||||||
pub fn intrinsics(&self) -> &Intrinsics<'ctx> {
|
pub fn intrinsics(&self) -> &Intrinsics<'ctx> {
|
||||||
&self.intrinsics
|
&self.intrinsics
|
||||||
@@ -391,49 +439,31 @@ where
|
|||||||
&self.llvm_runtime
|
&self.llvm_runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Declare a function already existing in the module.
|
|
||||||
pub fn declare_extern_function(
|
|
||||||
&mut self,
|
|
||||||
name: &str,
|
|
||||||
) -> anyhow::Result<Rc<RefCell<Function<'ctx>>>> {
|
|
||||||
let function = self.module().get_function(name).ok_or_else(|| {
|
|
||||||
anyhow::anyhow!("Failed to activate an undeclared function `{}`", name)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let basic_block = self.llvm.append_basic_block(function, name);
|
|
||||||
let declaration = FunctionDeclaration::new(
|
|
||||||
self.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0, false),
|
|
||||||
function,
|
|
||||||
);
|
|
||||||
let function = Function::new(
|
|
||||||
name.to_owned(),
|
|
||||||
declaration,
|
|
||||||
FunctionReturn::None,
|
|
||||||
basic_block,
|
|
||||||
basic_block,
|
|
||||||
);
|
|
||||||
Function::set_default_attributes(self.llvm, function.declaration(), &self.optimizer);
|
|
||||||
|
|
||||||
let function = Rc::new(RefCell::new(function));
|
|
||||||
self.functions.insert(name.to_string(), function.clone());
|
|
||||||
|
|
||||||
Ok(function)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Appends a function to the current module.
|
/// Appends a function to the current module.
|
||||||
pub fn add_function(
|
pub fn add_function(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: &str,
|
name: &str,
|
||||||
r#type: inkwell::types::FunctionType<'ctx>,
|
r#type: inkwell::types::FunctionType<'ctx>,
|
||||||
return_values_length: usize,
|
return_values_length: usize,
|
||||||
mut linkage: Option<inkwell::module::Linkage>,
|
linkage: Option<inkwell::module::Linkage>,
|
||||||
) -> anyhow::Result<Rc<RefCell<Function<'ctx>>>> {
|
) -> anyhow::Result<Rc<RefCell<Function<'ctx>>>> {
|
||||||
if Function::is_near_call_abi(name) && self.is_system_mode() {
|
|
||||||
linkage = Some(inkwell::module::Linkage::External);
|
|
||||||
}
|
|
||||||
|
|
||||||
let value = self.module().add_function(name, r#type, linkage);
|
let value = self.module().add_function(name, r#type, linkage);
|
||||||
|
|
||||||
|
if self.debug_info().is_some() {
|
||||||
|
self.builder().unset_current_debug_location();
|
||||||
|
let func_scope = match value.get_subprogram() {
|
||||||
|
None => {
|
||||||
|
let fn_name = value.get_name().to_str()?;
|
||||||
|
let scp = self.build_function_debug_info(fn_name, 0)?;
|
||||||
|
value.set_subprogram(scp);
|
||||||
|
scp
|
||||||
|
}
|
||||||
|
Some(scp) => scp,
|
||||||
|
};
|
||||||
|
self.push_debug_scope(func_scope.as_debug_info_scope());
|
||||||
|
self.set_debug_location(0, 0, Some(func_scope.as_debug_info_scope()))?;
|
||||||
|
}
|
||||||
|
|
||||||
let entry_block = self.llvm.append_basic_block(value, "entry");
|
let entry_block = self.llvm.append_basic_block(value, "entry");
|
||||||
let return_block = self.llvm.append_basic_block(value, "return");
|
let return_block = self.llvm.append_basic_block(value, "return");
|
||||||
|
|
||||||
@@ -444,12 +474,6 @@ where
|
|||||||
let pointer = self.build_alloca(self.word_type(), "return_pointer");
|
let pointer = self.build_alloca(self.word_type(), "return_pointer");
|
||||||
FunctionReturn::primitive(pointer)
|
FunctionReturn::primitive(pointer)
|
||||||
}
|
}
|
||||||
size if name.starts_with(Function::ZKSYNC_NEAR_CALL_ABI_PREFIX) => {
|
|
||||||
let first_argument = value.get_first_param().expect("Always exists");
|
|
||||||
let r#type = self.structure_type(vec![self.word_type(); size].as_slice());
|
|
||||||
let pointer = first_argument.into_pointer_value();
|
|
||||||
FunctionReturn::compound(Pointer::new(r#type, AddressSpace::Stack, pointer), size)
|
|
||||||
}
|
|
||||||
size => {
|
size => {
|
||||||
self.set_basic_block(entry_block);
|
self.set_basic_block(entry_block);
|
||||||
let pointer = self.build_alloca(
|
let pointer = self.build_alloca(
|
||||||
@@ -470,13 +494,11 @@ where
|
|||||||
return_block,
|
return_block,
|
||||||
);
|
);
|
||||||
Function::set_default_attributes(self.llvm, function.declaration(), &self.optimizer);
|
Function::set_default_attributes(self.llvm, function.declaration(), &self.optimizer);
|
||||||
if Function::is_near_call_abi(function.name()) && self.is_system_mode() {
|
|
||||||
Function::set_exception_handler_attributes(self.llvm, function.declaration());
|
|
||||||
}
|
|
||||||
|
|
||||||
let function = Rc::new(RefCell::new(function));
|
let function = Rc::new(RefCell::new(function));
|
||||||
self.functions.insert(name.to_string(), function.clone());
|
self.functions.insert(name.to_string(), function.clone());
|
||||||
|
|
||||||
|
self.pop_debug_scope();
|
||||||
|
|
||||||
Ok(function)
|
Ok(function)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,15 +514,95 @@ where
|
|||||||
.expect("Must be declared before use")
|
.expect("Must be declared before use")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the current active function.
|
/// Sets the current active function. If debug-info generation is enabled,
|
||||||
pub fn set_current_function(&mut self, name: &str) -> anyhow::Result<()> {
|
/// constructs a debug-scope and pushes in on the scope-stack.
|
||||||
|
pub fn set_current_function(&mut self, name: &str, line: Option<u32>) -> anyhow::Result<()> {
|
||||||
let function = self.functions.get(name).cloned().ok_or_else(|| {
|
let function = self.functions.get(name).cloned().ok_or_else(|| {
|
||||||
anyhow::anyhow!("Failed to activate an undeclared function `{}`", name)
|
anyhow::anyhow!("Failed to activate an undeclared function `{}`", name)
|
||||||
})?;
|
})?;
|
||||||
self.current_function = Some(function);
|
self.current_function = Some(function);
|
||||||
|
|
||||||
|
if let Some(scope) = self.current_function().borrow().get_debug_scope() {
|
||||||
|
self.push_debug_scope(scope);
|
||||||
|
}
|
||||||
|
self.set_debug_location(line.unwrap_or_default(), 0, None)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds a debug-info scope for a function.
|
||||||
|
pub fn build_function_debug_info(
|
||||||
|
&self,
|
||||||
|
name: &str,
|
||||||
|
line_no: u32,
|
||||||
|
) -> anyhow::Result<inkwell::debug_info::DISubprogram<'ctx>> {
|
||||||
|
let Some(debug_info) = self.debug_info() else {
|
||||||
|
anyhow::bail!("expected debug-info builders");
|
||||||
|
};
|
||||||
|
let builder = debug_info.builder();
|
||||||
|
let file = debug_info.compilation_unit().get_file();
|
||||||
|
let scope = file.as_debug_info_scope();
|
||||||
|
let flags = inkwell::debug_info::DIFlagsConstants::PUBLIC;
|
||||||
|
let return_type = debug_info.create_word_type(Some(flags))?.as_type();
|
||||||
|
let subroutine_type = builder.create_subroutine_type(file, Some(return_type), &[], flags);
|
||||||
|
|
||||||
|
Ok(builder.create_function(
|
||||||
|
scope,
|
||||||
|
name,
|
||||||
|
None,
|
||||||
|
file,
|
||||||
|
line_no,
|
||||||
|
subroutine_type,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
1,
|
||||||
|
flags,
|
||||||
|
false,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the debug info location.
|
||||||
|
///
|
||||||
|
/// No-op if the emitting debug info is disabled.
|
||||||
|
///
|
||||||
|
/// If `scope` is `None` the top scope will be used.
|
||||||
|
pub fn set_debug_location(
|
||||||
|
&self,
|
||||||
|
line: u32,
|
||||||
|
column: u32,
|
||||||
|
scope: Option<DIScope<'ctx>>,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
let Some(debug_info) = self.debug_info() else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
let scope = match scope {
|
||||||
|
Some(scp) => scp,
|
||||||
|
None => debug_info.top_scope().expect("expected a debug-info scope"),
|
||||||
|
};
|
||||||
|
let location =
|
||||||
|
debug_info
|
||||||
|
.builder()
|
||||||
|
.create_debug_location(self.llvm(), line, column, scope, None);
|
||||||
|
|
||||||
|
self.builder().set_current_debug_location(location);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pushes a debug-info scope to the stack.
|
||||||
|
pub fn push_debug_scope(&self, scope: DIScope<'ctx>) {
|
||||||
|
if let Some(debug_info) = self.debug_info() {
|
||||||
|
debug_info.push_scope(scope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pops the top of the debug-info scope stack.
|
||||||
|
pub fn pop_debug_scope(&self) {
|
||||||
|
if let Some(debug_info) = self.debug_info() {
|
||||||
|
debug_info.pop_scope();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Pushes a new loop context to the stack.
|
/// Pushes a new loop context to the stack.
|
||||||
pub fn push_loop(
|
pub fn push_loop(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -534,10 +636,6 @@ where
|
|||||||
manager,
|
manager,
|
||||||
name,
|
name,
|
||||||
self.optimizer.settings().to_owned(),
|
self.optimizer.settings().to_owned(),
|
||||||
self.yul_data
|
|
||||||
.as_ref()
|
|
||||||
.map(|data| data.is_system_mode())
|
|
||||||
.unwrap_or_default(),
|
|
||||||
self.include_metadata_hash,
|
self.include_metadata_hash,
|
||||||
self.debug_config.clone(),
|
self.debug_config.clone(),
|
||||||
)
|
)
|
||||||
@@ -574,9 +672,14 @@ where
|
|||||||
.expect("The dependency manager is unset")
|
.expect("The dependency manager is unset")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the debug info.
|
||||||
|
pub fn debug_info(&self) -> Option<&DebugInfo<'ctx>> {
|
||||||
|
self.debug_info.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the debug config reference.
|
/// Returns the debug config reference.
|
||||||
pub fn debug_config(&self) -> Option<&DebugConfig> {
|
pub fn debug_config(&self) -> &DebugConfig {
|
||||||
self.debug_config.as_ref()
|
&self.debug_config
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Appends a new basic block to the current function.
|
/// Appends a new basic block to the current function.
|
||||||
@@ -595,59 +698,70 @@ where
|
|||||||
self.builder.get_insert_block().expect("Always exists")
|
self.builder.get_insert_block().expect("Always exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a stack allocation instruction.
|
/// Builds an aligned stack allocation at the function entry.
|
||||||
/// Sets the alignment to 128 bits.
|
pub fn build_alloca_at_entry<T: BasicType<'ctx> + Clone + Copy>(
|
||||||
|
&self,
|
||||||
|
r#type: T,
|
||||||
|
name: &str,
|
||||||
|
) -> Pointer<'ctx> {
|
||||||
|
let current_block = self.basic_block();
|
||||||
|
let entry_block = self.current_function().borrow().entry_block();
|
||||||
|
|
||||||
|
match entry_block.get_first_instruction() {
|
||||||
|
Some(instruction) => self.builder().position_before(&instruction),
|
||||||
|
None => self.builder().position_at_end(entry_block),
|
||||||
|
}
|
||||||
|
|
||||||
|
let pointer = self.build_alloca(r#type, name);
|
||||||
|
self.set_basic_block(current_block);
|
||||||
|
pointer
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builds an aligned stack allocation at the current position.
|
||||||
|
/// Use this if [`build_alloca_at_entry`] might change program semantics.
|
||||||
|
/// Otherwise, alloca should always be built at the function prelude!
|
||||||
pub fn build_alloca<T: BasicType<'ctx> + Clone + Copy>(
|
pub fn build_alloca<T: BasicType<'ctx> + Clone + Copy>(
|
||||||
&self,
|
&self,
|
||||||
r#type: T,
|
r#type: T,
|
||||||
name: &str,
|
name: &str,
|
||||||
) -> Pointer<'ctx> {
|
) -> Pointer<'ctx> {
|
||||||
let pointer = self.builder.build_alloca(r#type, name).unwrap();
|
let pointer = self.builder.build_alloca(r#type, name).unwrap();
|
||||||
self.basic_block()
|
pointer
|
||||||
.get_last_instruction()
|
.as_instruction()
|
||||||
.expect("Always exists")
|
.unwrap()
|
||||||
.set_alignment(revive_common::BYTE_LENGTH_STACK_ALIGN as u32)
|
.set_alignment(revive_common::BYTE_LENGTH_STACK_ALIGN as u32)
|
||||||
.expect("Alignment is valid");
|
.expect("Alignment is valid");
|
||||||
|
|
||||||
Pointer::new(r#type, AddressSpace::Stack, pointer)
|
Pointer::new(r#type, AddressSpace::Stack, pointer)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allocate an int of size `bit_length` on the stack.
|
/// Truncate `address` to the ethereum address length and store it as bytes on the stack.
|
||||||
/// Returns the allocation pointer and the length pointer.
|
/// The stack allocation will be at the function entry. Returns the stack pointer.
|
||||||
///
|
/// This helper should be used when passing address arguments to the runtime, ensuring correct size and endianness.
|
||||||
/// Useful helper for passing runtime API parameters on the stack.
|
pub fn build_address_argument_store(
|
||||||
pub fn build_stack_parameter(
|
|
||||||
&self,
|
&self,
|
||||||
bit_length: usize,
|
address: inkwell::values::IntValue<'ctx>,
|
||||||
name: &str,
|
) -> anyhow::Result<Pointer<'ctx>> {
|
||||||
) -> (Pointer<'ctx>, Pointer<'ctx>) {
|
let address_type = self.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
||||||
let buffer_pointer = self.build_alloca(self.integer_type(bit_length), name);
|
let address_pointer = self.build_alloca_at_entry(address_type, "address_pointer");
|
||||||
let symbol = match bit_length {
|
let address_truncated =
|
||||||
revive_common::BIT_LENGTH_WORD => GLOBAL_I256_SIZE,
|
self.builder()
|
||||||
revive_common::BIT_LENGTH_ETH_ADDRESS => GLOBAL_I160_SIZE,
|
.build_int_truncate(address, address_type, "address_truncated")?;
|
||||||
revive_common::BIT_LENGTH_BLOCK_NUMBER => GLOBAL_I64_SIZE,
|
let address_swapped = self.build_byte_swap(address_truncated.into())?;
|
||||||
_ => panic!("invalid stack parameter bit width: {bit_length}"),
|
self.build_store(address_pointer, address_swapped)?;
|
||||||
};
|
Ok(address_pointer)
|
||||||
let length_pointer = self.get_global(symbol).expect("should be declared");
|
|
||||||
(buffer_pointer, length_pointer.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load the integer at given pointer and zero extend it to the VM word size.
|
/// Load the address at given pointer and zero extend it to the VM word size.
|
||||||
pub fn build_load_word(
|
pub fn build_load_address(
|
||||||
&self,
|
&self,
|
||||||
pointer: Pointer<'ctx>,
|
pointer: Pointer<'ctx>,
|
||||||
bit_length: usize,
|
|
||||||
name: &str,
|
|
||||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
|
||||||
let value = self.build_load(
|
let address = self.build_byte_swap(self.build_load(pointer, "address_pointer")?)?;
|
||||||
pointer.cast(self.integer_type(bit_length)),
|
Ok(self
|
||||||
&format!("load_{name}"),
|
.builder()
|
||||||
)?;
|
.build_int_z_extend(address.into_int_value(), self.word_type(), "address_zext")?
|
||||||
let value_extended = self.builder().build_int_z_extend(
|
.into())
|
||||||
value.into_int_value(),
|
|
||||||
self.word_type(),
|
|
||||||
&format!("zext_{name}"),
|
|
||||||
)?;
|
|
||||||
Ok(value_extended.as_basic_value_enum())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a stack load instruction.
|
/// Builds a stack load instruction.
|
||||||
@@ -684,22 +798,10 @@ where
|
|||||||
self.build_byte_swap(value)
|
self.build_byte_swap(value)
|
||||||
}
|
}
|
||||||
AddressSpace::Storage | AddressSpace::TransientStorage => {
|
AddressSpace::Storage | AddressSpace::TransientStorage => {
|
||||||
let storage_key_value = self.builder().build_ptr_to_int(
|
|
||||||
pointer.value,
|
|
||||||
self.word_type(),
|
|
||||||
"storage_ptr_to_int",
|
|
||||||
)?;
|
|
||||||
let storage_key_pointer = self.build_alloca(self.word_type(), "storage_key");
|
|
||||||
let storage_key_pointer_casted = self.builder().build_ptr_to_int(
|
|
||||||
storage_key_pointer.value,
|
|
||||||
self.xlen_type(),
|
|
||||||
"storage_key_pointer_casted",
|
|
||||||
)?;
|
|
||||||
self.builder()
|
|
||||||
.build_store(storage_key_pointer.value, storage_key_value)?;
|
|
||||||
|
|
||||||
let storage_value_pointer =
|
let storage_value_pointer =
|
||||||
self.build_alloca(self.word_type(), "storage_value_pointer");
|
self.build_alloca(self.word_type(), "storage_value_pointer");
|
||||||
|
self.build_store(storage_value_pointer, self.word_const(0))?;
|
||||||
|
|
||||||
let storage_value_length_pointer =
|
let storage_value_length_pointer =
|
||||||
self.build_alloca(self.xlen_type(), "storage_value_length_pointer");
|
self.build_alloca(self.xlen_type(), "storage_value_length_pointer");
|
||||||
self.build_store(
|
self.build_store(
|
||||||
@@ -710,10 +812,10 @@ where
|
|||||||
let transient = pointer.address_space == AddressSpace::TransientStorage;
|
let transient = pointer.address_space == AddressSpace::TransientStorage;
|
||||||
|
|
||||||
self.build_runtime_call(
|
self.build_runtime_call(
|
||||||
runtime_api::imports::GET_STORAGE,
|
revive_runtime_api::polkavm_imports::GET_STORAGE,
|
||||||
&[
|
&[
|
||||||
self.xlen_type().const_int(transient as u64, false).into(),
|
self.xlen_type().const_int(transient as u64, false).into(),
|
||||||
storage_key_pointer_casted.into(),
|
pointer.to_int(self).into(),
|
||||||
self.xlen_type().const_all_ones().into(),
|
self.xlen_type().const_all_ones().into(),
|
||||||
storage_value_pointer.to_int(self).into(),
|
storage_value_pointer.to_int(self).into(),
|
||||||
storage_value_length_pointer.to_int(self).into(),
|
storage_value_length_pointer.to_int(self).into(),
|
||||||
@@ -782,18 +884,6 @@ where
|
|||||||
self.word_type().as_basic_type_enum()
|
self.word_type().as_basic_type_enum()
|
||||||
);
|
);
|
||||||
|
|
||||||
let storage_key_value = self.builder().build_ptr_to_int(
|
|
||||||
pointer.value,
|
|
||||||
self.word_type(),
|
|
||||||
"storage_ptr_to_int",
|
|
||||||
)?;
|
|
||||||
let storage_key_pointer = self.build_alloca(self.word_type(), "storage_key");
|
|
||||||
let storage_key_pointer_casted = self.builder().build_ptr_to_int(
|
|
||||||
storage_key_pointer.value,
|
|
||||||
self.xlen_type(),
|
|
||||||
"storage_key_pointer_casted",
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let storage_value_pointer = self.build_alloca(self.word_type(), "storage_value");
|
let storage_value_pointer = self.build_alloca(self.word_type(), "storage_value");
|
||||||
let storage_value_pointer_casted = self.builder().build_ptr_to_int(
|
let storage_value_pointer_casted = self.builder().build_ptr_to_int(
|
||||||
storage_value_pointer.value,
|
storage_value_pointer.value,
|
||||||
@@ -801,18 +891,16 @@ where
|
|||||||
"storage_value_pointer_casted",
|
"storage_value_pointer_casted",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.builder()
|
|
||||||
.build_store(storage_key_pointer.value, storage_key_value)?;
|
|
||||||
self.builder()
|
self.builder()
|
||||||
.build_store(storage_value_pointer.value, value)?;
|
.build_store(storage_value_pointer.value, value)?;
|
||||||
|
|
||||||
let transient = pointer.address_space == AddressSpace::TransientStorage;
|
let transient = pointer.address_space == AddressSpace::TransientStorage;
|
||||||
|
|
||||||
self.build_runtime_call(
|
self.build_runtime_call(
|
||||||
runtime_api::imports::SET_STORAGE,
|
revive_runtime_api::polkavm_imports::SET_STORAGE,
|
||||||
&[
|
&[
|
||||||
self.xlen_type().const_int(transient as u64, false).into(),
|
self.xlen_type().const_int(transient as u64, false).into(),
|
||||||
storage_key_pointer_casted.into(),
|
pointer.to_int(self).into(),
|
||||||
self.xlen_type().const_all_ones().into(),
|
self.xlen_type().const_all_ones().into(),
|
||||||
storage_value_pointer_casted.into(),
|
storage_value_pointer_casted.into(),
|
||||||
self.integer_const(crate::polkavm::XLEN, 32).into(),
|
self.integer_const(crate::polkavm::XLEN, 32).into(),
|
||||||
@@ -921,13 +1009,29 @@ where
|
|||||||
.copied()
|
.copied()
|
||||||
.map(inkwell::values::BasicMetadataValueEnum::from)
|
.map(inkwell::values::BasicMetadataValueEnum::from)
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
&format!("runtime API call {name}"),
|
&format!("runtime_api_{name}_return_value"),
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.try_as_basic_value()
|
.try_as_basic_value()
|
||||||
.left()
|
.left()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds a call to the runtime API `import`, where `import` is a "getter" API.
|
||||||
|
/// This means that the supplied API method just writes back a single word.
|
||||||
|
/// `import` is thus expect to have a single parameter, the 32 bytes output buffer,
|
||||||
|
/// and no return value.
|
||||||
|
pub fn build_runtime_call_to_getter(
|
||||||
|
&self,
|
||||||
|
import: &'static str,
|
||||||
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
|
where
|
||||||
|
D: Dependency + Clone,
|
||||||
|
{
|
||||||
|
let pointer = self.build_alloca_at_entry(self.word_type(), &format!("{import}_output"));
|
||||||
|
self.build_runtime_call(import, &[pointer.to_int(self).into()]);
|
||||||
|
self.build_load(pointer, import)
|
||||||
|
}
|
||||||
|
|
||||||
/// Builds a call.
|
/// Builds a call.
|
||||||
pub fn build_call(
|
pub fn build_call(
|
||||||
&self,
|
&self,
|
||||||
@@ -1028,7 +1132,7 @@ where
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.build_runtime_call(
|
self.build_runtime_call(
|
||||||
runtime_api::imports::RETURN,
|
revive_runtime_api::polkavm_imports::RETURN,
|
||||||
&[flags.into(), offset_pointer.into(), length_pointer.into()],
|
&[flags.into(), offset_pointer.into(), length_pointer.into()],
|
||||||
);
|
);
|
||||||
self.build_unreachable();
|
self.build_unreachable();
|
||||||
@@ -1086,16 +1190,20 @@ where
|
|||||||
Ok(truncated)
|
Ok(truncated)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build a call to PolkaVM `sbrk` for extending the heap by `size`.
|
/// Build a call to PolkaVM `sbrk` for extending the heap from offset by `size`.
|
||||||
|
/// The allocation is aligned to 32 bytes.
|
||||||
|
///
|
||||||
|
/// This emulates the EVM linear memory until the runtime supports metered memory.
|
||||||
pub fn build_sbrk(
|
pub fn build_sbrk(
|
||||||
&self,
|
&self,
|
||||||
|
offset: inkwell::values::IntValue<'ctx>,
|
||||||
size: inkwell::values::IntValue<'ctx>,
|
size: inkwell::values::IntValue<'ctx>,
|
||||||
) -> anyhow::Result<inkwell::values::PointerValue<'ctx>> {
|
) -> anyhow::Result<inkwell::values::PointerValue<'ctx>> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.builder()
|
.builder()
|
||||||
.build_call(
|
.build_call(
|
||||||
self.runtime_api_method(runtime_api::SBRK),
|
self.runtime_api_method(revive_runtime_api::polkavm_imports::SBRK),
|
||||||
&[size.into()],
|
&[offset.into(), size.into()],
|
||||||
"call_sbrk",
|
"call_sbrk",
|
||||||
)?
|
)?
|
||||||
.try_as_basic_value()
|
.try_as_basic_value()
|
||||||
@@ -1104,14 +1212,29 @@ where
|
|||||||
.into_pointer_value())
|
.into_pointer_value())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call PolkaVM `sbrk` for extending the heap by `size`,
|
/// Build a call to PolkaVM `msize` for querying the linear memory size.
|
||||||
|
pub fn build_msize(&self) -> anyhow::Result<inkwell::values::IntValue<'ctx>> {
|
||||||
|
Ok(self
|
||||||
|
.builder()
|
||||||
|
.build_call(
|
||||||
|
self.runtime_api_method(revive_runtime_api::polkavm_imports::MEMORY_SIZE),
|
||||||
|
&[],
|
||||||
|
"call_msize",
|
||||||
|
)?
|
||||||
|
.try_as_basic_value()
|
||||||
|
.left()
|
||||||
|
.expect("sbrk returns an int")
|
||||||
|
.into_int_value())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Call PolkaVM `sbrk` for extending the heap by `offset` + `size`,
|
||||||
/// trapping the contract if the call failed.
|
/// trapping the contract if the call failed.
|
||||||
/// Returns the end of memory pointer.
|
|
||||||
pub fn build_heap_alloc(
|
pub fn build_heap_alloc(
|
||||||
&self,
|
&self,
|
||||||
|
offset: inkwell::values::IntValue<'ctx>,
|
||||||
size: inkwell::values::IntValue<'ctx>,
|
size: inkwell::values::IntValue<'ctx>,
|
||||||
) -> anyhow::Result<inkwell::values::PointerValue<'ctx>> {
|
) -> anyhow::Result<()> {
|
||||||
let end_of_memory = self.build_sbrk(size)?;
|
let end_of_memory = self.build_sbrk(offset, size)?;
|
||||||
let return_is_nil = self.builder().build_int_compare(
|
let return_is_nil = self.builder().build_int_compare(
|
||||||
inkwell::IntPredicate::EQ,
|
inkwell::IntPredicate::EQ,
|
||||||
end_of_memory,
|
end_of_memory,
|
||||||
@@ -1129,7 +1252,7 @@ where
|
|||||||
|
|
||||||
self.set_basic_block(continue_block);
|
self.set_basic_block(continue_block);
|
||||||
|
|
||||||
Ok(end_of_memory)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a pointer to `offset` into the heap, allocating
|
/// Returns a pointer to `offset` into the heap, allocating
|
||||||
@@ -1144,40 +1267,12 @@ where
|
|||||||
assert_eq!(offset.get_type(), self.xlen_type());
|
assert_eq!(offset.get_type(), self.xlen_type());
|
||||||
assert_eq!(length.get_type(), self.xlen_type());
|
assert_eq!(length.get_type(), self.xlen_type());
|
||||||
|
|
||||||
|
self.build_heap_alloc(offset, length)?;
|
||||||
|
|
||||||
let heap_start = self
|
let heap_start = self
|
||||||
.get_global(crate::polkavm::GLOBAL_HEAP_MEMORY_POINTER)?
|
.get_global(crate::polkavm::GLOBAL_HEAP_MEMORY_POINTER)?
|
||||||
.value
|
.value
|
||||||
.as_pointer_value();
|
.as_pointer_value();
|
||||||
let heap_end = self.build_sbrk(self.integer_const(crate::polkavm::XLEN, 0))?;
|
|
||||||
let value_end = self.build_gep(
|
|
||||||
Pointer::new(self.byte_type(), AddressSpace::Stack, heap_start),
|
|
||||||
&[self.builder().build_int_nuw_add(offset, length, "end")?],
|
|
||||||
self.byte_type(),
|
|
||||||
"heap_end_gep",
|
|
||||||
);
|
|
||||||
let is_out_of_bounds = self.builder().build_int_compare(
|
|
||||||
inkwell::IntPredicate::UGT,
|
|
||||||
value_end.value,
|
|
||||||
heap_end,
|
|
||||||
"is_value_overflowing_heap",
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let out_of_bounds_block = self.append_basic_block("heap_offset_out_of_bounds");
|
|
||||||
let heap_offset_block = self.append_basic_block("build_heap_pointer");
|
|
||||||
self.build_conditional_branch(is_out_of_bounds, out_of_bounds_block, heap_offset_block)?;
|
|
||||||
|
|
||||||
self.set_basic_block(out_of_bounds_block);
|
|
||||||
let size = self.builder().build_int_nuw_sub(
|
|
||||||
self.builder()
|
|
||||||
.build_ptr_to_int(value_end.value, self.xlen_type(), "value_end")?,
|
|
||||||
self.builder()
|
|
||||||
.build_ptr_to_int(heap_end, self.xlen_type(), "heap_end")?,
|
|
||||||
"heap_alloc_size",
|
|
||||||
)?;
|
|
||||||
self.build_heap_alloc(size)?;
|
|
||||||
self.build_unconditional_branch(heap_offset_block);
|
|
||||||
|
|
||||||
self.set_basic_block(heap_offset_block);
|
|
||||||
Ok(self.build_gep(
|
Ok(self.build_gep(
|
||||||
Pointer::new(self.byte_type(), AddressSpace::Stack, heap_start),
|
Pointer::new(self.byte_type(), AddressSpace::Stack, heap_start),
|
||||||
&[offset],
|
&[offset],
|
||||||
@@ -1298,12 +1393,11 @@ where
|
|||||||
&self,
|
&self,
|
||||||
argument_types: Vec<T>,
|
argument_types: Vec<T>,
|
||||||
return_values_size: usize,
|
return_values_size: usize,
|
||||||
is_near_call_abi: bool,
|
|
||||||
) -> inkwell::types::FunctionType<'ctx>
|
) -> inkwell::types::FunctionType<'ctx>
|
||||||
where
|
where
|
||||||
T: BasicType<'ctx>,
|
T: BasicType<'ctx>,
|
||||||
{
|
{
|
||||||
let mut argument_types: Vec<inkwell::types::BasicMetadataTypeEnum> = argument_types
|
let argument_types: Vec<inkwell::types::BasicMetadataTypeEnum> = argument_types
|
||||||
.as_slice()
|
.as_slice()
|
||||||
.iter()
|
.iter()
|
||||||
.map(T::as_basic_type_enum)
|
.map(T::as_basic_type_enum)
|
||||||
@@ -1315,11 +1409,6 @@ where
|
|||||||
.void_type()
|
.void_type()
|
||||||
.fn_type(argument_types.as_slice(), false),
|
.fn_type(argument_types.as_slice(), false),
|
||||||
1 => self.word_type().fn_type(argument_types.as_slice(), false),
|
1 => self.word_type().fn_type(argument_types.as_slice(), false),
|
||||||
_size if is_near_call_abi && self.is_system_mode() => {
|
|
||||||
let return_type = self.llvm().ptr_type(AddressSpace::Stack.into());
|
|
||||||
argument_types.insert(0, return_type.as_basic_type_enum().into());
|
|
||||||
return_type.fn_type(argument_types.as_slice(), false)
|
|
||||||
}
|
|
||||||
size => self
|
size => self
|
||||||
.structure_type(vec![self.word_type().as_basic_type_enum(); size].as_slice())
|
.structure_type(vec![self.word_type().as_basic_type_enum(); size].as_slice())
|
||||||
.fn_type(argument_types.as_slice(), false),
|
.fn_type(argument_types.as_slice(), false),
|
||||||
@@ -1512,12 +1601,4 @@ where
|
|||||||
anyhow::bail!("The immutable size data is not available");
|
anyhow::bail!("The immutable size data is not available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the system mode is enabled.
|
|
||||||
pub fn is_system_mode(&self) -> bool {
|
|
||||||
self.yul_data
|
|
||||||
.as_ref()
|
|
||||||
.map(|data| data.is_system_mode())
|
|
||||||
.unwrap_or_default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ impl SolidityData {
|
|||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current number of immutables values in the contract.
|
/// Returns the current size of immutable values in the contract.
|
||||||
pub fn immutables_size(&self) -> usize {
|
pub fn immutables_size(&self) -> usize {
|
||||||
self.immutables.len() * revive_common::BYTE_LENGTH_WORD
|
self.immutables.len() * revive_common::BYTE_LENGTH_WORD
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub fn create_context(
|
|||||||
let module = llvm.create_module("test");
|
let module = llvm.create_module("test");
|
||||||
let optimizer = Optimizer::new(optimizer_settings);
|
let optimizer = Optimizer::new(optimizer_settings);
|
||||||
|
|
||||||
Context::<DummyDependency>::new(llvm, module, optimizer, None, true, None)
|
Context::<DummyDependency>::new(llvm, module, optimizer, None, true, Default::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -8,28 +8,12 @@ use num::Zero;
|
|||||||
/// Describes some data that is only relevant to Yul.
|
/// Describes some data that is only relevant to Yul.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct YulData {
|
pub struct YulData {
|
||||||
/// The system mode flag.
|
|
||||||
/// The call simulations only work if this mode is enabled.
|
|
||||||
is_system_mode: bool,
|
|
||||||
/// The list of constant arrays in the code section.
|
/// The list of constant arrays in the code section.
|
||||||
/// It is a temporary storage used until the finalization method is called.
|
/// It is a temporary storage used until the finalization method is called.
|
||||||
const_arrays: BTreeMap<u8, Vec<num::BigUint>>,
|
const_arrays: BTreeMap<u8, Vec<num::BigUint>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl YulData {
|
impl YulData {
|
||||||
/// A shortcut constructor.
|
|
||||||
pub fn new(is_system_mode: bool) -> Self {
|
|
||||||
Self {
|
|
||||||
is_system_mode,
|
|
||||||
const_arrays: BTreeMap::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the system mode is enabled.
|
|
||||||
pub fn is_system_mode(&self) -> bool {
|
|
||||||
self.is_system_mode
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Declares a temporary constant array representation.
|
/// Declares a temporary constant array representation.
|
||||||
pub fn const_array_declare(&mut self, index: u8, size: u16) -> anyhow::Result<()> {
|
pub fn const_array_declare(&mut self, index: u8, size: u16) -> anyhow::Result<()> {
|
||||||
if self.const_arrays.contains_key(&index) {
|
if self.const_arrays.contains_key(&index) {
|
||||||
|
|||||||
@@ -5,14 +5,11 @@ use inkwell::values::BasicValue;
|
|||||||
use crate::polkavm::context::argument::Argument;
|
use crate::polkavm::context::argument::Argument;
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
use crate::polkavm_const::runtime_api;
|
|
||||||
|
|
||||||
static STATIC_CALL_FLAG: u32 = 0b0001_0000;
|
const STATIC_CALL_FLAG: u32 = 0b0001_0000;
|
||||||
|
const REENTRANT_CALL_FLAG: u32 = 0b0000_1000;
|
||||||
|
|
||||||
/// Translates a contract call.
|
/// Translates a contract call.
|
||||||
///
|
|
||||||
/// If the `simulation_address` is specified, the call is
|
|
||||||
/// substituted with another instruction according to the specification.
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn call<'ctx, D>(
|
pub fn call<'ctx, D>(
|
||||||
context: &mut Context<'ctx, D>,
|
context: &mut Context<'ctx, D>,
|
||||||
@@ -29,66 +26,71 @@ pub fn call<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let address_pointer = context.build_alloca(context.word_type(), "address_ptr");
|
let address_pointer = context.build_address_argument_store(address)?;
|
||||||
context.build_store(address_pointer, address)?;
|
|
||||||
|
|
||||||
let value_pointer = if let Some(value) = value {
|
let value = value.unwrap_or_else(|| context.word_const(0));
|
||||||
let value_pointer = context.build_alloca(context.value_type(), "value");
|
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||||
context.build_store(value_pointer, value)?;
|
context.build_store(value_pointer, value)?;
|
||||||
value_pointer
|
|
||||||
} else {
|
|
||||||
context.sentinel_pointer()
|
|
||||||
};
|
|
||||||
|
|
||||||
let input_offset = context.safe_truncate_int_to_xlen(input_offset)?;
|
let input_offset = context.safe_truncate_int_to_xlen(input_offset)?;
|
||||||
let input_length = context.safe_truncate_int_to_xlen(input_length)?;
|
let input_length = context.safe_truncate_int_to_xlen(input_length)?;
|
||||||
let output_offset = context.safe_truncate_int_to_xlen(output_offset)?;
|
let output_offset = context.safe_truncate_int_to_xlen(output_offset)?;
|
||||||
let output_length = context.safe_truncate_int_to_xlen(output_length)?;
|
let output_length = context.safe_truncate_int_to_xlen(output_length)?;
|
||||||
|
|
||||||
let gas = context
|
// TODO: What to supply here? Is there a weight to gas?
|
||||||
|
let _gas = context
|
||||||
.builder()
|
.builder()
|
||||||
.build_int_truncate(gas, context.integer_type(64), "gas")?;
|
.build_int_truncate(gas, context.integer_type(64), "gas")?;
|
||||||
|
|
||||||
let flags = if static_call { STATIC_CALL_FLAG } else { 0 };
|
|
||||||
|
|
||||||
let input_pointer = context.build_heap_gep(input_offset, input_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_pointer = context.build_heap_gep(output_offset, output_length)?;
|
||||||
|
|
||||||
let output_length_pointer = context.get_global(crate::polkavm::GLOBAL_RETURN_DATA_SIZE)?;
|
let output_length_pointer = context.build_alloca_at_entry(context.xlen_type(), "output_length");
|
||||||
context.build_store(output_length_pointer.into(), output_length)?;
|
context.build_store(output_length_pointer, output_length)?;
|
||||||
|
|
||||||
let argument_pointer = revive_runtime_api::calling_convention::Spill::new(
|
let flags = if static_call {
|
||||||
|
REENTRANT_CALL_FLAG | STATIC_CALL_FLAG
|
||||||
|
} else {
|
||||||
|
REENTRANT_CALL_FLAG
|
||||||
|
};
|
||||||
|
let flags = context.xlen_type().const_int(flags as u64, false);
|
||||||
|
|
||||||
|
let argument_type = revive_runtime_api::calling_convention::call(context.llvm());
|
||||||
|
let argument_pointer = context.build_alloca_at_entry(argument_type, "call_arguments");
|
||||||
|
let arguments = &[
|
||||||
|
flags.as_basic_value_enum(),
|
||||||
|
address_pointer.value.as_basic_value_enum(),
|
||||||
|
context.integer_const(64, 0).as_basic_value_enum(),
|
||||||
|
context.integer_const(64, 0).as_basic_value_enum(),
|
||||||
|
context.sentinel_pointer().value.as_basic_value_enum(),
|
||||||
|
value_pointer.value.as_basic_value_enum(),
|
||||||
|
input_pointer.value.as_basic_value_enum(),
|
||||||
|
input_length.as_basic_value_enum(),
|
||||||
|
output_pointer.value.as_basic_value_enum(),
|
||||||
|
output_length_pointer.value.as_basic_value_enum(),
|
||||||
|
];
|
||||||
|
revive_runtime_api::calling_convention::spill(
|
||||||
context.builder(),
|
context.builder(),
|
||||||
revive_runtime_api::calling_convention::call(context.llvm()),
|
argument_pointer.value,
|
||||||
"call_arguments",
|
argument_type,
|
||||||
)?
|
arguments,
|
||||||
.next(context.xlen_type().const_int(flags as u64, false))?
|
)?;
|
||||||
.next(address_pointer.value)?
|
|
||||||
.next(gas)?
|
|
||||||
.skip()
|
|
||||||
.next(context.sentinel_pointer().value)?
|
|
||||||
.next(value_pointer.value)?
|
|
||||||
.next(input_pointer.value)?
|
|
||||||
.next(input_length)?
|
|
||||||
.next(output_pointer.value)?
|
|
||||||
.next(output_length_pointer.value)?
|
|
||||||
.done();
|
|
||||||
|
|
||||||
let name = runtime_api::imports::CALL;
|
let name = revive_runtime_api::polkavm_imports::CALL;
|
||||||
let arguments = context.builder().build_ptr_to_int(
|
let argument_pointer = context.builder().build_ptr_to_int(
|
||||||
argument_pointer,
|
argument_pointer.value,
|
||||||
context.xlen_type(),
|
context.xlen_type(),
|
||||||
"argument_pointer",
|
"call_argument_pointer",
|
||||||
)?;
|
)?;
|
||||||
let success = context
|
let success = context
|
||||||
.build_runtime_call(name, &[arguments.into()])
|
.build_runtime_call(name, &[argument_pointer.into()])
|
||||||
.unwrap_or_else(|| panic!("{name} should return a value"))
|
.unwrap_or_else(|| panic!("{name} should return a value"))
|
||||||
.into_int_value();
|
.into_int_value();
|
||||||
|
|
||||||
let is_success = context.builder().build_int_compare(
|
let is_success = context.builder().build_int_compare(
|
||||||
inkwell::IntPredicate::EQ,
|
inkwell::IntPredicate::EQ,
|
||||||
success,
|
success,
|
||||||
context.xlen_type().const_zero(),
|
context.integer_const(revive_common::BIT_LENGTH_X64, 0),
|
||||||
"is_success",
|
"is_success",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -100,20 +102,84 @@ where
|
|||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn delegate_call<'ctx, D>(
|
pub fn delegate_call<'ctx, D>(
|
||||||
_context: &mut Context<'ctx, D>,
|
context: &mut Context<'ctx, D>,
|
||||||
_gas: inkwell::values::IntValue<'ctx>,
|
gas: inkwell::values::IntValue<'ctx>,
|
||||||
_address: inkwell::values::IntValue<'ctx>,
|
address: inkwell::values::IntValue<'ctx>,
|
||||||
_value: Option<inkwell::values::IntValue<'ctx>>,
|
input_offset: inkwell::values::IntValue<'ctx>,
|
||||||
_input_offset: inkwell::values::IntValue<'ctx>,
|
input_length: inkwell::values::IntValue<'ctx>,
|
||||||
_input_length: inkwell::values::IntValue<'ctx>,
|
output_offset: inkwell::values::IntValue<'ctx>,
|
||||||
_output_offset: inkwell::values::IntValue<'ctx>,
|
output_length: inkwell::values::IntValue<'ctx>,
|
||||||
_output_length: inkwell::values::IntValue<'ctx>,
|
|
||||||
_constants: Vec<Option<num::BigUint>>,
|
_constants: Vec<Option<num::BigUint>>,
|
||||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
todo!()
|
let address_pointer = context.build_address_argument_store(address)?;
|
||||||
|
|
||||||
|
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)?;
|
||||||
|
|
||||||
|
// TODO: What to supply here? Is there a weight to gas?
|
||||||
|
let _gas = context
|
||||||
|
.builder()
|
||||||
|
.build_int_truncate(gas, context.integer_type(64), "gas")?;
|
||||||
|
|
||||||
|
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 = context.xlen_type().const_int(0u64, false);
|
||||||
|
|
||||||
|
let argument_type = revive_runtime_api::calling_convention::delegate_call(context.llvm());
|
||||||
|
let argument_pointer = context.build_alloca_at_entry(argument_type, "delegate_call_arguments");
|
||||||
|
let arguments = &[
|
||||||
|
flags.as_basic_value_enum(),
|
||||||
|
address_pointer.value.as_basic_value_enum(),
|
||||||
|
context
|
||||||
|
.integer_const(revive_common::BIT_LENGTH_X64, 0)
|
||||||
|
.as_basic_value_enum(),
|
||||||
|
context
|
||||||
|
.integer_const(revive_common::BIT_LENGTH_X64, 0)
|
||||||
|
.as_basic_value_enum(),
|
||||||
|
context.sentinel_pointer().value.as_basic_value_enum(),
|
||||||
|
input_pointer.value.as_basic_value_enum(),
|
||||||
|
input_length.as_basic_value_enum(),
|
||||||
|
output_pointer.value.as_basic_value_enum(),
|
||||||
|
output_length_pointer.value.as_basic_value_enum(),
|
||||||
|
];
|
||||||
|
revive_runtime_api::calling_convention::spill(
|
||||||
|
context.builder(),
|
||||||
|
argument_pointer.value,
|
||||||
|
argument_type,
|
||||||
|
arguments,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let name = revive_runtime_api::polkavm_imports::DELEGATE_CALL;
|
||||||
|
let argument_pointer = context.builder().build_ptr_to_int(
|
||||||
|
argument_pointer.value,
|
||||||
|
context.xlen_type(),
|
||||||
|
"delegate_call_argument_pointer",
|
||||||
|
)?;
|
||||||
|
let success = context
|
||||||
|
.build_runtime_call(name, &[argument_pointer.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())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the Yul `linkersymbol` instruction.
|
/// Translates the Yul `linkersymbol` instruction.
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use inkwell::values::BasicValue;
|
|||||||
|
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
use crate::polkavm_const::runtime_api;
|
|
||||||
|
|
||||||
/// Translates the `gas_limit` instruction.
|
/// Translates the `gas_limit` instruction.
|
||||||
pub fn gas_limit<'ctx, D>(
|
pub fn gas_limit<'ctx, D>(
|
||||||
@@ -18,22 +17,29 @@ where
|
|||||||
|
|
||||||
/// Translates the `gas_price` instruction.
|
/// Translates the `gas_price` instruction.
|
||||||
pub fn gas_price<'ctx, D>(
|
pub fn gas_price<'ctx, D>(
|
||||||
_context: &mut Context<'ctx, D>,
|
context: &mut Context<'ctx, D>,
|
||||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
todo!()
|
Ok(context.word_const(1).as_basic_value_enum())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `tx.origin` instruction.
|
/// Translates the `tx.origin` instruction.
|
||||||
pub fn origin<'ctx, D>(
|
pub fn origin<'ctx, D>(
|
||||||
_context: &mut Context<'ctx, D>,
|
context: &mut Context<'ctx, D>,
|
||||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
todo!()
|
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
||||||
|
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,
|
||||||
|
&[address_pointer.to_int(context).into()],
|
||||||
|
);
|
||||||
|
context.build_load_address(address_pointer)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `chain_id` instruction.
|
/// Translates the `chain_id` instruction.
|
||||||
@@ -43,7 +49,7 @@ pub fn chain_id<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
Ok(context.word_const(0).as_basic_value_enum())
|
context.build_runtime_call_to_getter(revive_runtime_api::polkavm_imports::CHAIN_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `block_number` instruction.
|
/// Translates the `block_number` instruction.
|
||||||
@@ -53,22 +59,7 @@ pub fn block_number<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let (output_pointer, output_length_pointer) = context.build_stack_parameter(
|
context.build_runtime_call_to_getter(revive_runtime_api::polkavm_imports::BLOCK_NUMBER)
|
||||||
revive_common::BIT_LENGTH_BLOCK_NUMBER,
|
|
||||||
"block_timestamp_output",
|
|
||||||
);
|
|
||||||
context.build_runtime_call(
|
|
||||||
runtime_api::imports::BLOCK_NUMBER,
|
|
||||||
&[
|
|
||||||
output_pointer.to_int(context).into(),
|
|
||||||
output_length_pointer.to_int(context).into(),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
context.build_load_word(
|
|
||||||
output_pointer,
|
|
||||||
revive_common::BIT_LENGTH_BLOCK_NUMBER,
|
|
||||||
"block_number",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `block_timestamp` instruction.
|
/// Translates the `block_timestamp` instruction.
|
||||||
@@ -78,33 +69,29 @@ pub fn block_timestamp<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let (output_pointer, output_length_pointer) = context.build_stack_parameter(
|
context.build_runtime_call_to_getter(revive_runtime_api::polkavm_imports::NOW)
|
||||||
revive_common::BIT_LENGTH_BLOCK_TIMESTAMP,
|
|
||||||
"block_timestamp_output",
|
|
||||||
);
|
|
||||||
context.build_runtime_call(
|
|
||||||
runtime_api::imports::NOW,
|
|
||||||
&[
|
|
||||||
output_pointer.to_int(context).into(),
|
|
||||||
output_length_pointer.to_int(context).into(),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
context.build_load_word(
|
|
||||||
output_pointer,
|
|
||||||
revive_common::BIT_LENGTH_BLOCK_TIMESTAMP,
|
|
||||||
"block_timestamp",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `block_hash` instruction.
|
/// Translates the `block_hash` instruction.
|
||||||
pub fn block_hash<'ctx, D>(
|
pub fn block_hash<'ctx, D>(
|
||||||
_context: &mut Context<'ctx, D>,
|
context: &mut Context<'ctx, D>,
|
||||||
_index: inkwell::values::IntValue<'ctx>,
|
index: inkwell::values::IntValue<'ctx>,
|
||||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
todo!()
|
let output_pointer = context.build_alloca_at_entry(context.word_type(), "blockhash_out_ptr");
|
||||||
|
let index_ptr = context.build_alloca_at_entry(context.word_type(), "blockhash_index_ptr");
|
||||||
|
context.build_store(index_ptr, index)?;
|
||||||
|
|
||||||
|
context.build_runtime_call(
|
||||||
|
revive_runtime_api::polkavm_imports::BLOCK_HASH,
|
||||||
|
&[
|
||||||
|
index_ptr.to_int(context).into(),
|
||||||
|
output_pointer.to_int(context).into(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
context.build_byte_swap(context.build_load(output_pointer, "block_hash")?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `difficulty` instruction.
|
/// Translates the `difficulty` instruction.
|
||||||
@@ -137,33 +124,6 @@ where
|
|||||||
Ok(context.word_const(0).as_basic_value_enum())
|
Ok(context.word_const(0).as_basic_value_enum())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `msize` instruction.
|
|
||||||
pub fn msize<'ctx, D>(
|
|
||||||
context: &mut Context<'ctx, D>,
|
|
||||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
|
||||||
where
|
|
||||||
D: Dependency + Clone,
|
|
||||||
{
|
|
||||||
let heap_end = context.build_sbrk(context.xlen_type().const_zero())?;
|
|
||||||
let heap_start = context
|
|
||||||
.get_global(crate::polkavm::GLOBAL_HEAP_MEMORY_POINTER)?
|
|
||||||
.value
|
|
||||||
.as_pointer_value();
|
|
||||||
let heap_size = context.builder().build_int_nuw_sub(
|
|
||||||
context
|
|
||||||
.builder()
|
|
||||||
.build_ptr_to_int(heap_end, context.xlen_type(), "heap_end")?,
|
|
||||||
context
|
|
||||||
.builder()
|
|
||||||
.build_ptr_to_int(heap_start, context.xlen_type(), "heap_start")?,
|
|
||||||
"heap_size",
|
|
||||||
)?;
|
|
||||||
Ok(context
|
|
||||||
.builder()
|
|
||||||
.build_int_z_extend(heap_size, context.word_type(), "heap_size_extended")?
|
|
||||||
.as_basic_value_enum())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Translates the `address` instruction.
|
/// Translates the `address` instruction.
|
||||||
pub fn address<'ctx, D>(
|
pub fn address<'ctx, D>(
|
||||||
context: &mut Context<'ctx, D>,
|
context: &mut Context<'ctx, D>,
|
||||||
@@ -171,20 +131,15 @@ pub fn address<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let (output_pointer, output_length_pointer) =
|
let pointer = context.build_alloca_at_entry(
|
||||||
context.build_stack_parameter(revive_common::BIT_LENGTH_ETH_ADDRESS, "address_output");
|
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
|
||||||
context.build_runtime_call(
|
"address_output",
|
||||||
runtime_api::imports::ADDRESS,
|
|
||||||
&[
|
|
||||||
output_pointer.to_int(context).into(),
|
|
||||||
output_length_pointer.to_int(context).into(),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
let value = context.build_byte_swap(context.build_load(output_pointer, "address")?)?;
|
context.build_runtime_call(
|
||||||
Ok(context
|
revive_runtime_api::polkavm_imports::ADDRESS,
|
||||||
.builder()
|
&[pointer.to_int(context).into()],
|
||||||
.build_int_z_extend(value.into_int_value(), context.word_type(), "address_zext")?
|
);
|
||||||
.into())
|
context.build_load_address(pointer)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `caller` instruction.
|
/// Translates the `caller` instruction.
|
||||||
@@ -194,18 +149,13 @@ pub fn caller<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let (output_pointer, output_length_pointer) =
|
let pointer = context.build_alloca_at_entry(
|
||||||
context.build_stack_parameter(revive_common::BIT_LENGTH_ETH_ADDRESS, "caller_output");
|
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
|
||||||
context.build_runtime_call(
|
"address_output",
|
||||||
runtime_api::imports::CALLER,
|
|
||||||
&[
|
|
||||||
output_pointer.to_int(context).into(),
|
|
||||||
output_length_pointer.to_int(context).into(),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
let value = context.build_byte_swap(context.build_load(output_pointer, "caller")?)?;
|
context.build_runtime_call(
|
||||||
Ok(context
|
revive_runtime_api::polkavm_imports::CALLER,
|
||||||
.builder()
|
&[pointer.to_int(context).into()],
|
||||||
.build_int_z_extend(value.into_int_value(), context.word_type(), "caller_zext")?
|
);
|
||||||
.into())
|
context.build_load_address(pointer)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,28 +7,15 @@ use crate::polkavm::context::argument::Argument;
|
|||||||
use crate::polkavm::context::code_type::CodeType;
|
use crate::polkavm::context::code_type::CodeType;
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
use crate::polkavm_const::runtime_api;
|
|
||||||
|
|
||||||
/// Translates the contract `create` instruction.
|
/// Translates the contract `create` and `create2` instruction.
|
||||||
/// The instruction is simulated by a call to a system contract.
|
///
|
||||||
|
/// A `salt` value of `None` is equivalent to `create1`.
|
||||||
pub fn create<'ctx, D>(
|
pub fn create<'ctx, D>(
|
||||||
context: &mut Context<'ctx, D>,
|
context: &mut Context<'ctx, D>,
|
||||||
value: inkwell::values::IntValue<'ctx>,
|
value: inkwell::values::IntValue<'ctx>,
|
||||||
input_offset: inkwell::values::IntValue<'ctx>,
|
input_offset: inkwell::values::IntValue<'ctx>,
|
||||||
input_length: inkwell::values::IntValue<'ctx>,
|
input_length: inkwell::values::IntValue<'ctx>,
|
||||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
|
||||||
where
|
|
||||||
D: Dependency + Clone,
|
|
||||||
{
|
|
||||||
self::create2(context, value, input_offset, input_length, None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Translates the contract `create2` instruction.
|
|
||||||
pub fn create2<'ctx, D>(
|
|
||||||
context: &mut Context<'ctx, D>,
|
|
||||||
value: inkwell::values::IntValue<'ctx>,
|
|
||||||
input_offset: inkwell::values::IntValue<'ctx>,
|
|
||||||
input_length: inkwell::values::IntValue<'ctx>,
|
|
||||||
salt: Option<inkwell::values::IntValue<'ctx>>,
|
salt: Option<inkwell::values::IntValue<'ctx>>,
|
||||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
where
|
where
|
||||||
@@ -37,9 +24,6 @@ where
|
|||||||
let input_offset = context.safe_truncate_int_to_xlen(input_offset)?;
|
let input_offset = context.safe_truncate_int_to_xlen(input_offset)?;
|
||||||
let input_length = context.safe_truncate_int_to_xlen(input_length)?;
|
let input_length = context.safe_truncate_int_to_xlen(input_length)?;
|
||||||
|
|
||||||
let value_pointer = context.build_alloca(context.value_type(), "value");
|
|
||||||
context.build_store(value_pointer, value)?;
|
|
||||||
|
|
||||||
let code_hash_pointer = context.build_heap_gep(input_offset, input_length)?;
|
let code_hash_pointer = context.build_heap_gep(input_offset, input_length)?;
|
||||||
|
|
||||||
let input_data_pointer = context.build_gep(
|
let input_data_pointer = context.build_gep(
|
||||||
@@ -48,53 +32,68 @@ where
|
|||||||
.xlen_type()
|
.xlen_type()
|
||||||
.const_int(revive_common::BYTE_LENGTH_WORD as u64, false)],
|
.const_int(revive_common::BYTE_LENGTH_WORD as u64, false)],
|
||||||
context.byte_type(),
|
context.byte_type(),
|
||||||
"value_ptr_parameter_offset",
|
"input_ptr_parameter_offset",
|
||||||
);
|
);
|
||||||
|
|
||||||
let salt_pointer = context.build_alloca(context.word_type(), "salt");
|
let value_pointer = context.build_alloca_at_entry(context.value_type(), "transferred_value");
|
||||||
context.build_store(salt_pointer, salt.unwrap_or_else(|| context.word_const(0)))?;
|
context.build_store(value_pointer, value)?;
|
||||||
|
|
||||||
let (address_pointer, address_length_pointer) =
|
let salt_pointer = match salt {
|
||||||
context.build_stack_parameter(revive_common::BIT_LENGTH_ETH_ADDRESS, "address_pointer");
|
Some(salt) => {
|
||||||
|
let salt_pointer = context.build_alloca_at_entry(context.word_type(), "salt_pointer");
|
||||||
|
context.build_store(salt_pointer, salt)?;
|
||||||
|
salt_pointer
|
||||||
|
}
|
||||||
|
None => context.sentinel_pointer(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let address_pointer = context.build_alloca_at_entry(
|
||||||
|
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
|
||||||
|
"address_pointer",
|
||||||
|
);
|
||||||
context.build_store(address_pointer, context.word_const(0))?;
|
context.build_store(address_pointer, context.word_const(0))?;
|
||||||
|
|
||||||
let argument_pointer = revive_runtime_api::calling_convention::Spill::new(
|
let argument_type = revive_runtime_api::calling_convention::instantiate(context.llvm());
|
||||||
|
let argument_pointer = context.build_alloca_at_entry(argument_type, "instantiate_arguments");
|
||||||
|
let arguments = &[
|
||||||
|
code_hash_pointer.value.as_basic_value_enum(),
|
||||||
|
context.integer_const(64, 0).as_basic_value_enum(),
|
||||||
|
context.integer_const(64, 0).as_basic_value_enum(),
|
||||||
|
context.sentinel_pointer().value.as_basic_value_enum(),
|
||||||
|
value_pointer.value.as_basic_value_enum(),
|
||||||
|
input_data_pointer.value.as_basic_value_enum(),
|
||||||
|
input_length.as_basic_value_enum(),
|
||||||
|
address_pointer.value.as_basic_value_enum(),
|
||||||
|
context.sentinel_pointer().value.as_basic_value_enum(),
|
||||||
|
context.sentinel_pointer().value.as_basic_value_enum(),
|
||||||
|
salt_pointer.value.as_basic_value_enum(),
|
||||||
|
];
|
||||||
|
revive_runtime_api::calling_convention::spill(
|
||||||
context.builder(),
|
context.builder(),
|
||||||
revive_runtime_api::calling_convention::instantiate(context.llvm()),
|
argument_pointer.value,
|
||||||
"create2_arguments",
|
argument_type,
|
||||||
)?
|
arguments,
|
||||||
.next(code_hash_pointer.value)?
|
)?;
|
||||||
.skip()
|
|
||||||
.skip()
|
|
||||||
.next(context.sentinel_pointer().value)?
|
|
||||||
.next(value_pointer.value)?
|
|
||||||
.next(input_data_pointer.value)?
|
|
||||||
.next(input_length)?
|
|
||||||
.next(address_pointer.value)?
|
|
||||||
.next(address_length_pointer.value)?
|
|
||||||
.next(context.sentinel_pointer().value)?
|
|
||||||
.next(context.sentinel_pointer().value)?
|
|
||||||
.next(salt_pointer.value)?
|
|
||||||
.next(
|
|
||||||
context
|
|
||||||
.xlen_type()
|
|
||||||
.const_int(revive_common::BYTE_LENGTH_WORD as u64, false),
|
|
||||||
)?
|
|
||||||
.done();
|
|
||||||
|
|
||||||
|
let argument_pointer = context.builder().build_ptr_to_int(
|
||||||
|
argument_pointer.value,
|
||||||
|
context.xlen_type(),
|
||||||
|
"instantiate_argument_pointer",
|
||||||
|
)?;
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(
|
||||||
runtime_api::imports::INSTANTIATE,
|
revive_runtime_api::polkavm_imports::INSTANTIATE,
|
||||||
&[context
|
&[argument_pointer.into()],
|
||||||
.builder()
|
|
||||||
.build_ptr_to_int(argument_pointer, context.xlen_type(), "argument_pointer")?
|
|
||||||
.into()],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
context.build_load_word(
|
let address = context.build_byte_swap(context.build_load(address_pointer, "address")?)?;
|
||||||
address_pointer,
|
Ok(context
|
||||||
revive_common::BIT_LENGTH_ETH_ADDRESS,
|
.builder()
|
||||||
"address",
|
.build_int_z_extend(
|
||||||
)
|
address.into_int_value(),
|
||||||
|
context.word_type(),
|
||||||
|
"address_zext",
|
||||||
|
)?
|
||||||
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the contract hash instruction, which is actually used to set the hash of the contract
|
/// Translates the contract hash instruction, which is actually used to set the hash of the contract
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
use crate::polkavm_const::runtime_api;
|
|
||||||
|
|
||||||
/// Translates the `sha3` instruction.
|
/// Translates the `sha3` instruction.
|
||||||
pub fn sha3<'ctx, D>(
|
pub fn sha3<'ctx, D>(
|
||||||
@@ -19,7 +18,7 @@ where
|
|||||||
let output_pointer = context.build_alloca(context.word_type(), "output_pointer");
|
let output_pointer = context.build_alloca(context.word_type(), "output_pointer");
|
||||||
|
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(
|
||||||
runtime_api::imports::HASH_KECCAK_256,
|
revive_runtime_api::polkavm_imports::HASH_KECCAK_256,
|
||||||
&[
|
&[
|
||||||
input_pointer.to_int(context).into(),
|
input_pointer.to_int(context).into(),
|
||||||
length_casted.into(),
|
length_casted.into(),
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use inkwell::values::BasicValue;
|
|||||||
|
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
use crate::polkavm_const::runtime_api;
|
|
||||||
|
|
||||||
/// Translates the `gas` instruction.
|
/// Translates the `gas` instruction.
|
||||||
pub fn gas<'ctx, D>(
|
pub fn gas<'ctx, D>(
|
||||||
@@ -23,20 +22,13 @@ pub fn value<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let (output_pointer, output_length_pointer) =
|
let output_pointer = context.build_alloca(context.value_type(), "value_transferred");
|
||||||
context.build_stack_parameter(revive_common::BIT_LENGTH_VALUE, "value_transferred_output");
|
context.build_store(output_pointer, context.word_const(0))?;
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(
|
||||||
runtime_api::imports::VALUE_TRANSFERRED,
|
revive_runtime_api::polkavm_imports::VALUE_TRANSFERRED,
|
||||||
&[
|
&[output_pointer.to_int(context).into()],
|
||||||
output_pointer.to_int(context).into(),
|
|
||||||
output_length_pointer.to_int(context).into(),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
context.build_load_word(
|
context.build_load(output_pointer, "value_transferred")
|
||||||
output_pointer,
|
|
||||||
revive_common::BIT_LENGTH_VALUE,
|
|
||||||
"value_transferred",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `balance` instructions.
|
/// Translates the `balance` instructions.
|
||||||
@@ -47,24 +39,40 @@ pub fn balance<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let balance_pointer = context.build_alloca(context.word_type(), "balance_pointer");
|
let address_pointer = context.build_address_argument_store(address)?;
|
||||||
let address_pointer = context.build_alloca(context.word_type(), "address_pointer");
|
|
||||||
context.build_store(address_pointer, address)?;
|
|
||||||
|
|
||||||
|
let balance_pointer = context.build_alloca(context.word_type(), "balance_pointer");
|
||||||
let balance = context.builder().build_ptr_to_int(
|
let balance = context.builder().build_ptr_to_int(
|
||||||
balance_pointer.value,
|
balance_pointer.value,
|
||||||
context.xlen_type(),
|
context.xlen_type(),
|
||||||
"balance",
|
"balance",
|
||||||
)?;
|
)?;
|
||||||
let address = context.builder().build_ptr_to_int(
|
|
||||||
address_pointer.value,
|
|
||||||
context.xlen_type(),
|
|
||||||
"address",
|
|
||||||
)?;
|
|
||||||
|
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(
|
||||||
runtime_api::imports::BALANCE,
|
revive_runtime_api::polkavm_imports::BALANCE_OF,
|
||||||
&[address.into(), balance.into()],
|
&[address_pointer.to_int(context).into(), balance.into()],
|
||||||
|
);
|
||||||
|
|
||||||
|
context.build_load(balance_pointer, "balance")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Translates the `selfbalance` instructions.
|
||||||
|
pub fn self_balance<'ctx, D>(
|
||||||
|
context: &mut Context<'ctx, D>,
|
||||||
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
|
where
|
||||||
|
D: Dependency + Clone,
|
||||||
|
{
|
||||||
|
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(),
|
||||||
|
"balance",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
context.build_runtime_call(
|
||||||
|
revive_runtime_api::polkavm_imports::BALANCE,
|
||||||
|
&[balance.into()],
|
||||||
);
|
);
|
||||||
|
|
||||||
context.build_load(balance_pointer, "balance")
|
context.build_load(balance_pointer, "balance")
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use inkwell::values::BasicValue;
|
|||||||
|
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
use crate::polkavm_const::runtime_api;
|
|
||||||
|
|
||||||
/// Translates a log or event call.
|
/// Translates a log or event call.
|
||||||
///
|
///
|
||||||
@@ -43,6 +42,7 @@ where
|
|||||||
context.byte_type().array_type(topics_buffer_size as u32),
|
context.byte_type().array_type(topics_buffer_size as u32),
|
||||||
"topics_buffer",
|
"topics_buffer",
|
||||||
);
|
);
|
||||||
|
|
||||||
for (n, topic) in topics.iter().enumerate() {
|
for (n, topic) in topics.iter().enumerate() {
|
||||||
let topic_buffer_offset = context
|
let topic_buffer_offset = context
|
||||||
.xlen_type()
|
.xlen_type()
|
||||||
@@ -57,6 +57,7 @@ where
|
|||||||
context.build_byte_swap(topic.as_basic_value_enum())?,
|
context.build_byte_swap(topic.as_basic_value_enum())?,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
[
|
[
|
||||||
context
|
context
|
||||||
.builder()
|
.builder()
|
||||||
@@ -68,14 +69,17 @@ where
|
|||||||
.as_basic_value_enum(),
|
.as_basic_value_enum(),
|
||||||
context
|
context
|
||||||
.xlen_type()
|
.xlen_type()
|
||||||
.const_int(topics_buffer_size as u64, false)
|
.const_int(topics.len() as u64, false)
|
||||||
.as_basic_value_enum(),
|
.as_basic_value_enum(),
|
||||||
input_pointer.as_basic_value_enum(),
|
input_pointer.as_basic_value_enum(),
|
||||||
input_length.as_basic_value_enum(),
|
input_length.as_basic_value_enum(),
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = context.build_runtime_call(runtime_api::imports::DEPOSIT_EVENT, &arguments);
|
let _ = context.build_runtime_call(
|
||||||
|
revive_runtime_api::polkavm_imports::DEPOSIT_EVENT,
|
||||||
|
&arguments,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
//! Translates the external code operations.
|
//! Translates the external code operations.
|
||||||
|
|
||||||
use inkwell::values::BasicValue;
|
|
||||||
|
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
use crate::polkavm_const::runtime_api;
|
|
||||||
|
|
||||||
/// Translates the `extcodesize` instruction if `address` is `Some`.
|
/// Translates the `extcodesize` instruction if `address` is `Some`.
|
||||||
/// Otherwise, translates the `codesize` instruction.
|
/// Otherwise, translates the `codesize` instruction.
|
||||||
@@ -15,41 +12,52 @@ pub fn size<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let address_pointer = match address {
|
let address = match address {
|
||||||
Some(address) => {
|
Some(address) => address,
|
||||||
let address_pointer = context.build_alloca(context.word_type(), "value");
|
None => super::context::address(context)?.into_int_value(),
|
||||||
context.build_store(address_pointer, address)?;
|
|
||||||
address_pointer
|
|
||||||
}
|
|
||||||
None => context.sentinel_pointer(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let address_pointer_casted = context.builder().build_ptr_to_int(
|
let address_pointer = context.build_address_argument_store(address)?;
|
||||||
address_pointer.value,
|
let output_pointer = context.build_alloca_at_entry(context.word_type(), "output_pointer");
|
||||||
context.xlen_type(),
|
|
||||||
"address_pointer",
|
|
||||||
)?;
|
|
||||||
let value = context
|
|
||||||
.build_runtime_call(
|
|
||||||
runtime_api::imports::CODE_SIZE,
|
|
||||||
&[address_pointer_casted.into()],
|
|
||||||
)
|
|
||||||
.unwrap_or_else(|| panic!("{} should return a value", runtime_api::imports::CODE_SIZE))
|
|
||||||
.into_int_value();
|
|
||||||
|
|
||||||
Ok(context
|
context.build_runtime_call(
|
||||||
.builder()
|
revive_runtime_api::polkavm_imports::CODE_SIZE,
|
||||||
.build_int_z_extend(value, context.word_type(), "extcodesize")?
|
&[
|
||||||
.as_basic_value_enum())
|
address_pointer.to_int(context).into(),
|
||||||
|
output_pointer.to_int(context).into(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
context.build_load(output_pointer, "code_size")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `extcodehash` instruction.
|
/// Translates the `extcodehash` instruction.
|
||||||
pub fn hash<'ctx, D>(
|
pub fn hash<'ctx, D>(
|
||||||
_context: &mut Context<'ctx, D>,
|
context: &mut Context<'ctx, D>,
|
||||||
_address: inkwell::values::IntValue<'ctx>,
|
address: inkwell::values::IntValue<'ctx>,
|
||||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
todo!()
|
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
||||||
|
let address_pointer = context.build_alloca_at_entry(address_type, "address_pointer");
|
||||||
|
let address_truncated =
|
||||||
|
context
|
||||||
|
.builder()
|
||||||
|
.build_int_truncate(address, address_type, "address_truncated")?;
|
||||||
|
let address_swapped = context.build_byte_swap(address_truncated.into())?;
|
||||||
|
context.build_store(address_pointer, address_swapped)?;
|
||||||
|
|
||||||
|
let extcodehash_pointer =
|
||||||
|
context.build_alloca_at_entry(context.word_type(), "extcodehash_pointer");
|
||||||
|
|
||||||
|
context.build_runtime_call(
|
||||||
|
revive_runtime_api::polkavm_imports::CODE_HASH,
|
||||||
|
&[
|
||||||
|
address_pointer.to_int(context).into(),
|
||||||
|
extcodehash_pointer.to_int(context).into(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
context.build_byte_swap(context.build_load(extcodehash_pointer, "extcodehash_value")?)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
//! Translates the contract immutable operations.
|
//! Translates the contract immutable operations.
|
||||||
|
|
||||||
|
use inkwell::types::BasicType;
|
||||||
|
|
||||||
use crate::polkavm::context::address_space::AddressSpace;
|
use crate::polkavm::context::address_space::AddressSpace;
|
||||||
use crate::polkavm::context::code_type::CodeType;
|
use crate::polkavm::context::code_type::CodeType;
|
||||||
|
use crate::polkavm::context::function::runtime;
|
||||||
use crate::polkavm::context::pointer::Pointer;
|
use crate::polkavm::context::pointer::Pointer;
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
|
|
||||||
/// Translates the contract immutable load.
|
/// Translates the contract immutable load.
|
||||||
/// In the deploy code the values are read from the auxiliary heap.
|
///
|
||||||
/// In the runtime code they are requested from the system contract.
|
/// In deploy code the values are read from the stack.
|
||||||
|
///
|
||||||
|
/// In runtime code they are loaded lazily with the `get_immutable_data` syscall.
|
||||||
pub fn load<'ctx, D>(
|
pub fn load<'ctx, D>(
|
||||||
context: &mut Context<'ctx, D>,
|
context: &mut Context<'ctx, D>,
|
||||||
index: inkwell::values::IntValue<'ctx>,
|
index: inkwell::values::IntValue<'ctx>,
|
||||||
@@ -20,38 +25,27 @@ where
|
|||||||
None => {
|
None => {
|
||||||
anyhow::bail!("Immutables are not available if the contract part is undefined");
|
anyhow::bail!("Immutables are not available if the contract part is undefined");
|
||||||
}
|
}
|
||||||
Some(CodeType::Deploy) => {
|
Some(CodeType::Deploy) => load_from_memory(context, index),
|
||||||
let index_double = context.builder().build_int_mul(
|
|
||||||
index,
|
|
||||||
context.word_const(2),
|
|
||||||
"immutable_load_index_double",
|
|
||||||
)?;
|
|
||||||
let offset_absolute = context.builder().build_int_add(
|
|
||||||
index_double,
|
|
||||||
context.word_const(
|
|
||||||
crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
|
||||||
+ (3 * revive_common::BYTE_LENGTH_WORD) as u64,
|
|
||||||
),
|
|
||||||
"immutable_offset_absolute",
|
|
||||||
)?;
|
|
||||||
let immutable_pointer = Pointer::new_with_offset(
|
|
||||||
context,
|
|
||||||
AddressSpace::default(),
|
|
||||||
context.word_type(),
|
|
||||||
offset_absolute,
|
|
||||||
"immutable_pointer",
|
|
||||||
);
|
|
||||||
context.build_load(immutable_pointer, "immutable_value")
|
|
||||||
}
|
|
||||||
Some(CodeType::Runtime) => {
|
Some(CodeType::Runtime) => {
|
||||||
todo!()
|
context.build_call(
|
||||||
|
context
|
||||||
|
.get_function(runtime::FUNCTION_LOAD_IMMUTABLE_DATA)
|
||||||
|
.expect("is always declared for runtime code")
|
||||||
|
.borrow()
|
||||||
|
.declaration(),
|
||||||
|
&[],
|
||||||
|
runtime::FUNCTION_LOAD_IMMUTABLE_DATA,
|
||||||
|
);
|
||||||
|
load_from_memory(context, index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the contract immutable store.
|
/// Translates the contract immutable store.
|
||||||
/// In the deploy code the values are written to the auxiliary heap at the predefined offset,
|
///
|
||||||
/// being prepared for returning to the system contract for saving.
|
/// In deploy code the values are written to the stack at the predefined offset,
|
||||||
|
/// being prepared for storing them using the `set_immutable_data` syscall.
|
||||||
|
///
|
||||||
/// Ignored in the runtime code.
|
/// Ignored in the runtime code.
|
||||||
pub fn store<'ctx, D>(
|
pub fn store<'ctx, D>(
|
||||||
context: &mut Context<'ctx, D>,
|
context: &mut Context<'ctx, D>,
|
||||||
@@ -66,46 +60,48 @@ where
|
|||||||
anyhow::bail!("Immutables are not available if the contract part is undefined");
|
anyhow::bail!("Immutables are not available if the contract part is undefined");
|
||||||
}
|
}
|
||||||
Some(CodeType::Deploy) => {
|
Some(CodeType::Deploy) => {
|
||||||
let index_double = context.builder().build_int_mul(
|
let immutable_data_pointer = context
|
||||||
index,
|
.get_global(revive_runtime_api::immutable_data::GLOBAL_IMMUTABLE_DATA_POINTER)?
|
||||||
context.word_const(2),
|
.value
|
||||||
"immutable_load_index_double",
|
.as_pointer_value();
|
||||||
)?;
|
let immutable_pointer = context.build_gep(
|
||||||
let index_offset_absolute = context.builder().build_int_add(
|
Pointer::new(
|
||||||
index_double,
|
context.word_type(),
|
||||||
context.word_const(
|
AddressSpace::Stack,
|
||||||
crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
immutable_data_pointer,
|
||||||
+ (2 * revive_common::BYTE_LENGTH_WORD) as u64,
|
|
||||||
),
|
),
|
||||||
"index_offset_absolute",
|
&[index],
|
||||||
)?;
|
context.word_type().as_basic_type_enum(),
|
||||||
let index_offset_pointer = Pointer::new_with_offset(
|
"immutable_variable_pointer",
|
||||||
context,
|
|
||||||
AddressSpace::default(),
|
|
||||||
context.word_type(),
|
|
||||||
index_offset_absolute,
|
|
||||||
"immutable_index_pointer",
|
|
||||||
);
|
);
|
||||||
context.build_store(index_offset_pointer, index)?;
|
context.build_store(immutable_pointer, value)
|
||||||
|
|
||||||
let value_offset_absolute = context.builder().build_int_add(
|
|
||||||
index_offset_absolute,
|
|
||||||
context.word_const(revive_common::BYTE_LENGTH_WORD as u64),
|
|
||||||
"value_offset_absolute",
|
|
||||||
)?;
|
|
||||||
let value_offset_pointer = Pointer::new_with_offset(
|
|
||||||
context,
|
|
||||||
AddressSpace::default(),
|
|
||||||
context.word_type(),
|
|
||||||
value_offset_absolute,
|
|
||||||
"immutable_value_pointer",
|
|
||||||
);
|
|
||||||
context.build_store(value_offset_pointer, value)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
Some(CodeType::Runtime) => {
|
Some(CodeType::Runtime) => {
|
||||||
anyhow::bail!("Immutable writes are not available in the runtime code");
|
anyhow::bail!("Immutable writes are not available in the runtime code");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load_from_memory<'ctx, D>(
|
||||||
|
context: &mut Context<'ctx, D>,
|
||||||
|
index: inkwell::values::IntValue<'ctx>,
|
||||||
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
|
where
|
||||||
|
D: Dependency + Clone,
|
||||||
|
{
|
||||||
|
let immutable_data_pointer = context
|
||||||
|
.get_global(revive_runtime_api::immutable_data::GLOBAL_IMMUTABLE_DATA_POINTER)?
|
||||||
|
.value
|
||||||
|
.as_pointer_value();
|
||||||
|
let immutable_pointer = context.build_gep(
|
||||||
|
Pointer::new(
|
||||||
|
context.word_type(),
|
||||||
|
AddressSpace::Stack,
|
||||||
|
immutable_data_pointer,
|
||||||
|
),
|
||||||
|
&[index],
|
||||||
|
context.word_type().as_basic_type_enum(),
|
||||||
|
"immutable_variable_pointer",
|
||||||
|
);
|
||||||
|
context.build_load(immutable_pointer, "immutable_value")
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,10 +1,29 @@
|
|||||||
//! Translates the heap memory operations.
|
//! Translates the heap memory operations.
|
||||||
|
|
||||||
|
use inkwell::values::BasicValue;
|
||||||
|
|
||||||
use crate::polkavm::context::address_space::AddressSpace;
|
use crate::polkavm::context::address_space::AddressSpace;
|
||||||
use crate::polkavm::context::pointer::Pointer;
|
use crate::polkavm::context::pointer::Pointer;
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
|
|
||||||
|
/// Translates the `msize` instruction.
|
||||||
|
pub fn msize<'ctx, D>(
|
||||||
|
context: &mut Context<'ctx, D>,
|
||||||
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
|
where
|
||||||
|
D: Dependency + Clone,
|
||||||
|
{
|
||||||
|
Ok(context
|
||||||
|
.builder()
|
||||||
|
.build_int_z_extend(
|
||||||
|
context.build_msize()?,
|
||||||
|
context.word_type(),
|
||||||
|
"heap_size_extended",
|
||||||
|
)?
|
||||||
|
.as_basic_value_enum())
|
||||||
|
}
|
||||||
|
|
||||||
/// Translates the `mload` instruction.
|
/// Translates the `mload` instruction.
|
||||||
/// Uses the main heap.
|
/// Uses the main heap.
|
||||||
pub fn load<'ctx, D>(
|
pub fn load<'ctx, D>(
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
//! Translates the transaction return operations.
|
//! Translates the transaction return operations.
|
||||||
|
|
||||||
|
use crate::polkavm::context::address_space::AddressSpace;
|
||||||
|
use crate::polkavm::context::code_type::CodeType;
|
||||||
|
use crate::polkavm::context::pointer::Pointer;
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
|
|
||||||
@@ -12,8 +15,60 @@ pub fn r#return<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
if context.code_type().is_none() {
|
match context.code_type() {
|
||||||
anyhow::bail!("Return is not available if the contract part is undefined");
|
None => anyhow::bail!("Return is not available if the contract part is undefined"),
|
||||||
|
Some(CodeType::Deploy) => {
|
||||||
|
let immutable_data_size_pointer = context
|
||||||
|
.get_global(revive_runtime_api::immutable_data::GLOBAL_IMMUTABLE_DATA_SIZE)?
|
||||||
|
.value
|
||||||
|
.as_pointer_value();
|
||||||
|
let immutable_data_size = context.build_load(
|
||||||
|
Pointer::new(
|
||||||
|
context.xlen_type(),
|
||||||
|
AddressSpace::Stack,
|
||||||
|
immutable_data_size_pointer,
|
||||||
|
),
|
||||||
|
"immutable_data_size_load",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let write_immutable_data_block = context.append_basic_block("write_immutables_block");
|
||||||
|
let join_return_block = context.append_basic_block("join_return_block");
|
||||||
|
let immutable_data_size_is_zero = context.builder().build_int_compare(
|
||||||
|
inkwell::IntPredicate::EQ,
|
||||||
|
context.xlen_type().const_zero(),
|
||||||
|
immutable_data_size.into_int_value(),
|
||||||
|
"immutable_data_size_is_zero",
|
||||||
|
)?;
|
||||||
|
context.build_conditional_branch(
|
||||||
|
immutable_data_size_is_zero,
|
||||||
|
join_return_block,
|
||||||
|
write_immutable_data_block,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
context.set_basic_block(write_immutable_data_block);
|
||||||
|
let immutable_data_pointer = context
|
||||||
|
.get_global(revive_runtime_api::immutable_data::GLOBAL_IMMUTABLE_DATA_POINTER)?
|
||||||
|
.value
|
||||||
|
.as_pointer_value();
|
||||||
|
context.build_runtime_call(
|
||||||
|
revive_runtime_api::polkavm_imports::SET_IMMUTABLE_DATA,
|
||||||
|
&[
|
||||||
|
context
|
||||||
|
.builder()
|
||||||
|
.build_ptr_to_int(
|
||||||
|
immutable_data_pointer,
|
||||||
|
context.xlen_type(),
|
||||||
|
"immutable_data_pointer_to_xlen",
|
||||||
|
)?
|
||||||
|
.into(),
|
||||||
|
immutable_data_size,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
context.build_unconditional_branch(join_return_block);
|
||||||
|
|
||||||
|
context.set_basic_block(join_return_block);
|
||||||
|
}
|
||||||
|
Some(CodeType::Runtime) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
context.build_exit(
|
context.build_exit(
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
//! Translates the return data instructions.
|
//! Translates the return data instructions.
|
||||||
|
|
||||||
use inkwell::values::BasicValue;
|
|
||||||
|
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
use crate::polkavm_const::runtime_api;
|
|
||||||
|
|
||||||
/// Translates the return data size.
|
/// Translates the return data size.
|
||||||
pub fn size<'ctx, D>(
|
pub fn size<'ctx, D>(
|
||||||
@@ -13,13 +10,17 @@ pub fn size<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let value = context
|
let output_pointer = context.build_alloca_at_entry(context.word_type(), "return_data_size");
|
||||||
.get_global_value(crate::polkavm::GLOBAL_RETURN_DATA_SIZE)?
|
let output_pointer_parameter = context.builder().build_ptr_to_int(
|
||||||
.into_int_value();
|
output_pointer.value,
|
||||||
Ok(context
|
context.xlen_type(),
|
||||||
.builder()
|
"return_data_copy_output_pointer",
|
||||||
.build_int_z_extend(value, context.word_type(), "calldatasize_extended")?
|
)?;
|
||||||
.as_basic_value_enum())
|
context.build_runtime_call(
|
||||||
|
revive_runtime_api::polkavm_imports::RETURNDATASIZE,
|
||||||
|
&[output_pointer_parameter.into()],
|
||||||
|
);
|
||||||
|
context.build_load(output_pointer, "return_data_size_load")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the return data copy, trapping if
|
/// Translates the return data copy, trapping if
|
||||||
@@ -39,16 +40,49 @@ where
|
|||||||
let destination_offset = context.safe_truncate_int_to_xlen(destination_offset)?;
|
let destination_offset = context.safe_truncate_int_to_xlen(destination_offset)?;
|
||||||
let size = context.safe_truncate_int_to_xlen(size)?;
|
let size = context.safe_truncate_int_to_xlen(size)?;
|
||||||
|
|
||||||
let destination_offset = context.builder().build_ptr_to_int(
|
let output_pointer = context.builder().build_ptr_to_int(
|
||||||
context.build_heap_gep(destination_offset, size)?.value,
|
context.build_heap_gep(destination_offset, size)?.value,
|
||||||
context.xlen_type(),
|
context.xlen_type(),
|
||||||
"destination_offset",
|
"return_data_copy_output_pointer",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let output_length_pointer = context.build_alloca_at_entry(
|
||||||
|
context.xlen_type(),
|
||||||
|
"return_data_copy_output_length_pointer",
|
||||||
|
);
|
||||||
|
context.build_store(output_length_pointer, size)?;
|
||||||
|
let output_length_pointer_int = context.builder().build_ptr_to_int(
|
||||||
|
output_length_pointer.value,
|
||||||
|
context.xlen_type(),
|
||||||
|
"return_data_copy_output_length_pointer_int",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(
|
||||||
runtime_api::imports::RETURNDATACOPY,
|
revive_runtime_api::polkavm_imports::RETURNDATACOPY,
|
||||||
&[destination_offset.into(), source_offset.into(), size.into()],
|
&[
|
||||||
|
output_pointer.into(),
|
||||||
|
output_length_pointer_int.into(),
|
||||||
|
source_offset.into(),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Trap on OOB (will be different in EOF code)
|
||||||
|
let overflow_block = context.append_basic_block("return_data_overflow");
|
||||||
|
let non_overflow_block = context.append_basic_block("return_data_non_overflow");
|
||||||
|
let is_overflow = context.builder().build_int_compare(
|
||||||
|
inkwell::IntPredicate::UGT,
|
||||||
|
size,
|
||||||
|
context
|
||||||
|
.build_load(output_length_pointer, "bytes_written")?
|
||||||
|
.into_int_value(),
|
||||||
|
"is_overflow",
|
||||||
|
)?;
|
||||||
|
context.build_conditional_branch(is_overflow, overflow_block, non_overflow_block)?;
|
||||||
|
|
||||||
|
context.set_basic_block(overflow_block);
|
||||||
|
context.build_call(context.intrinsics().trap, &[], "invalid_trap");
|
||||||
|
context.build_unreachable();
|
||||||
|
|
||||||
|
context.set_basic_block(non_overflow_block);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
//! Translates the storage operations.
|
//! Translates the storage operations.
|
||||||
|
|
||||||
use crate::polkavm::context::address_space::AddressSpace;
|
use crate::polkavm::context::address_space::AddressSpace;
|
||||||
use crate::polkavm::context::pointer::Pointer;
|
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
|
|
||||||
@@ -13,14 +12,10 @@ pub fn load<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let position_pointer = Pointer::new_with_offset(
|
let mut slot_ptr = context.build_alloca_at_entry(context.word_type(), "slot_pointer");
|
||||||
context,
|
slot_ptr.address_space = AddressSpace::Storage;
|
||||||
AddressSpace::Storage,
|
context.builder().build_store(slot_ptr.value, position)?;
|
||||||
context.word_type(),
|
context.build_load(slot_ptr, "storage_load_value")
|
||||||
position,
|
|
||||||
"storage_load_position_pointer",
|
|
||||||
);
|
|
||||||
context.build_load(position_pointer, "storage_load_value")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the storage store.
|
/// Translates the storage store.
|
||||||
@@ -32,14 +27,10 @@ pub fn store<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let position_pointer = Pointer::new_with_offset(
|
let mut slot_ptr = context.build_alloca_at_entry(context.word_type(), "slot_pointer");
|
||||||
context,
|
slot_ptr.address_space = AddressSpace::Storage;
|
||||||
AddressSpace::Storage,
|
context.builder().build_store(slot_ptr.value, position)?;
|
||||||
context.word_type(),
|
context.build_store(slot_ptr, value)?;
|
||||||
position,
|
|
||||||
"storage_store_position_pointer",
|
|
||||||
);
|
|
||||||
context.build_store(position_pointer, value)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,14 +42,10 @@ pub fn transient_load<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let position_pointer = Pointer::new_with_offset(
|
let mut slot_ptr = context.build_alloca_at_entry(context.word_type(), "slot_pointer");
|
||||||
context,
|
slot_ptr.address_space = AddressSpace::TransientStorage;
|
||||||
AddressSpace::TransientStorage,
|
context.builder().build_store(slot_ptr.value, position)?;
|
||||||
context.word_type(),
|
context.build_load(slot_ptr, "transient_storage_load_value")
|
||||||
position,
|
|
||||||
"transient_storage_load_position_pointer",
|
|
||||||
);
|
|
||||||
context.build_load(position_pointer, "transient_storage_load_value")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the transient storage store.
|
/// Translates the transient storage store.
|
||||||
@@ -70,13 +57,9 @@ pub fn transient_store<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let position_pointer = Pointer::new_with_offset(
|
let mut slot_ptr = context.build_alloca_at_entry(context.word_type(), "slot_pointer");
|
||||||
context,
|
slot_ptr.address_space = AddressSpace::TransientStorage;
|
||||||
AddressSpace::TransientStorage,
|
context.builder().build_store(slot_ptr.value, position)?;
|
||||||
context.word_type(),
|
context.build_store(slot_ptr, value)?;
|
||||||
position,
|
|
||||||
"transient_storage_store_position_pointer",
|
|
||||||
);
|
|
||||||
context.build_store(position_pointer, value)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ pub mod r#const;
|
|||||||
pub mod context;
|
pub mod context;
|
||||||
pub mod evm;
|
pub mod evm;
|
||||||
pub mod metadata_hash;
|
pub mod metadata_hash;
|
||||||
pub mod utils;
|
|
||||||
|
|
||||||
pub use self::r#const::*;
|
pub use self::r#const::*;
|
||||||
use self::utils::keccak256;
|
|
||||||
|
|
||||||
use crate::debug_config::DebugConfig;
|
use crate::debug_config::DebugConfig;
|
||||||
use crate::optimizer::settings::Settings as OptimizerSettings;
|
use crate::optimizer::settings::Settings as OptimizerSettings;
|
||||||
@@ -15,6 +13,7 @@ use crate::optimizer::settings::Settings as OptimizerSettings;
|
|||||||
use anyhow::Context as AnyhowContext;
|
use anyhow::Context as AnyhowContext;
|
||||||
use polkavm_common::program::ProgramBlob;
|
use polkavm_common::program::ProgramBlob;
|
||||||
use polkavm_disassembler::{Disassembler, DisassemblyFormat};
|
use polkavm_disassembler::{Disassembler, DisassemblyFormat};
|
||||||
|
use sha3::Digest;
|
||||||
|
|
||||||
use self::context::build::Build;
|
use self::context::build::Build;
|
||||||
use self::context::Context;
|
use self::context::Context;
|
||||||
@@ -29,7 +28,7 @@ pub fn build_assembly_text(
|
|||||||
contract_path: &str,
|
contract_path: &str,
|
||||||
bytecode: &[u8],
|
bytecode: &[u8],
|
||||||
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
|
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
|
||||||
debug_config: Option<&DebugConfig>,
|
debug_config: &DebugConfig,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
let program_blob = ProgramBlob::parse(bytecode.into())
|
let program_blob = ProgramBlob::parse(bytecode.into())
|
||||||
.map_err(anyhow::Error::msg)
|
.map_err(anyhow::Error::msg)
|
||||||
@@ -49,15 +48,13 @@ pub fn build_assembly_text(
|
|||||||
format!("Failed to convert disassembled code to string for contract: {contract_path}")
|
format!("Failed to convert disassembled code to string for contract: {contract_path}")
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if let Some(debug_config) = debug_config {
|
debug_config.dump_assembly(contract_path, &assembly_text)?;
|
||||||
debug_config.dump_assembly(contract_path, &assembly_text)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Build::new(
|
Ok(Build::new(
|
||||||
assembly_text.to_owned(),
|
assembly_text.to_owned(),
|
||||||
metadata_hash,
|
metadata_hash,
|
||||||
bytecode.to_owned(),
|
bytecode.to_owned(),
|
||||||
keccak256(bytecode),
|
hex::encode(sha3::Keccak256::digest(bytecode)),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +94,8 @@ pub trait Dependency {
|
|||||||
dependency: Self,
|
dependency: Self,
|
||||||
path: &str,
|
path: &str,
|
||||||
optimizer_settings: OptimizerSettings,
|
optimizer_settings: OptimizerSettings,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: Option<DebugConfig>,
|
debug_config: DebugConfig,
|
||||||
) -> anyhow::Result<String>;
|
) -> anyhow::Result<String>;
|
||||||
|
|
||||||
/// Resolves a full contract path.
|
/// Resolves a full contract path.
|
||||||
@@ -118,9 +114,8 @@ impl Dependency for DummyDependency {
|
|||||||
_dependency: Self,
|
_dependency: Self,
|
||||||
_path: &str,
|
_path: &str,
|
||||||
_optimizer_settings: OptimizerSettings,
|
_optimizer_settings: OptimizerSettings,
|
||||||
_is_system_mode: bool,
|
|
||||||
_include_metadata_hash: bool,
|
_include_metadata_hash: bool,
|
||||||
_debug_config: Option<DebugConfig>,
|
_debug_config: DebugConfig,
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
Ok(String::new())
|
Ok(String::new())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
//! Some LLVM IR generator utilies.
|
|
||||||
|
|
||||||
use crate::polkavm::context::Context;
|
|
||||||
use crate::polkavm::Dependency;
|
|
||||||
|
|
||||||
/// Clamps `value` to `max_value`, if `value` is bigger than `max_value`.
|
|
||||||
pub fn clamp<'ctx, D>(
|
|
||||||
context: &mut Context<'ctx, D>,
|
|
||||||
value: inkwell::values::IntValue<'ctx>,
|
|
||||||
max_value: inkwell::values::IntValue<'ctx>,
|
|
||||||
name: &str,
|
|
||||||
) -> anyhow::Result<inkwell::values::IntValue<'ctx>>
|
|
||||||
where
|
|
||||||
D: Dependency + Clone,
|
|
||||||
{
|
|
||||||
let in_bounds_block = context.append_basic_block(format!("{name}_is_bounds_block").as_str());
|
|
||||||
let join_block = context.append_basic_block(format!("{name}_join_block").as_str());
|
|
||||||
|
|
||||||
let pointer = context.build_alloca(context.word_type(), format!("{name}_pointer").as_str());
|
|
||||||
context.build_store(pointer, max_value)?;
|
|
||||||
|
|
||||||
let is_in_bounds = context.builder().build_int_compare(
|
|
||||||
inkwell::IntPredicate::ULE,
|
|
||||||
value,
|
|
||||||
max_value,
|
|
||||||
format!("{name}_is_in_bounds").as_str(),
|
|
||||||
)?;
|
|
||||||
context.build_conditional_branch(is_in_bounds, in_bounds_block, join_block)?;
|
|
||||||
|
|
||||||
context.set_basic_block(in_bounds_block);
|
|
||||||
context.build_store(pointer, value)?;
|
|
||||||
context.build_unconditional_branch(join_block);
|
|
||||||
|
|
||||||
context.set_basic_block(join_block);
|
|
||||||
let result = context.build_load(pointer, name)?;
|
|
||||||
Ok(result.into_int_value())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Computes the `keccak256` hash for `preimage`.
|
|
||||||
pub fn keccak256(preimage: &[u8]) -> String {
|
|
||||||
use sha3::Digest;
|
|
||||||
|
|
||||||
let hash_bytes = sha3::Keccak256::digest(preimage);
|
|
||||||
hash_bytes
|
|
||||||
.into_iter()
|
|
||||||
.map(|byte| format!("{byte:02x}"))
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join("")
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn keccak256() {
|
|
||||||
assert_eq!(
|
|
||||||
super::keccak256("zksync".as_bytes()),
|
|
||||||
"0238fb1ab06c28c32885f9a4842207ac480c2467df26b6c58e201679628c5a5b"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,28 +20,16 @@ pub struct TargetMachine {
|
|||||||
|
|
||||||
impl TargetMachine {
|
impl TargetMachine {
|
||||||
/// The LLVM target name.
|
/// The LLVM target name.
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
pub const VM_TARGET_NAME: &'static str = "riscv32";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
pub const VM_TARGET_NAME: &'static str = "riscv64";
|
pub const VM_TARGET_NAME: &'static str = "riscv64";
|
||||||
|
|
||||||
/// The LLVM target triple.
|
/// The LLVM target triple.
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
pub const VM_TARGET_TRIPLE: &'static str = "riscv32-unknown-unknown-elf";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
pub const VM_TARGET_TRIPLE: &'static str = "riscv64-unknown-unknown-elf";
|
pub const VM_TARGET_TRIPLE: &'static str = "riscv64-unknown-unknown-elf";
|
||||||
|
|
||||||
/// The LLVM target cpu
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
pub const VM_TARGET_CPU: &'static str = "generic-rv32";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
pub const VM_TARGET_CPU: &'static str = "generic-rv64";
|
pub const VM_TARGET_CPU: &'static str = "generic-rv64";
|
||||||
|
|
||||||
/// LLVM target features.
|
/// LLVM target features.
|
||||||
#[cfg(feature = "riscv-zbb")]
|
pub const VM_FEATURES: &'static str =
|
||||||
pub const VM_FEATURES: &'static str = "+zbb,+e,+m";
|
"+e,+m,+a,+c,+zbb,+auipc-addi-fusion,+ld-add-fusion,+lui-addi-fusion,+xtheadcondmov";
|
||||||
#[cfg(not(feature = "riscv-zbb"))]
|
|
||||||
pub const VM_FEATURES: &'static str = "+e,+m";
|
|
||||||
|
|
||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
/// A separate instance for every optimization level is created.
|
/// A separate instance for every optimization level is created.
|
||||||
@@ -70,12 +58,6 @@ impl TargetMachine {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the target-specific data in the module.
|
|
||||||
pub fn set_target_data(&self, module: &inkwell::module::Module) {
|
|
||||||
module.set_triple(&self.target_machine.get_triple());
|
|
||||||
module.set_data_layout(&self.target_machine.get_target_data().get_data_layout());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Writes the LLVM module to a memory buffer.
|
/// Writes the LLVM module to a memory buffer.
|
||||||
pub fn write_to_memory_buffer(
|
pub fn write_to_memory_buffer(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ impl Target {
|
|||||||
/// Returns the target name.
|
/// Returns the target name.
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
Self::PVM => "riscv32",
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
Self::PVM => "riscv64",
|
Self::PVM => "riscv64",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,9 +20,6 @@ impl Target {
|
|||||||
/// Returns the target triple.
|
/// Returns the target triple.
|
||||||
pub fn triple(&self) -> &str {
|
pub fn triple(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
Self::PVM => "riscv32-unknown-unknown-elf",
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
Self::PVM => "riscv64-unknown-unknown-elf",
|
Self::PVM => "riscv64-unknown-unknown-elf",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,9 +37,6 @@ impl FromStr for Target {
|
|||||||
|
|
||||||
fn from_str(string: &str) -> Result<Self, Self::Err> {
|
fn from_str(string: &str) -> Result<Self, Self::Err> {
|
||||||
match string {
|
match string {
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
"riscv32" => Ok(Self::PVM),
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
"riscv64" => Ok(Self::PVM),
|
"riscv64" => Ok(Self::PVM),
|
||||||
_ => Err(anyhow::anyhow!(
|
_ => Err(anyhow::anyhow!(
|
||||||
"Unknown target `{}`. Supported targets: {:?}",
|
"Unknown target `{}`. Supported targets: {:?}",
|
||||||
@@ -59,9 +50,6 @@ impl FromStr for Target {
|
|||||||
impl std::fmt::Display for Target {
|
impl std::fmt::Display for Target {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
Target::PVM => write!(f, "riscv32"),
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
Target::PVM => write!(f, "riscv64"),
|
Target::PVM => write!(f, "riscv64"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
+23
-12
@@ -26,13 +26,13 @@
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use hex::{FromHex, ToHex};
|
use hex::{FromHex, ToHex};
|
||||||
use pallet_revive::AddressMapper;
|
use pallet_revive::{AddressMapper, ExecReturnValue, InstantiateReturnValue};
|
||||||
use polkadot_sdk::*;
|
use polkadot_sdk::*;
|
||||||
use polkadot_sdk::{
|
use polkadot_sdk::{
|
||||||
pallet_revive::{CollectEvents, ContractExecResult, ContractInstantiateResult, DebugInfo},
|
pallet_revive::{CollectEvents, ContractResult, DebugInfo},
|
||||||
polkadot_runtime_common::BuildStorage,
|
polkadot_runtime_common::BuildStorage,
|
||||||
polkadot_sdk_frame::testing_prelude::*,
|
polkadot_sdk_frame::testing_prelude::*,
|
||||||
sp_core::H160,
|
sp_core::{H160, H256},
|
||||||
sp_keystore::{testing::MemoryKeystore, KeystoreExt},
|
sp_keystore::{testing::MemoryKeystore, KeystoreExt},
|
||||||
sp_runtime::AccountId32,
|
sp_runtime::AccountId32,
|
||||||
};
|
};
|
||||||
@@ -55,7 +55,7 @@ pub const BOB: H160 = H160([2u8; 20]);
|
|||||||
/// The charlie test account
|
/// The charlie test account
|
||||||
pub const CHARLIE: H160 = H160([3u8; 20]);
|
pub const CHARLIE: H160 = H160([3u8; 20]);
|
||||||
/// Default gas limit
|
/// Default gas limit
|
||||||
pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000, 3 * 1024 * 1024);
|
pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000_000, 3 * 1024 * 1024 * 1024);
|
||||||
/// Default deposit limit
|
/// Default deposit limit
|
||||||
pub const DEPOSIT_LIMIT: Balance = 10_000_000;
|
pub const DEPOSIT_LIMIT: Balance = 10_000_000;
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ impl ExtBuilder {
|
|||||||
Self {
|
Self {
|
||||||
balance_genesis_config: value
|
balance_genesis_config: value
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(address, balance)| (AccountId::to_account_id(address), *balance))
|
.map(|(address, balance)| (AccountId::to_fallback_account_id(address), *balance))
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ impl VerifyCallExpectation {
|
|||||||
fn verify(self, result: &CallResult) {
|
fn verify(self, result: &CallResult) {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
self.success,
|
self.success,
|
||||||
result.is_ok(),
|
!result.did_revert(),
|
||||||
"contract execution result mismatch: {result:?}"
|
"contract execution result mismatch: {result:?}"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -179,23 +179,33 @@ impl VerifyCallExpectation {
|
|||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum CallResult {
|
pub enum CallResult {
|
||||||
Exec {
|
Exec {
|
||||||
result: ContractExecResult<Balance, EventRecord>,
|
result: ContractResult<ExecReturnValue, Balance, EventRecord>,
|
||||||
wall_time: Duration,
|
wall_time: Duration,
|
||||||
},
|
},
|
||||||
Instantiate {
|
Instantiate {
|
||||||
result: ContractInstantiateResult<Balance, EventRecord>,
|
result: ContractResult<InstantiateReturnValue, Balance, EventRecord>,
|
||||||
wall_time: Duration,
|
wall_time: Duration,
|
||||||
|
code_hash: H256,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallResult {
|
impl CallResult {
|
||||||
/// Check if the call was successful
|
/// Check if the call was successful
|
||||||
fn is_ok(&self) -> bool {
|
fn did_revert(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Exec { result, .. } => result.result.is_ok(),
|
Self::Exec { result, .. } => result
|
||||||
Self::Instantiate { result, .. } => result.result.is_ok(),
|
.result
|
||||||
|
.as_ref()
|
||||||
|
.map(|r| r.did_revert())
|
||||||
|
.unwrap_or(true),
|
||||||
|
Self::Instantiate { result, .. } => result
|
||||||
|
.result
|
||||||
|
.as_ref()
|
||||||
|
.map(|r| r.result.did_revert())
|
||||||
|
.unwrap_or(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the output of the call
|
/// Get the output of the call
|
||||||
fn output(&self) -> Vec<u8> {
|
fn output(&self) -> Vec<u8> {
|
||||||
match self {
|
match self {
|
||||||
@@ -211,6 +221,7 @@ impl CallResult {
|
|||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the gas consumed by the call
|
/// Get the gas consumed by the call
|
||||||
fn gas_consumed(&self) -> Weight {
|
fn gas_consumed(&self) -> Weight {
|
||||||
match self {
|
match self {
|
||||||
@@ -235,7 +246,7 @@ pub enum Code {
|
|||||||
/// A contract blob
|
/// A contract blob
|
||||||
Bytes(Vec<u8>),
|
Bytes(Vec<u8>),
|
||||||
/// Pre-existing contract hash
|
/// Pre-existing contract hash
|
||||||
Hash(Hash),
|
Hash(crate::runtime::Hash),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Code {
|
impl Default for Code {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use frame_support::runtime;
|
use frame_support::runtime;
|
||||||
|
|
||||||
|
use pallet_revive::AccountId32Mapper;
|
||||||
use polkadot_sdk::*;
|
use polkadot_sdk::*;
|
||||||
use polkadot_sdk::{
|
use polkadot_sdk::{
|
||||||
polkadot_sdk_frame::{log, runtime::prelude::*},
|
polkadot_sdk_frame::{log, runtime::prelude::*},
|
||||||
@@ -7,7 +8,7 @@ use polkadot_sdk::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub type Balance = u128;
|
pub type Balance = u128;
|
||||||
pub type AccountId = pallet_revive::DefaultAddressMapper;
|
pub type AccountId = pallet_revive::AccountId32Mapper<Runtime>;
|
||||||
pub type Block = frame_system::mocking::MockBlock<Runtime>;
|
pub type Block = frame_system::mocking::MockBlock<Runtime>;
|
||||||
pub type Hash = <Runtime as frame_system::Config>::Hash;
|
pub type Hash = <Runtime as frame_system::Config>::Hash;
|
||||||
pub type EventRecord =
|
pub type EventRecord =
|
||||||
@@ -74,11 +75,13 @@ impl pallet_revive::Config for Runtime {
|
|||||||
type ChainExtension = ();
|
type ChainExtension = ();
|
||||||
type DepositPerByte = DepositPerByte;
|
type DepositPerByte = DepositPerByte;
|
||||||
type DepositPerItem = DepositPerItem;
|
type DepositPerItem = DepositPerItem;
|
||||||
type AddressMapper = AccountId;
|
type AddressMapper = AccountId32Mapper<Self>;
|
||||||
|
type RuntimeMemory = ConstU32<{ 512 * 1024 * 1024 }>;
|
||||||
|
type PVFMemory = ConstU32<{ 1024 * 1024 * 1024 }>;
|
||||||
type UnsafeUnstableInterface = UnstableInterface;
|
type UnsafeUnstableInterface = UnstableInterface;
|
||||||
type UploadOrigin = EnsureSigned<AccountId32>;
|
type UploadOrigin = EnsureSigned<AccountId32>;
|
||||||
type InstantiateOrigin = EnsureSigned<AccountId32>;
|
type InstantiateOrigin = EnsureSigned<AccountId32>;
|
||||||
type Migrations = ();
|
|
||||||
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
|
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
|
||||||
type Debug = ();
|
type Debug = ();
|
||||||
|
type ChainId = ConstU64<420_420_420>;
|
||||||
}
|
}
|
||||||
|
|||||||
+65
-24
@@ -1,10 +1,9 @@
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use pallet_revive::AddressMapper;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use alloy_primitives::Address;
|
use alloy_primitives::{keccak256, Address};
|
||||||
#[cfg(feature = "revive-solidity")]
|
#[cfg(feature = "revive-solidity")]
|
||||||
use revive_differential::{Evm, EvmLog};
|
use revive_differential::{Evm, EvmLog};
|
||||||
#[cfg(feature = "revive-solidity")]
|
#[cfg(feature = "revive-solidity")]
|
||||||
@@ -58,7 +57,6 @@ pub enum SpecsAction {
|
|||||||
},
|
},
|
||||||
/// Verify the result of the last call, omitting this will simply ensure the last call was successful
|
/// Verify the result of the last call, omitting this will simply ensure the last call was successful
|
||||||
VerifyCall(VerifyCallExpectation),
|
VerifyCall(VerifyCallExpectation),
|
||||||
|
|
||||||
/// Verify the balance of an account
|
/// Verify the balance of an account
|
||||||
VerifyBalance {
|
VerifyBalance {
|
||||||
origin: TestAddress,
|
origin: TestAddress,
|
||||||
@@ -179,7 +177,11 @@ impl Default for Specs {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
differential: false,
|
differential: false,
|
||||||
balances: vec![(ALICE, 1_000_000_000)],
|
balances: vec![
|
||||||
|
(ALICE, 1_000_000_000),
|
||||||
|
(BOB, 1_000_000_000),
|
||||||
|
(CHARLIE, 1_000_000_000),
|
||||||
|
],
|
||||||
actions: Default::default(),
|
actions: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,10 +274,10 @@ impl Specs {
|
|||||||
origin,
|
origin,
|
||||||
value,
|
value,
|
||||||
gas_limit,
|
gas_limit,
|
||||||
storage_deposit_limit,
|
|
||||||
code,
|
code,
|
||||||
data,
|
data,
|
||||||
salt,
|
salt,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
let Code::Solidity {
|
let Code::Solidity {
|
||||||
path: Some(path),
|
path: Some(path),
|
||||||
@@ -286,21 +288,37 @@ impl Specs {
|
|||||||
else {
|
else {
|
||||||
panic!("the differential runner requires Code::Solidity source");
|
panic!("the differential runner requires Code::Solidity source");
|
||||||
};
|
};
|
||||||
assert_ne!(solc_optimizer, Some(false), "solc_optimizer must be enabled in differntial mode");
|
assert_ne!(
|
||||||
assert_ne!(pipeline, Some(revive_solidity::SolcPipeline::EVMLA), "yul pipeline must be enabled in differntial mode");
|
pipeline,
|
||||||
assert!(storage_deposit_limit.is_none(), "storage deposit limit is not supported in differential mode");
|
Some(revive_solidity::SolcPipeline::EVMLA),
|
||||||
assert!(salt.0.is_none(), "salt is not supported in differential mode");
|
"yul pipeline must be enabled in differential mode"
|
||||||
assert_eq!(origin, TestAddress::default(), "configuring the origin is not supported in differential mode");
|
);
|
||||||
|
assert!(
|
||||||
|
salt.0.is_none(),
|
||||||
|
"salt is not supported in differential mode"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
origin,
|
||||||
|
TestAddress::default(),
|
||||||
|
"configuring the origin is not supported in differential mode"
|
||||||
|
);
|
||||||
|
|
||||||
let deploy_code = match std::fs::read_to_string(&path) {
|
let deploy_code = match std::fs::read_to_string(&path) {
|
||||||
Ok(solidity_source) => compile_evm_deploy_code(&contract, &solidity_source),
|
Ok(solidity_source) => hex::encode(compile_evm_deploy_code(
|
||||||
|
&contract,
|
||||||
|
&solidity_source,
|
||||||
|
solc_optimizer.unwrap_or(true),
|
||||||
|
)),
|
||||||
Err(err) => panic!(
|
Err(err) => panic!(
|
||||||
"failed to read solidity source\n . path: '{}'\n . error: {:?}",
|
"failed to read solidity source\n . path: '{}'\n . error: {:?}",
|
||||||
path.display(),
|
path.display(),
|
||||||
err
|
err
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
let deploy_code = hex::encode(deploy_code);
|
let mut vm = evm
|
||||||
let mut vm = evm.code_blob(deploy_code.as_bytes().to_vec()).sender(origin.to_eth_addr(&[]).0.into()).deploy(true);
|
.code_blob(deploy_code.as_bytes().to_vec())
|
||||||
|
.sender(origin.to_eth_addr(&[]).0.into())
|
||||||
|
.deploy(true);
|
||||||
if !data.is_empty() {
|
if !data.is_empty() {
|
||||||
vm = vm.input(data.into());
|
vm = vm.input(data.into());
|
||||||
}
|
}
|
||||||
@@ -315,7 +333,13 @@ impl Specs {
|
|||||||
let deployed_account = log.account_deployed.expect("no account was created");
|
let deployed_account = log.account_deployed.expect("no account was created");
|
||||||
let account_pvm = TestAddress::Instantiated(deployed_accounts.len());
|
let account_pvm = TestAddress::Instantiated(deployed_accounts.len());
|
||||||
deployed_accounts.push(deployed_account);
|
deployed_accounts.push(deployed_account);
|
||||||
derived_specs.actions.append(&mut SpecsAction::derive_verification(&log, deployed_account, account_pvm));
|
derived_specs
|
||||||
|
.actions
|
||||||
|
.append(&mut SpecsAction::derive_verification(
|
||||||
|
&log,
|
||||||
|
deployed_account,
|
||||||
|
account_pvm,
|
||||||
|
));
|
||||||
evm = Evm::from_genesis(log.state_dump.into());
|
evm = Evm::from_genesis(log.state_dump.into());
|
||||||
}
|
}
|
||||||
Call {
|
Call {
|
||||||
@@ -323,16 +347,23 @@ impl Specs {
|
|||||||
dest,
|
dest,
|
||||||
value,
|
value,
|
||||||
gas_limit,
|
gas_limit,
|
||||||
storage_deposit_limit,
|
|
||||||
data,
|
data,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(origin, TestAddress::default(), "configuring the origin is not supported in differential mode");
|
assert_eq!(
|
||||||
assert!(storage_deposit_limit.is_none(), "storage deposit limit is not supported in differential mode");
|
origin,
|
||||||
|
TestAddress::default(),
|
||||||
|
"configuring the origin is not supported in differential mode"
|
||||||
|
);
|
||||||
let TestAddress::Instantiated(n) = dest else {
|
let TestAddress::Instantiated(n) = dest else {
|
||||||
panic!("the differential runner requires TestAccountId::Instantiated(n) as dest");
|
panic!("the differential runner requires TestAccountId::Instantiated(n) as dest");
|
||||||
};
|
};
|
||||||
let address = deployed_accounts.get(n).unwrap_or_else(|| panic!("no account at index {n} "));
|
let address = deployed_accounts
|
||||||
let mut vm = evm.receiver(*address).sender(origin.to_eth_addr(&[]).0.into());
|
.get(n)
|
||||||
|
.unwrap_or_else(|| panic!("no account at index {n} "));
|
||||||
|
let mut vm = evm
|
||||||
|
.receiver(*address)
|
||||||
|
.sender(origin.to_eth_addr(&[]).0.into());
|
||||||
if !data.is_empty() {
|
if !data.is_empty() {
|
||||||
vm = vm.input(data.into());
|
vm = vm.input(data.into());
|
||||||
}
|
}
|
||||||
@@ -344,10 +375,13 @@ impl Specs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let log = vm.run();
|
let log = vm.run();
|
||||||
derived_specs.actions.append(&mut SpecsAction::derive_verification(&log, *address, dest));
|
derived_specs
|
||||||
|
.actions
|
||||||
|
.append(&mut SpecsAction::derive_verification(&log, *address, dest));
|
||||||
evm = Evm::from_genesis(log.state_dump.into());
|
evm = Evm::from_genesis(log.state_dump.into());
|
||||||
}
|
}
|
||||||
_ => panic!("only instantiate and call action allowed in differential mode, got: {action:?}"),
|
Upload { .. } => continue,
|
||||||
|
other => derived_specs.actions.push(other),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,6 +408,13 @@ impl Specs {
|
|||||||
data,
|
data,
|
||||||
salt,
|
salt,
|
||||||
} => {
|
} => {
|
||||||
|
let code: pallet_revive::Code = code.into();
|
||||||
|
let code_hash = match code.clone() {
|
||||||
|
pallet_revive::Code::Existing(code_hash) => code_hash,
|
||||||
|
pallet_revive::Code::Upload(bytes) => {
|
||||||
|
H256::from_slice(keccak256(&bytes).as_slice())
|
||||||
|
}
|
||||||
|
};
|
||||||
let origin = RuntimeOrigin::signed(origin.to_account_id(&results));
|
let origin = RuntimeOrigin::signed(origin.to_account_id(&results));
|
||||||
let time_start = Instant::now();
|
let time_start = Instant::now();
|
||||||
let result = Contracts::bare_instantiate(
|
let result = Contracts::bare_instantiate(
|
||||||
@@ -381,7 +422,7 @@ impl Specs {
|
|||||||
value,
|
value,
|
||||||
gas_limit.unwrap_or(GAS_LIMIT),
|
gas_limit.unwrap_or(GAS_LIMIT),
|
||||||
storage_deposit_limit.unwrap_or(DEPOSIT_LIMIT),
|
storage_deposit_limit.unwrap_or(DEPOSIT_LIMIT),
|
||||||
code.into(),
|
code,
|
||||||
data,
|
data,
|
||||||
salt.0,
|
salt.0,
|
||||||
DebugInfo::Skip,
|
DebugInfo::Skip,
|
||||||
@@ -390,6 +431,7 @@ impl Specs {
|
|||||||
results.push(CallResult::Instantiate {
|
results.push(CallResult::Instantiate {
|
||||||
result,
|
result,
|
||||||
wall_time: time_start.elapsed(),
|
wall_time: time_start.elapsed(),
|
||||||
|
code_hash,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Upload {
|
Upload {
|
||||||
@@ -402,7 +444,7 @@ impl Specs {
|
|||||||
pallet_revive::Code::Existing(_) => continue,
|
pallet_revive::Code::Existing(_) => continue,
|
||||||
pallet_revive::Code::Upload(bytes) => bytes,
|
pallet_revive::Code::Upload(bytes) => bytes,
|
||||||
},
|
},
|
||||||
storage_deposit_limit.unwrap_or_default(),
|
storage_deposit_limit.unwrap_or(DEPOSIT_LIMIT),
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|error| panic!("code upload failed: {error:?}")),
|
.unwrap_or_else(|error| panic!("code upload failed: {error:?}")),
|
||||||
Call {
|
Call {
|
||||||
@@ -442,7 +484,6 @@ impl Specs {
|
|||||||
expected,
|
expected,
|
||||||
} => {
|
} => {
|
||||||
let address = contract.to_eth_addr(&results);
|
let address = contract.to_eth_addr(&results);
|
||||||
dbg!(contract.to_account_id(&results));
|
|
||||||
let Ok(value) = Contracts::get_storage(address, key) else {
|
let Ok(value) = Contracts::get_storage(address, key) else {
|
||||||
panic!("error reading storage for address {address}");
|
panic!("error reading storage for address {address}");
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ repository.workspace = true
|
|||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
description = "Implements the low level runtime API bindings with pallet contracts"
|
description = "Implements the low level runtime API bindings with pallet contracts"
|
||||||
|
|
||||||
[features]
|
|
||||||
riscv-64 = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm18-0"] }
|
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm18-0"] }
|
||||||
|
|
||||||
|
revive-common = { workspace = true }
|
||||||
|
|||||||
@@ -1,23 +1,8 @@
|
|||||||
use std::{env, fs, path::Path, process::Command};
|
use std::{env, fs, path::Path, process::Command};
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
const TARGET_TRIPLE_FLAG: &str = "-triple=riscv32-unknown-unknown-elf";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
const TARGET_TRIPLE_FLAG: &str = "-triple=riscv64-unknown-unknown-elf";
|
const TARGET_TRIPLE_FLAG: &str = "-triple=riscv64-unknown-unknown-elf";
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
const TARGET_FLAG: &str = "--target=riscv32";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
const TARGET_FLAG: &str = "--target=riscv64";
|
const TARGET_FLAG: &str = "--target=riscv64";
|
||||||
|
const TARGET_ARCH_FLAG: &str = "-march=rv64emac";
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
const TARGET_ARCH_FLAG: &str = "-march=rv32em";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
const TARGET_ARCH_FLAG: &str = "-march=rv64em";
|
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
const TARGET_ABI_FLAG: &str = "-mabi=ilp32e";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
const TARGET_ABI_FLAG: &str = "-mabi=lp64e";
|
const TARGET_ABI_FLAG: &str = "-mabi=lp64e";
|
||||||
|
|
||||||
const IMPORTS_SOUCE: &str = "src/polkavm_imports.c";
|
const IMPORTS_SOUCE: &str = "src/polkavm_imports.c";
|
||||||
@@ -36,6 +21,10 @@ fn compile(source_path: &str, bitcode_path: &str) {
|
|||||||
TARGET_TRIPLE_FLAG,
|
TARGET_TRIPLE_FLAG,
|
||||||
TARGET_ARCH_FLAG,
|
TARGET_ARCH_FLAG,
|
||||||
TARGET_ABI_FLAG,
|
TARGET_ABI_FLAG,
|
||||||
|
"-Xclang",
|
||||||
|
"-target-feature",
|
||||||
|
"-Xclang",
|
||||||
|
"+fast-unaligned-access,+xtheadcondmov",
|
||||||
"-fno-exceptions",
|
"-fno-exceptions",
|
||||||
"-ffreestanding",
|
"-ffreestanding",
|
||||||
"-Wall",
|
"-Wall",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use inkwell::{
|
|||||||
context::Context,
|
context::Context,
|
||||||
module::Module,
|
module::Module,
|
||||||
types::{BasicType, StructType},
|
types::{BasicType, StructType},
|
||||||
values::{BasicValue, PointerValue},
|
values::{BasicValueEnum, PointerValue},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Creates a module that sets the PolkaVM minimum stack size to [`size`] if linked in.
|
/// Creates a module that sets the PolkaVM minimum stack size to [`size`] if linked in.
|
||||||
@@ -21,114 +21,115 @@ pub fn min_stack_size<'context>(
|
|||||||
module
|
module
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Spill<'a, 'ctx> {
|
/// Helper for building function calls with stack spilled arguments.
|
||||||
|
/// - `pointer`: points to a struct of the packed argument struct type
|
||||||
|
/// - `type`: the packed argument struct type
|
||||||
|
/// - `arguments`: a correctly ordered list of the struct field values
|
||||||
|
pub fn spill<'ctx>(
|
||||||
|
builder: &Builder<'ctx>,
|
||||||
pointer: PointerValue<'ctx>,
|
pointer: PointerValue<'ctx>,
|
||||||
builder: &'a Builder<'ctx>,
|
|
||||||
r#type: StructType<'ctx>,
|
r#type: StructType<'ctx>,
|
||||||
current_field: u32,
|
arguments: &[BasicValueEnum<'ctx>],
|
||||||
}
|
) -> anyhow::Result<()> {
|
||||||
|
for index in 0..r#type.get_field_types().len() {
|
||||||
impl<'a, 'ctx> Spill<'a, 'ctx> {
|
let field_pointer = builder.build_struct_gep(
|
||||||
pub fn new(
|
|
||||||
builder: &'a Builder<'ctx>,
|
|
||||||
r#type: StructType<'ctx>,
|
|
||||||
name: &str,
|
|
||||||
) -> anyhow::Result<Self> {
|
|
||||||
Ok(Self {
|
|
||||||
pointer: builder.build_alloca(r#type, name)?,
|
|
||||||
builder,
|
|
||||||
r#type,
|
r#type,
|
||||||
current_field: 0,
|
pointer,
|
||||||
})
|
index as u32,
|
||||||
}
|
&format!("spill_parameter_{}", index),
|
||||||
|
|
||||||
pub fn next<V: BasicValue<'ctx>>(mut self, value: V) -> anyhow::Result<Self> {
|
|
||||||
let field_pointer = self.builder.build_struct_gep(
|
|
||||||
self.r#type,
|
|
||||||
self.pointer,
|
|
||||||
self.current_field,
|
|
||||||
&format!("spill_parameter_{}", self.current_field),
|
|
||||||
)?;
|
)?;
|
||||||
self.builder.build_store(field_pointer, value)?;
|
let field_value = arguments
|
||||||
self.current_field += 1;
|
.get(index)
|
||||||
Ok(self)
|
.ok_or_else(|| anyhow::anyhow!("invalid index {index} for struct type {}", r#type))?;
|
||||||
|
builder.build_store(field_pointer, *field_value)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn skip(mut self) -> Self {
|
Ok(())
|
||||||
self.current_field += 1;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn done(self) -> PointerValue<'ctx> {
|
|
||||||
assert!(
|
|
||||||
self.r#type
|
|
||||||
.get_field_type_at_index(self.current_field)
|
|
||||||
.is_none(),
|
|
||||||
"there must not be any missing parameters"
|
|
||||||
);
|
|
||||||
|
|
||||||
self.pointer
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a packed struct argument type for the `instantiate` API.
|
||||||
pub fn instantiate(context: &Context) -> StructType {
|
pub fn instantiate(context: &Context) -> StructType {
|
||||||
context.struct_type(
|
context.struct_type(
|
||||||
&[
|
&[
|
||||||
// code_hash_ptr: u32,
|
// code_hash_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// ref_time_limit: u64,
|
// ref_time_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// proof_size_limit: u64,
|
// proof_size_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// deposit_ptr: u32,
|
// deposit_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// value_ptr: u32,
|
// value_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// input_data_ptr: u32,
|
// input_data_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// input_data_len: u32,
|
// input_data_len: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// address_ptr: u32,
|
// address_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// address_len_ptr: u32,
|
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
|
||||||
// output_ptr: u32,
|
// output_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// output_len_ptr: u32,
|
// output_len_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// salt_ptr: u32,
|
// salt_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
|
||||||
// salt_len: u32
|
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
],
|
],
|
||||||
true,
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a packed struct argument type for the `call` API.
|
||||||
pub fn call(context: &Context) -> StructType {
|
pub fn call(context: &Context) -> StructType {
|
||||||
context.struct_type(
|
context.struct_type(
|
||||||
&[
|
&[
|
||||||
// flags: u32,
|
// flags: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// address_ptr:
|
// address_ptr:
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// ref_time_limit: u64,
|
// ref_time_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// proof_size_limit: u64,
|
// proof_size_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// deposit_ptr: u32,
|
// deposit_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// value_ptr: u32,
|
// value_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// input_data_ptr: u32,
|
// input_data_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// input_data_len: u32,
|
// input_data_len: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// output_ptr: u32,
|
// output_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// output_len_ptr: u32,
|
// output_len_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
],
|
],
|
||||||
true,
|
false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a packed struct argument type for the `delegate_call` API.
|
||||||
|
pub fn delegate_call(context: &Context) -> StructType {
|
||||||
|
context.struct_type(
|
||||||
|
&[
|
||||||
|
// flags: u32,
|
||||||
|
context.i32_type().as_basic_type_enum(),
|
||||||
|
// address_ptr:
|
||||||
|
context.i32_type().as_basic_type_enum(),
|
||||||
|
// ref_time_limit: u64,
|
||||||
|
context.i64_type().as_basic_type_enum(),
|
||||||
|
// proof_size_limit: u64,
|
||||||
|
context.i64_type().as_basic_type_enum(),
|
||||||
|
// deposit_ptr: u32,
|
||||||
|
context.i32_type().as_basic_type_enum(),
|
||||||
|
// input_data_ptr: u32,
|
||||||
|
context.i32_type().as_basic_type_enum(),
|
||||||
|
// input_data_len: u32,
|
||||||
|
context.i32_type().as_basic_type_enum(),
|
||||||
|
// output_ptr: u32,
|
||||||
|
context.i32_type().as_basic_type_enum(),
|
||||||
|
// output_len_ptr: u32,
|
||||||
|
context.i32_type().as_basic_type_enum(),
|
||||||
|
],
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
//! Allocates memory for the immutable data in a separate module.
|
||||||
|
//!
|
||||||
|
//! Because we only know how many immutable variables were set after
|
||||||
|
//! translating the whole contract code, we want to set the size at
|
||||||
|
//! last. However, array types need a size upon declaration.
|
||||||
|
//!
|
||||||
|
//! A simple work around is to replace it during link time.
|
||||||
|
//! To quote the [LLVM docs][0]:
|
||||||
|
//!
|
||||||
|
//! > For global variable declarations [..] the allocation size and
|
||||||
|
//! > alignment of the definition it resolves to must be greater than
|
||||||
|
//! > or equal to that of the declaration [..]
|
||||||
|
//!
|
||||||
|
//! To adhere to this we initially declare a length of 0 in
|
||||||
|
//! `revive-llvm-context`.
|
||||||
|
//!
|
||||||
|
//! [0]: https://llvm.org/docs/LangRef.html#global-variables
|
||||||
|
|
||||||
|
/// The immutable data module name.
|
||||||
|
pub static MODULE_NAME: &str = "__evm_immutables";
|
||||||
|
/// The immutable data global pointer.
|
||||||
|
pub static GLOBAL_IMMUTABLE_DATA_POINTER: &str = "__immutable_data_ptr";
|
||||||
|
/// The immutable data global size.
|
||||||
|
pub static GLOBAL_IMMUTABLE_DATA_SIZE: &str = "__immutable_data_size";
|
||||||
|
/// The immutable data maximum size in bytes.
|
||||||
|
pub static IMMUTABLE_DATA_MAX_SIZE: u32 = 4 * 1024;
|
||||||
|
|
||||||
|
/// Returns the immutable data global type.
|
||||||
|
pub fn data_type(context: &inkwell::context::Context, size: u32) -> inkwell::types::ArrayType {
|
||||||
|
context
|
||||||
|
.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
|
.array_type(size)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the immutable data size global type.
|
||||||
|
pub fn size_type(context: &inkwell::context::Context) -> inkwell::types::IntType {
|
||||||
|
context.custom_width_int_type(revive_common::BIT_LENGTH_X32 as u32)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a LLVM module with the immutable data and its `size` in bytes.
|
||||||
|
pub fn module(context: &inkwell::context::Context, size: u32) -> inkwell::module::Module {
|
||||||
|
let module = context.create_module(MODULE_NAME);
|
||||||
|
let length = size / revive_common::BYTE_LENGTH_WORD as u32;
|
||||||
|
|
||||||
|
let immutable_data = module.add_global(
|
||||||
|
data_type(context, length),
|
||||||
|
Default::default(),
|
||||||
|
GLOBAL_IMMUTABLE_DATA_POINTER,
|
||||||
|
);
|
||||||
|
immutable_data.set_linkage(inkwell::module::Linkage::External);
|
||||||
|
immutable_data.set_visibility(inkwell::GlobalVisibility::Default);
|
||||||
|
immutable_data.set_initializer(&data_type(context, length).get_undef());
|
||||||
|
|
||||||
|
let immutable_data_size = module.add_global(
|
||||||
|
size_type(context),
|
||||||
|
Default::default(),
|
||||||
|
GLOBAL_IMMUTABLE_DATA_SIZE,
|
||||||
|
);
|
||||||
|
immutable_data_size.set_linkage(inkwell::module::Linkage::External);
|
||||||
|
immutable_data_size.set_visibility(inkwell::GlobalVisibility::Default);
|
||||||
|
immutable_data_size.set_initializer(&size_type(context).const_int(size as u64, false));
|
||||||
|
|
||||||
|
module
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::immutable_data::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
inkwell::targets::Target::initialize_riscv(&Default::default());
|
||||||
|
let context = inkwell::context::Context::create();
|
||||||
|
let size = 512;
|
||||||
|
let module = crate::immutable_data::module(&context, size);
|
||||||
|
|
||||||
|
let immutable_data_pointer = module.get_global(GLOBAL_IMMUTABLE_DATA_POINTER).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
immutable_data_pointer.get_initializer().unwrap(),
|
||||||
|
data_type(&context, size / 32).get_undef()
|
||||||
|
);
|
||||||
|
|
||||||
|
let immutable_data_size = module.get_global(GLOBAL_IMMUTABLE_DATA_SIZE).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
immutable_data_size.get_initializer().unwrap(),
|
||||||
|
size_type(&context).const_int(size as u64, false)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,5 +7,6 @@
|
|||||||
//! [1]: [https://docs.rs/pallet-contracts/26.0.0/pallet_contracts/api_doc/index.html]
|
//! [1]: [https://docs.rs/pallet-contracts/26.0.0/pallet_contracts/api_doc/index.html]
|
||||||
|
|
||||||
pub mod calling_convention;
|
pub mod calling_convention;
|
||||||
|
pub mod immutable_data;
|
||||||
pub mod polkavm_exports;
|
pub mod polkavm_exports;
|
||||||
pub mod polkavm_imports;
|
pub mod polkavm_imports;
|
||||||
|
|||||||
@@ -2,6 +2,16 @@ use inkwell::{context::Context, memory_buffer::MemoryBuffer, module::Module, sup
|
|||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/polkavm_exports.rs"));
|
include!(concat!(env!("OUT_DIR"), "/polkavm_exports.rs"));
|
||||||
|
|
||||||
|
/// The contract deploy export.
|
||||||
|
pub static CALL: &str = "call";
|
||||||
|
|
||||||
|
/// The contract call export.
|
||||||
|
pub static DEPLOY: &str = "deploy";
|
||||||
|
|
||||||
|
/// All exported symbols.
|
||||||
|
/// Useful for configuring common attributes and linkage.
|
||||||
|
pub static EXPORTS: [&str; 2] = [CALL, DEPLOY];
|
||||||
|
|
||||||
/// Creates a LLVM module from the [BITCODE].
|
/// Creates a LLVM module from the [BITCODE].
|
||||||
/// The module exports `call` and `deploy` functions (which are named thereafter).
|
/// The module exports `call` and `deploy` functions (which are named thereafter).
|
||||||
/// Returns `Error` if the bitcode fails to parse, which should never happen.
|
/// Returns `Error` if the bitcode fails to parse, which should never happen.
|
||||||
@@ -23,7 +33,7 @@ mod tests {
|
|||||||
let context = inkwell::context::Context::create();
|
let context = inkwell::context::Context::create();
|
||||||
let module = polkavm_exports::module(&context, "polkavm_exports").unwrap();
|
let module = polkavm_exports::module(&context, "polkavm_exports").unwrap();
|
||||||
|
|
||||||
assert!(module.get_function("call").is_some());
|
assert!(module.get_function(polkavm_exports::CALL).is_some());
|
||||||
assert!(module.get_function("deploy").is_some());
|
assert!(module.get_function(polkavm_exports::DEPLOY).is_some());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,11 @@
|
|||||||
|
|
||||||
#define POLKAVM_REGS_FOR_TY_void 0
|
#define POLKAVM_REGS_FOR_TY_void 0
|
||||||
#define POLKAVM_REGS_FOR_TY_i32 1
|
#define POLKAVM_REGS_FOR_TY_i32 1
|
||||||
#define POLKAVM_REGS_FOR_TY_i64 2
|
#ifdef _LP64
|
||||||
|
#define POLKAVM_REGS_FOR_TY_i64 1
|
||||||
|
#else
|
||||||
|
#define POLKAVM_REGS_FOR_TY_i64 2
|
||||||
|
#endif
|
||||||
|
|
||||||
#define POLKAVM_REGS_FOR_TY_int8_t POLKAVM_REGS_FOR_TY_i32
|
#define POLKAVM_REGS_FOR_TY_int8_t POLKAVM_REGS_FOR_TY_i32
|
||||||
#define POLKAVM_REGS_FOR_TY_uint8_t POLKAVM_REGS_FOR_TY_i32
|
#define POLKAVM_REGS_FOR_TY_uint8_t POLKAVM_REGS_FOR_TY_i32
|
||||||
@@ -107,6 +111,26 @@ struct PolkaVM_Metadata {
|
|||||||
unsigned char output_regs;
|
unsigned char output_regs;
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
#ifdef _LP64
|
||||||
|
#define POLKAVM_EXPORT_DEF() \
|
||||||
|
".quad %[metadata]\n" \
|
||||||
|
".quad %[function]\n"
|
||||||
|
#else
|
||||||
|
#define POLKAVM_EXPORT_DEF() \
|
||||||
|
".word %[metadata]\n" \
|
||||||
|
".word %[function]\n"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _LP64
|
||||||
|
#define POLKAVM_IMPORT_DEF() \
|
||||||
|
".word 0x0000000b\n" \
|
||||||
|
".quad %[metadata]\n"
|
||||||
|
#else
|
||||||
|
#define POLKAVM_IMPORT_DEF() \
|
||||||
|
".word 0x0000000b\n" \
|
||||||
|
".word %[metadata]\n"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define POLKAVM_EXPORT(arg_return_ty, fn_name, ...) \
|
#define POLKAVM_EXPORT(arg_return_ty, fn_name, ...) \
|
||||||
static struct PolkaVM_Metadata POLKAVM_JOIN(fn_name, __EXPORT_METADATA) __attribute__ ((section(".polkavm_metadata"))) = { \
|
static struct PolkaVM_Metadata POLKAVM_JOIN(fn_name, __EXPORT_METADATA) __attribute__ ((section(".polkavm_metadata"))) = { \
|
||||||
1, 0, sizeof(#fn_name) - 1, #fn_name, POLKAVM_COUNT_REGS(__VA_ARGS__), POLKAVM_COUNT_REGS(arg_return_ty) \
|
1, 0, sizeof(#fn_name) - 1, #fn_name, POLKAVM_COUNT_REGS(__VA_ARGS__), POLKAVM_COUNT_REGS(arg_return_ty) \
|
||||||
@@ -115,8 +139,7 @@ static void __attribute__ ((naked, used)) POLKAVM_UNIQUE(polkavm_export_dummy)()
|
|||||||
__asm__( \
|
__asm__( \
|
||||||
".pushsection .polkavm_exports,\"R\",@note\n" \
|
".pushsection .polkavm_exports,\"R\",@note\n" \
|
||||||
".byte 1\n" \
|
".byte 1\n" \
|
||||||
".word %[metadata]\n" \
|
POLKAVM_EXPORT_DEF() \
|
||||||
".word %[function]\n" \
|
|
||||||
".popsection\n" \
|
".popsection\n" \
|
||||||
: \
|
: \
|
||||||
: \
|
: \
|
||||||
@@ -130,10 +153,9 @@ static void __attribute__ ((naked, used)) POLKAVM_UNIQUE(polkavm_export_dummy)()
|
|||||||
static struct PolkaVM_Metadata POLKAVM_JOIN(fn_name, __IMPORT_METADATA) __attribute__ ((section(".polkavm_metadata"))) = { \
|
static struct PolkaVM_Metadata POLKAVM_JOIN(fn_name, __IMPORT_METADATA) __attribute__ ((section(".polkavm_metadata"))) = { \
|
||||||
1, 0, sizeof(#fn_name) - 1, #fn_name, POLKAVM_COUNT_REGS(__VA_ARGS__), POLKAVM_COUNT_REGS(arg_return_ty) \
|
1, 0, sizeof(#fn_name) - 1, #fn_name, POLKAVM_COUNT_REGS(__VA_ARGS__), POLKAVM_COUNT_REGS(arg_return_ty) \
|
||||||
}; \
|
}; \
|
||||||
static arg_return_ty __attribute__ ((naked, used)) fn_name(POLKAVM_IMPORT_ARGS_IMPL(__VA_ARGS__)) { \
|
static arg_return_ty __attribute__ ((used, naked)) fn_name(POLKAVM_IMPORT_ARGS_IMPL(__VA_ARGS__)) { \
|
||||||
__asm__( \
|
__asm__( \
|
||||||
".word 0x0000000b\n" \
|
POLKAVM_IMPORT_DEF() \
|
||||||
".word %[metadata]\n" \
|
|
||||||
"ret\n" \
|
"ret\n" \
|
||||||
: \
|
: \
|
||||||
: \
|
: \
|
||||||
|
|||||||
@@ -3,9 +3,34 @@
|
|||||||
|
|
||||||
#include "polkavm_guest.h"
|
#include "polkavm_guest.h"
|
||||||
|
|
||||||
|
|
||||||
// Missing builtins
|
// Missing builtins
|
||||||
|
|
||||||
|
#define EVM_WORD_SIZE 32
|
||||||
|
#define ALIGN(size) ((size + EVM_WORD_SIZE - 1) & ~(EVM_WORD_SIZE - 1))
|
||||||
|
#define MAX_MEMORY_SIZE (64 * 1024)
|
||||||
|
static char __memory[MAX_MEMORY_SIZE];
|
||||||
|
static uint32_t __memory_size = 0;
|
||||||
|
|
||||||
|
void * __sbrk_internal(uint32_t offset, uint32_t size) {
|
||||||
|
if (offset >= MAX_MEMORY_SIZE || size > MAX_MEMORY_SIZE) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t new_size = ALIGN(offset + size);
|
||||||
|
if (new_size > MAX_MEMORY_SIZE) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (new_size > __memory_size) {
|
||||||
|
__memory_size = new_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (void *)&__memory[__memory_size];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t __msize() {
|
||||||
|
return __memory_size;
|
||||||
|
}
|
||||||
|
|
||||||
void * memset(void *b, int c, size_t len) {
|
void * memset(void *b, int c, size_t len) {
|
||||||
uint8_t *dest = b;
|
uint8_t *dest = b;
|
||||||
while (len-- > 0) *dest++ = c;
|
while (len-- > 0) *dest++ = c;
|
||||||
@@ -37,90 +62,56 @@ void * memmove(void *dst, const void *src, size_t n) {
|
|||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
void * __sbrk(uint32_t size) {
|
|
||||||
uint32_t address;
|
|
||||||
__asm__ __volatile__(
|
|
||||||
".insn r 0xb, 1, 0, %[dst], %[sz], zero"
|
|
||||||
: [dst] "=r" (address)
|
|
||||||
: [sz] "ir" (size)
|
|
||||||
:
|
|
||||||
);
|
|
||||||
return (void *)address;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Imports
|
// Imports
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, input, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, address, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, balance, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, returndatacopy, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, balance_of, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, value_transferred, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, block_hash, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, block_number, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, get_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(uint64_t, call, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, clear_storage, uint32_t, uint32_t)
|
POLKAVM_IMPORT(uint64_t, delegate_call, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, contains_storage, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, caller, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, take_storage, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, chain_id, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, call, uint32_t)
|
POLKAVM_IMPORT(void, code_size, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, delegate_call, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, code_hash, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, instantiate, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, terminate, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, caller, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, is_contract, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, code_hash, uint32_t, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, code_size, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, own_code_hash, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, caller_is_origin)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, caller_is_root)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, address, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, weight_to_fee, uint64_t, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, gas_left, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, balance, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, now, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, minimum_balance, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, deposit_event, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, deposit_event, uint32_t, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, block_number, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, get_immutable_data, uint32_t, uint32_t);
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, hash_sha2_256, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(uint64_t, get_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, hash_keccak_256, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, hash_keccak_256, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, hash_blake2_256, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, input, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, hash_blake2_128, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(uint64_t, instantiate, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, call_chain_extension, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, now, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, debug_message, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, origin, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, set_code_hash, uint32_t)
|
POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint64_t, instantiation_nonce,)
|
POLKAVM_IMPORT(uint64_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, transfer, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, return_data_copy, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, return_data_size, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, set_immutable_data, uint32_t, uint32_t);
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, value_transferred, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, weight_to_fee, uint64_t, uint64_t, uint32_t);
|
||||||
|
|||||||
@@ -10,6 +10,95 @@ use inkwell::{context::Context, memory_buffer::MemoryBuffer, module::Module, sup
|
|||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/polkavm_imports.rs"));
|
include!(concat!(env!("OUT_DIR"), "/polkavm_imports.rs"));
|
||||||
|
|
||||||
|
pub static SBRK: &str = "__sbrk_internal";
|
||||||
|
|
||||||
|
pub static MEMORY_SIZE: &str = "__msize";
|
||||||
|
|
||||||
|
pub static ADDRESS: &str = "address";
|
||||||
|
|
||||||
|
pub static BALANCE: &str = "balance";
|
||||||
|
|
||||||
|
pub static BALANCE_OF: &str = "balance_of";
|
||||||
|
|
||||||
|
pub static BLOCK_HASH: &str = "block_hash";
|
||||||
|
|
||||||
|
pub static BLOCK_NUMBER: &str = "block_number";
|
||||||
|
|
||||||
|
pub static CALL: &str = "call";
|
||||||
|
|
||||||
|
pub static DELEGATE_CALL: &str = "delegate_call";
|
||||||
|
|
||||||
|
pub static CALLER: &str = "caller";
|
||||||
|
|
||||||
|
pub static CHAIN_ID: &str = "chain_id";
|
||||||
|
|
||||||
|
pub static CODE_SIZE: &str = "code_size";
|
||||||
|
|
||||||
|
pub static CODE_HASH: &str = "code_hash";
|
||||||
|
|
||||||
|
pub static DEPOSIT_EVENT: &str = "deposit_event";
|
||||||
|
|
||||||
|
pub static GET_IMMUTABLE_DATA: &str = "get_immutable_data";
|
||||||
|
|
||||||
|
pub static GET_STORAGE: &str = "get_storage";
|
||||||
|
|
||||||
|
pub static HASH_KECCAK_256: &str = "hash_keccak_256";
|
||||||
|
|
||||||
|
pub static INPUT: &str = "input";
|
||||||
|
|
||||||
|
pub static INSTANTIATE: &str = "instantiate";
|
||||||
|
|
||||||
|
pub static NOW: &str = "now";
|
||||||
|
|
||||||
|
pub static ORIGIN: &str = "origin";
|
||||||
|
|
||||||
|
pub static RETURN: &str = "seal_return";
|
||||||
|
|
||||||
|
pub static SET_STORAGE: &str = "set_storage";
|
||||||
|
|
||||||
|
pub static RETURNDATACOPY: &str = "return_data_copy";
|
||||||
|
|
||||||
|
pub static RETURNDATASIZE: &str = "return_data_size";
|
||||||
|
|
||||||
|
pub static SET_IMMUTABLE_DATA: &str = "set_immutable_data";
|
||||||
|
|
||||||
|
pub static VALUE_TRANSFERRED: &str = "value_transferred";
|
||||||
|
|
||||||
|
pub static WEIGHT_TO_FEE: &str = "weight_to_fee";
|
||||||
|
|
||||||
|
/// All imported runtime API symbols.
|
||||||
|
/// Useful for configuring common attributes and linkage.
|
||||||
|
pub static IMPORTS: [&str; 28] = [
|
||||||
|
SBRK,
|
||||||
|
MEMORY_SIZE,
|
||||||
|
ADDRESS,
|
||||||
|
BALANCE,
|
||||||
|
BALANCE_OF,
|
||||||
|
BLOCK_HASH,
|
||||||
|
BLOCK_NUMBER,
|
||||||
|
CALL,
|
||||||
|
DELEGATE_CALL,
|
||||||
|
CALLER,
|
||||||
|
CHAIN_ID,
|
||||||
|
CODE_SIZE,
|
||||||
|
CODE_HASH,
|
||||||
|
DEPOSIT_EVENT,
|
||||||
|
GET_IMMUTABLE_DATA,
|
||||||
|
GET_STORAGE,
|
||||||
|
HASH_KECCAK_256,
|
||||||
|
INPUT,
|
||||||
|
INSTANTIATE,
|
||||||
|
NOW,
|
||||||
|
ORIGIN,
|
||||||
|
RETURN,
|
||||||
|
RETURNDATACOPY,
|
||||||
|
RETURNDATASIZE,
|
||||||
|
SET_IMMUTABLE_DATA,
|
||||||
|
SET_STORAGE,
|
||||||
|
VALUE_TRANSFERRED,
|
||||||
|
WEIGHT_TO_FEE,
|
||||||
|
];
|
||||||
|
|
||||||
/// Creates a LLVM module from the [BITCODE].
|
/// Creates a LLVM module from the [BITCODE].
|
||||||
/// The module imports `pallet-revive` runtime API functions.
|
/// The module imports `pallet-revive` runtime API functions.
|
||||||
/// Returns `Error` if the bitcode fails to parse, which should never happen.
|
/// Returns `Error` if the bitcode fails to parse, which should never happen.
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ thiserror = { workspace = true }
|
|||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
which = { workspace = true }
|
which = { workspace = true }
|
||||||
path-slash = { workspace = true }
|
path-slash = { workspace = true }
|
||||||
rayon = { workspace = true }
|
rayon = { workspace = true, optional = true }
|
||||||
|
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
@@ -41,6 +41,13 @@ inkwell = { workspace = true }
|
|||||||
revive-common = { workspace = true }
|
revive-common = { workspace = true }
|
||||||
revive-llvm-context = { workspace = true }
|
revive-llvm-context = { workspace = true }
|
||||||
|
|
||||||
|
|
||||||
[target.'cfg(target_env = "musl")'.dependencies]
|
[target.'cfg(target_env = "musl")'.dependencies]
|
||||||
mimalloc = { version = "*", default-features = false }
|
mimalloc = { version = "*", default-features = false }
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "emscripten")'.dependencies]
|
||||||
|
libc = { workspace = true }
|
||||||
|
inkwell = { workspace = true, features = ["target-riscv", "llvm18-0-no-llvm-linking"]}
|
||||||
|
|
||||||
|
[features]
|
||||||
|
parallel = ["rayon"]
|
||||||
|
default = ["parallel"]
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fn main() {
|
||||||
|
let git_rev = std::process::Command::new("git")
|
||||||
|
.args(["rev-parse", "--short", "HEAD"])
|
||||||
|
.output()
|
||||||
|
.map(|out| String::from_utf8(out.stdout).unwrap_or_default())
|
||||||
|
.unwrap_or("unknown".to_owned());
|
||||||
|
|
||||||
|
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_rev.trim());
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ use std::path::Path;
|
|||||||
use crate::solc::combined_json::CombinedJson;
|
use crate::solc::combined_json::CombinedJson;
|
||||||
use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
||||||
use crate::solc::version::Version as SolcVersion;
|
use crate::solc::version::Version as SolcVersion;
|
||||||
|
use crate::ResolcVersion;
|
||||||
|
|
||||||
use self::contract::Contract;
|
use self::contract::Contract;
|
||||||
|
|
||||||
@@ -40,11 +41,7 @@ impl Build {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Writes all contracts assembly and bytecode to the combined JSON.
|
/// Writes all contracts assembly and bytecode to the combined JSON.
|
||||||
pub fn write_to_combined_json(
|
pub fn write_to_combined_json(self, combined_json: &mut CombinedJson) -> anyhow::Result<()> {
|
||||||
self,
|
|
||||||
combined_json: &mut CombinedJson,
|
|
||||||
resolc_version: &semver::Version,
|
|
||||||
) -> anyhow::Result<()> {
|
|
||||||
for (path, contract) in self.contracts.into_iter() {
|
for (path, contract) in self.contracts.into_iter() {
|
||||||
let combined_json_contract = combined_json
|
let combined_json_contract = combined_json
|
||||||
.contracts
|
.contracts
|
||||||
@@ -61,7 +58,7 @@ impl Build {
|
|||||||
contract.write_to_combined_json(combined_json_contract)?;
|
contract.write_to_combined_json(combined_json_contract)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
combined_json.zk_version = Some(resolc_version.to_string());
|
combined_json.revive_version = Some(ResolcVersion::default().long);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -71,7 +68,6 @@ impl Build {
|
|||||||
mut self,
|
mut self,
|
||||||
standard_json: &mut StandardJsonOutput,
|
standard_json: &mut StandardJsonOutput,
|
||||||
solc_version: &SolcVersion,
|
solc_version: &SolcVersion,
|
||||||
resolc_version: &semver::Version,
|
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let contracts = match standard_json.contracts.as_mut() {
|
let contracts = match standard_json.contracts.as_mut() {
|
||||||
Some(contracts) => contracts,
|
Some(contracts) => contracts,
|
||||||
@@ -90,7 +86,7 @@ impl Build {
|
|||||||
|
|
||||||
standard_json.version = Some(solc_version.default.to_string());
|
standard_json.version = Some(solc_version.default.to_string());
|
||||||
standard_json.long_version = Some(solc_version.long.to_owned());
|
standard_json.long_version = Some(solc_version.long.to_owned());
|
||||||
standard_json.zk_version = Some(resolc_version.to_string());
|
standard_json.revive_version = Some(ResolcVersion::default().long);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use std::collections::HashSet;
|
|||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use sha3::Digest;
|
||||||
|
|
||||||
use crate::evmla::ethereal_ir::entry_link::EntryLink;
|
use crate::evmla::ethereal_ir::entry_link::EntryLink;
|
||||||
use crate::evmla::ethereal_ir::EtherealIR;
|
use crate::evmla::ethereal_ir::EtherealIR;
|
||||||
@@ -45,7 +46,7 @@ impl Assembly {
|
|||||||
/// Gets the contract `keccak256` hash.
|
/// Gets the contract `keccak256` hash.
|
||||||
pub fn keccak256(&self) -> String {
|
pub fn keccak256(&self) -> String {
|
||||||
let json = serde_json::to_vec(self).expect("Always valid");
|
let json = serde_json::to_vec(self).expect("Always valid");
|
||||||
revive_llvm_context::polkavm_utils::keccak256(json.as_slice())
|
hex::encode(sha3::Keccak256::digest(json.as_slice()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the full contract path.
|
/// Sets the full contract path.
|
||||||
@@ -199,6 +200,7 @@ where
|
|||||||
revive_llvm_context::PolkaVMDummyLLVMWritable::default(),
|
revive_llvm_context::PolkaVMDummyLLVMWritable::default(),
|
||||||
)
|
)
|
||||||
.declare(context)?;
|
.declare(context)?;
|
||||||
|
revive_llvm_context::PolkaVMImmutableDataLoadFunction.declare(context)?;
|
||||||
|
|
||||||
entry.into_llvm(context)?;
|
entry.into_llvm(context)?;
|
||||||
|
|
||||||
@@ -211,9 +213,10 @@ where
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let full_path = self.full_path().to_owned();
|
let full_path = self.full_path().to_owned();
|
||||||
|
|
||||||
if let Some(debug_config) = context.debug_config() {
|
context
|
||||||
debug_config.dump_evmla(full_path.as_str(), self.to_string().as_str())?;
|
.debug_config()
|
||||||
}
|
.dump_evmla(full_path.as_str(), self.to_string().as_str())?;
|
||||||
|
|
||||||
let deploy_code_blocks = EtherealIR::get_blocks(
|
let deploy_code_blocks = EtherealIR::get_blocks(
|
||||||
context.evmla().version.to_owned(),
|
context.evmla().version.to_owned(),
|
||||||
revive_llvm_context::PolkaVMCodeType::Deploy,
|
revive_llvm_context::PolkaVMCodeType::Deploy,
|
||||||
@@ -227,9 +230,11 @@ where
|
|||||||
.ok_or_else(|| anyhow::anyhow!("Runtime code data not found"))?
|
.ok_or_else(|| anyhow::anyhow!("Runtime code data not found"))?
|
||||||
.remove("0")
|
.remove("0")
|
||||||
.expect("Always exists");
|
.expect("Always exists");
|
||||||
if let Some(debug_config) = context.debug_config() {
|
|
||||||
debug_config.dump_evmla(full_path.as_str(), data.to_string().as_str())?;
|
context
|
||||||
}
|
.debug_config()
|
||||||
|
.dump_evmla(full_path.as_str(), data.to_string().as_str())?;
|
||||||
|
|
||||||
let runtime_code_instructions = match data {
|
let runtime_code_instructions = match data {
|
||||||
Data::Assembly(assembly) => assembly
|
Data::Assembly(assembly) => assembly
|
||||||
.code
|
.code
|
||||||
@@ -252,9 +257,11 @@ where
|
|||||||
blocks.extend(runtime_code_blocks);
|
blocks.extend(runtime_code_blocks);
|
||||||
let mut ethereal_ir =
|
let mut ethereal_ir =
|
||||||
EtherealIR::new(context.evmla().version.to_owned(), extra_metadata, blocks)?;
|
EtherealIR::new(context.evmla().version.to_owned(), extra_metadata, blocks)?;
|
||||||
if let Some(debug_config) = context.debug_config() {
|
|
||||||
debug_config.dump_ethir(full_path.as_str(), ethereal_ir.to_string().as_str())?;
|
context
|
||||||
}
|
.debug_config()
|
||||||
|
.dump_ethir(full_path.as_str(), ethereal_ir.to_string().as_str())?;
|
||||||
|
|
||||||
ethereal_ir.declare(context)?;
|
ethereal_ir.declare(context)?;
|
||||||
ethereal_ir.into_llvm(context)?;
|
ethereal_ir.into_llvm(context)?;
|
||||||
|
|
||||||
@@ -266,6 +273,7 @@ where
|
|||||||
revive_llvm_context::PolkaVMCodeType::Runtime,
|
revive_llvm_context::PolkaVMCodeType::Runtime,
|
||||||
))
|
))
|
||||||
.into_llvm(context)?;
|
.into_llvm(context)?;
|
||||||
|
revive_llvm_context::PolkaVMImmutableDataLoadFunction.into_llvm(context)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ impl Element {
|
|||||||
fn pop_arguments_llvm<'ctx, D>(
|
fn pop_arguments_llvm<'ctx, D>(
|
||||||
&mut self,
|
&mut self,
|
||||||
context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>,
|
context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>,
|
||||||
) -> Vec<inkwell::values::BasicValueEnum<'ctx>>
|
) -> anyhow::Result<Vec<inkwell::values::BasicValueEnum<'ctx>>>
|
||||||
where
|
where
|
||||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||||
{
|
{
|
||||||
@@ -57,15 +57,13 @@ impl Element {
|
|||||||
[self.stack.elements.len() + input_size - output_size - 1 - index]
|
[self.stack.elements.len() + input_size - output_size - 1 - index]
|
||||||
.to_llvm()
|
.to_llvm()
|
||||||
.into_pointer_value();
|
.into_pointer_value();
|
||||||
let value = context
|
let value = context.build_load(
|
||||||
.build_load(
|
revive_llvm_context::PolkaVMPointer::new_stack_field(context, pointer),
|
||||||
revive_llvm_context::PolkaVMPointer::new_stack_field(context, pointer),
|
format!("argument_{index}").as_str(),
|
||||||
format!("argument_{index}").as_str(),
|
)?;
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
arguments.push(value);
|
arguments.push(value);
|
||||||
}
|
}
|
||||||
arguments
|
Ok(arguments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,7 +424,7 @@ where
|
|||||||
InstructionName::JUMPDEST => Ok(None),
|
InstructionName::JUMPDEST => Ok(None),
|
||||||
|
|
||||||
InstructionName::ADD => {
|
InstructionName::ADD => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_arithmetic::addition(
|
revive_llvm_context::polkavm_evm_arithmetic::addition(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -435,7 +433,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::SUB => {
|
InstructionName::SUB => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_arithmetic::subtraction(
|
revive_llvm_context::polkavm_evm_arithmetic::subtraction(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -444,7 +442,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::MUL => {
|
InstructionName::MUL => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_arithmetic::multiplication(
|
revive_llvm_context::polkavm_evm_arithmetic::multiplication(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -453,7 +451,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::DIV => {
|
InstructionName::DIV => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_arithmetic::division(
|
revive_llvm_context::polkavm_evm_arithmetic::division(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -462,7 +460,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::MOD => {
|
InstructionName::MOD => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_arithmetic::remainder(
|
revive_llvm_context::polkavm_evm_arithmetic::remainder(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -471,7 +469,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::SDIV => {
|
InstructionName::SDIV => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_arithmetic::division_signed(
|
revive_llvm_context::polkavm_evm_arithmetic::division_signed(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -480,7 +478,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::SMOD => {
|
InstructionName::SMOD => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_arithmetic::remainder_signed(
|
revive_llvm_context::polkavm_evm_arithmetic::remainder_signed(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -490,7 +488,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
InstructionName::LT => {
|
InstructionName::LT => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_comparison::compare(
|
revive_llvm_context::polkavm_evm_comparison::compare(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -500,7 +498,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::GT => {
|
InstructionName::GT => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_comparison::compare(
|
revive_llvm_context::polkavm_evm_comparison::compare(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -510,7 +508,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::EQ => {
|
InstructionName::EQ => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_comparison::compare(
|
revive_llvm_context::polkavm_evm_comparison::compare(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -520,7 +518,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::ISZERO => {
|
InstructionName::ISZERO => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_comparison::compare(
|
revive_llvm_context::polkavm_evm_comparison::compare(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -530,7 +528,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::SLT => {
|
InstructionName::SLT => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_comparison::compare(
|
revive_llvm_context::polkavm_evm_comparison::compare(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -540,7 +538,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::SGT => {
|
InstructionName::SGT => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_comparison::compare(
|
revive_llvm_context::polkavm_evm_comparison::compare(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -551,7 +549,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
InstructionName::OR => {
|
InstructionName::OR => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_bitwise::or(
|
revive_llvm_context::polkavm_evm_bitwise::or(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -560,7 +558,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::XOR => {
|
InstructionName::XOR => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_bitwise::xor(
|
revive_llvm_context::polkavm_evm_bitwise::xor(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -569,7 +567,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::NOT => {
|
InstructionName::NOT => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_bitwise::xor(
|
revive_llvm_context::polkavm_evm_bitwise::xor(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -578,7 +576,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::AND => {
|
InstructionName::AND => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_bitwise::and(
|
revive_llvm_context::polkavm_evm_bitwise::and(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -587,7 +585,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::SHL => {
|
InstructionName::SHL => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_bitwise::shift_left(
|
revive_llvm_context::polkavm_evm_bitwise::shift_left(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -596,7 +594,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::SHR => {
|
InstructionName::SHR => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_bitwise::shift_right(
|
revive_llvm_context::polkavm_evm_bitwise::shift_right(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -605,7 +603,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::SAR => {
|
InstructionName::SAR => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_bitwise::shift_right_arithmetic(
|
revive_llvm_context::polkavm_evm_bitwise::shift_right_arithmetic(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -614,7 +612,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::BYTE => {
|
InstructionName::BYTE => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_bitwise::byte(
|
revive_llvm_context::polkavm_evm_bitwise::byte(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -624,7 +622,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
InstructionName::ADDMOD => {
|
InstructionName::ADDMOD => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_math::add_mod(
|
revive_llvm_context::polkavm_evm_math::add_mod(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -634,7 +632,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::MULMOD => {
|
InstructionName::MULMOD => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_math::mul_mod(
|
revive_llvm_context::polkavm_evm_math::mul_mod(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -644,7 +642,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::EXP => {
|
InstructionName::EXP => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_math::exponent(
|
revive_llvm_context::polkavm_evm_math::exponent(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -653,7 +651,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::SIGNEXTEND => {
|
InstructionName::SIGNEXTEND => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_math::sign_extend(
|
revive_llvm_context::polkavm_evm_math::sign_extend(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -663,7 +661,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
InstructionName::SHA3 | InstructionName::KECCAK256 => {
|
InstructionName::SHA3 | InstructionName::KECCAK256 => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_crypto::sha3(
|
revive_llvm_context::polkavm_evm_crypto::sha3(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -673,7 +671,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
InstructionName::MLOAD => {
|
InstructionName::MLOAD => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_memory::load(
|
revive_llvm_context::polkavm_evm_memory::load(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -681,7 +679,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::MSTORE => {
|
InstructionName::MSTORE => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_memory::store(
|
revive_llvm_context::polkavm_evm_memory::store(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -690,7 +688,7 @@ where
|
|||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
}
|
}
|
||||||
InstructionName::MSTORE8 => {
|
InstructionName::MSTORE8 => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_memory::store_byte(
|
revive_llvm_context::polkavm_evm_memory::store_byte(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -699,7 +697,7 @@ where
|
|||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
}
|
}
|
||||||
InstructionName::MCOPY => {
|
InstructionName::MCOPY => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
let destination = revive_llvm_context::PolkaVMPointer::new_with_offset(
|
let destination = revive_llvm_context::PolkaVMPointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
revive_llvm_context::PolkaVMAddressSpace::Heap,
|
revive_llvm_context::PolkaVMAddressSpace::Heap,
|
||||||
@@ -725,7 +723,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
InstructionName::SLOAD => {
|
InstructionName::SLOAD => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_storage::load(
|
revive_llvm_context::polkavm_evm_storage::load(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -733,7 +731,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::SSTORE => {
|
InstructionName::SSTORE => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_storage::store(
|
revive_llvm_context::polkavm_evm_storage::store(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -742,7 +740,7 @@ where
|
|||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
}
|
}
|
||||||
InstructionName::TLOAD => {
|
InstructionName::TLOAD => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_storage::transient_load(
|
revive_llvm_context::polkavm_evm_storage::transient_load(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -750,7 +748,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::TSTORE => {
|
InstructionName::TSTORE => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_storage::transient_store(
|
revive_llvm_context::polkavm_evm_storage::transient_store(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -766,27 +764,28 @@ where
|
|||||||
|
|
||||||
let offset = context
|
let offset = context
|
||||||
.solidity_mut()
|
.solidity_mut()
|
||||||
.get_or_allocate_immutable(key.as_str());
|
.get_or_allocate_immutable(key.as_str())
|
||||||
|
/ revive_common::BYTE_LENGTH_WORD;
|
||||||
|
|
||||||
let index = context.word_const(offset as u64);
|
let index = context.xlen_type().const_int(offset as u64, false);
|
||||||
revive_llvm_context::polkavm_evm_immutable::load(context, index).map(Some)
|
revive_llvm_context::polkavm_evm_immutable::load(context, index).map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::ASSIGNIMMUTABLE => {
|
InstructionName::ASSIGNIMMUTABLE => {
|
||||||
let mut arguments = self.pop_arguments_llvm(context);
|
let mut arguments = self.pop_arguments_llvm(context)?;
|
||||||
|
|
||||||
let key = self
|
let key = self
|
||||||
.instruction
|
.instruction
|
||||||
.value
|
.value
|
||||||
.ok_or_else(|| anyhow::anyhow!("Instruction value missing"))?;
|
.ok_or_else(|| anyhow::anyhow!("Instruction value missing"))?;
|
||||||
|
|
||||||
let offset = context.solidity_mut().allocate_immutable(key.as_str());
|
let offset = context.solidity_mut().allocate_immutable(key.as_str())
|
||||||
|
/ revive_common::BYTE_LENGTH_WORD;
|
||||||
|
|
||||||
let index = context.word_const(offset as u64);
|
let index = context.xlen_type().const_int(offset as u64, false);
|
||||||
let value = arguments.pop().expect("Always exists").into_int_value();
|
let value = arguments.pop().expect("Always exists").into_int_value();
|
||||||
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
|
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
|
||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
}
|
}
|
||||||
|
|
||||||
InstructionName::CALLDATALOAD => {
|
InstructionName::CALLDATALOAD => {
|
||||||
match context
|
match context
|
||||||
.code_type()
|
.code_type()
|
||||||
@@ -796,7 +795,7 @@ where
|
|||||||
Ok(Some(context.word_const(0).as_basic_value_enum()))
|
Ok(Some(context.word_const(0).as_basic_value_enum()))
|
||||||
}
|
}
|
||||||
revive_llvm_context::PolkaVMCodeType::Runtime => {
|
revive_llvm_context::PolkaVMCodeType::Runtime => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_calldata::load(
|
revive_llvm_context::polkavm_evm_calldata::load(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -819,7 +818,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
InstructionName::CALLDATACOPY => {
|
InstructionName::CALLDATACOPY => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
|
|
||||||
match context
|
match context
|
||||||
.code_type()
|
.code_type()
|
||||||
@@ -862,7 +861,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
InstructionName::CODECOPY => {
|
InstructionName::CODECOPY => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
|
|
||||||
let parent = context.module().get_name().to_str().expect("Always valid");
|
let parent = context.module().get_name().to_str().expect("Always valid");
|
||||||
let source = &self.stack_input.elements[1];
|
let source = &self.stack_input.elements[1];
|
||||||
@@ -917,7 +916,7 @@ where
|
|||||||
revive_llvm_context::polkavm_evm_return_data::size(context).map(Some)
|
revive_llvm_context::polkavm_evm_return_data::size(context).map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::RETURNDATACOPY => {
|
InstructionName::RETURNDATACOPY => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_return_data::copy(
|
revive_llvm_context::polkavm_evm_return_data::copy(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -927,7 +926,7 @@ where
|
|||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
}
|
}
|
||||||
InstructionName::EXTCODESIZE => {
|
InstructionName::EXTCODESIZE => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_ext_code::size(
|
revive_llvm_context::polkavm_evm_ext_code::size(
|
||||||
context,
|
context,
|
||||||
Some(arguments[0].into_int_value()),
|
Some(arguments[0].into_int_value()),
|
||||||
@@ -935,7 +934,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::EXTCODEHASH => {
|
InstructionName::EXTCODEHASH => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_ext_code::hash(
|
revive_llvm_context::polkavm_evm_ext_code::hash(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -944,7 +943,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
InstructionName::RETURN => {
|
InstructionName::RETURN => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_return::r#return(
|
revive_llvm_context::polkavm_evm_return::r#return(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -953,7 +952,7 @@ where
|
|||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
}
|
}
|
||||||
InstructionName::REVERT => {
|
InstructionName::REVERT => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_return::revert(
|
revive_llvm_context::polkavm_evm_return::revert(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
@@ -969,7 +968,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
InstructionName::LOG0 => {
|
InstructionName::LOG0 => {
|
||||||
let mut arguments = self.pop_arguments_llvm(context);
|
let mut arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_event::log(
|
revive_llvm_context::polkavm_evm_event::log(
|
||||||
context,
|
context,
|
||||||
arguments.remove(0).into_int_value(),
|
arguments.remove(0).into_int_value(),
|
||||||
@@ -982,7 +981,7 @@ where
|
|||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
}
|
}
|
||||||
InstructionName::LOG1 => {
|
InstructionName::LOG1 => {
|
||||||
let mut arguments = self.pop_arguments_llvm(context);
|
let mut arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_event::log(
|
revive_llvm_context::polkavm_evm_event::log(
|
||||||
context,
|
context,
|
||||||
arguments.remove(0).into_int_value(),
|
arguments.remove(0).into_int_value(),
|
||||||
@@ -995,7 +994,7 @@ where
|
|||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
}
|
}
|
||||||
InstructionName::LOG2 => {
|
InstructionName::LOG2 => {
|
||||||
let mut arguments = self.pop_arguments_llvm(context);
|
let mut arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_event::log(
|
revive_llvm_context::polkavm_evm_event::log(
|
||||||
context,
|
context,
|
||||||
arguments.remove(0).into_int_value(),
|
arguments.remove(0).into_int_value(),
|
||||||
@@ -1008,7 +1007,7 @@ where
|
|||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
}
|
}
|
||||||
InstructionName::LOG3 => {
|
InstructionName::LOG3 => {
|
||||||
let mut arguments = self.pop_arguments_llvm(context);
|
let mut arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_event::log(
|
revive_llvm_context::polkavm_evm_event::log(
|
||||||
context,
|
context,
|
||||||
arguments.remove(0).into_int_value(),
|
arguments.remove(0).into_int_value(),
|
||||||
@@ -1021,7 +1020,7 @@ where
|
|||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
}
|
}
|
||||||
InstructionName::LOG4 => {
|
InstructionName::LOG4 => {
|
||||||
let mut arguments = self.pop_arguments_llvm(context);
|
let mut arguments = self.pop_arguments_llvm(context)?;
|
||||||
revive_llvm_context::polkavm_evm_event::log(
|
revive_llvm_context::polkavm_evm_event::log(
|
||||||
context,
|
context,
|
||||||
arguments.remove(0).into_int_value(),
|
arguments.remove(0).into_int_value(),
|
||||||
@@ -1035,7 +1034,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
InstructionName::CALL => {
|
InstructionName::CALL => {
|
||||||
let mut arguments = self.pop_arguments_llvm(context);
|
let mut arguments = self.pop_arguments_llvm(context)?;
|
||||||
|
|
||||||
let gas = arguments.remove(0).into_int_value();
|
let gas = arguments.remove(0).into_int_value();
|
||||||
let address = arguments.remove(0).into_int_value();
|
let address = arguments.remove(0).into_int_value();
|
||||||
@@ -1060,7 +1059,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::STATICCALL => {
|
InstructionName::STATICCALL => {
|
||||||
let mut arguments = self.pop_arguments_llvm(context);
|
let mut arguments = self.pop_arguments_llvm(context)?;
|
||||||
|
|
||||||
let gas = arguments.remove(0).into_int_value();
|
let gas = arguments.remove(0).into_int_value();
|
||||||
let address = arguments.remove(0).into_int_value();
|
let address = arguments.remove(0).into_int_value();
|
||||||
@@ -1084,7 +1083,7 @@ where
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::DELEGATECALL => {
|
InstructionName::DELEGATECALL => {
|
||||||
let mut arguments = self.pop_arguments_llvm(context);
|
let mut arguments = self.pop_arguments_llvm(context)?;
|
||||||
|
|
||||||
let gas = arguments.remove(0).into_int_value();
|
let gas = arguments.remove(0).into_int_value();
|
||||||
let address = arguments.remove(0).into_int_value();
|
let address = arguments.remove(0).into_int_value();
|
||||||
@@ -1097,7 +1096,6 @@ where
|
|||||||
context,
|
context,
|
||||||
gas,
|
gas,
|
||||||
address,
|
address,
|
||||||
None,
|
|
||||||
input_offset,
|
input_offset,
|
||||||
input_size,
|
input_size,
|
||||||
output_offset,
|
output_offset,
|
||||||
@@ -1108,7 +1106,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
InstructionName::CREATE | InstructionName::ZK_CREATE => {
|
InstructionName::CREATE | InstructionName::ZK_CREATE => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
|
|
||||||
let value = arguments[0].into_int_value();
|
let value = arguments[0].into_int_value();
|
||||||
let input_offset = arguments[1].into_int_value();
|
let input_offset = arguments[1].into_int_value();
|
||||||
@@ -1119,18 +1117,19 @@ where
|
|||||||
value,
|
value,
|
||||||
input_offset,
|
input_offset,
|
||||||
input_length,
|
input_length,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::CREATE2 | InstructionName::ZK_CREATE2 => {
|
InstructionName::CREATE2 | InstructionName::ZK_CREATE2 => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
|
|
||||||
let value = arguments[0].into_int_value();
|
let value = arguments[0].into_int_value();
|
||||||
let input_offset = arguments[1].into_int_value();
|
let input_offset = arguments[1].into_int_value();
|
||||||
let input_length = arguments[2].into_int_value();
|
let input_length = arguments[2].into_int_value();
|
||||||
let salt = arguments[3].into_int_value();
|
let salt = arguments[3].into_int_value();
|
||||||
|
|
||||||
revive_llvm_context::polkavm_evm_create::create2(
|
revive_llvm_context::polkavm_evm_create::create(
|
||||||
context,
|
context,
|
||||||
value,
|
value,
|
||||||
input_offset,
|
input_offset,
|
||||||
@@ -1154,12 +1153,14 @@ where
|
|||||||
revive_llvm_context::polkavm_evm_ether_gas::gas(context).map(Some)
|
revive_llvm_context::polkavm_evm_ether_gas::gas(context).map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::BALANCE => {
|
InstructionName::BALANCE => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
|
|
||||||
let address = arguments[0].into_int_value();
|
let address = arguments[0].into_int_value();
|
||||||
revive_llvm_context::polkavm_evm_ether_gas::balance(context, address).map(Some)
|
revive_llvm_context::polkavm_evm_ether_gas::balance(context, address).map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::SELFBALANCE => todo!(),
|
InstructionName::SELFBALANCE => {
|
||||||
|
revive_llvm_context::polkavm_evm_ether_gas::self_balance(context).map(Some)
|
||||||
|
}
|
||||||
|
|
||||||
InstructionName::GASLIMIT => {
|
InstructionName::GASLIMIT => {
|
||||||
revive_llvm_context::polkavm_evm_contract_context::gas_limit(context).map(Some)
|
revive_llvm_context::polkavm_evm_contract_context::gas_limit(context).map(Some)
|
||||||
@@ -1181,7 +1182,7 @@ where
|
|||||||
revive_llvm_context::polkavm_evm_contract_context::block_number(context).map(Some)
|
revive_llvm_context::polkavm_evm_contract_context::block_number(context).map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::BLOCKHASH => {
|
InstructionName::BLOCKHASH => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context)?;
|
||||||
let index = arguments[0].into_int_value();
|
let index = arguments[0].into_int_value();
|
||||||
|
|
||||||
revive_llvm_context::polkavm_evm_contract_context::block_hash(context, index)
|
revive_llvm_context::polkavm_evm_contract_context::block_hash(context, index)
|
||||||
@@ -1204,7 +1205,7 @@ where
|
|||||||
anyhow::bail!("The `BLOBBASEFEE` instruction is not supported until zkVM v1.5.0");
|
anyhow::bail!("The `BLOBBASEFEE` instruction is not supported until zkVM v1.5.0");
|
||||||
}
|
}
|
||||||
InstructionName::MSIZE => {
|
InstructionName::MSIZE => {
|
||||||
revive_llvm_context::polkavm_evm_contract_context::msize(context).map(Some)
|
revive_llvm_context::polkavm_evm_memory::msize(context).map(Some)
|
||||||
}
|
}
|
||||||
|
|
||||||
InstructionName::CALLCODE => {
|
InstructionName::CALLCODE => {
|
||||||
@@ -1219,7 +1220,7 @@ where
|
|||||||
anyhow::bail!("The `EXTCODECOPY` instruction is not supported");
|
anyhow::bail!("The `EXTCODECOPY` instruction is not supported");
|
||||||
}
|
}
|
||||||
InstructionName::SELFDESTRUCT => {
|
InstructionName::SELFDESTRUCT => {
|
||||||
let _arguments = self.pop_arguments_llvm(context);
|
let _arguments = self.pop_arguments_llvm(context)?;
|
||||||
anyhow::bail!("The `SELFDESTRUCT` instruction is not supported");
|
anyhow::bail!("The `SELFDESTRUCT` instruction is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1231,7 +1232,7 @@ where
|
|||||||
return_address,
|
return_address,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let mut arguments = self.pop_arguments_llvm(context);
|
let mut arguments = self.pop_arguments_llvm(context)?;
|
||||||
arguments.pop();
|
arguments.pop();
|
||||||
arguments.reverse();
|
arguments.reverse();
|
||||||
arguments.pop();
|
arguments.pop();
|
||||||
@@ -1294,7 +1295,7 @@ where
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
InstructionName::RecursiveReturn { .. } => {
|
InstructionName::RecursiveReturn { .. } => {
|
||||||
let mut arguments = self.pop_arguments_llvm(context);
|
let mut arguments = self.pop_arguments_llvm(context)?;
|
||||||
arguments.reverse();
|
arguments.reverse();
|
||||||
arguments.pop();
|
arguments.pop();
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user