fix(sdk-coin-icp): parse certificate to detect canister rejections on withdrawal#9344
Open
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Open
fix(sdk-coin-icp): parse certificate to detect canister rejections on withdrawal#9344bitgo-ai-agent-dev[bot] wants to merge 1 commit into
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Conversation
bitgo-ai-agent-dev
Bot
force-pushed
the
spt-114-icp-withdrawal-fix
branch
from
July 24, 2026 00:37
2d414a4 to
eb0c4ad
Compare
Contributor
The ICP /api/v3/canister/call endpoint returns HTTP 200 with outer status='replied' even when the canister rejects the transaction (e.g. insufficient funds). The rejection details are encoded in the certificate's request_status subtree. Previously, broadcastTransaction only checked the outer status field and treated any 'replied' response as a success. This caused silent failures: withdrawals that were rejected by the ICP ledger (e.g. due to insufficient balance) were reported as successful by the SDK. This fix adds ICP labeled hash tree traversal to extract the actual request status from the certificate. When the certificate contains request_status.status='rejected', the broadcast now throws with the canister's reject_message, surfacing the real failure to callers. Changes: - Add IcpCertificate, IcpHashTree types and REQUEST_STATUS_* constants to iface.ts - Add lookupPathInTree, extractRequestStatusFromCertificate, and helper tree-traversal methods to Utils class - Update broadcastTransaction to decode the certificate and throw on canister rejection - Replace the test broadcast response fixture with a minimal success response; rename the original rejected fixture to PublicNodeApiBroadcastResponseRejected - Add test case that verifies canister rejections are surfaced Ticket: COINS-1257 Session-Id: c40a0622-f3d1-48cc-82a2-5d3debf68691 Task-Id: b2e68cd6-bb53-4c2c-b0b6-f8c4e7f3d652
bitgo-ai-agent-dev
Bot
force-pushed
the
spt-114-icp-withdrawal-fix
branch
from
July 24, 2026 16:06
eb0c4ad to
3716514
Compare
ralph-bitgo
Bot
force-pushed
the
spt-114-icp-withdrawal-fix
branch
from
July 24, 2026 16:06
3716514 to
65f87fa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Utils(lookupPathInTree,extractRequestStatusFromCertificate) to decode the certificate returned by the ICP v3/callendpointbroadcastTransactioninicp.tsto inspect the certificate'srequest_statussubtree after receivingstatus: 'replied'— throws with the canister'sreject_messageif the inner status isrejectedIcpCertificate,IcpHashTreetypes andREQUEST_STATUS_REPLIED/REQUEST_STATUS_REJECTEDconstants toiface.tsPublicNodeApiBroadcastResponseRejectedWhy
status: 'replied'even when the canister rejects the call (e.g. insufficient funds). The actual outcome is encoded inside a CBOR certificate in the response body.broadcastTransactiononly checked the outer status and treated everyrepliedresponse as a success. This caused ICP withdrawals rejected by the ledger to be silently reported as successful by the BitGo SDK, which is the root cause of the reported API failure (COINS-1257).Test plan
test/unit/transactionBuilder/transactionRecover.ts— all 94 tests pass including new caseshould fail to recover if canister rejects the transaction (e.g. insufficient funds)— verifies the rejected certificate fixture now throwsTicket: COINS-1257