Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
2a2d3c9
WIP: Upgrade substrate
libredot Sep 15, 2021
69aab30
Upgrade substrate to ce1746ddf6588c8f9ecfb77411c3cac7a2c09db3
libredot Sep 15, 2021
9524050
Update Cargo.lock
libredot Sep 15, 2021
7b760ee
Fix cargo check --features=runtime-benchmarks
libredot Sep 15, 2021
5b87a51
Upgrade substrate to e1ddbb3ffec3c8f05de6cb05d9f5f7a922788c3f
libredot Sep 15, 2021
6943ae1
Add `LightSyncStateExtension` to the chain spec as an extension
libredot Sep 15, 2021
6f58f9a
Upgrade substrate to eb4de697ccd45948254db422abbcd735ae3c295a
libredot Sep 15, 2021
5b75278
cargo fmt
libredot Sep 15, 2021
07c9e9a
Upgrade substrate to ba153b9ae050eda022f002d74d76f98d1e339a81
libredot Sep 15, 2021
ad8aa08
Upgrade substrate to 435f56edc14a3a7e895ff5370f6e5179dc547cc4
libredot Dec 29, 2021
3b6a5e4
Upgrade substrate to 88b4fc861129b63b445492e3088d7f12382f0128
libredot Dec 29, 2021
fd65a3a
Upgrade substrate to ce3c31f2bfa7e10817a8a0833faddeaee818910d
libredot Dec 29, 2021
1d637a9
Upgrade substrate to 7fcebc86856164a346f6762d339e8cc3b6ec9d30
libredot Dec 29, 2021
be7e197
Upgrade substrate to bf9683eee40f82cc4e01a05cd375b0e8bba3c8ef
libredot Dec 29, 2021
6f64218
Upgrade substrate to 12b6441ef138303f50fa2fb20895fbf57c8e4735 (polkad…
libredot Dec 29, 2021
71c198e
Upgrade substrate to e09e70a3d14b3757de0be427c6ac22dfc6fcd498 (purest…
libredot Dec 29, 2021
b510cea
bump to edition 2021; fix compile errors
libredot Dec 29, 2021
e20551c
Upgrade substrate to 3a5aa8c1a48b015b12e2419fa76b2e2530b3ac75 (purest…
libredot Dec 29, 2021
b7f6221
Fix node compile error
libredot Dec 29, 2021
1b5126b
Downgrade substrate to c881b9c86df5d0e4e3607921598768a3ab8ccdc8 (Pure…
libredot Dec 29, 2021
e838715
init pallet-evm from purestake
libredot Dec 29, 2021
5f85b02
Use purestake/substrate branch moonbeam-polkadot-v0.9.13 for consistency
libredot Dec 30, 2021
97f015a
Add evm to genesis config
libredot Dec 30, 2021
194841d
CI: bump rust toolchain version to nightly-2021-12-13
libredot Dec 30, 2021
e14113e
add pallet-ethereum: init
libredot Dec 30, 2021
22e229d
install pallet ethereum and self contained unchecked extrinsic
libredot Jan 1, 2022
1f1bc0a
impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime
libredot Jan 1, 2022
8bda1d8
disable node/testing
libredot Jan 1, 2022
06e92f9
Add NetApi RPC endpoint
libredot Jan 3, 2022
6b4b83f
debug1
libredot Jan 3, 2022
2146964
fix compile error
libredot Jan 3, 2022
00e5fb5
add transaction converter
libredot Jan 4, 2022
845e337
use opaque::Block
libredot Jan 4, 2022
4305198
Add Eth RPC
libredot Jan 4, 2022
f9d16dc
add pallet-deposit for transferring fund from substrate to evm
libredot Jan 5, 2022
a52ef77
prefund accounts
libredot Jan 5, 2022
447685f
set eth chainid to 12191
libredot Jan 5, 2022
c7d6c0d
set ss58prefix to 42
libredot Jan 5, 2022
c8234cc
use forked frontier
libredot Jan 5, 2022
b7c0335
bump frontier: add evm decimal converter
libredot Jan 5, 2022
6d56054
patch ss58-registry
libredot Jan 6, 2022
8a84fd4
Revert "set ss58prefix to 42"
libredot Jan 6, 2022
d9ef567
bump frontier: add TokenDecimals support in pallet-evm
libredot Jan 6, 2022
26ee956
pallet-evm: set CallOrigin/WithdrawOrigin to EnsureAddressTruncated
libredot Jan 7, 2022
cf92761
drop FrontierBlockImport consensus support to maintain backward compa…
libredot Jan 7, 2022
cf820f7
add pallet-template
libredot Jan 10, 2022
7ae4f4a
upgrade frontier(pallet-evm): add fn token_decimals() -> u8
libredot Jan 11, 2022
bcf1900
add standard precompiles
libredot Jan 11, 2022
0763912
add PalletTemplatePrecompile
libredot Jan 11, 2022
3de979c
create pallet-template-precompiles under /precompiles
libredot Jan 12, 2022
eaa5ac7
deposit: add benchmarking
libredot Jan 12, 2022
62b2692
add PalletTemplateInterface.sol
libredot Jan 12, 2022
bc50ad5
pallet-template-precompiles: fix do_something() dispatch
libredot Jan 12, 2022
46e2dc8
add pallet-evm-precompile-balances-erc20 from moonbeam
libredot Jan 12, 2022
bbdec64
pallet-template-precompiles: fix deps repo
libredot Jan 13, 2022
6527cb9
init withdraw-balance-precompiles
libredot Jan 13, 2022
d63fef9
add withdraw-balance-precompiles to runtime
libredot Jan 13, 2022
06b2850
pallet-evm: impl custom FeeCalculator and GasWeightMapping
libredot Jan 20, 2022
36a693f
withdraw balance debug
libredot Jan 20, 2022
ef51d77
withdraw-balance: fix compile errors
libredot Jan 20, 2022
a71b677
add nftmart-nft-precompiles
libredot Jan 20, 2022
75fced0
init nftmart-{auction,order}-precompiles
libredot Jan 20, 2022
108838e
update nftmart-* precompiles contract interface
libredot Jan 20, 2022
661cb97
add pallet-nop and precompiles for debugging
libredot Jan 25, 2022
d2c39e0
add frame-system-precompiles
libredot Feb 7, 2022
3df14ba
initialize precompile opcode placeholder to allow calling from other …
libredot Feb 11, 2022
8f94d48
nftmart-nft-precompiles: add arg parsing logic
libredot Feb 15, 2022
46443e2
add account type conversion
libredot Feb 17, 2022
2692b88
nftmart-nft-precompiles: dispatch_call: burn
libredot Feb 17, 2022
b836dbe
nftmart-nft-precompiles: dispatch_call: mint
libredot Feb 17, 2022
9f61529
nftmart-nft-precompiles: dispatch_call: destroy_class
libredot Feb 17, 2022
59b3606
nftmart-nft-precompiles: dispatch_call: create_class
libredot Feb 17, 2022
3694215
nftmart-nft-precompiles: dispatch_call: proxy_mint
libredot Feb 17, 2022
66cb1be
sp-arithmetic: turn off default-features to make compiler happy
libredot Feb 17, 2022
878db85
precompiles: add write methods for all nft pallets
libredot Feb 21, 2022
09659f5
rewrite precompiles with BTreeMap
libredot Feb 23, 2022
0ad6aca
Add return value to createClass()
libredot Feb 23, 2022
de996ae
impl EvmData for NftItem
libredot Feb 23, 2022
831bfe3
add pallet-ethereum-chain-id to make chain_id configurable
libredot Mar 1, 2022
0d381f6
fix token decimals
libredot Mar 1, 2022
0780585
fix withdraw-balance precompile gasometer
libredot Mar 1, 2022
9e9bd82
init pallet-staking-precompiles
libredot Mar 3, 2022
2251961
pallet-staking-precompiles: add chill()
libredot Mar 3, 2022
831370f
init pallet-identity
libredot Mar 4, 2022
3cc4caa
pallet-staking-precompiles: add more methods
libredot Mar 7, 2022
e9d1207
nftmart-nft-precompiles: add read methods
libredot Mar 8, 2022
b030cd6
debug: disable non essential precompiles
libredot Mar 17, 2022
a2d20a5
precompiles/utils: reduce warning
libredot Mar 17, 2022
d619bd8
pallet-identity-precompiles: add set_name()
libredot Mar 17, 2022
317ba02
ethereum-chain-id: add setter method
libredot Mar 17, 2022
1c09436
runtime: expose EthereumChainId's methods
libredot Mar 17, 2022
20bea18
bump runtime version to 280
libredot Mar 17, 2022
3c64b73
housekeeping
libredot Mar 29, 2022
b6f06e0
fix cargo bench --features runtime-benchmarks
libredot Mar 29, 2022
8418e80
bump frontier
libredot Mar 29, 2022
498aeab
fix readme
libredot Mar 29, 2022
6b2cb31
add cargo doc workflow build step
libredot Mar 29, 2022
ada86a8
frontier: use associated const for TOKEN_DECIMAL
libredot Apr 5, 2022
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
Prev Previous commit
Next Next commit
add frame-system-precompiles
  • Loading branch information
navigaid committed Feb 7, 2022
commit d2c39e00efafe27f5cb4036f8a72abdc80c437c7
24 changes: 24 additions & 0 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 node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pallet-evm-precompile-dispatch = { default-features = false, git = 'https://gith
pallet-evm-precompile-sha3fips = { default-features = false, git = 'https://github.com/nftt-studio/frontier.git', branch = "moonbeam-polkadot-v0.9.13"}
pallet-evm-precompile-balances-erc20 = { default-features = false, git = 'https://github.com/nftt-studio/moonbeam.git', branch = "master"}

frame-system-precompiles = { default-features = false, path = "../../precompiles/frame-system" }
pallet-template-precompiles = { default-features = false, path = "../../precompiles/pallet-template" }
pallet-nop-precompiles = { default-features = false, path = "../../precompiles/pallet-nop" }
withdraw-balance-precompiles = { default-features = false, path = "../../precompiles/withdraw-balance" }
Expand Down Expand Up @@ -207,6 +208,7 @@ std = [
"nftmart-rpc-runtime-api/std",
"pallet-deposit/std",
"num_enum/std",
"frame-system-precompiles/std",
"pallet-template/std",
"pallet-template-precompiles/std",
"pallet-nop/std",
Expand Down
7 changes: 6 additions & 1 deletion node/runtime/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use pallet_evm_precompile_sha3fips::Sha3FIPS256;
use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256};
use pallet_template_precompiles::PalletTemplatePrecompile;
use pallet_nop_precompiles::PalletNopPrecompile;
use frame_system_precompiles::FrameSystemWrapper;
use sp_core::{H160, H256};
use sp_std::marker::PhantomData;
use withdraw_balance_precompiles::WithdrawBalancePrecompile;
Expand All @@ -51,7 +52,7 @@ where
/// Return all addresses that contain precompiles. This can be used to populate dummy code
/// under the precompile.
pub fn used_addresses() -> sp_std::vec::Vec<H160> {
sp_std::vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 2048, 2049, 2050, 2051, 2052, 2053, 2054]
sp_std::vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 2048, 2049, 2050, 2051, 2052, 2053, 2054, 2057]
.into_iter()
.map(hash)
.collect()
Expand All @@ -71,6 +72,7 @@ where
Dispatch<R>: Precompile,
PalletTemplatePrecompile<R>: Precompile,
PalletNopPrecompile<R>: Precompile,
FrameSystemWrapper<R>: Precompile,
WithdrawBalancePrecompile<R>: Precompile,
NftmartNftPrecompile<R>: Precompile,
NftmartOrderPrecompile<R>: Precompile,
Expand Down Expand Up @@ -126,6 +128,9 @@ where
a if a == hash(2054) => Some(<PalletNopPrecompile<R> as Precompile>::execute(
input, target_gas, context, is_static,
)),
a if a == hash(2057) => Some(<FrameSystemWrapper<R> as Precompile>::execute(
input, target_gas, context, is_static,
)),
_ => None,
}
}
Expand Down
55 changes: 55 additions & 0 deletions precompiles/frame-system/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[lib]
path = "lib.rs"

[package]
name = "frame-system-precompiles"
authors = [ "NFTMart" ]
description = "A Precompile to make Substrate's pallet-nop accessible to pallet-evm"
edition = "2021"
version = "4.0.0-dev"

[dependencies]
log = {version = "0.4", default-features = false }
num_enum = { version = "0.5.3", default-features = false }

# Moonbeam
precompile-utils = { default-features = false, git = 'https://github.com/nftt-studio/moonbeam.git', branch = "master"}

# Substrate
codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false }
fp-evm = { git = "https://github.com/nftt-studio/frontier.git", branch = "moonbeam-polkadot-v0.9.13", default-features = false }
frame-support = { git = "https://github.com/purestake/substrate.git", branch = "moonbeam-polkadot-v0.9.13", default-features = false }
frame-system = { git = "https://github.com/purestake/substrate.git", branch = "moonbeam-polkadot-v0.9.13", default-features = false }
sp-core = { git = "https://github.com/purestake/substrate.git", branch = "moonbeam-polkadot-v0.9.13", default-features = false }
sp-io = { git = "https://github.com/purestake/substrate.git", branch = "moonbeam-polkadot-v0.9.13", default-features = false }
sp-std = { git = "https://github.com/purestake/substrate.git", branch = "moonbeam-polkadot-v0.9.13", default-features = false }
pallet-balances = { git = "https://github.com/purestake/substrate.git", branch = "moonbeam-polkadot-v0.9.13", default-features = false }


# Frontier
pallet-evm = { git = "https://github.com/nftt-studio/frontier.git", branch = "moonbeam-polkadot-v0.9.13", default-features = false }

[dev-dependencies]
derive_more = "0.99"
hex-literal = "0.3.4"
serde = "1.0.100"

# Substrate
scale-info = { version = "1.0", default-features = false, features = [ "derive" ] }
sp-runtime = { git = "https://github.com/purestake/substrate.git", branch = "moonbeam-polkadot-v0.9.13" }

[features]
default = [ "std" ]
std = [
"log/std",
"codec/std",
"fp-evm/std",
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"pallet-evm/std",
"precompile-utils/std",
"sp-core/std",
"sp-io/std",
"sp-std/std",
]
13 changes: 13 additions & 0 deletions precompiles/frame-system/IFrameSystem.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.0;

// precompile address: 0x0000000000000000000000000000000000000809 (=2057)
interface IFrameSystem {
function remarkWithEvent(bytes memory remark) external;
}

contract FrameSystem {
function ayyyy(bytes memory remark) external {
IFrameSystem(0x0000000000000000000000000000000000000809).remarkWithEvent(remark);
}
}
92 changes: 92 additions & 0 deletions precompiles/frame-system/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![feature(assert_matches)]

use frame_support::dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo};
use pallet_evm::{AddressMapping, ExitSucceed, Precompile};
use precompile_utils::{Bytes, EvmDataReader, EvmResult, Gasometer, RuntimeHelper};

