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

pallet-revive: Statically verify imports on code deployment #6759

Merged
merged 12 commits into from
Dec 11, 2024

Conversation

athei
Copy link
Member

@athei athei commented Dec 4, 2024

Previously, we failed at runtime if an unknown or unstable host function was called. This requires us to keep track of when a host function was added and when a code was deployed. We used the api_version to track at which API version each code was deployed. This made sure that when a new host function was added that old code won't have access to it. This is necessary as otherwise the behavior of a contract that made calls to this previously non existent host function would change from "trap" to "do something".

In this PR we remove the API version. Instead, we statically verify on upload that no non-existent host function is ever used in the code. This will allow us to add new host function later without needing to keep track when they were added.

This simplifies the code and also gives an immediate feedback if unknown host functions are used.

@athei athei added the R0-silent Changes should not be mentioned in any release notes label Dec 4, 2024
@athei
Copy link
Member Author

athei commented Dec 4, 2024

/cmd prdoc --audience runtime_dev

Comment on lines -90 to +94
/// The API version that this contract operates under.
///
/// This determines which host functions are available to the contract. This
/// prevents that new host functions become available to already deployed contracts.
api_version: u16,
/// The behaviour version that this contract operates under.
///
/// Whenever any observeable change (with the exception of weights) are made we need
/// to make sure that already deployed contracts will not be affected. We do this by
/// exposing the old behaviour depending on the set behaviour version of the contract.
///
/// As of right now this is a reserved field that is always set to 0.
behaviour_version: u16,
behaviour_version: u32,
Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't need migration. Everything was set to zero and we just widen behavior_version to cover both fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

65k was not enough ? 🙃

Copy link
Member Author

Choose a reason for hiding this comment

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

We would need a migration if keeping it u16. By widening it the encoded format of the structure stays the same.

@athei athei requested review from xermicus and pgherveou and removed request for xermicus December 7, 2024 09:37
Comment on lines +22 to +25
#[polkavm_derive::polkavm_import]
extern "C" {
pub fn set_code_hash();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we make a dedicated unstable api just for test so that this does not fail when this becomes stable

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that is a good idea. But we will cross the bridge once we get there.

Comment on lines -90 to +94
/// The API version that this contract operates under.
///
/// This determines which host functions are available to the contract. This
/// prevents that new host functions become available to already deployed contracts.
api_version: u16,
/// The behaviour version that this contract operates under.
///
/// Whenever any observeable change (with the exception of weights) are made we need
/// to make sure that already deployed contracts will not be affected. We do this by
/// exposing the old behaviour depending on the set behaviour version of the contract.
///
/// As of right now this is a reserved field that is always set to 0.
behaviour_version: u16,
behaviour_version: u32,
Copy link
Contributor

Choose a reason for hiding this comment

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

65k was not enough ? 🙃

@athei athei enabled auto-merge December 11, 2024 11:48
@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/12277480916
Failed job name: run-frame-omni-bencher

@athei athei added this pull request to the merge queue Dec 11, 2024
Merged via the queue into master with commit f0b5c3e Dec 11, 2024
196 of 199 checks passed
@athei athei deleted the at/static-verify branch December 11, 2024 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants