Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets Call Runtime #963

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ jobs:
chain=${{ matrix.chain }}
runtime_version=$(cat $chain-compressed-info.json | jq '.core_version' | tr -d '"' | cut -d ' ' -f 1)
echo $runtime_version
echo "::set-output name=runtime_version::$runtime_version"
echo "runtime=$(echo $runtime_version)" >> $GITHUB_ENV
echo "${{ matrix.chain }}=$(echo $runtime_version)" >> $GITHUB_OUTPUT

- name: Upload ${{ matrix.chain }} Wasm
uses: actions/upload-release-asset@v1
Expand All @@ -476,7 +477,7 @@ jobs:
with:
upload_url: ${{ needs.publish-release-draft.outputs.upload_url }}
asset_path: ${{ matrix.chain }}_runtime.compact.compressed.wasm
asset_name: ${{ steps.get-runtime-version.outputs.runtime_version }}.wasm
asset_name: ${{ env.runtime }}.wasm
asset_content_type: application/wasm

- name: Upload ${{ matrix.chain }} Metadata
Expand Down Expand Up @@ -509,20 +510,20 @@ jobs:
asset_name: ${{ matrix.chain }}-srtool-digest.json
asset_content_type: application/json

outputs:
astar_runtime_version: ${{ steps.get-runtime-version.outputs.astar }}
shiden_runtime_version: ${{ steps.get-runtime-version.outputs.shiden }}
shibuya_runtime_version: ${{ steps.get-runtime-version.outputs.shibuya }}

upload-evm-tracing-artifacts:
needs: publish-release-draft
needs: [publish-release-draft,upload-runtimes]
runs-on: ubuntu-latest
steps:
- name: Download pre-built collator binary for evm tracing
uses: actions/download-artifact@v3
with:
name: astar-evm-tracing-ubuntu-latest-x86_64-unknown-linux-gnu
path: evm-tracing-artifacts

- name: Make evm tracing binary executable and tar gzip
run: |
cd evm-tracing-artifacts
chmod +x astar-collator

- name: Download evm tracing runtime
uses: actions/download-artifact@v3
Expand All @@ -542,6 +543,14 @@ jobs:
name: shibuya-evm-tracing-runtime
path: evm-tracing-artifacts

- name: Make evm tracing binary executable and rename
run: |
cd evm-tracing-artifacts
chmod +x astar-collator
mv astar_evm_tracing_runtime.compact.compressed.wasm ${{needs.upload-runtimes.outputs.astar_runtime_version}}_evm_tracing_runtime.compact.compressed.wasm
mv shiden_evm_tracing_runtime.compact.compressed.wasm ${{needs.upload-runtimes.outputs.shiden_runtime_version}}_evm_tracing_runtime.compact.compressed.wasm
mv shibuya_evm_tracing_runtime.compact.compressed.wasm ${{needs.upload-runtimes.outputs.shibuya_runtime_version}}_evm_tracing_runtime.compact.compressed.wasm

- name: Compress folder
run: |
tar zcvf evm-tracing-artifacts.tar.gz evm-tracing-artifacts
Expand Down
61 changes: 55 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ num-traits = { version = "0.2", default-features = false }
rand = { version = "0.8.5", default-features = false }
bounded-collections = { version = "0.1.5", default-features = false }
hex = { version = "0.4.3", default-features = false }
paste = "1.0.6"

# (native)
array-bytes = "6.0.0"
Expand Down Expand Up @@ -285,6 +286,7 @@ pallet-evm-precompile-substrate-ecdsa = { path = "./precompiles/substrate-ecdsa"
pallet-evm-precompile-xcm = { path = "./precompiles/xcm", default-features = false }
pallet-evm-precompile-xvm = { path = "./precompiles/xvm", default-features = false }
pallet-evm-precompile-dapps-staking = { path = "./precompiles/dapps-staking", default-features = false }
pallet-evm-precompile-batch = { path = "./precompiles/batch", default-features = false }

pallet-chain-extension-dapps-staking = { path = "./chain-extensions/dapps-staking", default-features = false }
pallet-chain-extension-xvm = { path = "./chain-extensions/xvm", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion bin/collator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astar-collator"
version = "5.16.1"
version = "5.17.0"
description = "Astar collator implementation in Rust."
build = "build.rs"
default-run = "astar-collator"
Expand Down
8 changes: 5 additions & 3 deletions chain-extensions/types/xvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#![cfg_attr(not(feature = "std"), no_std)]

use astar_primitives::xvm::CallError;
use astar_primitives::{xvm::CallError, Balance};
use parity_scale_codec::{Decode, Encode};
use sp_std::vec::Vec;

Expand All @@ -38,10 +38,10 @@ impl From<CallError> for XvmExecutionResult {
// `0` is reserved for `Ok`
let error_code = match input {
InvalidVmId => 1,
SameVmCallNotAllowed => 2,
SameVmCallDenied => 2,
InvalidTarget => 3,
InputTooLarge => 4,
BadOrigin => 5,
ReentranceDenied => 5,
ExecutionFailed(_) => 6,
};
Self::Err(error_code)
Expand All @@ -65,4 +65,6 @@ pub struct XvmCallArgs {
pub to: Vec<u8>,
/// Encoded call params
pub input: Vec<u8>,
/// Value to transfer
pub value: Balance,
}
36 changes: 13 additions & 23 deletions chain-extensions/xvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@

#![cfg_attr(not(feature = "std"), no_std)]

use astar_primitives::xvm::{CallError, Context, VmId, XvmCall};
use astar_primitives::xvm::{Context, VmId, XvmCall};
use frame_support::dispatch::Encode;
use pallet_contracts::{
chain_extension::{ChainExtension, Environment, Ext, InitState, RetVal},
Origin,
};
use pallet_contracts::chain_extension::{ChainExtension, Environment, Ext, InitState, RetVal};
use sp_runtime::DispatchError;
use sp_std::marker::PhantomData;
use xvm_chain_extension_types::{XvmCallArgs, XvmExecutionResult};

enum XvmFuncId {
Call,
// TODO: expand with other calls too
}

impl TryFrom<u16> for XvmFuncId {
Expand Down Expand Up @@ -76,28 +72,22 @@ where
// So we will charge a 32KB dummy value as a temporary replacement.
let charged_weight = env.charge_weight(weight_limit.set_proof_size(32 * 1024))?;

let caller = match env.ext().caller().clone() {
Origin::Signed(address) => address,
Origin::Root => {
log::trace!(
target: "xvm-extension::xvm_call",
"root origin not supported"
);
return Ok(RetVal::Converging(
XvmExecutionResult::from(CallError::BadOrigin).into(),
));
}
};
let XvmCallArgs {
vm_id,
to,
input,
value,
} = env.read_as_unbounded(env.in_len())?;

let XvmCallArgs { vm_id, to, input } = env.read_as_unbounded(env.in_len())?;
// Similar to EVM behavior, the `source` should be (limited to) the
// contract address. Otherwise contracts would be able to do arbitrary
// things on behalf of the caller via XVM.
let source = env.ext().address();

let _origin_address = env.ext().address().clone();
let _value = env.ext().value_transferred();
let xvm_context = Context {
source_vm_id: VmId::Wasm,
weight_limit,
};

let vm_id = {
match TryInto::<VmId>::try_into(vm_id) {
Ok(id) => id,
Expand All @@ -108,7 +98,7 @@ where
}
}
};
let call_result = XC::call(xvm_context, vm_id, caller, to, input);
let call_result = XC::call(xvm_context, vm_id, source.clone(), to, input, value);

let actual_weight = match call_result {
Ok(ref info) => info.used_weight,
Expand Down
4 changes: 2 additions & 2 deletions pallets/ethereum-checked/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use super::*;

use astar_primitives::ethereum_checked::MAX_ETHEREUM_TX_INPUT_SIZE;
use astar_primitives::ethereum_checked::EthereumTxInput;
use frame_benchmarking::v2::*;

#[benchmarks]
Expand All @@ -31,7 +31,7 @@ mod benchmarks {
let target =
H160::from_slice(&hex::decode("dfb975d018f03994a3b943808e3aa0964bd78463").unwrap());
// Calling `store(3)`
let input = BoundedVec::<u8, ConstU32<MAX_ETHEREUM_TX_INPUT_SIZE>>::try_from(
let input = EthereumTxInput::try_from(
hex::decode("6057361d0000000000000000000000000000000000000000000000000000000000000003")
.unwrap(),
)
Expand Down
2 changes: 1 addition & 1 deletion pallets/ethereum-checked/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl ExtBuilder {
assert_ok!(Evm::create2(
RuntimeOrigin::root(),
ALICE_H160,
hex::decode(STORAGE_CONTRACT).unwrap(),
hex::decode(STORAGE_CONTRACT).expect("invalid code hex"),
H256::zero(),
U256::zero(),
1_000_000,
Expand Down
Loading