Skip to content

fix(lib): do not stamp a sibling with the caller's _root - #548

Closed
ClemensLey wants to merge 4 commits into
stagingfrom
report/commodity-inherited-root
Closed

ClemensLey wants to merge 4 commits into
stagingfrom
report/commodity-inherited-root

Conversation

@ClemensLey

@ClemensLey ClemensLey commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

A new used to inherit _root from 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 _root has a non-empty salt, so the sibling passed even though the mint did not pay its amount.

The published library now inherits _root only 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 and isGenuine() to be false.

@bitcoin-computer/commodity also publishes main and types, and CommodityHelper deploys the TBC777 chain. merge still throws.

The library source is Bitcoin-Computer-Secrets/workspace branch report/commodity-inherited-root.

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.
@ClemensLey ClemensLey changed the title A call-stamped Commodity sibling passes isGenuine fix(lib): do not stamp a sibling with the caller's _root Oct 5, 2026
@ClemensLey
ClemensLey requested a balanced review from Copilot October 5, 2026 06:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity

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 a CommodityHelper that deploys the TBC777 inheritance chain and exposes mint/balanceOf/transfer; relax merge() to accept (and ignore) a tokens arg so it matches the TBC20 call shape while still throwing.
  • Add a mocha test asserting a sibling-constructed Commodity gets its own _root and fails isGenuine().
  • Regenerate committed artifacts: node/dist bundles and lib/types (introducing getTXOs block-cursor fields ltBlockHeight/ltBlockIndex/ltRev and TXOOrderBy: 'block', which are unrelated to the stated _root fix).
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.

Comment on lines +8 to +9
"main": "./build/src/index.js",
"types": "./build/src/index.d.ts",
@ltardivo

Copy link
Copy Markdown
Collaborator

Closing. Already integrated in #487 and #521.

@ltardivo ltardivo closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants