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

fp-account #1019

Merged
merged 29 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bd2da65
bootstrap fp-account
bernardoaraujor Mar 15, 2023
20e7806
clippy
bernardoaraujor Mar 15, 2023
0e396b1
make IdentityAddressMapping support From<H160>
bernardoaraujor Mar 15, 2023
63a4403
clippy
bernardoaraujor Mar 15, 2023
b2610f8
fix import warning
bernardoaraujor Mar 15, 2023
434c463
fix pallet-evm tests
bernardoaraujor Mar 16, 2023
f42e985
fix pallet-hotfix-sufficients tests
bernardoaraujor Mar 16, 2023
1816c53
use libsecp256k1::PublicKey::parse_compressed and sp_core::keccak_256…
bernardoaraujor Mar 16, 2023
09cbbc2
simplify keccak_256 hashing
bernardoaraujor Mar 16, 2023
c17dd3a
format derives
bernardoaraujor Mar 16, 2023
46efbd4
merge_derives = false
bernardoaraujor Mar 16, 2023
bc512bc
fix imports
bernardoaraujor Mar 16, 2023
32e21bf
impl Debug for AccountId20
bernardoaraujor Mar 16, 2023
2524979
simplify Display for EthereumSigner
bernardoaraujor Mar 16, 2023
8f27a64
fmt
bernardoaraujor Mar 16, 2023
6bbb24b
simplify keccak_256 hashing
bernardoaraujor Mar 16, 2023
849dea9
simplify ecdsa path
bernardoaraujor Mar 16, 2023
9ff7471
format derives
bernardoaraujor Mar 16, 2023
74dde28
use sp_io for keccak_256
bernardoaraujor Mar 16, 2023
dc9e114
remove sha3 dependency
bernardoaraujor Mar 16, 2023
1c4a25a
remove sha3 dependency
bernardoaraujor Mar 16, 2023
4ab0301
remove sha3 dependency
bernardoaraujor Mar 16, 2023
4c90a2d
remove sha3 import
bernardoaraujor Mar 16, 2023
3ec257f
remove sha3 dependency
bernardoaraujor Mar 16, 2023
157adb4
simplify keccak_256 hashing on tests
bernardoaraujor Mar 16, 2023
75d6b91
remove serde imports
bernardoaraujor Mar 16, 2023
72946e2
add account docs
bernardoaraujor Mar 16, 2023
ca54a7a
Merge branch 'master' into bar/fp-account
sorpaas Mar 16, 2023
cee0f91
remove sp-keyring from template deps
bernardoaraujor Mar 16, 2023
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
41 changes: 35 additions & 6 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"client/db",
"client/storage",
"client/mapping-sync",
"primitives/account",
"primitives/consensus",
"primitives/dynamic-fee",
"primitives/evm",
Expand All @@ -41,15 +42,18 @@ environmental = { version = "1.1.3", default-features = false }
ethereum = { version = "0.14.0", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }
evm = { version = "0.37.0", default-features = false }
impl-serde = { version = "0.3.1", default-features = false }
jsonrpsee = "0.16.2"
kvdb-rocksdb = "0.17.0"
libsecp256k1 = "0.7.1"
libsecp256k1 = { version = "0.7.1", default-features = false }
log = { version = "0.4.17", default-features = false }
parity-db = "0.4.2"
rlp = { version = "0.5", default-features = false }
scale-codec = { package = "parity-scale-codec", version = "3.2.1", default-features = false, features = ["derive"] }
scale-info = { version = "2.3.1", default-features = false, features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha3 = { version = "0.10", default-features = false }
bernardoaraujor marked this conversation as resolved.
Show resolved Hide resolved
# Substrate Client
sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-block-builder = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down Expand Up @@ -124,6 +128,7 @@ fc-rpc = { version = "2.0.0-dev", path = "client/rpc" }
fc-rpc-core = { version = "1.1.0-dev", path = "client/rpc-core" }
fc-storage = { version = "1.0.0-dev", path = "client/storage" }
# Frontier Primitive
fp-account = { version = "1.0.0-dev", path = "primitives/account", default-features = false }
fp-consensus = { version = "2.0.0-dev", path = "primitives/consensus", default-features = false }
fp-dynamic-fee = { version = "1.0.0", path = "primitives/dynamic-fee", default-features = false }
fp-ethereum = { version = "1.0.0-dev", path = "primitives/ethereum", default-features = false }
Expand Down
4 changes: 3 additions & 1 deletion frame/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ environmental = { workspace = true, optional = true }
evm = { workspace = true, features = ["with-codec"] }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
impl-trait-for-tuples = "0.2.2"
log = { version = "0.4.17", default-features = false }
log = { workspace = true }
rlp = { workspace = true }
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
Expand All @@ -30,6 +30,7 @@ sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
# Frontier
fp-account = { workspace = true }
fp-evm = { workspace = true }

[dev-dependencies]
Expand Down Expand Up @@ -59,6 +60,7 @@ std = [
"sp-std/std",
# Frontier
"fp-evm/std",
"fp-account/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
25 changes: 22 additions & 3 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ use sp_std::{cmp::min, vec::Vec};
pub use evm::{
Config as EvmConfig, Context, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed,
};
use fp_account::AccountId20;
#[cfg(feature = "std")]
use fp_evm::GenesisAccount;
pub use fp_evm::{
Expand Down Expand Up @@ -603,16 +604,34 @@ where
}
}

/// Ensure that the address is AccountId20.
pub struct EnsureAccountId20;

impl<OuterOrigin> EnsureAddressOrigin<OuterOrigin> for EnsureAccountId20
where
OuterOrigin: Into<Result<RawOrigin<AccountId20>, OuterOrigin>> + From<RawOrigin<AccountId20>>,
{
type Success = AccountId20;

fn try_address_origin(address: &H160, origin: OuterOrigin) -> Result<AccountId20, OuterOrigin> {
let acc: AccountId20 = AccountId20::from(*address);
origin.into().and_then(|o| match o {
RawOrigin::Signed(who) if who == acc => Ok(who),
r => Err(OuterOrigin::from(r)),
})
}
}

pub trait AddressMapping<A> {
fn into_account_id(address: H160) -> A;
}

/// Identity address mapping.
pub struct IdentityAddressMapping;

impl AddressMapping<H160> for IdentityAddressMapping {
fn into_account_id(address: H160) -> H160 {
address
impl<T: From<H160>> AddressMapping<T> for IdentityAddressMapping {
fn into_account_id(address: H160) -> T {
address.into()
}
}

Expand Down
6 changes: 4 additions & 2 deletions frame/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@ fn handle_sufficient_reference() {
new_test_ext().execute_with(|| {
let addr = H160::from_str("1230000000000000000000000000000000000001").unwrap();
let addr_2 = H160::from_str("1234000000000000000000000000000000000001").unwrap();
let substrate_addr = <Test as Config>::AddressMapping::into_account_id(addr);
let substrate_addr_2 = <Test as Config>::AddressMapping::into_account_id(addr_2);
let substrate_addr: <Test as frame_system::Config>::AccountId =
<Test as Config>::AddressMapping::into_account_id(addr);
let substrate_addr_2: <Test as frame_system::Config>::AccountId =
<Test as Config>::AddressMapping::into_account_id(addr_2);

// Sufficients should increase when creating EVM accounts.
let _ = <crate::AccountCodes<Test>>::insert(addr, &vec![0]);
Expand Down
12 changes: 8 additions & 4 deletions frame/hotfix-sufficients/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ fn test_hotfix_inc_account_sufficients_increments_if_nonce_nonzero() {
let addr_2 = "1234000000000000000000000000000000000001"
.parse::<H160>()
.unwrap();
let substrate_addr_1 = <Test as Config>::AddressMapping::into_account_id(addr_1);
let substrate_addr_2 = <Test as Config>::AddressMapping::into_account_id(addr_2);
let substrate_addr_1: <Test as frame_system::Config>::AccountId =
<Test as Config>::AddressMapping::into_account_id(addr_1);
let substrate_addr_2: <Test as frame_system::Config>::AccountId =
<Test as Config>::AddressMapping::into_account_id(addr_2);

frame_system::Pallet::<Test>::inc_account_nonce(&substrate_addr_1);

Expand Down Expand Up @@ -95,7 +97,8 @@ fn test_hotfix_inc_account_sufficients_increments_with_saturation_if_nonce_nonze
let addr = "1230000000000000000000000000000000000001"
.parse::<H160>()
.unwrap();
let substrate_addr = <Test as Config>::AddressMapping::into_account_id(addr);
let substrate_addr: <Test as frame_system::Config>::AccountId =
<Test as Config>::AddressMapping::into_account_id(addr);

frame_system::Account::<Test>::mutate(substrate_addr, |x| {
x.nonce = 1;
Expand Down Expand Up @@ -125,7 +128,8 @@ fn test_hotfix_inc_account_sufficients_does_not_increment_if_both_nonce_and_refs
let addr = "1230000000000000000000000000000000000001"
.parse::<H160>()
.unwrap();
let substrate_addr = <Test as Config>::AddressMapping::into_account_id(addr);
let substrate_addr: <Test as frame_system::Config>::AccountId =
<Test as Config>::AddressMapping::into_account_id(addr);

frame_system::Account::<Test>::mutate(substrate_addr, |x| {
x.nonce = 1;
Expand Down
38 changes: 38 additions & 0 deletions primitives/account/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "fp-account"
version = "1.0.0-dev"
license = "Apache-2.0"
description = "Primitives for Frontier AccountId20."
authors = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }

[dependencies]
hex = { version = "0.4.3", default-features = false }
impl-serde = { workspace = true }
libsecp256k1 = { workspace = true, default-features = false }
log = { workspace = true }
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
serde = { workspace = true }
sha3 = { workspace = true }
bernardoaraujor marked this conversation as resolved.
Show resolved Hide resolved
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]

[features]
default = ["std"]
std = [
"impl-serde/std",
"hex/std",
"libsecp256k1/std",
"log/std",
"sha3/std",
bernardoaraujor marked this conversation as resolved.
Show resolved Hide resolved
"serde/std",
# Substrate
"sp-io/std",
"sp-core/std",
"sp-runtime/std",
]
Loading