Skip to content

shannon entropy calculation and script type matching#335

Draft
cc-unchained wants to merge 2 commits intocaravan-bitcoin:mainfrom
cc-unchained:entropy-fingerprinting
Draft

shannon entropy calculation and script type matching#335
cc-unchained wants to merge 2 commits intocaravan-bitcoin:mainfrom
cc-unchained:entropy-fingerprinting

Conversation

@cc-unchained
Copy link
Contributor

@cc-unchained cc-unchained commented Jul 9, 2025

What kind of change does this PR introduce?

POC implementation of entropy calculation for output amounts. Side-steps the complexity of obtaining prevout address information from outpoints.

Possibly a binary representation of change fingerprinting based on value entropy.

For follow up work addressing the above, a z-score calculation may be of interest.
https://en.wikipedia.org/wiki/Standard_score

Issue Number:

#317

Snapshots/Videos:

If relevant, did you update the documentation?

Summary

Does this PR introduce a breaking change?

Checklist

  • I have tested my changes thoroughly.
  • I have added or updated tests to cover my changes (if applicable).
  • I have verified that test coverage meets or exceeds 95% (if applicable).
  • I have run the test suite locally, and all tests pass.
  • I have written tests for all new changes/features
  • I have followed the project's coding style and conventions.
  • I have created a changeset to document my changes (npm run changeset)

Other information

Have you read the contributing guide?

For information on creating and using changesets, please refer to our documentation on changesets.

@changeset-bot
Copy link

changeset-bot bot commented Jul 9, 2025

⚠️ No Changeset found

Latest commit: a3c82b9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Jul 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
caravan-coordinator ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 3, 2025 5:26pm

@cc-unchained cc-unchained marked this pull request as draft July 9, 2025 02:37
@Legend101Zz Legend101Zz added enhancement New feature or request wallet-health related to the wallet health and tx analysis project. related to @caravan/health package labels Jul 10, 2025
Copy link
Contributor

@bucko13 bucko13 left a comment

Choose a reason for hiding this comment

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

This is awesome. Thanks for putting together. I'd love to merge this in if we can. Just a couple of relatively minor comments.


it("can measure amount entropy", () => {
const result = amountFingerprints(["40.8199902", "1.18000000"]);
expect(result).toEqual([true, false]);
Copy link
Contributor

Choose a reason for hiding this comment

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

is the idea that there is always one (and only one) value that will be true?

const maxEntropy = Math.max(...entropies);

// Mark true if this output has the maximum entropy
return entropies.map((e) => e === maxEntropy);
Copy link
Contributor

Choose a reason for hiding this comment

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

If you have a "perfect spend" transaction that has 1 output, then this will always return [ true ]. Is this desirable? Maybe yes, maybe no. I can't decide 😅. Maybe if it's length 1, it should be [ false ]?

}, 0);
}

export function amountFingerprints(amounts: string[]): boolean[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

would you mind adding docstrings to this to explain what's being solved here and in particular to describe how to interpret the output.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2025

This pull request has been inactive for 30 days and has been marked as stale. It will be closed in 7 days if no further activity occurs. To keep this PR open, add the "long-lived" label or comment on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request long-lived stale wallet-health related to the wallet health and tx analysis project. related to @caravan/health package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants