Skip to content

test: pin the u64::MAX amount convention for confidential transfers - #1410

Open
pwsaragossy wants to merge 1 commit into
solana-program:mainfrom
pwsaragossy:test/confidential-transfer-hook-amount-sentinel
Open

test: pin the u64::MAX amount convention for confidential transfers#1410
pwsaragossy wants to merge 1 commit into
solana-program:mainfrom
pwsaragossy:test/confidential-transfer-hook-amount-sentinel

Conversation

@pwsaragossy

Copy link
Copy Markdown

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

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
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.

1 participant