use fp_evm::{Context, PrecompileOutput};

use sp_std::{fmt::Debug, if_std, marker::PhantomData, prelude::*};

/// Each variant represents a method that is exposed in the public Solidity interface
/// The function selectors will be automatically generated at compile-time by the macros
#[precompile_utils::generate_function_selector]
#[derive(Debug, PartialEq)]
enum Action {
RemarkWithEvent = "remarkWithEvent(bytes)",
}

pub struct FrameSystemWrapper<T>(PhantomData<T>);

impl<T> Precompile for FrameSystemWrapper<T>
where
T: frame_system::Config + pallet_evm::Config,
T::Call: Dispatchable<PostInfo = PostDispatchInfo> + GetDispatchInfo,
<T::Call as Dispatchable>::Origin: From<Option<T::AccountId>>,
T::Call: From<frame_system::Call<T>>,
{
fn execute(
input: &[u8], //Reminder this is big-endian
target_gas: Option<u64>,
context: &Context,
_is_static: bool,
) -> EvmResult<PrecompileOutput> {
let mut gasometer = Gasometer::new(target_gas);
let gasometer = &mut gasometer;

let (mut input, selector) = match EvmDataReader::new_with_selector(gasometer, input) {
Ok((input, selector)) => (input, selector),
Err(e) => return Err(e),
};
let input = &mut input;

match selector {
// Check for accessor methods first. These return results immediately
Action::RemarkWithEvent => Self::remark_with_event(input, gasometer, context),
}
}
}

