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

Add contract creation allow lists to EVM domains #3350

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Conversation

teor2345
Copy link
Member

@teor2345 teor2345 commented Jan 15, 2025

This PR adds a pallet which filters ethereum contract creation using an allow list. The allow list can be updated by the domain sudo account.

By default, all accounts can create contracts, to maintain compatibility with existing EVM domains. But the chainspec can be configured with an initial allow list of accounts. For our "private" EVM, that will be the domain sudo.

Close #3344.

I couldn't work out how to do a dynamic check for the domain sudo inside the pallet or runtime. I'm not sure if that's needed, because we can add the sudo account in the chainspec, or they can add themselves to the list using the (sudo) call provided by the pallet.

Part of #3353.

Code contributor checklist:

@teor2345 teor2345 added enhancement New feature or request execution Subspace execution labels Jan 15, 2025
@teor2345 teor2345 self-assigned this Jan 15, 2025
@teor2345

This comment was marked as resolved.

NingLin-P

This comment was marked as resolved.

teor2345

This comment was marked as resolved.

@vedhavyas

This comment was marked as resolved.

@teor2345

This comment was marked as resolved.

@vedhavyas

This comment was marked as resolved.

Copy link
Member

@vedhavyas vedhavyas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense overall. Left questions on penalizing malicious operator including these txns in bundle

domains/runtime/evm/src/lib.rs Show resolved Hide resolved
domains/pallets/evm_nonce_tracker/src/lib.rs Outdated Show resolved Hide resolved
domains/pallets/evm_nonce_tracker/src/lib.rs Outdated Show resolved Hide resolved
pub struct CheckContractCreation;

impl SignedExtension for CheckContractCreation {
const IDENTIFIER: &'static str = "CheckContractCreation";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this Extension to the pallet itself?
Also ideal if we change the name of pallet to something more alighed with new changes
maybe just pallet-evm-tracker ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this Extension to the pallet itself?

This also makes sense to me, as we can use this extension in the test evm runtime too, and we can write integration test for it.

Also ideal if we change the name of pallet to something more alighed with new changes
maybe just pallet-evm-tracker ?

It is okay to change the crate name but notice we can't change the pallet name in the runtime, because the pallet name is used to construct the storage key changing it make break compatibility with the existing evm domain on Taurus

Copy link
Member Author

@teor2345 teor2345 Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this Extension to the pallet itself?

Not easily. The extension matches on the Runtime::Call enum, which is composed via a macro. Similar code isn't located in pallets, it's located in crates/subspace-runtime/src/signed_extensions.rs and crates/subspace-runtime/src/object_mapping.rs.

We could move the extension to the pallet, but we'd need to keep the code that identifies a contract creation transaction next to the code that constructs the domain runtime. And add a new ContainsContractCreation trait so the extension can call that runtime-specific code.

Also ideal if we change the name of pallet to something more alighed with new changes
maybe just pallet-evm-tracker ?

Sure, I'll do this last.
Edit: done in PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not easily. The extension matches on the Runtime::Call enum, which is composed via a macro. Similar code isn't located in pallets, it's located in crates/subspace-runtime/src/signed_extensions.rs and crates/subspace-runtime/src/object_mapping.rs.

We could move the extension to the pallet, but we'd need to keep the code that identifies a contract creation transaction next to the code that constructs the domain runtime. And add a new ContainsContractCreation trait so the extension can call that runtime-specific code.

Ok, I worked out how to do this in a way that's easier to maintain. At the moment, we use complicated matching or trait impls, which need to be kept in sync between the production and test runtime code.

But if we use this design pattern, the copied impls are small and straightforward:

  • in the runtime, have a trait that converts into the pallet call type, for example MaybeIntoUtilityCall
  • in the pallet, call that trait on the RuntimeCall type to get the pallet Call type
  • the pallet can then depend directly on the other pallets whose structures it needs to use

This will let me move these things into pallet-evm-tracker:

