Expand description
Zero-copy Token-2022 extension TLV readers.
Token-2022 stores extension data in a TLV region after a fixed
per-account prefix. Each TLV entry is
[type: u16 LE][length: u16 LE][data: length bytes].
Anchor routes every extension constraint through
InterfaceAccount<Mint>, which Borsh-deserializes the whole
account. Quasar has a zero-copy base-layout reader but no TLV
helpers. Pinocchio has nothing. This module fills the gap.
Every reader here validates only the bytes it reads. No heap
allocation, no full-account decode, no version coupling to
spl-token-2022. A program that needs to enforce
transfer_hook::authority = X on a mint calls require_transfer_hook_authority
and pays the cost of a TLV scan plus a 32-byte compare. That is the
cost floor for a correct check.
§On-chain layout (authoritative)
An extended mint is padded to the same length as an extended token
account so that the Token-2022 program cannot confuse the two by
data length alone; the one-byte AccountType discriminator at
offset ACCOUNT_TYPE_OFFSET (= 165) disambiguates them.
Extended mint : [0..82] Mint base | [82..165] padding | [165] AccountType=1 | [166..] TLV
Extended token account: [0..165] Account base | [165] AccountType=2 | [166..] TLVBoth shapes place the AccountType byte at offset 165 and begin TLV
data at offset 166. BASE_MINT_LEN (82) is the length of a plain,
non-extended mint and is used by length checks; it is not the
offset at which mint extensions live. This layout matches
spl-token-2022 and the pinocchio reference implementation
(validate_account_type keys on bytes[BASE_ACCOUNT_LENGTH]
where BASE_ACCOUNT_LENGTH = 165).
§Extension type constants
Values are the on-chain u16 encoding from
spl-token-2022::extension::ExtensionType. They are stable wire
values and safe to hard-code. The full set is listed below so
tooling can surface the name for any TLV it encounters.
Constants§
- ACCOUNT_
TYPE_ MINT - Account-type byte: Mint.
- ACCOUNT_
TYPE_ OFFSET - Offset of the
AccountTypediscriminator on any extended Token-2022 account (mint or token account). - ACCOUNT_
TYPE_ TOKEN - Account-type byte: Token Account.
- BASE_
MINT_ LEN - Length of a plain (non-extended) mint’s data region.
- BASE_
TOKEN_ LEN - Length of a plain (non-extended) token-account’s data region.
- EXT_
CONFIDENTIAL_ TRANSFER_ ACCOUNT - EXT_
CONFIDENTIAL_ TRANSFER_ FEE_ AMOUNT - EXT_
CONFIDENTIAL_ TRANSFER_ FEE_ CONFIG - EXT_
CONFIDENTIAL_ TRANSFER_ MINT - EXT_
CPI_ GUARD - EXT_
DEFAULT_ ACCOUNT_ STATE - EXT_
GROUP_ MEMBER_ POINTER - EXT_
GROUP_ POINTER - EXT_
IMMUTABLE_ OWNER - EXT_
INTEREST_ BEARING_ CONFIG - EXT_
MEMO_ TRANSFER - EXT_
METADATA_ POINTER - EXT_
MINT_ CLOSE_ AUTHORITY - EXT_
NON_ TRANSFERABLE - EXT_
NON_ TRANSFERABLE_ ACCOUNT - EXT_
PAUSABLE_ ACCOUNT - EXT_
PAUSABLE_ CONFIG - EXT_
PERMANENT_ DELEGATE - EXT_
SCALED_ UI_ AMOUNT_ CONFIG - EXT_
TOKEN_ GROUP - EXT_
TOKEN_ GROUP_ MEMBER - EXT_
TOKEN_ METADATA - EXT_
TRANSFER_ FEE_ AMOUNT - EXT_
TRANSFER_ FEE_ CONFIG - EXT_
TRANSFER_ HOOK - EXT_
TRANSFER_ HOOK_ ACCOUNT - EXT_
UNINITIALIZED - MINT_
EXTENSION_ PADDING_ END - End of the mint extension padding region (exclusive).
- MINT_
EXTENSION_ PADDING_ START - Start of the mint’s extension padding region (82..165). Bytes in this range are zero-filled and exist purely to equalize the length of extended mints and extended token accounts.
- TLV_
OFFSET - Offset at which the TLV extension region begins on any extended Token-2022 account (mint or token account).
Functions§
- find_
extension - Locate an extension in a Token-2022 account’s TLV region.
- mint_
tlv_ region - Slice the TLV region out of a mint account’s data.
- require_
default_ account_ state - Require a mint’s
DefaultAccountStatebyte to equalexpected. - require_
immutable_ owner - Require a token account to carry the
ImmutableOwnerextension. - require_
interest_ bearing_ authority - Require a mint’s
InterestBearingConfigrate-authority to equalexpected. - require_
metadata_ pointer_ address - Require a mint’s
MetadataPointermetadata-address to equalexpected. - require_
metadata_ pointer_ authority - Require a mint’s
MetadataPointerauthority to equalexpected. - require_
mint_ close_ authority - Require a mint’s
MintCloseAuthorityextension to equalexpected. - require_
non_ transferable - Require a mint to carry the
NonTransferableextension. - require_
permanent_ delegate - Require a mint’s
PermanentDelegateextension to equalexpected. - require_
transfer_ fee_ config_ authority - Require a mint’s
TransferFeeConfigtransfer-fee-config authority to equalexpected. - require_
transfer_ fee_ withdraw_ authority - Require a mint’s
TransferFeeConfigwithdraw-withheld-authority to equalexpected. - require_
transfer_ hook_ authority - Require a mint’s
TransferHookauthority to equalexpected. - require_
transfer_ hook_ program - Require a mint’s
TransferHookprogram id to equalexpected. - token_
account_ tlv_ region - Slice the TLV region out of a token-account’s data.