Skip to content

Fix byte-array PDA seeds deriving with a Borsh length prefix - #1126

Merged
lorisleiva merged 1 commit into
mainfrom
fix/bytes-pda-seed
Aug 29, 2026
Merged

Fix byte-array PDA seeds deriving with a Borsh length prefix#1126
lorisleiva merged 1 commit into
mainfrom
fix/bytes-pda-seed

Conversation

@lorisleiva

@lorisleiva lorisleiva commented Aug 28, 2026

Copy link
Copy Markdown
Member

This PR resurrects #1101 by @latent-9, which I accidentally closed whilst cleaning up stale branches (sorry again! 🙏). The original commit is cherry-picked verbatim from the PR ref, so authorship is preserved and it already has an approving review on the original thread.

In short: a Vec<u8> instruction argument used as a PDA seed kept its Borsh sizePrefixTypeNode(u32, bytesTypeNode()) type when converted from an Anchor IDL, whereas Anchor derives byte-array seeds from the raw bytes. This meant generated clients computed a different PDA than the on-chain program. The fix mirrors the existing isBorshString special case with an isBorshBytes counterpart that emits a raw bytesTypeNode() seed.

A Vec<u8> instruction argument used as a PDA seed keeps its Borsh
sizePrefixTypeNode(u32, bytes) type when converted from an Anchor IDL.
Anchor derives byte-array seeds from the raw bytes without the length
prefix, so the generated client computes a different PDA than the
on-chain program. String seeds already strip the prefix; byte-array
seeds were the missing case.

Extend the argument-seed conversion to also recognize a size-prefixed
bytes argument and emit a raw bytesTypeNode seed.
@changeset-bot

changeset-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 815c912

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@codama/nodes-from-anchor Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@lorisleiva lorisleiva changed the title fix(nodes-from-anchor): strip the Borsh prefix from bytes PDA seeds Fix byte-array PDA seeds deriving with a Borsh length prefix Aug 28, 2026
@lorisleiva
lorisleiva marked this pull request as ready for review August 28, 2026 16:20

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@lorisleiva
lorisleiva merged commit 9a19abf into main Aug 29, 2026
5 checks passed
@lorisleiva
lorisleiva deleted the fix/bytes-pda-seed branch August 29, 2026 09:52
lorisleiva added a commit that referenced this pull request Aug 29, 2026
This PR is a follow-up to #1126, which fixed byte-array PDA seeds for Anchor v01 IDLs. The legacy v00 path has the same bug: `pdaNodeFromAnchorV00` strips the Borsh size prefix from constant `string` and `bytes` seeds but not from variable ones, so a variable seed derives a different PDA than the on-chain program. This change hoists the seed type conversion into a single helper used by both branches, so constant and variable seeds are now consistent by construction.
@latent-9

latent-9 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

@lorisleiva thanks for this merged

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