Repository navigation
fix(lib): do not stamp a sibling with the caller's _root - #548
ClemensLey wants to merge 4 commits into
Conversation
A call on a claimed mint copies that mint's _root onto a second Commodity created in the same transaction. The sibling has an empty salt and an amount the mint did not pay, and isGenuine() returns true. The test fails on that result. The contract is unchanged.
A new object kept the root of the last call in the transaction, so a sibling constructed beside a call on a mint was stamped with that mint. The published library and node bundles now follow the source rule: a new inherits _root only while a method of an object that already has one is executing. The rebuilt client types also accept the block keyset cursor (orderBy: 'block', ltBlockHeight, ltBlockIndex, ltRev).
The sibling is its own creation output. Its root is its id, and isGenuine() stays false after the transaction is indexed.
TypeScript could not resolve @bitcoin-computer/commodity because the package had no main or types. The build now emits declarations at build/src/index, and CommodityHelper deploys the TBC777 chain. merge still throws. It accepts the TBC20 argument so a caller that passes the bags it meant to combine still typechecks.
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The behavioral fix is in an external published library and the bulk of the diff is large regenerated minified artifacts that can't be meaningfully verified here, plus the commodity main/types publish config excludes the build/ output from files.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
This PR packages the @bitcoin-computer/commodity module for consumption and adds a regression test for a @bitcoin-computer/lib fix: a new executed as a sibling of a method call used to inherit the caller's _root, which let a sibling token falsely pass Commodity.isGenuine(). The actual framework fix lives in the external published lib (sourced from the report/commodity-inherited-root branch); here the committed packages/node/dist/*.mjs bundles and packages/lib/types are regenerated, and the commodity package gains a public entry point plus a CommodityHelper.
Changes:
- Add a package entry point (
src/index.ts,main/types,declaration: true) and aCommodityHelperthat deploys the TBC777 inheritance chain and exposesmint/balanceOf/transfer; relaxmerge()to accept (and ignore) atokensarg so it matches the TBC20 call shape while still throwing. - Add a mocha test asserting a sibling-constructed
Commoditygets its own_rootand failsisGenuine(). - Regenerate committed artifacts:
node/distbundles andlib/types(introducinggetTXOsblock-cursor fieldsltBlockHeight/ltBlockIndex/ltRevandTXOOrderBy: 'block', which are unrelated to the stated_rootfix).
| File | Description |
|---|---|
| packages/commodity/src/index.ts | New barrel export for Commodity, config, CommodityHelper, Sha256 (all resolve). |
| packages/commodity/src/helper.ts | New CommodityHelper; duplicates the test's inline stripComments/deploy logic. |
| packages/commodity/src/commodity.ts | merge() now accepts an ignored tokens? param; still throws. |
| packages/commodity/package.json | Adds main/types into build/ and renames the esbuild output to commodity.bundle.js; files still excludes build. |
| packages/commodity/tsconfig.release.json | Enables declaration so .d.ts are emitted for types. |
| packages/commodity/test/commodity.test.ts | New inherited _root test validating the sibling _root fix. |
| packages/lib/types/src/types.d.ts | Adds block-cursor query fields and 'block' order. |
| packages/lib/types/src/root-lineage.d.ts | New empty ambient module file. |
| packages/node/dist/bcn.es.mjs, bcn.sync.es.mjs | Regenerated minified server bundles (committed artifacts). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| "main": "./build/src/index.js", | ||
| "types": "./build/src/index.d.ts", |

A
newused to inherit_rootfrom the last call in the transaction. A sibling constructed beside a call on a claimed mint therefore carried that mint's root.isGenuine()only checks that the object at_roothas a non-empty salt, so the sibling passed even though the mint did not pay its amount.The published library now inherits
_rootonly while a method of an object that already has one is executing. The frame ends when that call returns, including at an async method's first await. The commodity test expects the sibling to be its own creation output andisGenuine()to be false.@bitcoin-computer/commodityalso publishesmainandtypes, andCommodityHelperdeploys the TBC777 chain.mergestill throws.The library source is Bitcoin-Computer-Secrets/workspace branch
report/commodity-inherited-root.