Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid serialization of type aliased values unless argument name matches type alias name #2820

Closed
halfbakedsneed opened this issue Feb 18, 2024 · 1 comment · Fixed by #2821
Labels
bug Something isn't working ts

Comments

@halfbakedsneed
Copy link
Contributor

halfbakedsneed commented Feb 18, 2024

Strange one. Take this simple program, and accompanying invocation:

// 0.29.0

use anchor_lang::prelude::*;

pub type MyType = [u8; 3];

#[program]
pub mod test {
    use super::*;

    pub fn initialize(ctx: Context<Initialize>, kek: MyType) -> Result<()> {
        msg!("{:?}", kek);

        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize {}
await program.methods.initialize([1, 2, 3]).rpc();

Expected Behaviour

I should see [1, 2, 3] in the program logs.

Current Behaviour

I see [0, 0, 0] in the program logs.

If I rename the argument kek to my_type, then everything works as expected! (hence why the example in the release notes works).

Possible Fix

I believe the culprit lies within the client code parsing the IDL into a layout here.

Unless I'm misunderstanding something, I believe this case should actually be written as follows, no?

case "alias": {
  return IdlCoder.fieldLayout(
-   { type: typeDef.type.value, name: typeDef.name },
+   { type: typeDef.type.value, name },
    types
  );
}

This patch resolves the quirk, but I'm not sure of what other effects it may have.

@acheroncrypto acheroncrypto added bug Something isn't working ts labels Feb 18, 2024
@acheroncrypto
Copy link
Collaborator

Yes, that's definitely a bug and your fix is correct — it should use name variable similar to the other defined types in typeDefLayout method.

I'm currently working on a rather large PR with regards to the IDL and it doesn't have this problem. However, if you'd like to make a PR with this fix, we can merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants