Skip to content

fix receiver should use reserve and carry_all_balance#631

Open
vicentevieytes wants to merge 6 commits intomainfrom
vv/fix-receiver-draining
Open

fix receiver should use reserve and carry_all_balance#631
vicentevieytes wants to merge 6 commits intomainfrom
vv/fix-receiver-draining

Conversation

@vicentevieytes
Copy link
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings February 26, 2026 23:39
@vicentevieytes vicentevieytes requested a review from a team as a code owner February 26, 2026 23:39
@github-actions
Copy link

👋 vicentevieytes, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the CCIP test receiver contract to preserve its original TON balance when handling ccipReceive, aligning the confirmation-send behavior with the intended reserve + carry-all-balance pattern.

Changes:

  • Add a regression test asserting the receiver’s balance is unchanged after a successful ccipReceive.
  • Update the test receiver contract to reserve the original balance and send the confirmation with SEND_MODE_CARRY_ALL_BALANCE.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
contracts/tests/ccip/Receiver.spec.ts Adds a balance-preservation regression test for successful ccipReceive.
contracts/contracts/ccip/test/receiver/contract.tolk Reserves original balance and changes confirmation send mode to carry all balance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +30 to +43
@@ -49,6 +38,20 @@ fun onInternalMessage(in: InMessage) {
processConsumeAllGas()
}
}

reserveToncoinsOnBalance(0, RESERVE_MODE_INCREASE_BY_ORIGINAL_BALANCE);
msg.validateAndConfirm({
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

processAccept / processRejectAll / processConsumeAllGas runs before validateAndConfirm (router + minValue checks). This changes semantics (e.g., unauthorized/low-value messages can now hit ConsumeAllGas and fail with out-of-gas instead of Unauthorized/LowValue) and can burn gas before failing. Validate the sender/value first (or split validation from confirmation), then run behavior, then reserve+send confirmation so failures are deterministic and cheap.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@patricios-space hmm this is true, the minValue check should happen at the very beginning, but setting the action for the confirm message with this send mode and the reserve at the very beginning fails to preserve the original balance.

Copy link
Collaborator

@patricios-space patricios-space Feb 27, 2026

Choose a reason for hiding this comment

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

Yes, I was about to mention this. Then we should split validateAndConfirm, runing the validate before, and confirm after.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We temporarily solved it by inlining the steps from the receiver library in the receiver implementation

Comment on lines +30 to +43
@@ -49,6 +38,20 @@ fun onInternalMessage(in: InMessage) {
processConsumeAllGas()
}
}

reserveToncoinsOnBalance(0, RESERVE_MODE_INCREASE_BY_ORIGINAL_BALANCE);
msg.validateAndConfirm({
Copy link
Collaborator

@patricios-space patricios-space Feb 27, 2026

Choose a reason for hiding this comment

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

Yes, I was about to mention this. Then we should split validateAndConfirm, runing the validate before, and confirm after.

@vicentevieytes vicentevieytes force-pushed the vv/fix-receiver-draining branch from a869e81 to fb5a003 Compare March 10, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants