Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# Changelog

## 6.0.0

### Removed (BREAKING)

- `DigCollateralCoin::morph_store_launcher_id_for_mirror` and
`DigCollateralCoin::create_mirror`. Mirror collateral is owned by the
`dig-mirror-coin` crate; use `dig_mirror_coin::mirror_hint` and
`dig_mirror_coin::create` instead.

These were removed rather than renamed because they did not merely share the
`DIG_STORE_MIRROR_COLLATERAL` tag with `dig-mirror-coin` — they occupied the
*same* namespace. `dig-mirror-coin` derives a mirror hint from
`morph(store + root + owner + epoch)` under that tag; this crate derived one
from `morph(store + epoch)`. Because both hash an additive sum, the extra
terms are absorbed rather than separating the two, so an author who chooses
the epoch freely can solve `e' = store + epoch - store' - root' - owner'` and
land a coin bonding their own store and root exactly on a hint derived here.

`dig-mirror-coin` defeats that one level up: its coins **declare** their four
terms and `MirrorCoin::advertises` checks the declaration term by term as well
as recomputing the hint. The two-term form had no such check and could not
gain one, because the epoch a coin was really built with is not recoverable
from its hint.

Coins already minted through the removed path are unaffected.
Comment thread
MichaelTaylor3d marked this conversation as resolved.
`DigCollateralCoin::from_coin_state` reads the morphed id out of the coin's
memos and never recomputes it, and `DigCollateralCoin::spend` does not use the
hint, so existing mirror coins remain readable and spendable.

- `DigCollateralCoin::morph_store_launcher_id_for_collateral` and the
store-collateral path are unchanged.
Comment thread
MichaelTaylor3d marked this conversation as resolved.

## 4.0.0

- Migrate the chia-family dependencies from the 0.30 to the 0.34 family
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [".", "napi"]
[package]
edition = "2021"
name = "datalayer-driver"
version = "5.0.0"
version = "6.0.0"
license = "MIT"
authors = ["yakuhito <y@kuhi.to>", "William Wills <wwills2@protonmail.com>"]
homepage = "https://github.com/DIG-Network/DataLayer-Driver"
Expand Down
2 changes: 1 addition & 1 deletion napi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dignetwork/datalayer-driver",
"version": "5.0.0",
"version": "6.0.0",
"main": "index.js",
"types": "index.d.ts",
"repository": {
Expand Down
69 changes: 21 additions & 48 deletions src/dig_collateral_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,28 @@ use chia_wallet_sdk::prelude::{AssertConcurrentSpend, Conditions, ToTreeHash, MA
use clvm_traits::{FromClvm, ToClvm};
use clvmr::Allocator;
use indexmap::indexmap;
use num_bigint::BigInt;

/// A `$DIG` collateral coin.
///
/// # The mirror-collateral namespace is not served here
///
/// This type once also derived and minted **mirror** collateral coins, under the namespace tag
/// `DIG_STORE_MIRROR_COLLATERAL`, from `morph(store_launcher_id + epoch)`. Both the morph and its
/// mint path (`morph_store_launcher_id_for_mirror`, `create_mirror`) were removed in 6.0.0.
///
/// They were removed rather than renamed because they were not a second namespace that merely
/// shared a tag — they were the *same* namespace as the canonical one. `dig-mirror-coin` hints a
/// mirror coin under `morph(store + root + owner + epoch)` beneath that identical tag, and because
/// both morphs hash an additive sum, the extra terms are absorbed rather than separating: an author
/// who freely chooses the epoch can solve `e' = store + epoch - store' - root' - owner'` and land a
/// coin bonding their own store and root exactly on a hint derived here. `dig-mirror-coin` closes
/// that one level up, by having the coin *declare* its four terms and checking the declaration as
/// well as the recompute; the two-term form had no such check and no way to add one, since the
/// epoch it was built with is not recoverable from the hint.
///
/// Mirror collateral therefore has a single owner: use the `dig-mirror-coin` crate. Coins already
/// minted through the removed path are unaffected — [`Self::from_coin_state`] reads the morphed id
/// out of the coin's memos and never recomputes it, and [`Self::spend`] does not use the hint.
Comment thread
MichaelTaylor3d marked this conversation as resolved.
#[derive(Debug, Clone)]
pub struct DigCollateralCoin {
inner: P2ParentCoin,
Expand All @@ -40,19 +60,6 @@ impl DigCollateralCoin {
.into()
}

/// Morphs a DIG store launcher ID into the DIG mirror collateral coin namespace.
pub fn morph_store_launcher_id_for_mirror(
store_launcher_id: Bytes32,
offset: &BigInt,
) -> Bytes32 {
let launcher_id_int = BigInt::from_signed_bytes_be(&store_launcher_id);
let offset_launcher_id = launcher_id_int + offset;

(offset_launcher_id, "DIG_STORE_MIRROR_COLLATERAL")
.tree_hash()
.into()
}

/// Instantiates a $DIG collateral coin
/// Verifies that coin is unspent and locked by the $DIG P2Parent puzzle
pub async fn from_coin_state(peer: &Peer, coin_state: CoinState) -> Result<Self, WalletError> {
Expand Down Expand Up @@ -174,40 +181,6 @@ impl DigCollateralCoin {
)
}

#[allow(clippy::result_large_err, clippy::too_many_arguments)]
pub fn create_mirror(
dig_coins: Vec<DigCoin>,
amount: u64,
store_id: Bytes32,
mirror_urls: Vec<String>,
epoch: BigInt,
synthetic_key: PublicKey,
fee_coins: Vec<Coin>,
fee: u64,
) -> Result<Vec<CoinSpend>, WalletError> {
let mut ctx = SpendContext::new();
let morphed_store_id = Self::morph_store_launcher_id_for_mirror(store_id, &epoch);
let mut memos_vec = Vec::with_capacity(mirror_urls.len() + 1);
memos_vec.push(morphed_store_id.to_vec());

for url in &mirror_urls {
memos_vec.push(url.as_bytes().to_vec());
}

let memos_node_ptr = ctx.alloc(&memos_vec)?;
let memos = Memos::Some(memos_node_ptr);

Self::build_coin_spends(
&mut ctx,
memos,
dig_coins,
amount,
synthetic_key,
fee_coins,
fee,
)
}

/// Builds the spend bundle for spending the $DIG collateral coin to de-collateralize
/// the store and return spendable $DIG to the wallet that created the collateral coin.
#[allow(clippy::result_large_err)]
Expand Down
Loading