Skip to content

Commit

Permalink
Merge pull request #263 from RGB-WG/mining
Browse files Browse the repository at this point in the history
Move non-consensus data types to stdlib; better separate commitments and logic validation
  • Loading branch information
dr-orlovsky authored Aug 9, 2024
2 parents 60377cf + fa31db7 commit e24c3d9
Show file tree
Hide file tree
Showing 40 changed files with 1,011 additions and 1,141 deletions.
53 changes: 36 additions & 17 deletions src/bin/rgbcore-stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,38 @@ use strict_types::SystemBuilder;
fn main() {
let (format, dir) = parse_args();

let rgb = rgbcore::stl::rgb_core_stl();
let rgb_commit = rgbcore::stl::rgb_commit_stl();
let rgb_logic = rgbcore::stl::rgb_logic_stl();

rgb.serialize(
format,
dir.as_ref(),
"0.1.0",
Some(
"
Description: Consensus layer for RGB smart contracts
rgb_commit
.serialize(
format,
dir.as_ref(),
"0.1.0",
Some(
"
Description: Consensus commitment layer for RGB smart contracts
Author: Dr Maxim Orlovsky <[email protected]>
Copyright (C) 2023-2024 LNP/BP Standards Association. All rights reserved.
License: Apache-2.0",
),
)
.expect("unable to write to the file");
),
)
.expect("unable to write to the file");

rgb_logic
.serialize(
format,
dir.as_ref(),
"0.1.0",
Some(
"
Description: Consensus logic layer for RGB smart contracts
Author: Dr Maxim Orlovsky <[email protected]>
Copyright (C) 2023-2024 LNP/BP Standards Association. All rights reserved.
License: Apache-2.0",
),
)
.expect("unable to write to the file");

let std = std_stl();
let tx = bp_tx_stl();
Expand All @@ -60,7 +77,9 @@ fn main() {
let vm = aluvm_stl();

let sys = SystemBuilder::new()
.import(rgb)
.import(rgb_logic)
.unwrap()
.import(rgb_commit)
.unwrap()
.import(vm)
.unwrap()
Expand Down Expand Up @@ -95,7 +114,7 @@ Schema vesper lexicon=types+commitments
.unwrap();
let layout = Schema::commitment_layout();
writeln!(file, "{layout}").unwrap();
let tt = sys.type_tree("RGB.Schema").unwrap();
let tt = sys.type_tree("RGBCommit.Schema").unwrap();
writeln!(file, "{tt}").unwrap();

let mut file = fs::File::create(format!("{dir}/Transition.vesper")).unwrap();
Expand All @@ -114,9 +133,9 @@ Transition vesper lexicon=types+commitments
.unwrap();
let layout = Transition::commitment_layout();
writeln!(file, "{layout}").unwrap();
let tt = sys.type_tree("RGB.OpCommitment").unwrap();
let tt = sys.type_tree("RGBCommit.OpCommitment").unwrap();
writeln!(file, "{tt}").unwrap();
let tt = sys.type_tree("RGB.Transition").unwrap();
let tt = sys.type_tree("RGBCommit.Transition").unwrap();
writeln!(file, "{tt}").unwrap();

let mut file = fs::File::create(format!("{dir}/AnchoredBundle.vesper")).unwrap();
Expand All @@ -135,8 +154,8 @@ Bundles vesper lexicon=types+commitments
.unwrap();
let layout = TransitionBundle::commitment_layout();
writeln!(file, "{layout}").unwrap();
let tt = sys.type_tree("RGB.DbcProof").unwrap();
let tt = sys.type_tree("RGBLogic.DbcProof").unwrap();
writeln!(file, "{tt}").unwrap();
let tt = sys.type_tree("RGB.TransitionBundle").unwrap();
let tt = sys.type_tree("RGBCommit.TransitionBundle").unwrap();
writeln!(file, "{tt}").unwrap();
}
8 changes: 4 additions & 4 deletions src/contract/assignments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use super::ExposedState;
use crate::contract::seal::GenesisSeal;
use crate::{
AssignmentType, ExposedSeal, GraphSeal, RevealedAttach, RevealedData, RevealedValue,
SecretSeal, StateType, VoidState, XChain, LIB_NAME_RGB,
SecretSeal, StateType, VoidState, XChain, LIB_NAME_RGB_COMMIT,
};

#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Display, Error)]
Expand All @@ -52,7 +52,7 @@ pub type AssignAttach<Seal> = Assign<RevealedAttach, Seal>;
#[derive(Clone, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(
lib = LIB_NAME_RGB,
lib = LIB_NAME_RGB_COMMIT,
tags = custom,
dumb = { Self::Confidential { seal: strict_dumb!(), state: strict_dumb!(), lock: default!() } }
)]
Expand Down Expand Up @@ -285,7 +285,7 @@ impl<State: ExposedState> Assign<State, GenesisSeal> {

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB, tags = custom, dumb = Self::Declarative(strict_dumb!()))]
#[strict_type(lib = LIB_NAME_RGB_COMMIT, tags = custom, dumb = Self::Declarative(strict_dumb!()))]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -577,7 +577,7 @@ impl TypedAssigns<GenesisSeal> {
#[wrapper(Deref)]
#[wrapper_mut(DerefMut)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down
49 changes: 38 additions & 11 deletions src/contract/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ use amplify::{ByteArray, Bytes32};
use baid64::{Baid64ParseError, DisplayBaid64, FromBaid64Str};
use bp::secp256k1::rand::{random, Rng, RngCore};
use commit_verify::{CommitId, CommitmentId, Conceal, DigestExt, Sha256};
use strict_encoding::StrictEncode;
use strict_encoding::{StrictEncode, StrictSerialize};

