You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
swimricky
changed the title
PDA derivation with string seed uses incorrect type for length for Anchor
PDA derivation with string seed incorrect for Anchor
Nov 29, 2024
Yes, I can see now that the Anchor macro says seeds = [name.as_bytes()], which basically means "remove the u32 size prefix of the String type.
The really annoying thing is that this is actually not exposed on the IDL whatsoever.
"pda": {
"seeds": [
{
"kind": "arg",
"path": "name"// argument "name" is `string`, not `string.as_bytes()` or something.
}
]
}
So from the perspective of Codama, you're just getting the string type which, by default with Anchor, is a u32 prefixed string.
Since I believe this is the way most people using string as seeds anyway, it may be okay to just assume that string seed should never have any prefix. But that would introduce a bug for anyone that currently uses u32 prefixed strings for seeds.
I think it's still worth doing but maybe best to release it in 2.0. 🤔
solana-program/create-solana-program#108
if you have an Anchor program like the following
the generated Encoder for the seeds is incorrect.
it generates the following snippet for resolving the
counter
account if not providedit should be using
The text was updated successfully, but these errors were encountered: