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

Feat/explicit-contract-version #3192

Merged
merged 51 commits into from
Aug 1, 2022
Merged

Feat/explicit-contract-version #3192

merged 51 commits into from
Aug 1, 2022

Conversation

jcnelson
Copy link
Member

@jcnelson jcnelson commented Jul 7, 2022

This addresses #3131 and #2719, as well as #2609. It introduces a SmartContract payload variant that takes an explicit Clarity version, so that post-2.1 developers can require that the contract adhere to Clarity 1 or Clarity 2 rules. If they do not do so, then the epoch default Clarity version is used (which will be Clarity 2 in 2.1).

The PR removes most uses of ClarityVersion::default_for_epoch() and replaces them with a transaction-supplied Clarity version. When a transaction is processed, a new method StacksChainState::get_tx_clarity_version() is called to deduce which version of Clarity to supply the Clarity VM. The rules are as follows:

  • If the transaction is a smart contract transaction, and a version is explicitly given, then use that.
  • If the transaction is a smart contract transaction, and a version is not given, then use the epoch default.
  • If the transaction is a contract-call transaction, then load up the target contract and use its version.
  • In all other cases, use the epoch default.

This PR tests #2719 by addressing #3131. It introduces a "torture test" for cross-contract and cross-Clarity-version contract calls in chainstate::stacks::tests::block_construction::test_contract_call_across_clarity_versions. It verifies the following:

  • The method invoked by a contract call transaction runs with the Clarity version that the contract that defined it used. So for example, a Clarity1 contract can call a Clarity2 contract function, and that Clarity2 function can do Clarity2-specific things.

  • The method invoked by an explicit contract-call? follows the above rule as well.

  • A trait defined in Clarity1 can be implemented by a Clarity2 contract.

  • A trait defined in Clarity2 can be implemented by a Clarity1 contract.

  • Dynamic dispatches to traits will run with the Clarity version of the trait implementation. So for example, if a Clarity1 contract calls into a trait that, regardless of the trait definition's Clarity version, has a Clarity2 implementation, then the dispatch will run in Clarity2.

  • The closure of an (at-block) will run with the Clarity version in which it is defined, like any other code statement. Similarly, contract-calls within the at-block will run in the target method's contract's Clarity version.

The PR addresses #2609 by ensuring that a block will not be processed if it contains 2.1-only transactions, such as pay-to-alt-principal coinbases and explicit-version smart contracts. This gating logic not only applies in block validation (which covers both the blockchain-processing and miner), but also in mempool acceptance.

jcnelson added 26 commits July 6, 2022 14:44
…ion, and use that version (not the epoch) when starting transactions
… version of clarity to use (i.e. don't use the epoch anymore)
… majority of lines changed in this particular commit)
…act or calls an existing one, deduce which version of Clarity to use. For smart contracts, use the one indicated in the transaction payload if given, or use the epoch-defined default if not. For contract-calls, load up the target contract's clarity version.
…sion, which represents a new transaction type in which an explicit version can be given
…ls can call into contracts with different versions, and everything will work out
… so we know what parsing, analysis, and runtime rules to apply
…nal test coverage to ensure that new 2.1 transaction variants cannot occur in blocks until after 2.1
…of different clarity versions, and with trait definitions and implementations in different clarity versions
@jcnelson jcnelson requested a review from kantai July 22, 2022 01:38
Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

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

LGTM

@blockstack-devops
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@stacks-network stacks-network locked as resolved and limited conversation to collaborators Nov 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants