Introducing a new way to review your PRs.

Read the announcement

solana-foundation / solana-go

Go SDK library and RPC client for the Solana Blockchain

View on GitHub

26 documents · Updated Nov 16, 2026

docs / legacy-and-versioned-transactions

Legacy and versioned transaction handling

Transactions turn a message and its signatures into bytes that Solana can verify and execute. This page explains how the repository preserves legacy messages, handles version 0 messages with address lookup tables, handles version 1 messages with inline transaction settings, signs the exact wire form, and supports durable nonce transactions. It complements Transaction lifecycle, Account and sysvar codecs, Transaction confirmation, and Lookup table and auxiliary programs.

Transaction signing

Signing applies to the serialized message rather than to the outer transaction envelope. The message header fixes the signer count and signer order, so each signature slot matches the key at the same position in the message account list. For a v1 message, the version prefix is part of these signed bytes. References: transaction.go• L34-43, transaction.go• L704-742, transaction.go• L854-878, message.go• L843-852, message_v1.go• L217-285

Signature slots

The first required-signature keys are the transaction signers. Sign requires a private key for every signer, while PartialSign fills only the slots for keys that the caller provides. Both paths use the same message bytes and keep signatures in signer order. References: transaction.go• L704-742, message.go• L843-852

A transaction may be assembled by several signers before it is sent. The signature list must still have one position for each required signer. Serialization supplies zero-valued placeholder signatures when a newly built transaction has fewer signatures than the message requires. References: transaction.go• L593-617

Signature verification

Verification re-serializes the message and checks every signature against the matching signer key. A changed blockhash, account order, instruction, lookup descriptor, message version, or v1 transaction setting therefore changes the signed content and invalidates the signatures. References: transaction.go• L854-878, message.go• L386-395, message_v1.go• L217-285

Wire formats

The wire format has two layers for legacy and v0 transactions, but v1 uses a distinct order. Legacy and v0 transactions begin with a compact signature count and fixed-size signatures followed by the message. A v1 transaction begins with its 0x81 message prefix, followed by the message and exactly the signatures required by its header. References: transaction.go• L34-44, transaction.go• L593-631, transaction.go• L641-702, message.go• L386-395

Legacy message format

A legacy message has no version marker. Its first three bytes describe required signatures and read-only account groups. The rest of the message contains all account keys, the recent blockhash, and compiled instruction data. References: message.go• L399-431, message.go• L707-797

Legacy messages keep every account in one static key list. Instruction program and account fields are indexes into that list, so the key order and header counts form one wire contract. References: message.go• L399-431, message.go• L954-1030

Version 0 message format

Version 0 messages set the high bit of the first wire byte and use the remaining version bits to identify version 0. They retain the legacy message body for the header, static keys, recent blockhash, and instructions. They then add address lookup descriptors after the instructions. References: message.go• L98-108, message.go• L434-495, message.go• L645-704

The version marker is part of the signed message. JSON uses the presence of addressTableLookups to preserve the version distinction because the internal version value is not itself a JSON field. References: message.go• L223-312, message.go• L386-395

Version 1 message format

Version 1 messages use the 0x81 prefix and carry the same core transaction ideas as legacy messages: a header, account addresses, a lifetime hash, and compiled instructions. They add an inline transaction configuration instead of address lookup descriptors. The configuration can carry a total priority fee, a compute-unit limit, a loaded-account-data limit, and a heap-size request. References: message_v1.go• L17-24, message_v1.go• L46-70, message_v1.go• L217-285

The v1 wire form uses a mask to include only the configuration values that are set. It places instruction headers before the instruction account indexes and data. This layout is fixed and is included in the signed message, so a change to a setting or to the field order changes the signature input. References: message_v1.go• L109-203, message_v1.go• L246-284

V1 does not support address lookup tables or ComputeBudget instructions. Transaction construction rejects those combinations and uses TransactionV1Config for inline compute settings. V1 encoding also rejects counts, indexes, and instruction data lengths that do not fit the wire fields. V1 validation limits the message to 64 addresses, 64 instructions, and 12 signatures, and checks the heap-size range when it is set. References: transaction.go• L196-208, transaction.go• L284-299, transaction.go• L574-584, message_v1.go• L217-244, sanitize.go• L118-160

The JSON form identifies the message kind by its fields: no version-specific field means legacy, addressTableLookups means v0, and transactionConfig means v1. A v1 JSON message does not include address table lookups. References: message.go• L223-312

Transaction envelope

For legacy and v0, the transaction envelope places a compact signature count and signatures before the message bytes. For v1, the envelope places the message first and then writes one fixed-size signature for each required signer; it has no signature-count field. Base64 and base58 helpers encode or decode this complete envelope. References: transaction.go• L91-119, transaction.go• L593-631, transaction.go• L641-702

The decoder selects the envelope from its first byte. A low-bit first byte starts the legacy or v0 path, 0x81 starts v1, and other high-bit values are rejected. Slice-level v1 decoding also rejects trailing bytes, while the streaming decoder leaves them for the caller and legacy or v0 slice decoding keeps its earlier lenient behavior. References: transaction.go• L91-103, transaction.go• L641-702, transaction_v1_test.go• L376-419

Address lookup tables

Address lookup tables let a version 0 message refer to non-signer accounts by table index instead of repeating each public key in the static key list. A lookup descriptor names one table and separates its selected entries into writable and read-only groups. References: message.go• L46-84, message.go• L111-138, message.go• L434-495

Table state

The table account is on-chain state. The client fetches it through RPC and decodes its metadata and ordered public keys before it can resolve a message. The table can be active or deactivated, and its state limits the address list to the supported table size. References: programs/…/address-lookup.go• L13-26, programs/…/address-lookup.go• L29-67, programs/…/address-lookup.go• L69-138, programs/…/address-lookup.go• L180-182

Lookup resolution

Resolution joins each descriptor with the supplied table contents. It returns writable looked-up accounts first and read-only looked-up accounts second, in descriptor order. The full account view is then the static keys followed by those resolved groups. References: message.go• L546-580, message.go• L583-643, message_v0_test.go• L19-88

The message does not contain the table contents. A versioned message with lookups is therefore incomplete for account, signer-permission, or index queries until the caller supplies a table map with SetAddressTables. Missing tables and out-of-range indexes return errors rather than silently producing account keys. References: message.go• L32-44, message.go• L142-155, message.go• L800-835, message_v0_test.go• L91-130

The address lookup table package also provides a one-step RPC path for fetched versioned transactions. ResolveMessageLookupsFromRPC gets every referenced table in one request, decodes the table addresses, attaches them to the message, and resolves the account keys. It is a no-op for legacy messages and already resolved messages. A missing table or incomplete fetch returns an error before the message is marked resolved. References: programs/…/resolve.go• L26-119, programs/…/resolve_test.go• L88-183

Resolution can be done without changing the message through GetAllKeys, or it can append the looked-up keys to AccountKeys through ResolveLookups. Repeated resolution is safe after the message has been resolved. References: message.go• L583-643, message_v0_test.go• L132-216

Lookup construction

Transaction construction accepts the contents of address tables as an option. It keeps the fee payer, signers, and invoked program IDs in the static key list. Other eligible accounts move into writable or read-only lookup groups, while instruction indexes point into the combined static and dynamic key space. References: transaction.go• L171-208, transaction.go• L317-381, transaction.go• L445-572

The construction path sorts table identifiers before it creates descriptors. This gives the message a stable table order and keeps the resulting dynamic account indexes aligned with the lookup descriptors. References: transaction.go• L317-345, transaction.go• L496-545

Durable nonce transactions

A durable nonce gives a transaction a stored recent-block value instead of relying on the short lifetime of a normal recent blockhash. The repository models nonce account state, checks the durable-nonce domain, and exposes the System program instructions used to create, consume, update, and upgrade nonce accounts. References: nonce.go• L17-26, nonce.go• L67-87, programs/…/instructions.go• L45-85

Nonce transaction detection

The transaction-level check treats a transaction as a durable nonce transaction when its first instruction is a System program AdvanceNonceAccount instruction. GetNonceAccount then reads the first account of that instruction. This is a structural check; validating the stored nonce value still requires the nonce account data. References: sanitize.go• L223-275

The advance instruction consumes the current nonce and replaces it with a successor. Its account set includes the writable nonce account, the recent-blockhashes sysvar, and a signer for the nonce authority. This first instruction is the link between the transaction wire form and the nonce account state. References: programs/…/AdvanceNonceAccount.go• L27-39, programs/…/AdvanceNonceAccount.go• L41-78

Nonce account state

An initialized nonce account stores an authority, a durable nonce, and the fee rate recorded for the next use. Current nonce versions keep durable nonces in a separate hash domain. The durable nonce is derived as sha256("DURABLE_NONCE" || blockhash) and is placed in the transaction RecentBlockhash field when used. References: nonce.go• L38-47, nonce.go• L67-87, nonce.go• L97-124

Nonce account data has a version and an initialized or uninitialized state. The common account representation is 80 bytes when stored on chain; uninitialized state data is padded to that account size. Decoding accepts account padding for general reads, while account verification uses strict decoding. References: nonce.go• L44-65, nonce.go• L150-196, nonce.go• L198-287

Nonce validation

Nonce validation succeeds only for a current, initialized nonce whose stored value matches the transaction recent blockhash. VerifyNonceAccount also requires the account owner to be the System program. Legacy nonce versions do not validate as durable nonce transactions because they use the old blockhash domain. References: nonce.go• L290-305, nonce.go• L377-390

Nonce lifecycle

System instructions cover the nonce account lifecycle. Initialization sets the authority and nonce value. Authorization changes the authority with the current authority's signature. Advancement consumes the nonce. A one-time upgrade moves an initialized legacy nonce into the current durable-nonce domain. References: programs/…/InitializeNonceAccount.go• L28-42, programs/…/InitializeNonceAccount.go• L55-68, programs/…/AuthorizeNonceAccount.go• L28-38, programs/…/UpgradeNonceAccount.go• L27-50, nonce.go• L317-366

The durable nonce flow connects transaction assembly, account lookup, and validation as follows:

flowchart LR
    A[Nonce account state] --> B[Stored durable nonce]
    B --> C[Transaction recent blockhash field]
    C --> D[First instruction: AdvanceNonceAccount]
    D --> E[Transaction message]
    E --> F[Sign exact message bytes]
    F --> G[Verify nonce and signatures]
    D --> H[Successor nonce in account state]

The flow shows why a nonce transaction needs both a correctly formed first instruction and a matching current nonce account. A valid signature alone does not prove that the durable nonce is current. References: sanitize.go• L231-275, nonce.go• L290-305, programs/…/AdvanceNonceAccount.go• L27-78

Format and state relationships

Legacy, v0, and v1 messages share the same account permissions and compiled-instruction model, but they differ in how account keys and transaction settings are represented. Legacy keeps all keys inline, v0 can load extra non-signer keys from tables, and v1 carries inline compute settings without table lookups. Nonce support uses the same message blockhash field in all three formats; it changes the source and validation of that value rather than creating a separate message format. References: message.go• L98-138, message.go• L386-495, message_v1.go• L217-285, nonce.go• L118-124

When a version 0 transaction uses lookup accounts and a durable nonce, the lookup tables supply only account keys. The nonce value remains in the message, and the nonce account and authority must still appear in positions that let the first instruction and signer rules work. V1 cannot combine address lookups with its inline configuration. References: transaction.go• L464-531, message.go• L954-1030, sanitize.go• L231-275, message_v1.go• L217-221

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to message version markers or field order must preserve legacy, v0, and v1 decoding as well as signature coverage.
  • Changes to the v1 envelope must keep the message-first layout, exact signature count, discriminator, and slice-level trailing-byte rule aligned.
  • Changes to v1 configuration masks or field values must keep JSON fields, mask bits, encoded value order, and validation limits aligned.
  • Changes to v1 wire counts or instruction field widths must keep marshal-time range checks aligned with the one-byte and two-byte encoded fields.
  • Changes to signer ordering must keep the message header, signature slots, partial signing, and verification aligned.
  • Changes to address lookup ordering must keep table descriptor order, writable/read-only grouping, resolved account order, and instruction indexes aligned.
  • Changes to lookup resolution must preserve the typed missing-table error, the RPC helper's all-or-nothing fetch behavior, and the distinction between unresolved and resolved account keys.
  • Changes to nonce account encoding must keep version, state, padding, hash-domain checks, and strict account validation compatible.
  • Changes to the System program nonce instruction set must keep the advance-instruction detector aligned with the instruction discriminant and account order.

