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 extrinsic weight and lenght check #637

Merged
merged 13 commits into from
May 12, 2022

Conversation

boundless-forest
Copy link
Collaborator

@boundless-forest boundless-forest commented Apr 15, 2022

As call.validate_self_contained(info) does not contain any extrinsic length and weight checks, the transaction's max_gas_limit is not restricted and can be higher than the block gas limit. Add this check to the fp-self-contained scope together with Signed and Unsigned.

@boundless-forest
Copy link
Collaborator Author

@sorpaas Please take a reivew?

@boundless-forest boundless-forest marked this pull request as ready for review April 27, 2022 08:47
@boundless-forest
Copy link
Collaborator Author

@tgmichel @koushiro Any feedback about this?

@tgmichel
Copy link
Contributor

tgmichel commented May 10, 2022

Thank you for taking a look at this. I've been thinking about this change and here is why I don't think is necessary - at least not like this.

  • SelfContained call performs it's own validation on the nonce, signature, sets the frame priority based on the priority fee etc So most of the Extra validation is already taken care of on the custom pallet-ethereum validation.
  • The weight is checked with the pallet-ethereum::transact dispatchable weight hint.

Now, for the extrinsic length check. As far as I understand your proposal, CheckWeights::check_block_length will ExhaustResources if the extrinsic being validated exceeds the available block length on submission. I don't think we want that when submiting transactions, as users might send future transactions and even if it's not a future and users expect it to be included in the ready queue, it could perfectly fit in the next block, so rejecting on submission I don't think is expected behaviour.

However, we want to reject extrinsics which's lenght is greater than the block length upper bound. @sorpaas in our SelfContained validation we are not currently checking that (imagine a user sending a tx with huge input that exceeds the block length upper bound and that he could afford to eventually pay but is set as a future nonce), do you know if that is part of the transaction validity checks somewhere in sc-transaction-pool? I couldn't find it.

Copy link
Member

@sorpaas sorpaas left a comment

Choose a reason for hiding this comment

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

Substrate's extensions do not have support for extending custom validations, so I think the approach in this PR is the simplest way to fix the problem.

We should probably add a note in the docs that while self-contained does not behave exactly like unsigned, it does call unsigned validation functions.

Copy link
Member

@sorpaas sorpaas left a comment

Choose a reason for hiding this comment

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

I read the rest of the self-contained logic and I think this will add too much confusion. I'd prefer if we just duplicate some code, which in this case will actually be cleaner.

Please instead add the weight checking directly to validate_self_contained. All code needed can be copied from the CheckWeight struct's do_validate function.

@boundless-forest
Copy link
Collaborator Author

boundless-forest commented May 11, 2022

I read the rest of the self-contained logic and I think this will add too much confusion. I'd prefer if we just duplicate some code, which in this case will actually be cleaner.

Make sense. It seems a bit weird to add unsigned transaction logic under SelfContained validation. It must be noted if used in this way.

Please instead add the weight checking directly to validate_self_contained. All code needed can be copied from the CheckWeight struct's do_validate function.

Do you mean something like this? We might add another runtime parameter to the CheckedExtrinsic structure, such as CheckedExtrinsic<AccountId, Call, Extra, SelfContainedSignedInfo, Runtime>. Is that expected, or can we achieve this in another way?

CheckedSignature::SelfContained(signed_info) => {
    // let unsigned_validation = Extra::validate_unsigned(&self.function, info, len)?;
    let weight_validation = CheckWeight::<Runtime>::do_validate(info, len)?;

    let self_contained_validation =
        self.function.validate_self_contained(&signed_info).ok_or(
            TransactionValidityError::Invalid(InvalidTransaction::BadProof),
        )??;
    Ok(weight_validation.combine_with(self_contained_validation))
}

@sorpaas
Copy link
Member

sorpaas commented May 11, 2022

I was thinking about putting it here: https://github.com/paritytech/frontier/blob/master/frame/ethereum/src/lib.rs#L151

You may want to add it to pre_dispatch_self_contained as well.

@boundless-forest boundless-forest marked this pull request as draft May 11, 2022 03:26
@boundless-forest boundless-forest marked this pull request as ready for review May 11, 2022 05:27
@boundless-forest
Copy link
Collaborator Author

@sorpaas Please take a review again.

frame/ethereum/src/lib.rs Outdated Show resolved Hide resolved
@boundless-forest boundless-forest marked this pull request as draft May 11, 2022 09:21
@boundless-forest boundless-forest marked this pull request as ready for review May 11, 2022 12:05
@sorpaas sorpaas merged commit 1490c01 into polkadot-evm:master May 12, 2022
@boundless-forest boundless-forest deleted the bear-add-weight-check branch May 12, 2022 01:15
intendednull pushed a commit to humanode-network/frontier that referenced this pull request Jun 21, 2022
abhijeetbhagat pushed a commit to web3labs/frontier that referenced this pull request Jan 11, 2023
* Try fix

* Format code

* Add tests

* Update evm BlockGasLimit

* Format

* Fix ts tests

* Add weight check to ethereum

* Format

* Handle review issue and fix unit tests

* Fix clippy

* Make CI Happy
icodezjb pushed a commit to chainx-org/frontier that referenced this pull request Dec 27, 2023
(1) Add extrinsic weight and lenght check (polkadot-evm#637)
(2) fix(frame): CheckWeight controls should be applied on pre_dispatch (polkadot-evm#749)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants