Skip to content

Commit

Permalink
validation: validate genesis asset tags
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Apr 9, 2024
1 parent 41c925d commit e0bf5b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
31 changes: 16 additions & 15 deletions src/validation/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ use amplify::Wrapper;
use strict_types::SemId;

use crate::schema::{AssignmentsSchema, GlobalSchema, ValencySchema};
use crate::validation::{CheckedConsignment, ConsignmentApi, VirtualMachine};
use crate::validation::{CheckedConsignment, ConsignmentApi, Failure, VirtualMachine};
use crate::{
validation, AssetTag, AssignmentType, Assignments, AssignmentsRef, ContractId, ExposedSeal,
GlobalState, GlobalStateSchema, GlobalValues, GraphSeal, Inputs, OpFullType, OpId, OpRef,
Operation, Opout, Schema, TransitionType, TypedAssigns, Valencies,
Operation, Opout, Schema, StateSchema, TransitionType, TypedAssigns, Valencies,
};

impl Schema {
Expand All @@ -42,6 +42,7 @@ impl Schema {
vm: &'consignment dyn VirtualMachine,
) -> validation::Status {
let id = op.id();
let mut status = validation::Status::new();

let empty_assign_schema = AssignmentsSchema::default();
let empty_valency_schema = ValencySchema::default();
Expand All @@ -53,16 +54,18 @@ impl Schema {
redeem_schema,
assign_schema,
valency_schema,
) = match (op.transition_type(), op.extension_type()) {
(None, None) => {
// Right now we do not have actions to implement; but later
// we may have embedded procedures which must be verified
// here
/*
if let Some(procedure) = self.genesis.abi.get(&GenesisAction::NoOp) {
) = match (op, op.transition_type(), op.extension_type()) {
(OpRef::Genesis(genesis), None, None) => {
for id in genesis.asset_tags.keys() {
if !matches!(self.owned_types.get(id), Some(StateSchema::Fungible(_))) {
status.add_failure(Failure::AssetTagNoState(*id));
}
}
for id in self.owned_types.keys() {
if !genesis.asset_tags.contains_key(id) {
status.add_failure(Failure::FungibleStateNoTag(*id));
}
}
*/

(
&self.genesis.metadata,
Expand All @@ -73,7 +76,7 @@ impl Schema {
&self.genesis.valencies,
)
}
(Some(transition_type), None) => {
(OpRef::Transition(_), Some(transition_type), None) => {
// Right now we do not have actions to implement; but later
// we may have embedded procedures which must be verified
// here
Expand Down Expand Up @@ -102,7 +105,7 @@ impl Schema {
&transition_schema.valencies,
)
}
(None, Some(extension_type)) => {
(OpRef::Extension(_), None, Some(extension_type)) => {
// Right now we do not have actions to implement; but later
// we may have embedded procedures which must be verified
// here
Expand Down Expand Up @@ -133,8 +136,6 @@ impl Schema {
_ => unreachable!("Node can't be extension and state transition at the same time"),
};

let mut status = validation::Status::new();

// Validate type system
status += self.validate_type_system();
status += self.validate_metadata(id, *metadata_schema, op.metadata());
Expand Down
11 changes: 9 additions & 2 deletions src/validation/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use strict_types::SemId;
use crate::contract::Opout;
use crate::schema::{self, SchemaId};
use crate::{
BundleId, ContractId, Layer1, OccurrencesMismatch, OpFullType, OpId, SecretSeal, StateType,
Vin, XChain, XGraphSeal, XWitnessId,
AssignmentType, BundleId, ContractId, Layer1, OccurrencesMismatch, OpFullType, OpId,
SecretSeal, StateType, Vin, XChain, XGraphSeal, XWitnessId,
};

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Display)]
Expand Down Expand Up @@ -282,6 +282,13 @@ pub enum Failure {
/// which is an input of the state transition {3}.
BundleInvalidCommitment(BundleId, Vin, XWitnessId, OpId),

// Errors checking asset tags
/// asset type provided in genesis references unknown fungible state of type
/// {0}.
AssetTagNoState(AssignmentType),
/// fungible state {0} has no asset tag defined.
FungibleStateNoTag(AssignmentType),

// Errors checking seal closing
/// transition {opid} references state type {state_type} absent in the
/// outputs of previous state transition {prev_id}.
Expand Down

0 comments on commit e0bf5b0

Please sign in to comment.