Important failure modes

TriggerConsequenceGuard
A message or v1 transaction setting changes after signatures are madeSignature verification failsSign and verify the exact serialized message bytes, including the v1 prefix
A signer key is missing during SignThe transaction is not fully signedUse PartialSign for staged signing or provide every required private key to Sign
A v1 transaction uses the legacy/v0 envelope orderThe transaction is rejected or decoded as malformedEncode v1 as message, then exactly the header-required signatures
A v1 message has too many wire entries or instruction data is too largeV1 marshaling fails before an invalid byte representation is producedKeep counts and data lengths within the v1 wire field widths
A v1 transaction has extra bytes after its signaturesTransactionFromBytes rejects the transactionPass the exact v1 wire slice; use streaming decode only when a caller owns the remaining bytes
A v1 message has lookups or ComputeBudget instructionsConstruction or sanitization failsUse v0 for address tables and TransactionV1Config for inline compute settings
A v1 config mask has unknown bits or one priority-fee bitV1 decoding failsUse only supported mask bits and include both priority-fee bits together
A versioned message has lookups but no table contentsAccount and permission queries return ErrAddressTablesNotSetFetch each table and call SetAddressTables before resolution
An RPC lookup fetch returns a missing table or an incomplete account listThe message is not resolvedCheck the RPC resolution error and retry with complete table accounts
A lookup index is outside the decoded tableLookup resolution failsKeep table contents current and validate index ranges
A version 0 prefix carries an unsupported versionMessage decoding failsAccept only supported message versions
The first instruction is not System AdvanceNonceAccountDurable nonce detection returns falseKeep nonce transactions structurally compliant and place the advance instruction first
A nonce is legacy, uninitialized, or does not match the message blockhashDurable nonce validation failsUse a current initialized nonce and verify the stored value
Nonce account data has the wrong owner or invalid trailing stateNonce account verification failsRequire System ownership and strict valid account data

Key files

FileWhy to read it
transaction.goShows transaction assembly, version selection, signature placement, binary envelope encoding, and signature verification.
message.goDefines legacy and version 0 message formats, JSON version selection, lookup descriptors, resolution, permissions, and message dispatch.
message_v1.goDefines the v1 wire format, inline transaction configuration, wire-field checks, size and policy limits, and v1 decoding.
sanitize.goShows v1 structural validation and how the transaction identifies a durable nonce from its first instruction.
nonce.goDefines durable nonce derivation, nonce account state, account validation, version upgrades, and fee data.
programs/…/address-lookup.goShows how on-chain lookup table accounts become ordered public-key lists for message resolution.
programs/…/resolve.goShows the RPC path that fetches all referenced lookup tables and resolves a versioned message.
programs/…/AdvanceNonceAccount.goDefines the instruction that consumes a nonce and the account roles required by the System program.
programs/…/InitializeNonceAccount.goShows how a nonce account receives its initial authority and nonce value.
programs/…/AuthorizeNonceAccount.goShows the authority-change operation for an initialized nonce account.
programs/…/UpgradeNonceAccount.goShows the one-time move from legacy nonce state to the current nonce domain.
transaction_v1_test.goDemonstrates v1 Rust-compatible wire round trips, signing, configuration, envelope rejection, size behavior, and durable nonce compatibility.
transaction_v0_test.goDemonstrates version 0 decoding, table injection, lookup resolution, and wire round-trip behavior.
message_v0_test.goDemonstrates lookup ordering, missing-table errors, index errors, and idempotent resolution.
programs/…/resolve_test.goDemonstrates RPC lookup fetching, no-op behavior, canonical key order, missing-table handling, and argument validation.
nonce_test.goShows durable nonce derivation, state encoding, current-version validation, and legacy upgrade behavior.