Skip to content

rust-legacy: test u64::MAX amount convention for confidential transfers - #1410

Merged
joncinque merged 2 commits into
solana-program:mainfrom
pwsaragossy:test/confidential-transfer-hook-amount-sentinel
Sep 3, 2026
Merged

rust-legacy: test u64::MAX amount convention for confidential transfers#1410
joncinque merged 2 commits into
solana-program:mainfrom
pwsaragossy:test/confidential-transfer-hook-amount-sentinel

Conversation

@pwsaragossy

Copy link
Copy Markdown
Contributor

Token-2022 cannot know the amount of a confidential transfer, so it hands the transfer hook u64::MAX as a convention:

https://github.com/solana-program/token-2022/blob/main/program/src/extension/confidential_transfer/processor.rs#L826-L836

Nothing currently tests that from the hook's side. success_confidential_transfer asserts balances and the transferring flag, and never what the hook was actually handed — so the convention is enforced by a source comment rather than by the suite.

This adds a test hook program that succeeds only when the amount is u64::MAX, and uses it from both directions so the convention is pinned rather than described:

  • success_confidential_transfer_hook_receives_sentinel_amount — the confidential transfer lands, which it can only do if the hook was handed the sentinel.
  • fail_transfer_hook_receives_real_amount_on_public_path — the same hook on the public path is rejected, because there it is handed the real amount.

The pair fails if either half of the convention changes, in either direction.

The program is a standalone crate under transfer-hook-test-programs/ built to a committed .so fixture, like the test programs beside it. It carries its own empty [workspace] table — without one, cargo-build-sbf refuses on the grounds that the crate believes it is in the root workspace but is not a member. Note the existing test programs hit the same error today, so they cannot currently be rebuilt from the repo; happy to fold a fix for those into this PR or leave it separate, whichever you prefer.

cargo test --manifest-path clients/rust-legacy/Cargo.toml --test transfer_hook
test result: ok. 14 passed; 0 failed

Related documentation fix on the interface side: solana-program/transfer-hook#156

pwsaragossy and others added 2 commits August 27, 2026 05:44
Token-2022 cannot know the amount of a confidential transfer, so it hands
the transfer hook `u64::MAX` as a convention. Nothing currently tests that
from the hook's side: `success_confidential_transfer` asserts balances, and
never what the hook was handed.

Adds a test hook program that succeeds only on the sentinel, and uses it
from both directions so the convention is pinned rather than described:
the confidential path lands, and the public path is rejected because there
the hook is handed the real amount.

The program is a standalone crate built to a committed .so fixture, like
the transfer-hook test programs beside it.

  14 passed; 0 failed
@joncinque joncinque changed the title test: pin the u64::MAX amount convention for confidential transfers rust-legacy: test u64::MAX amount convention for confidential transfers Sep 3, 2026

@joncinque joncinque left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for your contribution! As a matter of safety, I rebuilt the program myself and uploaded that to your PR

@joncinque
joncinque merged commit 6070f76 into solana-program:main Sep 3, 2026
45 checks passed
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