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

Cross-chain secret seals. Better and more stable cross-chain APIs #199

Merged
merged 11 commits into from
Jan 6, 2024
Merged
42 changes: 21 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rgb-core"
version = "0.11.0-beta.3"
version = "0.11.0-beta.4"
authors = ["Dr Maxim Orlovsky <[email protected]>"]
description = "RGB Core Library: confidential & scalable smart contracts on Bitcoin & Lightning (consensus layer)"
repository = "https://github.com/RGB-WG/rgb-core"
Expand All @@ -23,12 +23,12 @@ required-features = ["stl"]

[dependencies]
amplify = { version = "~4.5.0", features = ["rand"] }
strict_encoding = "~2.6.1"
strict_encoding = "~2.6.2"
strict_types = "~1.6.3"
aluvm = { version = "~0.11.0-beta.2", features = ["std"] }
commit_verify = { version = "~0.11.0-beta.2", features = ["rand", "derive"] }
single_use_seals = "~0.11.0-beta.2"
bp-core = { version = "~0.11.0-beta.2" }
commit_verify = { version = "~0.11.0-beta.3", features = ["rand", "derive"] }
single_use_seals = "~0.11.0-beta.3"
bp-core = { version = "~0.11.0-beta.3" }
secp256k1-zkp = { version = "0.9.2", features = ["rand", "rand-std", "global-context"] } # TODO: Update version before the release
baid58 = "~0.4.4"
mime = "~0.3.17"
Expand Down
50 changes: 8 additions & 42 deletions src/contract/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use commit_verify::mpc;
use strict_encoding::StrictDumb;

use crate::{BundleId, ContractId, TransitionBundle, WitnessId, WitnessOrd, LIB_NAME_RGB};
use crate::{BundleId, ContractId, TransitionBundle, WitnessId, WitnessOrd, XChain, LIB_NAME_RGB};

#[derive(Clone, Eq, PartialEq, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
Expand All @@ -49,48 +49,14 @@
pub fn bundle_id(&self) -> BundleId { self.bundle.bundle_id() }
}

#[derive(Clone, Eq, PartialEq, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB, tags = custom, dumb = Self::Bitcoin(strict_dumb!()))]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub enum XAnchor<P: mpc::Proof + StrictDumb = mpc::MerkleProof> {
#[strict_type(tag = 0x00)]
Bitcoin(AnchorSet<P>),

#[strict_type(tag = 0x01)]
Liquid(AnchorSet<P>),
}
pub type XAnchor<P = mpc::MerkleProof> = XChain<AnchorSet<P>>;

impl<P: mpc::Proof + StrictDumb> XAnchor<P> {
#[inline]
pub fn layer1(&self) -> Layer1 {
match self {
XAnchor::Bitcoin(_) => Layer1::Bitcoin,
XAnchor::Liquid(_) => Layer1::Liquid,
}
}
pub fn witness_id(&self) -> Option<WitnessId> { self.maybe_map_ref(|set| set.txid()) }

Check warning on line 56 in src/contract/anchor.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/anchor.rs#L56

Added line #L56 was not covered by tests

#[inline]
pub fn witness_id(&self) -> WitnessId {
match self {
XAnchor::Bitcoin(anchor) => WitnessId::Bitcoin(anchor.txid_unchecked()),
XAnchor::Liquid(anchor) => WitnessId::Liquid(anchor.txid_unchecked()),
}
}

fn map<Q: mpc::Proof + StrictDumb, E>(
self,
f: impl FnOnce(AnchorSet<P>) -> Result<AnchorSet<Q>, E>,
) -> Result<XAnchor<Q>, E> {
match self {
XAnchor::Bitcoin(anchor) => f(anchor).map(XAnchor::Bitcoin),
XAnchor::Liquid(anchor) => f(anchor).map(XAnchor::Liquid),
}
}
pub fn witness_id_unchecked(&self) -> WitnessId { self.map_ref(|set| set.txid_unchecked()) }

Check warning on line 59 in src/contract/anchor.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/anchor.rs#L59

Added line #L59 was not covered by tests
}

