Skip to content

Commit

Permalink
Merge branch 'vesper' into v0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Feb 4, 2024
2 parents 3f52bc3 + d510e90 commit 23592f6
Show file tree
Hide file tree
Showing 22 changed files with 1,559 additions and 915 deletions.
243 changes: 133 additions & 110 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ name = "rgbcore-stl"
required-features = ["stl"]

[dependencies]
amplify = { version = "~4.5.0", features = ["rand"] }
amplify = { version = "~4.5.1", features = ["rand"] }
strict_encoding = "~2.6.2"
strict_types = "~1.6.3"
aluvm = { version = "~0.11.0-beta.2", features = ["std"] }
Expand Down Expand Up @@ -62,4 +62,8 @@ wasm-bindgen-test = "0.3"
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" }
65 changes: 55 additions & 10 deletions src/bin/rgbcore-stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,68 @@
// 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 dir = dir.unwrap_or_else(|| ".".to_owned());

let tt = sys.type_tree("RGB.Transition").unwrap();
fs::write(format!("{dir}/Transition.vesper",), format!("{tt}")).unwrap();

let tt = sys.type_tree("RGB.Schema").unwrap();
fs::write(format!("{dir}/Schema.vesper",), format!("{tt}")).unwrap();

let tt = sys.type_tree("RGB.AnchoredBundle").unwrap();
fs::write(format!("{dir}/AnchoredBundle.vesper",), format!("{tt}")).unwrap();
}
84 changes: 2 additions & 82 deletions src/contract/assignments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ use core::cmp::Ordering;
use core::fmt::Debug;
use std::collections::BTreeSet;
use std::hash::{Hash, Hasher};
use std::{io, vec};

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

use super::ExposedState;
use crate::contract::seal::GenesisSeal;
Expand Down Expand Up @@ -231,40 +229,6 @@ where Self: Clone
}
}

// We do not derive here since we omit serialization of the tag: all data are
// concealed, thus no tag is needed.
impl<State: ExposedState, Seal: ExposedSeal> CommitEncode for Assign<State, Seal>
where Self: Clone
{
fn commit_encode(&self, e: &mut impl io::Write) {
match self {
Assign::Confidential { seal, state } => {
seal.commit_encode(e);
state.commit_encode(e);
}
Assign::ConfidentialState { seal, state } => {
seal.conceal().commit_encode(e);
state.commit_encode(e);
}
Assign::Revealed { seal, state } => {
seal.conceal().commit_encode(e);
state.commit_encode(e);
}
Assign::ConfidentialSeal { seal, state } => {
seal.commit_encode(e);
state.commit_encode(e);
}
}
}
}

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,38 +517,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;

fn merkle_leaves(&self) -> Self::LeafIter<'_> {
match self {
TypedAssigns::Declarative(vec) => vec
.iter()
.map(AssignRights::commitment_id)
.collect::<Vec<_>>(),
TypedAssigns::Fungible(vec) => vec
.iter()
.map(AssignFungible::commitment_id)
.collect::<Vec<_>>(),
TypedAssigns::Structured(vec) => vec
.iter()
.map(AssignData::commitment_id)
.collect::<Vec<_>>(),
TypedAssigns::Attachment(vec) => vec
.iter()
.map(AssignAttach::commitment_id)
.collect::<Vec<_>>(),
}
.into_iter()
}
}

impl TypedAssigns<GenesisSeal> {
pub fn transmutate_seals(&self) -> TypedAssigns<GraphSeal> {
match self {
Expand Down Expand Up @@ -629,18 +561,6 @@ impl<Seal: ExposedSeal> Default for Assignments<Seal> {
fn default() -> Self { Self(empty!()) }
}

impl<Seal: ExposedSeal> CommitEncode for Assignments<Seal> {
fn commit_encode(&self, mut e: &mut impl io::Write) {
let w = StrictWriter::with(u32::MAX as usize, &mut e);
self.0.len_u8().strict_encode(w).ok();
for (ty, state) in &self.0 {
let w = StrictWriter::with(u32::MAX as usize, &mut e);
ty.strict_encode(w).ok();
state.commit_encode(e);
}
}
}

impl Assignments<GenesisSeal> {
pub fn transmutate_seals(&self) -> Assignments<GraphSeal> {
Assignments(
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
25 changes: 13 additions & 12 deletions src/contract/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
// limitations under the License.

use std::collections::BTreeMap;
use std::io::Write;

use amplify::confinement::{Confined, U16};
use amplify::{Bytes32, Wrapper};
use bp::Vout;
use commit_verify::{mpc, CommitEncode, CommitmentId};
use strict_encoding::{StrictDumb, StrictEncode, StrictWriter};
use commit_verify::{mpc, CommitEncode, CommitEngine, CommitId, CommitmentId, DigestExt, Sha256};
use strict_encoding::{StrictDumb, StrictEncode};

use super::OpId;
use crate::{Transition, LIB_NAME_RGB};
Expand All @@ -51,6 +50,14 @@ pub struct BundleId(
Bytes32,
);

impl From<Sha256> for BundleId {
fn from(hasher: Sha256) -> Self { hasher.finish().into() }
}

impl CommitmentId for BundleId {
const TAG: &'static str = "urn:lnpbp:rgb:bundle#2024-02-03";
}

impl From<BundleId> for mpc::Message {
fn from(id: BundleId) -> Self { mpc::Message::from_inner(id.into_inner()) }
}
Expand All @@ -73,15 +80,9 @@ pub struct TransitionBundle {
}

impl CommitEncode for TransitionBundle {
fn commit_encode(&self, e: &mut impl Write) {
let w = StrictWriter::with(u32::MAX as usize, e);
self.input_map.strict_encode(w).ok();
}
}
type CommitmentId = BundleId;

impl CommitmentId for TransitionBundle {
const TAG: [u8; 32] = *b"urn:lnpbp:rgb:bundle:v1#20230306";
type Id = BundleId;
fn commit_encode(&self, e: &mut CommitEngine) { e.commit_to(&self.input_map); }
}

impl StrictDumb for TransitionBundle {
Expand All @@ -94,5 +95,5 @@ impl StrictDumb for TransitionBundle {
}

impl TransitionBundle {
pub fn bundle_id(&self) -> BundleId { self.commitment_id() }
pub fn bundle_id(&self) -> BundleId { self.commit_id() }
}
16 changes: 1 addition & 15 deletions src/contract/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@

use core::fmt::{self, Debug, Formatter};
use std::cmp::Ordering;
use std::io::Write;

use amplify::confinement::SmallBlob;
use amplify::hex::ToHex;
use amplify::{Bytes32, Wrapper};
use bp::secp256k1::rand::{random, Rng, RngCore};
use commit_verify::{CommitEncode, CommitVerify, Conceal, StrictEncodedProtocol};
use commit_verify::{CommitVerify, Conceal, StrictEncodedProtocol};
use strict_encoding::{StrictSerialize, StrictType};

use super::{ConfidentialState, ExposedState};
Expand All @@ -39,8 +38,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 +62,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 @@ -116,13 +111,6 @@ impl Conceal for RevealedData {
fn conceal(&self) -> Self::Concealed { ConcealedData::commit(self) }
}

impl CommitEncode for RevealedData {
fn commit_encode(&self, e: &mut impl Write) {
e.write_all(&self.value).ok();
e.write_all(&self.salt.to_le_bytes()).ok();
}
}

impl PartialOrd for RevealedData {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
}
Expand Down Expand Up @@ -154,8 +142,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
Loading

0 comments on commit 23592f6

Please sign in to comment.