Skip to content

Commit

Permalink
unified seals
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedberg committed Jan 29, 2025
1 parent aec5944 commit 657ab35
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 329 deletions.
8 changes: 1 addition & 7 deletions src/operation/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use std::collections::{btree_map, BTreeMap};

use amplify::confinement::{Confined, U16 as U16MAX};
use amplify::{Bytes32, Wrapper};
use bp::seals::txout::CloseMethod;
use bp::Vout;
use commit_verify::{mpc, CommitEncode, CommitEngine, CommitId, CommitmentId, DigestExt, Sha256};
use strict_encoding::{StrictDumb, StrictEncode};
Expand Down Expand Up @@ -109,24 +108,19 @@ impl<'a> IntoIterator for &'a InputMap {
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct TransitionBundle {
pub close_method: CloseMethod,
pub input_map: InputMap,
pub known_transitions: Confined<BTreeMap<OpId, Transition>, 1, U16MAX>,
}

impl CommitEncode for TransitionBundle {
type CommitmentId = BundleId;

fn commit_encode(&self, e: &mut CommitEngine) {
e.commit_to_serialized(&self.close_method);
e.commit_to_serialized(&self.input_map);
}
fn commit_encode(&self, e: &mut CommitEngine) { e.commit_to_serialized(&self.input_map); }
}

impl StrictDumb for TransitionBundle {
fn strict_dumb() -> Self {
Self {
close_method: strict_dumb!(),
input_map: strict_dumb!(),
known_transitions: Confined::with_key_value(strict_dumb!(), strict_dumb!()),
}
Expand Down
3 changes: 0 additions & 3 deletions src/operation/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ 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 Down Expand Up @@ -239,7 +238,6 @@ pub struct BaseCommitment {
pub issuer: StrictHash,
pub layer1: Layer1,
pub testnet: bool,
pub close_method: CloseMethod,
}

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
Expand Down Expand Up @@ -283,7 +281,6 @@ impl Genesis {
timestamp: self.timestamp,
layer1: self.layer1,
testnet: self.testnet,
close_method: self.close_method,
issuer: self.issuer.commit_id(),
};
OpCommitment {
Expand Down
2 changes: 0 additions & 2 deletions src/operation/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ 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 Down Expand Up @@ -346,7 +345,6 @@ pub struct Genesis {
pub issuer: Identity,
pub layer1: Layer1,
pub testnet: bool,
pub close_method: CloseMethod,
pub metadata: Metadata,
pub globals: GlobalState,
pub assignments: Assignments<GenesisSeal>,
Expand Down
4 changes: 2 additions & 2 deletions src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ use crate::{

/// Strict types id for the library providing data types for RGB consensus.
pub const LIB_ID_RGB_COMMIT: &str =
"stl:nX8j7yoL-WB1gVNN-JHgJDvZ-UL8177c-Hexose2-JYJs1Bs#level-exodus-final";
"stl:FjjU0$$o-dgf5dmK-ohaEobc-Y6Vz3rp-TqLj3kS-8F7NMQQ#capsule-arthur-quest";
/// Strict types id for the library providing data types for RGB consensus.
pub const LIB_ID_RGB_LOGIC: &str =
"stl:E2vH0scY-5u2NHhW-M5$ZWEP-33VJvaA-yeF1fVR-37IJ1ak#nitro-sandra-salami";
"stl:iLZ2rLhr-oAp7rHh-cX2LO3T-7evttnL-KT6MX!V-m64WEyQ#janet-mineral-phone";

fn _rgb_commit_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_RGB_COMMIT), tiny_bset! {
Expand Down
13 changes: 5 additions & 8 deletions src/validation/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,14 @@ pub enum Failure {
/// single-use seals for the operation {0} were not validated, which
/// probably indicates unanchored state transition.
SealsUnvalidated(OpId),
/// anchor provides different type of DBC proof than required by the bundle
/// {0}.
AnchorMethodMismatch(BundleId),
/// transition bundle {0} is not properly anchored to the witness {1}.
/// Details: {2}
MpcInvalid(BundleId, Txid, 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),
/// witness transaction {0} has no taproot or OP_RETURN output.
NoDbcOutput(Txid),
/// first DBC-compatible output of witness transaction {0} doesn't match the provided proof
/// type ({1})
InvalidProofType(Txid, CloseMethod),

// State extensions errors
/// valency {valency} redeemed by state extension {opid} references
Expand Down
52 changes: 23 additions & 29 deletions src/validation/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet};
use std::rc::Rc;

use bp::dbc::{Anchor, Proof};
use bp::dbc::Anchor;
use bp::seals::txout::{CloseMethod, Witness};
use bp::{dbc, Outpoint, Tx, Txid};
use commit_verify::mpc;
Expand Down Expand Up @@ -119,7 +119,6 @@ pub struct Validator<

schema_id: SchemaId,
contract_id: ContractId,
close_method: CloseMethod,

contract_state: Rc<RefCell<S>>,
validated_op_seals: RefCell<BTreeSet<OpId>>,
Expand All @@ -146,7 +145,6 @@ impl<
let genesis = consignment.genesis();
let contract_id = genesis.contract_id();
let schema_id = genesis.schema_id;
let close_method = genesis.close_method;

// Prevent repeated validation of single-use seals
let validated_op_seals = RefCell::new(BTreeSet::<OpId>::new());
Expand All @@ -157,7 +155,6 @@ impl<
status: RefCell::new(status),
schema_id,
contract_id,
close_method,
validated_op_seals,
input_assignments: input_transitions,
resolver: CheckedWitnessResolver::from(resolver),
Expand Down Expand Up @@ -381,31 +378,6 @@ impl<
// [VALIDATION]: We validate that the seals were properly defined on BP-type layer
let (seals, input_map) = self.validate_seal_definitions(bundle);

if self.close_method != anchor.dbc_proof.method() {
self.status
.borrow_mut()
.add_failure(Failure::AnchorInvalidMethod(
anchor.dbc_proof.method(),
self.close_method,
));
continue;
}
if self.close_method != bundle.close_method {
self.status
.borrow_mut()
.add_failure(Failure::BundleInvalidMethod(
bundle.close_method,
self.close_method,
));
continue;
}
if anchor.dbc_proof.method() != bundle.close_method {
self.status
.borrow_mut()
.add_failure(Failure::AnchorMethodMismatch(bundle_id));
continue;
}

// [VALIDATION]: We validate that the seals were properly closed on BP-type layer
let Some(witness_tx) =
self.validate_seal_commitments(&seals, bundle_id, witness_id, anchor)
Expand Down Expand Up @@ -624,6 +596,28 @@ impl<
.add_failure(Failure::MpcInvalid(bundle_id, witness_id, err));
}
Ok(commitment) => {
// [VALIDATION]: Verify commitment
let Some(output) = witness
.tx
.outputs()
.find(|out| out.script_pubkey.is_op_return() || out.script_pubkey.is_p2tr())
else {
self.status
.borrow_mut()
.add_failure(Failure::NoDbcOutput(witness_id));
return;
};
let output_method = if output.script_pubkey.is_op_return() {
CloseMethod::OpretFirst
} else {
CloseMethod::TapretFirst
};
let proof_method = witness.proof.method();
if proof_method != output_method {
self.status
.borrow_mut()
.add_failure(Failure::InvalidProofType(witness_id, proof_method));
}
// [VALIDATION]: CHECKING SINGLE-USE-SEALS
witness
.verify_many_seals(seals, &commitment)
Expand Down
1 change: 0 additions & 1 deletion stl/AnchoredBundle.vesper
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Bundles vesper lexicon=types+commitments

BundleId commitment hasher=SHA256 tagged=urn:lnp-bp:rgb:bundle#2024-02-03
Method serialized
InputMap serialized

DbcProof union
Expand Down
Loading

0 comments on commit 657ab35

Please sign in to comment.