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(applying): certificate and native script validation for ShelleyMA #510

Merged
merged 8 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 47 additions & 9 deletions pallas-applying/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,78 @@ pub mod utils;
use alonzo::validate_alonzo_tx;
use babbage::validate_babbage_tx;
use byron::validate_byron_tx;
use pallas_primitives::alonzo::TransactionIndex;
use pallas_traverse::{Era, MultiEraTx};
use shelley_ma::validate_shelley_ma_tx;

pub use utils::{
Environment, MultiEraProtocolParameters, UTxOs,
ValidationError::{TxAndProtParamsDiffer, UnknownProtParams},
CertState, Environment, MultiEraProtocolParameters, UTxOs,
ValidationError::{
EnvMissingAccountState, PParamsByronDoesntNeedAccountState, TxAndProtParamsDiffer,
UnknownProtParams,
},
ValidationResult,
};

pub fn validate(metx: &MultiEraTx, utxos: &UTxOs, env: &Environment) -> ValidationResult {
match env.prot_params() {
MultiEraProtocolParameters::Byron(bpp) => match metx {
/// Ledger sequence rule: LEDGERS
pub fn validate_txs(
metxs: &[MultiEraTx],
env: &Environment,
utxos: &UTxOs,
cert_state: &mut CertState,
) -> ValidationResult {
let mut delta_state: CertState = cert_state.clone();
for (txix, metx) in metxs.iter().enumerate() {
validate_tx(
&metx,
txix.try_into().unwrap(),
env,
utxos,
&mut delta_state,
)?;
}
*cert_state = delta_state;
Ok(())
}

/// Ledger inference rule: LEDGER
pub fn validate_tx(
metx: &MultiEraTx,
txix: TransactionIndex,
env: &Environment,
utxos: &UTxOs,
cert_state: &mut CertState,
) -> ValidationResult {
let pp_acnt = (env.prot_params(), env.acnt());
match pp_acnt {
(MultiEraProtocolParameters::Byron(bpp), None) => match metx {
MultiEraTx::Byron(mtxp) => validate_byron_tx(mtxp, utxos, bpp, env.prot_magic()),
_ => Err(TxAndProtParamsDiffer),
},
MultiEraProtocolParameters::Shelley(spp) => match metx {
(MultiEraProtocolParameters::Byron(_), Some(_)) => Err(PParamsByronDoesntNeedAccountState),
(MultiEraProtocolParameters::Shelley(spp), Some(acnt)) => match metx {
MultiEraTx::AlonzoCompatible(mtx, Era::Shelley)
| MultiEraTx::AlonzoCompatible(mtx, Era::Allegra)
| MultiEraTx::AlonzoCompatible(mtx, Era::Mary) => validate_shelley_ma_tx(
mtx,
txix,
utxos,
cert_state,
spp,
&acnt,
env.block_slot(),
env.network_id(),
&metx.era(),
),
_ => Err(TxAndProtParamsDiffer),
},
MultiEraProtocolParameters::Alonzo(app) => match metx {
(MultiEraProtocolParameters::Alonzo(app), _) => match metx {
MultiEraTx::AlonzoCompatible(mtx, Era::Alonzo) => {
validate_alonzo_tx(mtx, utxos, app, env.block_slot(), env.network_id())
}
_ => Err(TxAndProtParamsDiffer),
},
MultiEraProtocolParameters::Babbage(bpp) => match metx {
(MultiEraProtocolParameters::Babbage(bpp), _) => match metx {
MultiEraTx::Babbage(mtx) => validate_babbage_tx(
mtx,
utxos,
Expand All @@ -54,8 +91,9 @@ pub fn validate(metx: &MultiEraTx, utxos: &UTxOs, env: &Environment) -> Validati
),
_ => Err(TxAndProtParamsDiffer),
},
MultiEraProtocolParameters::Conway(_) => {
(MultiEraProtocolParameters::Conway(_), _) => {
todo!("conway phase-1 validation not yet implemented");
}
(_, None) => Err(EnvMissingAccountState),
}
}
Loading