4

I would like to better understand what the parachain validation function is and how it is used throughout Polkadot.

In The Polkadot Parachain Host Implementers' Guide, it says that the parachain validation function (PVF) is:

The validation code that is run by validators on parachains or parathreads.

1 Answer 1

6

Parachain Validation Function (PVF)

/// A struct that carries code of a parachain validation function and its hash.
///
/// Should be cheap to clone.
#[derive(Clone)]
pub struct Pvf {
    pub(crate) code: Arc<Vec<u8>>,
    pub(crate) code_hash: ValidationCodeHash,
}

Remember that a parachain runtime is essentially a state-transition function.

The parachain validation function or PVF for short, is the current runtime Wasm for a parachain that is stored on the Relay chain.

One example of where the parachain validation function (PVF) is used is in the Relay chain module: paras. This module tracks the state of parachains as mentioned at the top of its file:

//! The most important responsibility of this module is to track which parachains
//! are active and what their current state is. The current state of a para consists of the current
//! head data and the current validation code (AKA Parachain Validation Function (PVF)).

The parachain validation function (PVF) code is hashed and stored in the paras module:

/// The validation code hash of every live para.
///
/// Corresponding code can be retrieved with [`CodeByHash`].
#[pallet::storage]
#[pallet::getter(fn current_code_hash)]
pub(super) type CurrentCodeHash<T: Config> =
    StorageMap<_, Twox64Concat, ParaId, ValidationCodeHash>;

When successfully upgrading a parachain, the parachain's validation code (or parachain validation function) would change and therefore the CurrentCodeHash storage would reflect that by having a different ValidationCodeHash.

Another example of where the parachain validation function (PVF) is used is in candidate validation.

When the parachain produces a new block, it sends a "Proof of Validity" (PoV) block to the Relay chain. This PoV-block or PoV is a parachain block with witness data. You can read more on this here. The Relay chain uses this PoV block along with the parachain validation function (PVF) and does a series of checks (one example) including executing the PVF (Wasm) against the PoV. This is what is considered as candidate validation - we are checking to see if this parachain block is a successful candidate to be a block for that parachain. Much of this logic can be found in the Candidate Validation subsystem as noted in the top of its file:

//! This handles incoming requests from other subsystems to validate candidates
//! according to a validation function. This delegates validation to an underlying
//! pool of processes used for execution of the Wasm.

If these checks come out successful then this PoV block is deemed a worthy candidate and is ready for candidate backing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.