-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revive: Bump PolkaVM and add static code validation (#5939)
This PR adds **static** validation that prevents upload of code that: 1) Contains basic blocks larger than the specified limit (currently `200`) 2) Contains invalid instructions 3) Uses the `sbrk` instruction Doing that statically at upload time (instead of at runtime) allows us to change the basic block limit or add instructions later without worrying about breaking old code. This is well worth the linear scan of the whole blob on deployment in my opinion. Please note that those checks are not applied when existing code is just run (hot path). Also some drive by fixes: - Remove superflous `publish = true` - Abort fixture build on warning and fix existing warnings - Re-enable optimizations in fixture builds (should be fixed now in PolkaVM) - Disable stripping for fixture builds (maybe we can get some line information on trap via `RUST_LOG`) --------- Co-authored-by: command-bot <> Co-authored-by: PG Herveou <[email protected]>
- Loading branch information
Showing
16 changed files
with
664 additions
and
474 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
title: "[pallet-revive] Bump PolkaVM and add static code validation" | ||
|
||
doc: | ||
- audience: Runtime Dev | ||
description: | | ||
Statically validate basic block sizes and instructions. | ||
|
||
crates: | ||
- name: pallet-revive | ||
bump: major | ||
- name: pallet-revive-fixtures | ||
bump: minor | ||
- name: pallet-revive-uapi | ||
bump: patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! Create a basic block that is larger than we allow. | ||
#![no_std] | ||
#![no_main] | ||
|
||
extern crate common; | ||
|
||
use core::arch::asm; | ||
|
||
// Export that is never called. We can put code here that should be in the binary | ||
// but is never supposed to be run. | ||
#[no_mangle] | ||
#[polkavm_derive::polkavm_export] | ||
pub extern "C" fn call_never() { | ||
// Stores cannot be optimized away because the optimizer cannot | ||
// know whether they have side effects. | ||
let value: u32 = 42; | ||
unsafe { | ||
// Repeat 1001 times to intentionally exceed the allowed basic block limit (1000) | ||
asm!(".rept 1001", "sw {x}, 0(sp)", ".endr", x = in(reg) value); | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
#[polkavm_derive::polkavm_export] | ||
pub extern "C" fn deploy() {} | ||
|
||
#[no_mangle] | ||
#[polkavm_derive::polkavm_export] | ||
pub extern "C" fn call() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.