mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 21:31:05 +00:00
Compare commits
32 Commits
v0.1.0-dev
...
sm/nodejs
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
@@ -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.27/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
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# 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
+1885
-824
File diff suppressed because it is too large
Load Diff
+20
-19
@@ -3,7 +3,7 @@ resolver = "2"
|
|||||||
members = ["crates/*"]
|
members = ["crates/*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.1.0"
|
version = "0.1.0-dev.5"
|
||||||
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", path = "crates/benchmarks" }
|
revive-benchmarks = { version = "0.1.0-dev.5", path = "crates/benchmarks" }
|
||||||
revive-builtins = { version = "0.1.0", path = "crates/builtins" }
|
revive-builtins = { version = "0.1.0-dev.5", path = "crates/builtins" }
|
||||||
revive-common = { version = "0.1.0", path = "crates/common" }
|
revive-common = { version = "0.1.0-dev.5", path = "crates/common" }
|
||||||
revive-differential = { version = "0.1.0", path = "crates/differential" }
|
revive-differential = { version = "0.1.0-dev.5", path = "crates/differential" }
|
||||||
revive-integration = { version = "0.1.0", path = "crates/integration" }
|
revive-integration = { version = "0.1.0-dev.5", path = "crates/integration" }
|
||||||
revive-linker = { version = "0.1.0", path = "crates/linker" }
|
revive-linker = { version = "0.1.0-dev.5", path = "crates/linker" }
|
||||||
lld-sys = { version = "0.1.0", path = "crates/lld-sys" }
|
lld-sys = { version = "0.1.0-dev.5", path = "crates/lld-sys" }
|
||||||
revive-llvm-context = { version = "0.1.0", path = "crates/llvm-context" }
|
revive-llvm-context = { version = "0.1.0-dev.5", path = "crates/llvm-context" }
|
||||||
revive-runtime-api = { version = "0.1.0", path = "crates/runtime-api" }
|
revive-runtime-api = { version = "0.1.0-dev.5", path = "crates/runtime-api" }
|
||||||
revive-runner = { version = "0.1.0", path = "crates/runner" }
|
revive-runner = { version = "0.1.0-dev.5", path = "crates/runner" }
|
||||||
revive-solidity = { version = "0.1.0", path = "crates/solidity" }
|
revive-solidity = { version = "0.1.0-dev.5", path = "crates/solidity" }
|
||||||
revive-stdlib = { version = "0.1.0", path = "crates/stdlib" }
|
revive-stdlib = { version = "0.1.0-dev.5", 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.10"
|
polkavm-common = "0.14"
|
||||||
polkavm-linker = "0.10"
|
polkavm-linker = "0.14"
|
||||||
polkavm-disassembler = "0.10"
|
polkavm-disassembler = "0.14"
|
||||||
polkavm = "0.10"
|
polkavm = "0.14"
|
||||||
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,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 = "c77095f51119d2eccdc54d2f3518bed0ffbd6d53" }
|
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "2b6b69641ccff4d7aa9c32051bbb2f1e775ef8cc" }
|
||||||
|
|
||||||
# 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"]
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ install-revive:
|
|||||||
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
|
||||||
@@ -45,9 +47,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/
|
||||||
|
|
||||||
|
|||||||
+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
|
||||||
@@ -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)]
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"Baseline": 912,
|
"Baseline": 967,
|
||||||
"Computation": 4413,
|
"Computation": 4022,
|
||||||
"DivisionArithmetics": 40689,
|
"DivisionArithmetics": 31787,
|
||||||
"ERC20": 54374,
|
"ERC20": 44233,
|
||||||
"Events": 1726,
|
"Events": 1743,
|
||||||
"FibonacciIterative": 3015,
|
"FibonacciIterative": 2927,
|
||||||
"Flipper": 3612,
|
"Flipper": 3408,
|
||||||
"SHA1": 32865
|
"SHA1": 26009
|
||||||
}
|
}
|
||||||
@@ -21,16 +21,8 @@ pragma solidity ^0.8;
|
|||||||
"Solidity": {
|
"Solidity": {
|
||||||
"contract": "Caller"
|
"contract": "Caller"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Call": {
|
|
||||||
"dest": {
|
|
||||||
"Instantiated": 0
|
|
||||||
},
|
},
|
||||||
"value": 123,
|
"value": 123
|
||||||
"data": "1eb16e5b000000000000000000000000d8b934580fce35a11b58c6d73adee468a2833fa8"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -49,11 +41,14 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
receive() external payable {}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract Caller {
|
contract Caller {
|
||||||
function value_transfer(address payable destination) public payable {
|
constructor() payable {
|
||||||
destination.transfer(msg.value);
|
Callee callee = new Callee();
|
||||||
|
payable(address(callee)).transfer(msg.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function call(bytes memory payload) public returns (bytes memory) {
|
function call(bytes memory payload) public returns (bytes memory) {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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,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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,15 @@ pragma solidity ^0.8;
|
|||||||
{
|
{
|
||||||
"differential": true,
|
"differential": true,
|
||||||
"actions": [
|
"actions": [
|
||||||
|
{
|
||||||
|
"Upload": {
|
||||||
|
"code": {
|
||||||
|
"Solidity": {
|
||||||
|
"contract": "ValueTester"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"Instantiate": {
|
"Instantiate": {
|
||||||
"value": 1024,
|
"value": 1024,
|
||||||
@@ -23,31 +32,35 @@ pragma solidity ^0.8;
|
|||||||
"value": 123,
|
"value": 123,
|
||||||
"data": "3fa4f245"
|
"data": "3fa4f245"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"Call": {
|
|
||||||
"dest": {
|
|
||||||
"Instantiated": 0
|
|
||||||
},
|
|
||||||
"data": "52da5fa0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
contract Value {
|
contract ValueTester {
|
||||||
constructor() payable {}
|
constructor() payable {}
|
||||||
|
|
||||||
function value() public payable returns (uint ret) {
|
|
||||||
ret = msg.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function balance_self() public view returns (uint ret) {
|
function balance_self() public view returns (uint ret) {
|
||||||
ret = address(this).balance;
|
ret = address(this).balance;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function balance_of(address _address) public view returns (uint ret) {
|
contract Value {
|
||||||
ret = _address.balance;
|
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) {
|
||||||
|
ret = msg.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
+198
-50
@@ -42,6 +42,8 @@ test_spec!(create, "CreateB", "Create.sol");
|
|||||||
test_spec!(call, "Caller", "Call.sol");
|
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!(transaction, "Transaction", "Transaction.sol");
|
||||||
|
|
||||||
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
||||||
vec![Instantiate {
|
vec![Instantiate {
|
||||||
@@ -229,6 +231,202 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -259,54 +457,4 @@ fn create2_failure() {
|
|||||||
|
|
||||||
assert_eq!(output.flags, ReturnFlags::Revert);
|
assert_eq!(output.flags, ReturnFlags::Revert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[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 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,9 +27,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;
|
||||||
|
|||||||
@@ -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,14 +1,8 @@
|
|||||||
//! 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.
|
|
||||||
pub const ZKEVM_VERSION: semver::Version = semver::Version::new(1, 3, 2);
|
|
||||||
|
|
||||||
/// The register width sized type
|
/// The register width sized type
|
||||||
pub static XLEN: usize = revive_common::BIT_LENGTH_X32;
|
pub static XLEN: usize = revive_common::BIT_LENGTH_X32;
|
||||||
|
|
||||||
@@ -24,31 +18,6 @@ pub static GLOBAL_CALLDATA_SIZE: &str = "calldatasize";
|
|||||||
/// 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 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,77 +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 CHAIN_ID: &str = "chain_id";
|
|
||||||
|
|
||||||
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 = "return_data_copy";
|
|
||||||
|
|
||||||
pub static RETURNDATASIZE: &str = "return_data_size";
|
|
||||||
|
|
||||||
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; 18] = [
|
|
||||||
ADDRESS,
|
|
||||||
BALANCE,
|
|
||||||
BLOCK_NUMBER,
|
|
||||||
CALL,
|
|
||||||
CALLER,
|
|
||||||
CHAIN_ID,
|
|
||||||
CODE_SIZE,
|
|
||||||
DEPOSIT_EVENT,
|
|
||||||
GET_STORAGE,
|
|
||||||
HASH_KECCAK_256,
|
|
||||||
INPUT,
|
|
||||||
INSTANTIATE,
|
|
||||||
NOW,
|
|
||||||
RETURN,
|
|
||||||
RETURNDATACOPY,
|
|
||||||
RETURNDATASIZE,
|
|
||||||
SET_STORAGE,
|
|
||||||
VALUE_TRANSFERRED,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// PolkaVM __sbrk API symbol to extend the heap memory.
|
|
||||||
pub static SBRK: &str = "__sbrk";
|
|
||||||
@@ -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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,12 +48,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 +85,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.
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use inkwell::types::BasicType;
|
|||||||
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;
|
||||||
|
|
||||||
@@ -19,9 +18,6 @@ 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.
|
|
||||||
pub const MANDATORY_ARGUMENTS_COUNT: usize = 2;
|
|
||||||
|
|
||||||
/// Reserve 1kb for calldata.
|
/// Reserve 1kb for calldata.
|
||||||
pub const MAX_CALLDATA_SIZE: usize = 1024;
|
pub const MAX_CALLDATA_SIZE: usize = 1024;
|
||||||
|
|
||||||
@@ -49,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(
|
||||||
@@ -97,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()],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -176,7 +175,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,
|
||||||
@@ -184,6 +183,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(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,116 @@
|
|||||||
|
//! 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)?;
|
||||||
|
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);
|
||||||
|
|
||||||
|
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,
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ 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;
|
||||||
@@ -136,7 +135,7 @@ 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")
|
.expect("should be declared")
|
||||||
@@ -162,6 +161,18 @@ where
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn link_immutable_data(&self, contract_path: &str) -> anyhow::Result<()> {
|
||||||
|
let size = self.solidity().immutables_size() as u32;
|
||||||
|
let exports = revive_runtime_api::immutable_data::module(self.llvm(), size);
|
||||||
|
self.module.link_in_module(exports).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,
|
||||||
@@ -239,6 +250,7 @@ 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());
|
target_machine.set_target_data(self.module());
|
||||||
@@ -381,6 +393,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,47 +412,14 @@ 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);
|
||||||
|
|
||||||
let entry_block = self.llvm.append_basic_block(value, "entry");
|
let entry_block = self.llvm.append_basic_block(value, "entry");
|
||||||
@@ -444,12 +432,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,10 +452,6 @@ 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());
|
||||||
|
|
||||||
@@ -534,10 +512,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(),
|
||||||
)
|
)
|
||||||
@@ -632,6 +606,23 @@ where
|
|||||||
Pointer::new(r#type, AddressSpace::Stack, pointer)
|
Pointer::new(r#type, AddressSpace::Stack, pointer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Truncate `address` to the ethereum address length and store it as bytes on the stack.
|
||||||
|
/// 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.
|
||||||
|
pub fn build_address_argument_store(
|
||||||
|
&self,
|
||||||
|
address: inkwell::values::IntValue<'ctx>,
|
||||||
|
) -> anyhow::Result<Pointer<'ctx>> {
|
||||||
|
let address_type = self.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
||||||
|
let address_pointer = self.build_alloca_at_entry(address_type, "address_pointer");
|
||||||
|
let address_truncated =
|
||||||
|
self.builder()
|
||||||
|
.build_int_truncate(address, address_type, "address_truncated")?;
|
||||||
|
let address_swapped = self.build_byte_swap(address_truncated.into())?;
|
||||||
|
self.build_store(address_pointer, address_swapped)?;
|
||||||
|
Ok(address_pointer)
|
||||||
|
}
|
||||||
|
|
||||||
/// Load the address 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_address(
|
pub fn build_load_address(
|
||||||
&self,
|
&self,
|
||||||
@@ -678,22 +669,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(
|
||||||
@@ -704,10 +683,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(),
|
||||||
@@ -776,18 +755,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,
|
||||||
@@ -795,18 +762,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(),
|
||||||
@@ -915,7 +880,7 @@ 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()
|
||||||
@@ -1038,7 +1003,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();
|
||||||
@@ -1096,16 +1061,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()
|
||||||
@@ -1114,14 +1083,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,
|
||||||
@@ -1139,7 +1123,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
|
||||||
@@ -1154,40 +1138,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],
|
||||||
@@ -1308,12 +1264,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)
|
||||||
@@ -1325,11 +1280,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),
|
||||||
@@ -1522,12 +1472,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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,7 +5,6 @@ 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;
|
|
||||||
|
|
||||||
const STATIC_CALL_FLAG: u32 = 0b0001_0000;
|
const STATIC_CALL_FLAG: u32 = 0b0001_0000;
|
||||||
const REENTRANT_CALL_FLAG: u32 = 0b0000_1000;
|
const REENTRANT_CALL_FLAG: u32 = 0b0000_1000;
|
||||||
@@ -27,14 +26,7 @@ pub fn call<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
let address_pointer = context.build_address_argument_store(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 value = value.unwrap_or_else(|| context.word_const(0));
|
let value = value.unwrap_or_else(|| context.word_const(0));
|
||||||
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||||
@@ -84,7 +76,7 @@ where
|
|||||||
arguments,
|
arguments,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let name = runtime_api::imports::CALL;
|
let name = revive_runtime_api::polkavm_imports::CALL;
|
||||||
let argument_pointer = context.builder().build_ptr_to_int(
|
let argument_pointer = context.builder().build_ptr_to_int(
|
||||||
argument_pointer.value,
|
argument_pointer.value,
|
||||||
context.xlen_type(),
|
context.xlen_type(),
|
||||||
|
|||||||
@@ -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>(
|
||||||
@@ -28,12 +27,19 @@ 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,
|
||||||
{
|
{
|
||||||
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,
|
||||||
{
|
{
|
||||||
context.build_runtime_call_to_getter(runtime_api::imports::CHAIN_ID)
|
context.build_runtime_call_to_getter(revive_runtime_api::polkavm_imports::CHAIN_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `block_number` instruction.
|
/// Translates the `block_number` instruction.
|
||||||
@@ -53,7 +59,7 @@ pub fn block_number<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
context.build_runtime_call_to_getter(runtime_api::imports::BLOCK_NUMBER)
|
context.build_runtime_call_to_getter(revive_runtime_api::polkavm_imports::BLOCK_NUMBER)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `block_timestamp` instruction.
|
/// Translates the `block_timestamp` instruction.
|
||||||
@@ -63,7 +69,7 @@ pub fn block_timestamp<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
context.build_runtime_call_to_getter(runtime_api::imports::NOW)
|
context.build_runtime_call_to_getter(revive_runtime_api::polkavm_imports::NOW)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `block_hash` instruction.
|
/// Translates the `block_hash` instruction.
|
||||||
@@ -107,33 +113,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>,
|
||||||
@@ -146,7 +125,7 @@ where
|
|||||||
"address_output",
|
"address_output",
|
||||||
);
|
);
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(
|
||||||
runtime_api::imports::ADDRESS,
|
revive_runtime_api::polkavm_imports::ADDRESS,
|
||||||
&[pointer.to_int(context).into()],
|
&[pointer.to_int(context).into()],
|
||||||
);
|
);
|
||||||
context.build_load_address(pointer)
|
context.build_load_address(pointer)
|
||||||
@@ -164,7 +143,7 @@ where
|
|||||||
"address_output",
|
"address_output",
|
||||||
);
|
);
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(
|
||||||
runtime_api::imports::CALLER,
|
revive_runtime_api::polkavm_imports::CALLER,
|
||||||
&[pointer.to_int(context).into()],
|
&[pointer.to_int(context).into()],
|
||||||
);
|
);
|
||||||
context.build_load_address(pointer)
|
context.build_load_address(pointer)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ 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` and `create2` instruction.
|
/// Translates the contract `create` and `create2` instruction.
|
||||||
///
|
///
|
||||||
@@ -82,7 +81,7 @@ where
|
|||||||
"instantiate_argument_pointer",
|
"instantiate_argument_pointer",
|
||||||
)?;
|
)?;
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(
|
||||||
runtime_api::imports::INSTANTIATE,
|
revive_runtime_api::polkavm_imports::INSTANTIATE,
|
||||||
&[argument_pointer.into()],
|
&[argument_pointer.into()],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -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>(
|
||||||
@@ -26,7 +25,7 @@ where
|
|||||||
let output_pointer = context.build_alloca(context.value_type(), "value_transferred");
|
let output_pointer = context.build_alloca(context.value_type(), "value_transferred");
|
||||||
context.build_store(output_pointer, context.word_const(0))?;
|
context.build_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()],
|
||||||
);
|
);
|
||||||
context.build_load(output_pointer, "value_transferred")
|
context.build_load(output_pointer, "value_transferred")
|
||||||
@@ -40,22 +39,19 @@ 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(runtime_api::imports::BALANCE, &[balance.into()]);
|
context.build_runtime_call(
|
||||||
|
revive_runtime_api::polkavm_imports::BALANCE_OF,
|
||||||
|
&[address_pointer.to_int(context).into(), balance.into()],
|
||||||
|
);
|
||||||
|
|
||||||
context.build_load(balance_pointer, "balance")
|
context.build_load(balance_pointer, "balance")
|
||||||
}
|
}
|
||||||
@@ -74,7 +70,10 @@ where
|
|||||||
"balance",
|
"balance",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
context.build_runtime_call(runtime_api::imports::BALANCE, &[balance.into()]);
|
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.
|
||||||
///
|
///
|
||||||
@@ -77,7 +76,10 @@ where
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
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(
|
||||||
|
|||||||
@@ -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 return data size.
|
/// Translates the return data size.
|
||||||
pub fn size<'ctx, D>(
|
pub fn size<'ctx, D>(
|
||||||
@@ -18,7 +17,7 @@ where
|
|||||||
"return_data_copy_output_pointer",
|
"return_data_copy_output_pointer",
|
||||||
)?;
|
)?;
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(
|
||||||
runtime_api::imports::RETURNDATASIZE,
|
revive_runtime_api::polkavm_imports::RETURNDATASIZE,
|
||||||
&[output_pointer_parameter.into()],
|
&[output_pointer_parameter.into()],
|
||||||
);
|
);
|
||||||
context.build_load(output_pointer, "return_data_size_load")
|
context.build_load(output_pointer, "return_data_size_load")
|
||||||
@@ -59,7 +58,7 @@ where
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(
|
||||||
runtime_api::imports::RETURNDATACOPY,
|
revive_runtime_api::polkavm_imports::RETURNDATACOPY,
|
||||||
&[
|
&[
|
||||||
output_pointer.into(),
|
output_pointer.into(),
|
||||||
output_length_pointer_int.into(),
|
output_length_pointer_int.into(),
|
||||||
|
|||||||
@@ -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(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,6 @@ 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: Option<DebugConfig>,
|
||||||
) -> anyhow::Result<String>;
|
) -> anyhow::Result<String>;
|
||||||
@@ -118,7 +117,6 @@ 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: Option<DebugConfig>,
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
|
|||||||
@@ -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,+e,+m,+c";
|
pub const VM_FEATURES: &'static str = "+zbb,+a,+e,+m,+c,+fast-unaligned-access,+xtheadcondmov";
|
||||||
#[cfg(not(feature = "riscv-zbb"))]
|
#[cfg(not(feature = "riscv-zbb"))]
|
||||||
pub const VM_FEATURES: &'static str = "+e,+m,+c";
|
pub const VM_FEATURES: &'static str = "+a,+e,+m,+c,+fast-unaligned-access,+xtheadcondmov";
|
||||||
|
|
||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
/// A separate instance for every optimization level is created.
|
/// A separate instance for every optimization level is created.
|
||||||
|
|||||||
Binary file not shown.
+22
-11
@@ -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,
|
||||||
};
|
};
|
||||||
@@ -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,7 +75,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 = AccountId;
|
type AddressMapper = AccountId32Mapper<Self>;
|
||||||
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;
|
||||||
|
|||||||
+16
-13
@@ -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")]
|
||||||
@@ -289,16 +288,10 @@ 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,
|
pipeline,
|
||||||
Some(revive_solidity::SolcPipeline::EVMLA),
|
Some(revive_solidity::SolcPipeline::EVMLA),
|
||||||
"yul pipeline must be enabled in differntial mode"
|
"yul pipeline must be enabled in differential mode"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
salt.0.is_none(),
|
salt.0.is_none(),
|
||||||
@@ -311,9 +304,11 @@ impl Specs {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let deploy_code = match std::fs::read_to_string(&path) {
|
let deploy_code = match std::fs::read_to_string(&path) {
|
||||||
Ok(solidity_source) => {
|
Ok(solidity_source) => hex::encode(compile_evm_deploy_code(
|
||||||
hex::encode(compile_evm_deploy_code(&contract, &solidity_source))
|
&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(),
|
||||||
@@ -413,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(
|
||||||
@@ -420,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,
|
||||||
@@ -429,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 {
|
||||||
|
|||||||
@@ -12,4 +12,6 @@ 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 }
|
||||||
|
|||||||
@@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,94 +62,50 @@ 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, address, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, balance, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, balance_of, uint32_t, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, block_number, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(uint32_t, call, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, caller, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, chain_id, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(uint32_t, code_size, uint32_t, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, code_hash, uint32_t, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, deposit_event, uint32_t, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, get_immutable_data, uint32_t, uint32_t);
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(uint32_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, input, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, input, uint32_t, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(uint32_t, instantiate, 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(void, return_data_copy, 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, 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, value_transferred, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, get_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, clear_storage, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, contains_storage, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, take_storage, uint32_t, uint32_t, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, call, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, delegate_call, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, instantiate, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, terminate, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, caller, 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)
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, chain_id, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, now, 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, block_number, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, hash_sha2_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, hash_blake2_128, uint32_t, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, call_chain_extension, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, debug_message, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, set_code_hash, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint64_t, instantiation_nonce,)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, transfer, uint32_t, uint32_t, uint32_t, uint32_t)
|
|
||||||
|
|||||||
@@ -10,6 +10,86 @@ 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_NUMBER: &str = "block_number";
|
||||||
|
|
||||||
|
pub static CALL: &str = "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";
|
||||||
|
|
||||||
|
/// All imported runtime API symbols.
|
||||||
|
/// Useful for configuring common attributes and linkage.
|
||||||
|
pub static IMPORTS: [&str; 25] = [
|
||||||
|
SBRK,
|
||||||
|
MEMORY_SIZE,
|
||||||
|
ADDRESS,
|
||||||
|
BALANCE,
|
||||||
|
BALANCE_OF,
|
||||||
|
BLOCK_NUMBER,
|
||||||
|
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,
|
||||||
|
];
|
||||||
|
|
||||||
/// 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.
|
||||||
|
|||||||
@@ -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(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,6 +199,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)?;
|
||||||
|
|
||||||
@@ -266,6 +267,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();
|
||||||
@@ -1108,7 +1107,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();
|
||||||
@@ -1124,7 +1123,7 @@ where
|
|||||||
.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();
|
||||||
@@ -1155,7 +1154,7 @@ 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)
|
||||||
@@ -1184,7 +1183,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)
|
||||||
@@ -1207,7 +1206,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 => {
|
||||||
@@ -1222,7 +1221,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");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1234,7 +1233,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();
|
||||||
@@ -1297,7 +1296,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();
|
||||||
|
|
||||||
|
|||||||
@@ -1139,7 +1139,6 @@ where
|
|||||||
.integer_type(revive_common::BIT_LENGTH_BOOLEAN)
|
.integer_type(revive_common::BIT_LENGTH_BOOLEAN)
|
||||||
.as_basic_type_enum()],
|
.as_basic_type_enum()],
|
||||||
output_size,
|
output_size,
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
(r#type, output_size)
|
(r#type, output_size)
|
||||||
}
|
}
|
||||||
@@ -1156,7 +1155,6 @@ where
|
|||||||
input_size
|
input_size
|
||||||
],
|
],
|
||||||
output_size,
|
output_size,
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
(r#type, output_size)
|
(r#type, output_size)
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-54
@@ -7,6 +7,7 @@ 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;
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ 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;
|
||||||
@@ -51,7 +53,6 @@ pub fn yul(
|
|||||||
input_files: &[PathBuf],
|
input_files: &[PathBuf],
|
||||||
solc: &mut SolcCompiler,
|
solc: &mut SolcCompiler,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: Option<revive_llvm_context::DebugConfig>,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
@@ -64,28 +65,17 @@ pub fn yul(
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let solc_validator = if is_system_mode {
|
if solc.version()?.default != SolcCompiler::LAST_SUPPORTED_VERSION {
|
||||||
None
|
anyhow::bail!(
|
||||||
} else {
|
|
||||||
if solc.version()?.default != SolcCompiler::LAST_SUPPORTED_VERSION {
|
|
||||||
anyhow::bail!(
|
|
||||||
"The Yul mode is only supported with the most recent version of the Solidity compiler: {}",
|
"The Yul mode is only supported with the most recent version of the Solidity compiler: {}",
|
||||||
SolcCompiler::LAST_SUPPORTED_VERSION,
|
SolcCompiler::LAST_SUPPORTED_VERSION,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(&*solc)
|
|
||||||
};
|
|
||||||
|
|
||||||
|
let solc_validator = Some(&*solc);
|
||||||
let project = Project::try_from_yul_path(path, solc_validator)?;
|
let project = Project::try_from_yul_path(path, solc_validator)?;
|
||||||
|
|
||||||
let build = project.compile(
|
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||||
optimizer_settings,
|
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
|
||||||
false,
|
|
||||||
debug_config,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(build)
|
Ok(build)
|
||||||
}
|
}
|
||||||
@@ -94,7 +84,6 @@ pub fn yul(
|
|||||||
pub fn llvm_ir(
|
pub fn llvm_ir(
|
||||||
input_files: &[PathBuf],
|
input_files: &[PathBuf],
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: Option<revive_llvm_context::DebugConfig>,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
@@ -109,13 +98,7 @@ pub fn llvm_ir(
|
|||||||
|
|
||||||
let project = Project::try_from_llvm_ir_path(path)?;
|
let project = Project::try_from_llvm_ir_path(path)?;
|
||||||
|
|
||||||
let build = project.compile(
|
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||||
optimizer_settings,
|
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
|
||||||
false,
|
|
||||||
debug_config,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(build)
|
Ok(build)
|
||||||
}
|
}
|
||||||
@@ -130,7 +113,6 @@ pub fn standard_output(
|
|||||||
solc_optimizer_enabled: bool,
|
solc_optimizer_enabled: bool,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
force_evmla: bool,
|
force_evmla: bool,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
base_path: Option<String>,
|
base_path: Option<String>,
|
||||||
include_paths: Vec<String>,
|
include_paths: Vec<String>,
|
||||||
@@ -154,7 +136,6 @@ pub fn standard_output(
|
|||||||
None,
|
None,
|
||||||
&solc_version.default,
|
&solc_version.default,
|
||||||
optimizer_settings.is_fallback_to_size_enabled(),
|
optimizer_settings.is_fallback_to_size_enabled(),
|
||||||
optimizer_settings.is_system_request_memoization_disabled(),
|
|
||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
solc_pipeline == SolcPipeline::Yul,
|
solc_pipeline == SolcPipeline::Yul,
|
||||||
@@ -200,13 +181,7 @@ pub fn standard_output(
|
|||||||
debug_config.as_ref(),
|
debug_config.as_ref(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let build = project.compile(
|
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||||
optimizer_settings,
|
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
|
||||||
false,
|
|
||||||
debug_config,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(build)
|
Ok(build)
|
||||||
}
|
}
|
||||||
@@ -217,7 +192,6 @@ pub fn standard_json(
|
|||||||
solc: &mut SolcCompiler,
|
solc: &mut SolcCompiler,
|
||||||
detect_missing_libraries: bool,
|
detect_missing_libraries: bool,
|
||||||
force_evmla: bool,
|
force_evmla: bool,
|
||||||
is_system_mode: bool,
|
|
||||||
base_path: Option<String>,
|
base_path: Option<String>,
|
||||||
include_paths: Vec<String>,
|
include_paths: Vec<String>,
|
||||||
allow_paths: Option<String>,
|
allow_paths: Option<String>,
|
||||||
@@ -225,7 +199,6 @@ 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
|
||||||
@@ -272,20 +245,10 @@ 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(
|
missing_libraries.write_to_standard_json(&mut solc_output, &solc_version)?;
|
||||||
&mut solc_output,
|
|
||||||
&solc_version,
|
|
||||||
&resolc_version,
|
|
||||||
)?;
|
|
||||||
} else {
|
} else {
|
||||||
let build = project.compile(
|
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||||
optimizer_settings,
|
build.write_to_standard_json(&mut solc_output, &solc_version)?;
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
|
||||||
false,
|
|
||||||
debug_config,
|
|
||||||
)?;
|
|
||||||
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);
|
||||||
@@ -302,7 +265,6 @@ pub fn combined_json(
|
|||||||
solc_optimizer_enabled: bool,
|
solc_optimizer_enabled: bool,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
force_evmla: bool,
|
force_evmla: bool,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
base_path: Option<String>,
|
base_path: Option<String>,
|
||||||
include_paths: Vec<String>,
|
include_paths: Vec<String>,
|
||||||
@@ -313,8 +275,6 @@ 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,
|
||||||
@@ -323,7 +283,6 @@ pub fn combined_json(
|
|||||||
solc_optimizer_enabled,
|
solc_optimizer_enabled,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
force_evmla,
|
force_evmla,
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
base_path,
|
base_path,
|
||||||
include_paths,
|
include_paths,
|
||||||
@@ -334,7 +293,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, &resolc_version)?;
|
build.write_to_combined_json(&mut combined_json)?;
|
||||||
|
|
||||||
match output_directory {
|
match output_directory {
|
||||||
Some(output_directory) => {
|
Some(output_directory) => {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ 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 {
|
||||||
@@ -23,7 +24,6 @@ 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.zk_version = Some(resolc_version.to_string());
|
standard_json.revive_version = Some(ResolcVersion::default().long);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,8 @@ pub struct Input {
|
|||||||
pub contract: Contract,
|
pub contract: Contract,
|
||||||
/// The project representation.
|
/// The project representation.
|
||||||
pub project: Project,
|
pub project: Project,
|
||||||
/// The system mode flag.
|
|
||||||
pub is_system_mode: bool,
|
|
||||||
/// Whether to append the metadata hash.
|
/// Whether to append the metadata hash.
|
||||||
pub include_metadata_hash: bool,
|
pub include_metadata_hash: bool,
|
||||||
/// Enables the test bytecode encoding.
|
|
||||||
pub enable_test_encoding: bool,
|
|
||||||
/// The optimizer settings.
|
/// The optimizer settings.
|
||||||
pub optimizer_settings: revive_llvm_context::OptimizerSettings,
|
pub optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
/// The debug output config.
|
/// The debug output config.
|
||||||
@@ -31,18 +27,14 @@ impl Input {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
contract: Contract,
|
contract: Contract,
|
||||||
project: Project,
|
project: Project,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
enable_test_encoding: bool,
|
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
debug_config: Option<revive_llvm_context::DebugConfig>,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
contract,
|
contract,
|
||||||
project,
|
project,
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
enable_test_encoding,
|
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
debug_config,
|
debug_config,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,13 +40,9 @@ pub fn run(input_file: Option<&mut std::fs::File>) -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let input: Input = revive_common::deserialize_from_slice(buffer.as_slice())?;
|
let input: Input = revive_common::deserialize_from_slice(buffer.as_slice())?;
|
||||||
if input.enable_test_encoding {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
let result = input.contract.compile(
|
let result = input.contract.compile(
|
||||||
input.project,
|
input.project,
|
||||||
input.optimizer_settings,
|
input.optimizer_settings,
|
||||||
input.is_system_mode,
|
|
||||||
input.include_metadata_hash,
|
input.include_metadata_hash,
|
||||||
input.debug_config,
|
input.debug_config,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
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)]
|
||||||
@@ -9,11 +11,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: semver::Version,
|
pub solc_version: String,
|
||||||
/// The zkVM `solc` edition.
|
/// The pallet revive edition.
|
||||||
pub solc_zkvm_edition: Option<semver::Version>,
|
pub revive_pallet_version: Option<semver::Version>,
|
||||||
/// The PolkaVM compiler version.
|
/// The PolkaVM compiler version.
|
||||||
pub zk_version: semver::Version,
|
pub revive_version: String,
|
||||||
/// The PolkaVM compiler optimizer settings.
|
/// The PolkaVM compiler optimizer settings.
|
||||||
pub optimizer_settings: revive_llvm_context::OptimizerSettings,
|
pub optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
}
|
}
|
||||||
@@ -22,16 +24,15 @@ 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: semver::Version,
|
solc_version: String,
|
||||||
solc_zkvm_edition: Option<semver::Version>,
|
revive_pallet_version: 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,
|
||||||
solc_zkvm_edition,
|
revive_pallet_version,
|
||||||
zk_version,
|
revive_version: ResolcVersion::default().long,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ impl Contract {
|
|||||||
mut self,
|
mut self,
|
||||||
project: Project,
|
project: Project,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: Option<revive_llvm_context::DebugConfig>,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<ContractBuild> {
|
) -> anyhow::Result<ContractBuild> {
|
||||||
@@ -90,9 +89,8 @@ impl Contract {
|
|||||||
|
|
||||||
let metadata = Metadata::new(
|
let metadata = Metadata::new(
|
||||||
self.metadata_json.take(),
|
self.metadata_json.take(),
|
||||||
version.default.clone(),
|
version.long.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");
|
||||||
@@ -127,8 +125,7 @@ impl Contract {
|
|||||||
context.set_solidity_data(revive_llvm_context::PolkaVMContextSolidityData::default());
|
context.set_solidity_data(revive_llvm_context::PolkaVMContextSolidityData::default());
|
||||||
match self.ir {
|
match self.ir {
|
||||||
IR::Yul(_) => {
|
IR::Yul(_) => {
|
||||||
let yul_data = revive_llvm_context::PolkaVMContextYulData::new(is_system_mode);
|
context.set_yul_data(Default::default());
|
||||||
context.set_yul_data(yul_data);
|
|
||||||
}
|
}
|
||||||
IR::EVMLA(_) => {
|
IR::EVMLA(_) => {
|
||||||
let evmla_data = revive_llvm_context::PolkaVMContextEVMLAData::new(version.default);
|
let evmla_data = revive_llvm_context::PolkaVMContextEVMLAData::new(version.default);
|
||||||
|
|||||||
@@ -62,9 +62,7 @@ impl Project {
|
|||||||
pub fn compile(
|
pub fn compile(
|
||||||
self,
|
self,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
bytecode_encoding_testing: bool,
|
|
||||||
debug_config: Option<revive_llvm_context::DebugConfig>,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
let project = self.clone();
|
let project = self.clone();
|
||||||
@@ -75,9 +73,7 @@ impl Project {
|
|||||||
let process_output = crate::process::call(ProcessInput::new(
|
let process_output = crate::process::call(ProcessInput::new(
|
||||||
contract,
|
contract,
|
||||||
project.clone(),
|
project.clone(),
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
bytecode_encoding_testing,
|
|
||||||
optimizer_settings.clone(),
|
optimizer_settings.clone(),
|
||||||
debug_config.clone(),
|
debug_config.clone(),
|
||||||
));
|
));
|
||||||
@@ -241,7 +237,6 @@ impl revive_llvm_context::PolkaVMDependency for Project {
|
|||||||
project: Self,
|
project: Self,
|
||||||
identifier: &str,
|
identifier: &str,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
is_system_mode: bool,
|
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: Option<revive_llvm_context::DebugConfig>,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
@@ -261,7 +256,6 @@ impl revive_llvm_context::PolkaVMDependency for Project {
|
|||||||
.compile(
|
.compile(
|
||||||
project,
|
project,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
debug_config,
|
debug_config,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -62,10 +62,6 @@ pub struct Arguments {
|
|||||||
#[structopt(long = "fallback-Oz")]
|
#[structopt(long = "fallback-Oz")]
|
||||||
pub fallback_to_optimizing_for_size: bool,
|
pub fallback_to_optimizing_for_size: bool,
|
||||||
|
|
||||||
/// Disable the system request memoization.
|
|
||||||
#[structopt(long = "disable-system-request-memoization")]
|
|
||||||
pub disable_system_request_memoization: bool,
|
|
||||||
|
|
||||||
/// Disable the `solc` optimizer.
|
/// Disable the `solc` optimizer.
|
||||||
/// Use it if your project uses the `MSIZE` instruction, or in other cases.
|
/// Use it if your project uses the `MSIZE` instruction, or in other cases.
|
||||||
/// Beware that it will prevent libraries from being inlined.
|
/// Beware that it will prevent libraries from being inlined.
|
||||||
@@ -123,13 +119,6 @@ pub struct Arguments {
|
|||||||
#[structopt(long = "force-evmla")]
|
#[structopt(long = "force-evmla")]
|
||||||
pub force_evmla: bool,
|
pub force_evmla: bool,
|
||||||
|
|
||||||
/// Enable system contract compilation mode.
|
|
||||||
/// In this mode PolkaVM extensions are enabled. For example, calls to addresses `0xFFFF` and below
|
|
||||||
/// are substituted by special PolkaVM instructions.
|
|
||||||
/// In the Yul mode, the `verbatim_*` instruction family is available.
|
|
||||||
#[structopt(long = "system-mode")]
|
|
||||||
pub is_system_mode: bool,
|
|
||||||
|
|
||||||
/// Set metadata hash mode.
|
/// Set metadata hash mode.
|
||||||
/// The only supported value is `none` that disables appending the metadata hash.
|
/// The only supported value is `none` that disables appending the metadata hash.
|
||||||
/// Is enabled by default.
|
/// Is enabled by default.
|
||||||
@@ -267,12 +256,6 @@ impl Arguments {
|
|||||||
if self.solc.is_some() {
|
if self.solc.is_some() {
|
||||||
anyhow::bail!("`solc` is not used in LLVM IR and PolkaVM assembly modes.");
|
anyhow::bail!("`solc` is not used in LLVM IR and PolkaVM assembly modes.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.is_system_mode {
|
|
||||||
anyhow::bail!(
|
|
||||||
"System contract mode is not supported in LLVM IR and PolkaVM assembly modes."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.combined_json.is_some() {
|
if self.combined_json.is_some() {
|
||||||
@@ -319,11 +302,6 @@ impl Arguments {
|
|||||||
"Falling back to -Oz must specified in standard JSON input settings."
|
"Falling back to -Oz must specified in standard JSON input settings."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self.disable_system_request_memoization {
|
|
||||||
anyhow::bail!(
|
|
||||||
"Disabling the system request memoization must specified in standard JSON input settings."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if self.metadata_hash.is_some() {
|
if self.metadata_hash.is_some() {
|
||||||
anyhow::bail!("Metadata hash mode must specified in standard JSON input settings.");
|
anyhow::bail!("Metadata hash mode must specified in standard JSON input settings.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,9 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
if arguments.version {
|
if arguments.version {
|
||||||
println!(
|
println!(
|
||||||
"{} v{} (LLVM build {:?})",
|
"{} version {}",
|
||||||
env!("CARGO_PKG_DESCRIPTION"),
|
env!("CARGO_PKG_DESCRIPTION"),
|
||||||
env!("CARGO_PKG_VERSION"),
|
revive_solidity::ResolcVersion::default().long
|
||||||
inkwell::support::get_llvm_version()
|
|
||||||
);
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -101,9 +100,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
if arguments.fallback_to_optimizing_for_size {
|
if arguments.fallback_to_optimizing_for_size {
|
||||||
optimizer_settings.enable_fallback_to_size();
|
optimizer_settings.enable_fallback_to_size();
|
||||||
}
|
}
|
||||||
if arguments.disable_system_request_memoization {
|
|
||||||
optimizer_settings.disable_system_request_memoization();
|
|
||||||
}
|
|
||||||
optimizer_settings.is_verify_each_enabled = arguments.llvm_verify_each;
|
optimizer_settings.is_verify_each_enabled = arguments.llvm_verify_each;
|
||||||
optimizer_settings.is_debug_logging_enabled = arguments.llvm_debug_logging;
|
optimizer_settings.is_debug_logging_enabled = arguments.llvm_debug_logging;
|
||||||
|
|
||||||
@@ -121,7 +117,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
input_files.as_slice(),
|
input_files.as_slice(),
|
||||||
&mut solc,
|
&mut solc,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
arguments.is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
debug_config,
|
debug_config,
|
||||||
)
|
)
|
||||||
@@ -129,7 +124,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
revive_solidity::llvm_ir(
|
revive_solidity::llvm_ir(
|
||||||
input_files.as_slice(),
|
input_files.as_slice(),
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
arguments.is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
debug_config,
|
debug_config,
|
||||||
)
|
)
|
||||||
@@ -138,7 +132,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
&mut solc,
|
&mut solc,
|
||||||
arguments.detect_missing_libraries,
|
arguments.detect_missing_libraries,
|
||||||
arguments.force_evmla,
|
arguments.force_evmla,
|
||||||
arguments.is_system_mode,
|
|
||||||
arguments.base_path,
|
arguments.base_path,
|
||||||
arguments.include_paths,
|
arguments.include_paths,
|
||||||
arguments.allow_paths,
|
arguments.allow_paths,
|
||||||
@@ -155,7 +148,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
!arguments.disable_solc_optimizer,
|
!arguments.disable_solc_optimizer,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
arguments.force_evmla,
|
arguments.force_evmla,
|
||||||
arguments.is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
arguments.base_path,
|
arguments.base_path,
|
||||||
arguments.include_paths,
|
arguments.include_paths,
|
||||||
@@ -176,7 +168,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
!arguments.disable_solc_optimizer,
|
!arguments.disable_solc_optimizer,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
arguments.force_evmla,
|
arguments.force_evmla,
|
||||||
arguments.is_system_mode,
|
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
arguments.base_path,
|
arguments.base_path,
|
||||||
arguments.include_paths,
|
arguments.include_paths,
|
||||||
|
|||||||
@@ -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 zk_version: Option<String>,
|
pub revive_version: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CombinedJson {
|
impl CombinedJson {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ impl Compiler {
|
|||||||
pub const FIRST_VIA_IR_VERSION: semver::Version = semver::Version::new(0, 8, 13);
|
pub const FIRST_VIA_IR_VERSION: semver::Version = semver::Version::new(0, 8, 13);
|
||||||
|
|
||||||
/// The last supported version of `solc`.
|
/// The last supported version of `solc`.
|
||||||
pub const LAST_SUPPORTED_VERSION: semver::Version = semver::Version::new(0, 8, 27);
|
pub const LAST_SUPPORTED_VERSION: semver::Version = semver::Version::new(0, 8, 28);
|
||||||
|
|
||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
/// Different tools may use different `executable` names. For example, the integration tester
|
/// Different tools may use different `executable` names. For example, the integration tester
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ pub struct Optimizer {
|
|||||||
/// Whether to try to recompile with -Oz if the bytecode is too large.
|
/// Whether to try to recompile with -Oz if the bytecode is too large.
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
pub fallback_to_optimizing_for_size: Option<bool>,
|
pub fallback_to_optimizing_for_size: Option<bool>,
|
||||||
/// Whether to disable the system request memoization.
|
|
||||||
#[serde(skip_serializing)]
|
|
||||||
pub disable_system_request_memoization: Option<bool>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Optimizer {
|
impl Optimizer {
|
||||||
@@ -34,14 +31,12 @@ impl Optimizer {
|
|||||||
mode: Option<char>,
|
mode: Option<char>,
|
||||||
version: &semver::Version,
|
version: &semver::Version,
|
||||||
fallback_to_optimizing_for_size: bool,
|
fallback_to_optimizing_for_size: bool,
|
||||||
disable_system_request_memoization: bool,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
enabled,
|
enabled,
|
||||||
mode,
|
mode,
|
||||||
details: Some(Details::disabled(version)),
|
details: Some(Details::disabled(version)),
|
||||||
fallback_to_optimizing_for_size: Some(fallback_to_optimizing_for_size),
|
fallback_to_optimizing_for_size: Some(fallback_to_optimizing_for_size),
|
||||||
disable_system_request_memoization: Some(disable_system_request_memoization),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,9 +61,6 @@ impl TryFrom<&Optimizer> for revive_llvm_context::OptimizerSettings {
|
|||||||
if value.fallback_to_optimizing_for_size.unwrap_or_default() {
|
if value.fallback_to_optimizing_for_size.unwrap_or_default() {
|
||||||
result.enable_fallback_to_size();
|
result.enable_fallback_to_size();
|
||||||
}
|
}
|
||||||
if value.disable_system_request_memoization.unwrap_or_default() {
|
|
||||||
result.disable_system_request_memoization();
|
|
||||||
}
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ pub enum Flag {
|
|||||||
EVMBC,
|
EVMBC,
|
||||||
#[serde(rename = "evm.deployedBytecode")]
|
#[serde(rename = "evm.deployedBytecode")]
|
||||||
EVMDBC,
|
EVMDBC,
|
||||||
|
/// The assembly code
|
||||||
|
#[serde(rename = "evm.assembly")]
|
||||||
|
Assembly,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SolcPipeline> for Flag {
|
impl From<SolcPipeline> for Flag {
|
||||||
@@ -66,6 +69,7 @@ impl std::fmt::Display for Flag {
|
|||||||
Self::EVMLA => write!(f, "evm.legacyAssembly"),
|
Self::EVMLA => write!(f, "evm.legacyAssembly"),
|
||||||
Self::EVMBC => write!(f, "evm.bytecode"),
|
Self::EVMBC => write!(f, "evm.bytecode"),
|
||||||
Self::EVMDBC => write!(f, "evm.deployedBytecode"),
|
Self::EVMDBC => write!(f, "evm.deployedBytecode"),
|
||||||
|
Self::Assembly => write!(f, "evm.assembly"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,15 +20,19 @@ use self::extra_metadata::ExtraMetadata;
|
|||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct EVM {
|
pub struct EVM {
|
||||||
/// The contract EVM legacy assembly code.
|
/// The contract EVM legacy assembly code.
|
||||||
#[serde(rename = "legacyAssembly")]
|
#[serde(rename = "legacyAssembly", skip_serializing_if = "Option::is_none")]
|
||||||
pub assembly: Option<Assembly>,
|
pub assembly: Option<Assembly>,
|
||||||
/// The contract PolkaVM assembly code.
|
/// The contract PolkaVM assembly code.
|
||||||
#[serde(rename = "assembly")]
|
#[serde(rename = "assembly", skip_serializing_if = "Option::is_none")]
|
||||||
pub assembly_text: Option<String>,
|
pub assembly_text: Option<String>,
|
||||||
/// The contract bytecode.
|
/// The contract bytecode.
|
||||||
/// Is reset by that of PolkaVM before yielding the compiled project artifacts.
|
/// Is reset by that of PolkaVM before yielding the compiled project artifacts.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub bytecode: Option<Bytecode>,
|
pub bytecode: Option<Bytecode>,
|
||||||
/// The contract deployed bytecode.
|
/// The deployed bytecode of the contract.
|
||||||
|
/// It is overwritten with the PolkaVM blob before yielding the compiled project artifacts.
|
||||||
|
/// Hence it will be the same as the runtime code but we keep both for compatibility reasons.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub deployed_bytecode: Option<DeployedBytecode>,
|
pub deployed_bytecode: Option<DeployedBytecode>,
|
||||||
/// The contract function signatures.
|
/// The contract function signatures.
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
@@ -42,6 +46,7 @@ impl EVM {
|
|||||||
/// Sets the PolkaVM assembly and bytecode.
|
/// Sets the PolkaVM assembly and bytecode.
|
||||||
pub fn modify(&mut self, assembly_text: String, bytecode: String) {
|
pub fn modify(&mut self, assembly_text: String, bytecode: String) {
|
||||||
self.assembly_text = Some(assembly_text);
|
self.assembly_text = Some(assembly_text);
|
||||||
self.bytecode = Some(Bytecode::new(bytecode));
|
self.bytecode = Some(Bytecode::new(bytecode.clone()));
|
||||||
|
self.deployed_bytecode = Some(DeployedBytecode::new(bytecode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 zk_version: Option<String>,
|
pub revive_version: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Output {
|
impl Output {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ 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;
|
||||||
@@ -95,7 +94,6 @@ pub fn build_solidity_with_options(
|
|||||||
None,
|
None,
|
||||||
&solc_version.default,
|
&solc_version.default,
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
pipeline == SolcPipeline::Yul,
|
pipeline == SolcPipeline::Yul,
|
||||||
@@ -106,12 +104,8 @@ 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, false, false, None)?;
|
let build: crate::Build = project.compile(optimizer_settings, false, None)?;
|
||||||
build.write_to_standard_json(
|
build.write_to_standard_json(&mut output, &solc_version)?;
|
||||||
&mut output,
|
|
||||||
&solc_version,
|
|
||||||
&semver::Version::from_str(env!("CARGO_PKG_VERSION"))?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
@@ -144,7 +138,6 @@ pub fn build_solidity_with_options_evm(
|
|||||||
None,
|
None,
|
||||||
&solc_version.default,
|
&solc_version.default,
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
pipeline == SolcPipeline::Yul,
|
pipeline == SolcPipeline::Yul,
|
||||||
@@ -193,13 +186,7 @@ pub fn build_solidity_and_detect_missing_libraries(
|
|||||||
libraries.clone(),
|
libraries.clone(),
|
||||||
None,
|
None,
|
||||||
SolcStandardJsonInputSettingsSelection::new_required(pipeline),
|
SolcStandardJsonInputSettingsSelection::new_required(pipeline),
|
||||||
SolcStandardJsonInputSettingsOptimizer::new(
|
SolcStandardJsonInputSettingsOptimizer::new(true, None, &solc_version.default, false),
|
||||||
true,
|
|
||||||
None,
|
|
||||||
&solc_version.default,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
None,
|
None,
|
||||||
pipeline == SolcPipeline::Yul,
|
pipeline == SolcPipeline::Yul,
|
||||||
None,
|
None,
|
||||||
@@ -210,11 +197,7 @@ 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(
|
missing_libraries.write_to_standard_json(&mut output, &solc.version()?)?;
|
||||||
&mut output,
|
|
||||||
&solc.version()?,
|
|
||||||
&semver::Version::from_str(env!("CARGO_PKG_VERSION"))?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
@@ -229,7 +212,7 @@ pub fn build_yul(source_code: &str) -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let project =
|
let project =
|
||||||
Project::try_from_yul_string(PathBuf::from("test.yul").as_path(), source_code, None)?;
|
Project::try_from_yul_string(PathBuf::from("test.yul").as_path(), source_code, None)?;
|
||||||
let _build = project.compile(optimizer_settings, false, false, false, None)?;
|
let _build = project.compile(optimizer_settings, false, None)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -240,14 +223,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_zkvm_edition: bool,
|
skip_for_revive_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_zkvm_edition && solc_version.l2_revision.is_some() {
|
if skip_for_revive_edition && solc_version.l2_revision.is_some() {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,13 +242,7 @@ pub fn check_solidity_warning(
|
|||||||
libraries,
|
libraries,
|
||||||
None,
|
None,
|
||||||
SolcStandardJsonInputSettingsSelection::new_required(pipeline),
|
SolcStandardJsonInputSettingsSelection::new_required(pipeline),
|
||||||
SolcStandardJsonInputSettingsOptimizer::new(
|
SolcStandardJsonInputSettingsOptimizer::new(true, None, &solc_version.default, false),
|
||||||
true,
|
|
||||||
None,
|
|
||||||
&solc_version.default,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
None,
|
None,
|
||||||
pipeline == SolcPipeline::Yul,
|
pipeline == SolcPipeline::Yul,
|
||||||
suppressed_warnings,
|
suppressed_warnings,
|
||||||
@@ -290,18 +267,26 @@ pub fn compile_blob(contract_name: &str, source_code: &str) -> Vec<u8> {
|
|||||||
/// Compile the EVM bin-runtime of `contract_name` found in given `source_code`.
|
/// Compile the EVM bin-runtime of `contract_name` found in given `source_code`.
|
||||||
/// The `solc` optimizer will be enabled
|
/// The `solc` optimizer will be enabled
|
||||||
pub fn compile_evm_bin_runtime(contract_name: &str, source_code: &str) -> Vec<u8> {
|
pub fn compile_evm_bin_runtime(contract_name: &str, source_code: &str) -> Vec<u8> {
|
||||||
compile_evm(contract_name, source_code, true)
|
compile_evm(contract_name, source_code, true, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compile the EVM bin of `contract_name` found in given `source_code`.
|
/// Compile the EVM bin of `contract_name` found in given `source_code`.
|
||||||
/// The `solc` optimizer will be enabled
|
/// The `solc` optimizer will be enabled
|
||||||
pub fn compile_evm_deploy_code(contract_name: &str, source_code: &str) -> Vec<u8> {
|
pub fn compile_evm_deploy_code(
|
||||||
compile_evm(contract_name, source_code, false)
|
contract_name: &str,
|
||||||
|
source_code: &str,
|
||||||
|
solc_optimizer_enabled: bool,
|
||||||
|
) -> Vec<u8> {
|
||||||
|
compile_evm(contract_name, source_code, solc_optimizer_enabled, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_evm(contract_name: &str, source_code: &str, runtime: bool) -> Vec<u8> {
|
fn compile_evm(
|
||||||
|
contract_name: &str,
|
||||||
|
source_code: &str,
|
||||||
|
solc_optimizer_enabled: bool,
|
||||||
|
runtime: bool,
|
||||||
|
) -> Vec<u8> {
|
||||||
let pipeline = SolcPipeline::Yul;
|
let pipeline = SolcPipeline::Yul;
|
||||||
let solc_optimizer_enabled = true;
|
|
||||||
let id = CachedBlob {
|
let id = CachedBlob {
|
||||||
contract_name: contract_name.to_owned(),
|
contract_name: contract_name.to_owned(),
|
||||||
pipeline,
|
pipeline,
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
//! 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -125,13 +125,6 @@ impl FunctionCall {
|
|||||||
let location = self.location;
|
let location = self.location;
|
||||||
|
|
||||||
match self.name {
|
match self.name {
|
||||||
Name::UserDefined(name)
|
|
||||||
if name.starts_with(
|
|
||||||
revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX,
|
|
||||||
) && context.is_system_mode() =>
|
|
||||||
{
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
Name::UserDefined(name) => {
|
Name::UserDefined(name) => {
|
||||||
let mut values = Vec::with_capacity(self.arguments.len());
|
let mut values = Vec::with_capacity(self.arguments.len());
|
||||||
for argument in self.arguments.into_iter().rev() {
|
for argument in self.arguments.into_iter().rev() {
|
||||||
@@ -501,25 +494,30 @@ impl FunctionCall {
|
|||||||
)
|
)
|
||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
}
|
}
|
||||||
Name::LoadImmutable => todo!(),
|
Name::LoadImmutable => {
|
||||||
|
let mut arguments = self.pop_arguments::<D, 1>(context)?;
|
||||||
|
let key = arguments[0].original.take().ok_or_else(|| {
|
||||||
|
anyhow::anyhow!("{} `load_immutable` literal is missing", location)
|
||||||
|
})?;
|
||||||
|
let offset = context
|
||||||
|
.solidity_mut()
|
||||||
|
.get_or_allocate_immutable(key.as_str())
|
||||||
|
/ revive_common::BYTE_LENGTH_WORD;
|
||||||
|
let index = context.xlen_type().const_int(offset as u64, false);
|
||||||
|
revive_llvm_context::polkavm_evm_immutable::load(context, index).map(Some)
|
||||||
|
}
|
||||||
Name::SetImmutable => {
|
Name::SetImmutable => {
|
||||||
let mut arguments = self.pop_arguments::<D, 3>(context)?;
|
let mut arguments = self.pop_arguments::<D, 3>(context)?;
|
||||||
let key = arguments[1].original.take().ok_or_else(|| {
|
let key = arguments[1].original.take().ok_or_else(|| {
|
||||||
anyhow::anyhow!("{} `load_immutable` literal is missing", location)
|
anyhow::anyhow!("{} `load_immutable` literal is missing", location)
|
||||||
})?;
|
})?;
|
||||||
|
let offset = context.solidity_mut().allocate_immutable(key.as_str())
|
||||||
if key.as_str() == "library_deploy_address" {
|
/ revive_common::BYTE_LENGTH_WORD;
|
||||||
return Ok(None);
|
let index = context.xlen_type().const_int(offset as u64, false);
|
||||||
}
|
|
||||||
|
|
||||||
let offset = context.solidity_mut().allocate_immutable(key.as_str());
|
|
||||||
|
|
||||||
let index = context.word_const(offset as u64);
|
|
||||||
let value = arguments[2].value.into_int_value();
|
let value = arguments[2].value.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)
|
||||||
}
|
}
|
||||||
|
|
||||||
Name::CallDataLoad => {
|
Name::CallDataLoad => {
|
||||||
let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
|
let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
|
||||||
|
|
||||||
@@ -965,9 +963,7 @@ impl FunctionCall {
|
|||||||
location
|
location
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Name::MSize => {
|
Name::MSize => revive_llvm_context::polkavm_evm_memory::msize(context).map(Some),
|
||||||
revive_llvm_context::polkavm_evm_contract_context::msize(context).map(Some)
|
|
||||||
}
|
|
||||||
|
|
||||||
Name::Verbatim {
|
Name::Verbatim {
|
||||||
input_size,
|
input_size,
|
||||||
|
|||||||
@@ -92,37 +92,7 @@ impl FunctionDefinition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (mut arguments, next) = Identifier::parse_typed_list(lexer, None)?;
|
let (arguments, next) = Identifier::parse_typed_list(lexer, None)?;
|
||||||
if identifier
|
|
||||||
.inner
|
|
||||||
.contains(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX)
|
|
||||||
{
|
|
||||||
if arguments.is_empty() {
|
|
||||||
return Err(ParserError::InvalidNumberOfArguments {
|
|
||||||
location,
|
|
||||||
identifier: identifier.inner,
|
|
||||||
expected: 1,
|
|
||||||
found: arguments.len(),
|
|
||||||
}
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
arguments.remove(0);
|
|
||||||
}
|
|
||||||
if identifier
|
|
||||||
.inner
|
|
||||||
.contains(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER)
|
|
||||||
&& !arguments.is_empty()
|
|
||||||
{
|
|
||||||
return Err(ParserError::InvalidNumberOfArguments {
|
|
||||||
location,
|
|
||||||
identifier: identifier.inner,
|
|
||||||
expected: 0,
|
|
||||||
found: arguments.len(),
|
|
||||||
}
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
match crate::yul::parser::take_or_next(next, lexer)? {
|
match crate::yul::parser::take_or_next(next, lexer)? {
|
||||||
Token {
|
Token {
|
||||||
lexeme: Lexeme::Symbol(Symbol::ParenthesisRight),
|
lexeme: Lexeme::Symbol(Symbol::ParenthesisRight),
|
||||||
@@ -234,12 +204,7 @@ where
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let function_type = context.function_type(
|
let function_type = context.function_type(argument_types, self.result.len());
|
||||||
argument_types,
|
|
||||||
self.result.len(),
|
|
||||||
self.identifier
|
|
||||||
.starts_with(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX),
|
|
||||||
);
|
|
||||||
|
|
||||||
let function = context.add_function(
|
let function = context.add_function(
|
||||||
self.identifier.as_str(),
|
self.identifier.as_str(),
|
||||||
@@ -310,23 +275,12 @@ where
|
|||||||
yul_type.into_llvm(context)
|
yul_type.into_llvm(context)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
for (mut index, argument) in self.arguments.iter().enumerate() {
|
for (index, argument) in self.arguments.iter().enumerate() {
|
||||||
let pointer = context.build_alloca(argument_types[index], argument.inner.as_str());
|
let pointer = context.build_alloca(argument_types[index], argument.inner.as_str());
|
||||||
context
|
context
|
||||||
.current_function()
|
.current_function()
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.insert_stack_pointer(argument.inner.clone(), pointer);
|
.insert_stack_pointer(argument.inner.clone(), pointer);
|
||||||
if self
|
|
||||||
.identifier
|
|
||||||
.starts_with(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX)
|
|
||||||
&& matches!(
|
|
||||||
context.current_function().borrow().r#return(),
|
|
||||||
revive_llvm_context::PolkaVMFunctionReturn::Compound { .. }
|
|
||||||
)
|
|
||||||
&& context.is_system_mode()
|
|
||||||
{
|
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
context.build_store(
|
context.build_store(
|
||||||
pointer,
|
pointer,
|
||||||
context.current_function().borrow().get_nth_param(index),
|
context.current_function().borrow().get_nth_param(index),
|
||||||
@@ -354,13 +308,6 @@ where
|
|||||||
let return_value = context.build_load(pointer, "return_value")?;
|
let return_value = context.build_load(pointer, "return_value")?;
|
||||||
context.build_return(Some(&return_value));
|
context.build_return(Some(&return_value));
|
||||||
}
|
}
|
||||||
revive_llvm_context::PolkaVMFunctionReturn::Compound { pointer, .. }
|
|
||||||
if context.current_function().borrow().name().starts_with(
|
|
||||||
revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX,
|
|
||||||
) =>
|
|
||||||
{
|
|
||||||
context.build_return(Some(&pointer.value));
|
|
||||||
}
|
|
||||||
revive_llvm_context::PolkaVMFunctionReturn::Compound { pointer, .. } => {
|
revive_llvm_context::PolkaVMFunctionReturn::Compound { pointer, .. } => {
|
||||||
let return_value = context.build_load(pointer, "return_value")?;
|
let return_value = context.build_load(pointer, "return_value")?;
|
||||||
context.build_return(Some(&return_value));
|
context.build_return(Some(&return_value));
|
||||||
@@ -524,80 +471,6 @@ object "Test" {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn error_invalid_number_of_arguments_near_call_abi() {
|
|
||||||
let input = r#"
|
|
||||||
object "Test" {
|
|
||||||
code {
|
|
||||||
{
|
|
||||||
return(0, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
object "Test_deployed" {
|
|
||||||
code {
|
|
||||||
{
|
|
||||||
return(0, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
function ZKSYNC_NEAR_CALL_test() -> result {
|
|
||||||
result := 42
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#;
|
|
||||||
|
|
||||||
let mut lexer = Lexer::new(input.to_owned());
|
|
||||||
let result = Object::parse(&mut lexer, None);
|
|
||||||
assert_eq!(
|
|
||||||
result,
|
|
||||||
Err(Error::InvalidNumberOfArguments {
|
|
||||||
location: Location::new(14, 22),
|
|
||||||
identifier: "ZKSYNC_NEAR_CALL_test".to_owned(),
|
|
||||||
expected: 1,
|
|
||||||
found: 0,
|
|
||||||
}
|
|
||||||
.into())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn error_invalid_number_of_arguments_near_call_abi_catch() {
|
|
||||||
let input = r#"
|
|
||||||
object "Test" {
|
|
||||||
code {
|
|
||||||
{
|
|
||||||
return(0, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
object "Test_deployed" {
|
|
||||||
code {
|
|
||||||
{
|
|
||||||
return(0, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
function ZKSYNC_CATCH_NEAR_CALL(length) {
|
|
||||||
revert(0, length)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#;
|
|
||||||
|
|
||||||
let mut lexer = Lexer::new(input.to_owned());
|
|
||||||
let result = Object::parse(&mut lexer, None);
|
|
||||||
assert_eq!(
|
|
||||||
result,
|
|
||||||
Err(Error::InvalidNumberOfArguments {
|
|
||||||
location: Location::new(14, 22),
|
|
||||||
identifier: "ZKSYNC_CATCH_NEAR_CALL".to_owned(),
|
|
||||||
expected: 0,
|
|
||||||
found: 1,
|
|
||||||
}
|
|
||||||
.into())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_reserved_identifier() {
|
fn error_reserved_identifier() {
|
||||||
let input = r#"
|
let input = r#"
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
context: &mut revive_llvm_context::PolkaVMContext<D>,
|
context: &mut revive_llvm_context::PolkaVMContext<D>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
revive_llvm_context::PolkaVMImmutableDataLoadFunction.declare(context)?;
|
||||||
let mut entry = revive_llvm_context::PolkaVMEntryFunction::default();
|
let mut entry = revive_llvm_context::PolkaVMEntryFunction::default();
|
||||||
entry.declare(context)?;
|
entry.declare(context)?;
|
||||||
|
|
||||||
@@ -199,6 +200,7 @@ where
|
|||||||
revive_llvm_context::PolkaVMFunctionDeployCode,
|
revive_llvm_context::PolkaVMFunctionDeployCode,
|
||||||
revive_llvm_context::PolkaVMFunctionRuntimeCode,
|
revive_llvm_context::PolkaVMFunctionRuntimeCode,
|
||||||
revive_llvm_context::PolkaVMFunctionEntry,
|
revive_llvm_context::PolkaVMFunctionEntry,
|
||||||
|
revive_llvm_context::PolkaVMFunctionImmutableDataLoad,
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
{
|
{
|
||||||
@@ -216,6 +218,7 @@ where
|
|||||||
|
|
||||||
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
|
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
|
||||||
if self.identifier.ends_with("_deployed") {
|
if self.identifier.ends_with("_deployed") {
|
||||||
|
revive_llvm_context::PolkaVMImmutableDataLoadFunction.into_llvm(context)?;
|
||||||
revive_llvm_context::PolkaVMRuntimeCodeFunction::new(self.code).into_llvm(context)?;
|
revive_llvm_context::PolkaVMRuntimeCodeFunction::new(self.code).into_llvm(context)?;
|
||||||
} else {
|
} else {
|
||||||
revive_llvm_context::PolkaVMDeployCodeFunction::new(self.code).into_llvm(context)?;
|
revive_llvm_context::PolkaVMDeployCodeFunction::new(self.code).into_llvm(context)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user