-
Notifications
You must be signed in to change notification settings - Fork 248
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
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this 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
pub struct CheckContractCreation; | ||
|
||
impl SignedExtension for CheckContractCreation { | ||
const IDENTIFIER: &'static str = "CheckContractCreation"; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 incrates/subspace-runtime/src/signed_extensions.rs
andcrates/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 palletCall
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.
@@ -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, | |||
}; |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
- Ethereum (self-contained) vs EVM (signed extension) calls
pub struct CheckContractCreation; | ||
|
||
impl SignedExtension for CheckContractCreation { | ||
const IDENTIFIER: &'static str = "CheckContractCreation"; |
There was a problem hiding this comment.
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
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
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); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in this branch: https://github.com/autonomys/subspace/tree/taurus-runtime-upgrade
Here's the exact change:
https://github.com/autonomys/subspace/pull/3342/files#diff-9f80450addc12cd3b681275c6acb663003edc27c2d8eeeb1f26147df9f8e5bbeR164
subspace/crates/pallet-domains/src/lib.rs
Line 164 in a19ba3d
const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); |
@@ -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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in this branch: https://github.com/autonomys/subspace/tree/taurus-runtime-upgrade
Here's the exact change:
https://github.com/autonomys/subspace/pull/3342/files#diff-9f80450addc12cd3b681275c6acb663003edc27c2d8eeeb1f26147df9f8e5bbeR164
subspace/crates/pallet-domains/src/lib.rs
Line 164 in a19ba3d
const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); |
@@ -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, |
There was a problem hiding this comment.
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, | |||
}; |
There was a problem hiding this comment.
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
- Ethereum (self-contained) vs EVM (signed extension) calls
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: