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

Permissioned contract deployment #3377

Merged
merged 15 commits into from
Mar 6, 2024

Conversation

Szegoo
Copy link
Contributor

@Szegoo Szegoo commented Feb 18, 2024

Closes: #3196

@Szegoo Szegoo requested a review from athei as a code owner February 18, 2024 16:28
Copy link
Member

@athei athei left a comment

Choose a reason for hiding this comment

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

This PR does not check the InstantiateOrigin when a contract instantiates another contract. Is this intended? No matter what the answer this has to be documented on the Config knob.

@Szegoo
Copy link
Contributor Author

Szegoo commented Feb 26, 2024

This PR does not check the InstantiateOrigin when a contract instantiates another contract. Is this intended?

Yes, this was intended, as I think it should probably be up to the contract logic to regulate other contract instantiation.

substrate/frame/contracts/src/lib.rs Show resolved Hide resolved
substrate/frame/contracts/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@athei athei left a comment

Choose a reason for hiding this comment

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

Tests are insufficient. The instantiation extrinsics are not tested. You also need to define a special implementation for EnsureOrigin where you can change what it does dynamically. Have a look how we do that with parameter_types! for our TestExtension. This will allow you to change what it does for your tests while leave it as-is for the existing tests.

Szegoo and others added 3 commits March 1, 2024 10:31
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
@Szegoo
Copy link
Contributor Author

Szegoo commented Mar 1, 2024

The instantiation extrinsics are not tested.

It was actually tested, the instantiation origin was configured to allow any signed origin to deploy, and there was already a root_cannot_instantiate test.

Based on your suggestion, I added more tests by dynamically restricting upload and instantiation, so it is better tested now.

@athei athei added the T7-smart_contracts This PR/Issue is related to smart contracts. label Mar 2, 2024
substrate/frame/contracts/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/contracts/src/tests.rs Outdated Show resolved Hide resolved
@athei athei requested a review from pgherveou March 2, 2024 05:28
Szegoo and others added 3 commits March 2, 2024 07:56
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
@pgherveou
Copy link
Contributor

@Szegoo seeing your PR a bit late commented here
#3196 (comment)

Haven't look at the code here yet, but from the description it seems that this is something that can be done already. Can you double check and tell me what you think

@Szegoo
Copy link
Contributor Author

Szegoo commented Mar 4, 2024

This is more configurable. dispatch_as requires the origin to be root, while here the upload and instantiate origin could be set to anything(e.g. a collective).

substrate/frame/contracts/src/tests.rs Outdated Show resolved Hide resolved
Szegoo and others added 2 commits March 4, 2024 19:43
Co-authored-by: PG Herveou <pgherveou@parity.io>
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: cargo-clippy
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5431858

Copy link
Member

@athei athei left a comment

Choose a reason for hiding this comment

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

dispatch_as requires the origin to be root, while here the upload and instantiate origin could be set to anything(e.g. a collective).

Are you sure this is true? You should be able to check the origin in the filter. Zeitgeist is not doing this but you could do that, right?

@Szegoo
Copy link
Contributor Author

Szegoo commented Mar 5, 2024

Are you sure this is true?

I was referring to:

ensure_root(origin)?;

Not so sure about checking the origin in the filter though. I will look into that.

@athei
Copy link
Member

athei commented Mar 5, 2024

Yes this is understood. Probably should have quoted this:

This is more configurable.

Because you don't need to use dispatch_as as Zeitgeist does I think. You should be able to check the origin in the filter.

@pgherveou
Copy link
Contributor

dispatch_as requires the origin to be root, while here the upload and instantiate origin could be set to anything(e.g. a collective).

Are you sure this is true? You should be able to check the origin in the filter. Zeitgeist is not doing this but you could do that, right?

I don't think you can the filter only give you access to the RuntimeCall

@pgherveou
Copy link
Contributor

pgherveou commented Mar 5, 2024

/// The basic call filter to use in Origin. All origins are built with this filter as base,
/// except Root.
///
/// This works as a filter for each incoming call. The call needs to pass this filter in
/// order to dispatch. Otherwise it will be rejected with `CallFiltered`. This can be
/// bypassed via `dispatch_bypass_filter` which should only be accessible by root. The
/// filter can be composed of sub-filters by nesting for example
/// [`frame_support::traits::InsideBoth`], [`frame_support::traits::TheseExcept`] or
/// [`frame_support::traits::EverythingBut`] et al. The default would be
/// [`frame_support::traits::Everything`].
#[pallet::no_default_bounds]
type BaseCallFilter: Contains<Self::RuntimeCall>;

This is used by the construct_runtime here

fn filter_call(&self, call: &Self::Call) -> bool {
match self.caller {
// Root bypasses all filters
OriginCaller::system(#system_path::Origin::<#runtime>::Root) => true,
_ => (self.filter)(call),
}
}

Copy link
Member

@athei athei left a comment

Choose a reason for hiding this comment

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

Yes you are right. The filter does not allow access to the origin.

@athei athei added this pull request to the merge queue Mar 6, 2024
Merged via the queue into paritytech:master with commit 8f8297e Mar 6, 2024
130 of 131 checks passed
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
Closes: paritytech#3196

---------

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: PG Herveou <pgherveou@parity.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T7-smart_contracts This PR/Issue is related to smart contracts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deploy origin for pallet-contracts
4 participants