feat(applying): implement Alonzo phase-1 validations (#380)

This commit is contained in:
Maico Leberle 2024-01-19 22:19:46 -03:00 committed by GitHub
parent 0b1e5f0231
commit da3e636759
33 changed files with 4900 additions and 704 deletions

View file

@ -0,0 +1,70 @@
//! Types used for representing the environment required for validation in each
//! era.
#[derive(Debug)]
pub struct Environment {
pub prot_params: MultiEraProtParams,
pub prot_magic: u32,
pub block_slot: u64,
pub network_id: u8,
}
// TODO: add variants for the other eras.
#[derive(Debug)]
#[non_exhaustive]
pub enum MultiEraProtParams {
Byron(ByronProtParams),
Shelley(ShelleyProtParams),
Alonzo(AlonzoProtParams),
}
#[derive(Debug, Clone)]
pub struct ByronProtParams {
pub fee_policy: FeePolicy,
pub max_tx_size: u64,
}
#[derive(Debug, Clone)]
pub struct ShelleyProtParams {
pub fee_policy: FeePolicy,
pub max_tx_size: u64,
pub min_lovelace: u64,
}
#[derive(Debug, Clone)]
pub struct FeePolicy {
pub summand: u64,
pub multiplier: u64,
}
#[derive(Debug, Clone)]
pub struct AlonzoProtParams {
pub fee_policy: FeePolicy,
pub max_tx_size: u64,
pub max_block_ex_mem: u64,
pub max_block_ex_steps: u64,
pub max_tx_ex_mem: u32,
pub max_tx_ex_steps: u64,
pub max_val_size: u64,
pub collateral_percent: u64,
pub max_collateral_inputs: u64,
pub coins_per_utxo_word: u64,
}
impl Environment {
pub fn prot_params(&self) -> &MultiEraProtParams {
&self.prot_params
}
pub fn prot_magic(&self) -> &u32 {
&self.prot_magic
}
pub fn block_slot(&self) -> &u64 {
&self.block_slot
}
pub fn network_id(&self) -> &u8 {
&self.network_id
}
}

View file

@ -0,0 +1,94 @@
//! Types for validating transactions in each era.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum ValidationError {
TxAndProtParamsDiffer,
Byron(ByronError),
ShelleyMA(ShelleyMAError),
Alonzo(AlonzoError),
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum ByronError {
TxInsEmpty,
TxOutsEmpty,
InputNotInUTxO,
OutputWithoutLovelace,
UnknownTxSize,
UnableToComputeFees,
FeesBelowMin,
MaxTxSizeExceeded,
UnableToProcessWitness,
MissingWitness,
WrongSignature,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum ShelleyMAError {
TxInsEmpty,
InputNotInUTxO,
TTLExceeded,
AlonzoCompNotShelley,
UnknownTxSize,
MaxTxSizeExceeded,
ValueNotShelley,
MinLovelaceUnreached,
PreservationOfValue,
NegativeValue,
FeesBelowMin,
WrongEraOutput,
AddressDecoding,
WrongNetworkID,
MetadataHash,
MissingVKWitness,
MissingScriptWitness,
WrongSignature,
MintingLacksPolicy,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum AlonzoError {
UnknownTxSize,
TxInsEmpty,
InputNotInUTxO,
CollateralNotInUTxO,
BlockExceedsValInt,
BlockPrecedesValInt,
ValIntUpperBoundMissing,
FeeBelowMin,
CollateralMissing,
TooManyCollaterals,
CollateralNotVKeyLocked,
AddressDecoding,
CollateralMinLovelace,
NonLovelaceCollateral,
NegativeValue,
PreservationOfValue,
MinLovelaceUnreached,
MaxValSizeExceeded,
OutputWrongNetworkID,
TxWrongNetworkID,
RedeemerMissing,
TxExUnitsExceeded,
MaxTxSizeExceeded,
VKWitnessMissing,
VKWrongSignature,
ReqSignerMissing,
ReqSignerWrongSig,
ScriptWitnessMissing,
MintingLacksPolicy,
InputDecoding,
UnneededNativeScript,
UnneededPlutusScript,
UnneededRedeemer,
DatumMissing,
UnneededDatum,
MetadataHash,
ScriptIntegrityHash,
}
pub type ValidationResult = Result<(), ValidationError>;