impl<T> FrameSystemWrapper<T>
where
T: frame_system::Config + pallet_evm::Config,
T::Call: Dispatchable<PostInfo = PostDispatchInfo> + GetDispatchInfo,
<T::Call as Dispatchable>::Origin: From<Option<T::AccountId>>,
T::Call: From<frame_system::Call<T>>,
{
fn remark_with_event(
input: &mut EvmDataReader,
gasometer: &mut Gasometer,
context: &Context,
) -> EvmResult<PrecompileOutput> {
// Bound check. We expect a single argument passed in.
input.expect_arguments(gasometer, 1)?;

// Use pallet-evm's account mapping to determine what AccountId to dispatch from.
let origin = T::AddressMapping::into_account_id(context.caller);
let remark: Vec<u8> = input.read::<Bytes>(gasometer)?.into();
let call = frame_system::Call::<T>::remark_with_event { remark: remark.clone() };

if_std! {
// This code is only being compiled and executed when the `std` feature is enabled.
println!("The caller account is: {:#?}", context.caller);
println!("The caller origin is: {:#?}", origin);
println!("The remark is: {:#?}", remark);
println!("The call is: {:#?}", call);
}

RuntimeHelper::<T>::try_dispatch(Some(origin).into(), call, gasometer)?;

let used_gas = gasometer.used_gas();
// Record the gas used in the gasometer
gasometer.record_cost(used_gas)?;

Ok(PrecompileOutput {
exit_status: ExitSucceed::Stopped,
cost: gasometer.used_gas(),
output: Default::default(),
logs: Default::default(),
})
}
}