Skip to content

Lyd/ignore sent commitments#497

Merged
lydiagarms merged 2 commits into
masterfrom
lyd/ignoreSentCommitments
Jul 21, 2026
Merged

Lyd/ignore sent commitments#497
lydiagarms merged 2 commits into
masterfrom
lyd/ignoreSentCommitments

Conversation

@lydiagarms

@lydiagarms lydiagarms commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

In the commitment DB in Starlight, we store commitments that are created on behalf of another user. However, if it is a whole variable this could cause a problem if the ownership of that variable is later transferred back to us. Consider the contract NFT_Escrow.zol, lets say we transfer a token to another user, and they then transfer it back to us. We will save the commitment during the initial transfer that we are sending to another user. We then receive another commitment with the same state id. However, because the first commitment is owned by the other user, we will never learn that it has been nullified as we do not own the variable and so don't know the nullifier. Therefore, if we try to use the token sent to us, we will use the first commitment instead of the second which causes an error.

Changes

  • When we call getCommitmentsDb, getBalance and getBalanceByState we filter commitments so that the public key is either the default one or the shared public key.

  • Previously, in contracts like BucketsOfBalls.zol where the ownership is a public address, we obtain the public key for new commitments by checking the on-chain mapping, even if this has not been set. If this is the case the public key used will be 0, which will mean that it will be filter out as per the previous change. As is already the case for secret addresses, we should default to the optional public key chosen by the user in the API call, then use the on-chain mapping if it exists, and otherwise use the default public key.

Checklist

  • Tests added/updated
  • CI passes
  • No secrets/keys committed
  • Docs updated (if needed)
  • Backwards compatible (or noted breaking change)

How to test

  1. Test the Swap.zol contract with ./bin/startup-double. First complete a swap, and then complete a swap again reversing the tokens back to the original owners.

@lydiagarms
lydiagarms force-pushed the lyd/ignoreSentCommitments branch 3 times, most recently from 7fc8394 to 72e1a9b Compare July 16, 2026 13:48
@lydiagarms
lydiagarms marked this pull request as ready for review July 17, 2026 08:38
@lydiagarms
lydiagarms requested review from AdarshRon and Wei-257 July 17, 2026 08:38
}

function getLocalPublicKeys() {
if (!fs.existsSync(keyDb)) return [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

do we allow empty set? is key initialization guranteed?

If empty set, then line 274, 319 and 335 will return null even when commitments exists.

do you want to return an empty filter object here or fail explicitly with a clear error that keys must be initialised?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point, fixed in fixup commit: 6560fe5

Comment thread src/boilerplate/common/commitment-storage.mjs

@AdarshRon AdarshRon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@lydiagarms
lydiagarms force-pushed the lyd/ignoreSentCommitments branch from 6560fe5 to ff925d8 Compare July 21, 2026 08:48
@lydiagarms
lydiagarms merged commit 0468775 into master Jul 21, 2026
2 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.10.13 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants