Skip to content
This repository was archived by the owner on Jul 10, 2026. It is now read-only.

Commit 8d00fcb

Browse files
authored
Merge pull request #21 from opentensor/feat/upgrade-polkadot-sdk-to-2503
Upgrade to Polkadot SDK stable2503-6 and merge upstream changes
2 parents 4aeb35e + eee4079 commit 8d00fcb

32 files changed

Lines changed: 2162 additions & 1751 deletions

File tree

Cargo.lock

Lines changed: 1387 additions & 1525 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 81 additions & 80 deletions
Large diffs are not rendered by default.

client/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fp-storage = { workspace = true, features = ["default"] }
2828
[dev-dependencies]
2929
futures = { workspace = true }
3030
scale-codec = { workspace = true }
31-
tempfile = "3.3.0"
31+
tempfile = "3.20"
3232
# Substrate
3333
sc-block-builder = { workspace = true }
3434
sc-client-db = { workspace = true, features = ["rocksdb"] }

client/db/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fp-storage = { workspace = true, features = ["default"] }
4040
[dev-dependencies]
4141
futures = { workspace = true }
4242
maplit = "1.0.2"
43-
tempfile = "3.17.1"
43+
tempfile = "3.20"
4444
# Substrate
4545
sc-block-builder = { workspace = true }
4646
sp-consensus = { workspace = true }

client/mapping-sync/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ethereum = { workspace = true }
3535
ethereum-types = { workspace = true }
3636
scale-codec = { workspace = true }
3737
sqlx = { workspace = true, features = ["runtime-tokio-native-tls", "sqlite"] }
38-
tempfile = "3.17.1"
38+
tempfile = "3.20"
3939
tokio = { workspace = true, features = ["sync"] }
4040
# Substrate
4141
sc-block-builder = { workspace = true }

client/rpc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fp-storage = { workspace = true, features = ["default"] }
6161
pallet-evm = { workspace = true, features = ["default"] }
6262

6363
[dev-dependencies]
64-
tempfile = "3.14.0"
64+
tempfile = "3.20"
6565
# Substrate
6666
sc-block-builder = { workspace = true }
6767
sc-client-db = { workspace = true, features = ["rocksdb"] }

