Skip to content

Commit

Permalink
validation: use new closing method API from DBC
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 12, 2024
1 parent b3be9b5 commit 6ea499d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
12 changes: 4 additions & 8 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ wasm-bindgen-test = "0.3"

[package.metadata.docs.rs]
features = ["all"]

[patch.crates-io]
bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "methods" }
bp-dbc = { git = "https://github.com/BP-WG/bp-core", branch = "methods" }
bp-seals = { git = "https://github.com/BP-WG/bp-core", branch = "methods" }
bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "methods" }
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:ZMTVCU25-QDo98xR-wI91wcu-ydb7kui-QfZbF$n-0KDS2ow#tuna-safari-design";
"stl:IFcnrPeI-TANxLfZ-feJax6Q-1TUM4Hq-AjI161s-3tbmxak#harvest-person-orion";
/// Strict types id for the library providing data types for RGB consensus.
pub const LIB_ID_RGB_LOGIC: &str =
"stl:bioTBozT-NqelHGE-SPbnpMA-XBNSbXZ-6X0dANE-WHVirL8#explain-marvin-bless";
"stl:i$!X9ANw-DGnAZEL-Tyvq9T1-n$BTbIG-DpcR!s1-mwKtnXA#rapid-baboon-satire";

fn _rgb_commit_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_RGB_COMMIT), tiny_bset! {
Expand Down
8 changes: 7 additions & 1 deletion src/validation/commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ impl StrictDeserialize for DbcProof {}

impl dbc::Proof for DbcProof {
type Error = DbcError;
const METHOD: Method = Method::OpretFirst;

fn method(&self) -> Method {
match self {
DbcProof::Tapret(_) => Method::TapretFirst,
DbcProof::Opret(_) => Method::OpretFirst,

Check warning on line 93 in src/validation/commitments.rs

View check run for this annotation

Codecov / codecov/patch

src/validation/commitments.rs#L90-L93

Added lines #L90 - L93 were not covered by tests
}
}

Check warning on line 95 in src/validation/commitments.rs

View check run for this annotation

Codecov / codecov/patch

src/validation/commitments.rs#L95

Added line #L95 was not covered by tests

fn verify(&self, msg: &Commitment, tx: &Tx) -> Result<(), Self::Error> {
match self {
Expand Down
22 changes: 9 additions & 13 deletions src/validation/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet};
use std::rc::Rc;

use bp::dbc::Anchor;
use bp::seals::txout::{CloseMethod, TxoSeal, Witness};
use bp::dbc::{Anchor, Proof};
use bp::seals::txout::{TxoSeal, Witness};
use bp::{dbc, Outpoint};
use commit_verify::mpc;
use single_use_seals::SealWitness;
Expand Down Expand Up @@ -395,7 +395,7 @@ impl<
// [VALIDATION]: We validate that the seals were properly defined on BP-type layers
let (seals, input_map) = self.validate_seal_definitions(witness_id.layer1(), bundle);

if anchor.method != bundle.close_method {
if anchor.dbc_proof.method() != bundle.close_method {
self.status
.borrow_mut()
.add_failure(Failure::AnchorMethodMismatch(bundle_id));
Expand Down Expand Up @@ -482,7 +482,10 @@ impl<
}
Ok(pub_witness) => {
let seals = seals.as_ref();
for seal in seals.iter().filter(|seal| seal.method() != anchor.method) {
for seal in seals
.iter()
.filter(|seal| seal.method() != anchor.dbc_proof.method())
{

Check warning on line 488 in src/validation/validator.rs

View check run for this annotation

Codecov / codecov/patch

src/validation/validator.rs#L485-L488

Added lines #L485 - L488 were not covered by tests
self.status
.borrow_mut()
.add_failure(Failure::SealInvalidMethod(bundle_id, *seal));
Expand All @@ -491,26 +494,19 @@ impl<
EAnchor {
mpc_proof,
dbc_proof: DbcProof::Tapret(tapret),
method: CloseMethod::TapretFirst,
..
} => {

Check warning on line 498 in src/validation/validator.rs

View check run for this annotation

Codecov / codecov/patch

src/validation/validator.rs#L493-L498

Added lines #L493 - L498 were not covered by tests
let witness = pub_witness.clone().map(|tx| Witness::with(tx, tapret));
self.validate_seal_closing(seals, bundle_id, witness, mpc_proof)
}
EAnchor {
mpc_proof,
dbc_proof: DbcProof::Opret(opret),
method: CloseMethod::OpretFirst,
..
} => {

Check warning on line 506 in src/validation/validator.rs

View check run for this annotation

Codecov / codecov/patch

src/validation/validator.rs#L502-L506

Added lines #L502 - L506 were not covered by tests
let witness = pub_witness.clone().map(|tx| Witness::with(tx, opret));
self.validate_seal_closing(seals, bundle_id, witness, mpc_proof)
}
_ => {
panic!(
"RGB standard library consignment implementation provides with \
anchors which DBC proof method doesn't match the anchor method. The \
RGB standard library used by this software is broken"
)
}
}

Some(pub_witness)
Expand Down

0 comments on commit 6ea499d

Please sign in to comment.