Skip to content

fix: correct SIP-018 message format in acceptIncomingTransfer#9

Merged
obycode merged 1 commit intoobycode:mainfrom
warmidris:fix/sip018-signing-format
Mar 6, 2026
Merged

fix: correct SIP-018 message format in acceptIncomingTransfer#9
obycode merged 1 commit intoobycode:mainfrom
warmidris:fix/sip018-signing-format

Conversation

@warmidris
Copy link
Contributor

Summary

  • Bug 1 — Wrong message structure: acceptIncomingTransfer was building a nested message (pipe-key as sub-object) with plain string values. The Clarity contract's make-structured-data-hash expects a flat merged tuple with explicit Clarity type hints ({type: "uint", value: N}, etc.), which is what sip018_sign requires.

  • Bug 2 — Wrong balance ordering: balance-1 was always set to myBalance and balance-2 to theirBalance, regardless of which side the local agent is. The contract assigns balance-1 to principal-1's balance canonically (same ordering as map-balances). Fix resolves ordering from pipeKey["principal-1"] before constructing the message.

Impact

Without this fix, every signature produced by acceptIncomingTransfer would fail on-chain verification — even if the counterparty's signature was valid — because the agent was signing a structurally different message than what the contract verifies.

Test plan

  • Unit test: acceptIncomingTransfer where local agent is principal-2 — verify balance-1 uses theirBalance (principal-1's balance)
  • Integration: open a pipe, exchange a payment, close it — verify both signatures pass verify-signature on-chain
  • Existing tests still pass (npm test)

🤖 Generated with Claude Code

Two bugs caused the agent to produce signatures incompatible with
on-chain verification:

1. Message was nested (pipe-key as sub-object) with plain string values.
   The Clarity contract uses a flat merged tuple with typed uint/principal
   fields — matching what sip018_sign expects.

2. balance-1/balance-2 always used myBalance/theirBalance regardless of
   whether the local agent is principal-1 or principal-2. The contract's
   map-balances logic assigns balance-1 to principal-1's balance canonically,
   so we must resolve ordering from pipeKey before building the message.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@obycode obycode force-pushed the fix/sip018-signing-format branch from 82b0348 to 7d11d85 Compare March 6, 2026 17:17
@obycode obycode merged commit 9ecc60e into obycode:main Mar 6, 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.

2 participants