Skip to content

Commit

Permalink
wip on vesper
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Feb 3, 2024
1 parent eb27dae commit d614f0b
Show file tree
Hide file tree
Showing 20 changed files with 736 additions and 498 deletions.
161 changes: 76 additions & 85 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ features = [ "all" ]
[patch.crates-io]
strict_encoding = { git = "https://github.com/strict-types/strict-encoding", branch = "ident" }
strict_types = { git = "https://github.com/strict-types/strict-types", branch = "vesper" }
commit_verify = { git = "https://github.com/LNP-BP/client_side_validation", branch = "v0.11" }
bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
aluvm = { git = "https://github.com/AluVM/rust-aluvm", branch = "v0.11" }
58 changes: 48 additions & 10 deletions src/bin/rgbcore-stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,61 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fs;

use aluvm::stl::aluvm_stl;
use bp::stl::bp_core_stl;
use commit_verify::stl::commit_verify_stl;
use rgb::stl::bp_tx_stl;
use strict_types::stl::{std_stl, strict_types_stl};
use strict_types::typelib::parse_args;
use strict_types::SystemBuilder;

fn main() {
let (format, dir) = parse_args();

rgb::stl::rgb_core_stl()
.serialize(
format,
dir,
"0.1.0",
Some(
"
let rgb = rgb::stl::rgb_core_stl();

rgb.serialize(
format,
dir.as_ref(),
"0.1.0",
Some(
"
Description: Consensus layer for RGB smart contracts
Author: Dr Maxim Orlovsky <[email protected]>
Copyright (C) 2023 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");

let std = std_stl();
let tx = bp_tx_stl();
let bp = bp_core_stl();
let cv = commit_verify_stl();
let st = strict_types_stl();
let vm = aluvm_stl();

let sys = SystemBuilder::new()
.import(rgb)
.unwrap()
.import(vm)
.unwrap()
.import(bp)
.unwrap()
.import(tx)
.unwrap()
.import(cv)
.unwrap()
.import(st)
.unwrap()
.import(std)
.unwrap()
.finalize()
.expect("not all libraries present");

let tt = sys.type_tree("RGB.Transition").unwrap();
let dir = dir.unwrap_or_else(|| ".".to_owned());
fs::write(format!("{dir}/Transition.vesper",), format!("{tt}")).unwrap();
}
14 changes: 1 addition & 13 deletions src/contract/assignments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::{io, vec};

use amplify::confinement::{Confined, SmallVec, TinyOrdMap};
use commit_verify::merkle::{MerkleLeaves, MerkleNode};
use commit_verify::{CommitEncode, CommitStrategy, CommitmentId, Conceal};
use commit_verify::{CommitEncode, CommitmentId, Conceal};
use strict_encoding::{StrictDumb, StrictEncode, StrictWriter};

use super::ExposedState;
Expand Down Expand Up @@ -258,13 +258,6 @@ where Self: Clone
}
}

impl<State: ExposedState, Seal: ExposedSeal> CommitmentId for Assign<State, Seal>
where Self: Clone
{
const TAG: [u8; 32] = *b"urn:lnpbp:rgb:owned-state:v1#23A";
type Id = MerkleNode;
}

impl<State: ExposedState> Assign<State, GenesisSeal> {
pub fn transmutate_seals(&self) -> Assign<State, GraphSeal> {
match self {
Expand Down Expand Up @@ -553,11 +546,6 @@ impl<Seal: ExposedSeal> TypedAssigns<Seal> {
}
}

impl<Seal: ExposedSeal> CommitStrategy for TypedAssigns<Seal> {
type Strategy =
commit_verify::strategies::Merklize<{ u128::from_be_bytes(*b"rgb:state:owned*") }>;
}

impl<Seal: ExposedSeal> MerkleLeaves for TypedAssigns<Seal> {
type Leaf = MerkleNode;
type LeafIter<'tmp> = vec::IntoIter<MerkleNode> where Self: 'tmp;
Expand Down
4 changes: 0 additions & 4 deletions src/contract/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ impl AttachId {
#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(conceal, strategy = strict)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -128,8 +126,6 @@ impl Conceal for RevealedAttach {
#[wrapper(Deref, BorrowSlice, Hex, Index, RangeOps)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down
7 changes: 1 addition & 6 deletions src/contract/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::io::Write;
use amplify::confinement::{Confined, U16};
use amplify::{Bytes32, Wrapper};
use bp::Vout;
use commit_verify::{mpc, CommitEncode, CommitmentId};
use commit_verify::{mpc, CommitEncode};
use strict_encoding::{StrictDumb, StrictEncode, StrictWriter};

use super::OpId;
Expand Down Expand Up @@ -79,11 +79,6 @@ impl CommitEncode for TransitionBundle {
}
}

impl CommitmentId for TransitionBundle {
const TAG: [u8; 32] = *b"urn:lnpbp:rgb:bundle:v1#20230306";
type Id = BundleId;
}

impl StrictDumb for TransitionBundle {
fn strict_dumb() -> Self {
Self {
Expand Down
6 changes: 0 additions & 6 deletions src/contract/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ use crate::{StateCommitment, StateData, StateType, LIB_NAME_RGB};
#[display("void")]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))]
pub struct VoidState(());

Expand All @@ -65,8 +63,6 @@ impl Conceal for VoidState {
#[wrapper(Deref, AsSlice, BorrowSlice, Hex)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))]
pub struct DataState(SmallBlob);
impl StrictSerialize for DataState {}
Expand Down Expand Up @@ -154,8 +150,6 @@ impl Debug for RevealedData {
#[wrapper(Deref, BorrowSlice, Hex, Index, RangeOps)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB, rename = "ConcealedData")]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down
3 changes: 0 additions & 3 deletions src/contract/fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,6 @@ impl Ord for RevealedValue {
#[wrapper(Deref, FromStr, Display, LowerHex)]
#[derive(StrictType)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -468,7 +466,6 @@ impl CommitmentProtocol for PedersenProtocol {}
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB, rename = "ConcealedFungible")]
#[derive(CommitEncode)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down
2 changes: 0 additions & 2 deletions src/contract/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ impl IntoIterator for GlobalValues {
#[wrapper_mut(DerefMut)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down
26 changes: 4 additions & 22 deletions src/contract/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use amplify::confinement::{SmallBlob, TinyOrdMap, TinyOrdSet};
use amplify::hex::{FromHex, ToHex};
use amplify::{hex, ByteArray, Bytes32, FromSliceError, Wrapper};
use baid58::{Baid58ParseError, Chunking, FromBaid58, ToBaid58, CHUNKING_32CHECKSUM};
use commit_verify::{mpc, CommitmentId, Conceal};
use commit_verify::{mpc, Conceal};
use strict_encoding::{StrictDeserialize, StrictEncode, StrictSerialize};

use crate::schema::{self, ExtensionType, OpFullType, OpType, SchemaId, TransitionType};
Expand All @@ -43,8 +43,6 @@ use crate::{
#[wrapper_mut(DerefMut)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand All @@ -64,8 +62,6 @@ impl<'a> IntoIterator for &'a Valencies {
#[wrapper_mut(DerefMut)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand All @@ -85,8 +81,6 @@ impl<'a> IntoIterator for &'a Redeemed {
#[wrapper_mut(DerefMut)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -266,6 +260,7 @@ pub trait Operation {
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = conceal, id = OpId)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand All @@ -289,6 +284,7 @@ impl StrictDeserialize for Genesis {}
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = conceal, id = OpId)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand All @@ -312,6 +308,7 @@ impl StrictDeserialize for Extension {}
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = conceal, id = OpId)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -343,11 +340,6 @@ impl Conceal for Genesis {
}
}

impl CommitmentId for Genesis {
const TAG: [u8; 32] = *b"urn:lnpbp:rgb:genesis:v02#202304";
type Id = ContractId;
}

impl Conceal for Transition {
type Concealed = Transition;
fn conceal(&self) -> Self::Concealed {
Expand All @@ -360,11 +352,6 @@ impl Conceal for Transition {
}
}

impl CommitmentId for Transition {
const TAG: [u8; 32] = *b"urn:lnpbp:rgb:transition:v02#23B";
type Id = OpId;
}

impl Conceal for Extension {
type Concealed = Extension;
fn conceal(&self) -> Self::Concealed {
Expand All @@ -377,11 +364,6 @@ impl Conceal for Extension {
}
}

impl CommitmentId for Extension {
const TAG: [u8; 32] = *b"urn:lnpbp:rgb:extension:v02#2304";
type Id = OpId;
}

impl Transition {
/// Returns reference to information about the owned rights in form of
/// [`Inputs`] wrapper structure which this operation updates with
Expand Down
6 changes: 1 addition & 5 deletions src/contract/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub use bp::seals::txout::TxoSeal;
use bp::seals::txout::{BlindSeal, CloseMethod, ExplicitSeal, SealTxid, VerifyError, Witness};
pub use bp::seals::SecretSeal;
use bp::{dbc, Outpoint, Tx, Txid, Vout};
use commit_verify::{mpc, strategies, CommitEncode, CommitStrategy, Conceal};
use commit_verify::{mpc, CommitEncode, Conceal};
use single_use_seals::SealWitness;
use strict_encoding::{StrictDecode, StrictDumb, StrictEncode, StrictType};

Expand Down Expand Up @@ -275,10 +275,6 @@ impl<Dbc: dbc::Proof, Seal: TxoSeal> SealWitness<Seal> for XWitness<Dbc> {
}
}

impl<Id: SealTxid> CommitStrategy for XChain<BlindSeal<Id>> {
type Strategy = strategies::Strict;
}

impl<Id: SealTxid> XChain<BlindSeal<Id>> {
/// Converts revealed seal into concealed.
#[inline]
Expand Down
2 changes: 0 additions & 2 deletions src/contract/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ pub enum StateType {
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB, tags = custom)]
#[derive(CommitEncode)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -129,7 +128,6 @@ impl Conceal for StateData {
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB, tags = custom)]
#[derive(CommitEncode)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ mod _reserved {
#[display("RGB/1.{0}")]
#[derive(StrictType, StrictEncode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down
14 changes: 2 additions & 12 deletions src/schema/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use std::str::FromStr;
use amplify::confinement::{TinyOrdMap, TinyOrdSet};
use amplify::{ByteArray, Bytes32};
use baid58::{Baid58ParseError, Chunking, FromBaid58, ToBaid58, CHUNKING_32};
use commit_verify::{CommitStrategy, CommitmentId};
use strict_encoding::{StrictDecode, StrictDeserialize, StrictEncode, StrictSerialize, StrictType};
use strict_types::TypeSystem;

Expand Down Expand Up @@ -57,7 +56,6 @@ impl GlobalStateType {
#[display("0x{0:04X}")]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand All @@ -73,7 +71,6 @@ impl ExtensionType {
#[display("0x{0:04X}")]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -144,6 +141,8 @@ pub type SubSchema = Schema<RootSchema>;
#[derive(Clone, Eq, Default, Debug)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict, id = SchemaId)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -178,15 +177,6 @@ impl<Root: SchemaRoot> PartialOrd for Schema<Root> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
}

impl<Root: SchemaRoot> CommitStrategy for Schema<Root> {
type Strategy = commit_verify::strategies::Strict;
}

impl<Root: SchemaRoot> CommitmentId for Schema<Root> {
const TAG: [u8; 32] = *b"urn:lnpbp:rgb:schema:v01#202302A";
type Id = SchemaId;
}

impl<Root: SchemaRoot> StrictSerialize for Schema<Root> {}
impl<Root: SchemaRoot> StrictDeserialize for Schema<Root> {}

Expand Down
Loading

0 comments on commit d614f0b

Please sign in to comment.