impl XAnchor<mpc::MerkleBlock> {
Expand All @@ -111,7 +77,7 @@
self,
contract_id: ContractId,
) -> Result<XAnchor<mpc::MerkleProof>, mpc::LeafNotKnown> {
self.map(|a| a.into_merkle_proof(contract_id))
self.try_map(|a| a.into_merkle_proof(contract_id))

Check warning on line 80 in src/contract/anchor.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/anchor.rs#L80

Added line #L80 was not covered by tests
}
}

Expand All @@ -129,7 +95,7 @@
contract_id: ContractId,
bundle_id: BundleId,
) -> Result<XAnchor<mpc::MerkleBlock>, mpc::InvalidProof> {
self.map(|a| a.into_merkle_block(contract_id, bundle_id))
self.try_map(|a| a.into_merkle_block(contract_id, bundle_id))

Check warning on line 98 in src/contract/anchor.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/anchor.rs#L98

Added line #L98 was not covered by tests
}
}

Expand Down Expand Up @@ -163,11 +129,11 @@
}
}

pub(crate) fn txid_unchecked(&self) -> Txid {
pub fn txid_unchecked(&self) -> Txid {

Check warning on line 132 in src/contract/anchor.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/anchor.rs#L132

Added line #L132 was not covered by tests
match self {
AnchorSet::Tapret(a) => a.txid,
AnchorSet::Opret(a) => a.txid,
AnchorSet::Dual { tapret, .. } => tapret.txid,
AnchorSet::Dual { tapret, opret: _ } => tapret.txid,

Check warning on line 136 in src/contract/anchor.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/anchor.rs#L136

Added line #L136 was not covered by tests
}
}

Expand Down
35 changes: 19 additions & 16 deletions src/contract/assignments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
use crate::contract::seal::GenesisSeal;
use crate::{
AssignmentType, ExposedSeal, GraphSeal, RevealedAttach, RevealedData, RevealedValue,
SecretSeal, StateType, VoidState, XSeal, LIB_NAME_RGB,
SecretSeal, StateType, VoidState, XChain, LIB_NAME_RGB,
};

#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Display, Error)]
Expand Down Expand Up @@ -72,16 +72,19 @@
pub enum Assign<State: ExposedState, Seal: ExposedSeal> {
#[strict_type(tag = 0x00)]
Confidential {
seal: SecretSeal,
seal: XChain<SecretSeal>,
state: State::Confidential,
},
#[strict_type(tag = 0x03)]
Revealed { seal: XSeal<Seal>, state: State },
Revealed { seal: XChain<Seal>, state: State },
#[strict_type(tag = 0x02)]
ConfidentialSeal { seal: SecretSeal, state: State },
ConfidentialSeal {
seal: XChain<SecretSeal>,
state: State,
},
#[strict_type(tag = 0x01)]
ConfidentialState {
seal: XSeal<Seal>,
seal: XChain<Seal>,
state: State::Confidential,
},
}
Expand Down Expand Up @@ -118,9 +121,9 @@
}

