From 2308c1700cd91a54e2ea096e0890d2ad23c6f702 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sun, 11 Feb 2024 11:01:15 +0100 Subject: [PATCH] contract: rename StateData and StateCommitment types remove their strict encoding --- src/contract/attachment.rs | 6 ++-- src/contract/data.rs | 10 +++--- src/contract/fungible.rs | 6 ++-- src/contract/mod.rs | 2 +- src/contract/state.rs | 65 +++++++++++--------------------------- src/stl.rs | 2 +- src/validation/state.rs | 22 ++++++------- 7 files changed, 42 insertions(+), 71 deletions(-) diff --git a/src/contract/attachment.rs b/src/contract/attachment.rs index b34eb1d5..69867714 100644 --- a/src/contract/attachment.rs +++ b/src/contract/attachment.rs @@ -29,7 +29,7 @@ use commit_verify::{CommitVerify, Conceal, StrictEncodedProtocol}; use strict_encoding::StrictEncode; use super::{ConfidentialState, ExposedState}; -use crate::{MediaType, StateCommitment, StateData, StateType, LIB_NAME_RGB}; +use crate::{ConcealedState, MediaType, RevealedState, StateType, LIB_NAME_RGB}; /// Unique data attachment identifier #[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display, From)] @@ -110,7 +110,7 @@ impl RevealedAttach { impl ExposedState for RevealedAttach { type Confidential = ConcealedAttach; fn state_type(&self) -> StateType { StateType::Attachment } - fn state_data(&self) -> StateData { StateData::Attachment(self.clone()) } + fn state_data(&self) -> RevealedState { RevealedState::Attachment(self.clone()) } } impl Conceal for RevealedAttach { @@ -139,7 +139,7 @@ pub struct ConcealedAttach( impl ConfidentialState for ConcealedAttach { fn state_type(&self) -> StateType { StateType::Attachment } - fn state_commitment(&self) -> StateCommitment { StateCommitment::Attachment(*self) } + fn state_commitment(&self) -> ConcealedState { ConcealedState::Attachment(*self) } } impl CommitVerify for ConcealedAttach { diff --git a/src/contract/data.rs b/src/contract/data.rs index ed93def2..278f8ec3 100644 --- a/src/contract/data.rs +++ b/src/contract/data.rs @@ -31,7 +31,7 @@ use commit_verify::{CommitVerify, Conceal, StrictEncodedProtocol}; use strict_encoding::{StrictSerialize, StrictType}; use super::{ConfidentialState, ExposedState}; -use crate::{StateCommitment, StateData, StateType, LIB_NAME_RGB}; +use crate::{ConcealedState, RevealedState, StateType, LIB_NAME_RGB}; /// Struct using for storing Void (i.e. absent) state #[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq, Hash, Display, Default)] @@ -43,13 +43,13 @@ pub struct VoidState(()); impl ConfidentialState for VoidState { fn state_type(&self) -> StateType { StateType::Void } - fn state_commitment(&self) -> StateCommitment { StateCommitment::Void } + fn state_commitment(&self) -> ConcealedState { ConcealedState::Void } } impl ExposedState for VoidState { type Confidential = VoidState; fn state_type(&self) -> StateType { StateType::Void } - fn state_data(&self) -> StateData { StateData::Void } + fn state_data(&self) -> RevealedState { RevealedState::Void } } impl Conceal for VoidState { @@ -102,7 +102,7 @@ impl RevealedData { impl ExposedState for RevealedData { type Confidential = ConcealedData; fn state_type(&self) -> StateType { StateType::Structured } - fn state_data(&self) -> StateData { StateData::Structured(self.clone()) } + fn state_data(&self) -> RevealedState { RevealedState::Structured(self.clone()) } } impl Conceal for RevealedData { @@ -155,7 +155,7 @@ pub struct ConcealedData( impl ConfidentialState for ConcealedData { fn state_type(&self) -> StateType { StateType::Structured } - fn state_commitment(&self) -> StateCommitment { StateCommitment::Structured(*self) } + fn state_commitment(&self) -> ConcealedState { ConcealedState::Structured(*self) } } impl CommitVerify for ConcealedData { diff --git a/src/contract/fungible.rs b/src/contract/fungible.rs index e6b1b155..4bc4aef6 100644 --- a/src/contract/fungible.rs +++ b/src/contract/fungible.rs @@ -55,7 +55,7 @@ use strict_encoding::{ }; use super::{ConfidentialState, ExposedState}; -use crate::{schema, AssignmentType, StateCommitment, StateData, StateType, LIB_NAME_RGB}; +use crate::{schema, AssignmentType, ConcealedState, RevealedState, StateType, LIB_NAME_RGB}; #[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)] #[wrapper(Deref, BorrowSlice, Hex, Index, RangeOps)] @@ -327,7 +327,7 @@ impl RevealedValue { impl ExposedState for RevealedValue { type Confidential = ConcealedValue; fn state_type(&self) -> StateType { StateType::Fungible } - fn state_data(&self) -> StateData { StateData::Fungible(*self) } + fn state_data(&self) -> RevealedState { RevealedState::Fungible(*self) } } impl Conceal for RevealedValue { @@ -470,7 +470,7 @@ pub struct ConcealedValue { impl ConfidentialState for ConcealedValue { fn state_type(&self) -> StateType { StateType::Fungible } - fn state_commitment(&self) -> StateCommitment { StateCommitment::Fungible(*self) } + fn state_commitment(&self) -> ConcealedState { ConcealedState::Fungible(*self) } } impl CommitVerify for ConcealedValue { diff --git a/src/contract/mod.rs b/src/contract/mod.rs index 7b1d2a33..14945963 100644 --- a/src/contract/mod.rs +++ b/src/contract/mod.rs @@ -60,7 +60,7 @@ pub use seal::{ ExposedSeal, GenesisSeal, GraphSeal, OutputSeal, SecretSeal, TxoSeal, WitnessId, WitnessOrd, WitnessPos, XGenesisSeal, XGraphSeal, XOutputSeal, XPubWitness, XWitness, }; -pub use state::{ConfidentialState, ExposedState, StateCommitment, StateData, StateType}; +pub use state::{ConcealedState, ConfidentialState, ExposedState, RevealedState, StateType}; pub use xchain::{ AltLayer1, AltLayer1Set, XChain, XChainParseError, XOutpoint, XCHAIN_BITCOIN_PREFIX, XCHAIN_LIQUID_PREFIX, diff --git a/src/contract/state.rs b/src/contract/state.rs index 3054ef27..00092e14 100644 --- a/src/contract/state.rs +++ b/src/contract/state.rs @@ -28,16 +28,13 @@ use strict_encoding::{StrictDecode, StrictDumb, StrictEncode}; use crate::{ ConcealedAttach, ConcealedData, ConcealedValue, RevealedAttach, RevealedData, RevealedValue, - LIB_NAME_RGB, }; /// Marker trait for types of state which are just a commitment to the actual /// state data. -pub trait ConfidentialState: - Debug + Hash + StrictDumb + StrictEncode + StrictDecode + Eq + Copy -{ +pub trait ConfidentialState: Debug + Hash + Eq + Copy { fn state_type(&self) -> StateType; - fn state_commitment(&self) -> StateCommitment; + fn state_commitment(&self) -> ConcealedState; } /// Marker trait for types of state holding explicit state data. @@ -51,9 +48,9 @@ pub trait ExposedState: + Ord + Clone { - type Confidential: ConfidentialState; + type Confidential: ConfidentialState + StrictEncode + StrictDecode + StrictDumb; fn state_type(&self) -> StateType; - fn state_data(&self) -> StateData; + fn state_data(&self) -> RevealedState; } /// Categories of the state @@ -81,77 +78,51 @@ pub enum StateType { /// Categories of the state #[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)] -#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] -#[strict_type(lib = LIB_NAME_RGB, tags = custom)] #[cfg_attr( feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate", rename_all = "camelCase") )] -pub enum StateData { - #[strict_type(tag = 0x00, dumb)] +pub enum RevealedState { Void, - #[strict_type(tag = 0x01)] Fungible(RevealedValue), - #[strict_type(tag = 0x02)] Structured(RevealedData), - #[strict_type(tag = 0xFF)] Attachment(RevealedAttach), } -impl ExposedState for StateData { - type Confidential = StateCommitment; - fn state_type(&self) -> StateType { - match self { - StateData::Void => StateType::Void, - StateData::Fungible(_) => StateType::Fungible, - StateData::Structured(_) => StateType::Structured, - StateData::Attachment(_) => StateType::Attachment, - } - } - fn state_data(&self) -> StateData { self.clone() } -} - -impl Conceal for StateData { - type Concealed = StateCommitment; - fn conceal(&self) -> Self::Concealed { +impl RevealedState { + pub fn state_type(&self) -> StateType { match self { - StateData::Void => StateCommitment::Void, - StateData::Fungible(value) => StateCommitment::Fungible(value.conceal()), - StateData::Structured(data) => StateCommitment::Structured(data.conceal()), - StateData::Attachment(attach) => StateCommitment::Attachment(attach.conceal()), + RevealedState::Void => StateType::Void, + RevealedState::Fungible(_) => StateType::Fungible, + RevealedState::Structured(_) => StateType::Structured, + RevealedState::Attachment(_) => StateType::Attachment, } } } #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] -#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] -#[strict_type(lib = LIB_NAME_RGB, tags = custom)] #[cfg_attr( feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate", rename_all = "camelCase") )] #[allow(clippy::large_enum_variant)] -pub enum StateCommitment { - #[strict_type(tag = 0x00, dumb)] +pub enum ConcealedState { Void, - #[strict_type(tag = 0x01)] Fungible(ConcealedValue), - #[strict_type(tag = 0x02)] Structured(ConcealedData), - #[strict_type(tag = 0xFF)] Attachment(ConcealedAttach), } -impl ConfidentialState for StateCommitment { +impl ConfidentialState for ConcealedState { fn state_type(&self) -> StateType { match self { - StateCommitment::Void => StateType::Void, - StateCommitment::Fungible(_) => StateType::Fungible, - StateCommitment::Structured(_) => StateType::Structured, - StateCommitment::Attachment(_) => StateType::Attachment, + ConcealedState::Void => StateType::Void, + ConcealedState::Fungible(_) => StateType::Fungible, + ConcealedState::Structured(_) => StateType::Structured, + ConcealedState::Attachment(_) => StateType::Attachment, } } - fn state_commitment(&self) -> StateCommitment { *self } + fn state_commitment(&self) -> ConcealedState { *self } } diff --git a/src/stl.rs b/src/stl.rs index 5128d3e1..a016b2a2 100644 --- a/src/stl.rs +++ b/src/stl.rs @@ -32,7 +32,7 @@ use crate::{AnchoredBundle, ContractState, Extension, Genesis, SubSchema, LIB_NA /// Strict types id for the library providing data types for RGB consensus. pub const LIB_ID_RGB: &str = - "urn:ubideco:stl:ENn5cEDW7QUStLzY6HBXjZFARAbrGHv3tXmdQ3QGzoU3#option-data-mimosa"; + "urn:ubideco:stl:2YfZKdnGf9Gibvh15WcNSqe3xN7WH1143j1gCbDgecvG#axiom-detail-panther"; fn _rgb_core_stl() -> Result { LibBuilder::new(libname!(LIB_NAME_RGB), tiny_bset! { diff --git a/src/validation/state.rs b/src/validation/state.rs index 586e9da6..878aa75e 100644 --- a/src/validation/state.rs +++ b/src/validation/state.rs @@ -24,8 +24,8 @@ use strict_types::TypeSystem; use crate::schema::AssignmentType; use crate::{ - validation, Assign, ConfidentialState, ExposedSeal, ExposedState, OpId, StateCommitment, - StateData, StateSchema, + validation, Assign, ConcealedState, ConfidentialState, ExposedSeal, ExposedState, OpId, + RevealedState, StateSchema, }; impl StateSchema { @@ -40,8 +40,8 @@ impl StateSchema { match data { Assign::Confidential { state, .. } | Assign::ConfidentialState { state, .. } => { match (self, state.state_commitment()) { - (StateSchema::Declarative, StateCommitment::Void) => {} - (StateSchema::Fungible(_), StateCommitment::Fungible(value)) => { + (StateSchema::Declarative, ConcealedState::Void) => {} + (StateSchema::Fungible(_), ConcealedState::Fungible(value)) => { // [SECURITY-CRITICAL]: Bulletproofs validation if let Err(err) = value.verify_range_proof() { status.add_failure(validation::Failure::BulletproofsInvalid( @@ -51,12 +51,12 @@ impl StateSchema { )); } } - (StateSchema::Structured(_), StateCommitment::Structured(_)) => { + (StateSchema::Structured(_), ConcealedState::Structured(_)) => { status.add_info(validation::Info::UncheckableConfidentialState( *opid, state_type, )); } - (StateSchema::Attachment(_), StateCommitment::Attachment(_)) => { + (StateSchema::Attachment(_), ConcealedState::Attachment(_)) => { status.add_info(validation::Info::UncheckableConfidentialState( *opid, state_type, )); @@ -74,8 +74,8 @@ impl StateSchema { } Assign::Revealed { state, .. } | Assign::ConfidentialSeal { state, .. } => { match (self, state.state_data()) { - (StateSchema::Declarative, StateData::Void) => {} - (StateSchema::Attachment(media_type), StateData::Attachment(attach)) + (StateSchema::Declarative, RevealedState::Void) => {} + (StateSchema::Attachment(media_type), RevealedState::Attachment(attach)) if !attach.media_type.conforms(media_type) => { status.add_failure(validation::Failure::MediaTypeMismatch { @@ -85,7 +85,7 @@ impl StateSchema { found: attach.media_type, }); } - (StateSchema::Fungible(schema), StateData::Fungible(v)) + (StateSchema::Fungible(schema), RevealedState::Fungible(v)) if v.value.fungible_type() != *schema => { status.add_failure(validation::Failure::FungibleTypeMismatch { @@ -95,8 +95,8 @@ impl StateSchema { found: v.value.fungible_type(), }); } - (StateSchema::Fungible(_), StateData::Fungible(_)) => {} - (StateSchema::Structured(sem_id), StateData::Structured(data)) => { + (StateSchema::Fungible(_), RevealedState::Fungible(_)) => {} + (StateSchema::Structured(sem_id), RevealedState::Structured(data)) => { if type_system .strict_deserialize_type(*sem_id, data.value.as_ref()) .is_err()