Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.11 fixes #285

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 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,7 @@ flowchart LR
subgraph "Genesis"
schemaId --> BaseCommitment
testnet --> BaseCommitment
altLayers1 -- StrictHash --> BaseCommitment
closeMethod --> BaseCommitment
end

subgraph "Transition"
Expand Down
9 changes: 6 additions & 3 deletions src/operation/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use amplify::hex::{FromHex, ToHex};
use amplify::num::u256;
use amplify::{hex, ByteArray, Bytes32, FromSliceError, Wrapper};
use baid64::{Baid64ParseError, DisplayBaid64, FromBaid64Str};
use bp::seals::txout::CloseMethod;
use commit_verify::{
mpc, CommitEncode, CommitEngine, CommitId, CommitmentId, Conceal, DigestExt, MerkleHash,
MerkleLeaves, ReservedBytes, Sha256, StrictHash,
Expand All @@ -39,7 +40,7 @@ use strict_encoding::StrictDumb;
use crate::{
impl_serde_baid64, Assign, AssignmentType, Assignments, BundleId, ConcealedAttach,
ConcealedData, ConcealedState, ConfidentialState, DataState, ExposedSeal, ExposedState,
Extension, ExtensionType, Ffv, Genesis, GlobalState, GlobalStateType, Operation,
Extension, ExtensionType, Ffv, Genesis, GlobalState, GlobalStateType, Layer1, Operation,
PedersenCommitment, Redeemed, SchemaId, SecretSeal, Transition, TransitionBundle,
TransitionType, TypedAssigns, XChain, LIB_NAME_RGB_COMMIT,
};
Expand Down Expand Up @@ -236,8 +237,9 @@ pub struct BaseCommitment {
pub schema_id: SchemaId,
pub timestamp: i64,
pub issuer: StrictHash,
pub layer1: Layer1,
pub testnet: bool,
pub alt_layers1: StrictHash,
pub close_method: CloseMethod,
pub asset_tags: StrictHash,
}

Expand Down Expand Up @@ -280,8 +282,9 @@ impl Genesis {
flags: self.flags,
schema_id: self.schema_id,
timestamp: self.timestamp,
layer1: self.layer1,
testnet: self.testnet,
alt_layers1: self.alt_layers1.commit_id(),
close_method: self.close_method,
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,
};
10 changes: 6 additions & 4 deletions src/operation/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::str::FromStr;

use amplify::confinement::{Confined, SmallOrdSet, TinyOrdMap, TinyOrdSet};
use amplify::{hex, Wrapper};
use bp::seals::txout::CloseMethod;
use commit_verify::{
CommitEncode, CommitEngine, CommitId, Conceal, MerkleHash, MerkleLeaves, ReservedBytes,
StrictHash,
Expand All @@ -37,10 +38,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 @@ -359,8 +360,9 @@ pub struct Genesis {
pub flags: ReservedBytes<1, 0>,
pub timestamp: i64,
pub issuer: Identity,
pub layer1: Layer1,
pub testnet: bool,
pub alt_layers1: AltLayer1Set,
pub close_method: CloseMethod,
pub asset_tags: AssetTags,
pub metadata: Metadata,
pub globals: GlobalState,
Expand Down
19 changes: 5 additions & 14 deletions src/operation/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@
use core::fmt::Debug;
use std::hash::Hash;

use bp::dbc::Method;
pub use bp::seals::txout::blind::{ChainBlindSeal, ParseError, SingleBlindSeal};
pub use bp::seals::txout::TxoSeal;
use bp::seals::txout::{BlindSeal, CloseMethod, ExplicitSeal, SealTxid};
use bp::seals::txout::{BlindSeal, ExplicitSeal, SealTxid};
pub use bp::seals::SecretSeal;
use bp::{Outpoint, Txid, Vout};
use commit_verify::Conceal;
use strict_encoding::{StrictDecode, StrictDumb, StrictEncode};

use crate::{XChain, XOutpoint};

pub type GenesisSeal = SingleBlindSeal<Method>;
pub type GraphSeal = ChainBlindSeal<Method>;
pub type GenesisSeal = SingleBlindSeal;
pub type GraphSeal = ChainBlindSeal;

pub type OutputSeal = ExplicitSeal<Txid, Method>;
pub type OutputSeal = ExplicitSeal<Txid>;

pub type XGenesisSeal = XChain<GenesisSeal>;
pub type XGraphSeal = XChain<GraphSeal>;
Expand All @@ -62,13 +61,6 @@ impl ExposedSeal for GraphSeal {}
impl ExposedSeal for GenesisSeal {}

impl<Seal: TxoSeal> TxoSeal for XChain<Seal> {
fn method(&self) -> CloseMethod {
match self {
XChain::Bitcoin(seal) | XChain::Liquid(seal) => seal.method(),
XChain::Other(_) => unreachable!(),
}
}

fn txid(&self) -> Option<Txid> {
match self {
XChain::Bitcoin(seal) | XChain::Liquid(seal) => seal.txid(),
Expand Down Expand Up @@ -146,7 +138,6 @@ mod test {
#[test]
fn secret_seal_is_sha256d() {
let reveal = XChain::Bitcoin(BlindSeal {
method: CloseMethod::TapretFirst,
blinding: 54683213134637,
txid: TxPtr::Txid(
Txid::from_hex("646ca5c1062619e2a2d60771c9dfd820551fb773e4dc8c4ed67965a8d1fae839")
Expand All @@ -157,7 +148,7 @@ mod test {
let secret = reveal.to_secret_seal();
assert_eq!(
secret.to_string(),
"bc:utxob:lD72u61i-sxCEKth-vqjH0mI-kcEwa1Q-fbnPLon-tDtXveO-keHh0"
"bc:utxob:nBRVm39A-ioJydHE-ug2d90m-aZyfPI0-MCc0ZNM-oMXMs2O-opKQ7"
);
assert_eq!(reveal.to_secret_seal(), reveal.conceal())
}
Expand Down
47 changes: 4 additions & 43 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 All @@ -42,16 +41,17 @@ pub const XCHAIN_LIQUID_PREFIX: &str = "lq";

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display)]
#[display(lowercase)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[derive(StrictType, 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)]
#[derive(Default)]
pub enum Layer1 {
#[strict_type(dumb)]
#[default]
Bitcoin = 0,
Liquid = 1,
}
Expand Down Expand Up @@ -105,31 +105,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 +155,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:IJ8ChpTj-XMVz1y3-z15BDBB-huKjqsO-YswXmFV-XxCnB0Y#pamela-polka-corona";
/// 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:MGoAZ!ex-Mxxzq!6-Iwump4Y-K$enNGN-!Aa52Ms-b1r7WF8#satire-herbert-nato";

fn _rgb_commit_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_RGB_COMMIT), tiny_bset! {
Expand Down
2 changes: 1 addition & 1 deletion src/validation/consignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<'consignment, C: ConsignmentApi> CheckedConsignment<'consignment, C> {
pub fn new(consignment: &'consignment C) -> Self { Self(consignment) }
}

impl<'consignment, C: ConsignmentApi> ConsignmentApi for CheckedConsignment<'consignment, C> {
impl<C: ConsignmentApi> ConsignmentApi for CheckedConsignment<'_, C> {
fn schema(&self) -> &Schema { self.0.schema() }

fn types(&self) -> &TypeSystem { self.0.types() }
Expand Down
17 changes: 11 additions & 6 deletions src/validation/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use core::ops::AddAssign;
use std::fmt::{self, Display, Formatter};

use amplify::num::u24;
use bp::seals::txout::CloseMethod;
use commit_verify::mpc::InvalidProof;
use strict_types::SemId;

Expand All @@ -32,7 +33,7 @@ use crate::validation::WitnessResolverError;
use crate::vm::XWitnessId;
use crate::{
BundleId, ContractId, Layer1, OccurrencesMismatch, OpFullType, OpId, Opout, StateType, Vin,
XGraphSeal, XOutputSeal,
XGraphSeal,
};

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Display)]
Expand Down Expand Up @@ -251,6 +252,8 @@ pub enum Failure {
WitnessUnresolved(BundleId, XWitnessId, WitnessResolverError),
/// operation {0} is under a different contract {1}.
ContractMismatch(OpId, ContractId),
/// opout {0} appears more than once as input
DoubleSpend(Opout),

// Errors checking bundle commitments
/// transition bundle {0} references state transition {1} which is not
Expand Down Expand Up @@ -288,11 +291,8 @@ pub enum Failure {
SealNoPubWitness(BundleId, XWitnessId, WitnessResolverError),
/// witness layer 1 {anchor} doesn't match seal definition {seal}.
SealWitnessLayer1Mismatch { seal: Layer1, anchor: Layer1 },
/// seal {1} is defined on {0} which is not in the set of layers allowed
/// by the contract genesis.
SealLayerMismatch(Layer1, XGraphSeal),
/// seal {1} has a different closing method from the bundle {0} requirement.
SealInvalidMethod(BundleId, XOutputSeal),
/// seal {0} is defined on {1} which is not the layer 1 defined by the contract genesis ({2}).
SealLayerMismatch(XGraphSeal, Layer1, Layer1),
/// transition bundle {0} doesn't close seal with the witness {1}. Details:
/// {2}
SealsInvalid(BundleId, XWitnessId, String),
Expand All @@ -306,6 +306,11 @@ pub enum Failure {
/// Details: {2}
MpcInvalid(BundleId, XWitnessId, InvalidProof),

/// anchor close method {0} is different from the one of the contract {1}
AnchorInvalidMethod(CloseMethod, CloseMethod),
/// bundle close method {0} is different from the one of the contract {1}
BundleInvalidMethod(CloseMethod, CloseMethod),

// State extensions errors
/// valency {valency} redeemed by state extension {opid} references
/// non-existing operation {prev_id}
Expand Down
Loading
Loading