frame/ethereum/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub use ethereum::{
4040
};
4141
use ethereum_types::{Bloom, BloomInput, H160, H256, H64, U256};
4242
use evm::ExitReason;
43-
use scale_codec::{Decode, Encode, MaxEncodedLen};
43+
use scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
4444
use scale_info::TypeInfo;
4545
// Substrate
4646
use frame_support::{
@@ -72,7 +72,7 @@ use fp_storage::{EthereumStorageSchema, PALLET_ETHEREUM_SCHEMA};
7272
use pallet_evm::{BlockHashMapping, FeeCalculator, GasWeightMapping, Runner};
7373

7474
#[derive(Clone, Eq, PartialEq, RuntimeDebug)]
75-
#[derive(Encode, Decode, MaxEncodedLen, TypeInfo)]
75+
#[derive(Encode, Decode, DecodeWithMemTracking, MaxEncodedLen, TypeInfo)]
7676
pub enum RawOrigin {
7777
EthereumTransaction(H160),
7878
}

frame/ethereum/src/mock.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
//! Test utilities
1919
20+
use core::str::FromStr;
2021
use ethereum::{TransactionAction, TransactionSignature};
2122
use rlp::RlpStream;
2223
// Substrate
@@ -28,7 +29,8 @@ use sp_runtime::{
2829
};
2930
// Frontier
3031
use pallet_evm::{
31-
config_preludes::ChainId, AddressMapping, BalanceConverter, EvmBalance, SubstrateBalance,
32+
config_preludes::ChainId, AddressMapping, BalanceConverter, EnsureAllowedCreateAddress,
33+
EvmBalance, SubstrateBalance,
3234
};
3335

3436
use super::*;
@@ -88,6 +90,9 @@ impl FindAuthor<H160> for FindAuthorTruncated {
8890
parameter_types! {
8991
pub const TransactionByteFee: u64 = 1;
9092
pub const GasLimitStorageGrowthRatio: u64 = 0;
93+
// Alice is allowed to create contracts via CREATE and CALL(CREATE)
94+
pub AllowedAddressesCreate: Vec<H160> = vec![H160::from_str("0x1a642f0e3c3af545e7acbd38b07251b3990914f1").expect("alice address")];
95+
pub AllowedAddressesCreateInner: Vec<H160> = vec![H160::from_str("0x1a642f0e3c3af545e7acbd38b07251b3990914f1").expect("alice address")];
9196
}
9297

9398
const EVM_DECIMALS_FACTOR: u64 = 1_000_000_000_u64;
@@ -131,6 +136,8 @@ impl pallet_evm::Config for Test {
131136
type BalanceConverter = SubtensorEvmBalanceConverter;
132137
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
133138
type BlockHashMapping = crate::EthereumBlockHashMapping<Self>;
139+
type CreateOriginFilter = EnsureAllowedCreateAddress<AllowedAddressesCreate>;
140+
type CreateInnerOriginFilter = EnsureAllowedCreateAddress<AllowedAddressesCreateInner>;
134141
type Currency = Balances;
135142
type PrecompilesType = ();
136143
type PrecompilesValue = ();
@@ -234,9 +241,12 @@ pub fn new_test_ext(accounts_len: usize) -> (Vec<AccountInfo>, sp_io::TestExtern
234241
.map(|i| (pairs[i].account_id.clone(), 10_000_000))
235242
.collect();
236243

237-
pallet_balances::GenesisConfig::<Test> { balances }
238-
.assimilate_storage(&mut ext)
239-
.unwrap();
244+
pallet_balances::GenesisConfig::<Test> {
245+
balances,
246+
dev_accounts: None,
247+
}
248+
.assimilate_storage(&mut ext)
249+
.unwrap();
240250

241251
(pairs, ext.into())
242252
}
@@ -259,9 +269,12 @@ pub fn new_test_ext_with_initial_balance(
259269
.map(|i| (pairs[i].account_id.clone(), initial_balance))
260270
.collect();
261271

262-
pallet_balances::GenesisConfig::<Test> { balances }
263-
.assimilate_storage(&mut ext)
264-
.unwrap();
272+
pallet_balances::GenesisConfig::<Test> {
273+
balances,
274+
dev_accounts: None,
275+
}
276+
.assimilate_storage(&mut ext)
277+
.unwrap();
265278

266279
(pairs, ext.into())
267280
}

frame/ethereum/src/tests/legacy.rs

Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ use super::*;
2121
use evm::{ExitReason, ExitRevert, ExitSucceed};
2222
use fp_ethereum::{TransactionData, ValidatedTransaction};
2323
use frame_support::{
24-
dispatch::{DispatchClass, GetDispatchInfo},
24+
dispatch::{DispatchClass, GetDispatchInfo, Pays, PostDispatchInfo},
2525
weights::Weight,
2626
};
2727
use pallet_evm::AddressMapping;
28+
use sp_runtime::{DispatchError, DispatchErrorWithPostInfo, ModuleError};
2829

2930
fn legacy_erc20_creation_unsigned_transaction() -> LegacyUnsignedTransaction {
3031
LegacyUnsignedTransaction {
@@ -41,6 +42,21 @@ fn legacy_erc20_creation_transaction(account: &AccountInfo) -> Transaction {
4142
legacy_erc20_creation_unsigned_transaction().sign(&account.private_key)
4243
}
4344

45+
fn legacy_foo_bar_contract_creation_unsigned_transaction() -> LegacyUnsignedTransaction {
46+
LegacyUnsignedTransaction {
47+
nonce: U256::zero(),
48+
gas_price: U256::from(1),
49+
gas_limit: U256::from(0x100000),
50+
action: ethereum::TransactionAction::Create,
51+
value: U256::zero(),
52+
input: hex::decode(FOO_BAR_CONTRACT_CREATOR_BYTECODE.trim_end()).unwrap(),
53+
}
54+
}
55+
56+
fn legacy_foo_bar_contract_creation_transaction(account: &AccountInfo) -> Transaction {
57+
legacy_foo_bar_contract_creation_unsigned_transaction().sign(&account.private_key)
58+
}
59+
4460
#[test]
4561
fn transaction_should_increment_nonce() {
4662
let (pairs, mut ext) = new_test_ext(1);
@@ -273,6 +289,138 @@ fn transaction_should_generate_correct_gas_used() {
273289
});
274290
}
275291

292+
#[test]
293+
fn contract_creation_succeeds_with_allowed_address() {
294+
let (pairs, mut ext) = new_test_ext(1);
295+
let alice = &pairs[0];
296+
297+
ext.execute_with(|| {
298+
// Alice can deploy contracts
299+
let t = LegacyUnsignedTransaction {
300+
nonce: U256::zero(),
301+
gas_price: U256::from(1),
302+
gas_limit: U256::from(0x100000),
303+
action: ethereum::TransactionAction::Create,
304+
value: U256::zero(),
305+
input: hex::decode(TEST_CONTRACT_CODE).unwrap(),
306+
}
307+
.sign(&alice.private_key);
308+
assert_ok!(Ethereum::execute(alice.address, &t, None,));
309+
});
310+
}
311+
312+
#[test]
313+
fn contract_creation_fails_with_not_allowed_address() {
314+
let (pairs, mut ext) = new_test_ext(2);
315+
let bob = &pairs[1];
316+
317+
ext.execute_with(|| {
318+
// Bob can't deploy contracts
319+
let t = LegacyUnsignedTransaction {
320+
nonce: U256::zero(),
321+
gas_price: U256::from(1),
322+
gas_limit: U256::from(0x100000),
323+
action: ethereum::TransactionAction::Create,
324+
value: U256::zero(),
325+
input: hex::decode(TEST_CONTRACT_CODE).unwrap(),
326+
}
327+
.sign(&bob.private_key);
328+
329+
let result = Ethereum::execute(bob.address, &t, None);
330+
assert!(result.is_err());
331+
332+
// Note: assert_err! macro doesn't work here because we receive 'None' as
333+
// 'actual_weight' using assert_err instead of Some(Weight::default()),
334+
// but the error is the same "CreateOriginNotAllowed".
335+
assert_eq!(
336+
result,
337+
Err(DispatchErrorWithPostInfo {
338+
post_info: PostDispatchInfo {
339+
actual_weight: Some(Weight::default()),
340+
pays_fee: Pays::Yes
341+
},
342+
error: DispatchError::Module(ModuleError {
343+
index: 3,
344+
error: [14, 0, 0, 0],
345+
message: Some("CreateOriginNotAllowed")
346+
})
347+
})
348+
);
349+
});
350+
}
351+
352+
#[test]
353+
fn inner_contract_creation_succeeds_with_allowed_address() {
354+
let (pairs, mut ext) = new_test_ext(1);
355+
let alice = &pairs[0];
356+
357+
ext.execute_with(|| {
358+
let t = legacy_foo_bar_contract_creation_transaction(alice);
359+
assert_ok!(Ethereum::execute(alice.address, &t, None,));
360+
361+
let contract_address = hex::decode("32dcab0ef3fb2de2fce1d2e0799d36239671f04a").unwrap();
362+
let new_bar = hex::decode("2fc11060").unwrap();
363+
364+
// Alice is allowed to deploy contracts via inner calls.
365+
let new_bar_inner_creation_tx = LegacyUnsignedTransaction {
366+
nonce: U256::from(1),
367+
gas_price: U256::from(1),
368+
gas_limit: U256::from(0x100000),
369+
action: TransactionAction::Call(H160::from_slice(&contract_address)),
370+
value: U256::zero(),
371+
input: new_bar,
372+
}
373+
.sign(&alice.private_key);
374+
375+
let (_, _, info) =
376+
Ethereum::execute(alice.address, &new_bar_inner_creation_tx, None).unwrap();
377+
378+
assert!(Ethereum::execute(alice.address, &new_bar_inner_creation_tx, None).is_ok());
379+
match info {
380+
CallOrCreateInfo::Call(info) => {
381+
assert_eq!(info.exit_reason, ExitReason::Succeed(ExitSucceed::Returned));
382+
}
383+
CallOrCreateInfo::Create(_) => panic!("expected call info"),
384+
}
385+
});
386+
}
387+
388+
#[test]
389+
fn inner_contract_creation_reverts_with_not_allowed_address() {
390+
let (pairs, mut ext) = new_test_ext(2);
391+
let alice = &pairs[0];
392+
let bob = &pairs[1];
393+
394+
ext.execute_with(|| {
395+
let t = legacy_foo_bar_contract_creation_transaction(alice);
396+
assert_ok!(Ethereum::execute(alice.address, &t, None,));
397+
398+
let contract_address = hex::decode("32dcab0ef3fb2de2fce1d2e0799d36239671f04a").unwrap();
399+
let new_bar = hex::decode("2fc11060").unwrap();
400+
401+
// Bob is not allowed to deploy contracts via inner calls.
402+
let new_bar_inner_creation_tx = LegacyUnsignedTransaction {
403+
nonce: U256::from(1),
404+
gas_price: U256::from(1),
405+
gas_limit: U256::from(0x100000),
406+
action: TransactionAction::Call(H160::from_slice(&contract_address)),
407+
value: U256::zero(),
408+
input: new_bar,
409+
}
410+
.sign(&bob.private_key);
411+
412+
let (_, _, info) =
413+
Ethereum::execute(bob.address, &new_bar_inner_creation_tx, None).unwrap();
414+
415+
match info {
416+
CallOrCreateInfo::Call(info) => {
417+
assert_eq!(info.exit_reason, ExitReason::Revert(ExitRevert::Reverted));
418+
}
419+
CallOrCreateInfo::Create(_) => panic!("expected call info"),
420+
}
421+
});
422+
}
423+
276424
#[test]
277425
fn call_should_handle_errors() {
278426
let (pairs, mut ext) = new_test_ext(1);

frame/ethereum/src/tests/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,26 @@ pub const ERC20_CONTRACT_BYTECODE: &str = include_str!("./res/erc20_contract_byt
5252
// }
5353
// }
5454
pub const TEST_CONTRACT_CODE: &str = "608060405234801561001057600080fd5b50610129806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c8063c2985578146037578063febb0f7e146055575b600080fd5b603d605d565b60405180821515815260200191505060405180910390f35b605b6066565b005b60006001905090565b600060bc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260358152602001806100bf6035913960400191505060405180910390fd5b56fe766572795f6c6f6e675f6572726f725f6d73675f746861745f77655f6578706563745f746f5f62655f7472696d6d65645f61776179a26469706673582212207af96dd688d3a3adc999c619e6073d5b6056c72c79ace04a90ea4835a77d179364736f6c634300060c0033";
55+
56+
// pragma solidity ^0.8.2;
57+
// contract Foo {
58+
// function newBar() // 2fc11060
59+
// public
60+
// returns(Bar newContract)
61+
// {
62+
// Bar b = new Bar();
63+
// return b;
64+
// }
65+
//}
66+
67+
// contract Bar {
68+
// function getNumber()
69+
// public
70+
// pure
71+
// returns (uint32 number)
72+
// {
73+
// return 10;
74+
// }
75+
//}
76+
pub const FOO_BAR_CONTRACT_CREATOR_BYTECODE: &str =
77+
include_str!("./res/foo_bar_contract_creator.txt");

0 commit comments

Comments
 (0)