diff --git a/CHANGELOG.md b/CHANGELOG.md index 485fde6..660c402 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. + `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. + ## 4.0.0 - Migrate the chia-family dependencies from the 0.30 to the 0.34 family diff --git a/Cargo.lock b/Cargo.lock index f1cab47..ff59dea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1071,7 +1071,7 @@ checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476" [[package]] name = "datalayer-driver" -version = "5.0.0" +version = "6.0.0" dependencies = [ "anyhow", "chia-bls 0.36.1", diff --git a/Cargo.toml b/Cargo.toml index 53ada75..e722a68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ members = [".", "napi"] [package] edition = "2021" name = "datalayer-driver" -version = "5.0.0" +version = "6.0.0" license = "MIT" authors = ["yakuhito ", "William Wills "] homepage = "https://github.com/DIG-Network/DataLayer-Driver" diff --git a/napi/package.json b/napi/package.json index 75b85ff..c3e1a93 100644 --- a/napi/package.json +++ b/napi/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/datalayer-driver", - "version": "5.0.0", + "version": "6.0.0", "main": "index.js", "types": "index.d.ts", "repository": { diff --git a/src/dig_collateral_coin.rs b/src/dig_collateral_coin.rs index cb32056..ba32862 100644 --- a/src/dig_collateral_coin.rs +++ b/src/dig_collateral_coin.rs @@ -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. #[derive(Debug, Clone)] pub struct DigCollateralCoin { inner: P2ParentCoin, @@ -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 { @@ -174,40 +181,6 @@ impl DigCollateralCoin { ) } - #[allow(clippy::result_large_err, clippy::too_many_arguments)] - pub fn create_mirror( - dig_coins: Vec, - amount: u64, - store_id: Bytes32, - mirror_urls: Vec, - epoch: BigInt, - synthetic_key: PublicKey, - fee_coins: Vec, - fee: u64, - ) -> Result, 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)]