Skip to content

Commit

Permalink
remove support for alt layers
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedberg committed Jan 13, 2025
1 parent 0de9e70 commit cf40921
Show file tree
Hide file tree
Showing 14 changed files with 286 additions and 332 deletions.
8 changes: 3 additions & 5 deletions doc/Commitments.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,9 @@ assignments are concealed before the merklization, and range proofs are
removed from the commitment, such that an aggregation of the historical proofs
can be applied without changing the operation ids.

To ensure succinctness, other types of collections, such as redeemed and
defined valencies and list of alternate layer 1 in genesis are not merklized
and strict-serialized producing `StrictHash`, which participates in the final
`OpCommitment` structure.
To ensure succinctness, other types of collections, such as redeemed and
defined valencies in genesis are not merklized and strict-serialized producing
`StrictHash`, which participates in the final `OpCommitment` structure.

```mermaid
flowchart LR
Expand All @@ -222,7 +221,6 @@ flowchart LR
subgraph "Genesis"
schemaId --> BaseCommitment
testnet --> BaseCommitment
altLayers1 -- StrictHash --> BaseCommitment
end
subgraph "Transition"
Expand Down
2 changes: 0 additions & 2 deletions src/operation/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ pub struct BaseCommitment {
pub timestamp: i64,
pub issuer: StrictHash,
pub testnet: bool,
pub alt_layers1: StrictHash,
pub asset_tags: StrictHash,
}

Expand Down Expand Up @@ -281,7 +280,6 @@ impl Genesis {
schema_id: self.schema_id,
timestamp: self.timestamp,
testnet: self.testnet,
alt_layers1: self.alt_layers1.commit_id(),
issuer: self.issuer.commit_id(),
asset_tags: self.asset_tags.commit_id(),
};
Expand Down
4 changes: 2 additions & 2 deletions src/operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ pub use seal::{
};
pub use state::{ConcealedState, ConfidentialState, ExposedState, RevealedState, StateType};
pub use xchain::{
AltLayer1, AltLayer1Set, Impossible, Layer1, XChain, XChainParseError, XOutpoint,
XCHAIN_BITCOIN_PREFIX, XCHAIN_LIQUID_PREFIX,
Impossible, Layer1, XChain, XChainParseError, XOutpoint, XCHAIN_BITCOIN_PREFIX,
XCHAIN_LIQUID_PREFIX,
};
20 changes: 16 additions & 4 deletions src/operation/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ use strict_encoding::{RString, StrictDeserialize, StrictEncode, StrictSerialize}

use crate::schema::{self, ExtensionType, OpFullType, OpType, SchemaId, TransitionType};
use crate::{
AltLayer1Set, AssetTag, Assign, AssignmentIndex, AssignmentType, Assignments, AssignmentsRef,
AssetTag, Assign, AssignmentIndex, AssignmentType, Assignments, AssignmentsRef,
ConcealedAttach, ConcealedData, ConcealedValue, ContractId, DiscloseHash, ExposedState, Ffv,
GenesisSeal, GlobalState, GraphSeal, Metadata, OpDisclose, OpId, SecretSeal, TypedAssigns,
VoidState, XChain, LIB_NAME_RGB_COMMIT,
GenesisSeal, GlobalState, GraphSeal, Layer1, Metadata, OpDisclose, OpId, SecretSeal,
TypedAssigns, VoidState, XChain, LIB_NAME_RGB_COMMIT,
};

#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
Expand Down Expand Up @@ -360,7 +360,6 @@ pub struct Genesis {
pub timestamp: i64,
pub issuer: Identity,
pub testnet: bool,
pub alt_layers1: AltLayer1Set,
pub asset_tags: AssetTags,
pub metadata: Metadata,
pub globals: GlobalState,
Expand All @@ -372,6 +371,19 @@ pub struct Genesis {
impl StrictSerialize for Genesis {}
impl StrictDeserialize for Genesis {}

impl Genesis {
pub fn layer1(&self) -> Option<Layer1> {
if let Some((_, typed_assigns)) = self.assignments.iter().next() {
typed_assigns
.to_confidential_seals()
.first()
.map(|cs| cs.layer1())
} else {
None
}
}
}

#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
Expand Down
42 changes: 1 addition & 41 deletions src/operation/xchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ use std::fmt::{Debug, Display, Formatter};
use std::str::FromStr;
use std::{fmt, io};

use amplify::confinement::TinyOrdSet;
use bp::{Bp, Outpoint};
use commit_verify::{Conceal, StrictHash};
use commit_verify::Conceal;
use strict_encoding::{
DecodeError, DefineUnion, ReadTuple, ReadUnion, StrictDecode, StrictDumb, StrictEncode,
StrictEnum, StrictSum, StrictType, StrictUnion, TypedRead, TypedWrite, VariantError,
Expand Down Expand Up @@ -105,31 +104,6 @@ mod _serde {
}
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display)]
#[display(lowercase)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT, tags = repr, into_u8, try_from_u8)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
#[repr(u8)]
pub enum AltLayer1 {
#[strict_type(dumb)]
Liquid = 1,
// Abraxas = 0x10,
// Prime = 0x11,
}

impl AltLayer1 {
pub fn layer1(&self) -> Layer1 {
match self {
AltLayer1::Liquid => Layer1::Liquid,
}
}
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[cfg_attr(
feature = "serde",
Expand Down Expand Up @@ -180,20 +154,6 @@ impl FromStr for Impossible {
fn from_str(_: &str) -> Result<Self, Self::Err> { panic!("must not be parsed") }
}

#[derive(Wrapper, WrapperMut, Clone, PartialEq, Eq, Hash, Debug, Default, From)]
#[wrapper(Deref)]
#[wrapper_mut(DerefMut)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict, id = StrictHash)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", transparent)
)]
pub struct AltLayer1Set(TinyOrdSet<AltLayer1>);

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[cfg_attr(
feature = "serde",
Expand Down
4 changes: 2 additions & 2 deletions src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ use crate::{

/// Strict types id for the library providing data types for RGB consensus.
pub const LIB_ID_RGB_COMMIT: &str =
"stl:IFcnrPeI-TANxLfZ-feJax6Q-1TUM4Hq-AjI161s-3tbmxak#harvest-person-orion";
"stl:bJ8Swut6-fEFixNt-bJuRY6D-ZNyYV2D-aNfTFnN-68w5Ngk#point-ariel-kinetic";
/// Strict types id for the library providing data types for RGB consensus.
pub const LIB_ID_RGB_LOGIC: &str =
"stl:mqltqlPk-O9$pYOd-BACRI70-DOMJ6cp-TFvhcK1-ibrOI9U#import-boxer-seminar";
"stl:lvwcOo0a-!8WJfTD-eeERZkb-hZFG$r5-W2uKv!P-Oujw$hM#regular-moment-north";

fn _rgb_commit_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_RGB_COMMIT), tiny_bset! {
Expand Down
13 changes: 6 additions & 7 deletions src/validation/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ use crate::vm::{
ContractStateAccess, ContractStateEvolve, OrdOpRef, WitnessOrd, XWitnessId, XWitnessTx,
};
use crate::{
validation, AltLayer1, BundleId, ContractId, Layer1, OpId, OpType, Operation, Opout, Schema,
SchemaId, TransitionBundle, XChain, XOutpoint, XOutputSeal,
validation, BundleId, ContractId, Layer1, OpId, OpType, Operation, Opout, Schema, SchemaId,
TransitionBundle, XChain, XOutpoint, XOutputSeal,
};

#[derive(Clone, PartialEq, Eq, Debug, Display, Error, From)]
Expand Down Expand Up @@ -134,7 +134,7 @@ pub struct Validator<

schema_id: SchemaId,
contract_id: ContractId,
layers1: BTreeSet<Layer1>,
layer1: Option<Layer1>,

contract_state: Rc<RefCell<S>>,
validated_op_seals: RefCell<BTreeSet<OpId>>,
Expand Down Expand Up @@ -164,15 +164,14 @@ impl<
// Prevent repeated validation of single-use seals
let validated_op_seals = RefCell::new(BTreeSet::<OpId>::new());

let mut layers1 = bset! { Layer1::Bitcoin };
layers1.extend(genesis.alt_layers1.iter().map(AltLayer1::layer1));
let layer1 = genesis.layer1();

Self {
consignment,
status: RefCell::new(status),
schema_id,
contract_id,
layers1,
layer1,
validated_op_seals,
resolver: CheckedWitnessResolver::from(resolver),
contract_state: Rc::new(RefCell::new(S::init(context))),
Expand Down Expand Up @@ -581,7 +580,7 @@ impl<
});
continue;
}
if !self.layers1.contains(&seal.layer1()) {
if self.layer1 != Some(seal.layer1()) {
self.status
.borrow_mut()
.add_failure(Failure::SealLayerMismatch(seal.layer1(), seal));
Expand Down
Loading

0 comments on commit cf40921

Please sign in to comment.