mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 14:31:05 +00:00
Compare commits
19 Commits
calls
..
v0.1.0-dev
| Author | SHA1 | Date | |
|---|---|---|---|
| e8fcd6118e | |||
| ad46e94ebd | |||
| 6585973e99 | |||
| 066acc4663 | |||
| 287272b789 | |||
| f621971a13 | |||
| b8bd44b62a | |||
| d8c708eba5 | |||
| 72d958392b | |||
| 616f044633 | |||
| 7dc8e6051e | |||
| 783fa640e4 | |||
| f086c57442 | |||
| 0f2b55f6ff | |||
| ac9215329c | |||
| 6635a0b337 | |||
| 77df88b3cb | |||
| 2955f77772 | |||
| d77ee1e0d4 |
@@ -0,0 +1,38 @@
|
||||
name: Build revive-debian
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
REVIVE_DEBIAN_PACKAGE: revive-debian-x86
|
||||
DEBIAN_CONTAINER: revive-builder-debian-x86
|
||||
DEBIAN_CONTAINER_BUILDER: build-debian-builder.sh
|
||||
DEBIAN_CONTAINER_RUNNER: run-debian-builder.sh
|
||||
REVIVE_DEBIAN_INSTALL: ${{ github.workspace }}/target/release
|
||||
REVIVE_DEBIAN_BINARY: resolc
|
||||
RUST_VERSION: "1.80"
|
||||
|
||||
jobs:
|
||||
build-revive-debian-x86:
|
||||
name: debian-container-x86
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: build-container
|
||||
run: |
|
||||
(cd utils && ./${{ env.DEBIAN_CONTAINER_BUILDER}} --build-arg RUST_VERSION=${{ env.RUST_VERSION}} . )
|
||||
|
||||
- name: build-revive-debian
|
||||
run: |
|
||||
rustup show
|
||||
cargo --version
|
||||
rustup +nightly show
|
||||
cargo +nightly --version
|
||||
bash --version
|
||||
utils/${{ env.DEBIAN_CONTAINER_RUNNER }} utils/build-revive.sh -o ${{ env.REVIVE_DEBIAN_INSTALL}}
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.REVIVE_DEBIAN_PACKAGE }}
|
||||
path: ${{ env.REVIVE_DEBIAN_INSTALL }}/${{ env.REVIVE_DEBIAN_BINARY }}
|
||||
retention-days: 1
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
- name: Install solc
|
||||
run: |
|
||||
mkdir -p solc
|
||||
curl -sSL --output solc/solc https://github.com/ethereum/solidity/releases/download/v0.8.26/solc-static-linux
|
||||
curl -sSL --output solc/solc https://github.com/ethereum/solidity/releases/download/v0.8.27/solc-static-linux
|
||||
chmod +x solc/solc
|
||||
echo "$(pwd)/solc/" >> $GITHUB_PATH
|
||||
|
||||
|
||||
Generated
+784
-673
File diff suppressed because it is too large
Load Diff
+3
-2
@@ -10,7 +10,8 @@ authors = [
|
||||
]
|
||||
license = "MIT/Apache-2.0"
|
||||
edition = "2021"
|
||||
repository = "https://github.com/xermicus/revive"
|
||||
repository = "https://github.com/paritytech/revive"
|
||||
rust-version = "1.80.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
revive-benchmarks = { version = "0.1.0", path = "crates/benchmarks" }
|
||||
@@ -66,7 +67,7 @@ log = { version = "0.4" }
|
||||
# polkadot-sdk and friends
|
||||
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
|
||||
scale-info = { version = "2.11.1", default-features = false }
|
||||
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "d7b575338b2c647e04fc48bfbe00ea8f492fb580" }
|
||||
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c77095f51119d2eccdc54d2f3518bed0ffbd6d53" }
|
||||
|
||||
# llvm
|
||||
[workspace.dependencies.inkwell]
|
||||
|
||||
@@ -8,6 +8,13 @@ install-bin:
|
||||
install-npm:
|
||||
npm install && npm fund
|
||||
|
||||
# install-revive: Build and install to the directory specified in REVIVE_INSTALL_DIR
|
||||
ifeq ($(origin REVIVE_INSTALL_DIR), undefined)
|
||||
REVIVE_INSTALL_DIR=`pwd`/release/revive-debian
|
||||
endif
|
||||
install-revive:
|
||||
cargo install --path crates/solidity --root $(REVIVE_INSTALL_DIR)
|
||||
|
||||
format:
|
||||
cargo fmt --all --check
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||

|
||||