  • is_create_contract_allowed()
  • is_create_unsigned_contract_allowed()
  • is_create_contract()
  • impl SignedExtension for CheckContractCreation

impl fp_self_contained::SelfContainedCall for RuntimeCall implements checks from multiple pallets, so I'm not sure where to move it. Somewhere that depends on pallet-evm-tracker, pallet-block-fees, and domain-check-weight, I guess.

domains/runtime/evm/src/lib.rs Show resolved Hide resolved
domains/runtime/evm/src/lib.rs Outdated Show resolved Hide resolved
crates/pallet-domains/src/domain_registry.rs Outdated Show resolved Hide resolved
@@ -633,6 +634,7 @@ fn test_bundle_format_verification() {
bundle_slot_probability: (1, 1),
operator_allow_list: OperatorAllowList::Anyone,
initial_balances: Default::default(),
initial_evm_contract_creation_allow_list: None,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add another test with some address included ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to do this after the API is stable, so I don't have to rework the tests multiple times.

Copy link
Member Author

@teor2345 teor2345 Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test matrix:

  • Instantiate domain with allow list, using all allow list combinations below
    • Instantiate domain without allow list (existing tests)
  • Update allow list using call, with all allow list combinations below
  • Migration v2 to v3 storage format (Taurus only)

Test contract allow/deny for all combinations of:

  • Anyone vs Empty vs 1 Account vs Multiple Accounts (First vs not First)
    • Signer vs Not Signer
  • Contract vs Non-Contract vs Deeply nested (contract vs non-contract)
    • Ethereum (self-contained) vs EVM (signed extension) calls
      • legacy vs vs eip1559 vs eip2930

domains/runtime/evm/src/lib.rs Show resolved Hide resolved
domains/pallets/evm_nonce_tracker/src/lib.rs Outdated Show resolved Hide resolved
domains/runtime/evm/src/lib.rs Outdated Show resolved Hide resolved
crates/pallet-domains/src/runtime_registry.rs Outdated Show resolved Hide resolved
crates/pallet-domains/src/domain_registry.rs Outdated Show resolved Hide resolved
pub struct CheckContractCreation;

impl SignedExtension for CheckContractCreation {
const IDENTIFIER: &'static str = "CheckContractCreation";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this Extension to the pallet itself?

This also makes sense to me, as we can use this extension in the test evm runtime too, and we can write integration test for it.

Also ideal if we change the name of pallet to something more alighed with new changes
maybe just pallet-evm-tracker ?

It is okay to change the crate name but notice we can't change the pallet name in the runtime, because the pallet name is used to construct the storage key changing it make break compatibility with the existing evm domain on Taurus

teor2345

This comment was marked as resolved.

@teor2345

This comment was marked as resolved.

@nazar-pc

This comment was marked as resolved.

@@ -161,7 +162,7 @@ pub type BlockTreeNodeFor<T> = crate::block_tree::BlockTreeNode<
>;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this due to Taurus being on storage version 2 already ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -136,7 +136,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: Cow::Borrowed("subspace"),
impl_name: Cow::Borrowed("subspace"),
authoring_version: 0,
spec_version: 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets not bump this yet.

I do a see a new problem with maintaing a new branch for taurus @dariolina
Apart from the spec_versin, there is also sometime storge versions for each pallet that involves migrations. This will problematic when we have a seperate branch for Taurus.

I still think having a single source of truth with same spec_version would be most non-confusing way to go

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the core protocol sync, we decided to:

  • keep the versions the same on Taurus and mainnet, skipping mainnet version numbers if needed
  • if a migration is Taurus-specific, only apply it to that branch

That means we'll need 2-3 commits for this specific PR to sync the versions:

  • Taurus version bump (different because Taurus was already bumped by the last migration, without bumping mainnet)
  • Mainnet version bump
  • Taurus migration

And then going forward we'll need 2 commits:

  • Version bump for Taurus and Mainnet
  • Migration for Taurus and maybe Mainnet

Copy link
Member Author

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've finished about half the tests, see the checklist in the comments

@@ -161,7 +162,7 @@ pub type BlockTreeNodeFor<T> = crate::block_tree::BlockTreeNode<
>;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -136,7 +136,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: Cow::Borrowed("subspace"),
impl_name: Cow::Borrowed("subspace"),
authoring_version: 0,
spec_version: 2,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the core protocol sync, we decided to:

  • keep the versions the same on Taurus and mainnet, skipping mainnet version numbers if needed
  • if a migration is Taurus-specific, only apply it to that branch

That means we'll need 2-3 commits for this specific PR to sync the versions:

  • Taurus version bump (different because Taurus was already bumped by the last migration, without bumping mainnet)
  • Mainnet version bump
  • Taurus migration

And then going forward we'll need 2 commits:

  • Version bump for Taurus and Mainnet
  • Migration for Taurus and maybe Mainnet

@@ -633,6 +634,7 @@ fn test_bundle_format_verification() {
bundle_slot_probability: (1, 1),
operator_allow_list: OperatorAllowList::Anyone,
initial_balances: Default::default(),
initial_evm_contract_creation_allow_list: None,
};
Copy link
Member Author

@teor2345 teor2345 Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test matrix:

  • Instantiate domain with allow list, using all allow list combinations below
    • Instantiate domain without allow list (existing tests)
  • Update allow list using call, with all allow list combinations below
  • Migration v2 to v3 storage format (Taurus only)

Test contract allow/deny for all combinations of:

  • Anyone vs Empty vs 1 Account vs Multiple Accounts (First vs not First)
    • Signer vs Not Signer
  • Contract vs Non-Contract vs Deeply nested (contract vs non-contract)
    • Ethereum (self-contained) vs EVM (signed extension) calls
      • legacy vs vs eip1559 vs eip2930

@teor2345

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request execution Subspace execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Private" EVM
4 participants