use super::{ConfidentialState, ExposedState};
use crate::{impl_serde_baid64, ConcealedState, MediaType, RevealedState, StateType, LIB_NAME_RGB};
use crate::{
impl_serde_baid64, ConcealedState, MediaType, RevealedState, StateType, LIB_NAME_RGB_COMMIT,
};

/// Unique data attachment identifier
#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)]
#[wrapper(Deref, BorrowSlice, Hex, Index, RangeOps)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
pub struct AttachId(
#[from]
#[from([u8; 32])]
Expand All @@ -63,21 +65,44 @@ impl Display for AttachId {

impl_serde_baid64!(AttachId);

#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Display)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict, id = ConcealedAttach)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[display("{id}:{media_type}")]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct RevealedAttach {
pub struct AttachState {
pub id: AttachId,
/// We do not enforce a MIME standard since non-standard types can be also
/// used
pub media_type: MediaType,
}
impl StrictSerialize for AttachState {}

impl From<RevealedAttach> for AttachState {
fn from(attach: RevealedAttach) -> Self {
AttachState {
id: attach.file.id,
media_type: attach.file.media_type,
}
}
}

#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict, id = ConcealedAttach)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct RevealedAttach {
pub file: AttachState,
pub salt: u64,
}

Expand All @@ -101,8 +126,10 @@ impl RevealedAttach {
/// Convenience constructor.
pub fn with_salt(id: AttachId, media_type: impl Into<MediaType>, salt: u64) -> Self {
Self {
id,
media_type: media_type.into(),
file: AttachState {
id,
media_type: media_type.into(),
},
salt,
}
}
Expand All @@ -126,7 +153,7 @@ impl Conceal for RevealedAttach {
#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)]
#[wrapper(Deref, BorrowSlice, Hex, Index, RangeOps)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down
8 changes: 4 additions & 4 deletions src/contract/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use bp::Vout;
use commit_verify::{mpc, CommitEncode, CommitEngine, CommitId, CommitmentId, DigestExt, Sha256};
use strict_encoding::{StrictDumb, StrictEncode};

use crate::{OpId, Transition, LIB_NAME_RGB};
use crate::{OpId, Transition, LIB_NAME_RGB_COMMIT};

pub type Vin = Vout;

Expand All @@ -38,7 +38,7 @@ pub type Vin = Vout;
#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)]
#[wrapper(Deref, BorrowSlice, Display, Hex, Index, RangeOps)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -70,7 +70,7 @@ impl From<mpc::Message> for BundleId {
#[wrapper(Deref)]
#[wrapper_mut(DerefMut)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -102,7 +102,7 @@ impl<'a> IntoIterator for &'a InputMap {

#[derive(Clone, PartialEq, Eq, Debug, From)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down
20 changes: 10 additions & 10 deletions src/contract/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ use crate::{
ConcealedData, ConcealedState, ConfidentialState, DataState, ExposedSeal, ExposedState,
Extension, ExtensionType, Ffv, Genesis, GlobalState, GlobalStateType, Operation,
PedersenCommitment, Redeemed, SchemaId, SecretSeal, Transition, TransitionBundle,
TransitionType, TypedAssigns, XChain, LIB_NAME_RGB,
TransitionType, TypedAssigns, XChain, LIB_NAME_RGB_COMMIT,
};

/// Unique contract identifier equivalent to the contract genesis commitment
#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)]
#[wrapper(Deref, BorrowSlice, Hex, Index, RangeOps)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
pub struct ContractId(
#[from]
#[from([u8; 32])]
Expand Down Expand Up @@ -101,7 +101,7 @@ impl_serde_baid64!(ContractId);
#[wrapper(Deref, BorrowSlice, Hex, Index, RangeOps)]
#[display(Self::to_hex)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -138,7 +138,7 @@ impl OpId {
#[wrapper(Deref, BorrowSlice, Hex, Index, RangeOps)]
#[display(Self::to_hex)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -171,7 +171,7 @@ impl DiscloseHash {

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
pub struct AssignmentIndex {
pub ty: AssignmentType,
pub pos: u16,
Expand All @@ -183,7 +183,7 @@ impl AssignmentIndex {

#[derive(Clone, Eq, PartialEq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict, id = DiscloseHash)]
pub struct OpDisclose {
Expand All @@ -196,7 +196,7 @@ pub struct OpDisclose {

#[derive(Clone, Eq, PartialEq, Hash, Debug)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict, id = DiscloseHash)]
pub struct BundleDisclosure {
Expand Down Expand Up @@ -230,7 +230,7 @@ impl TransitionBundle {

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
pub struct BaseCommitment {
pub flags: ReservedBytes<1, 0>,
pub schema_id: SchemaId,
Expand All @@ -243,7 +243,7 @@ pub struct BaseCommitment {

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB, tags = custom, dumb = Self::Transition(strict_dumb!(), strict_dumb!()))]
#[strict_type(lib = LIB_NAME_RGB_COMMIT, tags = custom, dumb = Self::Transition(strict_dumb!(), strict_dumb!()))]
pub enum TypeCommitment {
#[strict_type(tag = 0)]
Genesis(BaseCommitment),
Expand All @@ -257,7 +257,7 @@ pub enum TypeCommitment {

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict, id = OpId)]
pub struct OpCommitment {
Expand Down
Loading

0 comments on commit e24c3d9

Please sign in to comment.