|
||||
|
||||
# revive
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ pub const BIT_LENGTH_ETH_ADDRESS: usize =
|
||||
pub const BIT_LENGTH_WORD: usize = crate::byte_length::BYTE_LENGTH_WORD * BIT_LENGTH_BYTE;
|
||||
|
||||
/// Bit length of the runtime value type.
|
||||
pub const BIT_LENGTH_VALUE: usize = crate::byte_length::BYTE_LENGTH_VALUE * BIT_LENGTH_BYTE;
|
||||
pub const BIT_LENGTH_VALUE: usize = BIT_LENGTH_WORD;
|
||||
|
||||
/// Bit length of thre runimte block number type.
|
||||
pub const BIT_LENGTH_BLOCK_NUMBER: usize =
|
||||
|
||||
@@ -6,15 +6,12 @@ pub const BYTE_LENGTH_BYTE: usize = 1;
|
||||
/// The x86 word byte-length.
|
||||
pub const BYTE_LENGTH_X32: usize = 4;
|
||||
|
||||
/// Native stack alignment size in bytes
|
||||
#[cfg(not(feature = "riscv-64"))]
|
||||
pub const BYTE_LENGTH_STACK_ALIGN: usize = 4;
|
||||
#[cfg(feature = "riscv-64")]
|
||||
pub const BYTE_LENGTH_STACK_ALIGN: usize = 8;
|
||||
|
||||
/// The x86_64 word byte-length.
|
||||
pub const BYTE_LENGTH_X64: usize = 8;
|
||||
|
||||
/// EVM native stack alignment size in bytes
|
||||
pub const BYTE_LENGTH_STACK_ALIGN: usize = 32;
|
||||
|
||||
/// The ETH address byte-length.
|
||||
pub const BYTE_LENGTH_ETH_ADDRESS: usize = 20;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"config": {
|
||||
"chainId": 1,
|
||||
"chainId": 420420420,
|
||||
"homesteadBlock": 0,
|
||||
"eip150Block": 0,
|
||||
"eip155Block": 0,
|
||||
@@ -26,5 +26,15 @@
|
||||
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"timestamp": "0x00",
|
||||
"alloc": {}
|
||||
"alloc": {
|
||||
"0101010101010101010101010101010101010101": {
|
||||
"balance": "1000000000"
|
||||
},
|
||||
"0202020202020202020202020202020202020202": {
|
||||
"balance": "1000000000"
|
||||
},
|
||||
"0303030303030303030303030303030303030303": {
|
||||
"balance": "1000000000"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,10 +100,9 @@ pub struct EvmOutput {
|
||||
impl EvmOutput {
|
||||
/// Return if there was no error found.
|
||||
///
|
||||
/// Panics if the gas used is zero as this indicates nothing was run, i.e.
|
||||
/// there was no receiving account but still no error is reported.
|
||||
/// Panics if the gas used is zero as this indicates nothing was run.
|
||||
pub fn run_success(&self) -> bool {
|
||||
assert_ne!(self.gas_used, U256::ZERO, "nothing was executed");
|
||||
assert_ne!(self.gas_used, U256::ZERO, "nothing was executed: {self:?}");
|
||||
self.error.is_none()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"Baseline": 878,
|
||||
"Computation": 4305,
|
||||
"DivisionArithmetics": 39774,
|
||||
"ERC20": 53405,
|
||||
"Events": 1693,
|
||||
"FibonacciIterative": 2917,
|
||||
"Flipper": 3570,
|
||||
"SHA1": 32557
|
||||
"Baseline": 912,
|
||||
"Computation": 4413,
|
||||
"DivisionArithmetics": 40689,
|
||||
"ERC20": 54374,
|
||||
"Events": 1726,
|
||||
"FibonacciIterative": 3015,
|
||||
"Flipper": 3612,
|
||||
"SHA1": 32865
|
||||
}
|
||||
@@ -7,10 +7,10 @@ pragma solidity ^0.8;
|
||||
"differential": true,
|
||||
"actions": [
|
||||
{
|
||||
"Instantiate": {
|
||||
"Upload": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "Call"
|
||||
"contract": "Callee"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ pragma solidity ^0.8;
|
||||
"Instantiate": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "Call"
|
||||
"contract": "Caller"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,28 +27,37 @@ pragma solidity ^0.8;
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 1
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "1b8b921d0000000000000000000000001c81a61a407017c58397a47d2ab28191b9b8ec9b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000050102030405000000000000000000000000000000000000000000000000000000"
|
||||
"value": 123,
|
||||
"data": "1eb16e5b000000000000000000000000d8b934580fce35a11b58c6d73adee468a2833fa8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "5a6535fc00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004cafebabe00000000000000000000000000000000000000000000000000000000"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
contract Call {
|
||||
contract Callee {
|
||||
function echo(bytes memory payload) public pure returns (bytes memory) {
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
|
||||
contract Caller {
|
||||
function value_transfer(address payable destination) public payable {
|
||||
destination.transfer(msg.value);
|
||||
}
|
||||
|
||||
function echo(bytes memory payload) public pure returns (bytes memory) {
|
||||
return payload;
|
||||
}
|
||||
|
||||
function call(
|
||||
address callee,
|
||||
bytes memory payload
|
||||
) public pure returns (bytes memory) {
|
||||
return Call(callee).echo(payload);
|
||||
function call(bytes memory payload) public returns (bytes memory) {
|
||||
Callee callee = new Callee();
|
||||
return callee.echo(payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,14 @@ pragma solidity ^0.8;
|
||||
},
|
||||
"data": "fc9c8d39"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "3af973b1"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -43,4 +51,12 @@ contract Context {
|
||||
function caller() public view returns (address ret) {
|
||||
ret = msg.sender;
|
||||
}
|
||||
|
||||
function chain_id() public view returns (uint) {
|
||||
uint256 id;
|
||||
assembly {
|
||||
id := chainid()
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,64 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.24;
|
||||
pragma solidity ^0.8;
|
||||
|
||||
/* runner.json
|
||||
{
|
||||
"differential": true,
|
||||
"actions": [
|
||||
{
|
||||
"Upload": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "CreateA"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Instantiate": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "CreateB"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"value": 10000
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
contract CreateA {
|
||||
address creator;
|
||||
|
||||
constructor() payable {
|
||||
creator = msg.sender;
|
||||
}
|
||||
constructor() payable {}
|
||||
}
|
||||
|
||||
contract CreateB {
|
||||
|
||||
@@ -4,30 +4,32 @@ pragma solidity ^0.8.24;
|
||||
|
||||
/* runner.json
|
||||
{
|
||||
"actions": [
|
||||
"differential": true,
|
||||
"actions": [
|
||||
{
|
||||
"Instantiate": {}
|
||||
"Instantiate": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "TestSha3"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "f9fbd5540000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000c68656c6c6f20776f726c64210000000000000000000000000000000000000000"
|
||||
}
|
||||
},
|
||||
{
|
||||
"VerifyCall": {
|
||||
"success": true,
|
||||
"output": "57caa176af1ac0433c5df30e8dabcd2ec1af1e92a26eced5f719b88458777cd6"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
contract TestSha3 {
|
||||
function test(string memory _pre) external payable returns (bytes32 hash) {
|
||||
hash = keccak256(bytes(_pre));
|
||||
function test(string memory _pre) external payable returns (bytes32) {
|
||||
bytes32 hash = keccak256(bytes(_pre));
|
||||
return bytes32(uint(hash) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +22,7 @@ pragma solidity ^0.8;
|
||||
},
|
||||
"data": "4d43bec90000000000000000000000000000000000000000000000000000000000000000"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
/* TODO when pallet_revive accepts Solidity event topics
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
@@ -36,7 +31,8 @@ pragma solidity ^0.8;
|
||||
"data": "4d43bec9000000000000000000000000000000000000000000000000000000000000007b"
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
contract Events {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8;
|
||||
|
||||
/* runner.json
|
||||
{
|
||||
"differential": true,
|
||||
"actions": [
|
||||
{
|
||||
"Upload": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "Callee"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Instantiate": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "ReturnDataOob"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
contract Callee {
|
||||
function echo(bytes memory payload) public pure returns (bytes memory) {
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
|
||||
contract ReturnDataOob {
|
||||
fallback() external {
|
||||
new Callee().echo(hex"1234");
|
||||
assembly {
|
||||
let pos := mload(64)
|
||||
let size := add(returndatasize(), 1)
|
||||
returndatacopy(pos, 0, size)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8;
|
||||
|
||||
/* runner.json
|
||||
{
|
||||
"differential": true,
|
||||
"actions": [
|
||||
{
|
||||
"Instantiate": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "Transfer"
|
||||
}
|
||||
},
|
||||
"value": 11
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "1c8d16b30000000000000000000000000303030303030303030303030303030303030303000000000000000000000000000000000000000000000000000000000000000a"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "fb9e8d0500000000000000000000000003030303030303030303030303030303030303030000000000000000000000000000000000000000000000000000000000000001"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
contract Transfer {
|
||||
constructor() payable {
|
||||
transfer_self(msg.value);
|
||||
}
|
||||
|
||||
function address_self() internal view returns (address payable) {
|
||||
return payable(address(this));
|
||||
}
|
||||
|
||||
function transfer_self(uint _amount) public payable {
|
||||
transfer_to(address_self(), _amount);
|
||||
}
|
||||
|
||||
function transfer_to(address payable _dest, uint _amount) public payable {
|
||||
_dest.transfer(_amount);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ pragma solidity ^0.8;
|
||||
"actions": [
|
||||
{
|
||||
"Instantiate": {
|
||||
"value": 1024,
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "Value"
|
||||
@@ -19,18 +20,33 @@ pragma solidity ^0.8;
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"value": 123,
|
||||
"data": "3fa4f245"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Call": {
|
||||
"dest": {
|
||||
"Instantiated": 0
|
||||
},
|
||||
"data": "52da5fa0"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
contract Value {
|
||||
constructor() payable {}
|
||||
|
||||
function value() public payable returns (uint ret) {
|
||||
ret = msg.value;
|
||||
}
|
||||
|
||||
function balance_self() public view returns (uint ret) {
|
||||
ret = address(this).balance;
|
||||
}
|
||||
|
||||
function balance_of(address _address) public view returns (uint ret) {
|
||||
ret = _address.balance;
|
||||
}
|
||||
|
||||
@@ -209,9 +209,11 @@ case!("Call.sol", "Call", vec![], call_constructor);
|
||||
sol!(
|
||||
contract Value {
|
||||
function balance_of(address _address) public view returns (uint ret);
|
||||
function balance_self() public view returns (uint ret);
|
||||
}
|
||||
);
|
||||
case!("Value.sol", Value, balance_ofCall, value_balance_of, address: Address);
|
||||
case!("Value.sol", Value, balance_selfCall, value_balance_self,);
|
||||
|
||||
sol!(
|
||||
contract Bitwise {
|
||||
|
||||
+28
-105
@@ -6,6 +6,10 @@ use SpecsAction::*;
|
||||
|
||||
use crate::cases::Contract;
|
||||
|
||||
/// Parameters:
|
||||
/// - The function name of the test
|
||||
/// - The contract name to fill in empty code based on the file path
|
||||
/// - The contract source file
|
||||
macro_rules! test_spec {
|
||||
($test_name:ident, $contract_name:literal, $source_file:literal) => {
|
||||
#[test]
|
||||
@@ -26,7 +30,6 @@ test_spec!(hash_keccak_256, "TestSha3", "Crypto.sol");
|
||||
test_spec!(erc20, "ERC20", "ERC20.sol");
|
||||
test_spec!(computation, "Computation", "Computation.sol");
|
||||
test_spec!(msize, "MSize", "MSize.sol");
|
||||
test_spec!(transferred_value, "Value", "Value.sol");
|
||||
test_spec!(sha1, "SHA1", "SHA1.sol");
|
||||
test_spec!(block, "Block", "Block.sol");
|
||||
test_spec!(mcopy, "MCopy", "MCopy.sol");
|
||||
@@ -34,6 +37,11 @@ test_spec!(events, "Events", "Events.sol");
|
||||
test_spec!(storage, "Storage", "Storage.sol");
|
||||
test_spec!(mstore8, "MStore8", "MStore8.sol");
|
||||
test_spec!(address, "Context", "Context.sol");
|
||||
test_spec!(balance, "Value", "Value.sol");
|
||||
test_spec!(create, "CreateB", "Create.sol");
|
||||
test_spec!(call, "Caller", "Call.sol");
|
||||
test_spec!(transfer, "Transfer", "Transfer.sol");
|
||||
test_spec!(return_data_oob, "ReturnDataOob", "ReturnDataOob.sol");
|
||||
|
||||
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
||||
vec![Instantiate {
|
||||
@@ -224,63 +232,7 @@ fn signed_remainder() {
|
||||
}
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn events() {
|
||||
assert_success(&Contract::event(U256::ZERO), true);
|
||||
assert_success(&Contract::event(U256::from(123)), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn balance() {
|
||||
let (_, output) = assert_success(&Contract::value_balance_of(Default::default()), false);
|
||||
|
||||
let expected = U256::ZERO;
|
||||
let received = U256::from_be_slice(&output.data);
|
||||
assert_eq!(expected, received);
|
||||
|
||||
let expected = U256::from(54589);
|
||||
let (mut state, address) = State::new_deployed(Contract::value_balance_of(Default::default()));
|
||||
state.accounts_mut().get_mut(&address).unwrap().value = expected;
|
||||
|
||||
let contract = Contract::value_balance_of(address);
|
||||
let (_, output) = state
|
||||
.transaction()
|
||||
.with_default_account(&contract.pvm_runtime)
|
||||
.calldata(contract.calldata)
|
||||
.call();
|
||||
|
||||
assert_eq!(ReturnFlags::Success, output.flags);
|
||||
|
||||
let received = U256::from_be_slice(&output.data);
|
||||
assert_eq!(expected, received)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create2() {
|
||||
let mut state = State::default();
|
||||
let contract_a = Contract::create_a();
|
||||
state.upload_code(&contract_a.pvm_runtime);
|
||||
|
||||
let contract = Contract::create_b();
|
||||
let (state, output) = state
|
||||
.transaction()
|
||||
.with_default_account(&contract.pvm_runtime)
|
||||
.calldata(contract.calldata)
|
||||
.call();
|
||||
|
||||
assert_eq!(output.flags, ReturnFlags::Success);
|
||||
assert_eq!(state.accounts().len(), 2);
|
||||
|
||||
for address in state.accounts().keys() {
|
||||
if *address != Transaction::default_address() {
|
||||
let derived_address = Transaction::default_address().create2(
|
||||
B256::from(U256::from(1)),
|
||||
keccak256(&contract_a.pvm_runtime).0,
|
||||
);
|
||||
assert_eq!(*address, derived_address);
|
||||
}
|
||||
}
|
||||
}
|
||||
// These test were implement for the mock-runtime and need to be ported yet.
|
||||
|
||||
#[test]
|
||||
fn create2_failure() {
|
||||
@@ -308,29 +260,30 @@ fn create2_failure() {
|
||||
assert_eq!(output.flags, ReturnFlags::Revert);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_with_value() {
|
||||
let mut state = State::default();
|
||||
state.upload_code(&Contract::create_a().pvm_runtime);
|
||||
let amount = U256::from(123);
|
||||
|
||||
let contract = Contract::create_b();
|
||||
let (state, output) = state
|
||||
#[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)
|
||||
.callvalue(amount)
|
||||
.calldata(contract.calldata)
|
||||
.call();
|
||||
|
||||
assert_eq!(output.flags, ReturnFlags::Success);
|
||||
assert_eq!(state.accounts().len(), 2);
|
||||
assert_eq!(ReturnFlags::Success, output.flags);
|
||||
|
||||
for (address, account) in state.accounts() {
|
||||
if *address == Transaction::default_address() {
|
||||
assert_eq!(account.value, U256::ZERO);
|
||||
} else {
|
||||
assert_eq!(account.value, amount);
|
||||
}
|
||||
}
|
||||
let received = U256::from_be_slice(&output.data);
|
||||
assert_eq!(expected, received)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -356,34 +309,4 @@ fn code_size() {
|
||||
let received = U256::from_be_slice(&output.data);
|
||||
assert_eq!(expected, received);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn value_transfer() {
|
||||
// Succeeds in remix (shanghai) but traps the interpreter
|
||||
let (state, _) = assert_success(&Contract::call_value_transfer(Default::default()), false);
|
||||
|
||||
assert_eq!(state.accounts().len(), 2);
|
||||
assert!(state.accounts().get(&Address::default()).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn echo() {
|
||||
let (state, address) = State::new_deployed(Contract::call_constructor());
|
||||
|
||||
let expected = vec![1, 2, 3, 4, 5];
|
||||
let contract = Contract::call_call(address, expected.clone());
|
||||
let (_, output) = state
|
||||
.transaction()
|
||||
.with_default_account(&contract.pvm_runtime)
|
||||
.calldata(contract.calldata)
|
||||
.call();
|
||||
|
||||
assert_eq!(output.flags, ReturnFlags::Success);
|
||||
|
||||
let received = alloy_primitives::Bytes::abi_decode(&output.data, true)
|
||||
.unwrap()
|
||||
.to_vec();
|
||||
|
||||
assert_eq!(expected, received);
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -32,6 +32,7 @@ fn invoke_lld(cmd_args: &[&str]) -> bool {
|
||||
fn polkavm_linker<T: AsRef<[u8]>>(code: T) -> anyhow::Result<Vec<u8>> {
|
||||
let mut config = polkavm_linker::Config::default();
|
||||
config.set_strip(true);
|
||||
config.set_optimize(true);
|
||||
|
||||
polkavm_linker::program_from_elf(config, code.as_ref())
|
||||
.map_err(|reason| anyhow::anyhow!("polkavm linker failed: {}", reason))
|
||||
|
||||
@@ -21,12 +21,6 @@ pub static GLOBAL_CALLDATA_POINTER: &str = "ptr_calldata";
|
||||
/// The calldata size global variable name.
|
||||
pub static GLOBAL_CALLDATA_SIZE: &str = "calldatasize";
|
||||
|
||||
/// The return data pointer global variable name.
|
||||
pub static GLOBAL_RETURN_DATA_POINTER: &str = "ptr_return_data";
|
||||
|
||||
/// The return data size pointer global variable name.
|
||||
pub static GLOBAL_RETURN_DATA_SIZE: &str = "returndatasize";
|
||||
|
||||
/// The call flags global variable name.
|
||||
pub static GLOBAL_CALL_FLAGS: &str = "call_flags";
|
||||
|
||||
@@ -36,15 +30,6 @@ pub static GLOBAL_CONST_ARRAY_PREFIX: &str = "const_array_";
|
||||
/// The global verbatim getter identifier prefix.
|
||||
pub static GLOBAL_VERBATIM_GETTER_PREFIX: &str = "get_global::";
|
||||
|
||||
/// The static word size.
|
||||
pub static GLOBAL_I256_SIZE: &str = "i256_size";
|
||||
|
||||
/// The static value size.
|
||||
pub static GLOBAL_I160_SIZE: &str = "i160_size";
|
||||
|
||||
/// The static i64 size.
|
||||
pub static GLOBAL_I64_SIZE: &str = "i64_size";
|
||||
|
||||
/// The external call data offset in the auxiliary heap.
|
||||
pub const HEAP_AUX_OFFSET_EXTERNAL_CALL: u64 = 0;
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ pub mod imports {
|
||||
|
||||
pub static BLOCK_NUMBER: &str = "block_number";
|
||||
|
||||
pub static CHAIN_ID: &str = "chain_id";
|
||||
|
||||
pub static CALL: &str = "call";
|
||||
|
||||
pub static CALLER: &str = "caller";
|
||||
@@ -39,7 +41,9 @@ pub mod imports {
|
||||
|
||||
pub static RETURN: &str = "seal_return";
|
||||
|
||||
pub static RETURNDATACOPY: &str = "returndatacopy";
|
||||
pub static RETURNDATACOPY: &str = "return_data_copy";
|
||||
|
||||
pub static RETURNDATASIZE: &str = "return_data_size";
|
||||
|
||||
pub static SET_STORAGE: &str = "set_storage";
|
||||
|
||||
@@ -47,12 +51,13 @@ pub mod imports {
|
||||
|
||||
/// All imported runtime API symbols.
|
||||
/// Useful for configuring common attributes and linkage.
|
||||
pub static IMPORTS: [&str; 16] = [
|
||||
pub static IMPORTS: [&str; 18] = [
|
||||
ADDRESS,
|
||||
BALANCE,
|
||||
BLOCK_NUMBER,
|
||||
CALL,
|
||||
CALLER,
|
||||
CHAIN_ID,
|
||||
CODE_SIZE,
|
||||
DEPOSIT_EVENT,
|
||||
GET_STORAGE,
|
||||
@@ -62,6 +67,7 @@ pub mod imports {
|
||||
NOW,
|
||||
RETURN,
|
||||
RETURNDATACOPY,
|
||||
RETURNDATASIZE,
|
||||
SET_STORAGE,
|
||||
VALUE_TRANSFERRED,
|
||||
];
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//! The entry function.
|
||||
|
||||
use inkwell::types::BasicType;
|
||||
use inkwell::values::BasicValue;
|
||||
|
||||
use crate::polkavm::context::address_space::AddressSpace;
|
||||
use crate::polkavm::context::function::runtime;
|
||||
@@ -23,11 +22,8 @@ impl Entry {
|
||||
/// The number of mandatory arguments.
|
||||
pub const MANDATORY_ARGUMENTS_COUNT: usize = 2;
|
||||
|
||||
/// Reserve 1mb for calldata.
|
||||
pub const MAX_CALLDATA_SIZE: usize = 1024 * 1024;
|
||||
|
||||
/// Reserve 1mb for returndata.
|
||||
pub const MAX_RETURNDATA_SIZE: usize = 1024 * 1024;
|
||||
/// Reserve 1kb for calldata.
|
||||
pub const MAX_CALLDATA_SIZE: usize = 1024;
|
||||
|
||||
/// Initializes the global variables.
|
||||
/// The pointers are not initialized, because it's not possible to create a null pointer.
|
||||
@@ -43,14 +39,6 @@ impl Entry {
|
||||
calldata_type.get_undef(),
|
||||
);
|
||||
|
||||
let returndata_type = context.array_type(context.byte_type(), Self::MAX_RETURNDATA_SIZE);
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_RETURN_DATA_POINTER,
|
||||
returndata_type,
|
||||
AddressSpace::Stack,
|
||||
returndata_type.get_undef(),
|
||||
);
|
||||
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_HEAP_MEMORY_POINTER,
|
||||
context.llvm().ptr_type(AddressSpace::Heap.into()),
|
||||
@@ -70,12 +58,6 @@ impl Entry {
|
||||
AddressSpace::Stack,
|
||||
context.word_undef(),
|
||||
);
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_RETURN_DATA_SIZE,
|
||||
context.xlen_type(),
|
||||
AddressSpace::Stack,
|
||||
context.xlen_type().const_zero().as_basic_value_enum(),
|
||||
);
|
||||
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_CALL_FLAGS,
|
||||
@@ -84,33 +66,6 @@ impl Entry {
|
||||
context.word_const(0),
|
||||
);
|
||||
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_I256_SIZE,
|
||||
context.xlen_type(),
|
||||
AddressSpace::Stack,
|
||||
context.integer_const(
|
||||
crate::polkavm::XLEN,
|
||||
revive_common::BYTE_LENGTH_X64 as u64 * 4,
|
||||
),
|
||||
);
|
||||
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_I160_SIZE,
|
||||
context.xlen_type(),
|
||||
AddressSpace::Stack,
|
||||
context.integer_const(
|
||||
crate::polkavm::XLEN,
|
||||
revive_common::BYTE_LENGTH_X64 as u64 * 2 + revive_common::BYTE_LENGTH_X32 as u64,
|
||||
),
|
||||
);
|
||||
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_I64_SIZE,
|
||||
context.xlen_type(),
|
||||
AddressSpace::Stack,
|
||||
context.integer_const(crate::polkavm::XLEN, revive_common::BYTE_LENGTH_X64 as u64),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -130,7 +85,7 @@ impl Entry {
|
||||
"input_pointer_casted",
|
||||
)?;
|
||||
|
||||
let length_pointer = context.build_alloca(context.xlen_type(), "len_ptr");
|
||||
let length_pointer = context.build_alloca_at_entry(context.xlen_type(), "len_ptr");
|
||||
let length_pointer_casted = context.builder.build_ptr_to_int(
|
||||
length_pointer.value,
|
||||
context.xlen_type(),
|
||||
|
||||
@@ -595,59 +595,53 @@ where
|
||||
self.builder.get_insert_block().expect("Always exists")
|
||||
}
|
||||
|
||||
/// Builds a stack allocation instruction.
|
||||
/// Sets the alignment to 128 bits.
|
||||
/// Builds an aligned stack allocation at the function entry.
|
||||
pub fn build_alloca_at_entry<T: BasicType<'ctx> + Clone + Copy>(
|
||||
&self,
|
||||
r#type: T,
|
||||
name: &str,
|
||||
) -> Pointer<'ctx> {
|
||||
let current_block = self.basic_block();
|
||||
let entry_block = self.current_function().borrow().entry_block();
|
||||
|
||||
match entry_block.get_first_instruction() {
|
||||
Some(instruction) => self.builder().position_before(&instruction),
|
||||
None => self.builder().position_at_end(entry_block),
|
||||
}
|
||||
|
||||
let pointer = self.build_alloca(r#type, name);
|
||||
self.set_basic_block(current_block);
|
||||
pointer
|
||||
}
|
||||
|
||||
/// Builds an aligned stack allocation at the current position.
|
||||
/// Use this if [`build_alloca_at_entry`] might change program semantics.
|
||||
/// Otherwise, alloca should always be built at the function prelude!
|
||||
pub fn build_alloca<T: BasicType<'ctx> + Clone + Copy>(
|
||||
&self,
|
||||
r#type: T,
|
||||
name: &str,
|
||||
) -> Pointer<'ctx> {
|
||||
let pointer = self.builder.build_alloca(r#type, name).unwrap();
|
||||
self.basic_block()
|
||||
.get_last_instruction()
|
||||
.expect("Always exists")
|
||||
pointer
|
||||
.as_instruction()
|
||||
.unwrap()
|
||||
.set_alignment(revive_common::BYTE_LENGTH_STACK_ALIGN as u32)
|
||||
.expect("Alignment is valid");
|
||||
|
||||
Pointer::new(r#type, AddressSpace::Stack, pointer)
|
||||
}
|
||||
|
||||
/// Allocate an int of size `bit_length` on the stack.
|
||||
/// Returns the allocation pointer and the length pointer.
|
||||
///
|
||||
/// Useful helper for passing runtime API parameters on the stack.
|
||||
pub fn build_stack_parameter(
|
||||
&self,
|
||||
bit_length: usize,
|
||||
name: &str,
|
||||
) -> (Pointer<'ctx>, Pointer<'ctx>) {
|
||||
let buffer_pointer = self.build_alloca(self.integer_type(bit_length), name);
|
||||
let symbol = match bit_length {
|
||||
revive_common::BIT_LENGTH_WORD => GLOBAL_I256_SIZE,
|
||||
revive_common::BIT_LENGTH_ETH_ADDRESS => GLOBAL_I160_SIZE,
|
||||
revive_common::BIT_LENGTH_BLOCK_NUMBER => GLOBAL_I64_SIZE,
|
||||
_ => panic!("invalid stack parameter bit width: {bit_length}"),
|
||||
};
|
||||
let length_pointer = self.get_global(symbol).expect("should be declared");
|
||||
(buffer_pointer, length_pointer.into())
|
||||
}
|
||||
|
||||
/// Load the integer at given pointer and zero extend it to the VM word size.
|
||||
pub fn build_load_word(
|
||||
/// Load the address at given pointer and zero extend it to the VM word size.
|
||||
pub fn build_load_address(
|
||||
&self,
|
||||
pointer: Pointer<'ctx>,
|
||||
bit_length: usize,
|
||||
name: &str,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
|
||||
let value = self.build_load(
|
||||
pointer.cast(self.integer_type(bit_length)),
|
||||
&format!("load_{name}"),
|
||||
)?;
|
||||
let value_extended = self.builder().build_int_z_extend(
|
||||
value.into_int_value(),
|
||||
self.word_type(),
|
||||
&format!("zext_{name}"),
|
||||
)?;
|
||||
Ok(value_extended.as_basic_value_enum())
|
||||
let address = self.build_byte_swap(self.build_load(pointer, "address_pointer")?)?;
|
||||
Ok(self
|
||||
.builder()
|
||||
.build_int_z_extend(address.into_int_value(), self.word_type(), "address_zext")?
|
||||
.into())
|
||||
}
|
||||
|
||||
/// Builds a stack load instruction.
|
||||
@@ -928,6 +922,22 @@ where
|
||||
.left()
|
||||
}
|
||||
|
||||
/// Builds a call to the runtime API `import`, where `import` is a "getter" API.
|
||||
/// This means that the supplied API method just writes back a single word.
|
||||
/// `import` is thus expect to have a single parameter, the 32 bytes output buffer,
|
||||
/// and no return value.
|
||||
pub fn build_runtime_call_to_getter(
|
||||
&self,
|
||||
import: &'static str,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let pointer = self.build_alloca_at_entry(self.word_type(), &format!("{import}_output"));
|
||||
self.build_runtime_call(import, &[pointer.to_int(self).into()]);
|
||||
self.build_load(pointer, import)
|
||||
}
|
||||
|
||||
/// Builds a call.
|
||||
pub fn build_call(
|
||||
&self,
|
||||
|
||||
@@ -7,16 +7,14 @@ use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
use crate::polkavm_const::runtime_api;
|
||||
|
||||
static STATIC_CALL_FLAG: u32 = 0b0001_0000;
|
||||
const STATIC_CALL_FLAG: u32 = 0b0001_0000;
|
||||
const REENTRANT_CALL_FLAG: u32 = 0b0000_1000;
|
||||
|
||||
/// Translates a contract call.
|
||||
///
|
||||
/// If the `simulation_address` is specified, the call is
|
||||
/// substituted with another instruction according to the specification.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn call<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
gas: inkwell::values::IntValue<'ctx>,
|
||||
_gas: inkwell::values::IntValue<'ctx>,
|
||||
address: inkwell::values::IntValue<'ctx>,
|
||||
value: Option<inkwell::values::IntValue<'ctx>>,
|
||||
input_offset: inkwell::values::IntValue<'ctx>,
|
||||
@@ -29,59 +27,71 @@ pub fn call<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let address_pointer = context.build_alloca(context.word_type(), "address_ptr");
|
||||
context.build_store(address_pointer, address)?;
|
||||
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 value_pointer = if let Some(value) = value {
|
||||
let value_pointer = context.build_alloca(context.value_type(), "value");
|
||||
context.build_store(value_pointer, value)?;
|
||||
value_pointer
|
||||
} else {
|
||||
context.sentinel_pointer()
|
||||
};
|
||||
let value = value.unwrap_or_else(|| context.word_const(0));
|
||||
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
|
||||
context.build_store(value_pointer, value)?;
|
||||
|
||||
let input_offset = context.safe_truncate_int_to_xlen(input_offset)?;
|
||||
let input_length = context.safe_truncate_int_to_xlen(input_length)?;
|
||||
let output_offset = context.safe_truncate_int_to_xlen(output_offset)?;
|
||||
let output_length = context.safe_truncate_int_to_xlen(output_length)?;
|
||||
|
||||
let gas = context
|
||||
// TODO: What to supply here? Is there a weight to gas?
|
||||
let _gas = context
|
||||
.builder()
|
||||
.build_int_truncate(gas, context.integer_type(64), "gas")?;
|
||||
|
||||
let flags = if static_call { STATIC_CALL_FLAG } else { 0 };
|
||||
.build_int_truncate(_gas, context.integer_type(64), "gas")?;
|
||||
|
||||
let input_pointer = context.build_heap_gep(input_offset, input_length)?;
|
||||
let output_pointer = context.build_heap_gep(output_offset, output_length)?;
|
||||
|
||||
let output_length_pointer = context.get_global(crate::polkavm::GLOBAL_RETURN_DATA_SIZE)?;
|
||||
context.build_store(output_length_pointer.into(), output_length)?;
|
||||
let output_length_pointer = context.build_alloca_at_entry(context.xlen_type(), "output_length");
|
||||
context.build_store(output_length_pointer, output_length)?;
|
||||
|
||||
let argument_pointer = revive_runtime_api::calling_convention::Spill::new(
|
||||
let flags = if static_call {
|
||||
REENTRANT_CALL_FLAG | STATIC_CALL_FLAG
|
||||
} else {
|
||||
REENTRANT_CALL_FLAG
|
||||
};
|
||||
let flags = context.xlen_type().const_int(flags as u64, false);
|
||||
|
||||
let argument_type = revive_runtime_api::calling_convention::call(context.llvm());
|
||||
let argument_pointer = context.build_alloca_at_entry(argument_type, "call_arguments");
|
||||
let arguments = &[
|
||||
flags.as_basic_value_enum(),
|
||||
address_pointer.value.as_basic_value_enum(),
|
||||
context.integer_const(64, 0).as_basic_value_enum(),
|
||||
context.integer_const(64, 0).as_basic_value_enum(),
|
||||
context.sentinel_pointer().value.as_basic_value_enum(),
|
||||
value_pointer.value.as_basic_value_enum(),
|
||||
input_pointer.value.as_basic_value_enum(),
|
||||
input_length.as_basic_value_enum(),
|
||||
output_pointer.value.as_basic_value_enum(),
|
||||
output_length_pointer.value.as_basic_value_enum(),
|
||||
];
|
||||
revive_runtime_api::calling_convention::spill(
|
||||
context.builder(),
|
||||
revive_runtime_api::calling_convention::call(context.llvm()),
|
||||
"call_arguments",
|
||||
)?
|
||||
.next(context.xlen_type().const_int(flags as u64, false))?
|
||||
.next(address_pointer.value)?
|
||||
.next(gas)?
|
||||
.skip()
|
||||
.next(context.sentinel_pointer().value)?
|
||||
.next(value_pointer.value)?
|
||||
.next(input_pointer.value)?
|
||||
.next(input_length)?
|
||||
.next(output_pointer.value)?
|
||||
.next(output_length_pointer.value)?
|
||||
.done();
|
||||
argument_pointer.value,
|
||||
argument_type,
|
||||
arguments,
|
||||
)?;
|
||||
|
||||
let name = runtime_api::imports::CALL;
|
||||
let arguments = context.builder().build_ptr_to_int(
|
||||
argument_pointer,
|
||||
let argument_pointer = context.builder().build_ptr_to_int(
|
||||
argument_pointer.value,
|
||||
context.xlen_type(),
|
||||
"argument_pointer",
|
||||
"call_argument_pointer",
|
||||
)?;
|
||||
let success = context
|
||||
.build_runtime_call(name, &[arguments.into()])
|
||||
.build_runtime_call(name, &[argument_pointer.into()])
|
||||
.unwrap_or_else(|| panic!("{name} should return a value"))
|
||||
.into_int_value();
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn chain_id<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
Ok(context.word_const(0).as_basic_value_enum())
|
||||
context.build_runtime_call_to_getter(runtime_api::imports::CHAIN_ID)
|
||||
}
|
||||
|
||||
/// Translates the `block_number` instruction.
|
||||
@@ -53,22 +53,7 @@ pub fn block_number<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let (output_pointer, output_length_pointer) = context.build_stack_parameter(
|
||||
revive_common::BIT_LENGTH_BLOCK_NUMBER,
|
||||
"block_timestamp_output",
|
||||
);
|
||||
context.build_runtime_call(
|
||||
runtime_api::imports::BLOCK_NUMBER,
|
||||
&[
|
||||
output_pointer.to_int(context).into(),
|
||||
output_length_pointer.to_int(context).into(),
|
||||
],
|
||||
);
|
||||
context.build_load_word(
|
||||
output_pointer,
|
||||
revive_common::BIT_LENGTH_BLOCK_NUMBER,
|
||||
"block_number",
|
||||
)
|
||||
context.build_runtime_call_to_getter(runtime_api::imports::BLOCK_NUMBER)
|
||||
}
|
||||
|
||||
/// Translates the `block_timestamp` instruction.
|
||||
@@ -78,22 +63,7 @@ pub fn block_timestamp<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let (output_pointer, output_length_pointer) = context.build_stack_parameter(
|
||||
revive_common::BIT_LENGTH_BLOCK_TIMESTAMP,
|
||||
"block_timestamp_output",
|
||||
);
|
||||
context.build_runtime_call(
|
||||
runtime_api::imports::NOW,
|
||||
&[
|
||||
output_pointer.to_int(context).into(),
|
||||
output_length_pointer.to_int(context).into(),
|
||||
],
|
||||
);
|
||||
context.build_load_word(
|
||||
output_pointer,
|
||||
revive_common::BIT_LENGTH_BLOCK_TIMESTAMP,
|
||||
"block_timestamp",
|
||||
)
|
||||
context.build_runtime_call_to_getter(runtime_api::imports::NOW)
|
||||
}
|
||||
|
||||
/// Translates the `block_hash` instruction.
|
||||
@@ -171,20 +141,15 @@ pub fn address<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let (output_pointer, output_length_pointer) =
|
||||
context.build_stack_parameter(revive_common::BIT_LENGTH_ETH_ADDRESS, "address_output");
|
||||
let pointer = context.build_alloca_at_entry(
|
||||
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
|
||||
"address_output",
|
||||
);
|
||||
context.build_runtime_call(
|
||||
runtime_api::imports::ADDRESS,
|
||||
&[
|
||||
output_pointer.to_int(context).into(),
|
||||
output_length_pointer.to_int(context).into(),
|
||||
],
|
||||
&[pointer.to_int(context).into()],
|
||||
);
|
||||
let value = context.build_byte_swap(context.build_load(output_pointer, "address")?)?;
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(value.into_int_value(), context.word_type(), "address_zext")?
|
||||
.into())
|
||||
context.build_load_address(pointer)
|
||||
}
|
||||
|
||||
/// Translates the `caller` instruction.
|
||||
@@ -194,18 +159,13 @@ pub fn caller<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let (output_pointer, output_length_pointer) =
|
||||
context.build_stack_parameter(revive_common::BIT_LENGTH_ETH_ADDRESS, "caller_output");
|
||||
let pointer = context.build_alloca_at_entry(
|
||||
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
|
||||
"address_output",
|
||||
);
|
||||
context.build_runtime_call(
|
||||
runtime_api::imports::CALLER,
|
||||
&[
|
||||
output_pointer.to_int(context).into(),
|
||||
output_length_pointer.to_int(context).into(),
|
||||
],
|
||||
&[pointer.to_int(context).into()],
|
||||
);
|
||||
let value = context.build_byte_swap(context.build_load(output_pointer, "caller")?)?;
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(value.into_int_value(), context.word_type(), "caller_zext")?
|
||||
.into())
|
||||
context.build_load_address(pointer)
|
||||
}
|
||||
|
||||
@@ -9,26 +9,14 @@ use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
use crate::polkavm_const::runtime_api;
|
||||
|
||||
/// Translates the contract `create` instruction.
|
||||
/// The instruction is simulated by a call to a system contract.
|
||||
/// Translates the contract `create` and `create2` instruction.
|
||||
///
|
||||
/// A `salt` value of `None` is equivalent to `create1`.
|
||||
pub fn create<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
value: inkwell::values::IntValue<'ctx>,
|
||||
input_offset: inkwell::values::IntValue<'ctx>,
|
||||
input_length: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
self::create2(context, value, input_offset, input_length, None)
|
||||
}
|
||||
|
||||
/// Translates the contract `create2` instruction.
|
||||
pub fn create2<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
value: inkwell::values::IntValue<'ctx>,
|
||||
input_offset: inkwell::values::IntValue<'ctx>,
|
||||
input_length: inkwell::values::IntValue<'ctx>,
|
||||
salt: Option<inkwell::values::IntValue<'ctx>>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
@@ -37,9 +25,6 @@ where
|
||||
let input_offset = context.safe_truncate_int_to_xlen(input_offset)?;
|
||||
let input_length = context.safe_truncate_int_to_xlen(input_length)?;
|
||||
|
||||
let value_pointer = context.build_alloca(context.value_type(), "value");
|
||||
context.build_store(value_pointer, value)?;
|
||||
|
||||
let code_hash_pointer = context.build_heap_gep(input_offset, input_length)?;
|
||||
|
||||
let input_data_pointer = context.build_gep(
|
||||
@@ -48,53 +33,68 @@ where
|
||||
.xlen_type()
|
||||
.const_int(revive_common::BYTE_LENGTH_WORD as u64, false)],
|
||||
context.byte_type(),
|
||||
"value_ptr_parameter_offset",
|
||||
"input_ptr_parameter_offset",
|
||||
);
|
||||
|
||||
let salt_pointer = context.build_alloca(context.word_type(), "salt");
|
||||
context.build_store(salt_pointer, salt.unwrap_or_else(|| context.word_const(0)))?;
|
||||
let value_pointer = context.build_alloca_at_entry(context.value_type(), "transferred_value");
|
||||
context.build_store(value_pointer, value)?;
|
||||
|
||||
let (address_pointer, address_length_pointer) =
|
||||
context.build_stack_parameter(revive_common::BIT_LENGTH_ETH_ADDRESS, "address_pointer");
|
||||
let salt_pointer = match salt {
|
||||
Some(salt) => {
|
||||
let salt_pointer = context.build_alloca_at_entry(context.word_type(), "salt_pointer");
|
||||
context.build_store(salt_pointer, salt)?;
|
||||
salt_pointer
|
||||
}
|
||||
None => context.sentinel_pointer(),
|
||||
};
|
||||
|
||||
let address_pointer = context.build_alloca_at_entry(
|
||||
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
|
||||
"address_pointer",
|
||||
);
|
||||
context.build_store(address_pointer, context.word_const(0))?;
|
||||
|
||||
let argument_pointer = revive_runtime_api::calling_convention::Spill::new(
|
||||
let argument_type = revive_runtime_api::calling_convention::instantiate(context.llvm());
|
||||
let argument_pointer = context.build_alloca_at_entry(argument_type, "instantiate_arguments");
|
||||
let arguments = &[
|
||||
code_hash_pointer.value.as_basic_value_enum(),
|
||||
context.integer_const(64, 0).as_basic_value_enum(),
|
||||
context.integer_const(64, 0).as_basic_value_enum(),
|
||||
context.sentinel_pointer().value.as_basic_value_enum(),
|
||||
value_pointer.value.as_basic_value_enum(),
|
||||
input_data_pointer.value.as_basic_value_enum(),
|
||||
input_length.as_basic_value_enum(),
|
||||
address_pointer.value.as_basic_value_enum(),
|
||||
context.sentinel_pointer().value.as_basic_value_enum(),
|
||||
context.sentinel_pointer().value.as_basic_value_enum(),
|
||||
salt_pointer.value.as_basic_value_enum(),
|
||||
];
|
||||
revive_runtime_api::calling_convention::spill(
|
||||
context.builder(),
|
||||
revive_runtime_api::calling_convention::instantiate(context.llvm()),
|
||||
"create2_arguments",
|
||||
)?
|
||||
.next(code_hash_pointer.value)?
|
||||
.skip()
|
||||
.skip()
|
||||
.next(context.sentinel_pointer().value)?
|
||||
.next(value_pointer.value)?
|
||||
.next(input_data_pointer.value)?
|
||||
.next(input_length)?
|
||||
.next(address_pointer.value)?
|
||||
.next(address_length_pointer.value)?
|
||||
.next(context.sentinel_pointer().value)?
|
||||
.next(context.sentinel_pointer().value)?
|
||||
.next(salt_pointer.value)?
|
||||
.next(
|
||||
context
|
||||
.xlen_type()
|
||||
.const_int(revive_common::BYTE_LENGTH_WORD as u64, false),
|
||||
)?
|
||||
.done();
|
||||
argument_pointer.value,
|
||||
argument_type,
|
||||
arguments,
|
||||
)?;
|
||||
|
||||
let argument_pointer = context.builder().build_ptr_to_int(
|
||||
argument_pointer.value,
|
||||
context.xlen_type(),
|
||||
"instantiate_argument_pointer",
|
||||
)?;
|
||||
context.build_runtime_call(
|
||||
runtime_api::imports::INSTANTIATE,
|
||||
&[context
|
||||
.builder()
|
||||
.build_ptr_to_int(argument_pointer, context.xlen_type(), "argument_pointer")?
|
||||
.into()],
|
||||
&[argument_pointer.into()],
|
||||
);
|
||||
|
||||
context.build_load_word(
|
||||
address_pointer,
|
||||
revive_common::BIT_LENGTH_ETH_ADDRESS,
|
||||
"address",
|
||||
)
|
||||
let address = context.build_byte_swap(context.build_load(address_pointer, "address")?)?;
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(
|
||||
address.into_int_value(),
|
||||
context.word_type(),
|
||||
"address_zext",
|
||||
)?
|
||||
.into())
|
||||
}
|
||||
|
||||
/// Translates the contract hash instruction, which is actually used to set the hash of the contract
|
||||
|
||||
@@ -23,20 +23,13 @@ pub fn value<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let (output_pointer, output_length_pointer) =
|
||||
context.build_stack_parameter(revive_common::BIT_LENGTH_VALUE, "value_transferred_output");
|
||||
let output_pointer = context.build_alloca(context.value_type(), "value_transferred");
|
||||
context.build_store(output_pointer, context.word_const(0))?;
|
||||
context.build_runtime_call(
|
||||
runtime_api::imports::VALUE_TRANSFERRED,
|
||||
&[
|
||||
output_pointer.to_int(context).into(),
|
||||
output_length_pointer.to_int(context).into(),
|
||||
],
|
||||
&[output_pointer.to_int(context).into()],
|
||||
);
|
||||
context.build_load_word(
|
||||
output_pointer,
|
||||
revive_common::BIT_LENGTH_VALUE,
|
||||
"value_transferred",
|
||||
)
|
||||
context.build_load(output_pointer, "value_transferred")
|
||||
}
|
||||
|
||||
/// Translates the `balance` instructions.
|
||||
@@ -56,16 +49,32 @@ where
|
||||
context.xlen_type(),
|
||||
"balance",
|
||||
)?;
|
||||
let address = context.builder().build_ptr_to_int(
|
||||
let _address = context.builder().build_ptr_to_int(
|
||||
address_pointer.value,
|
||||
context.xlen_type(),
|
||||
"address",
|
||||
)?;
|
||||
|
||||
context.build_runtime_call(
|
||||
runtime_api::imports::BALANCE,
|
||||
&[address.into(), balance.into()],
|
||||
);
|
||||
context.build_runtime_call(runtime_api::imports::BALANCE, &[balance.into()]);
|
||||
|
||||
context.build_load(balance_pointer, "balance")
|
||||
}
|
||||
|
||||
/// Translates the `selfbalance` instructions.
|
||||
pub fn self_balance<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let balance_pointer = context.build_alloca(context.word_type(), "balance_pointer");
|
||||
let balance = context.builder().build_ptr_to_int(
|
||||
balance_pointer.value,
|
||||
context.xlen_type(),
|
||||
"balance",
|
||||
)?;
|
||||
|
||||
context.build_runtime_call(runtime_api::imports::BALANCE, &[balance.into()]);
|
||||
|
||||
context.build_load(balance_pointer, "balance")
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ where
|
||||
context.byte_type().array_type(topics_buffer_size as u32),
|
||||
"topics_buffer",
|
||||
);
|
||||
|
||||
for (n, topic) in topics.iter().enumerate() {
|
||||
let topic_buffer_offset = context
|
||||
.xlen_type()
|
||||
@@ -57,6 +58,7 @@ where
|
||||
context.build_byte_swap(topic.as_basic_value_enum())?,
|
||||
)?;
|
||||
}
|
||||
|
||||
[
|
||||
context
|
||||
.builder()
|
||||
@@ -68,7 +70,7 @@ where
|
||||
.as_basic_value_enum(),
|
||||
context
|
||||
.xlen_type()
|
||||
.const_int(topics_buffer_size as u64, false)
|
||||
.const_int(topics.len() as u64, false)
|
||||
.as_basic_value_enum(),
|
||||
input_pointer.as_basic_value_enum(),
|
||||
input_length.as_basic_value_enum(),
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
//! Translates the return data instructions.
|
||||
|
||||
use inkwell::values::BasicValue;
|
||||
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
use crate::polkavm_const::runtime_api;
|
||||
@@ -13,13 +11,17 @@ pub fn size<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let value = context
|
||||
.get_global_value(crate::polkavm::GLOBAL_RETURN_DATA_SIZE)?
|
||||
.into_int_value();
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(value, context.word_type(), "calldatasize_extended")?
|
||||
.as_basic_value_enum())
|
||||
let output_pointer = context.build_alloca_at_entry(context.word_type(), "return_data_size");
|
||||
let output_pointer_parameter = context.builder().build_ptr_to_int(
|
||||
output_pointer.value,
|
||||
context.xlen_type(),
|
||||
"return_data_copy_output_pointer",
|
||||
)?;
|
||||
context.build_runtime_call(
|
||||
runtime_api::imports::RETURNDATASIZE,
|
||||
&[output_pointer_parameter.into()],
|
||||
);
|
||||
context.build_load(output_pointer, "return_data_size_load")
|
||||
}
|
||||
|
||||
/// Translates the return data copy, trapping if
|
||||
@@ -39,16 +41,49 @@ where
|
||||
let destination_offset = context.safe_truncate_int_to_xlen(destination_offset)?;
|
||||
let size = context.safe_truncate_int_to_xlen(size)?;
|
||||
|
||||
let destination_offset = context.builder().build_ptr_to_int(
|
||||
let output_pointer = context.builder().build_ptr_to_int(
|
||||
context.build_heap_gep(destination_offset, size)?.value,
|
||||
context.xlen_type(),
|
||||
"destination_offset",
|
||||
"return_data_copy_output_pointer",
|
||||
)?;
|
||||
|
||||
let output_length_pointer = context.build_alloca_at_entry(
|
||||
context.xlen_type(),
|
||||
"return_data_copy_output_length_pointer",
|
||||
);
|
||||
context.build_store(output_length_pointer, size)?;
|
||||
let output_length_pointer_int = context.builder().build_ptr_to_int(
|
||||
output_length_pointer.value,
|
||||
context.xlen_type(),
|
||||
"return_data_copy_output_length_pointer_int",
|
||||
)?;
|
||||
|
||||
context.build_runtime_call(
|
||||
runtime_api::imports::RETURNDATACOPY,
|
||||
&[destination_offset.into(), source_offset.into(), size.into()],
|
||||
&[
|
||||
output_pointer.into(),
|
||||
output_length_pointer_int.into(),
|
||||
source_offset.into(),
|
||||
],
|
||||
);
|
||||
|
||||
// Trap on OOB (will be different in EOF code)
|
||||
let overflow_block = context.append_basic_block("return_data_overflow");
|
||||
let non_overflow_block = context.append_basic_block("return_data_non_overflow");
|
||||
let is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
size,
|
||||
context
|
||||
.build_load(output_length_pointer, "bytes_written")?
|
||||
.into_int_value(),
|
||||
"is_overflow",
|
||||
)?;
|
||||
context.build_conditional_branch(is_overflow, overflow_block, non_overflow_block)?;
|
||||
|
||||
context.set_basic_block(overflow_block);
|
||||
context.build_call(context.intrinsics().trap, &[], "invalid_trap");
|
||||
context.build_unreachable();
|
||||
|
||||
context.set_basic_block(non_overflow_block);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -39,9 +39,9 @@ impl TargetMachine {
|
||||
|
||||
/// LLVM target features.
|
||||
#[cfg(feature = "riscv-zbb")]
|
||||
pub const VM_FEATURES: &'static str = "+zbb,+e,+m";
|
||||
pub const VM_FEATURES: &'static str = "+zbb,+e,+m,+c";
|
||||
#[cfg(not(feature = "riscv-zbb"))]
|
||||
pub const VM_FEATURES: &'static str = "+e,+m";
|
||||
pub const VM_FEATURES: &'static str = "+e,+m,+c";
|
||||
|
||||
/// A shortcut constructor.
|
||||
/// A separate instance for every optimization level is created.
|
||||
|
||||
Binary file not shown.
@@ -75,10 +75,12 @@ impl pallet_revive::Config for Runtime {
|
||||
type DepositPerByte = DepositPerByte;
|
||||
type DepositPerItem = DepositPerItem;
|
||||
type AddressMapper = AccountId;
|
||||
type RuntimeMemory = ConstU32<{ 512 * 1024 * 1024 }>;
|
||||
type PVFMemory = ConstU32<{ 1024 * 1024 * 1024 }>;
|
||||
type UnsafeUnstableInterface = UnstableInterface;
|
||||
type UploadOrigin = EnsureSigned<AccountId32>;
|
||||
type InstantiateOrigin = EnsureSigned<AccountId32>;
|
||||
type Migrations = ();
|
||||
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
|
||||
type Debug = ();
|
||||
type ChainId = ConstU64<420_420_420>;
|
||||
}
|
||||
|
||||
+59
-21
@@ -58,7 +58,6 @@ pub enum SpecsAction {
|
||||
},
|
||||
/// Verify the result of the last call, omitting this will simply ensure the last call was successful
|
||||
VerifyCall(VerifyCallExpectation),
|
||||
|
||||
/// Verify the balance of an account
|
||||
VerifyBalance {
|
||||
origin: TestAddress,
|
||||
@@ -179,7 +178,11 @@ impl Default for Specs {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
differential: false,
|
||||
balances: vec![(ALICE, 1_000_000_000)],
|
||||
balances: vec![
|
||||
(ALICE, 1_000_000_000),
|
||||
(BOB, 1_000_000_000),
|
||||
(CHARLIE, 1_000_000_000),
|
||||
],
|
||||
actions: Default::default(),
|
||||
}
|
||||
}
|
||||
@@ -272,10 +275,10 @@ impl Specs {
|
||||
origin,
|
||||
value,
|
||||
gas_limit,
|
||||
storage_deposit_limit,
|
||||
code,
|
||||
data,
|
||||
salt,
|
||||
..
|
||||
} => {
|
||||
let Code::Solidity {
|
||||
path: Some(path),
|
||||
@@ -286,21 +289,41 @@ impl Specs {
|
||||
else {
|
||||
panic!("the differential runner requires Code::Solidity source");
|
||||
};
|
||||
assert_ne!(solc_optimizer, Some(false), "solc_optimizer must be enabled in differntial mode");
|
||||
assert_ne!(pipeline, Some(revive_solidity::SolcPipeline::EVMLA), "yul pipeline must be enabled in differntial mode");
|
||||
assert!(storage_deposit_limit.is_none(), "storage deposit limit is not supported in differential mode");
|
||||
assert!(salt.0.is_none(), "salt is not supported in differential mode");
|
||||
assert_eq!(origin, TestAddress::default(), "configuring the origin is not supported in differential mode");
|
||||
|
||||
assert_ne!(
|
||||
solc_optimizer,
|
||||
Some(false),
|
||||
"solc_optimizer must be enabled in differntial mode"
|
||||
);
|
||||
assert_ne!(
|
||||
pipeline,
|
||||
Some(revive_solidity::SolcPipeline::EVMLA),
|
||||
"yul pipeline must be enabled in differntial mode"
|
||||
);
|
||||
assert!(
|
||||
salt.0.is_none(),
|
||||
"salt is not supported in differential mode"
|
||||
);
|
||||
assert_eq!(
|
||||
origin,
|
||||
TestAddress::default(),
|
||||
"configuring the origin is not supported in differential mode"
|
||||
);
|
||||
|
||||
let deploy_code = match std::fs::read_to_string(&path) {
|
||||
Ok(solidity_source) => compile_evm_deploy_code(&contract, &solidity_source),
|
||||
Ok(solidity_source) => {
|
||||
hex::encode(compile_evm_deploy_code(&contract, &solidity_source))
|
||||
}
|
||||
Err(err) => panic!(
|
||||
"failed to read solidity source\n . path: '{}'\n . error: {:?}",
|
||||
path.display(),
|
||||
err
|
||||
),
|
||||
};
|
||||
let deploy_code = hex::encode(deploy_code);
|
||||
let mut vm = evm.code_blob(deploy_code.as_bytes().to_vec()).sender(origin.to_eth_addr(&[]).0.into()).deploy(true);
|
||||
let mut vm = evm
|
||||
.code_blob(deploy_code.as_bytes().to_vec())
|
||||
.sender(origin.to_eth_addr(&[]).0.into())
|
||||
.deploy(true);
|
||||
if !data.is_empty() {
|
||||
vm = vm.input(data.into());
|
||||
}
|
||||
@@ -315,7 +338,13 @@ impl Specs {
|
||||
let deployed_account = log.account_deployed.expect("no account was created");
|
||||
let account_pvm = TestAddress::Instantiated(deployed_accounts.len());
|
||||
deployed_accounts.push(deployed_account);
|
||||
derived_specs.actions.append(&mut SpecsAction::derive_verification(&log, deployed_account, account_pvm));
|
||||
derived_specs
|
||||
.actions
|
||||
.append(&mut SpecsAction::derive_verification(
|
||||
&log,
|
||||
deployed_account,
|
||||
account_pvm,
|
||||
));
|
||||
evm = Evm::from_genesis(log.state_dump.into());
|
||||
}
|
||||
Call {
|
||||
@@ -323,16 +352,23 @@ impl Specs {
|
||||
dest,
|
||||
value,
|
||||
gas_limit,
|
||||
storage_deposit_limit,
|
||||
data,
|
||||
..
|
||||
} => {
|
||||
assert_eq!(origin, TestAddress::default(), "configuring the origin is not supported in differential mode");
|
||||
assert!(storage_deposit_limit.is_none(), "storage deposit limit is not supported in differential mode");
|
||||
assert_eq!(
|
||||
origin,
|
||||
TestAddress::default(),
|
||||
"configuring the origin is not supported in differential mode"
|
||||
);
|
||||
let TestAddress::Instantiated(n) = dest else {
|
||||
panic!("the differential runner requires TestAccountId::Instantiated(n) as dest");
|
||||
};
|
||||
let address = deployed_accounts.get(n).unwrap_or_else(|| panic!("no account at index {n} "));
|
||||
let mut vm = evm.receiver(*address).sender(origin.to_eth_addr(&[]).0.into());
|
||||
let address = deployed_accounts
|
||||
.get(n)
|
||||
.unwrap_or_else(|| panic!("no account at index {n} "));
|
||||
let mut vm = evm
|
||||
.receiver(*address)
|
||||
.sender(origin.to_eth_addr(&[]).0.into());
|
||||
if !data.is_empty() {
|
||||
vm = vm.input(data.into());
|
||||
}
|
||||
@@ -344,10 +380,13 @@ impl Specs {
|
||||
}
|
||||
|
||||
let log = vm.run();
|
||||
derived_specs.actions.append(&mut SpecsAction::derive_verification(&log, *address, dest));
|
||||
derived_specs
|
||||
.actions
|
||||
.append(&mut SpecsAction::derive_verification(&log, *address, dest));
|
||||
evm = Evm::from_genesis(log.state_dump.into());
|
||||
}
|
||||
_ => panic!("only instantiate and call action allowed in differential mode, got: {action:?}"),
|
||||
Upload { .. } => continue,
|
||||
other => derived_specs.actions.push(other),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,7 +441,7 @@ impl Specs {
|
||||
pallet_revive::Code::Existing(_) => continue,
|
||||
pallet_revive::Code::Upload(bytes) => bytes,
|
||||
},
|
||||
storage_deposit_limit.unwrap_or_default(),
|
||||
storage_deposit_limit.unwrap_or(DEPOSIT_LIMIT),
|
||||
)
|
||||
.unwrap_or_else(|error| panic!("code upload failed: {error:?}")),
|
||||
Call {
|
||||
@@ -442,7 +481,6 @@ impl Specs {
|
||||
expected,
|
||||
} => {
|
||||
let address = contract.to_eth_addr(&results);
|
||||
dbg!(contract.to_account_id(&results));
|
||||
let Ok(value) = Contracts::get_storage(address, key) else {
|
||||
panic!("error reading storage for address {address}");
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ use inkwell::{
|
||||
context::Context,
|
||||
module::Module,
|
||||
types::{BasicType, StructType},
|
||||
values::{BasicValue, PointerValue},
|
||||
values::{BasicValueEnum, PointerValue},
|
||||
};
|
||||
|
||||
/// Creates a module that sets the PolkaVM minimum stack size to [`size`] if linked in.
|
||||
@@ -21,56 +21,33 @@ pub fn min_stack_size<'context>(
|
||||
module
|
||||
}
|
||||
|
||||
pub struct Spill<'a, 'ctx> {
|
||||
/// Helper for building function calls with stack spilled arguments.
|
||||
/// - `pointer`: points to a struct of the packed argument struct type
|
||||
/// - `type`: the packed argument struct type
|
||||
/// - `arguments`: a correctly ordered list of the struct field values
|
||||
pub fn spill<'ctx>(
|
||||
builder: &Builder<'ctx>,
|
||||
pointer: PointerValue<'ctx>,
|
||||
builder: &'a Builder<'ctx>,
|
||||
r#type: StructType<'ctx>,
|
||||
current_field: u32,
|
||||
}
|
||||
|
||||
impl<'a, 'ctx> Spill<'a, 'ctx> {
|
||||
pub fn new(
|
||||
builder: &'a Builder<'ctx>,
|
||||
r#type: StructType<'ctx>,
|
||||
name: &str,
|
||||
) -> anyhow::Result<Self> {
|
||||
Ok(Self {
|
||||
pointer: builder.build_alloca(r#type, name)?,
|
||||
builder,
|
||||
arguments: &[BasicValueEnum<'ctx>],
|
||||
) -> anyhow::Result<()> {
|
||||
for index in 0..r#type.get_field_types().len() {
|
||||
let field_pointer = builder.build_struct_gep(
|
||||
r#type,
|
||||
current_field: 0,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn next<V: BasicValue<'ctx>>(mut self, value: V) -> anyhow::Result<Self> {
|
||||
let field_pointer = self.builder.build_struct_gep(
|
||||
self.r#type,
|
||||
self.pointer,
|
||||
self.current_field,
|
||||
&format!("spill_parameter_{}", self.current_field),
|
||||
pointer,
|
||||
index as u32,
|
||||
&format!("spill_parameter_{}", index),
|
||||
)?;
|
||||
self.builder.build_store(field_pointer, value)?;
|
||||
self.current_field += 1;
|
||||
Ok(self)
|
||||
let field_value = arguments
|
||||
.get(index)
|
||||
.ok_or_else(|| anyhow::anyhow!("invalid index {index} for struct type {}", r#type))?;
|
||||
builder.build_store(field_pointer, *field_value)?;
|
||||
}
|
||||
|
||||
pub fn skip(mut self) -> Self {
|
||||
self.current_field += 1;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn done(self) -> PointerValue<'ctx> {
|
||||
assert!(
|
||||
self.r#type
|
||||
.get_field_type_at_index(self.current_field)
|
||||
.is_none(),
|
||||
"there must not be any missing parameters"
|
||||
);
|
||||
|
||||
self.pointer
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns a packed struct argument type for the `instantiate` API.
|
||||
pub fn instantiate(context: &Context) -> StructType {
|
||||
context.struct_type(
|
||||
&[
|
||||
@@ -90,21 +67,18 @@ pub fn instantiate(context: &Context) -> StructType {
|
||||
context.i32_type().as_basic_type_enum(),
|
||||
// address_ptr: u32,
|
||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||
// address_len_ptr: u32,
|
||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||
// output_ptr: u32,
|
||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||
// output_len_ptr: u32,
|
||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||
// salt_ptr: u32,
|
||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||
// salt_len: u32
|
||||
context.i32_type().as_basic_type_enum(),
|
||||
],
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns a packed struct argument type for the `call` API.
|
||||
pub fn call(context: &Context) -> StructType {
|
||||
context.struct_type(
|
||||
&[
|
||||
|
||||
@@ -55,9 +55,11 @@ POLKAVM_IMPORT(void, input, uint32_t, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(void, returndatacopy, uint32_t, uint32_t, uint32_t)
|
||||
POLKAVM_IMPORT(void, return_data_copy, uint32_t, uint32_t, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(void, value_transferred, uint32_t, uint32_t)
|
||||
POLKAVM_IMPORT(void, return_data_size, 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)
|
||||
|
||||
@@ -77,7 +79,7 @@ POLKAVM_IMPORT(uint32_t, instantiate, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(void, terminate, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(void, caller, uint32_t, uint32_t)
|
||||
POLKAVM_IMPORT(void, caller, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(uint32_t, is_contract, uint32_t)
|
||||
|
||||
@@ -91,21 +93,23 @@ POLKAVM_IMPORT(uint32_t, caller_is_origin)
|
||||
|
||||
POLKAVM_IMPORT(uint32_t, caller_is_root)
|
||||
|
||||
POLKAVM_IMPORT(void, address, uint32_t, uint32_t)
|
||||
POLKAVM_IMPORT(void, 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, uint32_t)
|
||||
POLKAVM_IMPORT(void, balance, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(void, now, uint32_t, 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, uint32_t)
|
||||
POLKAVM_IMPORT(void, block_number, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(void, hash_sha2_256, uint32_t, uint32_t, uint32_t)
|
||||
|
||||
|
||||
@@ -1119,6 +1119,7 @@ where
|
||||
value,
|
||||
input_offset,
|
||||
input_length,
|
||||
None,
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
@@ -1130,7 +1131,7 @@ where
|
||||
let input_length = arguments[2].into_int_value();
|
||||
let salt = arguments[3].into_int_value();
|
||||
|
||||
revive_llvm_context::polkavm_evm_create::create2(
|
||||
revive_llvm_context::polkavm_evm_create::create(
|
||||
context,
|
||||
value,
|
||||
input_offset,
|
||||
@@ -1159,7 +1160,9 @@ where
|
||||
let address = arguments[0].into_int_value();
|
||||
revive_llvm_context::polkavm_evm_ether_gas::balance(context, address).map(Some)
|
||||
}
|
||||
InstructionName::SELFBALANCE => todo!(),
|
||||
InstructionName::SELFBALANCE => {
|
||||
revive_llvm_context::polkavm_evm_ether_gas::self_balance(context).map(Some)
|
||||
}
|
||||
|
||||
InstructionName::GASLIMIT => {
|
||||
revive_llvm_context::polkavm_evm_contract_context::gas_limit(context).map(Some)
|
||||
|
||||
@@ -79,7 +79,7 @@ pub struct Arguments {
|
||||
pub solc: Option<String>,
|
||||
|
||||
/// The EVM target version to generate IR for.
|
||||
/// See https://github.com/xermicus/revive/blob/main/crates/common/src/evm_version.rs for reference.
|
||||
/// See https://github.com/paritytech/revive/blob/main/crates/common/src/evm_version.rs for reference.
|
||||
#[structopt(long = "evm-version")]
|
||||
pub evm_version: Option<String>,
|
||||
|
||||
@@ -196,14 +196,14 @@ impl Arguments {
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
if self.recursive_process_input.is_none() && !self.recursive_process {
|
||||
if self.recursive_process_input.is_some() && !self.recursive_process {
|
||||
anyhow::bail!("--process-input can be only used when --recursive-process is given");
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
if self.recursive_process
|
||||
&& ((self.recursive_process_input.is_none() && std::env::args().count() > 2)
|
||||
|| (self.recursive_process_input.is_none() && std::env::args().count() > 4))
|
||||
|| (self.recursive_process_input.is_some() && std::env::args().count() > 4))
|
||||
{
|
||||
anyhow::bail!("No other options are allowed in recursive mode.");
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ impl Compiler {
|
||||
pub const FIRST_VIA_IR_VERSION: semver::Version = semver::Version::new(0, 8, 13);
|
||||
|
||||
/// The last supported version of `solc`.
|
||||
pub const LAST_SUPPORTED_VERSION: semver::Version = semver::Version::new(0, 8, 26);
|
||||
pub const LAST_SUPPORTED_VERSION: semver::Version = semver::Version::new(0, 8, 27);
|
||||
|
||||
/// A shortcut constructor.
|
||||
/// Different tools may use different `executable` names. For example, the integration tester
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"version": "1.0.0",
|
||||
"title": "resolc CLI Tests",
|
||||
"description": "Auto tests for verifying resolc CLI",
|
||||
"repository": "https://github.com/xermicus/revive",
|
||||
"repository": "https://github.com/paritytech/revive",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -831,6 +831,7 @@ impl FunctionCall {
|
||||
value,
|
||||
input_offset,
|
||||
input_length,
|
||||
None,
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
@@ -842,7 +843,7 @@ impl FunctionCall {
|
||||
let input_length = arguments[2].into_int_value();
|
||||
let salt = arguments[3].into_int_value();
|
||||
|
||||
revive_llvm_context::polkavm_evm_create::create2(
|
||||
revive_llvm_context::polkavm_evm_create::create(
|
||||
context,
|
||||
value,
|
||||
input_offset,
|
||||
@@ -912,7 +913,9 @@ impl FunctionCall {
|
||||
let address = arguments[0].into_int_value();
|
||||
revive_llvm_context::polkavm_evm_ether_gas::balance(context, address).map(Some)
|
||||
}
|
||||
Name::SelfBalance => todo!(),
|
||||
Name::SelfBalance => {
|
||||
revive_llvm_context::polkavm_evm_ether_gas::self_balance(context).map(Some)
|
||||
}
|
||||
|
||||
Name::GasLimit => {
|
||||
revive_llvm_context::polkavm_evm_contract_context::gas_limit(context).map(Some)
|
||||
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
CONTAINER=revive-builder-debian-x86
|
||||
VERSION=latest
|
||||
DOCKERFILE=revive-builder-debian.dockerfile
|
||||
|
||||
docker build --rm -t ${CONTAINER}:${VERSION} -f ${DOCKERFILE} $@
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
REVIVE_INSTALL_DIR=$(pwd)/target/release
|
||||
while getopts "o:" option ; do
|
||||
case $option in
|
||||
o) # Output directory
|
||||
REVIVE_INSTALL_DIR=$OPTARG
|
||||
;;
|
||||
\?) echo "Error: Invalid option"
|
||||
exit 1;;
|
||||
esac
|
||||
done
|
||||
echo "Installing to ${REVIVE_INSTALL_DIR}"
|
||||
|
||||
$(pwd)/build-llvm.sh
|
||||
export PATH=$(pwd)/llvm18.0/bin:$PATH
|
||||
|
||||
make install-revive REVIVE_INSTALL_DIR=${REVIVE_INSTALL_DIR}
|
||||
@@ -0,0 +1,14 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
# Dockerfile for building revive in a Debian container.
|
||||
FROM debian:12
|
||||
RUN <<EOF
|
||||
apt-get update
|
||||
apt-get install -q -y build-essential cmake make ninja-build python3 \
|
||||
libmpfr-dev libgmp-dev libmpc-dev ncurses-dev \
|
||||
git curl
|
||||
EOF
|
||||
ARG RUST_VERSION=stable
|
||||
RUN <<EOF
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${RUST_VERSION}
|
||||
EOF
|
||||
ENV PATH=/root/.cargo/bin:${PATH}
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
CONTAINER=revive-builder-debian-x86
|
||||
VERSION=latest
|
||||
|
||||
docker run --rm -v $(pwd):$(pwd) -w $(pwd) ${CONTAINER}:${VERSION} $@
|
||||
Reference in New Issue
Block a user