Add STATE_VERSION to all settlement PDA seeds - #89
Open
kaze-cow wants to merge 2 commits into
Open
Conversation
Every account the settlement program stores lived at a PDA whose first seed was the bare string `settlement`. A program upgrade that changed the layout or meaning of stored state would therefore land on exactly the same addresses as the previous version, so old order and state accounts would be silently reinterpreted under the new layout. Fold a `STATE_VERSION` constant into the prefix seed that all three PDA families share, so bumping it relocates the program's whole address space at once and accounts written by an older version become unreachable rather than misread. The version is formatted as decimal ASCII and concatenated onto the prefix, giving `settlement1`, so the seed stays legible wherever seeds surface. It remains a single seed rather than an extra seed slot, which leaves the seed arity of all three schemes untouched and the compute cost of every derivation unchanged. The seed is built in a `const` item rather than a `const fn` because the workspace denies `clippy::arithmetic_side_effects` and that lint skips `const` item bodies but not `const fn` bodies. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Updates the settlement root PDA seed to correspond to the Major and minor cargo package versions
Contents
Generally speaking the root state PDA is now:
The whole seed is printable ASCII, so it shows up readably in explorers, logs and
solana accountoutput instead of trailing a raw byte. At 15 bytes it has ample headroom under the 32-byteMAX_SEED_LEN, which a test now pins.No CU cost. Everything resolves in
rustc—stringson the built.soshowssettlement v0.1baked into rodata — so nothing happens on-chain. The four extra seed bytes are free too:sol_create_program_addressandsol_try_find_program_addresscharge a flatcreate_program_address_units(1500 CU) per bump attempted, before the seeds are even read out of program memory, so cost never scales with seed length.Other considerations
How to test
Check new strategy
🤖 Generated with Claude Code