1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
// RGB Core Library: a reference implementation of RGB smart contract standards.
// Written in 2019-2022 by
// Dr. Maxim Orlovsky <orlovsky@lnp-bp.org>
//
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
//
// You should have received a copy of the MIT License along with this software.
// If not, see <https://opensource.org/licenses/MIT>.
#![allow(clippy::unnecessary_cast)]
//! Components related to the scripting system used by schema or applied at the
//! specific contract node level
use commit_verify::commit_encode;
use crate::vm::alure;
/// Virtual machine types.
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[display(Debug)]
pub enum VmType {
/// Embedded code (not a virtual machine) which is the part of this RGB
/// Core Library.
Embedded,
/// AluVM: pure functional register-based virtual machine designed for RGB
/// and multiparty computing.
AluVM,
}
/// Virtual machine and machine-specific script data.
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))]
#[derive(StrictEncode, StrictDecode)]
#[strict_encoding(by_value, repr = u8)]
pub enum ValidationScript {
/// Embedded code (not a virtual machine) which is the part of this RGB
/// Core Library. Using this option results in the fact that the schema
/// does not commit to the actual validating code and the validation logic
/// may change in the future (like to be patched) with new RGB Core Lib
/// releases.
#[strict_encoding(value = 0x00)]
Embedded,
/// AluVM: pure functional register-based virtual machine designed for RGB
/// and multiparty computing.
///
/// The inner data contains actual executable code in form of complete set
/// of AliVM libraries, which must be holistic and not dependent on any
/// external libraries (i.e. must contain all libraries embedded).
///
/// Its routines can be accessed only through well-typed ABI entrance
/// pointers, defined as a part of the schema.
#[strict_encoding(value = 0x01)]
AluVM(alure::ValidationScript),
}
impl Default for ValidationScript {
// TODO: Update default VM type to AluVM in RGBv1 release
fn default() -> Self { ValidationScript::Embedded }
}
impl commit_encode::Strategy for ValidationScript {
type Strategy = commit_encode::strategies::UsingStrict;
}
impl ValidationScript {
pub fn vm_type(&self) -> VmType {
match self {
ValidationScript::Embedded => VmType::Embedded,
ValidationScript::AluVM(_) => VmType::AluVM,
}
}
}
/// VM and script overwrite rules by subschemata.
///
/// Defines whether subschemata are allowed to replace (overwrite) the type of
/// VM and scripts.
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "kebab-case")
)]
#[derive(StrictEncode, StrictDecode)]
#[repr(u8)]
pub enum OverrideRules {
#[display("deny")]
/// Denies overwrites
Deny = 0u8,
#[display("allow-same-vm")]
/// Allows overwrite only if the same VM is used
AllowSameVm = 1u8,
#[display("allow-any-vm")]
/// Allows overwrite of both executable code and type of VM
AllowAnyVm = 2u8,
}
impl Default for OverrideRules {
fn default() -> Self { OverrideRules::Deny }
}