mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 18:01:05 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 199b6145f2 | |||
| 36f9345c22 | |||
| 33d589ea7f | |||
| fdc44db1be | |||
| 76f815f33b | |||
| a293264028 | |||
| 7bf9d49166 | |||
| d5b9c489ea |
@@ -0,0 +1,6 @@
|
|||||||
|
FROM revive-llvm
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN RUSTFLAGS='-L /app/llvm18.0/lib/unknown -L /usr/lib -L /app/llvm18.0/lib' REVIVE_INSTALL_DIR='/app/release/revive/' make install-revive
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
FROM alpine:3.20.3
|
||||||
|
|
||||||
|
ARG RUST_VERSION=stable
|
||||||
|
|
||||||
|
RUN apk add bash git cmake make ninja python3 ncurses-static curl
|
||||||
|
RUN ninja --version
|
||||||
|
|
||||||
|
COPY build-llvm.sh .
|
||||||
|
|
||||||
|
RUN bash -c ./build-llvm.sh
|
||||||
|
|
||||||
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${RUST_VERSION}
|
||||||
|
ENV PATH=/root/.cargo/bin:/llvm18.0/bin:${PATH}
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
RUN REVIVE_INSTALL_DIR=$(pwd)/target/release
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
name: Release
|
||||||
|
run-name: Release ${{ github.ref_name }}
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "[0-9]+.[0-9]+.[0-9]+"
|
||||||
|
- "[0-9]+.[0-9]+.[0-9]+-[a-zA-Z0-9]+"
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
CreateRelease:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- name: Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
draft: true
|
||||||
|
make_latest: true
|
||||||
|
|
||||||
|
Release:
|
||||||
|
needs: [CreateRelease]
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
steps:
|
||||||
|
- name: build llvm
|
||||||
|
run: docker build -t revive-llvm:latest --progress=plain -f --build-arg RUST_VERSION=1.80 .github/Dockerfile-llvm
|
||||||
|
|
||||||
|
- name: build revive
|
||||||
|
run: docker build -t revive:latest --progress=plain -f .github/Dockerfile
|
||||||
|
|
||||||
|
- name: get binary
|
||||||
|
run: docker run --rm revive:latest -v output:/app/output cp /app/release/revive/resolc /app/output
|
||||||
|
|
||||||
|
# docker push revive:latest
|
||||||
|
|
||||||
|
- run: gh release upload ${{ github.ref_name }} output/resolc --clobber
|
||||||
@@ -3,8 +3,6 @@ name: Build
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["main"]
|
branches: ["main"]
|
||||||
pull_request:
|
|
||||||
branches: ["main"]
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
name: Test
|
||||||
|
run-name: Test ${{ github.ref_name }}
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened, ready_for_review]
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Release:
|
||||||
|
# runs-on: ubuntu-20.04
|
||||||
|
runs-on: parity-large
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: build llvm
|
||||||
|
run: docker build -t revive-llvm:latest --progress=plain --build-arg RUST_VERSION=1.80 -f .github/Dockerfile-llvm .
|
||||||
|
|
||||||
|
- name: build revive
|
||||||
|
run: docker build -t revive:latest --progress=plain -f .github/Dockerfile
|
||||||
|
|
||||||
|
- name: get binary
|
||||||
|
run: docker run --rm revive:latest -v output:/app/output cp /app/release/revive/resolc /app/output .
|
||||||
|
|
||||||
|
# docker push revive:latest
|
||||||
|
|
||||||
|
- run: gh release upload ${{ github.ref_name }} output/resolc
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
## Unreleased
|
|
||||||
|
|
||||||
## 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
+582
-601
File diff suppressed because it is too large
Load Diff
+19
-20
@@ -3,7 +3,7 @@ resolver = "2"
|
|||||||
members = ["crates/*"]
|
members = ["crates/*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.1.0-dev.5"
|
version = "0.1.0"
|
||||||
authors = [
|
authors = [
|
||||||
"Cyrill Leutwiler <cyrill@parity.io>",
|
"Cyrill Leutwiler <cyrill@parity.io>",
|
||||||
"Parity Technologies <admin@parity.io>",
|
"Parity Technologies <admin@parity.io>",
|
||||||
@@ -14,18 +14,18 @@ repository = "https://github.com/paritytech/revive"
|
|||||||
rust-version = "1.80.0"
|
rust-version = "1.80.0"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
revive-benchmarks = { version = "0.1.0-dev.5", path = "crates/benchmarks" }
|
revive-benchmarks = { version = "0.1.0", path = "crates/benchmarks" }
|
||||||
revive-builtins = { version = "0.1.0-dev.5", path = "crates/builtins" }
|
revive-builtins = { version = "0.1.0", path = "crates/builtins" }
|
||||||
revive-common = { version = "0.1.0-dev.5", path = "crates/common" }
|
revive-common = { version = "0.1.0", path = "crates/common" }
|
||||||
revive-differential = { version = "0.1.0-dev.5", path = "crates/differential" }
|
revive-differential = { version = "0.1.0", path = "crates/differential" }
|
||||||
revive-integration = { version = "0.1.0-dev.5", path = "crates/integration" }
|
revive-integration = { version = "0.1.0", path = "crates/integration" }
|
||||||
revive-linker = { version = "0.1.0-dev.5", path = "crates/linker" }
|
revive-linker = { version = "0.1.0", path = "crates/linker" }
|
||||||
lld-sys = { version = "0.1.0-dev.5", path = "crates/lld-sys" }
|
lld-sys = { version = "0.1.0", path = "crates/lld-sys" }
|
||||||
revive-llvm-context = { version = "0.1.0-dev.5", path = "crates/llvm-context" }
|
revive-llvm-context = { version = "0.1.0", path = "crates/llvm-context" }
|
||||||
revive-runtime-api = { version = "0.1.0-dev.5", path = "crates/runtime-api" }
|
revive-runtime-api = { version = "0.1.0", path = "crates/runtime-api" }
|
||||||
revive-runner = { version = "0.1.0-dev.5", path = "crates/runner" }
|
revive-runner = { version = "0.1.0", path = "crates/runner" }
|
||||||
revive-solidity = { version = "0.1.0-dev.5", path = "crates/solidity" }
|
revive-solidity = { version = "0.1.0", path = "crates/solidity" }
|
||||||
revive-stdlib = { version = "0.1.0-dev.5", path = "crates/stdlib" }
|
revive-stdlib = { version = "0.1.0", path = "crates/stdlib" }
|
||||||
|
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
petgraph = "0.6"
|
petgraph = "0.6"
|
||||||
@@ -51,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.14"
|
polkavm-common = "0.13"
|
||||||
polkavm-linker = "0.14"
|
polkavm-linker = "0.13"
|
||||||
polkavm-disassembler = "0.14"
|
polkavm-disassembler = "0.13"
|
||||||
polkavm = "0.14"
|
polkavm = "0.13"
|
||||||
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"
|
||||||
@@ -67,12 +67,11 @@ 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 = "2b6b69641ccff4d7aa9c32051bbb2f1e775ef8cc" }
|
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "aeebf2f383390f2f86527d70212162d5dbea8b93" }
|
||||||
|
|
||||||
# llvm
|
# llvm
|
||||||
[workspace.dependencies.inkwell]
|
[workspace.dependencies.inkwell]
|
||||||
git = "https://github.com/TheDan64/inkwell.git"
|
version = "0.5"
|
||||||
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"]
|
||||||
|
|
||||||
|
|||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
# 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
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"Baseline": 967,
|
"Baseline": 989,
|
||||||
"Computation": 4022,
|
"Computation": 4153,
|
||||||
"DivisionArithmetics": 31787,
|
"DivisionArithmetics": 40614,
|
||||||
"ERC20": 44233,
|
"ERC20": 47343,
|
||||||
"Events": 1743,
|
"Events": 1781,
|
||||||
"FibonacciIterative": 2927,
|
"FibonacciIterative": 3035,
|
||||||
"Flipper": 3408,
|
"Flipper": 3393,
|
||||||
"SHA1": 26009
|
"SHA1": 33553
|
||||||
}
|
}
|
||||||
@@ -4,27 +4,11 @@ pragma solidity ^0.8;
|
|||||||
|
|
||||||
/* runner.json
|
/* runner.json
|
||||||
{
|
{
|
||||||
"differential": true,
|
|
||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
"Upload": {
|
"Instantiate": {}
|
||||||
"code": {
|
}
|
||||||
"Solidity": {
|
]
|
||||||
"contract": "ERC20"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Instantiate": {
|
|
||||||
"code": {
|
|
||||||
"Solidity": {
|
|
||||||
"contract": "ERC20Tester"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -98,26 +82,3 @@ 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,14 +22,6 @@ pragma solidity ^0.8;
|
|||||||
},
|
},
|
||||||
"data": "fabc9efaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
"data": "fabc9efaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"Call": {
|
|
||||||
"dest": {
|
|
||||||
"Instantiated": 0
|
|
||||||
},
|
|
||||||
"data": "558b9f9bffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -38,18 +30,10 @@ 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 := 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00
|
let slot := 123
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+24
-109
@@ -43,7 +43,6 @@ test_spec!(call, "Caller", "Call.sol");
|
|||||||
test_spec!(transfer, "Transfer", "Transfer.sol");
|
test_spec!(transfer, "Transfer", "Transfer.sol");
|
||||||
test_spec!(return_data_oob, "ReturnDataOob", "ReturnDataOob.sol");
|
test_spec!(return_data_oob, "ReturnDataOob", "ReturnDataOob.sol");
|
||||||
test_spec!(immutables, "Immutables", "Immutables.sol");
|
test_spec!(immutables, "Immutables", "Immutables.sol");
|
||||||
test_spec!(transaction, "Transaction", "Transaction.sol");
|
|
||||||
|
|
||||||
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
||||||
vec![Instantiate {
|
vec![Instantiate {
|
||||||
@@ -321,114 +320,6 @@ fn ext_code_hash() {
|
|||||||
.run();
|
.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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// These test were implement for the mock-runtime and need to be ported yet.
|
// These test were implement for the mock-runtime and need to be ported yet.
|
||||||
|
|
||||||
@@ -457,4 +348,28 @@ fn create2_failure() {
|
|||||||
|
|
||||||
assert_eq!(output.flags, ReturnFlags::Revert);
|
assert_eq!(output.flags, ReturnFlags::Revert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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);
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -27,6 +27,18 @@ impl Entry {
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
|
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,
|
||||||
|
);
|
||||||
|
|
||||||
let calldata_type = context.array_type(context.byte_type(), Self::MAX_CALLDATA_SIZE);
|
let calldata_type = context.array_type(context.byte_type(), Self::MAX_CALLDATA_SIZE);
|
||||||
context.set_global(
|
context.set_global(
|
||||||
crate::polkavm::GLOBAL_CALLDATA_POINTER,
|
crate::polkavm::GLOBAL_CALLDATA_POINTER,
|
||||||
@@ -183,18 +195,6 @@ 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(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -669,10 +669,22 @@ 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(
|
||||||
@@ -686,7 +698,7 @@ where
|
|||||||
revive_runtime_api::polkavm_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(),
|
||||||
pointer.to_int(self).into(),
|
storage_key_pointer_casted.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(),
|
||||||
@@ -755,6 +767,18 @@ 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,
|
||||||
@@ -762,6 +786,8 @@ 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)?;
|
||||||
|
|
||||||
@@ -771,7 +797,7 @@ where
|
|||||||
revive_runtime_api::polkavm_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(),
|
||||||
pointer.to_int(self).into(),
|
storage_key_pointer_casted.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(),
|
||||||
|
|||||||
@@ -27,19 +27,12 @@ where
|
|||||||
|
|
||||||
/// 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,
|
||||||
{
|
{
|
||||||
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
todo!()
|
||||||
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.
|
||||||
|
|||||||
@@ -1,5 +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;
|
||||||
|
|
||||||
@@ -12,23 +14,37 @@ pub fn size<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let address = match address {
|
let address_pointer = match address {
|
||||||
Some(address) => address,
|
Some(address) => {
|
||||||
None => super::context::address(context)?.into_int_value(),
|
let address_pointer = context.build_alloca(context.word_type(), "value");
|
||||||
|
context.build_store(address_pointer, address)?;
|
||||||
|
address_pointer
|
||||||
|
}
|
||||||
|
None => context.sentinel_pointer(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let address_pointer = context.build_address_argument_store(address)?;
|
let address_pointer_casted = context.builder().build_ptr_to_int(
|
||||||
let output_pointer = context.build_alloca_at_entry(context.word_type(), "output_pointer");
|
address_pointer.value,
|
||||||
|
context.xlen_type(),
|
||||||
|
"address_pointer",
|
||||||
|
)?;
|
||||||
|
let value = context
|
||||||
|
.build_runtime_call(
|
||||||
|
revive_runtime_api::polkavm_imports::CODE_SIZE,
|
||||||
|
&[address_pointer_casted.into()],
|
||||||
|
)
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
panic!(
|
||||||
|
"{} should return a value",
|
||||||
|
revive_runtime_api::polkavm_imports::CODE_SIZE
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.into_int_value();
|
||||||
|
|
||||||
context.build_runtime_call(
|
Ok(context
|
||||||
revive_runtime_api::polkavm_imports::CODE_SIZE,
|
.builder()
|
||||||
&[
|
.build_int_z_extend(value, context.word_type(), "extcodesize")?
|
||||||
address_pointer.to_int(context).into(),
|
.as_basic_value_enum())
|
||||||
output_pointer.to_int(context).into(),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
context.build_load(output_pointer, "code_size")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `extcodehash` instruction.
|
/// Translates the `extcodehash` instruction.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
//! 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;
|
||||||
|
|
||||||
@@ -12,10 +13,14 @@ pub fn load<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let mut slot_ptr = context.build_alloca_at_entry(context.word_type(), "slot_pointer");
|
let position_pointer = Pointer::new_with_offset(
|
||||||
slot_ptr.address_space = AddressSpace::Storage;
|
context,
|
||||||
context.builder().build_store(slot_ptr.value, position)?;
|
AddressSpace::Storage,
|
||||||
context.build_load(slot_ptr, "storage_load_value")
|
context.word_type(),
|
||||||
|
position,
|
||||||
|
"storage_load_position_pointer",
|
||||||
|
);
|
||||||
|
context.build_load(position_pointer, "storage_load_value")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the storage store.
|
/// Translates the storage store.
|
||||||
@@ -27,10 +32,14 @@ pub fn store<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let mut slot_ptr = context.build_alloca_at_entry(context.word_type(), "slot_pointer");
|
let position_pointer = Pointer::new_with_offset(
|
||||||
slot_ptr.address_space = AddressSpace::Storage;
|
context,
|
||||||
context.builder().build_store(slot_ptr.value, position)?;
|
AddressSpace::Storage,
|
||||||
context.build_store(slot_ptr, value)?;
|
context.word_type(),
|
||||||
|
position,
|
||||||
|
"storage_store_position_pointer",
|
||||||
|
);
|
||||||
|
context.build_store(position_pointer, value)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,10 +51,14 @@ pub fn transient_load<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let mut slot_ptr = context.build_alloca_at_entry(context.word_type(), "slot_pointer");
|
let position_pointer = Pointer::new_with_offset(
|
||||||
slot_ptr.address_space = AddressSpace::TransientStorage;
|
context,
|
||||||
context.builder().build_store(slot_ptr.value, position)?;
|
AddressSpace::TransientStorage,
|
||||||
context.build_load(slot_ptr, "transient_storage_load_value")
|
context.word_type(),
|
||||||
|
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.
|
||||||
@@ -57,9 +70,13 @@ pub fn transient_store<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let mut slot_ptr = context.build_alloca_at_entry(context.word_type(), "slot_pointer");
|
let position_pointer = Pointer::new_with_offset(
|
||||||
slot_ptr.address_space = AddressSpace::TransientStorage;
|
context,
|
||||||
context.builder().build_store(slot_ptr.value, position)?;
|
AddressSpace::TransientStorage,
|
||||||
context.build_store(slot_ptr, value)?;
|
context.word_type(),
|
||||||
|
position,
|
||||||
|
"transient_storage_store_position_pointer",
|
||||||
|
);
|
||||||
|
context.build_store(position_pointer, value)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ impl TargetMachine {
|
|||||||
|
|
||||||
/// LLVM target features.
|
/// LLVM target features.
|
||||||
#[cfg(feature = "riscv-zbb")]
|
#[cfg(feature = "riscv-zbb")]
|
||||||
pub const VM_FEATURES: &'static str = "+zbb,+a,+e,+m,+c,+fast-unaligned-access,+xtheadcondmov";
|
pub const VM_FEATURES: &'static str = "+zbb,+e,+m,+c";
|
||||||
#[cfg(not(feature = "riscv-zbb"))]
|
#[cfg(not(feature = "riscv-zbb"))]
|
||||||
pub const VM_FEATURES: &'static str = "+a,+e,+m,+c,+fast-unaligned-access,+xtheadcondmov";
|
pub const VM_FEATURES: &'static str = "+e,+m,+c";
|
||||||
|
|
||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
/// A separate instance for every optimization level is created.
|
/// A separate instance for every optimization level is created.
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ impl ExtBuilder {
|
|||||||
Self {
|
Self {
|
||||||
balance_genesis_config: value
|
balance_genesis_config: value
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(address, balance)| (AccountId::to_fallback_account_id(address), *balance))
|
.map(|(address, balance)| (AccountId::to_account_id(address), *balance))
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,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(crate::runtime::Hash),
|
Hash(Hash),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Code {
|
impl Default for Code {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
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::*},
|
||||||
@@ -8,7 +7,7 @@ use polkadot_sdk::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub type Balance = u128;
|
pub type Balance = u128;
|
||||||
pub type AccountId = pallet_revive::AccountId32Mapper<Runtime>;
|
pub type AccountId = pallet_revive::DefaultAddressMapper;
|
||||||
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 =
|
||||||
@@ -75,7 +74,7 @@ impl pallet_revive::Config for Runtime {
|
|||||||
type ChainExtension = ();
|
type ChainExtension = ();
|
||||||
type DepositPerByte = DepositPerByte;
|
type DepositPerByte = DepositPerByte;
|
||||||
type DepositPerItem = DepositPerItem;
|
type DepositPerItem = DepositPerItem;
|
||||||
type AddressMapper = AccountId32Mapper<Self>;
|
type AddressMapper = AccountId;
|
||||||
type RuntimeMemory = ConstU32<{ 512 * 1024 * 1024 }>;
|
type RuntimeMemory = ConstU32<{ 512 * 1024 * 1024 }>;
|
||||||
type PVFMemory = ConstU32<{ 1024 * 1024 * 1024 }>;
|
type PVFMemory = ConstU32<{ 1024 * 1024 * 1024 }>;
|
||||||
type UnsafeUnstableInterface = UnstableInterface;
|
type UnsafeUnstableInterface = UnstableInterface;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use pallet_revive::AddressMapper;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ POLKAVM_IMPORT(void, caller, uint32_t)
|
|||||||
|
|
||||||
POLKAVM_IMPORT(void, chain_id, uint32_t)
|
POLKAVM_IMPORT(void, chain_id, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, code_size, uint32_t, uint32_t)
|
POLKAVM_IMPORT(uint32_t, code_size, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, code_hash, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, code_hash, uint32_t, uint32_t)
|
||||||
|
|
||||||
@@ -96,8 +96,6 @@ POLKAVM_IMPORT(uint32_t, instantiate, uint32_t)
|
|||||||
|
|
||||||
POLKAVM_IMPORT(void, now, uint32_t)
|
POLKAVM_IMPORT(void, now, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, origin, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(uint32_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ pub static INSTANTIATE: &str = "instantiate";
|
|||||||
|
|
||||||
pub static NOW: &str = "now";
|
pub static NOW: &str = "now";
|
||||||
|
|
||||||
pub static ORIGIN: &str = "origin";
|
|
||||||
|
|
||||||
pub static RETURN: &str = "seal_return";
|
pub static RETURN: &str = "seal_return";
|
||||||
|
|
||||||
pub static SET_STORAGE: &str = "set_storage";
|
pub static SET_STORAGE: &str = "set_storage";
|
||||||
@@ -62,7 +60,7 @@ pub static VALUE_TRANSFERRED: &str = "value_transferred";
|
|||||||
|
|
||||||
/// All imported runtime API symbols.
|
/// All imported runtime API symbols.
|
||||||
/// Useful for configuring common attributes and linkage.
|
/// Useful for configuring common attributes and linkage.
|
||||||
pub static IMPORTS: [&str; 25] = [
|
pub static IMPORTS: [&str; 24] = [
|
||||||
SBRK,
|
SBRK,
|
||||||
MEMORY_SIZE,
|
MEMORY_SIZE,
|
||||||
ADDRESS,
|
ADDRESS,
|
||||||
@@ -81,7 +79,6 @@ pub static IMPORTS: [&str; 25] = [
|
|||||||
INPUT,
|
INPUT,
|
||||||
INSTANTIATE,
|
INSTANTIATE,
|
||||||
NOW,
|
NOW,
|
||||||
ORIGIN,
|
|
||||||
RETURN,
|
RETURN,
|
||||||
RETURNDATACOPY,
|
RETURNDATACOPY,
|
||||||
RETURNDATASIZE,
|
RETURNDATASIZE,
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
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,7 +8,6 @@ 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;
|
||||||
|
|
||||||
@@ -41,7 +40,11 @@ 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(self, combined_json: &mut CombinedJson) -> anyhow::Result<()> {
|
pub fn write_to_combined_json(
|
||||||
|
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
|
||||||
@@ -58,7 +61,7 @@ impl Build {
|
|||||||
contract.write_to_combined_json(combined_json_contract)?;
|
contract.write_to_combined_json(combined_json_contract)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
combined_json.revive_version = Some(ResolcVersion::default().long);
|
combined_json.zk_version = Some(resolc_version.to_string());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -68,6 +71,7 @@ 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,
|
||||||
@@ -86,7 +90,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.revive_version = Some(ResolcVersion::default().long);
|
standard_json.zk_version = Some(resolc_version.to_string());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ pub(crate) mod missing_libraries;
|
|||||||
pub(crate) mod process;
|
pub(crate) mod process;
|
||||||
pub(crate) mod project;
|
pub(crate) mod project;
|
||||||
pub(crate) mod solc;
|
pub(crate) mod solc;
|
||||||
pub(crate) mod version;
|
|
||||||
pub(crate) mod warning;
|
pub(crate) mod warning;
|
||||||
pub(crate) mod yul;
|
pub(crate) mod yul;
|
||||||
|
|
||||||
@@ -39,7 +38,6 @@ pub use self::solc::standard_json::output::contract::Contract as SolcStandardJso
|
|||||||
pub use self::solc::standard_json::output::Output as SolcStandardJsonOutput;
|
pub use self::solc::standard_json::output::Output as SolcStandardJsonOutput;
|
||||||
pub use self::solc::version::Version as SolcVersion;
|
pub use self::solc::version::Version as SolcVersion;
|
||||||
pub use self::solc::Compiler as SolcCompiler;
|
pub use self::solc::Compiler as SolcCompiler;
|
||||||
pub use self::version::Version as ResolcVersion;
|
|
||||||
pub use self::warning::Warning;
|
pub use self::warning::Warning;
|
||||||
|
|
||||||
pub mod test_utils;
|
pub mod test_utils;
|
||||||
@@ -199,6 +197,7 @@ pub fn standard_json(
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let solc_version = solc.version()?;
|
let solc_version = solc.version()?;
|
||||||
let solc_pipeline = SolcPipeline::new(&solc_version, force_evmla);
|
let solc_pipeline = SolcPipeline::new(&solc_version, force_evmla);
|
||||||
|
let resolc_version = semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Always valid");
|
||||||
|
|
||||||
let solc_input = SolcStandardJsonInput::try_from_stdin(solc_pipeline)?;
|
let solc_input = SolcStandardJsonInput::try_from_stdin(solc_pipeline)?;
|
||||||
let source_code_files = solc_input
|
let source_code_files = solc_input
|
||||||
@@ -245,10 +244,14 @@ pub fn standard_json(
|
|||||||
|
|
||||||
if detect_missing_libraries {
|
if detect_missing_libraries {
|
||||||
let missing_libraries = project.get_missing_libraries();
|
let missing_libraries = project.get_missing_libraries();
|
||||||
missing_libraries.write_to_standard_json(&mut solc_output, &solc_version)?;
|
missing_libraries.write_to_standard_json(
|
||||||
|
&mut solc_output,
|
||||||
|
&solc_version,
|
||||||
|
&resolc_version,
|
||||||
|
)?;
|
||||||
} else {
|
} else {
|
||||||
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||||
build.write_to_standard_json(&mut solc_output, &solc_version)?;
|
build.write_to_standard_json(&mut solc_output, &solc_version, &resolc_version)?;
|
||||||
}
|
}
|
||||||
serde_json::to_writer(std::io::stdout(), &solc_output)?;
|
serde_json::to_writer(std::io::stdout(), &solc_output)?;
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
@@ -275,6 +278,8 @@ pub fn combined_json(
|
|||||||
output_directory: Option<PathBuf>,
|
output_directory: Option<PathBuf>,
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
let resolc_version = semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Always valid");
|
||||||
|
|
||||||
let build = standard_output(
|
let build = standard_output(
|
||||||
input_files,
|
input_files,
|
||||||
libraries,
|
libraries,
|
||||||
@@ -293,7 +298,7 @@ pub fn combined_json(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
let mut combined_json = solc.combined_json(input_files, format.as_str())?;
|
let mut combined_json = solc.combined_json(input_files, format.as_str())?;
|
||||||
build.write_to_combined_json(&mut combined_json)?;
|
build.write_to_combined_json(&mut combined_json, &resolc_version)?;
|
||||||
|
|
||||||
match output_directory {
|
match output_directory {
|
||||||
Some(output_directory) => {
|
Some(output_directory) => {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use std::collections::HashSet;
|
|||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
/// The missing Solidity libraries.
|
/// The missing Solidity libraries.
|
||||||
pub struct MissingLibraries {
|
pub struct MissingLibraries {
|
||||||
@@ -24,6 +23,7 @@ impl MissingLibraries {
|
|||||||
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,
|
||||||
@@ -43,7 +43,7 @@ impl MissingLibraries {
|
|||||||
|
|
||||||
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.revive_version = Some(ResolcVersion::default().long);
|
standard_json.zk_version = Some(resolc_version.to_string());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::ResolcVersion;
|
|
||||||
|
|
||||||
/// The Solidity contract metadata.
|
/// The Solidity contract metadata.
|
||||||
/// Is used to append the metadata hash to the contract bytecode.
|
/// Is used to append the metadata hash to the contract bytecode.
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@@ -11,11 +9,11 @@ pub struct Metadata {
|
|||||||
/// The `solc` metadata.
|
/// The `solc` metadata.
|
||||||
pub solc_metadata: serde_json::Value,
|
pub solc_metadata: serde_json::Value,
|
||||||
/// The `solc` version.
|
/// The `solc` version.
|
||||||
pub solc_version: String,
|
pub solc_version: semver::Version,
|
||||||
/// The pallet revive edition.
|
/// The zkVM `solc` edition.
|
||||||
pub revive_pallet_version: Option<semver::Version>,
|
pub solc_zkvm_edition: Option<semver::Version>,
|
||||||
/// The PolkaVM compiler version.
|
/// The PolkaVM compiler version.
|
||||||
pub revive_version: String,
|
pub zk_version: semver::Version,
|
||||||
/// The PolkaVM compiler optimizer settings.
|
/// The PolkaVM compiler optimizer settings.
|
||||||
pub optimizer_settings: revive_llvm_context::OptimizerSettings,
|
pub optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
}
|
}
|
||||||
@@ -24,15 +22,16 @@ impl Metadata {
|
|||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
solc_metadata: serde_json::Value,
|
solc_metadata: serde_json::Value,
|
||||||
solc_version: String,
|
solc_version: semver::Version,
|
||||||
revive_pallet_version: Option<semver::Version>,
|
solc_zkvm_edition: Option<semver::Version>,
|
||||||
|
zk_version: semver::Version,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
solc_metadata,
|
solc_metadata,
|
||||||
solc_version,
|
solc_version,
|
||||||
revive_pallet_version,
|
solc_zkvm_edition,
|
||||||
revive_version: ResolcVersion::default().long,
|
zk_version,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,8 +89,9 @@ impl Contract {
|
|||||||
|
|
||||||
let metadata = Metadata::new(
|
let metadata = Metadata::new(
|
||||||
self.metadata_json.take(),
|
self.metadata_json.take(),
|
||||||
version.long.clone(),
|
version.default.clone(),
|
||||||
version.l2_revision.clone(),
|
version.l2_revision.clone(),
|
||||||
|
semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Always valid"),
|
||||||
optimizer.settings().to_owned(),
|
optimizer.settings().to_owned(),
|
||||||
);
|
);
|
||||||
let metadata_json = serde_json::to_value(&metadata).expect("Always valid");
|
let metadata_json = serde_json::to_value(&metadata).expect("Always valid");
|
||||||
|
|||||||
@@ -31,9 +31,10 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
if arguments.version {
|
if arguments.version {
|
||||||
println!(
|
println!(
|
||||||
"{} version {}",
|
"{} v{} (LLVM build {:?})",
|
||||||
env!("CARGO_PKG_DESCRIPTION"),
|
env!("CARGO_PKG_DESCRIPTION"),
|
||||||
revive_solidity::ResolcVersion::default().long
|
env!("CARGO_PKG_VERSION"),
|
||||||
|
inkwell::support::get_llvm_version()
|
||||||
);
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ pub struct CombinedJson {
|
|||||||
pub version: String,
|
pub version: String,
|
||||||
/// The `resolc` compiler version.
|
/// The `resolc` compiler version.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub revive_version: Option<String>,
|
pub zk_version: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CombinedJson {
|
impl CombinedJson {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ pub struct Output {
|
|||||||
pub long_version: Option<String>,
|
pub long_version: Option<String>,
|
||||||
/// The `resolc` compiler version.
|
/// The `resolc` compiler version.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub revive_version: Option<String>,
|
pub zk_version: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Output {
|
impl Output {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::collections::BTreeMap;
|
|||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
@@ -105,7 +106,11 @@ pub fn build_solidity_with_options(
|
|||||||
let project = output.try_to_project(sources, libraries, pipeline, &solc_version, None)?;
|
let project = output.try_to_project(sources, libraries, pipeline, &solc_version, None)?;
|
||||||
|
|
||||||
let build: crate::Build = project.compile(optimizer_settings, false, None)?;
|
let build: crate::Build = project.compile(optimizer_settings, false, None)?;
|
||||||
build.write_to_standard_json(&mut output, &solc_version)?;
|
build.write_to_standard_json(
|
||||||
|
&mut output,
|
||||||
|
&solc_version,
|
||||||
|
&semver::Version::from_str(env!("CARGO_PKG_VERSION"))?,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
@@ -197,7 +202,11 @@ pub fn build_solidity_and_detect_missing_libraries(
|
|||||||
let project = output.try_to_project(sources, libraries, pipeline, &solc_version, None)?;
|
let project = output.try_to_project(sources, libraries, pipeline, &solc_version, None)?;
|
||||||
|
|
||||||
let missing_libraries = project.get_missing_libraries();
|
let missing_libraries = project.get_missing_libraries();
|
||||||
missing_libraries.write_to_standard_json(&mut output, &solc.version()?)?;
|
missing_libraries.write_to_standard_json(
|
||||||
|
&mut output,
|
||||||
|
&solc.version()?,
|
||||||
|
&semver::Version::from_str(env!("CARGO_PKG_VERSION"))?,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
@@ -223,14 +232,14 @@ pub fn check_solidity_warning(
|
|||||||
warning_substring: &str,
|
warning_substring: &str,
|
||||||
libraries: BTreeMap<String, BTreeMap<String, String>>,
|
libraries: BTreeMap<String, BTreeMap<String, String>>,
|
||||||
pipeline: SolcPipeline,
|
pipeline: SolcPipeline,
|
||||||
skip_for_revive_edition: bool,
|
skip_for_zkvm_edition: bool,
|
||||||
suppressed_warnings: Option<Vec<Warning>>,
|
suppressed_warnings: Option<Vec<Warning>>,
|
||||||
) -> anyhow::Result<bool> {
|
) -> anyhow::Result<bool> {
|
||||||
check_dependencies();
|
check_dependencies();
|
||||||
|
|
||||||
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
||||||
let solc_version = solc.version()?;
|
let solc_version = solc.version()?;
|
||||||
if skip_for_revive_edition && solc_version.l2_revision.is_some() {
|
if skip_for_zkvm_edition && solc_version.l2_revision.is_some() {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
//! The resolc compiler version.
|
|
||||||
|
|
||||||
use serde::Deserialize;
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
/// The resolc compiler version.
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
||||||
pub struct Version {
|
|
||||||
/// The long version string.
|
|
||||||
pub long: String,
|
|
||||||
/// The short `semver`.
|
|
||||||
pub default: semver::Version,
|
|
||||||
/// The LLVM version string.
|
|
||||||
pub llvm: semver::Version,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Version {
|
|
||||||
fn default() -> Self {
|
|
||||||
let default = semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Always valid");
|
|
||||||
let commit = env!("GIT_COMMIT_HASH");
|
|
||||||
let (llvm_major, llvm_minor, llvm_patch) = inkwell::support::get_llvm_version();
|
|
||||||
let llvm = semver::Version::new(llvm_major as u64, llvm_minor as u64, llvm_patch as u64);
|
|
||||||
|
|
||||||
Self {
|
|
||||||
long: format!("{default}+commit.{commit}.llvm-{llvm}"),
|
|
||||||
default,
|
|
||||||
llvm,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user