impl<State: ExposedState, Seal: ExposedSeal> Assign<State, Seal> {
pub fn revealed(seal: XSeal<Seal>, state: State) -> Self { Assign::Revealed { seal, state } }
pub fn revealed(seal: XChain<Seal>, state: State) -> Self { Assign::Revealed { seal, state } }

Check warning on line 124 in src/contract/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/assignments.rs#L124

Added line #L124 was not covered by tests

pub fn with_seal_replaced(assignment: &Self, seal: XSeal<Seal>) -> Self {
pub fn with_seal_replaced(assignment: &Self, seal: XChain<Seal>) -> Self {

Check warning on line 126 in src/contract/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/assignments.rs#L126

Added line #L126 was not covered by tests
match assignment {
Assign::Confidential { seal: _, state } |
Assign::ConfidentialState { seal: _, state } => Assign::ConfidentialState {
Expand All @@ -136,7 +139,7 @@
}
}

pub fn to_confidential_seal(&self) -> SecretSeal {
pub fn to_confidential_seal(&self) -> XChain<SecretSeal> {

Check warning on line 142 in src/contract/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/assignments.rs#L142

Added line #L142 was not covered by tests
match self {
Assign::Revealed { seal, .. } | Assign::ConfidentialState { seal, .. } => {
seal.conceal()
Expand All @@ -145,7 +148,7 @@
}
}

pub fn revealed_seal(&self) -> Option<XSeal<Seal>> {
pub fn revealed_seal(&self) -> Option<XChain<Seal>> {

Check warning on line 151 in src/contract/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/assignments.rs#L151

Added line #L151 was not covered by tests
match self {
Assign::Revealed { seal, .. } | Assign::ConfidentialState { seal, .. } => Some(*seal),
Assign::Confidential { .. } | Assign::ConfidentialSeal { .. } => None,
Expand Down Expand Up @@ -182,21 +185,21 @@
}
}

pub fn as_revealed(&self) -> Option<(&XSeal<Seal>, &State)> {
pub fn as_revealed(&self) -> Option<(&XChain<Seal>, &State)> {

Check warning on line 188 in src/contract/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/assignments.rs#L188

Added line #L188 was not covered by tests
match self {
Assign::Revealed { seal, state } => Some((seal, state)),
_ => None,
}
}

pub fn to_revealed(&self) -> Option<(XSeal<Seal>, State)> {
pub fn to_revealed(&self) -> Option<(XChain<Seal>, State)> {

Check warning on line 195 in src/contract/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/assignments.rs#L195

Added line #L195 was not covered by tests
match self {
Assign::Revealed { seal, state } => Some((*seal, state.clone())),
_ => None,
}
}

pub fn into_revealed(self) -> Option<(XSeal<Seal>, State)> {
pub fn into_revealed(self) -> Option<(XChain<Seal>, State)> {

Check warning on line 202 in src/contract/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/assignments.rs#L202

Added line #L202 was not covered by tests
match self {
Assign::Revealed { seal, state } => Some((seal, state)),
_ => None,
Expand Down Expand Up @@ -240,11 +243,11 @@
state.commit_encode(e);
}
Assign::ConfidentialState { seal, state } => {
seal.commit_encode(e);
seal.conceal().commit_encode(e);

Check warning on line 246 in src/contract/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/assignments.rs#L246

Added line #L246 was not covered by tests
state.commit_encode(e);
}
Assign::Revealed { seal, state } => {
seal.commit_encode(e);
seal.conceal().commit_encode(e);

Check warning on line 250 in src/contract/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/assignments.rs#L250

Added line #L250 was not covered by tests
state.commit_encode(e);
}
Assign::ConfidentialSeal { seal, state } => {
Expand Down Expand Up @@ -445,7 +448,7 @@
/// If seal definition does not exist, returns [`UnknownDataError`]. If the
/// seal is confidential, returns `Ok(None)`; otherwise returns revealed
/// seal data packed as `Ok(Some(`[`Seal`]`))`
pub fn revealed_seal_at(&self, index: u16) -> Result<Option<XSeal<Seal>>, UnknownDataError> {
pub fn revealed_seal_at(&self, index: u16) -> Result<Option<XChain<Seal>>, UnknownDataError> {

Check warning on line 451 in src/contract/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/assignments.rs#L451

Added line #L451 was not covered by tests
Ok(match self {
TypedAssigns::Declarative(vec) => vec
.get(index as usize)
Expand All @@ -466,7 +469,7 @@
})
}

pub fn to_confidential_seals(&self) -> Vec<SecretSeal> {
pub fn to_confidential_seals(&self) -> Vec<XChain<SecretSeal>> {

Check warning on line 472 in src/contract/assignments.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/assignments.rs#L472

Added line #L472 was not covered by tests
match self {
TypedAssigns::Declarative(s) => s
.iter()
Expand Down
Loading
Loading